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 | ||
|
|
9c500d06f2 | ||
|
|
aea157d7c9 | ||
|
|
9c68b94136 | ||
|
|
26b4ab07a4 | ||
|
|
a34ce8f4f9 | ||
|
|
e2b367a169 | ||
|
|
8070023643 | ||
|
|
54a613b9db | ||
|
|
d3df735f89 | ||
|
|
74334a7700 | ||
|
|
09d11ace60 | ||
|
|
bf820013df | ||
|
|
21c6164910 | ||
|
|
6da10fa438 | ||
|
|
bbccb57929 | ||
|
|
5980512a08 | ||
|
|
3700e1fc5b | ||
|
|
46deecdb53 | ||
|
|
eb67b4c407 | ||
|
|
ee17131bdf | ||
|
|
fa45b3cb79 | ||
|
|
d3b1619b06 | ||
|
|
3101d7ebb4 | ||
|
|
157a79216f | ||
|
|
a61f6018f2 | ||
|
|
a639f3fca2 | ||
|
|
3baa5f6f7c | ||
|
|
184d07e47c | ||
|
|
8963c84dad | ||
|
|
7e9a022c74 | ||
|
|
7ca792043c | ||
|
|
028cad3c3b | ||
|
|
5e387e6ee7 | ||
|
|
dc86ebaf28 | ||
|
|
fa0c4963e9 | ||
|
|
9fec507daf | ||
|
|
74b0b63da8 | ||
|
|
fb07cb380c | ||
|
|
d6a247cc04 | ||
|
|
bcca20a3e6 | ||
|
|
1dd1c2796a | ||
|
|
65ef313cc4 | ||
|
|
b106091343 | ||
|
|
594df6bf43 | ||
|
|
52e333af0b | ||
|
|
12026c32de | ||
|
|
6c9a647576 | ||
|
|
e1e9e53d45 | ||
|
|
0bfc0e90c1 | ||
|
|
9c0c3d5ced | ||
|
|
b96a3a3250 | ||
|
|
e5abe844d1 | ||
|
|
9e79e9975f | ||
|
|
70e8197344 | ||
|
|
34f9e5f95e | ||
|
|
e42d1cf9fd | ||
|
|
8077fd8936 | ||
|
|
df08d801fe | ||
|
|
e0fabc6127 | ||
|
|
5e8c8508ef | ||
|
|
4a11f9f08f | ||
|
|
c07cd2e44e | ||
|
|
71a035d619 | ||
|
|
bc10479452 | ||
|
|
adf4640104 | ||
|
|
0466526b1d | ||
|
|
8346a20aa0 | ||
|
|
fb2e65f40b | ||
|
|
c4b9454807 | ||
|
|
f3c8424515 | ||
|
|
2c14f89bfc | ||
|
|
210e82d08d | ||
|
|
891846f23e | ||
|
|
649b2c0683 | ||
|
|
479562ad2b | ||
|
|
91492773b1 | ||
|
|
e9baa2977c | ||
|
|
f7419c60be | ||
|
|
93dfb1ac5b | ||
|
|
8bf91ce80f | ||
|
|
72632f6569 | ||
|
|
6ea160ffff | ||
|
|
c15434df2b | ||
|
|
d3d31b434a | ||
|
|
6a5faa0bec | ||
|
|
d522221668 | ||
|
|
5bba62bcde | ||
|
|
0ba5cbea4f | ||
|
|
7290691142 | ||
|
|
34e4be193e | ||
|
|
4b54fc203f | ||
|
|
ad2f478c46 | ||
|
|
947d85cefc | ||
|
|
0d0de2fcc5 | ||
|
|
2ccebf7a95 | ||
|
|
dcbf99d334 | ||
|
|
1360f530f1 | ||
|
|
d0a91c2f9b | ||
|
|
fa073543c4 | ||
|
|
4c0a4d985f | ||
|
|
c981b246ce | ||
|
|
8cb182e1b8 | ||
|
|
6266197e92 | ||
|
|
2e6999df4a | ||
|
|
3f1201c8b3 | ||
|
|
624d146cd6 | ||
|
|
21aa3ecf60 | ||
|
|
4a8ea0d23b | ||
|
|
22fba83df2 | ||
|
|
fd987e97f0 | ||
|
|
56ba3d45bd | ||
|
|
34dbeb3626 | ||
|
|
c853cec164 | ||
|
|
073233b9f1 | ||
|
|
055c11f63c | ||
|
|
f60aa47715 | ||
|
|
5e399a7e17 | ||
|
|
0480185d07 | ||
|
|
607e8ec0e7 | ||
|
|
ec4b4d979f | ||
|
|
a664dee4f6 | ||
|
|
45a56e468d | ||
|
|
d7fada25e5 | ||
|
|
4b6a25ac06 | ||
|
|
238e3ffb34 | ||
|
|
2f05d8dd32 | ||
|
|
fba81e4174 | ||
|
|
a09dd9cd00 | ||
|
|
8945d9f0ae | ||
|
|
ea2eaef173 | ||
|
|
d8da7f55f7 | ||
|
|
9274b5556e | ||
|
|
c42fbaaf80 | ||
|
|
2061a18313 | ||
|
|
66abbbe72d | ||
|
|
e71b3e08a6 | ||
|
|
d8062ed35f | ||
|
|
276ca8369d | ||
|
|
feea6db815 | ||
|
|
c3f29ce4ac | ||
|
|
444ad35250 | ||
|
|
c0c6db0a5e | ||
|
|
6f56738ab0 | ||
|
|
41dd25d8e6 | ||
|
|
cbb179ef0b | ||
|
|
e54a3827df | ||
|
|
fd879e45c8 | ||
|
|
f63c29c886 | ||
|
|
60d738626b | ||
|
|
4292fe7795 | ||
|
|
2b73e2183f | ||
|
|
f4f14419c4 | ||
|
|
cd834de190 | ||
|
|
c8c9abc669 | ||
|
|
6f93737d8e | ||
|
|
c978015af1 | ||
|
|
25057baf54 | ||
|
|
3474de599f | ||
|
|
1b4d130cf5 | ||
|
|
b837e65b21 | ||
|
|
83987babd3 | ||
|
|
79527fb6f7 | ||
|
|
f43dd6ae18 | ||
|
|
cbaa4b9fd2 | ||
|
|
e793a729f6 | ||
|
|
582a8dc624 | ||
|
|
7b8171fe01 | ||
|
|
db7f340b3a | ||
|
|
1c0bda0e7c | ||
|
|
7671ac1ae2 | ||
|
|
f208b1222b | ||
|
|
f46aeca9a5 | ||
|
|
03b8e8bc19 | ||
|
|
add2685a55 | ||
|
|
cbe52ca43c | ||
|
|
07d993cbc1 | ||
|
|
a89d987e8a | ||
|
|
1fda61b5a0 | ||
|
|
641e5823c0 | ||
|
|
eb4d01cc46 | ||
|
|
297274ca15 | ||
|
|
8ff437236f | ||
|
|
eab4ae000b | ||
|
|
931b038b27 | ||
|
|
323a4d0147 |
No files matched your search
@@ -18,4 +18,6 @@ stamp-h1
|
|||||||
autom4te.cache
|
autom4te.cache
|
||||||
cscope.files
|
cscope.files
|
||||||
cscope.out
|
cscope.out
|
||||||
|
compile
|
||||||
*~
|
*~
|
||||||
|
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
|
||||||
+14
-1
@@ -4,12 +4,19 @@ SUBDIRS = \
|
|||||||
etc \
|
etc \
|
||||||
docs \
|
docs \
|
||||||
m4macros \
|
m4macros \
|
||||||
packaging \
|
|
||||||
tests
|
tests
|
||||||
|
|
||||||
# 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 \
|
||||||
@@ -18,5 +25,11 @@ EXTRA_DIST = \
|
|||||||
test: all
|
test: all
|
||||||
./tests/scripts/run_tests.sh
|
./tests/scripts/run_tests.sh
|
||||||
|
|
||||||
|
test-wait:
|
||||||
|
TINYPROXY_TESTS_WAIT=yes $(MAKE) test
|
||||||
|
|
||||||
valgrind-test: all
|
valgrind-test: all
|
||||||
./tests/scripts/run_tests_valgrind.sh
|
./tests/scripts/run_tests_valgrind.sh
|
||||||
|
|
||||||
|
valgrind-test-wait:
|
||||||
|
TINYPROXY_TESTS_WAIT=yes $(MAKE) valgrind-test
|
||||||
@@ -1,26 +1 @@
|
|||||||
Tinyproxy NEWS
|
See git log for recent changes in Tinyproxy.
|
||||||
==============
|
|
||||||
|
|
||||||
Version 1.7.1
|
|
||||||
-------------
|
|
||||||
|
|
||||||
* Fixed all warnings reported by GCC
|
|
||||||
* Wrote improved asciidoc manpages
|
|
||||||
* Cleaned up build system
|
|
||||||
* Fixed various other bugs
|
|
||||||
|
|
||||||
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.
|
|
||||||
@@ -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://www.banu.com/tinyproxy/
|
|
||||||
|
|
||||||
|
|
||||||
Installation
|
|
||||||
------------
|
|
||||||
|
|
||||||
To install this package under a UNIX derivative, read the INSTALL file.
|
|
||||||
Tinyproxy uses a standard GNU `configure` script. Basically you should
|
|
||||||
be able to do:
|
|
||||||
|
|
||||||
----
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
----
|
|
||||||
|
|
||||||
in the top level directory to compile and install Tinyproxy. There are
|
|
||||||
additional command line arguments you can supply to `configure`. They
|
|
||||||
include:
|
|
||||||
|
|
||||||
--enable-debug If you would like to turn on full
|
|
||||||
debugging support
|
|
||||||
--enable-xtinyproxy Compile in support for the XTinyproxy
|
|
||||||
header, which is sent to any web
|
|
||||||
server in your domain.
|
|
||||||
--enable-filter Allows Tinyproxy to filter out certain
|
|
||||||
domains and URLs.
|
|
||||||
--enable-upstream Enable support for proxying connections
|
|
||||||
through another proxy server.
|
|
||||||
--enable-transparent-proxy
|
|
||||||
Allow Tinyproxy to be used as a
|
|
||||||
transparent proxy daemon
|
|
||||||
--enable-static Compile a static version of Tinyproxy
|
|
||||||
|
|
||||||
--with-stathost=HOST Set the default name of the stats host
|
|
||||||
|
|
||||||
|
|
||||||
Support
|
|
||||||
-------
|
|
||||||
|
|
||||||
If you are having problems with Tinyproxy, please submit a bug report
|
|
||||||
using Tinyproxy as the component at:
|
|
||||||
|
|
||||||
https://www.banu.com/bugzilla/
|
|
||||||
|
|
||||||
You may also wish to subscribe to the Tinyproxy mailing lists. To do so
|
|
||||||
please visit:
|
|
||||||
|
|
||||||
https://www.banu.com/mailman/listinfo/tinyproxy-announce-list
|
|
||||||
https://www.banu.com/mailman/listinfo/tinyproxy-users-list
|
|
||||||
https://www.banu.com/mailman/listinfo/tinyproxy-developers-list
|
|
||||||
|
|
||||||
for more information on how to subscribe and post messages to the lists.
|
|
||||||
|
|
||||||
|
|
||||||
Contributing
|
|
||||||
------------
|
|
||||||
|
|
||||||
If you would like to contribute a feature, or a bug fix to the Tinyproxy
|
|
||||||
source, please send a patch (preferably as a unified diff. i.e. `diff
|
|
||||||
-u` against the "master" branch of the Tinyproxy source code git
|
|
||||||
repository to tinyproxy-developers-list. Please include a description
|
|
||||||
of what your patch does.
|
|
||||||
|
|
||||||
Tinyproxy's git repository is git://www.banu.com/tinyproxy.git. The
|
|
||||||
following command creates a local copy:
|
|
||||||
|
|
||||||
----
|
|
||||||
git clone git://www.banu.com/tinyproxy.git
|
|
||||||
----
|
|
||||||
|
|
||||||
The easiest and preferred way to create a patch for submission is to
|
|
||||||
check in your changes locally and use `git format-patch` to generate a
|
|
||||||
mbox-style commit file that contains the diff along with the commit
|
|
||||||
message and author information. Such a format-patch file can be
|
|
||||||
integrated into the upstream repository, automatically keeping the
|
|
||||||
commit message and author information.
|
|
||||||
|
|
||||||
You can also meet developers and discuss development issues and patches
|
|
||||||
in the #tinyproxy IRC channel on Freenode (irc.freenode.net).
|
|
||||||
@@ -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,4 +38,15 @@ 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
|
||||||
|
|
||||||
|
* Remove common.h and fix order of headers
|
||||||
|
|
||||||
|
* Remove memory debugging functions (Valgrind is good enough)
|
||||||
|
|
||||||
|
* Make all functions return from one place (the end of the function)
|
||||||
|
|
||||||
|
* Move TODO items to Banu Bugzilla
|
||||||
|
|
||||||
+2
-2
@@ -17,8 +17,8 @@ cd $ORIGDIR
|
|||||||
|
|
||||||
set -
|
set -
|
||||||
|
|
||||||
echo $srcdir/configure --enable-maintainer-mode "$@"
|
echo $srcdir/configure "$@"
|
||||||
$srcdir/configure --enable-maintainer-mode "$@"
|
$srcdir/configure "$@"
|
||||||
RC=$?
|
RC=$?
|
||||||
if test $RC -ne 0; then
|
if test $RC -ne 0; then
|
||||||
echo
|
echo
|
||||||
|
|||||||
+63
-112
@@ -4,44 +4,25 @@
|
|||||||
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], [7])
|
m4_define([tinyproxy_minor_version], [10])
|
||||||
m4_define([tinyproxy_micro_version], [1])
|
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], [0.7.0])
|
# 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://www.banu.com/bugzilla/enter_bug.cgi?product=Tinyproxy],
|
[https://tinyproxy.github.io/],
|
||||||
[tinyproxy])
|
[tinyproxy])
|
||||||
|
|
||||||
AC_CANONICAL_TARGET
|
AC_CANONICAL_TARGET
|
||||||
AM_INIT_AUTOMAKE
|
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])
|
||||||
AM_MAINTAINER_MODE
|
|
||||||
|
|
||||||
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([no])])
|
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
|
||||||
|
|
||||||
TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
|
|
||||||
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
|
|
||||||
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])
|
||||||
@@ -65,8 +46,12 @@ AH_TEMPLATE([TINYPROXY_STATHOST],
|
|||||||
[This controls remote proxy stats display.])
|
[This controls remote proxy stats display.])
|
||||||
AC_ARG_WITH(stathost,
|
AC_ARG_WITH(stathost,
|
||||||
[AC_HELP_STRING([--with-stathost=HOST], [Default status host])],
|
[AC_HELP_STRING([--with-stathost=HOST], [Default status host])],
|
||||||
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")],
|
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")
|
||||||
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")])
|
TINYPROXY_STATHOST="$withval"],
|
||||||
|
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")
|
||||||
|
TINYPROXY_STATHOST="tinyproxy.stats"])
|
||||||
|
|
||||||
|
AC_SUBST(TINYPROXY_STATHOST)
|
||||||
|
|
||||||
dnl Add compiler-specific optimization flags
|
dnl Add compiler-specific optimization flags
|
||||||
TP_ARG_ENABLE(debug,
|
TP_ARG_ENABLE(debug,
|
||||||
@@ -110,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)
|
||||||
@@ -121,8 +106,8 @@ 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)
|
||||||
@@ -158,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"
|
||||||
@@ -214,55 +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
|
|
||||||
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
|
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl Substitute the variables into the various Makefiles
|
dnl Substitute the variables into the various Makefiles
|
||||||
dnl
|
dnl
|
||||||
@@ -272,10 +190,29 @@ 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")
|
||||||
|
|
||||||
|
# checking xmllint
|
||||||
|
AC_PATH_PROG(XMLLINT, xmllint, no)
|
||||||
|
if test "x$XMLLINT" != "xno"; then
|
||||||
|
AS_ECHO_N("testing xmllint... ")
|
||||||
|
echo "TEST" > conftest.txt
|
||||||
|
if $A2X -f docbook conftest.txt 2>/dev/null; then
|
||||||
|
AS_ECHO("ok")
|
||||||
|
else
|
||||||
|
AS_ECHO("failed")
|
||||||
|
XMLLINT="no"
|
||||||
|
fi
|
||||||
|
rm -f conftest.txt conftest.xml
|
||||||
|
fi
|
||||||
|
AM_CONDITIONAL(HAVE_XMLLINT, test "x$XMLLINT" != "xno")
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
@@ -288,11 +225,25 @@ docs/man5/tinyproxy.conf.txt
|
|||||||
docs/man8/Makefile
|
docs/man8/Makefile
|
||||||
docs/man8/tinyproxy.txt
|
docs/man8/tinyproxy.txt
|
||||||
m4macros/Makefile
|
m4macros/Makefile
|
||||||
packaging/Makefile
|
|
||||||
packaging/fedora/tinyproxy.spec
|
|
||||||
packaging/fedora/Makefile
|
|
||||||
tests/Makefile
|
tests/Makefile
|
||||||
tests/scripts/Makefile
|
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,23 +1,25 @@
|
|||||||
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)
|
||||||
|
|
||||||
.txt.5:
|
.txt.5:
|
||||||
if HAVE_A2X
|
if HAVE_A2X
|
||||||
a2x $(A2X_ARGS) $<
|
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
|
||||||
else
|
else
|
||||||
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
|
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
|
||||||
endif
|
endif
|
||||||
|
|
||||||
EXTRA_DIST = \
|
|
||||||
$(man_MANS)
|
|
||||||
|
|
||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
$(MAN5_FILES:.txt=.5) \
|
$(MAN5_FILES:.txt=.5) \
|
||||||
$(MAN5_FILES:.txt=.xml)
|
$(MAN5_FILES:.txt=.xml)
|
||||||
|
|
||||||
|
EXTRA_DIST = \
|
||||||
|
$(MAN5_FILES:.txt=.5)
|
||||||
@@ -83,6 +83,14 @@ The possible keywords and their descriptions are as follows:
|
|||||||
This parameter controls the HTML template file returned when an
|
This parameter controls the HTML template file returned when an
|
||||||
error occurs for which no specific error file has been set.
|
error occurs for which no specific error file has been set.
|
||||||
|
|
||||||
|
*StatHost*::
|
||||||
|
|
||||||
|
This configures the host name or IP address that is treated
|
||||||
|
as the `stat host`: Whenever a request for this host is received,
|
||||||
|
Tinyproxy will return an internal statistics page instead of
|
||||||
|
forwarding the request to that host. The template for this
|
||||||
|
page can be configured with the `StatFile` configuration option.
|
||||||
|
The default value of `StatHost` is `@TINYPROXY_STATHOST@`.
|
||||||
|
|
||||||
*StatFile*::
|
*StatFile*::
|
||||||
|
|
||||||
@@ -91,8 +99,7 @@ The possible keywords and their descriptions are as follows:
|
|||||||
not set, Tinyproxy returns a hard-coded basic statistics page.
|
not set, Tinyproxy returns a hard-coded basic statistics page.
|
||||||
See the STATHOST section in the `tinyproxy(8)` manual page
|
See the STATHOST section in the `tinyproxy(8)` manual page
|
||||||
for details.
|
for details.
|
||||||
|
+
|
||||||
|
|
||||||
Note that the StatFile and the error files configured with ErrorFile
|
Note that the StatFile and the error files configured with ErrorFile
|
||||||
and DefaultErrorFile are template files that can contain a few
|
and DefaultErrorFile are template files that can contain a few
|
||||||
template variables that Tinyproxy expands prior to delivery.
|
template variables that Tinyproxy expands prior to delivery.
|
||||||
@@ -114,7 +121,10 @@ The possible keywords and their descriptions are as follows:
|
|||||||
|
|
||||||
*LogLevel*::
|
*LogLevel*::
|
||||||
|
|
||||||
This sets the log level. Allowed values are:
|
Sets the log level. Messages from the set level and above are
|
||||||
|
logged. For example, if the LogLevel was set to Warning, then all
|
||||||
|
log messages from Warning to Critical would be output, but Notice
|
||||||
|
and below would be suppressed. Allowed values are:
|
||||||
|
|
||||||
* Critical (least verbose)
|
* Critical (least verbose)
|
||||||
* Error
|
* Error
|
||||||
@@ -123,11 +133,6 @@ The possible keywords and their descriptions are as follows:
|
|||||||
* Connect (log connections without Info's noise)
|
* Connect (log connections without Info's noise)
|
||||||
* Info (most verbose)
|
* Info (most verbose)
|
||||||
|
|
||||||
The LogLevel logs from the set level and above. For example, if
|
|
||||||
the LogLevel was set to Warning, than all log messages from
|
|
||||||
Warning to Critical would be output, but Notice and below would be
|
|
||||||
suppressed.
|
|
||||||
|
|
||||||
*PidFile*::
|
*PidFile*::
|
||||||
|
|
||||||
This option controls the location of the file where the main
|
This option controls the location of the file where the main
|
||||||
@@ -138,21 +143,26 @@ The possible keywords and their descriptions are as follows:
|
|||||||
Setting this option to `Yes` tells Tinyproxy to add a header
|
Setting this option to `Yes` tells Tinyproxy to add a header
|
||||||
`X-Tinyproxy` containing the client's IP address to the request.
|
`X-Tinyproxy` containing the client's IP address to the request.
|
||||||
|
|
||||||
*[No] Upstream*::
|
*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 a 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
|
||||||
@@ -204,23 +214,42 @@ The possible keywords and their descriptions are as follows:
|
|||||||
which clients are allowed to access Tinyproxy. `Allow` and `Deny`
|
which clients are allowed to access Tinyproxy. `Allow` and `Deny`
|
||||||
lines can be specified multiple times to build the access control
|
lines can be specified multiple times to build the access control
|
||||||
list for Tinyproxy. The order in the config file is important.
|
list for Tinyproxy. The order in the config file is important.
|
||||||
If there are no `Access` or `Deny` lines, then all clients are
|
If there are no `Allow` or `Deny` lines, then all clients are
|
||||||
allowed. Otherwise, the default action is to deny access.
|
allowed. Otherwise, the default action is to deny access.
|
||||||
The argument to `Access` or `Deny` can be a single IP address
|
The argument to `Allow` or `Deny` can be a single IP address
|
||||||
of a client host, like `127.0.0.1`, an IP address range, like
|
of a client host, like `127.0.0.1`, an IP address range, like
|
||||||
`192.168.0.1/24` or a string that will be matched against the
|
`192.168.0.1/24` or a string that will be matched against the
|
||||||
end of the client host name, i.e, this can be a full host name
|
end of the client host name, i.e, this can be a full host name
|
||||||
like `host.example.com` or a domain name like `.example.com` or
|
like `host.example.com` or a domain name like `.example.com` or
|
||||||
even a top level domain name like `.com`.
|
even a top level domain name like `.com`.
|
||||||
|
|
||||||
|
*AddHeader*::
|
||||||
|
|
||||||
|
Configure one or more HTTP request headers to be added to outgoing
|
||||||
|
HTTP requests that Tinyproxy makes. Note that this option will not
|
||||||
|
work for HTTPS traffic, as Tinyproxy has no control over what
|
||||||
|
headers are exchanged.
|
||||||
|
+
|
||||||
|
----
|
||||||
|
AddHeader "X-My-Header" "Powered by Tinyproxy"
|
||||||
|
----
|
||||||
|
|
||||||
*ViaProxyName*::
|
*ViaProxyName*::
|
||||||
|
|
||||||
RFC 2616 requires proxies to add a `Via` header to the HTTP
|
RFC 2616 requires proxies to add a `Via` header to the HTTP
|
||||||
requests, but using the real host name can be a security
|
requests, but using the real host name can be a security
|
||||||
concern. If the `ViaProxyname` option is present, than its
|
concern. If the `ViaProxyname` option is present, then its
|
||||||
string value will be used as the host name in the Via header.
|
string value will be used as the host name in the Via header.
|
||||||
Otherwise, the server's host name will be used.
|
Otherwise, the server's host name will be used.
|
||||||
|
|
||||||
|
*DisableViaHeader*::
|
||||||
|
|
||||||
|
When this is set to yes, Tinyproxy does NOT add the `Via` header
|
||||||
|
to the requests. This virtually puts Tinyproxy into stealth mode.
|
||||||
|
Note that RFC 2616 requires proxies to set the `Via` header, so by
|
||||||
|
enabling this option, you break compliance.
|
||||||
|
Don't disable the `Via` header unless you know what you are doing...
|
||||||
|
|
||||||
*Filter*::
|
*Filter*::
|
||||||
|
|
||||||
Tinyproxy supports filtering of web sites based on URLs or
|
Tinyproxy supports filtering of web sites based on URLs or
|
||||||
@@ -259,15 +288,17 @@ The possible keywords and their descriptions are as follows:
|
|||||||
through, while all others are denied. If no Anonymous keyword
|
through, while all others are denied. If no Anonymous keyword
|
||||||
is present, then all headers are allowed through. You must
|
is present, then all headers are allowed through. You must
|
||||||
include quotes around the headers.
|
include quotes around the headers.
|
||||||
|
+
|
||||||
Most sites require cookies to be enabled for them to work correctly, so
|
Most sites require cookies to be enabled for them to work correctly, so
|
||||||
you will need to allow Cookies through if you access those sites.
|
you will need to allow cookies through if you access those sites.
|
||||||
|
+
|
||||||
Example:
|
Example:
|
||||||
|
+
|
||||||
Anonymous "Host"
|
----
|
||||||
Anonymous "Authorization"
|
Anonymous "Host"
|
||||||
Anonymous "Cookie"
|
Anonymous "Authorization"
|
||||||
|
Anonymous "Cookie"
|
||||||
|
----
|
||||||
|
|
||||||
*ConnectPort*::
|
*ConnectPort*::
|
||||||
|
|
||||||
@@ -281,12 +312,14 @@ The possible keywords and their descriptions are as follows:
|
|||||||
Configure one or more ReversePath directives to enable reverse proxy
|
Configure one or more ReversePath directives to enable reverse proxy
|
||||||
support. With reverse proxying it's possible to make a number of
|
support. With reverse proxying it's possible to make a number of
|
||||||
sites appear as if they were part of a single site.
|
sites appear as if they were part of a single site.
|
||||||
|
+
|
||||||
If you uncomment the following two directives and run Tinyproxy
|
If you uncomment the following two directives and run Tinyproxy
|
||||||
on your own computer at port 8888, you can access example.com,
|
on your own computer at port 8888, you can access example.com,
|
||||||
using http://localhost:8888/example/.
|
using http://localhost:8888/example/.
|
||||||
|
+
|
||||||
ReversePath "/example/" "http://www.example.com/"
|
----
|
||||||
|
ReversePath "/example/" "http://www.example.com/"
|
||||||
|
----
|
||||||
|
|
||||||
*ReverseOnly*::
|
*ReverseOnly*::
|
||||||
|
|
||||||
@@ -314,16 +347,24 @@ BUGS
|
|||||||
----
|
----
|
||||||
|
|
||||||
To report bugs in Tinyproxy, please visit
|
To report bugs in Tinyproxy, please visit
|
||||||
<https://www.banu.com/tinyproxy/support/[https://www.banu.com/tinyproxy/support/]>.
|
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>.
|
||||||
|
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
--------
|
||||||
|
tinyproxy(8)
|
||||||
|
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
------
|
||||||
|
|
||||||
|
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 Mukund Sivaraman;
|
|
||||||
Copyright (c) 2009 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,23 +1,25 @@
|
|||||||
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)
|
||||||
|
|
||||||
.txt.8:
|
.txt.8:
|
||||||
if HAVE_A2X
|
if HAVE_A2X
|
||||||
a2x $(A2X_ARGS) $<
|
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
|
||||||
else
|
else
|
||||||
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
|
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
|
||||||
endif
|
endif
|
||||||
|
|
||||||
EXTRA_DIST = \
|
|
||||||
$(man_MANS)
|
|
||||||
|
|
||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
$(MAN8_FILES:.txt=.8) \
|
$(MAN8_FILES:.txt=.8) \
|
||||||
$(MAN8_FILES:.txt=.xml)
|
$(MAN8_FILES:.txt=.xml)
|
||||||
|
|
||||||
|
EXTRA_DIST= \
|
||||||
|
$(MAN8_FILES:.txt=.8)
|
||||||
+17
-12
@@ -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.
|
||||||
|
|
||||||
@@ -119,9 +116,9 @@ STATHOST
|
|||||||
|
|
||||||
Tinyproxy returns a HTML page with connection statistics when it
|
Tinyproxy returns a HTML page with connection statistics when it
|
||||||
receives a HTTP request for a certain host -- the stathost. The
|
receives a HTTP request for a certain host -- the stathost. The
|
||||||
stathost name defaults to `tinyproxy.stats` and can be changed at
|
stathost name defaults to `@TINYPROXY_STATHOST@` and can be changed at
|
||||||
compile-time with the configure switch `--with-stathost` to any name or
|
runtime to any name or IP address with the configuration variable
|
||||||
IP address.
|
`StatHost`.
|
||||||
|
|
||||||
The stat file template can be changed at runtime through the
|
The stat file template can be changed at runtime through the
|
||||||
configuration variable `StatFile`.
|
configuration variable `StatFile`.
|
||||||
@@ -130,22 +127,30 @@ configuration variable `StatFile`.
|
|||||||
FILES
|
FILES
|
||||||
-----
|
-----
|
||||||
|
|
||||||
`/etc/tinyproxy/tinyproxy.conf`, `/var/run/tinyproxy.pid`, `/var/log/tinyproxy.log`
|
`/etc/tinyproxy/tinyproxy.conf`, `/var/run/tinyproxy/tinyproxy.pid`, `/var/log/tinyproxy/tinyproxy.log`
|
||||||
|
|
||||||
BUGS
|
BUGS
|
||||||
----
|
----
|
||||||
|
|
||||||
To report bugs in Tinyproxy, please visit
|
To report bugs in Tinyproxy, please visit
|
||||||
<https://www.banu.com/tinyproxy/support/[https://www.banu.com/tinyproxy/support/]>.
|
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>.
|
||||||
|
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
--------
|
||||||
|
tinyproxy.conf(5)
|
||||||
|
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
------
|
||||||
|
|
||||||
|
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 Mukund Sivaraman;
|
|
||||||
Copyright (c) 2009 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
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
tinyproxy.conf
|
||||||
+22
-2
@@ -1,5 +1,25 @@
|
|||||||
sysconf_DATA = \
|
pkgsysconfdir = $(sysconfdir)/$(PACKAGE)
|
||||||
|
|
||||||
|
pkgsysconf_DATA = \
|
||||||
tinyproxy.conf
|
tinyproxy.conf
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
$(sysconf_DATA)
|
tinyproxy.conf.in
|
||||||
|
|
||||||
|
edit = sed \
|
||||||
|
-e 's|@bindir[@]|$(bindir)|g' \
|
||||||
|
-e 's|@datadir[@]|$(datadir)|g' \
|
||||||
|
-e 's|@datarootdir[@]|$(datarootdir)|g' \
|
||||||
|
-e 's|@pkgsysconfdir[@]|$(pkgsysconfdir)|g' \
|
||||||
|
-e 's|@localstatedir[@]|$(localstatedir)|g' \
|
||||||
|
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
|
||||||
|
-e 's|@prefix[@]|$(prefix)|g' \
|
||||||
|
-e 's|@TINYPROXY_STATHOST[@]|$(TINYPROXY_STATHOST)|g'
|
||||||
|
|
||||||
|
tinyproxy.conf: $(top_srcdir)/etc/tinyproxy.conf.in Makefile
|
||||||
|
@rm -f $@ $@.tmp
|
||||||
|
$(AM_V_GEN) $(edit) $(top_srcdir)/etc/$@.in > $@.tmp
|
||||||
|
@mv $@.tmp $@
|
||||||
|
|
||||||
|
CLEANFILES = \
|
||||||
|
tinyproxy.conf
|
||||||
@@ -56,33 +56,44 @@ Timeout 600
|
|||||||
# /usr/share/tinyproxy
|
# /usr/share/tinyproxy
|
||||||
# /etc/tinyproxy
|
# /etc/tinyproxy
|
||||||
#
|
#
|
||||||
#ErrorFile 404 "/usr/share/tinyproxy/404.html"
|
#ErrorFile 404 "@pkgdatadir@/404.html"
|
||||||
#ErrorFile 400 "/usr/share/tinyproxy/400.html"
|
#ErrorFile 400 "@pkgdatadir@/400.html"
|
||||||
#ErrorFile 503 "/usr/share/tinyproxy/503.html"
|
#ErrorFile 503 "@pkgdatadir@/503.html"
|
||||||
#ErrorFile 403 "/usr/share/tinyproxy/403.html"
|
#ErrorFile 403 "@pkgdatadir@/403.html"
|
||||||
#ErrorFile 408 "/usr/share/tinyproxy/408.html"
|
#ErrorFile 408 "@pkgdatadir@/408.html"
|
||||||
|
|
||||||
#
|
#
|
||||||
# DefaultErrorFile: The HTML file that gets sent if there is no
|
# DefaultErrorFile: The HTML file that gets sent if there is no
|
||||||
# HTML file defined with an ErrorFile keyword for the HTTP error
|
# HTML file defined with an ErrorFile keyword for the HTTP error
|
||||||
# that has occured.
|
# that has occured.
|
||||||
#
|
#
|
||||||
DefaultErrorFile "/usr/share/tinyproxy/default.html"
|
DefaultErrorFile "@pkgdatadir@/default.html"
|
||||||
|
|
||||||
|
#
|
||||||
|
# StatHost: This configures the host name or IP address that is treated
|
||||||
|
# as the stat host: Whenever a request for this host is received,
|
||||||
|
# Tinyproxy will return an internal statistics page instead of
|
||||||
|
# forwarding the request to that host. The default value of StatHost is
|
||||||
|
# @TINYPROXY_STATHOST@.
|
||||||
|
#
|
||||||
|
#StatHost "@TINYPROXY_STATHOST@"
|
||||||
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
# StatFile: The HTML file that gets sent when a request is made
|
# StatFile: The HTML file that gets sent when a request is made
|
||||||
# for the stathost. If this file doesn't exist a basic page is
|
# for the stathost. If this file doesn't exist a basic page is
|
||||||
# hardcoded in tinyproxy.
|
# hardcoded in tinyproxy.
|
||||||
#
|
#
|
||||||
StatFile "/usr/share/tinyproxy/stats.html"
|
StatFile "@pkgdatadir@/stats.html"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Logfile: Allows you to specify the location where information should
|
# LogFile: Allows you to specify the location where information should
|
||||||
# be logged to. If you would prefer to log to syslog, then disable this
|
# 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 "/var/log/tinyproxy.log"
|
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Syslog: Tell tinyproxy to use syslog instead of a logfile. This
|
# Syslog: Tell tinyproxy to use syslog instead of a logfile. This
|
||||||
@@ -92,7 +103,7 @@ Logfile "/var/log/tinyproxy.log"
|
|||||||
#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)
|
||||||
@@ -103,7 +114,7 @@ Logfile "/var/log/tinyproxy.log"
|
|||||||
# Info (most verbose)
|
# Info (most verbose)
|
||||||
#
|
#
|
||||||
# The LogLevel logs from the set level and above. For example, if the
|
# The LogLevel logs from the set level and above. For example, if the
|
||||||
# LogLevel was set to Warning, than all log messages from Warning to
|
# LogLevel was set to Warning, then all log messages from Warning to
|
||||||
# Critical would be output, but Notice and below would be suppressed.
|
# Critical would be output, but Notice and below would be suppressed.
|
||||||
#
|
#
|
||||||
LogLevel Info
|
LogLevel Info
|
||||||
@@ -111,8 +122,9 @@ 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 "/var/run/tinyproxy.pid"
|
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
|
||||||
|
|
||||||
#
|
#
|
||||||
# XTinyproxy: Tell Tinyproxy to include the X-Tinyproxy header, which
|
# XTinyproxy: Tell Tinyproxy to include the X-Tinyproxy header, which
|
||||||
@@ -128,25 +140,37 @@ PidFile "/var/run/tinyproxy.pid"
|
|||||||
# 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:
|
||||||
@@ -156,7 +180,7 @@ PidFile "/var/run/tinyproxy.pid"
|
|||||||
# 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
|
||||||
@@ -199,6 +223,18 @@ 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
|
||||||
|
# Tinyproxy makes. Note that this option will not work for HTTPS
|
||||||
|
# traffic, as Tinyproxy has no control over what headers are exchanged.
|
||||||
|
#
|
||||||
|
#AddHeader "X-My-Header" "Powered by Tinyproxy"
|
||||||
|
|
||||||
#
|
#
|
||||||
# ViaProxyName: The "Via" header is required by the HTTP RFC, but using
|
# ViaProxyName: The "Via" header is required by the HTTP RFC, but using
|
||||||
# the real host name is a security concern. If the following directive
|
# the real host name is a security concern. If the following directive
|
||||||
@@ -207,10 +243,19 @@ Allow 127.0.0.1
|
|||||||
#
|
#
|
||||||
ViaProxyName "tinyproxy"
|
ViaProxyName "tinyproxy"
|
||||||
|
|
||||||
|
#
|
||||||
|
# DisableViaHeader: When this is set to yes, Tinyproxy does NOT add
|
||||||
|
# the Via header to the requests. This virtually puts Tinyproxy into
|
||||||
|
# stealth mode. Note that RFC 2616 requires proxies to set the Via
|
||||||
|
# header, so by enabling this option, you break compliance.
|
||||||
|
# Don't disable the Via header unless you know what you are doing...
|
||||||
|
#
|
||||||
|
#DisableViaHeader Yes
|
||||||
|
|
||||||
#
|
#
|
||||||
# Filter: This allows you to specify the location of the filter file.
|
# Filter: This allows you to specify the location of the filter file.
|
||||||
#
|
#
|
||||||
#Filter "/etc/tinyproxy/filter"
|
#Filter "@pkgsysconfdir@/filter"
|
||||||
|
|
||||||
#
|
#
|
||||||
# FilterURLs: Filter based on URLs rather than domains.
|
# FilterURLs: Filter based on URLs rather than domains.
|
||||||
@@ -257,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
|
|
||||||
])
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
# The various packaging directories
|
|
||||||
|
|
||||||
SUBDIRS = fedora
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
tinyproxy.spec
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
# Packaging files
|
|
||||||
|
|
||||||
PACKAGING_FILES = \
|
|
||||||
tinyproxy.init \
|
|
||||||
tinyproxy.spec
|
|
||||||
|
|
||||||
EXTRA_DIST = $(PACKAGING_FILES)
|
|
||||||
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# tinyproxy Startup script for the tinyproxy server
|
|
||||||
#
|
|
||||||
# chkconfig: - 85 15
|
|
||||||
# description: small, efficient HTTP/SSL proxy daemon
|
|
||||||
#
|
|
||||||
# processname: tinyproxy
|
|
||||||
# config: /etc/tinyproxy/tinyproxy.conf
|
|
||||||
# config: /etc/sysconfig/tinyproxy
|
|
||||||
# pidfile: /var/run/tinyproxy.pid
|
|
||||||
#
|
|
||||||
# Note: pidfile is created by tinyproxy in its config
|
|
||||||
# see PidFile in the configuration file.
|
|
||||||
|
|
||||||
# Source function library.
|
|
||||||
. /etc/rc.d/init.d/functions
|
|
||||||
|
|
||||||
# Source networking configuration.
|
|
||||||
. /etc/sysconfig/network
|
|
||||||
|
|
||||||
# Check that networking is up.
|
|
||||||
[ "$NETWORKING" = "no" ] && exit 0
|
|
||||||
|
|
||||||
exec="/usr/sbin/tinyproxy"
|
|
||||||
prog=$(basename $exec)
|
|
||||||
config="/etc/tinyproxy/tinyproxy.conf"
|
|
||||||
|
|
||||||
[ -e /etc/sysconfig/tinyproxy ] && . /etc/sysconfig/tinyproxy
|
|
||||||
|
|
||||||
lockfile=/var/lock/subsys/tinyproxy
|
|
||||||
|
|
||||||
start() {
|
|
||||||
[ -x $exec ] || exit 5
|
|
||||||
[ -f $config ] || exit 6
|
|
||||||
echo -n $"Starting $prog: "
|
|
||||||
daemon $exec -c $config
|
|
||||||
retval=$?
|
|
||||||
echo
|
|
||||||
[ $retval -eq 0 ] && touch $lockfile
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
echo -n $"Stopping $prog: "
|
|
||||||
# stop it here, often "killproc $prog"
|
|
||||||
killproc $prog
|
|
||||||
retval=$?
|
|
||||||
echo
|
|
||||||
[ $retval -eq 0 ] && rm -f $lockfile
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
restart() {
|
|
||||||
stop
|
|
||||||
start
|
|
||||||
}
|
|
||||||
|
|
||||||
reload() {
|
|
||||||
restart
|
|
||||||
}
|
|
||||||
|
|
||||||
force_reload() {
|
|
||||||
restart
|
|
||||||
}
|
|
||||||
|
|
||||||
rh_status() {
|
|
||||||
status $prog
|
|
||||||
}
|
|
||||||
|
|
||||||
rh_status_q() {
|
|
||||||
rh_status >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
rh_status_q && exit 0
|
|
||||||
$1
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
rh_status_q || exit 0
|
|
||||||
$1
|
|
||||||
;;
|
|
||||||
restart)
|
|
||||||
$1
|
|
||||||
;;
|
|
||||||
reload)
|
|
||||||
rh_status_q || exit 7
|
|
||||||
$1
|
|
||||||
;;
|
|
||||||
force-reload)
|
|
||||||
force_reload
|
|
||||||
;;
|
|
||||||
status)
|
|
||||||
rh_status
|
|
||||||
;;
|
|
||||||
condrestart|try-restart)
|
|
||||||
rh_status_q || exit 0
|
|
||||||
restart
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
|
|
||||||
exit 2
|
|
||||||
esac
|
|
||||||
exit $?
|
|
||||||
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
%define tinyproxy_confdir %{_sysconfdir}/tinyproxy
|
|
||||||
%define tinyproxy_datadir %{_datadir}/tinyproxy
|
|
||||||
|
|
||||||
Name: tinyproxy
|
|
||||||
Version: @VERSION@
|
|
||||||
Release: 2%{?dist}
|
|
||||||
Summary: A light-weight HTTP proxy daemon
|
|
||||||
|
|
||||||
Group: System Environment/Daemons
|
|
||||||
License: GPLv2+
|
|
||||||
URL: https://www.banu.com/tinyproxy/
|
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
|
||||||
|
|
||||||
Source0: https://www.banu.com/pub/tinyproxy/1.7/%{name}-%{version}.tar.gz
|
|
||||||
Source1: %{name}.init
|
|
||||||
Source2: %{name}.conf
|
|
||||||
|
|
||||||
Requires(post): chkconfig
|
|
||||||
Requires(preun): chkconfig
|
|
||||||
Requires(preun): initscripts
|
|
||||||
|
|
||||||
%description
|
|
||||||
Tinyproxy is a light-weight HTTP proxy daemon designed to consume a
|
|
||||||
minimum amount of system resources. It listens on a given TCP port and
|
|
||||||
handles HTTP proxy requests. Designed from the ground up to be fast and
|
|
||||||
yet small, it is an ideal solution for use cases such as embedded
|
|
||||||
deployments where a full featured HTTP proxy is required, but the system
|
|
||||||
resources for a larger proxy are unavailable.
|
|
||||||
|
|
||||||
|
|
||||||
%prep
|
|
||||||
%setup -q
|
|
||||||
|
|
||||||
|
|
||||||
%build
|
|
||||||
%configure --with-config=%{tinyproxy_confdir}/%{name}.conf
|
|
||||||
make %{?_smp_mflags}
|
|
||||||
|
|
||||||
|
|
||||||
%install
|
|
||||||
rm -rf %{buildroot}
|
|
||||||
make install-exec DESTDIR=%{buildroot}
|
|
||||||
|
|
||||||
# The default 'make install' installs too many items, so we trim it down
|
|
||||||
# and install manually
|
|
||||||
%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/%{name}
|
|
||||||
%{__install} -p -D -m 0644 %{SOURCE2} %{buildroot}%{tinyproxy_confdir}/%{name}.conf
|
|
||||||
%{__install} -d -m 0755 %{buildroot}%{tinyproxy_datadir}
|
|
||||||
%{__install} -p -D -m 0644 ./doc/%{name}.8 %{buildroot}%{_mandir}/man8/%{name}.8
|
|
||||||
|
|
||||||
for htmlfile in $(find ./doc/ -type f -name '*.html')
|
|
||||||
do
|
|
||||||
%{__install} -p -m 0644 $htmlfile %{buildroot}%{tinyproxy_datadir}
|
|
||||||
done
|
|
||||||
|
|
||||||
%clean
|
|
||||||
rm -rf %{buildroot}
|
|
||||||
|
|
||||||
|
|
||||||
%post
|
|
||||||
/sbin/chkconfig --add %{name}
|
|
||||||
|
|
||||||
|
|
||||||
%preun
|
|
||||||
if [ $1 = 0 ]; then
|
|
||||||
/sbin/service %{name} stop >/dev/null 2>&1
|
|
||||||
/sbin/chkconfig --del %{name}
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
%postun
|
|
||||||
if [ "$1" -ge "1" ]; then
|
|
||||||
/sbin/service %{name} condrestart > /dev/null 2>&1 || :
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%files
|
|
||||||
%defattr(-,root,root,-)
|
|
||||||
%doc AUTHORS COPYING README doc/*.txt
|
|
||||||
%{_sbindir}/%{name}
|
|
||||||
%{_mandir}/man8/%{name}.8.gz
|
|
||||||
%{_initrddir}/%{name}
|
|
||||||
%dir %{tinyproxy_datadir}
|
|
||||||
%dir %{tinyproxy_datadir}/*
|
|
||||||
%dir %{tinyproxy_confdir}
|
|
||||||
%config(noreplace) %{tinyproxy_confdir}/%{name}.conf
|
|
||||||
|
|
||||||
%changelog
|
|
||||||
* Wed Apr 16 2008 Jeremy Hinegardner <jeremy at hinegardner dot org> - 1.6.3-2
|
|
||||||
- fix spec review issues
|
|
||||||
- fix initscript
|
|
||||||
|
|
||||||
* Sun Mar 09 2008 Jeremy Hinegardner <jeremy at hinegardner dot org> - 1.6.3-1
|
|
||||||
- Initial rpm configuration
|
|
||||||
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}"
|
||||||
+10
-3
@@ -15,10 +15,13 @@
|
|||||||
# 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}\"
|
||||||
|
|
||||||
tinyproxy_SOURCES = \
|
tinyproxy_SOURCES = \
|
||||||
acl.c acl.h \
|
acl.c acl.h \
|
||||||
@@ -41,7 +44,11 @@ tinyproxy_SOURCES = \
|
|||||||
text.c text.h \
|
text.c text.h \
|
||||||
main.c main.h \
|
main.c main.h \
|
||||||
utils.c utils.h \
|
utils.c utils.h \
|
||||||
vector.c vector.h
|
vector.c vector.h \
|
||||||
|
upstream.c upstream.h \
|
||||||
|
basicauth.c basicauth.h \
|
||||||
|
base64.c base64.h \
|
||||||
|
connect-ports.c connect-ports.h
|
||||||
|
|
||||||
EXTRA_tinyproxy_SOURCES = filter.c filter.h \
|
EXTRA_tinyproxy_SOURCES = filter.c filter.h \
|
||||||
reverse-proxy.c reverse-proxy.h \
|
reverse-proxy.c reverse-proxy.h \
|
||||||
|
|||||||
@@ -51,17 +51,12 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* All the access lists are stored in a vector.
|
|
||||||
*/
|
|
||||||
static vector_t access_list = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fills in the netmask array given a numeric value.
|
* Fills in the netmask array given a numeric value.
|
||||||
*
|
*
|
||||||
@@ -71,23 +66,30 @@ static vector_t access_list = NULL;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
fill_netmask_array (char *bitmask_string, unsigned char array[],
|
fill_netmask_array (char *bitmask_string, int v6,
|
||||||
unsigned int len)
|
unsigned char array[], size_t len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
long int mask;
|
unsigned long int mask;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
errno = 0; /* to distinguish success/failure after call */
|
errno = 0; /* to distinguish success/failure after call */
|
||||||
mask = strtol (bitmask_string, &endptr, 10);
|
mask = strtoul (bitmask_string, &endptr, 10);
|
||||||
|
|
||||||
/* check for various conversion errors */
|
/* check for various conversion errors */
|
||||||
if ((errno == ERANGE && (mask == LONG_MIN || mask == LONG_MAX))
|
if ((errno == ERANGE && mask == ULONG_MAX)
|
||||||
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
|
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* valid range for a bit mask */
|
if (v6 == 0) {
|
||||||
if (mask < 0 || mask > (8 * len))
|
/* The mask comparison is done as an IPv6 address, so
|
||||||
|
* convert to a longer mask in the case of IPv4
|
||||||
|
* addresses. */
|
||||||
|
mask += 12 * 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check valid range for a bit mask */
|
||||||
|
if (mask > (8 * len))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* we have a valid range to fill in the array */
|
/* we have a valid range to fill in the array */
|
||||||
@@ -106,6 +108,23 @@ fill_netmask_array (char *bitmask_string, unsigned char array[],
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the access list has not been set up, create it.
|
||||||
|
*/
|
||||||
|
static int init_access_list(vector_t *access_list)
|
||||||
|
{
|
||||||
|
if (!*access_list) {
|
||||||
|
*access_list = vector_create ();
|
||||||
|
if (!*access_list) {
|
||||||
|
log_message (LOG_ERR,
|
||||||
|
"Unable to allocate memory for access list");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inserts a new access control into the list. The function will figure out
|
* Inserts a new access control into the list. The function will figure out
|
||||||
* whether the location is an IP address (with optional netmask) or a
|
* whether the location is an IP address (with optional netmask) or a
|
||||||
@@ -115,7 +134,8 @@ fill_netmask_array (char *bitmask_string, unsigned char array[],
|
|||||||
* -1 on failure
|
* -1 on failure
|
||||||
* 0 otherwise.
|
* 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int insert_acl (char *location, acl_access_t access_type)
|
int
|
||||||
|
insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
|
||||||
{
|
{
|
||||||
struct acl_s acl;
|
struct acl_s acl;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -123,17 +143,10 @@ int insert_acl (char *location, acl_access_t access_type)
|
|||||||
|
|
||||||
assert (location != NULL);
|
assert (location != NULL);
|
||||||
|
|
||||||
/*
|
ret = init_access_list(access_list);
|
||||||
* If the access list has not been set up, create it.
|
if (ret != 0) {
|
||||||
*/
|
|
||||||
if (!access_list) {
|
|
||||||
access_list = vector_create ();
|
|
||||||
if (!access_list) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Unable to allocate memory for access list");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start populating the access control structure.
|
* Start populating the access control structure.
|
||||||
@@ -146,15 +159,20 @@ int insert_acl (char *location, acl_access_t access_type)
|
|||||||
*/
|
*/
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
p = strchr (location, '/');
|
p = strchr (location, '/');
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
|
char dst[sizeof(struct in6_addr)];
|
||||||
|
int v6;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have a slash, so it's intended to be an
|
* We have a slash, so it's intended to be an
|
||||||
* IP address with mask
|
* IP address with mask
|
||||||
@@ -164,12 +182,22 @@ int insert_acl (char *location, acl_access_t access_type)
|
|||||||
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
|
||||||
|
* an IPv6 address */
|
||||||
|
if (inet_pton(AF_INET6, location, dst) > 0)
|
||||||
|
v6 = 1;
|
||||||
|
else
|
||||||
|
v6 = 0;
|
||||||
|
|
||||||
if (fill_netmask_array
|
if (fill_netmask_array
|
||||||
(p + 1, &(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;
|
||||||
@@ -179,11 +207,7 @@ int insert_acl (char *location, acl_access_t access_type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
ret = vector_append (*access_list, &acl, sizeof (struct acl_s));
|
||||||
* Add the entry and then clean up.
|
|
||||||
*/
|
|
||||||
ret = vector_append (access_list, &acl, sizeof (struct acl_s));
|
|
||||||
safefree (acl.address.string);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,11 +311,11 @@ 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)
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The addresses match, return the permission */
|
/* The addresses match, return the permission */
|
||||||
@@ -305,7 +329,7 @@ static int check_numeric_acl (const struct acl_s *acl, const char *ip)
|
|||||||
* 1 if allowed
|
* 1 if allowed
|
||||||
* 0 if denied
|
* 0 if denied
|
||||||
*/
|
*/
|
||||||
int check_acl (const char *ip, const char *host)
|
int check_acl (const char *ip, const char *host, vector_t access_list)
|
||||||
{
|
{
|
||||||
struct acl_s *acl;
|
struct acl_s *acl;
|
||||||
int perm = 0;
|
int perm = 0;
|
||||||
@@ -351,3 +375,27 @@ int check_acl (const char *ip, const char *host)
|
|||||||
host, ip);
|
host, ip);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void flush_access_list (vector_t access_list)
|
||||||
|
{
|
||||||
|
struct acl_s *acl;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!access_list) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need to free allocated data hanging off the acl entries
|
||||||
|
* before we can free the acl entries themselves.
|
||||||
|
* A hierarchical memory system would be great...
|
||||||
|
*/
|
||||||
|
for (i = 0; i != (size_t) vector_length (access_list); ++i) {
|
||||||
|
acl = (struct acl_s *) vector_getentry (access_list, i, NULL);
|
||||||
|
if (acl->type == ACL_STRING) {
|
||||||
|
safefree (acl->address.string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector_delete (access_list);
|
||||||
|
}
|
||||||
@@ -21,9 +21,14 @@
|
|||||||
#ifndef TINYPROXY_ACL_H
|
#ifndef TINYPROXY_ACL_H
|
||||||
#define TINYPROXY_ACL_H
|
#define TINYPROXY_ACL_H
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
|
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
|
||||||
|
|
||||||
extern int insert_acl (char *location, acl_access_t access_type);
|
extern int insert_acl (char *location, acl_access_t access_type,
|
||||||
extern int check_acl (const char *ip_address, const char *string_address);
|
vector_t *access_list);
|
||||||
|
extern int check_acl (const char *ip_address, const char *string_address,
|
||||||
|
vector_t access_list);
|
||||||
|
extern void flush_access_list (vector_t access_list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+9
-10
@@ -26,12 +26,11 @@
|
|||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "conf.h"
|
||||||
static hashmap_t anonymous_map = NULL;
|
|
||||||
|
|
||||||
short int is_anonymous_enabled (void)
|
short int is_anonymous_enabled (void)
|
||||||
{
|
{
|
||||||
return (anonymous_map != NULL) ? 1 : 0;
|
return (config.anonymous_map != NULL) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -41,9 +40,9 @@ short int is_anonymous_enabled (void)
|
|||||||
int anonymous_search (const char *s)
|
int anonymous_search (const char *s)
|
||||||
{
|
{
|
||||||
assert (s != NULL);
|
assert (s != NULL);
|
||||||
assert (anonymous_map != NULL);
|
assert (config.anonymous_map != NULL);
|
||||||
|
|
||||||
return hashmap_search (anonymous_map, s);
|
return hashmap_search (config.anonymous_map, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -58,17 +57,17 @@ int anonymous_insert (const char *s)
|
|||||||
|
|
||||||
assert (s != NULL);
|
assert (s != NULL);
|
||||||
|
|
||||||
if (!anonymous_map) {
|
if (!config.anonymous_map) {
|
||||||
anonymous_map = hashmap_create (32);
|
config.anonymous_map = hashmap_create (32);
|
||||||
if (!anonymous_map)
|
if (!config.anonymous_map)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashmap_search (anonymous_map, s) > 0) {
|
if (hashmap_search (config.anonymous_map, s) > 0) {
|
||||||
/* The key was already found, so return a positive number. */
|
/* The key was already found, so return a positive number. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert the new key */
|
/* Insert the new key */
|
||||||
return hashmap_insert (anonymous_map, s, &data, sizeof (data));
|
return hashmap_insert (config.anonymous_map, s, &data, sizeof (data));
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
+167
-18
@@ -30,9 +30,9 @@
|
|||||||
#include "reqs.h"
|
#include "reqs.h"
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
static int listenfd;
|
static vector_t listen_fds;
|
||||||
static socklen_t addrlen;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stores the internal data needed for each child (connection)
|
* Stores the internal data needed for each child (connection)
|
||||||
@@ -160,6 +160,24 @@ short int child_configure (child_config_t type, unsigned int val)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* child signal handler for sighup
|
||||||
|
*/
|
||||||
|
static void child_sighup_handler (int sig)
|
||||||
|
{
|
||||||
|
if (sig == SIGHUP) {
|
||||||
|
/*
|
||||||
|
* Ignore the return value of reload_config for now.
|
||||||
|
* This should actually be handled somehow...
|
||||||
|
*/
|
||||||
|
reload_config ();
|
||||||
|
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
filter_reload ();
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the main (per child) loop.
|
* This is the main (per child) loop.
|
||||||
*/
|
*/
|
||||||
@@ -168,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.");
|
||||||
@@ -177,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);
|
||||||
|
|
||||||
@@ -272,7 +366,7 @@ static pid_t child_make (struct child_s *ptr)
|
|||||||
*/
|
*/
|
||||||
set_signal_handler (SIGCHLD, SIG_DFL);
|
set_signal_handler (SIGCHLD, SIG_DFL);
|
||||||
set_signal_handler (SIGTERM, SIG_DFL);
|
set_signal_handler (SIGTERM, SIG_DFL);
|
||||||
set_signal_handler (SIGHUP, SIG_DFL);
|
set_signal_handler (SIGHUP, child_sighup_handler);
|
||||||
|
|
||||||
child_main (ptr); /* never returns */
|
child_main (ptr); /* never returns */
|
||||||
return -1;
|
return -1;
|
||||||
@@ -414,17 +508,19 @@ void child_main_loop (void)
|
|||||||
|
|
||||||
/* Handle log rotation if it was requested */
|
/* Handle log rotation if it was requested */
|
||||||
if (received_sighup) {
|
if (received_sighup) {
|
||||||
truncate_log_file ();
|
/*
|
||||||
|
* Ignore the return value of reload_config for now.
|
||||||
|
* This should actually be handled somehow...
|
||||||
|
*/
|
||||||
|
reload_config ();
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
if (config.filter) {
|
filter_reload ();
|
||||||
log_message (LOG_NOTICE,
|
|
||||||
"Re-reading filter file.");
|
|
||||||
filter_destroy ();
|
|
||||||
filter_init ();
|
|
||||||
}
|
|
||||||
#endif /* FILTER_ENABLE */
|
#endif /* FILTER_ENABLE */
|
||||||
|
|
||||||
|
/* propagate filter reload to all children */
|
||||||
|
child_kill_children (SIGHUP);
|
||||||
|
|
||||||
received_sighup = FALSE;
|
received_sighup = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,23 +529,76 @@ void child_main_loop (void)
|
|||||||
/*
|
/*
|
||||||
* Go through all the non-empty children and cancel them.
|
* Go through all the non-empty children and cancel them.
|
||||||
*/
|
*/
|
||||||
void child_kill_children (void)
|
void child_kill_children (int sig)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i != child_config.maxclients; i++) {
|
for (i = 0; i != child_config.maxclients; i++) {
|
||||||
if (child_ptr[i].status != T_EMPTY)
|
if (child_ptr[i].status != T_EMPTY)
|
||||||
kill (child_ptr[i].tid, SIGTERM);
|
kill (child_ptr[i].tid, sig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int child_listening_sock (uint16_t port)
|
|
||||||
|
/**
|
||||||
|
* Listen on the various configured interfaces
|
||||||
|
*/
|
||||||
|
int child_listening_sockets(vector_t listen_addrs, uint16_t port)
|
||||||
{
|
{
|
||||||
listenfd = listen_sock (port, &addrlen);
|
int ret;
|
||||||
return listenfd;
|
ssize_t i;
|
||||||
|
|
||||||
|
assert (port > 0);
|
||||||
|
|
||||||
|
if (listen_fds == NULL) {
|
||||||
|
listen_fds = vector_create();
|
||||||
|
if (listen_fds == NULL) {
|
||||||
|
log_message (LOG_ERR, "Could not create the list "
|
||||||
|
"of listening fds");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
+4
-2
@@ -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,10 +32,10 @@ typedef enum {
|
|||||||
} child_config_t;
|
} child_config_t;
|
||||||
|
|
||||||
extern short int child_pool_create (void);
|
extern short int child_pool_create (void);
|
||||||
extern int child_listening_sock (uint16_t port);
|
extern int child_listening_sockets (vector_t listen_addrs, uint16_t port);
|
||||||
extern void child_close_sock (void);
|
extern void child_close_sock (void);
|
||||||
extern void child_main_loop (void);
|
extern void child_main_loop (void);
|
||||||
extern void child_kill_children (void);
|
extern void child_kill_children (int sig);
|
||||||
|
|
||||||
extern short int child_configure (child_config_t type, unsigned int val);
|
extern short int child_configure (child_config_t type, unsigned int val);
|
||||||
|
|
||||||
|
|||||||
+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
|
||||||
|
|||||||
+467
-68
@@ -1,5 +1,6 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
|
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -22,8 +23,6 @@
|
|||||||
* add new directives to. Who knows if I'm right though.
|
* add new directives to. Who knows if I'm right though.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
#include "acl.h"
|
#include "acl.h"
|
||||||
@@ -35,6 +34,9 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "reqs.h"
|
#include "reqs.h"
|
||||||
#include "reverse-proxy.h"
|
#include "reverse-proxy.h"
|
||||||
|
#include "upstream.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
|
||||||
@@ -52,6 +54,28 @@
|
|||||||
#define ALNUM "([-a-z0-9._]+)"
|
#define ALNUM "([-a-z0-9._]+)"
|
||||||
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
|
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
|
||||||
#define IPMASK "(" IP "(/[[:digit:]]+)?)"
|
#define IPMASK "(" IP "(/[[:digit:]]+)?)"
|
||||||
|
#define IPV6 "(" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,6})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,6}(:[0-9a-f]{1,4}){1,1})|" \
|
||||||
|
"((([0-9a-f]{1,4}:){1,7}|:):)|" \
|
||||||
|
"(:(:[0-9a-f]{1,4}){1,7})|" \
|
||||||
|
"([0-9a-f]{1,4}(:[0-9a-f]{1,4}){1,7})|" \
|
||||||
|
"(((([0-9a-f]{1,4}:){6})(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}))|" \
|
||||||
|
"((([0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}))|" \
|
||||||
|
"(([0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,4}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,3}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,2}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
|
||||||
|
"(([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,1}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
|
||||||
|
"((([0-9a-f]{1,4}:){1,5}|:):(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})|" \
|
||||||
|
"(:(:[0-9a-f]{1,4}){1,5}:(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3})" \
|
||||||
|
")"
|
||||||
|
|
||||||
|
#define IPV6MASK "(" IPV6 "(/[[:digit:]]+)?)"
|
||||||
#define BEGIN "^[[:space:]]*"
|
#define BEGIN "^[[:space:]]*"
|
||||||
#define END "[[:space:]]*$"
|
#define END "[[:space:]]*$"
|
||||||
|
|
||||||
@@ -93,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);
|
||||||
@@ -100,6 +125,7 @@ static HANDLE_FUNC (handle_connectport);
|
|||||||
static HANDLE_FUNC (handle_defaulterrorfile);
|
static HANDLE_FUNC (handle_defaulterrorfile);
|
||||||
static HANDLE_FUNC (handle_deny);
|
static HANDLE_FUNC (handle_deny);
|
||||||
static HANDLE_FUNC (handle_errorfile);
|
static HANDLE_FUNC (handle_errorfile);
|
||||||
|
static HANDLE_FUNC (handle_addheader);
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
static HANDLE_FUNC (handle_filter);
|
static HANDLE_FUNC (handle_filter);
|
||||||
static HANDLE_FUNC (handle_filtercasesensitive);
|
static HANDLE_FUNC (handle_filtercasesensitive);
|
||||||
@@ -131,6 +157,7 @@ static HANDLE_FUNC (handle_timeout);
|
|||||||
|
|
||||||
static HANDLE_FUNC (handle_user);
|
static HANDLE_FUNC (handle_user);
|
||||||
static HANDLE_FUNC (handle_viaproxyname);
|
static HANDLE_FUNC (handle_viaproxyname);
|
||||||
|
static HANDLE_FUNC (handle_disableviaheader);
|
||||||
static HANDLE_FUNC (handle_xtinyproxy);
|
static HANDLE_FUNC (handle_xtinyproxy);
|
||||||
|
|
||||||
#ifdef UPSTREAM_SUPPORT
|
#ifdef UPSTREAM_SUPPORT
|
||||||
@@ -138,6 +165,8 @@ static HANDLE_FUNC (handle_upstream);
|
|||||||
static HANDLE_FUNC (handle_upstream_no);
|
static HANDLE_FUNC (handle_upstream_no);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void config_free_regex (void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This macro can be used to make standard directives in the form:
|
* This macro can be used to make standard directives in the form:
|
||||||
* directive arguments [arguments ...]
|
* directive arguments [arguments ...]
|
||||||
@@ -182,6 +211,7 @@ struct {
|
|||||||
/* boolean arguments */
|
/* boolean arguments */
|
||||||
STDCONF ("syslog", BOOL, handle_syslog),
|
STDCONF ("syslog", BOOL, handle_syslog),
|
||||||
STDCONF ("bindsame", BOOL, handle_bindsame),
|
STDCONF ("bindsame", BOOL, handle_bindsame),
|
||||||
|
STDCONF ("disableviaheader", BOOL, handle_disableviaheader),
|
||||||
/* integer arguments */
|
/* integer arguments */
|
||||||
STDCONF ("port", INT, handle_port),
|
STDCONF ("port", INT, handle_port),
|
||||||
STDCONF ("maxclients", INT, handle_maxclients),
|
STDCONF ("maxclients", INT, handle_maxclients),
|
||||||
@@ -195,12 +225,17 @@ struct {
|
|||||||
STDCONF ("user", ALNUM, handle_user),
|
STDCONF ("user", ALNUM, handle_user),
|
||||||
STDCONF ("group", ALNUM, handle_group),
|
STDCONF ("group", ALNUM, handle_group),
|
||||||
/* ip arguments */
|
/* ip arguments */
|
||||||
STDCONF ("listen", IP, handle_listen),
|
STDCONF ("listen", "(" IP "|" IPV6 ")", handle_listen),
|
||||||
STDCONF ("allow", "(" IPMASK "|" ALNUM ")", handle_allow),
|
STDCONF ("allow", "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
|
||||||
STDCONF ("deny", "(" IPMASK "|" ALNUM ")", handle_deny),
|
handle_allow),
|
||||||
STDCONF ("bind", IP, handle_bind),
|
STDCONF ("deny", "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
|
||||||
/* error files */
|
handle_deny),
|
||||||
|
STDCONF ("bind", "(" IP "|" IPV6 ")", handle_bind),
|
||||||
|
/* 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),
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
#ifdef FILTER_ENABLE
|
||||||
/* filtering */
|
/* filtering */
|
||||||
STDCONF ("filter", STR, handle_filter),
|
STDCONF ("filter", STR, handle_filter),
|
||||||
@@ -214,16 +249,18 @@ struct {
|
|||||||
STDCONF ("reversebaseurl", STR, handle_reversebaseurl),
|
STDCONF ("reversebaseurl", STR, handle_reversebaseurl),
|
||||||
STDCONF ("reverseonly", BOOL, handle_reverseonly),
|
STDCONF ("reverseonly", BOOL, handle_reverseonly),
|
||||||
STDCONF ("reversemagic", BOOL, handle_reversemagic),
|
STDCONF ("reversemagic", BOOL, handle_reversemagic),
|
||||||
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 */
|
||||||
@@ -233,13 +270,63 @@ struct {
|
|||||||
|
|
||||||
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
|
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_added_headers (vector_t add_headers)
|
||||||
|
{
|
||||||
|
ssize_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < vector_length (add_headers); i++) {
|
||||||
|
http_header_t *header = (http_header_t *)
|
||||||
|
vector_getentry (add_headers, i, NULL);
|
||||||
|
|
||||||
|
safefree (header->name);
|
||||||
|
safefree (header->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector_delete (add_headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void free_config (struct config_s *conf)
|
||||||
|
{
|
||||||
|
safefree (conf->config_file);
|
||||||
|
safefree (conf->logf_name);
|
||||||
|
safefree (conf->stathost);
|
||||||
|
safefree (conf->user);
|
||||||
|
safefree (conf->group);
|
||||||
|
vector_delete(conf->listen_addrs);
|
||||||
|
vector_delete(conf->basicauth_list);
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
safefree (conf->filter);
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
#ifdef REVERSE_SUPPORT
|
||||||
|
free_reversepath_list(conf->reversepath_list);
|
||||||
|
safefree (conf->reversebaseurl);
|
||||||
|
#endif
|
||||||
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
free_upstream_list (conf->upstream_list);
|
||||||
|
#endif /* UPSTREAM_SUPPORT */
|
||||||
|
safefree (conf->pidpath);
|
||||||
|
safefree (conf->bind_address);
|
||||||
|
safefree (conf->via_proxy_name);
|
||||||
|
hashmap_delete (conf->errorpages);
|
||||||
|
free_added_headers (conf->add_headers);
|
||||||
|
safefree (conf->errorpage_undef);
|
||||||
|
safefree (conf->statpage);
|
||||||
|
flush_access_list (conf->access_list);
|
||||||
|
free_connect_ports_list (conf->connect_ports);
|
||||||
|
hashmap_delete (conf->anonymous_map);
|
||||||
|
|
||||||
|
memset (conf, 0, sizeof(*conf));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compiles the regular expressions used by the configuration file. This
|
* Compiles the regular expressions used by the configuration file. This
|
||||||
* routine MUST be called before trying to parse the configuration file.
|
* routine MUST be called before trying to parse the configuration file.
|
||||||
*
|
*
|
||||||
* Returns 0 on success; negative upon failure.
|
* Returns 0 on success; negative upon failure.
|
||||||
*/
|
*/
|
||||||
int config_compile (void)
|
int
|
||||||
|
config_compile_regex (void)
|
||||||
{
|
{
|
||||||
unsigned int i, r;
|
unsigned int i, r;
|
||||||
|
|
||||||
@@ -257,9 +344,30 @@ int config_compile (void)
|
|||||||
if (r)
|
if (r)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atexit (config_free_regex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Frees pre-compiled regular expressions used by the configuration
|
||||||
|
* file. This function is registered to be automatically called at exit.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
config_free_regex (void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ndirectives; i++) {
|
||||||
|
if (directives[i].cre) {
|
||||||
|
regfree (directives[i].cre);
|
||||||
|
safefree (directives[i].cre);
|
||||||
|
directives[i].cre = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attempt to match the supplied line with any of the configuration
|
* Attempt to match the supplied line with any of the configuration
|
||||||
* regexes defined above. If a match is found, call the handler
|
* regexes defined above. If a match is found, call the handler
|
||||||
@@ -288,7 +396,7 @@ static int check_match (struct config_s *conf, const char *line)
|
|||||||
/*
|
/*
|
||||||
* Parse the previously opened configuration stream.
|
* Parse the previously opened configuration stream.
|
||||||
*/
|
*/
|
||||||
int config_parse (struct config_s *conf, FILE * f)
|
static int config_parse (struct config_s *conf, FILE * f)
|
||||||
{
|
{
|
||||||
char buffer[1024]; /* 1KB lines should be plenty */
|
char buffer[1024]; /* 1KB lines should be plenty */
|
||||||
unsigned long lineno = 1;
|
unsigned long lineno = 1;
|
||||||
@@ -303,6 +411,187 @@ int config_parse (struct config_s *conf, FILE * f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the settings from a config file.
|
||||||
|
*/
|
||||||
|
static int load_config_file (const char *config_fname, struct config_s *conf)
|
||||||
|
{
|
||||||
|
FILE *config_file;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
config_file = fopen (config_fname, "r");
|
||||||
|
if (!config_file) {
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: Could not open config file \"%s\".\n",
|
||||||
|
PACKAGE, config_fname);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config_parse (conf, config_file)) {
|
||||||
|
fprintf (stderr, "Unable to parse config file. "
|
||||||
|
"Not starting.\n");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (config_file)
|
||||||
|
fclose (config_file);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initialize_with_defaults (struct config_s *conf,
|
||||||
|
struct config_s *defaults)
|
||||||
|
{
|
||||||
|
if (defaults->logf_name) {
|
||||||
|
conf->logf_name = safestrdup (defaults->logf_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaults->config_file) {
|
||||||
|
conf->config_file = safestrdup (defaults->config_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->syslog = defaults->syslog;
|
||||||
|
conf->port = defaults->port;
|
||||||
|
|
||||||
|
if (defaults->stathost) {
|
||||||
|
conf->stathost = safestrdup (defaults->stathost);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->godaemon = defaults->godaemon;
|
||||||
|
conf->quit = defaults->quit;
|
||||||
|
|
||||||
|
if (defaults->user) {
|
||||||
|
conf->user = safestrdup (defaults->user);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaults->group) {
|
||||||
|
conf->group = safestrdup (defaults->group);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaults->listen_addrs) {
|
||||||
|
ssize_t i;
|
||||||
|
|
||||||
|
conf->listen_addrs = vector_create();
|
||||||
|
for (i=0; i < vector_length(defaults->listen_addrs); i++) {
|
||||||
|
char *addr;
|
||||||
|
size_t size;
|
||||||
|
addr = (char *)vector_getentry(defaults->listen_addrs,
|
||||||
|
i, &size);
|
||||||
|
vector_append(conf->listen_addrs, addr, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
if (defaults->filter) {
|
||||||
|
conf->filter = safestrdup (defaults->filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->filter_url = defaults->filter_url;
|
||||||
|
conf->filter_extended = defaults->filter_extended;
|
||||||
|
conf->filter_casesensitive = defaults->filter_casesensitive;
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
|
||||||
|
#ifdef XTINYPROXY_ENABLE
|
||||||
|
conf->add_xtinyproxy = defaults->add_xtinyproxy;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef REVERSE_SUPPORT
|
||||||
|
/* struct reversepath *reversepath_list; */
|
||||||
|
conf->reverseonly = defaults->reverseonly;
|
||||||
|
conf->reversemagic = defaults->reversemagic;
|
||||||
|
|
||||||
|
if (defaults->reversebaseurl) {
|
||||||
|
conf->reversebaseurl = safestrdup (defaults->reversebaseurl);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
/* struct upstream *upstream_list; */
|
||||||
|
#endif /* UPSTREAM_SUPPORT */
|
||||||
|
|
||||||
|
if (defaults->pidpath) {
|
||||||
|
conf->pidpath = safestrdup (defaults->pidpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->idletimeout = defaults->idletimeout;
|
||||||
|
|
||||||
|
if (defaults->bind_address) {
|
||||||
|
conf->bind_address = safestrdup (defaults->bind_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->bindsame = defaults->bindsame;
|
||||||
|
|
||||||
|
if (defaults->via_proxy_name) {
|
||||||
|
conf->via_proxy_name = safestrdup (defaults->via_proxy_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->disable_viaheader = defaults->disable_viaheader;
|
||||||
|
|
||||||
|
if (defaults->errorpage_undef) {
|
||||||
|
conf->errorpage_undef = safestrdup (defaults->errorpage_undef);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaults->statpage) {
|
||||||
|
conf->statpage = safestrdup (defaults->statpage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vector_t access_list; */
|
||||||
|
/* vector_t connect_ports; */
|
||||||
|
/* hashmap_t anonymous_map; */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the configuration.
|
||||||
|
*/
|
||||||
|
int reload_config_file (const char *config_fname, struct config_s *conf,
|
||||||
|
struct config_s *defaults)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
log_message (LOG_INFO, "Reloading config file");
|
||||||
|
|
||||||
|
free_config (conf);
|
||||||
|
|
||||||
|
initialize_with_defaults (conf, defaults);
|
||||||
|
|
||||||
|
ret = load_config_file (config_fname, conf);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the default values if they were not set in the config file. */
|
||||||
|
if (conf->port == 0) {
|
||||||
|
/*
|
||||||
|
* Don't log here in error path:
|
||||||
|
* logging might not be set up yet!
|
||||||
|
*/
|
||||||
|
fprintf (stderr, PACKAGE ": You MUST set a Port in the "
|
||||||
|
"config file.\n");
|
||||||
|
ret = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!conf->user) {
|
||||||
|
log_message (LOG_WARNING, "You SHOULD set a UserName in the "
|
||||||
|
"config file. Using current user instead.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conf->idletimeout == 0) {
|
||||||
|
log_message (LOG_WARNING, "Invalid idle time setting. "
|
||||||
|
"Only values greater than zero are allowed. "
|
||||||
|
"Therefore setting idle timeout to %u seconds.",
|
||||||
|
MAX_IDLE_TIME);
|
||||||
|
conf->idletimeout = MAX_IDLE_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* The following are basic data extraction building blocks that can
|
* The following are basic data extraction building blocks that can
|
||||||
@@ -333,9 +622,14 @@ static int set_string_arg (char **var, const char *line, regmatch_t * match)
|
|||||||
|
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return -1;
|
return -1;
|
||||||
*var = safestrdup (arg);
|
|
||||||
safefree (arg);
|
if (*var != NULL) {
|
||||||
return *var ? 0 : -1;
|
safefree (*var);
|
||||||
|
}
|
||||||
|
|
||||||
|
*var = arg;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_bool_arg (const char *line, regmatch_t * match)
|
static int get_bool_arg (const char *line, regmatch_t * match)
|
||||||
@@ -363,8 +657,8 @@ set_bool_arg (unsigned int *var, const char *line, regmatch_t * match)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long int
|
static unsigned long
|
||||||
get_int_arg (const char *line, regmatch_t * match)
|
get_long_arg (const char *line, regmatch_t * match)
|
||||||
{
|
{
|
||||||
assert (line);
|
assert (line);
|
||||||
assert (match && match->rm_so != -1);
|
assert (match && match->rm_so != -1);
|
||||||
@@ -373,13 +667,13 @@ get_int_arg (const char *line, regmatch_t * match)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
set_int_arg (unsigned long int *var, const char *line, regmatch_t * match)
|
set_int_arg (unsigned int *var, const char *line, regmatch_t * match)
|
||||||
{
|
{
|
||||||
assert (var);
|
assert (var);
|
||||||
assert (line);
|
assert (line);
|
||||||
assert (match);
|
assert (match);
|
||||||
|
|
||||||
*var = get_int_arg (line, match);
|
*var = (unsigned int) get_long_arg (line, match);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,11 +724,24 @@ static HANDLE_FUNC (handle_viaproxyname)
|
|||||||
if (r)
|
if (r)
|
||||||
return r;
|
return r;
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"Setting \"Via\" header proxy to %s",
|
"Setting \"Via\" header to '%s'",
|
||||||
conf->via_proxy_name);
|
conf->via_proxy_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HANDLE_FUNC (handle_disableviaheader)
|
||||||
|
{
|
||||||
|
int r = set_bool_arg (&conf->disable_viaheader, line, &match[2]);
|
||||||
|
|
||||||
|
if (r) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message (LOG_INFO,
|
||||||
|
"Disabling transmission of the \"Via\" header.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_defaulterrorfile)
|
static HANDLE_FUNC (handle_defaulterrorfile)
|
||||||
{
|
{
|
||||||
return set_string_arg (&conf->errorpage_undef, line, &match[2]);
|
return set_string_arg (&conf->errorpage_undef, line, &match[2]);
|
||||||
@@ -468,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)
|
||||||
@@ -488,49 +790,59 @@ static HANDLE_FUNC (handle_bindsame)
|
|||||||
|
|
||||||
static HANDLE_FUNC (handle_port)
|
static HANDLE_FUNC (handle_port)
|
||||||
{
|
{
|
||||||
return set_int_arg ((unsigned long int *) &conf->port, line, &match[2]);
|
set_int_arg (&conf->port, line, &match[2]);
|
||||||
|
|
||||||
|
if (conf->port > 65535) {
|
||||||
|
fprintf (stderr, "Bad port number (%d) supplied for Port.\n",
|
||||||
|
conf->port);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_maxclients)
|
static HANDLE_FUNC (handle_maxclients)
|
||||||
{
|
{
|
||||||
child_configure (CHILD_MAXCLIENTS, get_int_arg (line, &match[2]));
|
child_configure (CHILD_MAXCLIENTS, get_long_arg (line, &match[2]));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_maxspareservers)
|
static HANDLE_FUNC (handle_maxspareservers)
|
||||||
{
|
{
|
||||||
child_configure (CHILD_MAXSPARESERVERS, get_int_arg (line, &match[2]));
|
child_configure (CHILD_MAXSPARESERVERS,
|
||||||
|
get_long_arg (line, &match[2]));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_minspareservers)
|
static HANDLE_FUNC (handle_minspareservers)
|
||||||
{
|
{
|
||||||
child_configure (CHILD_MINSPARESERVERS, get_int_arg (line, &match[2]));
|
child_configure (CHILD_MINSPARESERVERS,
|
||||||
|
get_long_arg (line, &match[2]));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_startservers)
|
static HANDLE_FUNC (handle_startservers)
|
||||||
{
|
{
|
||||||
child_configure (CHILD_STARTSERVERS, get_int_arg (line, &match[2]));
|
child_configure (CHILD_STARTSERVERS, get_long_arg (line, &match[2]));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_maxrequestsperchild)
|
static HANDLE_FUNC (handle_maxrequestsperchild)
|
||||||
{
|
{
|
||||||
child_configure (CHILD_MAXREQUESTSPERCHILD,
|
child_configure (CHILD_MAXREQUESTSPERCHILD,
|
||||||
get_int_arg (line, &match[2]));
|
get_long_arg (line, &match[2]));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_timeout)
|
static HANDLE_FUNC (handle_timeout)
|
||||||
{
|
{
|
||||||
return set_int_arg ((unsigned long int *) &conf->idletimeout, line,
|
return set_int_arg (&conf->idletimeout, line, &match[2]);
|
||||||
&match[2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE_FUNC (handle_connectport)
|
static HANDLE_FUNC (handle_connectport)
|
||||||
{
|
{
|
||||||
add_connect_port_allowed (get_int_arg (line, &match[2]));
|
add_connect_port_allowed (get_long_arg (line, &match[2]),
|
||||||
|
&conf->connect_ports);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,7 +860,7 @@ static HANDLE_FUNC (handle_allow)
|
|||||||
{
|
{
|
||||||
char *arg = get_string_arg (line, &match[2]);
|
char *arg = get_string_arg (line, &match[2]);
|
||||||
|
|
||||||
insert_acl (arg, ACL_ALLOW);
|
insert_acl (arg, ACL_ALLOW, &conf->access_list);
|
||||||
safefree (arg);
|
safefree (arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -557,14 +869,13 @@ static HANDLE_FUNC (handle_deny)
|
|||||||
{
|
{
|
||||||
char *arg = get_string_arg (line, &match[2]);
|
char *arg = get_string_arg (line, &match[2]);
|
||||||
|
|
||||||
insert_acl (arg, ACL_DENY);
|
insert_acl (arg, ACL_DENY, &conf->access_list);
|
||||||
safefree (arg);
|
safefree (arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -572,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, "Listing 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,7 +920,7 @@ static HANDLE_FUNC (handle_errorfile)
|
|||||||
* present. This is why the "string" is located at
|
* present. This is why the "string" is located at
|
||||||
* match[4] (rather than the more intuitive match[3].
|
* match[4] (rather than the more intuitive match[3].
|
||||||
*/
|
*/
|
||||||
unsigned long int err = get_int_arg (line, &match[2]);
|
unsigned long int err = get_long_arg (line, &match[2]);
|
||||||
char *page = get_string_arg (line, &match[4]);
|
char *page = get_string_arg (line, &match[4]);
|
||||||
|
|
||||||
add_new_errorpage (page, err);
|
add_new_errorpage (page, err);
|
||||||
@@ -606,8 +928,33 @@ static HANDLE_FUNC (handle_errorfile)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HANDLE_FUNC (handle_addheader)
|
||||||
|
{
|
||||||
|
char *name = get_string_arg (line, &match[2]);
|
||||||
|
char *value = get_string_arg (line, &match[3]);
|
||||||
|
http_header_t *header;
|
||||||
|
|
||||||
|
if (!conf->add_headers) {
|
||||||
|
conf->add_headers = vector_create ();
|
||||||
|
}
|
||||||
|
|
||||||
|
header = (http_header_t *) safemalloc (sizeof (http_header_t));
|
||||||
|
header->name = name;
|
||||||
|
header->value = value;
|
||||||
|
|
||||||
|
vector_prepend (conf->add_headers, header, sizeof *header);
|
||||||
|
|
||||||
|
safefree (header);
|
||||||
|
|
||||||
|
/* Don't free name or value here, as they are referenced in the
|
||||||
|
* struct inserted into the vector. */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Log level's strings.
|
* Log level's strings.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
struct log_levels_s {
|
struct log_levels_s {
|
||||||
const char *string;
|
const char *string;
|
||||||
@@ -642,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)
|
||||||
{
|
{
|
||||||
@@ -700,17 +1068,17 @@ static HANDLE_FUNC (handle_reversepath)
|
|||||||
if (!arg1)
|
if (!arg1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (match[3].rm_so != -1) {
|
if (match[4].rm_so != -1) {
|
||||||
arg2 = get_string_arg (line, &match[3]);
|
arg2 = get_string_arg (line, &match[4]);
|
||||||
if (!arg2) {
|
if (!arg2) {
|
||||||
safefree (arg1);
|
safefree (arg1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
reversepath_add (arg1, arg2);
|
reversepath_add (arg1, arg2, &conf->reversepath_list);
|
||||||
safefree (arg1);
|
safefree (arg1);
|
||||||
safefree (arg2);
|
safefree (arg2);
|
||||||
} else {
|
} else {
|
||||||
reversepath_add (NULL, arg1);
|
reversepath_add (NULL, arg1, &conf->reversepath_list);
|
||||||
safefree (arg1);
|
safefree (arg1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -718,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_int_arg (line, &match[7]);
|
mi += 5;
|
||||||
|
|
||||||
if (match[9].rm_so != -1) {
|
port = (int) get_long_arg (line, &match[mi]);
|
||||||
domain = get_string_arg (line, &match[9]);
|
mi += 3;
|
||||||
if (domain) {
|
|
||||||
upstream_add (ip, port, domain);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (ip);
|
safefree (ip);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -748,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);
|
upstream_add (NULL, 0, domain, 0, 0, PT_NONE, &conf->upstream_list);
|
||||||
safefree (domain);
|
safefree (domain);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+96
-2
@@ -1,5 +1,6 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
|
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,7 +22,100 @@
|
|||||||
#ifndef TINYPROXY_CONF_H
|
#ifndef TINYPROXY_CONF_H
|
||||||
#define TINYPROXY_CONF_H
|
#define TINYPROXY_CONF_H
|
||||||
|
|
||||||
extern int config_compile (void);
|
#include "hashmap.h"
|
||||||
extern int config_parse (struct config_s *conf, FILE * f);
|
#include "vector.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stores a HTTP header created using the AddHeader directive.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
char *value;
|
||||||
|
} http_header_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hold all the configuration time information.
|
||||||
|
*/
|
||||||
|
struct config_s {
|
||||||
|
vector_t basicauth_list;
|
||||||
|
char *logf_name;
|
||||||
|
char *config_file;
|
||||||
|
unsigned int syslog; /* boolean */
|
||||||
|
unsigned int port;
|
||||||
|
char *stathost;
|
||||||
|
unsigned int godaemon; /* boolean */
|
||||||
|
unsigned int quit; /* boolean */
|
||||||
|
char *user;
|
||||||
|
char *group;
|
||||||
|
vector_t listen_addrs;
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
char *filter;
|
||||||
|
unsigned int filter_url; /* boolean */
|
||||||
|
unsigned int filter_extended; /* boolean */
|
||||||
|
unsigned int filter_casesensitive; /* boolean */
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
#ifdef XTINYPROXY_ENABLE
|
||||||
|
unsigned int add_xtinyproxy; /* boolean */
|
||||||
|
#endif
|
||||||
|
#ifdef REVERSE_SUPPORT
|
||||||
|
struct reversepath *reversepath_list;
|
||||||
|
unsigned int reverseonly; /* boolean */
|
||||||
|
unsigned int reversemagic; /* boolean */
|
||||||
|
char *reversebaseurl;
|
||||||
|
#endif
|
||||||
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
struct upstream *upstream_list;
|
||||||
|
#endif /* UPSTREAM_SUPPORT */
|
||||||
|
char *pidpath;
|
||||||
|
unsigned int idletimeout;
|
||||||
|
char *bind_address;
|
||||||
|
unsigned int bindsame;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The configured name to use in the HTTP "Via" header field.
|
||||||
|
*/
|
||||||
|
char *via_proxy_name;
|
||||||
|
|
||||||
|
unsigned int disable_viaheader; /* boolean */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Error page support. Map error numbers to file paths.
|
||||||
|
*/
|
||||||
|
hashmap_t errorpages;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Error page to be displayed if appropriate page cannot be located
|
||||||
|
* in the errorpages structure.
|
||||||
|
*/
|
||||||
|
char *errorpage_undef;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The HTML statistics page.
|
||||||
|
*/
|
||||||
|
char *statpage;
|
||||||
|
|
||||||
|
vector_t access_list;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Store the list of port allowed by CONNECT.
|
||||||
|
*/
|
||||||
|
vector_t connect_ports;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Map of headers which should be let through when the
|
||||||
|
* anonymous feature is turned on.
|
||||||
|
*/
|
||||||
|
hashmap_t anonymous_map;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Extra headers to be added to outgoing HTTP requests.
|
||||||
|
*/
|
||||||
|
vector_t add_headers;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern int reload_config_file (const char *config_fname, struct config_s *conf,
|
||||||
|
struct config_s *defaults);
|
||||||
|
|
||||||
|
int config_compile_regex (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
||||||
|
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "connect-ports.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now, this routine adds a "port" to the list. It also creates the list if
|
||||||
|
* it hasn't already by done.
|
||||||
|
*/
|
||||||
|
void add_connect_port_allowed (int port, vector_t *connect_ports)
|
||||||
|
{
|
||||||
|
if (!*connect_ports) {
|
||||||
|
*connect_ports = vector_create ();
|
||||||
|
if (!*connect_ports) {
|
||||||
|
log_message (LOG_WARNING,
|
||||||
|
"Could not create a list of allowed CONNECT ports");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message (LOG_INFO,
|
||||||
|
"Adding Port [%d] to the list allowed by CONNECT", port);
|
||||||
|
vector_append (*connect_ports, &port, sizeof (port));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This routine checks to see if a port is allowed in the CONNECT method.
|
||||||
|
*
|
||||||
|
* Returns: 1 if allowed
|
||||||
|
* 0 if denied
|
||||||
|
*/
|
||||||
|
int check_allowed_connect_ports (int port, vector_t connect_ports)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int *data;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The absence of ConnectPort options in the config file
|
||||||
|
* meanas that all ports are allowed for CONNECT.
|
||||||
|
*/
|
||||||
|
if (!connect_ports)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
for (i = 0; i != (size_t) vector_length (connect_ports); ++i) {
|
||||||
|
data = (int *) vector_getentry (connect_ports, i, NULL);
|
||||||
|
if (data && *data == port)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free a connect_ports list.
|
||||||
|
*/
|
||||||
|
void free_connect_ports_list (vector_t connect_ports)
|
||||||
|
{
|
||||||
|
vector_delete (connect_ports);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
||||||
|
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TINYPROXY_CONNECT_PORTS_H_
|
||||||
|
#define _TINYPROXY_CONNECT_PORTS_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
|
extern void add_connect_port_allowed (int port, vector_t *connect_ports);
|
||||||
|
int check_allowed_connect_ports (int port, vector_t connect_ports);
|
||||||
|
void free_connect_ports_list (vector_t connect_ports);
|
||||||
|
|
||||||
|
#endif /* _TINYPROXY_CONNECT_PORTS_ */
|
||||||
+2
-1
@@ -76,7 +76,8 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
|
|||||||
/* There is _no_ content length initially */
|
/* There is _no_ content length initially */
|
||||||
connptr->content_length.server = connptr->content_length.client = -1;
|
connptr->content_length.server = connptr->content_length.client = -1;
|
||||||
|
|
||||||
connptr->server_ip_addr = sock_ipaddr ? safestrdup (sock_ipaddr) : 0;
|
connptr->server_ip_addr = (sock_ipaddr ?
|
||||||
|
safestrdup (sock_ipaddr) : NULL);
|
||||||
connptr->client_ip_addr = safestrdup (ipaddr);
|
connptr->client_ip_addr = safestrdup (ipaddr);
|
||||||
connptr->client_string_addr = safestrdup (string_addr);
|
connptr->client_string_addr = safestrdup (string_addr);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ void makedaemon (void)
|
|||||||
|
|
||||||
umask (0177);
|
umask (0177);
|
||||||
|
|
||||||
#if NDEBUG
|
#ifdef NDEBUG
|
||||||
/*
|
/*
|
||||||
* When not in debugging mode, close the standard file
|
* When not in debugging mode, close the standard file
|
||||||
* descriptors.
|
* descriptors.
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "reqs.h"
|
#include "reqs.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
#define FILTER_BUFFER_LEN (512)
|
#define FILTER_BUFFER_LEN (512)
|
||||||
|
|
||||||
@@ -150,6 +151,18 @@ void filter_destroy (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reload the filter file if filtering is enabled
|
||||||
|
*/
|
||||||
|
void filter_reload (void)
|
||||||
|
{
|
||||||
|
if (config.filter) {
|
||||||
|
log_message (LOG_NOTICE, "Re-reading filter file.");
|
||||||
|
filter_destroy ();
|
||||||
|
filter_init ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Return 0 to allow, non-zero to block */
|
/* Return 0 to allow, non-zero to block */
|
||||||
int filter_domain (const char *host)
|
int filter_domain (const char *host)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ typedef enum {
|
|||||||
|
|
||||||
extern void filter_init (void);
|
extern void filter_init (void);
|
||||||
extern void filter_destroy (void);
|
extern void filter_destroy (void);
|
||||||
|
extern void filter_reload (void);
|
||||||
extern int filter_domain (const char *host);
|
extern int filter_domain (const char *host);
|
||||||
extern int filter_url (const char *url);
|
extern int filter_url (const char *url);
|
||||||
|
|
||||||
|
|||||||
+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);
|
||||||
|
}
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
#ifndef _HASHMAP_H
|
#ifndef _HASHMAP_H
|
||||||
#define _HASHMAP_H
|
#define _HASHMAP_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We're using a typedef here to "hide" the implementation details of the
|
* We're using a typedef here to "hide" the implementation details of the
|
||||||
* hash map. Sure, it's a pointer, but the struct is hidden in the C file.
|
* hash map. Sure, it's a pointer, but the struct is hidden in the C file.
|
||||||
@@ -115,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 */
|
||||||
+8
-6
@@ -38,8 +38,8 @@ void *debugging_calloc (size_t nmemb, size_t size, const char *file,
|
|||||||
assert (size > 0);
|
assert (size > 0);
|
||||||
|
|
||||||
ptr = calloc (nmemb, size);
|
ptr = calloc (nmemb, size);
|
||||||
fprintf (stderr, "{calloc: %p:%zu x %zu} %s:%lu\n", ptr, nmemb, size,
|
fprintf (stderr, "{calloc: %p:%lu x %lu} %s:%lu\n", ptr,
|
||||||
file, line);
|
(unsigned long) nmemb, (unsigned long) size, file, line);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,8 @@ void *debugging_malloc (size_t size, const char *file, unsigned long line)
|
|||||||
assert (size > 0);
|
assert (size > 0);
|
||||||
|
|
||||||
ptr = malloc (size);
|
ptr = malloc (size);
|
||||||
fprintf (stderr, "{malloc: %p:%zu} %s:%lu\n", ptr, size, file, line);
|
fprintf (stderr, "{malloc: %p:%lu} %s:%lu\n", ptr,
|
||||||
|
(unsigned long) size, file, line);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +63,8 @@ void *debugging_realloc (void *ptr, size_t size, const char *file,
|
|||||||
assert (size > 0);
|
assert (size > 0);
|
||||||
|
|
||||||
newptr = realloc (ptr, size);
|
newptr = realloc (ptr, size);
|
||||||
fprintf (stderr, "{realloc: %p -> %p:%zu} %s:%lu\n", ptr, newptr, size,
|
fprintf (stderr, "{realloc: %p -> %p:%lu} %s:%lu\n", ptr, newptr,
|
||||||
file, line);
|
(unsigned long) size, file, line);
|
||||||
return newptr;
|
return newptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +90,8 @@ char *debugging_strdup (const char *s, const char *file, unsigned long line)
|
|||||||
return NULL;
|
return NULL;
|
||||||
memcpy (ptr, s, len);
|
memcpy (ptr, s, len);
|
||||||
|
|
||||||
fprintf (stderr, "{strdup: %p:%zu} %s:%lu\n", ptr, len, file, line);
|
fprintf (stderr, "{strdup: %p:%lu} %s:%lu\n", ptr,
|
||||||
|
(unsigned long) len, file, line);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+49
-50
@@ -29,6 +29,7 @@
|
|||||||
#include "html-error.h"
|
#include "html-error.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add an error number -> filename mapping to the errorpages list.
|
* Add an error number -> filename mapping to the errorpages list.
|
||||||
@@ -61,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);
|
||||||
|
|
||||||
@@ -82,63 +83,42 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define HTML_BUFSIZE 4096
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send an already-opened file to the client with variable substitution.
|
* Send an already-opened file to the client with variable substitution.
|
||||||
*/
|
*/
|
||||||
int send_html_file (FILE * infile, struct conn_s *connptr)
|
int
|
||||||
|
send_html_file (FILE *infile, struct conn_s *connptr)
|
||||||
{
|
{
|
||||||
char inbuf[HTML_BUFSIZE], *varstart = NULL, *p;
|
char *inbuf;
|
||||||
|
char *varstart = NULL;
|
||||||
|
char *p;
|
||||||
const char *varval;
|
const char *varval;
|
||||||
int in_variable = 0, writeret;
|
int in_variable = 0;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
while (fgets (inbuf, HTML_BUFSIZE, infile) != NULL) {
|
inbuf = (char *) safemalloc (4096);
|
||||||
|
|
||||||
|
while (fgets (inbuf, 4096, infile) != NULL) {
|
||||||
for (p = inbuf; *p; p++) {
|
for (p = inbuf; *p; p++) {
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '}':
|
case '}':
|
||||||
if (in_variable) {
|
if (in_variable) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
varval =
|
varval = (const char *)
|
||||||
(const char *)
|
lookup_variable (connptr->error_variables,
|
||||||
lookup_variable (connptr, varstart);
|
varstart);
|
||||||
if (!varval)
|
if (!varval)
|
||||||
varval = "(unknown)";
|
varval = "(unknown)";
|
||||||
writeret =
|
r = write_message (connptr->client_fd,
|
||||||
write_message (connptr->client_fd,
|
|
||||||
"%s", varval);
|
"%s", varval);
|
||||||
if (writeret)
|
|
||||||
return (writeret);
|
|
||||||
in_variable = 0;
|
in_variable = 0;
|
||||||
} else {
|
} else {
|
||||||
writeret =
|
r = write_message (connptr->client_fd,
|
||||||
write_message (connptr->client_fd,
|
|
||||||
"%c", *p);
|
"%c", *p);
|
||||||
if (writeret)
|
|
||||||
return (writeret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
/* a {{ will print a single {. If we are NOT
|
/* a {{ will print a single {. If we are NOT
|
||||||
* already in a { variable, then proceed with
|
* already in a { variable, then proceed with
|
||||||
@@ -151,31 +131,50 @@ int send_html_file (FILE * infile, struct conn_s *connptr)
|
|||||||
in_variable++;
|
in_variable++;
|
||||||
} else
|
} else
|
||||||
in_variable = 0;
|
in_variable = 0;
|
||||||
|
|
||||||
|
/* FALL THROUGH */
|
||||||
default:
|
default:
|
||||||
if (!in_variable) {
|
if (!in_variable) {
|
||||||
writeret =
|
r = write_message (connptr->client_fd,
|
||||||
write_message (connptr->client_fd,
|
|
||||||
"%c", *p);
|
"%c", *p);
|
||||||
if (writeret)
|
}
|
||||||
return (writeret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (r)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (r)
|
||||||
|
break;
|
||||||
|
|
||||||
in_variable = 0;
|
in_variable = 0;
|
||||||
}
|
}
|
||||||
return (0);
|
|
||||||
|
safefree (inbuf);
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -204,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,
|
||||||
@@ -272,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",
|
||||||
"http://www.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);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
||||||
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
static const char *syslog_level[] = {
|
static const char *syslog_level[] = {
|
||||||
NULL,
|
NULL,
|
||||||
@@ -61,12 +63,21 @@ static int log_level = LOG_INFO;
|
|||||||
*/
|
*/
|
||||||
static vector_t log_message_storage;
|
static vector_t log_message_storage;
|
||||||
|
|
||||||
|
static unsigned int logging_initialized = FALSE; /* boolean */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open the log file and store the file descriptor in a global location.
|
* Open the log file and store the file descriptor in a global location.
|
||||||
*/
|
*/
|
||||||
int 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,19 +86,12 @@ int open_log_file (const char *log_file_name)
|
|||||||
*/
|
*/
|
||||||
void close_log_file (void)
|
void close_log_file (void)
|
||||||
{
|
{
|
||||||
close (log_file_fd);
|
if (log_file_fd < 0 || log_file_fd == fileno(stdout)) {
|
||||||
}
|
return;
|
||||||
|
|
||||||
/*
|
|
||||||
* Truncate log file to a zero length.
|
|
||||||
*/
|
|
||||||
void truncate_log_file (void)
|
|
||||||
{
|
|
||||||
lseek (log_file_fd, 0, SEEK_SET);
|
|
||||||
if (ftruncate (log_file_fd, 0) != 0) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Unable to truncate log file to zero length");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close (log_file_fd);
|
||||||
|
log_file_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -125,10 +129,8 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
if (config.syslog && level == LOG_CONN)
|
if (config.syslog && level == LOG_CONN)
|
||||||
level = LOG_INFO;
|
level = LOG_INFO;
|
||||||
#endif
|
|
||||||
|
|
||||||
va_start (args, fmt);
|
va_start (args, fmt);
|
||||||
|
|
||||||
@@ -136,7 +138,7 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
* If the config file hasn't been processed, then we need to store
|
* If the config file hasn't been processed, then we need to store
|
||||||
* the messages for later processing.
|
* the messages for later processing.
|
||||||
*/
|
*/
|
||||||
if (!processed_config_file) {
|
if (!logging_initialized) {
|
||||||
char *entry_buffer;
|
char *entry_buffer;
|
||||||
|
|
||||||
if (!log_message_storage) {
|
if (!log_message_storage) {
|
||||||
@@ -158,16 +160,20 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
safefree (entry_buffer);
|
safefree (entry_buffer);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
|
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);
|
||||||
# else
|
#else
|
||||||
vsnprintf (str, STRING_LENGTH, fmt, args);
|
vsnprintf (str, STRING_LENGTH, fmt, args);
|
||||||
syslog (level, "%s", str);
|
syslog (level, "%s", str);
|
||||||
# endif
|
|
||||||
} else {
|
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
char *p;
|
||||||
|
|
||||||
nowtime = time (NULL);
|
nowtime = time (NULL);
|
||||||
/* Format is month day hour:minute:second (24 time) */
|
/* Format is month day hour:minute:second (24 time) */
|
||||||
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
||||||
@@ -177,32 +183,32 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
syslog_level[level], time_string,
|
syslog_level[level], time_string,
|
||||||
(long int) getpid ());
|
(long int) getpid ());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Overwrite the '\0' and leave room for a trailing '\n'
|
||||||
|
* be added next.
|
||||||
|
*/
|
||||||
|
p = str + strlen(str);
|
||||||
|
vsnprintf (p, STRING_LENGTH - strlen(str) - 1, fmt, args);
|
||||||
|
|
||||||
|
p = str + strlen(str);
|
||||||
|
*p = '\n';
|
||||||
|
*(p+1) = '\0';
|
||||||
|
|
||||||
assert (log_file_fd >= 0);
|
assert (log_file_fd >= 0);
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
vsnprintf (str, STRING_LENGTH, fmt, args);
|
log_message(LOG_CRIT, "ERROR: Could not write to log "
|
||||||
ret = write (log_file_fd, str, strlen (str));
|
"file %s: %s.",
|
||||||
if (ret == -1) {
|
config.logf_name, strerror(errno));
|
||||||
log_message (LOG_WARNING,
|
log_message(LOG_CRIT,
|
||||||
"Could not write to log file");
|
"Falling back to syslog logging");
|
||||||
}
|
|
||||||
|
|
||||||
ret = write (log_file_fd, "\n", 1);
|
|
||||||
if (ret == -1) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Could not write to log file");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fsync (log_file_fd);
|
fsync (log_file_fd);
|
||||||
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
va_end (args);
|
va_end (args);
|
||||||
@@ -211,15 +217,18 @@ 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;
|
||||||
|
|
||||||
int level;
|
int level;
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
if (log_message_storage == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
log_message(LOG_DEBUG, "sending stored logs");
|
||||||
|
|
||||||
for (i = 0; (ssize_t) i != vector_length (log_message_storage); ++i) {
|
for (i = 0; (ssize_t) i != vector_length (log_message_storage); ++i) {
|
||||||
string =
|
string =
|
||||||
(char *) vector_getentry (log_message_storage, i, NULL);
|
(char *) vector_getentry (log_message_storage, i, NULL);
|
||||||
@@ -237,9 +246,67 @@ void send_stored_logs (void)
|
|||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
log_message (level, ptr);
|
log_message (level, "%s", ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_delete (log_message_storage);
|
vector_delete (log_message_storage);
|
||||||
log_message_storage = NULL;
|
log_message_storage = NULL;
|
||||||
|
|
||||||
|
log_message(LOG_DEBUG, "done sending stored logs");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the logging subsystem, based on the configuration.
|
||||||
|
* Returns 0 upon success, -1 upon failure.
|
||||||
|
*
|
||||||
|
* This function uses fprintf() instead of log_message(), since
|
||||||
|
* the logging is not yet set up...
|
||||||
|
*/
|
||||||
|
int setup_logging (void)
|
||||||
|
{
|
||||||
|
if (!config.syslog) {
|
||||||
|
if (open_log_file (config.logf_name) < 0) {
|
||||||
|
/*
|
||||||
|
* If opening the log file fails, we try
|
||||||
|
* to fall back to syslog logging...
|
||||||
|
*/
|
||||||
|
config.syslog = TRUE;
|
||||||
|
|
||||||
|
log_message (LOG_CRIT, "ERROR: Could not create log "
|
||||||
|
"file %s: %s.",
|
||||||
|
config.logf_name, strerror (errno));
|
||||||
|
log_message (LOG_CRIT,
|
||||||
|
"Falling back to syslog logging.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.syslog) {
|
||||||
|
if (config.godaemon == TRUE)
|
||||||
|
openlog ("tinyproxy", LOG_PID, LOG_DAEMON);
|
||||||
|
else
|
||||||
|
openlog ("tinyproxy", LOG_PID, LOG_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
logging_initialized = TRUE;
|
||||||
|
send_stored_logs ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the logging subsystem.
|
||||||
|
*/
|
||||||
|
void shutdown_logging (void)
|
||||||
|
{
|
||||||
|
if (!logging_initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.syslog) {
|
||||||
|
closelog ();
|
||||||
|
} else {
|
||||||
|
close_log_file ();
|
||||||
|
}
|
||||||
|
|
||||||
|
logging_initialized = FALSE;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
||||||
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -76,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 */
|
||||||
|
|
||||||
@@ -111,10 +103,11 @@
|
|||||||
|
|
||||||
extern int open_log_file (const char *file);
|
extern int open_log_file (const char *file);
|
||||||
extern void close_log_file (void);
|
extern void close_log_file (void);
|
||||||
extern void truncate_log_file (void);
|
|
||||||
|
|
||||||
extern void log_message (int level, 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 void shutdown_logging (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+103
-132
@@ -1,7 +1,10 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
*
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
||||||
* Copyright (C) 1998-2002 Robert James Kaes <rjkaes@users.sourceforge.net>
|
* Copyright (C) 1998-2002 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
|
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
|
||||||
|
* Copyright (C) 2009-2010 Mukund Sivaraman <muks@banu.com>
|
||||||
|
* Copyright (C) 2009-2010 Michael Adam <obnox@samba.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -45,8 +48,8 @@
|
|||||||
* Global Structures
|
* Global Structures
|
||||||
*/
|
*/
|
||||||
struct config_s config;
|
struct config_s config;
|
||||||
|
struct config_s config_defaults;
|
||||||
unsigned int received_sighup = FALSE; /* boolean */
|
unsigned int received_sighup = FALSE; /* boolean */
|
||||||
unsigned int processed_config_file = FALSE; /* boolean */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle a signal
|
* Handle a signal
|
||||||
@@ -83,35 +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\
|
|
||||||
\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.
|
||||||
*/
|
*/
|
||||||
@@ -126,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 */
|
||||||
@@ -157,12 +130,17 @@ display_usage (void)
|
|||||||
features++;
|
features++;
|
||||||
#endif /* REVERSE_SUPPORT */
|
#endif /* REVERSE_SUPPORT */
|
||||||
|
|
||||||
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
printf (" Upstream proxy support\n");
|
||||||
|
features++;
|
||||||
|
#endif /* UPSTREAM_SUPPORT */
|
||||||
|
|
||||||
if (0 == features)
|
if (0 == features)
|
||||||
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://www.banu.com/tinyproxy/support/>.\n");
|
"<https://tinyproxy.github.io/>.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -191,27 +169,26 @@ get_id (char *str)
|
|||||||
* This function parses command line arguments.
|
* This function parses command line arguments.
|
||||||
**/
|
**/
|
||||||
static void
|
static void
|
||||||
process_cmdline (int argc, char **argv)
|
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':
|
||||||
config.godaemon = FALSE;
|
conf->godaemon = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
config.config_file = safestrdup (optarg);
|
if (conf->config_file != NULL) {
|
||||||
if (!config.config_file) {
|
safefree (conf->config_file);
|
||||||
|
}
|
||||||
|
conf->config_file = safestrdup (optarg);
|
||||||
|
if (!conf->config_file) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"%s: Could not allocate memory.\n",
|
"%s: Could not allocate memory.\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
@@ -264,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);
|
||||||
}
|
}
|
||||||
@@ -296,96 +283,72 @@ change_user (const char *program)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void initialize_config_defaults (struct config_s *conf)
|
||||||
|
{
|
||||||
|
memset (conf, 0, sizeof(*conf));
|
||||||
|
|
||||||
|
conf->config_file = safestrdup (SYSCONFDIR "/tinyproxy.conf");
|
||||||
|
if (!conf->config_file) {
|
||||||
|
fprintf (stderr, PACKAGE ": Could not allocate memory.\n");
|
||||||
|
exit (EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
conf->godaemon = TRUE;
|
||||||
|
/*
|
||||||
|
* Make sure the HTML error pages array is NULL to begin with.
|
||||||
|
* (FIXME: Should have a better API for all this)
|
||||||
|
*/
|
||||||
|
conf->errorpages = NULL;
|
||||||
|
conf->stathost = safestrdup (TINYPROXY_STATHOST);
|
||||||
|
conf->idletimeout = MAX_IDLE_TIME;
|
||||||
|
conf->logf_name = NULL;
|
||||||
|
conf->pidpath = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convenience wrapper around reload_config_file
|
||||||
|
* that also re-initializes logging.
|
||||||
|
*/
|
||||||
|
int reload_config (void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
shutdown_logging ();
|
||||||
|
|
||||||
|
ret = reload_config_file (config_defaults.config_file, &config,
|
||||||
|
&config_defaults);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = setup_logging ();
|
||||||
|
|
||||||
|
done:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
FILE *config_file;
|
|
||||||
|
|
||||||
/* Only allow u+rw bits. This may be required for some versions
|
/* Only allow u+rw bits. This may be required for some versions
|
||||||
* of glibc so that mkstemp() doesn't make us vulnerable.
|
* of glibc so that mkstemp() doesn't make us vulnerable.
|
||||||
*/
|
*/
|
||||||
umask (0177);
|
umask (0177);
|
||||||
|
|
||||||
config.config_file = SYSCONFDIR "/tinyproxy.conf";
|
|
||||||
config.godaemon = TRUE;
|
|
||||||
|
|
||||||
process_cmdline (argc, argv);
|
|
||||||
|
|
||||||
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
|
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
|
||||||
|
|
||||||
/*
|
if (config_compile_regex()) {
|
||||||
* Make sure the HTML error pages array is NULL to begin with.
|
|
||||||
* (FIXME: Should have a better API for all this)
|
|
||||||
*/
|
|
||||||
config.errorpages = NULL;
|
|
||||||
|
|
||||||
/* Read in the settings from the config file */
|
|
||||||
config_file = fopen (config.config_file, "r");
|
|
||||||
if (!config_file) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Could not open config file \"%s\".\n",
|
|
||||||
argv[0], config.config_file);
|
|
||||||
exit (EX_SOFTWARE);
|
exit (EX_SOFTWARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_compile () || config_parse (&config, config_file)) {
|
initialize_config_defaults (&config_defaults);
|
||||||
fprintf (stderr, "Unable to parse config file. "
|
process_cmdline (argc, argv, &config_defaults);
|
||||||
"Not starting.\n");
|
|
||||||
|
if (reload_config_file (config_defaults.config_file,
|
||||||
|
&config,
|
||||||
|
&config_defaults)) {
|
||||||
exit (EX_SOFTWARE);
|
exit (EX_SOFTWARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (config_file);
|
|
||||||
|
|
||||||
/* Write to a user supplied log file if it's defined. This will
|
|
||||||
* override using the syslog even if syslog is defined. */
|
|
||||||
if (config.logf_name) {
|
|
||||||
if (open_log_file (config.logf_name) < 0) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Could not create log file.\n", argv[0]);
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
config.syslog = FALSE; /* disable syslog */
|
|
||||||
} else if (config.syslog) {
|
|
||||||
if (config.godaemon == TRUE)
|
|
||||||
openlog ("tinyproxy", LOG_PID, LOG_DAEMON);
|
|
||||||
else
|
|
||||||
openlog ("tinyproxy", LOG_PID, LOG_USER);
|
|
||||||
} else {
|
|
||||||
fprintf (stderr, "%s: Either define a logfile or "
|
|
||||||
"enable syslog logging.\n", argv[0]);
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
|
|
||||||
processed_config_file = TRUE;
|
|
||||||
send_stored_logs ();
|
|
||||||
|
|
||||||
/* Set the default values if they were not set in the config
|
|
||||||
* file. */
|
|
||||||
if (config.port == 0) {
|
|
||||||
fprintf (stderr, "%s: You MUST set a Port in the "
|
|
||||||
"config file.\n", argv[0]);
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config.stathost) {
|
|
||||||
log_message (LOG_INFO, "Setting stathost to \"%s\".",
|
|
||||||
TINYPROXY_STATHOST);
|
|
||||||
config.stathost = strdup (TINYPROXY_STATHOST);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config.user) {
|
|
||||||
log_message (LOG_WARNING, "You SHOULD set a UserName in the "
|
|
||||||
"config file. Using current user instead.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.idletimeout == 0) {
|
|
||||||
log_message (LOG_WARNING, "Invalid idle time setting. "
|
|
||||||
"Only values greater than zero are allowed. "
|
|
||||||
"Therefore setting idle timeout to %u seconds.",
|
|
||||||
MAX_IDLE_TIME);
|
|
||||||
config.idletimeout = MAX_IDLE_TIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_stats ();
|
init_stats ();
|
||||||
|
|
||||||
/* If ANONYMOUS is turned on, make sure that Content-Length is
|
/* If ANONYMOUS is turned on, make sure that Content-Length is
|
||||||
@@ -397,15 +360,12 @@ main (int argc, char **argv)
|
|||||||
anonymous_insert ("Content-Type");
|
anonymous_insert ("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.godaemon == TRUE)
|
if (config.godaemon == TRUE) {
|
||||||
makedaemon ();
|
if (!config.syslog && config.logf_name == NULL)
|
||||||
|
fprintf(stderr, "WARNING: logging deactivated "
|
||||||
|
"(can't log to stdout when daemonized)\n");
|
||||||
|
|
||||||
if (config.pidpath) {
|
makedaemon ();
|
||||||
if (pidfile_create (config.pidpath) < 0) {
|
|
||||||
fprintf (stderr, "%s: Could not create PID file.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_OSERR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
|
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||||
@@ -420,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]);
|
||||||
@@ -433,6 +402,11 @@ main (int argc, char **argv)
|
|||||||
log_message (LOG_WARNING,
|
log_message (LOG_WARNING,
|
||||||
"Not running as root, so not changing UID/GID.");
|
"Not running as root, so not changing UID/GID.");
|
||||||
|
|
||||||
|
/* Create log file after we drop privileges */
|
||||||
|
if (setup_logging ()) {
|
||||||
|
exit (EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
|
||||||
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",
|
||||||
@@ -468,11 +442,11 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
log_message (LOG_INFO, "Shutting down.");
|
log_message (LOG_INFO, "Shutting down.");
|
||||||
|
|
||||||
child_kill_children ();
|
child_kill_children (SIGTERM);
|
||||||
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));
|
||||||
@@ -483,10 +457,7 @@ main (int argc, char **argv)
|
|||||||
filter_destroy ();
|
filter_destroy ();
|
||||||
#endif /* FILTER_ENABLE */
|
#endif /* FILTER_ENABLE */
|
||||||
|
|
||||||
if (config.syslog)
|
shutdown_logging ();
|
||||||
closelog ();
|
|
||||||
else
|
|
||||||
close_log_file ();
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
+2
-73
@@ -23,86 +23,15 @@
|
|||||||
#define __MAIN_H__
|
#define __MAIN_H__
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "hashmap.h"
|
|
||||||
|
|
||||||
/* Global variables for the main controls of the program */
|
/* Global variables for the main controls of the program */
|
||||||
#define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */
|
#define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */
|
||||||
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
|
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
|
||||||
|
|
||||||
/*
|
|
||||||
* Even if upstream support is not compiled into tinyproxy, this
|
|
||||||
* structure still needs to be defined.
|
|
||||||
*/
|
|
||||||
struct upstream {
|
|
||||||
struct upstream *next;
|
|
||||||
char *domain; /* optional */
|
|
||||||
char *host;
|
|
||||||
int port;
|
|
||||||
in_addr_t ip, mask;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hold all the configuration time information.
|
|
||||||
*/
|
|
||||||
struct config_s {
|
|
||||||
char *logf_name;
|
|
||||||
const char *config_file;
|
|
||||||
unsigned int syslog; /* boolean */
|
|
||||||
int port;
|
|
||||||
char *stathost;
|
|
||||||
unsigned int godaemon; /* boolean */
|
|
||||||
unsigned int quit; /* boolean */
|
|
||||||
char *user;
|
|
||||||
char *group;
|
|
||||||
char *ipAddr;
|
|
||||||
#ifdef FILTER_ENABLE
|
|
||||||
char *filter;
|
|
||||||
unsigned int filter_url; /* boolean */
|
|
||||||
unsigned int filter_extended; /* boolean */
|
|
||||||
unsigned int filter_casesensitive; /* boolean */
|
|
||||||
#endif /* FILTER_ENABLE */
|
|
||||||
#ifdef XTINYPROXY_ENABLE
|
|
||||||
unsigned int add_xtinyproxy; /* boolean */
|
|
||||||
#endif
|
|
||||||
#ifdef REVERSE_SUPPORT
|
|
||||||
struct reversepath *reversepath_list;
|
|
||||||
unsigned int reverseonly; /* boolean */
|
|
||||||
unsigned int reversemagic; /* boolean */
|
|
||||||
char *reversebaseurl;
|
|
||||||
#endif
|
|
||||||
#ifdef UPSTREAM_SUPPORT
|
|
||||||
struct upstream *upstream_list;
|
|
||||||
#endif /* UPSTREAM_SUPPORT */
|
|
||||||
char *pidpath;
|
|
||||||
unsigned int idletimeout;
|
|
||||||
char *bind_address;
|
|
||||||
unsigned int bindsame;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The configured name to use in the HTTP "Via" header field.
|
|
||||||
*/
|
|
||||||
char *via_proxy_name;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Error page support. Map error numbers to file paths.
|
|
||||||
*/
|
|
||||||
hashmap_t errorpages;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Error page to be displayed if appropriate page cannot be located
|
|
||||||
* in the errorpages structure.
|
|
||||||
*/
|
|
||||||
char *errorpage_undef;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The HTML statistics page.
|
|
||||||
*/
|
|
||||||
char *statpage;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Global Structures used in the program */
|
/* Global Structures used in the program */
|
||||||
extern struct config_s config;
|
extern struct config_s config;
|
||||||
extern unsigned int received_sighup; /* boolean */
|
extern unsigned int received_sighup; /* boolean */
|
||||||
extern unsigned int processed_config_file; /* boolean */
|
|
||||||
|
extern int reload_config (void);
|
||||||
|
|
||||||
#endif /* __MAIN_H__ */
|
#endif /* __MAIN_H__ */
|
||||||
+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
|
||||||
+419
-381
File diff suppressed because it is too large.
Load diff
@@ -44,7 +44,5 @@ struct request_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern void handle_connection (int fd);
|
extern void handle_connection (int fd);
|
||||||
extern void add_connect_port_allowed (int port);
|
|
||||||
extern void upstream_add (const char *host, int port, const char *domain);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+26
-16
@@ -25,11 +25,13 @@
|
|||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
#include "html-error.h"
|
#include "html-error.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add entry to the reversepath list
|
* Add entry to the reversepath list
|
||||||
*/
|
*/
|
||||||
void reversepath_add (const char *path, const char *url)
|
void reversepath_add (const char *path, const char *url,
|
||||||
|
struct reversepath **reversepath_list)
|
||||||
{
|
{
|
||||||
struct reversepath *reverse;
|
struct reversepath *reverse;
|
||||||
|
|
||||||
@@ -68,8 +70,8 @@ void reversepath_add (const char *path, const char *url)
|
|||||||
|
|
||||||
reverse->url = safestrdup (url);
|
reverse->url = safestrdup (url);
|
||||||
|
|
||||||
reverse->next = config.reversepath_list;
|
reverse->next = *reversepath_list;
|
||||||
config.reversepath_list = reverse;
|
*reversepath_list = reverse;
|
||||||
|
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"Added reverse proxy rule: %s -> %s", reverse->path,
|
"Added reverse proxy rule: %s -> %s", reverse->path,
|
||||||
@@ -79,10 +81,8 @@ void reversepath_add (const char *path, const char *url)
|
|||||||
/*
|
/*
|
||||||
* Check if a request url is in the reversepath list
|
* Check if a request url is in the reversepath list
|
||||||
*/
|
*/
|
||||||
struct reversepath *reversepath_get (char *url)
|
struct reversepath *reversepath_get (char *url, struct reversepath *reverse)
|
||||||
{
|
{
|
||||||
struct reversepath *reverse = config.reversepath_list;
|
|
||||||
|
|
||||||
while (reverse) {
|
while (reverse) {
|
||||||
if (strstr (url, reverse->path) == url)
|
if (strstr (url, reverse->path) == url)
|
||||||
return reverse;
|
return reverse;
|
||||||
@@ -93,6 +93,21 @@ struct reversepath *reversepath_get (char *url)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free a reversepath list
|
||||||
|
*/
|
||||||
|
|
||||||
|
void free_reversepath_list (struct reversepath *reverse)
|
||||||
|
{
|
||||||
|
while (reverse) {
|
||||||
|
struct reversepath *tmp = reverse;
|
||||||
|
reverse = reverse->next;
|
||||||
|
safefree (tmp->url);
|
||||||
|
safefree (tmp->path);
|
||||||
|
safefree (tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rewrite the URL for reverse proxying.
|
* Rewrite the URL for reverse proxying.
|
||||||
*/
|
*/
|
||||||
@@ -107,7 +122,7 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
/* Reverse requests always start with a slash */
|
/* Reverse requests always start with a slash */
|
||||||
if (*url == '/') {
|
if (*url == '/') {
|
||||||
/* First try locating the reverse mapping by request url */
|
/* First try locating the reverse mapping by request url */
|
||||||
reverse = reversepath_get (url);
|
reverse = reversepath_get (url, config.reversepath_list);
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
rewrite_url = (char *)
|
rewrite_url = (char *)
|
||||||
safemalloc (strlen (url) + strlen (reverse->url) +
|
safemalloc (strlen (url) + strlen (reverse->url) +
|
||||||
@@ -123,8 +138,9 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
if ((cookieval = strstr (cookie, REVERSE_COOKIE "="))
|
if ((cookieval = strstr (cookie, REVERSE_COOKIE "="))
|
||||||
&& (reverse =
|
&& (reverse =
|
||||||
reversepath_get (cookieval +
|
reversepath_get (cookieval +
|
||||||
strlen (REVERSE_COOKIE) +
|
strlen (REVERSE_COOKIE) + 1,
|
||||||
1))) {
|
config.reversepath_list)))
|
||||||
|
{
|
||||||
|
|
||||||
rewrite_url = (char *) safemalloc
|
rewrite_url = (char *) safemalloc
|
||||||
(strlen (url) +
|
(strlen (url) +
|
||||||
@@ -140,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -31,8 +31,11 @@ struct reversepath {
|
|||||||
|
|
||||||
#define REVERSE_COOKIE "yummy_magical_cookie"
|
#define REVERSE_COOKIE "yummy_magical_cookie"
|
||||||
|
|
||||||
extern void reversepath_add (const char *path, const char *url);
|
extern void reversepath_add (const char *path, const char *url,
|
||||||
extern struct reversepath *reversepath_get (char *url);
|
struct reversepath **reversepath_list);
|
||||||
|
extern struct reversepath *reversepath_get (char *url,
|
||||||
|
struct reversepath *reverse);
|
||||||
|
void free_reversepath_list (struct reversepath *reverse);
|
||||||
extern char *reverse_rewrite_url (struct conn_s *connptr,
|
extern char *reverse_rewrite_url (struct conn_s *connptr,
|
||||||
hashmap_t hashofheaders, char *url);
|
hashmap_t hashofheaders, char *url);
|
||||||
|
|
||||||
|
|||||||
+139
-36
@@ -32,13 +32,15 @@
|
|||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind the given socket to the supplied address. The socket is
|
* Bind the given socket to the supplied address. The socket is
|
||||||
* returned if the bind succeeded. Otherwise, -1 is returned
|
* returned if the bind succeeded. Otherwise, -1 is returned
|
||||||
* to indicate an error.
|
* to indicate an error.
|
||||||
*/
|
*/
|
||||||
static int bind_socket (int sockfd, const char *addr)
|
static int
|
||||||
|
bind_socket (int sockfd, const char *addr, int family)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *res, *ressave;
|
struct addrinfo hints, *res, *ressave;
|
||||||
|
|
||||||
@@ -46,7 +48,7 @@ static int bind_socket (int sockfd, const char *addr)
|
|||||||
assert (addr != NULL && strlen (addr) != 0);
|
assert (addr != NULL && strlen (addr) != 0);
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (struct addrinfo));
|
memset (&hints, 0, sizeof (struct addrinfo));
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = family;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
/* The local port it not important */
|
/* The local port it not important */
|
||||||
@@ -82,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;
|
||||||
@@ -95,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 =
|
||||||
@@ -104,12 +112,14 @@ int opensock (const char *host, int port, const char *bind_to)
|
|||||||
|
|
||||||
/* Bind to the specified address */
|
/* Bind to the specified address */
|
||||||
if (bind_to) {
|
if (bind_to) {
|
||||||
if (bind_socket (sockfd, bind_to) < 0) {
|
if (bind_socket (sockfd, bind_to,
|
||||||
|
res->ai_family) < 0) {
|
||||||
close (sockfd);
|
close (sockfd);
|
||||||
continue; /* can't bind, so try again */
|
continue; /* can't bind, so try again */
|
||||||
}
|
}
|
||||||
} else if (config.bind_address) {
|
} else if (config.bind_address) {
|
||||||
if (bind_socket (sockfd, config.bind_address) < 0) {
|
if (bind_socket (sockfd, config.bind_address,
|
||||||
|
res->ai_family) < 0) {
|
||||||
close (sockfd);
|
close (sockfd);
|
||||||
continue; /* can't bind, so try again */
|
continue; /* can't bind, so try again */
|
||||||
}
|
}
|
||||||
@@ -158,53 +168,146 @@ 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 listenfd;
|
||||||
|
int ret;
|
||||||
const int on = 1;
|
const int on = 1;
|
||||||
struct sockaddr_in addr;
|
char numerichost[NI_MAXHOST];
|
||||||
|
int flags = NI_NUMERICHOST;
|
||||||
|
|
||||||
assert (port > 0);
|
ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
|
||||||
assert (addrlen != NULL);
|
numerichost, NI_MAXHOST, NULL, 0, flags);
|
||||||
|
if (ret != 0) {
|
||||||
listenfd = socket (AF_INET, SOCK_STREAM, 0);
|
log_message(LOG_ERR, "error calling getnameinfo: %s",
|
||||||
setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on));
|
gai_strerror(errno));
|
||||||
|
|
||||||
memset (&addr, 0, sizeof (addr));
|
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
addr.sin_port = htons (port);
|
|
||||||
|
|
||||||
if (config.ipAddr) {
|
|
||||||
addr.sin_addr.s_addr = inet_addr (config.ipAddr);
|
|
||||||
} else {
|
|
||||||
addr.sin_addr.s_addr = inet_addr ("0.0.0.0");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bind (listenfd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Unable to bind listening socket because of %s",
|
|
||||||
strerror (errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen (listenfd, MAXLISTEN) < 0) {
|
log_message(LOG_INFO, "trying to listen on host[%s], family[%d], "
|
||||||
log_message (LOG_ERR,
|
"socktype[%d], proto[%d]", numerichost,
|
||||||
"Unable to start listening socket because of %s",
|
ad->ai_family, ad->ai_socktype, ad->ai_protocol);
|
||||||
strerror (errno));
|
|
||||||
|
listenfd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
|
||||||
|
if (listenfd == -1) {
|
||||||
|
log_message(LOG_ERR, "socket() failed: %s", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*addrlen = sizeof (addr);
|
ret = setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR,
|
||||||
|
"setsockopt failed to set SO_REUSEADDR: %s",
|
||||||
|
strerror(errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ad->ai_family == AF_INET6) {
|
||||||
|
ret = setsockopt(listenfd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
|
||||||
|
sizeof(on));
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR,
|
||||||
|
"setsockopt failed to set IPV6_V6ONLY: %s",
|
||||||
|
strerror(errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = bind(listenfd, ad->ai_addr, ad->ai_addrlen);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "bind failed: %s", strerror (errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = listen(listenfd, MAXLISTEN);
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message(LOG_ERR, "listen failed: %s", strerror(errno));
|
||||||
|
close(listenfd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "listening on fd [%d]", listenfd);
|
||||||
|
|
||||||
return listenfd;
|
return listenfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start listening on a socket. Create a socket with the selected port.
|
||||||
|
* If the provided address is NULL, we may listen on multiple sockets,
|
||||||
|
* e.g. the wildcard addresse for IPv4 and IPv6, depending on what is
|
||||||
|
* supported. If the address is not NULL, we only listen on the first
|
||||||
|
* address reported by getaddrinfo that works.
|
||||||
|
*
|
||||||
|
* Upon success, the listen-fds are added to the listen_fds list
|
||||||
|
* and 0 is returned. Upon error, -1 is returned.
|
||||||
|
*/
|
||||||
|
int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
|
||||||
|
{
|
||||||
|
struct addrinfo hints, *result, *rp;
|
||||||
|
char portstr[6];
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
assert (port > 0);
|
||||||
|
assert (listen_fds != NULL);
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "listen_sock called with addr = '%s'",
|
||||||
|
addr == NULL ? "(NULL)" : addr);
|
||||||
|
|
||||||
|
memset (&hints, 0, sizeof (struct addrinfo));
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_flags = AI_PASSIVE;
|
||||||
|
|
||||||
|
snprintf (portstr, sizeof (portstr), "%d", port);
|
||||||
|
|
||||||
|
if (getaddrinfo (addr, portstr, &hints, &result) != 0) {
|
||||||
|
log_message (LOG_ERR,
|
||||||
|
"Unable to getaddrinfo() because of %s",
|
||||||
|
strerror (errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||||
|
int listenfd;
|
||||||
|
|
||||||
|
listenfd = listen_on_one_socket(rp);
|
||||||
|
if (listenfd == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector_append (listen_fds, &listenfd, sizeof(int));
|
||||||
|
|
||||||
|
/* success */
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
if (addr != NULL) {
|
||||||
|
/*
|
||||||
|
* Unless wildcard is requested, only listen
|
||||||
|
* on the first result that works.
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
log_message (LOG_ERR, "Unable to listen on any address.");
|
||||||
|
}
|
||||||
|
|
||||||
|
freeaddrinfo (result);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Takes a socket descriptor and returns the socket's IP address.
|
* Takes a socket descriptor and returns the socket's IP address.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+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);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "html-error.h"
|
#include "html-error.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
struct stat_s {
|
struct stat_s {
|
||||||
unsigned long int num_reqs;
|
unsigned long int num_reqs;
|
||||||
|
|||||||
+43
-25
@@ -23,14 +23,14 @@
|
|||||||
* traffic to tinyproxy for this to work properly.
|
* traffic to tinyproxy for this to work properly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "transparent-proxy.h"
|
#include "transparent-proxy.h"
|
||||||
#include "conns.h"
|
#include "conns.h"
|
||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
#include "html-error.h"
|
#include "html-error.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "reqs.h"
|
#include "reqs.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build a URL from parts.
|
* Build a URL from parts.
|
||||||
@@ -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;
|
||||||
|
|
||||||
@@ -55,10 +55,12 @@ static int build_url (char **url, const char *host, int port, const char *path)
|
|||||||
int
|
int
|
||||||
do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
||||||
struct request_s *request, struct config_s *conf,
|
struct request_s *request, struct config_s *conf,
|
||||||
char *url)
|
char **url)
|
||||||
{
|
{
|
||||||
socklen_t length;
|
socklen_t length;
|
||||||
char *data;
|
char *data;
|
||||||
|
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) {
|
||||||
@@ -72,45 +74,61 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
connptr->client_fd);
|
connptr->client_fd);
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
"detail", "Unknown destination",
|
"detail", "Unknown destination",
|
||||||
"url", url, NULL);
|
"url", *url, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
request->host = (char *) safemalloc (17);
|
request->host = (char *) safemalloc (17);
|
||||||
strcpy (request->host, inet_ntoa (dest_addr.sin_addr));
|
strlcpy (request->host, inet_ntoa (dest_addr.sin_addr), 17);
|
||||||
|
|
||||||
request->port = ntohs (dest_addr.sin_port);
|
request->port = ntohs (dest_addr.sin_port);
|
||||||
request->path = (char *) safemalloc (strlen (url) + 1);
|
|
||||||
strcpy (request->path, url);
|
request->path = (char *) safemalloc (ulen + 1);
|
||||||
safefree (url);
|
strlcpy (request->path, *url, ulen + 1);
|
||||||
build_url (&url, request->host, request->port, request->path);
|
|
||||||
|
build_url (url, request->host, request->port, request->path);
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"process_request: trans IP %s %s for %d",
|
"process_request: trans IP %s %s for %d",
|
||||||
request->method, url, connptr->client_fd);
|
request->method, *url, connptr->client_fd);
|
||||||
} else {
|
} else {
|
||||||
request->host = (char *) safemalloc (length + 1);
|
request->host = (char *) safemalloc (length + 1);
|
||||||
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
|
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
|
||||||
2) {
|
2) {
|
||||||
strcpy (request->host, data);
|
strlcpy (request->host, data, length + 1);
|
||||||
request->port = HTTP_PORT;
|
request->port = HTTP_PORT;
|
||||||
}
|
}
|
||||||
request->path = (char *) safemalloc (strlen (url) + 1);
|
|
||||||
strcpy (request->path, url);
|
request->path = (char *) safemalloc (ulen + 1);
|
||||||
safefree (url);
|
strlcpy (request->path, *url, ulen + 1);
|
||||||
build_url (&url, request->host, request->port, request->path);
|
|
||||||
|
build_url (url, request->host, request->port, request->path);
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
"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;
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
extern int do_transparent_proxy (struct conn_s *connptr,
|
extern int do_transparent_proxy (struct conn_s *connptr,
|
||||||
hashmap_t hashofheaders,
|
hashmap_t hashofheaders,
|
||||||
struct request_s *request,
|
struct request_s *request,
|
||||||
struct config_s *config, char *url);
|
struct config_s *config, char **url);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+260
@@ -0,0 +1,260 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
||||||
|
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
|
||||||
|
* Copyright (C) 2002 Petr Lampa <lampa@fit.vutbr.cz>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Routines for handling the list of upstream proxies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "upstream.h"
|
||||||
|
#include "heap.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "base64.h"
|
||||||
|
#include "basicauth.h"
|
||||||
|
|
||||||
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
const char *
|
||||||
|
proxy_type_name(proxy_type type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case PT_NONE: return "none";
|
||||||
|
case PT_HTTP: return "http";
|
||||||
|
case PT_SOCKS4: return "socks4";
|
||||||
|
case PT_SOCKS5: return "socks5";
|
||||||
|
default: return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an upstream struct from input data.
|
||||||
|
*/
|
||||||
|
static struct upstream *upstream_build (const char *host, int port, const char *domain,
|
||||||
|
const char *user, const char *pass,
|
||||||
|
proxy_type type)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
struct upstream *up;
|
||||||
|
|
||||||
|
up = (struct upstream *) safemalloc (sizeof (struct upstream));
|
||||||
|
if (!up) {
|
||||||
|
log_message (LOG_ERR,
|
||||||
|
"Unable to allocate memory in upstream_build()");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
up->type = type;
|
||||||
|
up->host = up->domain = up->ua.user = up->pass = NULL;
|
||||||
|
up->ip = up->mask = 0;
|
||||||
|
if (user) {
|
||||||
|
if (type == PT_HTTP) {
|
||||||
|
char b[BASE64ENC_BYTES((256+2)-1) + 1];
|
||||||
|
ssize_t ret;
|
||||||
|
ret = basicauth_string(user, pass, b, sizeof b);
|
||||||
|
if (ret == 0) {
|
||||||
|
log_message (LOG_ERR,
|
||||||
|
"User / pass in upstream config too long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
up->ua.authstr = safestrdup (b);
|
||||||
|
} else {
|
||||||
|
up->ua.user = safestrdup (user);
|
||||||
|
up->pass = safestrdup (pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domain == NULL) {
|
||||||
|
if (!host || host[0] == '\0' || port < 1) {
|
||||||
|
log_message (LOG_WARNING,
|
||||||
|
"Nonsense upstream rule: invalid host or port");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
up->host = safestrdup (host);
|
||||||
|
up->port = port;
|
||||||
|
|
||||||
|
log_message (LOG_INFO, "Added upstream %s %s:%d for [default]",
|
||||||
|
proxy_type_name(type), host, port);
|
||||||
|
} else if (host == NULL || type == PT_NONE) {
|
||||||
|
if (!domain || domain[0] == '\0') {
|
||||||
|
log_message (LOG_WARNING,
|
||||||
|
"Nonsense no-upstream rule: empty domain");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = strchr (domain, '/');
|
||||||
|
if (ptr) {
|
||||||
|
struct in_addr addrstruct;
|
||||||
|
|
||||||
|
*ptr = '\0';
|
||||||
|
if (inet_aton (domain, &addrstruct) != 0) {
|
||||||
|
up->ip = ntohl (addrstruct.s_addr);
|
||||||
|
*ptr++ = '/';
|
||||||
|
|
||||||
|
if (strchr (ptr, '.')) {
|
||||||
|
if (inet_aton (ptr, &addrstruct) != 0)
|
||||||
|
up->mask =
|
||||||
|
ntohl (addrstruct.s_addr);
|
||||||
|
} else {
|
||||||
|
up->mask =
|
||||||
|
~((1 << (32 - atoi (ptr))) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
up->domain = safestrdup (domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message (LOG_INFO, "Added no-upstream for %s", domain);
|
||||||
|
} else {
|
||||||
|
if (!host || host[0] == '\0' || port < 1 || !domain
|
||||||
|
|| domain[0] == '\0') {
|
||||||
|
log_message (LOG_WARNING,
|
||||||
|
"Nonsense upstream rule: invalid parameters");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
up->host = safestrdup (host);
|
||||||
|
up->port = port;
|
||||||
|
up->domain = safestrdup (domain);
|
||||||
|
|
||||||
|
log_message (LOG_INFO, "Added upstream %s %s:%d for %s",
|
||||||
|
proxy_type_name(type), host, port, domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
return up;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
safefree (up->ua.user);
|
||||||
|
safefree (up->pass);
|
||||||
|
safefree (up->host);
|
||||||
|
safefree (up->domain);
|
||||||
|
safefree (up);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an entry to the upstream list
|
||||||
|
*/
|
||||||
|
void upstream_add (const char *host, int port, const char *domain,
|
||||||
|
const char *user, const char *pass,
|
||||||
|
proxy_type type, struct upstream **upstream_list)
|
||||||
|
{
|
||||||
|
struct upstream *up;
|
||||||
|
|
||||||
|
up = upstream_build (host, port, domain, user, pass, type);
|
||||||
|
if (up == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!up->domain && !up->ip) { /* always add default to end */
|
||||||
|
struct upstream *tmp = *upstream_list;
|
||||||
|
|
||||||
|
while (tmp) {
|
||||||
|
if (!tmp->domain && !tmp->ip) {
|
||||||
|
log_message (LOG_WARNING,
|
||||||
|
"Duplicate default upstream");
|
||||||
|
goto upstream_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tmp->next) {
|
||||||
|
up->next = NULL;
|
||||||
|
tmp->next = up;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
up->next = *upstream_list;
|
||||||
|
*upstream_list = up;
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
upstream_cleanup:
|
||||||
|
safefree (up->host);
|
||||||
|
safefree (up->domain);
|
||||||
|
safefree (up);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if a host is in the upstream list
|
||||||
|
*/
|
||||||
|
struct upstream *upstream_get (char *host, struct upstream *up)
|
||||||
|
{
|
||||||
|
in_addr_t my_ip = INADDR_NONE;
|
||||||
|
|
||||||
|
while (up) {
|
||||||
|
if (up->domain) {
|
||||||
|
if (strcasecmp (host, up->domain) == 0)
|
||||||
|
break; /* exact match */
|
||||||
|
|
||||||
|
if (up->domain[0] == '.') {
|
||||||
|
char *dot = strchr (host, '.');
|
||||||
|
|
||||||
|
if (!dot && !up->domain[1])
|
||||||
|
break; /* local host matches "." */
|
||||||
|
|
||||||
|
while (dot && strcasecmp (dot, up->domain))
|
||||||
|
dot = strchr (dot + 1, '.');
|
||||||
|
|
||||||
|
if (dot)
|
||||||
|
break; /* subdomain match */
|
||||||
|
}
|
||||||
|
} else if (up->ip) {
|
||||||
|
if (my_ip == INADDR_NONE)
|
||||||
|
my_ip = ntohl (inet_addr (host));
|
||||||
|
|
||||||
|
if ((my_ip & up->mask) == up->ip)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
break; /* No domain or IP, default upstream */
|
||||||
|
}
|
||||||
|
|
||||||
|
up = up->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (up && (!up->host || !up->port))
|
||||||
|
up = NULL;
|
||||||
|
|
||||||
|
if (up)
|
||||||
|
log_message (LOG_INFO, "Found upstream proxy %s %s:%d for %s",
|
||||||
|
proxy_type_name(up->type), up->host, up->port, host);
|
||||||
|
else
|
||||||
|
log_message (LOG_INFO, "No upstream proxy for %s", host);
|
||||||
|
|
||||||
|
return up;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_upstream_list (struct upstream *up)
|
||||||
|
{
|
||||||
|
while (up) {
|
||||||
|
struct upstream *tmp = up;
|
||||||
|
up = up->next;
|
||||||
|
safefree (tmp->domain);
|
||||||
|
safefree (tmp->host);
|
||||||
|
safefree (tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/* tinyproxy - A fast light-weight HTTP proxy
|
||||||
|
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
||||||
|
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Routines for handling the list of upstream proxies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TINYPROXY_UPSTREAM_H_
|
||||||
|
#define _TINYPROXY_UPSTREAM_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Even if upstream support is not compiled into tinyproxy, this
|
||||||
|
* structure still needs to be defined.
|
||||||
|
*/
|
||||||
|
typedef enum proxy_type {
|
||||||
|
PT_NONE = 0,
|
||||||
|
PT_HTTP,
|
||||||
|
PT_SOCKS4,
|
||||||
|
PT_SOCKS5
|
||||||
|
} proxy_type;
|
||||||
|
|
||||||
|
struct upstream {
|
||||||
|
struct upstream *next;
|
||||||
|
char *domain; /* optional */
|
||||||
|
char *host;
|
||||||
|
union {
|
||||||
|
char *user;
|
||||||
|
char *authstr;
|
||||||
|
} ua;
|
||||||
|
char *pass;
|
||||||
|
int port;
|
||||||
|
in_addr_t ip, mask;
|
||||||
|
proxy_type type;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef UPSTREAM_SUPPORT
|
||||||
|
const char *proxy_type_name(proxy_type type);
|
||||||
|
extern void upstream_add (const char *host, int port, const char *domain,
|
||||||
|
const char *user, const char *pass,
|
||||||
|
proxy_type type, struct upstream **upstream_list);
|
||||||
|
extern struct upstream *upstream_get (char *host, struct upstream *up);
|
||||||
|
extern void free_upstream_list (struct upstream *up);
|
||||||
|
#endif /* UPSTREAM_SUPPORT */
|
||||||
|
|
||||||
|
#endif /* _TINYPROXY_UPSTREAM_H_ */
|
||||||
+11
-4
@@ -104,10 +104,17 @@ int vector_delete (vector_t vector)
|
|||||||
* Returns: 0 on success
|
* Returns: 0 on success
|
||||||
* negative number if there are errors
|
* negative number if there are errors
|
||||||
*/
|
*/
|
||||||
#define INSERT_PREPEND 0
|
|
||||||
#define INSERT_APPEND 1
|
|
||||||
|
|
||||||
static int vector_insert (vector_t vector, void *data, size_t len, int pos)
|
typedef enum {
|
||||||
|
INSERT_PREPEND,
|
||||||
|
INSERT_APPEND
|
||||||
|
} vector_pos_t;
|
||||||
|
|
||||||
|
static int
|
||||||
|
vector_insert (vector_t vector,
|
||||||
|
void *data,
|
||||||
|
size_t len,
|
||||||
|
vector_pos_t pos)
|
||||||
{
|
{
|
||||||
struct vectorentry_s *entry;
|
struct vectorentry_s *entry;
|
||||||
|
|
||||||
@@ -133,7 +140,7 @@ static int vector_insert (vector_t vector, void *data, size_t len, int pos)
|
|||||||
/* If there is no head or tail, create them */
|
/* If there is no head or tail, create them */
|
||||||
if (!vector->head && !vector->tail)
|
if (!vector->head && !vector->tail)
|
||||||
vector->head = vector->tail = entry;
|
vector->head = vector->tail = entry;
|
||||||
else if (pos == 0) {
|
else if (pos == INSERT_PREPEND) {
|
||||||
/* prepend the entry */
|
/* prepend the entry */
|
||||||
entry->next = vector->head;
|
entry->next = vector->head;
|
||||||
vector->head = entry;
|
vector->head = entry;
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ LOG_DIR=$TESTENV_DIR/var/log
|
|||||||
|
|
||||||
TINYPROXY_IP=127.0.0.2
|
TINYPROXY_IP=127.0.0.2
|
||||||
TINYPROXY_PORT=12321
|
TINYPROXY_PORT=12321
|
||||||
TINYPROXY_USER=$USER
|
TINYPROXY_USER=$(id -un)
|
||||||
TINYPROXY_PID_DIR=$TESTENV_DIR/var/run/tinyproxy
|
TINYPROXY_PID_DIR=$TESTENV_DIR/var/run/tinyproxy
|
||||||
TINYPROXY_PID_FILE=$TINYPROXY_PID_DIR/tinyproxy.pid
|
TINYPROXY_PID_FILE=$TINYPROXY_PID_DIR/tinyproxy.pid
|
||||||
TINYPROXY_LOG_DIR=$LOG_DIR
|
TINYPROXY_LOG_DIR=$LOG_DIR/tinyproxy
|
||||||
TINYPROXY_DATA_DIR=$TESTENV_DIR/usr/share/tinyproxy
|
TINYPROXY_DATA_DIR=$TESTENV_DIR/usr/share/tinyproxy
|
||||||
TINYPROXY_CONF_DIR=$TESTENV_DIR/etc/tinyproxy
|
TINYPROXY_CONF_DIR=$TESTENV_DIR/etc/tinyproxy
|
||||||
TINYPROXY_CONF_FILE=$TINYPROXY_CONF_DIR/tinyproxy.conf
|
TINYPROXY_CONF_FILE=$TINYPROXY_CONF_DIR/tinyproxy.conf
|
||||||
@@ -90,6 +90,7 @@ StartServers 10
|
|||||||
MaxRequestsPerChild 0
|
MaxRequestsPerChild 0
|
||||||
Allow 127.0.0.0/8
|
Allow 127.0.0.0/8
|
||||||
ViaProxyName "tinyproxy"
|
ViaProxyName "tinyproxy"
|
||||||
|
#DisableViaHeader Yes
|
||||||
ConnectPort 443
|
ConnectPort 443
|
||||||
ConnectPort 563
|
ConnectPort 563
|
||||||
FilterURLs On
|
FilterURLs On
|
||||||
@@ -158,12 +159,13 @@ run_basic_webclient_request() {
|
|||||||
if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
|
if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
|
||||||
echo " ok"
|
echo " ok"
|
||||||
else
|
else
|
||||||
echo "ERROR ($EBCLIENT_EXIT_CODE)"
|
echo "ERROR ($WEBCLIENT_EXIT_CODE)"
|
||||||
echo "webclient output:"
|
echo "webclient output:"
|
||||||
cat $WEBCLIENT_LOG
|
cat $WEBCLIENT_LOG
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
|
return $WEBCLIENT_EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
# "main"
|
# "main"
|
||||||
|
|
||||||
@@ -176,22 +178,31 @@ start_tinyproxy
|
|||||||
|
|
||||||
wait_for_some_seconds 3
|
wait_for_some_seconds 3
|
||||||
|
|
||||||
|
FAILED=0
|
||||||
|
|
||||||
echo -n "checking direct connection to web server..."
|
echo -n "checking direct connection to web server..."
|
||||||
run_basic_webclient_request "$WEBSERVER_IP:$WEBSERVER_PORT" /
|
run_basic_webclient_request "$WEBSERVER_IP:$WEBSERVER_PORT" /
|
||||||
|
test "x$?" = "x0" || FAILED=$((FAILED + 1))
|
||||||
|
|
||||||
echo -n "testing connection through tinyproxy..."
|
echo -n "testing connection through tinyproxy..."
|
||||||
run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$WEBSERVER_IP:$WEBSERVER_PORT/"
|
run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$WEBSERVER_IP:$WEBSERVER_PORT/"
|
||||||
|
test "x$?" = "x0" || FAILED=$((FAILED + 1))
|
||||||
|
|
||||||
echo -n "requesting statspage via stathost url..."
|
echo -n "requesting statspage via stathost url..."
|
||||||
run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$TINYPROXY_STATHOST_IP"
|
run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$TINYPROXY_STATHOST_IP"
|
||||||
|
test "x$?" = "x0" || FAILED=$((FAILED + 1))
|
||||||
|
|
||||||
echo "You can continue using the webserver and tinyproxy."
|
echo "$FAILED errors"
|
||||||
echo -n "hit <enter> to stop the servers and exit: "
|
|
||||||
read READ
|
if test "x$TINYPROXY_TESTS_WAIT" = "xyes"; then
|
||||||
|
echo "You can continue using the webserver and tinyproxy."
|
||||||
|
echo -n "hit <enter> to stop the servers and exit: "
|
||||||
|
read READ
|
||||||
|
fi
|
||||||
|
|
||||||
stop_tinyproxy
|
stop_tinyproxy
|
||||||
stop_webserver
|
stop_webserver
|
||||||
|
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|
||||||
exit 0
|
exit $FAILED
|
||||||
@@ -34,6 +34,7 @@ my $http_version = "1.0";
|
|||||||
my $method = "GET";
|
my $method = "GET";
|
||||||
my $dry_run = 0;
|
my $dry_run = 0;
|
||||||
my $help = 0;
|
my $help = 0;
|
||||||
|
my $entity = undef;
|
||||||
|
|
||||||
my $default_port = "80";
|
my $default_port = "80";
|
||||||
my $port = $default_port;
|
my $port = $default_port;
|
||||||
@@ -42,7 +43,8 @@ sub process_options() {
|
|||||||
my $result = GetOptions("help|?" => \$help,
|
my $result = GetOptions("help|?" => \$help,
|
||||||
"http-version=s" => \$http_version,
|
"http-version=s" => \$http_version,
|
||||||
"method=s" => \$method,
|
"method=s" => \$method,
|
||||||
"dry-run" => \$dry_run);
|
"dry-run" => \$dry_run,
|
||||||
|
"entity=s" => \$entity);
|
||||||
die "Error reading cmdline options! $!" unless $result;
|
die "Error reading cmdline options! $!" unless $result;
|
||||||
|
|
||||||
pod2usage(1) if $help;
|
pod2usage(1) if $help;
|
||||||
@@ -51,9 +53,9 @@ sub process_options() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub build_request($$$$$)
|
sub build_request($$$$$$)
|
||||||
{
|
{
|
||||||
my ( $host, $port, $version, $method, $document ) = @_;
|
my ( $host, $port, $version, $method, $document, $entity ) = @_;
|
||||||
my $request = "";
|
my $request = "";
|
||||||
|
|
||||||
$method = uc($method);
|
$method = uc($method);
|
||||||
@@ -77,6 +79,10 @@ sub build_request($$$$$)
|
|||||||
|
|
||||||
$request .= $EOL;
|
$request .= $EOL;
|
||||||
|
|
||||||
|
if ($entity) {
|
||||||
|
$request .= $entity;
|
||||||
|
}
|
||||||
|
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +103,7 @@ if ($host =~ /^([^:]+):(.*)/) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach my $document (@ARGV) {
|
foreach my $document (@ARGV) {
|
||||||
my $request = build_request($host, $port, $http_version, $method, $document);
|
my $request = build_request($host, $port, $http_version, $method, $document, $entity);
|
||||||
if ($dry_run) {
|
if ($dry_run) {
|
||||||
print $request;
|
print $request;
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -151,6 +157,10 @@ Specify the HTTP protocol version to use (0.9, 1.0, 1.1). Default is 1.0.
|
|||||||
|
|
||||||
Specify the HTTP request method ('GET', 'CONNECT', ...). Default is 'GET'.
|
Specify the HTTP request method ('GET', 'CONNECT', ...). Default is 'GET'.
|
||||||
|
|
||||||
|
=item B<--entity>
|
||||||
|
|
||||||
|
Add the provided string as entity (i.e. body) to the request.
|
||||||
|
|
||||||
=item B<--dry-run>
|
=item B<--dry-run>
|
||||||
|
|
||||||
Don't actually connect to the server but print the request that would be sent.
|
Don't actually connect to the server but print the request that would be sent.
|
||||||
|
|||||||
@@ -193,10 +193,13 @@ sub child_action($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->{version} ne "0.9") {
|
||||||
print $client "HTTP/1.0 200 OK$EOL";
|
print $client "HTTP/1.0 200 OK$EOL";
|
||||||
print $client "$server_header$EOL";
|
print $client "$server_header$EOL";
|
||||||
print $client "Content-Type: text/html$EOL";
|
print $client "Content-Type: text/html$EOL";
|
||||||
print $client "$EOL";
|
print $client "$EOL";
|
||||||
|
}
|
||||||
|
|
||||||
print $client "<html>$EOL";
|
print $client "<html>$EOL";
|
||||||
print $client "<h1>Tinyproxy test WEB server</h1>$EOL";
|
print $client "<h1>Tinyproxy test WEB server</h1>$EOL";
|
||||||
print $client "<h2>Fortune</h2>$EOL";
|
print $client "<h2>Fortune</h2>$EOL";
|
||||||
|
|||||||
Reference in new issue
Block a user