Compare commits

..
774 Commits
Author SHA1 Message Date
Michael Adam 1115251555 Bump version to 1.8.4.
Signed-off-by: Michael Adam <obnox@samba.org>
2014-12-13 01:57:23 +01:00
Michael Adam 72b477da9e Update NEWS for 1.8.4.
Signed-off-by: Michael Adam <obnox@samba.org>
2014-12-13 01:56:27 +01:00
Michael Adam 87e8da90b0 BB#110 Increase number of hash buckets from 32 to 256.
This should make hash processing generally faster.

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

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

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 800c3a250c)
2014-12-13 01:49:01 +01:00
Michael Adam c348513095 BB#110 limit the number of headers per request to prevent DoS
Based on patch provided by gpernot@praksys.org on bugzilla.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 545463c75d)
2014-12-13 01:48:49 +01:00
Michael Adam 8845bdbff7 BB#110 secure the hashmaps by adding a seed
Based on a patch provided by gpernot@praksys.org on bugzilla.

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

Reviewed-by: Michael Adam <obnox@samba.org>
(cherry picked from commit ab6255393d)
2014-12-13 01:48:27 +01:00
Michael Adam 12c454119b Update NEWS for coverity fixes.
Signed-off-by: Michael Adam <obnox@samba.org>
2014-07-21 13:26:57 +02:00
Michael Adam 9db1b0d087 buffer: fix log message in read_buffer().
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit b59ecd0c66)
2014-07-21 13:26:57 +02:00
Michael Adam e16844bd3b buffer: reduce indentation in read_buffer()
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit ffa3a56ab8)
2014-07-21 13:26:57 +02:00
Michael Adam 3cb25a7857 reqs: fix typo in a debug message in get_request_entity()
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 76bd008cf9)
2014-07-21 13:26:57 +02:00
Michael Adam ffbef661cd transparent: make transparent support compile after introduction of multi Listen
I seem to have forgotten to compile with transparent support enabled...
This belongs to the fix for bug BB#63.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit b3ac7d2c7b)
2014-07-21 13:26:57 +02:00
Michael Adam 54244661f7 child: remove use of config.listen_addrs in child_listening_sockets()
This was accidentially used instead of the function parameter listen_addrs
This still belongs to the fix for bug BB#63.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit b92d70be07)
2014-07-21 13:26:57 +02:00
Michael Adam 5054b9b80f reqs: Fix CID 1130969 (part 3) - unchecked return value from library.
Check the return value of socket_blocking (fcntl) at the
end of relay_connection() for client socket.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 3710accf72)
2014-07-21 13:26:57 +02:00
Michael Adam b86ecaa11b reqs: Fix CID 1130969 (part 2) - unchecked return value from library.
Check the return value of socket_blocking (fcntl) at the
end of relay_connection().

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit e07c363df2)
2014-07-21 13:26:57 +02:00
Michael Adam e467744134 reqs: Fix CID 1130972 - remove logically dead code.
url == NULL is caught above.

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit c82840bfcb)
2014-07-21 13:26:57 +02:00
Michael Adam 4ebb3c1bb6 network: Fix CID 113095 - unchecked return value from library
Check return of "recv" in readline().

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 49c55ed26c)
2014-07-21 13:26:57 +02:00
Michael Adam d05e801eef reqs: rename a variable.
ret will be used in enclosing scope.
so rename this special varibale.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit c27b6d15e2)
2014-07-21 13:26:57 +02:00
Michael Adam e1af5ffa58 reqs: Fix CID 1130968 - unchecked return value from library
Check the return code of fcntl via socket_nonblocking
in pull_client_data()

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 9efa5799f0)
2014-07-21 13:26:57 +02:00
Michael Adam 6c8d9de3cc reqs: Fix CID 1130967 - unchecked return value from library.
Check the return code of fcntl via socket_blocking
in pull_client_data().

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 0a99803425)
2014-07-21 13:26:57 +02:00
Michael Adam 9eec142886 child: Fix CID 1130966 - unchecked return value from library
check the return code of fcntl via socket_nonblocking
on the listen sockets in child_main()

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 38ef36d998)
2014-07-21 13:26:56 +02:00
Michael Adam f413620c5f child: check return code of socket_blocking for accept in child_main
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 198600ce42)
2014-07-21 13:26:56 +02:00
Michael Adam 903c9eeb1c reqs: fix CID 1130969 - unchecked return code from library
Effectively, the return code of fcntl was not checked
by not checking the return code of socket_nonblocking()
for the server fd.

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 68bd0b61b5)
2014-07-21 13:26:56 +02:00
Michael Adam 5a5ae8bfe1 reqs: fix CID 1130970 - unchecked return code from library
Effectively, the return code of fcntl was not checked
by not checking the return code of socket_nonblocking()
for the client fd.

Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 2004abc1e3)
2014-07-21 13:26:56 +02:00
Michael Adam 51d4f11448 conf: Fix CID 1130973 - resource leak.
Found by coverity.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit a244c1d4aa)
2014-07-21 13:26:56 +02:00
Mukund Sivaraman 78ff8e0f07 Remove suggester (see Banu RT #138) 2014-05-01 14:00:44 +05:30
Michael Adam 6505867f7a NEWS: fix typo
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-20 14:25:31 +01:00
Michael Adam 0654ed6403 Start updating NEWS for 1.8.4
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-16 15:34:43 +01:00
Michael Adam 9ed48eb03b BB#106: remove now unused extract_ssl_url.
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 0f18e4fc3a)
2013-11-16 15:27:06 +01:00
Michael Adam 578f409a03 BB#106: fix CONNECT requsts with IPv6 literal addresses as host.
Use extract_url instead of the old extract_ssl_url:
extract_url is generic and handles ipv6 literal addresses correctly.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 9f43cfd488)
2013-11-16 15:27:00 +01:00
Michael Adam 08c44a36ba BB#106: add default_port argument to extract_http_url and rename it to extract_url
There is in fact nothing http-specific any more about this function, hence
the rename. The input has been stripped of the <proto>:// header anyways.

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

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 98f77ef8c7)
2013-11-16 15:26:53 +01:00
Michael Adam e0ad093b0f BB#116: fix invalid free when connecting to ipv6 literal address
When removing the '[' and ']' characers from the ipv6 literal address, make sure
the pointer that is later free'd stays a malloced pointer by memmoving the
string one place left.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit bb2e894e0d)
2013-11-16 13:13:18 +01:00
Michael Adam 4ef81ff95d build: check for memmove
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 7e1d8154de)
2013-11-16 13:13:17 +01:00
Michael Adam 3cdb1bf7aa [BB#63] conf: Allow multiple Listen statements in the config.
This introduces a list (vector) of addresses instead of
having just one address string.

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

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

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit d0732f9ade)
2013-11-16 11:35:58 +01:00
Michael Adam fdfa365bae sock: add a starting debug message to listen_sock()
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit e40b91974a)
2013-11-16 11:35:58 +01:00
Michael Adam 954d427565 sock: update introductory comment for listen_sock()
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 22587d3d41)
2013-11-16 11:35:58 +01:00
Michael Adam bb5d6af78f sock: set IPV6_V6ONLY on the socket before binding an IPv6 address
so that we can bind wildcard for both IPv4 and IPv6.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 0698e4d180)
2013-11-16 11:35:58 +01:00
Michael Adam 79f34cd113 sock: factor listening on one socket out of the gai-result-loop in listen_sock()
for clarity of the code

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit d7f67768eb)
2013-11-16 11:35:58 +01:00
Michael Adam 4f600654d2 sock: in listen_sock(), move variable for setsockopt() into scope
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 157879d4f6)
2013-11-16 11:35:58 +01:00
Michael Adam 37ffa6986d sock: log each result of getaddrinfo() in listen_sock()
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit a7898a2c98)
2013-11-16 11:35:58 +01:00
Michael Adam 5608382be9 sock: in listen_sock(), add a log message for when bind() has failed
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 947e255d19)
2013-11-16 11:35:58 +01:00
Michael Adam 04cc18d0f8 sock: in listen_sock(), detect and log failure to call setsockopt()
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit b41d140984)
2013-11-16 11:35:58 +01:00
Michael Adam 7b1801d8e7 sock: in listen_sock(), add debug message when socket() call failed.
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 5392e9829c)
2013-11-16 11:35:58 +01:00
Michael Adam 844403afbe sock: move listen() into the getaddrinfo result loop in listen_sock()
This also reverses the exit logic of the loop.
It prepares listening on multiple addresses.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit fa26ad4d56)
2013-11-16 11:35:58 +01:00
Michael Adam 866f1c3e56 child: use a list of listen_fds instead of one single listenfd.
This prepares listenting on multiple sockets, which will be ussed to
fix listening on the wildcard (listen on both ipv6 and ipv4) and
help add the support for multiple Listen statements in the config

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 2ebfd456ef)
2013-11-16 11:35:58 +01:00
Michael Adam 425ce3beb6 child: add addr argument to child_listening_sock().
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 070d621534)
2013-11-16 11:35:58 +01:00
Michael Adam a8a2342527 sock: add addr argument to listen_sock()
instead of using config.ipAddr internally.
This is in preparation to make it possible
to call it for multiple addresses.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 2bd919f01e)
2013-11-16 11:35:58 +01:00
Michael Adam ccb987e8e0 sock/child: remove global variable addrlen.
This changes listen_sock() to not return the
addrlen of the used address from getaddrinfo call
to the caller, stored in global addrlen in child.c.

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

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

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 7eea1638bc)
2013-11-16 11:35:58 +01:00
Michael Adam 0adf359245 [BB#109] Fix crash (infinite loop) when writing to log file fails.
Fall back to syslog logging in that case.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 4bbd6e8626)
2013-11-09 13:47:18 +01:00
Michael Adam 54eaac8e76 log: remove extra newline characters in log messages.
Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit d652681e8a)
2013-11-09 13:47:16 +01:00
Gaudenz Steinlin 8963739e4b [BB#115] Drop supplementary groups
Supplementary groups are inherited from the calling process. Drop all
supplementary groups if the "Group" configuration directive is set to
change to a different user. Otherwise the process may have more rights
than expected.

Reviewed-by: Michael Adam <obnox@samba.org>
(cherry picked from commit c8b8247f70)
2013-11-01 06:40:22 +01:00
Michael Adam a747617c05 [BB#112] build: fix build with autoconf >= 2.69
Use AC_CONFIG_HEADERS instead of obsolete AM_CONFIG_HEADER.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 3cc59ec3be)

Conflicts:

	configure.ac
2013-04-10 00:01:44 +02:00
Mukund Sivaraman 9d7a95bd56 build: Prepend to LDFLAGS instead of replacing its contents 2012-01-23 16:26:07 +05:30
Mukund Sivaraman 3933daf793 Make .xz compressed dist targets too 2011-09-11 11:53:46 +05:30
Mukund Sivaraman 18db1675a0 Update NEWS 2011-08-16 17:56:04 +05:30
Mukund Sivaraman 4d979df636 Bump version to 1.8.3 2011-08-16 17:45:06 +05:30
Mukund Sivaraman fc354343f9 Minor whitespace fix 2011-08-16 17:43:59 +05:30
Mukund Sivaraman 1db982793d [BB#90]: Fix bug in ACL netmask generation
Thanks to John Horne who diagnosed this issue and found the problem.
2011-03-04 14:47:54 +05:30
Mukund Sivaraman 95a6f8259c Validate port number specified in Port directive
This was asked in bug #90 comment #8.
2011-03-04 14:10:11 +05:30
Mukund Sivaraman 8b76f1a939 Update URLs of Tinyproxy 2011-02-28 12:46:46 +05:30
Mukund Sivaraman 121a11d8e5 Surround IPv6 literals with [] in Host: headers 2011-02-07 18:01:03 +05:30
Mukund Sivaraman 736e052dc1 Handle IPv6 literals in URLs correctly 2011-02-04 21:03:12 +05:30
Michael Adam aa197d6dc8 [BB#95] remove two comments that have become wrong by the fix. 2010-12-01 22:21:11 +01:00
Daniel Egger d13d575d29 [BB#95] Fix FilterURLs with transparent proxy support.
Pass a pointer to a char pointer to do_transparent_proxy so the reassembled URL
will actually end up back in the caller where it is needed for filtering
decisions. This fixes the problem that a tinyproxy configured with the
transparent proxy functionality and "FilterURLs Yes" would filter on everything
but the domain.

Signed-off-by: daniel.egger@sphairon.com
Signed-off-by: Michael Adam <obnox@samba.org>
2010-12-01 22:18:08 +01:00
Michael Adam c4b187c8ab README: correctly list --enable-transparent
--enable-transparent-proxy was renamed to --enable-transparent
in August 2004... :-)
2010-12-01 21:44:32 +01:00
Michael Adam 5012ce690f [BB#91] Fix upstream proxy support.
Patch by Jordi Mallach.
2010-08-24 22:50:53 +02:00
Michael Adam 4b75b634d9 upstream: clarify debug messages
There are frequent questions "what does 'No proxy for ...' mean?"
on the mailing list and IRC. Be more specific. (No upstream proxy ...)
Correspondingly, log "Found upstream proxy ... for ..."
2010-08-24 22:50:48 +02:00
Mukund Sivaraman 4b64de4c31 Change wording in NEWS 2010-06-05 09:29:58 +05:30
Mukund Sivaraman 7fa544c3d8 Bump version in configure.ac 2010-06-02 10:40:23 +05:30
Mukund Sivaraman a5a3741291 Add BB#74 to NEWS 2010-06-02 10:39:56 +05:30
Mukund Sivaraman 784d458b82 [BB#74] Create log and pid files after we drop privs 2010-06-02 10:19:49 +05:30
Mukund Sivaraman 94edc4f4c5 Remove excessive code 2010-06-02 10:11:10 +05:30
Mukund Sivaraman be63d2ca19 Add BB#89 to NEWS 2010-06-02 05:05:30 +05:30
Mukund Sivaraman a905437242 Add NEWS for 1.8.2 2010-06-01 08:12:29 +05:30
John van der Kamp 3127e726d0 [BB#89] Don't recompile regular expressions
This is a modification of a patch originally written by
John van der Kamp <john@kirika.demon.nl> at
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579427#12>

The modification was done by the committer.
2010-06-01 07:58:02 +05:30
Mukund Sivaraman 5bb184c54d Fix typo in manpage 2010-05-30 10:02:45 +05:30
Jordi Mallach 505ff803e9 [BB#83] Use output of id instead of $USER 2010-04-21 21:01:59 +05:30
Dmitry Semyonov d03e3a52e5 Fix crash in send_stored_logs() 2010-04-21 20:32:41 +05:30
Mukund Sivaraman fe9444d585 Fix compiler warning about dereferencing type-punned pointers
This is a backport of commit 19b9bff888
from the master branch.
2010-04-21 20:21:22 +05:30
Mukund Sivaraman b37135524d Revert "main: drop privileges right after reading the config"
This reverts commit 965664798c. It should
fix the issue in bug #87.
2010-04-21 20:09:20 +05:30
Mukund Sivaraman 7f053670c0 Just fix the support URLs
These should always point to the top-level Tinyproxy homepage.
2010-03-28 10:29:56 +05:30
Mukund Sivaraman b28e438cdf Revert "Update Tinyproxy website URLs"
This reverts commit e495bdf129.
2010-03-28 10:27:45 +05:30
Mukund Sivaraman e495bdf129 Update Tinyproxy website URLs 2010-03-27 08:19:53 +05:30
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
Mukund Sivaraman 21c8d7a7ed Add more bugs to NEWS 2009-09-28 19:08:54 +05:30
Mukund Sivaraman 92378a9085 docs: Fix typos in tinyproxy.conf manpage 2009-09-28 18:51:42 +05:30
Mukund Sivaraman 03c8a415e3 Add note about build system to NEWS 2009-09-28 18:37:40 +05:30
Mukund Sivaraman afcd38536b docs: Fix case 2009-09-28 16:26:19 +05:30
Michael Adam 5a77c9744a docs: document the reverse proxying options in tinyproxy.conf(5) 2009-09-28 12:18:52 +02:00
Michael Adam f0cbc35ca9 docs: document ConnectPort in tinyproxy.conf(5) 2009-09-28 11:37:54 +02:00
Michael Adam 9ff9bd18fe docs: document Anonymous in tinproxy.conf(5) 2009-09-28 11:35:20 +02:00
Michael Adam f1e5360ef1 docs: document the filtering options in tinyproxy.conf(5) 2009-09-28 11:24:34 +02:00
Michael Adam 33872928d5 docs: document ViaProxyName in tinyproxy.conf(5) 2009-09-28 11:24:34 +02:00
Michael Adam 8c31287805 docs: document Allow and Deny in tinyproxy.conf(5) 2009-09-28 11:24:34 +02:00
Michael Adam 42b072b863 docs: document MaxRequestsPerChild in tinyproy.conf(5) 2009-09-28 11:24:34 +02:00
Michael Adam 553b95b3ed docs: document StartServers in tinyproxy.conf(5) 2009-09-28 11:24:34 +02:00
Michael Adam 9574bf0855 docs: document MinSpareServers and MaxSpareServers in tinyproxy.conf(5)
Michael
2009-09-28 11:24:33 +02:00
Michael Adam bc1b7def01 docs: document "MaxClients" in tinyproxy.conf(5)
Michael
2009-09-28 11:24:33 +02:00
Michael Adam 078040731c docs:document "Upstream"/"No Upstream" in the tinyproxy.conf manpage
Michael
2009-09-28 11:24:33 +02:00
Michael Adam 5198ae644b conf: beautify one formatting in the directives array.
Michael
2009-09-28 11:24:33 +02:00
Michael Adam 2beaac96d3 handle_connection: make logic clearer when deciding whether to use connect/ssl
Michael
2009-09-28 11:24:33 +02:00
Mukund Sivaraman f08f0218af Include limits.h for LONG_MAX and LONG_MIN
Not including limits.h caused an issue when building on FreeBSD.
2009-09-28 13:41:36 +05:30
Mukund Sivaraman f0263c5823 Fix version in NEWS file 2009-09-27 19:25:51 +05:30
Mukund Sivaraman e58f392e57 Add NEWS for 0.7.1 2009-09-27 19:24:11 +05:30
Mukund Sivaraman 44e32f15d7 Remove section on debugging from README 2009-09-27 19:09:51 +05:30
Mukund Sivaraman bf38e2e68b Update README to asciidoc format 2009-09-27 19:08:46 +05:30
Mukund Sivaraman 630d44e67b [BB#10] Do not filter out transfer-encoding header 2009-09-27 16:27:51 +05:30
Michael Adam 4668ae9e06 tests: set XTinyproxy Yes in the test setup
Michael
2009-09-27 12:52:39 +02:00
Michael Adam 7710dc4a8c conf: make xtinyproxy BOOL in the directives array, too
Michael
2009-09-27 12:48:48 +02:00
Michael Adam c8a0a1efdc docs:tinyproxy.conf(5): fix a typo.
Michael
2009-09-27 12:41:30 +02:00
Michael Adam 95f2584883 docs: document XTinyproxy in the tinyproxy.conf manpage.
Michael
2009-09-27 12:40:44 +02:00
Michael Adam 577e95880e tinyproxy.conf: Update the description of XTinyproxy (it is a bool).
Michael
2009-09-27 12:35:16 +02:00
Michael Adam eecf145dbb conf: turn XTinyproxy into a boolean option
This is what it actually is.

The string value was used in earlier versions to compare
against the uri->authority string. But not as a list of
sites to create an X-Tinyproxy header for, as the tinyproxy.conf
template states...

Michael
2009-09-27 12:32:31 +02:00
Michael Adam 0539be08b4 tests: fix infinite loop "waiting for 3 seconds..." in bash
Michael
2009-09-27 12:07:54 +02:00
Michael Adam 79e994dd97 tests:webclient: allow HTTP/1.0 requests with methods other than GET
Michael
2009-09-27 11:18:52 +02:00
Michael Adam 039537cbe7 make: add targets "test" and "valgrind-test"
These simply run the corresponding test scripts.
Needs to be extended.

Michael
2009-09-27 11:18:52 +02:00
Mukund Sivaraman 2fd7417f56 Modify usage help text shown when Tinyproxy is run with -h 2009-09-27 08:09:24 +05:30
Mukund Sivaraman 1cdec54029 build: Reverse maintainer mode test
This is so that if this variable name changes in the future,
Tinyproxy would still build without aborting on -Werror.
2009-09-27 08:09:24 +05:30
Mukund Sivaraman 54f4e8a91f Use correct format string for POSIX pid_t in pidfile_create()
This patch also adds a gtk-doc comment for pidfile_create().
2009-09-27 08:09:24 +05:30
Mukund Sivaraman 43d0af85af Remove obsolete comment 2009-09-27 08:09:24 +05:30
Mukund Sivaraman 1c72d8f063 build: Run configure in autogen.sh 2009-09-27 08:09:23 +05:30
Mukund Sivaraman 38c20cd867 Add explicit casts for c++ mode in transparent-proxy.c 2009-09-27 08:09:23 +05:30
Mukund Sivaraman c8be0250cd Fix use of uninitialized variable 2009-09-27 08:09:23 +05:30
Mukund Sivaraman 0dda30295e Add explicit casts for c++ mode in reverse-proxy.c 2009-09-27 08:09:23 +05:30
Mukund Sivaraman 00931dfc68 build: Add -Werror to CFLAGS during maintainer mode builds 2009-09-27 08:09:23 +05:30
Mukund Sivaraman 3f0ccdef3c strdup() the default stathost in config struct as it can be freed 2009-09-27 08:09:23 +05:30
Mukund Sivaraman 0ecb688269 Don't ignore retval of ftruncate() in utils.c 2009-09-27 08:09:23 +05:30
Mukund Sivaraman 1586b39138 Don't ignore retval of read() in reqs.c 2009-09-27 08:09:22 +05:30
Mukund Sivaraman 003df7454a Don't ignore retval of write() in log.c 2009-09-27 08:09:22 +05:30
Mukund Sivaraman 616c03a9fb Don't ignore retval of ftruncate() in log.c 2009-09-27 08:09:22 +05:30
Mukund Sivaraman fc7415a5b0 Include debugging functions only when debug mode is used 2009-09-27 08:09:22 +05:30
Mukund Sivaraman d102ed4ed3 Don't ignore retval of chdir() 2009-09-27 08:09:22 +05:30
Michael Adam 50c781d0c9 build: import the AM_SILENT_RULES if available, but default to verbose.
Automake 1.11 (and I think 1.10b already) offers the AM_SILENT_RULES macro.
This adds switches --quiet, --enable-silent-rules and --disable-silent-rules
to configure.

--quiet makes the configure run itself quite.
--enable-silent-rules makes the compile process less verbose:
  for a file that is compiled without errors or warnings, a simple
  "CC     main.o" is printed (e.g.). Compiler warnings and errors
  are printed of course.
  This makes it much easier (IMHO) to spot build problems.
--disable-silent-rules turns the silent rules off

I have set it up such that the default for tinyproxy is to build
in verbose mode (i.e. with silent rules disabled). This prints
the whole compile call command line for each source file compiled,
precisely as before.

You can also control verbose/non-verbose mode at "make" time, i.e.
after configure has run, by calling "make V=0 ..." or "make V=1 ..."
for running in silent and verbose mode, respectively.

If the version automake used to create configure is too old,
the result is unaltered, compared to the result before this change.

Wow - this is a long commit message for a 1-liner.
But since I discussed this with Mukund earlier, and he did
not seem to be too fond if this, I felt the need to justify
this change... :-)

Michael
2009-09-22 13:09:25 +02:00
Michael Adam e8cbd7088c docs:tinyproxy.conf: document "PidFile".
Michael
2009-09-22 00:22:19 +02:00
Michael Adam 7b07477ebd docs:tinyproxy.conf: document LogFile, Syslog, and LogLevel
Michael
2009-09-22 00:19:12 +02:00
Michael Adam 93219ea0db docs:tinyproxy.conf: describe ErrorFile and DefaultErrorFile and StatFile
Somehow, I don't quite get the asciidoc formatting yet.
I can't get the extra paragraph on templates to look nice
in the manpage output.
But at least there is some content...

Michael
2009-09-22 00:05:23 +02:00
Michael Adam 92c64cabc1 tests: use the debug.html file as DefaultErrorFile in the tests.
Michael
2009-09-21 09:42:47 +02:00
Mukund Sivaraman df6e8ae046 Fix warning about format string not being a string literal 2009-09-21 10:04:09 +05:30
Mukund Sivaraman f0cc213c5a Remove trailing comma from acl_type enum 2009-09-21 09:59:11 +05:30
Mukund Sivaraman e9f8212560 Suppress gcc warnings about variadic macros 2009-09-21 09:57:29 +05:30
Mukund Sivaraman 0cc707b3ff Rename conffile.[ch] to conf.[ch] 2009-09-21 09:41:59 +05:30
Mukund Sivaraman 9d5a15ed2d [BB#18] Fix pointer aliasing issues
The changes were suggested by ians on the Banu forums.
2009-09-21 09:16:58 +05:30
Mukund Sivaraman d7ae6e4653 build: Add -ansi and --std=c89 to CFLAGS 2009-09-21 09:14:51 +05:30
Mukund Sivaraman eccc765057 Remove trailing comma from filter_policy_t 2009-09-21 07:32:38 +05:30
Michael Adam b424ec2865 configure: fix a typo in the tinyproxy version definition.
Michael
2009-09-20 22:26:41 +02:00
Michael Adam b95f7b9ffb Print a http error when the client headers could not be retrieved.
A ususal case here is that the headers were buggy, e.g. a line
without a ":" to separate the header field name from the value.
Previous behaviour was to silently return a blank page.

Michael
2009-09-20 22:24:18 +02:00
Michael Adam fcb053a77c Revert "Remove unused parameter from process_request()"
This reverts commit f3312c22a0.

The "hashofheaders" argument to process_request() is needed
for building with reverse support or with transparent support.

Michael
2009-09-20 21:58:52 +02:00
Michael Adam 87f7a79e89 tests:webclient: fix default version (string, not number...)
Michael
2009-09-20 13:24:06 +02:00
Michael Adam 2208bebeac tinyproxy.conf: add a comment referring to the tinyproxy.conf(5) manpage
Michael
2009-09-20 11:01:30 +02:00
Michael Adam 30cb3f89ab tinyproxy.conf: update description of User/Group
Michael
2009-09-20 10:58:18 +02:00
Mukund Sivaraman ad8f0feb4f build: Remove obsolete/unused macros 2009-09-20 14:14:27 +05:30
Mukund Sivaraman 23464e88ad Remove unnecessary vfork.h include 2009-09-20 14:08:14 +05:30
Mukund Sivaraman 73409c9fe1 build: Remove use of the obsolete AC_TYPE_SIGNAL macro
C89 compilers use void return type for signal handler functions.
2009-09-20 14:03:56 +05:30
Mukund Sivaraman 919eedc7f9 Remove inline keyword from static functions
The compiler inlines static functions as necessary anyway.
No more inline keywords exist in Tinyproxy source code. We want to
avoid using this keyword anyway.
2009-09-20 13:58:50 +05:30
Mukund Sivaraman 403fd7cc25 build: Remove obsolete/unused macros 2009-09-20 13:54:57 +05:30
Mukund Sivaraman 0978decbac build: Rename autoconf variable 2009-09-20 13:45:47 +05:30
Mukund Sivaraman a1725f6297 Better handle the debugging flags 2009-09-20 13:38:53 +05:30
Mukund Sivaraman 1a5d1b4833 build: Remove profiling related CFLAGS
These can be specified manually by a developer when necessary. Such flags
do not belong in a generic distribution.
2009-09-20 13:37:09 +05:30
Mukund Sivaraman 753010f571 build: Update CFLAGS and also check if they are supported
Also, enable all warnings by default, whether it is a debug
build or not.
2009-09-20 13:32:46 +05:30
Mukund Sivaraman 07ad8ad1b2 Remove unnecessary CFLAGS initialization 2009-09-20 13:19:22 +05:30
Mukund Sivaraman 1196cc11b9 Remove unnecessary prefix test 2009-09-20 13:12:57 +05:30
Mukund Sivaraman abafcf08ab Remove the target system information when the version is displayed
If we require information about the runtime environment, it can be
found using the uname program. And binutils can tell about what the
tinyproxy binary contains. Tinyproxy doesn't have to report this
information.
2009-09-20 12:40:52 +05:30
Mukund Sivaraman 90e7d07f44 Remove ability to change the name of the default configuration file
This feature will only confuse us during support, if users come to
us with a Tinyproxy build which has a differently named default config
file. This feature is not that useful anyway.
2009-09-20 12:33:47 +05:30
Mukund Sivaraman 6f9fa5287f Remove obsolete SOCKS related entries from configure.ac
These were probably never supported, and we shouldn't claim that
we support SOCKS when we don't.
2009-09-20 12:21:59 +05:30
Mukund Sivaraman fbc0549540 Remove unused statements from configure.ac 2009-09-20 12:14:02 +05:30
Mukund Sivaraman 851ef02fbe build: Generate more version related variables 2009-09-20 12:13:26 +05:30
Mukund Sivaraman e33fb9f77b docs: Make formatting changes in tinyproxy.conf manpage 2009-09-20 11:55:47 +05:30
Mukund Sivaraman 9dfe1f1a56 docs: Further describe User and Group keys in tinyproxy.conf manpage 2009-09-20 11:53:44 +05:30
Mukund Sivaraman 9f0bf550af Revert "docs: extend description of the User and Group parameters."
This reverts commit b6433522eb.
2009-09-20 11:50:47 +05:30
Michael Adam 371e13e44f docs: document Listen, Bind, Bindsame, and Timeout in tinyproxy.conf(5)
Michael
2009-09-20 01:54:06 +02:00
Michael Adam b6433522eb docs: extend description of the User and Group parameters.
Michael
2009-09-20 01:54:06 +02:00
Mukund Sivaraman f7d494d9f7 doc: Add initial description in tinyproxy.conf manpage 2009-09-19 23:04:04 +05:30
Mukund Sivaraman 0def858576 docs: Add placeholder for tinyproxy.conf manpage 2009-09-19 09:57:24 +05:30
Michael Adam 4d4f7d2a09 tests:webclient: add copyright notice to the pod documentation.
Michael
2009-09-17 00:25:57 +02:00
Michael Adam d1c8a68375 tests:webserver: Add copyright notice to the pod documentation.
Michael
2009-09-17 00:25:57 +02:00
Michael Adam aae8ae5d8d tests:webclient: reduce duplication.
Michael
2009-09-17 00:25:57 +02:00
Michael Adam b7d9256a7a tests:webclient: add a --dry-run mode that prints the request to stdout
and does not connect to the server at all.

Michael
2009-09-16 22:35:35 +02:00
Michael Adam 4ef7901115 tests:webclient: extend webclient to support HTTP/0.9, 1.0 and 1.1 requests.
Enable spcifying HTTP protocol version on command line ( --http-version).
Enable specifying method (GET, CONNECT, ...) on the command line (--method).
Add POD documentation.
Use pod2usage() to print help message.

Michael
2009-09-16 22:35:35 +02:00
Michael Adam b5a69151fa tests: add Makefile.am to tests/ and tests/scripts dir (for packaging)
Michael
2009-09-16 22:35:35 +02:00
Michael Adam f648d82edc tests: prepare tinyproxy for filter file usage in tests.
Michael
2009-09-15 02:25:10 +02:00
Michael Adam 574a65c28e filter: un-linebreak after un-indent...
Michael
2009-09-15 02:25:10 +02:00
Michael Adam c240ca3bcc child: move log messagte in child_main_loop() to a less irritating place.
Michael
2009-09-15 02:25:10 +02:00
Michael Adam 93b00446b9 filter: reduce indentation in filter_init by 16 characters by using return.
Michael
2009-09-15 02:25:09 +02:00
Mukund Sivaraman 9594b8889e Revert "Fix constness of stathost"
This reverts commit 42d2e10c93.
2009-09-15 04:14:26 +05:30
Mukund Sivaraman f3312c22a0 Remove unused parameter from process_request() 2009-09-15 04:11:58 +05:30
Mukund Sivaraman 551e041638 Make takesig() into a static function 2009-09-15 04:09:34 +05:30
Mukund Sivaraman 42d2e10c93 Fix constness of stathost 2009-09-15 04:08:26 +05:30
Mukund Sivaraman 83ebd74d87 Minor indenting changes
Also changed the text "configuration file" to read "config file".
2009-09-15 04:07:06 +05:30
Mukund Sivaraman d243515fa7 Return instead of exit() at end of main() 2009-09-15 04:06:26 +05:30
Mukund Sivaraman ce55167487 Minor indenting changes 2009-09-15 03:53:35 +05:30
Mukund Sivaraman b3065b6d18 Exit with proper status in case of bad commandline arguments 2009-09-15 03:53:18 +05:30
Mukund Sivaraman 34e23233ce Add doc for change_user() 2009-09-15 02:00:20 +05:30
Mukund Sivaraman 1d744eb4c9 Return correct error status when setuid() or setgid() fails 2009-09-15 01:55:16 +05:30
Mukund Sivaraman 56748c5e65 Extract setuid/setgid code into a function 2009-09-15 01:55:16 +05:30
Mukund Sivaraman 5ec5449194 Extract cmdline parsing code into a function 2009-09-15 01:55:16 +05:30
Michael Adam f25b0e2872 filter: untangle assignment and check in filter_init().
Michael
2009-09-14 22:18:28 +02:00
Michael Adam c8e1696a22 conffile: reformat the directives array for readability.
Michael
2009-09-14 22:17:45 +02:00
Michael Adam b6413068e2 tests:webserver: record the value of the server header field in a variable.
Michael
2009-09-14 22:12:30 +02:00
Mukund Sivaraman 96303e10f3 Remove unused variable 2009-09-15 01:15:27 +05:30
Mukund Sivaraman 7b9234f394 Indent code to Tinyproxy coding style
The modified files were indented with GNU indent using the
following command:

indent -npro -kr -i8 -ts8 -sob -l80 -ss -cs -cp1 -bs -nlps -nprs -pcs \
    -saf -sai -saw -sc -cdw -ce -nut -il0

No other changes of any sort were made.
2009-09-15 01:11:25 +05:30
Mukund Sivaraman 2cb6777592 Remove C++ wrapper from headers
These are not necessary as Tinyproxy is pure C code, and only
to be used within Tinyproxy. It is not a library.
2009-09-15 01:04:28 +05:30
Mukund Sivaraman 26b95f7b81 Add Tinyproxy indent script 2009-09-15 01:00:50 +05:30
Mukund Sivaraman 5d48ba3c66 docs: Fix .gitignore 2009-09-14 19:13:34 +05:30
Michael Adam df4892d939 tests:webclient: add User-Agent header to request.
Michael
2009-09-14 13:30:58 +02:00
Michael Adam 8c5391ab6e tests:webserver: add handing of bad request error.
Michael
2009-09-14 13:30:57 +02:00
Michael Adam 78502e4565 tests:webserver: add parsing of request
Michael
2009-09-14 13:30:57 +02:00
Mukund Sivaraman e06aaa5c79 Rename doc directory to docs 2009-09-14 16:56:12 +05:30
Mukund Sivaraman 0491411807 doc: Remove pre-generated manpage from repo
A pre-generated manpage still gets EXTRA_DIST'ed in release tarballs.
2009-09-14 16:50:49 +05:30
Mukund Sivaraman 325d12b01d doc: Don't EXTRA_DIST configure generated tinyproxy.txt 2009-09-14 16:49:56 +05:30
Mukund Sivaraman caba182038 doc: Add .gitignore to doc/man8/ 2009-09-14 16:43:06 +05:30
Mukund Sivaraman 05ee13a649 doc: Another manpage text update 2009-09-14 16:20:10 +05:30
Mukund Sivaraman 017ba5d42f doc: Case changes and minor text updates to manpage 2009-09-14 15:51:37 +05:30
Mukund Sivaraman 00614c1523 doc: Update manpage to set missing fields 2009-09-14 15:46:18 +05:30
Michael Adam 675c7492c1 docs: update asciidoc-generated manpage tinyproxy.8 after changes.
Michael
2009-09-14 11:22:51 +02:00
Michael Adam 19add5471b doc: use asciidoc-auto-enumeration in list.
Michael
2009-09-14 11:20:07 +02:00
Michael Adam b3e3fe6647 doc: add my c to the manpage
Michael
2009-09-14 11:03:34 +02:00
Michael Adam cdb9d54dca docs: update tinyproxy manpage: elaborate template files and explain stat host.
Michael
2009-09-14 11:02:28 +02:00
Michael Adam afacc3d80b tests:webserver: move parsing of request to its own function.
(Prepare for really parsing the request...)

Michael
2009-09-14 11:02:28 +02:00
Mukund Sivaraman 8f8f99098e packaging: Update summary and description in spec file 2009-09-13 17:26:38 +05:30
Mukund Sivaraman b952bc6595 Remove acinclude.m4 and configure macro dir 2009-09-13 17:14:08 +05:30
Michael Adam f1a586648e tests: test retreival of stathost page.
Michael
2009-09-13 01:52:26 +02:00
Michael Adam 282ec11792 tests: set stathost to 127.0.0.127 in the testsuite
Michael
2009-09-13 01:52:11 +02:00
Michael Adam 5a96099cde tests: print IP and port after firing up tinyproxy and webserver
Michael
2009-09-13 01:31:05 +02:00
Michael Adam abb2283e2e tests:webserver: be more rfc 1945 compliant in the server-header.
Michael
2009-09-13 01:14:44 +02:00
Michael Adam 71f3721bb1 tests: fix run_tests.sh after templates have moved.
Michael
2009-09-13 01:09:44 +02:00
Mukund Sivaraman 7aa5482754 doc: Remove missing tinyproxy.conf from EXTRA_DIST 2009-09-13 04:14:21 +05:30
Mukund Sivaraman 168935344a Cleanup top-level Makefile.am 2009-09-13 04:13:21 +05:30
Mukund Sivaraman 9b6975c9eb m4macros: EXTRA_DIST m4 macros from its own directory 2009-09-13 04:12:32 +05:30
Mukund Sivaraman 49971a76b9 Remove files that are distributed anyway from EXTRA_DIST 2009-09-13 04:09:37 +05:30
Mukund Sivaraman 7b4f67ecef data: Cleanup installation of templates 2009-09-13 04:08:06 +05:30
Mukund Sivaraman 9d7bd43d8e Fix Makefile.am 2009-09-13 04:05:28 +05:30
Mukund Sivaraman c44264ddaa doc: Move doc/tinyproxy.conf to etc/ directory 2009-09-13 04:04:18 +05:30
Mukund Sivaraman 4cbc6b0359 doc: Move doc/HTML_VARIABLES content to the manpage 2009-09-13 03:59:03 +05:30
Mukund Sivaraman 13ccc059d0 doc: Rename some files 2009-09-13 03:53:32 +05:30
Mukund Sivaraman ce97014bc0 doc: Delete report.sh.tmpl 2009-09-13 03:49:20 +05:30
Mukund Sivaraman f3e06436b5 doc: Move templates to data/templates/ directory 2009-09-13 03:48:24 +05:30
Mukund Sivaraman d7296318a0 doc: Cleanup doc/Makefile.am 2009-09-13 03:40:59 +05:30
Mukund Sivaraman a4a93917c9 doc: Use asciidoc for manpage 2009-09-13 03:32:38 +05:30
Mukund Sivaraman 31f98e9adc doc: Remove report.sh script 2009-09-13 02:55:42 +05:30
Michael Adam 6c83a49bbb tests: add a script wrapper to run tinyproxy under valgrind in the tests.
This runs valgrind with the -q switch - i.e. the log file
tests/env/var/log/valgrind.log will only contain anything when there were
valgrind errors. (Memory leaks...)

Michael
2009-09-11 01:10:11 +02:00
Michael Adam 26aa8648b6 tests: add support for running tinyproxy under valgrind.
When you want to run tinyproxy under valgrind,
set the environment variable VALGRIND to some useful
valgrind command line.

Michael
2009-09-11 01:02:52 +02:00
Michael Adam 389f5d1464 make "config_file" a const in the config struct.
Michael
2009-09-10 22:16:58 +02:00
Michael Adam 735c9cb70f reqs.c: fix two implicit cast warnings.
Michael
2009-09-10 22:12:16 +02:00
Michael Adam 408c781d14 tests: restructure run_tests into functions to make main flow clearer.
Also prepare for modularizing the testsuite.

Michael
2009-09-10 12:53:25 +02:00
Michael Adam dfa1763af9 tests:run_tests: add complete GPL boilerplate.
Michael
2009-09-10 12:09:12 +02:00
Michael Adam bc1da1cbb5 tests:webclient: add complete GPL boilerplate.
Michael
2009-09-10 12:08:17 +02:00
Michael Adam 290c4f581e tests/webserver: add complete GPL boilerplate.
Michael
2009-09-10 12:07:48 +02:00
Michael Adam 4d4f8bffef tests:webserver: make pid-file, log-dir and doc-root reside in /tmp by default
So simply starting the server will work.

Michael
2009-09-10 11:08:17 +02:00
Michael Adam 974be68476 tests/webserver: rework locking of pid file.
Michael
2009-09-10 11:08:17 +02:00
Michael Adam 449af292dc tests:webserver: reopen STDOUT/STDERR after locking pid file.
Michael
2009-09-10 11:08:08 +02:00
Michael Adam 526c70f687 tests: this is a first draft of the beginning of a test suite.
It provisions a test envirnonment, fires up the perl web server
and tinyproxy and currently makes one direct request to the
web server and one request through tinyproxy.

This will be modularized and extended in the sequel.

Michael
2009-09-10 01:20:59 +02:00
Michael Adam 158f8a7e15 tests: add a simple web client written in perl.
This should be one of the test tools for writing our testsuite.

This can be used to make direct connects to web servers like so:

webclient.pl server_ip:port /path/file.html

and to make requestis via a proxy like this:

webclient.pl proxy_ip:port http://webserver:port/path/file.html

Michael
2009-09-10 01:15:01 +02:00
Michael Adam a39d7cd8d8 tests: add a simple webserver written in perl.
This should be the web server to test against in the upcoming selftest suite.
This web server will evolve as the test suite grows.
Currently, it just returns a web site quoting the request and a fortune
(if fortune is installed...) for whatever request it gets.

The option to provide a document root is already present.

Michael
2009-09-10 01:13:01 +02:00
Michael Adam e39da7d0b2 README: Update the CONTRIBUTING section.
* provide the git url
* mention git format-patch
* mention the #tinyproxy irc channel

Michael
2009-09-09 10:52:17 +02:00
Michael Adam 4092c70b06 Fix compiler warnings: make const strings const in process_server_headers().
Michael
2009-08-12 23:49:46 +02:00
Michael Adam 0d585dca8d Fix compiler warnings: make const strings const in process_client_headers().
Michael
2009-08-12 23:49:16 +02:00
Michael Adam c59d012d11 Fix compiler warnings: Make const strings const in remove_connection_headers()
Michael
2009-08-12 23:47:45 +02:00
Michael Adam 1bfe8b6bea Fix implicit cast warning in get_all_headers().
And untangle assignment from check.

Michael
2009-08-09 23:30:04 +02:00
Michael Adam 3b6bc45c37 Fix two implicit cast warnings in pull_client_data().
Michael
2009-08-09 23:28:36 +02:00
Michael Adam bfca4019b7 Fix three implicit cast warnings in process_request().
Michael
2009-08-09 23:08:54 +02:00
Michael Adam 43fcc9ea37 Fix implicit cast warning in upstream_add().
Michael
2009-08-09 23:06:31 +02:00
Michael Adam 00fd84586c Fix implicit cast warning in extract_ssl_url().
Michael
2009-08-09 23:05:28 +02:00
Michael Adam ed23ceef64 Fix implicit cast warning in extract_http_url().
Michael
2009-08-09 23:04:27 +02:00
Michael Adam bfa2c8ed77 Fix implicit cast warning in check_allowed_connect_ports().
Michael
2009-08-09 23:02:54 +02:00
Michael Adam eb0deeb966 fix signed vs unsigned comparison warning in check_allowed_connect_ports().
Michael
2009-08-09 23:01:32 +02:00
Michael Adam caee88c774 readline(): fix 5 implicit cast warnings
Michael
2009-08-07 10:10:04 +02:00
Michael Adam 947e8eb838 write_message(): fix signed/unsigned comparison warning
Michael
2009-08-07 10:07:07 +02:00
Michael Adam c535939a9c write_message(): fix implicit cast warnings.
Michael
2009-08-07 10:06:12 +02:00
Michael Adam b450ad76ff safe_write: fix unsigned vs. signed comparison
Michael
2009-08-07 10:04:57 +02:00
Michael Adam 2fff622819 send_stored_logs(): remove an implicit cast warning.
Michael
2009-08-07 09:54:15 +02:00
Michael Adam 4434dd24f1 send_stored_logs: fix signed/unsigned comparison
Michael
2009-08-07 09:42:45 +02:00
Michael Adam 8a27e29f7e log_message(): remove implicit cast warning.
Michael
2009-08-07 09:28:35 +02:00
Michael Adam 87f5657db0 log: make const char array const.
Michael
2009-08-07 09:27:51 +02:00
Michael Adam 1052502b63 http_message_add_headers: make argument num_headers unsigned
and remove signed vs. unsigned comparison warnings.

Michael
2009-08-07 09:24:32 +02:00
Michael Adam f99edadc92 http_message_add_headers(): fix implicit cast warning.
Michael
2009-08-07 09:21:28 +02:00
Michael Adam baf634194c http_message_create(): remove two implicit cast warnings.
Michael
2009-08-07 09:20:28 +02:00
Michael Adam 6a35704cdb heap: make a const string const in malloc_shared_memory().
Michael
2009-08-07 09:17:49 +02:00
Michael Adam 8f50875740 heap: fix an implicit cast warning.
Michael
2009-08-07 09:17:12 +02:00
Michael Adam ab9e8a59e2 hashmap: fix three implicit cast warnings.
Michael
2009-08-07 09:16:07 +02:00
Michael Adam 181b03d729 Fix an implicit cast warning in initialize_conn().
Michael
2009-08-07 09:12:42 +02:00
Michael Adam 02e7bc7545 send_html_file(): remove a discards qualifyer warning
and untangle assignment from check.

 Michael
2009-08-07 08:56:46 +02:00
Michael Adam 3adec81872 html-error: make read only argument const in lookup_variable().
Michael
2009-08-07 08:53:26 +02:00
Michael Adam 76dadf47d3 make a const string const in send_http_error_message().
Michael
2009-08-07 08:51:35 +02:00
Michael Adam 1c3c268b50 make a const string const in send_http_headers().
Michael
2009-08-07 08:49:21 +02:00
Michael Adam c8ee85702e make message argument of indicate_http_error() const.
Michael
2009-08-07 08:48:51 +02:00
Michael Adam 20b606b6f5 make message argument to send_http_headers() constant.
Michael
2009-08-07 08:44:47 +02:00
Michael Adam 251a975126 add_error_variable(): make key and data arguments const
Michael
2009-08-07 08:41:36 +02:00
Michael Adam 05d1b2b372 showstats(): fix an implicit cast warning.
Michael
2009-08-07 08:38:41 +02:00
Michael Adam 3127baa4c6 showstats(): add a const to a const string
Michael
2009-08-07 08:37:44 +02:00
Michael Adam bb067eb13c init_stats(): fix implicit cast warning.
Michael
2009-08-07 08:36:10 +02:00
Mukund Sivaraman 6f255d0900 Update bug tracker URL 2009-08-07 05:38:46 +05:30
Mukund Sivaraman 4518e4334d Wrap len in parantheses 2009-08-07 04:30:38 +05:30
Matthew Dempsky 59d273fdcc correctly handle folded header fields 2009-08-07 03:59:10 +05:30
Mukund Sivaraman 402b662def Fix const warning 2009-08-07 03:54:08 +05:30
Mukund Sivaraman a21cd7e3ed Rename tinyproxy.[ch] to main.[ch] 2009-08-07 03:42:53 +05:30
Matthew Dempsky b5089fecc7 fix error message formatting
Signed-off-by: Michael Adam <obnox@samba.org>
2009-08-06 07:33:20 +02:00
Michael Adam f904831acd .gitignore: ignore vi backup files
Michael
2009-08-05 00:28:01 +02:00
Michael Adam 2ca1f9027b add const to the key argument of anonymous_insert().
Michael
2009-08-05 00:15:04 +02:00
Michael Adam c6475974b5 add const to the key argument for anonymous_search().
Michael
2009-08-05 00:14:20 +02:00
Michael Adam caf20d786b utils: make headers constant in send_http_message() to reduce compiler warnings
Michael
2009-08-05 00:09:41 +02:00
Michael Adam 1cdd76af31 http_message_add_headers(): make parameter headers const.
Michael
2009-08-05 00:09:16 +02:00
Michael Adam 867b4c9813 filter_init(): kill implicit cast warnings by adding explicit casts.
Michael
2009-08-04 23:57:30 +02:00
Michael Adam f0a46fd71c vector: remove implicit cast warning in vector_insert() by adding explicit cast
Michael
2009-08-04 23:52:56 +02:00
Michael Adam 5b81dec879 vector: remove implicit cast warning in vector_create()
Michael
2009-08-04 23:51:29 +02:00
Michael Adam 0aa45b0d34 child_pool_create(): add to explicit cats to reduce compiler warnings.
Michael
2009-08-04 23:47:28 +02:00
Michael Adam 60de38ceaa child: adapt child_config to contain unsigned integers
as just changed in get_int_arg.

Michael
2009-08-04 23:47:28 +02:00
Michael Adam b4d8c5b9bf conffile: change [sg]et_int_arg() to return unsigned long int
This is also the parser regexp for INT in the definition.

Michael
2009-08-04 23:47:28 +02:00
Michael Adam 23b09947c6 conffile: add explicit cast in get_string_arg().
Michael
2009-08-04 23:47:28 +02:00
Michael Adam 35abbbc26d config_compile(): add an explicit cast.
Michael
2009-08-04 23:47:28 +02:00
Michael Adam 0b583194b7 config_compile(): fix as signed / unsigned comparison compiler warning.
Michael
2009-08-04 23:47:28 +02:00
Michael Adam f52be1a2a1 conffile: fix indentation in the directives definition.
Michael
2009-08-04 23:47:28 +02:00
Michael Adam e6ac4b28cd conffile: fix some missing initializer warnings in the directives definition.
Michael
2009-08-04 23:47:28 +02:00
Michael Adam 32c7caf710 conffile: reformat some indentation and linebreak in the directives definition.
Michael
2009-08-04 23:47:28 +02:00
Michael Adam 8f955d5543 child: add explicit cast in child_main().
Michael
2009-08-04 23:47:28 +02:00
Michael Adam 50dbd61063 buffer: add explicit cast in read_buffer().
Michael
2009-08-04 23:47:28 +02:00
Michael Adam e5e665b0c6 buffer: add explicit cast in new_buffer().
Michael
2009-08-04 23:47:27 +02:00
Michael Adam 88dbe04c81 buffer: untangle assignment and check.
Michael
2009-08-04 23:47:27 +02:00
Michael Adam f5c80119ca buffer: add two explicit casts to reduce compiler warnings in makenewline().
Michael
2009-08-04 23:47:27 +02:00
Michael Adam 25344751eb buffer: untangle assignment from check in makenewline().
For better debuggability.

Michael
2009-08-04 23:47:27 +02:00
Michael Adam ab4df6edb8 check_acl(): initialize "perm" to eliminate compiler warning.
Provides safe fallback for switch statement, just in case..

Michael
2009-08-04 23:47:27 +02:00
Michael Adam 14a3e187ee check_acl(): remove the fd argument - it is not used.
Host name and IP address are provided instead.

Michael
2009-08-04 23:47:27 +02:00
Michael Adam 64ff313260 check_acl(): fix function header comment.
Michael
2009-08-04 23:47:27 +02:00
Michael Adam 0abd82b7e9 check_acl(): add explicit cast to return value of vector_getentry()
to reduce compiler warnings.

Michael
2009-08-04 23:47:27 +02:00
Michael Adam b9f2325c54 check_acl(): add cast to recuce compiler warning (unsigned / signed comparison)
vector_lenth() returns < 0 if the vectore is NULL but this has been
checked before, so we can safely cast.

Michael
2009-08-04 23:47:27 +02:00
Michael Adam a34276feee change vector_prepend() to take size_t len instead of ssize_t len argument.
Michael
2009-08-04 23:47:27 +02:00
Michael Adam 67628dcc63 change vector_append() to take size_t len instead of ssize_t len argument
Michael
2009-08-04 23:47:27 +02:00
Michael Adam 590f99ef2d vector: change vectore_insert() to take size_t len instead of ssize_t len arg
Michael
2009-08-04 23:47:27 +02:00
Michael Adam c2c7245030 remove "discard const" compiler warnings with log_message().
Michael
2009-08-04 23:47:26 +02:00
Michael Adam c409e0f9d8 configure: Add more warnings to CFLAGS in debug mode
Michael
2009-08-04 23:47:26 +02:00
Michael Adam 04b19ac8b4 tinyproxy.conf: fix a comment typo
Michael
2009-08-04 01:36:22 +02:00
Mukund Sivaraman 9d971cb2d0 [BB#53] Add a GPLv2 COPYING file
Tinyproxy is distributed under the GNU GPLv2 or above license.
If autotools are used to build Tinyproxy without this file, they
copy the system installed COPYING file which is nowadays the
GNU GPLv3 license.
2009-08-04 04:21:46 +05:30
Michael Adam 1491483c35 tinyproxy.conf: kill some trailing spaces
Michael
2009-06-14 23:01:07 +02:00
Michael Adam 3ebb2ce607 autogen.sh: fix errors with new autotools.
The following errors occurred when running ./autogen.sh :

$ ./autogen.sh
+ aclocal
configure.ac:18: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
../../lib/autoconf/specific.m4:386: AC_USE_SYSTEM_EXTENSIONS is expanded from...
../../lib/autoconf/specific.m4:332: AC_GNU_SOURCE is expanded from...
configure.ac:18: the top level
configure.ac:18: warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
configure.ac:19: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
../../lib/autoconf/specific.m4:459: AC_MINIX is expanded from...
configure.ac:19: the top level
configure.ac:19: warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

and so on for autoheader and friends.
According to the autotools docs, the proper way to handle this
is to just call AC_USE_SYSTEM_EXTENSIONS.

Michael
2009-05-29 00:09:43 +02:00
Mukund Sivaraman 0b191f16fe Indenting change 2008-12-29 13:28:02 +00:00
Mukund Sivaraman 024b317de0 Convert tabs to spaces 2008-12-08 13:39:44 +00:00
Mukund Sivaraman 6e6f992f8c Update Tinyproxy website URL 2008-12-08 12:41:44 +00:00
Mukund Sivaraman 4c1ede779e Break at 80 columns 2008-12-08 12:26:08 +00:00
Mukund Sivaraman a257703e59 Reformat code to GNU coding style
This is a commit which simply ran all C source code files
through GNU indent. No other modifications were made.
2008-12-01 15:01:11 +00:00
Mukund Sivaraman 448c19077c Don't disable the creation of core files
Creation of core files can be disabled in the OS environment such
as by using the ulimit program.
2008-12-01 14:40:26 +00:00
Mukund Sivaraman a37a81db2d Update Tinyproxy website URLs 2008-10-16 18:21:16 +01:00
Mukund Sivaraman c15fc551da Tweak configure.ac a bit 2008-08-24 12:28:39 +05:30
Mukund Sivaraman 8c1beab96e Update the bugmail field 2008-08-24 12:16:08 +05:30
Mukund Sivaraman fadb98ee55 Add more calls to umask() before mkstemp() 2008-08-24 11:47:50 +05:30
Mukund Sivaraman 82cd6c765b Move buffer to the heap due to its size 2008-08-24 11:38:59 +05:30
Mukund Sivaraman fce253253a Set umask before mkstemp() for some versions of glibc 2008-08-24 11:27:38 +05:30
Mukund Sivaraman 62ddbd5e74 pos can never be less than 0 as it's of type size_t
Also fix the type which is passed in from various places.
2008-08-24 10:58:16 +05:30
Mukund Sivaraman 90c1bb4b73 Remove useless check as data can't be NULL at this point 2008-08-24 10:45:29 +05:30
Mukund Sivaraman 039273c134 Add whitespace 2008-07-30 18:56:15 +05:30
Mukund Sivaraman f613cec7ad Update the bug-report field 2008-07-30 18:53:55 +05:30
Mukund Sivaraman fc06880f81 Add missing comma 2008-07-14 18:20:43 +05:30
Mukund Sivaraman 7c1c547fc8 Change bug report address to email address in AC_INIT 2008-07-14 18:17:41 +05:30
Mukund Sivaraman aa95c34004 Allow numeric uid/gids in User and Group directives
This change allows numeric uid/gids to be specified in the User and
Group directives in tinyproxy.conf. Formerly, only username and group
names were accepted. This fixes bug #15, which was created after
looking at a case on the OpenWrt wiki.

X-Banu-Bugzilla-Ids: 15
2008-07-14 17:40:20 +05:30
Mukund Sivaraman 2fe213d777 Fix error variable names that stats.html expects 2008-07-14 17:14:12 +05:30
Mukund Sivaraman 7e5ac7c58a Fix a regression where empty error variables caused strlen() to crash
This fixes a regression (bug #16) introduced in
95c1f39f60, where a NULL check was
removed. This caused NULL error variable values to be sent to
add_error_variable() in which strlen() segfaulted.

With this fix, custom stats pages should be displayed properly.

X-Banu-Bugzilla-Ids: 16
2008-07-14 17:13:06 +05:30
Mukund Sivaraman 7bdd47d030 Make the embedded error message display valid XHTML too
Also fix the information that is displayed.
2008-07-14 15:47:00 +05:30
Mukund Sivaraman 7b9e178a76 Add version info in embedded stats page 2008-07-14 15:46:05 +05:30
Mukund Sivaraman 7f12f71f94 Add error number as a template parameter for error pages 2008-07-14 15:31:14 +05:30
Mukund Sivaraman 8b26558254 Make the embedded stats message display valid XHTML too 2008-07-14 15:09:02 +05:30
Mukund Sivaraman 74f5c3e417 Spruce up error page footers a bit 2008-07-14 15:02:41 +05:30
Mukund Sivaraman 4caa397ec5 Replace h2 with h1 for the main heading 2008-07-14 14:32:02 +05:30
Mukund Sivaraman 4f0b24ff9a Remove ltmain.sh from dist target 2008-07-14 14:30:32 +05:30
Mukund Sivaraman fea8dafe0c Remove title attribute 2008-07-14 14:28:17 +05:30
Mukund Sivaraman 922e0be574 Update error pages to valid XHTML format
Also change some text and how the messages are displayed,
to look better.
2008-07-14 11:58:19 +05:30
Mukund Sivaraman 7751efc218 Remove unused autoconf macro calls 2008-07-14 11:31:13 +05:30
Mukund Sivaraman 7bac0827f6 Fix tinyproxy homepage link 2008-06-20 12:42:18 +05:30
Mukund Sivaraman 1b99c216fe Remove Id tag from configure.ac 2008-06-19 21:36:46 +05:30
Mukund Sivaraman 20a7e61360 Removed obsolete ignore rules 2008-06-19 21:33:20 +05:30
Mukund Sivaraman 7dcb5f9061 Include values.h to use LONG_MAX and LONG_MIN 2008-06-17 13:44:42 +05:30
Robert James Kaes c8cf89a954 Add strtol conversion error checking
Moved the strtol() call into fill_netmask_array() and added additional
error checking to ensure that the strtol() call succeeded.

Error checking code taken from strtol() manpage.

Signed-off-by: Robert James Kaes <rjk@wormbytes.ca>
2008-06-17 13:32:20 +05:30
Robert James Kaes 51fb15be2c Refactored netmask array fill with range check
When building a numeric ACL with netmask, range check the supplied
value.  In addition, the code to walk the array has been extracted and
"simplified".

Signed-off-by: Robert James Kaes <rjk@wormbytes.ca>
2008-06-17 13:31:04 +05:30
Mukund Sivaraman 95c1f39f60 Don't check the value to be inserted as it's already checked
This change primarily avoids a gcc warning where timebuf
is never non-NULL. There is no need to check the value to be
inserted as it's checked inside hashmap_insert().

This changeset also lets error return values from hashmap_insert()
propogate instead of clamping them to -1 (not that these are
currently used anyway).
2008-06-10 09:51:23 +05:30
Robert James Kaes 5ea289d82e Moved transparent proxy code into its own file
Extracted the transparent proxy logic from reqs.c and placed it into a
separate file.

Signed-off-by: Robert James Kaes <rjk@wormbytes.ca>
2008-06-09 10:01:14 +05:30
Mukund Sivaraman 445e4cb09c Change tinyproxy Bugzilla component to product 2008-06-04 09:45:50 +05:30
Robert James Kaes b092de72f8 Ignore profiling generated files
The *.pcno files are generated as part of the profiling code.

Signed-off-by: Robert James Kaes <rjk@wormbytes.ca>
2008-06-03 21:51:02 +05:30
Mukund Sivaraman 8938b9cd86 Another minor README update 2008-05-24 16:49:32 +05:30
Mukund Sivaraman 2038d4ca8c Updated README 2008-05-24 16:48:45 +05:30
Mukund Sivaraman e7ecb1dabb Added .gitignore entries 2008-05-24 16:35:46 +05:30
Mukund Sivaraman 8949675e5d Updated toplevel Makefile.am to reflect recent automake changes 2008-05-24 16:34:15 +05:30
Mukund Sivaraman cc1f04ecba Updated copyright header in Makefile.am 2008-05-24 16:24:12 +05:30
Mukund Sivaraman 6f9ee262e5 Removed unnecessary LDFLAGS variable 2008-05-24 16:21:29 +05:30
Mukund Sivaraman 06a08b28de Quoted TP_ARG_ENABLE 2008-05-24 16:19:42 +05:30
Mukund Sivaraman 20ad96495c configure.ac changes 2008-05-24 16:17:29 +05:30
Mukund Sivaraman 868a4561fe Restructured automake macros 2008-05-24 16:13:40 +05:30
Mukund Sivaraman b0a3568de0 Renamed htmlerror.[ch] to html-error.[ch] 2008-05-24 13:47:14 +05:30
Mukund Sivaraman 249d4b7f33 Updated copyright, license notices in source code
The notices have been changed to a more GNU look. Documentation
comments have been separated from the copyright header. I've tried to
keep all copyright notices intact. Some author contact details have
been updated.
2008-05-24 13:35:49 +05:30
Mukund Sivaraman b441485b5e Fixed links in spec file 2008-05-05 16:22:30 +05:30
Mukund Sivaraman eb7c535d4e Updated .gitignore files 2008-05-03 13:21:54 +05:30
Jeremy Hinegardner fa7ecaca6d Sync Fedora initscript and specfile 2008-05-01 19:47:58 +05:30
Mukund Sivaraman b110332ed3 Free arg before returning, or it'll leak 2008-03-30 17:56:45 -07:00
Mukund Sivaraman ff72f5426e Free entry_buffer or it'll be leaked
vector_append() calls vector_insert() which makes a copy
of the passed buffer, so the caller can free its buffer.
2008-03-30 17:51:51 -07:00
Mukund Sivaraman 12501d599c Fixed leaks of va_lists 2008-03-30 17:43:32 -07:00
Mukund Sivaraman bd8f8807ff Generate RPM spec file from .spec.in file 2008-03-30 17:18:58 -07:00
Mukund Sivaraman 6a6a3b0409 Added Makefile.am in packaging dirs 2008-03-30 17:12:26 -07:00
Mukund Sivaraman e6d9bb2150 Removed old RPM packaging files 2008-03-30 17:01:29 -07:00
Jeremy Hinegardner 14edbda9f0 Added Fedora packaging files 2008-03-30 16:59:11 -07:00
Mukund Sivaraman e229b36083 Moved RPM packaging dir to top-level 2008-03-30 16:48:47 -07:00
Mukund Sivaraman d9c41d4e4d Removed obsolete packaging patch file 2008-03-30 16:41:10 -07:00
Mukund Sivaraman 13cf5ae0d5 Do not allow anyone except localhost by default 2008-03-30 16:39:35 -07:00
Mukund Sivaraman d0ae798f71 Made the default group nobody 2008-03-30 16:38:44 -07:00
Mukund Sivaraman 44d91bdf6b Removed obsolete lexer/parser files 2008-03-30 16:33:08 -07:00
Andrew Stribblehill fdf7e4ea8b Added more patterns to .gitignore 2008-03-19 15:11:13 -07:00
Mukund Sivaraman b11c74637f Fixed format string warnings 2008-03-13 15:09:30 -07:00
Mukund Sivaraman fc62283164 Removed the clean target from the src directory
This was overriding the automake clean target to clean up
files like *.o by default.
2008-03-13 15:09:26 -07:00
Mukund Sivaraman 8848b647d7 Corrected datatype of salen to fix compiler warning 2008-03-13 15:09:21 -07:00
Mukund Sivaraman 0ac647ab98 Added missing ltmain.sh 2008-03-13 15:09:09 -07:00
Mukund Sivaraman 2db8c8f2d1 Added empty NEWS file that's required by autotools now 2008-03-13 15:07:47 -07:00
Mukund Sivaraman 31766cce90 Renamed file to replace underscores in it with dashes 2008-03-13 15:07:43 -07:00
Mukund Sivaraman d5472ec0bd Renamed file to replace underscores in it with dashes 2008-03-13 15:07:37 -07:00
Mukund Sivaraman 376caf8f25 Renamed .cvsignore to .gitignore 2008-03-13 15:07:29 -07:00
Mukund Sivaraman e2ef2479d8 Renamed bootstrap to autogen.sh 2008-03-13 15:07:15 -07:00
Robert James Kaes 2f5118046d Added support for UPSTREAM directive.
Included the basic grammar and handler functions for the "upstream" and
"no upstream" directives.  I still need to update the grammar to match
_all_ the possibilities documented in the tinyproxy.conf file, but at
least it now does as much as the old config parser.
2005-11-04 05:15:47 +00:00
Robert James Kaes 72e1731092 Reformatted the reverse and filter configuration blocks. If either
section is not enabled at compile time, it should not be included in the
object file.
2005-11-04 01:31:41 +00:00
Robert James Kaes ffec04c65e Fixed up whitespace formatting of the config file directives. Also
added blank lines to group related directives.
2005-11-04 00:47:07 +00:00
Robert James Kaes bed712ffa7 Added the typecheck.m4 macro file to improve type checking support in
the configure.ac script.  The various typedefs are checked in a larger
collection of locations.
2005-08-16 14:22:39 +00:00
Robert James Kaes 4c58663041 * [Refactor] Moved Reverse Proxy Code
Moved the reverse proxy code from reqs.c into it's own files
(reverse_proxy.c).  The code in reqs.c is way too complicated, so I
want to move unrelated code into their own files to simplify the main
concepts in reqs.c.
2005-08-16 04:03:19 +00:00
Robert James Kaes 808bdbd1e9 * [Indent] Fixed typedef Formatting
Added the list of tinyproxy typedefs to the indent command to have them
formatted correctly as well.
2005-08-15 18:35:09 +00:00
Robert James Kaes c0299e1868 * [Indent] Ran Source Through indent
I re-indented the source code using indent with the following options:

indent -kr -bad -bap -nut -i8 -l80 -psl -sob -ss -ncs

There are now _no_ tabs in the source files, and all indentation is
eight spaces.  Lines are 80 characters long, and the procedure type is
on it's own line.  Read the indent manual for more information about
what each option means.
2005-08-15 03:54:31 +00:00
Robert James Kaes 38f0b3a103 * Specified Correct typedef in getsock_ip()
Changed the variable type for the namelen variable to the correct
socklen_t type.  The configure script already checked for it, but for
some reason I never got around to actually using it in this function.
2005-07-12 20:34:26 +00:00
Robert James Kaes a59117c7ca * Updated Copyright Email Addresses
Updated the copyright email addresses for Robert James Kaes.  The
users.sourceforge.net address should always exist.
2005-07-12 17:39:44 +00:00
Robert James Kaes 6042483a0e Removed the proxy-* headers from the list of headers to skip. Since
tinyproxy does not prompt for any proxy information from the client, it
should not be eating the proxy headers.  They are most likely needed by
an upstream proxy.
2005-07-06 21:44:08 +00:00
Robert James Kaes 51096e2944 * [1118363] Proxy reverse order of headers
Changed the internal implementation of the hashmap to maintain the
  insert order if the same key is repeated.  The insertion is still
  constant since we keep track of the head and tail of the bucket
  chain.
2005-05-03 20:34:54 +00:00
Robert James Kaes bf172f9242 Replaced all the AC_ARG_ENABLE calls with calls to our own
TP_ARG_ENABLE macro.  Except for the transparent proxy option, all the
other options remain identical.  To enable transparent proxy support
use only --enable-transparent, rather than the old
--enable-transparent-proxy.
2004-08-24 18:43:17 +00:00
Robert James Kaes 7e91fdd975 Added config/argenable.m4 to the list of configuration files needed by
the autoconf system.
2004-08-24 18:41:18 +00:00
Robert James Kaes 7af47907be Initial checkin of the TP_ARG_ENABLE macro. This macro extends the
default AC_ARG_ENABLE macro to do better error checking of the input
values.
2004-08-24 18:40:21 +00:00
Robert James Kaes ab270dc35c Moved the autoconf/automake configuration files into the config
directory, so inform autoconf of this (the AC_CONFIG_AUX_DIR and
AC_CONFIG_MACRO_DIR macros.)

Also added a bunch of portability tests discovered by autoscan.
2004-08-24 16:41:11 +00:00
Robert James Kaes c3b2bf38e2 Moved all the autoconf/automake configuration information into the
config directory.
2004-08-24 16:39:29 +00:00
Robert James Kaes 893aed8eef Removed the "releases.txt" file from the distribution. It didn't
really add anything, so there's no point in having it.
2004-08-24 16:38:42 +00:00
Robert James Kaes 019b91c3f9 (takesig): Fixed the return type to use the autoconf defined
RETSIGTYPE.  This is portable, while simply using "void" is not.
2004-08-24 16:36:22 +00:00
Robert James Kaes c446e19003 Added code to handle HTTP/0.9 simple GET requests. 2004-08-24 16:35:27 +00:00
Robert James Kaes 79d40a536a (get_bool_arg): Moved the initialization of "p" _before_ the assert()
calls.  The code doesn't compile under gcc 2.95 otherwise.  (I'm
surprised it compiles under gcc 3.3 without a problem.)
2004-08-24 16:34:22 +00:00
Robert James Kaes 35196f7d8e Changed some of the variable types so that the code compiles cleanly
on other operating systems.  (Used cf.sourceforge.net as the test
system for cross compiling.)
2004-08-24 16:33:00 +00:00
Robert James Kaes d41260fe2d Fixed up the acl_s structure so that it compiles correctly under
gcc 2.95.
2004-08-24 16:31:45 +00:00
Robert James Kaes 337af524dd Bootstrap the autoconf system 2004-08-20 19:56:05 +00:00
Robert James Kaes 7b0f1fe562 Moved the configuration information into it's own directory to avoid
cluttering up the root directory.
2004-08-20 16:01:31 +00:00
Robert James Kaes 93fbb5ff49 Changed the calls to the config_compile() and config_parse()
functions.  Also, if the "logfile" directive is used, it will now
override use of the syslog system.  Added an error message if neither
is defined.
2004-08-14 03:21:28 +00:00
Robert James Kaes 5c02939533 (log_message): Added a fsync() call after each line outputted to the
log file.
2004-08-14 03:20:01 +00:00
Robert James Kaes c5307363be Reorganized the source code. Added the missing reverse proxy
directives.  Added a bunch of comments to clarify how the code works.
2004-08-14 03:18:41 +00:00
Robert James Kaes 9f4323a562 Removed the last code relating to the old configuration parsing
system.  The grammar.y and scanner.l files still need to be removed.
2004-08-14 00:37:51 +00:00
Robert James Kaes 52562b49df Removed the grammar.y and scanner.l files from the list of files
required by tinyproxy.
2004-08-13 21:04:24 +00:00
Robert James Kaes febb521bfd Added some error logging information for directives that are
conditionally compiled.  Still need to add info messages for the
directives.
2004-08-13 21:03:58 +00:00
Robert James Kaes 1d2e4fc2c3 Change the code to use the new config_parse() method rather than the
flex/bison based configuration system.
2004-08-13 21:03:11 +00:00
Robert James Kaes 9d04667848 Added the new configuration parsing system (conffile.c and
conffile.h.)  The new system is intended to replace the existing
grammar.y and scanner.l files.  I don't want to depend on flex/bison
any longer.
2004-08-13 20:19:50 +00:00
Robert James Kaes b3943c21f2 (check_allowed_connect_ports): By default DENY any CONNECT requests
unless explicitly allowed by a configuration directive.
2004-08-12 20:15:04 +00:00
Robert James Kaes 28dd133623 (add_xtinyproxy_header): Removed the runtime error checking of the
connptr->server_fd variable and moved it into an assert since we
should never be called with invalid data.  Also made the function an
inline function since it's only called in one place.
2004-08-12 19:57:15 +00:00
Robert James Kaes 924da17c17 Completely rewrote the ACL functionality. The new system is intended
to handle IPv6 style addresses along with the existing IPv4 and string
addresses.  In addition, the hand-rolled "list" code has been replaced
with a vector (code reuse.)  Also, the code should be a little easier
to understand (relatively speaking.)

I do need to add some kind of testing framework (in general) to check
that the new code does work with all the formats that will be thrown
at it.
2004-08-11 20:09:20 +00:00
Robert James Kaes fd4b67bbb4 (strip_username_password): Removed one of the pointer variables since
it's no longer needed.  Reorganized the function to make it more
obvious what was actually being done.
2004-08-11 02:49:05 +00:00
Robert James Kaes badc7673d0 Merged in changes from 1.6.3 2004-08-10 21:24:24 +00:00
Robert James Kaes 18df4910a4 Added the "BindSame" configure directive from Oswald Buddenhagen.
This allows tinyproxy to respond to a request bound to the same
interface that the request came in on.  As Oswald explains:

  "attached is a patch that adds the BindSame option. it causes
  binding an outgoing connection to the ip address of the respective
  incoming connection. that way one can simulate an entire proxy farm
  with a single instance of tinyproxy on a multi-homed machine."

Cool.
2004-04-27 18:53:14 +00:00
Robert James Kaes 3b961ec66b (init_stats): Fixed a memset bug, where the structure was not cleared
properly.  (The sizeof "struct stat" was being used rather than the
proper "struct stat_s".  On my system, "struct stat" is 88 bytes long,
while "struct stat_s" is 20 bytes long.  Quite a difference!)
2004-04-27 18:48:53 +00:00
Robert James Kaes 095d0d0142 These files list all the other files that CVS should ignore. It makes
looking at the CVS status information a little cleaner.
2004-04-27 18:28:45 +00:00
Robert James Kaes 5ecd9157ce Converted the various socket functions to work with both IPv4 and IPv6
addresses.
2004-02-18 20:18:53 +00:00
Robert James Kaes c21df1ea0f Added two functions:
- get_ip_string() converts a binary network address into either a
   dotted-decimal IPv4 address, or a IPv6 hex-string
 - full_inet_pton() converts a numeric character string into an IPv6
   network address (binary form).  It's like the system inet_pton()
   function, but it will work with bot IPv4 and IPv6 character
   strings.

These functions are required for the conversion to Internet protocol
independence.  (Or to put it more clearly: allow tinyproxy to work in
an IPv6 network.)
2004-02-18 20:17:18 +00:00
Robert James Kaes 02893c3489 Rewrote the "early history" of the project, and added a section for
"major" addition authors.
2004-02-17 19:49:54 +00:00
Robert James Kaes aee5a63849 Removed unnecessary casts (mostly dealing with memory allocation.) I
should never have added them in the first place.  They don't really
buy anything, and they can hide bugs.
2004-02-13 21:27:42 +00:00
Robert James Kaes bf22966f55 (strip_return_port): Patch from "alex" to strip the port from the host
string and return the port.  I cleaned up and added error handling to
the code, but it's basically "alex"'s fix.

(extract_http_url): Rewrote this function to remove all the sscanf()
calls.  It's much easier to just split on the path slash (if it's
present) and then strip the user name/password and port from the host
string.  Less code, handles more cases!
2004-02-04 19:57:40 +00:00
Robert James Kaes 47df93b8f3 # Updated change log 2004-01-26 19:19:31 +00:00
Robert James Kaes 0a8e4e4d8d Added reverse proxy support from Kim Holviala. His comments regarding
this addition follow:

  The patch implements a simple reverse proxy (with one funky extra
  feature). It has all the regular features: mapping remote servers to local
  namespace (ReversePath), disabling forward proxying (ReverseOnly) and HTTP
  redirect rewriting (ReverseBaseURL).

  The funky feature is this: You map Google to /google/ and the Google front
  page opens up fine. Type in stuff and click "Google Search" and you'll get
  an error from tinyproxy. Reason for this is that Google's form submits to
  "/search" which unfortunately bypasses our /google/ mapping (if they'd
  submit to "search" without the slash it would have worked ok). Turn on
  ReverseMagic and it starts working....

  ReverseMagic "hijacks" one cookie which it sends to the client browser.
  This cookie contains the current reverse proxy path mapping (in the above
  case /google/) so that even if the site uses absolute links the reverse
  proxy still knows where to map the request.

  And yes, it works. No, I've never seen this done before - I couldn't find
  _any_ working OSS reverse proxies, and the commercial ones I've seen try
  to parse the page and fix all links (in the above case changing "/search"
  to "/google/search"). The problem with modifying the html is that it might
  not be parsable (very common) or it might be encoded so that the proxy
  can't read it (mod_gzip or likes).

  Hope you like that patch. One caveat - I haven't coded with C in like
  three years so my code might be a bit messy.... There shouldn't be any
  security problems thou, but you never know. I did all the stuff out of my
  memory without reading any RFC's, but I tested everything with Moz, Konq,
  IE6, Links and Lynx and they all worked fine.
2004-01-26 19:11:52 +00:00
Robert James Kaes f2d846d057 Merged in changes from the 1.6.2 release. (Fixes for the filtering code
and the HTML installation script.)
2003-10-17 16:11:00 +00:00
Robert James Kaes 27d93b1f08 Merged in missing $(DESTDIR) in tinyproxy-html-files rules bug fix
from the stable branch.
2003-08-14 15:16:50 +00:00
Robert James Kaes a13ca8271e Incorporated patches from Marc Silver to improve the readability and
understandability of the documentation.
2003-08-07 16:50:55 +00:00
Robert James Kaes d2098f638f tinyproxy no longer includes a fall-back regular expression library,
so these files needed to be modified to only use the system's
installed regular expression library.
2003-08-07 16:32:12 +00:00
Robert James Kaes d72fa83245 Removed the included regular expression library, since it should come
standard on any reasonably modern system.
2003-08-07 16:29:54 +00:00
Robert James Kaes 7eb4eba381 # Merged in changes from the stable 1.6 branch. 2003-08-07 15:31:20 +00:00
Robert James Kaes 630b99334c Patch from Marc Silver to improve the readability and accuracy of the
tinyproxy man page.
2003-08-05 21:14:43 +00:00
Robert James Kaes fd23cd4aed # Fixed a comment to actually reflect what the function does. 2003-08-05 16:11:59 +00:00
Robert James Kaes 26ad896676 Added the cookie header to the documented list of headers to allow
through.
2003-08-05 16:11:06 +00:00
Robert James Kaes a117ed9cb0 Included patches from Steven Young to use the hashmap functionality to
manage the HTML error pages.  It simplifies the source, and also make
the object file smaller.  Nice.  Also added any casting from (void*)
to ensure that the code compiles using a C++ compiler.
2003-08-01 00:14:34 +00:00
Robert James Kaes 15870a9582 Added appropriate casts (void*) casts to allow the code to compile
cleanly using a C++ compiler.

Changed the servers_waiting variable to an unsigned int, since the
number of servers waiting can never be negative, and added an assert()
to ensure this invariant.
2003-07-31 23:44:52 +00:00
Robert James Kaes bc77dfb492 (debugging_realloc): Removed the assert for the NULL pointer, since
realloc() can take a NULL pointer, as defined by the realloc() man
page.

Fixed the cast in both safefree() macros to compile cleaning using a
C++ compiler.
2003-07-31 23:42:51 +00:00
Robert James Kaes 5a2af49e58 Fixed the cast in both safefree() macros to compile cleaning using a
C++ compiler.
2003-07-31 23:41:26 +00:00
Robert James Kaes 8a6a94db0a # Fixed a preprocessor test (misspelled __cplusplus) 2003-07-31 23:40:16 +00:00
Robert James Kaes 6aaa863432 Added appropriate casts from (void*) so that the code will compile
cleanly with a C++ compiler.  (Tested using GCC 3.3)
2003-07-31 23:38:28 +00:00
Robert James Kaes ab02f47a29 # Bumped up the version number because of a maintenance release (to fix
a problem with the scanner.c file.
2003-07-24 15:13:00 +00:00
Robert James Kaes 7115a37f23 # Updated ChangeLog 2003-07-14 17:45:11 +00:00
Robert James Kaes a748265b50 # Bumped up version number. 2003-07-14 17:43:26 +00:00
Robert James Kaes 7c96935552 (indicate_http_error): Added calls to va_end() before leaving the
function.
2003-07-14 17:42:43 +00:00
Robert James Kaes 09aa3d6409 # Updated the ChangeLog 2003-06-26 18:33:13 +00:00
Robert James Kaes 717be92385 # Bumped up the version number and made sure to only add the debugging
flags to flex if it really is flex.
2003-06-26 18:31:16 +00:00
Robert James Kaes a4cd3eb9ec # Removed the debugging information. 2003-06-26 18:26:10 +00:00
Robert James Kaes a8798e999b # Added debugging flags for the flex scanner. 2003-06-26 18:23:01 +00:00
Robert James Kaes 1cb032a934 (upstream_add): Rewrote the function to actually handle the various
types of upstream configurations correctly.  Hopefully, the code is
also a little clearer in it's implementation.
2003-06-26 18:19:57 +00:00
Robert James Kaes 988f243286 # Removed the STRING_ADDRESS token since it was conflicting with the
IDENTIFIER directive and also the keyword directives.
2003-06-26 18:17:09 +00:00
Robert James Kaes db142b6e23 Modified the patterns to allow the new upstream directives to work as
defined in the tinyproxy.conf documentation.
2003-06-26 18:16:09 +00:00
Robert James Kaes 2736a19518 (debugging_free): Rather than assert on a NULL pointer, log the NULL
pointer and return.
2003-06-26 18:14:13 +00:00
Robert James Kaes 93ac7d8824 # Bumped up the version number. 2003-06-25 18:23:11 +00:00
Robert James Kaes 61a6ca82db # Updated the changelog 2003-06-25 18:22:37 +00:00
Robert James Kaes ddcac5ae09 Added a test to define INADDR_NONE if it's not present. For example,
SunOS (solaris 2.8) does not include this define.  [Thank to Ben
Hartshorne for pointing this out.]
2003-06-25 18:20:22 +00:00
Robert James Kaes d2f5f5c564 Changed the calls to "ps" and "grep" to use a more portable syntax. 2003-06-25 18:18:19 +00:00
Robert James Kaes 66fc80e922 # Bumped up the version number. 2003-06-23 21:15:04 +00:00
Robert James Kaes 8b8d3b1477 # Added a bit more description to describe where to look for the error
HTML files.  In the future the installation script should modify the
  tinyproxy.conf file.
2003-06-23 21:14:32 +00:00
Robert James Kaes 5ba1325ef5 # Updated ChangeLog 2003-06-20 18:01:26 +00:00
Robert James Kaes 4c9141aac6 Removed the "ViaHeader" directive and replaced it with the
"ViaProxyName" directive.  The "Via" HTTP header is _required_ by the
HTTP spec, so the code has been changed to always send the header.
However, including the proxy's host name could be considered a
security threat, so the "ViaProxyName" directive is used to set the
token sent in the "Via" header.  If the directive is not enabled the
proxy's host name will be used.
2003-06-20 17:02:13 +00:00
Robert James Kaes 0d3962f1f0 # Removed the HTML error suggestion since it's been implemented with
Steven Young's patches.  Added a suggestion for user authentication.
2003-06-19 16:45:58 +00:00
Robert James Kaes b081019d5a (connect_to_upstream): Fixed an off-by-one error in the snprintf()
call used to build the URL for the upstream proxy. [Patch suggested by
David T. Pierso]
2003-06-06 16:14:50 +00:00
Robert James Kaes c2240df616 Remove the -O2 optimization if debugging is enabled. Also, remove the
-g option if the code does _not_ have debugging enabled.
2003-06-02 21:57:14 +00:00
Robert James Kaes 7f8e4647f7 Included additional examples of how to configure the upstream proxy
support for more selective proxying.
2003-06-02 21:56:00 +00:00
Robert James Kaes 91e082671a (upstream_get):
(upstream_add): Added support to allow ip addresses and networks to be
used when matching an upstream proxy directive.
[Code by Peter da Silva]
2003-06-02 21:55:14 +00:00
Robert James Kaes ea50171a95 Changed the safefree() macro to make it safe to use a conditional
statement, and also safe to use with a rvalue that has a side
effect.  [Bug fix recommended by Peter da Silva]
2003-05-31 23:04:15 +00:00
Robert James Kaes 77ca1c8ce0 # Changed all the for calls to use the != test rather than < test.
The change was recommended in the C/C++ User Journal magazine.
2003-05-31 23:02:21 +00:00
Robert James Kaes 86c9d69086 # Updated ChangeLog 2003-05-30 16:27:57 +00:00
Robert James Kaes 983a76ecef # Bumped up the version number 2003-05-30 16:25:41 +00:00
Robert James Kaes af5e1e29f6 # Changed the calls to vector_getentry() to use the new calling
convention.
2003-05-30 16:22:30 +00:00
Robert James Kaes 1955dcd47b (vector_getentry): Changed the API to return the data pointer and have
the length returned in a argument variable pointer.  This should be a
more natural way of using the function.
2003-05-30 16:21:48 +00:00
Robert James Kaes c3eaebd1c5 # Added a vector_prepend() function and recoded the old vector_insert()
to be a general "insert" for both vector_append() and vector_prepend()
2003-05-29 21:07:22 +00:00
Robert James Kaes 8ab278998f # Renamed the vector_insert() calls to vector_append() 2003-05-29 20:48:25 +00:00
Robert James Kaes 42f9f37afc (vector_append): Renamed the vector_insert() function to more
accurately indicate that entries are appended to the end of the
vector.
2003-05-29 20:47:52 +00:00
Robert James Kaes 4a377a712d Improved the upstream proxy support by making the upstream proxy
server configurable based on the destination host.  [Code written by
Peter da Silva]
2003-05-29 19:44:00 +00:00
Robert James Kaes 2e9f27769d Added support for installing the HTML error files used by tinyproxy. 2003-05-10 23:16:45 +00:00
Robert James Kaes 5e1303ecd1 (establish_http_connection): If the port being requested is not a
standard HTTP port (80 or 443) append the port string to the host
header; otherwise, leave the host string with only the host's domain
name.

Replaced all occurrences of constant 80 and 443 with defines HTTP_PORT
and HTTP_PORT_SSL.
2003-05-05 16:46:05 +00:00
Robert James Kaes ac88af1f71 Fixed a bug that would kill a child process because of an invalid
safefree() call.  Basically, destroy_conn() was trying to free memory
not allocated by malloc.  [Fix by David T. Pierson]
2003-05-04 04:35:10 +00:00
Robert James Kaes 65115c75c8 # Updated change log 2003-04-16 18:14:16 +00:00
Robert James Kaes 4a66257e65 # Updated version number 2003-04-16 18:12:45 +00:00
Robert James Kaes c94bfa8223 (build_url): Rebuild the URL from the component pieces. This function
is used by the transparent proxy code.  [Anatole Shaw]
(process_request): Fixed up the transparent proxy code so that
filtering can be done on the whole URL.  [Anatole Shaw]

(pull_client_data): Added a bug fix for Internet Explorer (IE).  IE
will leave an extra CR and LF after the data in an HTTP POST.  The new
code will eat the extra bytes if they're present.  Thanks to Yannick
Koehler for finding the bug and offering an explanation as to why it
was happening.

Changed all calls of connptr->remote_content_length to
connptr->content_length.server
2003-04-16 18:11:58 +00:00
Robert James Kaes 648e8f1438 # Changed it again to this time use the TINYPROXY_DEBUG environment
variable to determine whether to wait for a connection from GDB.
2003-04-16 18:04:58 +00:00
Robert James Kaes 4a942bc59a # The programmer is now made to _explicitly_ enable the GDB support in
the child handling function.
2003-04-16 16:39:23 +00:00
Robert James Kaes 6ff4192069 Removed the remote_content_length field in the "conn" structure and
replaced it with a smaller structure containing both the remote/server
and the local/client content-length fields if they're present in the
HTTP response headers.
2003-04-16 16:37:59 +00:00
Robert James Kaes acece1ee67 # Updated change log (should have done this _before_ the tagging of course.) 2003-04-01 16:56:41 +00:00
Robert James Kaes 82ce7176f7 Removed duplicate header tests. 2003-04-01 16:50:41 +00:00
Robert James Kaes 5f8a497f0c Reorganized some of the code, and remove some function tests for which
results were never used.
2003-04-01 16:46:45 +00:00
Robert James Kaes bcf25dc67e (add_error_variable): Test whether connptr->error_variable is NULL,
and if so call safemalloc().  This is needed since saferealloc() will
assert() if the first argument is a NULL pointer.
2003-04-01 16:41:33 +00:00
Robert James Kaes 7cd19206cc (establish_http_connection): Always include the port number for the
requested server.  This fixes a problem when the server is not
listening on the default port, 80.
[Fix suggested by duncan@sapio.co.uk]
2003-03-26 16:47:30 +00:00
Robert James Kaes 63a7914830 # Moved the location of the "initializing" log message to below the
processing of the command line options.
2003-03-17 04:24:19 +00:00
Robert James Kaes 89ede8cd28 Create the doc/report.sh script from the new template file. 2003-03-17 04:21:11 +00:00
Robert James Kaes 232aea721c Moved the doc/report.sh script to doc/report.sh.tmpl file. The script
is then updated by the make procedure to reflect the correct location
of the tinyproxy executable.
2003-03-17 04:20:19 +00:00
Robert James Kaes d2c9ffac23 Made get_html_file() and lookup_variable() static functions since they
are only used with this file.
2003-03-14 22:49:03 +00:00
Robert James Kaes 5faa0879ec # Added copyright notices for Steve. Reformatted the source code to
better match the existing tinyproxy practise.  Included a few bug
  fixes from Steve.
2003-03-14 22:45:59 +00:00
Robert James Kaes cc90414b29 (send_http_message): Changed the function to use the new http_message
API.
2003-03-14 06:15:27 +00:00
Robert James Kaes c76183a3f0 # Updated all the calls to indicate_http_error() to include a
terminating NULL.  The va_arg() function requires it to work
  properly.
2003-03-14 06:13:04 +00:00
Robert James Kaes aff52c552e # Include the HTML variable substitution documentation files with the
tarball.
2003-03-13 22:38:09 +00:00
Robert James Kaes 1763373f29 # Updated ChangeLog with Steven Young's log of changes to include the
variable substitution code.
2003-03-13 22:03:24 +00:00
Robert James Kaes 75dd0b22c4 Allow the URL for the statistic page to be controlled from the
configuration file, rather than being hard-coded in the program.
[John M Wright]
2003-03-13 21:42:46 +00:00
Robert James Kaes fa1480a3e1 Include example information for the new "file" directives (ErrorFile,
DefaultErrorFile, StatFile.)  [Steven Young]
2003-03-13 21:38:00 +00:00
Robert James Kaes 78c1ed384a # Added default HTML files for HTTP error messages and the stats
page. [Steven Young]
2003-03-13 21:35:58 +00:00
Robert James Kaes a46bfdc2e0 Moved the send_http_error_message() and indicate_http_error()
functions into the htmlerror.c file, and recoded them to use the new
variable substitution system. [Steven Young]
2003-03-13 21:34:38 +00:00
Robert James Kaes badd237fe6 # Added variables to config structure to keep track of the files to be
displayed for various HTTP errors and the stats page. [Steven Young]
2003-03-13 21:32:33 +00:00
Robert James Kaes b06f26cba1 # Changed showstats() to use the HTML variable functions when
possible.  It still retains the hard-coded page for when an HTML file
  is not available. [Steven Young]
2003-03-13 21:31:03 +00:00
Robert James Kaes cb8aaf521e # Changed calls to indicate_http_error() to use the new HTML variable
substitution mechanism. [Steven Young]
2003-03-13 21:29:45 +00:00
Robert James Kaes 7995027c8c # Added parser support for the error file configuration keywords
(ErrorFile, DefaultErrorFile, StatFile) [Steven Young]
2003-03-13 21:28:37 +00:00
Robert James Kaes 056bbf84bd # Added variables to keep track of the variables to be substituted in
.html files displayed to the client [Steven Young]
2003-03-13 21:27:29 +00:00
Robert James Kaes a830af5097 # Steve Young's code to implement file based HTML error messages,
rather than the hard coded string.
2003-03-13 21:25:06 +00:00
Robert James Kaes d28d9fb195 # Added htmlerror.c and htmlerror.h 2003-03-13 21:23:01 +00:00
Robert James Kaes 2057ffdb50 # Changed the wording of the header comment to remove the reference to
"dnsserver"
2003-03-13 19:31:09 +00:00
Robert James Kaes 99ec965544 # (child_main): If this is a debugging build output the child process
ID and wait for 10 seconds so we have time to connect gdb to the
  child.  This is needed if we want to use gdb against the child
  process.
2003-03-13 19:30:19 +00:00
Robert James Kaes 0a3a1d7c71 Fixed up the include order for the <sys/time.h> and <time.h> headers. 2003-03-13 16:56:28 +00:00
Robert James Kaes e04ff12768 # Include the http_message.[ch] into the compiled tinyproxy object. 2003-03-13 05:28:46 +00:00
Robert James Kaes 686826c3b0 An API to handle HTTP messages as concrete entities. 2003-03-13 05:25:30 +00:00
Robert James Kaes 2f9370afe7 (chomp): Fixed up the code to prevent negative array access. Added
code to make sure the supplied arguments are valid.
2003-03-13 05:20:06 +00:00
Robert James Kaes d98e5352c2 # Updated ChangeLog 2003-03-10 20:15:43 +00:00
Robert James Kaes 146998ee2b # Bumped up the version number and added AC_PROG_LIBTOOL to the list
of programs searched for by configure.  This is needed since libtool
  is now a separate program from automake.
2003-03-10 20:07:55 +00:00
Robert James Kaes 069700db50 # Added support for including source packaging files 2003-03-10 20:04:52 +00:00
Robert James Kaes dbe4a508c8 Added the files required for creating tinyproxy RPMs for Redhat based
systems.
2003-03-08 20:03:37 +00:00
Robert James Kaes 20d3008c38 (main): Removed duplicate code calling the filter_destroy() function.
Once is enough.  [Detected by John M Wright]
2003-02-26 22:37:38 +00:00
Robert James Kaes 1155be1c15 # Fixed up some formatting to make sure the line is less than 80
characters long
2003-02-21 17:09:24 +00:00
Robert James Kaes 40c4d3c57a # (connect_to_upstream): Improved the preprocessor directives to make
sure the function would compile cleanly regardless of how the
  directive was set.
2003-01-28 21:21:55 +00:00
Robert James Kaes 8f43cd72ad # Updated changelog 2003-01-27 18:52:24 +00:00
Robert James Kaes 2f98fec1aa # Style clean up. 2003-01-27 18:45:25 +00:00
Robert James Kaes abbf826445 (display_usage): Removed the output line mentioning that regular
expression support was included.  It will be there always.
2003-01-27 18:44:43 +00:00
Robert James Kaes 2fc9c76969 (connect_to_upstream): Reorganized the preprocessor directives to make
sure the function's symbol name is stored, even if upstream was not
compiled it.  This should keep some compilers from reporting errors.
2003-01-27 18:42:18 +00:00
Robert James Kaes cb7e3eef04 Added support for conditionally using case sensitive filtering files.
Code changes from James E. Flemer.
2003-01-27 17:57:45 +00:00
Robert James Kaes 1624979f13 Moved the AH_TEMPLATE() macro for the GNU regex library to out from
inside an if...fi test.  Thanks to James E. Flemer for supplying a
patch.

Bumped up the version number.
2003-01-27 17:48:26 +00:00
Robert James Kaes ba02bd7567 # Grammar fix up. Thanks to James E. Flemer for pointing it out. 2003-01-27 17:42:50 +00:00
Robert James Kaes c33d934a59 Changed the default manual section to section 8 (administrator
commands).
2003-01-27 17:41:52 +00:00
Robert James Kaes 212abd64d7 (process_client_headers): Fixed inverted anonymous header logic. Fix
comes from the FreeBSD port through James E. Flemer.
2003-01-27 17:39:02 +00:00
104 changed files with 9250 additions and 9675 deletions

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
INSTALL
Makefile
Makefile.in
aclocal.m4
config.cache
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
install-sh
libtool
missing
stamp-h1
autom4te.cache
cscope.files
cscope.out
*~
tags
+15 -8
View File
@@ -1,12 +1,19 @@
tinyproxy is a collaborative work between Steven Young Early History
<sdyoung@well.com> and Robert James Kaes <rjkaes@flarenet.com>. -------------
From versions 0-1.1, Steven Young was the primary maintainer. Steven Young is the original author and was the primary maintainer of
From 1.2 to 1.3.0, Robert James Kaes was the primary maintainer. tinyproxy until version 1.1. He also maintained the project from
As of 1.3.1, Steven Young was once again be the primary maintainer. version 1.3.1 until 1.4.0.
But, Robert James Kaes was again the maintainer starting with 1.4.0. Robert James Kaes is the current maintainer and lead programmer. He
Place your bets as to when the maintainer will change again. :) Kidding! also maintained the project between versions 1.2 and 1.3.0, and again
starting with version 1.4.0.
Please see the ChangeLog for futher details as to who did what. :)
Major Additions/Improvements
----------------------------
James E. Flemer <jflemer@acm.jhu.edu> - URL/domain filtering
Kim Holviala <kim@holviala.com> - Reverse proxy support
Petr Lampa <lampa@fit.vutbr.cz> - Transparent proxy support
George Talusan <gstalusan@uwaterloo.ca> - URL/domain filtering
+339
View File
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
+317
View File
@@ -1,3 +1,320 @@
2004-08-10 Robert James Kaes <rjkaes@users.sourceforge.net>
Merged in changes from 1.6.3.
2004-01-26 Robert James Kaes <rjkaes@flarenet.com>
Released tinyproxy 1.7.0 (2004-01-26)
* configure.ac, doc/tinyproxy.conf, src/conns.c, src/conns.h, src/grammar.y, src/reqs.c, src/reqs.h, src/scanner.l, src/tinyproxy.c, src/tinyproxy.h:
Added reverse proxy support from Kim Holviala.
2003-11-19 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (upstream_add): Fixed a spelling mistake with "Nonsence"
2003-10-17 Robert James Kaes <rjkaes@flarenet.com>
* src/filter.c, ChangeLog, Makefile.am, configure.ac:
Merged in changes from the 1.6.2 release. (Fixes for the filtering code
and the HTML installation script.)
2003-10-17 Robert James Kaes <rjkaes@flarenet.com>
Released tinyproxy 1.6.2 (2003-10-17)
* Makefile.am:
Removed a redundant "mkdir" command, since the $(mkinstalldirs)
command handles it correctly.
2003-10-16 Robert James Kaes <rjkaes@flarenet.com>
* src/filter.c (filter_init):
Fixed up the comment handling code. Closes bug 822226
[https://sourceforge.net/tracker/index.php?func=detail&aid=822226&group_id=2632&atid=102632]
2003-08-06 Robert James Kaes <rjkaes@flarenet.com>
Released tinyproxy 1.6.1 (2003-08-06)
* heap.c (debugging_realloc):
Remove the assert on the ptr being NULL since a NULL pointer is
allowed by the realloc() spec.
* child.c (child_main):
Fixed an off-by-one error with the maxrequestsperchild
variable. [Fix proposed by Yannick Koehler]
2003-07-14 Robert James Kaes <rjkaes@flarenet.com>
Released tinyproxy 1.6.0 (2003-07-14)
* src/htmlerror.c (indicate_http_error):
Added calls to va_end() before leaving the function.
2003-06-26 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (upstream_add):
Rewrote the function to actually handle the various types of
upstream configurations correctly. Hopefully, the code is also a
little clearer in it's implementation.
* src/scanner.l:
Modified the patterns to allow the new upstream directives to work
as defined in the tinyproxy.conf documentation.
* src/heap.c (debugging_free):
Rather than assert on a NULL pointer, log the NULL pointer and
return.
2003-06-25 Robert James Kaes <rjkaes@flarenet.com>
* src/common.h:
Added a test to define INADDR_NONE if it's not present. For
example, SunOS (solaris 2.8) does not include this define. [Thank
to Ben Hartshorne for pointing this out.]
* doc/report.sh.tmpl:
Changed the calls to "ps" and "grep" to use a more portable
syntax.
2003-06-20 Robert James Kaes <rjkaes@flarenet.com>
* doc/tinyproxy.conf, src/grammar.y, src/reqs.c, src/scanner.l, src/tinyproxy.h:
Removed the "ViaHeader" directive and replaced it with the
"ViaProxyName" directive. The "Via" HTTP header is _required_ by
the HTTP spec, so the code has been changed to always send the
header. However, including the proxy's host name could be
considered a security threat, so the "ViaProxyName" directive is
used to set the token sent in the "Via" header. If the directive
is not enabled the proxy's host name will be used.
2003-06-06 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (connect_to_upstream):
Fixed an off-by-one error in the snprintf() call used to build the
URL for the upstream proxy. [Patch suggested by David T. Pierso]
2003-06-02 Robert James Kaes <rjkaes@flarenet.com>
* configure.ac:
Remove the -O2 optimization if debugging is enabled. Also, remove
the -g option if the code does _not_ have debugging enabled.
* doc/tinyproxy.conf:
Included additional examples of how to configure the upstream
proxy support for more selective proxying.
* src/reqs.c, src/tinyproxy.h: (upstream_get):
(upstream_add): Added support to allow ip addresses and networks
to be used when matching an upstream proxy directive.
[Code by Peter da Silva]
2003-05-31 Robert James Kaes <rjkaes@flarenet.com>
* src/heap.h:
Changed the safefree() macro to make it safe to use a conditional
statement, and also safe to use with a rvalue that has a side
effect. [Bug fix recommended by Peter da Silva]
2003-05-30 Robert James Kaes <rjkaes@flarenet.com>
* src/vector.c, src/vector.h (vector_getentry):
Changed the API to return the data pointer and have the length
returned in a argument variable pointer. This should be a more
natural way of using the function.
2003-05-29 Robert James Kaes <rjkaes@flarenet.com>
* src/vector.c, src/vector.h (vector_append):
Renamed the vector_insert() function to more accurately indicate
that entries are appended to the end of the vector.
* doc/tinyproxy.conf, src/grammar.y, src/reqs.c, src/reqs.h, src/tinyproxy.h:
Improved the upstream proxy support by making the upstream proxy
server configurable based on the destination host. [Code written by
Peter da Silva]
2003-05-10 Robert James Kaes <rjkaes@flarenet.com>
* Makefile.am:
Added support for installing the HTML error files used by tinyproxy.
2003-05-05 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (establish_http_connection):
If the port being requested is not a standard HTTP port (80 or
443) append the port string to the host header; otherwise, leave
the host string with only the host's domain name.
Replaced all occurrences of constant 80 and 443 with defines
HTTP_PORT and HTTP_PORT_SSL.
2003-05-04 Robert James Kaes <rjkaes@flarenet.com>
* src/conns.c, src/conns.h:
Fixed a bug that would kill a child process because of an invalid
safefree() call. Basically, destroy_conn() was trying to free
memory not allocated by malloc. [Fix by David T. Pierson]
2003-04-16 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (build_url):
Rebuild the URL from the component pieces. This function
is used by the transparent proxy code. [Anatole Shaw]
(process_request): Fixed up the transparent proxy code so that
filtering can be done on the whole URL. [Anatole Shaw]
(pull_client_data): Added a bug fix for Internet Explorer (IE).
IE will leave an extra CR and LF after the data in an HTTP POST.
The new code will eat the extra bytes if they're present. Thanks
to Yannick Koehler for finding the bug and offering an explanation
as to why it was happening.
Changed all calls of connptr->remote_content_length to
connptr->content_length.server
* src/conns.c, src/conns.h:
Removed the remote_content_length field in the "conn" structure
and replaced it with a smaller structure containing both the
remote/server and the local/client content-length fields if
they're present in the HTTP response headers.
2003-04-01 Robert James Kaes <rjkaes@flarenet.com>
* configure.ac:
Reorganized some of the code, and remove some function tests for
which results were never used, and removed duplicate header tests.
* src/htmlerror.c (add_error_variable):
Test whether connptr->error_variable is NULL, and if so call
safemalloc(). This is needed since saferealloc() will assert() if
the first argument is a NULL pointer.
2003-03-26 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (establish_http_connection):
Always include the port number for the requested server. This
fixes a problem when the server is not listening on the default
port, 80. [Fix suggested by duncan@sapio.co.uk]
2003-03-17 Robert James Kaes <rjkaes@flarenet.com>
* doc/Makefile.am:
Create the doc/report.sh script from the new template file.
* doc/report.sh, doc/report.sh.tmpl:
Moved the doc/report.sh script to doc/report.sh.tmpl file. The
script is then updated by the make procedure to reflect the
correct location of the tinyproxy executable.
2003-03-14 Robert James Kaes <rjkaes@flarenet.com>
* src/htmlerror.c:
Made get_html_file() and lookup_variable() static functions since
they are only used with this file.
* src/utils.c (send_http_message):
Changed the function to use the new http_message API.
2003-03-13 Robert James Kaes <rjkaes@flarenet.com>
* src/grammar.y, src/scanner.l:
Allow the URL for the statistic page to be controlled from the
configuration file, rather than being hard-coded in the program.
[John M Wright]
* doc/tinyproxy.conf:
Include example information for the new "file" directives
(ErrorFile, DefaultErrorFile, StatFile.) [Steven Young]
* src/utils.c, src/utils.h:
Moved the send_http_error_message() and indicate_http_error()
functions into the htmlerror.c file, and recoded them to use the
new variable substitution system. [Steven Young]
* src/common.h:
Fixed up the include order for the <sys/time.h> and <time.h>
headers.
* src/http_message.c, src/http_message.h:
An API to handle HTTP messages as concrete entities.
* src/text.c, src/text.h (chomp):
Fixed up the code to prevent negative array access. Added
code to make sure the supplied arguments are valid.
2003-03-09 Steven Young <sdyoung@well.com>
* src/htmlerror.[ch]: Code to allow the use of substituted
variables in .html files for error reporting instead of
hard-coded HTML documents that use snprintf() for variable
substitution.
* src/stats.c: Changed showstats to use the HTML variable
functions when possible. It still retains the hard-coded
page for when an HTML file is not available.
* src/reqs.c: Changed calls to indicate_http_error() to
use the new HTML variable mechanism.
* src/tinyproxy.h: Added variables to config structure
to keep track of the files to be displayed for various
HTTP errors and the stats page.
* src/conns.h: Added variables to keep track of the
variables to be substituted in .html files displayed
to that client.
* src/grammar.y, src/scanner.l: Added parser support
for the error file configuration keywords
(ErrorFile, DefaultErrorFile, StatFile)
2003-03-08 Robert James Kaes <rjkaes@flarenet.com>
Released tinyproxy 1.5.3 (2003-03-10)
Added the files required for creating tinyproxy RPMs for Redhat based
systems. (See packaging/redhat)
2003-02-26 Robert James Kaes <rjkaes@flarenet.com>
* src/tinyproxy.c (main):
Removed duplicate code calling the filter_destroy() function.
Once is enough. [Detected by John M Wright]
2003-01-27 Robert James Kaes <rjkaes@flarenet.com>
* src/tinyproxy.c (display_usage):
Removed the output line mentioning that regular expression support
was included. It will be there always.
* src/reqs.c (connect_to_upstream):
Reorganized the preprocessor directives to make sure the
function's symbol name is stored, even if upstream was not
compiled it. This should keep some compilers from reporting
errors.
* doc/tinyproxy.conf, src/filter.c, src/grammar.y, src/scanner.l,
* src/tinyproxy.h:
Added support for conditionally using case sensitive filtering
files. Code changes from James E. Flemer.
* configure.ac:
Moved the AH_TEMPLATE() macro for the GNU regex library to out
from inside an if...fi test. Thanks to James E. Flemer for
supplying a patch.
Bumped up the version number.
* doc/tinyproxy.8:
Changed the default manual section to section 8 (administrator
commands).
* src/reqs.c (process_client_headers):
Fixed inverted anonymous header logic. Fix comes from the FreeBSD
port through James E. Flemer.
2003-01-22 Robert James Kaes <rjkaes@flarenet.com> 2003-01-22 Robert James Kaes <rjkaes@flarenet.com>
Released tinyproxy 1.5.2 (2003-01-22) Released tinyproxy 1.5.2 (2003-01-22)
+26 -23
View File
@@ -1,24 +1,27 @@
EXTRA_DIST = TODO SUBDIRS = \
SUBDIRS = src doc src \
data \
etc \
docs \
m4macros \
tests
install-data-local: # tools want this on a single line
$(mkinstalldirs) $(DESTDIR)@TINYPROXY_CONFIG_DIR@ ACLOCAL_AMFLAGS = -I m4macros
$(INSTALL) -m 600 $(srcdir)/doc/tinyproxy.conf \
$(DESTDIR)@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@-dist EXTRA_DIST = \
test -f $(DESTDIR)@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@ \ autogen.sh \
|| $(INSTALL) -m 600 $(srcdir)/doc/tinyproxy.conf \ tinyproxy-indent.sh \
$(DESTDIR)@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@ TODO
@echo ""
@echo "A configuration file has been copied to:" test: all
@echo "" ./tests/scripts/run_tests.sh
@echo "@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@-dist"
@echo "" test-wait:
@echo "You will need to rename this file to:" TINYPROXY_TESTS_WAIT=yes $(MAKE) test
@echo ""
@echo "@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@" valgrind-test: all
@echo "" ./tests/scripts/run_tests_valgrind.sh
@echo "and modify the values to suit your local system."
@echo "" valgrind-test-wait:
@echo "All the configuration directives are commented in the file, so" TINYPROXY_TESTS_WAIT=yes $(MAKE) valgrind-test
@echo "you should not have any problems configuring your system."
@echo ""
+179
View File
@@ -0,0 +1,179 @@
Tinyproxy NEWS
==============
Version 1.8.4
-------------
Most notably, this release removes the limitation of
a single Listen address of not listening on the
wildcard address (BB#63) and a DoS (BB#110, CVE-2012-3505).
Among several other bug fixes, this release fixes a bunch of issues found
by coverity (scan.coverity.com).
Bugs resolved since version 1.8.3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#110: fix algorithmic complexity DoS in hashmap
* BB#106: fix failing CONNECT requests with IPv6 literal addresses
* BB#116: fix invalid free for GET requests to IPv6 literal addresses
* BB#63: support multiple Listen statements in configuration
* BB#81: support listening on ipv4 and ipv6 wildcard if no Listen specified
* BB#109: fix crash when writing to log file fails
* BB#112: fix build with autoconf >= 2.69
Contributors:
~~~~~~~~~~~~~
Mukund Sivaraman, Michael Adam, Gaudenz Steinlin, Peter H. Froehlich
Version 1.8.3
-------------
This release mostly fixes support for IPv6, and also some security
bugs. Fixes to messages, etc. were also made.
Bugs resolved since version 1.8.2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#91: Fix upstream proxy support
* BB#95: Fix FilterURLs with transparent proxy support
* BB#90: Fix bug in ACL netmask generation
Contributors
~~~~~~~~~~~~
Daniel Egger, John Horne, Michael Adam, Mukund Sivaraman.
Version 1.8.2
-------------
* Minor formatting changes and typo fixes were made.
Bugs resolved since version 1.8.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#69: INET6 not available when configured to Listen and Bind in v4,
and vice versa
* BB#74: tinyproxy unable to reopen log files after receiving HUP
* BB#78: Warn if configuration results in an open proxy
* BB#82: https access not working
* BB#83: run_tests.sh relies on $USER
* BB#84: Unaligned access error on ia64 and alpha
* BB#87: Unable to listen on ports less than 1024 (regression in 1.8.1)
* BB#88: Crashes when reloading configuration
* BB#89: tinyproxy leaks memory over time
Contributors
~~~~~~~~~~~~
Dmitry Semyonov, John van der Kamp, Jordi Mallach, Michael Adam,
Mukund Sivaraman.
Version 1.8.1
-------------
* Tinyproxy now drops `root` user privileges more quickly.
* The log and pid files are now stored in a sub-directory in `/var/`.
* A format string vulnerability was fixed.
* Minor formatting changes and typo fixes were made.
Bugs fixed since version 1.8.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#74: tinyproxy unable to reopen log files after receiving HUP
* BB#79: Make the testsuite uninteractive
* BB#80: Handle errors in testsuite
* BB#81: Listen directive doesn't work as expected
* BB#72: upstream support is not reported with tinyproxy -h
* BB#73: generated tinyproxy.conf has the wrong location for the html
file installation
Contributors
~~~~~~~~~~~~
Michael Adam, Mukund Sivaraman.
Version 1.8.0
-------------
* Tinyproxy now reloads its configuration upon SIGHUP signal.
* Tinyproxy reopens its log file (instead of truncation) upon SIGHUP
signal. This is to play more nicely with logrotate.
* File logging is now the default.
Syslog is chosen if and only if "SysLog Yes" is in the config,
i.e., a present "SysLog Yes" in the config file now overrides
any LogFile setting.
* The XTinyProxy option is now documented as a global boolean.
Before it was documented to build a list of sites to add a
X-Tinyproxy header for, but it was implemented as global boolean.
* A new config option AddHeader allows the user to configure a list of
custom headers to send in outgoing HTTP requests.
* A new config option DisableViaHeader allows the user to disable
sending of the "Via:" header.
* Tinyproxy is now IPv6 capable.
* The config option PidFile now has a compiled in default.
Bugs fixed since version 1.7.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#9: Add support for the IPv6 protocol
* BB#17: Add support for custom headers
* BB#55: Error message response omits body when request has a body
* BB#60: Add config option to disable Via header
* BB#61: SIGHUP does not refresh filter list
* BB#62: Make tinyproxy reload the config upon SIGHUP
* BB#64: Config parsing error with reverse proxy option
* BB#65: Format string compile warnings
* BB#67: ACL processing error with multiple Allow statements
Contributors
~~~~~~~~~~~~
David Shanks, Mathew Mrosko, Michael Adam, Mukund Sivaraman.
Version 1.7.1
-------------
* Fixed all warnings reported by GCC.
* The tinyproxy manpage has been extended and converted to asciidoc.
* There is a new tinyproxy.conf manpage that describes all the options.
* The build system has been considerably cleaned up.
* Various other bugs have been fixed.
Bugs fixed since version 1.7.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#2: Fix Tinyproxy for requests like www.site.com:8001
* BB#5: Move templates from the doc directory to its own directory
* BB#8: Update README, INSTALL, NEWS and the manpage
* BB#10: Do not filter out transfer-encoding header
* BB#18: Fix pointer aliasing issues
* BB#53: Add a GPLv2 COPYING file
Contributors
~~~~~~~~~~~~
Andrew Stribblehill, Jeremy Hinegardner, Matthew Dempsky, Michael Adam,
Mukund Sivaraman, Robert James Kaes.
Version 1.7.0
-------------
* There is now support for reverse proxying.
* Tinyproxy does not bundle a vendor regular expressions library
anymore. It uses the system installed regular expressions library.
* The documentation has been updated.
* Tinyproxy now contains some code optimizations such as the use of a
hashmap internally for looking up error pages.
* Various other bugs have been fixed.
Contributors
~~~~~~~~~~~~
Kim Holviala, Marc Silver, Robert James Kaes, Steven Young.
+66 -75
View File
@@ -1,106 +1,97 @@
Tinyproxy
=========
DESCRIPTION Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
----------- GNU General Public License. Tinyproxy is very useful in a small network
setting, where a larger proxy would either be too resource intensive, or
tinyproxy is a small, efficient HTTP/SSL proxy daemon released under a security risk. One of the key features of Tinyproxy is the buffering
the GNU General Public License (GPL). tinyproxy is very useful in a connection concept. In effect, Tinyproxy will buffer a high speed
small network setting, where a larger proxy like Squid would either response from a server, and then relay it to a client at the highest
be too resource intensive, or a security risk. One of the key speed the client will accept. This feature greatly reduces the problems
features of tinyproxy is the buffering connection concept. In with sluggishness on the Internet. If you are sharing an Internet
effect, tinyproxy will buffer a high speed response from a server, connection with a small network, and you only want to allow HTTP
and then relay it to a client at the highest speed the client will requests to be allowed, then Tinyproxy is a great tool for the network
accept. This feature greatly reduces the problems with sluggishness
on the Internet. If you are sharing an Internet connection with a
small network, and you only want to allow HTTP requests to be
allowed, then tinyproxy is a great tool for the network
administrator. administrator.
For more info, please visit:
INSTALLATION https://banu.com/tinyproxy/
Installation
------------ ------------
To install this package under a Unix derivative, read the INSTALL To install this package under a UNIX derivative, read the INSTALL file.
file. tinyproxy uses a standard GNU configure script (basically you Tinyproxy uses a standard GNU `configure` script. Basically you should
should be able to do: be able to do:
./configure ; make ; make install ----
./configure
make
make install
----
in the top level directory to compile and install tinyproxy). There in the top level directory to compile and install Tinyproxy. There are
are additional command line arguments you can supply to configure. additional command line arguments you can supply to `configure`. They
They include: include:
--enable-debug If you would like to turn on full --enable-debug If you would like to turn on full
debugging support debugging support
--enable-socks This turns on SOCKS support for using
tinyproxy across a fire wall.
--enable-xtinyproxy Compile in support for the XTinyproxy --enable-xtinyproxy Compile in support for the XTinyproxy
header, which is sent to any web header, which is sent to any web
server in your domain. server in your domain.
--enable-filter Allows tinyproxy to filter out certain --enable-filter Allows Tinyproxy to filter out certain
domains and URLs. domains and URLs.
--enable-upstream Enable support for proxying connections --enable-upstream Enable support for proxying connections
through another proxy server. through another proxy server.
--enable-transparent-proxy --enable-transparent
Allow tinyproxy to be used a Allow Tinyproxy to be used as a
transparent proxy daemon transparent proxy daemon
--enable-static Compile a static version of tinyproxy --enable-static Compile a static version of Tinyproxy
Options for file locations etc.
--with-stathost=HOST Set the default name of the stats host --with-stathost=HOST Set the default name of the stats host
--with-config=FILE Set the default location of the
configuration file
Once you have completed your installation, if you would like to
report your success please execute the report.sh script in the doc
directory. This will send an email to the authors reporting your
version, and a few bits of information concerning the memory usage of
tinyproxy. Alternatively, you could just send an email stating the
version, whichever you prefer.
SUPPORT Support
------- -------
If you are having problems with tinyproxy, please submit a bug to the If you are having problems with Tinyproxy, please submit a bug report
tinyproxy Bug Tracking system hosted by SourceForge and located at: using Tinyproxy as the product at:
http://sourceforge.net/tracker/?group_id=2632 https://banu.com/bugzilla/
You may also wish to subscribe to the tinyproxy-user mailing list. To You may also wish to subscribe to the Tinyproxy mailing lists. To do so
do so please visit: please visit:
http://lists.sourceforge.net/lists/listinfo/tinyproxy-users https://banu.com/mailman/listinfo/tinyproxy-announce-list
https://banu.com/mailman/listinfo/tinyproxy-users-list
https://banu.com/mailman/listinfo/tinyproxy-developers-list
for more information on how to subscribe and post messages to the for more information on how to subscribe and post messages to the lists.
list.
Please recompile tinyproxy with full debug support (--enable-debug)
and include a copy of the log file, and any assert errors reported by
tinyproxy. Note that tinyproxy will output memory statistics to
standard error if compiled with debugging support so you might want
to redirect the output to a file for later examination. Also, if you
feel up to it, try running tinyproxy under your debugger and report
the error your received and a context listing of the location. Under
gdb you would run tinyproxy like so:
gdb tinyproxy
(gdb) run -c location_of_tinyproxy_conf -d 2>/dev/null
Now access the port tinyproxy is on until you receive a break in the
gdb. You can now type:
(gbd) l
to produce a context listing of the location of the error. Send a
copy to the authors.
HOW TO CONTRIBUTE TO tinyproxy Contributing
------------------------------ ------------
If you would like to contribute a feature, or a bug fix to the If you would like to contribute a feature, or a bug fix to the Tinyproxy
tinyproxy source, please send a diff (preferable a unified source, please send a patch (preferably as a unified diff. i.e. `diff
diff. i.e. "diff -u") against the latest release of tinyproxy. Also, -u` against the "master" branch of the Tinyproxy source code git
if you could include a brief description of what your patch does. repository to tinyproxy-developers-list. Please include a description
of what your patch does.
Tinyproxy's git repository is git://banu.com/tinyproxy.git. The
following command creates a local copy:
----
git clone git://banu.com/tinyproxy.git
----
The easiest and preferred way to create a patch for submission is to
check in your changes locally and use `git format-patch` to generate a
mbox-style commit file that contains the diff along with the commit
message and author information. Such a format-patch file can be
integrated into the upstream repository, automatically keeping the
commit message and author information.
You can also meet developers and discuss development issues and patches
in the #tinyproxy IRC channel on Freenode (irc.freenode.net).
+16 -4
View File
@@ -16,10 +16,6 @@ against the current tree and I'll integrate it if possible.
proxies (ftp, www, etc) they'd like enabled in tinyproxy.h proxies (ftp, www, etc) they'd like enabled in tinyproxy.h
Suggested: Tarun Tuli. Suggested: Tarun Tuli.
* Find a more elegant solution to embedding HTML documents in the
source than the current method. (see httperr() and showstats() for
examples of how it's done right now).
* Include a function to rewrite the incoming requests. Should not be * Include a function to rewrite the incoming requests. Should not be
much of a problem. Just need to modify the process_method() code much of a problem. Just need to modify the process_method() code
to look up the URL and rewrite it. If we want to go really fancy to look up the URL and rewrite it. If we want to go really fancy
@@ -38,3 +34,19 @@ against the current tree and I'll integrate it if possible.
for the administrators. Right now it's more a hodge-podge for the administrators. Right now it's more a hodge-podge
collections of error messages without a _real_ standard. I would collections of error messages without a _real_ standard. I would
prefer a more uniform look. prefer a more uniform look.
* Include user authentication for accessing tinyproxy itself.
Administrators should be allowed to selectively allow certain users
access to tinyproxy via a user name/password pair. Check the
HTTP/1.1 RFC for more information.
==> 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
Executable
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
set -x
cd $srcdir
aclocal -I m4macros \
&& autoheader \
&& automake --gnu --add-missing \
&& autoconf
cd $ORIGDIR
set -
echo $srcdir/configure "$@"
$srcdir/configure "$@"
RC=$?
if test $RC -ne 0; then
echo
echo "Configure failed or did not finish!"
exit $RC
fi
echo
echo "Now type 'make' to compile Tinyproxy."
+151 -195
View File
@@ -1,103 +1,87 @@
dnl $Id: configure.ac,v 2.48 2003-01-22 19:46:06 rjkaes Exp $ # Process this file with autoconf to produce a configure script.
# Portions of this file were adapted from GIMP.
dnl Devlopers, please strive to achieve this order: AC_PREREQ(2.54)
dnl
dnl 0. Initialization and options processing
dnl 1. Programs
dnl 2. Libraries
dnl 3. Header files
dnl 4. Types
dnl 5. Structures
dnl 6. Compiler characteristics
dnl 7. Functions, global variables
dnl 8. System services
dnl
dnl Read the Autoconf manual for details.
AC_INIT([tinyproxy], [1.5.2], [rjkaes@users.sourceforge.net]) m4_define([tinyproxy_major_version], [1])
AC_CONFIG_SRCDIR([src/tinyproxy.c]) m4_define([tinyproxy_minor_version], [8])
AC_PREREQ(2.52) m4_define([tinyproxy_micro_version], [4])
m4_define([tinyproxy_real_version],
[tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
m4_define([tinyproxy_version], [tinyproxy_real_version])
# For overriding the version string. Comment out if not needed.
# m4_define([tinyproxy_version], [1.8.2])
m4_define([tinyproxy_unstable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [1], [yes], [no]))
m4_define([tinyproxy_stable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [0], [yes], [no]))
AC_INIT([Tinyproxy], [tinyproxy_version],
[https://banu.com/tinyproxy/],
[tinyproxy])
AC_CANONICAL_TARGET AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([dist-bzip2 dist-xz])
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR([m4macros])
AH_TEMPLATE([TARGET_SYSTEM], m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
[A string containing the target system for which tinyproxy was built.])
AC_DEFINE_UNQUOTED(TARGET_SYSTEM, ["$target"]) TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
TINYPROXY_MICRO_VERSION=tinyproxy_micro_version
TINYPROXY_REAL_VERSION=tinyproxy_real_version
TINYPROXY_VERSION=tinyproxy_version
TINYPROXY_UNSTABLE=tinyproxy_unstable
AC_SUBST(TINYPROXY_MAJOR_VERSION)
AC_SUBST(TINYPROXY_MINOR_VERSION)
AC_SUBST(TINYPROXY_MICRO_VERSION)
AC_SUBST(TINYPROXY_REAL_VERSION)
AC_SUBST(TINYPROXY_VERSION)
AC_SUBST(TINYPROXY_UNSTABLE)
dnl Temporarily defined here until we get tinyproxy-version.h
AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number])
# The symbol TINYPROXY_UNSTABLE is defined above for substitution in
# Makefiles and conditionally defined here as a preprocessor symbol
# and automake conditional.
if test "x$TINYPROXY_UNSTABLE" = "xyes"; then
AC_DEFINE(TINYPROXY_UNSTABLE, 1,
[Define to 1 if this is an unstable version of Tinyproxy])
fi
AM_CONDITIONAL(TINYPROXY_UNSTABLE, test "x$TINYPROXY_UNSTABLE" = "xyes")
AM_INIT_AUTOMAKE($PACKAGE_NAME, $PACKAGE_VERSION)
AM_CONFIG_HEADER(config.h)
dnl Check if we're compiling on a weird platform :) dnl Check if we're compiling on a weird platform :)
AC_AIX AC_USE_SYSTEM_EXTENSIONS
AC_ISC_POSIX
AC_MINIX
dnl
dnl Command line options
dnl
dnl Set the URL name for find the statistics of tinyproxy dnl Set the domain name for find the statistics of tinyproxy
AH_TEMPLATE([DEFAULT_STATHOST], AH_TEMPLATE([TINYPROXY_STATHOST],
[This controls remote proxy stats display.]) [This controls remote proxy stats display.])
AC_ARG_WITH(stathost, AC_ARG_WITH(stathost,
[AC_HELP_STRING([--with-stathost=HOST], [Default status host])], [AC_HELP_STRING([--with-stathost=HOST], [Default status host])],
[AC_DEFINE_UNQUOTED(DEFAULT_STATHOST, "$withval")], [AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")
[AC_DEFINE_UNQUOTED(DEFAULT_STATHOST, "tinyproxy.stats")]) TINYPROXY_STATHOST="$withval"],
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")
TINYPROXY_STATHOST="tinyproxy.stats"])
dnl Set the default configuration file location AC_SUBST(TINYPROXY_STATHOST)
test "$prefix" = "NONE" && prefix=/usr/local
AH_TEMPLATE([DEFAULT_CONF_FILE],
[This is the default file name for the configuration file.])
AC_ARG_WITH(config,
[AC_HELP_STRING([--with-config=FILE],
[Set the default location of the config file])],
[tp_config_file="$withval"],
[tp_config_file="tinyproxy.conf"])
# If the first character is a slash, it's an absolute path
if [[ `echo $tp_config_file | cut -c1` = "/" ]]; then
TINYPROXY_CONFIG_DIR=`echo "$tp_config_file" | sed 's/^\(.*\)\/[[^\/]]*$/\1/'`
TINYPROXY_CONFIG_FILE=`echo "$tp_config_file" | sed 's/^.*\/\([[^\/]]*\)$/\1/'`
else
# If sysconfdir is /usr/etc, change it to /etc (since /usr/etc doesn't exist)
if [[ "/usr/etc" = `eval echo $sysconfdir` -a "/usr" = "$prefix" ]]; then
TINYPROXY_CONFIG_DIR="/etc/tinyproxy"
else
TINYPROXY_CONFIG_DIR=`eval echo $sysconfdir/tinyproxy`
fi
TINYPROXY_CONFIG_FILE="$tp_config_file"
fi
AC_DEFINE_UNQUOTED(DEFAULT_CONF_FILE, "$TINYPROXY_CONFIG_DIR/$TINYPROXY_CONFIG_FILE")
AC_MSG_NOTICE([Default config location and file is: $TINYPROXY_CONFIG_DIR/$TINYPROXY_CONFIG_FILE])
dnl Add compiler-specific optimization flags dnl Add compiler-specific optimization flags
AC_ARG_ENABLE(debug, TP_ARG_ENABLE(debug,
[AC_HELP_STRING([--enable-debug], [Enable debugging support code and methods (default is NO)],
[Disable aggressive optimizations (default is NO)])], no)
debug_enabled=$enableval, debug_enabled=no)
dnl Add in profiling information
AC_ARG_ENABLE(profiling,
[AC_HELP_STRING([--enable-profiling],
[Enable profiling information (default is NO)])],
profiling_enabled=$enableval, profiling_enabled=no)
dnl Include SOCKS support
AC_ARG_ENABLE(socks,
[AC_HELP_STRING([--enable-socks],
[Enable SOCKS support (default is NO)])],
socks_enabled=$enableval, socks_enabled=no)
dnl Check to see if the XTinyproxy header is to be included dnl Check to see if the XTinyproxy header is to be included
AH_TEMPLATE([XTINYPROXY_ENABLE], AH_TEMPLATE([XTINYPROXY_ENABLE],
[Define if you want to have the peer's IP address included in a XTinyproxy header sent to the server.]) [Define if you want to have the peer's IP address included in a XTinyproxy header sent to the server.])
AC_ARG_ENABLE(xtinyproxy, TP_ARG_ENABLE(xtinyproxy,
[AC_HELP_STRING([--enable-xtinyproxy], [Include the X-Tinyproxy header (default is YES)],
[Include X-Tinyproxy header (default is YES)])], yes)
xtinyproxy_enabled=$enableval, xtinyproxy_enabled=yes)
if test x"$xtinyproxy_enabled" = x"yes"; then if test x"$xtinyproxy_enabled" = x"yes"; then
AC_DEFINE(XTINYPROXY_ENABLE) AC_DEFINE(XTINYPROXY_ENABLE)
@@ -106,10 +90,9 @@ fi
dnl Include filtering for domain/URLs dnl Include filtering for domain/URLs
AH_TEMPLATE([FILTER_ENABLE], AH_TEMPLATE([FILTER_ENABLE],
[Defined if you would like filtering code included.]) [Defined if you would like filtering code included.])
AC_ARG_ENABLE(filter, TP_ARG_ENABLE(filter,
[AC_HELP_STRING([--enable-filter], [Enable filtering of domains/URLS (default is YES)],
[Enable filtering of domains/URLs (default is YES)])], yes)
filter_enabled=$enableval, filter_enabled=yes)
if test x"$filter_enabled" = x"yes"; then if test x"$filter_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS filter.o" ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS filter.o"
@@ -119,53 +102,42 @@ fi
dnl Include support for upstream proxies? dnl Include support for upstream proxies?
AH_TEMPLATE([UPSTREAM_SUPPORT], AH_TEMPLATE([UPSTREAM_SUPPORT],
[Include support for connecting to an upstream proxy.]) [Include support for connecting to an upstream proxy.])
AC_ARG_ENABLE(upstream, TP_ARG_ENABLE(upstream,
[AC_HELP_STRING([--enable-upstream], [Enable upstream proxying (default is YES)],
[Enable support for upstream proxies (default is YES)])], yes)
upstream_enabled=$enableval, upstream_enabled=yes)
if test x"$upstream_enabled" = x"yes"; then if test x"$upstream_enabled" = x"yes"; then
AC_DEFINE(UPSTREAM_SUPPORT) AC_DEFINE(UPSTREAM_SUPPORT)
fi fi
dnl Include support for reverse proxy?
AH_TEMPLATE([REVERSE_SUPPORT],
[Include support for reverse proxy.])
TP_ARG_ENABLE(reverse,
[Enable reverse proxying (default is NO)],
no)
if test x"$reverse_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
AC_DEFINE(REVERSE_SUPPORT)
fi
dnl Include the transparent proxy support dnl Include the transparent proxy support
AH_TEMPLATE([TRANSPARENT_PROXY], AH_TEMPLATE([TRANSPARENT_PROXY],
[Include support for using tinyproxy as a transparent proxy.]) [Include support for using tinyproxy as a transparent proxy.])
AC_ARG_ENABLE(transparent-proxy, TP_ARG_ENABLE(transparent,
[AC_HELP_STRING([--enable-transparent-proxy], [Enable transparent proxying code (default is NO)],
[Enable transparent proxy support (default is NO)])], no)
transparent_enabled=$enableval, transparent_enabled=no)
if test x"$transparent_enabled" = x"yes"; then if test x"$transparent_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
AC_DEFINE(TRANSPARENT_PROXY) AC_DEFINE(TRANSPARENT_PROXY)
fi fi
dnl Include support for a statically compiled tinyproxy dnl Check for broken regex library
AC_ARG_ENABLE(static, TP_ARG_ENABLE(regexcheck,
[AC_HELP_STRING([--enable-static], [Check for working regex library (default is YES)],
[Statically link tinyproxy (default is NO)])], yes)
[LDFLAGS="-static $LDFLAGS"])
# This is required to build test programs below
dnl
dnl Checks for programs
dnl
cflags_save="$CFLAGS"
AC_PROG_AWK
AC_PROG_MAKE_SET
AC_PROG_CC AC_PROG_CC
AC_PROG_CC_STDC
AC_PROG_INSTALL
AC_PROG_LN_S
AM_PROG_LEX
AC_PROG_YACC
CFLAGS="$cflags_save"
dnl Make sure YACC is actually bison
if test x"$YACC" != x"bison -y"; then
AC_MSG_WARN([You will need bison if you want to regenerate the parser.])
fi
dnl dnl
dnl Checks for libraries dnl Checks for libraries
@@ -187,20 +159,20 @@ if test x"$tinyproxy_no_nsl_checks" != x"yes"; then
fi fi
AC_CHECK_LIB(resolv, inet_aton) AC_CHECK_LIB(resolv, inet_aton)
AC_CHECK_LIB(socks, main, socks_library=yes, socks_library=no)
dnl dnl
dnl Checks for headers dnl Checks for headers
dnl dnl
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS([sys/types.h sys/ioctl.h sys/mman.h sys/resource.h \ AC_HEADER_TIME
sys/select.h sys/socket.h sys/stat.h sys/time.h sys/uio.h \ AC_HEADER_SYS_WAIT
sys/un.h sys/wait.h arpa/inet.h netinet/in.h alloca.h \ AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \
sys/select.h sys/socket.h sys/time.h sys/uio.h \
sys/un.h arpa/inet.h netinet/in.h \
assert.h ctype.h errno.h fcntl.h grp.h io.h libintl.h \ assert.h ctype.h errno.h fcntl.h grp.h io.h libintl.h \
memory.h netdb.h pwd.h regex.h signal.h \ netdb.h pwd.h regex.h signal.h stdarg.h stddef.h stdio.h \
stdarg.h stddef.h stdint.h stdio.h stdlib.h string.h \ sysexits.h syslog.h time.h wchar.h wctype.h \
strings.h sysexits.h syslog.h time.h unistd.h wchar.h \ values.h])
wctype.h])
dnl OpenBSD machines don't like having malloc included (even if it's present) dnl OpenBSD machines don't like having malloc included (even if it's present)
dnl as they expect you to use stdlib.h dnl as they expect you to use stdlib.h
@@ -209,16 +181,10 @@ case "$target" in
*) AC_CHECK_HEADER(malloc.h);; *) AC_CHECK_HEADER(malloc.h);;
esac esac
AC_CHECK_HEADER(socks.h, socks_header=yes, socks_header=no)
dnl
dnl Checks for types dnl Checks for types
dnl
AM_C_PROTOTYPES
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T AC_TYPE_SIZE_T
AC_HEADER_TIME AC_TYPE_PID_T
AC_UNP_CHECK_TYPE(uint8_t, unsigned char) AC_UNP_CHECK_TYPE(uint8_t, unsigned char)
AC_UNP_CHECK_TYPE(int16_t, short) AC_UNP_CHECK_TYPE(int16_t, short)
AC_UNP_CHECK_TYPE(uint16_t, unsigned short) AC_UNP_CHECK_TYPE(uint16_t, unsigned short)
@@ -227,72 +193,48 @@ AC_UNP_CHECK_TYPE(uint32_t, unsigned int)
AC_UNP_CHECK_TYPE(ssize_t, int) AC_UNP_CHECK_TYPE(ssize_t, int)
AC_UNP_CHECK_TYPE(socklen_t, unsigned int) AC_UNP_CHECK_TYPE(socklen_t, unsigned int)
AC_UNP_CHECK_TYPE(in_addr_t, uint32_t) AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
AC_TYPE_PID_T
dnl
dnl Checks for libary functions dnl Checks for libary functions
dnl AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_ALLOCA
AC_FUNC_FORK
AC_FUNC_MALLOC AC_FUNC_MALLOC
AC_TYPE_SIGNAL AC_FUNC_REALLOC
AC_FUNC_STRERROR_R
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([btowc bzero ftruncate gethostbyaddr gethostbyname gethostname \
inet_ntoa memchr memset re_comp regcomp \
regexec select setrlimit socket strncasecmp strchr strdup \
strerror strstr strtol vsyslog vsnprintf])
AC_CHECK_FUNCS(strlcpy strlcat) AC_CHECK_FUNCS([gethostname inet_ntoa memchr memset select socket strcasecmp \
strchr strdup strerror strncasecmp strpbrk strstr strtol])
AC_CHECK_FUNCS([isascii memcpy memmove setrlimit ftruncate regcomp regexec])
AC_CHECK_FUNCS([strlcpy strlcat setgroups])
dnl AC_CHECK_FUNCS([time rand srand])
dnl Compiler characteristics
dnl
dnl If profiling is enabled, then enable the debugging code
if test x"$profiling_enabled" = x"yes" ; then dnl Enable extra warnings
AC_MSG_NOTICE([profiling is enabled, therefore enabling debugging code.]) DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -pedantic -Wc++-compat -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
debug_enabled=yes
if test -n "${MAINTAINER_MODE_FALSE}"; then
DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
fi fi
dnl Enable the debugging flags (by checking for the GCC compiler) for flag in $DESIRED_FLAGS; do
if test x"$debug_enabled" = x"yes" ; then AS_COMPILER_FLAG([$flag], [CFLAGS="$CFLAGS $flag"])
dnl Add the warnings if we have the GCC compiler done
if test x"$GCC" = x"yes" ; then
if test x"$profiling_enabled" = x"yes" ; then dnl Disable debugging if it's not specified
CFLAGS="-pg -fprofile-arcs $CFLAGS" if test x"$debug_enabled" != x"yes" ; then
fi CFLAGS="-DNDEBUG $CFLAGS"
CFLAGS="-Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes $CFLAGS"
CFLAGS="-Wmissing-prototypes -Wmissing-declarations $CFLAGS"
CFLAGS="-Wpointer-arith -Waggregate-return -Wnested-externs $CFLAGS"
fi
CFLAGS="-Wall -g -DYYDEBUG $CFLAGS"
YFLAGS="-v -d"
else
dnl No debugging information, include the optimizations
CFLAGS="-O2 -DNDEBUG $CFLAGS"
YFLAGS="-d"
fi fi
LDFLAGS="-Wl,-z,defs $LDFLAGS"
dnl dnl
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff. dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
dnl dnl
dnl Handle the SOCKS support
if test x"$socks_enabled" = x"yes"; then
if test x"$socks_header" = x"yes" -a x"$socks_library" = x"yes"; then
CFLAGS="-I/usr/include/sock.h -DSOCKS $CFLAGS"
LIBS="-lsocks $LIBS"
else
AC_MSG_ERROR([Could not include the SOCKS library or header])
fi
fi
dnl Handle the REGEX library dnl Handle the REGEX library
if test x"$ac_cv_func_regexec" != x"yes"; then if test x"$ac_cv_func_regexec" != x"yes"; then
dnl We don't have a functioning REGEX so include our copy AC_MSG_ERROR([Could not locate the regexec() function])
tinyproxy_use_our_regex=yes
else else
if test x"$regexcheck_enabled" = x"yes" ; then
AC_MSG_CHECKING([whether the system's regex library is broken]) AC_MSG_CHECKING([whether the system's regex library is broken])
AC_CACHE_VAL(tinyproxy_cv_regex_broken, AC_CACHE_VAL(tinyproxy_cv_regex_broken,
[AC_TRY_RUN([ [AC_TRY_RUN([
@@ -305,6 +247,9 @@ else
#if HAVE_REGEX_H #if HAVE_REGEX_H
# include <regex.h> # include <regex.h>
#endif #endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
int main(void) int main(void)
{ {
regex_t blah; regex_t blah;
@@ -325,17 +270,9 @@ int main(void)
AC_MSG_RESULT([$tinyproxy_cv_regex_broken]) AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
AC_MSG_NOTICE([Using the included GNU regex instead.]) AC_MSG_ERROR([Your system's regexec() function is broken.])
tinyproxy_use_our_regex=yes
fi fi
fi fi
if test x"$tinyproxy_use_our_regex" = x"yes" ; then
AH_TEMPLATE([USE_GNU_REGEX],
[Defined if you want to use the included regex routines.])
AC_DEFINE(USE_GNU_REGEX)
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS gnuregex.o"
fi fi
dnl dnl
@@ -343,12 +280,31 @@ dnl Substitute the variables into the various Makefiles
dnl dnl
AC_SUBST(CFLAGS) AC_SUBST(CFLAGS)
AC_SUBST(LDFLAGS) AC_SUBST(LDFLAGS)
AC_SUBST(YFLAGS)
AC_SUBST(CPPFLAGS) AC_SUBST(CPPFLAGS)
AC_SUBST(LIBS) AC_SUBST(LIBS)
AC_SUBST(ADDITIONAL_OBJECTS) AC_SUBST(ADDITIONAL_OBJECTS)
AC_SUBST(TINYPROXY_CONFIG_DIR)
AC_SUBST(TINYPROXY_CONFIG_FILE)
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile]) # 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
src/Makefile
data/Makefile
data/templates/Makefile
etc/Makefile
docs/Makefile
docs/man5/Makefile
docs/man5/tinyproxy.conf.txt
docs/man8/Makefile
docs/man8/tinyproxy.txt
m4macros/Makefile
tests/Makefile
tests/scripts/Makefile
])
AC_OUTPUT AC_OUTPUT
+2
View File
@@ -0,0 +1,2 @@
SUBDIRS = \
templates
+12
View File
@@ -0,0 +1,12 @@
templatesdir = $(pkgdatadir)
TEMPLATES = \
debug.html \
default.html \
stats.html
templates_DATA = \
$(TEMPLATES)
EXTRA_DIST = \
$(TEMPLATES)
+56
View File
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>{errno} {cause}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>{cause}</h1>
<p>{detail}</p>
<p>Here are the error variables:</p>
<dl>
<dt>request</dt>
<dd>{request}</dd>
<dt>cause</dt>
<dd>{cause}</dd>
<dt>clientip</dt>
<dd>{clientip}</dd>
<dt>clienthost</dt>
<dd>{clienthost}</dd>
<dt>version</dt>
<dd>{version}</dd>
<dt>package</dt>
<dd>{package}</dd>
<dt>date</dt>
<dd>{date}</dd>
<dt>detail</dt>
<dd>{detail}</dd>
<dt>url</dt>
<dd>{url}</dd>
</dl>
<hr />
<p><em>Generated by <a href="{website}">{package}</a> version {version}.</em></p>
</body>
</html>
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>{errno} {cause}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>{cause}</h1>
<p>{detail}</p>
<hr />
<p><em>Generated by <a href="{website}">{package}</a> version {version}.</em></p>
</body>
</html>
+69
View File
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>{package} version {version} run-time statistics</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css" media="screen">
<!--/*--><![CDATA[<!--*/
th, td
{
text-align: left;
padding: 0.5em;
border: 1px solid gray;
}
/*]]>*/-->
</style>
</head>
<body>
<h1>{package} version {version} run-time statistics</h1>
<table>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<tr>
<td>Number of open connections</td>
<td>{opens}</td>
</tr>
<tr>
<td>Number of requests</td>
<td>{reqs}</td>
</tr>
<tr>
<td>Number of bad connections</td>
<td>{badconns}</td>
</tr>
<tr>
<td>Number of denied connections</td>
<td>{deniedconns}</td>
</tr>
<tr>
<td>Number of refused connections due to high load</td>
<td>{refusedconns}</td>
</tr>
</table>
<hr />
<p><em>Generated by <a href="{website}">{package}</a> version {version}.</em></p>
</body>
</html>
-7
View File
@@ -1,7 +0,0 @@
EXTRA_DIST = tinyproxy.8 tinyproxy.conf \
HTTP_ERROR_CODES RFC_INFO \
releases.txt \
filter-howto.txt \
report.sh
man_MANS = tinyproxy.8
-14
View File
@@ -1,14 +0,0 @@
#!/bin/sh
(echo "date: "
date
echo "uname: "
uname -a
echo "ps: "
ps -auxw | grep '[t]inyproxy' -
echo "ver: "
if [ -x /usr/local/bin/tinyproxy ]; then
/usr/local/bin/tinyproxy -v
else
echo no ver available.
fi;) 2>&1 | mail -s 'tinyproxy install report' rjkaes@users.sourceforge.net
-60
View File
@@ -1,60 +0,0 @@
.\" -*- nroff -*-
.\"
.\" tinyproxy.1
.\"
.\" Copyright (c) 1998-2000 Steven Young and Robert James Kaes.
.\" Copyright (c) 2001 Robert James Kaes
.\"
.\" This program is distributed under the terms of the GNU General Public
.\" License. See COPYING for additional information.
.\"
.TH tinyproxy 1 .\" "tinyproxy Manual" "August 25, 2001"
.SH NAME
tinyproxy - A small HTTP proxy server
.SH SYNTAX
\fBtinyproxy\fR [ \fBoptions\fR ]
.SH VERSION
This man page documents tinyproxy
.SH DESCRIPTION
\fBtinyproxy\fR is an HTTP proxy server designed to consume a minimum of
system resources. It listens on a given TCP port and handles HTTP proxy
requests.
.SH OPTIONS
.IP "-c config_file"
Use an alternate configuration file.
.IP -d
Don't daemonize; stay in the foreground. Useful for debugging purposes.
.IP -h
Display a short help screen of command line arguments and exit.
.IP -l
Displays the licensing agreement.
.IP -v
Display version information and exit.
.SH SIGNALS
In addition to these command line options, there are also several signals
that can be sent to tinyproxy while it is running to generate debugging
information and to force certain events.
.TP 5
.B SIGHUP
Force \fBtinyproxy\fR to do a garbage collection on the current connections
linked list. This is usually done automatically after a certain number of
connections have been handled.
.SH FILES
.nf
/etc/tinyproxy/tinyproxy.conf
/var/run/tinyproxy.pid
/var/log/tinyproxy.log
.fi
.SH AUTHORS
.nf
Robert James Kaes (rjkaes@flarenet.com)
Steven Young (sdyoung@users.sourceforge.net)
.fi
.SH COPYRIGHT
\fBtinyproxy\fR is distributed under the GNU Public License (GPL). For more
information on the GPL, please see the file COPYING which should have been
included in the archive with \fBtinyproxy\fR. Failing that,
http://www.fsf.org/ will doubtless have a copy up for you to peruse. Please
don't use this software if you don't agree to the terms specified therein.
.SH AVAILABILITY
The latest version of \fBtinyproxy\fR can be acquired from: http://tinyproxy.sourceforge.net/
-163
View File
@@ -1,163 +0,0 @@
##
## tinyproxy.conf -- tinyproxy daemon configuration file
##
#
# Name of the user the tinyproxy daemon should switch to after the port
# has been bound.
#
User nobody
Group nogroup
#
# Port to listen on.
#
Port 8888
#
# If you have multiple interfaces this allows you to bind to only one. If
# this is commented out, tinyproxy will bind to all interfaces present.
#
#Listen 192.168.0.1
#
# The Bind directive allows you to bind the outgoing connections to a
# particular IP address.
#
#Bind 192.168.0.1
#
# Timeout: The number of seconds of inactivity a connection is allowed to
# have before it closed by tinyproxy.
#
Timeout 600
#
# Where to log the information. Either LogFile or Syslog should be set,
# but not both.
#
Logfile "/var/log/tinyproxy.log"
# Syslog On
#
# Set the logging level. Allowed settings are:
# Critical (least verbose)
# Error
# Warning
# Notice
# Connect (to 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.
#
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"
#
# Include the X-Tinyproxy header, which has the client's IP address when
# connecting to the sites listed.
#
#XTinyproxy mydomain.com
#
# Turns on upstream proxy support.
#
#Upstream some.remote.proxy:port
#
# This is the absolute highest number of threads which will be created. In
# other words, only MaxClients number of clients can be connected at the
# same time.
#
MaxClients 100
#
# These settings set the upper and lower limit for the number of
# spare servers which should be available. If the number of spare servers
# falls below MinSpareServers then new ones will be created. If the number
# of servers exceeds MaxSpareServers then the extras will be killed off.
#
MinSpareServers 5
MaxSpareServers 20
#
# Number of servers to start initially.
#
StartServers 10
#
# MaxRequestsPerChild is the number of connections a thread will handle
# before it is killed. In practise this should be set to 0, which disables
# thread reaping. If you do notice problems with memory leakage, then set
# this to something like 10000
#
MaxRequestsPerChild 0
#
# The following is the authorization controls. If there are any access
# control keywords then the default action is to DENY. Otherwise, the
# default action is ALLOW.
#
# Also the order of the controls are important. The incoming connections
# are tested against the controls based on order.
#
Allow 127.0.0.1
Allow 192.168.1.0/25
#
# Control whether the HTTP Via header should be included in requests or
# responses. The RFC says it should be there, but it could be a security
# concern. The default is off.
#
#ViaHeader On
#
# The location of the filter file.
#
#Filter "/etc/tinyproxy/filter"
#
# Filter based on URLs rather than domains.
#
#FilterURLs On
#
# Use POSIX Extended regular expressions rather than basic.
#
#FilterExtended On
#
# Change the default policy of the filtering system. If this directive is
# commented out, or is set to "No" then the default policy is to allow everything
# which is not specifically denied by the filter file.
#
# However, by setting this directive to "Yes" the default policy becomes to
# deny everything which is _not_ specifically allowed by the filter file.
#
#FilterDefaultDeny Yes
#
# If an Anonymous keyword is present, then anonymous proxying is enabled.
# The headers listed are allowed through, while all others are denied. If
# no Anonymous keyword is present, then all header are allowed through.
# You must include quotes around the headers.
#
#Anonymous "Host"
#Anonymous "Authorization"
#
# This is a list of ports allowed by tinyproxy when the CONNECT method
# is used. To disable the CONNECT method altogether, set the value to 0.
# If no ConnectPort line is found, all ports are allowed (which is not
# very secure.)
#
# The following two ports are used by SSL.
#
ConnectPort 443
ConnectPort 563
+3
View File
@@ -0,0 +1,3 @@
Makefile
Makefile.in
report.sh
+9
View File
@@ -0,0 +1,9 @@
SUBDIRS = \
man5 \
man8
EXTRA_DIST = \
http-error-codes.txt \
http-rfcs.txt \
filter-howto.txt
File renamed without changes.
File renamed without changes.
View File
File renamed without changes.
+3
View File
@@ -0,0 +1,3 @@
*.5
*.xml
*.txt
+20
View File
@@ -0,0 +1,20 @@
MAN5_FILES = \
tinyproxy.conf.txt
A2X_ARGS = \
-d manpage \
-f manpage
man_MANS = \
$(MAN5_FILES:.txt=.5)
.txt.5:
if HAVE_A2X
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
else
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
endif
CLEANFILES = \
$(MAN5_FILES:.txt=.5) \
$(MAN5_FILES:.txt=.xml)
+370
View File
@@ -0,0 +1,370 @@
TINYPROXY.CONF(5)
=================
:man source: Version @VERSION@
:man manual: Tinyproxy manual
NAME
----
tinyproxy.conf - Tinyproxy HTTP proxy daemon configuration file
SYNOPSIS
--------
*tinyproxy.conf*
DESCRIPTION
-----------
`tinyproxy(8)` reads its configuration file, typically stored in
`/etc/tinyproxy/tinyproxy.conf` (or passed to Tinyproxy with -c on the
command line). This manpage describes the syntax and contents of the
configuration file.
The Tinyproxy configuration file contains key-value pairs, one per
line. Lines starting with `#` and empty lines are comments and are
ignored. Keywords are case-insensitive, whereas values are
case-sensitive. Values may be enclosed in double-quotes (") if they
contain spaces.
The possible keywords and their descriptions are as follows:
*User*::
The user which the Tinyproxy process should run as, after the
initial port-binding has been done as the `root` user. Either the
user name or the UID may be specified.
*Group*::
The group which the Tinyproxy process should run as, after the
initial port-binding has been done as the `root` user. Either the
group name or the GID may be specified.
*Port*::
The port which the Tinyproxy service will listen on. If the port is
less than 1024, you will need to start the Tinyproxy process as the
`root` user.
*Listen*::
By default, Tinyproxy listens for connections on all available
interfaces (i.e. it listens on the wildcard address `0.0.0.0`).
With this configuration parameter, Tinyproxy can be told to listen
only on one specific address.
*Bind*::
This allows you to specify which address Tinyproxy will bind
to for outgoing connections to web servers or upstream proxies.
*BindSame*::
If this boolean parameter is set to `yes`, then Tinyproxy will
bind the outgoing connection to the IP address of the incoming
connection that triggered the outgoing request.
*Timeout*::
The maximum number of seconds of inactivity a connection is
allowed to have before it is closed by Tinyproxy.
*ErrorFile*::
This parameter controls which HTML file Tinyproxy returns when a
given HTTP error occurs. It takes two arguments, the error number
and the location of the HTML error file.
*DefaultErrorFile*::
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*::
This configures the HTML file that Tinyproxy sends when
a request for the stathost is received. If this parameter is
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.
Examples are "\{cause}" for an abbreviated error description and
"\{detail}" for a detailed error message. The `tinyproxy(8)`
manual page contains a description of all template variables.
*LogFile*::
This controls the location of the file to which Tinyproxy
writes its debug output. Alternatively, Tinyproxy can log
to syslog -- see the Syslog option.
*Syslog*::
When set to `On`, this option tells Tinyproxy to write its
debug messages to syslog instead of to a log file configured
with `LogFile`. These two options are mutually exclusive.
*LogLevel*::
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
* Warning
* Notice
* Connect (log connections without Info's noise)
* Info (most verbose)
*PidFile*::
This option controls the location of the file where the main
Tinyproxy process stores its process ID for signaling purposes.
*XTinyproxy*::
Setting this option to `Yes` tells Tinyproxy to add a header
`X-Tinyproxy` containing the client's IP address to the request.
*Upstream*::
*No Upstream*::
This option allows you to set up a set of rules for deciding
whether an upstream proxy server is to be used, based on the
host or domain of the site being accessed. The rules are stored
in the order encountered in the configuration file and the
LAST matching rule wins. There are three possible forms for
specifying upstream rules:
* 'upstream host:port' turns proxy upstream support on generally.
* 'upstream host:port "site_spec"' turns on the upstream proxy for
the sites matching `site_spec`.
* 'no upstream "site_spec"' turns off upstream support for sites
matching `site_spec`.
The site can be specified in various forms as a hostname, domain
name or as an IP range:
* 'name' matches host exactly
* '.name' matches any host in domain "name"
* '.' matches any host with no domain (in 'empty' domain)
* 'IP/bits' matches network/mask
* 'IP/mask' matches network/mask
*MaxClients*::
Tinyproxy creates one child process for each connected client.
This options specifies the absolute highest number processes that
will be created. With other words, only MaxClients clients can be
connected to Tinyproxy simultaneously.
*MinSpareServers*::
*MaxSpareServers*::
Tinyproxy always keeps a certain number of idle child processes
so that it can handle new incoming client requests quickly.
`MinSpareServer` and `MaxSpareServers` control the lower and upper
limits for the number of spare processes. I.e. when the number of
spare servers drops below `MinSpareServers` then Tinyproxy will
start forking new spare processes in the background and when the
number of spare processes exceeds `MaxSpareServers` then Tinyproxy
will kill off extra processes.
*StartServers*::
The number of servers to start initially. This should usually be
set to a value between MinSpareServers and MaxSpareServers.
*MaxRequestsPerChild*::
This limits the number of connections that a child process
will handle before it is killed. The default value is `0`
which disables this feature. This option is meant as an
emergency measure in the case of problems with memory leakage.
In that case, setting `MaxRequestsPerChild` to a value of e.g.
1000, or 10000 can be useful.
*Allow*::
*Deny*::
The `Allow` and `Deny` options provide a means to customize
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 `Allow` or `Deny` lines, then all clients are
allowed. Otherwise, the default action is to deny access.
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, 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
domains. This option specifies the location of the file
containing the filter rules, one rule per line.
*FilterURLs*::
If this boolean option is set to `Yes` or `On`, filtering is
performed for URLs rather than for domains. The default is to
filter based on domains.
*FilterExtended*::
If this boolean option is set to `Yes`, then extended POSIX
regular expressions are used for matching the filter rules.
The default is to use basic POSIX regular expressions.
*FilterCaseSensitive*::
If this boolean option is set to `Yes`, then the filter rules
are matched in a case sensitive manner. The default is to
match case-insensitively.
*FilterDefaultDeny*::
The default filtering policy is to allow everything that is
not matched by a filtering rule. Setting `FilterDefaultDeny`
to `Yes` changes the policy do deny everything but the domains
or URLs matched by the filtering rules.
*Anonymous*::
If an `Anonymous` keyword is present, then anonymous proxying
is enabled. The headers listed with `Anonymous` are allowed
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.
+
Example:
+
----
Anonymous "Host"
Anonymous "Authorization"
Anonymous "Cookie"
----
*ConnectPort*::
This option can be used to specify the ports allowed for the
CONNECT method. If no `ConnectPort` line is found, then all
ports are allowed. To disable CONNECT altogether, include a
single ConnectPort line with a value of `0`.
*ReversePath*::
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/"
----
*ReverseOnly*::
When using Tinyproxy as a reverse proxy, it is STRONGLY
recommended that the normal proxy is turned off by setting
this boolean option to `Yes`.
*ReverseMagic*::
Setting this option to `Yes`, makes Tinyproxy use a cookie to
track reverse proxy mappings. If you need to reverse proxy
sites which have absolute links you must use this option.
*ReverseBaseURL*::
The URL that is used to access this reverse proxy. The URL is
used to rewrite HTTP redirects so that they won't escape the
proxy. If you have a chain of reverse proxies, you'll need to
put the outermost URL here (the address which the end user
types into his/her browser). If this option is not set then
no rewriting of redirects occurs.
BUGS
----
To report bugs in Tinyproxy, please visit
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
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-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
information.
+3
View File
@@ -0,0 +1,3 @@
*.8
*.xml
*.txt
+20
View File
@@ -0,0 +1,20 @@
MAN8_FILES = \
tinyproxy.txt
A2X_ARGS = \
-d manpage \
-f manpage
man_MANS = \
$(MAN8_FILES:.txt=.8)
.txt.8:
if HAVE_A2X
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
else
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
endif
CLEANFILES = \
$(MAN8_FILES:.txt=.8) \
$(MAN8_FILES:.txt=.xml)
+163
View File
@@ -0,0 +1,163 @@
TINYPROXY(8)
============
:man source: Version @VERSION@
:man manual: Tinyproxy manual
NAME
----
tinyproxy - A light-weight HTTP proxy daemon
SYNOPSIS
--------
*tinyproxy* [-vldch]
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.
OPTIONS
-------
*tinyproxy* accepts the following options:
*-c <config-file>*::
Use an alternate configuration file.
*-d*::
Don't daemonize and stay in the foreground. Useful for debugging purposes.
*-h*::
Display a short help screen of command line arguments and exit.
*-l*::
Display the licensing agreement.
*-v*::
Display version information and exit.
SIGNALS
-------
In addition to command-line options, there are also several signals that
can be sent to *tinyproxy* while it is running to generate debugging
information and to force certain events.
*SIGHUP*::
Force Tinyproxy to do a garbage collection on the current
connections linked list. This is usually done automatically after a
certain number of connections have been handled.
TEMPLATE FILES
--------------
There are two occasions when Tinyproxy delivers HTML pages to
the client on it's own right:
. When an error occurred, a corresponding error page is returned.
. When a request for the stathost is made, a page summarizing the
connection statistics is returned. (See STATHOST below.)
The layout of both error pages and the statistics page can be
controlled via configurable HTML template files that are plain
HTML files that additionally understand a few template
variables.
TEMPLATE VARIABLES
------------------
There are several standard HTML variables that are available in every
template file:
*request*::
The full HTTP request line.
*cause*::
The abbreviated cause of the error condition.
*clientip*::
The IP address of the client making the request.
*clienthost*::
The hostname of the client making the request.
*version*::
The version of Tinyproxy.
*package*::
The package name. Presently, resolves to 'tinyproxy'.
*date*::
The current date/time in HTTP format.
In addition, almost all templates support:
*detail*::
A detailed, plain English explanation of the error and possible
causes.
When Tinyproxy finds a variable name enclosed in braces, e.g.
"\{request}", then this is replaced by the value of the corresponding
variable before delivery of the page.
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_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`.
FILES
-----
`/etc/tinyproxy/tinyproxy.conf`, `/var/run/tinyproxy/tinyproxy.pid`, `/var/log/tinyproxy/tinyproxy.log`
BUGS
----
To report bugs in Tinyproxy, please visit
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
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-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
information.
+1
View File
@@ -0,0 +1 @@
tinyproxy.conf
+23
View File
@@ -0,0 +1,23 @@
sysconf_DATA = \
tinyproxy.conf
EXTRA_DIST = \
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
+330
View File
@@ -0,0 +1,330 @@
##
## tinyproxy.conf -- tinyproxy daemon configuration file
##
## This example tinyproxy.conf file contains example settings
## with explanations in comments. For decriptions of all
## parameters, see the tinproxy.conf(5) manual page.
##
#
# User/Group: This allows you to set the user and group that will be
# used for tinyproxy after the initial binding to the port has been done
# as the root user. Either the user or group name or the UID or GID
# number may be used.
#
User nobody
Group nobody
#
# Port: Specify the port which tinyproxy will listen on. Please note
# that should you choose to run on a port lower than 1024 you will need
# to start tinyproxy using root.
#
Port 8888
#
# Listen: If you have multiple interfaces this allows you to bind to
# only one. If this is commented out, tinyproxy will bind to all
# interfaces present.
#
#Listen 192.168.0.1
#
# Bind: This allows you to specify which interface will be used for
# outgoing connections. This is useful for multi-home'd machines where
# you want all traffic to appear outgoing from one particular interface.
#
#Bind 192.168.0.1
#
# BindSame: If enabled, tinyproxy will bind the outgoing connection to the
# ip address of the incoming connection.
#
#BindSame yes
#
# Timeout: The maximum number of seconds of inactivity a connection is
# allowed to have before it is closed by tinyproxy.
#
Timeout 600
#
# ErrorFile: Defines the HTML file to send when a given HTTP error
# occurs. You will probably need to customize the location to your
# particular install. The usual locations to check are:
# /usr/local/share/tinyproxy
# /usr/share/tinyproxy
# /etc/tinyproxy
#
#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 "@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 "@pkgdatadir@/stats.html"
#
# LogFile: Allows you to specify the location where information should
# be logged to. If you would prefer to log to syslog, then disable this
# and enable the Syslog directive. These directives are mutually
# exclusive.
#
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
#
# Syslog: Tell tinyproxy to use syslog instead of a logfile. This
# option must not be enabled if the Logfile directive is being used.
# These two directives are mutually exclusive.
#
#Syslog On
#
# LogLevel:
#
# Set the logging level. Allowed settings are:
# Critical (least verbose)
# Error
# Warning
# Notice
# Connect (to 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, then all log messages from Warning to
# Critical would be output, but Notice and below would be suppressed.
#
LogLevel Info
#
# PidFile: Write the PID of the main tinyproxy thread to this file so it
# can be used for signalling purposes.
#
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
#
# XTinyproxy: Tell Tinyproxy to include the X-Tinyproxy header, which
# contains the client's IP address.
#
#XTinyproxy Yes
#
# Upstream:
#
# Turns on upstream proxy support.
#
# The upstream rules allow you to selectively route upstream connections
# based on the host/domain of the site being accessed.
#
# For example:
# # connection to test domain goes through testproxy
# upstream testproxy:8008 ".test.domain.invalid"
# upstream testproxy:8008 ".our_testbed.example.com"
# upstream testproxy:8008 "192.168.128.0/255.255.254.0"
#
# # no upstream proxy for internal websites and unqualified hosts
# no upstream ".internal.example.com"
# no upstream "www.example.com"
# no upstream "10.0.0.0/8"
# no upstream "192.168.0.0/255.255.254.0"
# no upstream "."
#
# # connection to these boxes go through their DMZ firewalls
# upstream cust1_firewall:8008 "testbed_for_cust1"
# upstream cust2_firewall:8008 "testbed_for_cust2"
#
# # default upstream is internet firewall
# upstream firewall.internal.example.com:80
#
# The LAST matching rule wins the route decision. As you can see, you
# can use a host, or a domain:
# name matches host exactly
# .name matches any host in domain "name"
# . matches any host with no domain (in 'empty' domain)
# IP/bits matches network/mask
# IP/mask matches network/mask
#
#Upstream some.remote.proxy:port
#
# MaxClients: This is the absolute highest number of threads which will
# be created. In other words, only MaxClients number of clients can be
# connected at the same time.
#
MaxClients 100
#
# MinSpareServers/MaxSpareServers: These settings set the upper and
# lower limit for the number of spare servers which should be available.
#
# If the number of spare servers falls below MinSpareServers then new
# server processes will be spawned. If the number of servers exceeds
# MaxSpareServers then the extras will be killed off.
#
MinSpareServers 5
MaxSpareServers 20
#
# StartServers: The number of servers to start initially.
#
StartServers 10
#
# MaxRequestsPerChild: The number of connections a thread will handle
# before it is killed. In practise this should be set to 0, which
# disables thread reaping. If you do notice problems with memory
# leakage, then set this to something like 10000.
#
MaxRequestsPerChild 0
#
# Allow: Customization of authorization controls. If there are any
# access control keywords then the default action is to DENY. Otherwise,
# the default action is ALLOW.
#
# The order of the controls are important. All incoming connections are
# tested against the controls based on order.
#
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
# is enabled, the string supplied will be used as the host name in the
# Via header; otherwise, the server's host name will be used.
#
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 "@sysconfdir@/filter"
#
# FilterURLs: Filter based on URLs rather than domains.
#
#FilterURLs On
#
# FilterExtended: Use POSIX Extended regular expressions rather than
# basic.
#
#FilterExtended On
#
# FilterCaseSensitive: Use case sensitive regular expressions.
#
#FilterCaseSensitive On
#
# FilterDefaultDeny: Change the default policy of the filtering system.
# If this directive is commented out, or is set to "No" then the default
# policy is to allow everything which is not specifically denied by the
# filter file.
#
# However, by setting this directive to "Yes" the default policy becomes
# to deny everything which is _not_ specifically allowed by the filter
# file.
#
#FilterDefaultDeny Yes
#
# Anonymous: If an Anonymous keyword is present, then anonymous proxying
# is enabled. The headers listed are allowed 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.
#
#Anonymous "Host"
#Anonymous "Authorization"
#Anonymous "Cookie"
#
# ConnectPort: This is a list of ports allowed by tinyproxy when the
# CONNECT method is used. To disable the CONNECT method altogether, set
# the value to 0. If no ConnectPort line is found, all ports are
# allowed (which is not very secure.)
#
# The following two ports are used by SSL.
#
ConnectPort 443
ConnectPort 563
#
# 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 Google using
# http://localhost:8888/google/ and Wired News using
# http://localhost:8888/wired/news/. Neither will actually work
# until you uncomment ReverseMagic as they use absolute linking.
#
#ReversePath "/google/" "http://www.google.com/"
#ReversePath "/wired/" "http://www.wired.com/"
#
# When using tinyproxy as a reverse proxy, it is STRONGLY recommended
# that the normal proxy is turned off by uncommenting the next directive.
#
#ReverseOnly Yes
#
# Use a cookie to track reverse proxy mappings. If you need to reverse
# proxy sites which have absolute links you must uncomment this.
#
#ReverseMagic Yes
#
# The URL that's used to access this reverse proxy. The URL is used to
# rewrite HTTP redirects so that they won't escape the proxy. If you
# have a chain of reverse proxies, you'll need to put the outermost
# URL here (the address which the end user types into his/her browser).
#
# If not set then no rewriting occurs.
#
#ReverseBaseURL "http://localhost:8888/"
+4
View File
@@ -0,0 +1,4 @@
EXTRA_DIST = \
as-compiler-flag.m4 \
argenable.m4 \
typecheck.m4
+19
View File
@@ -0,0 +1,19 @@
dnl $Id: argenable.m4,v 1.1 2004-08-24 18:40:21 rjkaes Exp $
dnl
dnl Define a new AC_ARG_ENABLE like macro which handles invalid inputs
dnl correctly. The macro takes three arguments:
dnl 1) the option name (used like --enable-option)
dnl 2) the help string
dnl 3) the default value (either yes or no)
dnl
dnl This macro also defines on variable in the form "option_enabled"
dnl set to either "yes" or "no".
dnl
AC_DEFUN([TP_ARG_ENABLE],
[AC_ARG_ENABLE([$1],
AS_HELP_STRING([--enable-$1], [$2]),
[case "${enableval}" in
yes) $1_enabled=yes ;;
no) $1_enabled=no ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-$1]) ;;
esac],[$1_enabled=$3])])
+64
View File
@@ -0,0 +1,64 @@
dnl as-compiler-flag.m4 0.1.0
dnl autostars m4 macro for detection of compiler flags
dnl David Schleef <ds@schleef.org>
dnl Tim-Philipp Müller <tim centricular net>
dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
dnl Tries to compile with the given CFLAGS.
dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
dnl and ACTION-IF-NOT-ACCEPTED otherwise.
AC_DEFUN([AS_COMPILER_FLAG],
[
AC_MSG_CHECKING([to see if compiler understands $1])
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $1"
AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
CFLAGS="$save_CFLAGS"
if test "X$flag_ok" = Xyes ; then
$2
true
else
$3
true
fi
AC_MSG_RESULT([$flag_ok])
])
dnl AS_CXX_COMPILER_FLAG(CPPFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
dnl Tries to compile with the given CPPFLAGS.
dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
dnl and ACTION-IF-NOT-ACCEPTED otherwise.
AC_DEFUN([AS_CXX_COMPILER_FLAG],
[
AC_REQUIRE([AC_PROG_CXX])
AC_MSG_CHECKING([to see if c++ compiler understands $1])
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $1"
AC_LANG_PUSH(C++)
AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
CPPFLAGS="$save_CPPFLAGS"
if test "X$flag_ok" = Xyes ; then
$2
true
else
$3
true
fi
AC_LANG_POP(C++)
AC_MSG_RESULT([$flag_ok])
])
File renamed without changes.
+7
View File
@@ -0,0 +1,7 @@
.deps
.libs
Makefile
Makefile.in
tinyproxy
*.o
*.pcno
+26 -28
View File
@@ -1,55 +1,53 @@
# $Id: Makefile.am,v 1.14 2002-05-26 18:56:43 rjkaes Exp $ # tinyproxy - A fast light-weight HTTP proxy
# Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
# #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# #
# Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com) # 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.,
# This program is free software; you can redistribute it and/or modify it # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, 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.
#
YFLAGS = @YFLAGS@
LDFLAGS = @LDFLAGS@
sbin_PROGRAMS = tinyproxy sbin_PROGRAMS = tinyproxy
AM_CPPFLAGS = \
-DSYSCONFDIR=\"${sysconfdir}\" \
-DLOCALSTATEDIR=\"${localstatedir}\"
tinyproxy_SOURCES = \ tinyproxy_SOURCES = \
acl.c acl.h \ acl.c acl.h \
anonymous.c anonymous.h \ anonymous.c anonymous.h \
buffer.c buffer.h \ buffer.c buffer.h \
child.c child.h \ child.c child.h \
common.h \ common.h \
conf.c conf.h \
conns.c conns.h \ conns.c conns.h \
daemon.c daemon.h \ daemon.c daemon.h \
hashmap.c hashmap.h \ hashmap.c hashmap.h \
heap.c heap.h \ heap.c heap.h \
html-error.c html-error.h \
http-message.c http-message.h \
log.c log.h \ log.c log.h \
network.c network.h \ network.c network.h \
reqs.c reqs.h \ reqs.c reqs.h \
sock.c sock.h \ sock.c sock.h \
stats.c stats.h \ stats.c stats.h \
text.c text.h \ text.c text.h \
tinyproxy.c tinyproxy.h \ main.c main.h \
utils.c utils.h \ utils.c utils.h \
vector.c vector.h \ vector.c vector.h \
grammar.y scanner.l \ upstream.c upstream.h \
regexp.h connect-ports.c connect-ports.h
EXTRA_DIST = gnuregex.c gnuregex.h EXTRA_tinyproxy_SOURCES = filter.c filter.h \
EXTRA_tinyproxy_SOURCES = filter.c filter.h grammar.h reverse-proxy.c reverse-proxy.h \
transparent-proxy.c transparent-proxy.h
tinyproxy_DEPENDENCIES = @ADDITIONAL_OBJECTS@ tinyproxy_DEPENDENCIES = @ADDITIONAL_OBJECTS@
tinyproxy_LDADD = @ADDITIONAL_OBJECTS@ tinyproxy_LDADD = @ADDITIONAL_OBJECTS@
scanner.c: scanner.l grammar.h
$(LEX) $(AM_LFLAGS) $(LFLAGS) -i $< && mv $(LEX_OUTPUT_ROOT).c $@
clean:
rm -f *.da
rm -f gmon.out
+278 -160
View File
@@ -1,49 +1,128 @@
/* $Id: acl.c,v 1.16 2002-06-05 16:59:21 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2000, 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This system handles Access Control for use of this daemon. A list of * This program is free software; you can redistribute it and/or modify
* domains, or IP addresses (including IP blocks) are stored in a list * it under the terms of the GNU General Public License as published by
* which is then used to compare incoming connections. * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* *
* Copyright (C) 2000,2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
#include "tinyproxy.h" /* This system handles Access Control for use of this daemon. A list of
* domains, or IP addresses (including IP blocks) are stored in a list
* which is then used to compare incoming connections.
*/
#include "main.h"
#include "acl.h" #include "acl.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "network.h"
#include "sock.h" #include "sock.h"
#include "vector.h"
struct acl_s { #include <limits.h>
acl_access_t acl_access;
enum { ACL_STRING, ACL_NUMERIC } type; /* Define how long an IPv6 address is in bytes (128 bits, 16 bytes) */
char *location; #define IPV6_LEN 16
int netmask;
struct acl_s *next; enum acl_type {
ACL_STRING,
ACL_NUMERIC
}; };
static struct acl_s *access_list = NULL; /*
* Hold the information about a particular access control. We store
* whether it's an ALLOW or DENY entry, and also whether it's a string
* entry (like a domain name) or an IP entry.
*/
struct acl_s {
acl_access_t access;
enum acl_type type;
union {
char *string;
struct {
unsigned char octet[IPV6_LEN];
unsigned char mask[IPV6_LEN];
} ip;
} address;
};
/* /*
* Take a netmask number (between 0 and 32) and returns a network ordered * Fills in the netmask array given a numeric value.
* value for comparison. *
* Returns:
* 0 on success
* -1 on failure (invalid mask value)
*
*/ */
static in_addr_t static int
make_netmask(int netmask_num) fill_netmask_array (char *bitmask_string, int v6,
unsigned char array[], size_t len)
{ {
assert(netmask_num >= 0 && netmask_num <= 32); unsigned int i;
unsigned long int mask;
char *endptr;
return htonl(~((1 << (32 - netmask_num)) - 1)); errno = 0; /* to distinguish success/failure after call */
mask = strtoul (bitmask_string, &endptr, 10);
/* check for various conversion errors */
if ((errno == ERANGE && mask == ULONG_MAX)
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
return -1;
if (v6 == 0) {
/* The mask comparison is done as an IPv6 address, so
* convert to a longer mask in the case of IPv4
* addresses. */
mask += 12 * 8;
}
/* check valid range for a bit mask */
if (mask > (8 * len))
return -1;
/* we have a valid range to fill in the array */
for (i = 0; i != len; ++i) {
if (mask >= 8) {
array[i] = 0xff;
mask -= 8;
} else if (mask > 0) {
array[i] = (unsigned char) (0xff << (8 - mask));
mask = 0;
} else {
array[i] = 0;
}
}
return 0;
}
/**
* If the access list has not been set up, create it.
*/
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;
} }
/* /*
@@ -55,81 +134,75 @@ make_netmask(int netmask_num)
* -1 on failure * -1 on failure
* 0 otherwise. * 0 otherwise.
*/ */
int int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
insert_acl(char *location, acl_access_t access_type)
{ {
size_t i; struct acl_s acl;
struct acl_s **rev_acl_ptr, *acl_ptr, *new_acl_ptr; int ret;
char *nptr; char *p, ip_dst[IPV6_LEN];
assert (location != NULL); assert (location != NULL);
/* ret = init_access_list(access_list);
* First check to see if the location is a string or numeric. if (ret != 0) {
*/
for (i = 0; location[i] != '\0'; i++) {
/*
* Numeric strings can not contain letters, so test on it.
*/
if (isalpha((unsigned char) location[i])) {
break;
}
}
/*
* Add a new ACL to the list.
*/
rev_acl_ptr = &access_list;
acl_ptr = access_list;
while (acl_ptr) {
rev_acl_ptr = &acl_ptr->next;
acl_ptr = acl_ptr->next;
}
new_acl_ptr = safemalloc(sizeof(struct acl_s));
if (!new_acl_ptr) {
return -1; return -1;
} }
new_acl_ptr->acl_access = access_type; /*
* Start populating the access control structure.
if (location[i] == '\0') { */
DEBUG2("ACL \"%s\" is a number.", location); memset (&acl, 0, sizeof (struct acl_s));
acl.access = access_type;
/* /*
* We did not break early, so this a numeric location. * Check for a valid IP address (the simplest case) first.
* Check for a netmask.
*/ */
new_acl_ptr->type = ACL_NUMERIC; if (full_inet_pton (location, ip_dst) > 0) {
nptr = strchr(location, '/'); acl.type = ACL_NUMERIC;
if (nptr) { memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
*nptr++ = '\0'; memset (acl.address.ip.mask, 0xff, IPV6_LEN);
new_acl_ptr->netmask = strtol(nptr, NULL, 10);
if (new_acl_ptr->netmask < 0
|| new_acl_ptr->netmask > 32) {
safefree(new_acl_ptr);
return -1;
}
} else { } else {
new_acl_ptr->netmask = 32; /*
} * At this point we're either a hostname or an
* IP address with a slash.
*/
p = strchr (location, '/');
if (p != NULL) {
char dst[sizeof(struct in6_addr)];
int v6;
/*
* We have a slash, so it's intended to be an
* IP address with mask
*/
*p = '\0';
if (full_inet_pton (location, ip_dst) <= 0)
return -1;
acl.type = ACL_NUMERIC;
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
/* Check if the IP address before the netmask is
* an IPv6 address */
if (inet_pton(AF_INET6, location, dst) > 0)
v6 = 1;
else
v6 = 0;
if (fill_netmask_array
(p + 1, v6, &(acl.address.ip.mask[0]), IPV6_LEN)
< 0)
return -1;
} else { } else {
DEBUG2("ACL \"%s\" is a string.", location); /* In all likelihood a string */
acl.type = ACL_STRING;
new_acl_ptr->type = ACL_STRING; acl.address.string = safestrdup (location);
new_acl_ptr->netmask = 32; if (!acl.address.string)
}
new_acl_ptr->location = safestrdup(location);
if (!new_acl_ptr->location) {
safefree(new_acl_ptr);
return -1; return -1;
} }
}
*rev_acl_ptr = new_acl_ptr; ret = vector_append (*access_list, &acl, sizeof (struct acl_s));
new_acl_ptr->next = acl_ptr; return ret;
return 0;
} }
/* /*
@@ -141,48 +214,55 @@ insert_acl(char *location, acl_access_t access_type)
* 1 if host is allowed * 1 if host is allowed
* -1 if no tests match, so skip * -1 if no tests match, so skip
*/ */
static inline int static int
acl_string_processing(struct acl_s* aclptr, acl_string_processing (struct acl_s *acl,
const char* ip_address, const char *ip_address, const char *string_address)
const char* string_address)
{ {
int i; int match;
struct hostent* result; struct addrinfo hints, *res, *ressave;
size_t test_length, match_length; size_t test_length, match_length;
char ipbuf[512];
assert (acl && acl->type == ACL_STRING);
assert (ip_address && strlen (ip_address) > 0);
assert (string_address && strlen (string_address) > 0);
/* /*
* If the first character of the ACL string is a period, we need to * If the first character of the ACL string is a period, we need to
* do a string based test only; otherwise, we can do a reverse * do a string based test only; otherwise, we can do a reverse
* lookup test as well. * lookup test as well.
*/ */
if (aclptr->location[0] != '.') { if (acl->address.string[0] != '.') {
/* It is not a partial domain, so do a reverse lookup. */ memset (&hints, 0, sizeof (struct addrinfo));
result = gethostbyname(aclptr->location); hints.ai_family = AF_UNSPEC;
if (!result) hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo (acl->address.string, NULL, &hints, &res) != 0)
goto STRING_TEST; goto STRING_TEST;
for (i = 0; result->h_addr_list[i]; ++i) { ressave = res;
if (strcmp(ip_address,
inet_ntoa(*((struct in_addr*)result->h_addr_list[i]))) == 0) { match = FALSE;
/* We have a match */ do {
if (aclptr->acl_access == ACL_DENY) { get_ip_string (res->ai_addr, ipbuf, sizeof (ipbuf));
if (strcmp (ip_address, ipbuf) == 0) {
match = TRUE;
break;
}
} while ((res = res->ai_next) != NULL);
freeaddrinfo (ressave);
if (match) {
if (acl->access == ACL_DENY)
return 0; return 0;
} else { else
DEBUG2("Matched using reverse domain lookup: %s", ip_address);
return 1; return 1;
} }
} }
}
/*
* If we got this far, the reverse didn't match, so drop down
* to a standard string test.
*/
}
STRING_TEST: STRING_TEST:
test_length = strlen (string_address); test_length = strlen (string_address);
match_length = strlen(aclptr->location); match_length = strlen (acl->address.string);
/* /*
* If the string length is shorter than AC string, return a -1 so * If the string length is shorter than AC string, return a -1 so
@@ -191,8 +271,10 @@ STRING_TEST:
if (test_length < match_length) if (test_length < match_length)
return -1; return -1;
if (strcasecmp(string_address + (test_length - match_length), aclptr->location) == 0) { if (strcasecmp
if (aclptr->acl_access == ACL_DENY) (string_address + (test_length - match_length),
acl->address.string) == 0) {
if (acl->access == ACL_DENY)
return 0; return 0;
else else
return 1; return 1;
@@ -203,75 +285,111 @@ STRING_TEST:
} }
/* /*
* Checks whether file descriptor is allowed. * Compare the supplied numeric IP address with the supplied ACL structure.
*
* Return:
* 1 IP address is allowed
* 0 IP address is denied
* -1 neither allowed nor denied.
*/
static int check_numeric_acl (const struct acl_s *acl, const char *ip)
{
uint8_t addr[IPV6_LEN], x, y;
int i;
assert (acl && acl->type == ACL_NUMERIC);
assert (ip && strlen (ip) > 0);
if (full_inet_pton (ip, &addr) <= 0)
return -1;
for (i = 0; i != IPV6_LEN; ++i) {
x = addr[i] & acl->address.ip.mask[i];
y = acl->address.ip.octet[i] & acl->address.ip.mask[i];
/* If x and y don't match, the IP addresses don't match */
if (x != y)
return -1;
}
/* The addresses match, return the permission */
return (acl->access == ACL_ALLOW);
}
/*
* Checks whether a connection is allowed.
* *
* Returns: * Returns:
* 1 if allowed * 1 if allowed
* 0 if denied * 0 if denied
*/ */
int int check_acl (const char *ip, const char *host, vector_t access_list)
check_acl(int fd, const char* ip_address, const char* string_address)
{ {
struct acl_s* aclptr; struct acl_s *acl;
int ret; int perm = 0;
size_t i;
assert(fd >= 0); assert (ip != NULL);
assert(ip_address != NULL); assert (host != NULL);
assert(string_address != NULL);
/* /*
* If there is no access list allow everything. * If there is no access list allow everything.
*/ */
aclptr = access_list; if (!access_list)
if (!aclptr)
return 1; return 1;
while (aclptr) { for (i = 0; i != (size_t) vector_length (access_list); ++i) {
if (aclptr->type == ACL_STRING) { acl = (struct acl_s *) vector_getentry (access_list, i, NULL);
ret = acl_string_processing(aclptr, switch (acl->type) {
ip_address, case ACL_STRING:
string_address); perm = acl_string_processing (acl, ip, host);
if (ret == 0) break;
goto UNAUTHORIZED;
else if (ret == 1)
return 1;
aclptr = aclptr->next; case ACL_NUMERIC:
if (ip[0] == '\0')
continue; continue;
} else { perm = check_numeric_acl (acl, ip);
struct in_addr test_addr, match_addr; break;
in_addr_t netmask_addr;
if (ip_address[0] == 0) {
aclptr = aclptr->next;
continue;
}
inet_aton(ip_address, &test_addr);
inet_aton(aclptr->location, &match_addr);
netmask_addr = make_netmask(aclptr->netmask);
if ((test_addr.s_addr & netmask_addr) ==
(match_addr.s_addr & netmask_addr)) {
if (aclptr->acl_access == ACL_DENY)
goto UNAUTHORIZED;
else
return 1;
}
} }
/* /*
* Dropped through... go on to the next one. * Check the return value too see if the IP address is
* allowed or denied.
*/ */
aclptr = aclptr->next; if (perm == 0)
break;
else if (perm == 1)
return perm;
} }
/* /*
* Deny all connections by default. * Deny all connections by default.
*/ */
UNAUTHORIZED:
log_message (LOG_NOTICE, "Unauthorized connection from \"%s\" [%s].", log_message (LOG_NOTICE, "Unauthorized connection from \"%s\" [%s].",
string_address, ip_address); host, ip);
return 0; 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);
}
+22 -14
View File
@@ -1,26 +1,34 @@
/* $Id: acl.h,v 1.3 2002-04-17 20:52:45 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'acl.c' for detailed information. * 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.
* *
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'acl.c' for detailed information. */
#ifndef TINYPROXY_ACL_H #ifndef TINYPROXY_ACL_H
#define TINYPROXY_ACL_H #define TINYPROXY_ACL_H
#include "vector.h"
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t; typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
extern int insert_acl(char *location, acl_access_t access_type); extern int insert_acl (char *location, acl_access_t access_type,
extern int check_acl(int fd, const char* ip_address, const char* string_address); 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 #endif
+30 -30
View File
@@ -1,47 +1,48 @@
/* $Id: anonymous.c,v 1.14 2002-05-23 18:20:27 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* Handles insertion and searches for headers which should be let through when * This program is free software; you can redistribute it and/or modify
* the anonymous feature is turned on. * 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.
* *
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
#include "tinyproxy.h" /* Handles insertion and searches for headers which should be let through
* when the anonymous feature is turned on.
*/
#include "main.h"
#include "anonymous.h" #include "anonymous.h"
#include "hashmap.h" #include "hashmap.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "conf.h"
static hashmap_t anonymous_map = NULL; short int is_anonymous_enabled (void)
short int
is_anonymous_enabled(void)
{ {
return (anonymous_map != NULL) ? 1 : 0; return (config.anonymous_map != NULL) ? 1 : 0;
} }
/* /*
* Search for the header. This function returns a positive value greater than * Search for the header. This function returns a positive value greater than
* zero if the string was found, zero if it wasn't and negative upon error. * zero if the string was found, zero if it wasn't and negative upon error.
*/ */
int int anonymous_search (const char *s)
anonymous_search(char *s)
{ {
assert (s != NULL); 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);
} }
/* /*
@@ -50,24 +51,23 @@ anonymous_search(char *s)
* Return -1 if there is an error, otherwise a 0 is returned if the insert was * Return -1 if there is an error, otherwise a 0 is returned if the insert was
* successful. * successful.
*/ */
int int anonymous_insert (const char *s)
anonymous_insert(char *s)
{ {
char data = 1; char data = 1;
assert (s != NULL); assert (s != NULL);
if (!anonymous_map) { if (!config.anonymous_map) {
anonymous_map = hashmap_create(32); config.anonymous_map = hashmap_create (32);
if (!anonymous_map) if (!config.anonymous_map)
return -1; 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. */ /* The key was already found, so return a positive number. */
return 0; return 0;
} }
/* Insert the new key */ /* Insert the new key */
return hashmap_insert(anonymous_map, s, &data, sizeof(data)); return hashmap_insert (config.anonymous_map, s, &data, sizeof (data));
} }
+17 -14
View File
@@ -1,25 +1,28 @@
/* $Id: anonymous.h,v 1.6 2001-12-15 20:08:24 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'anonymous.c' for a detailed description. * 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.
* *
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'anonymous.c' for detailed information. */
#ifndef _TINYPROXY_ANONYMOUS_H_ #ifndef _TINYPROXY_ANONYMOUS_H_
#define _TINYPROXY_ANONYMOUS_H_ #define _TINYPROXY_ANONYMOUS_H_
extern short int is_anonymous_enabled (void); extern short int is_anonymous_enabled (void);
extern int anonymous_search(char *s); extern int anonymous_search (const char *s);
extern int anonymous_insert(char *s); extern int anonymous_insert (const char *s);
#endif #endif
+56 -49
View File
@@ -1,27 +1,31 @@
/* $Id: buffer.c,v 1.22 2002-05-24 04:45:32 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1999, 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* The buffer used in each connection is a linked list of lines. As the lines * 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.
*/
/* The buffer used in each connection is a linked list of lines. As the lines
* are read in and written out the buffer expands and contracts. Basically, * are read in and written out the buffer expands and contracts. Basically,
* by using this method we can increase the buffer size dynamically. However, * by using this method we can increase the buffer size dynamically. However,
* we have a hard limit of 64 KB for the size of the buffer. The buffer can be * we have a hard limit of 64 KB for the size of the buffer. The buffer can be
* thought of as a queue were we act on both the head and tail. The various * thought of as a queue were we act on both the head and tail. The various
* functions act on each end (the names are taken from what Perl uses to act on * functions act on each end (the names are taken from what Perl uses to act on
* the ends of an array. :) * the ends of an array. :)
*
* Copyright (C) 1999,2001 Robert James Kaes (rjkaes@users.sourceforge.net)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "buffer.h" #include "buffer.h"
#include "heap.h" #include "heap.h"
@@ -52,18 +56,19 @@ struct buffer_s {
* to the buffer. The data IS copied, so make sure if you allocated your * to the buffer. The data IS copied, so make sure if you allocated your
* data buffer on the heap, delete it because you now have TWO copies. * data buffer on the heap, delete it because you now have TWO copies.
*/ */
static struct bufline_s * static struct bufline_s *makenewline (unsigned char *data, size_t length)
makenewline(unsigned char *data, size_t length)
{ {
struct bufline_s *newline; struct bufline_s *newline;
assert (data != NULL); assert (data != NULL);
assert (length > 0); assert (length > 0);
if (!(newline = safemalloc(sizeof(struct bufline_s)))) newline = (struct bufline_s *) safemalloc (sizeof (struct bufline_s));
if (!newline)
return NULL; return NULL;
if (!(newline->string = safemalloc(length))) { newline->string = (unsigned char *) safemalloc (length);
if (!newline->string) {
safefree (newline); safefree (newline);
return NULL; return NULL;
} }
@@ -82,8 +87,7 @@ makenewline(unsigned char *data, size_t length)
/* /*
* Free the allocated buffer line * Free the allocated buffer line
*/ */
static void static void free_line (struct bufline_s *line)
free_line(struct bufline_s *line)
{ {
assert (line != NULL); assert (line != NULL);
@@ -99,12 +103,12 @@ free_line(struct bufline_s *line)
/* /*
* Create a new buffer * Create a new buffer
*/ */
struct buffer_s * struct buffer_s *new_buffer (void)
new_buffer(void)
{ {
struct buffer_s *buffptr; struct buffer_s *buffptr;
if (!(buffptr = safemalloc(sizeof(struct buffer_s)))) buffptr = (struct buffer_s *) safemalloc (sizeof (struct buffer_s));
if (!buffptr)
return NULL; return NULL;
/* /*
@@ -121,8 +125,7 @@ new_buffer(void)
/* /*
* Delete all the lines in the buffer and the buffer itself * Delete all the lines in the buffer and the buffer itself
*/ */
void void delete_buffer (struct buffer_s *buffptr)
delete_buffer(struct buffer_s *buffptr)
{ {
struct bufline_s *next; struct bufline_s *next;
@@ -148,8 +151,7 @@ size_t buffer_size(struct buffer_s *buffptr)
/* /*
* Push a new line on to the end of the buffer. * Push a new line on to the end of the buffer.
*/ */
int int add_to_buffer (struct buffer_s *buffptr, unsigned char *data, size_t length)
add_to_buffer(struct buffer_s *buffptr, unsigned char *data, size_t length)
{ {
struct bufline_s *newline; struct bufline_s *newline;
@@ -187,8 +189,7 @@ add_to_buffer(struct buffer_s *buffptr, unsigned char *data, size_t length)
/* /*
* Remove the first line from the top of the buffer * Remove the first line from the top of the buffer
*/ */
static struct bufline_s * static struct bufline_s *remove_from_buffer (struct buffer_s *buffptr)
remove_from_buffer(struct buffer_s *buffptr)
{ {
struct bufline_s *line; struct bufline_s *line;
@@ -208,11 +209,10 @@ remove_from_buffer(struct buffer_s *buffptr)
* Takes a connection and returns the number of bytes read. * Takes a connection and returns the number of bytes read.
*/ */
#define READ_BUFFER_SIZE (1024 * 2) #define READ_BUFFER_SIZE (1024 * 2)
ssize_t ssize_t read_buffer (int fd, struct buffer_s * buffptr)
read_buffer(int fd, struct buffer_s * buffptr)
{ {
ssize_t bytesin; ssize_t bytesin;
unsigned char buffer[READ_BUFFER_SIZE]; unsigned char *buffer;
assert (fd >= 0); assert (fd >= 0);
assert (buffptr != NULL); assert (buffptr != NULL);
@@ -223,20 +223,22 @@ read_buffer(int fd, struct buffer_s * buffptr)
if (buffptr->size >= MAXBUFFSIZE) if (buffptr->size >= MAXBUFFSIZE)
return 0; return 0;
buffer = (unsigned char *) safemalloc (READ_BUFFER_SIZE);
if (!buffer) {
return -ENOMEM;
}
bytesin = read (fd, buffer, READ_BUFFER_SIZE); bytesin = read (fd, buffer, READ_BUFFER_SIZE);
if (bytesin > 0) { if (bytesin > 0) {
if (add_to_buffer (buffptr, buffer, bytesin) < 0) { if (add_to_buffer (buffptr, buffer, bytesin) < 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"readbuff: add_to_buffer() error."); "readbuff: add_to_buffer() error.");
return -1; bytesin = -1;
} }
} else if (bytesin == 0) {
return bytesin;
} else {
if (bytesin == 0) {
/* connection was closed by client */ /* connection was closed by client */
return -1; bytesin = -1;
} else { } else {
switch (errno) { switch (errno) {
#ifdef EWOULDBLOCK #ifdef EWOULDBLOCK
@@ -247,23 +249,26 @@ read_buffer(int fd, struct buffer_s * buffptr)
# endif # endif
#endif #endif
case EINTR: case EINTR:
return 0; bytesin = 0;
break;
default: default:
log_message (LOG_ERR, log_message (LOG_ERR,
"readbuff: recv() error \"%s\" on file descriptor %d", "read_buffer: read() failed on fd %d: %s",
strerror(errno), fd); fd, strerror(errno));
return -1; bytesin = -1;
} break;
} }
} }
safefree (buffer);
return bytesin;
} }
/* /*
* Write the bytes in the buffer to the socket. * Write the bytes in the buffer to the socket.
* Takes a connection and returns the number of bytes written. * Takes a connection and returns the number of bytes written.
*/ */
ssize_t ssize_t write_buffer (int fd, struct buffer_s * buffptr)
write_buffer(int fd, struct buffer_s * buffptr)
{ {
ssize_t bytessent; ssize_t bytessent;
struct bufline_s *line; struct bufline_s *line;
@@ -279,7 +284,8 @@ write_buffer(int fd, struct buffer_s * buffptr)
line = BUFFER_HEAD (buffptr); line = BUFFER_HEAD (buffptr);
bytessent = bytessent =
send(fd, line->string + line->pos, line->length - line->pos, MSG_NOSIGNAL); send (fd, line->string + line->pos, line->length - line->pos,
MSG_NOSIGNAL);
if (bytessent >= 0) { if (bytessent >= 0) {
/* bytes sent, adjust buffer */ /* bytes sent, adjust buffer */
@@ -301,8 +307,9 @@ write_buffer(int fd, struct buffer_s * buffptr)
case ENOBUFS: case ENOBUFS:
case ENOMEM: case ENOMEM:
log_message (LOG_ERR, log_message (LOG_ERR,
"writebuff: write() error [NOBUFS/NOMEM] \"%s\" on file descriptor %d", "writebuff: write() error [NOBUFS/NOMEM] \"%s\" on "
strerror(errno), fd); "file descriptor %d", strerror (errno),
fd);
return 0; return 0;
default: default:
log_message (LOG_ERR, log_message (LOG_ERR,
+15 -12
View File
@@ -1,20 +1,23 @@
/* $Id: buffer.h,v 1.8 2002-05-14 00:43:38 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'buffer.c' for a detailed description. * 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.
* *
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'buffer.c' for detailed information. */
#ifndef _TINYPROXY_BUFFER_H_ #ifndef _TINYPROXY_BUFFER_H_
#define _TINYPROXY_BUFFER_H_ #define _TINYPROXY_BUFFER_H_
+254 -79
View File
@@ -1,22 +1,26 @@
/* $Id: child.c,v 1.7 2002-11-21 21:54:09 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* Handles the creation/destruction of the various children required for * This program is free software; you can redistribute it and/or modify
* processing incoming connections. * 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.
* *
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
#include "tinyproxy.h" /* Handles the creation/destruction of the various children required for
* processing incoming connections.
*/
#include "main.h"
#include "child.h" #include "child.h"
#include "daemon.h" #include "daemon.h"
@@ -26,17 +30,18 @@
#include "reqs.h" #include "reqs.h"
#include "sock.h" #include "sock.h"
#include "utils.h" #include "utils.h"
#include "conf.h"
static int listenfd; static vector_t listen_fds;
static socklen_t addrlen;
/* /*
* Stores the internal data needed for each child (connection) * Stores the internal data needed for each child (connection)
*/ */
enum child_status_t { T_EMPTY, T_WAITING, T_CONNECTED };
struct child_s { struct child_s {
pid_t tid; pid_t tid;
unsigned int connects; unsigned int connects;
enum { T_EMPTY, T_WAITING, T_CONNECTED } status; enum child_status_t status;
}; };
/* /*
@@ -50,7 +55,7 @@ static struct child_config_s {
unsigned int maxspareservers, minspareservers, startservers; unsigned int maxspareservers, minspareservers, startservers;
} child_config; } child_config;
static int* servers_waiting; /* servers waiting for a connection */ static unsigned int *servers_waiting; /* servers waiting for a connection */
/* /*
* Lock/Unlock the "servers_waiting" variable so that two children cannot * Lock/Unlock the "servers_waiting" variable so that two children cannot
@@ -68,11 +73,15 @@ static int* servers_waiting; /* servers waiting for a connection */
static struct flock lock_it, unlock_it; static struct flock lock_it, unlock_it;
static int lock_fd = -1; static int lock_fd = -1;
static void static void _child_lock_init (void)
_child_lock_init(void)
{ {
char lock_file[] = "/tmp/tinyproxy.servers.lock.XXXXXX"; char lock_file[] = "/tmp/tinyproxy.servers.lock.XXXXXX";
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask (0177);
lock_fd = mkstemp (lock_file); lock_fd = mkstemp (lock_file);
unlink (lock_file); unlink (lock_file);
@@ -87,8 +96,7 @@ _child_lock_init(void)
unlock_it.l_len = 0; unlock_it.l_len = 0;
} }
static void static void _child_lock_wait (void)
_child_lock_wait(void)
{ {
int rc; int rc;
@@ -100,8 +108,7 @@ _child_lock_wait(void)
} }
} }
static void static void _child_lock_release (void)
_child_lock_release(void)
{ {
if (fcntl (lock_fd, F_SETLKW, &unlock_it) < 0) if (fcntl (lock_fd, F_SETLKW, &unlock_it) < 0)
return; return;
@@ -118,6 +125,7 @@ _child_lock_release(void)
#define SERVER_DEC() do { \ #define SERVER_DEC() do { \
SERVER_COUNT_LOCK(); \ SERVER_COUNT_LOCK(); \
assert(*servers_waiting > 0); \
--(*servers_waiting); \ --(*servers_waiting); \
DEBUG2("DEC: servers_waiting: %d", *servers_waiting); \ DEBUG2("DEC: servers_waiting: %d", *servers_waiting); \
SERVER_COUNT_UNLOCK(); \ SERVER_COUNT_UNLOCK(); \
@@ -126,8 +134,7 @@ _child_lock_release(void)
/* /*
* Set the configuration values for the various child related settings. * Set the configuration values for the various child related settings.
*/ */
short int short int child_configure (child_config_t type, unsigned int val)
child_configure(child_config_t type, unsigned int val)
{ {
switch (type) { switch (type) {
case CHILD_MAXCLIENTS: case CHILD_MAXCLIENTS:
@@ -153,17 +160,39 @@ child_configure(child_config_t type, unsigned int val)
return 0; 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. * This is the main (per child) loop.
*/ */
static void static void child_main (struct child_s *ptr)
child_main(struct child_s* ptr)
{ {
int connfd; int connfd;
struct sockaddr *cliaddr; struct sockaddr *cliaddr;
socklen_t clilen; socklen_t clilen;
fd_set rfds;
int maxfd = 0;
ssize_t i;
int ret;
cliaddr = safemalloc(addrlen); cliaddr = (struct sockaddr *)
safemalloc (sizeof(struct sockaddr_storage));
if (!cliaddr) { if (!cliaddr) {
log_message (LOG_CRIT, log_message (LOG_CRIT,
"Could not allocate memory for child address."); "Could not allocate memory for child address.");
@@ -171,21 +200,105 @@ child_main(struct child_s* ptr)
} }
ptr->connects = 0; ptr->connects = 0;
srand(time(NULL));
/*
* We have to wait for connections on multiple fds,
* so use select.
*/
FD_ZERO(&rfds);
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
ret = socket_nonblocking(*fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the listening "
"socket %d to non-blocking: %s",
fd, strerror(errno));
exit(1);
}
FD_SET(*fd, &rfds);
maxfd = max(maxfd, *fd);
}
while (!config.quit) { while (!config.quit) {
int listenfd = -1;
ptr->status = T_WAITING; ptr->status = T_WAITING;
clilen = addrlen; clilen = sizeof(struct sockaddr_storage);
ret = select(maxfd + 1, &rfds, NULL, NULL, NULL);
if (ret == -1) {
log_message (LOG_ERR, "error calling select: %s",
strerror(errno));
exit(1);
} else if (ret == 0) {
log_message (LOG_WARNING, "Strange: select returned 0 "
"but we did not specify a timeout...");
continue;
}
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
if (FD_ISSET(*fd, &rfds)) {
/*
* only accept the connection on the first
* fd that we find readable. - fair?
*/
listenfd = *fd;
break;
}
}
if (listenfd == -1) {
log_message(LOG_WARNING, "Strange: None of our listen "
"fds was readable after select");
continue;
}
ret = socket_blocking(listenfd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set listening "
"socket %d to blocking for accept: %s",
listenfd, strerror(errno));
exit(1);
}
/*
* We have a socket that is readable.
* Continue handling this connection.
*/
connfd = accept (listenfd, cliaddr, &clilen); connfd = accept (listenfd, cliaddr, &clilen);
DEBUG2("Process %u has accepted connection", ptr->tid); #ifndef NDEBUG
/*
* Enable the TINYPROXY_DEBUG environment variable if you
* want to use the GDB debugger.
*/
if (getenv ("TINYPROXY_DEBUG")) {
/* Pause for 10 seconds to allow us to connect debugger */
fprintf (stderr,
"Process has accepted connection: %ld\n",
(long int) ptr->tid);
sleep (10);
fprintf (stderr, "Continuing process: %ld\n",
(long int) ptr->tid);
}
#endif
/* /*
* Make sure no error occurred... * Make sure no error occurred...
*/ */
if (connfd < 0) { if (connfd < 0) {
log_message(LOG_ERR, "Accept returned an error (%s) ... retrying.", strerror(errno)); log_message (LOG_ERR,
"Accept returned an error (%s) ... retrying.",
strerror (errno));
continue; continue;
} }
@@ -194,16 +307,15 @@ child_main(struct child_s* ptr)
SERVER_DEC (); SERVER_DEC ();
handle_connection (connfd); handle_connection (connfd);
if (child_config.maxrequestsperchild != 0) {
ptr->connects++; ptr->connects++;
if (child_config.maxrequestsperchild != 0) {
DEBUG2 ("%u connections so far...", ptr->connects); DEBUG2 ("%u connections so far...", ptr->connects);
if (ptr->connects == child_config.maxrequestsperchild - 1) { if (ptr->connects == child_config.maxrequestsperchild) {
log_message (LOG_NOTICE, log_message (LOG_NOTICE,
"Child has reached MaxRequestsPerChild (%u). Killing child.", "Child has reached MaxRequestsPerChild (%u). "
ptr->connects); "Killing child.", ptr->connects);
break; break;
} }
} }
@@ -215,8 +327,10 @@ child_main(struct child_s* ptr)
* off. * off.
*/ */
log_message (LOG_NOTICE, log_message (LOG_NOTICE,
"Waiting servers (%d) exceeds MaxSpareServers (%d). Killing child.", "Waiting servers (%d) exceeds MaxSpareServers (%d). "
*servers_waiting, child_config.maxspareservers); "Killing child.",
*servers_waiting,
child_config.maxspareservers);
SERVER_COUNT_UNLOCK (); SERVER_COUNT_UNLOCK ();
break; break;
@@ -237,8 +351,7 @@ child_main(struct child_s* ptr)
* Fork a child "child" (or in our case a process) and then start up the * Fork a child "child" (or in our case a process) and then start up the
* child_main() function. * child_main() function.
*/ */
static int static pid_t child_make (struct child_s *ptr)
child_make(struct child_s* ptr)
{ {
pid_t pid; pid_t pid;
@@ -250,7 +363,7 @@ child_make(struct child_s* ptr)
*/ */
set_signal_handler (SIGCHLD, SIG_DFL); set_signal_handler (SIGCHLD, SIG_DFL);
set_signal_handler (SIGTERM, 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 */ child_main (ptr); /* never returns */
return -1; return -1;
@@ -259,8 +372,7 @@ child_make(struct child_s* ptr)
/* /*
* Create a pool of children to handle incoming connections * Create a pool of children to handle incoming connections
*/ */
short int short int child_pool_create (void)
child_pool_create(void)
{ {
unsigned int i; unsigned int i;
@@ -271,25 +383,31 @@ child_pool_create(void)
*/ */
if (child_config.maxclients == 0) { if (child_config.maxclients == 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"child_pool_create: \"MaxClients\" must be greater than zero."); "child_pool_create: \"MaxClients\" must be "
"greater than zero.");
return -1; return -1;
} }
if (child_config.startservers == 0) { if (child_config.startservers == 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"child_pool_create: \"StartServers\" must be greater than zero."); "child_pool_create: \"StartServers\" must be "
"greater than zero.");
return -1; return -1;
} }
child_ptr = calloc_shared_memory(child_config.maxclients, child_ptr =
(struct child_s *) calloc_shared_memory (child_config.maxclients,
sizeof (struct child_s)); sizeof (struct child_s));
if (!child_ptr) { if (!child_ptr) {
log_message(LOG_ERR, "Could not allocate memory for children."); log_message (LOG_ERR,
"Could not allocate memory for children.");
return -1; return -1;
} }
servers_waiting = malloc_shared_memory(sizeof(int)); servers_waiting =
(unsigned int *) malloc_shared_memory (sizeof (unsigned int));
if (servers_waiting == MAP_FAILED) { if (servers_waiting == MAP_FAILED) {
log_message(LOG_ERR, "Could not allocate memory for child counting."); log_message (LOG_ERR,
"Could not allocate memory for child counting.");
return -1; return -1;
} }
*servers_waiting = 0; *servers_waiting = 0;
@@ -302,18 +420,20 @@ child_pool_create(void)
if (child_config.startservers > child_config.maxclients) { if (child_config.startservers > child_config.maxclients) {
log_message (LOG_WARNING, log_message (LOG_WARNING,
"Can not start more than \"MaxClients\" servers. Starting %u servers instead.", "Can not start more than \"MaxClients\" servers. "
"Starting %u servers instead.",
child_config.maxclients); child_config.maxclients);
child_config.startservers = child_config.maxclients; child_config.startservers = child_config.maxclients;
} }
for (i = 0; i < child_config.maxclients; i++) { for (i = 0; i != child_config.maxclients; i++) {
child_ptr[i].status = T_EMPTY; child_ptr[i].status = T_EMPTY;
child_ptr[i].connects = 0; child_ptr[i].connects = 0;
} }
for (i = 0; i < child_config.startservers; i++) { for (i = 0; i != child_config.startservers; i++) {
DEBUG2("Trying to create child %d of %d", i + 1, child_config.startservers); DEBUG2 ("Trying to create child %d of %d", i + 1,
child_config.startservers);
child_ptr[i].status = T_WAITING; child_ptr[i].status = T_WAITING;
child_ptr[i].tid = child_make (&child_ptr[i]); child_ptr[i].tid = child_make (&child_ptr[i]);
@@ -340,10 +460,9 @@ child_pool_create(void)
* Keep the proper number of servers running. This is the birth of the * Keep the proper number of servers running. This is the birth of the
* servers. It monitors this at least once a second. * servers. It monitors this at least once a second.
*/ */
void void child_main_loop (void)
child_main_loop(void)
{ {
int i; unsigned int i;
while (1) { while (1) {
if (config.quit) if (config.quit)
@@ -353,15 +472,18 @@ child_main_loop(void)
SERVER_COUNT_LOCK (); SERVER_COUNT_LOCK ();
if (*servers_waiting < child_config.minspareservers) { if (*servers_waiting < child_config.minspareservers) {
log_message (LOG_NOTICE, log_message (LOG_NOTICE,
"Waiting servers (%d) is less than MinSpareServers (%d). Creating new child.", "Waiting servers (%d) is less than MinSpareServers (%d). "
*servers_waiting, child_config.minspareservers); "Creating new child.",
*servers_waiting,
child_config.minspareservers);
SERVER_COUNT_UNLOCK (); SERVER_COUNT_UNLOCK ();
for (i = 0; i < child_config.maxclients; i++) { for (i = 0; i != child_config.maxclients; i++) {
if (child_ptr[i].status == T_EMPTY) { if (child_ptr[i].status == T_EMPTY) {
child_ptr[i].status = T_WAITING; child_ptr[i].status = T_WAITING;
child_ptr[i].tid = child_make(&child_ptr[i]); child_ptr[i].tid =
child_make (&child_ptr[i]);
if (child_ptr[i].tid < 0) { if (child_ptr[i].tid < 0) {
log_message (LOG_NOTICE, log_message (LOG_NOTICE,
"Could not create child"); "Could not create child");
@@ -383,16 +505,19 @@ child_main_loop(void)
/* Handle log rotation if it was requested */ /* Handle log rotation if it was requested */
if (received_sighup) { 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 #ifdef FILTER_ENABLE
if (config.filter) { filter_reload ();
filter_destroy();
filter_init();
}
log_message(LOG_NOTICE, "Re-reading filter file.");
#endif /* FILTER_ENABLE */ #endif /* FILTER_ENABLE */
/* propagate filter reload to all children */
child_kill_children (SIGHUP);
received_sighup = FALSE; received_sighup = FALSE;
} }
} }
@@ -401,26 +526,76 @@ child_main_loop(void)
/* /*
* Go through all the non-empty children and cancel them. * Go through all the non-empty children and cancel them.
*/ */
void void child_kill_children (int sig)
child_kill_children(void)
{ {
int i; unsigned int i;
for (i = 0; i < child_config.maxclients; i++) { for (i = 0; i != child_config.maxclients; i++) {
if (child_ptr[i].status != T_EMPTY) if (child_ptr[i].status != T_EMPTY)
kill(child_ptr[i].tid, SIGTERM); kill (child_ptr[i].tid, sig);
} }
} }
int
child_listening_sock(uint16_t port) /**
* Listen on the various configured interfaces
*/
int child_listening_sockets(vector_t listen_addrs, uint16_t port)
{ {
listenfd = listen_sock(port, &addrlen); int ret;
return listenfd; ssize_t i;
assert (port > 0);
if (listen_fds == NULL) {
listen_fds = vector_create();
if (listen_fds == NULL) {
log_message (LOG_ERR, "Could not create the list "
"of listening fds");
return -1;
}
} }
void if ((listen_addrs == NULL) ||
child_close_sock(void) (vector_length(listen_addrs) == 0))
{ {
close(listenfd); /*
* no Listen directive:
* listen on the wildcard address(es)
*/
ret = listen_sock(NULL, port, listen_fds);
return ret;
}
for (i = 0; i < vector_length(listen_addrs); i++) {
const char *addr;
addr = (char *)vector_getentry(listen_addrs, i, NULL);
if (addr == NULL) {
log_message(LOG_WARNING,
"got NULL from listen_addrs - skipping");
continue;
}
ret = listen_sock(addr, port, listen_fds);
if (ret != 0) {
return ret;
}
}
return 0;
}
void child_close_sock (void)
{
ssize_t i;
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
close (*fd);
}
vector_delete(listen_fds);
listen_fds = NULL;
} }
+19 -14
View File
@@ -1,23 +1,28 @@
/* $Id: child.h,v 1.1 2002-05-26 18:45:26 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'child.c' for more information. * 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.
* *
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'child.c' for detailed information. */
#ifndef TINYPROXY_CHILD_H #ifndef TINYPROXY_CHILD_H
#define TINYPROXY_CHILD_H #define TINYPROXY_CHILD_H
#include "vector.h"
typedef enum { typedef enum {
CHILD_MAXCLIENTS, CHILD_MAXCLIENTS,
CHILD_MAXSPARESERVERS, CHILD_MAXSPARESERVERS,
@@ -27,10 +32,10 @@ typedef enum {
} child_config_t; } child_config_t;
extern short int child_pool_create (void); extern short int child_pool_create (void);
extern int child_listening_sock(uint16_t port); extern int child_listening_sockets (vector_t listen_addrs, uint16_t port);
extern void child_close_sock (void); extern void child_close_sock (void);
extern void child_main_loop (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); extern short int child_configure (child_config_t type, unsigned int val);
+33 -23
View File
@@ -1,21 +1,25 @@
/* $Id: common.h,v 1.3 2002-12-04 17:06:13 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This file groups all the headers required throughout the tinyproxy * This program is free software; you can redistribute it and/or modify
* system. All this information use to be in the "tinyproxy.h" header, * it under the terms of the GNU General Public License as published by
* but since dnsserver.c also needs these headers, so it's been moved into * the Free Software Foundation; either version 2 of the License, or
* this file. * (at your option) any later version.
* *
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* later version. */
*
* This program is distributed in the hope that it will be useful, but /* This file groups all the headers required throughout the tinyproxy
* WITHOUT ANY WARRANTY; without even the implied warranty of * system. All this information use to be in the "main.h" header,
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * but various other "libraries" in the program need the same information,
* General Public License for more details. * without the tinyproxy specific defines.
*/ */
#ifndef COMMON_HEADER_H #ifndef COMMON_HEADER_H
@@ -31,6 +35,9 @@
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#ifdef HAVE_VALUES_H
# include <values.h>
#endif
#ifdef HAVE_INTTYPES_H #ifdef HAVE_INTTYPES_H
# include <inttypes.h> # include <inttypes.h>
#endif #endif
@@ -54,20 +61,16 @@
# include <sys/stat.h> # include <sys/stat.h>
#endif #endif
#ifdef HAVE_SYS_TIME_H #ifdef TIME_WITH_SYS_TIME
# include <sys/time.h> # include <sys/time.h>
# ifdef HAVE_TIME_H
# include <time.h> # include <time.h>
# endif
#else #else
# ifdef HAVE_SYS_TIME_H # ifdef HAVE_SYS_TIME_H
# include <sys/time.h> # include <sys/time.h>
# else # else
# ifdef HAVE_TIME_H
# include <time.h> # include <time.h>
# endif # endif
#endif #endif
#endif
#ifdef HAVE_SYS_RESOURCE_H #ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h> # include <sys/resource.h>
@@ -115,6 +118,9 @@
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
# include <pwd.h> # include <pwd.h>
#endif #endif
#ifdef HAVE_REGEX_H
# include <regex.h>
#endif
#ifdef HAVE_SIGNAL_H #ifdef HAVE_SIGNAL_H
# include <signal.h> # include <signal.h>
#endif #endif
@@ -146,9 +152,6 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#ifdef HAVE_VFORK_H
# include <vfork.h>
#endif
#ifdef HAVE_WCHAR_H #ifdef HAVE_WCHAR_H
# include <wchar.h> # include <wchar.h>
#endif #endif
@@ -175,6 +178,13 @@
#define MAXLISTEN 1024 /* Max number of connections */ #define MAXLISTEN 1024 /* Max number of connections */
/*
* SunOS doesn't have INADDR_NONE defined.
*/
#ifndef INADDR_NONE
# define INADDR_NONE -1
#endif
/* Define boolean values */ /* Define boolean values */
#ifndef FALSE #ifndef FALSE
# define FALSE 0 # define FALSE 0
+1112
View File
File diff suppressed because it is too large. Load diff
+120
View File
@@ -0,0 +1,120 @@
/* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'conf.c' for detailed information. */
#ifndef TINYPROXY_CONF_H
#define TINYPROXY_CONF_H
#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 */
unsigned int port;
char *stathost;
unsigned int godaemon; /* boolean */
unsigned int quit; /* boolean */
char *user;
char *group;
vector_t listen_addrs;
#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);
int config_compile_regex (void);
#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_ */
+45 -21
View File
@@ -1,24 +1,28 @@
/* $Id: conns.c,v 1.13 2002-11-13 17:47:40 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* Create and free the connection structure. One day there could be * 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.
*/
/* Create and free the connection structure. One day there could be
* other connection related tasks put here, but for now the header * other connection related tasks put here, but for now the header
* file and this file are only used for create/free functions and the * file and this file are only used for create/free functions and the
* connection structure definition. * connection structure definition.
*
* Copyright (C) 2001 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "buffer.h" #include "buffer.h"
#include "conns.h" #include "conns.h"
@@ -26,8 +30,9 @@
#include "log.h" #include "log.h"
#include "stats.h" #include "stats.h"
struct conn_s * struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
initialize_conn(int client_fd, const char* ipaddr, const char* string_addr) const char *string_addr,
const char *sock_ipaddr)
{ {
struct conn_s *connptr; struct conn_s *connptr;
struct buffer_s *cbuffer, *sbuffer; struct buffer_s *cbuffer, *sbuffer;
@@ -46,7 +51,7 @@ initialize_conn(int client_fd, const char* ipaddr, const char* string_addr)
/* /*
* Allocate the space for the conn_s structure itself. * Allocate the space for the conn_s structure itself.
*/ */
connptr = safemalloc(sizeof(struct conn_s)); connptr = (struct conn_s *) safemalloc (sizeof (struct conn_s));
if (!connptr) if (!connptr)
goto error_exit; goto error_exit;
@@ -59,6 +64,7 @@ initialize_conn(int client_fd, const char* ipaddr, const char* string_addr)
connptr->request_line = NULL; connptr->request_line = NULL;
/* These store any error strings */ /* These store any error strings */
connptr->error_variables = NULL;
connptr->error_string = NULL; connptr->error_string = NULL;
connptr->error_number = -1; connptr->error_number = -1;
@@ -67,13 +73,22 @@ initialize_conn(int client_fd, const char* ipaddr, const char* string_addr)
connptr->protocol.major = connptr->protocol.minor = 0; connptr->protocol.major = connptr->protocol.minor = 0;
connptr->remote_content_length = -1; /* There is _no_ content length initially */
connptr->content_length.server = connptr->content_length.client = -1;
connptr->server_ip_addr = (sock_ipaddr ?
safestrdup (sock_ipaddr) : NULL);
connptr->client_ip_addr = safestrdup (ipaddr); connptr->client_ip_addr = safestrdup (ipaddr);
connptr->client_string_addr = safestrdup (string_addr); connptr->client_string_addr = safestrdup (string_addr);
connptr->upstream_proxy = NULL;
update_stats (STAT_OPEN); update_stats (STAT_OPEN);
#ifdef REVERSE_SUPPORT
connptr->reversepath = NULL;
#endif
return connptr; return connptr;
error_exit: error_exit:
@@ -88,8 +103,7 @@ error_exit:
return NULL; return NULL;
} }
void void destroy_conn (struct conn_s *connptr)
destroy_conn(struct conn_s *connptr)
{ {
assert (connptr != NULL); assert (connptr != NULL);
@@ -110,14 +124,24 @@ destroy_conn(struct conn_s *connptr)
if (connptr->request_line) if (connptr->request_line)
safefree (connptr->request_line); safefree (connptr->request_line);
if (connptr->error_variables)
hashmap_delete (connptr->error_variables);
if (connptr->error_string) if (connptr->error_string)
safefree (connptr->error_string); safefree (connptr->error_string);
if (connptr->server_ip_addr)
safefree (connptr->server_ip_addr);
if (connptr->client_ip_addr) if (connptr->client_ip_addr)
safefree (connptr->client_ip_addr); safefree (connptr->client_ip_addr);
if (connptr->client_string_addr) if (connptr->client_string_addr)
safefree (connptr->client_string_addr); safefree (connptr->client_string_addr);
#ifdef REVERSE_SUPPORT
if (connptr->reversepath)
safefree (connptr->reversepath);
#endif
safefree (connptr); safefree (connptr);
update_stats (STAT_CLOSE); update_stats (STAT_CLOSE);
+47 -17
View File
@@ -1,24 +1,28 @@
/* $Id: conns.h,v 1.11 2002-12-04 17:06:13 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'conns.c' for a detailed description. * 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.
* *
* Copyright (C) 2001 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'conns.c' for detailed information. */
#ifndef TINYPROXY_CONNS_H #ifndef TINYPROXY_CONNS_H
#define TINYPROXY_CONNS_H #define TINYPROXY_CONNS_H
#include "tinyproxy.h" #include "main.h"
#include "hashmap.h"
/* /*
* Connection Definition * Connection Definition
@@ -37,12 +41,25 @@ struct conn_s {
unsigned int connect_method; unsigned int connect_method;
unsigned int show_stats; unsigned int show_stats;
/* Store the error response if there is one */ /*
char *error_string; * This structure stores key -> value mappings for substitution
* in the error HTML files.
*/
hashmap_t error_variables;
int error_number; int error_number;
char *error_string;
/* A Content-Length value from the remote server */ /* A Content-Length value from the remote server */
long remote_content_length; struct {
long int server;
long int client;
} content_length;
/*
* Store the server's IP (for BindSame)
*/
char *server_ip_addr;
/* /*
* Store the client's IP and hostname information * Store the client's IP and hostname information
@@ -57,13 +74,26 @@ struct conn_s {
unsigned int major; unsigned int major;
unsigned int minor; unsigned int minor;
} protocol; } protocol;
#ifdef REVERSE_SUPPORT
/*
* Place to store the current per-connection reverse proxy path
*/
char *reversepath;
#endif
/*
* Pointer to upstream proxy.
*/
struct upstream *upstream_proxy;
}; };
/* /*
* Functions for the creation and destruction of a connection structure. * Functions for the creation and destruction of a connection structure.
*/ */
extern struct conn_s *initialize_conn (int client_fd, const char *ipaddr, extern struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
const char* string_addr); const char *string_addr,
const char *sock_ipaddr);
extern void destroy_conn (struct conn_s *connptr); extern void destroy_conn (struct conn_s *connptr);
#endif #endif
+33 -22
View File
@@ -1,32 +1,36 @@
/* $Id: daemon.c,v 1.2 2002-10-03 20:38:06 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This file contains functions which are useful when writing a * This program is free software; you can redistribute it and/or modify
* daemon process. The functions include a "makedaemon" function and * it under the terms of the GNU General Public License as published by
* a function to portably set a signal handler. * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* *
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
#include "tinyproxy.h" /* This file contains functions which are useful when writing a
* daemon process. The functions include a "makedaemon" function and
* a function to portably set a signal handler.
*/
#include "main.h"
#include "daemon.h" #include "daemon.h"
#include "log.h"
/* /*
* Fork a child process and then kill the parent so make the calling * Fork a child process and then kill the parent so make the calling
* program a daemon process. * program a daemon process.
*/ */
void void makedaemon (void)
makedaemon(void)
{ {
if (fork () != 0) if (fork () != 0)
exit (0); exit (0);
@@ -37,10 +41,18 @@ makedaemon(void)
if (fork () != 0) if (fork () != 0)
exit (0); exit (0);
chdir("/"); if (chdir ("/") != 0) {
umask(077); log_message (LOG_WARNING,
"Could not change directory to /");
}
#if 0 umask (0177);
#ifdef NDEBUG
/*
* When not in debugging mode, close the standard file
* descriptors.
*/
close (0); close (0);
close (1); close (1);
close (2); close (2);
@@ -51,8 +63,7 @@ makedaemon(void)
* Pass a signal number and a signal handling function into this function * Pass a signal number and a signal handling function into this function
* to handle signals sent to the process. * to handle signals sent to the process.
*/ */
signal_func * signal_func *set_signal_handler (int signo, signal_func * func)
set_signal_handler(int signo, signal_func *func)
{ {
struct sigaction act, oact; struct sigaction act, oact;
+15 -12
View File
@@ -1,20 +1,23 @@
/* $Id: daemon.h,v 1.1 2002-05-23 04:39:32 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'daemon.c' for a detailed description. * 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.
* *
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'daemon.c' for detailed information. */
#ifndef TINYPROXY_DAEMON_H #ifndef TINYPROXY_DAEMON_H
#define TINYPROXY_DAEMON_H #define TINYPROXY_DAEMON_H
+87 -56
View File
@@ -1,30 +1,34 @@
/* $Id: filter.c,v 1.15 2002-10-03 20:40:39 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1999 George Talusan <gstalusan@uwaterloo.ca>
* Copyright (C) 2002 James E. Flemer <jflemer@acm.jhu.edu>
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca) * This program is free software; you can redistribute it and/or modify
* Copyright (c) 2002 James E. Flemer (jflemer@acm.jhu.edu) * it under the terms of the GNU General Public License as published by
* Copyright (c) 2002 Robert James Kaes (rjkaes@flarenet.com) * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* *
* A substring of the domain to be filtered goes into the file * This program is distributed in the hope that it will be useful,
* pointed at by DEFAULT_FILTER. * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
#include "tinyproxy.h" /* A substring of the domain to be filtered goes into the file
* pointed at by DEFAULT_FILTER.
*/
#include "main.h"
#include "filter.h" #include "filter.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "regexp.h"
#include "reqs.h" #include "reqs.h"
#include "conf.h"
#define FILTER_BUFFER_LEN (512) #define FILTER_BUFFER_LEN (512)
@@ -43,46 +47,52 @@ static filter_policy_t default_policy = FILTER_DEFAULT_ALLOW;
/* /*
* Initializes a linked list of strings containing hosts/urls to be filtered * Initializes a linked list of strings containing hosts/urls to be filtered
*/ */
void void filter_init (void)
filter_init(void)
{ {
FILE *fd; FILE *fd;
struct filter_list *p; struct filter_list *p;
char buf[FILTER_BUFFER_LEN]; char buf[FILTER_BUFFER_LEN];
char *s, *t; char *s;
int cflags; int cflags;
if (!fl && !already_init) { if (fl || already_init) {
return;
}
fd = fopen (config.filter, "r"); fd = fopen (config.filter, "r");
if (fd) { if (!fd) {
return;
}
p = NULL; p = NULL;
cflags = REG_NEWLINE | REG_NOSUB | REG_ICASE; cflags = REG_NEWLINE | REG_NOSUB;
if (config.filter_extended) if (config.filter_extended)
cflags |= REG_EXTENDED; cflags |= REG_EXTENDED;
if (!config.filter_casesensitive)
cflags |= REG_ICASE;
while (fgets (buf, FILTER_BUFFER_LEN, fd)) { while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
/*
* Remove any trailing white space and
* comments.
*/
s = buf; s = buf;
if (!p) /* head of list */ while (*s) {
fl = p = if (isspace ((unsigned char) *s))
safecalloc(1, break;
sizeof(struct if (*s == '#') {
filter_list)); /*
else { /* next entry */ * If the '#' char is preceeded by
p->next = * an escape, it's not a comment
safecalloc(1, * string.
sizeof(struct */
filter_list)); if (s == buf || *(s - 1) != '\\')
p = p->next; break;
} }
++s;
/* strip trailing whitespace & comments */
t = s;
while (*s && *s != '#') {
if (!isspace((unsigned char)*(s++)))
t = s;
} }
*t = '\0'; *s = '\0';
/* skip leading whitespace */ /* skip leading whitespace */
s = buf; s = buf;
@@ -93,10 +103,23 @@ filter_init(void)
if (*s == '\0') if (*s == '\0')
continue; continue;
if (!p) /* head of list */
fl = p =
(struct filter_list *)
safecalloc (1, sizeof (struct filter_list));
else { /* next entry */
p->next =
(struct filter_list *)
safecalloc (1, sizeof (struct filter_list));
p = p->next;
}
p->pat = safestrdup (s); p->pat = safestrdup (s);
p->cpat = safemalloc(sizeof(regex_t)); p->cpat = (regex_t *) safemalloc (sizeof (regex_t));
if ((err = regcomp(p->cpat, p->pat, cflags)) != 0) { err = regcomp (p->cpat, p->pat, cflags);
fprintf(stderr, "Bad regex in %s: %s\n", if (err != 0) {
fprintf (stderr,
"Bad regex in %s: %s\n",
config.filter, p->pat); config.filter, p->pat);
exit (EX_DATAERR); exit (EX_DATAERR);
} }
@@ -109,12 +132,9 @@ filter_init(void)
already_init = 1; already_init = 1;
} }
}
}
/* unlink the list */ /* unlink the list */
void void filter_destroy (void)
filter_destroy(void)
{ {
struct filter_list *p, *q; struct filter_list *p, *q;
@@ -131,9 +151,20 @@ 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 */ /* Return 0 to allow, non-zero to block */
int int filter_domain (const char *host)
filter_domain(const char *host)
{ {
struct filter_list *p; struct filter_list *p;
int result; int result;
@@ -142,7 +173,8 @@ filter_domain(const char *host)
goto COMMON_EXIT; goto COMMON_EXIT;
for (p = fl; p; p = p->next) { for (p = fl; p; p = p->next) {
result = regexec(p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0); result =
regexec (p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0);
if (result == 0) { if (result == 0) {
if (default_policy == FILTER_DEFAULT_ALLOW) if (default_policy == FILTER_DEFAULT_ALLOW)
@@ -160,8 +192,7 @@ filter_domain(const char *host)
} }
/* returns 0 to allow, non-zero to block */ /* returns 0 to allow, non-zero to block */
int int filter_url (const char *url)
filter_url(const char *url)
{ {
struct filter_list *p; struct filter_list *p;
int result; int result;
@@ -170,7 +201,8 @@ filter_url(const char *url)
goto COMMON_EXIT; goto COMMON_EXIT;
for (p = fl; p; p = p->next) { for (p = fl; p; p = p->next) {
result = regexec(p->cpat, url, (size_t) 0, (regmatch_t *) 0, 0); result =
regexec (p->cpat, url, (size_t) 0, (regmatch_t *) 0, 0);
if (result == 0) { if (result == 0) {
if (default_policy == FILTER_DEFAULT_ALLOW) if (default_policy == FILTER_DEFAULT_ALLOW)
@@ -190,8 +222,7 @@ filter_url(const char *url)
/* /*
* Set the default filtering policy * Set the default filtering policy
*/ */
void void filter_set_default_policy (filter_policy_t policy)
filter_set_default_policy(filter_policy_t policy)
{ {
default_policy = policy; default_policy = policy;
} }
+17 -13
View File
@@ -1,30 +1,34 @@
/* $Id: filter.h,v 1.5 2002-06-07 18:36:21 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1999 George Talusan <gstalusan@uwaterloo.ca>
* *
* See 'filter.c' for a detailed description. * 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.
* *
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'filter.c' for detailed information. */
#ifndef _TINYPROXY_FILTER_H_ #ifndef _TINYPROXY_FILTER_H_
#define _TINYPROXY_FILTER_H_ #define _TINYPROXY_FILTER_H_
typedef enum { typedef enum {
FILTER_DEFAULT_ALLOW, FILTER_DEFAULT_ALLOW,
FILTER_DEFAULT_DENY, FILTER_DEFAULT_DENY
} filter_policy_t; } filter_policy_t;
extern void filter_init (void); extern void filter_init (void);
extern void filter_destroy (void); extern void filter_destroy (void);
extern void filter_reload (void);
extern int filter_domain (const char *host); extern int filter_domain (const char *host);
extern int filter_url (const char *url); extern int filter_url (const char *url);
-5880
View File
File diff suppressed because it is too large. Load diff
-542
View File
@@ -1,542 +0,0 @@
/* Definitions for data structures and routines for the regular
expression library, version 0.12.
Copyright (C) 1985,89,90,91,92,93,95,96,97,98 Free Software Foundation, Inc.
This file is part of the GNU C Library. Its master source is NOT part of
the C library, however. The master source lives in /gd/gnu/lib.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _REGEX_H
#define _REGEX_H 1
/* Allow the use in C++ code. */
#ifdef __cplusplus
extern "C" {
#endif
/* POSIX says that <sys/types.h> must be included (by the caller) before
<regex.h>. */
#if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
should be there. */
# include <stddef.h>
#endif
/* The following two types have to be signed and unsigned integer type
wide enough to hold a value of a pointer. For most ANSI compilers
ptrdiff_t and size_t should be likely OK. Still size of these two
types is 2 for Microsoft C. Ugh... */
typedef long int s_reg_t;
typedef unsigned long int active_reg_t;
/* The following bits are used to determine the regexp syntax we
recognize. The set/not-set meanings are chosen so that Emacs syntax
remains the value 0. The bits are given in alphabetical order, and
the definitions shifted by one from the previous bit; thus, when we
add or remove a bit, only one other definition need change. */
typedef unsigned long int reg_syntax_t;
/* If this bit is not set, then \ inside a bracket expression is literal.
If set, then such a \ quotes the following character. */
#define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
/* If this bit is not set, then + and ? are operators, and \+ and \? are
literals.
If set, then \+ and \? are operators and + and ? are literals. */
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
/* If this bit is set, then character classes are supported. They are:
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
If not set, then character classes are not supported. */
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
/* If this bit is set, then ^ and $ are always anchors (outside bracket
expressions, of course).
If this bit is not set, then it depends:
^ is an anchor if it is at the beginning of a regular
expression or after an open-group or an alternation operator;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
POSIX draft 11.2 says that * etc. in leading positions is undefined.
We already implemented a previous draft which made those constructs
invalid, though, so we haven't changed the code back. */
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
/* If this bit is set, then special characters are always special
regardless of where they are in the pattern.
If this bit is not set, then special characters are special only in
some contexts; otherwise they are ordinary. Specifically,
* + ? and intervals are only special when not after the beginning,
open-group, or alternation operator. */
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
immediately after an alternation or begin-group operator. */
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
/* If this bit is set, then . matches newline.
If not set, then it doesn't. */
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
/* If this bit is set, then . doesn't match NUL.
If not set, then it does. */
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
/* If this bit is set, nonmatching lists [^...] do not match newline.
If not set, they do. */
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
/* If this bit is set, either \{...\} or {...} defines an
interval, depending on RE_NO_BK_BRACES.
If not set, \{, \}, {, and } are literals. */
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
/* If this bit is set, +, ? and | aren't recognized as operators.
If not set, they are. */
#define RE_LIMITED_OPS (RE_INTERVALS << 1)
/* If this bit is set, newline is an alternation operator.
If not set, newline is literal. */
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
are literals.
If not set, then `\{...\}' defines an interval. */
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
/* If this bit is set, (...) defines a group, and \( and \) are literals.
If not set, \(...\) defines a group, and ( and ) are literals. */
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
/* If this bit is set, then \<digit> matches <digit>.
If not set, then \<digit> is a back-reference. */
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
/* If this bit is set, then | is an alternation operator, and \| is literal.
If not set, then \| is an alternation operator, and | is literal. */
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
/* If this bit is set, then an ending range point collating higher
than the starting range point, as in [z-a], is invalid.
If not set, then when ending range point collates higher than the
starting range point, the range is ignored. */
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
/* If this bit is set, then an unmatched ) is ordinary.
If not set, then an unmatched ) is invalid. */
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
/* If this bit is set, succeed as soon as we match the whole pattern,
without further backtracking. */
#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
/* If this bit is set, do not process the GNU regex operators.
If not set, then the GNU regex operators are recognized. */
#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
/* If this bit is set, turn on internal regex debugging.
If not set, and debugging was on, turn it off.
This only works if regex.c is compiled -DDEBUG.
We define this bit always, so that all that's needed to turn on
debugging is to recompile regex.c; the calling code can always have
this bit set, and it won't affect anything in the normal case. */
#define RE_DEBUG (RE_NO_GNU_OPS << 1)
/* This global variable defines the particular regexp syntax to use (for
some interfaces). When a regexp is compiled, the syntax used is
stored in the pattern buffer, so changing this does not affect
already-compiled regexps. */
extern reg_syntax_t re_syntax_options;
/* Define combinations of the above bits for the standard possibilities.
(The [[[ comments delimit what gets put into the Texinfo file, so
don't delete them!) */
/* [[[begin syntaxes]]] */
#define RE_SYNTAX_EMACS 0
#define RE_SYNTAX_AWK \
(RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
| RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
| RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
#define RE_SYNTAX_GNU_AWK \
((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS))
#define RE_SYNTAX_POSIX_AWK \
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
| RE_INTERVALS | RE_NO_GNU_OPS)
#define RE_SYNTAX_GREP \
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
| RE_NEWLINE_ALT)
#define RE_SYNTAX_EGREP \
(RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
| RE_NEWLINE_ALT | RE_NO_BK_PARENS \
| RE_NO_BK_VBAR)
#define RE_SYNTAX_POSIX_EGREP \
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
/* Syntax bits common to both basic and extended POSIX regex syntax. */
#define _RE_SYNTAX_POSIX_COMMON \
(RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
| RE_INTERVALS | RE_NO_EMPTY_RANGES)
#define RE_SYNTAX_POSIX_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
isn't minimal, since other operators, such as \`, aren't disabled. */
#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
#define RE_SYNTAX_POSIX_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_VBAR \
| RE_UNMATCHED_RIGHT_PAREN_ORD)
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
/* [[[end syntaxes]]] */
/* Maximum number of duplicates an interval can allow. Some systems
(erroneously) define this in other header files, but we want our
value, so remove any previous define. */
#ifdef RE_DUP_MAX
# undef RE_DUP_MAX
#endif
/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */
#define RE_DUP_MAX (0x7fff)
/* POSIX `cflags' bits (i.e., information for `regcomp'). */
/* If this bit is set, then use extended regular expression syntax.
If not set, then use basic regular expression syntax. */
#define REG_EXTENDED 1
/* If this bit is set, then ignore case when matching.
If not set, then case is significant. */
#define REG_ICASE (REG_EXTENDED << 1)
/* If this bit is set, then anchors do not match at newline
characters in the string.
If not set, then anchors do match at newlines. */
#define REG_NEWLINE (REG_ICASE << 1)
/* If this bit is set, then report only success or fail in regexec.
If not set, then returns differ between not matching and errors. */
#define REG_NOSUB (REG_NEWLINE << 1)
/* POSIX `eflags' bits (i.e., information for regexec). */
/* If this bit is set, then the beginning-of-line operator doesn't match
the beginning of the string (presumably because it's not the
beginning of a line).
If not set, then the beginning-of-line operator does match the
beginning of the string. */
#define REG_NOTBOL 1
/* Like REG_NOTBOL, except for the end-of-line. */
#define REG_NOTEOL (1 << 1)
/* If any error codes are removed, changed, or added, update the
`re_error_msg' table in regex.c. */
typedef enum
{
#ifdef _XOPEN_SOURCE
REG_ENOSYS = -1, /* This will never happen for this implementation. */
#endif
REG_NOERROR = 0, /* Success. */
REG_NOMATCH, /* Didn't find a match (for regexec). */
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
REG_BADPAT, /* Invalid pattern. */
REG_ECOLLATE, /* Not implemented. */
REG_ECTYPE, /* Invalid character class name. */
REG_EESCAPE, /* Trailing backslash. */
REG_ESUBREG, /* Invalid back reference. */
REG_EBRACK, /* Unmatched left bracket. */
REG_EPAREN, /* Parenthesis imbalance. */
REG_EBRACE, /* Unmatched \{. */
REG_BADBR, /* Invalid contents of \{\}. */
REG_ERANGE, /* Invalid range end. */
REG_ESPACE, /* Ran out of memory. */
REG_BADRPT, /* No preceding re for repetition op. */
/* Error codes we've added. */
REG_EEND, /* Premature end. */
REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
} reg_errcode_t;
/* This data structure represents a compiled pattern. Before calling
the pattern compiler, the fields `buffer', `allocated', `fastmap',
`translate', and `no_sub' can be set. After the pattern has been
compiled, the `re_nsub' field is available. All other fields are
private to the regex routines. */
#ifndef RE_TRANSLATE_TYPE
# define RE_TRANSLATE_TYPE char *
#endif
struct re_pattern_buffer
{
/* [[[begin pattern_buffer]]] */
/* Space that holds the compiled pattern. It is declared as
`unsigned char *' because its elements are
sometimes used as array indexes. */
unsigned char *buffer;
/* Number of bytes to which `buffer' points. */
unsigned long int allocated;
/* Number of bytes actually used in `buffer'. */
unsigned long int used;
/* Syntax setting with which the pattern was compiled. */
reg_syntax_t syntax;
/* Pointer to a fastmap, if any, otherwise zero. re_search uses
the fastmap, if there is one, to skip over impossible
starting points for matches. */
char *fastmap;
/* Either a translate table to apply to all characters before
comparing them, or zero for no translation. The translation
is applied to a pattern when it is compiled and to a string
when it is matched. */
RE_TRANSLATE_TYPE translate;
/* Number of subexpressions found by the compiler. */
size_t re_nsub;
/* Zero if this pattern cannot match the empty string, one else.
Well, in truth it's used only in `re_search_2', to see
whether or not we should use the fastmap, so we don't set
this absolutely perfectly; see `re_compile_fastmap' (the
`duplicate' case). */
unsigned can_be_null : 1;
/* If REGS_UNALLOCATED, allocate space in the `regs' structure
for `max (RE_NREGS, re_nsub + 1)' groups.
If REGS_REALLOCATE, reallocate space if necessary.
If REGS_FIXED, use what's there. */
#define REGS_UNALLOCATED 0
#define REGS_REALLOCATE 1
#define REGS_FIXED 2
unsigned regs_allocated : 2;
/* Set to zero when `regex_compile' compiles a pattern; set to one
by `re_compile_fastmap' if it updates the fastmap. */
unsigned fastmap_accurate : 1;
/* If set, `re_match_2' does not return information about
subexpressions. */
unsigned no_sub : 1;
/* If set, a beginning-of-line anchor doesn't match at the
beginning of the string. */
unsigned not_bol : 1;
/* Similarly for an end-of-line anchor. */
unsigned not_eol : 1;
/* If true, an anchor at a newline matches. */
unsigned newline_anchor : 1;
/* [[[end pattern_buffer]]] */
};
typedef struct re_pattern_buffer regex_t;
/* Type for byte offsets within the string. POSIX mandates this. */
typedef int regoff_t;
/* This is the structure we store register match data in. See
regex.texinfo for a full description of what registers match. */
struct re_registers
{
unsigned num_regs;
regoff_t *start;
regoff_t *end;
};
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
`re_match_2' returns information about at least this many registers
the first time a `regs' structure is passed. */
#ifndef RE_NREGS
# define RE_NREGS 30
#endif
/* POSIX specification for registers. Aside from the different names than
`re_registers', POSIX uses an array of structures, instead of a
structure of arrays. */
typedef struct
{
regoff_t rm_so; /* Byte offset from string's start to substring's start. */
regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
} regmatch_t;
/* Declarations for routines. */
/* To avoid duplicating every routine declaration -- once with a
prototype (if we are ANSI), and once without (if we aren't) -- we
use the following macro to declare argument types. This
unfortunately clutters up the declarations a bit, but I think it's
worth it. */
#if __STDC__
# define _RE_ARGS(args) args
#else /* not __STDC__ */
# define _RE_ARGS(args) ()
#endif /* not __STDC__ */
/* Sets the current default syntax to SYNTAX, and return the old syntax.
You can also simply assign to the `re_syntax_options' variable. */
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
/* Compile the regular expression PATTERN, with length LENGTH
and syntax given by the global `re_syntax_options', into the buffer
BUFFER. Return NULL if successful, and an error string if not. */
extern const char *re_compile_pattern
_RE_ARGS ((const char *pattern, size_t length,
struct re_pattern_buffer *buffer));
/* Compile a fastmap for the compiled pattern in BUFFER; used to
accelerate searches. Return 0 if successful and -2 if was an
internal error. */
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
/* Search in the string STRING (with length LENGTH) for the pattern
compiled into BUFFER. Start searching at position START, for RANGE
characters. Return the starting position of the match, -1 for no
match, or -2 for an internal error. Also return register
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
extern int re_search
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, int range, struct re_registers *regs));
/* Like `re_search', but search in the concatenation of STRING1 and
STRING2. Also, stop searching at index START + STOP. */
extern int re_search_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2,
int start, int range, struct re_registers *regs, int stop));
/* Like `re_search', but return how many characters in STRING the regexp
in BUFFER matched, starting at position START. */
extern int re_match
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, struct re_registers *regs));
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
extern int re_match_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2,
int start, struct re_registers *regs, int stop));
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
ENDS. Subsequent matches using BUFFER and REGS will use this memory
for recording register information. STARTS and ENDS must be
allocated with malloc, and must each be at least `NUM_REGS * sizeof
(regoff_t)' bytes long.
If NUM_REGS == 0, then subsequent matches should allocate their own
register data.
Unless this function is called, the first search or match using
PATTERN_BUFFER will allocate its own register data, without
freeing the old data. */
extern void re_set_registers
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
unsigned num_regs, regoff_t *starts, regoff_t *ends));
#if defined _REGEX_RE_COMP || defined _LIBC
# ifndef _CRAY
/* 4.2 bsd compatibility. */
extern char *re_comp _RE_ARGS ((const char *));
extern int re_exec _RE_ARGS ((const char *));
# endif
#endif
/* POSIX compatibility. */
extern int regcomp _RE_ARGS ((regex_t *__preg, const char *__pattern,
int __cflags));
extern int regexec _RE_ARGS ((const regex_t *__preg,
const char *__string, size_t __nmatch,
regmatch_t __pmatch[], int __eflags));
extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
char *__errbuf, size_t __errbuf_size));
extern void regfree _RE_ARGS ((regex_t *__preg));
#ifdef __cplusplus
}
#endif /* C++ */
#endif /* regex.h */
/*
Local variables:
make-backup-files: t
version-control: t
trim-versions-without-asking: nil
End:
*/
-231
View File
@@ -1,231 +0,0 @@
/* $Id: grammar.y,v 1.17 2002-11-26 21:44:43 rjkaes Exp $
*
* This is the grammar for tinyproxy's configuration file. It needs to be
* in sync with scanner.l. If you know more about yacc and lex than I do
* please update these files.
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/
%{
#include "tinyproxy.h"
#include "acl.h"
#include "anonymous.h"
#include "child.h"
#include "filter.h"
#include "log.h"
#include "reqs.h"
void yyerror(char *s);
int yylex(void);
%}
%union {
unsigned int num;
char *cptr;
void *ptr;
}
/* statements */
%token KW_PORT KW_LISTEN
%token KW_LOGFILE KW_PIDFILE KW_SYSLOG
%token KW_MAXCLIENTS KW_MAXSPARESERVERS KW_MINSPARESERVERS KW_STARTSERVERS
%token KW_MAXREQUESTSPERCHILD
%token KW_TIMEOUT
%token KW_USER KW_GROUP
%token KW_ANONYMOUS KW_XTINYPROXY
%token KW_FILTER KW_FILTERURLS KW_FILTEREXTENDED KW_FILTER_DEFAULT_DENY
%token KW_UPSTREAM
%token KW_CONNECTPORT KW_BIND KW_HTTP_VIA
%token KW_ALLOW KW_DENY
/* yes/no switches */
%token KW_YES KW_NO
/* settings for loglevel */
%token KW_LOGLEVEL
%token KW_LOG_CRITICAL KW_LOG_ERROR KW_LOG_WARNING KW_LOG_NOTICE KW_LOG_CONNECT KW_LOG_INFO
%token <cptr> IDENTIFIER
%token <num> NUMBER
%token <cptr> STRING
%token <cptr> NUMERIC_ADDRESS
%token <cptr> STRING_ADDRESS
%token <cptr> NETMASK_ADDRESS
%type <num> yesno
%type <cptr> string
%type <cptr> network_address
%type <cptr> unique_address
%type <num> loglevels
%%
start
: /* empty */
| start line
;
line
: '\n'
| statement '\n'
;
statement
: KW_PORT NUMBER { config.port = $2; }
| KW_TIMEOUT NUMBER { config.idletimeout = $2; }
| KW_SYSLOG yesno
{
#ifdef HAVE_SYSLOG_H
config.syslog = $2;
#else
log_message(LOG_WARNING, "Syslog support was not compiled in.");
#endif
}
| KW_MAXCLIENTS NUMBER { child_configure(CHILD_MAXCLIENTS, $2); }
| KW_MAXSPARESERVERS NUMBER { child_configure(CHILD_MAXSPARESERVERS, $2); }
| KW_MINSPARESERVERS NUMBER { child_configure(CHILD_MINSPARESERVERS, $2); }
| KW_STARTSERVERS NUMBER { child_configure(CHILD_STARTSERVERS, $2); }
| KW_MAXREQUESTSPERCHILD NUMBER { child_configure(CHILD_MAXREQUESTSPERCHILD, $2); }
| KW_LOGFILE string
{
config.logf_name = $2;
if (!config.logf_name) {
fprintf(stderr, "bad log file\n");
}
}
| KW_PIDFILE string { config.pidpath = $2; }
| KW_USER string { config.username = $2; }
| KW_GROUP string { config.group = $2; }
| KW_ANONYMOUS string { anonymous_insert($2); }
| KW_FILTER string
{
#ifdef FILTER_ENABLE
config.filter = $2;
#else
log_message(LOG_WARNING, "Filter support was not compiled in.");
#endif
}
| KW_FILTERURLS yesno
{
#ifdef FILTER_ENABLE
config.filter_url = $2;
#else
log_message(LOG_WARNING, "Filter support wss not compiled in.");
#endif
}
| KW_FILTEREXTENDED yesno
{
#ifdef FILTER_ENABLE
config.filter_extended = $2;
#else
log_message(LOG_WARNING, "Filter support was not compiled in.");
#endif
}
| KW_FILTER_DEFAULT_DENY yesno
{
#ifdef FILTER_ENABLE
if ($2)
filter_set_default_policy(FILTER_DEFAULT_DENY);
#else
log_message(LOG_WARNING, "FIlter support was not compiled in.");
#endif
}
| KW_XTINYPROXY network_address
{
#ifdef XTINYPROXY_ENABLE
config.my_domain = $2;
#else
log_message(LOG_WARNING, "X-Tinyproxy header support was not compiled in.");
#endif
}
| KW_UPSTREAM unique_address ':' NUMBER
{
#ifdef UPSTREAM_SUPPORT
config.upstream_name = $2;
config.upstream_port = $4;
#else
log_message(LOG_WARNING, "Upstream proxy support was not compiled in.");
#endif
}
| KW_LISTEN NUMERIC_ADDRESS
{
log_message(LOG_INFO, "Establishing listening socket on IP %s", $2);
config.ipAddr = $2;
}
| KW_ALLOW network_address { insert_acl($2, ACL_ALLOW); }
| KW_DENY network_address { insert_acl($2, ACL_DENY); }
| KW_LOGLEVEL loglevels { set_log_level($2); }
| KW_CONNECTPORT NUMBER { add_connect_port_allowed($2); }
| KW_BIND NUMERIC_ADDRESS
{
#ifndef TRANSPARENT_PROXY
log_message(LOG_INFO, "Binding outgoing connections to %s", $2);
config.bind_address = $2;
#else
log_message(LOG_WARNING, "The 'Bind' directive can not be used with transparent proxy support. Ignoring the directive.");
#endif
}
| KW_HTTP_VIA yesno
{
if ($2) {
log_message(LOG_INFO, "Enabling HTTP Via header.");
config.via_http_header = TRUE;
} else {
config.via_http_header = FALSE;
}
}
;
loglevels
: KW_LOG_CRITICAL { $$ = LOG_CRIT; }
| KW_LOG_ERROR { $$ = LOG_ERR; }
| KW_LOG_WARNING { $$ = LOG_WARNING; }
| KW_LOG_NOTICE { $$ = LOG_NOTICE; }
| KW_LOG_CONNECT { $$ = LOG_CONN; }
| KW_LOG_INFO { $$ = LOG_INFO; }
;
network_address
: unique_address
| NETMASK_ADDRESS
;
unique_address
: STRING_ADDRESS
| NUMERIC_ADDRESS
;
yesno
: KW_YES { $$ = 1; }
| KW_NO { $$ = 0; }
| NUMBER { $$ = $1; }
;
string
: IDENTIFIER
| STRING
;
%%
extern unsigned int yylineno;
void
yyerror(char *s)
{
fprintf(stderr, "Line %d: %s\n", yylineno, s);
}
+82 -93
View File
@@ -1,14 +1,5 @@
/* $Id: hashmap.c,v 1.11 2002-05-24 04:45:32 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* * Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
* key and the data in the hashmap itself, so you must free the original
* key and data to avoid a memory leak. The hashmap returns a pointer
* to the data when a key is searched for, so take care in modifying the
* data as it's modifying the data stored in the hashmap. (In other words,
* don't try to free the data, or realloc the memory. :)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -20,12 +11,21 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, write to the Free Software * with this program; if not, write to the Free Software Foundation, Inc.,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "tinyproxy.h" /* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
* key and the data in the hashmap itself, so you must free the original
* key and data to avoid a memory leak. The hashmap returns a pointer
* to the data when a key is searched for, so take care in modifying the
* data as it's modifying the data stored in the hashmap. (In other words,
* don't try to free the data, or realloc the memory. :)
*/
#include "main.h"
#include "hashmap.h" #include "hashmap.h"
#include "heap.h" #include "heap.h"
@@ -44,11 +44,17 @@ struct hashentry_s {
struct hashentry_s *prev, *next; struct hashentry_s *prev, *next;
}; };
struct hashbucket_s {
struct hashentry_s *head, *tail;
};
struct hashmap_s { struct hashmap_s {
uint32_t seed;
unsigned int size; unsigned int size;
hashmap_iter end_iterator; hashmap_iter end_iterator;
struct hashentry_s **buckets; struct hashbucket_s *buckets;
}; };
/* /*
@@ -58,10 +64,12 @@ struct hashmap_s {
* The contents of the key are converted to lowercase, so this function * The contents of the key are converted to lowercase, so this function
* is not case-sensitive. * is not case-sensitive.
* *
* This is Dan Bernstein's hash function as described, for example, here:
* http://www.cse.yorku.ca/~oz/hash.html
*
* If any of the arguments are invalid a negative number is returned. * If any of the arguments are invalid a negative number is returned.
*/ */
static int static int hashfunc (const char *key, unsigned int size, uint32_t seed)
hashfunc(const char *key, unsigned int size)
{ {
uint32_t hash; uint32_t hash;
@@ -70,12 +78,8 @@ hashfunc(const char *key, unsigned int size)
if (size == 0) if (size == 0)
return -ERANGE; return -ERANGE;
for (hash = tolower(*key++); *key != '\0'; key++) { for (hash = seed; *key != '\0'; key++) {
uint32_t bit = hash = ((hash << 5) + hash) ^ tolower (*key);
(hash & 1) ? (1 << (sizeof(uint32_t) - 1)) : 0;
hash >>= 1;
hash += tolower(*key) + bit;
} }
/* Keep the hash within the table limits */ /* Keep the hash within the table limits */
@@ -89,20 +93,22 @@ hashfunc(const char *key, unsigned int size)
* *
* NULLs are also returned if memory could not be allocated for hashmap. * NULLs are also returned if memory could not be allocated for hashmap.
*/ */
hashmap_t hashmap_t hashmap_create (unsigned int nbuckets)
hashmap_create(unsigned int nbuckets)
{ {
struct hashmap_s *ptr; struct hashmap_s *ptr;
if (nbuckets == 0) if (nbuckets == 0)
return NULL; return NULL;
ptr = safecalloc(1, sizeof(struct hashmap_s)); ptr = (struct hashmap_s *) safecalloc (1, sizeof (struct hashmap_s));
if (!ptr) if (!ptr)
return NULL; return NULL;
ptr->seed = (uint32_t)rand();
ptr->size = nbuckets; ptr->size = nbuckets;
ptr->buckets = safecalloc(nbuckets, sizeof(struct hashentry_s *)); ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets,
sizeof (struct
hashbucket_s));
if (!ptr->buckets) { if (!ptr->buckets) {
safefree (ptr); safefree (ptr);
return NULL; return NULL;
@@ -121,16 +127,15 @@ hashmap_create(unsigned int nbuckets)
* Returns: 0 if the function completed successfully * Returns: 0 if the function completed successfully
* negative number is returned if "entry" was NULL * negative number is returned if "entry" was NULL
*/ */
static inline int static int delete_hashbucket (struct hashbucket_s *bucket)
delete_hashbucket(struct hashentry_s* entry)
{ {
struct hashentry_s *nextptr; struct hashentry_s *nextptr;
struct hashentry_s *ptr; struct hashentry_s *ptr;
if (entry == NULL) if (bucket == NULL || bucket->head == NULL)
return -EINVAL; return -EINVAL;
ptr = entry; ptr = bucket->head;
while (ptr) { while (ptr) {
nextptr = ptr->next; nextptr = ptr->next;
@@ -150,18 +155,16 @@ delete_hashbucket(struct hashentry_s* entry)
* Returns: 0 on success * Returns: 0 on success
* negative if a NULL "map" was supplied * negative if a NULL "map" was supplied
*/ */
int int hashmap_delete (hashmap_t map)
hashmap_delete(hashmap_t map)
{ {
unsigned int i; unsigned int i;
if (map == NULL) if (map == NULL)
return -EINVAL; return -EINVAL;
for (i = 0; i < map->size; i++) { for (i = 0; i != map->size; i++) {
if (map->buckets[i] != NULL) { if (map->buckets[i].head != NULL) {
delete_hashbucket(map->buckets[i]); delete_hashbucket (&map->buckets[i]);
map->buckets[i] = NULL;
} }
} }
@@ -182,8 +185,7 @@ hashmap_delete(hashmap_t map)
* negative number if there are errors * negative number if there are errors
*/ */
int int
hashmap_insert(hashmap_t map, const char *key, hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
const void *data, size_t len)
{ {
struct hashentry_s *ptr; struct hashentry_s *ptr;
int hash; int hash;
@@ -200,7 +202,7 @@ hashmap_insert(hashmap_t map, const char *key,
if (!data || len < 1) if (!data || len < 1)
return -ERANGE; return -ERANGE;
hash = hashfunc(key, map->size); hash = hashfunc (key, map->size, map->seed);
if (hash < 0) if (hash < 0)
return hash; return hash;
@@ -212,18 +214,14 @@ hashmap_insert(hashmap_t map, const char *key,
if (!key_copy) if (!key_copy)
return -ENOMEM; return -ENOMEM;
if (data) {
data_copy = safemalloc (len); data_copy = safemalloc (len);
if (!data_copy) { if (!data_copy) {
safefree (key_copy); safefree (key_copy);
return -ENOMEM; return -ENOMEM;
} }
memcpy (data_copy, data, len); memcpy (data_copy, data, len);
} else {
data_copy = NULL;
}
ptr = safemalloc(sizeof(struct hashentry_s)); ptr = (struct hashentry_s *) safemalloc (sizeof (struct hashentry_s));
if (!ptr) { if (!ptr) {
safefree (key_copy); safefree (key_copy);
safefree (data_copy); safefree (data_copy);
@@ -235,14 +233,16 @@ hashmap_insert(hashmap_t map, const char *key,
ptr->len = len; ptr->len = len;
/* /*
* Put the entry at the beginning of the chain. This is a constant * Now add the entry to the end of the bucket chain.
* time insert. Thanks to Justin Guyett for the code.
*/ */
ptr->prev = NULL; ptr->next = NULL;
ptr->next = map->buckets[hash]; ptr->prev = map->buckets[hash].tail;
map->buckets[hash] = ptr; if (map->buckets[hash].tail)
if (ptr->next) map->buckets[hash].tail->next = ptr;
ptr->next->prev = ptr;
map->buckets[hash].tail = ptr;
if (!map->buckets[hash].head)
map->buckets[hash].head = ptr;
map->end_iterator++; map->end_iterator++;
return 0; return 0;
@@ -253,8 +253,7 @@ hashmap_insert(hashmap_t map, const char *key,
* *
* Returns: an negative value upon error. * Returns: an negative value upon error.
*/ */
hashmap_iter hashmap_iter hashmap_first (hashmap_t map)
hashmap_first(hashmap_t map)
{ {
assert (map != NULL); assert (map != NULL);
@@ -273,8 +272,7 @@ hashmap_first(hashmap_t map)
* Returns: 1 if it is the end * Returns: 1 if it is the end
* 0 otherwise * 0 otherwise
*/ */
int int hashmap_is_end (hashmap_t map, hashmap_iter iter)
hashmap_is_end(hashmap_t map, hashmap_iter iter)
{ {
assert (map != NULL); assert (map != NULL);
assert (iter >= 0); assert (iter >= 0);
@@ -296,8 +294,7 @@ hashmap_is_end(hashmap_t map, hashmap_iter iter)
* an "iterator" pointing at the first key * an "iterator" pointing at the first key
* an "end-iterator" if the key wasn't found * an "end-iterator" if the key wasn't found
*/ */
hashmap_iter hashmap_iter hashmap_find (hashmap_t map, const char *key)
hashmap_find(hashmap_t map, const char* key)
{ {
unsigned int i; unsigned int i;
hashmap_iter iter = 0; hashmap_iter iter = 0;
@@ -313,8 +310,8 @@ hashmap_find(hashmap_t map, const char* key)
* Loop through all the keys and look for the first occurrence * Loop through all the keys and look for the first occurrence
* of a particular key. * of a particular key.
*/ */
for (i = 0; i < map->size; i++) { for (i = 0; i != map->size; i++) {
ptr = map->buckets[i]; ptr = map->buckets[i].head;
while (ptr) { while (ptr) {
if (strcasecmp (ptr->key, key) == 0) { if (strcasecmp (ptr->key, key) == 0) {
@@ -337,8 +334,7 @@ hashmap_find(hashmap_t map, const char* key)
* negative upon error * negative upon error
*/ */
ssize_t ssize_t
hashmap_return_entry(hashmap_t map, hashmap_iter iter, hashmap_return_entry (hashmap_t map, hashmap_iter iter, char **key, void **data)
char** key, void** data)
{ {
unsigned int i; unsigned int i;
struct hashentry_s *ptr; struct hashentry_s *ptr;
@@ -353,8 +349,8 @@ hashmap_return_entry(hashmap_t map, hashmap_iter iter,
if (!map || iter < 0 || !key || !data) if (!map || iter < 0 || !key || !data)
return -EINVAL; return -EINVAL;
for (i = 0; i < map->size; i++) { for (i = 0; i != map->size; i++) {
ptr = map->buckets[i]; ptr = map->buckets[i].head;
while (ptr) { while (ptr) {
if (count == iter) { if (count == iter) {
/* This is the data so return it */ /* This is the data so return it */
@@ -378,8 +374,7 @@ hashmap_return_entry(hashmap_t map, hashmap_iter iter,
* zero if no key is found * zero if no key is found
* count found * count found
*/ */
ssize_t ssize_t hashmap_search (hashmap_t map, const char *key)
hashmap_search(hashmap_t map, const char *key)
{ {
int hash; int hash;
struct hashentry_s *ptr; struct hashentry_s *ptr;
@@ -388,11 +383,11 @@ hashmap_search(hashmap_t map, const char *key)
if (map == NULL || key == NULL) if (map == NULL || key == NULL)
return -EINVAL; return -EINVAL;
hash = hashfunc(key, map->size); hash = hashfunc (key, map->size, map->seed);
if (hash < 0) if (hash < 0)
return hash; return hash;
ptr = map->buckets[hash]; ptr = map->buckets[hash].head;
/* All right, there is an entry here, now see if it's the one we want */ /* All right, there is an entry here, now see if it's the one we want */
while (ptr) { while (ptr) {
@@ -414,8 +409,7 @@ hashmap_search(hashmap_t map, const char *key)
* zero if no entry is found * zero if no entry is found
* length of data for the entry * length of data for the entry
*/ */
ssize_t ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, void **data)
hashmap_entry_by_key(hashmap_t map, const char* key, void** data)
{ {
int hash; int hash;
struct hashentry_s *ptr; struct hashentry_s *ptr;
@@ -423,11 +417,11 @@ hashmap_entry_by_key(hashmap_t map, const char* key, void** data)
if (!map || !key || !data) if (!map || !key || !data)
return -EINVAL; return -EINVAL;
hash = hashfunc(key, map->size); hash = hashfunc (key, map->size, map->seed);
if (hash < 0) if (hash < 0)
return hash; return hash;
ptr = map->buckets[hash]; ptr = map->buckets[hash].head;
while (ptr) { while (ptr) {
if (strcasecmp (ptr->key, key) == 0) { if (strcasecmp (ptr->key, key) == 0) {
@@ -449,38 +443,37 @@ hashmap_entry_by_key(hashmap_t map, const char* key, void** data)
* 0 if the key was not found * 0 if the key was not found
* positive count of entries deleted * positive count of entries deleted
*/ */
ssize_t ssize_t hashmap_remove (hashmap_t map, const char *key)
hashmap_remove(hashmap_t map, const char *key)
{ {
int hash; int hash;
struct hashentry_s* ptr; struct hashentry_s *ptr, *next;
short int deleted = 0; short int deleted = 0;
if (map == NULL || key == NULL) if (map == NULL || key == NULL)
return -EINVAL; return -EINVAL;
hash = hashfunc(key, map->size); hash = hashfunc (key, map->size, map->seed);
if (hash < 0) if (hash < 0)
return hash; return hash;
ptr = map->buckets[hash]; ptr = map->buckets[hash].head;
while (ptr) { while (ptr) {
if (strcasecmp (ptr->key, key) == 0) { if (strcasecmp (ptr->key, key) == 0) {
/* /*
* Found the data, now need to remove everything * Found the data, now need to remove everything
* and update the hashmap. * and update the hashmap.
*/ */
struct hashentry_s* prevptr = ptr->prev; next = ptr->next;
if (prevptr != NULL) {
prevptr->next = ptr->next; if (ptr->prev)
ptr->prev->next = ptr->next;
if (ptr->next) if (ptr->next)
ptr->next->prev = prevptr; ptr->next->prev = ptr->prev;
} else {
/* Entry was first in map */ if (map->buckets[hash].head == ptr)
map->buckets[hash] = ptr->next; map->buckets[hash].head = ptr->next;
if (ptr->next) if (map->buckets[hash].tail == ptr)
ptr->next->prev = NULL; map->buckets[hash].tail = ptr->prev;
}
safefree (ptr->key); safefree (ptr->key);
safefree (ptr->data); safefree (ptr->data);
@@ -489,11 +482,7 @@ hashmap_remove(hashmap_t map, const char *key)
++deleted; ++deleted;
--map->end_iterator; --map->end_iterator;
if (prevptr) ptr = next;
ptr = prevptr;
else
ptr = map->buckets[hash];
continue; continue;
} }
+10 -23
View File
@@ -1,14 +1,5 @@
/* $Id: hashmap.h,v 1.2 2002-04-25 18:55:56 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* * Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
* key and the data in the hashmap itself, so you must free the original
* key and data to avoid a memory leak. The hashmap returns a pointer
* to the data when a key is searched for, so take care in modifying the
* data as it's modifying the data stored in the hashmap. (In other words,
* don't try to free the data, or realloc the memory. :)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -20,18 +11,17 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, write to the Free Software * with this program; if not, write to the Free Software Foundation, Inc.,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/* See 'hashmap.c' for detailed information. */
#ifndef _HASHMAP_H #ifndef _HASHMAP_H
#define _HASHMAP_H #define _HASHMAP_H
/* Allow the use in C++ code. */ #include "common.h"
#if defined(__cplusplus)
extern "C" {
#endif
/* /*
* We're using a typedef here to "hide" the implementation details of the * We're using a typedef here to "hide" the implementation details of the
@@ -104,7 +94,8 @@ extern ssize_t hashmap_return_entry(hashmap_t map, hashmap_iter iter,
* zero if no entry is found * zero if no entry is found
* length of data for the entry * length of data for the entry
*/ */
extern ssize_t hashmap_entry_by_key(hashmap_t map, const char* key, void** data); extern ssize_t hashmap_entry_by_key (hashmap_t map, const char *key,
void **data);
/* /*
* Searches for _any_ occurrances of "key" within the hashmap and returns the * Searches for _any_ occurrances of "key" within the hashmap and returns the
@@ -126,8 +117,4 @@ extern ssize_t hashmap_search(hashmap_t map, const char *key);
*/ */
extern ssize_t hashmap_remove (hashmap_t map, const char *key); extern ssize_t hashmap_remove (hashmap_t map, const char *key);
#if defined(__cplusplus)
}
#endif /* C++ */
#endif /* _HASHMAP_H */ #endif /* _HASHMAP_H */
+50 -43
View File
@@ -1,30 +1,35 @@
/* $Id: heap.c,v 1.5 2002-07-09 18:52:32 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* Debugging versions of various heap related functions are combined * 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.
*/
/* Debugging versions of various heap related functions are combined
* here. The debugging versions include assertions and also print * here. The debugging versions include assertions and also print
* (to standard error) the function called along with the amount * (to standard error) the function called along with the amount
* of memory allocated, and where the memory is pointing. The * of memory allocated, and where the memory is pointing. The
* format of the log message is standardized. * format of the log message is standardized.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "heap.h" #include "heap.h"
#include "text.h" #include "text.h"
void * #ifndef NDEBUG
debugging_calloc(size_t nmemb, size_t size, const char *file,
void *debugging_calloc (size_t nmemb, size_t size, const char *file,
unsigned long line) unsigned long line)
{ {
void *ptr; void *ptr;
@@ -33,49 +38,46 @@ debugging_calloc(size_t nmemb, size_t size, const char *file,
assert (size > 0); assert (size > 0);
ptr = calloc (nmemb, size); ptr = calloc (nmemb, size);
fprintf(stderr, "{calloc: %p:%u x %u} %s:%lu\n", ptr, nmemb, size, file, fprintf (stderr, "{calloc: %p:%lu x %lu} %s:%lu\n", ptr,
line); (unsigned long) nmemb, (unsigned long) size, file, line);
return ptr; return ptr;
} }
void * void *debugging_malloc (size_t size, const char *file, unsigned long line)
debugging_malloc(size_t size, const char *file, unsigned long line)
{ {
void *ptr; void *ptr;
assert (size > 0); assert (size > 0);
ptr = malloc (size); ptr = malloc (size);
fprintf(stderr, "{malloc: %p:%u} %s:%lu\n", ptr, size, file, line); fprintf (stderr, "{malloc: %p:%lu} %s:%lu\n", ptr,
(unsigned long) size, file, line);
return ptr; return ptr;
} }
void * void *debugging_realloc (void *ptr, size_t size, const char *file,
debugging_realloc(void *ptr, size_t size, const char *file, unsigned long line) unsigned long line)
{ {
void *newptr; void *newptr;
assert(ptr != NULL);
assert (size > 0); assert (size > 0);
newptr = realloc (ptr, size); newptr = realloc (ptr, size);
fprintf(stderr, "{realloc: %p -> %p:%u} %s:%lu\n", ptr, newptr, size, fprintf (stderr, "{realloc: %p -> %p:%lu} %s:%lu\n", ptr, newptr,
file, line); (unsigned long) size, file, line);
return newptr; return newptr;
} }
void void debugging_free (void *ptr, const char *file, unsigned long line)
debugging_free(void *ptr, const char *file, unsigned long line)
{ {
assert(ptr != NULL);
fprintf (stderr, "{free: %p} %s:%lu\n", ptr, file, line); fprintf (stderr, "{free: %p} %s:%lu\n", ptr, file, line);
if (ptr != NULL)
free (ptr); free (ptr);
return; return;
} }
char* char *debugging_strdup (const char *s, const char *file, unsigned long line)
debugging_strdup(const char* s, const char* file, unsigned long line)
{ {
char *ptr; char *ptr;
size_t len; size_t len;
@@ -83,15 +85,18 @@ debugging_strdup(const char* s, const char* file, unsigned long line)
assert (s != NULL); assert (s != NULL);
len = strlen (s) + 1; len = strlen (s) + 1;
ptr = malloc(len); ptr = (char *) malloc (len);
if (!ptr) if (!ptr)
return NULL; return NULL;
memcpy (ptr, s, len); memcpy (ptr, s, len);
fprintf(stderr, "{strdup: %p:%u} %s:%lu\n", ptr, len, file, line); fprintf (stderr, "{strdup: %p:%lu} %s:%lu\n", ptr,
(unsigned long) len, file, line);
return ptr; return ptr;
} }
#endif /* !NDEBUG */
/* /*
* Allocate a block of memory in the "shared" memory region. * Allocate a block of memory in the "shared" memory region.
* *
@@ -100,25 +105,29 @@ debugging_strdup(const char* s, const char* file, unsigned long line)
* want to look into something like MM (Shared Memory Library) for a better * want to look into something like MM (Shared Memory Library) for a better
* solution. * solution.
*/ */
void* void *malloc_shared_memory (size_t size)
malloc_shared_memory(size_t size)
{ {
int fd; int fd;
void *ptr; void *ptr;
char buffer[32]; char buffer[32];
static char* shared_file = "/tmp/tinyproxy.shared.XXXXXX"; static const char *shared_file = "/tmp/tinyproxy.shared.XXXXXX";
assert (size > 0); assert (size > 0);
strlcpy (buffer, shared_file, sizeof (buffer)); strlcpy (buffer, shared_file, sizeof (buffer));
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask (0177);
if ((fd = mkstemp (buffer)) == -1) if ((fd = mkstemp (buffer)) == -1)
return (void *)MAP_FAILED; return MAP_FAILED;
unlink (buffer); unlink (buffer);
if (ftruncate (fd, size) == -1) if (ftruncate (fd, size) == -1)
return (void *)MAP_FAILED; return MAP_FAILED;
ptr = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ptr = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return ptr; return ptr;
@@ -128,8 +137,7 @@ malloc_shared_memory(size_t size)
* Allocate a block of memory from the "shared" region an initialize it to * Allocate a block of memory from the "shared" region an initialize it to
* zero. * zero.
*/ */
void* void *calloc_shared_memory (size_t nmemb, size_t size)
calloc_shared_memory(size_t nmemb, size_t size)
{ {
void *ptr; void *ptr;
long length; long length;
@@ -147,4 +155,3 @@ calloc_shared_memory(size_t nmemb, size_t size)
return ptr; return ptr;
} }
+20 -14
View File
@@ -1,20 +1,23 @@
/* $Id: heap.h,v 1.2 2002-05-26 18:56:06 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'heap.c' for a detailed description. * 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.
* *
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'heap.c' for detailed information. */
#ifndef TINYPROXY_HEAP_H #ifndef TINYPROXY_HEAP_H
#define TINYPROXY_HEAP_H #define TINYPROXY_HEAP_H
@@ -36,14 +39,17 @@ extern char *debugging_strdup(const char* s, const char* file,
# define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__) # define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__) # define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__) # define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
# define safefree(x) debugging_free(x, __FILE__, __LINE__); (x) = NULL
# define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__) # define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
# define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL)
#else #else
# define safecalloc(x, y) calloc(x, y) # define safecalloc(x, y) calloc(x, y)
# define safemalloc(x) malloc(x) # define safemalloc(x) malloc(x)
# define saferealloc(x, y) realloc(x, y) # define saferealloc(x, y) realloc(x, y)
# define safefree(x) free(x); (x) = NULL # define safefree(x) (free (x), *(&(x)) = NULL)
# define safestrdup(x) strdup(x) # define safestrdup(x) strdup(x)
#endif #endif
/* /*
+317
View File
@@ -0,0 +1,317 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2003 Steven Young <sdyoung@miranda.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.
*/
/* This file contains source code for the handling and display of
* HTML error pages with variable substitution.
*/
#include "main.h"
#include "common.h"
#include "buffer.h"
#include "conns.h"
#include "heap.h"
#include "html-error.h"
#include "network.h"
#include "utils.h"
#include "conf.h"
/*
* Add an error number -> filename mapping to the errorpages list.
*/
#define ERRORNUM_BUFSIZE 8 /* this is more than required */
#define ERRPAGES_BUCKETCOUNT 16
int add_new_errorpage (char *filepath, unsigned int errornum)
{
char errornbuf[ERRORNUM_BUFSIZE];
config.errorpages = hashmap_create (ERRPAGES_BUCKETCOUNT);
if (!config.errorpages)
return (-1);
snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
if (hashmap_insert (config.errorpages, errornbuf,
filepath, strlen (filepath) + 1) < 0)
return (-1);
return (0);
}
/*
* Get the file appropriate for a given error.
*/
static char *get_html_file (unsigned int errornum)
{
hashmap_iter result_iter;
char errornbuf[ERRORNUM_BUFSIZE];
char *key;
static char *val;
assert (errornum >= 100 && errornum < 1000);
if (!config.errorpages)
return (config.errorpage_undef);
snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
result_iter = hashmap_find (config.errorpages, errornbuf);
if (hashmap_is_end (config.errorpages, result_iter))
return (config.errorpage_undef);
if (hashmap_return_entry (config.errorpages, result_iter,
&key, (void **) &val) < 0)
return (config.errorpage_undef);
return (val);
}
/*
* Look up the value for a variable.
*/
static char *lookup_variable (struct conn_s *connptr, const char *varname)
{
hashmap_iter result_iter;
char *key;
static char *data;
result_iter = hashmap_find (connptr->error_variables, varname);
if (hashmap_is_end (connptr->error_variables, result_iter))
return (NULL);
if (hashmap_return_entry (connptr->error_variables, result_iter,
&key, (void **) &data) < 0)
return (NULL);
return (data);
}
/*
* Send an already-opened file to the client with variable substitution.
*/
int
send_html_file (FILE *infile, struct conn_s *connptr)
{
char *inbuf;
char *varstart = NULL;
char *p;
const char *varval;
int in_variable = 0;
int r = 0;
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);
if (!varval)
varval = "(unknown)";
r = write_message (connptr->client_fd,
"%s", varval);
in_variable = 0;
} else {
r = write_message (connptr->client_fd,
"%c", *p);
}
break;
case '{':
/* a {{ will print a single {. If we are NOT
* already in a { variable, then proceed with
* setup. If we ARE already in a { variable,
* this code will fallthrough to the code that
* just dumps a character to the client fd.
*/
if (!in_variable) {
varstart = p + 1;
in_variable++;
} else
in_variable = 0;
default:
if (!in_variable) {
r = write_message (connptr->client_fd,
"%c", *p);
}
}
if (r)
break;
}
if (r)
break;
in_variable = 0;
}
safefree (inbuf);
return r;
}
int send_http_headers (struct conn_s *connptr, int code, const char *message)
{
const char *headers =
"HTTP/1.0 %d %s\r\n"
"Server: %s/%s\r\n"
"Content-Type: text/html\r\n" "Connection: close\r\n" "\r\n";
return (write_message (connptr->client_fd, headers,
code, message, PACKAGE, VERSION));
}
/*
* Display an error to the client.
*/
int send_http_error_message (struct conn_s *connptr)
{
char *error_file;
FILE *infile;
int ret;
const char *fallback_error =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
"<html>\n"
"<head><title>%d %s</title></head>\n"
"<body>\n"
"<h1>%s</h1>\n"
"<p>%s</p>\n"
"<hr />\n"
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
"</html>\n";
send_http_headers (connptr, connptr->error_number,
connptr->error_string);
error_file = get_html_file (connptr->error_number);
if (!(infile = fopen (error_file, "r"))) {
char *detail = lookup_variable (connptr, "detail");
return (write_message (connptr->client_fd, fallback_error,
connptr->error_number,
connptr->error_string,
connptr->error_string,
detail, PACKAGE, VERSION));
}
ret = send_html_file (infile, connptr);
fclose (infile);
return (ret);
}
/*
* Add a key -> value mapping for HTML file substitution.
*/
#define ERRVAR_BUCKETCOUNT 16
int
add_error_variable (struct conn_s *connptr, const char *key, const char *val)
{
if (!connptr->error_variables)
if (!
(connptr->error_variables =
hashmap_create (ERRVAR_BUCKETCOUNT)))
return (-1);
return hashmap_insert (connptr->error_variables, key, val,
strlen (val) + 1);
}
#define ADD_VAR_RET(x, y) \
do { \
if (y == NULL) \
break; \
if (add_error_variable(connptr, x, y) < 0) \
return -1; \
} while (0)
/*
* Set some standard variables used by all HTML pages
*/
int add_standard_vars (struct conn_s *connptr)
{
char errnobuf[16];
char timebuf[30];
time_t global_time;
snprintf (errnobuf, sizeof errnobuf, "%d", connptr->error_number);
ADD_VAR_RET ("errno", errnobuf);
ADD_VAR_RET ("cause", connptr->error_string);
ADD_VAR_RET ("request", connptr->request_line);
ADD_VAR_RET ("clientip", connptr->client_ip_addr);
ADD_VAR_RET ("clienthost", connptr->client_string_addr);
/* The following value parts are all non-NULL and will
* trigger warnings in ADD_VAR_RET(), so we use
* add_error_variable() directly.
*/
global_time = time (NULL);
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
gmtime (&global_time));
add_error_variable (connptr, "date", timebuf);
add_error_variable (connptr, "website",
"https://banu.com/tinyproxy/");
add_error_variable (connptr, "version", VERSION);
add_error_variable (connptr, "package", PACKAGE);
return (0);
}
/*
* Add the error information to the conn structure.
*/
int
indicate_http_error (struct conn_s *connptr, int number,
const char *message, ...)
{
va_list ap;
char *key, *val;
va_start (ap, message);
while ((key = va_arg (ap, char *))) {
val = va_arg (ap, char *);
if (add_error_variable (connptr, key, val) == -1) {
va_end (ap);
return (-1);
}
}
connptr->error_number = number;
connptr->error_string = safestrdup (message);
va_end (ap);
return (add_standard_vars (connptr));
}
+38
View File
@@ -0,0 +1,38 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2003 Steven Young <sdyoung@miranda.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.
*/
/* See 'html-error.c' for detailed information. */
#ifndef TINYPROXY_HTML_ERROR_H
#define TINYPROXY_HTML_ERROR_H
/* Forward declaration */
struct conn_s;
extern int add_new_errorpage (char *filepath, unsigned int errornum);
extern int send_http_error_message (struct conn_s *connptr);
extern int indicate_http_error (struct conn_s *connptr, int number,
const char *message, ...);
extern int add_error_variable (struct conn_s *connptr, const char *key,
const char *val);
extern int send_html_file (FILE * infile, struct conn_s *connptr);
extern int send_http_headers (struct conn_s *connptr, int code,
const char *message);
extern int add_standard_vars (struct conn_s *connptr);
#endif /* !TINYPROXY_HTML_ERROR_H */
+271
View File
@@ -0,0 +1,271 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2003 Robert James Kaes <rjkaes@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'http-message.h' for detailed information. */
#include "common.h"
#include "heap.h"
#include "http-message.h"
#include "network.h"
/*
* Package up an HTTP message into a nice little structure. As you can
* see this structure doesn't actually store any allocated strings;
* therefore, the caller must free any memory referenced by this struct.
* Also, the caller MUST NOT free the memory while the structure is
* still in use---bad things would happen.
*/
struct http_message_s {
/* Response string and code supplied on the HTTP status line */
struct {
const char *string;
int code;
} response;
/*
* A group of headers to be sent with this message. Right now
* the strings are referenced through pointers in an array.
* I might change this to a vector in the future.
*/
struct {
const char **strings;
unsigned int total;
unsigned int used;
} headers;
/* Body of the message (most likely an HTML message) */
struct {
const char *text;
size_t length;
} body;
};
/*
* Check if the HTTP message is validly formed. This is the one odd-ball
* function. It returns 0 if the message is invalid; otherwise, a positive
* number is returned. Useful for if() tests and assert() tests.
*/
static int is_http_message_valid (http_message_t msg)
{
if (msg == NULL)
return 0;
if (msg->headers.strings == NULL)
return 0;
if (msg->response.string == NULL)
return 0;
if (msg->response.code < 1 || msg->response.code > 999)
return 0;
return 1;
}
/* Initially allocate space for 128 headers */
#define NUMBER_OF_HEADERS 128
/*
* Allocate a new http_message structure on the heap.
* If memory could not be allocated, return a NULL.
*/
http_message_t
http_message_create (int response_code, const char *response_string)
{
http_message_t msg;
int ret;
msg =
(struct http_message_s *) safecalloc (1,
sizeof (struct
http_message_s));
if (msg == NULL)
return NULL;
msg->headers.strings = (const char **) safecalloc (NUMBER_OF_HEADERS,
sizeof (char *));
if (msg->headers.strings == NULL) {
safefree (msg);
return NULL;
}
msg->headers.total = NUMBER_OF_HEADERS;
/* Store the HTTP response information in the structure */
ret = http_message_set_response (msg, response_code, response_string);
if (IS_HTTP_MSG_ERROR (ret)) {
safefree (msg->headers.strings);
safefree (msg);
return NULL;
}
return msg;
}
/*
* Free up the space associated with this HTTP message structure.
* This DOES NOT free the pointers stored in this structure. That memory
* is the responsibility of the caller.
*/
int http_message_destroy (http_message_t msg)
{
assert (msg != NULL);
assert (msg->headers.strings != NULL);
/* Check for valid arguments */
if (msg == NULL)
return -EFAULT;
if (msg->headers.strings != NULL)
safefree (msg->headers.strings);
safefree (msg);
return 0;
}
/*
* Set the HTTP response information for this structure. The response_string
* must be a NUL ('\0') terminated C string.
*/
int
http_message_set_response (http_message_t msg,
int response_code, const char *response_string)
{
/* Check for valid arguments */
if (msg == NULL)
return -EFAULT;
if (response_code < 1 || response_code > 999)
return -EINVAL;
if (response_string == NULL)
return -EINVAL;
if (strlen (response_string) == 0)
return -EINVAL;
msg->response.code = response_code;
msg->response.string = response_string;
return 0;
}
/*
* Set the HTTP message body.
*/
int http_message_set_body (http_message_t msg, const char *body, size_t len)
{
/* Check for valid arguments */
if (msg == NULL)
return -EFAULT;
if (body == NULL)
return -EINVAL;
if (len == 0)
return -EINVAL;
msg->body.text = body;
msg->body.length = len;
return 0;
}
/*
* Add headers to the structure.
*/
int
http_message_add_headers (http_message_t msg, const char **headers,
unsigned int num_headers)
{
const char **new_headers;
unsigned int i;
/* Check for valid arguments */
if (msg == NULL)
return -EFAULT;
if (headers == NULL)
return -EINVAL;
/*
* If the number of headers to add is greater than the space
* available, reallocate the memory.
*/
if (msg->headers.used + num_headers > msg->headers.total) {
new_headers =
(const char **) safecalloc (msg->headers.total * 2,
sizeof (char *));
if (new_headers == NULL)
return -ENOMEM;
/* Copy the array */
for (i = 0; i != msg->headers.used; ++i)
new_headers[i] = msg->headers.strings[i];
/* Remove the old array and replace it with the new array */
safefree (msg->headers.strings);
msg->headers.strings = new_headers;
msg->headers.total *= 2;
}
/*
* Add the new headers to the structure
*/
for (i = 0; i != num_headers; ++i)
msg->headers.strings[i + msg->headers.used] = headers[i];
msg->headers.used += num_headers;
return 0;
}
/*
* Send the completed HTTP message via the supplied file descriptor.
*/
int http_message_send (http_message_t msg, int fd)
{
char timebuf[30];
time_t global_time;
unsigned int i;
assert (is_http_message_valid (msg));
/* Check for valid arguments */
if (msg == NULL)
return -EFAULT;
if (fd < 1)
return -EBADF;
if (!is_http_message_valid (msg))
return -EINVAL;
/* Write the response line */
write_message (fd, "HTTP/1.0 %d %s\r\n",
msg->response.code, msg->response.string);
/* Go through all the headers */
for (i = 0; i != msg->headers.used; ++i)
write_message (fd, "%s\r\n", msg->headers.strings[i]);
/* Output the date */
global_time = time (NULL);
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
gmtime (&global_time));
write_message (fd, "Date: %s\r\n", timebuf);
/* Output the content-length */
write_message (fd, "Content-length: %u\r\n", msg->body.length);
/* Write the separator between the headers and body */
safe_write (fd, "\r\n", 2);
/* If there's a body, send it! */
if (msg->body.length > 0)
safe_write (fd, msg->body.text, msg->body.length);
return 0;
}
+94
View File
@@ -0,0 +1,94 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2003 Robert James Kaes <rjkaes@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* HTTP Message API
* ----------------
* The idea behind this application programming interface (API) is to
* represent an HTTP response message as a concrete entity. The API
* functions allow the message to be built up systematically before
* transmission to a connected socket.
*
* The order of the functions in your program would look something like
* this:
* http_message_create()
* http_message_set_response()
* http_message_set_body() [optional if no body is required]
* http_message_add_headers() [optional if no additional headers are used]
* http_message_send()
* http_message_destroy()
*
* NOTE: No user data is stored in the http_message_t type; therefore,
* do not delete strings referenced by the http_message_t object
* before you call http_message_destroy(). By not copying data, the
* API functions are faster, but you must take greater care.
*
* (Side note: be _very_ careful when using stack allocated memory with
* this API. Bad things will happen if you try to pass the
* http_message_t out of the calling function since the stack
* allocated memory referenced by the http_message_t will no long
* exist.)
*/
#ifndef _TINYPROXY_HTTP_MESSAGE_H_
#define _TINYPROXY_HTTP_MESSAGE_H_
/* Use the "http_message_t" as a cookie or handle to the structure. */
typedef struct http_message_s *http_message_t;
/*
* Macro to test if an error occurred with the API. All the HTTP message
* functions will return 0 if no error occurred, or a negative number if
* there was a problem.
*/
#define IS_HTTP_MSG_ERROR(x) (x < 0)
/* Initialize the internal structure of the HTTP message */
extern http_message_t http_message_create (int response_code,
const char *response_string);
/* Free up an _internal_ resources */
extern int http_message_destroy (http_message_t msg);
/*
* Send an HTTP message via the supplied file descriptor. This function
* will add the "Date" header before it's sent.
*/
extern int http_message_send (http_message_t msg, int fd);
/*
* Change the internal state of the HTTP message. Either set the
* body of the message, update the response information, or
* add a new set of headers.
*/
extern int http_message_set_body (http_message_t msg,
const char *body, size_t len);
extern int http_message_set_response (http_message_t msg,
int response_code,
const char *response_string);
/*
* Set the headers for this HTTP message. Each string must be NUL ('\0')
* terminated, but DO NOT include any carriage returns (CR) or
* line-feeds (LF) since they will be included when the http_message is
* sent.
*/
extern int http_message_add_headers (http_message_t msg,
const char **headers,
unsigned int num_headers);
#endif /* _TINYPROXY_HTTP_MESSAGE_H_ */
+138 -61
View File
@@ -1,30 +1,36 @@
/* $Id: log.c,v 1.23 2002-10-03 20:49:57 rjkaes Exp $ /* 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>
* *
* Logs the various messages which tinyproxy produces to either a log file or * This program is free software; you can redistribute it and/or modify
* the syslog daemon. Not much to it... * 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.
* *
* Copyright (C) 1998 Steven Young * This program is distributed in the hope that it will be useful,
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
#include "tinyproxy.h" /* Logs the various messages which tinyproxy produces to either a log file
* or the syslog daemon. Not much to it...
*/
#include "main.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "utils.h" #include "utils.h"
#include "vector.h" #include "vector.h"
#include "conf.h"
static char *syslog_level[] = { static const char *syslog_level[] = {
NULL, NULL,
NULL, NULL,
"CRITICAL", "CRITICAL",
@@ -57,11 +63,12 @@ static int log_level = LOG_INFO;
*/ */
static vector_t log_message_storage; 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. * Open the log file and store the file descriptor in a global location.
*/ */
int int open_log_file (const char *log_file_name)
open_log_file(const char* log_file_name)
{ {
log_file_fd = create_file_safely (log_file_name, FALSE); log_file_fd = create_file_safely (log_file_name, FALSE);
return log_file_fd; return log_file_fd;
@@ -70,27 +77,20 @@ open_log_file(const char* log_file_name)
/* /*
* Close the log file * Close the log file
*/ */
void void close_log_file (void)
close_log_file(void)
{ {
close(log_file_fd); if (log_file_fd < 0) {
return;
} }
/* close (log_file_fd);
* Truncate log file to a zero length. log_file_fd = -1;
*/
void
truncate_log_file(void)
{
lseek(log_file_fd, 0, SEEK_SET);
ftruncate(log_file_fd, 0);
} }
/* /*
* Set the log level for writing to the log file. * Set the log level for writing to the log file.
*/ */
void void set_log_level (int level)
set_log_level(int level)
{ {
log_level = level; log_level = level;
} }
@@ -98,8 +98,7 @@ set_log_level(int level)
/* /*
* This routine logs messages to either the log file or the syslog function. * This routine logs messages to either the log file or the syslog function.
*/ */
void void log_message (int level, const char *fmt, ...)
log_message(int level, char *fmt, ...)
{ {
va_list args; va_list args;
time_t nowtime; time_t nowtime;
@@ -107,6 +106,8 @@ log_message(int level, char *fmt, ...)
char time_string[TIME_LENGTH]; char time_string[TIME_LENGTH];
char str[STRING_LENGTH]; char str[STRING_LENGTH];
ssize_t ret;
#ifdef NDEBUG #ifdef NDEBUG
/* /*
* Figure out if we should write the message or not. * Figure out if we should write the message or not.
@@ -121,10 +122,8 @@ log_message(int level, char *fmt, ...)
return; return;
#endif #endif
#ifdef HAVE_SYSLOG_H
if (config.syslog && level == LOG_CONN) if (config.syslog && level == LOG_CONN)
level = LOG_INFO; level = LOG_INFO;
#endif
va_start (args, fmt); va_start (args, fmt);
@@ -132,31 +131,29 @@ log_message(int level, char *fmt, ...)
* If the config file hasn't been processed, then we need to store * If the config file hasn't been processed, then we need to store
* the messages for later processing. * the messages for later processing.
*/ */
if (!processed_config_file) { if (!logging_initialized) {
char *entry_buffer; char *entry_buffer;
if (!log_message_storage) { if (!log_message_storage) {
log_message_storage = vector_create (); log_message_storage = vector_create ();
if (!log_message_storage) if (!log_message_storage)
return; goto out;
} }
vsnprintf (str, STRING_LENGTH, fmt, args); vsnprintf (str, STRING_LENGTH, fmt, args);
entry_buffer = safemalloc(strlen(str) + 6); entry_buffer = (char *) safemalloc (strlen (str) + 6);
if (!entry_buffer) if (!entry_buffer)
return; goto out;
sprintf (entry_buffer, "%d %s", level, str); sprintf (entry_buffer, "%d %s", level, str);
vector_insert(log_message_storage, entry_buffer, vector_append (log_message_storage, entry_buffer,
strlen (entry_buffer) + 1); strlen (entry_buffer) + 1);
va_end(args); safefree (entry_buffer);
goto out;
return;
} }
#ifdef HAVE_SYSLOG_H
if (config.syslog) { if (config.syslog) {
#ifdef HAVE_VSYSLOG_H #ifdef HAVE_VSYSLOG_H
vsyslog (level, fmt, args); vsyslog (level, fmt, args);
@@ -165,49 +162,71 @@ log_message(int level, char *fmt, ...)
syslog (level, "%s", str); syslog (level, "%s", str);
#endif #endif
} else { } else {
#endif char *p;
nowtime = time (NULL); nowtime = time (NULL);
/* Format is month day hour:minute:second (24 time) */ /* Format is month day hour:minute:second (24 time) */
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S", strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
localtime (&nowtime)); localtime (&nowtime));
snprintf(str, STRING_LENGTH, "%-9s %s [%ld]: ", syslog_level[level], snprintf (str, STRING_LENGTH, "%-9s %s [%ld]: ",
time_string, (long int) getpid()); 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); assert (log_file_fd >= 0);
write(log_file_fd, str, strlen(str)); ret = write (log_file_fd, str, strlen (str));
vsnprintf(str, STRING_LENGTH, fmt, args); if (ret == -1) {
write(log_file_fd, str, strlen(str)); config.syslog = TRUE;
write(log_file_fd, "\n", 1);
#ifdef HAVE_SYSLOG_H log_message(LOG_CRIT, "ERROR: Could not write to log "
"file %s: %s.",
config.logf_name, strerror(errno));
log_message(LOG_CRIT,
"Falling back to syslog logging");
} }
#endif
fsync (log_file_fd);
}
out:
va_end (args); va_end (args);
} }
/* /*
* This needs to send any stored log messages. * This needs to send any stored log messages.
*/ */
void void send_stored_logs (void)
send_stored_logs(void)
{ {
char *string; char *string;
char *ptr; char *ptr;
int level; int level;
size_t i;
int i; if (log_message_storage == NULL)
return;
for (i = 0; i < vector_length(log_message_storage); ++i) { log_message(LOG_DEBUG, "sending stored logs");
vector_getentry(log_message_storage, i, (void **)&string);
for (i = 0; (ssize_t) i != vector_length (log_message_storage); ++i) {
string =
(char *) vector_getentry (log_message_storage, i, NULL);
ptr = strchr (string, ' ') + 1; ptr = strchr (string, ' ') + 1;
level = atoi (string); level = atoi (string);
#if NDEBUG #ifdef NDEBUG
if (log_level == LOG_CONN && level == LOG_INFO) if (log_level == LOG_CONN && level == LOG_INFO)
continue; continue;
else if (log_level == LOG_INFO) { else if (log_level == LOG_INFO) {
@@ -217,9 +236,67 @@ send_stored_logs(void)
continue; continue;
#endif #endif
log_message(level, ptr); log_message (level, "%s", ptr);
} }
vector_delete (log_message_storage); vector_delete (log_message_storage);
log_message_storage = NULL; 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.",
config.logf_name, strerror (errno));
log_message (LOG_CRIT,
"Falling back to syslog logging.");
}
}
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;
} }
+30 -17
View File
@@ -1,21 +1,25 @@
/* $Id: log.h,v 1.11 2002-10-03 20:49:57 rjkaes Exp $ /* 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>
* *
* See 'log.c' for a detailed description. * 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.
* *
* Copyright (C) 1998 Steven Young * This program is distributed in the hope that it will be useful,
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'log.c' for detailed information. */
#ifndef TINYPROXY_LOG_H #ifndef TINYPROXY_LOG_H
#define TINYPROXY_LOG_H #define TINYPROXY_LOG_H
@@ -86,14 +90,21 @@
#define LOG_CONN 8 /* extra to log connections without the INFO stuff */ #define LOG_CONN 8 /* extra to log connections without the INFO stuff */
/* Suppress warnings when GCC is in -pedantic mode and not -std=c99 */
#if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
#pragma GCC system_header
#endif
/* /*
* Use this for debugging. The format is specific: * Use this for debugging. The format is specific:
* DEBUG1("There was a major problem"); * DEBUG1("There was a major problem");
* DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr); * DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr);
*/ */
#ifndef NDEBUG #ifndef NDEBUG
# define DEBUG1(x) log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__) # define DEBUG1(x) \
# define DEBUG2(x, y...) log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__, ## y) log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__)
# define DEBUG2(x, y...) \
log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__, ## y)
#else #else
# define DEBUG1(x) do { } while(0) # define DEBUG1(x) do { } while(0)
# define DEBUG2(x, y...) do { } while(0) # define DEBUG2(x, y...) do { } while(0)
@@ -101,10 +112,12 @@
extern int open_log_file (const char *file); extern int open_log_file (const char *file);
extern void close_log_file (void); extern void close_log_file (void);
extern void truncate_log_file(void);
extern void log_message(int level, char *fmt, ...); extern void log_message (int level, const char *fmt, ...);
extern void set_log_level (int level); extern void set_log_level (int level);
extern void send_stored_logs (void); extern void send_stored_logs (void);
extern int setup_logging (void);
extern void shutdown_logging (void);
#endif #endif
+494
View File
@@ -0,0 +1,494 @@
/* 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
* 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.
*/
/* The initialize routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops
* over the new connections until the daemon is closed. Also has additional
* functions to handle the "user friendly" aspects of a program (usage,
* stats, etc.) Like any good program, most of the work is actually done
* elsewhere.
*/
#include "main.h"
#include "anonymous.h"
#include "buffer.h"
#include "conf.h"
#include "daemon.h"
#include "heap.h"
#include "filter.h"
#include "child.h"
#include "log.h"
#include "reqs.h"
#include "sock.h"
#include "stats.h"
#include "utils.h"
/*
* Global Structures
*/
struct config_s config;
struct config_s config_defaults;
unsigned int received_sighup = FALSE; /* boolean */
/*
* Handle a signal
*/
static void
takesig (int sig)
{
pid_t pid;
int status;
switch (sig) {
case SIGHUP:
received_sighup = TRUE;
break;
case SIGTERM:
config.quit = TRUE;
break;
case SIGCHLD:
while ((pid = waitpid (-1, &status, WNOHANG)) > 0) ;
break;
}
return;
}
/*
* Display the version information for the user.
*/
static void
display_version (void)
{
printf ("%s %s\n", PACKAGE, VERSION);
}
/*
* Display the copyright and license for this program.
*/
static void
display_license (void)
{
display_version ();
printf ("\
Copyright 1998 Steven Young (sdyoung@well.com)\n\
Copyright 1998-2002 Robert James Kaes (rjkaes@users.sourceforge.net)\n\
Copyright 1999 George Talusan (gstalusan@uwaterloo.ca)\n\
Copyright 2000 Chris Lightfoot (chris@ex-parrot.com)\n\
Copyright 2009-2010 Mukund Sivaraman (muks@banu.com)\n\
Copyright 2009-2010 Michael Adam (obnox@samba.org)\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation; either version 2, or (at your option)\n\
any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n");
}
/*
* Display usage to the user.
*/
static void
display_usage (void)
{
int features = 0;
printf ("Usage: %s [options]\n", PACKAGE);
printf ("\n"
"Options are:\n"
" -d Do not daemonize (run in foreground).\n"
" -c FILE Use an alternate configuration file.\n"
" -h Display this usage information.\n"
" -l Display the license.\n"
" -v Display version information.\n");
/* Display the modes compiled into tinyproxy */
printf ("\nFeatures compiled in:\n");
#ifdef XTINYPROXY_ENABLE
printf (" XTinyproxy header\n");
features++;
#endif /* XTINYPROXY */
#ifdef FILTER_ENABLE
printf (" Filtering\n");
features++;
#endif /* FILTER_ENABLE */
#ifndef NDEBUG
printf (" Debugging code\n");
features++;
#endif /* NDEBUG */
#ifdef TRANSPARENT_PROXY
printf (" Transparent proxy support\n");
features++;
#endif /* TRANSPARENT_PROXY */
#ifdef REVERSE_SUPPORT
printf (" Reverse proxy support\n");
features++;
#endif /* REVERSE_SUPPORT */
#ifdef UPSTREAM_SUPPORT
printf (" Upstream proxy support\n");
features++;
#endif /* UPSTREAM_SUPPORT */
if (0 == features)
printf (" None\n");
printf ("\n"
"For bug reporting instructions, please see:\n"
"<https://banu.com/tinyproxy/>.\n");
}
static int
get_id (char *str)
{
char *tstr;
if (str == NULL)
return -1;
tstr = str;
while (*tstr != 0) {
if (!isdigit (*tstr))
return -1;
tstr++;
}
return atoi (str);
}
/**
* process_cmdline:
* @argc: argc as passed to main()
* @argv: argv as passed to main()
*
* This function parses command line arguments.
**/
static void
process_cmdline (int argc, char **argv, struct config_s *conf)
{
int opt;
while ((opt = getopt (argc, argv, "c:vldh")) != EOF) {
switch (opt) {
case 'v':
display_version ();
exit (EX_OK);
case 'l':
display_license ();
exit (EX_OK);
case 'd':
conf->godaemon = FALSE;
break;
case 'c':
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]);
exit (EX_SOFTWARE);
}
break;
case 'h':
display_usage ();
exit (EX_OK);
default:
display_usage ();
exit (EX_USAGE);
}
}
}
/**
* change_user:
* @program: The name of the program. Pass argv[0] here.
*
* This function tries to change UID and GID to the ones specified in
* the config file. This function is typically called during
* initialization when the effective user is root.
**/
static void
change_user (const char *program)
{
if (config.group && strlen (config.group) > 0) {
int gid = get_id (config.group);
if (gid < 0) {
struct group *thisgroup = getgrnam (config.group);
if (!thisgroup) {
fprintf (stderr,
"%s: Unable to find group \"%s\".\n",
program, config.group);
exit (EX_NOUSER);
}
gid = thisgroup->gr_gid;
}
if (setgid (gid) < 0) {
fprintf (stderr,
"%s: Unable to change to group \"%s\".\n",
program, config.group);
exit (EX_NOPERM);
}
#ifdef HAVE_SETGROUPS
/* Drop all supplementary groups, otherwise these are inherited from the calling process */
if (setgroups (0, NULL) < 0) {
fprintf (stderr,
"%s: Unable to drop supplementary groups.\n",
program);
exit (EX_NOPERM);
}
#endif
log_message (LOG_INFO, "Now running as group \"%s\".",
config.group);
}
if (config.user && strlen (config.user) > 0) {
int uid = get_id (config.user);
if (uid < 0) {
struct passwd *thisuser = getpwnam (config.user);
if (!thisuser) {
fprintf (stderr,
"%s: Unable to find user \"%s\".\n",
program, config.user);
exit (EX_NOUSER);
}
uid = thisuser->pw_uid;
}
if (setuid (uid) < 0) {
fprintf (stderr,
"%s: Unable to change to user \"%s\".\n",
program, config.user);
exit (EX_NOPERM);
}
log_message (LOG_INFO, "Now running as user \"%s\".",
config.user);
}
}
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)
{
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask (0177);
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
if (config_compile_regex()) {
exit (EX_SOFTWARE);
}
initialize_config_defaults (&config_defaults);
process_cmdline (argc, argv, &config_defaults);
if (reload_config_file (config_defaults.config_file,
&config,
&config_defaults)) {
exit (EX_SOFTWARE);
}
init_stats ();
/* If ANONYMOUS is turned on, make sure that Content-Length is
* in the list of allowed headers, since it is required in a
* HTTP/1.0 request. Also add the Content-Type header since it
* goes hand in hand with Content-Length. */
if (is_anonymous_enabled ()) {
anonymous_insert ("Content-Length");
anonymous_insert ("Content-Type");
}
if (config.godaemon == TRUE)
makedaemon ();
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
argv[0]);
exit (EX_OSERR);
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_init ();
#endif /* FILTER_ENABLE */
/* Start listening on the selected port. */
if (child_listening_sockets(config.listen_addrs, config.port) < 0) {
fprintf (stderr, "%s: Could not create listening sockets.\n",
argv[0]);
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.");
/* Create log file after we drop privileges */
if (setup_logging ()) {
exit (EX_SOFTWARE);
}
/* Create pid file after we drop privileges */
if (config.pidpath) {
if (pidfile_create (config.pidpath) < 0) {
fprintf (stderr, "%s: Could not create PID file.\n",
argv[0]);
exit (EX_OSERR);
}
}
if (child_pool_create () < 0) {
fprintf (stderr,
"%s: Could not create the pool of children.\n",
argv[0]);
exit (EX_SOFTWARE);
}
/* These signals are only for the parent process. */
log_message (LOG_INFO, "Setting the various signals.");
if (set_signal_handler (SIGCHLD, takesig) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGCHLD\" signal.\n",
argv[0]);
exit (EX_OSERR);
}
if (set_signal_handler (SIGTERM, takesig) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGTERM\" signal.\n",
argv[0]);
exit (EX_OSERR);
}
if (set_signal_handler (SIGHUP, takesig) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGHUP\" signal.\n",
argv[0]);
exit (EX_OSERR);
}
/* Start the main loop */
log_message (LOG_INFO, "Starting main loop. Accepting connections.");
child_main_loop ();
log_message (LOG_INFO, "Shutting down.");
child_kill_children (SIGTERM);
child_close_sock ();
/* Remove the PID file */
if (unlink (config.pidpath) < 0) {
log_message (LOG_WARNING,
"Could not remove PID file \"%s\": %s.",
config.pidpath, strerror (errno));
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy ();
#endif /* FILTER_ENABLE */
shutdown_logging ();
return EXIT_SUCCESS;
}
+37
View File
@@ -0,0 +1,37 @@
/* 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>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'main.c' for detailed information. */
#ifndef __MAIN_H__
#define __MAIN_H__
#include "common.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 */
/* Global Structures used in the program */
extern struct config_s config;
extern unsigned int received_sighup; /* boolean */
extern int reload_config (void);
#endif /* __MAIN_H__ */
+122 -33
View File
@@ -1,25 +1,29 @@
/* $Id: network.c,v 1.1 2002-05-23 04:41:48 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* The functions found here are used for communicating across a * 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.
*/
/* The functions found here are used for communicating across a
* network. They include both safe reading and writing (which are * network. They include both safe reading and writing (which are
* the basic building blocks) along with two functions for * the basic building blocks) along with two functions for
* easily reading a line of text from the network, and a function * easily reading a line of text from the network, and a function
* to write an arbitrary amount of data to the network. * to write an arbitrary amount of data to the network.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "heap.h" #include "heap.h"
#include "network.h" #include "network.h"
@@ -28,8 +32,7 @@
* Write the buffer to the socket. If an EINTR occurs, pick up and try * Write the buffer to the socket. If an EINTR occurs, pick up and try
* again. Keep sending until the buffer has been sent. * again. Keep sending until the buffer has been sent.
*/ */
ssize_t ssize_t safe_write (int fd, const char *buffer, size_t count)
safe_write(int fd, const char *buffer, size_t count)
{ {
ssize_t len; ssize_t len;
size_t bytestosend; size_t bytestosend;
@@ -50,7 +53,7 @@ safe_write(int fd, const char *buffer, size_t count)
return -errno; return -errno;
} }
if (len == bytestosend) if ((size_t) len == bytestosend)
break; break;
buffer += len; buffer += len;
@@ -64,8 +67,7 @@ safe_write(int fd, const char *buffer, size_t count)
* Matched pair for safe_write(). If an EINTR occurs, pick up and try * Matched pair for safe_write(). If an EINTR occurs, pick up and try
* again. * again.
*/ */
ssize_t ssize_t safe_read (int fd, char *buffer, size_t count)
safe_read(int fd, char *buffer, size_t count)
{ {
ssize_t len; ssize_t len;
@@ -82,15 +84,14 @@ safe_read(int fd, char *buffer, size_t count)
* was basically stolen from the snprintf() man page of Debian Linux * was basically stolen from the snprintf() man page of Debian Linux
* (although I did fix a memory leak. :) * (although I did fix a memory leak. :)
*/ */
int int write_message (int fd, const char *fmt, ...)
write_message(int fd, const char *fmt, ...)
{ {
ssize_t n; ssize_t n;
size_t size = (1024 * 8); /* start with 8 KB and go from there */ size_t size = (1024 * 8); /* start with 8 KB and go from there */
char *buf, *tmpbuf; char *buf, *tmpbuf;
va_list ap; va_list ap;
if ((buf = safemalloc(size)) == NULL) if ((buf = (char *) safemalloc (size)) == NULL)
return -1; return -1;
while (1) { while (1) {
@@ -99,7 +100,7 @@ write_message(int fd, const char *fmt, ...)
va_end (ap); va_end (ap);
/* If that worked, break out so we can send the buffer */ /* If that worked, break out so we can send the buffer */
if (n > -1 && n < size) if (n > -1 && (size_t) n < size)
break; break;
/* Else, try again with more space */ /* Else, try again with more space */
@@ -110,7 +111,7 @@ write_message(int fd, const char *fmt, ...)
/* twice the old size (glibc2.0) */ /* twice the old size (glibc2.0) */
size *= 2; size *= 2;
if ((tmpbuf = saferealloc(buf, size)) == NULL) { if ((tmpbuf = (char *) saferealloc (buf, size)) == NULL) {
safefree (buf); safefree (buf);
return -1; return -1;
} else } else
@@ -137,8 +138,7 @@ write_message(int fd, const char *fmt, ...)
*/ */
#define SEGMENT_LEN (512) #define SEGMENT_LEN (512)
#define MAXIMUM_BUFFER_LENGTH (128 * 1024) #define MAXIMUM_BUFFER_LENGTH (128 * 1024)
ssize_t ssize_t readline (int fd, char **whole_buffer)
readline(int fd, char **whole_buffer)
{ {
ssize_t whole_buffer_len; ssize_t whole_buffer_len;
char buffer[SEGMENT_LEN]; char buffer[SEGMENT_LEN];
@@ -154,7 +154,9 @@ readline(int fd, char **whole_buffer)
}; };
struct read_lines_s *first_line, *line_ptr; struct read_lines_s *first_line, *line_ptr;
first_line = safecalloc(sizeof(struct read_lines_s), 1); first_line =
(struct read_lines_s *) safecalloc (sizeof (struct read_lines_s),
1);
if (!first_line) if (!first_line)
return -ENOMEM; return -ENOMEM;
@@ -166,7 +168,7 @@ readline(int fd, char **whole_buffer)
if (ret <= 0) if (ret <= 0)
goto CLEANUP; goto CLEANUP;
ptr = memchr(buffer, '\n', ret); ptr = (char *) memchr (buffer, '\n', ret);
if (ptr) if (ptr)
diff = ptr - buffer + 1; diff = ptr - buffer + 1;
else else
@@ -183,13 +185,17 @@ readline(int fd, char **whole_buffer)
goto CLEANUP; goto CLEANUP;
} }
line_ptr->data = safemalloc(diff); line_ptr->data = (char *) safemalloc (diff);
if (!line_ptr->data) { if (!line_ptr->data) {
ret = -ENOMEM; ret = -ENOMEM;
goto CLEANUP; goto CLEANUP;
} }
recv(fd, line_ptr->data, diff, 0); ret = recv (fd, line_ptr->data, diff, 0);
if (ret == -1) {
goto CLEANUP;
}
line_ptr->len = diff; line_ptr->len = diff;
if (ptr) { if (ptr) {
@@ -197,7 +203,9 @@ readline(int fd, char **whole_buffer)
break; break;
} }
line_ptr->next = safecalloc(sizeof(struct read_lines_s), 1); line_ptr->next =
(struct read_lines_s *)
safecalloc (sizeof (struct read_lines_s), 1);
if (!line_ptr->next) { if (!line_ptr->next) {
ret = -ENOMEM; ret = -ENOMEM;
goto CLEANUP; goto CLEANUP;
@@ -205,7 +213,7 @@ readline(int fd, char **whole_buffer)
line_ptr = line_ptr->next; line_ptr = line_ptr->next;
} }
*whole_buffer = safemalloc(whole_buffer_len + 1); *whole_buffer = (char *) safemalloc (whole_buffer_len + 1);
if (!*whole_buffer) { if (!*whole_buffer) {
ret = -ENOMEM; ret = -ENOMEM;
goto CLEANUP; goto CLEANUP;
@@ -236,3 +244,84 @@ readline(int fd, char **whole_buffer)
return ret; return ret;
} }
/*
* Convert the network address into either a dotted-decimal or an IPv6
* hex string.
*/
char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{
assert (sa != NULL);
assert (buf != NULL);
assert (buflen != 0);
buf[0] = '\0'; /* start with an empty string */
switch (sa->sa_family) {
case AF_INET:
{
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
inet_ntop (AF_INET, &sa_in->sin_addr, buf, buflen);
break;
}
case AF_INET6:
{
struct sockaddr_in6 *sa_in6 =
(struct sockaddr_in6 *) sa;
inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, buflen);
break;
}
default:
/* no valid family */
return NULL;
}
return buf;
}
/*
* Convert a numeric character string into an IPv6 network address
* (in binary form.) The function works just like inet_pton(), but it
* will accept both IPv4 and IPv6 numeric addresses.
*
* Returns the same as inet_pton().
*/
int full_inet_pton (const char *ip, void *dst)
{
char buf[24], tmp[24]; /* IPv4->IPv6 = ::FFFF:xxx.xxx.xxx.xxx\0 */
int n;
assert (ip != NULL && strlen (ip) != 0);
assert (dst != NULL);
/*
* Check if the string is an IPv4 numeric address. We use the
* older inet_aton() call since it handles more IPv4 numeric
* address formats.
*/
n = inet_aton (ip, (struct in_addr *) dst);
if (n == 0) {
/*
* Simple case: "ip" wasn't an IPv4 numeric address, so
* try doing the conversion as an IPv6 address. This
* will either succeed or fail, but we can't do any
* more processing anyway.
*/
return inet_pton (AF_INET6, ip, dst);
}
/*
* "ip" was an IPv4 address, so we need to convert it to
* an IPv4-mapped IPv6 address and do the conversion
* again to get the IPv6 network structure.
*
* We convert the IPv4 binary address back into the
* standard dotted-decimal format using inet_ntop()
* so we can be sure that inet_pton will accept the
* full string.
*/
snprintf (buf, sizeof (buf), "::ffff:%s",
inet_ntop (AF_INET, dst, tmp, sizeof (tmp)));
return inet_pton (AF_INET6, buf, dst);
}
+18 -12
View File
@@ -1,20 +1,23 @@
/* $Id: network.h,v 1.1 2002-05-23 04:41:48 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'network.c' for a detailed description. * 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.
* *
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'network.c' for detailed information. */
#ifndef TINYPROXY_NETWORK_H #ifndef TINYPROXY_NETWORK_H
#define TINYPROXY_NETWORK_H #define TINYPROXY_NETWORK_H
@@ -24,4 +27,7 @@ extern ssize_t safe_read(int fd, char *buffer, size_t count);
extern int write_message (int fd, const char *fmt, ...); extern int write_message (int fd, const char *fmt, ...);
extern ssize_t readline (int fd, char **whole_buffer); extern ssize_t readline (int fd, char **whole_buffer);
extern char *get_ip_string (struct sockaddr *sa, char *buf, size_t len);
extern int full_inet_pton (const char *ip, void *dst);
#endif #endif
-35
View File
@@ -1,35 +0,0 @@
/* $Id: regexp.h,v 1.3 2001-11-25 22:06:54 rjkaes Exp $
*
* We need this little header to help distinguish whether to use the REGEX
* library installed in the system, or to include our own version (the GNU
* version to be exact.)
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/
#ifndef _TINYPROXY_REGEXP_H_
#define _TINYPROXY_REGEXP_H_
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef USE_GNU_REGEX
# include "gnuregex.h"
#else
# ifdef HAVE_REGEX_H
# include <regex.h>
# endif
#endif
#endif
+696 -481
View File
File diff suppressed because it is too large. Load diff
+37 -14
View File
@@ -1,25 +1,48 @@
/* $Id: reqs.h,v 1.3 2002-04-12 17:00:42 rjkaes Exp $ /* 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>
* *
* See 'reqs.c' for a detailed description. * 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.
* *
* Copyright (C) 1998 Steven Young * This program is distributed in the hope that it will be useful,
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'reqs.c' for detailed information. */
#ifndef _TINYPROXY_REQS_H_ #ifndef _TINYPROXY_REQS_H_
#define _TINYPROXY_REQS_H_ #define _TINYPROXY_REQS_H_
#include "common.h"
/*
* Port constants for HTTP (80) and SSL (443)
*/
#define HTTP_PORT 80
#define HTTP_PORT_SSL 443
/*
* This structure holds the information pulled from a URL request.
*/
struct request_s {
char *method;
char *protocol;
char *host;
uint16_t port;
char *path;
};
extern void handle_connection (int fd); extern void handle_connection (int fd);
extern void add_connect_port_allowed(int port);
#endif #endif
+176
View File
@@ -0,0 +1,176 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* Allow tinyproxy to be used as a reverse proxy. */
#include "main.h"
#include "reverse-proxy.h"
#include "conns.h"
#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,
struct reversepath **reversepath_list)
{
struct reversepath *reverse;
if (url == NULL) {
log_message (LOG_WARNING,
"Illegal reverse proxy rule: missing url");
return;
}
if (!strstr (url, "://")) {
log_message (LOG_WARNING,
"Skipping reverse proxy rule: '%s' is not a valid url",
url);
return;
}
if (path && *path != '/') {
log_message (LOG_WARNING,
"Skipping reverse proxy rule: path '%s' "
"doesn't start with a /", path);
return;
}
reverse = (struct reversepath *) safemalloc (sizeof
(struct reversepath));
if (!reverse) {
log_message (LOG_ERR,
"Unable to allocate memory in reversepath_add()");
return;
}
if (!path)
reverse->path = safestrdup ("/");
else
reverse->path = safestrdup (path);
reverse->url = safestrdup (url);
reverse->next = *reversepath_list;
*reversepath_list = reverse;
log_message (LOG_INFO,
"Added reverse proxy rule: %s -> %s", reverse->path,
reverse->url);
}
/*
* Check if a request url is in the reversepath list
*/
struct reversepath *reversepath_get (char *url, struct reversepath *reverse)
{
while (reverse) {
if (strstr (url, reverse->path) == url)
return reverse;
reverse = reverse->next;
}
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.
*/
char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
char *url)
{
char *rewrite_url = NULL;
char *cookie = NULL;
char *cookieval;
struct reversepath *reverse = NULL;
/* Reverse requests always start with a slash */
if (*url == '/') {
/* First try locating the reverse mapping by request url */
reverse = reversepath_get (url, config.reversepath_list);
if (reverse) {
rewrite_url = (char *)
safemalloc (strlen (url) + strlen (reverse->url) +
1);
strcpy (rewrite_url, reverse->url);
strcat (rewrite_url, url + strlen (reverse->path));
} else if (config.reversemagic
&& hashmap_entry_by_key (hashofheaders,
"cookie",
(void **) &cookie) > 0) {
/* No match - try the magical tracking cookie next */
if ((cookieval = strstr (cookie, REVERSE_COOKIE "="))
&& (reverse =
reversepath_get (cookieval +
strlen (REVERSE_COOKIE) + 1,
config.reversepath_list)))
{
rewrite_url = (char *) safemalloc
(strlen (url) +
strlen (reverse->url) +
1);
strcpy (rewrite_url, reverse->url);
strcat (rewrite_url, url + 1);
log_message (LOG_INFO,
"Magical tracking cookie says: %s",
reverse->path);
}
}
}
/* Forward proxy support off and no reverse path match found */
if (config.reverseonly && !rewrite_url) {
log_message (LOG_ERR, "Bad request");
indicate_http_error (connptr, 400, "Bad Request",
"detail",
"Request has an invalid URL", "url", url,
NULL);
return NULL;
}
log_message (LOG_CONN, "Rewriting URL: %s -> %s", url, rewrite_url);
/* Store reverse path so that the magical tracking cookie can be set */
if (config.reversemagic && reverse)
connptr->reversepath = safestrdup (reverse->path);
return rewrite_url;
}
+42
View File
@@ -0,0 +1,42 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2005 Robert James Kaes <rjkaes@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'reverse-proxy.c' for detailed information. */
#ifndef TINYPROXY_REVERSE_PROXY_H
#define TINYPROXY_REVERSE_PROXY_H
#include "conns.h"
struct reversepath {
struct reversepath *next;
char *path;
char *url;
};
#define REVERSE_COOKIE "yummy_magical_cookie"
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);
#endif
-163
View File
@@ -1,163 +0,0 @@
/* $Id: scanner.l,v 1.16 2002-11-26 21:44:43 rjkaes Exp $
*
* This builds the scanner for the tinyproxy configuration file. This
* file needs to stay in sync with grammar.y. If someone knows lex and yacc
* better than I do, please update these files.
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/
%{
#include "tinyproxy.h"
#include "grammar.h"
struct keyword {
char *kw_name;
int kw_token;
};
static struct keyword keywords[] = {
/* statements */
{ "port", KW_PORT },
{ "logfile", KW_LOGFILE },
{ "syslog", KW_SYSLOG },
{ "maxclients", KW_MAXCLIENTS },
{ "maxspareservers", KW_MAXSPARESERVERS },
{ "minspareservers", KW_MINSPARESERVERS },
{ "startservers", KW_STARTSERVERS },
{ "maxrequestsperchild", KW_MAXREQUESTSPERCHILD },
{ "pidfile", KW_PIDFILE },
{ "timeout", KW_TIMEOUT },
{ "listen", KW_LISTEN },
{ "user", KW_USER },
{ "group", KW_GROUP },
{ "anonymous", KW_ANONYMOUS },
{ "filter", KW_FILTER },
{ "filterurls", KW_FILTERURLS },
{ "filterextended", KW_FILTEREXTENDED },
{ "filterdefaultdeny", KW_FILTER_DEFAULT_DENY },
{ "xtinyproxy", KW_XTINYPROXY },
{ "upstream", KW_UPSTREAM },
{ "allow", KW_ALLOW },
{ "deny", KW_DENY },
{ "connectport", KW_CONNECTPORT },
{ "bind", KW_BIND },
{ "viaheader", KW_HTTP_VIA },
/* loglevel and the settings */
{ "loglevel", KW_LOGLEVEL },
{ "critical", KW_LOG_CRITICAL },
{ "error", KW_LOG_ERROR },
{ "warning", KW_LOG_WARNING },
{ "notice", KW_LOG_NOTICE },
{ "connect", KW_LOG_CONNECT },
{ "info", KW_LOG_INFO },
/* on/off switches */
{ "yes", KW_YES },
{ "on", KW_YES },
{ "no", KW_NO },
{ "off", KW_NO }
};
#define YY_NO_UNPUT 1
#define MAX_REGEXP_LEN 1024
unsigned int yylineno = 1;
char tiny_buf[MAX_REGEXP_LEN];
char *tiny_str;
static int check_reserved_words(char *token);
static void append_string(int length, char *str);
static void append_char(char c);
%}
%option noyywrap
white [ \t]
digit [0-9]
alpha [a-zA-Z]
alphanum [a-zA-Z0-9]
word [^ \#'"\(\)\{\}\\;\n\t,|\.]
%x string
%%
\#.*$ ;
\n { yylineno++; return '\n'; }
: { return ':'; }
{white}+ ;
0x{digit}+ { yylval.num = strtol(yytext, NULL, 16); return NUMBER; }
0{digit}+ { yylval.num = strtol(yytext, NULL, 8); return NUMBER; }
{digit}+ { yylval.num = atoi(yytext); return NUMBER; }
{alpha}+ { return check_reserved_words(yytext); }
\" {
tiny_str = tiny_buf;
BEGIN(string);
}
<string>\\a { append_char(7); }
<string>\\n { append_char(10); }
<string>\\r { append_char(13); }
<string>\\t { append_char(9); }
<string>\\v { append_char(11); }
<string>\\[^anrtv] { append_string(1, yytext + 1); }
<string>\" {
BEGIN(INITIAL);
yylval.cptr = strdup(tiny_buf);
return STRING;
}
<string>[^"\\]+ { append_string(strlen(yytext), yytext); }
({digit}{1,3}\.){3}{digit}{1,3} { yylval.cptr = strdup(yytext); return NUMERIC_ADDRESS; }
({digit}{1,3}\.){3}{digit}{1,3}\/{digit}+ { yylval.cptr = strdup(yytext); return NETMASK_ADDRESS; }
([-_a-z0-9]+\.)+[a-z]+ { yylval.cptr = strdup(yytext); return STRING_ADDRESS; }
%%
int
check_reserved_words(char *token)
{
int i;
for (i = 0; i < (sizeof(keywords) / sizeof(struct keyword)); i++) {
if (strcasecmp(keywords[i].kw_name, token) == 0) {
return keywords[i].kw_token;
}
}
yylval.cptr = strdup(token);
return IDENTIFIER;
}
static void
append_string(int length, char *s)
{
int to_copy = min(MAX_REGEXP_LEN - (tiny_str - tiny_buf) - 1, length);
memcpy(tiny_str, s, to_copy);
tiny_str += to_copy;
*tiny_str = 0;
}
static void
append_char(char c)
{
*tiny_str = c;
tiny_str++;
*tiny_str = 0;
}
+258 -135
View File
@@ -1,127 +1,145 @@
/* $Id: sock.c,v 1.39 2002-10-03 20:50:59 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
* *
* Sockets are created and destroyed here. When a new connection comes in from * 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.
*/
/* Sockets are created and destroyed here. When a new connection comes in from
* a client, we need to copy the socket and the create a second socket to the * a client, we need to copy the socket and the create a second socket to the
* remote server the client is trying to connect to. Also, the listening * remote server the client is trying to connect to. Also, the listening
* socket is created and destroyed here. Sounds more impressive than it * socket is created and destroyed here. Sounds more impressive than it
* actually is. * actually is.
*
* Copyright (C) 1998 Steven Young
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
* Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com)
*
* 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, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "log.h" #include "log.h"
#include "heap.h" #include "heap.h"
#include "network.h"
#include "sock.h" #include "sock.h"
#include "text.h" #include "text.h"
#include "conf.h"
/* /*
* Take a string host address and return a struct in_addr so we can connect * Bind the given socket to the supplied address. The socket is
* to the remote host. * returned if the bind succeeded. Otherwise, -1 is returned
* * to indicate an error.
* Return a negative if there is a problem.
*/ */
static int static int
lookup_domain(struct in_addr *addr, const char *domain) bind_socket (int sockfd, const char *addr, int family)
{ {
struct hostent* result; struct addrinfo hints, *res, *ressave;
assert(domain != NULL); assert (sockfd >= 0);
assert (addr != NULL && strlen (addr) != 0);
result = gethostbyname(domain); memset (&hints, 0, sizeof (struct addrinfo));
if (result) { hints.ai_family = family;
memcpy(addr, result->h_addr_list[0], result->h_length); hints.ai_socktype = SOCK_STREAM;
return 0;
} else /* The local port it not important */
if (getaddrinfo (addr, NULL, &hints, &res) != 0)
return -1; return -1;
ressave = res;
/* Loop through the addresses and try to bind to each */
do {
if (bind (sockfd, res->ai_addr, res->ai_addrlen) == 0)
break; /* success */
} while ((res = res->ai_next) != NULL);
freeaddrinfo (ressave);
if (res == NULL) /* was not able to bind to any address */
return -1;
return sockfd;
} }
/* This routine is so old I can't even remember writing it. But I do /*
* remember that it was an .h file because I didn't know putting code in a * Open a connection to a remote host. It's been re-written to use
* header was bad magic yet. anyway, this routine opens a connection to a * the getaddrinfo() library function, which allows for a protocol
* system and returns the fd. * independent implementation (mostly for IPv4 and IPv6 addresses.)
* - steve
*
* Cleaned up some of the code to use memory routines which are now the
* default. Also, the routine first checks to see if the address is in
* dotted-decimal form before it does a name lookup.
* - rjkaes
*/ */
int int opensock (const char *host, int port, const char *bind_to)
opensock(char *ip_addr, uint16_t port)
{ {
int sock_fd; int sockfd, n;
struct sockaddr_in port_info; struct addrinfo hints, *res, *ressave;
struct sockaddr_in bind_addr; char portstr[6];
int ret;
assert(ip_addr != NULL); assert (host != NULL);
assert (port > 0); assert (port > 0);
memset((struct sockaddr *) &port_info, 0, sizeof(port_info)); memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
port_info.sin_family = AF_INET; snprintf (portstr, sizeof (portstr), "%d", port);
/* Lookup and return the address if possible */ n = getaddrinfo (host, portstr, &hints, &res);
ret = lookup_domain(&port_info.sin_addr, ip_addr); if (n != 0) {
if (ret < 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"opensock: Could not lookup address \"%s\".", "opensock: Could not retrieve info for %s", host);
ip_addr);
return -1; return -1;
} }
port_info.sin_port = htons(port); ressave = res;
do {
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { sockfd =
log_message(LOG_ERR, "opensock: socket() error \"%s\".", socket (res->ai_family, res->ai_socktype, res->ai_protocol);
strerror(errno)); if (sockfd < 0)
return -1; continue; /* ignore this one */
}
/* Bind to the specified address */ /* Bind to the specified address */
if (config.bind_address) { if (bind_to) {
memset(&bind_addr, 0, sizeof(bind_addr)); if (bind_socket (sockfd, bind_to,
bind_addr.sin_family = AF_INET; res->ai_family) < 0) {
bind_addr.sin_addr.s_addr = inet_addr(config.bind_address); close (sockfd);
continue; /* can't bind, so try again */
ret = bind(sock_fd, (struct sockaddr *)&bind_addr, sizeof(bind_addr)); }
if (ret < 0) { } else if (config.bind_address) {
log_message(LOG_ERR, "Could not bind local address \"%\" because of %s", if (bind_socket (sockfd, config.bind_address,
config.bind_address, res->ai_family) < 0) {
strerror(errno)); close (sockfd);
return -1; continue; /* can't bind, so try again */
} }
} }
if (connect(sock_fd, (struct sockaddr *) &port_info, sizeof(port_info)) < 0) { if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0)
log_message(LOG_ERR, "opensock: connect() error \"%s\".", break; /* success */
strerror(errno));
close (sockfd);
} while ((res = res->ai_next) != NULL);
freeaddrinfo (ressave);
if (res == NULL) {
log_message (LOG_ERR,
"opensock: Could not establish a connection to %s",
host);
return -1; return -1;
} }
return sock_fd; return sockfd;
} }
/* /*
* Set the socket to non blocking -rjkaes * Set the socket to non blocking -rjkaes
*/ */
int int socket_nonblocking (int sock)
socket_nonblocking(int sock)
{ {
int flags; int flags;
@@ -134,8 +152,7 @@ socket_nonblocking(int sock)
/* /*
* Set the socket to blocking -rjkaes * Set the socket to blocking -rjkaes
*/ */
int int socket_blocking (int sock)
socket_blocking(int sock)
{ {
int flags; int flags;
@@ -145,87 +162,193 @@ socket_blocking(int sock)
return fcntl (sock, F_SETFL, flags & ~O_NONBLOCK); return fcntl (sock, F_SETFL, flags & ~O_NONBLOCK);
} }
/*
* Start listening to a socket. Create a socket with the selected port. /**
* The size of the socket address will be returned to the caller through * Try to listen on one socket based on the addrinfo
* the pointer, while the socket is returned as a default return. * as returned from getaddrinfo.
* - rjkaes *
* Return the file descriptor upon success, -1 upon error.
*/ */
int static int listen_on_one_socket(struct addrinfo *ad)
listen_sock(uint16_t port, socklen_t* addrlen)
{ {
int listenfd; int listenfd;
int ret;
const int on = 1; const int on = 1;
struct sockaddr_in addr; char numerichost[NI_MAXHOST];
int flags = NI_NUMERICHOST;
assert(port > 0); ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
assert(addrlen != NULL); numerichost, NI_MAXHOST, NULL, 0, flags);
if (ret != 0) {
listenfd = socket(AF_INET, SOCK_STREAM, 0); log_message(LOG_ERR, "error calling getnameinfo: %s",
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); gai_strerror(errno));
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(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 (bind(listenfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
log_message(LOG_ERR, "Unable to bind listening socket because of %s",
strerror(errno));
return -1; return -1;
} }
if (listen(listenfd, MAXLISTEN) < 0) { log_message(LOG_INFO, "trying to listen on host[%s], family[%d], "
log_message(LOG_ERR, "Unable to start listening socket because of %s", "socktype[%d], proto[%d]", numerichost,
strerror(errno)); ad->ai_family, ad->ai_socktype, ad->ai_protocol);
listenfd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
if (listenfd == -1) {
log_message(LOG_ERR, "socket() failed: %s", strerror(errno));
return -1; return -1;
} }
*addrlen = sizeof(addr); ret = setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (ret != 0) {
log_message(LOG_ERR,
"setsockopt failed to set SO_REUSEADDR: %s",
strerror(errno));
close(listenfd);
return -1;
}
if (ad->ai_family == AF_INET6) {
ret = setsockopt(listenfd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on));
if (ret != 0) {
log_message(LOG_ERR,
"setsockopt failed to set IPV6_V6ONLY: %s",
strerror(errno));
close(listenfd);
return -1;
}
}
ret = bind(listenfd, ad->ai_addr, ad->ai_addrlen);
if (ret != 0) {
log_message(LOG_ERR, "bind failed: %s", strerror (errno));
close(listenfd);
return -1;
}
ret = listen(listenfd, MAXLISTEN);
if (ret != 0) {
log_message(LOG_ERR, "listen failed: %s", strerror(errno));
close(listenfd);
return -1;
}
log_message(LOG_INFO, "listening on fd [%d]", listenfd);
return listenfd; return listenfd;
} }
/*
* Start listening on a socket. Create a socket with the selected port.
* If the provided address is NULL, we may listen on multiple sockets,
* e.g. the wildcard addresse for IPv4 and IPv6, depending on what is
* supported. If the address is not NULL, we only listen on the first
* address reported by getaddrinfo that works.
*
* Upon success, the listen-fds are added to the listen_fds list
* and 0 is returned. Upon error, -1 is returned.
*/
int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
{
struct addrinfo hints, *result, *rp;
char portstr[6];
int ret = -1;
assert (port > 0);
assert (listen_fds != NULL);
log_message(LOG_INFO, "listen_sock called with addr = '%s'",
addr == NULL ? "(NULL)" : addr);
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
snprintf (portstr, sizeof (portstr), "%d", port);
if (getaddrinfo (addr, portstr, &hints, &result) != 0) {
log_message (LOG_ERR,
"Unable to getaddrinfo() because of %s",
strerror (errno));
return -1;
}
for (rp = result; rp != NULL; rp = rp->ai_next) {
int listenfd;
listenfd = listen_on_one_socket(rp);
if (listenfd == -1) {
continue;
}
vector_append (listen_fds, &listenfd, sizeof(int));
/* success */
ret = 0;
if (addr != NULL) {
/*
* Unless wildcard is requested, only listen
* on the first result that works.
*/
break;
}
}
if (ret != 0) {
log_message (LOG_ERR, "Unable to listen on any address.");
}
freeaddrinfo (result);
return ret;
}
/*
* Takes a socket descriptor and returns the socket's IP address.
*/
int getsock_ip (int fd, char *ipaddr)
{
struct sockaddr_storage name;
socklen_t namelen = sizeof (name);
assert (fd >= 0);
if (getsockname (fd, (struct sockaddr *) &name, &namelen) != 0) {
log_message (LOG_ERR, "getsock_ip: getsockname() error: %s",
strerror (errno));
return -1;
}
if (get_ip_string ((struct sockaddr *) &name, ipaddr, IP_LENGTH) ==
NULL)
return -1;
return 0;
}
/* /*
* Return the peer's socket information. * Return the peer's socket information.
*/ */
int int getpeer_information (int fd, char *ipaddr, char *string_addr)
getpeer_information(int fd, char* ipaddr, char* string_addr)
{ {
struct sockaddr_in name; struct sockaddr_storage sa;
size_t namelen = sizeof(name); socklen_t salen = sizeof sa;
struct hostent* result;
assert (fd >= 0); assert (fd >= 0);
assert (ipaddr != NULL); assert (ipaddr != NULL);
assert (string_addr != NULL); assert (string_addr != NULL);
/* /* Set the strings to default values */
* Clear the memory. ipaddr[0] = '\0';
*/ strlcpy (string_addr, "[unknown]", HOSTNAME_LENGTH);
memset(ipaddr, '\0', PEER_IP_LENGTH);
memset(string_addr, '\0', PEER_STRING_LENGTH);
if (getpeername(fd, (struct sockaddr *)&name, &namelen) != 0) { /* Look up the IP address */
log_message(LOG_ERR, "getpeer_information: getpeername() error: %s", if (getpeername (fd, (struct sockaddr *) &sa, &salen) != 0)
strerror(errno));
return -1; return -1;
} else {
strlcpy(ipaddr,
inet_ntoa(*(struct in_addr *)&name.sin_addr.s_addr),
PEER_IP_LENGTH);
}
result = gethostbyaddr((char *)&name.sin_addr.s_addr, 4, AF_INET); if (get_ip_string ((struct sockaddr *) &sa, ipaddr, IP_LENGTH) == NULL)
if (result) {
strlcpy(string_addr, result->h_name, PEER_STRING_LENGTH);
return 0;
} else {
return -1; return -1;
}
/* Get the full host name */
return getnameinfo ((struct sockaddr *) &sa, salen,
string_addr, HOSTNAME_LENGTH, NULL, 0, 0);
} }
+24 -17
View File
@@ -1,35 +1,42 @@
/* $Id: sock.h,v 1.10 2002-05-23 18:25:55 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'sock.c' for a detailed description. * 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.
* *
* Copyright (C) 1998 Steven Young * This program is distributed in the hope that it will be useful,
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'sock.c' for detailed information. */
#ifndef TINYPROXY_SOCK_H #ifndef TINYPROXY_SOCK_H
#define TINYPROXY_SOCK_H #define TINYPROXY_SOCK_H
#define PEER_IP_LENGTH 16 /* The IP length is set to 48, since IPv6 can be that long */
#define PEER_STRING_LENGTH 256 #define IP_LENGTH 48
#define HOSTNAME_LENGTH 1024
#define MAXLINE (1024 * 4) #define MAXLINE (1024 * 4)
extern int opensock(char *ip_addr, uint16_t port); #include "vector.h"
extern int listen_sock(uint16_t port, socklen_t * addrlen);
extern int opensock (const char *host, int port, const char *bind_to);
extern int listen_sock (const char *addr, uint16_t port, vector_t listen_fds);
extern int socket_nonblocking (int sock); extern int socket_nonblocking (int sock);
extern int socket_blocking (int sock); extern int socket_blocking (int sock);
extern int getsock_ip (int fd, char *ipaddr);
extern int getpeer_information (int fd, char *ipaddr, char *string_addr); extern int getpeer_information (int fd, char *ipaddr, char *string_addr);
#endif #endif
+71 -37
View File
@@ -1,32 +1,38 @@
/* $Id: stats.c,v 1.12 2002-05-29 20:49:55 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This module handles the statistics for tinyproxy. There are only two * 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.
*/
/* This module handles the statistics for tinyproxy. There are only two
* public API functions. The reason for the functions, rather than just a * public API functions. The reason for the functions, rather than just a
* external structure is that tinyproxy is now multi-threaded and we can * external structure is that tinyproxy is now multi-threaded and we can
* not allow more than one child to access the statistics at the same * not allow more than one child to access the statistics at the same
* time. This is prevented by a mutex. If there is a need for more * time. This is prevented by a mutex. If there is a need for more
* statistics in the future, just add to the structure, enum (in the header), * statistics in the future, just add to the structure, enum (in the header),
* and the switch statement in update_stats(). * and the switch statement in update_stats().
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "log.h" #include "log.h"
#include "heap.h" #include "heap.h"
#include "html-error.h"
#include "stats.h" #include "stats.h"
#include "utils.h" #include "utils.h"
#include "conf.h"
struct stat_s { struct stat_s {
unsigned long int num_reqs; unsigned long int num_reqs;
@@ -41,14 +47,13 @@ static struct stat_s *stats;
/* /*
* Initialize the statistics information to zero. * Initialize the statistics information to zero.
*/ */
void void init_stats (void)
init_stats(void)
{ {
stats = malloc_shared_memory(sizeof(struct stat_s)); stats = (struct stat_s *) malloc_shared_memory (sizeof (struct stat_s));
if (stats == MAP_FAILED) if (stats == MAP_FAILED)
return; return;
memset(stats, 0, sizeof(struct stat)); memset (stats, 0, sizeof (struct stat_s));
} }
/* /*
@@ -57,31 +62,48 @@ init_stats(void)
int int
showstats (struct conn_s *connptr) showstats (struct conn_s *connptr)
{ {
static char *msg =
"<html><head><title>%s (%s) stats</title></head>\r\n"
"<body>\r\n"
"<center><h2>%s (%s) run-time statistics</h2></center><hr>\r\n"
"<blockquote>\r\n"
"Number of open connections: %lu<br>\r\n"
"Number of requests: %lu<br>\r\n"
"Number of bad connections: %lu<br>\r\n"
"Number of denied connections: %lu<br>\r\n"
"Number of refused connections due to high load: %lu\r\n"
"</blockquote>\r\n</body></html>\r\n";
char *message_buffer; char *message_buffer;
char opens[16], reqs[16], badconns[16], denied[16], refused[16];
FILE *statfile;
message_buffer = safemalloc(MAXBUFFSIZE); snprintf (opens, sizeof (opens), "%lu", stats->num_open);
snprintf (reqs, sizeof (reqs), "%lu", stats->num_reqs);
snprintf (badconns, sizeof (badconns), "%lu", stats->num_badcons);
snprintf (denied, sizeof (denied), "%lu", stats->num_denied);
snprintf (refused, sizeof (refused), "%lu", stats->num_refused);
if (!config.statpage || (!(statfile = fopen (config.statpage, "r")))) {
message_buffer = (char *) safemalloc (MAXBUFFSIZE);
if (!message_buffer) if (!message_buffer)
return -1; return -1;
snprintf(message_buffer, MAXBUFFSIZE, msg, snprintf
(message_buffer, MAXBUFFSIZE,
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
"<html>\n"
"<head><title>%s version %s run-time statistics</title></head>\n"
"<body>\n"
"<h1>%s version %s run-time statistics</h1>\n"
"<p>\n"
"Number of open connections: %lu<br />\n"
"Number of requests: %lu<br />\n"
"Number of bad connections: %lu<br />\n"
"Number of denied connections: %lu<br />\n"
"Number of refused connections due to high load: %lu\n"
"</p>\n"
"<hr />\n"
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
"</html>\n",
PACKAGE, VERSION, PACKAGE, VERSION, PACKAGE, VERSION, PACKAGE, VERSION,
stats->num_open, stats->num_open,
stats->num_reqs, stats->num_reqs,
stats->num_badcons, stats->num_denied, stats->num_refused); stats->num_badcons, stats->num_denied,
stats->num_refused, PACKAGE, VERSION);
if (send_http_message(connptr, 200, "OK", message_buffer) < 0) { if (send_http_message (connptr, 200, "OK",
message_buffer) < 0) {
safefree (message_buffer); safefree (message_buffer);
return -1; return -1;
} }
@@ -90,12 +112,24 @@ showstats(struct conn_s *connptr)
return 0; return 0;
} }
add_error_variable (connptr, "opens", opens);
add_error_variable (connptr, "reqs", reqs);
add_error_variable (connptr, "badconns", badconns);
add_error_variable (connptr, "deniedconns", denied);
add_error_variable (connptr, "refusedconns", refused);
add_standard_vars (connptr);
send_http_headers (connptr, 200, "Statistic requested");
send_html_file (statfile, connptr);
fclose (statfile);
return 0;
}
/* /*
* Update the value of the statistics. The update_level is defined in * Update the value of the statistics. The update_level is defined in
* stats.h * stats.h
*/ */
int int update_stats (status_t update_level)
update_stats(status_t update_level)
{ {
switch (update_level) { switch (update_level) {
case STAT_BADCONN: case STAT_BADCONN:
+15 -12
View File
@@ -1,20 +1,23 @@
/* $Id: stats.h,v 1.4 2001-11-22 00:31:10 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'stats.h' for a detailed description. * 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.
* *
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'stats.c' for detailed information. */
#ifndef _TINYPROXY_STATS_H_ #ifndef _TINYPROXY_STATS_H_
#define _TINYPROXY_STATS_H_ #define _TINYPROXY_STATS_H_
+34 -24
View File
@@ -1,24 +1,28 @@
/* $Id: text.c,v 1.2 2002-05-24 04:45:32 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* The functions included here are useful for text manipulation. They * 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.
*/
/* The functions included here are useful for text manipulation. They
* replace or augment the standard C string library. These functions * replace or augment the standard C string library. These functions
* are either safer replacements, or they provide services not included * are either safer replacements, or they provide services not included
* with the standard C string library. * with the standard C string library.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "text.h" #include "text.h"
@@ -28,8 +32,7 @@
* buffer, and always NULL terminates the buffer. size is the size of the * buffer, and always NULL terminates the buffer. size is the size of the
* destination buffer. * destination buffer.
*/ */
size_t size_t strlcpy (char *dst, const char *src, size_t size)
strlcpy(char *dst, const char *src, size_t size)
{ {
size_t len = strlen (src); size_t len = strlen (src);
size_t ret = len; size_t ret = len;
@@ -51,8 +54,7 @@ strlcpy(char *dst, const char *src, size_t size)
* buffer, which should be one more than the maximum resulting string * buffer, which should be one more than the maximum resulting string
* length. * length.
*/ */
size_t size_t strlcat (char *dst, const char *src, size_t size)
strlcat(char *dst, const char *src, size_t size)
{ {
size_t len1 = strlen (dst); size_t len1 = strlen (dst);
size_t len2 = strlen (src); size_t len2 = strlen (src);
@@ -75,23 +77,31 @@ strlcat(char *dst, const char *src, size_t size)
* "length" should be the number of characters in the buffer, not including * "length" should be the number of characters in the buffer, not including
* the trailing NULL. * the trailing NULL.
* *
* Returns the number of characters removed from the end of the string. * Returns the number of characters removed from the end of the string. A
* negative return value indicates an error.
*/ */
size_t ssize_t chomp (char *buffer, size_t length)
chomp(char *buffer, size_t length)
{ {
size_t chars; size_t chars;
assert (buffer != NULL); assert (buffer != NULL);
assert (length > 0);
/* Make sure the arguments are valid */
if (buffer == NULL)
return -EFAULT;
if (length < 1)
return -ERANGE;
chars = 0; chars = 0;
--length; --length;
while (buffer[length] == '\r' || buffer[length] == '\n') { while (buffer[length] == '\r' || buffer[length] == '\n') {
buffer[length--] = '\0'; buffer[length] = '\0';
chars++; chars++;
if (length < 0) /* Stop once we get to zero to prevent wrap-around */
if (length-- == 0)
break; break;
} }
+16 -13
View File
@@ -1,20 +1,23 @@
/* $Id: text.h,v 1.1 2002-05-23 04:42:30 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* See 'text.c' for a detailed description. * 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.
* *
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'text.c' for detailed information. */
#ifndef TINYPROXY_TEXT_H #ifndef TINYPROXY_TEXT_H
#define TINYPROXY_TEXT_H #define TINYPROXY_TEXT_H
@@ -26,6 +29,6 @@ extern size_t strlcat(char *dst, const char *src, size_t size);
extern size_t strlcpy (char *dst, const char *src, size_t size); extern size_t strlcpy (char *dst, const char *src, size_t size);
#endif /* HAVE_STRLCPY */ #endif /* HAVE_STRLCPY */
extern size_t chomp(char *buffer, size_t length); extern ssize_t chomp (char *buffer, size_t length);
#endif #endif
-413
View File
@@ -1,413 +0,0 @@
/* $Id: tinyproxy.c,v 1.42 2002-12-04 17:06:14 rjkaes Exp $
*
* The initialize routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops
* over the new connections until the daemon is closed. Also has additional
* functions to handle the "user friendly" aspects of a program (usage,
* stats, etc.) Like any good program, most of the work is actually done
* elsewhere.
*
* Copyright (C) 1998 Steven Young
* Copyright (C) 1998-2002 Robert James Kaes (rjkaes@flarenet.com)
* Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com>
*
* 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, 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.
*/
#include "tinyproxy.h"
#include "anonymous.h"
#include "buffer.h"
#include "daemon.h"
#include "heap.h"
#include "filter.h"
#include "child.h"
#include "log.h"
#include "reqs.h"
#include "sock.h"
#include "stats.h"
#include "utils.h"
void takesig(int sig);
extern int yyparse(void);
extern FILE *yyin;
/*
* Global Structures
*/
struct config_s config;
float load = 0.00;
unsigned int received_sighup = FALSE; /* boolean */
unsigned int processed_config_file = FALSE; /* boolean */
/*
* Handle a signal
*/
void
takesig(int sig)
{
pid_t pid;
int status;
switch (sig) {
case SIGHUP:
received_sighup = TRUE;
break;
case SIGTERM:
config.quit = TRUE;
break;
case SIGCHLD:
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
;
break;
}
return;
}
/*
* Display the version information for the user.
*/
static void
display_version(void)
{
printf("%s %s (%s)\n", PACKAGE, VERSION, TARGET_SYSTEM);
}
/*
* Display the copyright and license for this program.
*/
static void
display_license(void)
{
display_version();
printf("\
Copyright 1998 Steven Young (sdyoung@well.com)\n\
Copyright 1998-2002 Robert James Kaes (rjkaes@users.sourceforge.net)\n\
Copyright 1999 George Talusan (gstalusan@uwaterloo.ca)\n\
Copyright 2000 Chris Lightfoot (chris@ex-parrot.com)\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation; either version 2, or (at your option)\n\
any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n");
}
/*
* Display usage to the user.
*/
static void
display_usage(void)
{
printf("Usage: %s [options]\n", PACKAGE);
printf("\
Options:\n\
-d Operate in DEBUG mode.\n\
-c FILE Use an alternate configuration file.\n\
-h Display this usage information.\n\
-l Display the license.\n\
-v Display the version number.\n");
/* Display the modes compiled into tinyproxy */
printf("\nFeatures Compiled In:\n");
#ifdef XTINYPROXY_ENABLE
printf(" XTinyproxy Header\n");
#endif /* XTINYPROXY */
#ifdef FILTER_ENABLE
printf(" Filtering\n");
printf(" * with Regular Expression support\n");
#endif /* FILTER_ENABLE */
#ifndef NDEBUG
printf(" Debugging code\n");
#endif /* NDEBUG */
#ifdef TRANSPARENT_PROXY
printf(" Transparent Proxy Support\n");
#endif /* TRANSPARENT_PROXY */
}
int
main(int argc, char **argv)
{
int optch;
unsigned int godaemon = TRUE; /* boolean */
struct passwd *thisuser = NULL;
struct group *thisgroup = NULL;
char *conf_file = DEFAULT_CONF_FILE;
/*
* Disable the creation of CORE files right up front.
*/
#if defined(HAVE_SETRLIMIT) && defined(NDEBUG)
struct rlimit core_limit = { 0, 0 };
if (setrlimit(RLIMIT_CORE, &core_limit) < 0) {
fprintf(stderr, "%s: Could not set the core limit to zero.\n",
argv[0]);
exit(EX_SOFTWARE);
}
#endif /* HAVE_SETRLIMIT */
log_message(LOG_INFO, "Initializing " PACKAGE " ...");
/*
* Process the various options
*/
while ((optch = getopt(argc, argv, "c:vldh")) != EOF) {
switch (optch) {
case 'v':
display_version();
exit(EX_OK);
case 'l':
display_license();
exit(EX_OK);
case 'd':
godaemon = FALSE;
break;
case 'c':
conf_file = safestrdup(optarg);
if (!conf_file) {
fprintf(stderr,
"%s: Could not allocate memory.\n",
argv[0]);
exit(EX_SOFTWARE);
}
break;
case 'h':
default:
display_usage();
exit(EX_OK);
}
}
/*
* Read in the settings from the config file.
*/
yyin = fopen(conf_file, "r");
if (!yyin) {
fprintf(stderr,
"%s: Could not open configuration file \"%s\".\n",
argv[0], conf_file);
exit(EX_SOFTWARE);
}
yyparse();
/* Open the log file if not using syslog */
if (config.syslog == FALSE) {
if (!config.logf_name) {
fprintf(stderr,
"%s: You MUST set a LogFile in the configuration file.\n",
argv[0]);
exit(EX_SOFTWARE);
} else {
if (open_log_file(config.logf_name) < 0) {
fprintf(stderr,
"%s: Could not create log file.\n",
argv[0]);
exit(EX_SOFTWARE);
}
}
} else {
if (godaemon == TRUE)
openlog("tinyproxy", LOG_PID, LOG_DAEMON);
else
openlog("tinyproxy", LOG_PID, LOG_USER);
}
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 configuration file.\n",
argv[0]);
exit(EX_SOFTWARE);
}
if (!config.stathost) {
log_message(LOG_INFO, "Setting stathost to \"%s\".",
DEFAULT_STATHOST);
config.stathost = DEFAULT_STATHOST;
}
if (!config.username) {
log_message(LOG_WARNING,
"You SHOULD set a UserName in the configuration file. Using current user instead.");
}
if (config.idletimeout == 0) {
log_message(LOG_WARNING, "Invalid idle time setting. Only values greater than zero 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
* in the list of allowed headers, since it is required in a
* HTTP/1.0 request. Also add the Content-Type header since it goes
* hand in hand with Content-Length.
* - rjkaes
*/
if (is_anonymous_enabled()) {
anonymous_insert("Content-Length");
anonymous_insert("Content-Type");
}
if (godaemon == TRUE)
makedaemon();
if (config.pidpath) {
if (pidfile_create(config.pidpath) < 0) {
fprintf(stderr, "%s: Could not create PID file.\n",
argv[0]);
exit(EX_OSERR);
}
}
if (set_signal_handler(SIGPIPE, SIG_IGN) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_init();
#endif /* FILTER_ENABLE */
/*
* Start listening on the selected port.
*/
if (child_listening_sock(config.port) < 0) {
fprintf(stderr, "%s: Could not create listening socket.\n",
argv[0]);
exit(EX_OSERR);
}
/*
* Switch to a different user.
*/
if (geteuid() == 0) {
if (config.group && strlen(config.group) > 0) {
thisgroup = getgrnam(config.group);
if (!thisgroup) {
fprintf(stderr,
"%s: Unable to find group \"%s\".\n",
argv[0], config.group);
exit(EX_NOUSER);
}
if (setgid(thisgroup->gr_gid) < 0) {
fprintf(stderr,
"%s: Unable to change to group \"%s\".\n",
argv[0], config.group);
exit(EX_CANTCREAT);
}
log_message(LOG_INFO, "Now running as group \"%s\".",
config.group);
}
if (config.username && strlen(config.username) > 0) {
thisuser = getpwnam(config.username);
if (!thisuser) {
fprintf(stderr,
"%s: Unable to find user \"%s\".",
argv[0], config.username);
exit(EX_NOUSER);
}
if (setuid(thisuser->pw_uid) < 0) {
fprintf(stderr,
"%s: Unable to change to user \"%s\".",
argv[0], config.username);
exit(EX_CANTCREAT);
}
log_message(LOG_INFO, "Now running as user \"%s\".",
config.username);
}
} 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.",
argv[0]);
exit(EX_SOFTWARE);
}
/*
* These signals are only for the parent process.
*/
log_message(LOG_INFO, "Setting the various signals.");
if (set_signal_handler(SIGCHLD, takesig) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGCHLD\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
if (set_signal_handler(SIGTERM, takesig) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGTERM\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
if (set_signal_handler(SIGHUP, takesig) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGHUP\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
/*
* Start the main loop.
*/
log_message(LOG_INFO, "Starting main loop. Accepting connections.");
child_main_loop();
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy();
#endif
log_message(LOG_INFO, "Shutting down.");
child_kill_children();
child_close_sock();
/*
* Remove the PID file.
*/
if (unlink(config.pidpath) < 0) {
log_message(LOG_WARNING,
"Could not remove PID file \"%s\": %s.",
config.pidpath, strerror(errno));
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy();
#endif /* FILTER_ENABLE */
if (config.syslog)
closelog();
else
close_log_file();
exit(EX_OK);
}
-64
View File
@@ -1,64 +0,0 @@
/* $Id: tinyproxy.h,v 1.36 2002-12-04 17:06:14 rjkaes Exp $
*
* See 'tinyproxy.c' for a detailed description.
*
* Copyright (C) 1998 Steven Young
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/
#ifndef TINYPROXY_TINYPROXY_H
#define TINYPROXY_TINYPROXY_H
#include "common.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 */
struct config_s {
char *logf_name;
unsigned int syslog; /* boolean */
int port;
char *stathost;
unsigned int quit; /* boolean */
char *username;
char *group;
char *ipAddr;
#ifdef FILTER_ENABLE
char *filter;
unsigned int filter_url; /* boolean */
unsigned int filter_extended; /* boolean */
#endif /* FILTER_ENABLE */
#ifdef XTINYPROXY_ENABLE
char *my_domain;
#endif
#ifdef UPSTREAM_SUPPORT
char *upstream_name;
int upstream_port;
#endif /* UPSTREAM_SUPPORT */
char *pidpath;
unsigned int idletimeout;
char* bind_address;
char* dnsserver_location;
char* dnsserver_socket;
unsigned int via_http_header; /* boolean */
};
/* Global Structures used in the program */
extern struct config_s config;
extern unsigned int received_sighup; /* boolean */
extern unsigned int processed_config_file; /* boolean */
#endif
+134
View File
@@ -0,0 +1,134 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Petr Lampa <lampa@fit.vutbr.cz>
* Copyright (C) 2008 Robert James Kaes <rjk@wormbytes.ca>
*
* 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.
*/
/*
* This section of code is used for the transparent proxy option. You will
* need to configure your firewall to redirect all connections for HTTP
* traffic to tinyproxy for this to work properly.
*/
#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.
*/
static int build_url (char **url, const char *host, int port, const char *path)
{
int len;
assert (url != NULL);
assert (host != NULL);
assert (port > 0 && port < 32768);
assert (path != NULL);
len = strlen (host) + strlen (path) + 14;
*url = (char *) safemalloc (len);
if (*url == NULL)
return -1;
return snprintf (*url, len, "http://%s:%d%s", host, port, path);
}
int
do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
struct request_s *request, struct config_s *conf,
char **url)
{
socklen_t length;
char *data;
size_t ulen = strlen (*url);
ssize_t i;
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
if (length <= 0) {
struct sockaddr_in dest_addr;
if (getsockname
(connptr->client_fd, (struct sockaddr *) &dest_addr,
&length) < 0) {
log_message (LOG_ERR,
"process_request: cannot get destination IP for %d",
connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Unknown destination",
"url", *url, NULL);
return 0;
}
request->host = (char *) safemalloc (17);
strlcpy (request->host, inet_ntoa (dest_addr.sin_addr), 17);
request->port = ntohs (dest_addr.sin_port);
request->path = (char *) safemalloc (ulen + 1);
strlcpy (request->path, *url, ulen + 1);
build_url (url, request->host, request->port, request->path);
log_message (LOG_INFO,
"process_request: trans IP %s %s for %d",
request->method, *url, connptr->client_fd);
} else {
request->host = (char *) safemalloc (length + 1);
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
2) {
strlcpy (request->host, data, length + 1);
request->port = HTTP_PORT;
}
request->path = (char *) safemalloc (ulen + 1);
strlcpy (request->path, *url, ulen + 1);
build_url (url, request->host, request->port, request->path);
log_message (LOG_INFO,
"process_request: trans Host %s %s for %d",
request->method, *url, connptr->client_fd);
}
if (conf->listen_addrs == NULL) {
return 1;
}
for (i = 0; i < vector_length(conf->listen_addrs); i++) {
const char *addr;
addr = (char *)vector_getentry(conf->listen_addrs, i, NULL);
if (addr && strcmp(request->host, addr) == 0) {
log_message(LOG_ERR,
"transparent: destination IP %s is local "
"on socket fd %d",
request->host, connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail",
"You tried to connect to the "
"machine the proxy is running on",
"url", *url, NULL);
return 0;
}
}
return 1;
}
+39
View File
@@ -0,0 +1,39 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2008 Robert James Kaes <rjk@wormbytes.ca>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'transparent-proxy.c' for detailed information. */
#ifndef TINYPROXY_TRANSPARENT_PROXY_H
#define TINYPROXY_TRANSPARENT_PROXY_H
#include "common.h"
#ifdef TRANSPARENT_PROXY
#include "conns.h"
#include "hashmap.h"
#include "reqs.h"
extern int do_transparent_proxy (struct conn_s *connptr,
hashmap_t hashofheaders,
struct request_s *request,
struct config_s *config, char **url);
#endif
#endif
+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 upstream proxy %s:%d for %s",
up->host, up->port, host);
else
log_message (LOG_INFO, "No upstream 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_ */
+51 -121
View File
@@ -1,37 +1,36 @@
/* $Id: utils.c,v 1.36 2002-12-04 17:06:14 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999-2003 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* Misc. routines which are used by the various functions to handle strings * 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.
*/
/* Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also, * and memory allocation and pretty much anything else we can think of. Also,
* the load cutoff routine is in here. Could not think of a better place for * the load cutoff routine is in here. Could not think of a better place for
* it, so it's in here. * it, so it's in here.
*
* Copyright (C) 1998 Steven Young
* Copyright (C) 1999,2001 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, 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.
*/ */
#include "tinyproxy.h" #include "main.h"
#include "buffer.h"
#include "conns.h" #include "conns.h"
#include "filter.h"
#include "heap.h" #include "heap.h"
#include "http-message.h"
#include "log.h" #include "log.h"
#include "network.h"
#include "sock.h"
#include "utils.h" #include "utils.h"
#define HEADER_SIZE (1024 * 8)
/* /*
* Build the data for a complete HTTP & HTML message for the client. * Build the data for a complete HTTP & HTML message for the client.
*/ */
@@ -39,97 +38,22 @@ int
send_http_message (struct conn_s *connptr, int http_code, send_http_message (struct conn_s *connptr, int http_code,
const char *error_title, const char *message) const char *error_title, const char *message)
{ {
static char *headers = \ static const char *headers[] = {
"HTTP/1.0 %d %s\r\n" \ "Server: " PACKAGE "/" VERSION,
"Server: %s/%s\r\n" \ "Content-type: text/html",
"Date: %s\r\n" \ "Connection: close"
"Content-Type: text/html\r\n" \ };
"Content-Length: %d\r\n" \
"Connection: close\r\n" \
"\r\n";
char timebuf[30]; http_message_t msg;
time_t global_time;
size_t message_len = strlen(message);
global_time = time(NULL); msg = http_message_create (http_code, error_title);
strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", if (msg == NULL)
gmtime(&global_time));
if (write_message(connptr->client_fd,
headers,
http_code, error_title, PACKAGE, VERSION,
timebuf, message_len) < 0)
return -1; return -1;
return safe_write(connptr->client_fd, message, message_len); http_message_add_headers (msg, headers, 3);
} http_message_set_body (msg, message, strlen (message));
http_message_send (msg, connptr->client_fd);
/* http_message_destroy (msg);
* Display an error to the client.
*/
int
send_http_error_message(struct conn_s *connptr)
{
static char *message = \
"<html><head><title>%s</title></head>\r\n" \
"<body>\r\n" \
"<font size=\"+2\">Cache Error!</font><br>\r\n" \
"An error of type %d occurred: %s\r\n" \
"<hr>\r\n" \
"<font size=\"-1\"><em>Generated by %s (%s)</em></font>\r\n" \
"</body></html>\r\n\r\n";
char *message_buffer;
char *tmpbuf;
size_t size = (1024 * 8); /* start with 8 KB */
ssize_t n;
int ret;
message_buffer = safemalloc(size);
if (!message_buffer)
return -1;
/*
* Build a new line. Keep increasing the size until the line fits.
* See the write_message() function in sock.c for more information.
*/
while (1) {
n = snprintf(message_buffer, size, message,
connptr->error_string, connptr->error_number,
connptr->error_string, PACKAGE, VERSION);
if (n > -1 && n < size)
break;
if (n > - 1)
size = n + 1;
else
size *= 2;
if ((tmpbuf = saferealloc(message_buffer, size)) == NULL) {
safefree(message_buffer);
return -1;
} else
message_buffer = tmpbuf;
}
ret = send_http_message(connptr, connptr->error_number,
connptr->error_string, message_buffer);
safefree(message_buffer);
return ret;
}
/*
* Add the error information to the conn structure.
*/
int
indicate_http_error(struct conn_s* connptr, int number, const char* string)
{
connptr->error_string = safestrdup(string);
if (!connptr->error_string)
return -1;
connptr->error_number = number;
return 0; return 0;
} }
@@ -137,8 +61,7 @@ indicate_http_error(struct conn_s* connptr, int number, const char* string)
/* /*
* Safely creates filename and returns the low-level file descriptor. * Safely creates filename and returns the low-level file descriptor.
*/ */
int int create_file_safely (const char *filename, unsigned int truncate_file)
create_file_safely(const char *filename, unsigned int truncate_file)
{ {
struct stat lstatinfo; struct stat lstatinfo;
int fildes; int fildes;
@@ -167,8 +90,7 @@ create_file_safely(const char *filename, unsigned int truncate_file)
*/ */
if ((fildes = if ((fildes =
open (filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) { open (filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) {
fprintf(stderr, fprintf (stderr, "%s: Could not create file %s: %s\n",
"%s: Could not create file %s: %s\n",
PACKAGE, filename, strerror (errno)); PACKAGE, filename, strerror (errno));
return fildes; return fildes;
} }
@@ -214,7 +136,8 @@ create_file_safely(const char *filename, unsigned int truncate_file)
*/ */
if (fstatinfo.st_nlink > 1 || !S_ISREG (lstatinfo.st_mode)) { if (fstatinfo.st_nlink > 1 || !S_ISREG (lstatinfo.st_mode)) {
fprintf (stderr, fprintf (stderr,
"%s: The file %s has too many links, or is not a regular file: %s\n", "%s: The file %s has too many links, "
"or is not a regular file: %s\n",
PACKAGE, filename, strerror (errno)); PACKAGE, filename, strerror (errno));
close (fildes); close (fildes);
return -EMLINK; return -EMLINK;
@@ -236,13 +159,15 @@ create_file_safely(const char *filename, unsigned int truncate_file)
* ("Little sympathy has been extended") * ("Little sympathy has been extended")
*/ */
#ifdef HAVE_FTRUNCATE #ifdef HAVE_FTRUNCATE
ftruncate(fildes, 0); if (ftruncate (fildes, 0) != 0) {
log_message (LOG_WARNING,
"Unable to truncate file '%s'", filename);
}
#else #else
close (fildes); close (fildes);
if ((fildes = if ((fildes =
open (filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) { open (filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) {
fprintf(stderr, fprintf (stderr, "%s: Could not open file %s: %s.",
"%s: Could not open file %s: %s.",
PACKAGE, filename, strerror (errno)); PACKAGE, filename, strerror (errno));
return fildes; return fildes;
} }
@@ -252,9 +177,14 @@ create_file_safely(const char *filename, unsigned int truncate_file)
return fildes; return fildes;
} }
/* /**
* Write the PID of the program to the specified file. * pidfile_create:
*/ * @filename: The name of the file which should be created.
*
* Creates a file with the PID of the Tinyproxy process.
*
* Returns: %0 on success, non-zero values on errors.
**/
int int
pidfile_create (const char *filename) pidfile_create (const char *filename)
{ {
@@ -279,7 +209,7 @@ pidfile_create(const char *filename)
return -EIO; return -EIO;
} }
fprintf(fd, "%ld\n", (long) getpid()); fprintf (fd, "%d\n", getpid ());
fclose (fd); fclose (fd);
return 0; return 0;
} }
+18 -17
View File
@@ -1,21 +1,24 @@
/* $Id: utils.h,v 1.22 2002-12-04 17:06:14 rjkaes Exp $ /* 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>
* *
* See 'utils.h' for a detailed description. * 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.
* *
* Copyright (C) 1998 Steven Young * This program is distributed in the hope that it will be useful,
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com) * 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.
* *
* This program is free software; you can redistribute it and/or modify it * You should have received a copy of the GNU General Public License along
* under the terms of the GNU General Public License as published by the * with this program; if not, write to the Free Software Foundation, Inc.,
* Free Software Foundation; either version 2, or (at your option) any * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 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.
*/ */
/* See 'utils.c' for detailed information. */
#ifndef TINYPROXY_UTILS_H #ifndef TINYPROXY_UTILS_H
#define TINYPROXY_UTILS_H #define TINYPROXY_UTILS_H
@@ -26,11 +29,9 @@ struct conn_s;
extern int send_http_message (struct conn_s *connptr, int http_code, extern int send_http_message (struct conn_s *connptr, int http_code,
const char *error_title, const char *message); const char *error_title, const char *message);
extern int send_http_error_message(struct conn_s *connptr);
extern int indicate_http_error(struct conn_s* connptr, int number,
const char *string);
extern int pidfile_create (const char *path); extern int pidfile_create (const char *path);
extern int create_file_safely(const char *filename, unsigned int truncate_file); extern int create_file_safely (const char *filename,
unsigned int truncate_file);
#endif #endif
+65 -39
View File
@@ -1,10 +1,5 @@
/* $Id: vector.c,v 1.6 2002-05-24 04:45:32 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* * Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* A vector implementation. The vector can be of an arbitrary length, and
* the data for each entry is an lump of data (the size is stored in the
* vector.)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -16,12 +11,17 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, write to the Free Software * with this program; if not, write to the Free Software Foundation, Inc.,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "tinyproxy.h" /* A vector implementation. The vector can be of an arbitrary length, and
* the data for each entry is an lump of data (the size is stored in the
* vector.)
*/
#include "main.h"
#include "heap.h" #include "heap.h"
#include "vector.h" #include "vector.h"
@@ -53,12 +53,11 @@ struct vector_s {
* A NULL is returned if memory could not be allocated for the * A NULL is returned if memory could not be allocated for the
* vector. * vector.
*/ */
vector_t vector_t vector_create (void)
vector_create(void)
{ {
vector_t vector; vector_t vector;
vector = safemalloc(sizeof(struct vector_s)); vector = (vector_t) safemalloc (sizeof (struct vector_s));
if (!vector) if (!vector)
return NULL; return NULL;
@@ -74,8 +73,7 @@ vector_create(void)
* Returns: 0 on success * Returns: 0 on success
* negative if a NULL vector is supplied * negative if a NULL vector is supplied
*/ */
int int vector_delete (vector_t vector)
vector_delete(vector_t vector)
{ {
struct vectorentry_s *ptr, *next; struct vectorentry_s *ptr, *next;
@@ -97,23 +95,35 @@ vector_delete(vector_t vector)
} }
/* /*
* Inserts an entry into the vector. The entry is an arbitrary * Appends an entry into the vector. The entry is an arbitrary
* collection of bytes of _len_ octets. The data is copied into the * collection of bytes of _len_ octets. The data is copied into the
* vector, so the original data must be freed to avoid a memory leak. * vector, so the original data must be freed to avoid a memory leak.
* The "data" must be non-NULL and the "len" must be greater than zero. * The "data" must be non-NULL and the "len" must be greater than zero.
* "pos" is either 0 to prepend the data, or 1 to append the data.
* *
* Returns: 0 on success * Returns: 0 on success
* negative number if there are errors * negative number if there are errors
*/ */
int
vector_insert(vector_t vector, void *data, ssize_t len) 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; struct vectorentry_s *entry;
if (!vector || !data || len <= 0) if (!vector || !data || len <= 0 ||
(pos != INSERT_PREPEND && pos != INSERT_APPEND))
return -EINVAL; return -EINVAL;
entry = safemalloc(sizeof(struct vectorentry_s)); entry =
(struct vectorentry_s *) safemalloc (sizeof (struct vectorentry_s));
if (!entry) if (!entry)
return -ENOMEM; return -ENOMEM;
@@ -127,13 +137,17 @@ vector_insert(vector_t vector, void *data, ssize_t len)
entry->len = len; entry->len = len;
entry->next = NULL; entry->next = NULL;
if (vector->tail) { /* If there is no head or tail, create them */
/* If "tail" is not NULL, it points to the last entry */ if (!vector->head && !vector->tail)
vector->head = vector->tail = entry;
else if (pos == INSERT_PREPEND) {
/* prepend the entry */
entry->next = vector->head;
vector->head = entry;
} else {
/* append the entry */
vector->tail->next = entry; vector->tail->next = entry;
vector->tail = entry; vector->tail = entry;
} else {
/* No "tail", meaning no entries. Create both. */
vector->head = vector->tail = entry;
} }
vector->num_entries++; vector->num_entries++;
@@ -142,23 +156,34 @@ vector_insert(vector_t vector, void *data, ssize_t len)
} }
/* /*
* A pointer to the data at position "pos" (zero based) is returned in the * The following two function are used to make the API clearer. As you
* "data" pointer. If the vector is out of bound, data is set to NULL. * can see they simply call the vector_insert() function with appropriate
* arguments.
*/
int vector_append (vector_t vector, void *data, size_t len)
{
return vector_insert (vector, data, len, INSERT_APPEND);
}
int vector_prepend (vector_t vector, void *data, size_t len)
{
return vector_insert (vector, data, len, INSERT_PREPEND);
}
/*
* A pointer to the data at position "pos" (zero based) is returned.
* If the vector is out of bound, data is set to NULL.
* *
* Returns: negative upon an error * Returns: negative upon an error
* length of data if position is valid * length of data if position is valid
*/ */
ssize_t void *vector_getentry (vector_t vector, size_t pos, size_t * size)
vector_getentry(vector_t vector, size_t pos, void **data)
{ {
struct vectorentry_s *ptr; struct vectorentry_s *ptr;
size_t loc; size_t loc;
if (!vector || !data) if (!vector || pos >= vector->num_entries)
return -EINVAL; return NULL;
if (pos < 0 || pos >= vector->num_entries)
return -ERANGE;
loc = 0; loc = 0;
ptr = vector->head; ptr = vector->head;
@@ -168,8 +193,10 @@ vector_getentry(vector_t vector, size_t pos, void **data)
loc++; loc++;
} }
*data = ptr->data; if (size)
return ptr->len; *size = ptr->len;
return ptr->data;
} }
/* /*
@@ -178,8 +205,7 @@ vector_getentry(vector_t vector, size_t pos, void **data)
* Returns: negative if vector is not valid * Returns: negative if vector is not valid
* positive length of vector otherwise * positive length of vector otherwise
*/ */
ssize_t ssize_t vector_length (vector_t vector)
vector_length(vector_t vector)
{ {
if (!vector) if (!vector)
return -EINVAL; return -EINVAL;
+18 -28
View File
@@ -1,10 +1,5 @@
/* $Id: vector.h,v 1.1 2002-04-07 21:29:23 rjkaes Exp $ /* tinyproxy - A fast light-weight HTTP proxy
* * Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* A vector implementation. The vector can be of an arbritrary length, and
* the data for each entry is an lump of data (the size is stored in the
* vector.)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -16,19 +11,16 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, write to the Free Software * with this program; if not, write to the Free Software Foundation, Inc.,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/* See 'vector.c' for detailed information. */
#ifndef _VECTOR_H #ifndef _VECTOR_H
#define _VECTOR_H #define _VECTOR_H
/* Allow the use in C++ code. */
#if defined(__cplusplus)
extern "C" {
#endif
/* /*
* We're using a typedef here to "hide" the implementation details of the * We're using a typedef here to "hide" the implementation details of the
* vector. Sure, it's a pointer, but the struct is hidden in the C file. * vector. Sure, it's a pointer, but the struct is hidden in the C file.
@@ -45,18 +37,18 @@ extern int vector_delete(vector_t vector);
/* /*
* When you insert a piece of data into the vector, the data will be * When you insert a piece of data into the vector, the data will be
* duplicated, so you must free your copy if it was created on the * duplicated, so you must free your copy if it was created on the heap.
* heap. The data must be non-NULL and the length must be greater * The data must be non-NULL and the length must be greater than zero.
* than zero.
* *
* Returns: negative on error * Returns: negative on error
* 0 upon successful insert. * 0 upon successful insert.
*/ */
extern int vector_insert(vector_t vector, void *data, ssize_t len); extern int vector_append (vector_t vector, void *data, size_t len);
extern int vector_prepend (vector_t vector, void *data, size_t len);
/* /*
* A pointer to the data at position "pos" (zero based) is returned in the * A pointer to the data at position "pos" (zero based) is returned and the
* "data" pointer. If the vector is out of bound, data is set to NULL. * size pointer contains the length of the data stored.
* *
* The pointer points to the actual data in the vector, so you have * The pointer points to the actual data in the vector, so you have
* the power to modify the data, but do it responsibly since the * the power to modify the data, but do it responsibly since the
@@ -65,10 +57,12 @@ extern int vector_insert(vector_t vector, void *data, ssize_t len);
* likely mess up the "length" parameter of the data.) However, DON'T * likely mess up the "length" parameter of the data.) However, DON'T
* try to realloc or free the data; doing so will break the vector. * try to realloc or free the data; doing so will break the vector.
* *
* Returns: negative upon an error * If "size" is NULL the size of the data is not returned.
* length of data if position is valid *
* Returns: NULL on error
* valid pointer to data
*/ */
extern ssize_t vector_getentry(vector_t vector, size_t pos, void **data); extern void *vector_getentry (vector_t vector, size_t pos, size_t * size);
/* /*
* Returns the number of enteries (or the length) of the vector. * Returns the number of enteries (or the length) of the vector.
@@ -78,8 +72,4 @@ extern ssize_t vector_getentry(vector_t vector, size_t pos, void **data);
*/ */
extern ssize_t vector_length (vector_t vector); extern ssize_t vector_length (vector_t vector);
#if defined(_cplusplus)
}
#endif /* C++ */
#endif /* _VECTOR_H */ #endif /* _VECTOR_H */
+1
View File
@@ -0,0 +1 @@
SUBDIRS = scripts
+5
View File
@@ -0,0 +1,5 @@
EXTRA_DIST = \
run_tests.sh \
run_tests_valgrind.sh \
webclient.pl \
webserver.pl
+208
View File
@@ -0,0 +1,208 @@
#!/bin/sh
# testsuite runner for tinyproxy
#
# 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, see <http://www.gnu.org/licenses/>.
SCRIPTS_DIR=$(pwd)/$(dirname $0)
BASEDIR=$SCRIPTS_DIR/../..
TESTS_DIR=$SCRIPTS_DIR/..
TESTENV_DIR=$TESTS_DIR/env
LOG_DIR=$TESTENV_DIR/var/log
TINYPROXY_IP=127.0.0.2
TINYPROXY_PORT=12321
TINYPROXY_USER=$(id -un)
TINYPROXY_PID_DIR=$TESTENV_DIR/var/run/tinyproxy
TINYPROXY_PID_FILE=$TINYPROXY_PID_DIR/tinyproxy.pid
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
TINYPROXY_FILTER_FILE=$TINYPROXY_CONF_DIR/filter
TINYPROXY_STDERR_LOG=$TINYPROXY_LOG_DIR/tinyproxy.stderr.log
TINYPROXY_BIN=$BASEDIR/src/tinyproxy
TINYPROXY_STATHOST_IP="127.0.0.127"
WEBSERVER_IP=127.0.0.3
WEBSERVER_PORT=32123
WEBSERVER_PID_DIR=$TESTENV_DIR/var/run/webserver
WEBSERVER_PID_FILE=$WEBSERVER_PID_DIR/webserver.pid
WEBSERVER_LOG_DIR=$TESTENV_DIR/var/log/webserver
WEBSERVER_BIN_FILE=webserver.pl
WEBSERVER_BIN=$SCRIPTS_DIR/$WEBSERVER_BIN_FILE
WEBCLIENT_LOG=$LOG_DIR/webclient.log
WEBCLIENT_BIN=$SCRIPTS_DIR/webclient.pl
provision_initial() {
if test -e $TESTENV_DIR ; then
TESTENV_DIR_OLD=$TESTENV_DIR.old
if test -e $TESTENV_DIR_OLD ; then
rm -rf $TESTENV_DIR_OLD
fi
mv $TESTENV_DIR $TESTENV_DIR.old
fi
mkdir -p $LOG_DIR
}
provision_tinyproxy() {
mkdir -p $TINYPROXY_DATA_DIR
cp $BASEDIR/data/templates/default.html $TINYPROXY_DATA_DIR
cp $BASEDIR/data/templates/debug.html $TINYPROXY_DATA_DIR
cp $BASEDIR/data/templates/stats.html $TINYPROXY_DATA_DIR
mkdir -p $TINYPROXY_PID_DIR
mkdir -p $TINYPROXY_LOG_DIR
mkdir -p $TINYPROXY_CONF_DIR
cat >>$TINYPROXY_CONF_FILE<<EOF
User $TINYPROXY_USER
#Group $TINYPROXY_GROUP
Port $TINYPROXY_PORT
#Bind $TINYPROXY_IP
Listen $TINYPROXY_IP
Timeout 600
StatHost "$TINYPROXY_STATHOST_IP"
DefaultErrorFile "$TINYPROXY_DATA_DIR/debug.html"
StatFile "$TINYPROXY_DATA_DIR/stats.html"
Logfile "$TINYPROXY_LOG_DIR/tinyproxy.log"
PidFile "$TINYPROXY_PID_FILE"
LogLevel Info
MaxClients 100
MinSpareServers 5
MaxSpareServers 20
StartServers 10
MaxRequestsPerChild 0
Allow 127.0.0.0/8
ViaProxyName "tinyproxy"
#DisableViaHeader Yes
ConnectPort 443
ConnectPort 563
FilterURLs On
Filter "$TINYPROXY_FILTER_FILE"
XTinyproxy Yes
EOF
touch $TINYPROXY_FILTER_FILE
}
start_tinyproxy() {
echo -n "starting tinyproxy..."
$VALGRIND $TINYPROXY_BIN -c $TINYPROXY_CONF_FILE 2> $TINYPROXY_STDERR_LOG
echo " done (listening on $TINYPROXY_IP:$TINYPROXY_PORT)"
}
stop_tinyproxy() {
echo -n "killing tinyproxy..."
kill $(cat $TINYPROXY_PID_FILE)
if test "x$?" = "x0" ; then
echo " ok"
else
echo " error"
fi
}
provision_webserver() {
mkdir -p $WEBSERVER_PID_DIR
mkdir -p $WEBSERVER_LOG_DIR
}
start_webserver() {
echo -n "starting web server..."
$WEBSERVER_BIN --port $WEBSERVER_PORT --log-dir $WEBSERVER_LOG_DIR --pid-file $WEBSERVER_PID_FILE
echo " done (listening on $WEBSERVER_IP:$WEBSERVER_PORT)"
}
stop_webserver() {
echo -n "killing webserver..."
kill $(cat $WEBSERVER_PID_FILE)
if test "x$?" = "x0" ; then
echo " ok"
else
echo " error"
fi
}
wait_for_some_seconds() {
SECONDS=$1
if test "x$SECONDS" = "x" ; then
SECONDS=1
fi
echo -n "waiting for $SECONDS seconds."
for COUNT in $(seq 1 $SECONDS) ; do
sleep 1
echo -n "."
done
echo " done"
}
run_basic_webclient_request() {
$WEBCLIENT_BIN $1 $2 >> $WEBCLIENT_LOG 2>&1
WEBCLIENT_EXIT_CODE=$?
if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
echo " ok"
else
echo "ERROR ($WEBCLIENT_EXIT_CODE)"
echo "webclient output:"
cat $WEBCLIENT_LOG
fi
return $WEBCLIENT_EXIT_CODE
}
# "main"
provision_initial
provision_tinyproxy
provision_webserver
start_webserver
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 "$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 $FAILED
Loaded 100 of 104 files, more files were not shown because too many files have changed in this diff. Show more