Compare commits
22
Commits
rofl0r-patch-1
...
1.11.1
| 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 |
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,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`).
|
||||
+7
-2
@@ -194,20 +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
|
||||
AM_CONDITIONAL(HAVE_GPERF, false)
|
||||
AS_ECHO("no")
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_GPERF, $tmp_gperf)
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
@@ -244,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
|
||||
+74
-48
@@ -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">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{package} version {version} run-time statistics</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<style type="text/css" media="screen">
|
||||
<!--/*--><![CDATA[<!--*/
|
||||
|
||||
th, td
|
||||
{
|
||||
text-align: left;
|
||||
padding: 0.5em;
|
||||
border: 1px solid gray;
|
||||
<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>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>{package} version {version} run-time statistics</h1>
|
||||
|
||||
<div id="container">
|
||||
<div id="inner">
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Value</th>
|
||||
<th colspan="2">{package} v{version} statistics</th>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td class="right">Open connections</td>
|
||||
<td class="center">{opens}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of open connections</td>
|
||||
<td>{opens}</td>
|
||||
<tr class="even">
|
||||
<td class="right">Bad connections</td>
|
||||
<td class="center">{badconns}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of requests</td>
|
||||
<td>{reqs}</td>
|
||||
<tr class="odd">
|
||||
<td class="right">Denied connections</td>
|
||||
<td class="center">{deniedconns}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of bad connections</td>
|
||||
<td>{badconns}</td>
|
||||
<tr class="even">
|
||||
<td class="right">Refused (high load)</td>
|
||||
<td class="center">{refusedconns}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number of denied connections</td>
|
||||
<td>{deniedconns}</td>
|
||||
<tr class="odd">
|
||||
<td class="right">Total requests</td>
|
||||
<td class="center">{reqs}</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>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -267,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:
|
||||
@@ -287,6 +287,20 @@ 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
|
||||
@@ -300,6 +314,7 @@ 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.
|
||||
@@ -308,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>
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
+1
-1
@@ -67,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
|
||||
|
||||
@@ -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,
|
||||
|
||||
+42
-6
@@ -135,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);
|
||||
@@ -234,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 */
|
||||
@@ -707,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;
|
||||
@@ -950,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]);
|
||||
@@ -957,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
|
||||
|
||||
|
||||
+1
-3
@@ -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 */
|
||||
|
||||
+24
-19
@@ -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)
|
||||
{
|
||||
@@ -66,10 +69,8 @@ void filter_init (void)
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -107,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,
|
||||
@@ -115,6 +121,7 @@ void filter_init (void)
|
||||
config->filter, lineno, s);
|
||||
exit (EX_DATAERR);
|
||||
}
|
||||
}
|
||||
if (!sblist_add(fl, &fe)) {
|
||||
oom:;
|
||||
fprintf (stderr,
|
||||
@@ -142,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);
|
||||
}
|
||||
@@ -175,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;
|
||||
@@ -187,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
|
||||
+17
-4
@@ -3,6 +3,15 @@
|
||||
#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.
|
||||
*
|
||||
@@ -13,13 +22,17 @@
|
||||
*/
|
||||
static int
|
||||
fill_netmask_array (char *bitmask_string, int v6,
|
||||
unsigned char array[], size_t len)
|
||||
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 */
|
||||
@@ -35,11 +48,11 @@ fill_netmask_array (char *bitmask_string, int v6,
|
||||
}
|
||||
|
||||
/* check valid range for a bit mask */
|
||||
if (mask > (8 * len))
|
||||
if (mask > (8 * IPV6_LEN))
|
||||
return -1;
|
||||
|
||||
/* we have a valid range to fill in the array */
|
||||
for (i = 0; i != len; ++i) {
|
||||
for (i = 0; i != IPV6_LEN; ++i) {
|
||||
if (mask >= 8) {
|
||||
array[i] = 0xff;
|
||||
mask -= 8;
|
||||
@@ -88,7 +101,7 @@ int hostspec_parse(char *location, struct hostspec *h) {
|
||||
v6 = 0;
|
||||
|
||||
if (fill_netmask_array
|
||||
(mask, v6, &(h->address.ip.mask[0]), IPV6_LEN)
|
||||
(mask, v6, &(h->address.ip.mask[0]))
|
||||
< 0)
|
||||
goto err;
|
||||
|
||||
|
||||
+7
-2
@@ -30,6 +30,7 @@
|
||||
#include "network.h"
|
||||
#include "utils.h"
|
||||
#include "conf.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
@@ -188,8 +189,12 @@ int send_http_error_message (struct conn_s *connptr)
|
||||
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,
|
||||
|
||||
+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,
|
||||
|
||||
+66
-31
@@ -471,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",
|
||||
@@ -523,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;
|
||||
@@ -548,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
|
||||
@@ -582,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;
|
||||
@@ -787,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)
|
||||
{
|
||||
@@ -802,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.
|
||||
@@ -896,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. :)
|
||||
@@ -960,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;
|
||||
}
|
||||
@@ -1376,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;
|
||||
}
|
||||
@@ -1388,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 "
|
||||
@@ -1464,8 +1506,8 @@ 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,
|
||||
@@ -1517,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)
|
||||
{
|
||||
@@ -1528,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];
|
||||
@@ -1550,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,
|
||||
@@ -1583,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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+23
-1
@@ -47,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
|
||||
@@ -69,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: %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;
|
||||
}
|
||||
|
||||
@@ -108,6 +118,16 @@ bind_socket_list (int sockfd, sblist *addresses, int family)
|
||||
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
|
||||
@@ -163,6 +183,8 @@ int opensock (const char *host, int port, const char *bind_to)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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