Compare commits

...
212 Commits
Author SHA1 Message Date
Mukund Sivaraman 287a7ae649 Revert "Revert "Pass address family when binding to outgoing socket""
This reverts commit 577ac16cf1. It looks
like bug #69 needs this fix after all.
2010-03-09 17:07:14 +05:30
Mukund Sivaraman 315e129f12 Pull BB#69 out of NEWS for 1.8.1 2010-03-09 06:58:24 +05:30
Mukund Sivaraman 7cb30dd9ee Separate different versions in NEWS with newlines 2010-03-09 06:55:25 +05:30
Mukund Sivaraman 9927d411bf Add the contributors section to 1.8.1 NEWS 2010-03-03 15:37:10 +05:30
Mukund Sivaraman 0f28221ec5 Minor grammatical change 2010-03-03 15:33:40 +05:30
Mukund Sivaraman 57d90c8bf7 Update NEWS for 1.8.1 2010-03-03 15:31:46 +05:30
Mukund Sivaraman 8de8634b8b Bump version to 1.8.1 2010-03-03 15:21:25 +05:30
Mukund Sivaraman ce149cc7a6 Use AI_PASSIVE flag to make tinyproxy listen on wildcard interface
Signed-off-by: Michael Adam <obnox@samba.org>
2010-03-03 09:27:22 +01:00
Michael Adam 410eaf107c Comment out the LogFile and PidFile options in the example tinyproxy.conf.
These are compiled in defaults now.

Michael
2010-03-03 01:06:25 +01:00
Michael Adam e6cbaf7b6e 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-03 01:06:25 +01:00
Michael Adam 2d0192b8a8 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-03 01:06:25 +01:00
Michael Adam 643d52ac5a main: some tabs->spaces 2010-03-03 01:06:25 +01:00
Michael Adam b92792fd8d main: move a log message. 2010-03-03 01:06:25 +01:00
Michael Adam 965664798c 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-03 01:06:25 +01:00
Michael Adam 6d5709de38 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-03 01:06:25 +01:00
Michael Adam 107f9117d0 tinyproxy.conf: fix LogFile to proper CamelCase for consistency 2010-03-03 01:06:24 +01:00
Michael Adam 1b3dd058d1 tests: fix bug #80: keep track of errors in return codes
Michael
(cherry picked from commit 3f1632603c)
2010-02-23 00:19:26 +01:00
Michael Adam 333d722d56 tests: fix a typo in run_tests.sh
(cherry picked from commit 7c15563430)
2010-02-23 00:19:23 +01:00
Michael Adam 6f0abb7339 test: add make target "make valgrind-test-wait"
(cherry picked from commit ee1f1e38f2)
2010-02-22 23:32:08 +01:00
Michael Adam a19f758743 tests: add a new make target "make test-wait"
(cherry picked from commit 752e4419a6)
2010-02-22 23:21:18 +01:00
Michael Adam f63730c77e 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
(cherry picked from commit d133eee36b)
2010-02-22 23:21:13 +01:00
Mukund Sivaraman ed3ada7c26 Use format string when logging messages 2010-02-19 21:08:00 +05:30
Mukund Sivaraman b9e6d9742d Fix pkgdatadir path in tinyproxy.conf 2010-02-19 21:07:58 +05:30
Mukund Sivaraman fbc434e26d Display upstream proxy support in usage message 2010-02-17 23:18:50 +05:30
Mukund Sivaraman cc74869e71 Fix typo in manpage 2010-01-25 19:35:41 +05:30
Mukund Sivaraman 577ac16cf1 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-24 11:18:27 +05:30
Mukund Sivaraman 810b9ae49a Remove completed items from TODO list 2010-01-18 16:01:16 +05:30
Michael Adam 9c500d06f2 Fix bug #68: Allow all ports for CONNECT at absence of ConnectPort in config. 2010-01-17 13:41:02 +01:00
Mukund Sivaraman aea157d7c9 Bump version to 1.8.0 2010-01-17 14:30:06 +05:30
Mukund Sivaraman 9c68b94136 Do an openlog() on fallback to syslog 2010-01-17 14:27:49 +05:30
Mukund Sivaraman 26b4ab07a4 Remove extra argument to log_message() 2010-01-17 14:27:19 +05:30
Mukund Sivaraman a34ce8f4f9 Remove ret variable as 0 is always returned 2010-01-17 14:26:56 +05:30
Mukund Sivaraman e2b367a169 Remove unused label 2010-01-17 14:26:08 +05:30
Michael Adam 8070023643 log: when opening the log file fails, fall back to syslog logging. 2010-01-17 01:10:21 +01:00
Michael Adam 54a613b9db conf: reduce indentation in load_config_file()
This replaces a do { ... } while (0) with break statements
ba gotos. Imho, this is much clearer.

Michael
2010-01-16 13:26:18 +01:00
Mukund Sivaraman d3df735f89 Add author sections to the manpages 2010-01-16 16:42:02 +05:30
Mukund Sivaraman 74334a7700 Add see-also sections to the manpages 2010-01-16 16:40:48 +05:30
Mukund Sivaraman 09d11ace60 Fix leak of file handle in load_config_file() 2010-01-16 11:09:14 +05:30
Mukund Sivaraman bf820013df Use HTTPS link in URLs to Tinyproxy websites 2010-01-16 10:22:22 +05:30
Mukund Sivaraman 21c6164910 Bump version number in override too 2010-01-16 10:18:14 +05:30
Mukund Sivaraman 6da10fa438 Fix text about bug reporting 2010-01-16 10:17:13 +05:30
Mukund Sivaraman bbccb57929 Fix case of Bugzilla product name 2010-01-16 10:17:07 +05:30
Mukund Sivaraman 5980512a08 Rename version 1.7.2 to 1.8.0 in NEWS 2010-01-15 22:28:14 +05:30
Mukund Sivaraman 3700e1fc5b Add old NEWS for 1.7.0 2010-01-14 13:59:35 +05:30
Mukund Sivaraman 46deecdb53 Fix case 2010-01-14 13:40:12 +05:30
Mukund Sivaraman eb67b4c407 Fix typos and elaborate some NEWS items 2010-01-14 13:30:54 +05:30
Mukund Sivaraman ee17131bdf Fix list of 1.7.2 contributors 2010-01-14 13:23:35 +05:30
Mukund Sivaraman fa45b3cb79 Revert list of 1.7.1 contributors to what it was before 2010-01-14 13:21:55 +05:30
Mukund Sivaraman d3b1619b06 Add a separate contributors section for version 1.7.2 2010-01-14 13:20:51 +05:30
Mukund Sivaraman 3101d7ebb4 Fix version number in NEWS file 2010-01-14 13:20:15 +05:30
Michael Adam 157a79216f NEWS: add David Shanks to the list of contributors. 2010-01-14 08:34:09 +01:00
Michael Adam a61f6018f2 NEWS: document some more new features in the release notes
Michael
2010-01-14 08:33:11 +01:00
Michael Adam a639f3fca2 NEWS: add list of bugs fixed since 1.7.1
Muks: please verify - thes are current the fixed bugs
with milestone 1.8.0 (i.e. the renamed 1.7.2).

I hope this is correct!
I also hope this was the intended scheme - have bug
lists per version section. Please feel free to edit...

Michael
2010-01-14 08:25:44 +01:00
Michael Adam 3baa5f6f7c NEWS: mention change of XTinyProxy to be a global bool
Michael
2010-01-14 08:14:01 +01:00
David Shanks 184d07e47c check_numeric_acl() should return -1 when IPs don't match.
Signed-off-by: Michael Adam <obnox@samba.org>
2010-01-14 07:46:31 +01:00
Michael Adam 8963c84dad NEWS: move the changes after 1.7.1 to new section 1.7.2
Michael
2010-01-13 23:26:20 +01:00
Michael Adam 7e9a022c74 NEWS: reformulate and elaborate some items.
Michael
2010-01-13 21:28:38 +01:00
Michael Adam 7ca792043c update NEWS
* mention config reload and upon HUP
* log-reopen (not trunc!) upon HUP
* file-logging as default

Michael
2010-01-13 21:25:03 +01:00
Michael Adam 028cad3c3b NEWS: add Mathew Mrosko as contributor. 2010-01-13 17:11:54 +01:00
Michael Adam 5e387e6ee7 log: turn tabs into spaces =)
Michael
2010-01-13 00:58:55 +01:00
Michael Adam dc86ebaf28 log: change internal logic to choose syslog over file logging.
Now that there is always a log file set, we just check for
syslog being set to TRUE and in that case use syslog logging,
file logging otherwiese.

Michael
2010-01-13 00:57:32 +01:00
Michael Adam fa0c4963e9 conf: add a default for PidFile: LOCALSTATEDIR/run/tinyproxy.pid
Michael
2010-01-13 00:30:50 +01:00
Michael Adam 9fec507daf log: remove a (now) useless fprintf in setup_logging.
Now that there is a default value for LogFile, the case
that neither the log file name nor syslog is configured
can not happen any more.

Michael
2010-01-13 00:23:48 +01:00
Michael Adam 74b0b63da8 conf: set default LogFile to LOCALSTATEDIR/log/tinyproxy.log
Michael
2010-01-13 00:21:39 +01:00
Michael Adam fb07cb380c Export configure variable localstatedir to C as define LOCALSTATEDIR.
So that it can be used for default values of some paths later on.

Michael
2010-01-13 00:16:02 +01:00
Mukund Sivaraman d6a247cc04 Make bzip2 compressed dist tarballs
We publish bzip2 compressed tarballs starting with the 1.8.x releases.
2010-01-11 04:17:26 +05:30
Michael Adam bcca20a3e6 log: remove an fprintf "not configured" error message in setup_logging().
Now that we exit early when !logging_initialized, this
can actually not happen anymore anyways: When logging is
initialized, it was also properly configured.

Michael
2010-01-10 19:29:33 +01:00
Michael Adam 1dd1c2796a log: shortcut return in shutdown_logging() if logging_initialized == false
This does for instance happen at startup when logging has not yet been set up.

Michael
2010-01-10 19:24:23 +01:00
Mukund Sivaraman 65ef313cc4 Pass address family when binding to outgoing socket 2010-01-10 19:51:24 +05:30
Michael Adam b106091343 Happy new year 2010! 2010-01-10 13:53:03 +01:00
Michael Adam 594df6bf43 Happy new year 2010! 2010-01-10 13:52:17 +01:00
Michael Adam 52e333af0b Happy new year 2010! 2010-01-10 13:51:33 +01:00
Michael Adam 12026c32de Fix bug #55: Read request entity before sending error page to client.
https://www.banu.com/bugzilla/show_bug.cgi?id=55

This is achieved by streamlining handle_connection, adding
a common cleanup-and-exit poing ("done") and a common
failure exit point ("fail") that reads any pending data
from the client fd first before trying to send back
data (error page or stats page).

The new function get_request_entity that is used here,
does not honour any content-length header. It just calls
select on the client-fd and gets any data that is there
to read.

Michael
2010-01-10 02:17:37 +01:00
Michael Adam 6c9a647576 reqs:handle_connection: untangle assignment from check
Michael
2010-01-10 01:49:14 +01:00
Michael Adam e1e9e53d45 reqs:process_client_headers: polish logic flow a bit.
Michael
2010-01-10 01:49:14 +01:00
Michael Adam 0bfc0e90c1 reqs: simply process_request a bit: create common fail exit point
Michael
2010-01-10 01:49:14 +01:00
Mukund Sivaraman 9c0c3d5ced [BB#17] Add custom HTTP request headers to outgoing HTTP requests 2010-01-08 22:05:17 +05:30
Mukund Sivaraman b96a3a3250 Fix case in log message 2010-01-06 11:54:57 +05:30
Mukund Sivaraman e5abe844d1 Use named lists to match rest of the document 2010-01-03 20:50:07 +05:30
Mukund Sivaraman 9e79e9975f Modify description of LogLevel in manpage 2010-01-03 20:46:37 +05:30
Mukund Sivaraman 70e8197344 Use proper asciidoc formatting in manpage 2010-01-03 20:14:43 +05:30
Mukund Sivaraman 34f9e5f95e Fix caps in manpage 2010-01-03 20:14:29 +05:30
Mukund Sivaraman e42d1cf9fd Use a configure arg to request regex checking
Disabling the regex check seems to be required during cross-compiles,
where it's not possible to test the target's regex library at
compile time.
2010-01-03 13:52:00 +05:30
Mukund Sivaraman 8077fd8936 Reindent the last configure.ac changes 2010-01-03 13:41:49 +05:30
Mathew Mrosko df08d801fe build: allow a forcing build with "broken" regex.
The configure would fail when cross compiling due to the regex check
automatically failing for cross compilation. Since you can't run the
regex binary check, assuming the regex library on the target platform is
working would be the only way to get the build working, or adding a
force for people to control based on their build environment.

Signed-off-by: Michael Adam <obnox@samba.org>
2010-01-02 00:10:17 +01:00
Michael Adam e0fabc6127 log: confess - add my (C) after substantial changes.
Michael
2009-12-23 00:33:31 +01:00
Michael Adam 5e8c8508ef conf: confess - add my (C) after substantial changes.
Michael
2009-12-23 00:33:21 +01:00
Michael Adam 4a11f9f08f log: remove unneeded truncate_log_file().
Michael
2009-12-23 00:31:56 +01:00
Michael Adam c07cd2e44e Use shutdown_logging() in main().
Michael
2009-12-23 00:31:56 +01:00
Michael Adam 71a035d619 Use reload_config() in main() to load config and init logging.
Michael
2009-12-23 00:31:55 +01:00
Michael Adam bc10479452 log: fix log_message so do only one write before the fsync.
This way the logging from the various child processes does not
get clobbered up. Formerly, the different write portions
(time stamp, message, newline) would get mixed from the
various child processes' log messages.

Michael
2009-12-23 00:31:55 +01:00
Michael Adam adf4640104 log: add start/end debug messages for "sending stored logs".
Michael
2009-12-23 00:31:55 +01:00
Michael Adam 0466526b1d Add warning comments to SIGHUP handlers, that we ignore the retrun code of reload_config().
This can actually fail, and we probably need some way to handle this.
Like an emergency error exit or so...

Michael
2009-12-23 00:31:55 +01:00
Michael Adam 8346a20aa0 Don't truncate the log file in the SIGHUP handler.
Logging is re-initialized by reload_config() now.
And truncation is wrong anyways: A syslog mechanism will
move the current log file and the reopen-action will just
create a new empty log file upon SIGHUP.

Michael
2009-12-23 00:31:55 +01:00
Michael Adam fb2e65f40b enhance reload_config to correctly re-initialize the logging subsystem.
This includes reopening the log file (in append mode).
Also switching from syslog to logfile and visa versa are included
when called from the SIGHUP handler.

Michael
2009-12-23 00:31:55 +01:00
Michael Adam c4b9454807 log: enhance close_log_file to reset logfile_fd to -1 after closing
Michael
2009-12-23 00:31:55 +01:00
Michael Adam f3c8424515 log.c: remove superfluous uses of #ifdef HAVE_SYSLOG_H
When this code is hit, availability of syslog has already
been checked (when reading the config file). So config.syslog == TRUE
only when HAVE_SYSLOG_H is defined.

So I remove the preprocessor checks which only clobber the logic
and make the code harder to read (IMHO).

Michael
2009-12-23 00:31:55 +01:00
Michael Adam 2c14f89bfc main: remove global bool processed_config_file.
This seemed out of place. Now the information is
stored in the correct places (as log.c:logging_initialized).

This way, we will be able to cleanly re-initialize
logging during config reload (SIGHUP) in subsequent
commits.

Michael
2009-12-23 00:27:32 +01:00
Michael Adam 210e82d08d log: call send_stored_logs in setup_logging instead of in main().
This is where it actually belongs.

Michael
2009-12-23 00:27:32 +01:00
Michael Adam 891846f23e log: add boolean local variable logging_initialized.
This controls whether log_messages should write to the
log file / syslog or rather to the log_message_storage.
This will make the global processed_config_file variable
from main unneccessary in the next step.

Michael
2009-12-23 00:27:26 +01:00
Michael Adam 649b2c0683 log: add function shutdown_logging().
Michael
2009-12-23 00:27:26 +01:00
Michael Adam 479562ad2b reload config upon SIGHUP
Michael
2009-12-22 00:15:00 +01:00
Michael Adam 91492773b1 conf: add a log messate ("reloading config file")
Michael
2009-12-22 00:15:00 +01:00
Michael Adam e9baa2977c conf: adapt a log message (add quotes to string value)
Michael
2009-12-22 00:15:00 +01:00
Michael Adam f7419c60be conf: elaborate a comment
Michael
2009-12-22 00:15:00 +01:00
Michael Adam 93dfb1ac5b conf: change a log message (to be more reasonable?)
Michael
2009-12-22 00:15:00 +01:00
Michael Adam 8bf91ce80f main: add convenience wrapper reload_config() for reload_config_file()
Michael
2009-12-22 00:14:59 +01:00
Michael Adam 72632f6569 conf.h: add "extern" to prototype of reload_config_file
Michael
2009-12-22 00:14:59 +01:00
Michael Adam 6ea160ffff conf: make free_config static
Michael
2009-12-22 00:14:59 +01:00
Michael Adam c15434df2b conf: make load_config_file static.
Michael
2009-12-22 00:14:59 +01:00
Michael Adam d3d31b434a conf: rename reload_config --> reload_config_file
Michael
2009-12-22 00:14:59 +01:00
Mukund Sivaraman 6a5faa0bec Remove AM_MAINTAINER_MODE 2009-12-08 10:52:17 +05:30
Michael Adam d522221668 Fix restarting of tinyproxy: call setsockopt with REUSEADDR _before_ calling bind
Somehow this got moved too far down in the ipv6 changes.
Thanks to Mathew Mrosko for helping me debugging this.

Michael
2009-12-08 01:24:31 +01:00
Michael Adam 5bba62bcde Fix the build with --enable-transaparent after conf changes.
Michael
2009-12-07 23:42:55 +01:00
Michael Adam 0ba5cbea4f fix build with "--enable-reverse" after conf changes
Michael
2009-12-07 23:40:24 +01:00
Michael Adam 7290691142 Move definition of "struct config_s" from main.h to conf.h
Michael
2009-12-07 22:33:27 +01:00
Michael Adam 34e4be193e main.h: fix tabs ---> spaces
Michael
2009-12-07 22:33:27 +01:00
Michael Adam 4b54fc203f conf: remove direct use of config from reload_config()
The "conf" argument has to be used.

Michael
2009-12-07 22:33:27 +01:00
Michael Adam ad2f478c46 conf: remove direct reference to config from load_config_file()
This has to use the parameter "conf".

Michael
2009-12-07 22:33:26 +01:00
Michael Adam 947d85cefc Use reload_config() in main.
Michael
2009-12-07 01:11:35 +01:00
Michael Adam 0d0de2fcc5 Add reload_config() - (re-)load the config file, keeping defaults.
This allows for later reloading the config at SIGHUP (e.g.).
First the old config data is freed, then the defaults that
are given as a parameter are copied over in a rather clumsy
manual fashion (maybe something more clever can be done here)
and finally, the actual config file is loaded.

Michael
2009-12-07 01:11:35 +01:00
Michael Adam 2ccebf7a95 main: Move setup_logging to after the config post-processing checks.
Michael
2009-12-07 00:40:25 +01:00
Michael Adam dcbf99d334 Add free_config() - free all config data.
Michael
2009-12-07 00:32:22 +01:00
Michael Adam 1360f530f1 Don't make config_file const in the config struct.
Michael
2009-12-07 00:32:22 +01:00
Michael Adam d0a91c2f9b Add the anonymous_map hasmap to the config struct.
Michael
2009-12-07 00:22:53 +01:00
Michael Adam fa073543c4 Add free_connect_ports_list().
Michael
2009-12-07 00:22:52 +01:00
Michael Adam 4c0a4d985f Add connect_ports list to config struct instead of keeping extra global var.
Michael
2009-12-07 00:22:52 +01:00
Michael Adam c981b246ce Move handling of connect_ports list to its own source module.
Michael
2009-12-07 00:22:52 +01:00
Michael Adam 8cb182e1b8 Add access_list to the config struct instead of a global variable in acl.c.
Change insert_acl, check_acl and flush_access_list to take a corresponding
argument.

Michael
2009-12-07 00:22:46 +01:00
Michael Adam 6266197e92 acl: add function flush_access_list(). 2009-12-07 00:22:46 +01:00
Michael Adam 2e6999df4a Add free_reversepath_list().
Michael
2009-12-07 00:22:46 +01:00
Michael Adam 3f1201c8b3 Add a reversepath argument to reversepath_get().
This abstracts the setter/getter functions for the reversepath
list from the concrete list in config.reversepath_list.

Michael
2009-12-07 00:22:46 +01:00
Michael Adam 624d146cd6 Add reversepath_list parameter to reversepath_add.
Michael
2009-12-07 00:22:36 +01:00
Michael Adam 21aa3ecf60 upstream: add free_upstream_list ()
Michael
2009-12-07 00:22:36 +01:00
Michael Adam 4a8ea0d23b upstream: Add upstream list parameter to upstream_get()
to abstract it from the concrete list in the config struct.
Now upstream.c does not use any reference to config any more.

Michael
2009-12-07 00:22:36 +01:00
Michael Adam 22fba83df2 upstream: add upstream list parameter to upstream_add()
to abstract it from the concrete list in the config struct.

Michael
2009-12-07 00:22:28 +01:00
Michael Adam fd987e97f0 move handling of upstream list to new module upstream.{c,h}
Michael
2009-12-06 13:17:18 +01:00
Michael Adam 56ba3d45bd upstream: refactor assembly of upstream out of upstream_add
Michael
2009-12-06 13:17:18 +01:00
Michael Adam 34dbeb3626 main/conf: add maxidletimeout to initialize_config_defaults
But keep the resetting check after processing the conf file.

Michael
2009-12-06 01:57:04 +01:00
Michael Adam c853cec164 main: fix tab -> spaces
Michael
2009-12-06 01:57:04 +01:00
Michael Adam 073233b9f1 conf: move setting of default stathost to initialize_config_defaults()
Michael
2009-12-06 01:56:59 +01:00
Michael Adam 055c11f63c conf: fix tab->spaces
Michael
2009-12-06 01:55:53 +01:00
Michael Adam f60aa47715 conf: allow set_string_arg to overwrite previous values (i.e. don't leak)
Michael
2009-12-06 01:55:53 +01:00
Michael Adam 5e399a7e17 main: use safestrdup instead of strdup in process_cmdline
Michael
2009-12-06 01:55:53 +01:00
Mukund Sivaraman 0480185d07 Use capitalized name in error messages 2009-12-04 05:41:36 +05:30
Michael Adam 607e8ec0e7 acl: split initialization of the access_list out into a function 2009-11-17 17:30:19 +01:00
Mukund Sivaraman ec4b4d979f Use NULL for pointers 2009-11-17 02:40:03 +05:30
Michael Adam a664dee4f6 set_string_arg: Remove unneccesary check for determining the return code. 2009-11-16 21:52:34 +01:00
Mukund Sivaraman 45a56e468d Remove excessive copying 2009-11-17 02:20:27 +05:30
Mukund Sivaraman d7fada25e5 Make position into an enum 2009-11-17 01:52:23 +05:30
Mukund Sivaraman 4b6a25ac06 Use snprintf() with size of the portstr buf 2009-11-17 01:44:21 +05:30
Mathew Mrosko 238e3ffb34 Fix format string warnings
C90 doesn't support z modifier in printf's, so cast values
to (unsigned long) which should be the same size as size_t
on both ILP32 and LP64.
2009-11-16 21:50:40 +05:30
Mukund Sivaraman 2f05d8dd32 Fix typo in log string 2009-11-14 18:57:31 +05:30
Michael Adam fba81e4174 conf: refactor loading of config file out into load_config_file()
and make config_compile and config_parse static to conf.c

Michael
2009-11-14 12:13:10 +01:00
Michael Adam a09dd9cd00 main: add a config struct argument to process_cmdline.
Michael
2009-11-14 12:13:10 +01:00
Michael Adam 8945d9f0ae main: put initialization of config defaults into a function of its own
Michael
2009-11-14 12:13:10 +01:00
Michael Adam ea2eaef173 extract setup of the logging subsystem into a function of its own.
Signed-off-by: Michael Adam <obnox@samba.org>
2009-11-14 12:13:10 +01:00
Michael Adam d8da7f55f7 main: move initialization of default config values closer together
Michael
2009-11-14 12:13:10 +01:00
Mukund Sivaraman 9274b5556e Remove packaging related items 2009-11-14 16:40:46 +05:30
Mukund Sivaraman c42fbaaf80 Make asciidoc a requirement for building Tinyproxy
asciidoc is necessary as the version number is added during
configure into the asciidoc manpage sources. So simply bundling
a pre-generated manpage won't do.
2009-11-14 16:34:06 +05:30
Mukund Sivaraman 2061a18313 Revert "Don't cleanup generated and dist'ed manpages"
This reverts commit 276ca8369d.
2009-11-14 16:16:49 +05:30
Mukund Sivaraman 66abbbe72d Use located a2x binary instead of hard-coded name 2009-11-14 15:47:51 +05:30
Mukund Sivaraman e71b3e08a6 Mark all generated stuff with silent rules 2009-11-14 15:47:21 +05:30
Mukund Sivaraman d8062ed35f Enable silent rules by default 2009-11-14 15:43:18 +05:30
Mukund Sivaraman 276ca8369d Don't cleanup generated and dist'ed manpages 2009-11-14 15:40:57 +05:30
Michael Adam feea6db815 daemon.c: fix #if NDEBUG --> #ifdef NDEBUG
Thanks to Mathew Mrosko for pointing that out.
2009-11-10 17:59:40 +01:00
Michael Adam c3f29ce4ac gitignore etc/tinyproxy.conf - it is generated 2009-11-10 17:12:16 +01:00
Michael Adam 444ad35250 intentation: convert a tab to spaces
Michael
2009-11-10 13:59:07 +01:00
Michael Adam c0c6db0a5e Update etc/Makefile.am to substitute TINYPROXY_STATHOST
Maybe, it would be better to have a two stage process here:

1. Have AC_SUBST from configure substitute as many variables
   as possible in  a fist stage
   tinyproxy.conf.tmpl.in --> tinyproxy.conf.tmp

2. Have make substitute those remaining paths that can not be
   substituted reasonable by configure due to the internal
   workings of automake.

Michael
2009-11-10 13:58:08 +01:00
Michael Adam 6f56738ab0 tinyproxy.conf: add a comment documenting StatHost
Michael
2009-11-10 13:58:08 +01:00
Michael Adam 41dd25d8e6 docs: update description of STATHOST in tinyproxy(8)
Michael
2009-11-10 13:58:08 +01:00
Michael Adam cbb179ef0b docs: document StatHost in tinyproxy.conf(5)
Michael
2009-11-10 13:58:07 +01:00
Michael Adam e54a3827df configure: AC_SUBST TINYPROXY_STATHOST, not only define it for config.h
Michael
2009-11-10 13:58:07 +01:00
Michael Adam fd879e45c8 conf: fix reverspath parsing: the string in the 2nd arg is actually the inner match
this fixes bug #64, https://www.banu.com/bugzilla/show_bug.cgi?id=64

the quotes of the string were part of the revers path after parseing.

Michael
2009-11-10 01:17:27 +01:00
Michael Adam f63c29c886 conf: make the WS optional too, before the optional 2nd argument to reversepath
Michael
2009-11-10 01:17:27 +01:00
Michael Adam 60d738626b conf: fix ipv6 regex patterns, take three
This extends the pattern by an alternative where there are no double colons.
This is for instance the case for and IPv6 address of the form
1111:222:33:4:55:666:7777:888

Michael
2009-11-10 00:55:39 +01:00
Michael Adam 4292fe7795 Fix a segfault in insert_acl and checks against string-type acls
The "address" member of struct acl_s is a union of a char *
and the numeric ip. So freeing the string after appending it to the
vector list is bad in two respects:

1. If the acl type was numeric, then this could (and would)
   lead to a segfault due to the numeric IP data interpreted
   as pointer to the string to be freed.

2. If the acl type was string, then the acl inserted into the
   list contained a reference to this address string that
   was freed. So in the worst case dereferencing this freed
   string could segfault, or at least this could lead to
   unexpectedly failing acl checks.

Michael
2009-11-10 00:37:57 +01:00
Michael Adam 2b73e2183f conf: fix the IPV6 regex patterns, take two
The patterns should not end with the end of line marker,
since they might be part of a continuing pattern,
say of the form ipv6address/mask (used for allow/deny)

Michael
2009-11-09 23:26:46 +01:00
Michael Adam f4f14419c4 conf: fix the IPV6 regex patterns
These are not matched against the beginning of a line
but somewhere in the middle (as in "listen <IPv6 address>").

Michael
2009-11-09 13:53:44 +01:00
Mukund Sivaraman cd834de190 Close listenfd upon errors 2009-11-09 11:16:38 +05:30
Mukund Sivaraman c8c9abc669 Fix validation of IPv6 addresses 2009-11-09 02:44:14 +05:30
Mukund Sivaraman 6f93737d8e Bump micro version 2009-11-09 01:14:03 +05:30
Mukund Sivaraman c978015af1 Add IPV6 support to listen_sock() 2009-11-09 01:13:41 +05:30
Michael Adam 25057baf54 propagate reload of filter file to child procs by sending HUP signals 2009-10-25 23:33:37 +01:00
Michael Adam 3474de599f Change child_kill_children() to take the signal as an argument. 2009-10-25 23:33:37 +01:00
Michael Adam 1b4d130cf5 child: handle SIGHUP in the child by reloading the filter file 2009-10-25 23:33:37 +01:00
Michael Adam b837e65b21 use new filter_reload() in child_main_loop() 2009-10-25 23:33:37 +01:00
Michael Adam 83987babd3 filter: add function filter_reload() 2009-10-25 23:33:37 +01:00
Michael Adam 79527fb6f7 gitignore add file tags (from ctags) 2009-10-25 23:33:37 +01:00
Michael Adam f43dd6ae18 TODO: add a reference to a bugzilla entry 2009-10-13 23:52:02 +02:00
Michael Adam cbaa4b9fd2 tests:webclient: add option to send a request entity (body) 2009-10-12 02:01:25 +02:00
Michael Adam e793a729f6 Clean tinyproxy.conf in make clean. 2009-10-11 13:21:13 +02:00
Michael Adam 582a8dc624 Fix make distcheck with tinyproxy.conf.in
(Fixes make install and out of tree builds)

Thanks to muks for the top_srcdir bit!
2009-10-11 13:19:36 +02:00
Michael Adam 7b8171fe01 tests: add commented out DisableViaHeader to tinyproxy conf in the tests. 2009-10-11 02:00:44 +02:00
Michael Adam db7f340b3a Document DisableViaHeader in the tinyproxy.conf(5) manpage. 2009-10-11 02:00:44 +02:00
Michael Adam 1c0bda0e7c Document DisableViaHeader in the tinyproxy.conf template. 2009-10-11 02:00:32 +02:00
Michael Adam 7671ac1ae2 Don't add "Via:" header when DisableViaHeader == Yes. 2009-10-11 01:27:24 +02:00
Michael Adam f208b1222b Add a boolean config option "DisableViaHeader". 2009-10-11 01:13:15 +02:00
Michael Adam f46aeca9a5 Fix a typo in the tinyproxy.conf template. 2009-10-10 22:25:03 +02:00
Michael Adam 03b8e8bc19 Fix another typo in the tinyproxy.conf(5) manpage. 2009-10-10 22:24:02 +02:00
Michael Adam add2685a55 Fix a typo in the tinyproxy.conf(5) manpage. 2009-10-10 22:23:28 +02:00
Michael Adam cbe52ca43c tests:webserver: correctly answer http/0.9 requests by sending no headers
Michael
2009-10-10 20:57:07 +02:00
Michael Adam 07d993cbc1 acl: Fix "comparison between signed and unsigned" warning on 32bit
This reads the mask bits as an unsigned int instead of as signend.
This is also what mask bits really are - there is no negative mask. :-)

Michael
2009-10-10 01:11:53 +02:00
Michael Adam a89d987e8a Use size_t not ssize_t for len argument. This is always >= 0. 2009-10-10 01:11:10 +02:00
Michael Adam 1fda61b5a0 generate etc/tinyproxy.conf from a tinyproxy.conf.in template
This is a first cut at providing a tinyproxy.conf file with
more useful default or example directories. It uses datadir,
sysconfdir and localstatedir.

Because automake is a little special here, this template can
not simply be processed by configure (AC_CONFIG_FILES(...)),
as these variables can only be used like this in makefiles.
Instead, we need a little sed-processor in the Makfile in etc/.

Michael
2009-10-10 00:58:55 +02:00
Mukund Sivaraman 641e5823c0 Use ssize_t for len argument 2009-10-09 13:50:12 +05:30
Michael Adam eb4d01cc46 add muks' and my (C) to the main.c boilerplate comment.
Michael
2009-10-07 01:08:03 +02:00
Michael Adam 297274ca15 main: add muks and me to the license output (tinyproxy -l)
Michael
2009-10-07 01:06:05 +02:00
Mukund Sivaraman 8ff437236f Add items to TODO 2009-10-02 15:55:42 +05:30
Mukund Sivaraman eab4ae000b url variable modified in do_transparent_proxy() is not the url variable in the caller 2009-10-02 15:27:43 +05:30
Mukund Sivaraman 931b038b27 Use safer string functions 2009-10-02 15:21:42 +05:30
Mukund Sivaraman 323a4d0147 Clean up html_send_file ()
- Make function return from one place
 - Move inbuf to the heap
2009-10-02 13:01:32 +05:30
53 changed files with 1703 additions and 998 deletions

No files matched your search

+1
View File
@@ -19,3 +19,4 @@ autom4te.cache
cscope.files
cscope.out
*~
tags
+6 -1
View File
@@ -4,7 +4,6 @@ SUBDIRS = \
etc \
docs \
m4macros \
packaging \
tests
# tools want this on a single line
@@ -18,5 +17,11 @@ EXTRA_DIST = \
test: all
./tests/scripts/run_tests.sh
test-wait:
TINYPROXY_TESTS_WAIT=yes $(MAKE) test
valgrind-test: all
./tests/scripts/run_tests_valgrind.sh
valgrind-test-wait:
TINYPROXY_TESTS_WAIT=yes $(MAKE) valgrind-test
+86 -4
View File
@@ -1,13 +1,78 @@
Tinyproxy NEWS
==============
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
* Wrote improved asciidoc manpages
* Cleaned up build system
* Fixed various other bugs
* 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -24,3 +89,20 @@ 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.
+1 -1
View File
@@ -56,7 +56,7 @@ Support
-------
If you are having problems with Tinyproxy, please submit a bug report
using Tinyproxy as the component at:
using Tinyproxy as the product at:
https://www.banu.com/bugzilla/
+11
View File
@@ -39,3 +39,14 @@ against the current tree and I'll integrate it if possible.
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]
==> https://www.banu.com/bugzilla/show_bug.cgi?id=13
* Remove common.h and fix order of headers
* Remove memory debugging functions (Valgrind is good enough)
* Make all functions return from one place (the end of the function)
* Move TODO items to Banu Bugzilla
+2 -2
View File
@@ -17,8 +17,8 @@ cd $ORIGDIR
set -
echo $srcdir/configure --enable-maintainer-mode "$@"
$srcdir/configure --enable-maintainer-mode "$@"
echo $srcdir/configure "$@"
$srcdir/configure "$@"
RC=$?
if test $RC -ne 0; then
echo
+31 -21
View File
@@ -4,14 +4,14 @@
AC_PREREQ(2.54)
m4_define([tinyproxy_major_version], [1])
m4_define([tinyproxy_minor_version], [7])
m4_define([tinyproxy_minor_version], [8])
m4_define([tinyproxy_micro_version], [1])
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], [0.7.0])
# m4_define([tinyproxy_version], [1.8.0])
m4_define([tinyproxy_unstable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [1], [yes], [no]))
@@ -19,16 +19,15 @@ m4_define([tinyproxy_stable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [0], [yes], [no]))
AC_INIT([Tinyproxy], [tinyproxy_version],
[https://www.banu.com/bugzilla/enter_bug.cgi?product=Tinyproxy],
[https://www.banu.com/bugzilla/enter_bug.cgi?product=tinyproxy],
[tinyproxy])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([dist-bzip2])
AM_CONFIG_HEADER(config.h)
AC_CONFIG_MACRO_DIR([m4macros])
AM_MAINTAINER_MODE
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([no])])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
@@ -65,8 +64,12 @@ AH_TEMPLATE([TINYPROXY_STATHOST],
[This controls remote proxy stats display.])
AC_ARG_WITH(stathost,
[AC_HELP_STRING([--with-stathost=HOST], [Default status host])],
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")],
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")])
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")
TINYPROXY_STATHOST="$withval"],
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")
TINYPROXY_STATHOST="tinyproxy.stats"])
AC_SUBST(TINYPROXY_STATHOST)
dnl Add compiler-specific optimization flags
TP_ARG_ENABLE(debug,
@@ -128,6 +131,11 @@ if test x"$transparent_enabled" = x"yes"; then
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
@@ -224,9 +232,10 @@ 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
AC_MSG_CHECKING([whether the system's regex library is broken])
AC_CACHE_VAL(tinyproxy_cv_regex_broken,
[AC_TRY_RUN([
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
@@ -251,15 +260,16 @@ int main(void)
return 0;
}
],
tinyproxy_cv_regex_broken=no,
tinyproxy_cv_regex_broken=yes,
tinyproxy_cv_regex_broken=yes)])
],
tinyproxy_cv_regex_broken=no,
tinyproxy_cv_regex_broken=yes,
tinyproxy_cv_regex_broken=yes)])
AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
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.])
if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
AC_MSG_ERROR([Your system's regexec() function is broken.])
fi
fi
fi
@@ -275,6 +285,9 @@ AC_SUBST(ADDITIONAL_OBJECTS)
# 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.])
fi
AC_CONFIG_FILES([
Makefile
@@ -288,9 +301,6 @@ docs/man5/tinyproxy.conf.txt
docs/man8/Makefile
docs/man8/tinyproxy.txt
m4macros/Makefile
packaging/Makefile
packaging/fedora/tinyproxy.spec
packaging/fedora/Makefile
tests/Makefile
tests/scripts/Makefile
])
+1 -4
View File
@@ -10,14 +10,11 @@ man_MANS = \
.txt.5:
if HAVE_A2X
a2x $(A2X_ARGS) $<
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
else
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
endif
EXTRA_DIST = \
$(man_MANS)
CLEANFILES = \
$(MAN5_FILES:.txt=.5) \
$(MAN5_FILES:.txt=.xml)
+64 -24
View File
@@ -83,6 +83,14 @@ The possible keywords and their descriptions are as follows:
This parameter controls the HTML template file returned when an
error occurs for which no specific error file has been set.
*StatHost*::
This configures the host name or IP address that is treated
as the `stat host`: Whenever a request for this host is received,
Tinyproxy will return an internal statistics page instead of
forwarding the request to that host. The template for this
page can be configured with the `StatFile` configuration option.
The default value of `StatHost` is `@TINYPROXY_STATHOST@`.
*StatFile*::
@@ -91,8 +99,7 @@ The possible keywords and their descriptions are as follows:
not set, Tinyproxy returns a hard-coded basic statistics page.
See the STATHOST section in the `tinyproxy(8)` manual page
for details.
+
Note that the StatFile and the error files configured with ErrorFile
and DefaultErrorFile are template files that can contain a few
template variables that Tinyproxy expands prior to delivery.
@@ -114,7 +121,10 @@ The possible keywords and their descriptions are as follows:
*LogLevel*::
This sets the log level. Allowed values are:
Sets the log level. Messages from the set level and above are
logged. For example, if the LogLevel was set to Warning, then all
log messages from Warning to Critical would be output, but Notice
and below would be suppressed. Allowed values are:
* Critical (least verbose)
* Error
@@ -123,11 +133,6 @@ The possible keywords and their descriptions are as follows:
* Connect (log connections without Info's noise)
* Info (most verbose)
The LogLevel logs from the set level and above. For example, if
the LogLevel was set to Warning, than all log messages from
Warning to Critical would be output, but Notice and below would be
suppressed.
*PidFile*::
This option controls the location of the file where the main
@@ -138,7 +143,8 @@ The possible keywords and their descriptions are as follows:
Setting this option to `Yes` tells Tinyproxy to add a header
`X-Tinyproxy` containing the client's IP address to the request.
*[No] Upstream*::
*Upstream*::
*No Upstream*::
This option allows you to set up a set of rules for deciding
whether an upstream a proxy server is to be used, based on the
@@ -204,23 +210,42 @@ The possible keywords and their descriptions are as follows:
which clients are allowed to access Tinyproxy. `Allow` and `Deny`
lines can be specified multiple times to build the access control
list for Tinyproxy. The order in the config file is important.
If there are no `Access` or `Deny` lines, then all clients are
If there are no `Allow` or `Deny` lines, then all clients are
allowed. Otherwise, the default action is to deny access.
The argument to `Access` or `Deny` can be a single IP address
The argument to `Allow` or `Deny` can be a single IP address
of a client host, like `127.0.0.1`, an IP address range, like
`192.168.0.1/24` or a string that will be matched against the
end of the client host name, i.e, this can be a full host name
like `host.example.com` or a domain name like `.example.com` or
even a top level domain name like `.com`.
*AddHeader*::
Configure one or more HTTP request headers to be added to outgoing
HTTP requests that Tinyproxy makes. Note that this option will not
work for HTTPS traffic, as Tinyproxy has no control over what
headers are exchanged.
+
----
AddHeader "X-My-Header" "Powered by Tinyproxy"
----
*ViaProxyName*::
RFC 2616 requires proxies to add a `Via` header to the HTTP
requests, but using the real host name can be a security
concern. If the `ViaProxyname` option is present, than its
concern. If the `ViaProxyname` option is present, then its
string value will be used as the host name in the Via header.
Otherwise, the server's host name will be used.
*DisableViaHeader*::
When this is set to yes, Tinyproxy does NOT add the `Via` header
to the requests. This virtually puts Tinyproxy into stealth mode.
Note that RFC 2616 requires proxies to set the `Via` header, so by
enabling this option, you break compliance.
Don't disable the `Via` header unless you know what you are doing...
*Filter*::
Tinyproxy supports filtering of web sites based on URLs or
@@ -259,15 +284,17 @@ The possible keywords and their descriptions are as follows:
through, while all others are denied. If no Anonymous keyword
is present, then all headers are allowed through. You must
include quotes around the headers.
+
Most sites require cookies to be enabled for them to work correctly, so
you will need to allow Cookies through if you access those sites.
you will need to allow cookies through if you access those sites.
+
Example:
Anonymous "Host"
Anonymous "Authorization"
Anonymous "Cookie"
+
----
Anonymous "Host"
Anonymous "Authorization"
Anonymous "Cookie"
----
*ConnectPort*::
@@ -281,12 +308,14 @@ The possible keywords and their descriptions are as follows:
Configure one or more ReversePath directives to enable reverse proxy
support. With reverse proxying it's possible to make a number of
sites appear as if they were part of a single site.
+
If you uncomment the following two directives and run Tinyproxy
on your own computer at port 8888, you can access example.com,
using http://localhost:8888/example/.
ReversePath "/example/" "http://www.example.com/"
+
----
ReversePath "/example/" "http://www.example.com/"
----
*ReverseOnly*::
@@ -317,13 +346,24 @@ To report bugs in Tinyproxy, please visit
<https://www.banu.com/tinyproxy/support/[https://www.banu.com/tinyproxy/support/]>.
SEE ALSO
--------
tinyproxy(8)
AUTHOR
------
Written by the Tinyproxy project team.
COPYRIGHT
---------
Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009 Mukund Sivaraman;
Copyright (c) 2009 Michael Adam.
Copyright (c) 2009-2010 Mukund Sivaraman;
Copyright (c) 2009-2010 Michael Adam.
This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional
+1 -4
View File
@@ -10,14 +10,11 @@ man_MANS = \
.txt.8:
if HAVE_A2X
a2x $(A2X_ARGS) $<
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
else
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
endif
EXTRA_DIST = \
$(man_MANS)
CLEANFILES = \
$(MAN8_FILES:.txt=.8) \
$(MAN8_FILES:.txt=.xml)
+17 -6
View File
@@ -119,9 +119,9 @@ STATHOST
Tinyproxy returns a HTML page with connection statistics when it
receives a HTTP request for a certain host -- the stathost. The
stathost name defaults to `tinyproxy.stats` and can be changed at
compile-time with the configure switch `--with-stathost` to any name or
IP address.
stathost name defaults to `@TINYPROXY_STATHOST@` and can be changed at
runtime to any name or IP address with the configuration variable
`StatHost`.
The stat file template can be changed at runtime through the
configuration variable `StatFile`.
@@ -130,7 +130,7 @@ configuration variable `StatFile`.
FILES
-----
`/etc/tinyproxy/tinyproxy.conf`, `/var/run/tinyproxy.pid`, `/var/log/tinyproxy.log`
`/etc/tinyproxy/tinyproxy.conf`, `/var/run/tinyproxy/tinyproxy.pid`, `/var/log/tinyproxy/tinyproxy.log`
BUGS
----
@@ -139,13 +139,24 @@ To report bugs in Tinyproxy, please visit
<https://www.banu.com/tinyproxy/support/[https://www.banu.com/tinyproxy/support/]>.
SEE ALSO
--------
tinyproxy.conf(5)
AUTHOR
------
Written by the Tinyproxy project team.
COPYRIGHT
---------
Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009 Mukund Sivaraman;
Copyright (c) 2009 Michael Adam.
Copyright (c) 2009-2010 Mukund Sivaraman;
Copyright (c) 2009-2010 Michael Adam.
This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional
+1
View File
@@ -0,0 +1 @@
tinyproxy.conf
+19 -1
View File
@@ -2,4 +2,22 @@ sysconf_DATA = \
tinyproxy.conf
EXTRA_DIST = \
$(sysconf_DATA)
tinyproxy.conf.in
edit = sed \
-e 's|@bindir[@]|$(bindir)|g' \
-e 's|@datadir[@]|$(datadir)|g' \
-e 's|@datarootdir[@]|$(datarootdir)|g' \
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@localstatedir[@]|$(localstatedir)|g' \
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
-e 's|@prefix[@]|$(prefix)|g' \
-e 's|@TINYPROXY_STATHOST[@]|$(TINYPROXY_STATHOST)|g'
tinyproxy.conf: $(top_srcdir)/etc/tinyproxy.conf.in Makefile
@rm -f $@ $@.tmp
$(AM_V_GEN) $(edit) $(top_srcdir)/etc/$@.in > $@.tmp
@mv $@.tmp $@
CLEANFILES = \
tinyproxy.conf
+38 -12
View File
@@ -56,33 +56,43 @@ Timeout 600
# /usr/share/tinyproxy
# /etc/tinyproxy
#
#ErrorFile 404 "/usr/share/tinyproxy/404.html"
#ErrorFile 400 "/usr/share/tinyproxy/400.html"
#ErrorFile 503 "/usr/share/tinyproxy/503.html"
#ErrorFile 403 "/usr/share/tinyproxy/403.html"
#ErrorFile 408 "/usr/share/tinyproxy/408.html"
#ErrorFile 404 "@pkgdatadir@/404.html"
#ErrorFile 400 "@pkgdatadir@/400.html"
#ErrorFile 503 "@pkgdatadir@/503.html"
#ErrorFile 403 "@pkgdatadir@/403.html"
#ErrorFile 408 "@pkgdatadir@/408.html"
#
# DefaultErrorFile: The HTML file that gets sent if there is no
# HTML file defined with an ErrorFile keyword for the HTTP error
# that has occured.
#
DefaultErrorFile "/usr/share/tinyproxy/default.html"
DefaultErrorFile "@pkgdatadir@/default.html"
#
# StatHost: This configures the host name or IP address that is treated
# as the stat host: Whenever a request for this host is received,
# Tinyproxy will return an internal statistics page instead of
# forwarding the request to that host. The default value of StatHost is
# @TINYPROXY_STATHOST@.
#
#StatHost "@TINYPROXY_STATHOST@"
#
#
# StatFile: The HTML file that gets sent when a request is made
# for the stathost. If this file doesn't exist a basic page is
# hardcoded in tinyproxy.
#
StatFile "/usr/share/tinyproxy/stats.html"
StatFile "@pkgdatadir@/stats.html"
#
# Logfile: Allows you to specify the location where information should
# 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.
#
Logfile "/var/log/tinyproxy.log"
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
#
# Syslog: Tell tinyproxy to use syslog instead of a logfile. This
@@ -103,7 +113,7 @@ Logfile "/var/log/tinyproxy.log"
# Info (most verbose)
#
# The LogLevel logs from the set level and above. For example, if the
# LogLevel was set to Warning, than all log messages from Warning to
# LogLevel was set to Warning, then all log messages from Warning to
# Critical would be output, but Notice and below would be suppressed.
#
LogLevel Info
@@ -112,7 +122,7 @@ LogLevel Info
# PidFile: Write the PID of the main tinyproxy thread to this file so it
# can be used for signalling purposes.
#
PidFile "/var/run/tinyproxy.pid"
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
#
# XTinyproxy: Tell Tinyproxy to include the X-Tinyproxy header, which
@@ -199,6 +209,13 @@ MaxRequestsPerChild 0
#
Allow 127.0.0.1
#
# AddHeader: Adds the specified headers to outgoing HTTP requests that
# Tinyproxy makes. Note that this option will not work for HTTPS
# traffic, as Tinyproxy has no control over what headers are exchanged.
#
#AddHeader "X-My-Header" "Powered by Tinyproxy"
#
# ViaProxyName: The "Via" header is required by the HTTP RFC, but using
# the real host name is a security concern. If the following directive
@@ -207,10 +224,19 @@ Allow 127.0.0.1
#
ViaProxyName "tinyproxy"
#
# DisableViaHeader: When this is set to yes, Tinyproxy does NOT add
# the Via header to the requests. This virtually puts Tinyproxy into
# stealth mode. Note that RFC 2616 requires proxies to set the Via
# header, so by enabling this option, you break compliance.
# Don't disable the Via header unless you know what you are doing...
#
#DisableViaHeader Yes
#
# Filter: This allows you to specify the location of the filter file.
#
#Filter "/etc/tinyproxy/filter"
#Filter "@sysconfdir@/filter"
#
# FilterURLs: Filter based on URLs rather than domains.
-5
View File
@@ -1,5 +0,0 @@
# The various packaging directories
SUBDIRS = fedora
-1
View File
@@ -1 +0,0 @@
tinyproxy.spec
-9
View File
@@ -1,9 +0,0 @@
# Packaging files
PACKAGING_FILES = \
tinyproxy.init \
tinyproxy.spec
EXTRA_DIST = $(PACKAGING_FILES)
-106
View File
@@ -1,106 +0,0 @@
#!/bin/sh
#
# tinyproxy Startup script for the tinyproxy server
#
# chkconfig: - 85 15
# description: small, efficient HTTP/SSL proxy daemon
#
# processname: tinyproxy
# config: /etc/tinyproxy/tinyproxy.conf
# config: /etc/sysconfig/tinyproxy
# pidfile: /var/run/tinyproxy.pid
#
# Note: pidfile is created by tinyproxy in its config
# see PidFile in the configuration file.
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
exec="/usr/sbin/tinyproxy"
prog=$(basename $exec)
config="/etc/tinyproxy/tinyproxy.conf"
[ -e /etc/sysconfig/tinyproxy ] && . /etc/sysconfig/tinyproxy
lockfile=/var/lock/subsys/tinyproxy
start() {
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
echo -n $"Starting $prog: "
daemon $exec -c $config
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
-95
View File
@@ -1,95 +0,0 @@
%define tinyproxy_confdir %{_sysconfdir}/tinyproxy
%define tinyproxy_datadir %{_datadir}/tinyproxy
Name: tinyproxy
Version: @VERSION@
Release: 2%{?dist}
Summary: A light-weight HTTP proxy daemon
Group: System Environment/Daemons
License: GPLv2+
URL: https://www.banu.com/tinyproxy/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Source0: https://www.banu.com/pub/tinyproxy/1.7/%{name}-%{version}.tar.gz
Source1: %{name}.init
Source2: %{name}.conf
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
%description
Tinyproxy is a light-weight HTTP proxy daemon designed to consume a
minimum amount of system resources. It listens on a given TCP port and
handles HTTP proxy requests. Designed from the ground up to be fast and
yet small, it is an ideal solution for use cases such as embedded
deployments where a full featured HTTP proxy is required, but the system
resources for a larger proxy are unavailable.
%prep
%setup -q
%build
%configure --with-config=%{tinyproxy_confdir}/%{name}.conf
make %{?_smp_mflags}
%install
rm -rf %{buildroot}
make install-exec DESTDIR=%{buildroot}
# The default 'make install' installs too many items, so we trim it down
# and install manually
%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/%{name}
%{__install} -p -D -m 0644 %{SOURCE2} %{buildroot}%{tinyproxy_confdir}/%{name}.conf
%{__install} -d -m 0755 %{buildroot}%{tinyproxy_datadir}
%{__install} -p -D -m 0644 ./doc/%{name}.8 %{buildroot}%{_mandir}/man8/%{name}.8
for htmlfile in $(find ./doc/ -type f -name '*.html')
do
%{__install} -p -m 0644 $htmlfile %{buildroot}%{tinyproxy_datadir}
done
%clean
rm -rf %{buildroot}
%post
/sbin/chkconfig --add %{name}
%preun
if [ $1 = 0 ]; then
/sbin/service %{name} stop >/dev/null 2>&1
/sbin/chkconfig --del %{name}
fi
%postun
if [ "$1" -ge "1" ]; then
/sbin/service %{name} condrestart > /dev/null 2>&1 || :
fi
%files
%defattr(-,root,root,-)
%doc AUTHORS COPYING README doc/*.txt
%{_sbindir}/%{name}
%{_mandir}/man8/%{name}.8.gz
%{_initrddir}/%{name}
%dir %{tinyproxy_datadir}
%dir %{tinyproxy_datadir}/*
%dir %{tinyproxy_confdir}
%config(noreplace) %{tinyproxy_confdir}/%{name}.conf
%changelog
* Wed Apr 16 2008 Jeremy Hinegardner <jeremy at hinegardner dot org> - 1.6.3-2
- fix spec review issues
- fix initscript
* Sun Mar 09 2008 Jeremy Hinegardner <jeremy at hinegardner dot org> - 1.6.3-1
- Initial rpm configuration
+5 -2
View File
@@ -18,7 +18,8 @@
sbin_PROGRAMS = tinyproxy
AM_CPPFLAGS = \
-DSYSCONFDIR=\"${sysconfdir}\"
-DSYSCONFDIR=\"${sysconfdir}\" \
-DLOCALSTATEDIR=\"${localstatedir}\"
tinyproxy_SOURCES = \
acl.c acl.h \
@@ -41,7 +42,9 @@ tinyproxy_SOURCES = \
text.c text.h \
main.c main.h \
utils.c utils.h \
vector.c vector.h
vector.c vector.h \
upstream.c upstream.h \
connect-ports.c connect-ports.h
EXTRA_tinyproxy_SOURCES = filter.c filter.h \
reverse-proxy.c reverse-proxy.h \
+53 -28
View File
@@ -57,11 +57,6 @@ struct acl_s {
} address;
};
/*
* All the access lists are stored in a vector.
*/
static vector_t access_list = NULL;
/*
* Fills in the netmask array given a numeric value.
*
@@ -72,22 +67,22 @@ static vector_t access_list = NULL;
*/
static int
fill_netmask_array (char *bitmask_string, unsigned char array[],
unsigned int len)
size_t len)
{
unsigned int i;
long int mask;
unsigned long int mask;
char *endptr;
errno = 0; /* to distinguish success/failure after call */
mask = strtol (bitmask_string, &endptr, 10);
mask = strtoul (bitmask_string, &endptr, 10);
/* check for various conversion errors */
if ((errno == ERANGE && (mask == LONG_MIN || mask == LONG_MAX))
if ((errno == ERANGE && mask == ULONG_MAX)
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
return -1;
/* valid range for a bit mask */
if (mask < 0 || mask > (8 * len))
if (mask > (8 * len))
return -1;
/* we have a valid range to fill in the array */
@@ -106,6 +101,23 @@ fill_netmask_array (char *bitmask_string, unsigned char array[],
return 0;
}
/**
* If the access list has not been set up, create it.
*/
static int init_access_list(vector_t *access_list)
{
if (!*access_list) {
*access_list = vector_create ();
if (!*access_list) {
log_message (LOG_ERR,
"Unable to allocate memory for access list");
return -1;
}
}
return 0;
}
/*
* Inserts a new access control into the list. The function will figure out
* whether the location is an IP address (with optional netmask) or a
@@ -115,7 +127,7 @@ fill_netmask_array (char *bitmask_string, unsigned char array[],
* -1 on failure
* 0 otherwise.
*/
int insert_acl (char *location, acl_access_t access_type)
int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
{
struct acl_s acl;
int ret;
@@ -123,16 +135,9 @@ int insert_acl (char *location, acl_access_t access_type)
assert (location != NULL);
/*
* If the access list has not been set up, create it.
*/
if (!access_list) {
access_list = vector_create ();
if (!access_list) {
log_message (LOG_ERR,
"Unable to allocate memory for access list");
return -1;
}
ret = init_access_list(access_list);
if (ret != 0) {
return -1;
}
/*
@@ -179,11 +184,7 @@ int insert_acl (char *location, acl_access_t access_type)
}
}
/*
* Add the entry and then clean up.
*/
ret = vector_append (access_list, &acl, sizeof (struct acl_s));
safefree (acl.address.string);
ret = vector_append (*access_list, &acl, sizeof (struct acl_s));
return ret;
}
@@ -291,7 +292,7 @@ static int check_numeric_acl (const struct acl_s *acl, const char *ip)
/* If x and y don't match, the IP addresses don't match */
if (x != y)
return 0;
return -1;
}
/* The addresses match, return the permission */
@@ -305,7 +306,7 @@ static int check_numeric_acl (const struct acl_s *acl, const char *ip)
* 1 if allowed
* 0 if denied
*/
int check_acl (const char *ip, const char *host)
int check_acl (const char *ip, const char *host, vector_t access_list)
{
struct acl_s *acl;
int perm = 0;
@@ -351,3 +352,27 @@ int check_acl (const char *ip, const char *host)
host, ip);
return 0;
}
void flush_access_list (vector_t access_list)
{
struct acl_s *acl;
size_t i;
if (!access_list) {
return;
}
/*
* We need to free allocated data hanging off the acl entries
* before we can free the acl entries themselves.
* A hierarchical memory system would be great...
*/
for (i = 0; i != (size_t) vector_length (access_list); ++i) {
acl = (struct acl_s *) vector_getentry (access_list, i, NULL);
if (acl->type == ACL_STRING) {
safefree (acl->address.string);
}
}
vector_delete (access_list);
}
+7 -2
View File
@@ -21,9 +21,14 @@
#ifndef TINYPROXY_ACL_H
#define TINYPROXY_ACL_H
#include "vector.h"
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
extern int insert_acl (char *location, acl_access_t access_type);
extern int check_acl (const char *ip_address, const char *string_address);
extern int insert_acl (char *location, acl_access_t access_type,
vector_t *access_list);
extern int check_acl (const char *ip_address, const char *string_address,
vector_t access_list);
extern void flush_access_list (vector_t access_list);
#endif
+9 -10
View File
@@ -26,12 +26,11 @@
#include "hashmap.h"
#include "heap.h"
#include "log.h"
static hashmap_t anonymous_map = NULL;
#include "conf.h"
short int is_anonymous_enabled (void)
{
return (anonymous_map != NULL) ? 1 : 0;
return (config.anonymous_map != NULL) ? 1 : 0;
}
/*
@@ -41,9 +40,9 @@ short int is_anonymous_enabled (void)
int anonymous_search (const char *s)
{
assert (s != NULL);
assert (anonymous_map != NULL);
assert (config.anonymous_map != NULL);
return hashmap_search (anonymous_map, s);
return hashmap_search (config.anonymous_map, s);
}
/*
@@ -58,17 +57,17 @@ int anonymous_insert (const char *s)
assert (s != NULL);
if (!anonymous_map) {
anonymous_map = hashmap_create (32);
if (!anonymous_map)
if (!config.anonymous_map) {
config.anonymous_map = hashmap_create (32);
if (!config.anonymous_map)
return -1;
}
if (hashmap_search (anonymous_map, s) > 0) {
if (hashmap_search (config.anonymous_map, s) > 0) {
/* The key was already found, so return a positive number. */
return 0;
}
/* Insert the new key */
return hashmap_insert (anonymous_map, s, &data, sizeof (data));
return hashmap_insert (config.anonymous_map, s, &data, sizeof (data));
}
+31 -10
View File
@@ -30,6 +30,7 @@
#include "reqs.h"
#include "sock.h"
#include "utils.h"
#include "conf.h"
static int listenfd;
static socklen_t addrlen;
@@ -160,6 +161,24 @@ short int child_configure (child_config_t type, unsigned int val)
return 0;
}
/**
* child signal handler for sighup
*/
static void child_sighup_handler (int sig)
{
if (sig == SIGHUP) {
/*
* Ignore the return value of reload_config for now.
* This should actually be handled somehow...
*/
reload_config ();
#ifdef FILTER_ENABLE
filter_reload ();
#endif /* FILTER_ENABLE */
}
}
/*
* This is the main (per child) loop.
*/
@@ -272,7 +291,7 @@ static pid_t child_make (struct child_s *ptr)
*/
set_signal_handler (SIGCHLD, SIG_DFL);
set_signal_handler (SIGTERM, SIG_DFL);
set_signal_handler (SIGHUP, SIG_DFL);
set_signal_handler (SIGHUP, child_sighup_handler);
child_main (ptr); /* never returns */
return -1;
@@ -414,17 +433,19 @@ void child_main_loop (void)
/* Handle log rotation if it was requested */
if (received_sighup) {
truncate_log_file ();
/*
* Ignore the return value of reload_config for now.
* This should actually be handled somehow...
*/
reload_config ();
#ifdef FILTER_ENABLE
if (config.filter) {
log_message (LOG_NOTICE,
"Re-reading filter file.");
filter_destroy ();
filter_init ();
}
filter_reload ();
#endif /* FILTER_ENABLE */
/* propagate filter reload to all children */
child_kill_children (SIGHUP);
received_sighup = FALSE;
}
}
@@ -433,13 +454,13 @@ void child_main_loop (void)
/*
* Go through all the non-empty children and cancel them.
*/
void child_kill_children (void)
void child_kill_children (int sig)
{
unsigned int i;
for (i = 0; i != child_config.maxclients; i++) {
if (child_ptr[i].status != T_EMPTY)
kill (child_ptr[i].tid, SIGTERM);
kill (child_ptr[i].tid, sig);
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ extern short int child_pool_create (void);
extern int child_listening_sock (uint16_t port);
extern void child_close_sock (void);
extern void child_main_loop (void);
extern void child_kill_children (void);
extern void child_kill_children (int sig);
extern short int child_configure (child_config_t type, unsigned int val);
+318 -26
View File
@@ -1,5 +1,6 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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
@@ -22,8 +23,6 @@
* add new directives to. Who knows if I'm right though.
*/
#include "main.h"
#include "conf.h"
#include "acl.h"
@@ -35,6 +34,8 @@
#include "log.h"
#include "reqs.h"
#include "reverse-proxy.h"
#include "upstream.h"
#include "connect-ports.h"
/*
* The configuration directives are defined in the structure below. Each
@@ -52,6 +53,28 @@
#define ALNUM "([-a-z0-9._]+)"
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
#define IPMASK "(" IP "(/[[:digit:]]+)?)"
#define IPV6 "(" \
"(([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,6})|" \
"(([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5})|" \
"(([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4})|" \
"(([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3})|" \
"(([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2})|" \
"(([0-9a-f]{1,4}:){1,6}(:[0-9a-f]{1,4}){1,1})|" \
"((([0-9a-f]{1,4}:){1,7}|:):)|" \
"(:(:[0-9a-f]{1,4}){1,7})|" \
"([0-9a-f]{1,4}(:[0-9a-f]{1,4}){1,7})|" \
"(((([0-9a-f]{1,4}:){6})(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}))|" \
"((([0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}))|" \
"(([0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
"(([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,4}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
"(([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,3}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
"(([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,2}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
"(([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,1}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
"((([0-9a-f]{1,4}:){1,5}|:):(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
"(:(:[0-9a-f]{1,4}){1,5}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})" \
")"
#define IPV6MASK "(" IPV6 "(/[[:digit:]]+)?)"
#define BEGIN "^[[:space:]]*"
#define END "[[:space:]]*$"
@@ -81,7 +104,7 @@ typedef int (*CONFFILE_HANDLER) (struct config_s *, const char *, regmatch_t[]);
*/
#define HANDLE_FUNC(func) \
int func(struct config_s* conf, const char* line, \
regmatch_t match[])
regmatch_t match[])
/*
* List all the handling functions. These are defined later, but they need
@@ -100,6 +123,7 @@ static HANDLE_FUNC (handle_connectport);
static HANDLE_FUNC (handle_defaulterrorfile);
static HANDLE_FUNC (handle_deny);
static HANDLE_FUNC (handle_errorfile);
static HANDLE_FUNC (handle_addheader);
#ifdef FILTER_ENABLE
static HANDLE_FUNC (handle_filter);
static HANDLE_FUNC (handle_filtercasesensitive);
@@ -131,6 +155,7 @@ static HANDLE_FUNC (handle_timeout);
static HANDLE_FUNC (handle_user);
static HANDLE_FUNC (handle_viaproxyname);
static HANDLE_FUNC (handle_disableviaheader);
static HANDLE_FUNC (handle_xtinyproxy);
#ifdef UPSTREAM_SUPPORT
@@ -182,6 +207,7 @@ struct {
/* boolean arguments */
STDCONF ("syslog", BOOL, handle_syslog),
STDCONF ("bindsame", BOOL, handle_bindsame),
STDCONF ("disableviaheader", BOOL, handle_disableviaheader),
/* integer arguments */
STDCONF ("port", INT, handle_port),
STDCONF ("maxclients", INT, handle_maxclients),
@@ -195,12 +221,16 @@ struct {
STDCONF ("user", ALNUM, handle_user),
STDCONF ("group", ALNUM, handle_group),
/* ip arguments */
STDCONF ("listen", IP, handle_listen),
STDCONF ("allow", "(" IPMASK "|" ALNUM ")", handle_allow),
STDCONF ("deny", "(" IPMASK "|" ALNUM ")", handle_deny),
STDCONF ("bind", IP, handle_bind),
/* error files */
STDCONF ("listen", "(" IP "|" IPV6 ")", handle_listen),
STDCONF ("allow", "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
handle_allow),
STDCONF ("deny", "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
handle_deny),
STDCONF ("bind", "(" IP "|" IPV6 ")", handle_bind),
/* other */
STDCONF ("errorfile", INT WS STR, handle_errorfile),
STDCONF ("addheader", STR WS STR, handle_addheader),
#ifdef FILTER_ENABLE
/* filtering */
STDCONF ("filter", STR, handle_filter),
@@ -214,7 +244,7 @@ struct {
STDCONF ("reversebaseurl", STR, handle_reversebaseurl),
STDCONF ("reverseonly", BOOL, handle_reverseonly),
STDCONF ("reversemagic", BOOL, handle_reversemagic),
STDCONF ("reversepath", STR WS "(" STR ")?", handle_reversepath),
STDCONF ("reversepath", STR "(" WS STR ")?", handle_reversepath),
#endif
#ifdef UPSTREAM_SUPPORT
/* upstream is rather complicated */
@@ -233,13 +263,61 @@ struct {
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
static void
free_added_headers (vector_t add_headers)
{
ssize_t i;
for (i = 0; i < vector_length (add_headers); i++) {
http_header_t *header = (http_header_t *)
vector_getentry (add_headers, i, NULL);
safefree (header->name);
safefree (header->value);
}
vector_delete (add_headers);
}
static void free_config (struct config_s *conf)
{
safefree (conf->config_file);
safefree (conf->logf_name);
safefree (conf->stathost);
safefree (conf->user);
safefree (conf->group);
safefree (conf->ipAddr);
#ifdef FILTER_ENABLE
safefree (conf->filter);
#endif /* FILTER_ENABLE */
#ifdef REVERSE_SUPPORT
free_reversepath_list(conf->reversepath_list);
safefree (conf->reversebaseurl);
#endif
#ifdef UPSTREAM_SUPPORT
free_upstream_list (conf->upstream_list);
#endif /* UPSTREAM_SUPPORT */
safefree (conf->pidpath);
safefree (conf->bind_address);
safefree (conf->via_proxy_name);
hashmap_delete (conf->errorpages);
free_added_headers (conf->add_headers);
safefree (conf->errorpage_undef);
safefree (conf->statpage);
flush_access_list (conf->access_list);
free_connect_ports_list (conf->connect_ports);
hashmap_delete (conf->anonymous_map);
memset (conf, 0, sizeof(*conf));
}
/*
* Compiles the regular expressions used by the configuration file. This
* routine MUST be called before trying to parse the configuration file.
*
* Returns 0 on success; negative upon failure.
*/
int config_compile (void)
static int config_compile (void)
{
unsigned int i, r;
@@ -288,7 +366,7 @@ static int check_match (struct config_s *conf, const char *line)
/*
* Parse the previously opened configuration stream.
*/
int config_parse (struct config_s *conf, FILE * f)
static int config_parse (struct config_s *conf, FILE * f)
{
char buffer[1024]; /* 1KB lines should be plenty */
unsigned long lineno = 1;
@@ -303,6 +381,177 @@ int config_parse (struct config_s *conf, FILE * f)
return 0;
}
/**
* Read the settings from a config file.
*/
static int load_config_file (const char *config_fname, struct config_s *conf)
{
FILE *config_file;
int ret = -1;
config_file = fopen (config_fname, "r");
if (!config_file) {
fprintf (stderr,
"%s: Could not open config file \"%s\".\n",
PACKAGE, config_fname);
goto done;
}
if (config_compile () || config_parse (conf, config_file)) {
fprintf (stderr, "Unable to parse config file. "
"Not starting.\n");
goto done;
}
ret = 0;
done:
if (config_file)
fclose (config_file);
return ret;
}
static void initialize_with_defaults (struct config_s *conf,
struct config_s *defaults)
{
if (defaults->logf_name) {
conf->logf_name = safestrdup (defaults->logf_name);
}
if (defaults->config_file) {
conf->config_file = safestrdup (defaults->config_file);
}
conf->syslog = defaults->syslog;
conf->port = defaults->port;
if (defaults->stathost) {
conf->stathost = safestrdup (defaults->stathost);
}
conf->godaemon = defaults->godaemon;
conf->quit = defaults->quit;
if (defaults->user) {
conf->user = safestrdup (defaults->user);
}
if (defaults->group) {
conf->group = safestrdup (defaults->group);
}
if (defaults->ipAddr) {
conf->ipAddr = safestrdup (defaults->ipAddr);
}
#ifdef FILTER_ENABLE
if (defaults->filter) {
conf->filter = safestrdup (defaults->filter);
}
conf->filter_url = defaults->filter_url;
conf->filter_extended = defaults->filter_extended;
conf->filter_casesensitive = defaults->filter_casesensitive;
#endif /* FILTER_ENABLE */
#ifdef XTINYPROXY_ENABLE
conf->add_xtinyproxy = defaults->add_xtinyproxy;
#endif
#ifdef REVERSE_SUPPORT
/* struct reversepath *reversepath_list; */
conf->reverseonly = defaults->reverseonly;
conf->reversemagic = defaults->reversemagic;
if (defaults->reversebaseurl) {
conf->reversebaseurl = safestrdup (defaults->reversebaseurl);
}
#endif
#ifdef UPSTREAM_SUPPORT
/* struct upstream *upstream_list; */
#endif /* UPSTREAM_SUPPORT */
if (defaults->pidpath) {
conf->pidpath = safestrdup (defaults->pidpath);
}
conf->idletimeout = defaults->idletimeout;
if (defaults->bind_address) {
conf->bind_address = safestrdup (defaults->bind_address);
}
conf->bindsame = defaults->bindsame;
if (defaults->via_proxy_name) {
conf->via_proxy_name = safestrdup (defaults->via_proxy_name);
}
conf->disable_viaheader = defaults->disable_viaheader;
if (defaults->errorpage_undef) {
conf->errorpage_undef = safestrdup (defaults->errorpage_undef);
}
if (defaults->statpage) {
conf->statpage = safestrdup (defaults->statpage);
}
/* vector_t access_list; */
/* vector_t connect_ports; */
/* hashmap_t anonymous_map; */
}
/**
* Load the configuration.
*/
int reload_config_file (const char *config_fname, struct config_s *conf,
struct config_s *defaults)
{
int ret;
log_message (LOG_INFO, "Reloading config file");
free_config (conf);
initialize_with_defaults (conf, defaults);
ret = load_config_file (config_fname, conf);
if (ret != 0) {
goto done;
}
/* Set the default values if they were not set in the config file. */
if (conf->port == 0) {
/*
* Don't log here in error path:
* logging might not be set up yet!
*/
fprintf (stderr, PACKAGE ": You MUST set a Port in the "
"config file.\n");
ret = -1;
goto done;
}
if (!conf->user) {
log_message (LOG_WARNING, "You SHOULD set a UserName in the "
"config file. Using current user instead.");
}
if (conf->idletimeout == 0) {
log_message (LOG_WARNING, "Invalid idle time setting. "
"Only values greater than zero are allowed. "
"Therefore setting idle timeout to %u seconds.",
MAX_IDLE_TIME);
conf->idletimeout = MAX_IDLE_TIME;
}
done:
return ret;
}
/***********************************************************************
*
* The following are basic data extraction building blocks that can
@@ -333,9 +582,14 @@ static int set_string_arg (char **var, const char *line, regmatch_t * match)
if (!arg)
return -1;
*var = safestrdup (arg);
safefree (arg);
return *var ? 0 : -1;
if (*var != NULL) {
safefree (*var);
}
*var = arg;
return 0;
}
static int get_bool_arg (const char *line, regmatch_t * match)
@@ -430,11 +684,24 @@ static HANDLE_FUNC (handle_viaproxyname)
if (r)
return r;
log_message (LOG_INFO,
"Setting \"Via\" header proxy to %s",
"Setting \"Via\" header to '%s'",
conf->via_proxy_name);
return 0;
}
static HANDLE_FUNC (handle_disableviaheader)
{
int r = set_bool_arg (&conf->disable_viaheader, line, &match[2]);
if (r) {
return r;
}
log_message (LOG_INFO,
"Disabling transmission of the \"Via\" header.");
return 0;
}
static HANDLE_FUNC (handle_defaulterrorfile)
{
return set_string_arg (&conf->errorpage_undef, line, &match[2]);
@@ -530,7 +797,8 @@ static HANDLE_FUNC (handle_timeout)
static HANDLE_FUNC (handle_connectport)
{
add_connect_port_allowed (get_int_arg (line, &match[2]));
add_connect_port_allowed (get_int_arg (line, &match[2]),
&conf->connect_ports);
return 0;
}
@@ -548,7 +816,7 @@ static HANDLE_FUNC (handle_allow)
{
char *arg = get_string_arg (line, &match[2]);
insert_acl (arg, ACL_ALLOW);
insert_acl (arg, ACL_ALLOW, &conf->access_list);
safefree (arg);
return 0;
}
@@ -557,7 +825,7 @@ static HANDLE_FUNC (handle_deny)
{
char *arg = get_string_arg (line, &match[2]);
insert_acl (arg, ACL_DENY);
insert_acl (arg, ACL_DENY, &conf->access_list);
safefree (arg);
return 0;
}
@@ -585,7 +853,7 @@ static HANDLE_FUNC (handle_listen)
if (r)
return r;
log_message (LOG_INFO, "Listing on IP %s", conf->ipAddr);
log_message (LOG_INFO, "Listening on IP %s", conf->ipAddr);
return 0;
}
@@ -606,6 +874,30 @@ static HANDLE_FUNC (handle_errorfile)
return 0;
}
static HANDLE_FUNC (handle_addheader)
{
char *name = get_string_arg (line, &match[2]);
char *value = get_string_arg (line, &match[3]);
http_header_t *header;
if (!conf->add_headers) {
conf->add_headers = vector_create ();
}
header = (http_header_t *) safemalloc (sizeof (http_header_t));
header->name = name;
header->value = value;
vector_prepend (conf->add_headers, header, sizeof *header);
safefree (header);
/* Don't free name or value here, as they are referenced in the
* struct inserted into the vector. */
return 0;
}
/*
* Log level's strings.
*/
@@ -700,17 +992,17 @@ static HANDLE_FUNC (handle_reversepath)
if (!arg1)
return -1;
if (match[3].rm_so != -1) {
arg2 = get_string_arg (line, &match[3]);
if (match[4].rm_so != -1) {
arg2 = get_string_arg (line, &match[4]);
if (!arg2) {
safefree (arg1);
return -1;
}
reversepath_add (arg1, arg2);
reversepath_add (arg1, arg2, &conf->reversepath_list);
safefree (arg1);
safefree (arg2);
} else {
reversepath_add (NULL, arg1);
reversepath_add (NULL, arg1, &conf->reversepath_list);
safefree (arg1);
}
return 0;
@@ -732,11 +1024,11 @@ static HANDLE_FUNC (handle_upstream)
if (match[9].rm_so != -1) {
domain = get_string_arg (line, &match[9]);
if (domain) {
upstream_add (ip, port, domain);
upstream_add (ip, port, domain, &conf->upstream_list);
safefree (domain);
}
} else {
upstream_add (ip, port, NULL);
upstream_add (ip, port, NULL, &conf->upstream_list);
}
safefree (ip);
@@ -752,7 +1044,7 @@ static HANDLE_FUNC (handle_upstream_no)
if (!domain)
return -1;
upstream_add (NULL, 0, domain);
upstream_add (NULL, 0, domain, &conf->upstream_list);
safefree (domain);
return 0;
+93 -2
View File
@@ -1,5 +1,6 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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
@@ -21,7 +22,97 @@
#ifndef TINYPROXY_CONF_H
#define TINYPROXY_CONF_H
extern int config_compile (void);
extern int config_parse (struct config_s *conf, FILE * f);
#include "hashmap.h"
#include "vector.h"
/*
* Stores a HTTP header created using the AddHeader directive.
*/
typedef struct {
char *name;
char *value;
} http_header_t;
/*
* Hold all the configuration time information.
*/
struct config_s {
char *logf_name;
char *config_file;
unsigned int syslog; /* boolean */
int port;
char *stathost;
unsigned int godaemon; /* boolean */
unsigned int quit; /* boolean */
char *user;
char *group;
char *ipAddr;
#ifdef FILTER_ENABLE
char *filter;
unsigned int filter_url; /* boolean */
unsigned int filter_extended; /* boolean */
unsigned int filter_casesensitive; /* boolean */
#endif /* FILTER_ENABLE */
#ifdef XTINYPROXY_ENABLE
unsigned int add_xtinyproxy; /* boolean */
#endif
#ifdef REVERSE_SUPPORT
struct reversepath *reversepath_list;
unsigned int reverseonly; /* boolean */
unsigned int reversemagic; /* boolean */
char *reversebaseurl;
#endif
#ifdef UPSTREAM_SUPPORT
struct upstream *upstream_list;
#endif /* UPSTREAM_SUPPORT */
char *pidpath;
unsigned int idletimeout;
char *bind_address;
unsigned int bindsame;
/*
* The configured name to use in the HTTP "Via" header field.
*/
char *via_proxy_name;
unsigned int disable_viaheader; /* boolean */
/*
* Error page support. Map error numbers to file paths.
*/
hashmap_t errorpages;
/*
* Error page to be displayed if appropriate page cannot be located
* in the errorpages structure.
*/
char *errorpage_undef;
/*
* The HTML statistics page.
*/
char *statpage;
vector_t access_list;
/*
* Store the list of port allowed by CONNECT.
*/
vector_t connect_ports;
/*
* Map of headers which should be let through when the
* anonymous feature is turned on.
*/
hashmap_t anonymous_map;
/*
* Extra headers to be added to outgoing HTTP requests.
*/
vector_t add_headers;
};
extern int reload_config_file (const char *config_fname, struct config_s *conf,
struct config_s *defaults);
#endif
+77
View File
@@ -0,0 +1,77 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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 "connect-ports.h"
#include "log.h"
/*
* Now, this routine adds a "port" to the list. It also creates the list if
* it hasn't already by done.
*/
void add_connect_port_allowed (int port, vector_t *connect_ports)
{
if (!*connect_ports) {
*connect_ports = vector_create ();
if (!*connect_ports) {
log_message (LOG_WARNING,
"Could not create a list of allowed CONNECT ports");
return;
}
}
log_message (LOG_INFO,
"Adding Port [%d] to the list allowed by CONNECT", port);
vector_append (*connect_ports, (void **) &port, sizeof (port));
}
/*
* This routine checks to see if a port is allowed in the CONNECT method.
*
* Returns: 1 if allowed
* 0 if denied
*/
int check_allowed_connect_ports (int port, vector_t connect_ports)
{
size_t i;
int *data;
/*
* The absence of ConnectPort options in the config file
* meanas that all ports are allowed for CONNECT.
*/
if (!connect_ports)
return 1;
for (i = 0; i != (size_t) vector_length (connect_ports); ++i) {
data = (int *) vector_getentry (connect_ports, i, NULL);
if (data && *data == port)
return 1;
}
return 0;
}
/**
* Free a connect_ports list.
*/
void free_connect_ports_list (vector_t connect_ports)
{
vector_delete (connect_ports);
}
+31
View File
@@ -0,0 +1,31 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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_CONNECT_PORTS_H_
#define _TINYPROXY_CONNECT_PORTS_H_
#include "common.h"
#include "vector.h"
extern void add_connect_port_allowed (int port, vector_t *connect_ports);
int check_allowed_connect_ports (int port, vector_t connect_ports);
void free_connect_ports_list (vector_t connect_ports);
#endif /* _TINYPROXY_CONNECT_PORTS_ */
+2 -1
View File
@@ -76,7 +76,8 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
/* There is _no_ content length initially */
connptr->content_length.server = connptr->content_length.client = -1;
connptr->server_ip_addr = sock_ipaddr ? safestrdup (sock_ipaddr) : 0;
connptr->server_ip_addr = (sock_ipaddr ?
safestrdup (sock_ipaddr) : NULL);
connptr->client_ip_addr = safestrdup (ipaddr);
connptr->client_string_addr = safestrdup (string_addr);
+1 -1
View File
@@ -48,7 +48,7 @@ void makedaemon (void)
umask (0177);
#if NDEBUG
#ifdef NDEBUG
/*
* When not in debugging mode, close the standard file
* descriptors.
+13
View File
@@ -28,6 +28,7 @@
#include "heap.h"
#include "log.h"
#include "reqs.h"
#include "conf.h"
#define FILTER_BUFFER_LEN (512)
@@ -150,6 +151,18 @@ void filter_destroy (void)
}
}
/**
* reload the filter file if filtering is enabled
*/
void filter_reload (void)
{
if (config.filter) {
log_message (LOG_NOTICE, "Re-reading filter file.");
filter_destroy ();
filter_init ();
}
}
/* Return 0 to allow, non-zero to block */
int filter_domain (const char *host)
{
+1
View File
@@ -28,6 +28,7 @@ typedef enum {
extern void filter_init (void);
extern void filter_destroy (void);
extern void filter_reload (void);
extern int filter_domain (const char *host);
extern int filter_url (const char *url);
+2
View File
@@ -21,6 +21,8 @@
#ifndef _HASHMAP_H
#define _HASHMAP_H
#include "common.h"
/*
* We're using a typedef here to "hide" the implementation details of the
* hash map. Sure, it's a pointer, but the struct is hidden in the C file.
+8 -6
View File
@@ -38,8 +38,8 @@ void *debugging_calloc (size_t nmemb, size_t size, const char *file,
assert (size > 0);
ptr = calloc (nmemb, size);
fprintf (stderr, "{calloc: %p:%zu x %zu} %s:%lu\n", ptr, nmemb, size,
file, line);
fprintf (stderr, "{calloc: %p:%lu x %lu} %s:%lu\n", ptr,
(unsigned long) nmemb, (unsigned long) size, file, line);
return ptr;
}
@@ -50,7 +50,8 @@ void *debugging_malloc (size_t size, const char *file, unsigned long line)
assert (size > 0);
ptr = malloc (size);
fprintf (stderr, "{malloc: %p:%zu} %s:%lu\n", ptr, size, file, line);
fprintf (stderr, "{malloc: %p:%lu} %s:%lu\n", ptr,
(unsigned long) size, file, line);
return ptr;
}
@@ -62,8 +63,8 @@ void *debugging_realloc (void *ptr, size_t size, const char *file,
assert (size > 0);
newptr = realloc (ptr, size);
fprintf (stderr, "{realloc: %p -> %p:%zu} %s:%lu\n", ptr, newptr, size,
file, line);
fprintf (stderr, "{realloc: %p -> %p:%lu} %s:%lu\n", ptr, newptr,
(unsigned long) size, file, line);
return newptr;
}
@@ -89,7 +90,8 @@ char *debugging_strdup (const char *s, const char *file, unsigned long line)
return NULL;
memcpy (ptr, s, len);
fprintf (stderr, "{strdup: %p:%zu} %s:%lu\n", ptr, len, file, line);
fprintf (stderr, "{strdup: %p:%lu} %s:%lu\n", ptr,
(unsigned long) len, file, line);
return ptr;
}
+32 -24
View File
@@ -29,6 +29,7 @@
#include "html-error.h"
#include "network.h"
#include "utils.h"
#include "conf.h"
/*
* Add an error number -> filename mapping to the errorpages list.
@@ -103,42 +104,42 @@ static char *lookup_variable (struct conn_s *connptr, const char *varname)
return (data);
}
#define HTML_BUFSIZE 4096
/*
* Send an already-opened file to the client with variable substitution.
*/
int send_html_file (FILE * infile, struct conn_s *connptr)
int
send_html_file (FILE *infile, struct conn_s *connptr)
{
char inbuf[HTML_BUFSIZE], *varstart = NULL, *p;
char *inbuf;
char *varstart = NULL;
char *p;
const char *varval;
int in_variable = 0, writeret;
int in_variable = 0;
int r = 0;
while (fgets (inbuf, HTML_BUFSIZE, infile) != NULL) {
inbuf = (char *) safemalloc (4096);
while (fgets (inbuf, 4096, infile) != NULL) {
for (p = inbuf; *p; p++) {
switch (*p) {
case '}':
if (in_variable) {
*p = '\0';
varval =
(const char *)
lookup_variable (connptr, varstart);
varval = (const char *)
lookup_variable (connptr,
varstart);
if (!varval)
varval = "(unknown)";
writeret =
write_message (connptr->client_fd,
r = write_message (connptr->client_fd,
"%s", varval);
if (writeret)
return (writeret);
in_variable = 0;
} else {
writeret =
write_message (connptr->client_fd,
r = write_message (connptr->client_fd,
"%c", *p);
if (writeret)
return (writeret);
}
break;
case '{':
/* a {{ will print a single {. If we are NOT
* already in a { variable, then proceed with
@@ -151,20 +152,27 @@ int send_html_file (FILE * infile, struct conn_s *connptr)
in_variable++;
} else
in_variable = 0;
default:
if (!in_variable) {
writeret =
write_message (connptr->client_fd,
r = write_message (connptr->client_fd,
"%c", *p);
if (writeret)
return (writeret);
}
}
if (r)
break;
}
if (r)
break;
in_variable = 0;
}
return (0);
safefree (inbuf);
return r;
}
int send_http_headers (struct conn_s *connptr, int code, const char *message)
@@ -272,7 +280,7 @@ int add_standard_vars (struct conn_s *connptr)
add_error_variable (connptr, "date", timebuf);
add_error_variable (connptr, "website",
"http://www.banu.com/tinyproxy/");
"https://www.banu.com/tinyproxy/");
add_error_variable (connptr, "version", VERSION);
add_error_variable (connptr, "package", PACKAGE);
+88 -37
View File
@@ -1,6 +1,7 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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
@@ -27,6 +28,7 @@
#include "log.h"
#include "utils.h"
#include "vector.h"
#include "conf.h"
static const char *syslog_level[] = {
NULL,
@@ -61,6 +63,8 @@ static int log_level = LOG_INFO;
*/
static vector_t log_message_storage;
static unsigned int logging_initialized = FALSE; /* boolean */
/*
* Open the log file and store the file descriptor in a global location.
*/
@@ -75,19 +79,12 @@ int open_log_file (const char *log_file_name)
*/
void close_log_file (void)
{
close (log_file_fd);
}
if (log_file_fd < 0) {
return;
}
/*
* Truncate log file to a zero length.
*/
void truncate_log_file (void)
{
lseek (log_file_fd, 0, SEEK_SET);
if (ftruncate (log_file_fd, 0) != 0) {
log_message (LOG_WARNING,
"Unable to truncate log file to zero length");
}
close (log_file_fd);
log_file_fd = -1;
}
/*
@@ -125,10 +122,8 @@ void log_message (int level, const char *fmt, ...)
return;
#endif
#ifdef HAVE_SYSLOG_H
if (config.syslog && level == LOG_CONN)
level = LOG_INFO;
#endif
va_start (args, fmt);
@@ -136,7 +131,7 @@ void log_message (int level, const char *fmt, ...)
* If the config file hasn't been processed, then we need to store
* the messages for later processing.
*/
if (!processed_config_file) {
if (!logging_initialized) {
char *entry_buffer;
if (!log_message_storage) {
@@ -158,16 +153,17 @@ void log_message (int level, const char *fmt, ...)
safefree (entry_buffer);
goto out;
}
#ifdef HAVE_SYSLOG_H
if (config.syslog) {
# ifdef HAVE_VSYSLOG_H
#ifdef HAVE_VSYSLOG_H
vsyslog (level, fmt, args);
# else
#else
vsnprintf (str, STRING_LENGTH, fmt, args);
syslog (level, "%s", str);
# endif
} else {
#endif
} else {
char *p;
nowtime = time (NULL);
/* Format is month day hour:minute:second (24 time) */
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
@@ -177,6 +173,17 @@ void log_message (int level, const char *fmt, ...)
syslog_level[level], time_string,
(long int) getpid ());
/*
* Overwrite the '\0' and leave room for a trailing '\n'
* be added next.
*/
p = str + strlen(str);
vsnprintf (p, STRING_LENGTH - strlen(str) - 1, fmt, args);
p = str + strlen(str);
*p = '\n';
*(p+1) = '\0';
assert (log_file_fd >= 0);
ret = write (log_file_fd, str, strlen (str));
@@ -185,24 +192,8 @@ void log_message (int level, const char *fmt, ...)
"Could not write to log file");
}
vsnprintf (str, STRING_LENGTH, fmt, args);
ret = write (log_file_fd, str, strlen (str));
if (ret == -1) {
log_message (LOG_WARNING,
"Could not write to log file");
}
ret = write (log_file_fd, "\n", 1);
if (ret == -1) {
log_message (LOG_WARNING,
"Could not write to log file");
}
fsync (log_file_fd);
#ifdef HAVE_SYSLOG_H
}
#endif
out:
va_end (args);
@@ -220,6 +211,8 @@ void send_stored_logs (void)
size_t i;
log_message(LOG_DEBUG, "sending stored logs");
for (i = 0; (ssize_t) i != vector_length (log_message_storage); ++i) {
string =
(char *) vector_getentry (log_message_storage, i, NULL);
@@ -237,9 +230,67 @@ void send_stored_logs (void)
continue;
#endif
log_message (level, ptr);
log_message (level, "%s", ptr);
}
vector_delete (log_message_storage);
log_message_storage = NULL;
log_message(LOG_DEBUG, "done sending stored logs");
}
/**
* Initialize the logging subsystem, based on the configuration.
* Returns 0 upon success, -1 upon failure.
*
* This function uses fprintf() instead of log_message(), since
* the logging is not yet set up...
*/
int setup_logging (void)
{
if (!config.syslog) {
if (open_log_file (config.logf_name) < 0) {
/*
* If opening the log file fails, we try
* to fall back to syslog logging...
*/
config.syslog = TRUE;
log_message (LOG_CRIT, "ERROR: Could not create log "
"file %s: %s.\n",
config.logf_name, strerror (errno));
log_message (LOG_CRIT,
"Falling back to syslog logging\n");
}
}
if (config.syslog) {
if (config.godaemon == TRUE)
openlog ("tinyproxy", LOG_PID, LOG_DAEMON);
else
openlog ("tinyproxy", LOG_PID, LOG_USER);
}
logging_initialized = TRUE;
send_stored_logs ();
return 0;
}
/**
* Stop the logging subsystem.
*/
void shutdown_logging (void)
{
if (!logging_initialized) {
return;
}
if (config.syslog) {
closelog ();
} else {
close_log_file ();
}
logging_initialized = FALSE;
}
+4 -1
View File
@@ -1,6 +1,7 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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
@@ -111,10 +112,12 @@
extern int open_log_file (const char *file);
extern void close_log_file (void);
extern void truncate_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);
#endif
+79 -88
View File
@@ -1,7 +1,10 @@
/* tinyproxy - A fast light-weight HTTP proxy
*
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1998-2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
* Copyright (C) 2009-2010 Mukund Sivaraman <muks@banu.com>
* Copyright (C) 2009-2010 Michael Adam <obnox@samba.org>
*
* 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
@@ -45,8 +48,8 @@
* Global Structures
*/
struct config_s config;
struct config_s config_defaults;
unsigned int received_sighup = FALSE; /* boolean */
unsigned int processed_config_file = FALSE; /* boolean */
/*
* Handle a signal
@@ -96,6 +99,8 @@ display_license (void)
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\
@@ -157,6 +162,11 @@ display_usage (void)
features++;
#endif /* REVERSE_SUPPORT */
#ifdef UPSTREAM_SUPPORT
printf (" Upstream proxy support\n");
features++;
#endif /* UPSTREAM_SUPPORT */
if (0 == features)
printf (" None\n");
@@ -191,7 +201,7 @@ get_id (char *str)
* This function parses command line arguments.
**/
static void
process_cmdline (int argc, char **argv)
process_cmdline (int argc, char **argv, struct config_s *conf)
{
int opt;
@@ -206,12 +216,15 @@ process_cmdline (int argc, char **argv)
exit (EX_OK);
case 'd':
config.godaemon = FALSE;
conf->godaemon = FALSE;
break;
case 'c':
config.config_file = safestrdup (optarg);
if (!config.config_file) {
if (conf->config_file != NULL) {
safefree (conf->config_file);
}
conf->config_file = safestrdup (optarg);
if (!conf->config_file) {
fprintf (stderr,
"%s: Could not allocate memory.\n",
argv[0]);
@@ -296,96 +309,84 @@ change_user (const char *program)
}
}
static void initialize_config_defaults (struct config_s *conf)
{
memset (conf, 0, sizeof(*conf));
conf->config_file = safestrdup (SYSCONFDIR "/tinyproxy.conf");
if (!conf->config_file) {
fprintf (stderr, PACKAGE ": Could not allocate memory.\n");
exit (EX_SOFTWARE);
}
conf->godaemon = TRUE;
/*
* Make sure the HTML error pages array is NULL to begin with.
* (FIXME: Should have a better API for all this)
*/
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");
}
/**
* convenience wrapper around reload_config_file
* that also re-initializes logging.
*/
int reload_config (void)
{
int ret;
shutdown_logging ();
ret = reload_config_file (config_defaults.config_file, &config,
&config_defaults);
if (ret != 0) {
goto done;
}
ret = setup_logging ();
done:
return ret;
}
int
main (int argc, char **argv)
{
FILE *config_file;
int ret;
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask (0177);
config.config_file = SYSCONFDIR "/tinyproxy.conf";
config.godaemon = TRUE;
process_cmdline (argc, argv);
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
/*
* Make sure the HTML error pages array is NULL to begin with.
* (FIXME: Should have a better API for all this)
*/
config.errorpages = NULL;
initialize_config_defaults (&config_defaults);
process_cmdline (argc, argv, &config_defaults);
/* Read in the settings from the config file */
config_file = fopen (config.config_file, "r");
if (!config_file) {
fprintf (stderr,
"%s: Could not open config file \"%s\".\n",
argv[0], config.config_file);
ret = reload_config_file (config_defaults.config_file,
&config,
&config_defaults);
if (ret != 0) {
exit (EX_SOFTWARE);
}
if (config_compile () || config_parse (&config, config_file)) {
fprintf (stderr, "Unable to parse config file. "
"Not starting.\n");
exit (EX_SOFTWARE);
}
fclose (config_file);
/* Write to a user supplied log file if it's defined. This will
* override using the syslog even if syslog is defined. */
if (config.logf_name) {
if (open_log_file (config.logf_name) < 0) {
fprintf (stderr,
"%s: Could not create log file.\n", argv[0]);
exit (EX_SOFTWARE);
}
config.syslog = FALSE; /* disable syslog */
} else if (config.syslog) {
if (config.godaemon == TRUE)
openlog ("tinyproxy", LOG_PID, LOG_DAEMON);
else
openlog ("tinyproxy", LOG_PID, LOG_USER);
/* Switch to a different user if we're running as root */
if (geteuid () == 0) {
change_user (argv[0]);
} else {
fprintf (stderr, "%s: Either define a logfile or "
"enable syslog logging.\n", argv[0]);
log_message (LOG_WARNING,
"Not running as root, so not changing UID/GID.");
}
ret = setup_logging ();
if (ret != 0) {
exit (EX_SOFTWARE);
}
processed_config_file = TRUE;
send_stored_logs ();
/* Set the default values if they were not set in the config
* file. */
if (config.port == 0) {
fprintf (stderr, "%s: You MUST set a Port in the "
"config file.\n", argv[0]);
exit (EX_SOFTWARE);
}
if (!config.stathost) {
log_message (LOG_INFO, "Setting stathost to \"%s\".",
TINYPROXY_STATHOST);
config.stathost = strdup (TINYPROXY_STATHOST);
}
if (!config.user) {
log_message (LOG_WARNING, "You SHOULD set a UserName in the "
"config file. Using current user instead.");
}
if (config.idletimeout == 0) {
log_message (LOG_WARNING, "Invalid idle time setting. "
"Only values greater than zero are allowed. "
"Therefore setting idle timeout to %u seconds.",
MAX_IDLE_TIME);
config.idletimeout = MAX_IDLE_TIME;
}
init_stats ();
/* If ANONYMOUS is turned on, make sure that Content-Length is
@@ -426,13 +427,6 @@ main (int argc, char **argv)
exit (EX_OSERR);
}
/* Switch to a different user if we're running as root */
if (geteuid () == 0)
change_user (argv[0]);
else
log_message (LOG_WARNING,
"Not running as root, so not changing UID/GID.");
if (child_pool_create () < 0) {
fprintf (stderr,
"%s: Could not create the pool of children.\n",
@@ -468,7 +462,7 @@ main (int argc, char **argv)
log_message (LOG_INFO, "Shutting down.");
child_kill_children ();
child_kill_children (SIGTERM);
child_close_sock ();
/* Remove the PID file */
@@ -483,10 +477,7 @@ main (int argc, char **argv)
filter_destroy ();
#endif /* FILTER_ENABLE */
if (config.syslog)
closelog ();
else
close_log_file ();
shutdown_logging ();
return EXIT_SUCCESS;
}
+4 -75
View File
@@ -23,86 +23,15 @@
#define __MAIN_H__
#include "common.h"
#include "hashmap.h"
/* Global variables for the main controls of the program */
#define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
/*
* Even if upstream support is not compiled into tinyproxy, this
* structure still needs to be defined.
*/
struct upstream {
struct upstream *next;
char *domain; /* optional */
char *host;
int port;
in_addr_t ip, mask;
};
/*
* Hold all the configuration time information.
*/
struct config_s {
char *logf_name;
const char *config_file;
unsigned int syslog; /* boolean */
int port;
char *stathost;
unsigned int godaemon; /* boolean */
unsigned int quit; /* boolean */
char *user;
char *group;
char *ipAddr;
#ifdef FILTER_ENABLE
char *filter;
unsigned int filter_url; /* boolean */
unsigned int filter_extended; /* boolean */
unsigned int filter_casesensitive; /* boolean */
#endif /* FILTER_ENABLE */
#ifdef XTINYPROXY_ENABLE
unsigned int add_xtinyproxy; /* boolean */
#endif
#ifdef REVERSE_SUPPORT
struct reversepath *reversepath_list;
unsigned int reverseonly; /* boolean */
unsigned int reversemagic; /* boolean */
char *reversebaseurl;
#endif
#ifdef UPSTREAM_SUPPORT
struct upstream *upstream_list;
#endif /* UPSTREAM_SUPPORT */
char *pidpath;
unsigned int idletimeout;
char *bind_address;
unsigned int bindsame;
/*
* The configured name to use in the HTTP "Via" header field.
*/
char *via_proxy_name;
/*
* Error page support. Map error numbers to file paths.
*/
hashmap_t errorpages;
/*
* Error page to be displayed if appropriate page cannot be located
* in the errorpages structure.
*/
char *errorpage_undef;
/*
* The HTML statistics page.
*/
char *statpage;
};
#define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
/* Global Structures used in the program */
extern struct config_s config;
extern unsigned int received_sighup; /* boolean */
extern unsigned int processed_config_file; /* boolean */
extern int reload_config (void);
#endif /* __MAIN_H__ */
+142 -327
View File
@@ -45,6 +45,9 @@
#include "vector.h"
#include "reverse-proxy.h"
#include "transparent-proxy.h"
#include "upstream.h"
#include "connect-ports.h"
#include "conf.h"
/*
* Maximum length of a HTTP line
@@ -57,7 +60,7 @@
*/
#ifdef UPSTREAM_SUPPORT
# define UPSTREAM_CONFIGURED() (config.upstream_list != NULL)
# define UPSTREAM_HOST(host) upstream_get(host)
# define UPSTREAM_HOST(host) upstream_get(host, config.upstream_list)
#else
# define UPSTREAM_CONFIGURED() (0)
# define UPSTREAM_HOST(host) (NULL)
@@ -76,61 +79,6 @@
#define CHECK_LWS(header, len) \
((len) > 0 && (header[0] == ' ' || header[0] == '\t'))
/*
* This is a global variable which stores which ports are allowed by
* the CONNECT method. It's a security thing.
*/
static vector_t ports_allowed_by_connect = NULL;
/*
* Now, this routine adds a "port" to the list. It also creates the list if
* it hasn't already by done.
*/
void add_connect_port_allowed (int port)
{
if (!ports_allowed_by_connect) {
ports_allowed_by_connect = vector_create ();
if (!ports_allowed_by_connect) {
log_message (LOG_WARNING,
"Could not create a list of allowed CONNECT ports");
return;
}
}
log_message (LOG_INFO,
"Adding Port [%d] to the list allowed by CONNECT", port);
vector_append (ports_allowed_by_connect, (void **) &port,
sizeof (port));
}
/*
* This routine checks to see if a port is allowed in the CONNECT method.
*
* Returns: 1 if allowed
* 0 if denied
*/
static int check_allowed_connect_ports (int port)
{
size_t i;
int *data;
/*
* A port list is REQUIRED for a CONNECT request to function
* properly. This closes a potential security hole.
*/
if (!ports_allowed_by_connect)
return 0;
for (i = 0; i != (size_t) vector_length (ports_allowed_by_connect); ++i) {
data =
(int *) vector_getentry (ports_allowed_by_connect, i, NULL);
if (data && *data == port)
return 1;
}
return 0;
}
/*
* Read in the first line from the client (the request line for HTTP
* connections. The request line is allocated from the heap, but it must
@@ -300,168 +248,6 @@ static int extract_ssl_url (const char *url, struct request_s *request)
return 0;
}
#ifdef UPSTREAM_SUPPORT
/*
* Add an entry to the upstream list
*/
void upstream_add (const char *host, int port, const char *domain)
{
char *ptr;
struct upstream *up =
(struct upstream *) safemalloc (sizeof (struct upstream));
if (!up) {
log_message (LOG_ERR,
"Unable to allocate memory in upstream_add()");
return;
}
up->host = up->domain = NULL;
up->ip = up->mask = 0;
if (domain == NULL) {
if (!host || host[0] == '\0' || port < 1) {
log_message (LOG_WARNING,
"Nonsense upstream rule: invalid host or port");
goto upstream_cleanup;
}
up->host = safestrdup (host);
up->port = port;
log_message (LOG_INFO, "Added upstream %s:%d for [default]",
host, port);
} else if (host == NULL) {
if (!domain || domain[0] == '\0') {
log_message (LOG_WARNING,
"Nonsense no-upstream rule: empty domain");
goto upstream_cleanup;
}
ptr = strchr (domain, '/');
if (ptr) {
struct in_addr addrstruct;
*ptr = '\0';
if (inet_aton (domain, &addrstruct) != 0) {
up->ip = ntohl (addrstruct.s_addr);
*ptr++ = '/';
if (strchr (ptr, '.')) {
if (inet_aton (ptr, &addrstruct) != 0)
up->mask =
ntohl (addrstruct.s_addr);
} else {
up->mask =
~((1 << (32 - atoi (ptr))) - 1);
}
}
} else {
up->domain = safestrdup (domain);
}
log_message (LOG_INFO, "Added no-upstream for %s", domain);
} else {
if (!host || host[0] == '\0' || port < 1 || !domain
|| domain == '\0') {
log_message (LOG_WARNING,
"Nonsense upstream rule: invalid parameters");
goto upstream_cleanup;
}
up->host = safestrdup (host);
up->port = port;
up->domain = safestrdup (domain);
log_message (LOG_INFO, "Added upstream %s:%d for %s",
host, port, domain);
}
if (!up->domain && !up->ip) { /* always add default to end */
struct upstream *tmp = config.upstream_list;
while (tmp) {
if (!tmp->domain && !tmp->ip) {
log_message (LOG_WARNING,
"Duplicate default upstream");
goto upstream_cleanup;
}
if (!tmp->next) {
up->next = NULL;
tmp->next = up;
return;
}
tmp = tmp->next;
}
}
up->next = config.upstream_list;
config.upstream_list = up;
return;
upstream_cleanup:
safefree (up->host);
safefree (up->domain);
safefree (up);
return;
}
/*
* Check if a host is in the upstream list
*/
static struct upstream *upstream_get (char *host)
{
struct upstream *up = config.upstream_list;
in_addr_t my_ip = INADDR_NONE;
while (up) {
if (up->domain) {
if (strcasecmp (host, up->domain) == 0)
break; /* exact match */
if (up->domain[0] == '.') {
char *dot = strchr (host, '.');
if (!dot && !up->domain[1])
break; /* local host matches "." */
while (dot && strcasecmp (dot, up->domain))
dot = strchr (dot + 1, '.');
if (dot)
break; /* subdomain match */
}
} else if (up->ip) {
if (my_ip == INADDR_NONE)
my_ip = ntohl (inet_addr (host));
if ((my_ip & up->mask) == up->ip)
break;
} else {
break; /* No domain or IP, default upstream */
}
up = up->next;
}
if (up && (!up->host || !up->port))
up = NULL;
if (up)
log_message (LOG_INFO, "Found proxy %s:%d for %s",
up->host, up->port, host);
else
log_message (LOG_INFO, "No proxy for %s", host);
return up;
}
#endif
/*
* Create a connection for HTTP connections.
*/
@@ -527,10 +313,7 @@ static struct request_s *process_request (struct conn_s *connptr,
request->protocol = (char *) safemalloc (request_len);
if (!request->method || !url || !request->protocol) {
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
ret = sscanf (connptr->request_line, "%[^ ] %[^ ] %[^ ]",
@@ -564,11 +347,7 @@ BAD_REQUEST_ERROR:
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Request has an invalid format",
"url", url, NULL);
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
if (!url) {
@@ -578,11 +357,7 @@ BAD_REQUEST_ERROR:
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Request has an empty URL",
"url", url, NULL);
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
#ifdef REVERSE_SUPPORT
if (config.reversepath_list != NULL) {
@@ -595,14 +370,13 @@ BAD_REQUEST_ERROR:
char *reverse_url;
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
safefree (url);
if (!reverse_url) {
free_request_struct (request);
return NULL;
} else {
url = reverse_url;
goto fail;
}
safefree (url);
url = reverse_url;
}
#endif
@@ -615,26 +389,20 @@ BAD_REQUEST_ERROR:
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Could not parse URL",
"url", url, NULL);
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
} else if (strcmp (request->method, "CONNECT") == 0) {
if (extract_ssl_url (url, request) < 0) {
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Could not parse URL",
"url", url, NULL);
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
/* Verify that the port in the CONNECT method is allowed */
if (!check_allowed_connect_ports (request->port)) {
if (!check_allowed_connect_ports (request->port,
config.connect_ports))
{
indicate_http_error (connptr, 403, "Access violation",
"detail",
"The CONNECT method not allowed "
@@ -643,11 +411,7 @@ BAD_REQUEST_ERROR:
log_message (LOG_INFO,
"Refused CONNECT method on port %d",
request->port);
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
connptr->connect_method = TRUE;
@@ -655,9 +419,7 @@ BAD_REQUEST_ERROR:
#ifdef TRANSPARENT_PROXY
if (!do_transparent_proxy
(connptr, hashofheaders, request, &config, url)) {
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
#else
indicate_http_error (connptr, 501, "Not Implemented",
@@ -666,10 +428,7 @@ BAD_REQUEST_ERROR:
"url", url, NULL);
log_message (LOG_INFO, "Unknown method (%s) or protocol (%s)",
request->method, url);
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
#endif
}
@@ -699,16 +458,11 @@ BAD_REQUEST_ERROR:
"detail",
"The request you made has been filtered",
"url", url, NULL);
safefree (url);
free_request_struct (request);
return NULL;
goto fail;
}
}
#endif
safefree (url);
/*
* Check to see if they're requesting the stat host
@@ -716,12 +470,17 @@ BAD_REQUEST_ERROR:
if (config.stathost && strcmp (config.stathost, request->host) == 0) {
log_message (LOG_NOTICE, "Request for the stathost.");
connptr->show_stats = TRUE;
free_request_struct (request);
return NULL;
goto fail;
}
safefree (url);
return request;
fail:
safefree (url);
free_request_struct (request);
return NULL;
}
/*
@@ -997,10 +756,15 @@ write_via_header (int fd, hashmap_t hashofheaders,
char *data;
int ret;
if (config.disable_viaheader) {
ret = 0;
goto done;
}
if (config.via_proxy_name) {
strlcpy (hostname, config.via_proxy_name, sizeof (hostname));
} else if (gethostname (hostname, sizeof (hostname)) < 0) {
strcpy (hostname, "unknown");
strlcpy (hostname, "unknown", 512);
}
/*
@@ -1021,6 +785,7 @@ write_via_header (int fd, hashmap_t hashofheaders,
major, minor, hostname, PACKAGE, VERSION);
}
done:
return ret;
}
@@ -1137,11 +902,12 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
* Spin here pulling the data from the client.
*/
PULL_CLIENT_DATA:
if (connptr->content_length.client > 0)
return pull_client_data (connptr,
connptr->content_length.client);
else
return ret;
if (connptr->content_length.client > 0) {
ret = pull_client_data (connptr,
connptr->content_length.client);
}
return ret;
}
/*
@@ -1207,7 +973,7 @@ retry:
indicate_http_error (connptr, 503,
"Could not retrieve all the headers",
"detail",
PACKAGE " "
PACKAGE_NAME " "
"was unable to retrieve and process headers from "
"the remote web server.", NULL);
return -1;
@@ -1523,6 +1289,50 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
#endif
}
static int
get_request_entity(struct conn_s *connptr)
{
int ret;
fd_set rset;
struct timeval tv;
FD_ZERO (&rset);
FD_SET (connptr->client_fd, &rset);
tv.tv_sec = 0;
tv.tv_usec = 0;
ret = select (connptr->client_fd + 1, &rset, NULL, NULL, &tv);
if (ret == -1) {
log_message (LOG_ERR,
"Error calling select on client fd %d: %s",
connptr->client_fd, strerror(errno));
} else if (ret == 0) {
log_message (LOG_INFO, "no entity");
} else if (ret == 1 && FD_ISSET (connptr->client_fd, &rset)) {
ssize_t nread;
nread = read_buffer (connptr->client_fd, connptr->cbuffer);
if (nread < 0) {
log_message (LOG_ERR,
"Error reading readble client_fd %d",
connptr->client_fd);
ret = -1;
} else {
log_message (LOG_INFO,
"Read request entity of %d bytes",
nread);
ret = 0;
}
} else {
log_message (LOG_ERR, "strange situation after select: "
"ret = %d, but client_fd (%d) is not readable...",
ret, connptr->client_fd);
ret = -1;
}
return ret;
}
/*
* This is the main drive for each connection. As you can tell, for the
* first few steps we are using a blocking socket. If you remember the
@@ -1534,6 +1344,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
*/
void handle_connection (int fd)
{
ssize_t i;
struct conn_s *connptr;
struct request_s *request = NULL;
hashmap_t hashofheaders = NULL;
@@ -1553,22 +1364,20 @@ void handle_connection (int fd)
fd, peer_string, peer_ipaddr, sock_ipaddr);
connptr = initialize_conn (fd, peer_ipaddr, peer_string,
config.bindsame ? sock_ipaddr : 0);
config.bindsame ? sock_ipaddr : NULL);
if (!connptr) {
close (fd);
return;
}
if (check_acl (peer_ipaddr, peer_string) <= 0) {
if (check_acl (peer_ipaddr, peer_string, config.access_list) <= 0) {
update_stats (STAT_DENIED);
indicate_http_error (connptr, 403, "Access denied",
"detail",
"The administrator of this proxy has not configured "
"it to service requests from your host.",
NULL);
send_http_error_message (connptr);
destroy_conn (connptr);
return;
goto fail;
}
if (read_request_line (connptr) < 0) {
@@ -1577,24 +1386,21 @@ void handle_connection (int fd)
"detail",
"Server timeout waiting for the HTTP request "
"from the client.", NULL);
send_http_error_message (connptr);
destroy_conn (connptr);
return;
goto fail;
}
/*
* The "hashofheaders" store the client's headers.
*/
if (!(hashofheaders = hashmap_create (HEADER_BUCKETS))) {
hashofheaders = hashmap_create (HEADER_BUCKETS);
if (hashofheaders == NULL) {
update_stats (STAT_BADCONN);
indicate_http_error (connptr, 503, "Internal error",
"detail",
"An internal server error occurred while processing "
"your request. Please contact the administrator.",
NULL);
send_http_error_message (connptr);
destroy_conn (connptr);
return;
goto fail;
}
/*
@@ -1607,28 +1413,35 @@ void handle_connection (int fd)
"detail",
"Could not retrieve all the headers from "
"the client.", NULL);
send_http_error_message (connptr);
hashmap_delete (hashofheaders);
update_stats (STAT_BADCONN);
destroy_conn (connptr);
return;
goto fail;
}
/*
* Add any user-specified headers (AddHeader directive) to the
* outgoing HTTP request.
*/
for (i = 0; i < vector_length (config.add_headers); i++) {
http_header_t *header = (http_header_t *)
vector_getentry (config.add_headers, i, NULL);
hashmap_insert (hashofheaders,
header->name,
header->value, strlen (header->value) + 1);
}
request = process_request (connptr, hashofheaders);
if (!request) {
if (!connptr->error_variables && !connptr->show_stats) {
if (!connptr->show_stats) {
update_stats (STAT_BADCONN);
destroy_conn (connptr);
hashmap_delete (hashofheaders);
return;
}
goto send_error;
goto fail;
}
connptr->upstream_proxy = UPSTREAM_HOST (request->host);
if (connptr->upstream_proxy != NULL) {
if (connect_to_upstream (connptr, request) < 0) {
goto send_error;
goto fail;
}
} else {
connptr->server_fd = opensock (request->host, request->port,
@@ -1636,10 +1449,10 @@ void handle_connection (int fd)
if (connptr->server_fd < 0) {
indicate_http_error (connptr, 500, "Unable to connect",
"detail",
PACKAGE " "
PACKAGE_NAME " "
"was unable to connect to the remote web server.",
"error", strerror (errno), NULL);
goto send_error;
goto fail;
}
log_message (LOG_CONN,
@@ -1651,37 +1464,15 @@ void handle_connection (int fd)
establish_http_connection (connptr, request);
}
send_error:
free_request_struct (request);
if (process_client_headers (connptr, hashofheaders) < 0) {
update_stats (STAT_BADCONN);
if (!connptr->error_variables) {
hashmap_delete (hashofheaders);
destroy_conn (connptr);
return;
}
}
hashmap_delete (hashofheaders);
if (connptr->error_variables) {
send_http_error_message (connptr);
destroy_conn (connptr);
return;
} else if (connptr->show_stats) {
showstats (connptr);
destroy_conn (connptr);
return;
goto fail;
}
if (!(connptr->connect_method && (connptr->upstream_proxy == NULL))) {
if (process_server_headers (connptr) < 0) {
if (connptr->error_variables)
send_http_error_message (connptr);
update_stats (STAT_BADCONN);
destroy_conn (connptr);
return;
goto fail;
}
} else {
if (send_ssl_response (connptr) < 0) {
@@ -1689,8 +1480,7 @@ send_error:
"handle_connection: Could not send SSL greeting "
"to client.");
update_stats (STAT_BADCONN);
destroy_conn (connptr);
return;
goto fail;
}
}
@@ -1701,9 +1491,34 @@ send_error:
"and remote client (fd:%d)",
connptr->client_fd, connptr->server_fd);
goto done;
fail:
/*
* All done... close everything and go home... :)
* First, get the body if there is one.
* If we don't read all there is from the socket first,
* it is still marked for reading and we won't be able
* to send our data properly.
*/
if (get_request_entity (connptr) < 0) {
log_message (LOG_WARNING,
"Could not retrieve request entity");
indicate_http_error (connptr, 400, "Bad Request",
"detail",
"Could not retrieve the request entity "
"the client.", NULL);
update_stats (STAT_BADCONN);
}
if (connptr->error_variables) {
send_http_error_message (connptr);
} else if (connptr->show_stats) {
showstats (connptr);
}
done:
free_request_struct (request);
hashmap_delete (hashofheaders);
destroy_conn (connptr);
return;
}
-2
View File
@@ -44,7 +44,5 @@ struct request_s {
};
extern void handle_connection (int fd);
extern void add_connect_port_allowed (int port);
extern void upstream_add (const char *host, int port, const char *domain);
#endif
+25 -9
View File
@@ -25,11 +25,13 @@
#include "heap.h"
#include "html-error.h"
#include "log.h"
#include "conf.h"
/*
* Add entry to the reversepath list
*/
void reversepath_add (const char *path, const char *url)
void reversepath_add (const char *path, const char *url,
struct reversepath **reversepath_list)
{
struct reversepath *reverse;
@@ -68,8 +70,8 @@ void reversepath_add (const char *path, const char *url)
reverse->url = safestrdup (url);
reverse->next = config.reversepath_list;
config.reversepath_list = reverse;
reverse->next = *reversepath_list;
*reversepath_list = reverse;
log_message (LOG_INFO,
"Added reverse proxy rule: %s -> %s", reverse->path,
@@ -79,10 +81,8 @@ void reversepath_add (const char *path, const char *url)
/*
* Check if a request url is in the reversepath list
*/
struct reversepath *reversepath_get (char *url)
struct reversepath *reversepath_get (char *url, struct reversepath *reverse)
{
struct reversepath *reverse = config.reversepath_list;
while (reverse) {
if (strstr (url, reverse->path) == url)
return reverse;
@@ -93,6 +93,21 @@ struct reversepath *reversepath_get (char *url)
return NULL;
}
/**
* Free a reversepath list
*/
void free_reversepath_list (struct reversepath *reverse)
{
while (reverse) {
struct reversepath *tmp = reverse;
reverse = reverse->next;
safefree (tmp->url);
safefree (tmp->path);
safefree (tmp);
}
}
/*
* Rewrite the URL for reverse proxying.
*/
@@ -107,7 +122,7 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
/* Reverse requests always start with a slash */
if (*url == '/') {
/* First try locating the reverse mapping by request url */
reverse = reversepath_get (url);
reverse = reversepath_get (url, config.reversepath_list);
if (reverse) {
rewrite_url = (char *)
safemalloc (strlen (url) + strlen (reverse->url) +
@@ -123,8 +138,9 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
if ((cookieval = strstr (cookie, REVERSE_COOKIE "="))
&& (reverse =
reversepath_get (cookieval +
strlen (REVERSE_COOKIE) +
1))) {
strlen (REVERSE_COOKIE) + 1,
config.reversepath_list)))
{
rewrite_url = (char *) safemalloc
(strlen (url) +
+5 -2
View File
@@ -31,8 +31,11 @@ struct reversepath {
#define REVERSE_COOKIE "yummy_magical_cookie"
extern void reversepath_add (const char *path, const char *url);
extern struct reversepath *reversepath_get (char *url);
extern void reversepath_add (const char *path, const char *url,
struct reversepath **reversepath_list);
extern struct reversepath *reversepath_get (char *url,
struct reversepath *reverse);
void free_reversepath_list (struct reversepath *reverse);
extern char *reverse_rewrite_url (struct conn_s *connptr,
hashmap_t hashofheaders, char *url);
+48 -19
View File
@@ -32,13 +32,15 @@
#include "network.h"
#include "sock.h"
#include "text.h"
#include "conf.h"
/*
* Bind the given socket to the supplied address. The socket is
* returned if the bind succeeded. Otherwise, -1 is returned
* to indicate an error.
*/
static int bind_socket (int sockfd, const char *addr)
static int
bind_socket (int sockfd, const char *addr, int family)
{
struct addrinfo hints, *res, *ressave;
@@ -46,7 +48,7 @@ static int bind_socket (int sockfd, const char *addr)
assert (addr != NULL && strlen (addr) != 0);
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
/* The local port it not important */
@@ -104,12 +106,14 @@ int opensock (const char *host, int port, const char *bind_to)
/* Bind to the specified address */
if (bind_to) {
if (bind_socket (sockfd, bind_to) < 0) {
if (bind_socket (sockfd, bind_to,
res->ai_family) < 0) {
close (sockfd);
continue; /* can't bind, so try again */
}
} else if (config.bind_address) {
if (bind_socket (sockfd, config.bind_address) < 0) {
if (bind_socket (sockfd, config.bind_address,
res->ai_family) < 0) {
close (sockfd);
continue; /* can't bind, so try again */
}
@@ -162,34 +166,54 @@ int socket_blocking (int sock)
* 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
* - rjkaes
*/
int listen_sock (uint16_t port, socklen_t * addrlen)
{
struct addrinfo hints, *result, *rp;
char portstr[6];
int listenfd;
const int on = 1;
struct sockaddr_in addr;
assert (port > 0);
assert (addrlen != NULL);
listenfd = socket (AF_INET, SOCK_STREAM, 0);
setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on));
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
addr.sin_port = htons (port);
snprintf (portstr, sizeof (portstr), "%d", port);
if (config.ipAddr) {
addr.sin_addr.s_addr = inet_addr (config.ipAddr);
} else {
addr.sin_addr.s_addr = inet_addr ("0.0.0.0");
if (getaddrinfo (config.ipAddr, portstr, &hints, &result) != 0) {
log_message (LOG_ERR,
"Unable to getaddrinfo() because of %s",
strerror (errno));
return -1;
}
if (bind (listenfd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
for (rp = result; rp != NULL; rp = rp->ai_next) {
listenfd = socket (rp->ai_family, rp->ai_socktype,
rp->ai_protocol);
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 because of %s",
strerror (errno));
"Unable to bind listening socket "
"to any address.");
freeaddrinfo (result);
return -1;
}
@@ -197,10 +221,15 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
log_message (LOG_ERR,
"Unable to start listening socket because of %s",
strerror (errno));
close (listenfd);
freeaddrinfo (result);
return -1;
}
*addrlen = sizeof (addr);
*addrlen = rp->ai_addrlen;
freeaddrinfo (result);
return listenfd;
}
+1
View File
@@ -32,6 +32,7 @@
#include "html-error.h"
#include "stats.h"
#include "utils.h"
#include "conf.h"
struct stat_s {
unsigned long int num_reqs;
+21 -10
View File
@@ -23,14 +23,14 @@
* traffic to tinyproxy for this to work properly.
*/
#include "main.h"
#include "transparent-proxy.h"
#include "conns.h"
#include "heap.h"
#include "html-error.h"
#include "log.h"
#include "reqs.h"
#include "text.h"
#include "conf.h"
/*
* Build a URL from parts.
@@ -59,6 +59,7 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
{
socklen_t length;
char *data;
size_t ulen = strlen (url);
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
if (length <= 0) {
@@ -75,12 +76,18 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
"url", url, NULL);
return 0;
}
request->host = (char *) safemalloc (17);
strcpy (request->host, inet_ntoa (dest_addr.sin_addr));
strlcpy (request->host, inet_ntoa (dest_addr.sin_addr), 17);
request->port = ntohs (dest_addr.sin_port);
request->path = (char *) safemalloc (strlen (url) + 1);
strcpy (request->path, url);
safefree (url);
request->path = (char *) safemalloc (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);
log_message (LOG_INFO,
"process_request: trans IP %s %s for %d",
@@ -89,12 +96,16 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
request->host = (char *) safemalloc (length + 1);
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
2) {
strcpy (request->host, data);
strlcpy (request->host, data, length + 1);
request->port = HTTP_PORT;
}
request->path = (char *) safemalloc (strlen (url) + 1);
strcpy (request->path, url);
safefree (url);
request->path = (char *) safemalloc (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);
log_message (LOG_INFO,
"process_request: trans Host %s %s for %d",
+224
View File
@@ -0,0 +1,224 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
* Copyright (C) 2002 Petr Lampa <lampa@fit.vutbr.cz>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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.
*/
/*
* Routines for handling the list of upstream proxies.
*/
#include "upstream.h"
#include "heap.h"
#include "log.h"
#ifdef UPSTREAM_SUPPORT
/**
* Construct an upstream struct from input data.
*/
static struct upstream *upstream_build (const char *host, int port, const char *domain)
{
char *ptr;
struct upstream *up;
up = (struct upstream *) safemalloc (sizeof (struct upstream));
if (!up) {
log_message (LOG_ERR,
"Unable to allocate memory in upstream_build()");
return NULL;
}
up->host = up->domain = NULL;
up->ip = up->mask = 0;
if (domain == NULL) {
if (!host || host[0] == '\0' || port < 1) {
log_message (LOG_WARNING,
"Nonsense upstream rule: invalid host or port");
goto fail;
}
up->host = safestrdup (host);
up->port = port;
log_message (LOG_INFO, "Added upstream %s:%d for [default]",
host, port);
} else if (host == NULL) {
if (!domain || domain[0] == '\0') {
log_message (LOG_WARNING,
"Nonsense no-upstream rule: empty domain");
goto fail;
}
ptr = strchr (domain, '/');
if (ptr) {
struct in_addr addrstruct;
*ptr = '\0';
if (inet_aton (domain, &addrstruct) != 0) {
up->ip = ntohl (addrstruct.s_addr);
*ptr++ = '/';
if (strchr (ptr, '.')) {
if (inet_aton (ptr, &addrstruct) != 0)
up->mask =
ntohl (addrstruct.s_addr);
} else {
up->mask =
~((1 << (32 - atoi (ptr))) - 1);
}
}
} else {
up->domain = safestrdup (domain);
}
log_message (LOG_INFO, "Added no-upstream for %s", domain);
} else {
if (!host || host[0] == '\0' || port < 1 || !domain
|| domain == '\0') {
log_message (LOG_WARNING,
"Nonsense upstream rule: invalid parameters");
goto fail;
}
up->host = safestrdup (host);
up->port = port;
up->domain = safestrdup (domain);
log_message (LOG_INFO, "Added upstream %s:%d for %s",
host, port, domain);
}
return up;
fail:
safefree (up->host);
safefree (up->domain);
safefree (up);
return NULL;
}
/*
* Add an entry to the upstream list
*/
void upstream_add (const char *host, int port, const char *domain,
struct upstream **upstream_list)
{
struct upstream *up;
up = upstream_build (host, port, domain);
if (up == NULL) {
return;
}
if (!up->domain && !up->ip) { /* always add default to end */
struct upstream *tmp = *upstream_list;
while (tmp) {
if (!tmp->domain && !tmp->ip) {
log_message (LOG_WARNING,
"Duplicate default upstream");
goto upstream_cleanup;
}
if (!tmp->next) {
up->next = NULL;
tmp->next = up;
return;
}
tmp = tmp->next;
}
}
up->next = *upstream_list;
*upstream_list = up;
return;
upstream_cleanup:
safefree (up->host);
safefree (up->domain);
safefree (up);
return;
}
/*
* Check if a host is in the upstream list
*/
struct upstream *upstream_get (char *host, struct upstream *up)
{
in_addr_t my_ip = INADDR_NONE;
while (up) {
if (up->domain) {
if (strcasecmp (host, up->domain) == 0)
break; /* exact match */
if (up->domain[0] == '.') {
char *dot = strchr (host, '.');
if (!dot && !up->domain[1])
break; /* local host matches "." */
while (dot && strcasecmp (dot, up->domain))
dot = strchr (dot + 1, '.');
if (dot)
break; /* subdomain match */
}
} else if (up->ip) {
if (my_ip == INADDR_NONE)
my_ip = ntohl (inet_addr (host));
if ((my_ip & up->mask) == up->ip)
break;
} else {
break; /* No domain or IP, default upstream */
}
up = up->next;
}
if (up && (!up->host || !up->port))
up = NULL;
if (up)
log_message (LOG_INFO, "Found proxy %s:%d for %s",
up->host, up->port, host);
else
log_message (LOG_INFO, "No proxy for %s", host);
return up;
}
void free_upstream_list (struct upstream *up)
{
while (up) {
struct upstream *tmp = up;
up = up->next;
safefree (tmp->domain);
safefree (tmp->host);
safefree (tmp);
}
}
#endif
+49
View File
@@ -0,0 +1,49 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
*
* 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.
*/
/*
* Routines for handling the list of upstream proxies.
*/
#ifndef _TINYPROXY_UPSTREAM_H_
#define _TINYPROXY_UPSTREAM_H_
#include "common.h"
/*
* Even if upstream support is not compiled into tinyproxy, this
* structure still needs to be defined.
*/
struct upstream {
struct upstream *next;
char *domain; /* optional */
char *host;
int port;
in_addr_t ip, mask;
};
#ifdef UPSTREAM_SUPPORT
extern void upstream_add (const char *host, int port, const char *domain,
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 */
#endif /* _TINYPROXY_UPSTREAM_H_ */
+11 -4
View File
@@ -104,10 +104,17 @@ int vector_delete (vector_t vector)
* Returns: 0 on success
* negative number if there are errors
*/
#define INSERT_PREPEND 0
#define INSERT_APPEND 1
static int vector_insert (vector_t vector, void *data, size_t len, int pos)
typedef enum {
INSERT_PREPEND,
INSERT_APPEND
} vector_pos_t;
static int
vector_insert (vector_t vector,
void *data,
size_t len,
vector_pos_t pos)
{
struct vectorentry_s *entry;
@@ -133,7 +140,7 @@ static int vector_insert (vector_t vector, void *data, size_t len, int pos)
/* If there is no head or tail, create them */
if (!vector->head && !vector->tail)
vector->head = vector->tail = entry;
else if (pos == 0) {
else if (pos == INSERT_PREPEND) {
/* prepend the entry */
entry->next = vector->head;
vector->head = entry;
+18 -7
View File
@@ -29,7 +29,7 @@ TINYPROXY_PORT=12321
TINYPROXY_USER=$USER
TINYPROXY_PID_DIR=$TESTENV_DIR/var/run/tinyproxy
TINYPROXY_PID_FILE=$TINYPROXY_PID_DIR/tinyproxy.pid
TINYPROXY_LOG_DIR=$LOG_DIR
TINYPROXY_LOG_DIR=$LOG_DIR/tinyproxy
TINYPROXY_DATA_DIR=$TESTENV_DIR/usr/share/tinyproxy
TINYPROXY_CONF_DIR=$TESTENV_DIR/etc/tinyproxy
TINYPROXY_CONF_FILE=$TINYPROXY_CONF_DIR/tinyproxy.conf
@@ -90,6 +90,7 @@ StartServers 10
MaxRequestsPerChild 0
Allow 127.0.0.0/8
ViaProxyName "tinyproxy"
#DisableViaHeader Yes
ConnectPort 443
ConnectPort 563
FilterURLs On
@@ -158,12 +159,13 @@ run_basic_webclient_request() {
if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
echo " ok"
else
echo "ERROR ($EBCLIENT_EXIT_CODE)"
echo "ERROR ($WEBCLIENT_EXIT_CODE)"
echo "webclient output:"
cat $WEBCLIENT_LOG
fi
}
return $WEBCLIENT_EXIT_CODE
}
# "main"
@@ -176,22 +178,31 @@ start_tinyproxy
wait_for_some_seconds 3
FAILED=0
echo -n "checking direct connection to web server..."
run_basic_webclient_request "$WEBSERVER_IP:$WEBSERVER_PORT" /
test "x$?" = "x0" || FAILED=$((FAILED + 1))
echo -n "testing connection through tinyproxy..."
run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$WEBSERVER_IP:$WEBSERVER_PORT/"
test "x$?" = "x0" || FAILED=$((FAILED + 1))
echo -n "requesting statspage via stathost url..."
run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$TINYPROXY_STATHOST_IP"
test "x$?" = "x0" || FAILED=$((FAILED + 1))
echo "You can continue using the webserver and tinyproxy."
echo -n "hit <enter> to stop the servers and exit: "
read READ
echo "$FAILED errors"
if test "x$TINYPROXY_TESTS_WAIT" = "xyes"; then
echo "You can continue using the webserver and tinyproxy."
echo -n "hit <enter> to stop the servers and exit: "
read READ
fi
stop_tinyproxy
stop_webserver
echo "done"
exit 0
exit $FAILED
+14 -4
View File
@@ -34,6 +34,7 @@ my $http_version = "1.0";
my $method = "GET";
my $dry_run = 0;
my $help = 0;
my $entity = undef;
my $default_port = "80";
my $port = $default_port;
@@ -42,7 +43,8 @@ sub process_options() {
my $result = GetOptions("help|?" => \$help,
"http-version=s" => \$http_version,
"method=s" => \$method,
"dry-run" => \$dry_run);
"dry-run" => \$dry_run,
"entity=s" => \$entity);
die "Error reading cmdline options! $!" unless $result;
pod2usage(1) if $help;
@@ -51,9 +53,9 @@ sub process_options() {
}
sub build_request($$$$$)
sub build_request($$$$$$)
{
my ( $host, $port, $version, $method, $document ) = @_;
my ( $host, $port, $version, $method, $document, $entity ) = @_;
my $request = "";
$method = uc($method);
@@ -77,6 +79,10 @@ sub build_request($$$$$)
$request .= $EOL;
if ($entity) {
$request .= $entity;
}
return $request;
}
@@ -97,7 +103,7 @@ if ($host =~ /^([^:]+):(.*)/) {
}
foreach my $document (@ARGV) {
my $request = build_request($host, $port, $http_version, $method, $document);
my $request = build_request($host, $port, $http_version, $method, $document, $entity);
if ($dry_run) {
print $request;
exit(0);
@@ -151,6 +157,10 @@ Specify the HTTP protocol version to use (0.9, 1.0, 1.1). Default is 1.0.
Specify the HTTP request method ('GET', 'CONNECT', ...). Default is 'GET'.
=item B<--entity>
Add the provided string as entity (i.e. body) to the request.
=item B<--dry-run>
Don't actually connect to the server but print the request that would be sent.
+7 -4
View File
@@ -193,10 +193,13 @@ sub child_action($) {
return;
}
print $client "HTTP/1.0 200 OK$EOL";
print $client "$server_header$EOL";
print $client "Content-Type: text/html$EOL";
print $client "$EOL";
if ($request->{version} ne "0.9") {
print $client "HTTP/1.0 200 OK$EOL";
print $client "$server_header$EOL";
print $client "Content-Type: text/html$EOL";
print $client "$EOL";
}
print $client "<html>$EOL";
print $client "<h1>Tinyproxy test WEB server</h1>$EOL";
print $client "<h2>Fortune</h2>$EOL";