Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90adf28663 | ||
|
|
ea75e79609 | ||
|
|
d6ee3835f0 | ||
|
|
d9e38babb7 | ||
|
|
77cd87efef | ||
|
|
7d1e86ccae | ||
|
|
235b1c10a7 | ||
|
|
26db3f6cc9 | ||
|
|
14d31ed63f | ||
|
|
c63028d675 | ||
|
|
9718be09c1 | ||
|
|
479df8ecec | ||
|
|
1576ee279f | ||
|
|
eced6822f8 | ||
|
|
17d3733be3 | ||
|
|
79d0b0fa79 | ||
|
|
d3d8943fe4 | ||
|
|
f0c291e1da | ||
|
|
207f790314 | ||
|
|
c1023f6821 | ||
|
|
39d7bf6c70 | ||
|
|
e91e48dd60 | ||
|
|
563978a3ea | ||
|
|
7ea9f80d3f | ||
|
|
bc81b4d9e8 | ||
|
|
558e3f748d | ||
|
|
7168a42624 | ||
|
|
60bf8b9e4d | ||
|
|
2db9a2a00f | ||
|
|
132a55cefb | ||
|
|
e81d7767d3 | ||
|
|
7af5b1a553 | ||
|
|
aeb7b19c53 | ||
|
|
9d815f69a4 | ||
|
|
cc47fbf1f7 | ||
|
|
a869e71ac3 | ||
|
|
979c737f9b | ||
|
|
2529597ea0 | ||
|
|
bc87de3482 | ||
|
|
11a4f6c5cf | ||
|
|
64badd6b37 | ||
|
|
48860bbe26 | ||
|
|
c4231e58bf | ||
|
|
38934921c4 | ||
|
|
4147e917d6 | ||
|
|
adad565c03 | ||
|
|
db5c0e99b4 | ||
|
|
8ebbd50cb2 | ||
|
|
732bdd0f56 | ||
|
|
3bb14e0440 | ||
|
|
2b49ef0e0f | ||
|
|
f7c616d2b9 | ||
|
|
cc0a7eb9a2 |
No files matched your search
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: New Issue, Bug report, Question
|
||||
about: New Issue, Bug report, Question
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
# IMPORTANT NOTICE
|
||||
|
||||
Before filing an issue here PLEASE keep in mind that **tinyproxy 1.10.0 and older are no longer supported**.
|
||||
Do not report issues with 1.10.0 or older, first try latest release 1.11.0, or even better, git master, and see whether the issue is already fixed.
|
||||
|
||||
## Tinyproxy version
|
||||
State the tinyproxy version you're using; whether git master or 1.11.0 stable.
|
||||
|
||||
## Issue
|
||||
Fill in your Issue text here.
|
||||
A good issue report is detailed and includes full error messages from tinyproxy's output, not "X doesn't work".
|
||||
@@ -0,0 +1,36 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: ./autogen.sh
|
||||
- run: ./configure
|
||||
- run: make
|
||||
- run: make test
|
||||
test-macos:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: brew install automake
|
||||
- run: ./autogen.sh
|
||||
- run: ./configure
|
||||
- run: make
|
||||
valgrind-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install valgrind
|
||||
run: sudo apt-get install --assume-yes valgrind
|
||||
- run: ./autogen.sh
|
||||
- run: ./configure --enable-debug --enable-transparent --enable-reverse
|
||||
- run: make
|
||||
- run: make test
|
||||
- run: make valgrind-test
|
||||
@@ -0,0 +1,61 @@
|
||||
name: Generate Source Tarball
|
||||
|
||||
# Trigger whenever a release is created
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- created
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: archive
|
||||
id: archive
|
||||
run: |
|
||||
sudo apt install -y gperf
|
||||
rm -rf .git
|
||||
autoreconf -i
|
||||
VERSION=$(cat VERSION)
|
||||
PKGNAME="tinyproxy-$VERSION"
|
||||
./configure
|
||||
make dist
|
||||
echo "::set-output name=tarball_xz::${PKGNAME}.tar.xz"
|
||||
echo "::set-output name=tarball_gz::${PKGNAME}.tar.gz"
|
||||
echo "::set-output name=tarball_bz2::${PKGNAME}.tar.bz2"
|
||||
|
||||
- name: upload tarball_xz
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./${{ steps.archive.outputs.tarball_xz }}
|
||||
asset_name: ${{ steps.archive.outputs.tarball_xz }}
|
||||
asset_content_type: application/x-xz
|
||||
|
||||
- name: upload tarball_gz
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./${{ steps.archive.outputs.tarball_gz }}
|
||||
asset_name: ${{ steps.archive.outputs.tarball_gz }}
|
||||
asset_content_type: application/x-gzip
|
||||
|
||||
- name: upload tarball_bz2
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./${{ steps.archive.outputs.tarball_bz2 }}
|
||||
asset_name: ${{ steps.archive.outputs.tarball_bz2 }}
|
||||
asset_content_type: application/x-bzip2
|
||||
@@ -89,4 +89,4 @@ and create a [pull request](https://github.com/tinyproxy/tinyproxy/pulls).
|
||||
|
||||
You can meet developers and users to discuss development,
|
||||
patches and deployment issues in the `#tinyproxy` IRC channel on
|
||||
Freenode (`irc.freenode.net`).
|
||||
libera (`irc.libera.chat`).
|
||||
+13
-12
@@ -170,17 +170,6 @@ if test x"$debug_enabled" != x"yes" ; then
|
||||
CFLAGS="-DNDEBUG $CFLAGS"
|
||||
fi
|
||||
|
||||
AS_ECHO_N(["checking to see if linker understands -z,defs... "])
|
||||
LDFLAGS_OLD="-Wl $LDFLAGS"
|
||||
LDFLAGS="-Wl,-z,defs $LDFLAGS"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM()],
|
||||
AS_ECHO("yes"),
|
||||
AS_ECHO("no"); LDFLAGS="$LDFLAGS_OLD")
|
||||
|
||||
dnl
|
||||
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
|
||||
dnl
|
||||
|
||||
dnl
|
||||
dnl Substitute the variables into the various Makefiles
|
||||
dnl
|
||||
@@ -205,13 +194,21 @@ fi #manpage_support_enabled
|
||||
AM_CONDITIONAL(HAVE_POD2MAN, test "x$POD2MAN" != "x" -a "x$POD2MAN" != "xno")
|
||||
|
||||
AC_PATH_PROG(GPERF, gperf, no)
|
||||
AM_CONDITIONAL(HAVE_GPERF, test "x$GPERF" != "x" -a "x$GPERF" != "xno")
|
||||
AH_TEMPLATE([HAVE_GPERF],
|
||||
[Whether you have gperf installed for faster config parsing.])
|
||||
|
||||
tmp_gperf=false
|
||||
if test "x$GPERF" != "x" -a "x$GPERF" != "xno" ; then
|
||||
AS_ECHO_N(["checking whether gperf is recent enough... "])
|
||||
if "$GPERF" < src/conf-tokens.gperf >/dev/null 2>&1 ; then
|
||||
AS_ECHO("yes")
|
||||
AC_DEFINE(HAVE_GPERF)
|
||||
tmp_gperf=true
|
||||
else
|
||||
AS_ECHO("no")
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_GPERF, $tmp_gperf)
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
@@ -248,3 +245,7 @@ if test "x$POD2MAN" = "xno" ; then
|
||||
touch docs/man8/tinyproxy.8
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$HAVE_GPERF" = "xno" && test -e src/conf-tokens-gperf.inc ; then
|
||||
touch src/conf-tokens-gperf.inc
|
||||
fi
|
||||
+88
-62
@@ -1,69 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Stats [{package} v{version}]</title>
|
||||
<meta charset="UTF-8" />
|
||||
<style type="text/css">
|
||||
body {
|
||||
color: #eee;
|
||||
background: #110d0d;
|
||||
text-align: center;
|
||||
font: 12pt/1.6 Open Sans, Segoe UI, sans-serif;
|
||||
}
|
||||
#container {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: table;
|
||||
}
|
||||
#inner {
|
||||
width: 100%;
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
}
|
||||
table {
|
||||
width: auto;
|
||||
margin: auto;
|
||||
height: auto;
|
||||
background: #222020;
|
||||
border: 1px solid #777373;
|
||||
border-spacing: 3px;
|
||||
}
|
||||
th,
|
||||
td {
|
||||
padding: 6px 18px;
|
||||
}
|
||||
th {
|
||||
font-weight: 700;
|
||||
background: linear-gradient(to bottom, #777373, #555151);
|
||||
}
|
||||
.odd {
|
||||
background: #444040;
|
||||
}
|
||||
.even {
|
||||
background: #555151;
|
||||
}
|
||||
.center {
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
text-align: right;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<head>
|
||||
<title>{package} version {version} run-time statistics</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="inner">
|
||||
<table>
|
||||
<tr>
|
||||
<th colspan="2">{package} v{version} statistics</th>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td class="right">Open connections</td>
|
||||
<td class="center">{opens}</td>
|
||||
</tr>
|
||||
|
||||
<style type="text/css" media="screen">
|
||||
<!--/*--><![CDATA[<!--*/
|
||||
<tr class="even">
|
||||
<td class="right">Bad connections</td>
|
||||
<td class="center">{badconns}</td>
|
||||
</tr>
|
||||
|
||||
th, td
|
||||
{
|
||||
text-align: left;
|
||||
padding: 0.5em;
|
||||
border: 1px solid gray;
|
||||
}
|
||||
<tr class="odd">
|
||||
<td class="right">Denied connections</td>
|
||||
<td class="center">{deniedconns}</td>
|
||||
</tr>
|
||||
|
||||
/*]]>*/-->
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>{package} version {version} run-time statistics</h1>
|
||||
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of open connections</td>
|
||||
<td>{opens}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of requests</td>
|
||||
<td>{reqs}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of bad connections</td>
|
||||
<td>{badconns}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of denied connections</td>
|
||||
<td>{deniedconns}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of refused connections due to high load</td>
|
||||
<td>{refusedconns}</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
|
||||
<p><em>Generated by <a href="{website}">{package}</a> version {version}.</em></p>
|
||||
|
||||
</body>
|
||||
<tr class="even">
|
||||
<td class="right">Refused (high load)</td>
|
||||
<td class="center">{refusedconns}</td>
|
||||
</tr>
|
||||
|
||||
<tr class="odd">
|
||||
<td class="right">Total requests</td>
|
||||
<td class="center">{reqs}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -58,6 +58,8 @@ only on one specific address.
|
||||
|
||||
This allows you to specify which address Tinyproxy will bind
|
||||
to for outgoing connections to web servers or upstream proxies.
|
||||
This parameter may be specified multiple times, then Tinyproxy
|
||||
will try all the specified addresses in order.
|
||||
|
||||
=item B<BindSame>
|
||||
|
||||
@@ -265,7 +267,7 @@ domains. This option specifies the location of the file
|
||||
containing the filter rules, one rule per line.
|
||||
|
||||
Rules are specified as POSIX basic regular expressions (BRE), unless
|
||||
FilterExtended is activated.
|
||||
another FilterType is specified.
|
||||
Comment lines start with a `#` character.
|
||||
|
||||
Example filter file contents:
|
||||
@@ -285,14 +287,34 @@ Example filter file contents:
|
||||
# filter any domain that starts with adserver
|
||||
^adserver
|
||||
|
||||
=item B<FilterType>
|
||||
|
||||
This option can be set to one of `bre`, `ere`, or `fnmatch`.
|
||||
If `bre` is set, the rules specified in the filter file are matched
|
||||
using POSIX basic regular expressions, when set to `ere`, using
|
||||
POSIX extended regular expressions, and when set to `fnmatch` using
|
||||
the `fnmatch` function as specified in the manpage `man 3p fnmatch`.
|
||||
`fnmatch` matching is identical to what's used in the shell to match
|
||||
filenames, so for example `*.google.com` matches everything that
|
||||
ends with `.google.com`.
|
||||
If you don't know what regular expressions are or you're using filter
|
||||
lists from 3rd party sources, `fnmatch` is probably what you want.
|
||||
It's also the fastest matching method of the three.
|
||||
|
||||
=item B<FilterURLs>
|
||||
|
||||
If this boolean option is set to `Yes` or `On`, filtering is
|
||||
performed for URLs rather than for domains. The default is to
|
||||
filter based on domains.
|
||||
|
||||
Note that filtering for URLs works only in plain HTTP scenarios.
|
||||
Since HTTPS has become ubiquitous during the last years, this
|
||||
will only work on a tiny fraction of websites, so it is
|
||||
recommended not to use this option.
|
||||
|
||||
=item B<FilterExtended>
|
||||
|
||||
Deprecated. Use `FilterType ere` instead.
|
||||
If this boolean option is set to `Yes`, then extended POSIX
|
||||
regular expressions are used for matching the filter rules.
|
||||
The default is to use basic POSIX regular expressions.
|
||||
@@ -301,7 +323,11 @@ The default is to use basic POSIX regular expressions.
|
||||
|
||||
If this boolean option is set to `Yes`, then the filter rules
|
||||
are matched in a case sensitive manner. The default is to
|
||||
match case-insensitively.
|
||||
match case-insensitively, unfortunately.
|
||||
If you set this to `Yes`, then your matching will be almost
|
||||
twice as fast.
|
||||
This setting affects only `bre` and `ere` FilterTypes, fnmatch
|
||||
is always case sensitive.
|
||||
|
||||
=item B<FilterDefaultDeny>
|
||||
|
||||
@@ -309,6 +335,8 @@ The default filtering policy is to allow everything that is
|
||||
not matched by a filtering rule. Setting `FilterDefaultDeny`
|
||||
to `Yes` changes the policy do deny everything but the domains
|
||||
or URLs matched by the filtering rules.
|
||||
In other words, if set to `No` the Filter list acts as a
|
||||
blacklist, if set to `Yes` as a whitelist.
|
||||
|
||||
=item B<Anonymous>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<ul>
|
||||
<li>Feel free to report a new bug or suggest features via github issues.</li>
|
||||
<li>Tinyproxy developers hang out in #tinyproxy on irc.freenode.net.</li>
|
||||
<li>Tinyproxy developers hang out in #tinyproxy on irc.libera.chat.</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -56,8 +56,8 @@ Timeout 600
|
||||
# /usr/share/tinyproxy
|
||||
# /etc/tinyproxy
|
||||
#
|
||||
#ErrorFile 404 "@pkgdatadir@/404.html"
|
||||
#ErrorFile 400 "@pkgdatadir@/400.html"
|
||||
#ErrorFile 502 "@pkgdatadir@/502.html"
|
||||
#ErrorFile 503 "@pkgdatadir@/503.html"
|
||||
#ErrorFile 403 "@pkgdatadir@/403.html"
|
||||
#ErrorFile 408 "@pkgdatadir@/408.html"
|
||||
@@ -240,10 +240,9 @@ ViaProxyName "tinyproxy"
|
||||
#FilterURLs On
|
||||
|
||||
#
|
||||
# FilterExtended: Use POSIX Extended regular expressions rather than
|
||||
# basic.
|
||||
# FilterType: Use bre (default), ere, or fnmatch for filtering.
|
||||
#
|
||||
#FilterExtended On
|
||||
#FilterType fnmatch
|
||||
|
||||
#
|
||||
# FilterCaseSensitive: Use case sensitive regular expressions.
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ AM_CPPFLAGS = \
|
||||
-DLOCALSTATEDIR=\"${localstatedir}\"
|
||||
|
||||
tinyproxy_SOURCES = \
|
||||
hostspec.c hostspec.h \
|
||||
acl.c acl.h \
|
||||
anonymous.c anonymous.h \
|
||||
buffer.c buffer.h \
|
||||
@@ -66,5 +67,5 @@ conf-tokens-gperf.inc: conf-tokens.gperf
|
||||
$(GPERF) $< > $@
|
||||
endif
|
||||
|
||||
EXTRA_DIST = conf-tokens.gperf
|
||||
EXTRA_DIST = conf-tokens.gperf conf-tokens-gperf.inc
|
||||
|
||||
@@ -29,16 +29,7 @@
|
||||
#include "network.h"
|
||||
#include "sock.h"
|
||||
#include "sblist.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
/* Define how long an IPv6 address is in bytes (128 bits, 16 bytes) */
|
||||
#define IPV6_LEN 16
|
||||
|
||||
enum acl_type {
|
||||
ACL_STRING,
|
||||
ACL_NUMERIC
|
||||
};
|
||||
#include "hostspec.h"
|
||||
|
||||
/*
|
||||
* Hold the information about a particular access control. We store
|
||||
@@ -47,66 +38,9 @@ enum acl_type {
|
||||
*/
|
||||
struct acl_s {
|
||||
acl_access_t access;
|
||||
enum acl_type type;
|
||||
union {
|
||||
char *string;
|
||||
struct {
|
||||
unsigned char network[IPV6_LEN];
|
||||
unsigned char mask[IPV6_LEN];
|
||||
} ip;
|
||||
} address;
|
||||
struct hostspec h;
|
||||
};
|
||||
|
||||
/*
|
||||
* Fills in the netmask array given a numeric value.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success
|
||||
* -1 on failure (invalid mask value)
|
||||
*
|
||||
*/
|
||||
static int
|
||||
fill_netmask_array (char *bitmask_string, int v6,
|
||||
unsigned char array[], size_t len)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned long int mask;
|
||||
char *endptr;
|
||||
|
||||
errno = 0; /* to distinguish success/failure after call */
|
||||
mask = strtoul (bitmask_string, &endptr, 10);
|
||||
|
||||
/* check for various conversion errors */
|
||||
if ((errno == ERANGE && mask == ULONG_MAX)
|
||||
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
|
||||
return -1;
|
||||
|
||||
if (v6 == 0) {
|
||||
/* The mask comparison is done as an IPv6 address, so
|
||||
* convert to a longer mask in the case of IPv4
|
||||
* addresses. */
|
||||
mask += 12 * 8;
|
||||
}
|
||||
|
||||
/* check valid range for a bit mask */
|
||||
if (mask > (8 * len))
|
||||
return -1;
|
||||
|
||||
/* we have a valid range to fill in the array */
|
||||
for (i = 0; i != len; ++i) {
|
||||
if (mask >= 8) {
|
||||
array[i] = 0xff;
|
||||
mask -= 8;
|
||||
} else if (mask > 0) {
|
||||
array[i] = (unsigned char) (0xff << (8 - mask));
|
||||
mask = 0;
|
||||
} else {
|
||||
array[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the access list has not been set up, create it.
|
||||
@@ -138,7 +72,6 @@ int
|
||||
insert_acl (char *location, acl_access_t access_type, acl_list_t *access_list)
|
||||
{
|
||||
struct acl_s acl;
|
||||
char *mask, ip_dst[IPV6_LEN];
|
||||
|
||||
assert (location != NULL);
|
||||
|
||||
@@ -150,55 +83,11 @@ insert_acl (char *location, acl_access_t access_type, acl_list_t *access_list)
|
||||
*/
|
||||
memset (&acl, 0, sizeof (struct acl_s));
|
||||
acl.access = access_type;
|
||||
|
||||
if ((mask = strrchr(location, '/')))
|
||||
*(mask++) = 0;
|
||||
|
||||
/*
|
||||
* Check for a valid IP address (the simplest case) first.
|
||||
*/
|
||||
if (full_inet_pton (location, ip_dst) > 0) {
|
||||
acl.type = ACL_NUMERIC;
|
||||
memcpy (acl.address.ip.network, ip_dst, IPV6_LEN);
|
||||
if(!mask) memset (acl.address.ip.mask, 0xff, IPV6_LEN);
|
||||
else {
|
||||
char dst[sizeof(struct in6_addr)];
|
||||
int v6, i;
|
||||
/* Check if the IP address before the netmask is
|
||||
* an IPv6 address */
|
||||
if (inet_pton(AF_INET6, location, dst) > 0)
|
||||
v6 = 1;
|
||||
else
|
||||
v6 = 0;
|
||||
|
||||
if (fill_netmask_array
|
||||
(mask, v6, &(acl.address.ip.mask[0]), IPV6_LEN)
|
||||
< 0)
|
||||
goto err;
|
||||
|
||||
for (i = 0; i < IPV6_LEN; i++)
|
||||
acl.address.ip.network[i] = ip_dst[i] &
|
||||
acl.address.ip.mask[i];
|
||||
}
|
||||
} else {
|
||||
/* either bogus IP or hostname */
|
||||
/* bogus ipv6 ? */
|
||||
if (mask || strchr (location, ':'))
|
||||
goto err;
|
||||
|
||||
/* In all likelihood a string */
|
||||
acl.type = ACL_STRING;
|
||||
acl.address.string = safestrdup (location);
|
||||
if (!acl.address.string)
|
||||
goto err;
|
||||
}
|
||||
if(hostspec_parse(location, &acl.h) || acl.h.type == HST_NONE)
|
||||
return -1;
|
||||
|
||||
if(!sblist_add(*access_list, &acl)) return -1;
|
||||
return 0;
|
||||
err:;
|
||||
/* restore mask for proper error message */
|
||||
if(mask) *(--mask) = '/';
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -219,7 +108,7 @@ acl_string_processing (struct acl_s *acl, const char *ip_address,
|
||||
size_t test_length, match_length;
|
||||
char ipbuf[512];
|
||||
|
||||
assert (acl && acl->type == ACL_STRING);
|
||||
assert (acl && acl->h.type == HST_STRING);
|
||||
assert (ip_address && strlen (ip_address) > 0);
|
||||
|
||||
/*
|
||||
@@ -227,11 +116,11 @@ acl_string_processing (struct acl_s *acl, const char *ip_address,
|
||||
* do a string based test only; otherwise, we can do a reverse
|
||||
* lookup test as well.
|
||||
*/
|
||||
if (acl->address.string[0] != '.') {
|
||||
if (acl->h.address.string[0] != '.') {
|
||||
memset (&hints, 0, sizeof (struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
if (getaddrinfo (acl->address.string, NULL, &hints, &res) != 0)
|
||||
if (getaddrinfo (acl->h.address.string, NULL, &hints, &res) != 0)
|
||||
goto STRING_TEST;
|
||||
|
||||
ressave = res;
|
||||
@@ -265,7 +154,7 @@ STRING_TEST:
|
||||
}
|
||||
|
||||
test_length = strlen (string_addr);
|
||||
match_length = strlen (acl->address.string);
|
||||
match_length = strlen (acl->h.address.string);
|
||||
|
||||
/*
|
||||
* If the string length is shorter than AC string, return a -1 so
|
||||
@@ -276,7 +165,7 @@ STRING_TEST:
|
||||
|
||||
if (strcasecmp
|
||||
(string_addr + (test_length - match_length),
|
||||
acl->address.string) == 0) {
|
||||
acl->h.address.string) == 0) {
|
||||
if (acl->access == ACL_DENY)
|
||||
return 0;
|
||||
else
|
||||
@@ -300,11 +189,11 @@ static int check_numeric_acl (const struct acl_s *acl, uint8_t addr[IPV6_LEN])
|
||||
uint8_t x, y;
|
||||
int i;
|
||||
|
||||
assert (acl && acl->type == ACL_NUMERIC);
|
||||
assert (acl && acl->h.type == HST_NUMERIC);
|
||||
|
||||
for (i = 0; i != IPV6_LEN; ++i) {
|
||||
x = addr[i] & acl->address.ip.mask[i];
|
||||
y = acl->address.ip.network[i];
|
||||
x = addr[i] & acl->h.address.ip.mask[i];
|
||||
y = acl->h.address.ip.network[i];
|
||||
|
||||
/* If x and y don't match, the IP addresses don't match */
|
||||
if (x != y)
|
||||
@@ -345,12 +234,12 @@ int check_acl (const char *ip, union sockaddr_union *addr, acl_list_t access_lis
|
||||
|
||||
for (i = 0; i < sblist_getsize (access_list); ++i) {
|
||||
acl = sblist_get (access_list, i);
|
||||
switch (acl->type) {
|
||||
case ACL_STRING:
|
||||
switch (acl->h.type) {
|
||||
case HST_STRING:
|
||||
perm = acl_string_processing (acl, ip, addr, string_addr);
|
||||
break;
|
||||
|
||||
case ACL_NUMERIC:
|
||||
case HST_NUMERIC:
|
||||
if (ip[0] == '\0')
|
||||
continue;
|
||||
|
||||
@@ -358,6 +247,10 @@ int check_acl (const char *ip, union sockaddr_union *addr, acl_list_t access_lis
|
||||
? check_numeric_acl (acl, numeric_addr)
|
||||
: -1;
|
||||
break;
|
||||
|
||||
case HST_NONE:
|
||||
perm = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -394,8 +287,8 @@ void flush_access_list (acl_list_t access_list)
|
||||
*/
|
||||
for (i = 0; i < sblist_getsize (access_list); ++i) {
|
||||
acl = sblist_get (access_list, i);
|
||||
if (acl->type == ACL_STRING) {
|
||||
safefree (acl->address.string);
|
||||
if (acl->h.type == HST_STRING) {
|
||||
safefree (acl->h.address.string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
# include <arpa/inet.h>
|
||||
# include <grp.h>
|
||||
# include <pwd.h>
|
||||
# include <limits.h>
|
||||
|
||||
/* rest - some oddball headers */
|
||||
#ifdef HAVE_VALUES_H
|
||||
|
||||
@@ -34,6 +34,7 @@ config_directive_find (register const char *str, register size_t len)
|
||||
{"defaulterrorfile", CD_defaulterrorfile},
|
||||
{"startservers", CD_startservers},
|
||||
{"filtercasesensitive", CD_filtercasesensitive},
|
||||
{"filtertype", CD_filtertype},
|
||||
{"filterurls", CD_filterurls},
|
||||
{"filter", CD_filter},
|
||||
{"reversemagic", CD_reversemagic},
|
||||
|
||||
@@ -51,6 +51,7 @@ filterurls, CD_filterurls
|
||||
filterextended, CD_filterextended
|
||||
filterdefaultdeny, CD_filterdefaultdeny
|
||||
filtercasesensitive, CD_filtercasesensitive
|
||||
filtertype, CD_filtertype
|
||||
reversebaseurl, CD_reversebaseurl
|
||||
reverseonly, CD_reverseonly
|
||||
reversemagic, CD_reversemagic
|
||||
|
||||
@@ -33,6 +33,7 @@ CD_errorfile,
|
||||
CD_addheader,
|
||||
CD_filter,
|
||||
CD_filterurls,
|
||||
CD_filtertype,
|
||||
CD_filterextended,
|
||||
CD_filterdefaultdeny,
|
||||
CD_filtercasesensitive,
|
||||
|
||||
+70
-13
@@ -40,6 +40,12 @@
|
||||
#include "basicauth.h"
|
||||
#include "conf-tokens.h"
|
||||
|
||||
#ifdef LINE_MAX
|
||||
#define TP_LINE_MAX LINE_MAX
|
||||
#else
|
||||
#define TP_LINE_MAX 1024
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The configuration directives are defined in the structure below. Each
|
||||
* directive requires a regular expression to match against, and a
|
||||
@@ -129,6 +135,7 @@ static HANDLE_FUNC (handle_filtercasesensitive);
|
||||
static HANDLE_FUNC (handle_filterdefaultdeny);
|
||||
static HANDLE_FUNC (handle_filterextended);
|
||||
static HANDLE_FUNC (handle_filterurls);
|
||||
static HANDLE_FUNC (handle_filtertype);
|
||||
#endif
|
||||
static HANDLE_FUNC (handle_group);
|
||||
static HANDLE_FUNC (handle_listen);
|
||||
@@ -228,6 +235,7 @@ struct {
|
||||
STDCONF (filterextended, BOOL, handle_filterextended),
|
||||
STDCONF (filterdefaultdeny, BOOL, handle_filterdefaultdeny),
|
||||
STDCONF (filtercasesensitive, BOOL, handle_filtercasesensitive),
|
||||
STDCONF (filtertype, "(bre|ere|fnmatch)", handle_filtertype),
|
||||
#endif
|
||||
#ifdef REVERSE_SUPPORT
|
||||
/* Reverse proxy arguments */
|
||||
@@ -291,6 +299,7 @@ void free_config (struct config_s *conf)
|
||||
safefree (conf->group);
|
||||
stringlist_free(conf->basicauth_list);
|
||||
stringlist_free(conf->listen_addrs);
|
||||
stringlist_free(conf->bind_addrs);
|
||||
#ifdef FILTER_ENABLE
|
||||
safefree (conf->filter);
|
||||
#endif /* FILTER_ENABLE */
|
||||
@@ -302,7 +311,6 @@ void free_config (struct config_s *conf)
|
||||
free_upstream_list (conf->upstream_list);
|
||||
#endif /* UPSTREAM_SUPPORT */
|
||||
safefree (conf->pidpath);
|
||||
safefree (conf->bind_address);
|
||||
safefree (conf->via_proxy_name);
|
||||
if (conf->errorpages) {
|
||||
it = 0;
|
||||
@@ -409,7 +417,7 @@ static int check_match (struct config_s *conf, const char *line,
|
||||
*/
|
||||
static int config_parse (struct config_s *conf, FILE * f)
|
||||
{
|
||||
char buffer[LINE_MAX], *p, *q, c;
|
||||
char buffer[TP_LINE_MAX], *p, *q, c;
|
||||
const struct config_directive_entry *e;
|
||||
unsigned long lineno = 1;
|
||||
|
||||
@@ -505,7 +513,7 @@ int reload_config_file (const char *config_fname, struct config_s *conf)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!conf->user) {
|
||||
if (!conf->user && !geteuid()) {
|
||||
log_message (LOG_WARNING, "You SHOULD set a UserName in the "
|
||||
"config file. Using current user instead.");
|
||||
}
|
||||
@@ -701,6 +709,8 @@ static HANDLE_FUNC (handle_xtinyproxy)
|
||||
#ifdef XTINYPROXY_ENABLE
|
||||
return set_bool_arg (&conf->add_xtinyproxy, line, &match[2]);
|
||||
#else
|
||||
if(!get_bool_arg(line, &match[2]))
|
||||
return 0;
|
||||
fprintf (stderr,
|
||||
"XTinyproxy NOT Enabled! Recompile with --enable-xtinyproxy\n");
|
||||
return 1;
|
||||
@@ -796,12 +806,27 @@ static HANDLE_FUNC (handle_deny)
|
||||
|
||||
static HANDLE_FUNC (handle_bind)
|
||||
{
|
||||
int r = set_string_arg (&conf->bind_address, line, &match[2]);
|
||||
char *arg = get_string_arg (line, &match[2]);
|
||||
|
||||
if (arg == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (conf->bind_addrs == NULL) {
|
||||
conf->bind_addrs = sblist_new(sizeof(char*), 16);
|
||||
if (conf->bind_addrs == NULL) {
|
||||
CP_WARN ("Could not create a list "
|
||||
"of bind addresses.", "");
|
||||
safefree(arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sblist_add (conf->bind_addrs, &arg);
|
||||
|
||||
if (r)
|
||||
return r;
|
||||
log_message (LOG_INFO,
|
||||
"Outgoing connections bound to IP %s", conf->bind_address);
|
||||
"Added bind address [%s] for outgoing connections.", arg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -929,6 +954,11 @@ static HANDLE_FUNC (handle_basicauth)
|
||||
}
|
||||
|
||||
#ifdef FILTER_ENABLE
|
||||
|
||||
static void warn_deprecated(const char *arg, unsigned long lineno) {
|
||||
CP_WARN ("deprecated option %s", arg);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filter)
|
||||
{
|
||||
return set_string_arg (&conf->filter, line, &match[2]);
|
||||
@@ -936,26 +966,53 @@ static HANDLE_FUNC (handle_filter)
|
||||
|
||||
static HANDLE_FUNC (handle_filterurls)
|
||||
{
|
||||
return set_bool_arg (&conf->filter_url, line, &match[2]);
|
||||
conf->filter_opts |=
|
||||
get_bool_arg (line, &match[2]) * FILTER_OPT_URL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filterextended)
|
||||
{
|
||||
return set_bool_arg (&conf->filter_extended, line, &match[2]);
|
||||
warn_deprecated("FilterExtended, use FilterType", lineno);
|
||||
conf->filter_opts |=
|
||||
get_bool_arg (line, &match[2]) * FILTER_OPT_TYPE_ERE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filterdefaultdeny)
|
||||
{
|
||||
assert (match[2].rm_so != -1);
|
||||
|
||||
if (get_bool_arg (line, &match[2]))
|
||||
filter_set_default_policy (FILTER_DEFAULT_DENY);
|
||||
conf->filter_opts |=
|
||||
get_bool_arg (line, &match[2]) * FILTER_OPT_DEFAULT_DENY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filtercasesensitive)
|
||||
{
|
||||
return set_bool_arg (&conf->filter_casesensitive, line, &match[2]);
|
||||
conf->filter_opts |=
|
||||
get_bool_arg (line, &match[2]) * FILTER_OPT_CASESENSITIVE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filtertype)
|
||||
{
|
||||
static const struct { unsigned short flag; char type[8]; }
|
||||
ftmap[] = {
|
||||
{FILTER_OPT_TYPE_ERE, "ere"},
|
||||
{FILTER_OPT_TYPE_BRE, "bre"},
|
||||
{FILTER_OPT_TYPE_FNMATCH, "fnmatch"},
|
||||
};
|
||||
char *type;
|
||||
unsigned i;
|
||||
type = get_string_arg(line, &match[2]);
|
||||
if (!type) return -1;
|
||||
|
||||
for(i=0;i<sizeof(ftmap)/sizeof(ftmap[0]);++i)
|
||||
if(!strcmp(ftmap[i].type, type))
|
||||
conf->filter_opts |= ftmap[i].flag;
|
||||
|
||||
safefree (type);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+2
-4
@@ -50,9 +50,7 @@ struct config_s {
|
||||
sblist *listen_addrs;
|
||||
#ifdef FILTER_ENABLE
|
||||
char *filter;
|
||||
unsigned int filter_url; /* boolean */
|
||||
unsigned int filter_extended; /* boolean */
|
||||
unsigned int filter_casesensitive; /* boolean */
|
||||
unsigned int filter_opts; /* enum filter_options */
|
||||
#endif /* FILTER_ENABLE */
|
||||
#ifdef XTINYPROXY_ENABLE
|
||||
unsigned int add_xtinyproxy; /* boolean */
|
||||
@@ -68,7 +66,7 @@ struct config_s {
|
||||
#endif /* UPSTREAM_SUPPORT */
|
||||
char *pidpath;
|
||||
unsigned int idletimeout;
|
||||
char *bind_address;
|
||||
sblist *bind_addrs;
|
||||
unsigned int bindsame;
|
||||
|
||||
/*
|
||||
|
||||
+26
-20
@@ -25,6 +25,7 @@
|
||||
#include "main.h"
|
||||
|
||||
#include <regex.h>
|
||||
#include <fnmatch.h>
|
||||
#include "filter.h"
|
||||
#include "heap.h"
|
||||
#include "log.h"
|
||||
@@ -37,15 +38,17 @@
|
||||
static int err;
|
||||
|
||||
struct filter_list {
|
||||
union {
|
||||
regex_t cpatb;
|
||||
char *pattern;
|
||||
} u;
|
||||
};
|
||||
|
||||
static sblist *fl = NULL;
|
||||
static int already_init = 0;
|
||||
static filter_policy_t default_policy = FILTER_DEFAULT_ALLOW;
|
||||
|
||||
/*
|
||||
* Initializes a linked list of strings containing hosts/urls to be filtered
|
||||
* Initializes a list of strings containing hosts/urls to be filtered
|
||||
*/
|
||||
void filter_init (void)
|
||||
{
|
||||
@@ -61,14 +64,13 @@ void filter_init (void)
|
||||
|
||||
fd = fopen (config->filter, "r");
|
||||
if (!fd) {
|
||||
return;
|
||||
perror ("filter file");
|
||||
exit (EX_DATAERR);
|
||||
}
|
||||
|
||||
cflags = REG_NEWLINE | REG_NOSUB;
|
||||
if (config->filter_extended)
|
||||
cflags |= REG_EXTENDED;
|
||||
if (!config->filter_casesensitive)
|
||||
cflags |= REG_ICASE;
|
||||
cflags |= (REG_EXTENDED * !!(config->filter_opts & FILTER_OPT_TYPE_ERE));
|
||||
cflags |= (REG_ICASE * !(config->filter_opts & FILTER_OPT_CASESENSITIVE));
|
||||
|
||||
while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
|
||||
++lineno;
|
||||
@@ -106,7 +108,12 @@ void filter_init (void)
|
||||
if (!fl) fl = sblist_new(sizeof(struct filter_list),
|
||||
4096/sizeof(struct filter_list));
|
||||
|
||||
err = regcomp (&fe.cpatb, s, cflags);
|
||||
if (config->filter_opts & FILTER_OPT_TYPE_FNMATCH) {
|
||||
fe.u.pattern = safestrdup(s);
|
||||
if (!fe.u.pattern) goto oom;
|
||||
} else {
|
||||
|
||||
err = regcomp (&fe.u.cpatb, s, cflags);
|
||||
if (err != 0) {
|
||||
if (err == REG_ESPACE) goto oom;
|
||||
fprintf (stderr,
|
||||
@@ -114,6 +121,7 @@ void filter_init (void)
|
||||
config->filter, lineno, s);
|
||||
exit (EX_DATAERR);
|
||||
}
|
||||
}
|
||||
if (!sblist_add(fl, &fe)) {
|
||||
oom:;
|
||||
fprintf (stderr,
|
||||
@@ -141,7 +149,10 @@ void filter_destroy (void)
|
||||
if (fl) {
|
||||
for (i = 0; i < sblist_getsize(fl); ++i) {
|
||||
p = sblist_get(fl, i);
|
||||
regfree (&p->cpatb);
|
||||
if (config->filter_opts & FILTER_OPT_TYPE_FNMATCH)
|
||||
safefree(p->u.pattern);
|
||||
else
|
||||
regfree (&p->u.cpatb);
|
||||
}
|
||||
sblist_free(fl);
|
||||
}
|
||||
@@ -174,11 +185,14 @@ int filter_run (const char *str)
|
||||
|
||||
for (i = 0; i < sblist_getsize(fl); ++i) {
|
||||
p = sblist_get(fl, i);
|
||||
if (config->filter_opts & FILTER_OPT_TYPE_FNMATCH)
|
||||
result = fnmatch (p->u.pattern, str, 0);
|
||||
else
|
||||
result =
|
||||
regexec (&p->cpatb, str, (size_t) 0, (regmatch_t *) 0, 0);
|
||||
regexec (&p->u.cpatb, str, (size_t) 0, (regmatch_t *) 0, 0);
|
||||
|
||||
if (result == 0) {
|
||||
if (default_policy == FILTER_DEFAULT_ALLOW)
|
||||
if (!(config->filter_opts & FILTER_OPT_DEFAULT_DENY))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
@@ -186,16 +200,8 @@ int filter_run (const char *str)
|
||||
}
|
||||
|
||||
COMMON_EXIT:
|
||||
if (default_policy == FILTER_DEFAULT_ALLOW)
|
||||
if (!(config->filter_opts & FILTER_OPT_DEFAULT_DENY))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the default filtering policy
|
||||
*/
|
||||
void filter_set_default_policy (filter_policy_t policy)
|
||||
{
|
||||
default_policy = policy;
|
||||
}
|
||||
+12
-6
@@ -21,16 +21,22 @@
|
||||
#ifndef _TINYPROXY_FILTER_H_
|
||||
#define _TINYPROXY_FILTER_H_
|
||||
|
||||
typedef enum {
|
||||
FILTER_DEFAULT_ALLOW,
|
||||
FILTER_DEFAULT_DENY
|
||||
} filter_policy_t;
|
||||
enum filter_options {
|
||||
FILTER_OPT_CASESENSITIVE = 1 << 0,
|
||||
FILTER_OPT_URL = 1 << 1,
|
||||
FILTER_OPT_DEFAULT_DENY = 1 << 2,
|
||||
|
||||
FILTER_OPT_TYPE_BRE = 1 << 8,
|
||||
FILTER_OPT_TYPE_ERE = 1 << 9,
|
||||
FILTER_OPT_TYPE_FNMATCH = 1 << 10,
|
||||
};
|
||||
|
||||
#define FILTER_TYPE_MASK \
|
||||
(FILTER_OPT_TYPE_BRE | FILTER_OPT_TYPE_ERE | FILTER_OPT_TYPE_FNMATCH)
|
||||
|
||||
extern void filter_init (void);
|
||||
extern void filter_destroy (void);
|
||||
extern void filter_reload (void);
|
||||
extern int filter_run (const char *str);
|
||||
|
||||
extern void filter_set_default_policy (filter_policy_t policy);
|
||||
|
||||
#endif
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
#include "common.h"
|
||||
#include "hostspec.h"
|
||||
#include "heap.h"
|
||||
#include "network.h"
|
||||
|
||||
static int dotted_mask(char *bitmask_string, unsigned char array[])
|
||||
{
|
||||
unsigned char v4bits[4];
|
||||
if (1 != inet_pton (AF_INET, bitmask_string, v4bits)) return -1;
|
||||
memset (array, 0xff, IPV6_LEN-4);
|
||||
memcpy (array + IPV6_LEN-4, v4bits, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills in the netmask array given a numeric value.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success
|
||||
* -1 on failure (invalid mask value)
|
||||
*
|
||||
*/
|
||||
static int
|
||||
fill_netmask_array (char *bitmask_string, int v6,
|
||||
unsigned char array[])
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned long int mask;
|
||||
char *endptr;
|
||||
|
||||
errno = 0; /* to distinguish success/failure after call */
|
||||
if (strchr (bitmask_string, '.')) {
|
||||
if (v6) return -1; /* ipv6 doesn't supported dotted netmasks */
|
||||
return dotted_mask(bitmask_string, array);
|
||||
}
|
||||
mask = strtoul (bitmask_string, &endptr, 10);
|
||||
|
||||
/* check for various conversion errors */
|
||||
if ((errno == ERANGE && mask == ULONG_MAX)
|
||||
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
|
||||
return -1;
|
||||
|
||||
if (v6 == 0) {
|
||||
/* The mask comparison is done as an IPv6 address, so
|
||||
* convert to a longer mask in the case of IPv4
|
||||
* addresses. */
|
||||
mask += 12 * 8;
|
||||
}
|
||||
|
||||
/* check valid range for a bit mask */
|
||||
if (mask > (8 * IPV6_LEN))
|
||||
return -1;
|
||||
|
||||
/* we have a valid range to fill in the array */
|
||||
for (i = 0; i != IPV6_LEN; ++i) {
|
||||
if (mask >= 8) {
|
||||
array[i] = 0xff;
|
||||
mask -= 8;
|
||||
} else if (mask > 0) {
|
||||
array[i] = (unsigned char) (0xff << (8 - mask));
|
||||
mask = 0;
|
||||
} else {
|
||||
array[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* parse a location string containing either an ipv4/ipv4 + hostmask tuple
|
||||
or a dnsname into a struct hostspec.
|
||||
returns 0 on success, non-0 on error (might be memory allocation, bogus
|
||||
ip address or mask).
|
||||
*/
|
||||
int hostspec_parse(char *location, struct hostspec *h) {
|
||||
char *mask, ip_dst[IPV6_LEN];
|
||||
|
||||
h->type = HST_NONE;
|
||||
if(!location) return 0;
|
||||
|
||||
memset(h, 0, sizeof(*h));
|
||||
if ((mask = strrchr(location, '/')))
|
||||
*(mask++) = 0;
|
||||
|
||||
/*
|
||||
* Check for a valid IP address (the simplest case) first.
|
||||
*/
|
||||
if (full_inet_pton (location, ip_dst) > 0) {
|
||||
h->type = HST_NUMERIC;
|
||||
memcpy (h->address.ip.network, ip_dst, IPV6_LEN);
|
||||
if(!mask) memset (h->address.ip.mask, 0xff, IPV6_LEN);
|
||||
else {
|
||||
char dst[sizeof(struct in6_addr)];
|
||||
int v6, i;
|
||||
/* Check if the IP address before the netmask is
|
||||
* an IPv6 address */
|
||||
if (inet_pton(AF_INET6, location, dst) > 0)
|
||||
v6 = 1;
|
||||
else
|
||||
v6 = 0;
|
||||
|
||||
if (fill_netmask_array
|
||||
(mask, v6, &(h->address.ip.mask[0]))
|
||||
< 0)
|
||||
goto err;
|
||||
|
||||
for (i = 0; i < IPV6_LEN; i++)
|
||||
h->address.ip.network[i] = ip_dst[i] &
|
||||
h->address.ip.mask[i];
|
||||
}
|
||||
} else {
|
||||
/* either bogus IP or hostname */
|
||||
/* bogus ipv6 ? */
|
||||
if (mask || strchr (location, ':'))
|
||||
goto err;
|
||||
|
||||
/* In all likelihood a string */
|
||||
h->type = HST_STRING;
|
||||
h->address.string = safestrdup (location);
|
||||
if (!h->address.string)
|
||||
goto err;
|
||||
}
|
||||
/* restore mask */
|
||||
if(mask) *(--mask) = '/';
|
||||
return 0;
|
||||
err:;
|
||||
if(mask) *(--mask) = '/';
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int string_match(const char *ip, const char *addrspec)
|
||||
{
|
||||
size_t test_length, match_length;
|
||||
if(!strcasecmp(ip, addrspec)) return 1;
|
||||
if(addrspec[0] != '.') return 0;
|
||||
test_length = strlen (ip);
|
||||
match_length = strlen (addrspec);
|
||||
if (test_length < match_length) return 0;
|
||||
return (strcasecmp
|
||||
(ip + (test_length - match_length),
|
||||
addrspec) == 0);
|
||||
}
|
||||
|
||||
static int numeric_match(const uint8_t addr[], const struct hostspec *h)
|
||||
{
|
||||
uint8_t x, y;
|
||||
int i;
|
||||
|
||||
for (i = 0; i != IPV6_LEN; ++i) {
|
||||
x = addr[i] & h->address.ip.mask[i];
|
||||
y = h->address.ip.network[i];
|
||||
|
||||
/* If x and y don't match, the IP addresses don't match */
|
||||
if (x != y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check whether ip matches hostspec.
|
||||
return 1 on match, 0 on non-match */
|
||||
int hostspec_match(const char *ip, const struct hostspec *h) {
|
||||
int is_numeric_addr;
|
||||
uint8_t numeric_addr[IPV6_LEN];
|
||||
if (ip[0] == '\0') return 0;
|
||||
is_numeric_addr = (full_inet_pton (ip, &numeric_addr) > 0);
|
||||
switch (h->type) {
|
||||
case HST_STRING:
|
||||
if(is_numeric_addr) return 0;
|
||||
return string_match (ip, h->address.string);
|
||||
case HST_NUMERIC:
|
||||
return numeric_match (numeric_addr, h);
|
||||
case HST_NONE:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef HOSTSPEC_H
|
||||
#define HOSTSPEC_H
|
||||
|
||||
#define IPV6_LEN 16
|
||||
|
||||
enum hostspec_type {
|
||||
HST_NONE,
|
||||
HST_STRING,
|
||||
HST_NUMERIC,
|
||||
};
|
||||
|
||||
struct hostspec {
|
||||
enum hostspec_type type;
|
||||
union {
|
||||
char *string;
|
||||
struct {
|
||||
unsigned char network[IPV6_LEN];
|
||||
unsigned char mask[IPV6_LEN];
|
||||
} ip;
|
||||
} address;
|
||||
};
|
||||
|
||||
int hostspec_parse(char *domain, struct hostspec *h);
|
||||
int hostspec_match(const char *ip, const struct hostspec *h);
|
||||
|
||||
#endif
|
||||
+32
-14
@@ -49,6 +49,7 @@ struct htab {
|
||||
size_t mask;
|
||||
size_t used;
|
||||
size_t seed;
|
||||
size_t dead;
|
||||
};
|
||||
|
||||
#define MINSIZE 8
|
||||
@@ -107,14 +108,14 @@ static int resize(struct htab *htab, size_t nel)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct elem *lookup(struct htab *htab, const char *key, size_t hash)
|
||||
static struct elem *lookup(struct htab *htab, const char *key, size_t hash, size_t dead)
|
||||
{
|
||||
size_t i, j;
|
||||
struct elem *e;
|
||||
|
||||
for (i=hash,j=1; ; i+=j++) {
|
||||
e = htab->elems + (i & htab->mask);
|
||||
if (!e->item.key ||
|
||||
if ((!e->item.key && (!e->hash || e->hash == dead)) ||
|
||||
(e->hash==hash && STRCMP(e->item.key, key)==0))
|
||||
break;
|
||||
}
|
||||
@@ -138,50 +139,67 @@ void htab_destroy(struct htab *htab)
|
||||
free(htab);
|
||||
}
|
||||
|
||||
static htab_entry *htab_find_item(struct htab *htab, const char* key)
|
||||
static struct elem *htab_find_elem(struct htab *htab, const char* key)
|
||||
{
|
||||
size_t hash = keyhash(key, htab->seed);
|
||||
struct elem *e = lookup(htab, key, hash);
|
||||
struct elem *e = lookup(htab, key, hash, 0);
|
||||
|
||||
if (e->item.key) {
|
||||
return &e->item;
|
||||
return e;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
htab_value* htab_find(struct htab *htab, const char* key)
|
||||
{
|
||||
htab_entry *i = htab_find_item(htab, key);
|
||||
if(i) return &i->data;
|
||||
return 0;
|
||||
struct elem *e = htab_find_elem(htab, key);
|
||||
if(!e) return 0;
|
||||
return &e->item.data;
|
||||
}
|
||||
|
||||
htab_value* htab_find2(struct htab *htab, const char* key, char **saved_key)
|
||||
{
|
||||
struct elem *e = htab_find_elem(htab, key);
|
||||
if(!e) return 0;
|
||||
*saved_key = e->item.key;
|
||||
return &e->item.data;
|
||||
}
|
||||
|
||||
int htab_delete(struct htab *htab, const char* key)
|
||||
{
|
||||
htab_entry *i = htab_find_item(htab, key);
|
||||
if(!i) return 0;
|
||||
i->key = 0;
|
||||
struct elem *e = htab_find_elem(htab, key);
|
||||
if(!e) return 0;
|
||||
e->item.key = 0;
|
||||
e->hash = 0xdeadc0de;
|
||||
--htab->used;
|
||||
++htab->dead;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int htab_insert(struct htab *htab, char* key, htab_value value)
|
||||
{
|
||||
size_t hash = keyhash(key, htab->seed);
|
||||
struct elem *e = lookup(htab, key, hash);
|
||||
size_t hash = keyhash(key, htab->seed), oh;
|
||||
struct elem *e = lookup(htab, key, hash, 0xdeadc0de);
|
||||
if(e->item.key) {
|
||||
/* it's not allowed to overwrite existing data */
|
||||
return 0;
|
||||
}
|
||||
|
||||
oh = e->hash; /* save old hash in case it's tombstone marker */
|
||||
e->item.key = key;
|
||||
e->item.data = value;
|
||||
e->hash = hash;
|
||||
if (++htab->used > htab->mask - htab->mask/4) {
|
||||
if (++htab->used + htab->dead > htab->mask - htab->mask/4) {
|
||||
if (!resize(htab, 2*htab->used)) {
|
||||
htab->used--;
|
||||
e->item.key = 0;
|
||||
e->hash = oh;
|
||||
return 0;
|
||||
}
|
||||
htab->dead = 0;
|
||||
} else if (oh == 0xdeadc0de) {
|
||||
/* re-used tomb */
|
||||
--htab->dead;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ typedef union htab_value {
|
||||
struct htab * htab_create(size_t);
|
||||
void htab_destroy(struct htab *);
|
||||
htab_value* htab_find(struct htab *, const char* key);
|
||||
/* same as htab_find, but can retrieve the saved key (for freeing) */
|
||||
htab_value* htab_find2(struct htab *htab, const char* key, char **saved_key);
|
||||
int htab_insert(struct htab *, char*, htab_value);
|
||||
int htab_delete(struct htab *htab, const char* key);
|
||||
size_t htab_next(struct htab *, size_t iterator, char** key, htab_value **v);
|
||||
|
||||
+32
-21
@@ -20,10 +20,9 @@
|
||||
* HTML error pages with variable substitution.
|
||||
*/
|
||||
|
||||
#include <regex.h>
|
||||
#include "common.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "buffer.h"
|
||||
#include "conns.h"
|
||||
#include "heap.h"
|
||||
@@ -31,6 +30,9 @@
|
||||
#include "network.h"
|
||||
#include "utils.h"
|
||||
#include "conf.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
/*
|
||||
* Add an error number -> filename mapping to the errorpages list.
|
||||
@@ -132,30 +134,21 @@ send_html_file (FILE *infile, struct conn_s *connptr)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int send_http_headers (struct conn_s *connptr, int code, const char *message)
|
||||
int send_http_headers (
|
||||
struct conn_s *connptr, int code,
|
||||
const char *message, const char *extra)
|
||||
{
|
||||
const char headers[] =
|
||||
"HTTP/1.0 %d %s\r\n"
|
||||
"HTTP/1.%u %d %s\r\n"
|
||||
"Server: %s/%s\r\n"
|
||||
"Content-Type: text/html\r\n"
|
||||
"%s"
|
||||
"Connection: close\r\n" "\r\n";
|
||||
|
||||
const char p_auth_str[] =
|
||||
"Proxy-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
const char w_auth_str[] =
|
||||
"WWW-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
/* according to rfc7235, the 407 error must be accompanied by
|
||||
a Proxy-Authenticate header field. */
|
||||
const char *add = code == 407 ? p_auth_str : (code == 401 ? w_auth_str : "");
|
||||
|
||||
return (write_message (connptr->client_fd, headers,
|
||||
connptr->protocol.major != 1 ? 0 : connptr->protocol.minor,
|
||||
code, message, PACKAGE, VERSION,
|
||||
add));
|
||||
extra));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -179,12 +172,29 @@ int send_http_error_message (struct conn_s *connptr)
|
||||
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
|
||||
"</html>\n";
|
||||
|
||||
const char p_auth_str[] =
|
||||
"Proxy-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
const char w_auth_str[] =
|
||||
"WWW-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
/* according to rfc7235, the 407 error must be accompanied by
|
||||
a Proxy-Authenticate header field. */
|
||||
const char *add = connptr->error_number == 407 ? p_auth_str :
|
||||
(connptr->error_number == 401 ? w_auth_str : "");
|
||||
|
||||
send_http_headers (connptr, connptr->error_number,
|
||||
connptr->error_string);
|
||||
connptr->error_string, add);
|
||||
|
||||
error_file = get_html_file (connptr->error_number);
|
||||
if (!(infile = fopen (error_file, "r"))) {
|
||||
char *detail = lookup_variable (connptr->error_variables, "detail");
|
||||
if (!error_file || !(infile = fopen (error_file, "r"))) {
|
||||
char *detail;
|
||||
if (error_file) log_message (LOG_ERR,
|
||||
"Error opening error file '%s' (%s)",
|
||||
error_file, strerror (errno));
|
||||
detail = lookup_variable (connptr->error_variables, "detail");
|
||||
return (write_message (connptr->client_fd, fallback_error,
|
||||
connptr->error_number,
|
||||
connptr->error_string,
|
||||
@@ -243,6 +253,7 @@ int add_standard_vars (struct conn_s *connptr)
|
||||
char errnobuf[16];
|
||||
char timebuf[30];
|
||||
time_t global_time;
|
||||
struct tm tm_buf;
|
||||
|
||||
snprintf (errnobuf, sizeof errnobuf, "%d", connptr->error_number);
|
||||
ADD_VAR_RET ("errno", errnobuf);
|
||||
@@ -258,7 +269,7 @@ int add_standard_vars (struct conn_s *connptr)
|
||||
|
||||
global_time = time (NULL);
|
||||
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
|
||||
gmtime (&global_time));
|
||||
gmtime_r (&global_time, &tm_buf));
|
||||
add_error_variable (connptr, "date", timebuf);
|
||||
|
||||
add_error_variable (connptr, "website",
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ extern int add_error_variable (struct conn_s *connptr, const char *key,
|
||||
const char *val);
|
||||
extern int send_html_file (FILE * infile, struct conn_s *connptr);
|
||||
extern int send_http_headers (struct conn_s *connptr, int code,
|
||||
const char *message);
|
||||
const char *message, const char *extra);
|
||||
extern int add_standard_vars (struct conn_s *connptr);
|
||||
|
||||
#endif /* !TINYPROXY_HTML_ERROR_H */
|
||||
+3
-2
@@ -232,6 +232,7 @@ int http_message_send (http_message_t msg, int fd)
|
||||
char timebuf[30];
|
||||
time_t global_time;
|
||||
unsigned int i;
|
||||
struct tm tm_buf;
|
||||
|
||||
assert (is_http_message_valid (msg));
|
||||
|
||||
@@ -254,11 +255,11 @@ int http_message_send (http_message_t msg, int fd)
|
||||
/* Output the date */
|
||||
global_time = time (NULL);
|
||||
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
|
||||
gmtime (&global_time));
|
||||
gmtime_r (&global_time, &tm_buf));
|
||||
write_message (fd, "Date: %s\r\n", timebuf);
|
||||
|
||||
/* Output the content-length */
|
||||
write_message (fd, "Content-length: %u\r\n", msg->body.length);
|
||||
write_message (fd, "Content-length: %lu\r\n", (unsigned long) msg->body.length);
|
||||
|
||||
/* Write the separator between the headers and body */
|
||||
safe_write (fd, "\r\n", 2);
|
||||
|
||||
@@ -109,6 +109,7 @@ void log_message (int level, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
struct timespec nowtime;
|
||||
struct tm tm_buf;
|
||||
|
||||
char time_string[TIME_LENGTH];
|
||||
char str[STRING_LENGTH];
|
||||
@@ -177,11 +178,11 @@ void log_message (int level, const char *fmt, ...)
|
||||
clock_gettime(CLOCK_REALTIME, &nowtime);
|
||||
/* Format is month day hour:minute:second (24 time) */
|
||||
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
||||
localtime (&nowtime.tv_sec));
|
||||
localtime_r (&nowtime.tv_sec, &tm_buf));
|
||||
|
||||
snprintf (str, STRING_LENGTH, "%-9s %s.%03u [%ld]: ",
|
||||
snprintf (str, STRING_LENGTH, "%-9s %s.%03lu [%ld]: ",
|
||||
syslog_level[level], time_string,
|
||||
nowtime.tv_nsec/1000000u,
|
||||
(unsigned long) nowtime.tv_nsec/1000000ul,
|
||||
(long int) getpid ());
|
||||
|
||||
/*
|
||||
|
||||
+9
-8
@@ -254,7 +254,7 @@ change_user (const char *program)
|
||||
*/
|
||||
int reload_config (int reload_logging)
|
||||
{
|
||||
int ret;
|
||||
int ret, ret2;
|
||||
struct config_s *c_next = get_next_config();
|
||||
|
||||
log_message (LOG_NOTICE, "Reloading config file");
|
||||
@@ -263,18 +263,19 @@ int reload_config (int reload_logging)
|
||||
|
||||
ret = reload_config_file (config_file, c_next);
|
||||
|
||||
if (ret != 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
if(config) free_config (config);
|
||||
config = c_next;
|
||||
}
|
||||
|
||||
if (reload_logging) ret = setup_logging ();
|
||||
ret2 = reload_logging ? setup_logging () : 0;
|
||||
|
||||
if (ret != 0)
|
||||
log_message (LOG_WARNING, "Reloading config file failed!");
|
||||
else
|
||||
log_message (LOG_NOTICE, "Reloading config file finished");
|
||||
|
||||
done:
|
||||
return ret;
|
||||
return ret ? ret : ret2;
|
||||
}
|
||||
|
||||
static void setup_sig(int sig, signal_func *sigh,
|
||||
|
||||
+7
-2
@@ -81,14 +81,19 @@ char* orderedmap_find(struct orderedmap *o, const char *key) {
|
||||
int orderedmap_remove(struct orderedmap *o, const char *key) {
|
||||
size_t i;
|
||||
char *lk;
|
||||
htab_value *lv, *v = htab_find(o->map, key);
|
||||
char *sk;
|
||||
char **sv;
|
||||
htab_value *lv, *v = htab_find2(o->map, key, &sk);
|
||||
if(!v) return 0;
|
||||
htab_delete(o->map, key);
|
||||
sv = sblist_get(o->values, v->n);
|
||||
free(*sv);
|
||||
sblist_delete(o->values, v->n);
|
||||
i = 0;
|
||||
while((i = htab_next(o->map, i, &lk, &lv))) {
|
||||
if(lv->n > v->n) lv->n--;
|
||||
}
|
||||
htab_delete(o->map, key);
|
||||
free(sk);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+92
-42
@@ -268,28 +268,34 @@ establish_http_connection (struct conn_s *connptr, struct request_s *request)
|
||||
/* host is an IPv6 address literal, so surround it with
|
||||
* [] */
|
||||
return write_message (connptr->server_fd,
|
||||
"%s %s HTTP/1.0\r\n"
|
||||
"%s %s HTTP/1.%u\r\n"
|
||||
"Host: [%s]%s\r\n"
|
||||
"Connection: close\r\n",
|
||||
request->method, request->path,
|
||||
connptr->protocol.major != 1 ? 0 :
|
||||
connptr->protocol.minor,
|
||||
request->host, portbuff);
|
||||
} else if (connptr->upstream_proxy &&
|
||||
connptr->upstream_proxy->type == PT_HTTP &&
|
||||
connptr->upstream_proxy->ua.authstr) {
|
||||
return write_message (connptr->server_fd,
|
||||
"%s %s HTTP/1.0\r\n"
|
||||
"%s %s HTTP/1.%u\r\n"
|
||||
"Host: %s%s\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Proxy-Authorization: Basic %s\r\n",
|
||||
request->method, request->path,
|
||||
connptr->protocol.major != 1 ? 0 :
|
||||
connptr->protocol.minor,
|
||||
request->host, portbuff,
|
||||
connptr->upstream_proxy->ua.authstr);
|
||||
} else {
|
||||
return write_message (connptr->server_fd,
|
||||
"%s %s HTTP/1.0\r\n"
|
||||
"%s %s HTTP/1.%u\r\n"
|
||||
"Host: %s%s\r\n"
|
||||
"Connection: close\r\n",
|
||||
request->method, request->path,
|
||||
connptr->protocol.major != 1 ? 0 :
|
||||
connptr->protocol.minor,
|
||||
request->host, portbuff);
|
||||
}
|
||||
}
|
||||
@@ -383,10 +389,17 @@ BAD_REQUEST_ERROR:
|
||||
* we'll be closing anyway.
|
||||
*/
|
||||
char *reverse_url;
|
||||
int reverse_status;
|
||||
|
||||
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
|
||||
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url, &reverse_status);
|
||||
|
||||
if (reverse_url != NULL) {
|
||||
if (reverse_status == 301) {
|
||||
char buf[PATH_MAX];
|
||||
snprintf (buf, sizeof buf, "Location: %s\r\n", reverse_url);
|
||||
send_http_headers (connptr, 301, "Moved Permanently", buf);
|
||||
goto fail;
|
||||
}
|
||||
safefree (url);
|
||||
url = reverse_url;
|
||||
} else if (config->reverseonly) {
|
||||
@@ -458,22 +471,16 @@ BAD_REQUEST_ERROR:
|
||||
* Filter restricted domains/urls
|
||||
*/
|
||||
if (config->filter) {
|
||||
if (config->filter_url)
|
||||
ret = filter_run (url);
|
||||
else
|
||||
ret = filter_run (request->host);
|
||||
int fu = config->filter_opts & FILTER_OPT_URL;
|
||||
ret = filter_run (fu ? url : request->host);
|
||||
|
||||
if (ret) {
|
||||
update_stats (STAT_DENIED);
|
||||
|
||||
if (config->filter_url)
|
||||
log_message (LOG_NOTICE,
|
||||
"Proxying refused on filtered url \"%s\"",
|
||||
url);
|
||||
else
|
||||
log_message (LOG_NOTICE,
|
||||
"Proxying refused on filtered domain \"%s\"",
|
||||
request->host);
|
||||
"Proxying refused on filtered %s \"%s\"",
|
||||
fu ? "url" : "domain",
|
||||
fu ? url : request->host);
|
||||
|
||||
indicate_http_error (connptr, 403, "Filtered",
|
||||
"detail",
|
||||
@@ -510,7 +517,7 @@ fail:
|
||||
* server headers can be processed.
|
||||
* - rjkaes
|
||||
*/
|
||||
static int pull_client_data (struct conn_s *connptr, long int length)
|
||||
static int pull_client_data (struct conn_s *connptr, long int length, int iehack)
|
||||
{
|
||||
char *buffer;
|
||||
ssize_t len;
|
||||
@@ -535,6 +542,7 @@ static int pull_client_data (struct conn_s *connptr, long int length)
|
||||
length -= len;
|
||||
} while (length > 0);
|
||||
|
||||
if (iehack) {
|
||||
/*
|
||||
* BUG FIX: Internet Explorer will leave two bytes (carriage
|
||||
* return and line feed) at the end of a POST message. These
|
||||
@@ -569,6 +577,41 @@ static int pull_client_data (struct conn_s *connptr, long int length)
|
||||
"Could not read two bytes from POST message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
safefree (buffer);
|
||||
return 0;
|
||||
|
||||
ERROR_EXIT:
|
||||
safefree (buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* pull chunked client data */
|
||||
static int pull_client_data_chunked (struct conn_s *connptr) {
|
||||
char *buffer = 0;
|
||||
ssize_t len;
|
||||
long chunklen;
|
||||
|
||||
while(1) {
|
||||
if (buffer) safefree(buffer);
|
||||
len = readline (connptr->client_fd, &buffer);
|
||||
|
||||
if (len <= 0)
|
||||
goto ERROR_EXIT;
|
||||
|
||||
if (!connptr->error_variables) {
|
||||
if (safe_write (connptr->server_fd, buffer, len) < 0)
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
chunklen = strtol (buffer, (char**)0, 16);
|
||||
|
||||
if (pull_client_data (connptr, chunklen+2, 0) < 0)
|
||||
goto ERROR_EXIT;
|
||||
|
||||
if(!chunklen) break;
|
||||
}
|
||||
|
||||
safefree (buffer);
|
||||
return 0;
|
||||
@@ -774,7 +817,7 @@ static int remove_connection_headers (orderedmap hashofheaders)
|
||||
|
||||
/*
|
||||
* If there is a Content-Length header, then return the value; otherwise, return
|
||||
* a negative number.
|
||||
* -1.
|
||||
*/
|
||||
static long get_content_length (orderedmap hashofheaders)
|
||||
{
|
||||
@@ -789,6 +832,13 @@ static long get_content_length (orderedmap hashofheaders)
|
||||
return content_length;
|
||||
}
|
||||
|
||||
static int is_chunked_transfer (orderedmap hashofheaders)
|
||||
{
|
||||
char *data;
|
||||
data = orderedmap_find (hashofheaders, "transfer-encoding");
|
||||
return data ? !strcmp (data, "chunked") : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Search for Via header in a hash of headers and either write a new Via
|
||||
* header, or append our information to the end of an existing Via header.
|
||||
@@ -883,6 +933,10 @@ process_client_headers (struct conn_s *connptr, orderedmap hashofheaders)
|
||||
*/
|
||||
connptr->content_length.client = get_content_length (hashofheaders);
|
||||
|
||||
/* Check whether client sends chunked data. */
|
||||
if (connptr->content_length.client == -1 && is_chunked_transfer (hashofheaders))
|
||||
connptr->content_length.client = -2;
|
||||
|
||||
/*
|
||||
* See if there is a "Connection" header. If so, we need to do a bit
|
||||
* of processing. :)
|
||||
@@ -947,8 +1001,9 @@ process_client_headers (struct conn_s *connptr, orderedmap hashofheaders)
|
||||
PULL_CLIENT_DATA:
|
||||
if (connptr->content_length.client > 0) {
|
||||
ret = pull_client_data (connptr,
|
||||
connptr->content_length.client);
|
||||
}
|
||||
connptr->content_length.client, 1);
|
||||
} else if (connptr->content_length.client == -2)
|
||||
ret = pull_client_data_chunked (connptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1231,7 +1286,6 @@ connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
|
||||
unsigned short port;
|
||||
size_t ulen, passlen;
|
||||
|
||||
struct hostent *host;
|
||||
struct upstream *cur_upstream = connptr->upstream_proxy;
|
||||
|
||||
ulen = cur_upstream->ua.user ? strlen(cur_upstream->ua.user) : 0;
|
||||
@@ -1248,10 +1302,13 @@ connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
|
||||
buff[1] = 1; /* connect command */
|
||||
port = htons(request->port);
|
||||
memcpy(&buff[2], &port, 2); /* dest port */
|
||||
host = gethostbyname(request->host);
|
||||
memcpy(&buff[4], host->h_addr_list[0], 4); /* dest ip */
|
||||
buff[8] = 0; /* user */
|
||||
if (9 != safe_write(connptr->server_fd, buff, 9))
|
||||
memcpy(&buff[4], "\0\0\0\1" /* socks4a fake ip */
|
||||
"\0" /* user */, 5);
|
||||
len = strlen(request->host);
|
||||
if(len>255)
|
||||
return -1;
|
||||
memcpy(&buff[9], request->host, len+1);
|
||||
if (9+len+1 != safe_write(connptr->server_fd, buff, 9+len+1))
|
||||
return -1;
|
||||
if (8 != safe_read(connptr->server_fd, buff, 8))
|
||||
return -1;
|
||||
@@ -1361,7 +1418,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
|
||||
log_message (LOG_WARNING,
|
||||
"No upstream proxy defined for %s.",
|
||||
request->host);
|
||||
indicate_http_error (connptr, 404,
|
||||
indicate_http_error (connptr, 502,
|
||||
"Unable to connect to upstream proxy.");
|
||||
return -1;
|
||||
}
|
||||
@@ -1373,7 +1430,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
|
||||
if (connptr->server_fd < 0) {
|
||||
log_message (LOG_WARNING,
|
||||
"Could not connect to upstream proxy.");
|
||||
indicate_http_error (connptr, 404,
|
||||
indicate_http_error (connptr, 502,
|
||||
"Unable to connect to upstream proxy",
|
||||
"detail",
|
||||
"A network error occurred while trying to "
|
||||
@@ -1449,13 +1506,13 @@ get_request_entity(struct conn_s *connptr)
|
||||
nread = read_buffer (connptr->client_fd, connptr->cbuffer);
|
||||
if (nread < 0) {
|
||||
log_message (LOG_ERR,
|
||||
"Error reading readable client_fd %d",
|
||||
connptr->client_fd);
|
||||
"Error reading readable client_fd %d (%s)",
|
||||
connptr->client_fd, strerror(errno));
|
||||
ret = -1;
|
||||
} else {
|
||||
log_message (LOG_INFO,
|
||||
"Read request entity of %d bytes",
|
||||
nread);
|
||||
"Read request entity of %ld bytes",
|
||||
(long) nread);
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
@@ -1502,6 +1559,9 @@ static void handle_connection_failure(struct conn_s *connptr, int got_headers)
|
||||
* when we start the relay portion. This makes most of the original
|
||||
* tinyproxy code, which was confusing, redundant. Hail progress.
|
||||
* - rjkaes
|
||||
|
||||
* this function is called directly from child_thread() with the newly
|
||||
* received fd from accept().
|
||||
*/
|
||||
void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
||||
{
|
||||
@@ -1513,7 +1573,6 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
||||
int got_headers = 0, fd = connptr->client_fd;
|
||||
size_t i;
|
||||
struct request_s *request = NULL;
|
||||
struct timeval tv;
|
||||
orderedmap hashofheaders = NULL;
|
||||
|
||||
char sock_ipaddr[IP_LENGTH];
|
||||
@@ -1535,12 +1594,7 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
||||
return;
|
||||
}
|
||||
|
||||
tv.tv_usec = 0;
|
||||
tv.tv_sec = config->idletimeout;
|
||||
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*) &tv, sizeof(tv));
|
||||
tv.tv_usec = 0;
|
||||
tv.tv_sec = config->idletimeout;
|
||||
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*) &tv, sizeof(tv));
|
||||
set_socket_timeout(fd);
|
||||
|
||||
if (connection_loops (addr)) {
|
||||
log_message (LOG_CONN,
|
||||
@@ -1568,11 +1622,7 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
||||
|
||||
if (read_request_line (connptr) < 0) {
|
||||
update_stats (STAT_BADCONN);
|
||||
indicate_http_error (connptr, 408, "Timeout",
|
||||
"detail",
|
||||
"Server timeout waiting for the HTTP request "
|
||||
"from the client.", NULL);
|
||||
HC_FAIL();
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+32
-9
@@ -34,6 +34,7 @@ void reversepath_add (const char *path, const char *url,
|
||||
struct reversepath **reversepath_list)
|
||||
{
|
||||
struct reversepath *reverse;
|
||||
size_t l;
|
||||
|
||||
if (url == NULL) {
|
||||
log_message (LOG_WARNING,
|
||||
@@ -65,8 +66,17 @@ void reversepath_add (const char *path, const char *url,
|
||||
|
||||
if (!path)
|
||||
reverse->path = safestrdup ("/");
|
||||
else
|
||||
else {
|
||||
l = strlen (path);
|
||||
if (l && path[l-1] == '/')
|
||||
reverse->path = safestrdup (path);
|
||||
else {
|
||||
reverse->path = safemalloc (l + 2);
|
||||
memcpy (reverse->path, path, l);
|
||||
reverse->path[l] = '/';
|
||||
reverse->path[l+1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
reverse->url = safestrdup (url);
|
||||
|
||||
@@ -83,10 +93,16 @@ void reversepath_add (const char *path, const char *url,
|
||||
*/
|
||||
struct reversepath *reversepath_get (char *url, struct reversepath *reverse)
|
||||
{
|
||||
size_t l, lu, lp;
|
||||
while (reverse) {
|
||||
if (strstr (url, reverse->path) == url)
|
||||
lu = strlen (url);
|
||||
lp = strlen (reverse->path);
|
||||
if ((
|
||||
(l = lu) == lp-1 ||
|
||||
(l = lp) <= lu
|
||||
) &&
|
||||
!memcmp(url, reverse->path, l))
|
||||
return reverse;
|
||||
|
||||
reverse = reverse->next;
|
||||
}
|
||||
|
||||
@@ -112,23 +128,30 @@ void free_reversepath_list (struct reversepath *reverse)
|
||||
* Rewrite the URL for reverse proxying.
|
||||
*/
|
||||
char *reverse_rewrite_url (struct conn_s *connptr, orderedmap hashofheaders,
|
||||
char *url)
|
||||
char *url, int *status)
|
||||
{
|
||||
char *rewrite_url = NULL;
|
||||
char *cookie = NULL;
|
||||
char *cookieval;
|
||||
struct reversepath *reverse = NULL;
|
||||
|
||||
*status = 0;
|
||||
|
||||
/* Reverse requests always start with a slash */
|
||||
if (*url == '/') {
|
||||
/* First try locating the reverse mapping by request url */
|
||||
reverse = reversepath_get (url, config->reversepath_list);
|
||||
if (reverse) {
|
||||
rewrite_url = (char *)
|
||||
safemalloc (strlen (url) + strlen (reverse->url) +
|
||||
1);
|
||||
strcpy (rewrite_url, reverse->url);
|
||||
strcat (rewrite_url, url + strlen (reverse->path));
|
||||
size_t lu = strlen (url);
|
||||
size_t lrp = strlen (reverse->path);
|
||||
if (lrp > lu) {
|
||||
rewrite_url = safestrdup (reverse->path);
|
||||
*status = 301;
|
||||
} else {
|
||||
rewrite_url = safemalloc (
|
||||
strlen (reverse->url) + lu + 1);
|
||||
sprintf (rewrite_url, "%s%s", reverse->url, url + lrp);
|
||||
}
|
||||
} else if (config->reversemagic
|
||||
&& (cookie = orderedmap_find (hashofheaders,
|
||||
"cookie"))) {
|
||||
|
||||
+2
-1
@@ -38,6 +38,7 @@ extern struct reversepath *reversepath_get (char *url,
|
||||
struct reversepath *reverse);
|
||||
void free_reversepath_list (struct reversepath *reverse);
|
||||
extern char *reverse_rewrite_url (struct conn_s *connptr,
|
||||
orderedmap hashofheaders, char *url);
|
||||
orderedmap hashofheaders, char *url,
|
||||
int *status);
|
||||
|
||||
#endif
|
||||
+46
-3
@@ -34,6 +34,7 @@
|
||||
#include "text.h"
|
||||
#include "conf.h"
|
||||
#include "loop.h"
|
||||
#include "sblist.h"
|
||||
|
||||
/*
|
||||
* Return a human readable error for getaddrinfo() and getnameinfo().
|
||||
@@ -46,6 +47,16 @@ static const char * get_gai_error (int n)
|
||||
return gai_strerror (n);
|
||||
}
|
||||
|
||||
static const char * family_string (int af)
|
||||
{
|
||||
switch(af) {
|
||||
case AF_UNSPEC: return "AF_UNSPEC";
|
||||
case AF_INET: return "AF_INET";
|
||||
case AF_INET6: return "AF_INET6";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/*
|
||||
* Bind the given socket to the supplied address. The socket is
|
||||
* returned if the bind succeeded. Otherwise, -1 is returned
|
||||
@@ -68,7 +79,7 @@ bind_socket (int sockfd, const char *addr, int family)
|
||||
n = getaddrinfo (addr, NULL, &hints, &res);
|
||||
if (n != 0) {
|
||||
log_message (LOG_INFO,
|
||||
"bind_socket: getaddrinfo failed for %s: ", addr, get_gai_error (n));
|
||||
"bind_socket: getaddrinfo failed for %s: %s (af: %s)", addr, get_gai_error (n), family_string(family));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -87,6 +98,36 @@ bind_socket (int sockfd, const char *addr, int family)
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try binding the given socket to supplied addresses, stopping when one succeeds.
|
||||
*/
|
||||
static int
|
||||
bind_socket_list (int sockfd, sblist *addresses, int family)
|
||||
{
|
||||
size_t nb_addresses = sblist_getsize(addresses);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nb_addresses; i++) {
|
||||
const char *address = *(const char **)sblist_get(addresses, i);
|
||||
if (bind_socket(sockfd, address, family) >= 0) {
|
||||
log_message(LOG_INFO, "Bound to %s", address);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void set_socket_timeout(int fd) {
|
||||
struct timeval tv;
|
||||
tv.tv_usec = 0;
|
||||
tv.tv_sec = config->idletimeout;
|
||||
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*) &tv, sizeof(tv));
|
||||
tv.tv_usec = 0;
|
||||
tv.tv_sec = config->idletimeout;
|
||||
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*) &tv, sizeof(tv));
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a connection to a remote host. It's been re-written to use
|
||||
* the getaddrinfo() library function, which allows for a protocol
|
||||
@@ -134,14 +175,16 @@ int opensock (const char *host, int port, const char *bind_to)
|
||||
close (sockfd);
|
||||
continue; /* can't bind, so try again */
|
||||
}
|
||||
} else if (config->bind_address) {
|
||||
if (bind_socket (sockfd, config->bind_address,
|
||||
} else if (config->bind_addrs) {
|
||||
if (bind_socket_list (sockfd, config->bind_addrs,
|
||||
res->ai_family) < 0) {
|
||||
close (sockfd);
|
||||
continue; /* can't bind, so try again */
|
||||
}
|
||||
}
|
||||
|
||||
set_socket_timeout(sockfd);
|
||||
|
||||
if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0) {
|
||||
union sockaddr_union *p = (void*) res->ai_addr, u;
|
||||
int af = res->ai_addr->sa_family;
|
||||
|
||||
@@ -56,6 +56,8 @@ extern int listen_sock (const char *addr, uint16_t port, sblist* listen_fds);
|
||||
extern int socket_nonblocking (int sock);
|
||||
extern int socket_blocking (int sock);
|
||||
|
||||
extern void set_socket_timeout(int fd);
|
||||
|
||||
extern int getsock_ip (int fd, char *ipaddr);
|
||||
extern void getpeer_information (union sockaddr_union *addr, char *ipaddr, size_t ipaddr_len);
|
||||
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ err_minus_one:
|
||||
add_error_variable (connptr, "deniedconns", denied);
|
||||
add_error_variable (connptr, "refusedconns", refused);
|
||||
add_standard_vars (connptr);
|
||||
send_http_headers (connptr, 200, "Statistic requested");
|
||||
send_http_headers (connptr, 200, "Statistic requested", "");
|
||||
send_html_file (statfile, connptr);
|
||||
fclose (statfile);
|
||||
pthread_mutex_unlock(&stats_file_lock);
|
||||
|
||||
+18
-58
@@ -60,11 +60,10 @@ const char* upstream_build_error_string(enum upstream_build_error ube) {
|
||||
/**
|
||||
* Construct an upstream struct from input data.
|
||||
*/
|
||||
static struct upstream *upstream_build (const char *host, int port, const char *domain,
|
||||
static struct upstream *upstream_build (const char *host, int port, char *domain,
|
||||
const char *user, const char *pass,
|
||||
proxy_type type, enum upstream_build_error *ube)
|
||||
{
|
||||
char *ptr;
|
||||
struct upstream *up;
|
||||
|
||||
*ube = UBE_SUCCESS;
|
||||
@@ -75,8 +74,8 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
||||
}
|
||||
|
||||
up->type = type;
|
||||
up->host = up->domain = up->ua.user = up->pass = NULL;
|
||||
up->ip = up->mask = 0;
|
||||
up->target.type = HST_NONE;
|
||||
up->host = up->ua.user = up->pass = NULL;
|
||||
if (user) {
|
||||
if (type == PT_HTTP) {
|
||||
char b[BASE64ENC_BYTES((256+2)-1) + 1];
|
||||
@@ -121,31 +120,11 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
||||
up->port = port;
|
||||
}
|
||||
|
||||
ptr = strchr (domain, '/');
|
||||
if (ptr) {
|
||||
struct in_addr addrstruct;
|
||||
|
||||
*ptr = '\0';
|
||||
if (inet_aton (domain, &addrstruct) != 0) {
|
||||
up->ip = ntohl (addrstruct.s_addr);
|
||||
*ptr++ = '/';
|
||||
|
||||
if (strchr (ptr, '.')) {
|
||||
if (inet_aton (ptr, &addrstruct) != 0)
|
||||
up->mask =
|
||||
ntohl (addrstruct.s_addr);
|
||||
} else {
|
||||
up->mask =
|
||||
~((1 << (32 - atoi (ptr))) - 1);
|
||||
}
|
||||
up->ip = up->ip & up->mask;
|
||||
} else {
|
||||
if (hostspec_parse(domain, &up->target)
|
||||
|| up->target.type == HST_NONE) {
|
||||
*ube = UBE_NETMASK;
|
||||
goto fail;
|
||||
}
|
||||
} else {
|
||||
up->domain = safestrdup (domain);
|
||||
}
|
||||
|
||||
if (type == PT_NONE)
|
||||
log_message (LOG_INFO, "Added upstream none for %s", domain);
|
||||
@@ -160,7 +139,8 @@ fail:
|
||||
safefree (up->ua.user);
|
||||
safefree (up->pass);
|
||||
safefree (up->host);
|
||||
safefree (up->domain);
|
||||
if(up->target.type == HST_STRING)
|
||||
safefree (up->target.address.string);
|
||||
safefree (up);
|
||||
|
||||
return NULL;
|
||||
@@ -170,7 +150,7 @@ fail:
|
||||
* Add an entry to the upstream list
|
||||
*/
|
||||
enum upstream_build_error upstream_add (
|
||||
const char *host, int port, const char *domain,
|
||||
const char *host, int port, char *domain,
|
||||
const char *user, const char *pass,
|
||||
proxy_type type, struct upstream **upstream_list)
|
||||
{
|
||||
@@ -182,11 +162,11 @@ enum upstream_build_error upstream_add (
|
||||
return ube;
|
||||
}
|
||||
|
||||
if (!up->domain && !up->ip) { /* always add default to end */
|
||||
if (up->target.type == HST_NONE) { /* always add default to end */
|
||||
struct upstream *tmp = *upstream_list;
|
||||
|
||||
while (tmp) {
|
||||
if (!tmp->domain && !tmp->ip) {
|
||||
if (tmp->target.type == HST_NONE) {
|
||||
log_message (LOG_WARNING,
|
||||
"Duplicate default upstream");
|
||||
goto upstream_cleanup;
|
||||
@@ -209,7 +189,8 @@ enum upstream_build_error upstream_add (
|
||||
|
||||
upstream_cleanup:
|
||||
safefree (up->host);
|
||||
safefree (up->domain);
|
||||
if(up->target.type == HST_STRING)
|
||||
safefree (up->target.address.string);
|
||||
safefree (up);
|
||||
|
||||
return ube;
|
||||
@@ -220,34 +201,12 @@ upstream_cleanup:
|
||||
*/
|
||||
struct upstream *upstream_get (char *host, struct upstream *up)
|
||||
{
|
||||
in_addr_t my_ip = INADDR_NONE;
|
||||
|
||||
while (up) {
|
||||
if (up->domain) {
|
||||
if (strcasecmp (host, up->domain) == 0)
|
||||
break; /* exact match */
|
||||
|
||||
if (up->domain[0] == '.') {
|
||||
char *dot = strchr (host, '.');
|
||||
|
||||
if (!dot && !up->domain[1])
|
||||
break; /* local host matches "." */
|
||||
|
||||
while (dot && strcasecmp (dot, up->domain))
|
||||
dot = strchr (dot + 1, '.');
|
||||
|
||||
if (dot)
|
||||
break; /* subdomain match */
|
||||
}
|
||||
} else if (up->ip) {
|
||||
if (my_ip == INADDR_NONE)
|
||||
my_ip = ntohl (inet_addr (host));
|
||||
|
||||
if ((my_ip & up->mask) == up->ip)
|
||||
if (up->target.type == HST_NONE)
|
||||
break;
|
||||
|
||||
if (hostspec_match(host, &up->target))
|
||||
break;
|
||||
} else {
|
||||
break; /* No domain or IP, default upstream */
|
||||
}
|
||||
|
||||
up = up->next;
|
||||
}
|
||||
@@ -269,7 +228,8 @@ void free_upstream_list (struct upstream *up)
|
||||
while (up) {
|
||||
struct upstream *tmp = up;
|
||||
up = up->next;
|
||||
safefree (tmp->domain);
|
||||
if(tmp->target.type == HST_STRING)
|
||||
safefree (tmp->target.address.string);
|
||||
safefree (tmp->host);
|
||||
safefree (tmp);
|
||||
}
|
||||
|
||||
+3
-3
@@ -26,6 +26,7 @@
|
||||
#define _TINYPROXY_UPSTREAM_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "hostspec.h"
|
||||
|
||||
enum upstream_build_error {
|
||||
UBE_SUCCESS = 0,
|
||||
@@ -50,7 +51,6 @@ typedef enum proxy_type {
|
||||
|
||||
struct upstream {
|
||||
struct upstream *next;
|
||||
char *domain; /* optional */
|
||||
char *host;
|
||||
union {
|
||||
char *user;
|
||||
@@ -58,14 +58,14 @@ struct upstream {
|
||||
} ua;
|
||||
char *pass;
|
||||
int port;
|
||||
in_addr_t ip, mask;
|
||||
struct hostspec target;
|
||||
proxy_type type;
|
||||
};
|
||||
|
||||
#ifdef UPSTREAM_SUPPORT
|
||||
const char *proxy_type_name(proxy_type type);
|
||||
extern enum upstream_build_error upstream_add (
|
||||
const char *host, int port, const char *domain,
|
||||
const char *host, int port, char *domain,
|
||||
const char *user, const char *pass,
|
||||
proxy_type type, struct upstream **upstream_list);
|
||||
extern struct upstream *upstream_get (char *host, struct upstream *up);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
SCRIPTS_DIR=$(pwd)/$(dirname $0)
|
||||
SCRIPTS_DIR=$(cd $(dirname $0) && pwd)
|
||||
BASEDIR=$SCRIPTS_DIR/../..
|
||||
TESTS_DIR=$SCRIPTS_DIR/..
|
||||
TESTENV_DIR=$TESTS_DIR/env
|
||||
@@ -83,6 +83,7 @@ DefaultErrorFile "$TINYPROXY_DATA_DIR/debug.html"
|
||||
ErrorFile 400 "$TINYPROXY_DATA_DIR/debug.html"
|
||||
ErrorFile 403 "$TINYPROXY_DATA_DIR/debug.html"
|
||||
ErrorFile 501 "$TINYPROXY_DATA_DIR/debug.html"
|
||||
ErrorFile 502 "$TINYPROXY_DATA_DIR/debug.html"
|
||||
StatFile "$TINYPROXY_DATA_DIR/stats.html"
|
||||
Logfile "$TINYPROXY_LOG_FILE"
|
||||
PidFile "$TINYPROXY_PID_FILE"
|
||||
@@ -99,6 +100,7 @@ XTinyproxy Yes
|
||||
AddHeader "X-My-Header1" "Powered by Tinyproxy"
|
||||
AddHeader "X-My-Header2" "Powered by Tinyproxy"
|
||||
AddHeader "X-My-Header3" "Powered by Tinyproxy"
|
||||
Upstream http 255.255.255.255:65535 ".invalid"
|
||||
EOF
|
||||
|
||||
cat << 'EOF' > $TINYPROXY_FILTER_FILE
|
||||
@@ -244,6 +246,10 @@ test "x$?" = "x0" || FAILED=$((FAILED + 1))
|
||||
echo -n "requesting connect method to denied port..."
|
||||
run_failure_webclient_request 403 --method=CONNECT "$TINYPROXY_IP:$TINYPROXY_PORT" "localhost:12345"
|
||||
test "x$?" = "x0" || FAILED=$((FAILED + 1))
|
||||
|
||||
echo -n "testing unavailable backend..."
|
||||
run_failure_webclient_request 502 "$TINYPROXY_IP:$TINYPROXY_PORT" "http://bogus.invalid"
|
||||
test "x$?" = "x0" || FAILED=$((FAILED + 1))
|
||||
}
|
||||
|
||||
basic_test
|
||||
|
||||
Reference in new issue
Block a user