Compare commits

..
208 Commits
Author SHA1 Message Date
Michael Adam a662c11b8d Release 1.10.0
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam 8333a4bb1a docs: update the copyright notice in the manpages
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam e2a92ea334 Update AUTHORS
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam 4c9289802a scripts: add a script to generate the AUTHORS file from git
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam 3eb3c2c099 Remove xml-based AUTHORS mechanism. AUTHORS is checked in.
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam a5e6d343d7 Remove unused authors.c/authors.h and generation mechanism.
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam 56f30a4386 main: remove the "-l" switch to display the license and authors
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam 89b2c68b2b NEWS: just mention to use git log
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
Michael Adam ec95d8b553 configure: remove unused variables
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-01 04:06:59 +02:00
rofl0r c651664720 fix socks5 upstream user/pass subnegotiation check
RFC 1929 specifies that the user/pass auth subnegotation repurposes the version
field for the version of that specification, which is 1, not 5.
however there's quite a good deal of software out there which got it wrong and
replies with version 5 to a successful authentication, so let's just accept both
forms - other socks5 client programs like curl do the same.

closes #172
2018-05-29 21:59:11 +02:00
rofl0r 0aad2f5b92 fix basicauth string comparison
closes #160
2018-03-29 00:40:18 +01:00
Michael Adam ae0cbfe3f2 html-error: Make a switch fallthrough explicit
This silences a gcc v7 compile warning.

Signed-off-by: Michael Adam <obnox@samba.org>
2018-03-27 09:36:53 +02:00
Michael Adam badb6435d6 upstream: Fix case of empty string domain.
Found by compiler note.

Signed-off-by: Michael Adam <obnox@samba.org>
2018-03-23 01:45:10 +01:00
rofl0r 8d0ea71486 install tinyproxy to bin/, not /sbin
sbin/ is meant for programs only usable by root, but in tinyproxy's
case, regular users can and *should* use tinyproxy; meaning it is
preferable from a security PoV to use tinyproxy as regular user.
2018-03-23 01:44:53 +01:00
rofl0r 09979629c0 make bind option usable with transparent proxy too
closes #15 for real.
the previous patch that was merged[0] was halfbaked and only removed
the warning part of the original patch from openwrt[1], but didn't
actually activate bind support. further it invoked UB by removing
the return value from the function, if transparent proxy support was
compiled in.

[0]: d97d486d53
[1]: https://gitlab.labs.nic.cz/turris/openwrt-packages/commit/7c01da4a72e6f0b7613a86529547659ea4007eba
2018-02-27 20:52:09 +00:00
rofl0r a53f62a212 enable transparent proxy by default
by having all features turned on by default, the binary is only
slightly bigger, but users of binary distros get the whole package
and don't need to compile tinyproxy by hand if they need a feature
that wasn't compiled in.
it also prevents the confusion from getting syntax errors when a
config file using those features is parsed.
another advantage is that by enabling them these features may
actually get some more testing.
2018-02-27 20:13:35 +00:00
rofl0r b8c6a2127d implement user/password auth for socks5 upstream proxy
just like the rest of the socks code, this was stolen from
proxychains-ng, of which i'm happen to be the maintainer of,
so it's not an issue (the licenses are identical, too).
2018-02-27 20:13:07 +00:00
rofl0r e78b461607 update upstream syntax in manpage template 2018-02-25 23:52:23 +00:00
rofl0r 057cf06805 config: unify upstream syntax for http,socks4,socks5 and none
closes #50
2018-02-25 23:52:23 +00:00
rofl0r 9cde492d68 configure.ac: remove -pedantic 2018-02-25 23:52:23 +00:00
rofl0r 39132b9787 rename members of proxy_type enum to have a common prefix
and add a NONE member.
2018-02-25 23:52:23 +00:00
rofl0r 86632a91eb fix early logging
tinyproxy uses a curious mechanism to log those early messages
that result from parsing the config file before the logging mechanism
has been properly set up yet by finishing parsing of the config file:
those early messages are written into a memory buffer and then
are printed later on. this slipped my attention when making it possible
to log to stdout in ccbbb81a.
2018-02-25 18:35:34 +00:00
rofl0r e1c11c47db make send_stored_logs static 2018-02-25 18:35:34 +00:00
rofl0r bf76aeeba1 implement HTTP basic auth for upstream proxies
loosely based on @valenbg1's code from PR #38

closes #38
closes #96
2018-02-25 15:13:45 +00:00
rofl0r 4d9891e59e basicauth.[ch]: refactor to make basicauth_string() reusable 2018-02-25 15:13:45 +00:00
bertliao 81ea4feb2e fix possible memory leak 2018-02-25 14:56:50 +00:00
John Weldon c7c88e9c59 Remove #ifdef for HAVE_SYSLOG_H
- syslog.h is a standard posix header, this #ifdef is an artifact
  accidentally left in.
2018-02-23 05:32:33 +00:00
Michael Adam 9acb0cb16c Fix CVE-2017-11747: Create PID file before dropping privileges.
Resolves #106

Signed-off-by: Michael Adam <obnox@samba.org>
2018-02-09 15:21:14 +01:00
rofl0r af1d7ab510 move base64 code into own file
it will be needed to add support for upstream proxy auth.
2018-02-06 16:57:02 +00:00
rofl0r bd04ed00d8 Basic Auth: send correct response codes and headers acc. to rfc7235
as reported by @natedogith1
2018-02-06 16:57:02 +00:00
rofl0r 8db511b9bf add support for basic HTTP authentication
using the "BasicAuth" keyword in tinyproxy.conf.

base64 code was written by myself and taken from my own library "libulz".
for this purpose it is relicensed under the usual terms of the tinyproxy
license.
2018-02-06 16:57:02 +00:00
rofl0r 1ebfd2a2d1 tinyproxy.conf.in: add example for SOCKS upstream 2018-02-06 16:11:39 +00:00
rofl0r 7a3fd81a8d fix types used in SOCKS4/5 support code
the line

    len = buff[0]; /* max = 255 */

could lead to a negative length if the value in buff[0] is > 127.
2018-02-06 16:11:39 +00:00
Gonzalo Tornaria 8906b0734e add SOCKS upstream proxy support (socks4/socks5)
original patch submitted in 2006 to debian mailing list:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=392848%29#12

this version was rebased to git and updated by Russ Dill <russ.dill@gmail.com>
in 2015 (the original patch used a different config file format).

as discussed in #40.

commit message by @rofl0r.
2018-02-06 16:11:39 +00:00
rofl0r 116e59e933 activate reverse proxy support by default
closes #17
2018-02-06 15:22:22 +00:00
rofl0r 9bb699628f safe_write/read: take void* buffer for generic use
if using one of unsigned or signed char for the function prototype, one
gets nasty warnings when using it with the other type. the only proper
solution is to put void* into the prototype, and then specialize the pointer
inside the function using an automatic variable.
for exactly this reason, libc functions like read(), write(), etc use void*
too.
2017-12-04 11:33:01 +00:00
rofl0r e9e0f0b4f0 configure.ac: remove -Wc++-compat 2017-11-29 19:11:04 +01:00
Brian Cain 08a9fbb041 Add example value for Log Level setting 2017-11-27 18:49:53 +01:00
rofl0r ccbbb81aa9 log to stdout if no logfile specified
some users want to run tinyproxy on an as-needed basis in a terminal,
without setting it up permanently to run as a daemon/service.
in such use case, it is very annoying that tinyproxy didn't have
an option to log to stdout, so the user has to keep a second terminal
open to `tail -f` the log.

additionally, this precluded usage with runit service supervisor,
which runs all services in foreground and creates logfiles from the
service's stdout/stderr.

since logging to stdout doesn't make sense when daemonized, now if
no logfile is specified and daemon mode activated, a warning is
printed to stderr once, and nothing is logged.
the original idea was to fail with an error message, though some users
might actually want to run tinyproxy as daemon and no logging at all.
2017-11-16 19:26:14 +01:00
rofl0r 64b29c5f4e do not create a pidfile, if none is specified in config
some people want to run tinyproxy with minimal configuration from
the command line (and as non-root), but tinyproxy insists on writing
a pid file, which only makes sense for usage as a service, hereby
forcing the user to either run it as root so it can write to the
default location, or start editing the default config file to work
around it.
and if no pidfile is specified in the config, it frankly doesn't
make sense to force creation of one anyway.
2017-11-16 19:26:14 +01:00
Pablo Panero d97d486d53 Issue 15 fix. PR 2017-11-16 01:21:43 +01:00
rofl0r 5062b78740 tinyproxy.conf.in: default to allow CONNECT method more broadly
tinyproxy conservatively defaulted to allow CONNECT method only
on two ports used by SSL in the ancient past, but since HTTPS usage
got much more widespread (actually, it's now the default for the
majority of websites), it makes sense now to allow it without
restriction by default to accomodate for the new situation.
2017-11-16 01:08:08 +01:00
Steven Conaway caf0ff3be8 Update README.md 2017-11-16 01:05:54 +01:00
Michael Adam 86a9a6729e Merge pull request #100 from dmd/patch-1
tinyproxy configure does not actually support enable-static
2017-08-24 22:48:46 +02:00
Daniel M. Drucker d67c48a49b tinyproxy configure does not actually support enable-static
See #90 and #99
2017-07-18 17:56:03 -04:00
Michael Adam cb6f868739 Merge pull request #86 from obnoxxx/getipstring1
honor result of inet_ntop in get_ip_string()
2017-03-30 00:52:43 +02:00
Michael Adam 46cbe5357c network: honour result of inet_ntop in get_ip_string()
Signed-off-by: Michael Adam <obnox@samba.org>
2017-03-29 23:57:08 +02:00
Michael Adam a71cebb094 network: let get_ip_string() return const char * instead of const char
Signed-off-by: Michael Adam <obnox@samba.org>
2017-03-29 23:56:48 +02:00
Michael Adam f149b62475 Merge pull request #66 from rofl0r/configure_trim
Configure trim
2017-03-29 23:26:45 +02:00
Michael Adam 3f6179a1fd Merge pull request #67 from dmz-uk/patch-1
Prevent child from calling exit() on interrupt
2017-03-29 09:19:55 +02:00
Michael Adam 2c574e9afe Merge pull request #85 from rofl0r/fix_72
src/Makefile.am: fix spaces vs TAB
2017-03-29 09:15:22 +02:00
rofl0r aade379acb src/Makefile.am: fix spaces vs TAB
this causes a build failure on several platforms using older versions
of autotools or GNU make.

make[2]: Entering directory `src'
Makefile:670: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.
make[2]: Leaving directory `src'

fixes #72
2017-03-27 18:57:01 +01:00
Michael Adam 1e93411810 Merge pull request #59 from gmp216/pull
Fix OS X build
2017-01-04 16:21:27 +01:00
Greg 1b8a6ef561 configure.ac: add conditional for -z,defs 2017-01-04 09:19:04 -05:00
Greg 802a6aa93f Added conditional for xmllint by testing "a2x" without the -L flag. 2017-01-04 09:18:20 -05:00
Michael Adam 302738dee5 Merge pull request #71 from gmp216/lookup
Move lookup_variable from html-error.c to hashmap.c
2017-01-04 13:59:14 +01:00
dmz-uk f9024c7186 Prevent child from calling exit() on interrupt
A proposed fix for the logrotate SIGHUP issue.
2016-12-30 10:16:19 +00:00
Greg fdb1aae3a9 Move lookup_variable into hashmap.c / hashmap.h 2016-12-27 12:23:51 -05:00
Greg 540069551d Change signature for lookup_variable to take map instead of connptr 2016-12-27 12:18:16 -05:00
Michael Adam e4ae0d10d2 Merge pull request #70 from obnoxxx/compile
add 'compile' to gitignore
2016-12-24 03:09:33 +01:00
Michael Adam 06281857a4 Merge pull request #69 from obnoxxx/readme
README: mention --enable-reverse configure option
2016-12-24 03:07:57 +01:00
Michael Adam 6c98f2cc27 add 'compile' to gitignore
it's generated by autogen

Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-24 03:04:50 +01:00
Michael Adam ff880a5e13 README: mention --enable-reverse configure option
Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-24 03:02:27 +01:00
Michael Adam 67fc3b54ba Merge pull request #68 from obnoxxx/travis
Enable travis-ci: add .travis.yml
2016-12-24 03:01:34 +01:00
Michael Adam 841fed4afd Enable travis-ci: add .travis.yml
Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-24 02:54:26 +01:00
rofl0r c98f1cd25a configure: remove checks for standard types 2016-12-21 21:16:06 +00:00
rofl0r c3cc308cc8 configure: remove checks for standard POSIX funcs
addresses #65
2016-12-21 21:16:06 +00:00
rofl0r 81a93f9e4f configure: do not check for standard POSIX headers
addresses #65
2016-12-21 21:01:37 +00:00
rofl0r 39c92a3f70 configure: do not check for standard C headers
addresses #65
2016-12-21 20:45:06 +00:00
Michael Adam 90df510932 Merge pull request #63 from rofl0r/fix_manpage_gen
ship manpages as part of the dist tarball
2016-12-20 22:27:11 +01:00
rofl0r 909528e29c ship manpages as part of the dist tarball
`make dist` now creates the manpages and puts them into the tarball, so
the user does not need to have `a2x` installed to build them.

closes #2
2016-12-20 21:06:20 +00:00
Michael Adam 4e0951afd9 Merge pull request #62 from obnoxxx/bundle-readme-md
build: add README.md to the bundled files
2016-12-20 19:28:59 +01:00
Michael Adam 2f4e6403f9 build: add README.md to the bundled files
Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-20 19:26:48 +01:00
Michael Adam 1bb255c3f8 Merge pull request #61 from obnoxxx/cleanup-readme
Cleanup readme and fix installation instructions
2016-12-20 19:24:28 +01:00
Michael Adam 85c73d68bd Add placeholder ChangeLog to keep automake happy
Closes #60

Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-20 19:22:17 +01:00
Michael Adam 7f3fe02d47 README: update install instructions
Closes #30

Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-20 19:22:17 +01:00
Michael Adam 271c4ecdcb README: add README pointing to README.md to make automake happy
Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-20 19:22:17 +01:00
Michael Adam 0d3ca13398 README: Rename README --> README.md
Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-20 19:04:56 +01:00
Michael Adam 82ce991b3d REAMDE: convert README to github markdown
Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-20 19:04:47 +01:00
Michael Adam af6e236521 README: cleanup readme from legacy content
Signed-off-by: Michael Adam <obnox@samba.org>
2016-12-20 19:04:43 +01:00
Michael Adam e541456ee7 Merge pull request #36 from obnoxxx/issue-21
build: remove foreign from AM_INIT_AUTOMAKE - generate INSTALL again
2016-09-11 00:16:30 +02:00
Michael Adam 60e5fc7c57 build: remove foreign from AM_INIT_AUTOMAKE - generate INSTALL again
Closes #21

Signed-off-by: Michael Adam <obnox@samba.org>
2016-09-11 00:11:21 +02:00
Stephan Leemburg c5da1cc934 Continue with forward proxy if ReverseOnly is not true and no mapping available (#35)
allow non-reverse mappings if reverseonly is not enabled
2016-09-10 19:22:45 +02:00
John Spencer 186bbc3efb configure.ac: remove check for broken regex which breaks crosscompilation
in the unlikely case that the user's C library has broken regex support,
she should probably update to a bugfree version.
in its full consequence, checking if individual functions works basically
require to test every single function in use, which is nonsensical.
since this check required to compile and run a code sample on the host,
it cannot be checked in cross-compile scenarios and as it defaulted to yes
(broken), causes build failure in any such scenario.

closes #1

Signed-off-by: John Spencer <maillist-tinyproxy@barfooze.de>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-01-19 22:50:20 +01:00
Michael Adam b036d2e055 Merge pull request #6 from rofl0r/url
update URL
2016-01-03 23:58:17 +01:00
rofl0r ee83293285 update URL 2016-01-03 21:16:21 +00:00
Michael Adam 800c3a250c BB#110 Increase number of hash buckets from 32 to 256.
This should make hash processing generally faster.

There is a treadeoff between memory footprint and
speed of processing. 10 KB instead of 1.2 KB of
hash table per process should not be a huge problem
even on very limited current systems.

Who really needs to stick to 32 buckets could
recompile. We could also think about making
this configurable at some point.

Signed-off-by: Michael Adam <obnox@samba.org>
2014-12-13 01:41:56 +01:00
Michael Adam 545463c75d BB#110 limit the number of headers per request to prevent DoS
Based on patch provided by gpernot@praksys.org on bugzilla.

Signed-off-by: Michael Adam <obnox@samba.org>
2014-12-13 01:28:07 +01:00
Michael Adam 308305d827 BB#110 secure the hashmaps by adding a seed
Based on a patch provided by gpernot@praksys.org on bugzilla.

Signed-off-by: Michael Adam <obnox@samba.org>
2014-12-13 01:21:02 +01:00
Peter H. Froehlich ab6255393d BB#110 Replace hash function with Dan Bernstein's.
This hash function distributes much better than the
original one. The effect is not as visible with
hashes taken modulo 32 than with a bigger modulus,
but it is there. And larger number of buckets migh
become possible in the future...

Reviewed-by: Michael Adam <obnox@samba.org>
2014-12-13 01:20:56 +01:00
Mukund Sivaraman 24087f743a Remove suggester (see Banu RT #138) 2014-05-01 13:58:54 +05:30
Michael Adam b59ecd0c66 buffer: fix log message in read_buffer().
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-23 12:21:59 +01:00
Michael Adam ffa3a56ab8 buffer: reduce indentation in read_buffer()
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-23 12:09:59 +01:00
Michael Adam 76bd008cf9 reqs: fix typo in a debug message in get_request_entity()
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-23 11:59:47 +01:00
Michael Adam b3ac7d2c7b transparent: make transparent support compile after introduction of multi Listen
I seem to have forgotten to compile with transparent support enabled...
This belongs to the fix for bug BB#63.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-23 00:18:04 +01:00
Michael Adam b92d70be07 child: remove use of config.listen_addrs in child_listening_sockets()
This was accidentially used instead of the function parameter listen_addrs
This still belongs to the fix for bug BB#63.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-23 00:17:55 +01:00
Michael Adam 3710accf72 reqs: Fix CID 1130969 (part 3) - unchecked return value from library.
Check the return value of socket_blocking (fcntl) at the
end of relay_connection() for client socket.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 21:56:39 +01:00
Michael Adam e07c363df2 reqs: Fix CID 1130969 (part 2) - unchecked return value from library.
Check the return value of socket_blocking (fcntl) at the
end of relay_connection().

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 21:44:12 +01:00
Michael Adam c82840bfcb reqs: Fix CID 1130972 - remove logically dead code.
url == NULL is caught above.

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 18:58:19 +01:00
Michael Adam 49c55ed26c network: Fix CID 113095 - unchecked return value from library
Check return of "recv" in readline().

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 18:54:22 +01:00
Michael Adam 198600ce42 child: check return code of socket_blocking for accept in child_main
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 18:49:45 +01:00
Michael Adam 38ef36d998 child: Fix CID 1130966 - unchecked return value from library
check the return code of fcntl via socket_nonblocking
on the listen sockets in child_main()

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 18:49:45 +01:00
Michael Adam 0a99803425 reqs: Fix CID 1130967 - unchecked return value from library.
Check the return code of fcntl via socket_blocking
in pull_client_data().

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 18:49:45 +01:00
Michael Adam 9efa5799f0 reqs: Fix CID 1130968 - unchecked return value from library
Check the return code of fcntl via socket_nonblocking
in pull_client_data()

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 18:49:45 +01:00
Michael Adam c27b6d15e2 reqs: rename a variable.
ret will be used in enclosing scope.
so rename this special varibale.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 18:49:45 +01:00
Michael Adam 68bd0b61b5 reqs: fix CID 1130969 - unchecked return code from library
Effectively, the return code of fcntl was not checked
by not checking the return code of socket_nonblocking()
for the server fd.

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 17:35:59 +01:00
Michael Adam 2004abc1e3 reqs: fix CID 1130970 - unchecked return code from library
Effectively, the return code of fcntl was not checked
by not checking the return code of socket_nonblocking()
for the client fd.

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 17:35:54 +01:00
Michael Adam a244c1d4aa conf: Fix CID 1130973 - resource leak.
Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-22 16:08:47 +01:00
Michael Adam 0f18e4fc3a BB#106: remove now unused extract_ssl_url.
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 15:26:06 +01:00
Michael Adam 9f43cfd488 BB#106: fix CONNECT requsts with IPv6 literal addresses as host.
Use extract_url instead of the old extract_ssl_url:
extract_url is generic and handles ipv6 literal addresses correctly.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 15:25:44 +01:00
Michael Adam 98f77ef8c7 BB#106: add default_port argument to extract_http_url and rename it to extract_url
There is in fact nothing http-specific any more about this function, hence
the rename. The input has been stripped of the <proto>:// header anyways.

This in preparation of fixing bug BB#106: ssl fails with literal ipv6 addrs.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 15:09:48 +01:00
Michael Adam 69c348ce6d req: move a variable into the scope where it is used in extract_http_url()
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 13:10:03 +01:00
Michael Adam bb2e894e0d BB#116: fix invalid free when connecting to ipv6 literal address
When removing the '[' and ']' characers from the ipv6 literal address, make sure
the pointer that is later free'd stays a malloced pointer by memmoving the
string one place left.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 13:07:19 +01:00
Michael Adam 7e1d8154de build: check for memmove
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 13:07:09 +01:00
Michael Adam 836d4534d6 sock: add debug messages to opensock()
log entering opensock and successful return of getaddrinfo.
This allows to detect dns timeouts from looking at the logs.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 11:30:07 +01:00
Michael Adam e82080a5f6 [BB#63] conf: Allow multiple Listen statements in the config.
This introduces a list (vector) of addresses instead of
having just one address string.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam d0732f9ade [BB#81] allow listening on multiple families when no Listen is provided in config
This is achieved by not stopping at the first result of getaddrinfo
that we managed to listen on: Without "Listen" in the config, we
call getraddrinfo with NULL address. With AI_PASSIVE, this gives results
for both IPv4 and IPv6 wildcard addresses (if both are supported).

This lets tinyproxy listen on both IPv4 and IPv6 wildcard if the system
supports them.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam e40b91974a sock: add a starting debug message to listen_sock()
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 22587d3d41 sock: update introductory comment for listen_sock()
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 0698e4d180 sock: set IPV6_V6ONLY on the socket before binding an IPv6 address
so that we can bind wildcard for both IPv4 and IPv6.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam d7f67768eb sock: factor listening on one socket out of the gai-result-loop in listen_sock()
for clarity of the code

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 157879d4f6 sock: in listen_sock(), move variable for setsockopt() into scope
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam a7898a2c98 sock: log each result of getaddrinfo() in listen_sock()
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 947e255d19 sock: in listen_sock(), add a log message for when bind() has failed
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam b41d140984 sock: in listen_sock(), detect and log failure to call setsockopt()
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 5392e9829c sock: in listen_sock(), add debug message when socket() call failed.
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam fa26ad4d56 sock: move listen() into the getaddrinfo result loop in listen_sock()
This also reverses the exit logic of the loop.
It prepares listening on multiple addresses.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 2ebfd456ef child: use a list of listen_fds instead of one single listenfd.
This prepares listenting on multiple sockets, which will be ussed to
fix listening on the wildcard (listen on both ipv6 and ipv4) and
help add the support for multiple Listen statements in the config

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 070d621534 child: add addr argument to child_listening_sock().
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 2bd919f01e sock: add addr argument to listen_sock()
instead of using config.ipAddr internally.
This is in preparation to make it possible
to call it for multiple addresses.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 7eea1638bc sock/child: remove global variable addrlen.
This changes listen_sock() to not return the
addrlen of the used address from getaddrinfo call
to the caller, stored in global addrlen in child.c.

This was only used to be able to allocate enough space for the
arguments to the later accept call depending on whether
IPv4 or IPv6 is used.

This removes the need to pass this info by always allocating
sizeof(struct sockaddr_storage) instead, which is enough
to carry both sockaddr_in and sockaddr_in6.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam 4bbd6e8626 [BB#109] Fix crash (infinite loop) when writing to log file fails.
Fall back to syslog logging in that case.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Michael Adam d652681e8a log: remove extra newline characters in log messages.
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09 13:34:33 +01:00
Gaudenz Steinlin c8b8247f70 [BB#115] Drop supplementary groups
Supplementary groups are inherited from the calling process. Drop all
supplementary groups if the "Group" configuration directive is set to
change to a different user. Otherwise the process may have more rights
than expected.

Reviewed-by: Michael Adam <obnox@samba.org>
2013-11-01 06:38:53 +01:00
Michael Adam 3cc59ec3be [BB#112] build: fix build with autoconf >= 2.69
Use AC_CONFIG_HEADERS instead of obsolete AM_CONFIG_HEADER.

Signed-off-by: Michael Adam <obnox@samba.org>
2013-04-09 22:35:20 +02:00
Mukund Sivaraman 983d241db6 Update authors 2012-01-23 16:32:35 +05:30
Mukund Sivaraman 2e4ea496b3 build: Prepend to LDFLAGS instead of replacing its contents 2012-01-23 16:25:24 +05:30
Mukund Sivaraman e5fd1fd556 Make .xz compressed dist targets too 2011-09-11 11:52:21 +05:30
Mukund Sivaraman 32563a4ed6 Bug #103: Move files installed in /etc/ to /etc/tinyproxy/ 2011-08-23 14:46:04 +05:30
Mukund Sivaraman ec86c15d5a Minor whitespace fix 2011-08-16 17:44:17 +05:30
Mukund Sivaraman e8426f6662 [BB#90]: Fix bug in ACL netmask generation
Thanks to John Horne who diagnosed this issue and found the problem.
2011-03-04 14:47:05 +05:30
Mukund Sivaraman 97b9984484 Validate port number specified in Port directive
This was asked in bug #90 comment #8.
2011-03-04 14:07:07 +05:30
Mukund Sivaraman 5ad24ba99d Update URLs of Tinyproxy 2011-02-28 12:36:05 +05:30
Mukund Sivaraman 7378c97524 Surround IPv6 literals with [] in Host: headers 2011-02-07 18:00:39 +05:30
Mukund Sivaraman 2d02e2211e Handle IPv6 literals in URLs correctly 2011-02-04 20:28:48 +05:30
Michael Adam 8fd3808ad3 [BB#95] remove two comments that have become wrong by the fix. 2010-12-01 22:25:44 +01:00
Daniel Egger 62443a6391 [BB#95] Fix FilterURLs with transparent proxy support.
Pass a pointer to a char pointer to do_transparent_proxy so the reassembled URL
will actually end up back in the caller where it is needed for filtering
decisions. This fixes the problem that a tinyproxy configured with the
transparent proxy functionality and "FilterURLs Yes" would filter on everything
but the domain.

Signed-off-by: daniel.egger@sphairon.com
Signed-off-by: Michael Adam <obnox@samba.org>
2010-12-01 22:25:44 +01:00
Michael Adam 58ac635a17 README: correctly list --enable-transparent
--enable-transparent-proxy was renamed to --enable-transparent
in August 2004... :-)
2010-12-01 21:40:07 +01:00
Michael Adam b672ca03fe [BB#91] Fix upstream proxy support.
Patch by Jordi Mallach.
2010-08-24 22:47:35 +02:00
Michael Adam 52cad36352 upstream: clarify debug messages
There are frequent questions "what does 'No proxy for ...' mean?"
on the mailing list and IRC. Be more specific. (No upstream proxy ...)
Correspondingly, log "Found upstream proxy ... for ..."
2010-08-24 22:46:10 +02:00
Mukund Sivaraman 691415a8f9 [BB#74] Create log and pid files after we drop privs 2010-06-02 10:36:05 +05:30
Mukund Sivaraman 56257d3da3 Remove excessive code 2010-06-02 10:11:17 +05:30
Mukund Sivaraman df9e6d3163 Add authors to authors.xml and regen 2010-06-01 08:16:53 +05:30
John van der Kamp a7933bdd36 [BB#89] Don't recompile regular expressions
This is a modification of a patch originally written by
John van der Kamp <john@kirika.demon.nl> at
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579427#12>

The modification was done by the committer.
2010-06-01 07:54:55 +05:30
Mukund Sivaraman 50e3a0f6d9 Fix typo in manpage 2010-05-30 10:01:36 +05:30
Mukund Sivaraman f84fb98766 Precompute network addresses for increased performance 2010-05-30 08:08:04 +05:30
Mukund Sivaraman 0963c4c71f Minor indent of code 2010-05-30 08:01:14 +05:30
Mukund Sivaraman 7c39cdfe1d Use complete sentences in the manpages 2010-04-22 21:14:27 +05:30
Jordi Mallach 7da3e4854c [BB#83] Use output of id instead of $USER 2010-04-21 21:02:57 +05:30
Dmitry Semyonov 7edb6e047c Fix crash in send_stored_logs() 2010-04-21 20:35:50 +05:30
Mukund Sivaraman d30ee746a7 Revert "main: drop privileges right after reading the config"
This reverts commit 7a9abc2a04. It should
fix the issue in bug #87.
2010-04-21 20:10:56 +05:30
Mukund Sivaraman 1e0ad98f7f Just fix the support URLs 2010-03-28 10:33:38 +05:30
Mukund Sivaraman 34088e2175 Revert "Update Tinyproxy website URLs"
This reverts commit b108162dfb.
2010-03-28 10:27:40 +05:30
Mukund Sivaraman b108162dfb Update Tinyproxy website URLs 2010-03-27 08:22:51 +05:30
Mukund Sivaraman d37a6b2c12 Revert "Revert "Pass address family when binding to outgoing socket""
This reverts commit 70885bf029. It looks
like bug #69 needs this fix after all.
2010-03-09 17:08:37 +05:30
Mukund Sivaraman 2f86b79d85 Use AI_PASSIVE flag to make tinyproxy listen on wildcard interface
Signed-off-by: Michael Adam <obnox@samba.org>
2010-03-03 01:03:45 +01:00
Michael Adam 243526d493 Comment out the LogFile and PidFile options in the example tinyproxy.conf.
These are compiled in defaults now.

Michael
2010-03-02 23:41:37 +01:00
Michael Adam e87c856487 change the default pid file location to "@LOCALSTATEDIR@/run/tinyproxy/tinyproxy.pid"
I.e., add a tinyproxy subdirectory.
This is meant to ease running tinyproxy as non-root user.
The subdirectory can be used to give the tinyproxy user
write permission.

Michael
2010-03-02 23:39:30 +01:00
Michael Adam cfa5792880 change the default log file location to "@LOCALSTATEDIR@/log/tinyproxy/tinyproxy.log"
i.e. add a tinyproxy subdirectory.
This is meant to ease running tinyproxy as non-root user
the subdirectory can be used to give the tinyproxy user
write permission.

Michael
2010-03-02 23:39:21 +01:00
Michael Adam f640c6fbb1 main: some tabs->spaces 2010-03-02 22:17:34 +01:00
Michael Adam fcf5fd2129 main: move a log message. 2010-03-02 22:05:28 +01:00
Michael Adam 7a9abc2a04 main: drop privileges right after reading the config
This is the second part of fixing bug #74.
I lets tinyproxy create its log and pid files as the
user as which it is running, so that later on at SIGHUP,
the log file can successfully be reopened.

Michael
2010-03-02 22:02:46 +01:00
Michael Adam 2235a97f05 main: separate loading of config and setup_logging at startup
This is the first part of a fix for bug #74
(making reloading of config work if running as non-privileged user)

Michael
2010-03-02 21:57:03 +01:00
Michael Adam f923649a11 tinyproxy.conf: fix LogFile to proper CamelCase for consistency 2010-02-23 08:06:55 +01:00
Michael Adam 3f1632603c tests: fix bug #80: keep track of errors in return codes
Michael
2010-02-23 00:18:29 +01:00
Michael Adam 7c15563430 tests: fix a typo in run_tests.sh 2010-02-23 00:17:21 +01:00
Michael Adam ee1f1e38f2 test: add make target "make valgrind-test-wait" 2010-02-22 23:31:40 +01:00
Michael Adam 752e4419a6 tests: add a new make target "make test-wait" 2010-02-22 23:17:39 +01:00
Michael Adam d133eee36b tests: Fix bug #79. Finish "make test" without waiting for user input.
Old behaviour is preserved by passing in the environment variable
TINYPROXY_TESTS_WAIT=yes.

Michael
2010-02-22 23:12:51 +01:00
Mukund Sivaraman 2f6840fd85 Use format string when logging messages 2010-02-19 21:04:02 +05:30
Mukund Sivaraman 719b5f6049 Fix pkgdatadir path in tinyproxy.conf 2010-02-18 00:30:19 +05:30
Mukund Sivaraman 907a6c2420 Display upstream proxy support in usage message 2010-02-17 23:11:45 +05:30
Mukund Sivaraman c6d4c68c99 Update help text a little 2010-02-17 00:29:29 +05:30
Mukund Sivaraman 3efcfd2345 Also install AUTHORS file in doc directory 2010-01-26 13:26:32 +05:30
Mukund Sivaraman a9b42c491f Install README and NEWS in doc directory 2010-01-26 12:24:41 +05:30
Mukund Sivaraman 9434b27cc1 Remove bogus static qualifiers for these auto variables 2010-01-25 23:40:03 +05:30
Mukund Sivaraman 2d85a69e49 Remove unnecessary cast to (void **)
Fixes a compiler warning about dereferencing type-punned pointers.
2010-01-25 21:36:18 +05:30
Mukund Sivaraman 0697a9047d Remove obsolete ChangeLog file 2010-01-25 21:16:39 +05:30
Mukund Sivaraman 41d80861e3 Fix typo in manpage 2010-01-25 19:35:30 +05:30
Mukund Sivaraman 19b9bff888 Fix compiler warning about dereferencing type-punned pointers 2010-01-25 13:06:58 +05:30
Mukund Sivaraman 13eb2258e0 Don't check for overlength strings 2010-01-25 12:47:13 +05:30
Mukund Sivaraman 2447e38618 Minor text updates 2010-01-24 11:17:20 +05:30
Mukund Sivaraman d9d66e6280 Minor text updates to the patch section 2010-01-24 11:07:28 +05:30
Mukund Sivaraman 70885bf029 Revert "Pass address family when binding to outgoing socket"
This reverts commit 65ef313cc4.
This patch could've been the reason for BB#69.
2010-01-21 06:29:15 +05:30
Mukund Sivaraman 9b9d8c10f8 Reformat README for asciidoc 2010-01-19 19:12:24 +05:30
Mukund Sivaraman b08420ec13 List all authors when license is requested
(Not just recent authors.)
2010-01-19 19:04:39 +05:30
Mukund Sivaraman e11a01f0b1 Add more authors 2010-01-19 19:03:36 +05:30
Mukund Sivaraman 7ac13d7924 Change to for loop 2010-01-19 05:14:06 +05:30
Mukund Sivaraman edea7e37d0 Show authors and documenters when license is requested 2010-01-18 19:05:31 +05:30
Mukund Sivaraman f3fe3d8e79 Add authors.* files to EXTRA_DIST 2010-01-18 18:45:13 +05:30
Mukund Sivaraman 510655e447 Make note about auto-generated file an asciidoc comment 2010-01-18 18:42:10 +05:30
Mukund Sivaraman 9e7dac7996 Update AUTHORS file for dual roles 2010-01-18 18:35:59 +05:30
Mukund Sivaraman b21270ffa5 Move documenters under Documentation section 2010-01-18 17:45:32 +05:30
Mukund Sivaraman 84d5926bdb Do better asciidoc formatting of AUTHORS file 2010-01-18 17:41:42 +05:30
Mukund Sivaraman 8631a9d531 Update the AUTHORS file
This uses an XML based system now to store author names.
We also keep a pre-generated AUTHORS file checked in.
2010-01-18 17:35:51 +05:30
Mukund Sivaraman d396e5592b Remove completed items from TODO list 2010-01-18 16:01:08 +05:30
Mukund Sivaraman ff2a7a2bdc Reset the NEWS file for the master branch 2010-01-17 21:05:13 +05:30
Mukund Sivaraman 26cfec06a0 Bump master version to 1.9.0 2010-01-17 19:21:22 +05:30
48 changed files with 1489 additions and 3111 deletions

No files matched your search

+1
View File
@@ -18,5 +18,6 @@ stamp-h1
autom4te.cache
cscope.files
cscope.out
compile
*~
tags
+18
View File
@@ -0,0 +1,18 @@
language: C
dist: trusty
sudo: true
before_install:
- sudo apt-get update -qq
- sudo apt-get install --assume-yes asciidoc valgrind
script:
- ./autogen.sh
- ./configure
- make
- make test
- ./configure --enable-debug --enable-transparent --enable-reverse
- make
- make test
- make valgrind-test
- make distcheck
+39 -19
View File
@@ -1,19 +1,39 @@
Early History
-------------
Steven Young is the original author and was the primary maintainer of
tinyproxy until version 1.1. He also maintained the project from
version 1.3.1 until 1.4.0.
Robert James Kaes is the current maintainer and lead programmer. He
also maintained the project between versions 1.2 and 1.3.0, and again
starting with version 1.4.0.
Major Additions/Improvements
----------------------------
James E. Flemer <jflemer@acm.jhu.edu> - URL/domain filtering
Kim Holviala <kim@holviala.com> - Reverse proxy support
Petr Lampa <lampa@fit.vutbr.cz> - Transparent proxy support
George Talusan <gstalusan@uwaterloo.ca> - URL/domain filtering
Andrew Stribblehill
bertliao
Bob Showalter
Brian Cain
cvs2svn
Daniel Egger
Daniel M. Drucker
David Shanks
Dmitry Semyonov
dmz-uk
Drew G. Wallace
Frank Morgner
gary-wzl77
Gaudenz Steinlin
goba62000374
Gonzalo Tornaria
Greg
Jeremy Hinegardner
John Spencer
John van der Kamp
John Weldon
Jordi
Jordi Mallach
Julien Hartmann
kikuchan
Mathew Mrosko
Matthew Dempsky
Michael Adam
Mike Mead
Mukund Sivaraman
Pablo Panero
Peter H. Froehlich
Robert James Kaes
rofl0r
Stephan Leemburg
Steven Conaway
Steven Young
Valen Blanco
Vladimir Belov
+1 -2155
View File
File diff suppressed because it is too large. Load diff
+8
View File
@@ -9,6 +9,14 @@ SUBDIRS = \
# tools want this on a single line
ACLOCAL_AMFLAGS = -I m4macros
all-local:
dist_doc_DATA = \
AUTHORS \
NEWS \
README \
README.md
EXTRA_DIST = \
autogen.sh \
tinyproxy-indent.sh \
+1 -134
View File
@@ -1,134 +1 @@
Tinyproxy NEWS
==============
Version 1.8.2
-------------
* Minor formatting changes and typo fixes were made.
Bugs resolved since version 1.8.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#69: INET6 not available when configured to Listen and Bind in v4,
and vice versa
* BB#74: tinyproxy unable to reopen log files after receiving HUP
* BB#78: Warn if configuration results in an open proxy
* BB#82: https access not working
* BB#83: run_tests.sh relies on $USER
* BB#84: Unaligned access error on ia64 and alpha
* BB#87: Unable to listen on ports less than 1024 (regression in 1.8.1)
* BB#88: Crashes when reloading configuration
* BB#89: tinyproxy leaks memory over time
Contributors
~~~~~~~~~~~~
Dmitry Semyonov, John van der Kamp, Jordi Mallach, Michael Adam,
Mukund Sivaraman.
Version 1.8.1
-------------
* Tinyproxy now drops `root` user privileges more quickly.
* The log and pid files are now stored in a sub-directory in `/var/`.
* A format string vulnerability was fixed.
* Minor formatting changes and typo fixes were made.
Bugs fixed since version 1.8.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#74: tinyproxy unable to reopen log files after receiving HUP
* BB#79: Make the testsuite uninteractive
* BB#80: Handle errors in testsuite
* BB#81: Listen directive doesn't work as expected
* BB#72: upstream support is not reported with tinyproxy -h
* BB#73: generated tinyproxy.conf has the wrong location for the html
file installation
Contributors
~~~~~~~~~~~~
Michael Adam, Mukund Sivaraman.
Version 1.8.0
-------------
* Tinyproxy now reloads its configuration upon SIGHUP signal.
* Tinyproxy reopens its log file (instead of truncation) upon SIGHUP
signal. This is to play more nicely with logrotate.
* File logging is now the default.
Syslog is chosen if and only if "SysLog Yes" is in the config,
i.e., a present "SysLog Yes" in the config file now overrides
any LogFile setting.
* The XTinyProxy option is now documented as a global boolean.
Before it was documented to build a list of sites to add a
X-Tinyproxy header for, but it was implemented as global boolean.
* A new config option AddHeader allows the user to configure a list of
custom headers to send in outgoing HTTP requests.
* A new config option DisableViaHeader allows the user to disable
sending of the "Via:" header.
* Tinyproxy is now IPv6 capable.
* The config option PidFile now has a compiled in default.
Bugs fixed since version 1.7.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#9: Add support for the IPv6 protocol
* BB#17: Add support for custom headers
* BB#55: Error message response omits body when request has a body
* BB#60: Add config option to disable Via header
* BB#61: SIGHUP does not refresh filter list
* BB#62: Make tinyproxy reload the config upon SIGHUP
* BB#64: Config parsing error with reverse proxy option
* BB#65: Format string compile warnings
* BB#67: ACL processing error with multiple Allow statements
Contributors
~~~~~~~~~~~~
David Shanks, Mathew Mrosko, Michael Adam, Mukund Sivaraman.
Version 1.7.1
-------------
* Fixed all warnings reported by GCC.
* The tinyproxy manpage has been extended and converted to asciidoc.
* There is a new tinyproxy.conf manpage that describes all the options.
* The build system has been considerably cleaned up.
* Various other bugs have been fixed.
Bugs fixed since version 1.7.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#2: Fix Tinyproxy for requests like www.site.com:8001
* BB#5: Move templates from the doc directory to its own directory
* BB#8: Update README, INSTALL, NEWS and the manpage
* BB#10: Do not filter out transfer-encoding header
* BB#18: Fix pointer aliasing issues
* BB#53: Add a GPLv2 COPYING file
Contributors
~~~~~~~~~~~~
Andrew Stribblehill, Jeremy Hinegardner, Matthew Dempsky, Michael Adam,
Mukund Sivaraman, Robert James Kaes.
Version 1.7.0
-------------
* There is now support for reverse proxying.
* Tinyproxy does not bundle a vendor regular expressions library
anymore. It uses the system installed regular expressions library.
* The documentation has been updated.
* Tinyproxy now contains some code optimizations such as the use of a
hashmap internally for looking up error pages.
* Various other bugs have been fixed.
Contributors
~~~~~~~~~~~~
Kim Holviala, Marc Silver, Robert James Kaes, Steven Young.
See git log for recent changes in Tinyproxy.
+1 -97
View File
@@ -1,97 +1 @@
Tinyproxy
=========
Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
GNU General Public License. Tinyproxy is very useful in a small network
setting, where a larger proxy would either be too resource intensive, or
a security risk. One of the key features of Tinyproxy is the buffering
connection concept. In effect, Tinyproxy will buffer a high speed
response from a server, and then relay it to a client at the highest
speed the client will accept. This feature greatly reduces the problems
with sluggishness on the Internet. If you are sharing an Internet
connection with a small network, and you only want to allow HTTP
requests to be allowed, then Tinyproxy is a great tool for the network
administrator.
For more info, please visit:
https://www.banu.com/tinyproxy/
Installation
------------
To install this package under a UNIX derivative, read the INSTALL file.
Tinyproxy uses a standard GNU `configure` script. Basically you should
be able to do:
----
./configure
make
make install
----
in the top level directory to compile and install Tinyproxy. There are
additional command line arguments you can supply to `configure`. They
include:
--enable-debug If you would like to turn on full
debugging support
--enable-xtinyproxy Compile in support for the XTinyproxy
header, which is sent to any web
server in your domain.
--enable-filter Allows Tinyproxy to filter out certain
domains and URLs.
--enable-upstream Enable support for proxying connections
through another proxy server.
--enable-transparent-proxy
Allow Tinyproxy to be used as a
transparent proxy daemon
--enable-static Compile a static version of Tinyproxy
--with-stathost=HOST Set the default name of the stats host
Support
-------
If you are having problems with Tinyproxy, please submit a bug report
using Tinyproxy as the product at:
https://www.banu.com/bugzilla/
You may also wish to subscribe to the Tinyproxy mailing lists. To do so
please visit:
https://www.banu.com/mailman/listinfo/tinyproxy-announce-list
https://www.banu.com/mailman/listinfo/tinyproxy-users-list
https://www.banu.com/mailman/listinfo/tinyproxy-developers-list
for more information on how to subscribe and post messages to the lists.
Contributing
------------
If you would like to contribute a feature, or a bug fix to the Tinyproxy
source, please send a patch (preferably as a unified diff. i.e. `diff
-u` against the "master" branch of the Tinyproxy source code git
repository to tinyproxy-developers-list. Please include a description
of what your patch does.
Tinyproxy's git repository is git://www.banu.com/tinyproxy.git. The
following command creates a local copy:
----
git clone git://www.banu.com/tinyproxy.git
----
The easiest and preferred way to create a patch for submission is to
check in your changes locally and use `git format-patch` to generate a
mbox-style commit file that contains the diff along with the commit
message and author information. Such a format-patch file can be
integrated into the upstream repository, automatically keeping the
commit message and author information.
You can also meet developers and discuss development issues and patches
in the #tinyproxy IRC channel on Freenode (irc.freenode.net).
see README.md
+89
View File
@@ -0,0 +1,89 @@
# Tinyproxy
Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
GNU General Public License. Tinyproxy is very useful in a small network
setting, where a larger proxy would either be too resource intensive, or
a security risk. One of the key features of Tinyproxy is the buffering
connection concept. In effect, Tinyproxy will buffer a high speed
response from a server, and then relay it to a client at the highest
speed the client will accept. This feature greatly reduces the problems
with sluggishness on the Internet. If you are sharing an Internet
connection with a small network, and you only want to allow HTTP
requests to be allowed, then Tinyproxy is a great tool for the network
administrator.
For more info, please visit [the Tinyproxy web site](https://tinyproxy.github.io/).
## Installation
Tinyproxy uses a standard GNU `configure` script based on the automake
system. If compiling from a git checkout, you need to first run
```
./autogen.sh
```
from the top level directory to generate the `configure` script.
The release tarball contains the pre-created `configure` script,
so when building from a release, you can skip this step.
Then basically all you need to do is
```
./configure
make
make install
```
in the top level directory to compile and install Tinyproxy. There are
additional command line arguments you can supply to `configure`. They
include:
- `--enable-debug`:
If you would like to turn on full debugging support.
- `--enable-xtinyproxy`:
Compile in support for the XTinyproxy header, which is sent to any
web server in your domain.
- `--enable-filter`:
Allows Tinyproxy to filter out certain domains and URLs.
- `--enable-upstream`:
Enable support for proxying connections through another proxy server.
- `--enable-transparent`:
Allow Tinyproxy to be used as a transparent proxy daemon.
- `--enable-reverse`:
Enable reverse proxying.
- `--with-stathost=HOST`:
Set the default name of the stats host.
For more information about the build system, read the INSTALL file
that is generated by `autogen.sh` and comes with the release tar ball.
## Support
If you are having problems with Tinyproxy, please raise an
[issue on github](https://github.com/tinyproxy/tinyproxy/issues).
## Contributing
If you would like to contribute a feature, or a bug fix to the Tinyproxy
source, please clone the
[git repository from github](https://github.com/tinyproxy/tinyproxy.git)
and create a [pull request](https://github.com/tinyproxy/tinyproxy/pulls).
## Community
You can meet developers and users to discuss development,
patches and deployment issues in the `#tinyproxy` IRC channel on
Freenode (`irc.freenode.net`).
+1 -1
View File
@@ -38,7 +38,7 @@ against the current tree and I'll integrate it if possible.
* Include user authentication for accessing tinyproxy itself.
Administrators should be allowed to selectively allow certain users
access to tinyproxy via a user name/password pair. Check the
HTTP/1.1 RFC for more information. [Suggested: Tyrone Tranmer]
HTTP/1.1 RFC for more information.
==> https://www.banu.com/bugzilla/show_bug.cgi?id=13
+55 -114
View File
@@ -4,44 +4,26 @@
AC_PREREQ(2.54)
m4_define([tinyproxy_major_version], [1])
m4_define([tinyproxy_minor_version], [8])
m4_define([tinyproxy_micro_version], [2])
m4_define([tinyproxy_minor_version], [10])
m4_define([tinyproxy_micro_version], [0])
m4_define([tinyproxy_real_version],
[tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
m4_define([tinyproxy_version], [tinyproxy_real_version])
# For overriding the version string. Comment out if not needed.
# m4_define([tinyproxy_version], [1.8.2])
m4_define([tinyproxy_unstable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [1], [yes], [no]))
m4_define([tinyproxy_stable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [0], [yes], [no]))
# m4_define([tinyproxy_version], [1.10.0])
AC_INIT([Tinyproxy], [tinyproxy_version],
[https://www.banu.com/tinyproxy/],
[https://tinyproxy.github.io/],
[tinyproxy])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([dist-bzip2])
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE([dist-bzip2 dist-xz])
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR([m4macros])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
TINYPROXY_MICRO_VERSION=tinyproxy_micro_version
TINYPROXY_REAL_VERSION=tinyproxy_real_version
TINYPROXY_VERSION=tinyproxy_version
TINYPROXY_UNSTABLE=tinyproxy_unstable
AC_SUBST(TINYPROXY_MAJOR_VERSION)
AC_SUBST(TINYPROXY_MINOR_VERSION)
AC_SUBST(TINYPROXY_MICRO_VERSION)
AC_SUBST(TINYPROXY_REAL_VERSION)
AC_SUBST(TINYPROXY_VERSION)
AC_SUBST(TINYPROXY_UNSTABLE)
dnl Temporarily defined here until we get tinyproxy-version.h
AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number])
@@ -113,8 +95,8 @@ dnl Include support for reverse proxy?
AH_TEMPLATE([REVERSE_SUPPORT],
[Include support for reverse proxy.])
TP_ARG_ENABLE(reverse,
[Enable reverse proxying (default is NO)],
no)
[Enable reverse proxying (default is YES)],
yes)
if test x"$reverse_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
AC_DEFINE(REVERSE_SUPPORT)
@@ -124,18 +106,13 @@ dnl Include the transparent proxy support
AH_TEMPLATE([TRANSPARENT_PROXY],
[Include support for using tinyproxy as a transparent proxy.])
TP_ARG_ENABLE(transparent,
[Enable transparent proxying code (default is NO)],
no)
[Enable transparent proxying code (default is YES)],
yes)
if test x"$transparent_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
AC_DEFINE(TRANSPARENT_PROXY)
fi
dnl Check for broken regex library
TP_ARG_ENABLE(regexcheck,
[Check for working regex library (default is YES)],
yes)
# This is required to build test programs below
AC_PROG_CC
@@ -166,48 +143,19 @@ dnl
AC_HEADER_STDC
AC_HEADER_TIME
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \
sys/select.h sys/socket.h sys/time.h sys/uio.h \
sys/un.h arpa/inet.h netinet/in.h \
assert.h ctype.h errno.h fcntl.h grp.h io.h libintl.h \
netdb.h pwd.h regex.h signal.h stdarg.h stddef.h stdio.h \
sysexits.h syslog.h time.h wchar.h wctype.h \
AC_CHECK_HEADERS([sys/ioctl.h alloca.h memory.h malloc.h sysexits.h \
values.h])
dnl OpenBSD machines don't like having malloc included (even if it's present)
dnl as they expect you to use stdlib.h
case "$target" in
*-openbsd*) ;;
*) AC_CHECK_HEADER(malloc.h);;
esac
dnl Checks for types
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_UNP_CHECK_TYPE(uint8_t, unsigned char)
AC_UNP_CHECK_TYPE(int16_t, short)
AC_UNP_CHECK_TYPE(uint16_t, unsigned short)
AC_UNP_CHECK_TYPE(int32_t, int)
AC_UNP_CHECK_TYPE(uint32_t, unsigned int)
AC_UNP_CHECK_TYPE(ssize_t, int)
AC_UNP_CHECK_TYPE(socklen_t, unsigned int)
AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
dnl Checks for libary functions
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([gethostname inet_ntoa memchr memset select socket strcasecmp \
strchr strdup strerror strncasecmp strpbrk strstr strtol])
AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regcomp regexec])
AC_CHECK_FUNCS([strlcpy strlcat])
AC_CHECK_FUNCS([inet_ntoa strdup])
AC_CHECK_FUNCS([strlcpy strlcat setgroups])
dnl Enable extra warnings
DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -pedantic -Wc++-compat -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -Wno-overlength-strings -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
if test -n "${MAINTAINER_MODE_FALSE}"; then
DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
@@ -222,57 +170,17 @@ if test x"$debug_enabled" != x"yes" ; then
CFLAGS="-DNDEBUG $CFLAGS"
fi
LDFLAGS="-Wl,-z,defs"
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 Handle the REGEX library
if test x"$ac_cv_func_regexec" != x"yes"; then
AC_MSG_ERROR([Could not locate the regexec() function])
else
if test x"$regexcheck_enabled" = x"yes" ; then
AC_MSG_CHECKING([whether the system's regex library is broken])
AC_CACHE_VAL(tinyproxy_cv_regex_broken,
[AC_TRY_RUN([
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_REGEX_H
# include <regex.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
int main(void)
{
regex_t blah;
if (regcomp(&blah, "foo.*bar", REG_NOSUB) != 0)
exit(1);
if (regexec(&blah, "foobar", 0, NULL, 0) != 0)
exit(1);
else
exit(0);
return 0;
}
],
tinyproxy_cv_regex_broken=no,
tinyproxy_cv_regex_broken=yes,
tinyproxy_cv_regex_broken=yes)])
AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
AC_MSG_ERROR([Your system's regexec() function is broken.])
fi
fi
fi
dnl
dnl Substitute the variables into the various Makefiles
dnl
@@ -282,12 +190,28 @@ AC_SUBST(CPPFLAGS)
AC_SUBST(LIBS)
AC_SUBST(ADDITIONAL_OBJECTS)
# Check for xml tools
AC_PATH_PROG(XSLTPROC, xsltproc, no)
AM_CONDITIONAL(HAVE_XSLTPROC, test "x$XSLTPROC" != "xno")
# Check for asciidoc
AC_PATH_PROG(A2X, a2x, no)
AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno")
if test x"$A2X" = x"no"; then
AC_MSG_ERROR([Test for asciidoc failed. See the file 'INSTALL' for help.])
# checking xmllint
AC_PATH_PROG(XMLLINT, xmllint, no)
if test "x$XMLLINT" != "xno"; then
AS_ECHO_N("testing xmllint... ")
echo "TEST" > conftest.txt
if $A2X -f docbook conftest.txt 2>/dev/null; then
AS_ECHO("ok")
else
AS_ECHO("failed")
XMLLINT="no"
fi
rm -f conftest.txt conftest.xml
fi
AM_CONDITIONAL(HAVE_XMLLINT, test "x$XMLLINT" != "xno")
AC_CONFIG_FILES([
Makefile
@@ -306,3 +230,20 @@ tests/scripts/Makefile
])
AC_OUTPUT
# the manpages are shipped in the release tarball and we don't want them to
# get regenerated if a2x is not available. the intermediate files from
# AC_CONFIG_FILES are created with config.status, which is created at configure
# runtime, so we need to touch them after config.status terminated to prevent
# make from rebuild them.
if test "x$A2X" = "xno"; then
touch docs/man5/tinyproxy.conf.txt
touch docs/man8/tinyproxy.txt
if test -e docs/man5/tinyproxy.conf.5 ; then
touch docs/man5/tinyproxy.conf.5
fi
if test -e docs/man8/tinyproxy.8 ; then
touch docs/man8/tinyproxy.8
fi
fi
+8 -3
View File
@@ -1,9 +1,11 @@
MAN5_FILES = \
tinyproxy.conf.txt
A2X_ARGS = \
-d manpage \
-f manpage
if HAVE_XMLLINT
A2X_ARGS = -d manpage -f manpage
else
A2X_ARGS = -d manpage -f manpage -L
endif
man_MANS = \
$(MAN5_FILES:.txt=.5)
@@ -18,3 +20,6 @@ endif
CLEANFILES = \
$(MAN5_FILES:.txt=.5) \
$(MAN5_FILES:.txt=.xml)
EXTRA_DIST = \
$(MAN5_FILES:.txt=.5)
+14 -13
View File
@@ -144,21 +144,25 @@ The possible keywords and their descriptions are as follows:
`X-Tinyproxy` containing the client's IP address to the request.
*Upstream*::
*No Upstream*::
This option allows you to set up a set of rules for deciding
whether an upstream proxy server is to be used, based on the
host or domain of the site being accessed. The rules are stored
in the order encountered in the configuration file and the
LAST matching rule wins. There are three possible forms for
specifying upstream rules:
LAST matching rule wins. The following forms for specifying upstream
rules exist:
* 'upstream host:port' turns proxy upstream support on generally.
* 'upstream type host:port' turns proxy upstream support on generally.
* 'upstream host:port "site_spec"' turns on the upstream proxy for
the sites matching `site_spec`.
* 'upstream type user:pass@host:port' does the same, but uses the
supplied credentials for authentication.
* 'no upstream "site_spec"' turns off upstream support for sites
* 'upstream type host:port "site_spec"' turns on the upstream proxy
for the sites matching `site_spec`.
`type` can be one of `http`, `socks4`, `socks5`, `none`.
* 'upstream none "site_spec"' turns off upstream support for sites
matching `site_spec`.
The site can be specified in various forms as a hostname, domain
@@ -343,7 +347,7 @@ BUGS
----
To report bugs in Tinyproxy, please visit
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>.
SEE ALSO
@@ -354,16 +358,13 @@ tinyproxy(8)
AUTHOR
------
Written by the Tinyproxy project team.
This manpage was written by the Tinyproxy project team.
COPYRIGHT
---------
Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009-2010 Mukund Sivaraman;
Copyright (c) 2009-2010 Michael Adam.
Copyright (c) 1998-2018 the Tinyproxy authors.
This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional
+8 -3
View File
@@ -1,9 +1,11 @@
MAN8_FILES = \
tinyproxy.txt
A2X_ARGS = \
-d manpage \
-f manpage
if HAVE_XMLLINT
A2X_ARGS = -d manpage -f manpage
else
A2X_ARGS = -d manpage -f manpage -L
endif
man_MANS = \
$(MAN8_FILES:.txt=.8)
@@ -18,3 +20,6 @@ endif
CLEANFILES = \
$(MAN8_FILES:.txt=.8) \
$(MAN8_FILES:.txt=.xml)
EXTRA_DIST= \
$(MAN8_FILES:.txt=.8)
+3 -9
View File
@@ -40,9 +40,6 @@ OPTIONS
*-h*::
Display a short help screen of command line arguments and exit.
*-l*::
Display the licensing agreement.
*-v*::
Display version information and exit.
@@ -136,7 +133,7 @@ BUGS
----
To report bugs in Tinyproxy, please visit
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>.
SEE ALSO
@@ -147,16 +144,13 @@ tinyproxy.conf(5)
AUTHOR
------
Written by the Tinyproxy project team.
This manpage was written by the Tinyproxy project team.
COPYRIGHT
---------
Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009-2010 Mukund Sivaraman;
Copyright (c) 2009-2010 Michael Adam.
Copyright (c) 1998-2018 the Tinyproxy authors.
This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional
+4 -2
View File
@@ -1,4 +1,6 @@
sysconf_DATA = \
pkgsysconfdir = $(sysconfdir)/$(PACKAGE)
pkgsysconf_DATA = \
tinyproxy.conf
EXTRA_DIST = \
@@ -8,7 +10,7 @@ edit = sed \
-e 's|@bindir[@]|$(bindir)|g' \
-e 's|@datadir[@]|$(datadir)|g' \
-e 's|@datarootdir[@]|$(datarootdir)|g' \
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@pkgsysconfdir[@]|$(pkgsysconfdir)|g' \
-e 's|@localstatedir[@]|$(localstatedir)|g' \
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
-e 's|@prefix[@]|$(prefix)|g' \
+37 -18
View File
@@ -90,7 +90,8 @@ StatFile "@pkgdatadir@/stats.html"
# LogFile: Allows you to specify the location where information should
# be logged to. If you would prefer to log to syslog, then disable this
# and enable the Syslog directive. These directives are mutually
# exclusive.
# exclusive. If neither Syslog nor LogFile are specified, output goes
# to stdout.
#
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
@@ -102,7 +103,7 @@ StatFile "@pkgdatadir@/stats.html"
#Syslog On
#
# LogLevel:
# LogLevel: Warning
#
# Set the logging level. Allowed settings are:
# Critical (least verbose)
@@ -121,6 +122,7 @@ LogLevel Info
#
# PidFile: Write the PID of the main tinyproxy thread to this file so it
# can be used for signalling purposes.
# If not specified, no pidfile will be written.
#
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
@@ -138,25 +140,37 @@ LogLevel Info
# The upstream rules allow you to selectively route upstream connections
# based on the host/domain of the site being accessed.
#
# Syntax: upstream type (user:pass@)ip:port ("domain")
# Or: upstream none "domain"
# The parts in parens are optional.
# Possible types are http, socks4, socks5, none
#
# For example:
# # connection to test domain goes through testproxy
# upstream testproxy:8008 ".test.domain.invalid"
# upstream testproxy:8008 ".our_testbed.example.com"
# upstream testproxy:8008 "192.168.128.0/255.255.254.0"
# upstream http testproxy:8008 ".test.domain.invalid"
# upstream http testproxy:8008 ".our_testbed.example.com"
# upstream http testproxy:8008 "192.168.128.0/255.255.254.0"
#
# # upstream proxy using basic authentication
# upstream http user:pass@testproxy:8008 ".test.domain.invalid"
#
# # no upstream proxy for internal websites and unqualified hosts
# no upstream ".internal.example.com"
# no upstream "www.example.com"
# no upstream "10.0.0.0/8"
# no upstream "192.168.0.0/255.255.254.0"
# no upstream "."
# upstream none ".internal.example.com"
# upstream none "www.example.com"
# upstream none "10.0.0.0/8"
# upstream none "192.168.0.0/255.255.254.0"
# upstream none "."
#
# # connection to these boxes go through their DMZ firewalls
# upstream cust1_firewall:8008 "testbed_for_cust1"
# upstream cust2_firewall:8008 "testbed_for_cust2"
# upstream http cust1_firewall:8008 "testbed_for_cust1"
# upstream http cust2_firewall:8008 "testbed_for_cust2"
#
# # default upstream is internet firewall
# upstream firewall.internal.example.com:80
# upstream http firewall.internal.example.com:80
#
# You may also use SOCKS4/SOCKS5 upstream proxies:
# upstream socks4 127.0.0.1:9050
# upstream socks5 socksproxy:1080
#
# The LAST matching rule wins the route decision. As you can see, you
# can use a host, or a domain:
@@ -166,7 +180,7 @@ LogLevel Info
# IP/bits matches network/mask
# IP/mask matches network/mask
#
#Upstream some.remote.proxy:port
#Upstream http some.remote.proxy:port
#
# MaxClients: This is the absolute highest number of threads which will
@@ -209,6 +223,11 @@ MaxRequestsPerChild 0
#
Allow 127.0.0.1
# BasicAuth: HTTP "Basic Authentication" for accessing the proxy.
# If there are any entries specified, access is only granted for authenticated
# users.
#BasicAuth user password
#
# AddHeader: Adds the specified headers to outgoing HTTP requests that
# Tinyproxy makes. Note that this option will not work for HTTPS
@@ -236,7 +255,7 @@ ViaProxyName "tinyproxy"
#
# Filter: This allows you to specify the location of the filter file.
#
#Filter "@sysconfdir@/filter"
#Filter "@pkgsysconfdir@/filter"
#
# FilterURLs: Filter based on URLs rather than domains.
@@ -283,12 +302,12 @@ ViaProxyName "tinyproxy"
# ConnectPort: This is a list of ports allowed by tinyproxy when the
# CONNECT method is used. To disable the CONNECT method altogether, set
# the value to 0. If no ConnectPort line is found, all ports are
# allowed (which is not very secure.)
# allowed.
#
# The following two ports are used by SSL.
#
ConnectPort 443
ConnectPort 563
#ConnectPort 443
#ConnectPort 563
#
# Configure one or more ReversePath directives to enable reverse proxy
+1 -2
View File
@@ -1,4 +1,3 @@
EXTRA_DIST = \
as-compiler-flag.m4 \
argenable.m4 \
typecheck.m4
argenable.m4
-103
View File
@@ -1,103 +0,0 @@
dnl Taken from Unix Network Programming, W. Richard Stevens
dnl ##################################################################
dnl We cannot use the AC_CHECK_TYPE macros becasue AC_CHECK_TYPE
dnl #includes only <sys/types.h>, <stdlib.h>, and <stddef.h>.
dnl Unfortunately, many implementations today hide typedefs in wierd
dnl locations: Solaris 2.5.1 has uint8_t and uint32_t in <pthread.h>.
dnl SunOS 4.1.x has int8_t in <sys/bittypes.h>.
dnl So we define our own macro AC_UNP_CHECK_TYPE that does the same
dnl #includes as "unp.h", and then looks for the typedef.
dnl
dnl This macro should be invoked after all the header checks have been
dnl performed, since we #include "confdefs.h" below, and then use the
dnl HAVE_foo_H values that is can #define.
dnl
AC_DEFUN([AC_UNP_CHECK_TYPE],
[AC_MSG_CHECKING(if $1 defined)
AC_CACHE_VAL(ac_cv_type_$1,
[AC_TRY_COMPILE(
[
#include "confdefs.h" /* the header built by configure so far */
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_FILIO_H
# include <sys/filio.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
],
[ $1 foo ],
[ac_cv_type_$1=yes],
[ac_cv_type_$1=no])])
AC_MSG_RESULT([$ac_cv_type_$1])
if test $ac_cv_type_$1 = no ; then
AH_TEMPLATE([$1], [Defined with the proper type.])
AC_DEFINE($1, $2)
fi
])
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
AUTHORS_FILE="${BASE_DIR}/AUTHORS"
type git > /dev/null || exit
test -d "${BASE_DIR}/.git" || exit
git log --all --format='%aN' | sort -u > "${AUTHORS_FILE}"
+6 -2
View File
@@ -15,10 +15,12 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
sbin_PROGRAMS = tinyproxy
pkgsysconfdir = $(sysconfdir)/$(PACKAGE)
bin_PROGRAMS = tinyproxy
AM_CPPFLAGS = \
-DSYSCONFDIR=\"${sysconfdir}\" \
-DSYSCONFDIR=\"${pkgsysconfdir}\" \
-DLOCALSTATEDIR=\"${localstatedir}\"
tinyproxy_SOURCES = \
@@ -44,6 +46,8 @@ tinyproxy_SOURCES = \
utils.c utils.h \
vector.c vector.h \
upstream.c upstream.h \
basicauth.c basicauth.h \
base64.c base64.h \
connect-ports.c connect-ports.h
EXTRA_tinyproxy_SOURCES = filter.c filter.h \
+32 -9
View File
@@ -51,7 +51,7 @@ struct acl_s {
union {
char *string;
struct {
unsigned char octet[IPV6_LEN];
unsigned char network[IPV6_LEN];
unsigned char mask[IPV6_LEN];
} ip;
} address;
@@ -66,8 +66,8 @@ struct acl_s {
*
*/
static int
fill_netmask_array (char *bitmask_string, unsigned char array[],
size_t len)
fill_netmask_array (char *bitmask_string, int v6,
unsigned char array[], size_t len)
{
unsigned int i;
unsigned long int mask;
@@ -81,7 +81,14 @@ fill_netmask_array (char *bitmask_string, unsigned char array[],
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
return -1;
/* valid range for a bit mask */
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;
@@ -127,7 +134,8 @@ static int init_access_list(vector_t *access_list)
* -1 on failure
* 0 otherwise.
*/
int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
int
insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
{
struct acl_s acl;
int ret;
@@ -151,15 +159,20 @@ int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
*/
if (full_inet_pton (location, ip_dst) > 0) {
acl.type = ACL_NUMERIC;
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
memcpy (acl.address.ip.network, ip_dst, IPV6_LEN);
memset (acl.address.ip.mask, 0xff, IPV6_LEN);
} else {
int i;
/*
* At this point we're either a hostname or an
* IP address with a slash.
*/
p = strchr (location, '/');
if (p != NULL) {
char dst[sizeof(struct in6_addr)];
int v6;
/*
* We have a slash, so it's intended to be an
* IP address with mask
@@ -169,12 +182,22 @@ int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
return -1;
acl.type = ACL_NUMERIC;
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
/* 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
(p + 1, &(acl.address.ip.mask[0]), IPV6_LEN)
(p + 1, v6, &(acl.address.ip.mask[0]), IPV6_LEN)
< 0)
return -1;
for (i = 0; i < IPV6_LEN; i++)
acl.address.ip.network[i] = ip_dst[i] &
acl.address.ip.mask[i];
} else {
/* In all likelihood a string */
acl.type = ACL_STRING;
@@ -288,7 +311,7 @@ static int check_numeric_acl (const struct acl_s *acl, const char *ip)
for (i = 0; i != IPV6_LEN; ++i) {
x = addr[i] & acl->address.ip.mask[i];
y = acl->address.ip.octet[i] & acl->address.ip.mask[i];
y = acl->address.ip.network[i];
/* If x and y don't match, the IP addresses don't match */
if (x != y)
+57
View File
@@ -0,0 +1,57 @@
/* tinyproxy - A fast light-weight HTTP proxy
* this file Copyright (C) 2016-2018 rofl0r
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "base64.h"
static const char base64_tbl[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/*
rofl0r's base64 impl (taken from libulz)
takes count bytes from src, writing base64 encoded string into dst.
dst needs to be at least BASE64ENC_BYTES(count) + 1 bytes in size.
the string in dst will be zero-terminated.
*/
void base64enc(char *dst, const void* src, size_t count)
{
unsigned const char *s = src;
char* d = dst;
while(count) {
int i = 0, n = *s << 16;
s++;
count--;
if(count) {
n |= *s << 8;
s++;
count--;
i++;
}
if(count) {
n |= *s;
s++;
count--;
i++;
}
*d++ = base64_tbl[(n >> 18) & 0x3f];
*d++ = base64_tbl[(n >> 12) & 0x3f];
*d++ = i ? base64_tbl[(n >> 6) & 0x3f] : '=';
*d++ = i == 2 ? base64_tbl[n & 0x3f] : '=';
}
*d = 0;
}
+29
View File
@@ -0,0 +1,29 @@
/* tinyproxy - A fast light-weight HTTP proxy
* this file Copyright (C) 2016-2018 rofl0r
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef TINYPROXY_BASE64_H
#define TINYPROXY_BASE64_H
#include <stddef.h>
/* calculates number of bytes base64-encoded stream of N bytes will take. */
#define BASE64ENC_BYTES(N) (((N+2)/3)*4)
void base64enc(char *dst, const void* src, size_t count);
#endif
+98
View File
@@ -0,0 +1,98 @@
/* tinyproxy - A fast light-weight HTTP proxy
* This file: Copyright (C) 2016-2017 rofl0r
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "main.h"
#include "basicauth.h"
#include "conns.h"
#include "heap.h"
#include "html-error.h"
#include "log.h"
#include "conf.h"
#include "base64.h"
/*
* Create basic-auth token in buf.
* Returns strlen of token on success,
* -1 if user/pass missing
* 0 if user/pass too long
*/
ssize_t basicauth_string(const char *user, const char *pass,
char *buf, size_t bufsize)
{
char tmp[256+2];
int l;
if (!user || !pass) return -1;
l = snprintf(tmp, sizeof tmp, "%s:%s", user, pass);
if (l < 0 || l >= (ssize_t) sizeof tmp) return 0;
if (bufsize < (BASE64ENC_BYTES((unsigned)l) + 1)) return 0;
base64enc(buf, tmp, l);
return BASE64ENC_BYTES(l);
}
/*
* Add entry to the basicauth list
*/
void basicauth_add (vector_t authlist,
const char *user, const char *pass)
{
char b[BASE64ENC_BYTES((256+2)-1) + 1];
ssize_t ret;
ret = basicauth_string(user, pass, b, sizeof b);
if (ret == -1) {
log_message (LOG_WARNING,
"Illegal basicauth rule: missing user or pass");
return;
} else if (ret == 0) {
log_message (LOG_WARNING,
"User / pass in basicauth rule too long");
return;
}
if (vector_append(authlist, b, ret + 1) == -ENOMEM) {
log_message (LOG_ERR,
"Unable to allocate memory in basicauth_add()");
return;
}
log_message (LOG_INFO,
"Added basic auth user : %s", user);
}
/*
* Check if a user/password combination (encoded as base64)
* is in the basicauth list.
* return 1 on success, 0 on failure.
*/
int basicauth_check (vector_t authlist, const char *authstring)
{
ssize_t vl, i;
size_t el;
const char* entry;
vl = vector_length (authlist);
if (vl == -EINVAL) return 0;
for (i = 0; i < vl; i++) {
entry = vector_getentry (authlist, i, &el);
if (strcmp (authstring, entry) == 0)
return 1;
}
return 0;
}
+35
View File
@@ -0,0 +1,35 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2005 Robert James Kaes <rjkaes@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'basicauth.c' for detailed information. */
#ifndef TINYPROXY_BASICAUTH_H
#define TINYPROXY_BASICAUTH_H
#include <stddef.h>
#include "vector.h"
extern ssize_t basicauth_string(const char *user, const char *pass,
char *buf, size_t bufsize);
extern void basicauth_add (vector_t authlist,
const char *user, const char *pass);
extern int basicauth_check (vector_t authlist, const char *authstring);
#endif
+3 -5
View File
@@ -236,8 +236,7 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
"readbuff: add_to_buffer() error.");
bytesin = -1;
}
} else {
if (bytesin == 0) {
} else if (bytesin == 0) {
/* connection was closed by client */
bytesin = -1;
} else {
@@ -254,13 +253,12 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
break;
default:
log_message (LOG_ERR,
"readbuff: recv() error \"%s\" on file descriptor %d",
strerror (errno), fd);
"read_buffer: read() failed on fd %d: %s",
fd, strerror(errno));
bytesin = -1;
break;
}
}
}
safefree (buffer);
return bytesin;
+136 -8
View File
@@ -32,8 +32,7 @@
#include "utils.h"
#include "conf.h"
static int listenfd;
static socklen_t addrlen;
static vector_t listen_fds;
/*
* Stores the internal data needed for each child (connection)
@@ -187,8 +186,13 @@ static void child_main (struct child_s *ptr)
int connfd;
struct sockaddr *cliaddr;
socklen_t clilen;
fd_set rfds;
int maxfd = 0;
ssize_t i;
int ret;
cliaddr = (struct sockaddr *) safemalloc (addrlen);
cliaddr = (struct sockaddr *)
safemalloc (sizeof(struct sockaddr_storage));
if (!cliaddr) {
log_message (LOG_CRIT,
"Could not allocate memory for child address.");
@@ -196,11 +200,82 @@ static void child_main (struct child_s *ptr)
}
ptr->connects = 0;
srand(time(NULL));
/*
* We have to wait for connections on multiple fds,
* so use select.
*/
FD_ZERO(&rfds);
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
ret = socket_nonblocking(*fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the listening "
"socket %d to non-blocking: %s",
fd, strerror(errno));
exit(1);
}
FD_SET(*fd, &rfds);
maxfd = max(maxfd, *fd);
}
while (!config.quit) {
int listenfd = -1;
ptr->status = T_WAITING;
clilen = addrlen;
clilen = sizeof(struct sockaddr_storage);
ret = select(maxfd + 1, &rfds, NULL, NULL, NULL);
if (ret == -1) {
if (errno == EINTR) {
continue;
}
log_message (LOG_ERR, "error calling select: %s",
strerror(errno));
exit(1);
} else if (ret == 0) {
log_message (LOG_WARNING, "Strange: select returned 0 "
"but we did not specify a timeout...");
continue;
}
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
if (FD_ISSET(*fd, &rfds)) {
/*
* only accept the connection on the first
* fd that we find readable. - fair?
*/
listenfd = *fd;
break;
}
}
if (listenfd == -1) {
log_message(LOG_WARNING, "Strange: None of our listen "
"fds was readable after select");
continue;
}
ret = socket_blocking(listenfd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set listening "
"socket %d to blocking for accept: %s",
listenfd, strerror(errno));
exit(1);
}
/*
* We have a socket that is readable.
* Continue handling this connection.
*/
connfd = accept (listenfd, cliaddr, &clilen);
@@ -464,13 +539,66 @@ void child_kill_children (int sig)
}
}
int child_listening_sock (uint16_t port)
/**
* Listen on the various configured interfaces
*/
int child_listening_sockets(vector_t listen_addrs, uint16_t port)
{
listenfd = listen_sock (port, &addrlen);
return listenfd;
int ret;
ssize_t i;
assert (port > 0);
if (listen_fds == NULL) {
listen_fds = vector_create();
if (listen_fds == NULL) {
log_message (LOG_ERR, "Could not create the list "
"of listening fds");
return -1;
}
}
if ((listen_addrs == NULL) ||
(vector_length(listen_addrs) == 0))
{
/*
* no Listen directive:
* listen on the wildcard address(es)
*/
ret = listen_sock(NULL, port, listen_fds);
return ret;
}
for (i = 0; i < vector_length(listen_addrs); i++) {
const char *addr;
addr = (char *)vector_getentry(listen_addrs, i, NULL);
if (addr == NULL) {
log_message(LOG_WARNING,
"got NULL from listen_addrs - skipping");
continue;
}
ret = listen_sock(addr, port, listen_fds);
if (ret != 0) {
return ret;
}
}
return 0;
}
void child_close_sock (void)
{
close (listenfd);
ssize_t i;
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
close (*fd);
}
vector_delete(listen_fds);
listen_fds = NULL;
}
+3 -1
View File
@@ -21,6 +21,8 @@
#ifndef TINYPROXY_CHILD_H
#define TINYPROXY_CHILD_H
#include "vector.h"
typedef enum {
CHILD_MAXCLIENTS,
CHILD_MAXSPARESERVERS,
@@ -30,7 +32,7 @@ typedef enum {
} child_config_t;
extern short int child_pool_create (void);
extern int child_listening_sock (uint16_t port);
extern int child_listening_sockets (vector_t listen_addrs, uint16_t port);
extern void child_close_sock (void);
extern void child_main_loop (void);
extern void child_kill_children (int sig);
+41 -108
View File
@@ -32,135 +32,68 @@
/*
* Include standard headers which are used through-out tinyproxy
*/
#ifdef HAVE_SYS_TYPES_H
/* standard C headers - we can safely assume they exist. */
#include <stddef.h>
#include <stdint.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* standard POSIX headers - they need to be there as well. */
# include <errno.h>
# include <fcntl.h>
# include <netdb.h>
# include <signal.h>
# include <stdarg.h>
# include <strings.h>
# include <syslog.h>
# include <wchar.h>
# include <wctype.h>
# include <sys/mman.h>
# include <sys/select.h>
# include <sys/socket.h>
# include <sys/stat.h>
# include <sys/types.h>
#endif
# include <sys/wait.h>
# include <sys/uio.h>
# include <sys/un.h>
# include <sys/time.h>
# include <time.h>
# include <inttypes.h>
# include <sys/resource.h>
# include <netinet/in.h>
# include <assert.h>
# include <arpa/inet.h>
# include <grp.h>
# include <pwd.h>
# include <regex.h>
/* rest - some oddball headers */
#ifdef HAVE_VALUES_H
# include <values.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#endif
#ifdef HAVE_ASSERT_H
# include <assert.h>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_GRP_H
# include <grp.h>
#endif
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#ifdef HAVE_REGEX_H
# include <regex.h>
#endif
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_SYSEXITS_H
# include <sysexits.h>
#endif
#ifdef HAVE_SYSLOG_H
# include <syslog.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_WCHAR_H
# include <wchar.h>
#endif
#ifdef HAVE_WCTYPE_H
# include <wctype.h>
#endif
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
/*
* If MSG_NOSIGNAL is not defined, define it to be zero so that it doesn't
+120 -38
View File
@@ -36,6 +36,7 @@
#include "reverse-proxy.h"
#include "upstream.h"
#include "connect-ports.h"
#include "basicauth.h"
/*
* The configuration directives are defined in the structure below. Each
@@ -116,6 +117,7 @@ static HANDLE_FUNC (handle_nop)
} /* do nothing function */
static HANDLE_FUNC (handle_allow);
static HANDLE_FUNC (handle_basicauth);
static HANDLE_FUNC (handle_anonymous);
static HANDLE_FUNC (handle_bind);
static HANDLE_FUNC (handle_bindsame);
@@ -230,6 +232,7 @@ struct {
handle_deny),
STDCONF ("bind", "(" IP "|" IPV6 ")", handle_bind),
/* other */
STDCONF ("basicauth", ALNUM WS ALNUM, handle_basicauth),
STDCONF ("errorfile", INT WS STR, handle_errorfile),
STDCONF ("addheader", STR WS STR, handle_addheader),
@@ -249,13 +252,15 @@ struct {
STDCONF ("reversepath", STR "(" WS STR ")?", handle_reversepath),
#endif
#ifdef UPSTREAM_SUPPORT
/* upstream is rather complicated */
{
BEGIN "(no" WS "upstream)" WS STR END, handle_upstream_no, NULL
BEGIN "(upstream)" WS "(none)" WS STR END, handle_upstream_no, NULL
},
{
BEGIN "(upstream)" WS "(" IP "|" ALNUM ")" ":" INT "(" WS STR
")?" END, handle_upstream, NULL
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS
"(" ALNUM /*username*/ ":" ALNUM /*password*/ "@" ")?"
"(" IP "|" ALNUM ")"
":" INT "(" WS STR ")?"
END, handle_upstream, NULL
},
#endif
/* loglevel */
@@ -288,7 +293,8 @@ static void free_config (struct config_s *conf)
safefree (conf->stathost);
safefree (conf->user);
safefree (conf->group);
safefree (conf->ipAddr);
vector_delete(conf->listen_addrs);
vector_delete(conf->basicauth_list);
#ifdef FILTER_ENABLE
safefree (conf->filter);
#endif /* FILTER_ENABLE */
@@ -465,8 +471,18 @@ static void initialize_with_defaults (struct config_s *conf,
conf->group = safestrdup (defaults->group);
}
if (defaults->ipAddr) {
conf->ipAddr = safestrdup (defaults->ipAddr);
if (defaults->listen_addrs) {
ssize_t i;
conf->listen_addrs = vector_create();
for (i=0; i < vector_length(defaults->listen_addrs); i++) {
char *addr;
size_t size;
addr = (char *)vector_getentry(defaults->listen_addrs,
i, &size);
vector_append(conf->listen_addrs, addr, size);
}
}
#ifdef FILTER_ENABLE
@@ -759,12 +775,7 @@ static HANDLE_FUNC (handle_xtinyproxy)
static HANDLE_FUNC (handle_syslog)
{
#ifdef HAVE_SYSLOG_H
return set_bool_arg (&conf->syslog, line, &match[2]);
#else
fprintf (stderr, "Syslog support not compiled in executable.\n");
return 1;
#endif
}
static HANDLE_FUNC (handle_bindsame)
@@ -779,7 +790,15 @@ static HANDLE_FUNC (handle_bindsame)
static HANDLE_FUNC (handle_port)
{
return set_int_arg (&conf->port, line, &match[2]);
set_int_arg (&conf->port, line, &match[2]);
if (conf->port > 65535) {
fprintf (stderr, "Bad port number (%d) supplied for Port.\n",
conf->port);
return 1;
}
return 0;
}
static HANDLE_FUNC (handle_maxclients)
@@ -857,7 +876,6 @@ static HANDLE_FUNC (handle_deny)
static HANDLE_FUNC (handle_bind)
{
#ifndef TRANSPARENT_PROXY
int r = set_string_arg (&conf->bind_address, line, &match[2]);
if (r)
@@ -865,20 +883,31 @@ static HANDLE_FUNC (handle_bind)
log_message (LOG_INFO,
"Outgoing connections bound to IP %s", conf->bind_address);
return 0;
#else
fprintf (stderr,
"\"Bind\" cannot be used with transparent support enabled.\n");
return 1;
#endif
}
static HANDLE_FUNC (handle_listen)
{
int r = set_string_arg (&conf->ipAddr, line, &match[2]);
char *arg = get_string_arg (line, &match[2]);
if (r)
return r;
log_message (LOG_INFO, "Listening on IP %s", conf->ipAddr);
if (arg == NULL) {
return -1;
}
if (conf->listen_addrs == NULL) {
conf->listen_addrs = vector_create();
if (conf->listen_addrs == NULL) {
log_message(LOG_WARNING, "Could not create a list "
"of listen addresses.");
safefree(arg);
return -1;
}
}
vector_append (conf->listen_addrs, arg, strlen(arg) + 1);
log_message(LOG_INFO, "Added address [%s] to listen addresses.", arg);
safefree (arg);
return 0;
}
@@ -925,6 +954,7 @@ static HANDLE_FUNC (handle_addheader)
/*
* Log level's strings.
*/
struct log_levels_s {
const char *string;
@@ -959,6 +989,27 @@ static HANDLE_FUNC (handle_loglevel)
return -1;
}
static HANDLE_FUNC (handle_basicauth)
{
char *user, *pass;
user = get_string_arg(line, &match[2]);
if (!user)
return -1;
pass = get_string_arg(line, &match[3]);
if (!pass) {
safefree (user);
return -1;
}
if (!conf->basicauth_list) {
conf->basicauth_list = vector_create ();
}
basicauth_add (conf->basicauth_list, user, pass);
safefree (user);
safefree (pass);
return 0;
}
#ifdef FILTER_ENABLE
static HANDLE_FUNC (handle_filter)
{
@@ -1035,27 +1086,58 @@ static HANDLE_FUNC (handle_reversepath)
#endif
#ifdef UPSTREAM_SUPPORT
static enum proxy_type pt_from_string(const char *s)
{
static const char pt_map[][7] = {
[PT_NONE] = "none",
[PT_HTTP] = "http",
[PT_SOCKS4] = "socks4",
[PT_SOCKS5] = "socks5",
};
unsigned i;
for (i = 0; i < sizeof(pt_map)/sizeof(pt_map[0]); i++)
if (!strcmp(pt_map[i], s))
return i;
return PT_NONE;
}
static HANDLE_FUNC (handle_upstream)
{
char *ip;
int port;
char *domain;
int port, mi = 2;
char *domain = 0, *user = 0, *pass = 0, *tmp;
enum proxy_type pt;
ip = get_string_arg (line, &match[2]);
tmp = get_string_arg (line, &match[mi]);
pt = pt_from_string(tmp);
safefree(tmp);
mi += 2;
if (match[mi].rm_so != -1)
user = get_string_arg (line, &match[mi]);
mi++;
if (match[mi].rm_so != -1)
pass = get_string_arg (line, &match[mi]);
mi++;
ip = get_string_arg (line, &match[mi]);
if (!ip)
return -1;
port = (int) get_long_arg (line, &match[7]);
mi += 5;
if (match[9].rm_so != -1) {
domain = get_string_arg (line, &match[9]);
if (domain) {
upstream_add (ip, port, domain, &conf->upstream_list);
port = (int) get_long_arg (line, &match[mi]);
mi += 3;
if (match[mi].rm_so != -1)
domain = get_string_arg (line, &match[mi]);
upstream_add (ip, port, domain, user, pass, pt, &conf->upstream_list);
safefree (user);
safefree (pass);
safefree (domain);
}
} else {
upstream_add (ip, port, NULL, &conf->upstream_list);
}
safefree (ip);
return 0;
@@ -1065,11 +1147,11 @@ static HANDLE_FUNC (handle_upstream_no)
{
char *domain;
domain = get_string_arg (line, &match[2]);
domain = get_string_arg (line, &match[3]);
if (!domain)
return -1;
upstream_add (NULL, 0, domain, &conf->upstream_list);
upstream_add (NULL, 0, domain, 0, 0, PT_NONE, &conf->upstream_list);
safefree (domain);
return 0;
+2 -1
View File
@@ -37,6 +37,7 @@ typedef struct {
* Hold all the configuration time information.
*/
struct config_s {
vector_t basicauth_list;
char *logf_name;
char *config_file;
unsigned int syslog; /* boolean */
@@ -46,7 +47,7 @@ struct config_s {
unsigned int quit; /* boolean */
char *user;
char *group;
char *ipAddr;
vector_t listen_addrs;
#ifdef FILTER_ENABLE
char *filter;
unsigned int filter_url; /* boolean */
+1 -1
View File
@@ -38,7 +38,7 @@ void add_connect_port_allowed (int port, vector_t *connect_ports)
log_message (LOG_INFO,
"Adding Port [%d] to the list allowed by CONNECT", port);
vector_append (*connect_ports, (void **) &port, sizeof (port));
vector_append (*connect_ports, &port, sizeof (port));
}
/*
+33 -11
View File
@@ -50,6 +50,7 @@ struct hashbucket_s {
};
struct hashmap_s {
uint32_t seed;
unsigned int size;
hashmap_iter end_iterator;
@@ -63,9 +64,12 @@ struct hashmap_s {
* The contents of the key are converted to lowercase, so this function
* is not case-sensitive.
*
* This is Dan Bernstein's hash function as described, for example, here:
* http://www.cse.yorku.ca/~oz/hash.html
*
* If any of the arguments are invalid a negative number is returned.
*/
static int hashfunc (const char *key, unsigned int size)
static int hashfunc (const char *key, unsigned int size, uint32_t seed)
{
uint32_t hash;
@@ -74,12 +78,8 @@ static int hashfunc (const char *key, unsigned int size)
if (size == 0)
return -ERANGE;
for (hash = tolower (*key++); *key != '\0'; key++) {
uint32_t bit = (hash & 1) ? (1 << (sizeof (uint32_t) - 1)) : 0;
hash >>= 1;
hash += tolower (*key) + bit;
for (hash = seed; *key != '\0'; key++) {
hash = ((hash << 5) + hash) ^ tolower (*key);
}
/* Keep the hash within the table limits */
@@ -104,6 +104,7 @@ hashmap_t hashmap_create (unsigned int nbuckets)
if (!ptr)
return NULL;
ptr->seed = (uint32_t)rand();
ptr->size = nbuckets;
ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets,
sizeof (struct
@@ -201,7 +202,7 @@ hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
if (!data || len < 1)
return -ERANGE;
hash = hashfunc (key, map->size);
hash = hashfunc (key, map->size, map->seed);
if (hash < 0)
return hash;
@@ -382,7 +383,7 @@ ssize_t hashmap_search (hashmap_t map, const char *key)
if (map == NULL || key == NULL)
return -EINVAL;
hash = hashfunc (key, map->size);
hash = hashfunc (key, map->size, map->seed);
if (hash < 0)
return hash;
@@ -416,7 +417,7 @@ ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, void **data)
if (!map || !key || !data)
return -EINVAL;
hash = hashfunc (key, map->size);
hash = hashfunc (key, map->size, map->seed);
if (hash < 0)
return hash;
@@ -451,7 +452,7 @@ ssize_t hashmap_remove (hashmap_t map, const char *key)
if (map == NULL || key == NULL)
return -EINVAL;
hash = hashfunc (key, map->size);
hash = hashfunc (key, map->size, map->seed);
if (hash < 0)
return hash;
@@ -492,3 +493,24 @@ ssize_t hashmap_remove (hashmap_t map, const char *key)
/* The key was not found, so return 0 */
return deleted;
}
/*
* Look up the value for a variable.
*/
char *lookup_variable (hashmap_t map, const char *varname)
{
hashmap_iter result_iter;
char *key;
char *data;
result_iter = hashmap_find (map, varname);
if (hashmap_is_end (map, result_iter))
return (NULL);
if (hashmap_return_entry (map, result_iter,
&key, (void **) &data) < 0)
return (NULL);
return (data);
}
+5
View File
@@ -117,4 +117,9 @@ extern ssize_t hashmap_search (hashmap_t map, const char *key);
*/
extern ssize_t hashmap_remove (hashmap_t map, const char *key);
/*
* Look up the value for a variable.
*/
extern char *lookup_variable (hashmap_t map, const char *varname);
#endif /* _HASHMAP_H */
+19 -28
View File
@@ -62,7 +62,7 @@ static char *get_html_file (unsigned int errornum)
hashmap_iter result_iter;
char errornbuf[ERRORNUM_BUFSIZE];
char *key;
static char *val;
char *val;
assert (errornum >= 100 && errornum < 1000);
@@ -83,27 +83,6 @@ static char *get_html_file (unsigned int errornum)
return (val);
}
/*
* Look up the value for a variable.
*/
static char *lookup_variable (struct conn_s *connptr, const char *varname)
{
hashmap_iter result_iter;
char *key;
static char *data;
result_iter = hashmap_find (connptr->error_variables, varname);
if (hashmap_is_end (connptr->error_variables, result_iter))
return (NULL);
if (hashmap_return_entry (connptr->error_variables, result_iter,
&key, (void **) &data) < 0)
return (NULL);
return (data);
}
/*
* Send an already-opened file to the client with variable substitution.
*/
@@ -126,7 +105,7 @@ send_html_file (FILE *infile, struct conn_s *connptr)
if (in_variable) {
*p = '\0';
varval = (const char *)
lookup_variable (connptr,
lookup_variable (connptr->error_variables,
varstart);
if (!varval)
varval = "(unknown)";
@@ -153,6 +132,7 @@ send_html_file (FILE *infile, struct conn_s *connptr)
} else
in_variable = 0;
/* FALL THROUGH */
default:
if (!in_variable) {
r = write_message (connptr->client_fd,
@@ -177,13 +157,24 @@ send_html_file (FILE *infile, struct conn_s *connptr)
int send_http_headers (struct conn_s *connptr, int code, const char *message)
{
const char *headers =
const char headers[] =
"HTTP/1.0 %d %s\r\n"
"Server: %s/%s\r\n"
"Content-Type: text/html\r\n" "Connection: close\r\n" "\r\n";
"Content-Type: text/html\r\n"
"%s"
"Connection: close\r\n" "\r\n";
const char auth_str[] =
"Proxy-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 ? auth_str : "";
return (write_message (connptr->client_fd, headers,
code, message, PACKAGE, VERSION));
code, message, PACKAGE, VERSION,
add));
}
/*
@@ -212,7 +203,7 @@ int send_http_error_message (struct conn_s *connptr)
error_file = get_html_file (connptr->error_number);
if (!(infile = fopen (error_file, "r"))) {
char *detail = lookup_variable (connptr, "detail");
char *detail = lookup_variable (connptr->error_variables, "detail");
return (write_message (connptr->client_fd, fallback_error,
connptr->error_number,
connptr->error_string,
@@ -280,7 +271,7 @@ int add_standard_vars (struct conn_s *connptr)
add_error_variable (connptr, "date", timebuf);
add_error_variable (connptr, "website",
"https://www.banu.com/tinyproxy/");
"https://tinyproxy.github.io/");
add_error_variable (connptr, "version", VERSION);
add_error_variable (connptr, "package", PACKAGE);
+21 -6
View File
@@ -70,7 +70,14 @@ static unsigned int logging_initialized = FALSE; /* boolean */
*/
int open_log_file (const char *log_file_name)
{
if (log_file_name == NULL) {
if(config.godaemon == FALSE)
log_file_fd = fileno(stdout);
else
log_file_fd = -1;
} else {
log_file_fd = create_file_safely (log_file_name, FALSE);
}
return log_file_fd;
}
@@ -79,7 +86,7 @@ int open_log_file (const char *log_file_name)
*/
void close_log_file (void)
{
if (log_file_fd < 0) {
if (log_file_fd < 0 || log_file_fd == fileno(stdout)) {
return;
}
@@ -154,6 +161,9 @@ void log_message (int level, const char *fmt, ...)
goto out;
}
if(!config.syslog && log_file_fd == -1)
goto out;
if (config.syslog) {
#ifdef HAVE_VSYSLOG_H
vsyslog (level, fmt, args);
@@ -188,8 +198,13 @@ void log_message (int level, const char *fmt, ...)
ret = write (log_file_fd, str, strlen (str));
if (ret == -1) {
log_message (LOG_WARNING,
"Could not write to log file");
config.syslog = TRUE;
log_message(LOG_CRIT, "ERROR: Could not write to log "
"file %s: %s.",
config.logf_name, strerror(errno));
log_message(LOG_CRIT,
"Falling back to syslog logging");
}
fsync (log_file_fd);
@@ -202,7 +217,7 @@ out:
/*
* This needs to send any stored log messages.
*/
void send_stored_logs (void)
static void send_stored_logs (void)
{
char *string;
char *ptr;
@@ -258,10 +273,10 @@ int setup_logging (void)
config.syslog = TRUE;
log_message (LOG_CRIT, "ERROR: Could not create log "
"file %s: %s.\n",
"file %s: %s.",
config.logf_name, strerror (errno));
log_message (LOG_CRIT,
"Falling back to syslog logging\n");
"Falling back to syslog logging.");
}
}
-10
View File
@@ -77,16 +77,7 @@
* don't advocate this, but it could be useful at times.)
*/
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
# define LOG_CRIT 2
# define LOG_ERR 3
# define LOG_WARNING 4
# define LOG_NOTICE 5
# define LOG_INFO 6
# define LOG_DEBUG 7
#endif
#define LOG_CONN 8 /* extra to log connections without the INFO stuff */
@@ -115,7 +106,6 @@ extern void close_log_file (void);
extern void log_message (int level, const char *fmt, ...);
extern void set_log_level (int level);
extern void send_stored_logs (void);
extern int setup_logging (void);
extern void shutdown_logging (void);
+33 -54
View File
@@ -86,37 +86,6 @@ display_version (void)
printf ("%s %s\n", PACKAGE, VERSION);
}
/*
* Display the copyright and license for this program.
*/
static void
display_license (void)
{
display_version ();
printf ("\
Copyright 1998 Steven Young (sdyoung@well.com)\n\
Copyright 1998-2002 Robert James Kaes (rjkaes@users.sourceforge.net)\n\
Copyright 1999 George Talusan (gstalusan@uwaterloo.ca)\n\
Copyright 2000 Chris Lightfoot (chris@ex-parrot.com)\n\
Copyright 2009-2010 Mukund Sivaraman (muks@banu.com)\n\
Copyright 2009-2010 Michael Adam (obnox@samba.org)\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation; either version 2, or (at your option)\n\
any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n");
}
/*
* Display usage to the user.
*/
@@ -131,7 +100,6 @@ display_usage (void)
" -d Do not daemonize (run in foreground).\n"
" -c FILE Use an alternate configuration file.\n"
" -h Display this usage information.\n"
" -l Display the license.\n"
" -v Display version information.\n");
/* Display the modes compiled into tinyproxy */
@@ -171,8 +139,8 @@ display_usage (void)
printf (" None\n");
printf ("\n"
"For bug reporting instructions, please see:\n"
"<https://www.banu.com/tinyproxy/>.\n");
"For support and bug reporting instructions, please visit\n"
"<https://tinyproxy.github.io/>.\n");
}
static int
@@ -205,16 +173,12 @@ process_cmdline (int argc, char **argv, struct config_s *conf)
{
int opt;
while ((opt = getopt (argc, argv, "c:vldh")) != EOF) {
while ((opt = getopt (argc, argv, "c:vdh")) != EOF) {
switch (opt) {
case 'v':
display_version ();
exit (EX_OK);
case 'l':
display_license ();
exit (EX_OK);
case 'd':
conf->godaemon = FALSE;
break;
@@ -277,6 +241,16 @@ change_user (const char *program)
exit (EX_NOPERM);
}
#ifdef HAVE_SETGROUPS
/* Drop all supplementary groups, otherwise these are inherited from the calling process */
if (setgroups (0, NULL) < 0) {
fprintf (stderr,
"%s: Unable to drop supplementary groups.\n",
program);
exit (EX_NOPERM);
}
#endif
log_message (LOG_INFO, "Now running as group \"%s\".",
config.group);
}
@@ -326,8 +300,8 @@ static void initialize_config_defaults (struct config_s *conf)
conf->errorpages = NULL;
conf->stathost = safestrdup (TINYPROXY_STATHOST);
conf->idletimeout = MAX_IDLE_TIME;
conf->logf_name = safestrdup (LOCALSTATEDIR "/log/tinyproxy/tinyproxy.log");
conf->pidpath = safestrdup (LOCALSTATEDIR "/run/tinyproxy/tinyproxy.pid");
conf->logf_name = NULL;
conf->pidpath = NULL;
}
/**
@@ -386,8 +360,13 @@ main (int argc, char **argv)
anonymous_insert ("Content-Type");
}
if (config.godaemon == TRUE)
if (config.godaemon == TRUE) {
if (!config.syslog && config.logf_name == NULL)
fprintf(stderr, "WARNING: logging deactivated "
"(can't log to stdout when daemonized)\n");
makedaemon ();
}
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
@@ -401,12 +380,21 @@ main (int argc, char **argv)
#endif /* FILTER_ENABLE */
/* Start listening on the selected port. */
if (child_listening_sock (config.port) < 0) {
fprintf (stderr, "%s: Could not create listening socket.\n",
if (child_listening_sockets(config.listen_addrs, config.port) < 0) {
fprintf (stderr, "%s: Could not create listening sockets.\n",
argv[0]);
exit (EX_OSERR);
}
/* Create pid file before we drop privileges */
if (config.pidpath) {
if (pidfile_create (config.pidpath) < 0) {
fprintf (stderr, "%s: Could not create PID file.\n",
argv[0]);
exit (EX_OSERR);
}
}
/* Switch to a different user if we're running as root */
if (geteuid () == 0)
change_user (argv[0]);
@@ -419,15 +407,6 @@ main (int argc, char **argv)
exit (EX_SOFTWARE);
}
/* Create pid file after we drop privileges */
if (config.pidpath) {
if (pidfile_create (config.pidpath) < 0) {
fprintf (stderr, "%s: Could not create PID file.\n",
argv[0]);
exit (EX_OSERR);
}
}
if (child_pool_create () < 0) {
fprintf (stderr,
"%s: Could not create the pool of children.\n",
@@ -467,7 +446,7 @@ main (int argc, char **argv)
child_close_sock ();
/* Remove the PID file */
if (unlink (config.pidpath) < 0) {
if (config.pidpath != NULL && unlink (config.pidpath) < 0) {
log_message (LOG_WARNING,
"Could not remove PID file \"%s\": %s.",
config.pidpath, strerror (errno));
+16 -7
View File
@@ -32,10 +32,11 @@
* Write the buffer to the socket. If an EINTR occurs, pick up and try
* again. Keep sending until the buffer has been sent.
*/
ssize_t safe_write (int fd, const char *buffer, size_t count)
ssize_t safe_write (int fd, const void *buf, size_t count)
{
ssize_t len;
size_t bytestosend;
const char *buffer = buf;
assert (fd >= 0);
assert (buffer != NULL);
@@ -67,7 +68,7 @@ ssize_t safe_write (int fd, const char *buffer, size_t count)
* Matched pair for safe_write(). If an EINTR occurs, pick up and try
* again.
*/
ssize_t safe_read (int fd, char *buffer, size_t count)
ssize_t safe_read (int fd, void *buffer, size_t count)
{
ssize_t len;
@@ -191,7 +192,11 @@ ssize_t readline (int fd, char **whole_buffer)
goto CLEANUP;
}
recv (fd, line_ptr->data, diff, 0);
ret = recv (fd, line_ptr->data, diff, 0);
if (ret == -1) {
goto CLEANUP;
}
line_ptr->len = diff;
if (ptr) {
@@ -245,8 +250,10 @@ CLEANUP:
* Convert the network address into either a dotted-decimal or an IPv6
* hex string.
*/
char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{
const char *result;
assert (sa != NULL);
assert (buf != NULL);
assert (buflen != 0);
@@ -257,7 +264,8 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
inet_ntop (AF_INET, &sa_in->sin_addr, buf, buflen);
result = inet_ntop (AF_INET, &sa_in->sin_addr, buf,
buflen);
break;
}
case AF_INET6:
@@ -265,7 +273,8 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
struct sockaddr_in6 *sa_in6 =
(struct sockaddr_in6 *) sa;
inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, buflen);
result = inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf,
buflen);
break;
}
default:
@@ -273,7 +282,7 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
return NULL;
}
return buf;
return result;
}
/*
+3 -3
View File
@@ -21,13 +21,13 @@
#ifndef TINYPROXY_NETWORK_H
#define TINYPROXY_NETWORK_H
extern ssize_t safe_write (int fd, const char *buffer, size_t count);
extern ssize_t safe_read (int fd, char *buffer, size_t count);
extern ssize_t safe_write (int fd, const void *buf, size_t count);
extern ssize_t safe_read (int fd, void *buf, size_t count);
extern int write_message (int fd, const char *fmt, ...);
extern ssize_t readline (int fd, char **whole_buffer);
extern char *get_ip_string (struct sockaddr *sa, char *buf, size_t len);
extern const char *get_ip_string (struct sockaddr *sa, char *buf, size_t len);
extern int full_inet_pton (const char *ip, void *dst);
#endif
+285 -62
View File
@@ -48,6 +48,7 @@
#include "upstream.h"
#include "connect-ports.h"
#include "conf.h"
#include "basicauth.h"
/*
* Maximum length of a HTTP line
@@ -61,9 +62,11 @@
#ifdef UPSTREAM_SUPPORT
# define UPSTREAM_CONFIGURED() (config.upstream_list != NULL)
# define UPSTREAM_HOST(host) upstream_get(host, config.upstream_list)
# define UPSTREAM_IS_HTTP(conn) (conn->upstream_proxy != NULL && conn->upstream_proxy->type == PT_HTTP)
#else
# define UPSTREAM_CONFIGURED() (0)
# define UPSTREAM_HOST(host) (NULL)
# define UPSTREAM_IS_HTTP(up) (0)
#endif
/*
@@ -167,12 +170,18 @@ static void strip_username_password (char *host)
static int strip_return_port (char *host)
{
char *ptr1;
char *ptr2;
int port;
ptr1 = strchr (host, ':');
ptr1 = strrchr (host, ':');
if (ptr1 == NULL)
return 0;
/* Check for IPv6 style literals */
ptr2 = strchr (ptr1, ']');
if (ptr2 != NULL)
return 0;
*ptr1++ = '\0';
if (sscanf (ptr1, "%d", &port) != 1) /* one conversion required */
return 0;
@@ -180,18 +189,22 @@ static int strip_return_port (char *host)
}
/*
* Pull the information out of the URL line. This will handle both HTTP
* and FTP (proxied) URLs.
* Pull the information out of the URL line.
* This expects urls with the initial '<proto>://'
* part stripped and hence can handle http urls,
* (proxied) ftp:// urls and https-requests that
* come in without the proto:// part via CONNECT.
*/
static int extract_http_url (const char *url, struct request_s *request)
static int extract_url (const char *url, int default_port,
struct request_s *request)
{
char *p;
int len;
int port;
/* Split the URL on the slash to separate host from path */
p = strchr (url, '/');
if (p != NULL) {
int len;
len = p - url;
request->host = (char *) safemalloc (len + 1);
memcpy (request->host, url, len);
@@ -210,7 +223,17 @@ static int extract_http_url (const char *url, struct request_s *request)
/* Find a proper port in www.site.com:8001 URLs */
port = strip_return_port (request->host);
request->port = (port != 0) ? port : HTTP_PORT;
request->port = (port != 0) ? port : default_port;
/* Remove any surrounding '[' and ']' from IPv6 literals */
p = strrchr (request->host, ']');
if (p && (*(request->host) == '[')) {
memmove(request->host, request->host + 1,
strlen(request->host) - 2);
*p = '\0';
p--;
*p = '\0';
}
return 0;
@@ -223,31 +246,6 @@ ERROR_EXIT:
return -1;
}
/*
* Extract the URL from a SSL connection.
*/
static int extract_ssl_url (const char *url, struct request_s *request)
{
request->host = (char *) safemalloc (strlen (url) + 1);
if (!request->host)
return -1;
if (sscanf (url, "%[^:]:%hu", request->host, &request->port) == 2) ;
else if (sscanf (url, "%s", request->host) == 1)
request->port = HTTP_PORT_SSL;
else {
log_message (LOG_ERR, "extract_ssl_url: Can't parse URL.");
safefree (request->host);
return -1;
}
/* Remove the username/password if they're present */
strip_username_password (request->host);
return 0;
}
/*
* Create a connection for HTTP connections.
*/
@@ -255,6 +253,7 @@ static int
establish_http_connection (struct conn_s *connptr, struct request_s *request)
{
char portbuff[7];
char dst[sizeof(struct in6_addr)];
/* Build a port string if it's not a standard port */
if (request->port != HTTP_PORT && request->port != HTTP_PORT_SSL)
@@ -262,6 +261,27 @@ establish_http_connection (struct conn_s *connptr, struct request_s *request)
else
portbuff[0] = '\0';
if (inet_pton(AF_INET6, request->host, dst) > 0) {
/* host is an IPv6 address literal, so surround it with
* [] */
return write_message (connptr->server_fd,
"%s %s HTTP/1.0\r\n"
"Host: [%s]%s\r\n"
"Connection: close\r\n",
request->method, request->path,
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"
"Host: %s%s\r\n"
"Connection: close\r\n"
"Proxy-Authorization: Basic %s\r\n",
request->method, request->path,
request->host, portbuff,
connptr->upstream_proxy->ua.authstr);
} else {
return write_message (connptr->server_fd,
"%s %s HTTP/1.0\r\n"
"Host: %s%s\r\n"
@@ -269,6 +289,7 @@ establish_http_connection (struct conn_s *connptr, struct request_s *request)
request->method, request->path,
request->host, portbuff);
}
}
/*
* These two defines are for the SSL tunnelling.
@@ -350,15 +371,6 @@ BAD_REQUEST_ERROR:
goto fail;
}
if (!url) {
log_message (LOG_ERR,
"process_request: Null URL on file descriptor %d",
connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Request has an empty URL",
"url", url, NULL);
goto fail;
}
#ifdef REVERSE_SUPPORT
if (config.reversepath_list != NULL) {
/*
@@ -371,12 +383,18 @@ BAD_REQUEST_ERROR:
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
if (!reverse_url) {
goto fail;
}
if (reverse_url != NULL) {
safefree (url);
url = reverse_url;
} else if (config.reverseonly) {
log_message (LOG_ERR,
"Bad request, no mapping for '%s' found",
url);
indicate_http_error (connptr, 400, "Bad Request",
"detail", "No mapping found for "
"requested url", "url", url, NULL);
goto fail;
}
}
#endif
@@ -385,14 +403,14 @@ BAD_REQUEST_ERROR:
{
char *skipped_type = strstr (url, "//") + 2;
if (extract_http_url (skipped_type, request) < 0) {
if (extract_url (skipped_type, HTTP_PORT, request) < 0) {
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Could not parse URL",
"url", url, NULL);
goto fail;
}
} else if (strcmp (request->method, "CONNECT") == 0) {
if (extract_ssl_url (url, request) < 0) {
if (extract_url (url, HTTP_PORT_SSL, request) < 0) {
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Could not parse URL",
"url", url, NULL);
@@ -418,7 +436,7 @@ BAD_REQUEST_ERROR:
} else {
#ifdef TRANSPARENT_PROXY
if (!do_transparent_proxy
(connptr, hashofheaders, request, &config, url)) {
(connptr, hashofheaders, request, &config, &url)) {
goto fail;
}
#else
@@ -493,6 +511,7 @@ static int pull_client_data (struct conn_s *connptr, long int length)
{
char *buffer;
ssize_t len;
int ret;
buffer =
(char *) safemalloc (min (MAXBUFFSIZE, (unsigned long int) length));
@@ -518,18 +537,30 @@ static int pull_client_data (struct conn_s *connptr, long int length)
* return and line feed) at the end of a POST message. These
* need to be eaten for tinyproxy to work correctly.
*/
socket_nonblocking (connptr->client_fd);
ret = socket_nonblocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket "
"to non-blocking: %s", strerror(errno));
goto ERROR_EXIT;
}
len = recv (connptr->client_fd, buffer, 2, MSG_PEEK);
socket_blocking (connptr->client_fd);
ret = socket_blocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket "
"to blocking: %s", strerror(errno));
goto ERROR_EXIT;
}
if (len < 0 && errno != EAGAIN)
goto ERROR_EXIT;
if ((len == 2) && CHECK_CRLF (buffer, len)) {
ssize_t ret;
ssize_t bytes_read;
ret = read (connptr->client_fd, buffer, 2);
if (ret == -1) {
bytes_read = read (connptr->client_fd, buffer, 2);
if (bytes_read == -1) {
log_message
(LOG_WARNING,
"Could not read two bytes from POST message");
@@ -585,6 +616,13 @@ add_header_to_connection (hashmap_t hashofheaders, char *header, size_t len)
return hashmap_insert (hashofheaders, header, sep, len);
}
/*
* Define maximum number of headers that we accept.
* This should be big enough to handle legitimate cases,
* but limited to avoid DoS.
*/
#define MAX_HEADERS 10000
/*
* Read all the headers from the stream
*/
@@ -592,6 +630,7 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
{
char *line = NULL;
char *header = NULL;
int count;
char *tmp;
ssize_t linelen;
ssize_t len = 0;
@@ -600,7 +639,7 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
assert (fd >= 0);
assert (hashofheaders != NULL);
for (;;) {
for (count = 0; count < MAX_HEADERS; count++) {
if ((linelen = readline (fd, &line)) <= 0) {
safefree (header);
safefree (line);
@@ -666,6 +705,14 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
safefree (line);
}
/*
* If we get here, this means we reached MAX_HEADERS count.
* Bail out with error.
*/
safefree (header);
safefree (line);
return -1;
}
/*
@@ -792,7 +839,7 @@ done:
/*
* Number of buckets to use internally in the hashmap.
*/
#define HEADER_BUCKETS 32
#define HEADER_BUCKETS 256
/*
* Here we loop through all the headers the client is sending. If we
@@ -820,10 +867,10 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
/*
* Don't send headers if there's already an error, if the request was
* a stats request, or if this was a CONNECT method (unless upstream
* proxy is in use.)
* http proxy is in use.)
*/
if (connptr->server_fd == -1 || connptr->show_stats
|| (connptr->connect_method && (connptr->upstream_proxy == NULL))) {
|| (connptr->connect_method && ! UPSTREAM_IS_HTTP(connptr))) {
log_message (LOG_INFO,
"Not sending client headers to remote machine");
return 0;
@@ -1112,8 +1159,19 @@ static void relay_connection (struct conn_s *connptr)
int maxfd = max (connptr->client_fd, connptr->server_fd) + 1;
ssize_t bytes_received;
socket_nonblocking (connptr->client_fd);
socket_nonblocking (connptr->server_fd);
ret = socket_nonblocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket "
"to non-blocking: %s", strerror(errno));
return;
}
ret = socket_nonblocking (connptr->server_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the server socket "
"to non-blocking: %s", strerror(errno));
return;
}
last_access = time (NULL);
@@ -1188,7 +1246,14 @@ static void relay_connection (struct conn_s *connptr)
* Here the server has closed the connection... write the
* remainder to the client and then exit.
*/
socket_blocking (connptr->client_fd);
ret = socket_blocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR,
"Failed to set client socket to blocking: %s",
strerror(errno));
return;
}
while (buffer_size (connptr->sbuffer) > 0) {
if (write_buffer (connptr->client_fd, connptr->sbuffer) < 0)
break;
@@ -1198,7 +1263,14 @@ static void relay_connection (struct conn_s *connptr)
/*
* Try to send any remaining data to the server if we can.
*/
socket_blocking (connptr->server_fd);
ret = socket_blocking (connptr->server_fd);
if (ret != 0) {
log_message(LOG_ERR,
"Failed to set server socket to blocking: %s",
strerror(errno));
return;
}
while (buffer_size (connptr->cbuffer) > 0) {
if (write_buffer (connptr->server_fd, connptr->cbuffer) < 0)
break;
@@ -1207,6 +1279,122 @@ static void relay_connection (struct conn_s *connptr)
return;
}
static int
connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
{
unsigned len;
unsigned char buff[512]; /* won't use more than 7 + 255 */
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;
passlen = cur_upstream->pass ? strlen(cur_upstream->pass) : 0;
log_message(LOG_CONN,
"Established connection to %s proxy \"%s\" using file descriptor %d.",
proxy_type_name(cur_upstream->type), cur_upstream->host, connptr->server_fd);
if (cur_upstream->type == PT_SOCKS4) {
buff[0] = 4; /* socks version */
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))
return -1;
if (8 != safe_read(connptr->server_fd, buff, 8))
return -1;
if (buff[0]!=0 || buff[1]!=90)
return -1;
} else if (cur_upstream->type == PT_SOCKS5) {
/* init */
int n_methods = ulen ? 2 : 1;
buff[0] = 5; /* socks version */
buff[1] = n_methods; /* number of methods */
buff[2] = 0; /* no auth method */
if (ulen) buff[3] = 2; /* auth method -> username / password */
if (2+n_methods != safe_write(connptr->server_fd, buff, 2+n_methods))
return -1;
if (2 != safe_read(connptr->server_fd, buff, 2))
return -1;
if (buff[0] != 5 || (buff[1] != 0 && buff[1] != 2))
return -1;
if (buff[1] == 2) {
/* authentication */
char in[2];
char out[515];
char *cur = out;
size_t c;
*cur++ = 1; /* version */
c = ulen & 0xFF;
*cur++ = c;
memcpy(cur, cur_upstream->ua.user, c);
cur += c;
c = passlen & 0xFF;
*cur++ = c;
memcpy(cur, cur_upstream->pass, c);
cur += c;
if((cur - out) != safe_write(connptr->server_fd, out, cur - out))
return -1;
if(2 != safe_read(connptr->server_fd, in, 2))
return -1;
if(in[1] != 0 || !(in[0] == 5 || in[0] == 1)) {
return -1;
}
}
/* connect */
buff[0] = 5; /* socks version */
buff[1] = 1; /* connect */
buff[2] = 0; /* reserved */
buff[3] = 3; /* domainname */
len=strlen(request->host);
if(len>255)
return -1;
buff[4] = len; /* length of domainname */
memcpy(&buff[5], request->host, len); /* dest ip */
port = htons(request->port);
memcpy(&buff[5+len], &port, 2); /* dest port */
if (7+len != safe_write(connptr->server_fd, buff, 7+len))
return -1;
if (4 != safe_read(connptr->server_fd, buff, 4))
return -1;
if (buff[0]!=5 || buff[1]!=0)
return -1;
switch(buff[3]) {
case 1: len=4; break; /* ip v4 */
case 4: len=16; break; /* ip v6 */
case 3: /* domainname */
if (1 != safe_read(connptr->server_fd, buff, 1))
return -1;
len = buff[0]; /* max = 255 */
break;
default: return -1;
}
if (2+len != safe_read(connptr->server_fd, buff, 2+len))
return -1;
} else {
return -1;
}
if (connptr->connect_method)
return 0;
return establish_http_connection(connptr, request);
}
/*
* Establish a connection to the upstream proxy server.
*/
@@ -1250,6 +1438,9 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
return -1;
}
if (cur_upstream->type != PT_HTTP)
return connect_to_upstream_proxy(connptr, request);
log_message (LOG_CONN,
"Established connection to upstream proxy \"%s\" "
"using file descriptor %d.",
@@ -1313,7 +1504,7 @@ get_request_entity(struct conn_s *connptr)
nread = read_buffer (connptr->client_fd, connptr->cbuffer);
if (nread < 0) {
log_message (LOG_ERR,
"Error reading readble client_fd %d",
"Error reading readable client_fd %d",
connptr->client_fd);
ret = -1;
} else {
@@ -1417,6 +1608,38 @@ void handle_connection (int fd)
goto fail;
}
if (config.basicauth_list != NULL) {
ssize_t len;
char *authstring;
int failure = 1;
len = hashmap_entry_by_key (hashofheaders, "proxy-authorization",
(void **) &authstring);
if (len == 0) {
update_stats (STAT_DENIED);
indicate_http_error (connptr, 407, "Proxy Authentication Required",
"detail",
"This proxy requires authentication.",
NULL);
goto fail;
}
if ( /* currently only "basic" auth supported */
(strncmp(authstring, "Basic ", 6) == 0 ||
strncmp(authstring, "basic ", 6) == 0) &&
basicauth_check (config.basicauth_list, authstring + 6) == 1)
failure = 0;
if(failure) {
update_stats (STAT_DENIED);
indicate_http_error (connptr, 401, "Unauthorized",
"detail",
"The administrator of this proxy has not configured "
"it to service requests from you.",
NULL);
goto fail;
}
hashmap_remove (hashofheaders, "proxy-authorization");
}
/*
* Add any user-specified headers (AddHeader directive) to the
* outgoing HTTP request.
@@ -1469,7 +1692,7 @@ void handle_connection (int fd)
goto fail;
}
if (!(connptr->connect_method && (connptr->upstream_proxy == NULL))) {
if (!connptr->connect_method || UPSTREAM_IS_HTTP(connptr)) {
if (process_server_headers (connptr) < 0) {
update_stats (STAT_BADCONN);
goto fail;
+1 -7
View File
@@ -156,13 +156,7 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
}
}
/* Forward proxy support off and no reverse path match found */
if (config.reverseonly && !rewrite_url) {
log_message (LOG_ERR, "Bad request");
indicate_http_error (connptr, 400, "Bad Request",
"detail",
"Request has an invalid URL", "url", url,
NULL);
if (rewrite_url == NULL) {
return NULL;
}
+113 -39
View File
@@ -84,6 +84,9 @@ int opensock (const char *host, int port, const char *bind_to)
assert (host != NULL);
assert (port > 0);
log_message(LOG_INFO,
"opensock: opening connection to %s:%d", host, port);
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
@@ -97,6 +100,9 @@ int opensock (const char *host, int port, const char *bind_to)
return -1;
}
log_message(LOG_INFO,
"opensock: getaddrinfo returned for %s:%d", host, port);
ressave = res;
do {
sockfd =
@@ -162,21 +168,100 @@ int socket_blocking (int sock)
return fcntl (sock, F_SETFL, flags & ~O_NONBLOCK);
}
/*
* Start listening to a socket. Create a socket with the selected port.
* The size of the socket address will be returned to the caller through
* the pointer, while the socket is returned as a default return.
* - rjkaes
/**
* Try to listen on one socket based on the addrinfo
* as returned from getaddrinfo.
*
* Return the file descriptor upon success, -1 upon error.
*/
int listen_sock (uint16_t port, socklen_t * addrlen)
static int listen_on_one_socket(struct addrinfo *ad)
{
int listenfd;
int ret;
const int on = 1;
char numerichost[NI_MAXHOST];
int flags = NI_NUMERICHOST;
ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
numerichost, NI_MAXHOST, NULL, 0, flags);
if (ret != 0) {
log_message(LOG_ERR, "error calling getnameinfo: %s",
gai_strerror(errno));
return -1;
}
log_message(LOG_INFO, "trying to listen on host[%s], family[%d], "
"socktype[%d], proto[%d]", numerichost,
ad->ai_family, ad->ai_socktype, ad->ai_protocol);
listenfd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
if (listenfd == -1) {
log_message(LOG_ERR, "socket() failed: %s", strerror(errno));
return -1;
}
ret = setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (ret != 0) {
log_message(LOG_ERR,
"setsockopt failed to set SO_REUSEADDR: %s",
strerror(errno));
close(listenfd);
return -1;
}
if (ad->ai_family == AF_INET6) {
ret = setsockopt(listenfd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on));
if (ret != 0) {
log_message(LOG_ERR,
"setsockopt failed to set IPV6_V6ONLY: %s",
strerror(errno));
close(listenfd);
return -1;
}
}
ret = bind(listenfd, ad->ai_addr, ad->ai_addrlen);
if (ret != 0) {
log_message(LOG_ERR, "bind failed: %s", strerror (errno));
close(listenfd);
return -1;
}
ret = listen(listenfd, MAXLISTEN);
if (ret != 0) {
log_message(LOG_ERR, "listen failed: %s", strerror(errno));
close(listenfd);
return -1;
}
log_message(LOG_INFO, "listening on fd [%d]", listenfd);
return listenfd;
}
/*
* Start listening on a socket. Create a socket with the selected port.
* If the provided address is NULL, we may listen on multiple sockets,
* e.g. the wildcard addresse for IPv4 and IPv6, depending on what is
* supported. If the address is not NULL, we only listen on the first
* address reported by getaddrinfo that works.
*
* Upon success, the listen-fds are added to the listen_fds list
* and 0 is returned. Upon error, -1 is returned.
*/
int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
{
struct addrinfo hints, *result, *rp;
char portstr[6];
int listenfd;
const int on = 1;
int ret = -1;
assert (port > 0);
assert (addrlen != NULL);
assert (listen_fds != NULL);
log_message(LOG_INFO, "listen_sock called with addr = '%s'",
addr == NULL ? "(NULL)" : addr);
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
@@ -185,7 +270,7 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
snprintf (portstr, sizeof (portstr), "%d", port);
if (getaddrinfo (config.ipAddr, portstr, &hints, &result) != 0) {
if (getaddrinfo (addr, portstr, &hints, &result) != 0) {
log_message (LOG_ERR,
"Unable to getaddrinfo() because of %s",
strerror (errno));
@@ -193,45 +278,34 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
}
for (rp = result; rp != NULL; rp = rp->ai_next) {
listenfd = socket (rp->ai_family, rp->ai_socktype,
rp->ai_protocol);
if (listenfd == -1)
int listenfd;
listenfd = listen_on_one_socket(rp);
if (listenfd == -1) {
continue;
setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof (on));
if (bind (listenfd, rp->ai_addr, rp->ai_addrlen) == 0)
break; /* success */
close (listenfd);
}
if (rp == NULL) {
/* was not able to bind to any address */
log_message (LOG_ERR,
"Unable to bind listening socket "
"to any address.");
vector_append (listen_fds, &listenfd, sizeof(int));
freeaddrinfo (result);
return -1;
/* success */
ret = 0;
if (addr != NULL) {
/*
* Unless wildcard is requested, only listen
* on the first result that works.
*/
break;
}
}
if (listen (listenfd, MAXLISTEN) < 0) {
log_message (LOG_ERR,
"Unable to start listening socket because of %s",
strerror (errno));
close (listenfd);
freeaddrinfo (result);
return -1;
if (ret != 0) {
log_message (LOG_ERR, "Unable to listen on any address.");
}
*addrlen = rp->ai_addrlen;
freeaddrinfo (result);
return listenfd;
return ret;
}
/*
+3 -1
View File
@@ -28,8 +28,10 @@
#define MAXLINE (1024 * 4)
#include "vector.h"
extern int opensock (const char *host, int port, const char *bind_to);
extern int listen_sock (uint16_t port, socklen_t * addrlen);
extern int listen_sock (const char *addr, uint16_t port, vector_t listen_fds);
extern int socket_nonblocking (int sock);
extern int socket_blocking (int sock);
+29 -22
View File
@@ -45,7 +45,7 @@ static int build_url (char **url, const char *host, int port, const char *path)
assert (path != NULL);
len = strlen (host) + strlen (path) + 14;
*url = (char *) safemalloc (len);
*url = (char *) saferealloc (*url, len);
if (*url == NULL)
return -1;
@@ -55,11 +55,12 @@ static int build_url (char **url, const char *host, int port, const char *path)
int
do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
struct request_s *request, struct config_s *conf,
char *url)
char **url)
{
socklen_t length;
char *data;
size_t ulen = strlen (url);
size_t ulen = strlen (*url);
ssize_t i;
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
if (length <= 0) {
@@ -73,7 +74,7 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Unknown destination",
"url", url, NULL);
"url", *url, NULL);
return 0;
}
@@ -83,15 +84,12 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
request->port = ntohs (dest_addr.sin_port);
request->path = (char *) safemalloc (ulen + 1);
strlcpy (request->path, url, ulen + 1);
strlcpy (request->path, *url, ulen + 1);
/* url overwritten by the call below is the url passed
* to this function, and is not the url variable in the
* caller. */
build_url (&url, request->host, request->port, request->path);
build_url (url, request->host, request->port, request->path);
log_message (LOG_INFO,
"process_request: trans IP %s %s for %d",
request->method, url, connptr->client_fd);
request->method, *url, connptr->client_fd);
} else {
request->host = (char *) safemalloc (length + 1);
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
@@ -101,27 +99,36 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
}
request->path = (char *) safemalloc (ulen + 1);
strlcpy (request->path, url, ulen + 1);
strlcpy (request->path, *url, ulen + 1);
/* url overwritten by the call below is the url passed
* to this function, and is not the url variable in the
* caller. */
build_url (&url, request->host, request->port, request->path);
build_url (url, request->host, request->port, request->path);
log_message (LOG_INFO,
"process_request: trans Host %s %s for %d",
request->method, url, connptr->client_fd);
request->method, *url, connptr->client_fd);
}
if (conf->ipAddr && strcmp (request->host, conf->ipAddr) == 0) {
if (conf->listen_addrs == NULL) {
return 1;
}
for (i = 0; i < vector_length(conf->listen_addrs); i++) {
const char *addr;
addr = (char *)vector_getentry(conf->listen_addrs, i, NULL);
if (addr && strcmp(request->host, addr) == 0) {
log_message(LOG_ERR,
"process_request: destination IP is localhost %d",
connptr->client_fd);
"transparent: destination IP %s is local "
"on socket fd %d",
request->host, connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail",
"You tried to connect to the machine "
"the proxy is running on", "url", url,
NULL);
"You tried to connect to the "
"machine the proxy is running on",
"url", *url, NULL);
return 0;
}
}
return 1;
}
+1 -1
View File
@@ -32,7 +32,7 @@
extern int do_transparent_proxy (struct conn_s *connptr,
hashmap_t hashofheaders,
struct request_s *request,
struct config_s *config, char *url);
struct config_s *config, char **url);
#endif
+49 -13
View File
@@ -27,12 +27,28 @@
#include "upstream.h"
#include "heap.h"
#include "log.h"
#include "base64.h"
#include "basicauth.h"
#ifdef UPSTREAM_SUPPORT
const char *
proxy_type_name(proxy_type type)
{
switch(type) {
case PT_NONE: return "none";
case PT_HTTP: return "http";
case PT_SOCKS4: return "socks4";
case PT_SOCKS5: return "socks5";
default: return "unknown";
}
}
/**
* 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, const char *domain,
const char *user, const char *pass,
proxy_type type)
{
char *ptr;
struct upstream *up;
@@ -44,8 +60,25 @@ static struct upstream *upstream_build (const char *host, int port, const char *
return NULL;
}
up->host = up->domain = NULL;
up->type = type;
up->host = up->domain = up->ua.user = up->pass = NULL;
up->ip = up->mask = 0;
if (user) {
if (type == PT_HTTP) {
char b[BASE64ENC_BYTES((256+2)-1) + 1];
ssize_t ret;
ret = basicauth_string(user, pass, b, sizeof b);
if (ret == 0) {
log_message (LOG_ERR,
"User / pass in upstream config too long");
return NULL;
}
up->ua.authstr = safestrdup (b);
} else {
up->ua.user = safestrdup (user);
up->pass = safestrdup (pass);
}
}
if (domain == NULL) {
if (!host || host[0] == '\0' || port < 1) {
@@ -57,9 +90,9 @@ static struct upstream *upstream_build (const char *host, int port, const char *
up->host = safestrdup (host);
up->port = port;
log_message (LOG_INFO, "Added upstream %s:%d for [default]",
host, port);
} else if (host == NULL) {
log_message (LOG_INFO, "Added upstream %s %s:%d for [default]",
proxy_type_name(type), host, port);
} else if (host == NULL || type == PT_NONE) {
if (!domain || domain[0] == '\0') {
log_message (LOG_WARNING,
"Nonsense no-upstream rule: empty domain");
@@ -91,7 +124,7 @@ static struct upstream *upstream_build (const char *host, int port, const char *
log_message (LOG_INFO, "Added no-upstream for %s", domain);
} else {
if (!host || host[0] == '\0' || port < 1 || !domain
|| domain == '\0') {
|| domain[0] == '\0') {
log_message (LOG_WARNING,
"Nonsense upstream rule: invalid parameters");
goto fail;
@@ -101,13 +134,15 @@ static struct upstream *upstream_build (const char *host, int port, const char *
up->port = port;
up->domain = safestrdup (domain);
log_message (LOG_INFO, "Added upstream %s:%d for %s",
host, port, domain);
log_message (LOG_INFO, "Added upstream %s %s:%d for %s",
proxy_type_name(type), host, port, domain);
}
return up;
fail:
safefree (up->ua.user);
safefree (up->pass);
safefree (up->host);
safefree (up->domain);
safefree (up);
@@ -119,11 +154,12 @@ fail:
* Add an entry to the upstream list
*/
void upstream_add (const char *host, int port, const char *domain,
struct upstream **upstream_list)
const char *user, const char *pass,
proxy_type type, struct upstream **upstream_list)
{
struct upstream *up;
up = upstream_build (host, port, domain);
up = upstream_build (host, port, domain, user, pass, type);
if (up == NULL) {
return;
}
@@ -202,10 +238,10 @@ struct upstream *upstream_get (char *host, struct upstream *up)
up = NULL;
if (up)
log_message (LOG_INFO, "Found proxy %s:%d for %s",
up->host, up->port, host);
log_message (LOG_INFO, "Found upstream proxy %s %s:%d for %s",
proxy_type_name(up->type), up->host, up->port, host);
else
log_message (LOG_INFO, "No proxy for %s", host);
log_message (LOG_INFO, "No upstream proxy for %s", host);
return up;
}
+16 -1
View File
@@ -31,17 +31,32 @@
* Even if upstream support is not compiled into tinyproxy, this
* structure still needs to be defined.
*/
typedef enum proxy_type {
PT_NONE = 0,
PT_HTTP,
PT_SOCKS4,
PT_SOCKS5
} proxy_type;
struct upstream {
struct upstream *next;
char *domain; /* optional */
char *host;
union {
char *user;
char *authstr;
} ua;
char *pass;
int port;
in_addr_t ip, mask;
proxy_type type;
};
#ifdef UPSTREAM_SUPPORT
const char *proxy_type_name(proxy_type type);
extern void upstream_add (const char *host, int port, const char *domain,
struct upstream **upstream_list);
const char *user, const char *pass,
proxy_type type, struct upstream **upstream_list);
extern struct upstream *upstream_get (char *host, struct upstream *up);
extern void free_upstream_list (struct upstream *up);
#endif /* UPSTREAM_SUPPORT */