Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a662c11b8d | ||
|
|
8333a4bb1a | ||
|
|
e2a92ea334 | ||
|
|
4c9289802a | ||
|
|
3eb3c2c099 | ||
|
|
a5e6d343d7 | ||
|
|
56f30a4386 | ||
|
|
89b2c68b2b | ||
|
|
ec95d8b553 | ||
|
|
c651664720 | ||
|
|
0aad2f5b92 | ||
|
|
ae0cbfe3f2 | ||
|
|
badb6435d6 | ||
|
|
8d0ea71486 | ||
|
|
09979629c0 | ||
|
|
a53f62a212 | ||
|
|
b8c6a2127d | ||
|
|
e78b461607 | ||
|
|
057cf06805 | ||
|
|
9cde492d68 | ||
|
|
39132b9787 | ||
|
|
86632a91eb | ||
|
|
e1c11c47db | ||
|
|
bf76aeeba1 | ||
|
|
4d9891e59e | ||
|
|
81ea4feb2e | ||
|
|
c7c88e9c59 | ||
|
|
9acb0cb16c | ||
|
|
af1d7ab510 | ||
|
|
bd04ed00d8 | ||
|
|
8db511b9bf | ||
|
|
1ebfd2a2d1 | ||
|
|
7a3fd81a8d | ||
|
|
8906b0734e | ||
|
|
116e59e933 | ||
|
|
9bb699628f | ||
|
|
e9e0f0b4f0 | ||
|
|
08a9fbb041 | ||
|
|
ccbbb81aa9 | ||
|
|
64b29c5f4e | ||
|
|
d97d486d53 | ||
|
|
5062b78740 | ||
|
|
caf0ff3be8 | ||
|
|
86a9a6729e | ||
|
|
d67c48a49b | ||
|
|
cb6f868739 | ||
|
|
46cbe5357c | ||
|
|
a71cebb094 | ||
|
|
f149b62475 | ||
|
|
3f6179a1fd | ||
|
|
2c574e9afe | ||
|
|
aade379acb | ||
|
|
1e93411810 | ||
|
|
1b8a6ef561 | ||
|
|
802a6aa93f | ||
|
|
302738dee5 | ||
|
|
f9024c7186 | ||
|
|
fdb1aae3a9 | ||
|
|
540069551d | ||
|
|
e4ae0d10d2 | ||
|
|
06281857a4 | ||
|
|
6c98f2cc27 | ||
|
|
ff880a5e13 | ||
|
|
67fc3b54ba | ||
|
|
841fed4afd | ||
|
|
c98f1cd25a | ||
|
|
c3cc308cc8 | ||
|
|
81a93f9e4f | ||
|
|
39c92a3f70 | ||
|
|
90df510932 | ||
|
|
909528e29c | ||
|
|
4e0951afd9 | ||
|
|
2f4e6403f9 | ||
|
|
1bb255c3f8 | ||
|
|
85c73d68bd | ||
|
|
7f3fe02d47 | ||
|
|
271c4ecdcb | ||
|
|
0d3ca13398 | ||
|
|
82ce991b3d | ||
|
|
af6e236521 | ||
|
|
e541456ee7 | ||
|
|
60e5fc7c57 | ||
|
|
c5da1cc934 | ||
|
|
186bbc3efb | ||
|
|
b036d2e055 | ||
|
|
ee83293285 | ||
|
|
800c3a250c | ||
|
|
545463c75d | ||
|
|
308305d827 | ||
|
|
ab6255393d | ||
|
|
24087f743a | ||
|
|
b59ecd0c66 | ||
|
|
ffa3a56ab8 | ||
|
|
76bd008cf9 | ||
|
|
b3ac7d2c7b | ||
|
|
b92d70be07 | ||
|
|
3710accf72 | ||
|
|
e07c363df2 | ||
|
|
c82840bfcb | ||
|
|
49c55ed26c | ||
|
|
198600ce42 | ||
|
|
38ef36d998 | ||
|
|
0a99803425 | ||
|
|
9efa5799f0 | ||
|
|
c27b6d15e2 | ||
|
|
68bd0b61b5 | ||
|
|
2004abc1e3 | ||
|
|
a244c1d4aa | ||
|
|
0f18e4fc3a | ||
|
|
9f43cfd488 | ||
|
|
98f77ef8c7 | ||
|
|
69c348ce6d | ||
|
|
bb2e894e0d | ||
|
|
7e1d8154de | ||
|
|
836d4534d6 | ||
|
|
e82080a5f6 | ||
|
|
d0732f9ade | ||
|
|
e40b91974a | ||
|
|
22587d3d41 | ||
|
|
0698e4d180 | ||
|
|
d7f67768eb | ||
|
|
157879d4f6 | ||
|
|
a7898a2c98 | ||
|
|
947e255d19 | ||
|
|
b41d140984 | ||
|
|
5392e9829c | ||
|
|
fa26ad4d56 | ||
|
|
2ebfd456ef | ||
|
|
070d621534 | ||
|
|
2bd919f01e | ||
|
|
7eea1638bc | ||
|
|
4bbd6e8626 | ||
|
|
d652681e8a | ||
|
|
c8b8247f70 | ||
|
|
3cc59ec3be | ||
|
|
983d241db6 | ||
|
|
2e4ea496b3 | ||
|
|
e5fd1fd556 | ||
|
|
32563a4ed6 | ||
|
|
ec86c15d5a | ||
|
|
e8426f6662 | ||
|
|
97b9984484 | ||
|
|
5ad24ba99d | ||
|
|
7378c97524 | ||
|
|
2d02e2211e | ||
|
|
8fd3808ad3 | ||
|
|
62443a6391 | ||
|
|
58ac635a17 | ||
|
|
b672ca03fe | ||
|
|
52cad36352 | ||
|
|
691415a8f9 | ||
|
|
56257d3da3 | ||
|
|
df9e6d3163 | ||
|
|
a7933bdd36 | ||
|
|
50e3a0f6d9 | ||
|
|
f84fb98766 | ||
|
|
0963c4c71f | ||
|
|
7c39cdfe1d | ||
|
|
7da3e4854c | ||
|
|
7edb6e047c | ||
|
|
d30ee746a7 | ||
|
|
1e0ad98f7f | ||
|
|
34088e2175 | ||
|
|
b108162dfb | ||
|
|
d37a6b2c12 | ||
|
|
2f86b79d85 | ||
|
|
243526d493 | ||
|
|
e87c856487 | ||
|
|
cfa5792880 | ||
|
|
f640c6fbb1 | ||
|
|
fcf5fd2129 | ||
|
|
7a9abc2a04 | ||
|
|
2235a97f05 | ||
|
|
f923649a11 | ||
|
|
3f1632603c | ||
|
|
7c15563430 | ||
|
|
ee1f1e38f2 | ||
|
|
752e4419a6 | ||
|
|
d133eee36b | ||
|
|
2f6840fd85 | ||
|
|
719b5f6049 | ||
|
|
907a6c2420 | ||
|
|
c6d4c68c99 | ||
|
|
3efcfd2345 | ||
|
|
a9b42c491f | ||
|
|
9434b27cc1 | ||
|
|
2d85a69e49 | ||
|
|
0697a9047d | ||
|
|
41d80861e3 | ||
|
|
19b9bff888 | ||
|
|
13eb2258e0 | ||
|
|
2447e38618 | ||
|
|
d9d66e6280 | ||
|
|
70885bf029 | ||
|
|
9b9d8c10f8 | ||
|
|
b08420ec13 | ||
|
|
e11a01f0b1 | ||
|
|
7ac13d7924 | ||
|
|
edea7e37d0 | ||
|
|
f3fe3d8e79 | ||
|
|
510655e447 | ||
|
|
9e7dac7996 | ||
|
|
b21270ffa5 | ||
|
|
84d5926bdb | ||
|
|
8631a9d531 | ||
|
|
d396e5592b | ||
|
|
ff2a7a2bdc | ||
|
|
26cfec06a0 |
No files matched your search
@@ -18,5 +18,6 @@ stamp-h1
|
|||||||
autom4te.cache
|
autom4te.cache
|
||||||
cscope.files
|
cscope.files
|
||||||
cscope.out
|
cscope.out
|
||||||
|
compile
|
||||||
*~
|
*~
|
||||||
tags
|
tags
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
language: C
|
||||||
|
dist: trusty
|
||||||
|
sudo: true
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- sudo apt-get update -qq
|
||||||
|
- sudo apt-get install --assume-yes asciidoc valgrind
|
||||||
|
|
||||||
|
script:
|
||||||
|
- ./autogen.sh
|
||||||
|
- ./configure
|
||||||
|
- make
|
||||||
|
- make test
|
||||||
|
- ./configure --enable-debug --enable-transparent --enable-reverse
|
||||||
|
- make
|
||||||
|
- make test
|
||||||
|
- make valgrind-test
|
||||||
|
- make distcheck
|
||||||
@@ -1,19 +1,39 @@
|
|||||||
Early History
|
Andrew Stribblehill
|
||||||
-------------
|
bertliao
|
||||||
|
Bob Showalter
|
||||||
Steven Young is the original author and was the primary maintainer of
|
Brian Cain
|
||||||
tinyproxy until version 1.1. He also maintained the project from
|
cvs2svn
|
||||||
version 1.3.1 until 1.4.0.
|
Daniel Egger
|
||||||
|
Daniel M. Drucker
|
||||||
Robert James Kaes is the current maintainer and lead programmer. He
|
David Shanks
|
||||||
also maintained the project between versions 1.2 and 1.3.0, and again
|
Dmitry Semyonov
|
||||||
starting with version 1.4.0.
|
dmz-uk
|
||||||
|
Drew G. Wallace
|
||||||
|
Frank Morgner
|
||||||
Major Additions/Improvements
|
gary-wzl77
|
||||||
----------------------------
|
Gaudenz Steinlin
|
||||||
|
goba62000374
|
||||||
James E. Flemer <jflemer@acm.jhu.edu> - URL/domain filtering
|
Gonzalo Tornaria
|
||||||
Kim Holviala <kim@holviala.com> - Reverse proxy support
|
Greg
|
||||||
Petr Lampa <lampa@fit.vutbr.cz> - Transparent proxy support
|
Jeremy Hinegardner
|
||||||
George Talusan <gstalusan@uwaterloo.ca> - URL/domain filtering
|
John Spencer
|
||||||
|
John van der Kamp
|
||||||
|
John Weldon
|
||||||
|
Jordi
|
||||||
|
Jordi Mallach
|
||||||
|
Julien Hartmann
|
||||||
|
kikuchan
|
||||||
|
Mathew Mrosko
|
||||||
|
Matthew Dempsky
|
||||||
|
Michael Adam
|
||||||
|
Mike Mead
|
||||||
|
Mukund Sivaraman
|
||||||
|
Pablo Panero
|
||||||
|
Peter H. Froehlich
|
||||||
|
Robert James Kaes
|
||||||
|
rofl0r
|
||||||
|
Stephan Leemburg
|
||||||
|
Steven Conaway
|
||||||
|
Steven Young
|
||||||
|
Valen Blanco
|
||||||
|
Vladimir Belov
|
||||||
@@ -9,6 +9,14 @@ SUBDIRS = \
|
|||||||
# tools want this on a single line
|
# tools want this on a single line
|
||||||
ACLOCAL_AMFLAGS = -I m4macros
|
ACLOCAL_AMFLAGS = -I m4macros
|
||||||
|
|
||||||
|
all-local:
|
||||||
|
|
||||||
|
dist_doc_DATA = \
|
||||||
|
AUTHORS \
|
||||||
|
NEWS \
|
||||||
|
README \
|
||||||
|
README.md
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
autogen.sh \
|
autogen.sh \
|
||||||
tinyproxy-indent.sh \
|
tinyproxy-indent.sh \
|
||||||
|
|||||||
@@ -1,153 +1 @@
|
|||||||
Tinyproxy NEWS
|
See git log for recent changes in Tinyproxy.
|
||||||
==============
|
|
||||||
|
|
||||||
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.
|
|
||||||
@@ -1,97 +1 @@
|
|||||||
Tinyproxy
|
see README.md
|
||||||
=========
|
|
||||||
|
|
||||||
Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
|
|
||||||
GNU General Public License. Tinyproxy is very useful in a small network
|
|
||||||
setting, where a larger proxy would either be too resource intensive, or
|
|
||||||
a security risk. One of the key features of Tinyproxy is the buffering
|
|
||||||
connection concept. In effect, Tinyproxy will buffer a high speed
|
|
||||||
response from a server, and then relay it to a client at the highest
|
|
||||||
speed the client will accept. This feature greatly reduces the problems
|
|
||||||
with sluggishness on the Internet. If you are sharing an Internet
|
|
||||||
connection with a small network, and you only want to allow HTTP
|
|
||||||
requests to be allowed, then Tinyproxy is a great tool for the network
|
|
||||||
administrator.
|
|
||||||
|
|
||||||
For more info, please visit:
|
|
||||||
|
|
||||||
https://banu.com/tinyproxy/
|
|
||||||
|
|
||||||
|
|
||||||
Installation
|
|
||||||
------------
|
|
||||||
|
|
||||||
To install this package under a UNIX derivative, read the INSTALL file.
|
|
||||||
Tinyproxy uses a standard GNU `configure` script. Basically you should
|
|
||||||
be able to do:
|
|
||||||
|
|
||||||
----
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
----
|
|
||||||
|
|
||||||
in the top level directory to compile and install Tinyproxy. There are
|
|
||||||
additional command line arguments you can supply to `configure`. They
|
|
||||||
include:
|
|
||||||
|
|
||||||
--enable-debug If you would like to turn on full
|
|
||||||
debugging support
|
|
||||||
--enable-xtinyproxy Compile in support for the XTinyproxy
|
|
||||||
header, which is sent to any web
|
|
||||||
server in your domain.
|
|
||||||
--enable-filter Allows Tinyproxy to filter out certain
|
|
||||||
domains and URLs.
|
|
||||||
--enable-upstream Enable support for proxying connections
|
|
||||||
through another proxy server.
|
|
||||||
--enable-transparent
|
|
||||||
Allow Tinyproxy to be used as a
|
|
||||||
transparent proxy daemon
|
|
||||||
--enable-static Compile a static version of Tinyproxy
|
|
||||||
|
|
||||||
--with-stathost=HOST Set the default name of the stats host
|
|
||||||
|
|
||||||
|
|
||||||
Support
|
|
||||||
-------
|
|
||||||
|
|
||||||
If you are having problems with Tinyproxy, please submit a bug report
|
|
||||||
using Tinyproxy as the product at:
|
|
||||||
|
|
||||||
https://banu.com/bugzilla/
|
|
||||||
|
|
||||||
You may also wish to subscribe to the Tinyproxy mailing lists. To do so
|
|
||||||
please visit:
|
|
||||||
|
|
||||||
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 lists.
|
|
||||||
|
|
||||||
|
|
||||||
Contributing
|
|
||||||
------------
|
|
||||||
|
|
||||||
If you would like to contribute a feature, or a bug fix to the Tinyproxy
|
|
||||||
source, please send a patch (preferably as a unified diff. i.e. `diff
|
|
||||||
-u` against the "master" branch of the Tinyproxy source code git
|
|
||||||
repository to tinyproxy-developers-list. Please include a description
|
|
||||||
of what your patch does.
|
|
||||||
|
|
||||||
Tinyproxy's git repository is git://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).
|
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
# Tinyproxy
|
||||||
|
|
||||||
|
Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
|
||||||
|
GNU General Public License. Tinyproxy is very useful in a small network
|
||||||
|
setting, where a larger proxy would either be too resource intensive, or
|
||||||
|
a security risk. One of the key features of Tinyproxy is the buffering
|
||||||
|
connection concept. In effect, Tinyproxy will buffer a high speed
|
||||||
|
response from a server, and then relay it to a client at the highest
|
||||||
|
speed the client will accept. This feature greatly reduces the problems
|
||||||
|
with sluggishness on the Internet. If you are sharing an Internet
|
||||||
|
connection with a small network, and you only want to allow HTTP
|
||||||
|
requests to be allowed, then Tinyproxy is a great tool for the network
|
||||||
|
administrator.
|
||||||
|
|
||||||
|
For more info, please visit [the Tinyproxy web site](https://tinyproxy.github.io/).
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Tinyproxy uses a standard GNU `configure` script based on the automake
|
||||||
|
system. If compiling from a git checkout, you need to first run
|
||||||
|
|
||||||
|
```
|
||||||
|
./autogen.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
from the top level directory to generate the `configure` script.
|
||||||
|
The release tarball contains the pre-created `configure` script,
|
||||||
|
so when building from a release, you can skip this step.
|
||||||
|
Then basically all you need to do is
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
in the top level directory to compile and install Tinyproxy. There are
|
||||||
|
additional command line arguments you can supply to `configure`. They
|
||||||
|
include:
|
||||||
|
|
||||||
|
- `--enable-debug`:
|
||||||
|
If you would like to turn on full debugging support.
|
||||||
|
|
||||||
|
- `--enable-xtinyproxy`:
|
||||||
|
Compile in support for the XTinyproxy header, which is sent to any
|
||||||
|
web server in your domain.
|
||||||
|
|
||||||
|
- `--enable-filter`:
|
||||||
|
Allows Tinyproxy to filter out certain domains and URLs.
|
||||||
|
|
||||||
|
- `--enable-upstream`:
|
||||||
|
Enable support for proxying connections through another proxy server.
|
||||||
|
|
||||||
|
- `--enable-transparent`:
|
||||||
|
Allow Tinyproxy to be used as a transparent proxy daemon.
|
||||||
|
|
||||||
|
- `--enable-reverse`:
|
||||||
|
Enable reverse proxying.
|
||||||
|
|
||||||
|
- `--with-stathost=HOST`:
|
||||||
|
Set the default name of the stats host.
|
||||||
|
|
||||||
|
For more information about the build system, read the INSTALL file
|
||||||
|
that is generated by `autogen.sh` and comes with the release tar ball.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
|
||||||
|
If you are having problems with Tinyproxy, please raise an
|
||||||
|
[issue on github](https://github.com/tinyproxy/tinyproxy/issues).
|
||||||
|
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
If you would like to contribute a feature, or a bug fix to the Tinyproxy
|
||||||
|
source, please clone the
|
||||||
|
[git repository from github](https://github.com/tinyproxy/tinyproxy.git)
|
||||||
|
and create a [pull request](https://github.com/tinyproxy/tinyproxy/pulls).
|
||||||
|
|
||||||
|
|
||||||
|
## Community
|
||||||
|
|
||||||
|
You can meet developers and users to discuss development,
|
||||||
|
patches and deployment issues in the `#tinyproxy` IRC channel on
|
||||||
|
Freenode (`irc.freenode.net`).
|
||||||
@@ -38,7 +38,7 @@ against the current tree and I'll integrate it if possible.
|
|||||||
* Include user authentication for accessing tinyproxy itself.
|
* Include user authentication for accessing tinyproxy itself.
|
||||||
Administrators should be allowed to selectively allow certain users
|
Administrators should be allowed to selectively allow certain users
|
||||||
access to tinyproxy via a user name/password pair. Check the
|
access to tinyproxy via a user name/password pair. Check the
|
||||||
HTTP/1.1 RFC for more information. [Suggested: Tyrone Tranmer]
|
HTTP/1.1 RFC for more information.
|
||||||
|
|
||||||
==> https://www.banu.com/bugzilla/show_bug.cgi?id=13
|
==> https://www.banu.com/bugzilla/show_bug.cgi?id=13
|
||||||
|
|
||||||
|
|||||||
+55
-114
@@ -4,44 +4,26 @@
|
|||||||
AC_PREREQ(2.54)
|
AC_PREREQ(2.54)
|
||||||
|
|
||||||
m4_define([tinyproxy_major_version], [1])
|
m4_define([tinyproxy_major_version], [1])
|
||||||
m4_define([tinyproxy_minor_version], [8])
|
m4_define([tinyproxy_minor_version], [10])
|
||||||
m4_define([tinyproxy_micro_version], [3])
|
m4_define([tinyproxy_micro_version], [0])
|
||||||
m4_define([tinyproxy_real_version],
|
m4_define([tinyproxy_real_version],
|
||||||
[tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
|
[tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
|
||||||
m4_define([tinyproxy_version], [tinyproxy_real_version])
|
m4_define([tinyproxy_version], [tinyproxy_real_version])
|
||||||
|
|
||||||
# For overriding the version string. Comment out if not needed.
|
# For overriding the version string. Comment out if not needed.
|
||||||
# m4_define([tinyproxy_version], [1.8.2])
|
# m4_define([tinyproxy_version], [1.10.0])
|
||||||
|
|
||||||
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],
|
AC_INIT([Tinyproxy], [tinyproxy_version],
|
||||||
[https://banu.com/tinyproxy/],
|
[https://tinyproxy.github.io/],
|
||||||
[tinyproxy])
|
[tinyproxy])
|
||||||
|
|
||||||
AC_CANONICAL_TARGET
|
AC_CANONICAL_TARGET
|
||||||
AM_INIT_AUTOMAKE([dist-bzip2])
|
AM_INIT_AUTOMAKE([dist-bzip2 dist-xz])
|
||||||
AM_CONFIG_HEADER(config.h)
|
AC_CONFIG_HEADERS(config.h)
|
||||||
AC_CONFIG_MACRO_DIR([m4macros])
|
AC_CONFIG_MACRO_DIR([m4macros])
|
||||||
|
|
||||||
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
|
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
|
||||||
|
|
||||||
TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
|
|
||||||
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
|
|
||||||
TINYPROXY_MICRO_VERSION=tinyproxy_micro_version
|
|
||||||
TINYPROXY_REAL_VERSION=tinyproxy_real_version
|
|
||||||
TINYPROXY_VERSION=tinyproxy_version
|
|
||||||
TINYPROXY_UNSTABLE=tinyproxy_unstable
|
|
||||||
AC_SUBST(TINYPROXY_MAJOR_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_MINOR_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_MICRO_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_REAL_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_UNSTABLE)
|
|
||||||
|
|
||||||
dnl Temporarily defined here until we get tinyproxy-version.h
|
dnl Temporarily defined here until we get tinyproxy-version.h
|
||||||
AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number])
|
AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number])
|
||||||
|
|
||||||
@@ -113,8 +95,8 @@ dnl Include support for reverse proxy?
|
|||||||
AH_TEMPLATE([REVERSE_SUPPORT],
|
AH_TEMPLATE([REVERSE_SUPPORT],
|
||||||
[Include support for reverse proxy.])
|
[Include support for reverse proxy.])
|
||||||
TP_ARG_ENABLE(reverse,
|
TP_ARG_ENABLE(reverse,
|
||||||
[Enable reverse proxying (default is NO)],
|
[Enable reverse proxying (default is YES)],
|
||||||
no)
|
yes)
|
||||||
if test x"$reverse_enabled" = x"yes"; then
|
if test x"$reverse_enabled" = x"yes"; then
|
||||||
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
|
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
|
||||||
AC_DEFINE(REVERSE_SUPPORT)
|
AC_DEFINE(REVERSE_SUPPORT)
|
||||||
@@ -124,18 +106,13 @@ 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.])
|
||||||
TP_ARG_ENABLE(transparent,
|
TP_ARG_ENABLE(transparent,
|
||||||
[Enable transparent proxying code (default is NO)],
|
[Enable transparent proxying code (default is YES)],
|
||||||
no)
|
yes)
|
||||||
if test x"$transparent_enabled" = x"yes"; then
|
if test x"$transparent_enabled" = x"yes"; then
|
||||||
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
|
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
|
||||||
AC_DEFINE(TRANSPARENT_PROXY)
|
AC_DEFINE(TRANSPARENT_PROXY)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dnl Check for broken regex library
|
|
||||||
TP_ARG_ENABLE(regexcheck,
|
|
||||||
[Check for working regex library (default is YES)],
|
|
||||||
yes)
|
|
||||||
|
|
||||||
# This is required to build test programs below
|
# This is required to build test programs below
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
|
||||||
@@ -166,48 +143,19 @@ dnl
|
|||||||
AC_HEADER_STDC
|
AC_HEADER_STDC
|
||||||
AC_HEADER_TIME
|
AC_HEADER_TIME
|
||||||
AC_HEADER_SYS_WAIT
|
AC_HEADER_SYS_WAIT
|
||||||
AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \
|
AC_CHECK_HEADERS([sys/ioctl.h alloca.h memory.h malloc.h sysexits.h \
|
||||||
sys/select.h sys/socket.h sys/time.h sys/uio.h \
|
|
||||||
sys/un.h arpa/inet.h netinet/in.h \
|
|
||||||
assert.h ctype.h errno.h fcntl.h grp.h io.h libintl.h \
|
|
||||||
netdb.h pwd.h regex.h signal.h stdarg.h stddef.h stdio.h \
|
|
||||||
sysexits.h syslog.h time.h wchar.h wctype.h \
|
|
||||||
values.h])
|
values.h])
|
||||||
|
|
||||||
dnl OpenBSD machines don't like having malloc included (even if it's present)
|
|
||||||
dnl as they expect you to use stdlib.h
|
|
||||||
case "$target" in
|
|
||||||
*-openbsd*) ;;
|
|
||||||
*) AC_CHECK_HEADER(malloc.h);;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
dnl Checks for types
|
|
||||||
AC_TYPE_SIZE_T
|
|
||||||
AC_TYPE_PID_T
|
|
||||||
AC_UNP_CHECK_TYPE(uint8_t, unsigned char)
|
|
||||||
AC_UNP_CHECK_TYPE(int16_t, short)
|
|
||||||
AC_UNP_CHECK_TYPE(uint16_t, unsigned short)
|
|
||||||
AC_UNP_CHECK_TYPE(int32_t, int)
|
|
||||||
AC_UNP_CHECK_TYPE(uint32_t, unsigned int)
|
|
||||||
AC_UNP_CHECK_TYPE(ssize_t, int)
|
|
||||||
AC_UNP_CHECK_TYPE(socklen_t, unsigned int)
|
|
||||||
AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
|
|
||||||
|
|
||||||
|
|
||||||
dnl Checks for libary functions
|
dnl Checks for libary functions
|
||||||
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
|
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
|
||||||
AC_FUNC_MALLOC
|
AC_FUNC_MALLOC
|
||||||
AC_FUNC_REALLOC
|
AC_FUNC_REALLOC
|
||||||
|
|
||||||
AC_CHECK_FUNCS([gethostname inet_ntoa memchr memset select socket strcasecmp \
|
AC_CHECK_FUNCS([inet_ntoa strdup])
|
||||||
strchr strdup strerror strncasecmp strpbrk strstr strtol])
|
AC_CHECK_FUNCS([strlcpy strlcat setgroups])
|
||||||
AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regcomp regexec])
|
|
||||||
AC_CHECK_FUNCS([strlcpy strlcat])
|
|
||||||
|
|
||||||
|
|
||||||
dnl Enable extra warnings
|
dnl Enable extra warnings
|
||||||
DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -pedantic -Wc++-compat -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
|
DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -Wno-overlength-strings -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
|
||||||
|
|
||||||
if test -n "${MAINTAINER_MODE_FALSE}"; then
|
if test -n "${MAINTAINER_MODE_FALSE}"; then
|
||||||
DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
|
DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
|
||||||
@@ -222,57 +170,17 @@ if test x"$debug_enabled" != x"yes" ; then
|
|||||||
CFLAGS="-DNDEBUG $CFLAGS"
|
CFLAGS="-DNDEBUG $CFLAGS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LDFLAGS="-Wl,-z,defs"
|
AS_ECHO_N(["checking to see if linker understands -z,defs... "])
|
||||||
|
LDFLAGS_OLD="-Wl $LDFLAGS"
|
||||||
|
LDFLAGS="-Wl,-z,defs $LDFLAGS"
|
||||||
|
AC_LINK_IFELSE([AC_LANG_PROGRAM()],
|
||||||
|
AS_ECHO("yes"),
|
||||||
|
AS_ECHO("no"); LDFLAGS="$LDFLAGS_OLD")
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
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 REGEX library
|
|
||||||
if test x"$ac_cv_func_regexec" != x"yes"; then
|
|
||||||
AC_MSG_ERROR([Could not locate the regexec() function])
|
|
||||||
else
|
|
||||||
if test x"$regexcheck_enabled" = x"yes" ; then
|
|
||||||
AC_MSG_CHECKING([whether the system's regex library is broken])
|
|
||||||
AC_CACHE_VAL(tinyproxy_cv_regex_broken,
|
|
||||||
[AC_TRY_RUN([
|
|
||||||
#if HAVE_SYS_TYPES_H
|
|
||||||
# include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_UNISTD_H
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_REGEX_H
|
|
||||||
# include <regex.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_STDLIB_H
|
|
||||||
# include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
regex_t blah;
|
|
||||||
if (regcomp(&blah, "foo.*bar", REG_NOSUB) != 0)
|
|
||||||
exit(1);
|
|
||||||
if (regexec(&blah, "foobar", 0, NULL, 0) != 0)
|
|
||||||
exit(1);
|
|
||||||
else
|
|
||||||
exit(0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tinyproxy_cv_regex_broken=no,
|
|
||||||
tinyproxy_cv_regex_broken=yes,
|
|
||||||
tinyproxy_cv_regex_broken=yes)])
|
|
||||||
|
|
||||||
AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
|
|
||||||
|
|
||||||
if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
|
|
||||||
AC_MSG_ERROR([Your system's regexec() function is broken.])
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl Substitute the variables into the various Makefiles
|
dnl Substitute the variables into the various Makefiles
|
||||||
dnl
|
dnl
|
||||||
@@ -282,12 +190,28 @@ AC_SUBST(CPPFLAGS)
|
|||||||
AC_SUBST(LIBS)
|
AC_SUBST(LIBS)
|
||||||
AC_SUBST(ADDITIONAL_OBJECTS)
|
AC_SUBST(ADDITIONAL_OBJECTS)
|
||||||
|
|
||||||
|
# Check for xml tools
|
||||||
|
AC_PATH_PROG(XSLTPROC, xsltproc, no)
|
||||||
|
AM_CONDITIONAL(HAVE_XSLTPROC, test "x$XSLTPROC" != "xno")
|
||||||
|
|
||||||
# Check for asciidoc
|
# Check for asciidoc
|
||||||
AC_PATH_PROG(A2X, a2x, no)
|
AC_PATH_PROG(A2X, a2x, no)
|
||||||
AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno")
|
AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno")
|
||||||
if test x"$A2X" = x"no"; then
|
|
||||||
AC_MSG_ERROR([Test for asciidoc failed. See the file 'INSTALL' for help.])
|
# checking xmllint
|
||||||
|
AC_PATH_PROG(XMLLINT, xmllint, no)
|
||||||
|
if test "x$XMLLINT" != "xno"; then
|
||||||
|
AS_ECHO_N("testing xmllint... ")
|
||||||
|
echo "TEST" > conftest.txt
|
||||||
|
if $A2X -f docbook conftest.txt 2>/dev/null; then
|
||||||
|
AS_ECHO("ok")
|
||||||
|
else
|
||||||
|
AS_ECHO("failed")
|
||||||
|
XMLLINT="no"
|
||||||
|
fi
|
||||||
|
rm -f conftest.txt conftest.xml
|
||||||
fi
|
fi
|
||||||
|
AM_CONDITIONAL(HAVE_XMLLINT, test "x$XMLLINT" != "xno")
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
@@ -306,3 +230,20 @@ tests/scripts/Makefile
|
|||||||
])
|
])
|
||||||
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
|
# the manpages are shipped in the release tarball and we don't want them to
|
||||||
|
# get regenerated if a2x is not available. the intermediate files from
|
||||||
|
# AC_CONFIG_FILES are created with config.status, which is created at configure
|
||||||
|
# runtime, so we need to touch them after config.status terminated to prevent
|
||||||
|
# make from rebuild them.
|
||||||
|
|
||||||
|
if test "x$A2X" = "xno"; then
|
||||||
|
touch docs/man5/tinyproxy.conf.txt
|
||||||
|
touch docs/man8/tinyproxy.txt
|
||||||
|
if test -e docs/man5/tinyproxy.conf.5 ; then
|
||||||
|
touch docs/man5/tinyproxy.conf.5
|
||||||
|
fi
|
||||||
|
if test -e docs/man8/tinyproxy.8 ; then
|
||||||
|
touch docs/man8/tinyproxy.8
|
||||||
|
fi
|
||||||
|
fi
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
MAN5_FILES = \
|
MAN5_FILES = \
|
||||||
tinyproxy.conf.txt
|
tinyproxy.conf.txt
|
||||||
|
|
||||||
A2X_ARGS = \
|
if HAVE_XMLLINT
|
||||||
-d manpage \
|
A2X_ARGS = -d manpage -f manpage
|
||||||
-f manpage
|
else
|
||||||
|
A2X_ARGS = -d manpage -f manpage -L
|
||||||
|
endif
|
||||||
|
|
||||||
man_MANS = \
|
man_MANS = \
|
||||||
$(MAN5_FILES:.txt=.5)
|
$(MAN5_FILES:.txt=.5)
|
||||||
@@ -18,3 +20,6 @@ endif
|
|||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
$(MAN5_FILES:.txt=.5) \
|
$(MAN5_FILES:.txt=.5) \
|
||||||
$(MAN5_FILES:.txt=.xml)
|
$(MAN5_FILES:.txt=.xml)
|
||||||
|
|
||||||
|
EXTRA_DIST = \
|
||||||
|
$(MAN5_FILES:.txt=.5)
|
||||||
@@ -144,21 +144,25 @@ The possible keywords and their descriptions are as follows:
|
|||||||
`X-Tinyproxy` containing the client's IP address to the request.
|
`X-Tinyproxy` containing the client's IP address to the request.
|
||||||
|
|
||||||
*Upstream*::
|
*Upstream*::
|
||||||
*No Upstream*::
|
|
||||||
|
|
||||||
This option allows you to set up a set of rules for deciding
|
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
|
whether an upstream proxy server is to be used, based on the
|
||||||
host or domain of the site being accessed. The rules are stored
|
host or domain of the site being accessed. The rules are stored
|
||||||
in the order encountered in the configuration file and the
|
in the order encountered in the configuration file and the
|
||||||
LAST matching rule wins. There are three possible forms for
|
LAST matching rule wins. The following forms for specifying upstream
|
||||||
specifying upstream rules:
|
rules exist:
|
||||||
|
|
||||||
* 'upstream host:port' turns proxy upstream support on generally.
|
* 'upstream type host:port' turns proxy upstream support on generally.
|
||||||
|
|
||||||
* 'upstream host:port "site_spec"' turns on the upstream proxy for
|
* 'upstream type user:pass@host:port' does the same, but uses the
|
||||||
the sites matching `site_spec`.
|
supplied credentials for authentication.
|
||||||
|
|
||||||
* 'no upstream "site_spec"' turns off upstream support for sites
|
* 'upstream type host:port "site_spec"' turns on the upstream proxy
|
||||||
|
for the sites matching `site_spec`.
|
||||||
|
|
||||||
|
`type` can be one of `http`, `socks4`, `socks5`, `none`.
|
||||||
|
|
||||||
|
* 'upstream none "site_spec"' turns off upstream support for sites
|
||||||
matching `site_spec`.
|
matching `site_spec`.
|
||||||
|
|
||||||
The site can be specified in various forms as a hostname, domain
|
The site can be specified in various forms as a hostname, domain
|
||||||
@@ -343,7 +347,7 @@ BUGS
|
|||||||
----
|
----
|
||||||
|
|
||||||
To report bugs in Tinyproxy, please visit
|
To report bugs in Tinyproxy, please visit
|
||||||
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
|
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>.
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
@@ -354,16 +358,13 @@ tinyproxy(8)
|
|||||||
AUTHOR
|
AUTHOR
|
||||||
------
|
------
|
||||||
|
|
||||||
Written by the Tinyproxy project team.
|
This manpage was written by the Tinyproxy project team.
|
||||||
|
|
||||||
|
|
||||||
COPYRIGHT
|
COPYRIGHT
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Copyright (c) 1998-2000 Steven Young;
|
Copyright (c) 1998-2018 the Tinyproxy authors.
|
||||||
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
|
This program is distributed under the terms of the GNU General Public
|
||||||
License version 2 or above. See the COPYING file for additional
|
License version 2 or above. See the COPYING file for additional
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
MAN8_FILES = \
|
MAN8_FILES = \
|
||||||
tinyproxy.txt
|
tinyproxy.txt
|
||||||
|
|
||||||
A2X_ARGS = \
|
if HAVE_XMLLINT
|
||||||
-d manpage \
|
A2X_ARGS = -d manpage -f manpage
|
||||||
-f manpage
|
else
|
||||||
|
A2X_ARGS = -d manpage -f manpage -L
|
||||||
|
endif
|
||||||
|
|
||||||
man_MANS = \
|
man_MANS = \
|
||||||
$(MAN8_FILES:.txt=.8)
|
$(MAN8_FILES:.txt=.8)
|
||||||
@@ -18,3 +20,6 @@ endif
|
|||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
$(MAN8_FILES:.txt=.8) \
|
$(MAN8_FILES:.txt=.8) \
|
||||||
$(MAN8_FILES:.txt=.xml)
|
$(MAN8_FILES:.txt=.xml)
|
||||||
|
|
||||||
|
EXTRA_DIST= \
|
||||||
|
$(MAN8_FILES:.txt=.8)
|
||||||
@@ -40,9 +40,6 @@ OPTIONS
|
|||||||
*-h*::
|
*-h*::
|
||||||
Display a short help screen of command line arguments and exit.
|
Display a short help screen of command line arguments and exit.
|
||||||
|
|
||||||
*-l*::
|
|
||||||
Display the licensing agreement.
|
|
||||||
|
|
||||||
*-v*::
|
*-v*::
|
||||||
Display version information and exit.
|
Display version information and exit.
|
||||||
|
|
||||||
@@ -136,7 +133,7 @@ BUGS
|
|||||||
----
|
----
|
||||||
|
|
||||||
To report bugs in Tinyproxy, please visit
|
To report bugs in Tinyproxy, please visit
|
||||||
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
|
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>.
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
@@ -147,16 +144,13 @@ tinyproxy.conf(5)
|
|||||||
AUTHOR
|
AUTHOR
|
||||||
------
|
------
|
||||||
|
|
||||||
Written by the Tinyproxy project team.
|
This manpage was written by the Tinyproxy project team.
|
||||||
|
|
||||||
|
|
||||||
COPYRIGHT
|
COPYRIGHT
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Copyright (c) 1998-2000 Steven Young;
|
Copyright (c) 1998-2018 the Tinyproxy authors.
|
||||||
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
|
This program is distributed under the terms of the GNU General Public
|
||||||
License version 2 or above. See the COPYING file for additional
|
License version 2 or above. See the COPYING file for additional
|
||||||
|
|||||||
+4
-2
@@ -1,4 +1,6 @@
|
|||||||
sysconf_DATA = \
|
pkgsysconfdir = $(sysconfdir)/$(PACKAGE)
|
||||||
|
|
||||||
|
pkgsysconf_DATA = \
|
||||||
tinyproxy.conf
|
tinyproxy.conf
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
@@ -8,7 +10,7 @@ edit = sed \
|
|||||||
-e 's|@bindir[@]|$(bindir)|g' \
|
-e 's|@bindir[@]|$(bindir)|g' \
|
||||||
-e 's|@datadir[@]|$(datadir)|g' \
|
-e 's|@datadir[@]|$(datadir)|g' \
|
||||||
-e 's|@datarootdir[@]|$(datarootdir)|g' \
|
-e 's|@datarootdir[@]|$(datarootdir)|g' \
|
||||||
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
|
-e 's|@pkgsysconfdir[@]|$(pkgsysconfdir)|g' \
|
||||||
-e 's|@localstatedir[@]|$(localstatedir)|g' \
|
-e 's|@localstatedir[@]|$(localstatedir)|g' \
|
||||||
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
|
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
|
||||||
-e 's|@prefix[@]|$(prefix)|g' \
|
-e 's|@prefix[@]|$(prefix)|g' \
|
||||||
|
|||||||
+37
-18
@@ -90,7 +90,8 @@ StatFile "@pkgdatadir@/stats.html"
|
|||||||
# LogFile: Allows you to specify the location where information should
|
# LogFile: Allows you to specify the location where information should
|
||||||
# be logged to. If you would prefer to log to syslog, then disable this
|
# be logged to. If you would prefer to log to syslog, then disable this
|
||||||
# and enable the Syslog directive. These directives are mutually
|
# and enable the Syslog directive. These directives are mutually
|
||||||
# exclusive.
|
# exclusive. If neither Syslog nor LogFile are specified, output goes
|
||||||
|
# to stdout.
|
||||||
#
|
#
|
||||||
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
|
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ StatFile "@pkgdatadir@/stats.html"
|
|||||||
#Syslog On
|
#Syslog On
|
||||||
|
|
||||||
#
|
#
|
||||||
# LogLevel:
|
# LogLevel: Warning
|
||||||
#
|
#
|
||||||
# Set the logging level. Allowed settings are:
|
# Set the logging level. Allowed settings are:
|
||||||
# Critical (least verbose)
|
# Critical (least verbose)
|
||||||
@@ -121,6 +122,7 @@ LogLevel Info
|
|||||||
#
|
#
|
||||||
# PidFile: Write the PID of the main tinyproxy thread to this file so it
|
# PidFile: Write the PID of the main tinyproxy thread to this file so it
|
||||||
# can be used for signalling purposes.
|
# can be used for signalling purposes.
|
||||||
|
# If not specified, no pidfile will be written.
|
||||||
#
|
#
|
||||||
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
|
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
|
||||||
|
|
||||||
@@ -138,25 +140,37 @@ LogLevel Info
|
|||||||
# The upstream rules allow you to selectively route upstream connections
|
# The upstream rules allow you to selectively route upstream connections
|
||||||
# based on the host/domain of the site being accessed.
|
# based on the host/domain of the site being accessed.
|
||||||
#
|
#
|
||||||
|
# Syntax: upstream type (user:pass@)ip:port ("domain")
|
||||||
|
# Or: upstream none "domain"
|
||||||
|
# The parts in parens are optional.
|
||||||
|
# Possible types are http, socks4, socks5, none
|
||||||
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# # connection to test domain goes through testproxy
|
# # connection to test domain goes through testproxy
|
||||||
# upstream testproxy:8008 ".test.domain.invalid"
|
# upstream http testproxy:8008 ".test.domain.invalid"
|
||||||
# upstream testproxy:8008 ".our_testbed.example.com"
|
# upstream http testproxy:8008 ".our_testbed.example.com"
|
||||||
# upstream testproxy:8008 "192.168.128.0/255.255.254.0"
|
# upstream http testproxy:8008 "192.168.128.0/255.255.254.0"
|
||||||
|
#
|
||||||
|
# # upstream proxy using basic authentication
|
||||||
|
# upstream http user:pass@testproxy:8008 ".test.domain.invalid"
|
||||||
#
|
#
|
||||||
# # no upstream proxy for internal websites and unqualified hosts
|
# # no upstream proxy for internal websites and unqualified hosts
|
||||||
# no upstream ".internal.example.com"
|
# upstream none ".internal.example.com"
|
||||||
# no upstream "www.example.com"
|
# upstream none "www.example.com"
|
||||||
# no upstream "10.0.0.0/8"
|
# upstream none "10.0.0.0/8"
|
||||||
# no upstream "192.168.0.0/255.255.254.0"
|
# upstream none "192.168.0.0/255.255.254.0"
|
||||||
# no upstream "."
|
# upstream none "."
|
||||||
#
|
#
|
||||||
# # connection to these boxes go through their DMZ firewalls
|
# # connection to these boxes go through their DMZ firewalls
|
||||||
# upstream cust1_firewall:8008 "testbed_for_cust1"
|
# upstream http cust1_firewall:8008 "testbed_for_cust1"
|
||||||
# upstream cust2_firewall:8008 "testbed_for_cust2"
|
# upstream http cust2_firewall:8008 "testbed_for_cust2"
|
||||||
#
|
#
|
||||||
# # default upstream is internet firewall
|
# # default upstream is internet firewall
|
||||||
# upstream firewall.internal.example.com:80
|
# upstream http firewall.internal.example.com:80
|
||||||
|
#
|
||||||
|
# You may also use SOCKS4/SOCKS5 upstream proxies:
|
||||||
|
# upstream socks4 127.0.0.1:9050
|
||||||
|
# upstream socks5 socksproxy:1080
|
||||||
#
|
#
|
||||||
# The LAST matching rule wins the route decision. As you can see, you
|
# The LAST matching rule wins the route decision. As you can see, you
|
||||||
# can use a host, or a domain:
|
# can use a host, or a domain:
|
||||||
@@ -166,7 +180,7 @@ LogLevel Info
|
|||||||
# IP/bits matches network/mask
|
# IP/bits matches network/mask
|
||||||
# IP/mask matches network/mask
|
# IP/mask matches network/mask
|
||||||
#
|
#
|
||||||
#Upstream some.remote.proxy:port
|
#Upstream http some.remote.proxy:port
|
||||||
|
|
||||||
#
|
#
|
||||||
# MaxClients: This is the absolute highest number of threads which will
|
# MaxClients: This is the absolute highest number of threads which will
|
||||||
@@ -209,6 +223,11 @@ MaxRequestsPerChild 0
|
|||||||
#
|
#
|
||||||
Allow 127.0.0.1
|
Allow 127.0.0.1
|
||||||
|
|
||||||
|
# BasicAuth: HTTP "Basic Authentication" for accessing the proxy.
|
||||||
|
# If there are any entries specified, access is only granted for authenticated
|
||||||
|
# users.
|
||||||
|
#BasicAuth user password
|
||||||
|
|
||||||
#
|
#
|
||||||
# AddHeader: Adds the specified headers to outgoing HTTP requests that
|
# AddHeader: Adds the specified headers to outgoing HTTP requests that
|
||||||
# Tinyproxy makes. Note that this option will not work for HTTPS
|
# Tinyproxy makes. Note that this option will not work for HTTPS
|
||||||
@@ -236,7 +255,7 @@ ViaProxyName "tinyproxy"
|
|||||||
#
|
#
|
||||||
# Filter: This allows you to specify the location of the filter file.
|
# Filter: This allows you to specify the location of the filter file.
|
||||||
#
|
#
|
||||||
#Filter "@sysconfdir@/filter"
|
#Filter "@pkgsysconfdir@/filter"
|
||||||
|
|
||||||
#
|
#
|
||||||
# FilterURLs: Filter based on URLs rather than domains.
|
# FilterURLs: Filter based on URLs rather than domains.
|
||||||
@@ -283,12 +302,12 @@ ViaProxyName "tinyproxy"
|
|||||||
# ConnectPort: This is a list of ports allowed by tinyproxy when the
|
# ConnectPort: This is a list of ports allowed by tinyproxy when the
|
||||||
# CONNECT method is used. To disable the CONNECT method altogether, set
|
# CONNECT method is used. To disable the CONNECT method altogether, set
|
||||||
# the value to 0. If no ConnectPort line is found, all ports are
|
# the value to 0. If no ConnectPort line is found, all ports are
|
||||||
# allowed (which is not very secure.)
|
# allowed.
|
||||||
#
|
#
|
||||||
# The following two ports are used by SSL.
|
# The following two ports are used by SSL.
|
||||||
#
|
#
|
||||||
ConnectPort 443
|
#ConnectPort 443
|
||||||
ConnectPort 563
|
#ConnectPort 563
|
||||||
|
|
||||||
#
|
#
|
||||||
# Configure one or more ReversePath directives to enable reverse proxy
|
# Configure one or more ReversePath directives to enable reverse proxy
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
as-compiler-flag.m4 \
|
as-compiler-flag.m4 \
|
||||||
argenable.m4 \
|
argenable.m4
|
||||||
typecheck.m4
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
dnl Taken from Unix Network Programming, W. Richard Stevens
|
|
||||||
|
|
||||||
dnl ##################################################################
|
|
||||||
dnl We cannot use the AC_CHECK_TYPE macros becasue AC_CHECK_TYPE
|
|
||||||
dnl #includes only <sys/types.h>, <stdlib.h>, and <stddef.h>.
|
|
||||||
dnl Unfortunately, many implementations today hide typedefs in wierd
|
|
||||||
dnl locations: Solaris 2.5.1 has uint8_t and uint32_t in <pthread.h>.
|
|
||||||
dnl SunOS 4.1.x has int8_t in <sys/bittypes.h>.
|
|
||||||
dnl So we define our own macro AC_UNP_CHECK_TYPE that does the same
|
|
||||||
dnl #includes as "unp.h", and then looks for the typedef.
|
|
||||||
dnl
|
|
||||||
dnl This macro should be invoked after all the header checks have been
|
|
||||||
dnl performed, since we #include "confdefs.h" below, and then use the
|
|
||||||
dnl HAVE_foo_H values that is can #define.
|
|
||||||
dnl
|
|
||||||
AC_DEFUN([AC_UNP_CHECK_TYPE],
|
|
||||||
[AC_MSG_CHECKING(if $1 defined)
|
|
||||||
AC_CACHE_VAL(ac_cv_type_$1,
|
|
||||||
[AC_TRY_COMPILE(
|
|
||||||
[
|
|
||||||
#include "confdefs.h" /* the header built by configure so far */
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
|
||||||
# include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
|
||||||
# include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_TIME_H
|
|
||||||
# include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_NETINET_IN_H
|
|
||||||
# include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ARPA_INET_H
|
|
||||||
# include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ERRNO_H
|
|
||||||
# include <errno.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_FCNTL_H
|
|
||||||
# include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_NETDB_H
|
|
||||||
# include <netdb.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SIGNAL_H
|
|
||||||
# include <signal.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDIO_H
|
|
||||||
# include <stdio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDLIB_H
|
|
||||||
# include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STRING_H
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
# include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_UIO_H
|
|
||||||
# include <sys/uio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_WAIT_H
|
|
||||||
# include <sys/wait.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_UN_H
|
|
||||||
# include <sys/un.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SELECT_H
|
|
||||||
# include <sys/select.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STRINGS_H
|
|
||||||
# include <strings.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_IOCTL_H
|
|
||||||
# include <sys/ioctl.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_FILIO_H
|
|
||||||
# include <sys/filio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SOCKIO_H
|
|
||||||
# include <sys/sockio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_PTHREAD_H
|
|
||||||
# include <pthread.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDINT_H
|
|
||||||
# include <stdint.h>
|
|
||||||
#endif
|
|
||||||
],
|
|
||||||
[ $1 foo ],
|
|
||||||
[ac_cv_type_$1=yes],
|
|
||||||
[ac_cv_type_$1=no])])
|
|
||||||
AC_MSG_RESULT([$ac_cv_type_$1])
|
|
||||||
if test $ac_cv_type_$1 = no ; then
|
|
||||||
AH_TEMPLATE([$1], [Defined with the proper type.])
|
|
||||||
AC_DEFINE($1, $2)
|
|
||||||
fi
|
|
||||||
])
|
|
||||||
Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
|
||||||
|
BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||||
|
AUTHORS_FILE="${BASE_DIR}/AUTHORS"
|
||||||
|
|
||||||
|
type git > /dev/null || exit
|
||||||
|
test -d "${BASE_DIR}/.git" || exit
|
||||||
|
|
||||||
|
git log --all --format='%aN' | sort -u > "${AUTHORS_FILE}"
|
||||||
+6
-2
@@ -15,10 +15,12 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
sbin_PROGRAMS = tinyproxy
|
pkgsysconfdir = $(sysconfdir)/$(PACKAGE)
|
||||||
|
|
||||||
|
bin_PROGRAMS = tinyproxy
|
||||||
|
|
||||||
AM_CPPFLAGS = \
|
AM_CPPFLAGS = \
|
||||||
-DSYSCONFDIR=\"${sysconfdir}\" \
|
-DSYSCONFDIR=\"${pkgsysconfdir}\" \
|
||||||
-DLOCALSTATEDIR=\"${localstatedir}\"
|
-DLOCALSTATEDIR=\"${localstatedir}\"
|
||||||
|
|
||||||
tinyproxy_SOURCES = \
|
tinyproxy_SOURCES = \
|
||||||
@@ -44,6 +46,8 @@ tinyproxy_SOURCES = \
|
|||||||
utils.c utils.h \
|
utils.c utils.h \
|
||||||
vector.c vector.h \
|
vector.c vector.h \
|
||||||
upstream.c upstream.h \
|
upstream.c upstream.h \
|
||||||
|
basicauth.c basicauth.h \
|
||||||
|
base64.c base64.h \
|
||||||
connect-ports.c connect-ports.h
|
connect-ports.c connect-ports.h
|
||||||
|
|
||||||
EXTRA_tinyproxy_SOURCES = filter.c filter.h \
|
EXTRA_tinyproxy_SOURCES = filter.c filter.h \
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ struct acl_s {
|
|||||||
union {
|
union {
|
||||||
char *string;
|
char *string;
|
||||||
struct {
|
struct {
|
||||||
unsigned char octet[IPV6_LEN];
|
unsigned char network[IPV6_LEN];
|
||||||
unsigned char mask[IPV6_LEN];
|
unsigned char mask[IPV6_LEN];
|
||||||
} ip;
|
} ip;
|
||||||
} address;
|
} address;
|
||||||
@@ -134,7 +134,8 @@ static int init_access_list(vector_t *access_list)
|
|||||||
* -1 on failure
|
* -1 on failure
|
||||||
* 0 otherwise.
|
* 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
|
int
|
||||||
|
insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
|
||||||
{
|
{
|
||||||
struct acl_s acl;
|
struct acl_s acl;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -158,9 +159,11 @@ int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
|
|||||||
*/
|
*/
|
||||||
if (full_inet_pton (location, ip_dst) > 0) {
|
if (full_inet_pton (location, ip_dst) > 0) {
|
||||||
acl.type = ACL_NUMERIC;
|
acl.type = ACL_NUMERIC;
|
||||||
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
|
memcpy (acl.address.ip.network, ip_dst, IPV6_LEN);
|
||||||
memset (acl.address.ip.mask, 0xff, IPV6_LEN);
|
memset (acl.address.ip.mask, 0xff, IPV6_LEN);
|
||||||
} else {
|
} else {
|
||||||
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At this point we're either a hostname or an
|
* At this point we're either a hostname or an
|
||||||
* IP address with a slash.
|
* IP address with a slash.
|
||||||
@@ -179,7 +182,6 @@ int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
acl.type = ACL_NUMERIC;
|
acl.type = ACL_NUMERIC;
|
||||||
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
|
|
||||||
|
|
||||||
/* Check if the IP address before the netmask is
|
/* Check if the IP address before the netmask is
|
||||||
* an IPv6 address */
|
* an IPv6 address */
|
||||||
@@ -192,6 +194,10 @@ int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
|
|||||||
(p + 1, v6, &(acl.address.ip.mask[0]), IPV6_LEN)
|
(p + 1, v6, &(acl.address.ip.mask[0]), IPV6_LEN)
|
||||||
< 0)
|
< 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i < IPV6_LEN; i++)
|
||||||
|
acl.address.ip.network[i] = ip_dst[i] &
|
||||||
|
acl.address.ip.mask[i];
|
||||||
} else {
|
} else {
|
||||||
/* In all likelihood a string */
|
/* In all likelihood a string */
|
||||||
acl.type = ACL_STRING;
|
acl.type = ACL_STRING;
|
||||||
@@ -305,7 +311,7 @@ static int check_numeric_acl (const struct acl_s *acl, const char *ip)
|
|||||||
|
|
||||||
for (i = 0; i != IPV6_LEN; ++i) {
|
for (i = 0; i != IPV6_LEN; ++i) {
|
||||||
x = addr[i] & acl->address.ip.mask[i];
|
x = addr[i] & acl->address.ip.mask[i];
|
||||||
y = acl->address.ip.octet[i] & acl->address.ip.mask[i];
|
y = acl->address.ip.network[i];
|
||||||
|
|
||||||
/* If x and y don't match, the IP addresses don't match */
|
/* If x and y don't match, the IP addresses don't match */
|
||||||
if (x != y)
|
if (x != y)
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* this file Copyright (C) 2016-2018 rofl0r
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "base64.h"
|
||||||
|
|
||||||
|
static const char base64_tbl[64] =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
|
/*
|
||||||
|
rofl0r's base64 impl (taken from libulz)
|
||||||
|
takes count bytes from src, writing base64 encoded string into dst.
|
||||||
|
dst needs to be at least BASE64ENC_BYTES(count) + 1 bytes in size.
|
||||||
|
the string in dst will be zero-terminated.
|
||||||
|
*/
|
||||||
|
void base64enc(char *dst, const void* src, size_t count)
|
||||||
|
{
|
||||||
|
unsigned const char *s = src;
|
||||||
|
char* d = dst;
|
||||||
|
while(count) {
|
||||||
|
int i = 0, n = *s << 16;
|
||||||
|
s++;
|
||||||
|
count--;
|
||||||
|
if(count) {
|
||||||
|
n |= *s << 8;
|
||||||
|
s++;
|
||||||
|
count--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if(count) {
|
||||||
|
n |= *s;
|
||||||
|
s++;
|
||||||
|
count--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
*d++ = base64_tbl[(n >> 18) & 0x3f];
|
||||||
|
*d++ = base64_tbl[(n >> 12) & 0x3f];
|
||||||
|
*d++ = i ? base64_tbl[(n >> 6) & 0x3f] : '=';
|
||||||
|
*d++ = i == 2 ? base64_tbl[n & 0x3f] : '=';
|
||||||
|
}
|
||||||
|
*d = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* this file Copyright (C) 2016-2018 rofl0r
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINYPROXY_BASE64_H
|
||||||
|
#define TINYPROXY_BASE64_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/* calculates number of bytes base64-encoded stream of N bytes will take. */
|
||||||
|
#define BASE64ENC_BYTES(N) (((N+2)/3)*4)
|
||||||
|
void base64enc(char *dst, const void* src, size_t count);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* This file: Copyright (C) 2016-2017 rofl0r
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include "basicauth.h"
|
||||||
|
|
||||||
|
#include "conns.h"
|
||||||
|
#include "heap.h"
|
||||||
|
#include "html-error.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "conf.h"
|
||||||
|
#include "base64.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create basic-auth token in buf.
|
||||||
|
* Returns strlen of token on success,
|
||||||
|
* -1 if user/pass missing
|
||||||
|
* 0 if user/pass too long
|
||||||
|
*/
|
||||||
|
ssize_t basicauth_string(const char *user, const char *pass,
|
||||||
|
char *buf, size_t bufsize)
|
||||||
|
{
|
||||||
|
char tmp[256+2];
|
||||||
|
int l;
|
||||||
|
if (!user || !pass) return -1;
|
||||||
|
l = snprintf(tmp, sizeof tmp, "%s:%s", user, pass);
|
||||||
|
if (l < 0 || l >= (ssize_t) sizeof tmp) return 0;
|
||||||
|
if (bufsize < (BASE64ENC_BYTES((unsigned)l) + 1)) return 0;
|
||||||
|
base64enc(buf, tmp, l);
|
||||||
|
return BASE64ENC_BYTES(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add entry to the basicauth list
|
||||||
|
*/
|
||||||
|
void basicauth_add (vector_t authlist,
|
||||||
|
const char *user, const char *pass)
|
||||||
|
{
|
||||||
|
char b[BASE64ENC_BYTES((256+2)-1) + 1];
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
|
ret = basicauth_string(user, pass, b, sizeof b);
|
||||||
|
if (ret == -1) {
|
||||||
|
log_message (LOG_WARNING,
|
||||||
|
"Illegal basicauth rule: missing user or pass");
|
||||||
|
return;
|
||||||
|
} else if (ret == 0) {
|
||||||
|
log_message (LOG_WARNING,
|
||||||
|
"User / pass in basicauth rule too long");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vector_append(authlist, b, ret + 1) == -ENOMEM) {
|
||||||
|
log_message (LOG_ERR,
|
||||||
|
"Unable to allocate memory in basicauth_add()");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message (LOG_INFO,
|
||||||
|
"Added basic auth user : %s", user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if a user/password combination (encoded as base64)
|
||||||
|
* is in the basicauth list.
|
||||||
|
* return 1 on success, 0 on failure.
|
||||||
|
*/
|
||||||
|
int basicauth_check (vector_t authlist, const char *authstring)
|
||||||
|
{
|
||||||
|
ssize_t vl, i;
|
||||||
|
size_t el;
|
||||||
|
const char* entry;
|
||||||
|
|
||||||
|
vl = vector_length (authlist);
|
||||||
|
if (vl == -EINVAL) return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < vl; i++) {
|
||||||
|
entry = vector_getentry (authlist, i, &el);
|
||||||
|
if (strcmp (authstring, entry) == 0)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* Copyright (C) 2005 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* See 'basicauth.c' for detailed information. */
|
||||||
|
|
||||||
|
#ifndef TINYPROXY_BASICAUTH_H
|
||||||
|
#define TINYPROXY_BASICAUTH_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
|
extern ssize_t basicauth_string(const char *user, const char *pass,
|
||||||
|
char *buf, size_t bufsize);
|
||||||
|
|
||||||
|
extern void basicauth_add (vector_t authlist,
|
||||||
|
const char *user, const char *pass);
|
||||||
|
|
||||||
|
extern int basicauth_check (vector_t authlist, const char *authstring);
|
||||||
|
|
||||||
|
#endif
|
||||||
+3
-5
@@ -236,8 +236,7 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
|
|||||||
"readbuff: add_to_buffer() error.");
|
"readbuff: add_to_buffer() error.");
|
||||||
bytesin = -1;
|
bytesin = -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (bytesin == 0) {
|
||||||
if (bytesin == 0) {
|
|
||||||
/* connection was closed by client */
|
/* connection was closed by client */
|
||||||
bytesin = -1;
|
bytesin = -1;
|
||||||
} else {
|
} else {
|
||||||
@@ -254,13 +253,12 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
|
|||||||
break;
|
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));
|
||||||
bytesin = -1;
|
bytesin = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
safefree (buffer);
|
safefree (buffer);
|
||||||
return bytesin;
|
return bytesin;
|
||||||
|
|||||||
+136
-8
@@ -32,8 +32,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "conf.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)
|
||||||
@@ -187,8 +186,13 @@ static void 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 = (struct sockaddr *) 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.");
|
||||||
@@ -196,11 +200,82 @@ static void 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) {
|
||||||
|
if (errno == EINTR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
log_message (LOG_ERR, "error calling select: %s",
|
||||||
|
strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
} else if (ret == 0) {
|
||||||
|
log_message (LOG_WARNING, "Strange: select returned 0 "
|
||||||
|
"but we did not specify a timeout...");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < vector_length(listen_fds); i++) {
|
||||||
|
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
|
||||||
|
|
||||||
|
if (FD_ISSET(*fd, &rfds)) {
|
||||||
|
/*
|
||||||
|
* only accept the connection on the first
|
||||||
|
* fd that we find readable. - fair?
|
||||||
|
*/
|
||||||
|
listenfd = *fd;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listenfd == -1) {
|
||||||
|
log_message(LOG_WARNING, "Strange: None of our listen "
|
||||||
|
"fds was readable after select");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = socket_blocking(listenfd);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "Failed to set listening "
|
||||||
|
"socket %d to blocking for accept: %s",
|
||||||
|
listenfd, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We have a socket that is readable.
|
||||||
|
* Continue handling this connection.
|
||||||
|
*/
|
||||||
|
|
||||||
connfd = accept (listenfd, cliaddr, &clilen);
|
connfd = accept (listenfd, cliaddr, &clilen);
|
||||||
|
|
||||||
@@ -464,13 +539,66 @@ void child_kill_children (int sig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int child_listening_sock (uint16_t port)
|
|
||||||
|
/**
|
||||||
|
* Listen on the various configured interfaces
|
||||||
|
*/
|
||||||
|
int child_listening_sockets(vector_t listen_addrs, uint16_t port)
|
||||||
{
|
{
|
||||||
listenfd = listen_sock (port, &addrlen);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((listen_addrs == NULL) ||
|
||||||
|
(vector_length(listen_addrs) == 0))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* no Listen directive:
|
||||||
|
* listen on the wildcard address(es)
|
||||||
|
*/
|
||||||
|
ret = listen_sock(NULL, port, listen_fds);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < vector_length(listen_addrs); i++) {
|
||||||
|
const char *addr;
|
||||||
|
|
||||||
|
addr = (char *)vector_getentry(listen_addrs, i, NULL);
|
||||||
|
if (addr == NULL) {
|
||||||
|
log_message(LOG_WARNING,
|
||||||
|
"got NULL from listen_addrs - skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = listen_sock(addr, port, listen_fds);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void child_close_sock (void)
|
void child_close_sock (void)
|
||||||
{
|
{
|
||||||
close (listenfd);
|
ssize_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < vector_length(listen_fds); i++) {
|
||||||
|
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
|
||||||
|
close (*fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector_delete(listen_fds);
|
||||||
|
|
||||||
|
listen_fds = NULL;
|
||||||
}
|
}
|
||||||
+3
-1
@@ -21,6 +21,8 @@
|
|||||||
#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,
|
||||||
@@ -30,7 +32,7 @@ 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 (int sig);
|
extern void child_kill_children (int sig);
|
||||||
|
|||||||
+42
-109
@@ -32,135 +32,68 @@
|
|||||||
/*
|
/*
|
||||||
* Include standard headers which are used through-out tinyproxy
|
* Include standard headers which are used through-out tinyproxy
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
|
||||||
|
/* standard C headers - we can safely assume they exist. */
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
/* standard POSIX headers - they need to be there as well. */
|
||||||
|
# include <errno.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <netdb.h>
|
||||||
|
# include <signal.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
# include <strings.h>
|
||||||
|
# include <syslog.h>
|
||||||
|
# include <wchar.h>
|
||||||
|
# include <wctype.h>
|
||||||
|
# include <sys/mman.h>
|
||||||
|
# include <sys/select.h>
|
||||||
|
# include <sys/socket.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
#endif
|
# include <sys/wait.h>
|
||||||
|
# include <sys/uio.h>
|
||||||
|
# include <sys/un.h>
|
||||||
|
# include <sys/time.h>
|
||||||
|
# include <time.h>
|
||||||
|
# include <inttypes.h>
|
||||||
|
# include <sys/resource.h>
|
||||||
|
# include <netinet/in.h>
|
||||||
|
# include <assert.h>
|
||||||
|
# include <arpa/inet.h>
|
||||||
|
# include <grp.h>
|
||||||
|
# include <pwd.h>
|
||||||
|
# include <regex.h>
|
||||||
|
|
||||||
|
/* rest - some oddball headers */
|
||||||
#ifdef HAVE_VALUES_H
|
#ifdef HAVE_VALUES_H
|
||||||
# include <values.h>
|
# include <values.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_INTTYPES_H
|
|
||||||
# include <inttypes.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDDEF_H
|
|
||||||
# include <stddef.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDINT_H
|
|
||||||
# include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_IOCTL_H
|
#ifdef HAVE_SYS_IOCTL_H
|
||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYS_SELECT_H
|
|
||||||
# include <sys/select.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
|
||||||
# include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
# include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TIME_WITH_SYS_TIME
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <time.h>
|
|
||||||
#else
|
|
||||||
# ifdef HAVE_SYS_TIME_H
|
|
||||||
# include <sys/time.h>
|
|
||||||
# else
|
|
||||||
# include <time.h>
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
# include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_UIO_H
|
|
||||||
# include <sys/uio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_UN_H
|
|
||||||
# include <sys/un.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_WAIT_H
|
|
||||||
# include <sys/wait.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_NETINET_IN_H
|
|
||||||
# include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ARPA_INET_H
|
|
||||||
# include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ALLOCA_H
|
#ifdef HAVE_ALLOCA_H
|
||||||
# include <alloca.h>
|
# include <alloca.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_ASSERT_H
|
|
||||||
# include <assert.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_CTYPE_H
|
|
||||||
# include <ctype.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ERRNO_H
|
|
||||||
# include <errno.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_FCNTL_H
|
|
||||||
# include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_GRP_H
|
|
||||||
# include <grp.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_MEMORY_H
|
#ifdef HAVE_MEMORY_H
|
||||||
# include <memory.h>
|
# include <memory.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_NETDB_H
|
|
||||||
# include <netdb.h>
|
#ifdef HAVE_MALLOC_H
|
||||||
#endif
|
|
||||||
#ifdef HAVE_PWD_H
|
|
||||||
# include <pwd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_REGEX_H
|
|
||||||
# include <regex.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SIGNAL_H
|
|
||||||
# include <signal.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDARG_H
|
|
||||||
# include <stdarg.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDIO_H
|
|
||||||
# include <stdio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDLIB_H
|
|
||||||
# include <stdlib.h>
|
|
||||||
#else
|
|
||||||
# ifdef HAVE_MALLOC_H
|
|
||||||
# include <malloc.h>
|
# include <malloc.h>
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STRING_H
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STRINGS_H
|
|
||||||
# include <strings.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SYSEXITS_H
|
#ifdef HAVE_SYSEXITS_H
|
||||||
# include <sysexits.h>
|
# include <sysexits.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
# include <syslog.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_WCHAR_H
|
|
||||||
# include <wchar.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_WCTYPE_H
|
|
||||||
# include <wctype.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_MMAN_H
|
|
||||||
# include <sys/mman.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If MSG_NOSIGNAL is not defined, define it to be zero so that it doesn't
|
* If MSG_NOSIGNAL is not defined, define it to be zero so that it doesn't
|
||||||
|
|||||||
+111
-37
@@ -36,6 +36,7 @@
|
|||||||
#include "reverse-proxy.h"
|
#include "reverse-proxy.h"
|
||||||
#include "upstream.h"
|
#include "upstream.h"
|
||||||
#include "connect-ports.h"
|
#include "connect-ports.h"
|
||||||
|
#include "basicauth.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The configuration directives are defined in the structure below. Each
|
* The configuration directives are defined in the structure below. Each
|
||||||
@@ -116,6 +117,7 @@ static HANDLE_FUNC (handle_nop)
|
|||||||
} /* do nothing function */
|
} /* do nothing function */
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_allow);
|
static HANDLE_FUNC (handle_allow);
|
||||||
|
static HANDLE_FUNC (handle_basicauth);
|
||||||
static HANDLE_FUNC (handle_anonymous);
|
static HANDLE_FUNC (handle_anonymous);
|
||||||
static HANDLE_FUNC (handle_bind);
|
static HANDLE_FUNC (handle_bind);
|
||||||
static HANDLE_FUNC (handle_bindsame);
|
static HANDLE_FUNC (handle_bindsame);
|
||||||
@@ -230,6 +232,7 @@ struct {
|
|||||||
handle_deny),
|
handle_deny),
|
||||||
STDCONF ("bind", "(" IP "|" IPV6 ")", handle_bind),
|
STDCONF ("bind", "(" IP "|" IPV6 ")", handle_bind),
|
||||||
/* other */
|
/* other */
|
||||||
|
STDCONF ("basicauth", ALNUM WS ALNUM, handle_basicauth),
|
||||||
STDCONF ("errorfile", INT WS STR, handle_errorfile),
|
STDCONF ("errorfile", INT WS STR, handle_errorfile),
|
||||||
STDCONF ("addheader", STR WS STR, handle_addheader),
|
STDCONF ("addheader", STR WS STR, handle_addheader),
|
||||||
|
|
||||||
@@ -249,13 +252,15 @@ struct {
|
|||||||
STDCONF ("reversepath", STR "(" WS STR ")?", handle_reversepath),
|
STDCONF ("reversepath", STR "(" WS STR ")?", handle_reversepath),
|
||||||
#endif
|
#endif
|
||||||
#ifdef UPSTREAM_SUPPORT
|
#ifdef UPSTREAM_SUPPORT
|
||||||
/* upstream is rather complicated */
|
|
||||||
{
|
{
|
||||||
BEGIN "(no" WS "upstream)" WS STR END, handle_upstream_no, NULL
|
BEGIN "(upstream)" WS "(none)" WS STR END, handle_upstream_no, NULL
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
BEGIN "(upstream)" WS "(" IP "|" ALNUM ")" ":" INT "(" WS STR
|
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS
|
||||||
")?" END, handle_upstream, NULL
|
"(" ALNUM /*username*/ ":" ALNUM /*password*/ "@" ")?"
|
||||||
|
"(" IP "|" ALNUM ")"
|
||||||
|
":" INT "(" WS STR ")?"
|
||||||
|
END, handle_upstream, NULL
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
/* loglevel */
|
/* loglevel */
|
||||||
@@ -288,7 +293,8 @@ static void free_config (struct config_s *conf)
|
|||||||
safefree (conf->stathost);
|
safefree (conf->stathost);
|
||||||
safefree (conf->user);
|
safefree (conf->user);
|
||||||
safefree (conf->group);
|
safefree (conf->group);
|
||||||
safefree (conf->ipAddr);
|
vector_delete(conf->listen_addrs);
|
||||||
|
vector_delete(conf->basicauth_list);
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
safefree (conf->filter);
|
safefree (conf->filter);
|
||||||
#endif /* FILTER_ENABLE */
|
#endif /* FILTER_ENABLE */
|
||||||
@@ -465,8 +471,18 @@ static void initialize_with_defaults (struct config_s *conf,
|
|||||||
conf->group = safestrdup (defaults->group);
|
conf->group = safestrdup (defaults->group);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaults->ipAddr) {
|
if (defaults->listen_addrs) {
|
||||||
conf->ipAddr = safestrdup (defaults->ipAddr);
|
ssize_t i;
|
||||||
|
|
||||||
|
conf->listen_addrs = vector_create();
|
||||||
|
for (i=0; i < vector_length(defaults->listen_addrs); i++) {
|
||||||
|
char *addr;
|
||||||
|
size_t size;
|
||||||
|
addr = (char *)vector_getentry(defaults->listen_addrs,
|
||||||
|
i, &size);
|
||||||
|
vector_append(conf->listen_addrs, addr, size);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
@@ -759,12 +775,7 @@ static HANDLE_FUNC (handle_xtinyproxy)
|
|||||||
|
|
||||||
static HANDLE_FUNC (handle_syslog)
|
static HANDLE_FUNC (handle_syslog)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
return set_bool_arg (&conf->syslog, line, &match[2]);
|
return set_bool_arg (&conf->syslog, line, &match[2]);
|
||||||
#else
|
|
||||||
fprintf (stderr, "Syslog support not compiled in executable.\n");
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_bindsame)
|
static HANDLE_FUNC (handle_bindsame)
|
||||||
@@ -865,7 +876,6 @@ static HANDLE_FUNC (handle_deny)
|
|||||||
|
|
||||||
static HANDLE_FUNC (handle_bind)
|
static HANDLE_FUNC (handle_bind)
|
||||||
{
|
{
|
||||||
#ifndef TRANSPARENT_PROXY
|
|
||||||
int r = set_string_arg (&conf->bind_address, line, &match[2]);
|
int r = set_string_arg (&conf->bind_address, line, &match[2]);
|
||||||
|
|
||||||
if (r)
|
if (r)
|
||||||
@@ -873,20 +883,31 @@ static HANDLE_FUNC (handle_bind)
|
|||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"Outgoing connections bound to IP %s", conf->bind_address);
|
"Outgoing connections bound to IP %s", conf->bind_address);
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
|
||||||
fprintf (stderr,
|
|
||||||
"\"Bind\" cannot be used with transparent support enabled.\n");
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_listen)
|
static HANDLE_FUNC (handle_listen)
|
||||||
{
|
{
|
||||||
int r = set_string_arg (&conf->ipAddr, line, &match[2]);
|
char *arg = get_string_arg (line, &match[2]);
|
||||||
|
|
||||||
if (r)
|
if (arg == NULL) {
|
||||||
return r;
|
return -1;
|
||||||
log_message (LOG_INFO, "Listening on IP %s", conf->ipAddr);
|
}
|
||||||
|
|
||||||
|
if (conf->listen_addrs == NULL) {
|
||||||
|
conf->listen_addrs = vector_create();
|
||||||
|
if (conf->listen_addrs == NULL) {
|
||||||
|
log_message(LOG_WARNING, "Could not create a list "
|
||||||
|
"of listen addresses.");
|
||||||
|
safefree(arg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector_append (conf->listen_addrs, arg, strlen(arg) + 1);
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "Added address [%s] to listen addresses.", arg);
|
||||||
|
|
||||||
|
safefree (arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -933,6 +954,7 @@ static HANDLE_FUNC (handle_addheader)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Log level's strings.
|
* Log level's strings.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
struct log_levels_s {
|
struct log_levels_s {
|
||||||
const char *string;
|
const char *string;
|
||||||
@@ -967,6 +989,27 @@ static HANDLE_FUNC (handle_loglevel)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HANDLE_FUNC (handle_basicauth)
|
||||||
|
{
|
||||||
|
char *user, *pass;
|
||||||
|
user = get_string_arg(line, &match[2]);
|
||||||
|
if (!user)
|
||||||
|
return -1;
|
||||||
|
pass = get_string_arg(line, &match[3]);
|
||||||
|
if (!pass) {
|
||||||
|
safefree (user);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!conf->basicauth_list) {
|
||||||
|
conf->basicauth_list = vector_create ();
|
||||||
|
}
|
||||||
|
|
||||||
|
basicauth_add (conf->basicauth_list, user, pass);
|
||||||
|
safefree (user);
|
||||||
|
safefree (pass);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
static HANDLE_FUNC (handle_filter)
|
static HANDLE_FUNC (handle_filter)
|
||||||
{
|
{
|
||||||
@@ -1043,27 +1086,58 @@ static HANDLE_FUNC (handle_reversepath)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UPSTREAM_SUPPORT
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
|
||||||
|
static enum proxy_type pt_from_string(const char *s)
|
||||||
|
{
|
||||||
|
static const char pt_map[][7] = {
|
||||||
|
[PT_NONE] = "none",
|
||||||
|
[PT_HTTP] = "http",
|
||||||
|
[PT_SOCKS4] = "socks4",
|
||||||
|
[PT_SOCKS5] = "socks5",
|
||||||
|
};
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; i < sizeof(pt_map)/sizeof(pt_map[0]); i++)
|
||||||
|
if (!strcmp(pt_map[i], s))
|
||||||
|
return i;
|
||||||
|
return PT_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_upstream)
|
static HANDLE_FUNC (handle_upstream)
|
||||||
{
|
{
|
||||||
char *ip;
|
char *ip;
|
||||||
int port;
|
int port, mi = 2;
|
||||||
char *domain;
|
char *domain = 0, *user = 0, *pass = 0, *tmp;
|
||||||
|
enum proxy_type pt;
|
||||||
|
|
||||||
ip = get_string_arg (line, &match[2]);
|
tmp = get_string_arg (line, &match[mi]);
|
||||||
|
pt = pt_from_string(tmp);
|
||||||
|
safefree(tmp);
|
||||||
|
mi += 2;
|
||||||
|
|
||||||
|
if (match[mi].rm_so != -1)
|
||||||
|
user = get_string_arg (line, &match[mi]);
|
||||||
|
mi++;
|
||||||
|
|
||||||
|
if (match[mi].rm_so != -1)
|
||||||
|
pass = get_string_arg (line, &match[mi]);
|
||||||
|
mi++;
|
||||||
|
|
||||||
|
ip = get_string_arg (line, &match[mi]);
|
||||||
if (!ip)
|
if (!ip)
|
||||||
return -1;
|
return -1;
|
||||||
port = (int) get_long_arg (line, &match[7]);
|
mi += 5;
|
||||||
|
|
||||||
if (match[10].rm_so != -1) {
|
port = (int) get_long_arg (line, &match[mi]);
|
||||||
domain = get_string_arg (line, &match[10]);
|
mi += 3;
|
||||||
if (domain) {
|
|
||||||
upstream_add (ip, port, domain, &conf->upstream_list);
|
if (match[mi].rm_so != -1)
|
||||||
|
domain = get_string_arg (line, &match[mi]);
|
||||||
|
|
||||||
|
upstream_add (ip, port, domain, user, pass, pt, &conf->upstream_list);
|
||||||
|
|
||||||
|
safefree (user);
|
||||||
|
safefree (pass);
|
||||||
safefree (domain);
|
safefree (domain);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
upstream_add (ip, port, NULL, &conf->upstream_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (ip);
|
safefree (ip);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1073,11 +1147,11 @@ static HANDLE_FUNC (handle_upstream_no)
|
|||||||
{
|
{
|
||||||
char *domain;
|
char *domain;
|
||||||
|
|
||||||
domain = get_string_arg (line, &match[2]);
|
domain = get_string_arg (line, &match[3]);
|
||||||
if (!domain)
|
if (!domain)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
upstream_add (NULL, 0, domain, &conf->upstream_list);
|
upstream_add (NULL, 0, domain, 0, 0, PT_NONE, &conf->upstream_list);
|
||||||
safefree (domain);
|
safefree (domain);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+2
-1
@@ -37,6 +37,7 @@ typedef struct {
|
|||||||
* Hold all the configuration time information.
|
* Hold all the configuration time information.
|
||||||
*/
|
*/
|
||||||
struct config_s {
|
struct config_s {
|
||||||
|
vector_t basicauth_list;
|
||||||
char *logf_name;
|
char *logf_name;
|
||||||
char *config_file;
|
char *config_file;
|
||||||
unsigned int syslog; /* boolean */
|
unsigned int syslog; /* boolean */
|
||||||
@@ -46,7 +47,7 @@ struct config_s {
|
|||||||
unsigned int quit; /* boolean */
|
unsigned int quit; /* boolean */
|
||||||
char *user;
|
char *user;
|
||||||
char *group;
|
char *group;
|
||||||
char *ipAddr;
|
vector_t listen_addrs;
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
char *filter;
|
char *filter;
|
||||||
unsigned int filter_url; /* boolean */
|
unsigned int filter_url; /* boolean */
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ void add_connect_port_allowed (int port, vector_t *connect_ports)
|
|||||||
|
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"Adding Port [%d] to the list allowed by CONNECT", port);
|
"Adding Port [%d] to the list allowed by CONNECT", port);
|
||||||
vector_append (*connect_ports, (void **) &port, sizeof (port));
|
vector_append (*connect_ports, &port, sizeof (port));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+33
-11
@@ -50,6 +50,7 @@ struct hashbucket_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct hashmap_s {
|
struct hashmap_s {
|
||||||
|
uint32_t seed;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
hashmap_iter end_iterator;
|
hashmap_iter end_iterator;
|
||||||
|
|
||||||
@@ -63,9 +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 hashfunc (const char *key, unsigned int size)
|
static int hashfunc (const char *key, unsigned int size, uint32_t seed)
|
||||||
{
|
{
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
|
|
||||||
@@ -74,12 +78,8 @@ static int 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 & 1) ? (1 << (sizeof (uint32_t) - 1)) : 0;
|
hash = ((hash << 5) + hash) ^ tolower (*key);
|
||||||
|
|
||||||
hash >>= 1;
|
|
||||||
|
|
||||||
hash += tolower (*key) + bit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep the hash within the table limits */
|
/* Keep the hash within the table limits */
|
||||||
@@ -104,6 +104,7 @@ hashmap_t hashmap_create (unsigned int nbuckets)
|
|||||||
if (!ptr)
|
if (!ptr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
ptr->seed = (uint32_t)rand();
|
||||||
ptr->size = nbuckets;
|
ptr->size = nbuckets;
|
||||||
ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets,
|
ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets,
|
||||||
sizeof (struct
|
sizeof (struct
|
||||||
@@ -201,7 +202,7 @@ hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
|
|||||||
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;
|
||||||
|
|
||||||
@@ -382,7 +383,7 @@ ssize_t 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;
|
||||||
|
|
||||||
@@ -416,7 +417,7 @@ ssize_t 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;
|
||||||
|
|
||||||
@@ -451,7 +452,7 @@ ssize_t hashmap_remove (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;
|
||||||
|
|
||||||
@@ -492,3 +493,24 @@ ssize_t hashmap_remove (hashmap_t map, const char *key)
|
|||||||
/* The key was not found, so return 0 */
|
/* The key was not found, so return 0 */
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look up the value for a variable.
|
||||||
|
*/
|
||||||
|
char *lookup_variable (hashmap_t map, const char *varname)
|
||||||
|
{
|
||||||
|
hashmap_iter result_iter;
|
||||||
|
char *key;
|
||||||
|
char *data;
|
||||||
|
|
||||||
|
result_iter = hashmap_find (map, varname);
|
||||||
|
|
||||||
|
if (hashmap_is_end (map, result_iter))
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
if (hashmap_return_entry (map, result_iter,
|
||||||
|
&key, (void **) &data) < 0)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
return (data);
|
||||||
|
}
|
||||||
@@ -117,4 +117,9 @@ extern ssize_t hashmap_search (hashmap_t map, const char *key);
|
|||||||
*/
|
*/
|
||||||
extern ssize_t hashmap_remove (hashmap_t map, const char *key);
|
extern ssize_t hashmap_remove (hashmap_t map, const char *key);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look up the value for a variable.
|
||||||
|
*/
|
||||||
|
extern char *lookup_variable (hashmap_t map, const char *varname);
|
||||||
|
|
||||||
#endif /* _HASHMAP_H */
|
#endif /* _HASHMAP_H */
|
||||||
+19
-28
@@ -62,7 +62,7 @@ static char *get_html_file (unsigned int errornum)
|
|||||||
hashmap_iter result_iter;
|
hashmap_iter result_iter;
|
||||||
char errornbuf[ERRORNUM_BUFSIZE];
|
char errornbuf[ERRORNUM_BUFSIZE];
|
||||||
char *key;
|
char *key;
|
||||||
static char *val;
|
char *val;
|
||||||
|
|
||||||
assert (errornum >= 100 && errornum < 1000);
|
assert (errornum >= 100 && errornum < 1000);
|
||||||
|
|
||||||
@@ -83,27 +83,6 @@ static char *get_html_file (unsigned int errornum)
|
|||||||
return (val);
|
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.
|
* Send an already-opened file to the client with variable substitution.
|
||||||
*/
|
*/
|
||||||
@@ -126,7 +105,7 @@ send_html_file (FILE *infile, struct conn_s *connptr)
|
|||||||
if (in_variable) {
|
if (in_variable) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
varval = (const char *)
|
varval = (const char *)
|
||||||
lookup_variable (connptr,
|
lookup_variable (connptr->error_variables,
|
||||||
varstart);
|
varstart);
|
||||||
if (!varval)
|
if (!varval)
|
||||||
varval = "(unknown)";
|
varval = "(unknown)";
|
||||||
@@ -153,6 +132,7 @@ send_html_file (FILE *infile, struct conn_s *connptr)
|
|||||||
} else
|
} else
|
||||||
in_variable = 0;
|
in_variable = 0;
|
||||||
|
|
||||||
|
/* FALL THROUGH */
|
||||||
default:
|
default:
|
||||||
if (!in_variable) {
|
if (!in_variable) {
|
||||||
r = write_message (connptr->client_fd,
|
r = write_message (connptr->client_fd,
|
||||||
@@ -177,13 +157,24 @@ send_html_file (FILE *infile, struct conn_s *connptr)
|
|||||||
|
|
||||||
int send_http_headers (struct conn_s *connptr, int code, const char *message)
|
int send_http_headers (struct conn_s *connptr, int code, const char *message)
|
||||||
{
|
{
|
||||||
const char *headers =
|
const char headers[] =
|
||||||
"HTTP/1.0 %d %s\r\n"
|
"HTTP/1.0 %d %s\r\n"
|
||||||
"Server: %s/%s\r\n"
|
"Server: %s/%s\r\n"
|
||||||
"Content-Type: text/html\r\n" "Connection: close\r\n" "\r\n";
|
"Content-Type: text/html\r\n"
|
||||||
|
"%s"
|
||||||
|
"Connection: close\r\n" "\r\n";
|
||||||
|
|
||||||
|
const char auth_str[] =
|
||||||
|
"Proxy-Authenticate: Basic realm=\""
|
||||||
|
PACKAGE_NAME "\"\r\n";
|
||||||
|
|
||||||
|
/* according to rfc7235, the 407 error must be accompanied by
|
||||||
|
a Proxy-Authenticate header field. */
|
||||||
|
const char *add = code == 407 ? auth_str : "";
|
||||||
|
|
||||||
return (write_message (connptr->client_fd, headers,
|
return (write_message (connptr->client_fd, headers,
|
||||||
code, message, PACKAGE, VERSION));
|
code, message, PACKAGE, VERSION,
|
||||||
|
add));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -212,7 +203,7 @@ int send_http_error_message (struct conn_s *connptr)
|
|||||||
|
|
||||||
error_file = get_html_file (connptr->error_number);
|
error_file = get_html_file (connptr->error_number);
|
||||||
if (!(infile = fopen (error_file, "r"))) {
|
if (!(infile = fopen (error_file, "r"))) {
|
||||||
char *detail = lookup_variable (connptr, "detail");
|
char *detail = lookup_variable (connptr->error_variables, "detail");
|
||||||
return (write_message (connptr->client_fd, fallback_error,
|
return (write_message (connptr->client_fd, fallback_error,
|
||||||
connptr->error_number,
|
connptr->error_number,
|
||||||
connptr->error_string,
|
connptr->error_string,
|
||||||
@@ -280,7 +271,7 @@ int add_standard_vars (struct conn_s *connptr)
|
|||||||
add_error_variable (connptr, "date", timebuf);
|
add_error_variable (connptr, "date", timebuf);
|
||||||
|
|
||||||
add_error_variable (connptr, "website",
|
add_error_variable (connptr, "website",
|
||||||
"https://banu.com/tinyproxy/");
|
"https://tinyproxy.github.io/");
|
||||||
add_error_variable (connptr, "version", VERSION);
|
add_error_variable (connptr, "version", VERSION);
|
||||||
add_error_variable (connptr, "package", PACKAGE);
|
add_error_variable (connptr, "package", PACKAGE);
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,14 @@ static unsigned int logging_initialized = FALSE; /* boolean */
|
|||||||
*/
|
*/
|
||||||
int open_log_file (const char *log_file_name)
|
int open_log_file (const char *log_file_name)
|
||||||
{
|
{
|
||||||
|
if (log_file_name == NULL) {
|
||||||
|
if(config.godaemon == FALSE)
|
||||||
|
log_file_fd = fileno(stdout);
|
||||||
|
else
|
||||||
|
log_file_fd = -1;
|
||||||
|
} else {
|
||||||
log_file_fd = create_file_safely (log_file_name, FALSE);
|
log_file_fd = create_file_safely (log_file_name, FALSE);
|
||||||
|
}
|
||||||
return log_file_fd;
|
return log_file_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +86,7 @@ int open_log_file (const char *log_file_name)
|
|||||||
*/
|
*/
|
||||||
void close_log_file (void)
|
void close_log_file (void)
|
||||||
{
|
{
|
||||||
if (log_file_fd < 0) {
|
if (log_file_fd < 0 || log_file_fd == fileno(stdout)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +161,9 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!config.syslog && log_file_fd == -1)
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (config.syslog) {
|
if (config.syslog) {
|
||||||
#ifdef HAVE_VSYSLOG_H
|
#ifdef HAVE_VSYSLOG_H
|
||||||
vsyslog (level, fmt, args);
|
vsyslog (level, fmt, args);
|
||||||
@@ -188,8 +198,13 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
|
|
||||||
ret = write (log_file_fd, str, strlen (str));
|
ret = write (log_file_fd, str, strlen (str));
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
log_message (LOG_WARNING,
|
config.syslog = TRUE;
|
||||||
"Could not write to log file");
|
|
||||||
|
log_message(LOG_CRIT, "ERROR: Could not write to log "
|
||||||
|
"file %s: %s.",
|
||||||
|
config.logf_name, strerror(errno));
|
||||||
|
log_message(LOG_CRIT,
|
||||||
|
"Falling back to syslog logging");
|
||||||
}
|
}
|
||||||
|
|
||||||
fsync (log_file_fd);
|
fsync (log_file_fd);
|
||||||
@@ -202,7 +217,7 @@ out:
|
|||||||
/*
|
/*
|
||||||
* This needs to send any stored log messages.
|
* This needs to send any stored log messages.
|
||||||
*/
|
*/
|
||||||
void send_stored_logs (void)
|
static void send_stored_logs (void)
|
||||||
{
|
{
|
||||||
char *string;
|
char *string;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
@@ -258,10 +273,10 @@ int setup_logging (void)
|
|||||||
config.syslog = TRUE;
|
config.syslog = TRUE;
|
||||||
|
|
||||||
log_message (LOG_CRIT, "ERROR: Could not create log "
|
log_message (LOG_CRIT, "ERROR: Could not create log "
|
||||||
"file %s: %s.\n",
|
"file %s: %s.",
|
||||||
config.logf_name, strerror (errno));
|
config.logf_name, strerror (errno));
|
||||||
log_message (LOG_CRIT,
|
log_message (LOG_CRIT,
|
||||||
"Falling back to syslog logging\n");
|
"Falling back to syslog logging.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,16 +77,7 @@
|
|||||||
* don't advocate this, but it could be useful at times.)
|
* don't advocate this, but it could be useful at times.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
#include <syslog.h>
|
||||||
# include <syslog.h>
|
|
||||||
#else
|
|
||||||
# define LOG_CRIT 2
|
|
||||||
# define LOG_ERR 3
|
|
||||||
# define LOG_WARNING 4
|
|
||||||
# define LOG_NOTICE 5
|
|
||||||
# define LOG_INFO 6
|
|
||||||
# define LOG_DEBUG 7
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define LOG_CONN 8 /* extra to log connections without the INFO stuff */
|
#define LOG_CONN 8 /* extra to log connections without the INFO stuff */
|
||||||
|
|
||||||
@@ -115,7 +106,6 @@ extern void close_log_file (void);
|
|||||||
|
|
||||||
extern void log_message (int level, const char *fmt, ...);
|
extern void 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 int setup_logging (void);
|
extern int setup_logging (void);
|
||||||
extern void shutdown_logging (void);
|
extern void shutdown_logging (void);
|
||||||
|
|||||||
+33
-54
@@ -86,37 +86,6 @@ display_version (void)
|
|||||||
printf ("%s %s\n", PACKAGE, VERSION);
|
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.
|
* Display usage to the user.
|
||||||
*/
|
*/
|
||||||
@@ -131,7 +100,6 @@ display_usage (void)
|
|||||||
" -d Do not daemonize (run in foreground).\n"
|
" -d Do not daemonize (run in foreground).\n"
|
||||||
" -c FILE Use an alternate configuration file.\n"
|
" -c FILE Use an alternate configuration file.\n"
|
||||||
" -h Display this usage information.\n"
|
" -h Display this usage information.\n"
|
||||||
" -l Display the license.\n"
|
|
||||||
" -v Display version information.\n");
|
" -v Display version information.\n");
|
||||||
|
|
||||||
/* Display the modes compiled into tinyproxy */
|
/* Display the modes compiled into tinyproxy */
|
||||||
@@ -171,8 +139,8 @@ display_usage (void)
|
|||||||
printf (" None\n");
|
printf (" None\n");
|
||||||
|
|
||||||
printf ("\n"
|
printf ("\n"
|
||||||
"For bug reporting instructions, please see:\n"
|
"For support and bug reporting instructions, please visit\n"
|
||||||
"<https://banu.com/tinyproxy/>.\n");
|
"<https://tinyproxy.github.io/>.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -205,16 +173,12 @@ process_cmdline (int argc, char **argv, struct config_s *conf)
|
|||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while ((opt = getopt (argc, argv, "c:vldh")) != EOF) {
|
while ((opt = getopt (argc, argv, "c:vdh")) != EOF) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'v':
|
case 'v':
|
||||||
display_version ();
|
display_version ();
|
||||||
exit (EX_OK);
|
exit (EX_OK);
|
||||||
|
|
||||||
case 'l':
|
|
||||||
display_license ();
|
|
||||||
exit (EX_OK);
|
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
conf->godaemon = FALSE;
|
conf->godaemon = FALSE;
|
||||||
break;
|
break;
|
||||||
@@ -277,6 +241,16 @@ change_user (const char *program)
|
|||||||
exit (EX_NOPERM);
|
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\".",
|
log_message (LOG_INFO, "Now running as group \"%s\".",
|
||||||
config.group);
|
config.group);
|
||||||
}
|
}
|
||||||
@@ -326,8 +300,8 @@ static void initialize_config_defaults (struct config_s *conf)
|
|||||||
conf->errorpages = NULL;
|
conf->errorpages = NULL;
|
||||||
conf->stathost = safestrdup (TINYPROXY_STATHOST);
|
conf->stathost = safestrdup (TINYPROXY_STATHOST);
|
||||||
conf->idletimeout = MAX_IDLE_TIME;
|
conf->idletimeout = MAX_IDLE_TIME;
|
||||||
conf->logf_name = safestrdup (LOCALSTATEDIR "/log/tinyproxy/tinyproxy.log");
|
conf->logf_name = NULL;
|
||||||
conf->pidpath = safestrdup (LOCALSTATEDIR "/run/tinyproxy/tinyproxy.pid");
|
conf->pidpath = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,8 +360,13 @@ main (int argc, char **argv)
|
|||||||
anonymous_insert ("Content-Type");
|
anonymous_insert ("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.godaemon == TRUE)
|
if (config.godaemon == TRUE) {
|
||||||
|
if (!config.syslog && config.logf_name == NULL)
|
||||||
|
fprintf(stderr, "WARNING: logging deactivated "
|
||||||
|
"(can't log to stdout when daemonized)\n");
|
||||||
|
|
||||||
makedaemon ();
|
makedaemon ();
|
||||||
|
}
|
||||||
|
|
||||||
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
|
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||||
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
|
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
|
||||||
@@ -401,12 +380,21 @@ main (int argc, char **argv)
|
|||||||
#endif /* FILTER_ENABLE */
|
#endif /* FILTER_ENABLE */
|
||||||
|
|
||||||
/* Start listening on the selected port. */
|
/* Start listening on the selected port. */
|
||||||
if (child_listening_sock (config.port) < 0) {
|
if (child_listening_sockets(config.listen_addrs, config.port) < 0) {
|
||||||
fprintf (stderr, "%s: Could not create listening socket.\n",
|
fprintf (stderr, "%s: Could not create listening sockets.\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
exit (EX_OSERR);
|
exit (EX_OSERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create pid file before we drop privileges */
|
||||||
|
if (config.pidpath) {
|
||||||
|
if (pidfile_create (config.pidpath) < 0) {
|
||||||
|
fprintf (stderr, "%s: Could not create PID file.\n",
|
||||||
|
argv[0]);
|
||||||
|
exit (EX_OSERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Switch to a different user if we're running as root */
|
/* Switch to a different user if we're running as root */
|
||||||
if (geteuid () == 0)
|
if (geteuid () == 0)
|
||||||
change_user (argv[0]);
|
change_user (argv[0]);
|
||||||
@@ -419,15 +407,6 @@ main (int argc, char **argv)
|
|||||||
exit (EX_SOFTWARE);
|
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) {
|
if (child_pool_create () < 0) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"%s: Could not create the pool of children.\n",
|
"%s: Could not create the pool of children.\n",
|
||||||
@@ -467,7 +446,7 @@ main (int argc, char **argv)
|
|||||||
child_close_sock ();
|
child_close_sock ();
|
||||||
|
|
||||||
/* Remove the PID file */
|
/* Remove the PID file */
|
||||||
if (unlink (config.pidpath) < 0) {
|
if (config.pidpath != NULL && unlink (config.pidpath) < 0) {
|
||||||
log_message (LOG_WARNING,
|
log_message (LOG_WARNING,
|
||||||
"Could not remove PID file \"%s\": %s.",
|
"Could not remove PID file \"%s\": %s.",
|
||||||
config.pidpath, strerror (errno));
|
config.pidpath, strerror (errno));
|
||||||
|
|||||||
+16
-7
@@ -32,10 +32,11 @@
|
|||||||
* 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 safe_write (int fd, const char *buffer, size_t count)
|
ssize_t safe_write (int fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
size_t bytestosend;
|
size_t bytestosend;
|
||||||
|
const char *buffer = buf;
|
||||||
|
|
||||||
assert (fd >= 0);
|
assert (fd >= 0);
|
||||||
assert (buffer != NULL);
|
assert (buffer != NULL);
|
||||||
@@ -67,7 +68,7 @@ ssize_t safe_write (int fd, const char *buffer, size_t count)
|
|||||||
* Matched pair for safe_write(). If an EINTR occurs, pick up and try
|
* Matched pair for safe_write(). If an EINTR occurs, pick up and try
|
||||||
* again.
|
* again.
|
||||||
*/
|
*/
|
||||||
ssize_t safe_read (int fd, char *buffer, size_t count)
|
ssize_t safe_read (int fd, void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
@@ -191,7 +192,11 @@ ssize_t readline (int fd, char **whole_buffer)
|
|||||||
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) {
|
||||||
@@ -245,8 +250,10 @@ CLEANUP:
|
|||||||
* Convert the network address into either a dotted-decimal or an IPv6
|
* Convert the network address into either a dotted-decimal or an IPv6
|
||||||
* hex string.
|
* hex string.
|
||||||
*/
|
*/
|
||||||
char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
|
const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
|
const char *result;
|
||||||
|
|
||||||
assert (sa != NULL);
|
assert (sa != NULL);
|
||||||
assert (buf != NULL);
|
assert (buf != NULL);
|
||||||
assert (buflen != 0);
|
assert (buflen != 0);
|
||||||
@@ -257,7 +264,8 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
|
|||||||
{
|
{
|
||||||
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
|
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
|
||||||
|
|
||||||
inet_ntop (AF_INET, &sa_in->sin_addr, buf, buflen);
|
result = inet_ntop (AF_INET, &sa_in->sin_addr, buf,
|
||||||
|
buflen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
@@ -265,7 +273,8 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
|
|||||||
struct sockaddr_in6 *sa_in6 =
|
struct sockaddr_in6 *sa_in6 =
|
||||||
(struct sockaddr_in6 *) sa;
|
(struct sockaddr_in6 *) sa;
|
||||||
|
|
||||||
inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, buflen);
|
result = inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf,
|
||||||
|
buflen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -273,7 +282,7 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+3
-3
@@ -21,13 +21,13 @@
|
|||||||
#ifndef TINYPROXY_NETWORK_H
|
#ifndef TINYPROXY_NETWORK_H
|
||||||
#define TINYPROXY_NETWORK_H
|
#define TINYPROXY_NETWORK_H
|
||||||
|
|
||||||
extern ssize_t safe_write (int fd, const char *buffer, size_t count);
|
extern ssize_t safe_write (int fd, const void *buf, size_t count);
|
||||||
extern ssize_t safe_read (int fd, char *buffer, size_t count);
|
extern ssize_t safe_read (int fd, void *buf, size_t count);
|
||||||
|
|
||||||
extern int write_message (int fd, const char *fmt, ...);
|
extern 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 const char *get_ip_string (struct sockaddr *sa, char *buf, size_t len);
|
||||||
extern int full_inet_pton (const char *ip, void *dst);
|
extern int full_inet_pton (const char *ip, void *dst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+259
-61
@@ -48,6 +48,7 @@
|
|||||||
#include "upstream.h"
|
#include "upstream.h"
|
||||||
#include "connect-ports.h"
|
#include "connect-ports.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
#include "basicauth.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Maximum length of a HTTP line
|
* Maximum length of a HTTP line
|
||||||
@@ -61,9 +62,11 @@
|
|||||||
#ifdef UPSTREAM_SUPPORT
|
#ifdef UPSTREAM_SUPPORT
|
||||||
# define UPSTREAM_CONFIGURED() (config.upstream_list != NULL)
|
# define UPSTREAM_CONFIGURED() (config.upstream_list != NULL)
|
||||||
# define UPSTREAM_HOST(host) upstream_get(host, config.upstream_list)
|
# define UPSTREAM_HOST(host) upstream_get(host, config.upstream_list)
|
||||||
|
# define UPSTREAM_IS_HTTP(conn) (conn->upstream_proxy != NULL && conn->upstream_proxy->type == PT_HTTP)
|
||||||
#else
|
#else
|
||||||
# define UPSTREAM_CONFIGURED() (0)
|
# define UPSTREAM_CONFIGURED() (0)
|
||||||
# define UPSTREAM_HOST(host) (NULL)
|
# define UPSTREAM_HOST(host) (NULL)
|
||||||
|
# define UPSTREAM_IS_HTTP(up) (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -186,18 +189,22 @@ static int strip_return_port (char *host)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pull the information out of the URL line. This will handle both HTTP
|
* Pull the information out of the URL line.
|
||||||
* and FTP (proxied) URLs.
|
* This expects urls with the initial '<proto>://'
|
||||||
|
* part stripped and hence can handle http urls,
|
||||||
|
* (proxied) ftp:// urls and https-requests that
|
||||||
|
* come in without the proto:// part via CONNECT.
|
||||||
*/
|
*/
|
||||||
static int extract_http_url (const char *url, struct request_s *request)
|
static int extract_url (const char *url, int default_port,
|
||||||
|
struct request_s *request)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
int len;
|
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
/* Split the URL on the slash to separate host from path */
|
/* Split the URL on the slash to separate host from path */
|
||||||
p = strchr (url, '/');
|
p = strchr (url, '/');
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
|
int len;
|
||||||
len = p - url;
|
len = p - url;
|
||||||
request->host = (char *) safemalloc (len + 1);
|
request->host = (char *) safemalloc (len + 1);
|
||||||
memcpy (request->host, url, len);
|
memcpy (request->host, url, len);
|
||||||
@@ -216,12 +223,15 @@ static int extract_http_url (const char *url, struct request_s *request)
|
|||||||
|
|
||||||
/* Find a proper port in www.site.com:8001 URLs */
|
/* Find a proper port in www.site.com:8001 URLs */
|
||||||
port = strip_return_port (request->host);
|
port = strip_return_port (request->host);
|
||||||
request->port = (port != 0) ? port : HTTP_PORT;
|
request->port = (port != 0) ? port : default_port;
|
||||||
|
|
||||||
/* Remove any surrounding '[' and ']' from IPv6 literals */
|
/* Remove any surrounding '[' and ']' from IPv6 literals */
|
||||||
p = strrchr (request->host, ']');
|
p = strrchr (request->host, ']');
|
||||||
if (p && (*(request->host) == '[')) {
|
if (p && (*(request->host) == '[')) {
|
||||||
request->host++;
|
memmove(request->host, request->host + 1,
|
||||||
|
strlen(request->host) - 2);
|
||||||
|
*p = '\0';
|
||||||
|
p--;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,31 +246,6 @@ ERROR_EXIT:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Extract the URL from a SSL connection.
|
|
||||||
*/
|
|
||||||
static int extract_ssl_url (const char *url, struct request_s *request)
|
|
||||||
{
|
|
||||||
request->host = (char *) safemalloc (strlen (url) + 1);
|
|
||||||
if (!request->host)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (sscanf (url, "%[^:]:%hu", request->host, &request->port) == 2) ;
|
|
||||||
else if (sscanf (url, "%s", request->host) == 1)
|
|
||||||
request->port = HTTP_PORT_SSL;
|
|
||||||
else {
|
|
||||||
log_message (LOG_ERR, "extract_ssl_url: Can't parse URL.");
|
|
||||||
|
|
||||||
safefree (request->host);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove the username/password if they're present */
|
|
||||||
strip_username_password (request->host);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a connection for HTTP connections.
|
* Create a connection for HTTP connections.
|
||||||
*/
|
*/
|
||||||
@@ -285,6 +270,17 @@ establish_http_connection (struct conn_s *connptr, struct request_s *request)
|
|||||||
"Connection: close\r\n",
|
"Connection: close\r\n",
|
||||||
request->method, request->path,
|
request->method, request->path,
|
||||||
request->host, portbuff);
|
request->host, portbuff);
|
||||||
|
} else if (connptr->upstream_proxy &&
|
||||||
|
connptr->upstream_proxy->type == PT_HTTP &&
|
||||||
|
connptr->upstream_proxy->ua.authstr) {
|
||||||
|
return write_message (connptr->server_fd,
|
||||||
|
"%s %s HTTP/1.0\r\n"
|
||||||
|
"Host: %s%s\r\n"
|
||||||
|
"Connection: close\r\n"
|
||||||
|
"Proxy-Authorization: Basic %s\r\n",
|
||||||
|
request->method, request->path,
|
||||||
|
request->host, portbuff,
|
||||||
|
connptr->upstream_proxy->ua.authstr);
|
||||||
} else {
|
} else {
|
||||||
return write_message (connptr->server_fd,
|
return write_message (connptr->server_fd,
|
||||||
"%s %s HTTP/1.0\r\n"
|
"%s %s HTTP/1.0\r\n"
|
||||||
@@ -375,15 +371,6 @@ BAD_REQUEST_ERROR:
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!url) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"process_request: Null URL on file descriptor %d",
|
|
||||||
connptr->client_fd);
|
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
|
||||||
"detail", "Request has an empty URL",
|
|
||||||
"url", url, NULL);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
#ifdef REVERSE_SUPPORT
|
#ifdef REVERSE_SUPPORT
|
||||||
if (config.reversepath_list != NULL) {
|
if (config.reversepath_list != NULL) {
|
||||||
/*
|
/*
|
||||||
@@ -396,12 +383,18 @@ BAD_REQUEST_ERROR:
|
|||||||
|
|
||||||
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
|
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
|
||||||
|
|
||||||
if (!reverse_url) {
|
if (reverse_url != NULL) {
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (url);
|
safefree (url);
|
||||||
url = reverse_url;
|
url = reverse_url;
|
||||||
|
} else if (config.reverseonly) {
|
||||||
|
log_message (LOG_ERR,
|
||||||
|
"Bad request, no mapping for '%s' found",
|
||||||
|
url);
|
||||||
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
|
"detail", "No mapping found for "
|
||||||
|
"requested url", "url", url, NULL);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -410,14 +403,14 @@ BAD_REQUEST_ERROR:
|
|||||||
{
|
{
|
||||||
char *skipped_type = strstr (url, "//") + 2;
|
char *skipped_type = strstr (url, "//") + 2;
|
||||||
|
|
||||||
if (extract_http_url (skipped_type, request) < 0) {
|
if (extract_url (skipped_type, HTTP_PORT, request) < 0) {
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
"detail", "Could not parse URL",
|
"detail", "Could not parse URL",
|
||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
} else if (strcmp (request->method, "CONNECT") == 0) {
|
} else if (strcmp (request->method, "CONNECT") == 0) {
|
||||||
if (extract_ssl_url (url, request) < 0) {
|
if (extract_url (url, HTTP_PORT_SSL, request) < 0) {
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
"detail", "Could not parse URL",
|
"detail", "Could not parse URL",
|
||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
@@ -518,6 +511,7 @@ static int pull_client_data (struct conn_s *connptr, long int length)
|
|||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
int ret;
|
||||||
|
|
||||||
buffer =
|
buffer =
|
||||||
(char *) safemalloc (min (MAXBUFFSIZE, (unsigned long int) length));
|
(char *) safemalloc (min (MAXBUFFSIZE, (unsigned long int) length));
|
||||||
@@ -543,18 +537,30 @@ static int pull_client_data (struct conn_s *connptr, long int length)
|
|||||||
* return and line feed) at the end of a POST message. These
|
* return and line feed) at the end of a POST message. These
|
||||||
* need to be eaten for tinyproxy to work correctly.
|
* need to be eaten for tinyproxy to work correctly.
|
||||||
*/
|
*/
|
||||||
socket_nonblocking (connptr->client_fd);
|
ret = socket_nonblocking (connptr->client_fd);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "Failed to set the client socket "
|
||||||
|
"to non-blocking: %s", strerror(errno));
|
||||||
|
goto ERROR_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
len = recv (connptr->client_fd, buffer, 2, MSG_PEEK);
|
len = recv (connptr->client_fd, buffer, 2, MSG_PEEK);
|
||||||
socket_blocking (connptr->client_fd);
|
|
||||||
|
ret = socket_blocking (connptr->client_fd);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "Failed to set the client socket "
|
||||||
|
"to blocking: %s", strerror(errno));
|
||||||
|
goto ERROR_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
if (len < 0 && errno != EAGAIN)
|
if (len < 0 && errno != EAGAIN)
|
||||||
goto ERROR_EXIT;
|
goto ERROR_EXIT;
|
||||||
|
|
||||||
if ((len == 2) && CHECK_CRLF (buffer, len)) {
|
if ((len == 2) && CHECK_CRLF (buffer, len)) {
|
||||||
ssize_t ret;
|
ssize_t bytes_read;
|
||||||
|
|
||||||
ret = read (connptr->client_fd, buffer, 2);
|
bytes_read = read (connptr->client_fd, buffer, 2);
|
||||||
if (ret == -1) {
|
if (bytes_read == -1) {
|
||||||
log_message
|
log_message
|
||||||
(LOG_WARNING,
|
(LOG_WARNING,
|
||||||
"Could not read two bytes from POST message");
|
"Could not read two bytes from POST message");
|
||||||
@@ -610,6 +616,13 @@ add_header_to_connection (hashmap_t hashofheaders, char *header, size_t len)
|
|||||||
return hashmap_insert (hashofheaders, header, sep, len);
|
return hashmap_insert (hashofheaders, header, sep, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define maximum number of headers that we accept.
|
||||||
|
* This should be big enough to handle legitimate cases,
|
||||||
|
* but limited to avoid DoS.
|
||||||
|
*/
|
||||||
|
#define MAX_HEADERS 10000
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read all the headers from the stream
|
* Read all the headers from the stream
|
||||||
*/
|
*/
|
||||||
@@ -617,6 +630,7 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
|
|||||||
{
|
{
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
char *header = NULL;
|
char *header = NULL;
|
||||||
|
int count;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
ssize_t linelen;
|
ssize_t linelen;
|
||||||
ssize_t len = 0;
|
ssize_t len = 0;
|
||||||
@@ -625,7 +639,7 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
|
|||||||
assert (fd >= 0);
|
assert (fd >= 0);
|
||||||
assert (hashofheaders != NULL);
|
assert (hashofheaders != NULL);
|
||||||
|
|
||||||
for (;;) {
|
for (count = 0; count < MAX_HEADERS; count++) {
|
||||||
if ((linelen = readline (fd, &line)) <= 0) {
|
if ((linelen = readline (fd, &line)) <= 0) {
|
||||||
safefree (header);
|
safefree (header);
|
||||||
safefree (line);
|
safefree (line);
|
||||||
@@ -691,6 +705,14 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
|
|||||||
|
|
||||||
safefree (line);
|
safefree (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we get here, this means we reached MAX_HEADERS count.
|
||||||
|
* Bail out with error.
|
||||||
|
*/
|
||||||
|
safefree (header);
|
||||||
|
safefree (line);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -817,7 +839,7 @@ done:
|
|||||||
/*
|
/*
|
||||||
* Number of buckets to use internally in the hashmap.
|
* Number of buckets to use internally in the hashmap.
|
||||||
*/
|
*/
|
||||||
#define HEADER_BUCKETS 32
|
#define HEADER_BUCKETS 256
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here we loop through all the headers the client is sending. If we
|
* Here we loop through all the headers the client is sending. If we
|
||||||
@@ -845,10 +867,10 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
|
|||||||
/*
|
/*
|
||||||
* Don't send headers if there's already an error, if the request was
|
* Don't send headers if there's already an error, if the request was
|
||||||
* a stats request, or if this was a CONNECT method (unless upstream
|
* a stats request, or if this was a CONNECT method (unless upstream
|
||||||
* proxy is in use.)
|
* http proxy is in use.)
|
||||||
*/
|
*/
|
||||||
if (connptr->server_fd == -1 || connptr->show_stats
|
if (connptr->server_fd == -1 || connptr->show_stats
|
||||||
|| (connptr->connect_method && (connptr->upstream_proxy == NULL))) {
|
|| (connptr->connect_method && ! UPSTREAM_IS_HTTP(connptr))) {
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"Not sending client headers to remote machine");
|
"Not sending client headers to remote machine");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1137,8 +1159,19 @@ static void relay_connection (struct conn_s *connptr)
|
|||||||
int maxfd = max (connptr->client_fd, connptr->server_fd) + 1;
|
int maxfd = max (connptr->client_fd, connptr->server_fd) + 1;
|
||||||
ssize_t bytes_received;
|
ssize_t bytes_received;
|
||||||
|
|
||||||
socket_nonblocking (connptr->client_fd);
|
ret = socket_nonblocking (connptr->client_fd);
|
||||||
socket_nonblocking (connptr->server_fd);
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "Failed to set the client socket "
|
||||||
|
"to non-blocking: %s", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = socket_nonblocking (connptr->server_fd);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "Failed to set the server socket "
|
||||||
|
"to non-blocking: %s", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
last_access = time (NULL);
|
last_access = time (NULL);
|
||||||
|
|
||||||
@@ -1213,7 +1246,14 @@ static void relay_connection (struct conn_s *connptr)
|
|||||||
* Here the server has closed the connection... write the
|
* Here the server has closed the connection... write the
|
||||||
* remainder to the client and then exit.
|
* remainder to the client and then exit.
|
||||||
*/
|
*/
|
||||||
socket_blocking (connptr->client_fd);
|
ret = socket_blocking (connptr->client_fd);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR,
|
||||||
|
"Failed to set client socket to blocking: %s",
|
||||||
|
strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (buffer_size (connptr->sbuffer) > 0) {
|
while (buffer_size (connptr->sbuffer) > 0) {
|
||||||
if (write_buffer (connptr->client_fd, connptr->sbuffer) < 0)
|
if (write_buffer (connptr->client_fd, connptr->sbuffer) < 0)
|
||||||
break;
|
break;
|
||||||
@@ -1223,7 +1263,14 @@ static void relay_connection (struct conn_s *connptr)
|
|||||||
/*
|
/*
|
||||||
* Try to send any remaining data to the server if we can.
|
* Try to send any remaining data to the server if we can.
|
||||||
*/
|
*/
|
||||||
socket_blocking (connptr->server_fd);
|
ret = socket_blocking (connptr->server_fd);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR,
|
||||||
|
"Failed to set server socket to blocking: %s",
|
||||||
|
strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (buffer_size (connptr->cbuffer) > 0) {
|
while (buffer_size (connptr->cbuffer) > 0) {
|
||||||
if (write_buffer (connptr->server_fd, connptr->cbuffer) < 0)
|
if (write_buffer (connptr->server_fd, connptr->cbuffer) < 0)
|
||||||
break;
|
break;
|
||||||
@@ -1232,6 +1279,122 @@ static void relay_connection (struct conn_s *connptr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
|
||||||
|
{
|
||||||
|
unsigned len;
|
||||||
|
unsigned char buff[512]; /* won't use more than 7 + 255 */
|
||||||
|
unsigned short port;
|
||||||
|
size_t ulen, passlen;
|
||||||
|
|
||||||
|
struct hostent *host;
|
||||||
|
struct upstream *cur_upstream = connptr->upstream_proxy;
|
||||||
|
|
||||||
|
ulen = cur_upstream->ua.user ? strlen(cur_upstream->ua.user) : 0;
|
||||||
|
passlen = cur_upstream->pass ? strlen(cur_upstream->pass) : 0;
|
||||||
|
|
||||||
|
|
||||||
|
log_message(LOG_CONN,
|
||||||
|
"Established connection to %s proxy \"%s\" using file descriptor %d.",
|
||||||
|
proxy_type_name(cur_upstream->type), cur_upstream->host, connptr->server_fd);
|
||||||
|
|
||||||
|
if (cur_upstream->type == PT_SOCKS4) {
|
||||||
|
|
||||||
|
buff[0] = 4; /* socks version */
|
||||||
|
buff[1] = 1; /* connect command */
|
||||||
|
port = htons(request->port);
|
||||||
|
memcpy(&buff[2], &port, 2); /* dest port */
|
||||||
|
host = gethostbyname(request->host);
|
||||||
|
memcpy(&buff[4], host->h_addr_list[0], 4); /* dest ip */
|
||||||
|
buff[8] = 0; /* user */
|
||||||
|
if (9 != safe_write(connptr->server_fd, buff, 9))
|
||||||
|
return -1;
|
||||||
|
if (8 != safe_read(connptr->server_fd, buff, 8))
|
||||||
|
return -1;
|
||||||
|
if (buff[0]!=0 || buff[1]!=90)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
} else if (cur_upstream->type == PT_SOCKS5) {
|
||||||
|
|
||||||
|
/* init */
|
||||||
|
int n_methods = ulen ? 2 : 1;
|
||||||
|
buff[0] = 5; /* socks version */
|
||||||
|
buff[1] = n_methods; /* number of methods */
|
||||||
|
buff[2] = 0; /* no auth method */
|
||||||
|
if (ulen) buff[3] = 2; /* auth method -> username / password */
|
||||||
|
if (2+n_methods != safe_write(connptr->server_fd, buff, 2+n_methods))
|
||||||
|
return -1;
|
||||||
|
if (2 != safe_read(connptr->server_fd, buff, 2))
|
||||||
|
return -1;
|
||||||
|
if (buff[0] != 5 || (buff[1] != 0 && buff[1] != 2))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (buff[1] == 2) {
|
||||||
|
/* authentication */
|
||||||
|
char in[2];
|
||||||
|
char out[515];
|
||||||
|
char *cur = out;
|
||||||
|
size_t c;
|
||||||
|
*cur++ = 1; /* version */
|
||||||
|
c = ulen & 0xFF;
|
||||||
|
*cur++ = c;
|
||||||
|
memcpy(cur, cur_upstream->ua.user, c);
|
||||||
|
cur += c;
|
||||||
|
c = passlen & 0xFF;
|
||||||
|
*cur++ = c;
|
||||||
|
memcpy(cur, cur_upstream->pass, c);
|
||||||
|
cur += c;
|
||||||
|
|
||||||
|
if((cur - out) != safe_write(connptr->server_fd, out, cur - out))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if(2 != safe_read(connptr->server_fd, in, 2))
|
||||||
|
return -1;
|
||||||
|
if(in[1] != 0 || !(in[0] == 5 || in[0] == 1)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* connect */
|
||||||
|
buff[0] = 5; /* socks version */
|
||||||
|
buff[1] = 1; /* connect */
|
||||||
|
buff[2] = 0; /* reserved */
|
||||||
|
buff[3] = 3; /* domainname */
|
||||||
|
len=strlen(request->host);
|
||||||
|
if(len>255)
|
||||||
|
return -1;
|
||||||
|
buff[4] = len; /* length of domainname */
|
||||||
|
memcpy(&buff[5], request->host, len); /* dest ip */
|
||||||
|
port = htons(request->port);
|
||||||
|
memcpy(&buff[5+len], &port, 2); /* dest port */
|
||||||
|
if (7+len != safe_write(connptr->server_fd, buff, 7+len))
|
||||||
|
return -1;
|
||||||
|
if (4 != safe_read(connptr->server_fd, buff, 4))
|
||||||
|
return -1;
|
||||||
|
if (buff[0]!=5 || buff[1]!=0)
|
||||||
|
return -1;
|
||||||
|
switch(buff[3]) {
|
||||||
|
case 1: len=4; break; /* ip v4 */
|
||||||
|
case 4: len=16; break; /* ip v6 */
|
||||||
|
case 3: /* domainname */
|
||||||
|
if (1 != safe_read(connptr->server_fd, buff, 1))
|
||||||
|
return -1;
|
||||||
|
len = buff[0]; /* max = 255 */
|
||||||
|
break;
|
||||||
|
default: return -1;
|
||||||
|
}
|
||||||
|
if (2+len != safe_read(connptr->server_fd, buff, 2+len))
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connptr->connect_method)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return establish_http_connection(connptr, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Establish a connection to the upstream proxy server.
|
* Establish a connection to the upstream proxy server.
|
||||||
*/
|
*/
|
||||||
@@ -1275,6 +1438,9 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cur_upstream->type != PT_HTTP)
|
||||||
|
return connect_to_upstream_proxy(connptr, request);
|
||||||
|
|
||||||
log_message (LOG_CONN,
|
log_message (LOG_CONN,
|
||||||
"Established connection to upstream proxy \"%s\" "
|
"Established connection to upstream proxy \"%s\" "
|
||||||
"using file descriptor %d.",
|
"using file descriptor %d.",
|
||||||
@@ -1338,7 +1504,7 @@ get_request_entity(struct conn_s *connptr)
|
|||||||
nread = read_buffer (connptr->client_fd, connptr->cbuffer);
|
nread = read_buffer (connptr->client_fd, connptr->cbuffer);
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
log_message (LOG_ERR,
|
log_message (LOG_ERR,
|
||||||
"Error reading readble client_fd %d",
|
"Error reading readable client_fd %d",
|
||||||
connptr->client_fd);
|
connptr->client_fd);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
} else {
|
} else {
|
||||||
@@ -1442,6 +1608,38 @@ void handle_connection (int fd)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.basicauth_list != NULL) {
|
||||||
|
ssize_t len;
|
||||||
|
char *authstring;
|
||||||
|
int failure = 1;
|
||||||
|
len = hashmap_entry_by_key (hashofheaders, "proxy-authorization",
|
||||||
|
(void **) &authstring);
|
||||||
|
|
||||||
|
if (len == 0) {
|
||||||
|
update_stats (STAT_DENIED);
|
||||||
|
indicate_http_error (connptr, 407, "Proxy Authentication Required",
|
||||||
|
"detail",
|
||||||
|
"This proxy requires authentication.",
|
||||||
|
NULL);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if ( /* currently only "basic" auth supported */
|
||||||
|
(strncmp(authstring, "Basic ", 6) == 0 ||
|
||||||
|
strncmp(authstring, "basic ", 6) == 0) &&
|
||||||
|
basicauth_check (config.basicauth_list, authstring + 6) == 1)
|
||||||
|
failure = 0;
|
||||||
|
if(failure) {
|
||||||
|
update_stats (STAT_DENIED);
|
||||||
|
indicate_http_error (connptr, 401, "Unauthorized",
|
||||||
|
"detail",
|
||||||
|
"The administrator of this proxy has not configured "
|
||||||
|
"it to service requests from you.",
|
||||||
|
NULL);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
hashmap_remove (hashofheaders, "proxy-authorization");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add any user-specified headers (AddHeader directive) to the
|
* Add any user-specified headers (AddHeader directive) to the
|
||||||
* outgoing HTTP request.
|
* outgoing HTTP request.
|
||||||
@@ -1494,7 +1692,7 @@ void handle_connection (int fd)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(connptr->connect_method && (connptr->upstream_proxy == NULL))) {
|
if (!connptr->connect_method || UPSTREAM_IS_HTTP(connptr)) {
|
||||||
if (process_server_headers (connptr) < 0) {
|
if (process_server_headers (connptr) < 0) {
|
||||||
update_stats (STAT_BADCONN);
|
update_stats (STAT_BADCONN);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|||||||
+1
-7
@@ -156,13 +156,7 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Forward proxy support off and no reverse path match found */
|
if (rewrite_url == NULL) {
|
||||||
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+113
-39
@@ -84,6 +84,9 @@ int opensock (const char *host, int port, const char *bind_to)
|
|||||||
assert (host != NULL);
|
assert (host != NULL);
|
||||||
assert (port > 0);
|
assert (port > 0);
|
||||||
|
|
||||||
|
log_message(LOG_INFO,
|
||||||
|
"opensock: opening connection to %s:%d", host, port);
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (struct addrinfo));
|
memset (&hints, 0, sizeof (struct addrinfo));
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_UNSPEC;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
@@ -97,6 +100,9 @@ int opensock (const char *host, int port, const char *bind_to)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_message(LOG_INFO,
|
||||||
|
"opensock: getaddrinfo returned for %s:%d", host, port);
|
||||||
|
|
||||||
ressave = res;
|
ressave = res;
|
||||||
do {
|
do {
|
||||||
sockfd =
|
sockfd =
|
||||||
@@ -162,21 +168,100 @@ int 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 listen_sock (uint16_t port, socklen_t * addrlen)
|
static int listen_on_one_socket(struct addrinfo *ad)
|
||||||
|
{
|
||||||
|
int listenfd;
|
||||||
|
int ret;
|
||||||
|
const int on = 1;
|
||||||
|
char numerichost[NI_MAXHOST];
|
||||||
|
int flags = NI_NUMERICHOST;
|
||||||
|
|
||||||
|
ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
|
||||||
|
numerichost, NI_MAXHOST, NULL, 0, flags);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "error calling getnameinfo: %s",
|
||||||
|
gai_strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "trying to listen on host[%s], family[%d], "
|
||||||
|
"socktype[%d], proto[%d]", numerichost,
|
||||||
|
ad->ai_family, ad->ai_socktype, ad->ai_protocol);
|
||||||
|
|
||||||
|
listenfd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
|
||||||
|
if (listenfd == -1) {
|
||||||
|
log_message(LOG_ERR, "socket() failed: %s", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR,
|
||||||
|
"setsockopt failed to set SO_REUSEADDR: %s",
|
||||||
|
strerror(errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ad->ai_family == AF_INET6) {
|
||||||
|
ret = setsockopt(listenfd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
|
||||||
|
sizeof(on));
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR,
|
||||||
|
"setsockopt failed to set IPV6_V6ONLY: %s",
|
||||||
|
strerror(errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = bind(listenfd, ad->ai_addr, ad->ai_addrlen);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "bind failed: %s", strerror (errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = listen(listenfd, MAXLISTEN);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "listen failed: %s", strerror(errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "listening on fd [%d]", listenfd);
|
||||||
|
|
||||||
|
return listenfd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start listening on a socket. Create a socket with the selected port.
|
||||||
|
* If the provided address is NULL, we may listen on multiple sockets,
|
||||||
|
* e.g. the wildcard addresse for IPv4 and IPv6, depending on what is
|
||||||
|
* supported. If the address is not NULL, we only listen on the first
|
||||||
|
* address reported by getaddrinfo that works.
|
||||||
|
*
|
||||||
|
* Upon success, the listen-fds are added to the listen_fds list
|
||||||
|
* and 0 is returned. Upon error, -1 is returned.
|
||||||
|
*/
|
||||||
|
int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *result, *rp;
|
struct addrinfo hints, *result, *rp;
|
||||||
char portstr[6];
|
char portstr[6];
|
||||||
int listenfd;
|
int ret = -1;
|
||||||
const int on = 1;
|
|
||||||
|
|
||||||
assert (port > 0);
|
assert (port > 0);
|
||||||
assert (addrlen != NULL);
|
assert (listen_fds != NULL);
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "listen_sock called with addr = '%s'",
|
||||||
|
addr == NULL ? "(NULL)" : addr);
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (struct addrinfo));
|
memset (&hints, 0, sizeof (struct addrinfo));
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_UNSPEC;
|
||||||
@@ -185,7 +270,7 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
|
|||||||
|
|
||||||
snprintf (portstr, sizeof (portstr), "%d", port);
|
snprintf (portstr, sizeof (portstr), "%d", port);
|
||||||
|
|
||||||
if (getaddrinfo (config.ipAddr, portstr, &hints, &result) != 0) {
|
if (getaddrinfo (addr, portstr, &hints, &result) != 0) {
|
||||||
log_message (LOG_ERR,
|
log_message (LOG_ERR,
|
||||||
"Unable to getaddrinfo() because of %s",
|
"Unable to getaddrinfo() because of %s",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
@@ -193,45 +278,34 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||||
listenfd = socket (rp->ai_family, rp->ai_socktype,
|
int listenfd;
|
||||||
rp->ai_protocol);
|
|
||||||
if (listenfd == -1)
|
listenfd = listen_on_one_socket(rp);
|
||||||
|
if (listenfd == -1) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on,
|
|
||||||
sizeof (on));
|
|
||||||
|
|
||||||
if (bind (listenfd, rp->ai_addr, rp->ai_addrlen) == 0)
|
|
||||||
break; /* success */
|
|
||||||
|
|
||||||
close (listenfd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rp == NULL) {
|
vector_append (listen_fds, &listenfd, sizeof(int));
|
||||||
/* was not able to bind to any address */
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Unable to bind listening socket "
|
|
||||||
"to any address.");
|
|
||||||
|
|
||||||
freeaddrinfo (result);
|
/* success */
|
||||||
return -1;
|
ret = 0;
|
||||||
|
|
||||||
|
if (addr != NULL) {
|
||||||
|
/*
|
||||||
|
* Unless wildcard is requested, only listen
|
||||||
|
* on the first result that works.
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen (listenfd, MAXLISTEN) < 0) {
|
if (ret != 0) {
|
||||||
log_message (LOG_ERR,
|
log_message (LOG_ERR, "Unable to listen on any address.");
|
||||||
"Unable to start listening socket because of %s",
|
|
||||||
strerror (errno));
|
|
||||||
|
|
||||||
close (listenfd);
|
|
||||||
freeaddrinfo (result);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*addrlen = rp->ai_addrlen;
|
|
||||||
|
|
||||||
freeaddrinfo (result);
|
freeaddrinfo (result);
|
||||||
|
|
||||||
return listenfd;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+3
-1
@@ -28,8 +28,10 @@
|
|||||||
|
|
||||||
#define MAXLINE (1024 * 4)
|
#define MAXLINE (1024 * 4)
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
extern int opensock (const char *host, int port, const char *bind_to);
|
extern int opensock (const char *host, int port, const char *bind_to);
|
||||||
extern int listen_sock (uint16_t port, socklen_t * addrlen);
|
extern int listen_sock (const char *addr, uint16_t port, vector_t listen_fds);
|
||||||
|
|
||||||
extern int socket_nonblocking (int sock);
|
extern int socket_nonblocking (int sock);
|
||||||
extern int socket_blocking (int sock);
|
extern int socket_blocking (int sock);
|
||||||
|
|||||||
+22
-9
@@ -45,7 +45,7 @@ static int build_url (char **url, const char *host, int port, const char *path)
|
|||||||
assert (path != NULL);
|
assert (path != NULL);
|
||||||
|
|
||||||
len = strlen (host) + strlen (path) + 14;
|
len = strlen (host) + strlen (path) + 14;
|
||||||
*url = (char *) safemalloc (len);
|
*url = (char *) saferealloc (*url, len);
|
||||||
if (*url == NULL)
|
if (*url == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
socklen_t length;
|
socklen_t length;
|
||||||
char *data;
|
char *data;
|
||||||
size_t ulen = strlen (*url);
|
size_t ulen = strlen (*url);
|
||||||
|
ssize_t i;
|
||||||
|
|
||||||
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
|
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
|
||||||
if (length <= 0) {
|
if (length <= 0) {
|
||||||
@@ -105,17 +106,29 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
"process_request: trans Host %s %s for %d",
|
"process_request: trans Host %s %s for %d",
|
||||||
request->method, *url, connptr->client_fd);
|
request->method, *url, connptr->client_fd);
|
||||||
}
|
}
|
||||||
if (conf->ipAddr && strcmp (request->host, conf->ipAddr) == 0) {
|
|
||||||
log_message (LOG_ERR,
|
if (conf->listen_addrs == NULL) {
|
||||||
"process_request: destination IP is localhost %d",
|
return 1;
|
||||||
connptr->client_fd);
|
}
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
|
||||||
|
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",
|
"detail",
|
||||||
"You tried to connect to the machine "
|
"You tried to connect to the "
|
||||||
"the proxy is running on", "url", *url,
|
"machine the proxy is running on",
|
||||||
NULL);
|
"url", *url, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
+48
-12
@@ -27,12 +27,28 @@
|
|||||||
#include "upstream.h"
|
#include "upstream.h"
|
||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "base64.h"
|
||||||
|
#include "basicauth.h"
|
||||||
|
|
||||||
#ifdef UPSTREAM_SUPPORT
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
const char *
|
||||||
|
proxy_type_name(proxy_type type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case PT_NONE: return "none";
|
||||||
|
case PT_HTTP: return "http";
|
||||||
|
case PT_SOCKS4: return "socks4";
|
||||||
|
case PT_SOCKS5: return "socks5";
|
||||||
|
default: return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an upstream struct from input data.
|
* Construct an upstream struct from input data.
|
||||||
*/
|
*/
|
||||||
static struct upstream *upstream_build (const char *host, int port, const char *domain)
|
static struct upstream *upstream_build (const char *host, int port, const char *domain,
|
||||||
|
const char *user, const char *pass,
|
||||||
|
proxy_type type)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
struct upstream *up;
|
struct upstream *up;
|
||||||
@@ -44,8 +60,25 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
up->host = up->domain = NULL;
|
up->type = type;
|
||||||
|
up->host = up->domain = up->ua.user = up->pass = NULL;
|
||||||
up->ip = up->mask = 0;
|
up->ip = up->mask = 0;
|
||||||
|
if (user) {
|
||||||
|
if (type == PT_HTTP) {
|
||||||
|
char b[BASE64ENC_BYTES((256+2)-1) + 1];
|
||||||
|
ssize_t ret;
|
||||||
|
ret = basicauth_string(user, pass, b, sizeof b);
|
||||||
|
if (ret == 0) {
|
||||||
|
log_message (LOG_ERR,
|
||||||
|
"User / pass in upstream config too long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
up->ua.authstr = safestrdup (b);
|
||||||
|
} else {
|
||||||
|
up->ua.user = safestrdup (user);
|
||||||
|
up->pass = safestrdup (pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (domain == NULL) {
|
if (domain == NULL) {
|
||||||
if (!host || host[0] == '\0' || port < 1) {
|
if (!host || host[0] == '\0' || port < 1) {
|
||||||
@@ -57,9 +90,9 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
|||||||
up->host = safestrdup (host);
|
up->host = safestrdup (host);
|
||||||
up->port = port;
|
up->port = port;
|
||||||
|
|
||||||
log_message (LOG_INFO, "Added upstream %s:%d for [default]",
|
log_message (LOG_INFO, "Added upstream %s %s:%d for [default]",
|
||||||
host, port);
|
proxy_type_name(type), host, port);
|
||||||
} else if (host == NULL) {
|
} else if (host == NULL || type == PT_NONE) {
|
||||||
if (!domain || domain[0] == '\0') {
|
if (!domain || domain[0] == '\0') {
|
||||||
log_message (LOG_WARNING,
|
log_message (LOG_WARNING,
|
||||||
"Nonsense no-upstream rule: empty domain");
|
"Nonsense no-upstream rule: empty domain");
|
||||||
@@ -91,7 +124,7 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
|||||||
log_message (LOG_INFO, "Added no-upstream for %s", domain);
|
log_message (LOG_INFO, "Added no-upstream for %s", domain);
|
||||||
} else {
|
} else {
|
||||||
if (!host || host[0] == '\0' || port < 1 || !domain
|
if (!host || host[0] == '\0' || port < 1 || !domain
|
||||||
|| domain == '\0') {
|
|| domain[0] == '\0') {
|
||||||
log_message (LOG_WARNING,
|
log_message (LOG_WARNING,
|
||||||
"Nonsense upstream rule: invalid parameters");
|
"Nonsense upstream rule: invalid parameters");
|
||||||
goto fail;
|
goto fail;
|
||||||
@@ -101,13 +134,15 @@ static struct upstream *upstream_build (const char *host, int port, const char *
|
|||||||
up->port = port;
|
up->port = port;
|
||||||
up->domain = safestrdup (domain);
|
up->domain = safestrdup (domain);
|
||||||
|
|
||||||
log_message (LOG_INFO, "Added upstream %s:%d for %s",
|
log_message (LOG_INFO, "Added upstream %s %s:%d for %s",
|
||||||
host, port, domain);
|
proxy_type_name(type), host, port, domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
return up;
|
return up;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
safefree (up->ua.user);
|
||||||
|
safefree (up->pass);
|
||||||
safefree (up->host);
|
safefree (up->host);
|
||||||
safefree (up->domain);
|
safefree (up->domain);
|
||||||
safefree (up);
|
safefree (up);
|
||||||
@@ -119,11 +154,12 @@ fail:
|
|||||||
* Add an entry to the upstream list
|
* Add an entry to the upstream list
|
||||||
*/
|
*/
|
||||||
void upstream_add (const char *host, int port, const char *domain,
|
void upstream_add (const char *host, int port, const char *domain,
|
||||||
struct upstream **upstream_list)
|
const char *user, const char *pass,
|
||||||
|
proxy_type type, struct upstream **upstream_list)
|
||||||
{
|
{
|
||||||
struct upstream *up;
|
struct upstream *up;
|
||||||
|
|
||||||
up = upstream_build (host, port, domain);
|
up = upstream_build (host, port, domain, user, pass, type);
|
||||||
if (up == NULL) {
|
if (up == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -202,8 +238,8 @@ struct upstream *upstream_get (char *host, struct upstream *up)
|
|||||||
up = NULL;
|
up = NULL;
|
||||||
|
|
||||||
if (up)
|
if (up)
|
||||||
log_message (LOG_INFO, "Found upstream proxy %s:%d for %s",
|
log_message (LOG_INFO, "Found upstream proxy %s %s:%d for %s",
|
||||||
up->host, up->port, host);
|
proxy_type_name(up->type), up->host, up->port, host);
|
||||||
else
|
else
|
||||||
log_message (LOG_INFO, "No upstream proxy for %s", host);
|
log_message (LOG_INFO, "No upstream proxy for %s", host);
|
||||||
|
|
||||||
|
|||||||
+16
-1
@@ -31,17 +31,32 @@
|
|||||||
* Even if upstream support is not compiled into tinyproxy, this
|
* Even if upstream support is not compiled into tinyproxy, this
|
||||||
* structure still needs to be defined.
|
* structure still needs to be defined.
|
||||||
*/
|
*/
|
||||||
|
typedef enum proxy_type {
|
||||||
|
PT_NONE = 0,
|
||||||
|
PT_HTTP,
|
||||||
|
PT_SOCKS4,
|
||||||
|
PT_SOCKS5
|
||||||
|
} proxy_type;
|
||||||
|
|
||||||
struct upstream {
|
struct upstream {
|
||||||
struct upstream *next;
|
struct upstream *next;
|
||||||
char *domain; /* optional */
|
char *domain; /* optional */
|
||||||
char *host;
|
char *host;
|
||||||
|
union {
|
||||||
|
char *user;
|
||||||
|
char *authstr;
|
||||||
|
} ua;
|
||||||
|
char *pass;
|
||||||
int port;
|
int port;
|
||||||
in_addr_t ip, mask;
|
in_addr_t ip, mask;
|
||||||
|
proxy_type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef UPSTREAM_SUPPORT
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
const char *proxy_type_name(proxy_type type);
|
||||||
extern void upstream_add (const char *host, int port, const char *domain,
|
extern void upstream_add (const char *host, int port, const char *domain,
|
||||||
struct upstream **upstream_list);
|
const char *user, const char *pass,
|
||||||
|
proxy_type type, struct upstream **upstream_list);
|
||||||
extern struct upstream *upstream_get (char *host, struct upstream *up);
|
extern struct upstream *upstream_get (char *host, struct upstream *up);
|
||||||
extern void free_upstream_list (struct upstream *up);
|
extern void free_upstream_list (struct upstream *up);
|
||||||
#endif /* UPSTREAM_SUPPORT */
|
#endif /* UPSTREAM_SUPPORT */
|
||||||
|
|||||||
Reference in new issue
Block a user