Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd217661f0 |
No files matched your search
-22
@@ -1,22 +0,0 @@
|
|||||||
INSTALL
|
|
||||||
Makefile
|
|
||||||
Makefile.in
|
|
||||||
aclocal.m4
|
|
||||||
config.cache
|
|
||||||
config.guess
|
|
||||||
config.h
|
|
||||||
config.h.in
|
|
||||||
config.log
|
|
||||||
config.status
|
|
||||||
config.sub
|
|
||||||
configure
|
|
||||||
depcomp
|
|
||||||
install-sh
|
|
||||||
libtool
|
|
||||||
missing
|
|
||||||
stamp-h1
|
|
||||||
autom4te.cache
|
|
||||||
cscope.files
|
|
||||||
cscope.out
|
|
||||||
*~
|
|
||||||
tags
|
|
||||||
@@ -1,19 +1,9 @@
|
|||||||
Early History
|
tinyproxy is a collaborative work between Steven Young
|
||||||
-------------
|
<sdyoung@well.com> and Robert James Kaes <rjkaes@flarenet.com>.
|
||||||
|
|
||||||
Steven Young is the original author and was the primary maintainer of
|
From versions 0-1.1, Steven Young was the primary maintainer.
|
||||||
tinyproxy until version 1.1. He also maintained the project from
|
From 1.2 to 1.3.0, Robert James Kaes was the primary maintainer.
|
||||||
version 1.3.1 until 1.4.0.
|
As of 1.3.1, Steven Young will once again be the primary maintainer.
|
||||||
|
|
||||||
Robert James Kaes is the current maintainer and lead programmer. He
|
Please see the ChangeLog for futher details as to who did what. :)
|
||||||
also maintained the project between versions 1.2 and 1.3.0, and again
|
|
||||||
starting with version 1.4.0.
|
|
||||||
|
|
||||||
|
|
||||||
Major Additions/Improvements
|
|
||||||
----------------------------
|
|
||||||
|
|
||||||
James E. Flemer <jflemer@acm.jhu.edu> - URL/domain filtering
|
|
||||||
Kim Holviala <kim@holviala.com> - Reverse proxy support
|
|
||||||
Petr Lampa <lampa@fit.vutbr.cz> - Transparent proxy support
|
|
||||||
George Talusan <gstalusan@uwaterloo.ca> - URL/domain filtering
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
|
|||||||
General Public License applies to most of the Free Software
|
General Public License applies to most of the Free Software
|
||||||
Foundation's software and to any other program whose authors commit to
|
Foundation's software and to any other program whose authors commit to
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
the GNU Lesser General Public License instead.) You can apply it to
|
the GNU Library General Public License instead.) You can apply it to
|
||||||
your programs, too.
|
your programs, too.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
@@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all.
|
|||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
|
|||||||
License. (Exception: if the Program itself is interactive but
|
License. (Exception: if the Program itself is interactive but
|
||||||
does not normally print such an announcement, your work based on
|
does not normally print such an announcement, your work based on
|
||||||
the Program is not required to print an announcement.)
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
These requirements apply to the modified work as a whole. If
|
||||||
identifiable sections of that work are not derived from the Program,
|
identifiable sections of that work are not derived from the Program,
|
||||||
and can be reasonably considered independent and separate works in
|
and can be reasonably considered independent and separate works in
|
||||||
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
|
|||||||
access to copy the source code from the same place counts as
|
access to copy the source code from the same place counts as
|
||||||
distribution of the source code, even though third parties are not
|
distribution of the source code, even though third parties are not
|
||||||
compelled to copy the source along with the object code.
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
except as expressly provided under this License. Any attempt
|
except as expressly provided under this License. Any attempt
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
@@ -225,7 +225,7 @@ impose that choice.
|
|||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
This section is intended to make thoroughly clear what is believed to
|
||||||
be a consequence of the rest of this License.
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
original copyright holder who places the Program under this License
|
original copyright holder who places the Program under this License
|
||||||
@@ -278,7 +278,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|||||||
POSSIBILITY OF SUCH DAMAGES.
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
If you develop a new program, and you want it to be of the greatest
|
||||||
@@ -303,16 +303,17 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License
|
||||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
along with this program; if not, write to the Free Software
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
If the program is interactive, make it output a short notice like this
|
||||||
when it starts in an interactive mode:
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
@@ -335,5 +336,5 @@ necessary. Here is a sample; alter the names:
|
|||||||
This General Public License does not permit incorporating your program into
|
This General Public License does not permit incorporating your program into
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
consider it more useful to permit linking proprietary applications with the
|
consider it more useful to permit linking proprietary applications with the
|
||||||
library. If this is what you want to do, use the GNU Lesser General
|
library. If this is what you want to do, use the GNU Library General
|
||||||
Public License instead of this License.
|
Public License instead of this License.
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
Basic Installation
|
||||||
|
==================
|
||||||
|
|
||||||
|
These are generic installation instructions.
|
||||||
|
|
||||||
|
The `configure' shell script attempts to guess correct values for
|
||||||
|
various system-dependent variables used during compilation. It uses
|
||||||
|
those values to create a `Makefile' in each directory of the package.
|
||||||
|
It may also create one or more `.h' files containing system-dependent
|
||||||
|
definitions. Finally, it creates a shell script `config.status' that
|
||||||
|
you can run in the future to recreate the current configuration, a file
|
||||||
|
`config.cache' that saves the results of its tests to speed up
|
||||||
|
reconfiguring, and a file `config.log' containing compiler output
|
||||||
|
(useful mainly for debugging `configure').
|
||||||
|
|
||||||
|
If you need to do unusual things to compile the package, please try
|
||||||
|
to figure out how `configure' could check whether to do them, and mail
|
||||||
|
diffs or instructions to the address given in the `README' so they can
|
||||||
|
be considered for the next release. If at some point `config.cache'
|
||||||
|
contains results you don't want to keep, you may remove or edit it.
|
||||||
|
|
||||||
|
The file `configure.in' is used to create `configure' by a program
|
||||||
|
called `autoconf'. You only need `configure.in' if you want to change
|
||||||
|
it or regenerate `configure' using a newer version of `autoconf'.
|
||||||
|
|
||||||
|
The simplest way to compile this package is:
|
||||||
|
|
||||||
|
1. `cd' to the directory containing the package's source code and type
|
||||||
|
`./configure' to configure the package for your system. If you're
|
||||||
|
using `csh' on an old version of System V, you might need to type
|
||||||
|
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||||
|
`configure' itself.
|
||||||
|
|
||||||
|
Running `configure' takes awhile. While running, it prints some
|
||||||
|
messages telling which features it is checking for.
|
||||||
|
|
||||||
|
2. Type `make' to compile the package.
|
||||||
|
|
||||||
|
3. Optionally, type `make check' to run any self-tests that come with
|
||||||
|
the package.
|
||||||
|
|
||||||
|
4. Type `make install' to install the programs and any data files and
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
5. You can remove the program binaries and object files from the
|
||||||
|
source code directory by typing `make clean'. To also remove the
|
||||||
|
files that `configure' created (so you can compile the package for
|
||||||
|
a different kind of computer), type `make distclean'. There is
|
||||||
|
also a `make maintainer-clean' target, but that is intended mainly
|
||||||
|
for the package's developers. If you use it, you may have to get
|
||||||
|
all sorts of other programs in order to regenerate files that came
|
||||||
|
with the distribution.
|
||||||
|
|
||||||
|
Compilers and Options
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Some systems require unusual options for compilation or linking that
|
||||||
|
the `configure' script does not know about. You can give `configure'
|
||||||
|
initial values for variables by setting them in the environment. Using
|
||||||
|
a Bourne-compatible shell, you can do that on the command line like
|
||||||
|
this:
|
||||||
|
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
|
||||||
|
|
||||||
|
Or on systems that have the `env' program, you can do it like this:
|
||||||
|
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
|
||||||
|
|
||||||
|
Compiling For Multiple Architectures
|
||||||
|
====================================
|
||||||
|
|
||||||
|
You can compile the package for more than one kind of computer at the
|
||||||
|
same time, by placing the object files for each architecture in their
|
||||||
|
own directory. To do this, you must use a version of `make' that
|
||||||
|
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||||
|
directory where you want the object files and executables to go and run
|
||||||
|
the `configure' script. `configure' automatically checks for the
|
||||||
|
source code in the directory that `configure' is in and in `..'.
|
||||||
|
|
||||||
|
If you have to use a `make' that does not supports the `VPATH'
|
||||||
|
variable, you have to compile the package for one architecture at a time
|
||||||
|
in the source code directory. After you have installed the package for
|
||||||
|
one architecture, use `make distclean' before reconfiguring for another
|
||||||
|
architecture.
|
||||||
|
|
||||||
|
Installation Names
|
||||||
|
==================
|
||||||
|
|
||||||
|
By default, `make install' will install the package's files in
|
||||||
|
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||||
|
installation prefix other than `/usr/local' by giving `configure' the
|
||||||
|
option `--prefix=PATH'.
|
||||||
|
|
||||||
|
You can specify separate installation prefixes for
|
||||||
|
architecture-specific files and architecture-independent files. If you
|
||||||
|
give `configure' the option `--exec-prefix=PATH', the package will use
|
||||||
|
PATH as the prefix for installing programs and libraries.
|
||||||
|
Documentation and other data files will still use the regular prefix.
|
||||||
|
|
||||||
|
In addition, if you use an unusual directory layout you can give
|
||||||
|
options like `--bindir=PATH' to specify different values for particular
|
||||||
|
kinds of files. Run `configure --help' for a list of the directories
|
||||||
|
you can set and what kinds of files go in them.
|
||||||
|
|
||||||
|
If the package supports it, you can cause programs to be installed
|
||||||
|
with an extra prefix or suffix on their names by giving `configure' the
|
||||||
|
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||||
|
|
||||||
|
Optional Features
|
||||||
|
=================
|
||||||
|
|
||||||
|
Some packages pay attention to `--enable-FEATURE' options to
|
||||||
|
`configure', where FEATURE indicates an optional part of the package.
|
||||||
|
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||||
|
is something like `gnu-as' or `x' (for the X Window System). The
|
||||||
|
`README' should mention any `--enable-' and `--with-' options that the
|
||||||
|
package recognizes.
|
||||||
|
|
||||||
|
For packages that use the X Window System, `configure' can usually
|
||||||
|
find the X include and library files automatically, but if it doesn't,
|
||||||
|
you can use the `configure' options `--x-includes=DIR' and
|
||||||
|
`--x-libraries=DIR' to specify their locations.
|
||||||
|
|
||||||
|
Specifying the System Type
|
||||||
|
==========================
|
||||||
|
|
||||||
|
There may be some features `configure' can not figure out
|
||||||
|
automatically, but needs to determine by the type of host the package
|
||||||
|
will run on. Usually `configure' can figure that out, but if it prints
|
||||||
|
a message saying it can not guess the host type, give it the
|
||||||
|
`--host=TYPE' option. TYPE can either be a short name for the system
|
||||||
|
type, such as `sun4', or a canonical name with three fields:
|
||||||
|
CPU-COMPANY-SYSTEM
|
||||||
|
|
||||||
|
See the file `config.sub' for the possible values of each field. If
|
||||||
|
`config.sub' isn't included in this package, then this package doesn't
|
||||||
|
need to know the host type.
|
||||||
|
|
||||||
|
If you are building compiler tools for cross-compiling, you can also
|
||||||
|
use the `--target=TYPE' option to select the type of system they will
|
||||||
|
produce code for and the `--build=TYPE' option to select the type of
|
||||||
|
system on which you are compiling the package.
|
||||||
|
|
||||||
|
Sharing Defaults
|
||||||
|
================
|
||||||
|
|
||||||
|
If you want to set default values for `configure' scripts to share,
|
||||||
|
you can create a site shell script called `config.site' that gives
|
||||||
|
default values for variables like `CC', `cache_file', and `prefix'.
|
||||||
|
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||||
|
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||||
|
`CONFIG_SITE' environment variable to the location of the site script.
|
||||||
|
A warning: not all `configure' scripts look for a site script.
|
||||||
|
|
||||||
|
Operation Controls
|
||||||
|
==================
|
||||||
|
|
||||||
|
`configure' recognizes the following options to control how it
|
||||||
|
operates.
|
||||||
|
|
||||||
|
`--cache-file=FILE'
|
||||||
|
Use and save the results of the tests in FILE instead of
|
||||||
|
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
|
||||||
|
debugging `configure'.
|
||||||
|
|
||||||
|
`--help'
|
||||||
|
Print a summary of the options to `configure', and exit.
|
||||||
|
|
||||||
|
`--quiet'
|
||||||
|
`--silent'
|
||||||
|
`-q'
|
||||||
|
Do not print messages saying which checks are being made. To
|
||||||
|
suppress all normal output, redirect it to `/dev/null' (any error
|
||||||
|
messages will still be shown).
|
||||||
|
|
||||||
|
`--srcdir=DIR'
|
||||||
|
Look for the package's source code in directory DIR. Usually
|
||||||
|
`configure' can determine that directory automatically.
|
||||||
|
|
||||||
|
`--version'
|
||||||
|
Print the version of Autoconf used to generate the `configure'
|
||||||
|
script, and exit.
|
||||||
|
|
||||||
|
`configure' also accepts some other, not widely useful, options.
|
||||||
+2
-27
@@ -1,27 +1,2 @@
|
|||||||
SUBDIRS = \
|
EXTRA_DIST = configure acconfig.h aclocal.m4 acinclude.m4 reconf
|
||||||
src \
|
SUBDIRS = src doc
|
||||||
data \
|
|
||||||
etc \
|
|
||||||
docs \
|
|
||||||
m4macros \
|
|
||||||
tests
|
|
||||||
|
|
||||||
# tools want this on a single line
|
|
||||||
ACLOCAL_AMFLAGS = -I m4macros
|
|
||||||
|
|
||||||
EXTRA_DIST = \
|
|
||||||
autogen.sh \
|
|
||||||
tinyproxy-indent.sh \
|
|
||||||
TODO
|
|
||||||
|
|
||||||
test: all
|
|
||||||
./tests/scripts/run_tests.sh
|
|
||||||
|
|
||||||
test-wait:
|
|
||||||
TINYPROXY_TESTS_WAIT=yes $(MAKE) test
|
|
||||||
|
|
||||||
valgrind-test: all
|
|
||||||
./tests/scripts/run_tests_valgrind.sh
|
|
||||||
|
|
||||||
valgrind-test-wait:
|
|
||||||
TINYPROXY_TESTS_WAIT=yes $(MAKE) valgrind-test
|
|
||||||
@@ -1,153 +1,26 @@
|
|||||||
Tinyproxy NEWS
|
|
||||||
==============
|
|
||||||
|
|
||||||
Version 1.8.3
|
NEWS
|
||||||
-------------
|
====
|
||||||
|
|
||||||
This release mostly fixes support for IPv6, and also some security
|
This is the long awaited 1.4.0 release of tinyproxy. Most of the
|
||||||
bugs. Fixes to messages, etc. were also made.
|
tinyproxy source has been rewritten in one form or another. The old
|
||||||
|
ADNS code has been removed, and the giant (ugly) state machine has
|
||||||
|
been banished. These have been replaced by a threaded connection
|
||||||
|
system. Not only did this make the source code cleaner, but it should
|
||||||
|
improve performance on SMP machines.
|
||||||
|
|
||||||
Bugs resolved since version 1.8.2
|
Another change to tinyproxy is the new configuration file. Take a look
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
at doc/tinyproxy.conf for an example of how to configure tinyproxy. If
|
||||||
|
you have any experience configuring the Apache web server you will
|
||||||
|
immediately see similarities between the tinyproxy and Apache
|
||||||
|
configuration files. In other words, we liberally copied from the
|
||||||
|
Apache style.
|
||||||
|
|
||||||
* BB#91: Fix upstream proxy support
|
The access control list (ACL) feature of tinyproxy has been greatly
|
||||||
* BB#95: Fix FilterURLs with transparent proxy support
|
expanded. tinyproxy now allows you to selectively allow or deny a much
|
||||||
* BB#90: Fix bug in ACL netmask generation
|
more specific set of IP addresses or subnets. In the same vein,
|
||||||
|
tinyproxy can be configured to only bind to one address on a
|
||||||
|
multi-homed machine.
|
||||||
|
|
||||||
Contributors
|
If this version is not the best tinyproxy released, than it's pretty
|
||||||
~~~~~~~~~~~~
|
darn close.
|
||||||
|
|
||||||
Daniel Egger, John Horne, Michael Adam, Mukund Sivaraman.
|
|
||||||
|
|
||||||
|
|
||||||
Version 1.8.2
|
|
||||||
-------------
|
|
||||||
|
|
||||||
* Minor formatting changes and typo fixes were made.
|
|
||||||
|
|
||||||
Bugs resolved since version 1.8.1
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
* BB#69: INET6 not available when configured to Listen and Bind in v4,
|
|
||||||
and vice versa
|
|
||||||
* BB#74: tinyproxy unable to reopen log files after receiving HUP
|
|
||||||
* BB#78: Warn if configuration results in an open proxy
|
|
||||||
* BB#82: https access not working
|
|
||||||
* BB#83: run_tests.sh relies on $USER
|
|
||||||
* BB#84: Unaligned access error on ia64 and alpha
|
|
||||||
* BB#87: Unable to listen on ports less than 1024 (regression in 1.8.1)
|
|
||||||
* BB#88: Crashes when reloading configuration
|
|
||||||
* BB#89: tinyproxy leaks memory over time
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Dmitry Semyonov, John van der Kamp, Jordi Mallach, Michael Adam,
|
|
||||||
Mukund Sivaraman.
|
|
||||||
|
|
||||||
|
|
||||||
Version 1.8.1
|
|
||||||
-------------
|
|
||||||
|
|
||||||
* Tinyproxy now drops `root` user privileges more quickly.
|
|
||||||
* The log and pid files are now stored in a sub-directory in `/var/`.
|
|
||||||
* A format string vulnerability was fixed.
|
|
||||||
* Minor formatting changes and typo fixes were made.
|
|
||||||
|
|
||||||
Bugs fixed since version 1.8.0
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
* BB#74: tinyproxy unable to reopen log files after receiving HUP
|
|
||||||
* BB#79: Make the testsuite uninteractive
|
|
||||||
* BB#80: Handle errors in testsuite
|
|
||||||
* BB#81: Listen directive doesn't work as expected
|
|
||||||
* BB#72: upstream support is not reported with tinyproxy -h
|
|
||||||
* BB#73: generated tinyproxy.conf has the wrong location for the html
|
|
||||||
file installation
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Michael Adam, Mukund Sivaraman.
|
|
||||||
|
|
||||||
|
|
||||||
Version 1.8.0
|
|
||||||
-------------
|
|
||||||
|
|
||||||
* Tinyproxy now reloads its configuration upon SIGHUP signal.
|
|
||||||
* Tinyproxy reopens its log file (instead of truncation) upon SIGHUP
|
|
||||||
signal. This is to play more nicely with logrotate.
|
|
||||||
* File logging is now the default.
|
|
||||||
Syslog is chosen if and only if "SysLog Yes" is in the config,
|
|
||||||
i.e., a present "SysLog Yes" in the config file now overrides
|
|
||||||
any LogFile setting.
|
|
||||||
* The XTinyProxy option is now documented as a global boolean.
|
|
||||||
Before it was documented to build a list of sites to add a
|
|
||||||
X-Tinyproxy header for, but it was implemented as global boolean.
|
|
||||||
* A new config option AddHeader allows the user to configure a list of
|
|
||||||
custom headers to send in outgoing HTTP requests.
|
|
||||||
* A new config option DisableViaHeader allows the user to disable
|
|
||||||
sending of the "Via:" header.
|
|
||||||
* Tinyproxy is now IPv6 capable.
|
|
||||||
* The config option PidFile now has a compiled in default.
|
|
||||||
|
|
||||||
Bugs fixed since version 1.7.1
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
* BB#9: Add support for the IPv6 protocol
|
|
||||||
* BB#17: Add support for custom headers
|
|
||||||
* BB#55: Error message response omits body when request has a body
|
|
||||||
* BB#60: Add config option to disable Via header
|
|
||||||
* BB#61: SIGHUP does not refresh filter list
|
|
||||||
* BB#62: Make tinyproxy reload the config upon SIGHUP
|
|
||||||
* BB#64: Config parsing error with reverse proxy option
|
|
||||||
* BB#65: Format string compile warnings
|
|
||||||
* BB#67: ACL processing error with multiple Allow statements
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
~~~~~~~~~~~~
|
|
||||||
|
|
||||||
David Shanks, Mathew Mrosko, Michael Adam, Mukund Sivaraman.
|
|
||||||
|
|
||||||
|
|
||||||
Version 1.7.1
|
|
||||||
-------------
|
|
||||||
|
|
||||||
* Fixed all warnings reported by GCC.
|
|
||||||
* The tinyproxy manpage has been extended and converted to asciidoc.
|
|
||||||
* There is a new tinyproxy.conf manpage that describes all the options.
|
|
||||||
* The build system has been considerably cleaned up.
|
|
||||||
* Various other bugs have been fixed.
|
|
||||||
|
|
||||||
Bugs fixed since version 1.7.0
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
* BB#2: Fix Tinyproxy for requests like www.site.com:8001
|
|
||||||
* BB#5: Move templates from the doc directory to its own directory
|
|
||||||
* BB#8: Update README, INSTALL, NEWS and the manpage
|
|
||||||
* BB#10: Do not filter out transfer-encoding header
|
|
||||||
* BB#18: Fix pointer aliasing issues
|
|
||||||
* BB#53: Add a GPLv2 COPYING file
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Andrew Stribblehill, Jeremy Hinegardner, Matthew Dempsky, Michael Adam,
|
|
||||||
Mukund Sivaraman, Robert James Kaes.
|
|
||||||
|
|
||||||
|
|
||||||
Version 1.7.0
|
|
||||||
-------------
|
|
||||||
|
|
||||||
* There is now support for reverse proxying.
|
|
||||||
* Tinyproxy does not bundle a vendor regular expressions library
|
|
||||||
anymore. It uses the system installed regular expressions library.
|
|
||||||
* The documentation has been updated.
|
|
||||||
* Tinyproxy now contains some code optimizations such as the use of a
|
|
||||||
hashmap internally for looking up error pages.
|
|
||||||
* Various other bugs have been fixed.
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Kim Holviala, Marc Silver, Robert James Kaes, Steven Young.
|
|
||||||
@@ -1,97 +1,88 @@
|
|||||||
Tinyproxy
|
|
||||||
=========
|
|
||||||
|
|
||||||
Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
|
DESCRIPTION
|
||||||
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:
|
tinyproxy is a small, efficient HTTP proxy daemon. tinyproxy is very
|
||||||
|
useful in a small network setting, where a larger proxy like Squid
|
||||||
https://banu.com/tinyproxy/
|
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.
|
||||||
|
|
||||||
|
|
||||||
Installation
|
INSTALLATION
|
||||||
------------
|
------------
|
||||||
|
|
||||||
To install this package under a UNIX derivative, read the INSTALL file.
|
To install this package under a Unix derivative, read the INSTALL
|
||||||
Tinyproxy uses a standard GNU `configure` script. Basically you should
|
file. tinyproxy uses a standard GNU configure script. There are
|
||||||
be able to do:
|
additional command line arguments you can supply to configure. They
|
||||||
|
include:
|
||||||
----
|
|
||||||
./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
|
--enable-debug If you would like to turn on full
|
||||||
debugging support
|
debugging support
|
||||||
|
--enable-socks This turns on SOCKS support for using
|
||||||
|
tinyproxy across a fire wall.
|
||||||
--enable-xtinyproxy Compile in support for the XTinyproxy
|
--enable-xtinyproxy Compile in support for the XTinyproxy
|
||||||
header, which is sent to any web
|
header, which is sent to any web
|
||||||
server in your domain.
|
server in your domain.
|
||||||
--enable-filter Allows Tinyproxy to filter out certain
|
--enable-filter Allows tinyproxy to filter out certain
|
||||||
domains and URLs.
|
domains and URLs.
|
||||||
--enable-upstream Enable support for proxying connections
|
--enable-tunnel Provides the option of having
|
||||||
through another proxy server.
|
tinyproxy act as TCP tunnel, rather
|
||||||
--enable-transparent
|
than a HTTP 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
|
Options for file locations etc.
|
||||||
|
--with-port=PORT Set the port on which tinyproxy listens,
|
||||||
|
by default 8080.
|
||||||
|
--with-log-file=FILE Set the default logfile location.
|
||||||
|
--with-user=USER Set the default user to which tinyproxy
|
||||||
|
will setuid() upon startup.
|
||||||
|
|
||||||
|
Once you have completed your installation, if you would like to
|
||||||
|
report your success please execute the report.sh script in the doc
|
||||||
|
directory. This will send an email to the authors reporting your
|
||||||
|
version, and a few bits of information concerning the memory usage of
|
||||||
|
tinyproxy. Alternatively, you could just send an email stating the
|
||||||
|
version. Which ever you prefer.
|
||||||
|
|
||||||
|
|
||||||
Support
|
SUPPORT
|
||||||
-------
|
-------
|
||||||
|
|
||||||
If you are having problems with Tinyproxy, please submit a bug report
|
If you are having problems with tinyproxy, please report the problem
|
||||||
using Tinyproxy as the product at:
|
to:
|
||||||
|
|
||||||
https://banu.com/bugzilla/
|
Robert James Kaes <rjkaes@flarenet.com>
|
||||||
|
Steven Young <sdyoung@users.sourceforge.net>
|
||||||
|
|
||||||
You may also wish to subscribe to the Tinyproxy mailing lists. To do so
|
Please recompile tinyproxy with full debug support (--enable-debug)
|
||||||
please visit:
|
and include a copy of the log file, and any assert errors reported by
|
||||||
|
tinyproxy. Also, if you feel up to it, try running tinyproxy under
|
||||||
|
your debugger and report the error your received and a context
|
||||||
|
listing of the location. Under gdb you would run tinyproxy like so:
|
||||||
|
|
||||||
https://banu.com/mailman/listinfo/tinyproxy-announce-list
|
gdb tinyproxy
|
||||||
https://banu.com/mailman/listinfo/tinyproxy-users-list
|
|
||||||
https://banu.com/mailman/listinfo/tinyproxy-developers-list
|
|
||||||
|
|
||||||
for more information on how to subscribe and post messages to the lists.
|
(gdb) set args -c location_of_tinyproxy_conf -d
|
||||||
|
(gdb) run
|
||||||
|
|
||||||
|
Now access the port tinyproxy is on until you receive a break in the
|
||||||
|
gdb. You can now type:
|
||||||
|
|
||||||
Contributing
|
(gbd) l
|
||||||
------------
|
|
||||||
|
|
||||||
If you would like to contribute a feature, or a bug fix to the Tinyproxy
|
to produce a context listing of the location of the error. Send a
|
||||||
source, please send a patch (preferably as a unified diff. i.e. `diff
|
copy to the authors.
|
||||||
-u` against the "master" branch of the Tinyproxy source code git
|
|
||||||
repository to tinyproxy-developers-list. Please include a description
|
|
||||||
of what your patch does.
|
|
||||||
|
|
||||||
Tinyproxy's git repository is git://banu.com/tinyproxy.git. The
|
HOW TO CONTRIBUTE TO tinyproxy
|
||||||
following command creates a local copy:
|
------------------------------
|
||||||
|
|
||||||
----
|
If you would like to contribute a feature, or a bug fix to the
|
||||||
git clone git://banu.com/tinyproxy.git
|
tinyproxy source, please send a diff (preferable a unified
|
||||||
----
|
diff. i.e. "diff -u") against the latest release of tinyproxy. Also,
|
||||||
|
if you could include a brief description of what your patch does.
|
||||||
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,43 @@
|
|||||||
|
Tinyproxy wouldn't be possible in its current form without the help of
|
||||||
|
the following people. Thanks a lot, guys (sorted in no particular
|
||||||
|
order). Note that in the case of entries listed under 'numerous others',
|
||||||
|
only the first person to report it is listed.
|
||||||
|
|
||||||
|
|
||||||
|
Steven Young - Wrote version 1.0 - 1.1
|
||||||
|
Robert James Kaes - Wrote versions from 1.2 to 1.3 and
|
||||||
|
autoconf enabled the source tree and
|
||||||
|
well just look at the ChangeLog for all
|
||||||
|
the rest. :)
|
||||||
|
Albert Ragnarsson - Made an RPM out of the 1.0d .tar.gz archive.
|
||||||
|
Alan W Black - Misc. bug reports and fixes.
|
||||||
|
Ed Boraas - Various suggestions, helped beta test 1.0d.
|
||||||
|
Abhijit Menon-Sen - Beta tested 1.1, numerous bugs fixed
|
||||||
|
and features improved. Also helped
|
||||||
|
establish world peace and eliminate
|
||||||
|
hunger and poverty. Generally
|
||||||
|
credited with the singlehanded
|
||||||
|
abolition of all crime and dishonesty.
|
||||||
|
Jay Kominek - Made the 1.1 DEB.
|
||||||
|
Eran Tromer - Provided webspace at attacca.com.
|
||||||
|
Bruno Viaris - Found and provided initial fix for
|
||||||
|
bug in the clientreq() routine when
|
||||||
|
dealing with broken requests from clients.
|
||||||
|
Alexander Loehr - Found and provided fix for a bug in
|
||||||
|
the listen_sock routine.
|
||||||
|
Bob Grabau - Added additional logging of URLs to
|
||||||
|
incoming connections.
|
||||||
|
Mitsuru Yoshida - Made the FreeBSD port
|
||||||
|
Ian Holsman - Suggested the selective listening option
|
||||||
|
Peter Meerwald - Portability suggests and improvements
|
||||||
|
Shaun Johnson - Fixed a problem with compiling with
|
||||||
|
syslog enabled on a SunOS box. Should
|
||||||
|
help other systems too.
|
||||||
|
Timothy E. Newsome - SOCKS firewall enabled tinyproxy
|
||||||
|
George Talusan - Bug testing
|
||||||
|
Chris Lightfoot - Provided patches to give tinyproxy adns
|
||||||
|
support.
|
||||||
|
Michael Pearson - Reported connptr bug with patch.
|
||||||
|
Raja Subramanian - Reported fd leak bug, with patch.
|
||||||
|
J.D. Bronson - Helped make version 1.4.0 release ready
|
||||||
|
numerous others - Reported null requests bug.
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
TODO List
|
|
||||||
---------
|
|
||||||
|
|
||||||
The following are features that I would like to add to tinyproxy in the
|
|
||||||
future. Where possible, I've listed the person who suggested it. This
|
|
||||||
list is in no particular order. And hey, if you want to implement one of
|
|
||||||
these, or another idea you have, go right ahead. Just mail me the diff
|
|
||||||
against the current tree and I'll integrate it if possible.
|
|
||||||
|
|
||||||
[ Actually, the ordering has become kind of important as of
|
|
||||||
late. Basically, I'm adding new ideas to the bottom of the list
|
|
||||||
as I go. ]
|
|
||||||
|
|
||||||
* Include hooks so other types of proxies can be modularly added to
|
|
||||||
the source tree. Then people can simply choose which types of
|
|
||||||
proxies (ftp, www, etc) they'd like enabled in tinyproxy.h
|
|
||||||
Suggested: Tarun Tuli.
|
|
||||||
|
|
||||||
* Include a function to rewrite the incoming requests. Should not be
|
|
||||||
much of a problem. Just need to modify the process_method() code
|
|
||||||
to look up the URL and rewrite it. If we want to go really fancy
|
|
||||||
with RegEx mapping this could get ugly. :)
|
|
||||||
|
|
||||||
* Have the ability to send the data from the connections through an
|
|
||||||
external filtering program. I kind of like this idea, but I don't
|
|
||||||
really have a good way of doing it yet.
|
|
||||||
Suggested: Ed Avis
|
|
||||||
|
|
||||||
* Include the ability to rewrite both incoming and outgoing headers.
|
|
||||||
|
|
||||||
* Enable an option for chroot() jailing tinyproxy.
|
|
||||||
|
|
||||||
* Come up with a more consistent (and elegant) way of logging errors
|
|
||||||
for the administrators. Right now it's more a hodge-podge
|
|
||||||
collections of error messages without a _real_ standard. I would
|
|
||||||
prefer a more uniform look.
|
|
||||||
|
|
||||||
* Include user authentication for accessing tinyproxy itself.
|
|
||||||
Administrators should be allowed to selectively allow certain users
|
|
||||||
access to tinyproxy via a user name/password pair. Check the
|
|
||||||
HTTP/1.1 RFC for more information. [Suggested: Tyrone Tranmer]
|
|
||||||
|
|
||||||
==> https://www.banu.com/bugzilla/show_bug.cgi?id=13
|
|
||||||
|
|
||||||
* Remove common.h and fix order of headers
|
|
||||||
|
|
||||||
* Remove memory debugging functions (Valgrind is good enough)
|
|
||||||
|
|
||||||
* Make all functions return from one place (the end of the function)
|
|
||||||
|
|
||||||
* Move TODO items to Banu Bugzilla
|
|
||||||
|
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Define if you want to have the peer's IP address to be included in a
|
||||||
|
* XTinyproxy header sent to the server.
|
||||||
|
*/
|
||||||
|
#undef XTINYPROXY_ENABLE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are the defaults, but they can be changed by configure at compile
|
||||||
|
* time, or on the command line at runtime.
|
||||||
|
*/
|
||||||
|
#define DEFAULT_LOG "/var/log/tinyproxy"
|
||||||
|
#define DEFAULT_PORT 8888
|
||||||
|
#define DEFAULT_USER ""
|
||||||
|
#define DEFAULT_CONF_FILE "/etc/tinyproxy/tinyproxy.conf"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if you would like to include filtering code.
|
||||||
|
*/
|
||||||
|
#undef FILTER_ENABLE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if you want to use the included GNU regex routine
|
||||||
|
*/
|
||||||
|
#undef USE_GNU_REGEX
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if you want to include upstream proxy support
|
||||||
|
*/
|
||||||
|
#undef TUNNEL_SUPPORT
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: for DEFAULT_STATHOST: this controls remote proxy stats display.
|
||||||
|
* for example, the default DEFAULT_STATHOST of "tinyproxy.stats" will
|
||||||
|
* mean that when you use the proxy to access http://tinyproxy.stats/",
|
||||||
|
* you will be shown the proxy stats. Set this to something obscure
|
||||||
|
* if you don't want random people to be able to see them, or set it to
|
||||||
|
* "" to disable. In the future, I figure maybe some sort of auth
|
||||||
|
* might be desirable, but that would involve a major simplicity
|
||||||
|
* sacrifice.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The "hostname" for getting tinyproxy stats. "" = disabled by default
|
||||||
|
*/
|
||||||
|
#define DEFAULT_STATHOST "tinyproxy.stats"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define the following for the appropriate datatype, if necessary
|
||||||
|
*/
|
||||||
|
#undef uint8_t
|
||||||
|
#undef int16_t
|
||||||
|
#undef uint16_t
|
||||||
|
#undef int32_t
|
||||||
|
#undef uint32_t
|
||||||
|
#undef in_addr_t
|
||||||
|
#undef size_t
|
||||||
|
#undef ssize_t
|
||||||
|
#undef socklen_t
|
||||||
@@ -13,10 +13,10 @@ 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 performed, since we #include "confdefs.h" below, and then use the
|
||||||
dnl HAVE_foo_H values that is can #define.
|
dnl HAVE_foo_H values that is can #define.
|
||||||
dnl
|
dnl
|
||||||
AC_DEFUN([AC_UNP_CHECK_TYPE],
|
AC_DEFUN(AC_UNP_CHECK_TYPE,
|
||||||
[AC_MSG_CHECKING(if $1 defined)
|
[AC_MSG_CHECKING(if $1 defined)
|
||||||
AC_CACHE_VAL(ac_cv_type_$1,
|
AC_CACHE_VAL(ac_cv_type_$1,
|
||||||
[AC_TRY_COMPILE(
|
AC_TRY_COMPILE(
|
||||||
[
|
[
|
||||||
#include "confdefs.h" /* the header built by configure so far */
|
#include "confdefs.h" /* the header built by configure so far */
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
@@ -93,11 +93,10 @@ AC_DEFUN([AC_UNP_CHECK_TYPE],
|
|||||||
#endif
|
#endif
|
||||||
],
|
],
|
||||||
[ $1 foo ],
|
[ $1 foo ],
|
||||||
[ac_cv_type_$1=yes],
|
ac_cv_type_$1=yes,
|
||||||
[ac_cv_type_$1=no])])
|
ac_cv_type_$1=no))
|
||||||
AC_MSG_RESULT([$ac_cv_type_$1])
|
AC_MSG_RESULT($ac_cv_type_$1)
|
||||||
if test $ac_cv_type_$1 = no ; then
|
if test $ac_cv_type_$1 = no ; then
|
||||||
AH_TEMPLATE([$1], [Defined with the proper type.])
|
|
||||||
AC_DEFINE($1, $2)
|
AC_DEFINE($1, $2)
|
||||||
fi
|
fi
|
||||||
])
|
])
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
srcdir=`dirname $0`
|
|
||||||
test -z "$srcdir" && srcdir=.
|
|
||||||
ORIGDIR=`pwd`
|
|
||||||
|
|
||||||
set -x
|
|
||||||
|
|
||||||
cd $srcdir
|
|
||||||
|
|
||||||
aclocal -I m4macros \
|
|
||||||
&& autoheader \
|
|
||||||
&& automake --gnu --add-missing \
|
|
||||||
&& autoconf
|
|
||||||
|
|
||||||
cd $ORIGDIR
|
|
||||||
|
|
||||||
set -
|
|
||||||
|
|
||||||
echo $srcdir/configure "$@"
|
|
||||||
$srcdir/configure "$@"
|
|
||||||
RC=$?
|
|
||||||
if test $RC -ne 0; then
|
|
||||||
echo
|
|
||||||
echo "Configure failed or did not finish!"
|
|
||||||
exit $RC
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Now type 'make' to compile Tinyproxy."
|
|
||||||
-308
@@ -1,308 +0,0 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
|
||||||
# Portions of this file were adapted from GIMP.
|
|
||||||
|
|
||||||
AC_PREREQ(2.54)
|
|
||||||
|
|
||||||
m4_define([tinyproxy_major_version], [1])
|
|
||||||
m4_define([tinyproxy_minor_version], [8])
|
|
||||||
m4_define([tinyproxy_micro_version], [3])
|
|
||||||
m4_define([tinyproxy_real_version],
|
|
||||||
[tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
|
|
||||||
m4_define([tinyproxy_version], [tinyproxy_real_version])
|
|
||||||
|
|
||||||
# For overriding the version string. Comment out if not needed.
|
|
||||||
# m4_define([tinyproxy_version], [1.8.2])
|
|
||||||
|
|
||||||
m4_define([tinyproxy_unstable],
|
|
||||||
m4_if(m4_eval(tinyproxy_minor_version % 2), [1], [yes], [no]))
|
|
||||||
m4_define([tinyproxy_stable],
|
|
||||||
m4_if(m4_eval(tinyproxy_minor_version % 2), [0], [yes], [no]))
|
|
||||||
|
|
||||||
AC_INIT([Tinyproxy], [tinyproxy_version],
|
|
||||||
[https://banu.com/tinyproxy/],
|
|
||||||
[tinyproxy])
|
|
||||||
|
|
||||||
AC_CANONICAL_TARGET
|
|
||||||
AM_INIT_AUTOMAKE([dist-bzip2])
|
|
||||||
AM_CONFIG_HEADER(config.h)
|
|
||||||
AC_CONFIG_MACRO_DIR([m4macros])
|
|
||||||
|
|
||||||
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
|
|
||||||
|
|
||||||
TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
|
|
||||||
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
|
|
||||||
TINYPROXY_MICRO_VERSION=tinyproxy_micro_version
|
|
||||||
TINYPROXY_REAL_VERSION=tinyproxy_real_version
|
|
||||||
TINYPROXY_VERSION=tinyproxy_version
|
|
||||||
TINYPROXY_UNSTABLE=tinyproxy_unstable
|
|
||||||
AC_SUBST(TINYPROXY_MAJOR_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_MINOR_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_MICRO_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_REAL_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_VERSION)
|
|
||||||
AC_SUBST(TINYPROXY_UNSTABLE)
|
|
||||||
|
|
||||||
dnl Temporarily defined here until we get tinyproxy-version.h
|
|
||||||
AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number])
|
|
||||||
|
|
||||||
# The symbol TINYPROXY_UNSTABLE is defined above for substitution in
|
|
||||||
# Makefiles and conditionally defined here as a preprocessor symbol
|
|
||||||
# and automake conditional.
|
|
||||||
if test "x$TINYPROXY_UNSTABLE" = "xyes"; then
|
|
||||||
AC_DEFINE(TINYPROXY_UNSTABLE, 1,
|
|
||||||
[Define to 1 if this is an unstable version of Tinyproxy])
|
|
||||||
fi
|
|
||||||
AM_CONDITIONAL(TINYPROXY_UNSTABLE, test "x$TINYPROXY_UNSTABLE" = "xyes")
|
|
||||||
|
|
||||||
|
|
||||||
dnl Check if we're compiling on a weird platform :)
|
|
||||||
AC_USE_SYSTEM_EXTENSIONS
|
|
||||||
|
|
||||||
|
|
||||||
dnl Set the domain name for find the statistics of tinyproxy
|
|
||||||
AH_TEMPLATE([TINYPROXY_STATHOST],
|
|
||||||
[This controls remote proxy stats display.])
|
|
||||||
AC_ARG_WITH(stathost,
|
|
||||||
[AC_HELP_STRING([--with-stathost=HOST], [Default status host])],
|
|
||||||
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")
|
|
||||||
TINYPROXY_STATHOST="$withval"],
|
|
||||||
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")
|
|
||||||
TINYPROXY_STATHOST="tinyproxy.stats"])
|
|
||||||
|
|
||||||
AC_SUBST(TINYPROXY_STATHOST)
|
|
||||||
|
|
||||||
dnl Add compiler-specific optimization flags
|
|
||||||
TP_ARG_ENABLE(debug,
|
|
||||||
[Enable debugging support code and methods (default is NO)],
|
|
||||||
no)
|
|
||||||
|
|
||||||
dnl Check to see if the XTinyproxy header is to be included
|
|
||||||
AH_TEMPLATE([XTINYPROXY_ENABLE],
|
|
||||||
[Define if you want to have the peer's IP address included in a XTinyproxy header sent to the server.])
|
|
||||||
TP_ARG_ENABLE(xtinyproxy,
|
|
||||||
[Include the X-Tinyproxy header (default is YES)],
|
|
||||||
yes)
|
|
||||||
|
|
||||||
if test x"$xtinyproxy_enabled" = x"yes"; then
|
|
||||||
AC_DEFINE(XTINYPROXY_ENABLE)
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl Include filtering for domain/URLs
|
|
||||||
AH_TEMPLATE([FILTER_ENABLE],
|
|
||||||
[Defined if you would like filtering code included.])
|
|
||||||
TP_ARG_ENABLE(filter,
|
|
||||||
[Enable filtering of domains/URLS (default is YES)],
|
|
||||||
yes)
|
|
||||||
|
|
||||||
if test x"$filter_enabled" = x"yes"; then
|
|
||||||
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS filter.o"
|
|
||||||
AC_DEFINE(FILTER_ENABLE)
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl Include support for upstream proxies?
|
|
||||||
AH_TEMPLATE([UPSTREAM_SUPPORT],
|
|
||||||
[Include support for connecting to an upstream proxy.])
|
|
||||||
TP_ARG_ENABLE(upstream,
|
|
||||||
[Enable upstream proxying (default is YES)],
|
|
||||||
yes)
|
|
||||||
if test x"$upstream_enabled" = x"yes"; then
|
|
||||||
AC_DEFINE(UPSTREAM_SUPPORT)
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl Include support for reverse proxy?
|
|
||||||
AH_TEMPLATE([REVERSE_SUPPORT],
|
|
||||||
[Include support for reverse proxy.])
|
|
||||||
TP_ARG_ENABLE(reverse,
|
|
||||||
[Enable reverse proxying (default is NO)],
|
|
||||||
no)
|
|
||||||
if test x"$reverse_enabled" = x"yes"; then
|
|
||||||
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
|
|
||||||
AC_DEFINE(REVERSE_SUPPORT)
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl Include the transparent proxy support
|
|
||||||
AH_TEMPLATE([TRANSPARENT_PROXY],
|
|
||||||
[Include support for using tinyproxy as a transparent proxy.])
|
|
||||||
TP_ARG_ENABLE(transparent,
|
|
||||||
[Enable transparent proxying code (default is NO)],
|
|
||||||
no)
|
|
||||||
if test x"$transparent_enabled" = x"yes"; then
|
|
||||||
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
|
|
||||||
AC_DEFINE(TRANSPARENT_PROXY)
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl Check for broken regex library
|
|
||||||
TP_ARG_ENABLE(regexcheck,
|
|
||||||
[Check for working regex library (default is YES)],
|
|
||||||
yes)
|
|
||||||
|
|
||||||
# This is required to build test programs below
|
|
||||||
AC_PROG_CC
|
|
||||||
|
|
||||||
dnl
|
|
||||||
dnl Checks for libraries
|
|
||||||
dnl
|
|
||||||
AC_CHECK_LIB(socket, socket, , [AC_CHECK_LIB(socket, htonl)])
|
|
||||||
|
|
||||||
dnl Some systems (OpenServer 5) dislike -lsocket -lnsl, so we try to
|
|
||||||
dnl avoid -lnsl checks, if we already have the functions which are
|
|
||||||
dnl usually in libnsl
|
|
||||||
|
|
||||||
unset ac_cv_func_yp_get_default_domain
|
|
||||||
AC_CHECK_FUNC(yp_get_default_domain,
|
|
||||||
tinyproxy_no_nsl_checks=yes,
|
|
||||||
tinyproxy_no_nsl_checks=no)
|
|
||||||
unset ac_cv_func_yp_get_default_domain
|
|
||||||
|
|
||||||
if test x"$tinyproxy_no_nsl_checks" != x"yes"; then
|
|
||||||
AC_CHECK_LIB(nsl, gethostname, , [AC_CHECK_LIB(nsl, gethostbyaddr)])
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_CHECK_LIB(resolv, inet_aton)
|
|
||||||
|
|
||||||
dnl
|
|
||||||
dnl Checks for headers
|
|
||||||
dnl
|
|
||||||
AC_HEADER_STDC
|
|
||||||
AC_HEADER_TIME
|
|
||||||
AC_HEADER_SYS_WAIT
|
|
||||||
AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \
|
|
||||||
sys/select.h sys/socket.h sys/time.h sys/uio.h \
|
|
||||||
sys/un.h arpa/inet.h netinet/in.h \
|
|
||||||
assert.h ctype.h errno.h fcntl.h grp.h io.h libintl.h \
|
|
||||||
netdb.h pwd.h regex.h signal.h stdarg.h stddef.h stdio.h \
|
|
||||||
sysexits.h syslog.h time.h wchar.h wctype.h \
|
|
||||||
values.h])
|
|
||||||
|
|
||||||
dnl OpenBSD machines don't like having malloc included (even if it's present)
|
|
||||||
dnl as they expect you to use stdlib.h
|
|
||||||
case "$target" in
|
|
||||||
*-openbsd*) ;;
|
|
||||||
*) AC_CHECK_HEADER(malloc.h);;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
dnl Checks for types
|
|
||||||
AC_TYPE_SIZE_T
|
|
||||||
AC_TYPE_PID_T
|
|
||||||
AC_UNP_CHECK_TYPE(uint8_t, unsigned char)
|
|
||||||
AC_UNP_CHECK_TYPE(int16_t, short)
|
|
||||||
AC_UNP_CHECK_TYPE(uint16_t, unsigned short)
|
|
||||||
AC_UNP_CHECK_TYPE(int32_t, int)
|
|
||||||
AC_UNP_CHECK_TYPE(uint32_t, unsigned int)
|
|
||||||
AC_UNP_CHECK_TYPE(ssize_t, int)
|
|
||||||
AC_UNP_CHECK_TYPE(socklen_t, unsigned int)
|
|
||||||
AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
|
|
||||||
|
|
||||||
|
|
||||||
dnl Checks for libary functions
|
|
||||||
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
|
|
||||||
AC_FUNC_MALLOC
|
|
||||||
AC_FUNC_REALLOC
|
|
||||||
|
|
||||||
AC_CHECK_FUNCS([gethostname inet_ntoa memchr memset select socket strcasecmp \
|
|
||||||
strchr strdup strerror strncasecmp strpbrk strstr strtol])
|
|
||||||
AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regcomp regexec])
|
|
||||||
AC_CHECK_FUNCS([strlcpy strlcat])
|
|
||||||
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
if test -n "${MAINTAINER_MODE_FALSE}"; then
|
|
||||||
DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
|
|
||||||
fi
|
|
||||||
|
|
||||||
for flag in $DESIRED_FLAGS; do
|
|
||||||
AS_COMPILER_FLAG([$flag], [CFLAGS="$CFLAGS $flag"])
|
|
||||||
done
|
|
||||||
|
|
||||||
dnl Disable debugging if it's not specified
|
|
||||||
if test x"$debug_enabled" != x"yes" ; then
|
|
||||||
CFLAGS="-DNDEBUG $CFLAGS"
|
|
||||||
fi
|
|
||||||
|
|
||||||
LDFLAGS="-Wl,-z,defs"
|
|
||||||
|
|
||||||
dnl
|
|
||||||
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
|
|
||||||
dnl
|
|
||||||
|
|
||||||
dnl Handle the REGEX library
|
|
||||||
if test x"$ac_cv_func_regexec" != x"yes"; then
|
|
||||||
AC_MSG_ERROR([Could not locate the regexec() function])
|
|
||||||
else
|
|
||||||
if test x"$regexcheck_enabled" = x"yes" ; then
|
|
||||||
AC_MSG_CHECKING([whether the system's regex library is broken])
|
|
||||||
AC_CACHE_VAL(tinyproxy_cv_regex_broken,
|
|
||||||
[AC_TRY_RUN([
|
|
||||||
#if HAVE_SYS_TYPES_H
|
|
||||||
# include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_UNISTD_H
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_REGEX_H
|
|
||||||
# include <regex.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_STDLIB_H
|
|
||||||
# include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
regex_t blah;
|
|
||||||
if (regcomp(&blah, "foo.*bar", REG_NOSUB) != 0)
|
|
||||||
exit(1);
|
|
||||||
if (regexec(&blah, "foobar", 0, NULL, 0) != 0)
|
|
||||||
exit(1);
|
|
||||||
else
|
|
||||||
exit(0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
],
|
|
||||||
tinyproxy_cv_regex_broken=no,
|
|
||||||
tinyproxy_cv_regex_broken=yes,
|
|
||||||
tinyproxy_cv_regex_broken=yes)])
|
|
||||||
|
|
||||||
AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
|
|
||||||
|
|
||||||
if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
|
|
||||||
AC_MSG_ERROR([Your system's regexec() function is broken.])
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
dnl
|
|
||||||
dnl Substitute the variables into the various Makefiles
|
|
||||||
dnl
|
|
||||||
AC_SUBST(CFLAGS)
|
|
||||||
AC_SUBST(LDFLAGS)
|
|
||||||
AC_SUBST(CPPFLAGS)
|
|
||||||
AC_SUBST(LIBS)
|
|
||||||
AC_SUBST(ADDITIONAL_OBJECTS)
|
|
||||||
|
|
||||||
# Check for asciidoc
|
|
||||||
AC_PATH_PROG(A2X, a2x, no)
|
|
||||||
AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno")
|
|
||||||
if test x"$A2X" = x"no"; then
|
|
||||||
AC_MSG_ERROR([Test for asciidoc failed. See the file 'INSTALL' for help.])
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
|
||||||
Makefile
|
|
||||||
src/Makefile
|
|
||||||
data/Makefile
|
|
||||||
data/templates/Makefile
|
|
||||||
etc/Makefile
|
|
||||||
docs/Makefile
|
|
||||||
docs/man5/Makefile
|
|
||||||
docs/man5/tinyproxy.conf.txt
|
|
||||||
docs/man8/Makefile
|
|
||||||
docs/man8/tinyproxy.txt
|
|
||||||
m4macros/Makefile
|
|
||||||
tests/Makefile
|
|
||||||
tests/scripts/Makefile
|
|
||||||
])
|
|
||||||
|
|
||||||
AC_OUTPUT
|
|
||||||
+267
@@ -0,0 +1,267 @@
|
|||||||
|
dnl $Id: configure.in,v 1.10 2001-06-02 17:23:16 rjkaes Exp $
|
||||||
|
|
||||||
|
AC_INIT()
|
||||||
|
AM_INIT_AUTOMAKE(tinyproxy,1.4.0pre5)
|
||||||
|
AM_CONFIG_HEADER(config.h)
|
||||||
|
|
||||||
|
AC_CANONICAL_HOST
|
||||||
|
AC_CANONICAL_TARGET
|
||||||
|
|
||||||
|
dnl Checks for programs.
|
||||||
|
AC_PROG_AWK
|
||||||
|
AC_PROG_MAKE_SET
|
||||||
|
AC_PROG_CC
|
||||||
|
AC_PROG_INSTALL
|
||||||
|
AC_PROG_LN_S
|
||||||
|
AC_PROG_YACC
|
||||||
|
if test "$YACC" != "bison -y"; then
|
||||||
|
AC_MSG_WARN(You will need bison if you want to regenerate the parser.)
|
||||||
|
else
|
||||||
|
AC_MSG_CHECKING(bison version)
|
||||||
|
oldIFS=$IFS; IFS=.
|
||||||
|
set `bison -V | sed -e 's/^GNU Bison version //'`
|
||||||
|
IFS=$oldIFS
|
||||||
|
if test "$1" = "1" -a "$2" -lt "25"; then
|
||||||
|
AC_MSG_WARN(Bison 1.25 or newer needed to regenerate parsers (found $1.$2).)
|
||||||
|
fi
|
||||||
|
AC_MSG_RESULT($1.$2 (ok))
|
||||||
|
fi
|
||||||
|
|
||||||
|
AM_PROG_LEX
|
||||||
|
AM_C_PROTOTYPES
|
||||||
|
|
||||||
|
dnl Checks for header files.
|
||||||
|
AC_HEADER_STDC
|
||||||
|
AC_CHECK_HEADERS(\
|
||||||
|
sys/types.h \
|
||||||
|
sys/ioctl.h \
|
||||||
|
sys/resource.h \
|
||||||
|
sys/select.h \
|
||||||
|
sys/socket.h \
|
||||||
|
sys/stat.h \
|
||||||
|
sys/sysctl.h \
|
||||||
|
sys/time.h \
|
||||||
|
sys/uio.h \
|
||||||
|
sys/un.h \
|
||||||
|
sys/wait.h \
|
||||||
|
arpa/inet.h \
|
||||||
|
netinet/in.h \
|
||||||
|
alloca.h \
|
||||||
|
assert.h \
|
||||||
|
ctype.h \
|
||||||
|
errno.h \
|
||||||
|
fcntl.h \
|
||||||
|
grp.h \
|
||||||
|
io.h \
|
||||||
|
libintl.h \
|
||||||
|
malloc.h \
|
||||||
|
netdb.h \
|
||||||
|
pthread.h \
|
||||||
|
pwd.h \
|
||||||
|
regex.h \
|
||||||
|
signal.h \
|
||||||
|
stdarg.h \
|
||||||
|
stddef.h \
|
||||||
|
stdint.h \
|
||||||
|
stdio.h \
|
||||||
|
stdlib.h \
|
||||||
|
string.h \
|
||||||
|
strings.h \
|
||||||
|
sysexists.h \
|
||||||
|
syslog.h \
|
||||||
|
time.h \
|
||||||
|
unistd.h \
|
||||||
|
wchar.h \
|
||||||
|
wctype.h \
|
||||||
|
)
|
||||||
|
|
||||||
|
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||||
|
AC_C_CONST
|
||||||
|
AC_C_INLINE
|
||||||
|
AC_HEADER_TIME
|
||||||
|
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(size_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 libraries
|
||||||
|
AC_CHECK_LIB(pthread, pthread_create)
|
||||||
|
if test "$ac_cv_lib_pthread_pthread_create" = "yes"; then
|
||||||
|
CFLAGS="$CFLAGS -D_REENTRANT"
|
||||||
|
else
|
||||||
|
AC_CHECK_LIB(pthreads, pthread_create)
|
||||||
|
if test "$ac_cv_lib_pthreads_pthread_create" = "yes"; then
|
||||||
|
CFLAGS="$CFLAGS -D_REENTRANT"
|
||||||
|
else
|
||||||
|
AC_MSG_ERROR(You must have a POSIX compliant threading library installed)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_CHECK_LIB(socket, socket, [ ], [ AC_CHECK_LIB(socket, htonl) ])
|
||||||
|
|
||||||
|
dnl Some systems (OpenServer 5) dislike -lsocket -lnsl, so we try to
|
||||||
|
dnl avoid -lnsl checks, if we already have the functions which are
|
||||||
|
dnl usually in libnsl
|
||||||
|
|
||||||
|
unset ac_cv_func_yp_get_default_domain
|
||||||
|
AC_CHECK_FUNC(yp_get_default_domain, [ tinyproxy_no_nsl_checks=yes ], [ ])
|
||||||
|
unset ac_cv_func_yp_get_default_domain
|
||||||
|
|
||||||
|
if test "$tinyproxy_no_nsl_checks" != "yes"; then
|
||||||
|
AC_CHECK_LIB(nsl, gethostname, [ ], [ AC_CHECK_LIB(nsl, gethostbyaddr) ])
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_CHECK_LIB(resolv, inet_aton)
|
||||||
|
|
||||||
|
dnl Checks for library functions.
|
||||||
|
AC_FUNC_ALLOCA
|
||||||
|
dnl AC_FUNC_MEMCMP
|
||||||
|
AC_TYPE_SIGNAL
|
||||||
|
AC_FUNC_STRFTIME
|
||||||
|
AC_FUNC_VPRINTF
|
||||||
|
AC_CHECK_FUNCS(\
|
||||||
|
ftruncate \
|
||||||
|
select \
|
||||||
|
setrlimit \
|
||||||
|
socket \
|
||||||
|
strdup \
|
||||||
|
strerror \
|
||||||
|
strtol \
|
||||||
|
vsnprintf \
|
||||||
|
vsyslog \
|
||||||
|
)
|
||||||
|
AC_CHECK_FUNCS(strlcpy strlcat)
|
||||||
|
|
||||||
|
dnl chris - allow user to choose log file location, port and username
|
||||||
|
AC_ARG_WITH(log-file, [ --with-log-file=FILE Default logfile name],
|
||||||
|
AC_DEFINE_UNQUOTED(DEFAULT_LOG, "$withval"))
|
||||||
|
|
||||||
|
AC_ARG_WITH(port, [ --with-port=PORT Default server port],
|
||||||
|
AC_DEFINE_UNQUOTED(DEFAULT_PORT, $withval))
|
||||||
|
|
||||||
|
AC_ARG_WITH(user, [ --with-user=USER Default user],
|
||||||
|
AC_DEFINE_UNQUOTED(DEFAULT_USER, "$withval"))
|
||||||
|
|
||||||
|
AC_ARG_WITH(stathost, [ --with-stathost=HOST Default status host],
|
||||||
|
AC_DEFINE_UNQUOTED(DEFAULT_STATHOST, "$withval"))
|
||||||
|
|
||||||
|
dnl Check for the regex library
|
||||||
|
AC_ARG_WITH(regex, [ --with-regex Use the GNU regex libary],
|
||||||
|
tinyproxy_cv_regex=yes,
|
||||||
|
AC_CHECK_FUNCS(regcomp, tinyproxy_cv_regex=no, tinyproxy_cv_regex=yes))
|
||||||
|
|
||||||
|
if test "$tinyproxy_cv_regex" != "yes" ; then
|
||||||
|
AC_MSG_CHECKING(whether your system's regexp library is completely broken)
|
||||||
|
AC_CACHE_VAL(tinyproxy_cv_regex_broken,
|
||||||
|
AC_TRY_RUN([
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <regex.h>
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
regex_t blah;
|
||||||
|
return regcomp(&blah, "foo.*bar", REG_NOSUB) || regexec(&blah, "foobar", 0, NULL, 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 "$tinyproxy_cv_regex_broken" = "yes" ; then
|
||||||
|
echo "Using the included GNU regex instead." >&AC_FD_MSG
|
||||||
|
tinyproxy_cv_regex=yes
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$tinyproxy_cv_regex" = "yes" ; then
|
||||||
|
AC_DEFINE(USE_GNU_REGEX)
|
||||||
|
LIBOBJS="$LIBOBJS gnuregex.o"
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl Add compiler-specific optimization flags
|
||||||
|
AC_ARG_ENABLE(debug,
|
||||||
|
[ --enable-debug Disable aggressive optimizations [default=no]],
|
||||||
|
debug_enabled=yes)
|
||||||
|
|
||||||
|
CFLAGS="$CFLAGS -Wall"
|
||||||
|
if test "$enable_debug" = "yes" ; then
|
||||||
|
dnl Add the warnings if we have the GCC compiler
|
||||||
|
if test x$ac_cv_prog_gcc = xyes ; then
|
||||||
|
CFLAGS="$CFLAGS -Wshadow"
|
||||||
|
CFLAGS="$CFLAGS -Wcast-qual"
|
||||||
|
CFLAGS="$CFLAGS -Wcast-align"
|
||||||
|
CFLAGS="$CFLAGS -Wstrict-prototypes"
|
||||||
|
CFLAGS="$CFLAGS -Wmissing-prototypes"
|
||||||
|
CFLAGS="$CFLAGS -Wmissing-declarations"
|
||||||
|
CFLAGS="$CFLAGS -Wpointer-arith"
|
||||||
|
CFLAGS="$CFLAGS -Waggregate-return"
|
||||||
|
CFLAGS="$CFLAGS -Wnested-externs"
|
||||||
|
fi
|
||||||
|
CFLAGS="$CFLAGS -DYYDEBUG"
|
||||||
|
YFLAGS="-v -d"
|
||||||
|
else
|
||||||
|
dnl No debugging information, include the optimizations
|
||||||
|
YFLAGS="-d"
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl Check for SOCKS support
|
||||||
|
AC_ARG_ENABLE(socks,
|
||||||
|
[ --enable-socks Enable SOCKS support [default=no]],
|
||||||
|
socks_enabled=yes)
|
||||||
|
|
||||||
|
if test "$socks_enabled" = "yes"; then
|
||||||
|
AC_CHECK_HEADER(socks.h, socks_header=yes, socks_header=no)
|
||||||
|
AC_CHECK_LIB(socks, main, socks_library=yes, socks_library=no)
|
||||||
|
if test "$socks_header" = "yes" -a "$socks_library" = "yes"; then
|
||||||
|
CFLAGS="$CFLAGS -I/usr/include/sock.h -DSOCKS"
|
||||||
|
LIBS="$LIBS -lsocks"
|
||||||
|
else
|
||||||
|
AC_MSG_ERROR(could not find the SOCKS library or header)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl Check to see if the XTinyproxy header is to be included
|
||||||
|
AC_ARG_ENABLE(xtinyproxy,
|
||||||
|
[ --enable-xtinyproxy Include X-Tinyproxy header [default=yes]],
|
||||||
|
xtinyproxy_enabled=yes)
|
||||||
|
|
||||||
|
if test "$xtinyproxy_enabled" = "yes" ; then
|
||||||
|
AC_DEFINE(XTINYPROXY_ENABLE)
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl Include filtering for domain/URLs
|
||||||
|
AC_ARG_ENABLE(filter,
|
||||||
|
[ --enable-filter Enable filtering of domains/URLs [default=yes]],
|
||||||
|
filter_enabled=yes)
|
||||||
|
|
||||||
|
if test "$filter_enabled" = "yes" ; then
|
||||||
|
LIBOBJS="$LIBOBJS filter.o"
|
||||||
|
AC_DEFINE(FILTER_ENABLE)
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl Include support for upstream proxies? (TCP tunneling)
|
||||||
|
AC_ARG_ENABLE(tunnel,
|
||||||
|
[ --enable-tunnel Enable support for TCP tunneling [default=yes]],
|
||||||
|
tunnel_enabled=yes)
|
||||||
|
|
||||||
|
if test "$tunnel_enabled" = "yes" ; then
|
||||||
|
AC_DEFINE(TUNNEL_SUPPORT)
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl Substitute the variables into the various Makefiles
|
||||||
|
AC_SUBST(CFLAGS)
|
||||||
|
AC_SUBST(YFLAGS)
|
||||||
|
AC_SUBST(CPPFLAGS)
|
||||||
|
AC_SUBST(LIBS)
|
||||||
|
AC_SUBST(LIBOBJS)
|
||||||
|
|
||||||
|
AC_OUTPUT([
|
||||||
|
Makefile
|
||||||
|
src/Makefile
|
||||||
|
doc/Makefile
|
||||||
|
])
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
SUBDIRS = \
|
|
||||||
templates
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
templatesdir = $(pkgdatadir)
|
|
||||||
|
|
||||||
TEMPLATES = \
|
|
||||||
debug.html \
|
|
||||||
default.html \
|
|
||||||
stats.html
|
|
||||||
|
|
||||||
templates_DATA = \
|
|
||||||
$(TEMPLATES)
|
|
||||||
|
|
||||||
EXTRA_DIST = \
|
|
||||||
$(TEMPLATES)
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
||||||
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>{errno} {cause}</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h1>{cause}</h1>
|
|
||||||
|
|
||||||
<p>{detail}</p>
|
|
||||||
|
|
||||||
<p>Here are the error variables:</p>
|
|
||||||
|
|
||||||
<dl>
|
|
||||||
|
|
||||||
<dt>request</dt>
|
|
||||||
<dd>{request}</dd>
|
|
||||||
|
|
||||||
<dt>cause</dt>
|
|
||||||
<dd>{cause}</dd>
|
|
||||||
|
|
||||||
<dt>clientip</dt>
|
|
||||||
<dd>{clientip}</dd>
|
|
||||||
|
|
||||||
<dt>clienthost</dt>
|
|
||||||
<dd>{clienthost}</dd>
|
|
||||||
|
|
||||||
<dt>version</dt>
|
|
||||||
<dd>{version}</dd>
|
|
||||||
|
|
||||||
<dt>package</dt>
|
|
||||||
<dd>{package}</dd>
|
|
||||||
|
|
||||||
<dt>date</dt>
|
|
||||||
<dd>{date}</dd>
|
|
||||||
|
|
||||||
<dt>detail</dt>
|
|
||||||
<dd>{detail}</dd>
|
|
||||||
|
|
||||||
<dt>url</dt>
|
|
||||||
<dd>{url}</dd>
|
|
||||||
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
<p><em>Generated by <a href="{website}">{package}</a> version {version}.</em></p>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
||||||
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>{errno} {cause}</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h1>{cause}</h1>
|
|
||||||
|
|
||||||
<p>{detail}</p>
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
<p><em>Generated by <a href="{website}">{package}</a> version {version}.</em></p>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
||||||
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>{package} version {version} run-time statistics</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
|
|
||||||
<style type="text/css" media="screen">
|
|
||||||
<!--/*--><![CDATA[<!--*/
|
|
||||||
|
|
||||||
th, td
|
|
||||||
{
|
|
||||||
text-align: left;
|
|
||||||
padding: 0.5em;
|
|
||||||
border: 1px solid gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*]]>*/-->
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h1>{package} version {version} run-time statistics</h1>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Value</th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>Number of open connections</td>
|
|
||||||
<td>{opens}</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>Number of requests</td>
|
|
||||||
<td>{reqs}</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>Number of bad connections</td>
|
|
||||||
<td>{badconns}</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>Number of denied connections</td>
|
|
||||||
<td>{deniedconns}</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>Number of refused connections due to high load</td>
|
|
||||||
<td>{refusedconns}</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
<p><em>Generated by <a href="{website}">{package}</a> version {version}.</em></p>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
File renamed without changes.
@@ -0,0 +1,2 @@
|
|||||||
|
EXTRA_DIST = tinyproxy.8 tinyproxy.conf HTTP_ERROR_CODES RFC_INFO TODO report.sh
|
||||||
|
man_MANS = tinyproxy.8
|
||||||
File renamed without changes.
@@ -0,0 +1,24 @@
|
|||||||
|
The following are some features that I'd like to add to tinyproxy in the
|
||||||
|
future. Where possible, I've listed the person who suggested it. This
|
||||||
|
list is in no particular order. And hey, if you want to implement one of
|
||||||
|
these, or another idea you have, go right ahead. Just mail me the diff
|
||||||
|
against the current tree and I'll integrate it if possible.
|
||||||
|
|
||||||
|
- Include hooks so other types of proxies can be modularly added to
|
||||||
|
the source tree. Then people can simply choose which types of
|
||||||
|
proxies (ftp, www, etc) they'd like enabled in tinyproxy.h
|
||||||
|
Suggested: Tarun Tuli.
|
||||||
|
- Find a more elegant solution to embedding HTML documents in the
|
||||||
|
source than the current method. (see httperr() and showstats() for
|
||||||
|
examples of how it's done right now).
|
||||||
|
- Include a function to rewrite the incoming requests. Should not be
|
||||||
|
much of a problem. Just need to modify the process_method() code
|
||||||
|
to look up the URL and rewrite it. If we want to go really fancy
|
||||||
|
with RegEx mapping this could get ugly. :)
|
||||||
|
- Ed Avis suggests having tinyproxy have the ability to send the data
|
||||||
|
from the connections through an external filtering program. I kind of
|
||||||
|
like this idea, but I don't really have a good way of doing it yet.
|
||||||
|
- Handle Secure Socket Layer (SSL) connections (usually port 443).
|
||||||
|
- Allow selective logging. For example a person may only want to log
|
||||||
|
error messages.
|
||||||
|
- Include the ability to rewrite both incoming and outgoing headers.
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
(echo "date: "
|
||||||
|
date
|
||||||
|
echo "uname: "
|
||||||
|
uname -a
|
||||||
|
echo "ps: "
|
||||||
|
ps -auxw | grep [t]inyproxy -
|
||||||
|
echo "ver: "
|
||||||
|
if [ -x /usr/local/bin/tinyproxy ]; then
|
||||||
|
/usr/local/bin/tinyproxy -v
|
||||||
|
else
|
||||||
|
echo no ver available.
|
||||||
|
fi;) 2>&1 | mail -s 'tinyproxy install report' rjkaes@flarenet.com
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
.\" -*- nroff -*-
|
||||||
|
.\"
|
||||||
|
.\" tinyproxy.1
|
||||||
|
.\"
|
||||||
|
.\" Copyright (c) 1998-2000 Steven Young and Robert James Kaes.
|
||||||
|
.\" Copyright (c) 2001 Robert James Kaes
|
||||||
|
.\"
|
||||||
|
.\" This program is distributed under the terms of the GNU General Public
|
||||||
|
.\" License. See COPYING for additional information.
|
||||||
|
.\"
|
||||||
|
.TH tinyproxy 1 .\" "tinyproxy Manual" "August 3, 2000"
|
||||||
|
.SH NAME
|
||||||
|
tinyproxy - A small HTTP proxy server
|
||||||
|
.SH SYNTAX
|
||||||
|
\fBtinyproxy\fR [ \fBoptions\fR ]
|
||||||
|
.SH VERSION
|
||||||
|
This man page documents tinyproxy
|
||||||
|
.SH DESCRIPTION
|
||||||
|
\fBtinyproxy\fR is an HTTP proxy server designed to consume a minimum of
|
||||||
|
system resources. It listens on a given TCP port and handles HTTP proxy
|
||||||
|
requests.
|
||||||
|
.SH OPTIONS
|
||||||
|
.IP "-c config_file"
|
||||||
|
Use an alternate configuration file.
|
||||||
|
.IP -d
|
||||||
|
Don't daemonize; stay in the foreground. Useful for debugging purposes.
|
||||||
|
.IP -h
|
||||||
|
Display a short help screen of command line arguments and exit.
|
||||||
|
.IP -v
|
||||||
|
Display version information and exit.
|
||||||
|
.SH SIGNALS
|
||||||
|
In addition to these command line options, there are also several signals
|
||||||
|
that can be sent to tinyproxy while it is running to generate debugging
|
||||||
|
information and to force certain events.
|
||||||
|
.TP 5
|
||||||
|
.B SIGHUP
|
||||||
|
Force \fBtinyproxy\fR to do a garbage collection on the current connections
|
||||||
|
linked list. This is usually done automatically after a certain number of
|
||||||
|
connections have been handled.
|
||||||
|
.SH FILES
|
||||||
|
.nf
|
||||||
|
/etc/tinyproxy/tinyproxy.conf
|
||||||
|
/var/run/tinyproxy.pid
|
||||||
|
/var/log/tinyproxy.log
|
||||||
|
.fi
|
||||||
|
.SH AUTHORS
|
||||||
|
.nf
|
||||||
|
Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
Steven Young (sdyoung@users.sourceforge.net)
|
||||||
|
.fi
|
||||||
|
.SH COPYRIGHT
|
||||||
|
\fBtinyproxy\fR is distributed under the GNU Public License (GPL). For more
|
||||||
|
information on the GPL, please see the file COPYING which should have been
|
||||||
|
included in the archive with \fBtinyproxy\fR. Failing that,
|
||||||
|
http://www.fsf.org/ will doubtless have a copy up for you to peruse. Please
|
||||||
|
don't use this software if you don't agree to the terms specified therein.
|
||||||
|
.SH AVAILABILITY
|
||||||
|
The latest version of \fBtinyproxy\fR can be acquired from: http://tinyproxy.sourceforge.net/
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
##
|
||||||
|
## tinyproxy.conf -- tinyproxy daemon configuration file
|
||||||
|
##
|
||||||
|
|
||||||
|
#
|
||||||
|
# Name of the user the tinyproxy daemon should switch to after the port
|
||||||
|
# has been bound.
|
||||||
|
#
|
||||||
|
User nobody
|
||||||
|
Group nogroup
|
||||||
|
|
||||||
|
#
|
||||||
|
# Port to listen on.
|
||||||
|
#
|
||||||
|
Port 8888
|
||||||
|
|
||||||
|
#
|
||||||
|
# If you have multiple interfaces this allows you to bind to only one. If
|
||||||
|
# this is commented out, tinyproxy will bind to all interfaces present.
|
||||||
|
#
|
||||||
|
#Listen 192.168.0.1
|
||||||
|
|
||||||
|
#
|
||||||
|
# Timeout: The number of seconds of inactivity a connection is allowed to
|
||||||
|
# have before it closed by tinyproxy.
|
||||||
|
#
|
||||||
|
Timeout 600
|
||||||
|
|
||||||
|
#
|
||||||
|
# Where to log the information. Either LogFile or Syslog should be set,
|
||||||
|
# but not both.
|
||||||
|
#
|
||||||
|
Logfile "/var/log/tinyproxy.log"
|
||||||
|
# Syslog On
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set the logging level. Allowed settings are:
|
||||||
|
# Critical (least verbose)
|
||||||
|
# Error
|
||||||
|
# Warning
|
||||||
|
# Notice
|
||||||
|
# Info (most verbose)
|
||||||
|
# The LogLevel logs from the set level and above. For example, if the LogLevel
|
||||||
|
# was set to Warning, than all log messages from Warning to Critical would be
|
||||||
|
# output, but Notice and below would be suppressed.
|
||||||
|
#
|
||||||
|
LogLevel Info
|
||||||
|
|
||||||
|
#
|
||||||
|
# PidFile: Write the PID of the main tinyproxy thread to this file so it
|
||||||
|
# can be used for signalling purposes.
|
||||||
|
#
|
||||||
|
PidFile "/var/run/tinyproxy.pid"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Include the X-Tinyproxy header, which has the client's IP address when
|
||||||
|
# connecting to the sites listed.
|
||||||
|
#
|
||||||
|
#XTinyproxy mydomain.com
|
||||||
|
|
||||||
|
#
|
||||||
|
# Turns tinyproxy into a TCP tunnel which connects the local computer on
|
||||||
|
# 'Port' to the remote computer's port. The form is remote_machine port
|
||||||
|
#
|
||||||
|
#Tunnel some.remote.computer:port
|
||||||
|
|
||||||
|
#
|
||||||
|
# This is the absolute highest number of threads which will be created. In
|
||||||
|
# other words, only MaxClients number of clients can be connected at the
|
||||||
|
# same time.
|
||||||
|
#
|
||||||
|
MaxClients 100
|
||||||
|
|
||||||
|
#
|
||||||
|
# These settings set the upper and lower limit for the number of
|
||||||
|
# spare servers which should be available. If the number of spare servers
|
||||||
|
# falls below MinSpareServers then new ones will be created. If the number
|
||||||
|
# of servers exceeds MaxSpareServers then the extras will be killed off.
|
||||||
|
#
|
||||||
|
MinSpareServers 5
|
||||||
|
MaxSpareServers 20
|
||||||
|
|
||||||
|
#
|
||||||
|
# Number of servers to start initially.
|
||||||
|
#
|
||||||
|
StartServers 10
|
||||||
|
|
||||||
|
#
|
||||||
|
# MaxRequestsPerChild is the number of connections a thread will handle
|
||||||
|
# before it is killed. In practice this should be set to 0, which disables
|
||||||
|
# thread reaping. If you do notice problems with memory leakage, then set
|
||||||
|
# this to something like 10000
|
||||||
|
#
|
||||||
|
MaxRequestsPerChild 0
|
||||||
|
|
||||||
|
#
|
||||||
|
# The following is the authorization controls. If there are any access
|
||||||
|
# control keywords then the default action is to DENY. Otherwise, the
|
||||||
|
# default action is ALLOW.
|
||||||
|
#
|
||||||
|
# Also the order of the controls are important. The incoming connections
|
||||||
|
# are tested against the controls based on order.
|
||||||
|
#
|
||||||
|
Allow 127.0.0.1
|
||||||
|
Allow 192.168.1.0/25
|
||||||
|
|
||||||
|
#
|
||||||
|
# The location of the filter file.
|
||||||
|
#
|
||||||
|
#Filter "/etc/tinyproxy/filter"
|
||||||
|
|
||||||
|
#
|
||||||
|
# If an Anonymous keyword is present, then anonymous proxying is enabled.
|
||||||
|
# The headers listed are allowed through, while all others are denied. If
|
||||||
|
# no Anonymous keyword is present, then all header are allowed through.
|
||||||
|
#
|
||||||
|
#Anonymous Host
|
||||||
|
#Anonymous Authorization
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Makefile
|
|
||||||
Makefile.in
|
|
||||||
report.sh
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
SUBDIRS = \
|
|
||||||
man5 \
|
|
||||||
man8
|
|
||||||
|
|
||||||
EXTRA_DIST = \
|
|
||||||
http-error-codes.txt \
|
|
||||||
http-rfcs.txt \
|
|
||||||
filter-howto.txt
|
|
||||||
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
Using tinyproxy with Your Home/Small Business Network
|
|
||||||
|
|
||||||
Written: Patrick L. McGillan
|
|
||||||
Edited: Robert James Kaes (2002-06-04)
|
|
||||||
-----------------------------------------------------
|
|
||||||
|
|
||||||
Being as this will be the most common usage and there were no clear
|
|
||||||
basic instructions for this scenario, I thought I would write up what
|
|
||||||
I did for my home system.
|
|
||||||
|
|
||||||
First the layout of the network. A cable modem is connected through a
|
|
||||||
Linksys Router to a small hub. The computers hanging off the hub and
|
|
||||||
have a clear shot to the Internet.
|
|
||||||
|
|
||||||
So, the connection from the Internet to the hub looks like this:
|
|
||||||
|
|
||||||
Internet->Cable TV Line->Cable Modem->Linksys Router->Hub/Switch
|
|
||||||
|
|
||||||
Restricting Internet web access on some of those computers (connected
|
|
||||||
to the hub) is what using tinyproxy is all about. Using the web
|
|
||||||
interface to the Linksys router, turn off all Internet access to those
|
|
||||||
computers that shouldn't have direct access to the Internet. This is
|
|
||||||
done by clicking on the advanced tab and entering the IP number in the
|
|
||||||
filter range. Now those computers have to go through a proxy, for
|
|
||||||
their access, as they have no direct access.
|
|
||||||
|
|
||||||
On one of the Linux computers which still has Internet access (I use
|
|
||||||
an old 486) load up tinyproxy. Now have the users configure their
|
|
||||||
Internet Explorer/Netscape Navigator programs to use the proxy on the
|
|
||||||
tinyproxy computer box, along with the port number declared in the
|
|
||||||
tinyproxy configuration file. By default, there is no blocking of web
|
|
||||||
sites with this program, so I created a file, called "filter", to
|
|
||||||
start blocking some sites.
|
|
||||||
|
|
||||||
Example "filter" file entries:
|
|
||||||
|
|
||||||
bannerads.zwire.com
|
|
||||||
ad.doubleclick.net
|
|
||||||
ads.fortunecity.com
|
|
||||||
|
|
||||||
This filter file usually goes into the same folder, as your
|
|
||||||
configuration file. Be sure and uncomment the 'Filter' line in your
|
|
||||||
configuration file and make sure it points at your newly created
|
|
||||||
filter file.
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Copyright (c) 2002 Patrick L. McGillan <pmcgillan@dwx.com>
|
|
||||||
|
|
||||||
This document is released under the same copyright license as
|
|
||||||
tinyproxy. You should have found a COPYING file in the top level
|
|
||||||
directory of this distribution which contains the current license.
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
*.5
|
|
||||||
*.xml
|
|
||||||
*.txt
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
MAN5_FILES = \
|
|
||||||
tinyproxy.conf.txt
|
|
||||||
|
|
||||||
A2X_ARGS = \
|
|
||||||
-d manpage \
|
|
||||||
-f manpage
|
|
||||||
|
|
||||||
man_MANS = \
|
|
||||||
$(MAN5_FILES:.txt=.5)
|
|
||||||
|
|
||||||
.txt.5:
|
|
||||||
if HAVE_A2X
|
|
||||||
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
|
|
||||||
else
|
|
||||||
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
|
|
||||||
endif
|
|
||||||
|
|
||||||
CLEANFILES = \
|
|
||||||
$(MAN5_FILES:.txt=.5) \
|
|
||||||
$(MAN5_FILES:.txt=.xml)
|
|
||||||
@@ -1,370 +0,0 @@
|
|||||||
TINYPROXY.CONF(5)
|
|
||||||
=================
|
|
||||||
:man source: Version @VERSION@
|
|
||||||
:man manual: Tinyproxy manual
|
|
||||||
|
|
||||||
NAME
|
|
||||||
----
|
|
||||||
|
|
||||||
tinyproxy.conf - Tinyproxy HTTP proxy daemon configuration file
|
|
||||||
|
|
||||||
|
|
||||||
SYNOPSIS
|
|
||||||
--------
|
|
||||||
|
|
||||||
*tinyproxy.conf*
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
-----------
|
|
||||||
|
|
||||||
`tinyproxy(8)` reads its configuration file, typically stored in
|
|
||||||
`/etc/tinyproxy/tinyproxy.conf` (or passed to Tinyproxy with -c on the
|
|
||||||
command line). This manpage describes the syntax and contents of the
|
|
||||||
configuration file.
|
|
||||||
|
|
||||||
The Tinyproxy configuration file contains key-value pairs, one per
|
|
||||||
line. Lines starting with `#` and empty lines are comments and are
|
|
||||||
ignored. Keywords are case-insensitive, whereas values are
|
|
||||||
case-sensitive. Values may be enclosed in double-quotes (") if they
|
|
||||||
contain spaces.
|
|
||||||
|
|
||||||
The possible keywords and their descriptions are as follows:
|
|
||||||
|
|
||||||
*User*::
|
|
||||||
|
|
||||||
The user which the Tinyproxy process should run as, after the
|
|
||||||
initial port-binding has been done as the `root` user. Either the
|
|
||||||
user name or the UID may be specified.
|
|
||||||
|
|
||||||
*Group*::
|
|
||||||
|
|
||||||
The group which the Tinyproxy process should run as, after the
|
|
||||||
initial port-binding has been done as the `root` user. Either the
|
|
||||||
group name or the GID may be specified.
|
|
||||||
|
|
||||||
*Port*::
|
|
||||||
|
|
||||||
The port which the Tinyproxy service will listen on. If the port is
|
|
||||||
less than 1024, you will need to start the Tinyproxy process as the
|
|
||||||
`root` user.
|
|
||||||
|
|
||||||
*Listen*::
|
|
||||||
|
|
||||||
By default, Tinyproxy listens for connections on all available
|
|
||||||
interfaces (i.e. it listens on the wildcard address `0.0.0.0`).
|
|
||||||
With this configuration parameter, Tinyproxy can be told to listen
|
|
||||||
only on one specific address.
|
|
||||||
|
|
||||||
*Bind*::
|
|
||||||
|
|
||||||
This allows you to specify which address Tinyproxy will bind
|
|
||||||
to for outgoing connections to web servers or upstream proxies.
|
|
||||||
|
|
||||||
*BindSame*::
|
|
||||||
|
|
||||||
If this boolean parameter is set to `yes`, then Tinyproxy will
|
|
||||||
bind the outgoing connection to the IP address of the incoming
|
|
||||||
connection that triggered the outgoing request.
|
|
||||||
|
|
||||||
*Timeout*::
|
|
||||||
|
|
||||||
The maximum number of seconds of inactivity a connection is
|
|
||||||
allowed to have before it is closed by Tinyproxy.
|
|
||||||
|
|
||||||
*ErrorFile*::
|
|
||||||
|
|
||||||
This parameter controls which HTML file Tinyproxy returns when a
|
|
||||||
given HTTP error occurs. It takes two arguments, the error number
|
|
||||||
and the location of the HTML error file.
|
|
||||||
|
|
||||||
*DefaultErrorFile*::
|
|
||||||
|
|
||||||
This parameter controls the HTML template file returned when an
|
|
||||||
error occurs for which no specific error file has been set.
|
|
||||||
|
|
||||||
*StatHost*::
|
|
||||||
|
|
||||||
This configures the host name or IP address that is treated
|
|
||||||
as the `stat host`: Whenever a request for this host is received,
|
|
||||||
Tinyproxy will return an internal statistics page instead of
|
|
||||||
forwarding the request to that host. The template for this
|
|
||||||
page can be configured with the `StatFile` configuration option.
|
|
||||||
The default value of `StatHost` is `@TINYPROXY_STATHOST@`.
|
|
||||||
|
|
||||||
*StatFile*::
|
|
||||||
|
|
||||||
This configures the HTML file that Tinyproxy sends when
|
|
||||||
a request for the stathost is received. If this parameter is
|
|
||||||
not set, Tinyproxy returns a hard-coded basic statistics page.
|
|
||||||
See the STATHOST section in the `tinyproxy(8)` manual page
|
|
||||||
for details.
|
|
||||||
+
|
|
||||||
Note that the StatFile and the error files configured with ErrorFile
|
|
||||||
and DefaultErrorFile are template files that can contain a few
|
|
||||||
template variables that Tinyproxy expands prior to delivery.
|
|
||||||
Examples are "\{cause}" for an abbreviated error description and
|
|
||||||
"\{detail}" for a detailed error message. The `tinyproxy(8)`
|
|
||||||
manual page contains a description of all template variables.
|
|
||||||
|
|
||||||
*LogFile*::
|
|
||||||
|
|
||||||
This controls the location of the file to which Tinyproxy
|
|
||||||
writes its debug output. Alternatively, Tinyproxy can log
|
|
||||||
to syslog -- see the Syslog option.
|
|
||||||
|
|
||||||
*Syslog*::
|
|
||||||
|
|
||||||
When set to `On`, this option tells Tinyproxy to write its
|
|
||||||
debug messages to syslog instead of to a log file configured
|
|
||||||
with `LogFile`. These two options are mutually exclusive.
|
|
||||||
|
|
||||||
*LogLevel*::
|
|
||||||
|
|
||||||
Sets the log level. Messages from the set level and above are
|
|
||||||
logged. For example, if the LogLevel was set to Warning, then all
|
|
||||||
log messages from Warning to Critical would be output, but Notice
|
|
||||||
and below would be suppressed. Allowed values are:
|
|
||||||
|
|
||||||
* Critical (least verbose)
|
|
||||||
* Error
|
|
||||||
* Warning
|
|
||||||
* Notice
|
|
||||||
* Connect (log connections without Info's noise)
|
|
||||||
* Info (most verbose)
|
|
||||||
|
|
||||||
*PidFile*::
|
|
||||||
|
|
||||||
This option controls the location of the file where the main
|
|
||||||
Tinyproxy process stores its process ID for signaling purposes.
|
|
||||||
|
|
||||||
*XTinyproxy*::
|
|
||||||
|
|
||||||
Setting this option to `Yes` tells Tinyproxy to add a header
|
|
||||||
`X-Tinyproxy` containing the client's IP address to the request.
|
|
||||||
|
|
||||||
*Upstream*::
|
|
||||||
*No Upstream*::
|
|
||||||
|
|
||||||
This option allows you to set up a set of rules for deciding
|
|
||||||
whether an upstream proxy server is to be used, based on the
|
|
||||||
host or domain of the site being accessed. The rules are stored
|
|
||||||
in the order encountered in the configuration file and the
|
|
||||||
LAST matching rule wins. There are three possible forms for
|
|
||||||
specifying upstream rules:
|
|
||||||
|
|
||||||
* 'upstream host:port' turns proxy upstream support on generally.
|
|
||||||
|
|
||||||
* 'upstream host:port "site_spec"' turns on the upstream proxy for
|
|
||||||
the sites matching `site_spec`.
|
|
||||||
|
|
||||||
* 'no upstream "site_spec"' turns off upstream support for sites
|
|
||||||
matching `site_spec`.
|
|
||||||
|
|
||||||
The site can be specified in various forms as a hostname, domain
|
|
||||||
name or as an IP range:
|
|
||||||
|
|
||||||
* 'name' matches host exactly
|
|
||||||
* '.name' matches any host in domain "name"
|
|
||||||
* '.' matches any host with no domain (in 'empty' domain)
|
|
||||||
* 'IP/bits' matches network/mask
|
|
||||||
* 'IP/mask' matches network/mask
|
|
||||||
|
|
||||||
*MaxClients*::
|
|
||||||
|
|
||||||
Tinyproxy creates one child process for each connected client.
|
|
||||||
This options specifies the absolute highest number processes that
|
|
||||||
will be created. With other words, only MaxClients clients can be
|
|
||||||
connected to Tinyproxy simultaneously.
|
|
||||||
|
|
||||||
*MinSpareServers*::
|
|
||||||
*MaxSpareServers*::
|
|
||||||
|
|
||||||
Tinyproxy always keeps a certain number of idle child processes
|
|
||||||
so that it can handle new incoming client requests quickly.
|
|
||||||
`MinSpareServer` and `MaxSpareServers` control the lower and upper
|
|
||||||
limits for the number of spare processes. I.e. when the number of
|
|
||||||
spare servers drops below `MinSpareServers` then Tinyproxy will
|
|
||||||
start forking new spare processes in the background and when the
|
|
||||||
number of spare processes exceeds `MaxSpareServers` then Tinyproxy
|
|
||||||
will kill off extra processes.
|
|
||||||
|
|
||||||
*StartServers*::
|
|
||||||
|
|
||||||
The number of servers to start initially. This should usually be
|
|
||||||
set to a value between MinSpareServers and MaxSpareServers.
|
|
||||||
|
|
||||||
*MaxRequestsPerChild*::
|
|
||||||
|
|
||||||
This limits the number of connections that a child process
|
|
||||||
will handle before it is killed. The default value is `0`
|
|
||||||
which disables this feature. This option is meant as an
|
|
||||||
emergency measure in the case of problems with memory leakage.
|
|
||||||
In that case, setting `MaxRequestsPerChild` to a value of e.g.
|
|
||||||
1000, or 10000 can be useful.
|
|
||||||
|
|
||||||
*Allow*::
|
|
||||||
*Deny*::
|
|
||||||
|
|
||||||
The `Allow` and `Deny` options provide a means to customize
|
|
||||||
which clients are allowed to access Tinyproxy. `Allow` and `Deny`
|
|
||||||
lines can be specified multiple times to build the access control
|
|
||||||
list for Tinyproxy. The order in the config file is important.
|
|
||||||
If there are no `Allow` or `Deny` lines, then all clients are
|
|
||||||
allowed. Otherwise, the default action is to deny access.
|
|
||||||
The argument to `Allow` or `Deny` can be a single IP address
|
|
||||||
of a client host, like `127.0.0.1`, an IP address range, like
|
|
||||||
`192.168.0.1/24` or a string that will be matched against the
|
|
||||||
end of the client host name, i.e, this can be a full host name
|
|
||||||
like `host.example.com` or a domain name like `.example.com` or
|
|
||||||
even a top level domain name like `.com`.
|
|
||||||
|
|
||||||
*AddHeader*::
|
|
||||||
|
|
||||||
Configure one or more HTTP request headers to be added to outgoing
|
|
||||||
HTTP requests that Tinyproxy makes. Note that this option will not
|
|
||||||
work for HTTPS traffic, as Tinyproxy has no control over what
|
|
||||||
headers are exchanged.
|
|
||||||
+
|
|
||||||
----
|
|
||||||
AddHeader "X-My-Header" "Powered by Tinyproxy"
|
|
||||||
----
|
|
||||||
|
|
||||||
*ViaProxyName*::
|
|
||||||
|
|
||||||
RFC 2616 requires proxies to add a `Via` header to the HTTP
|
|
||||||
requests, but using the real host name can be a security
|
|
||||||
concern. If the `ViaProxyname` option is present, then its
|
|
||||||
string value will be used as the host name in the Via header.
|
|
||||||
Otherwise, the server's host name will be used.
|
|
||||||
|
|
||||||
*DisableViaHeader*::
|
|
||||||
|
|
||||||
When this is set to yes, Tinyproxy does NOT add the `Via` header
|
|
||||||
to the requests. This virtually puts Tinyproxy into stealth mode.
|
|
||||||
Note that RFC 2616 requires proxies to set the `Via` header, so by
|
|
||||||
enabling this option, you break compliance.
|
|
||||||
Don't disable the `Via` header unless you know what you are doing...
|
|
||||||
|
|
||||||
*Filter*::
|
|
||||||
|
|
||||||
Tinyproxy supports filtering of web sites based on URLs or
|
|
||||||
domains. This option specifies the location of the file
|
|
||||||
containing the filter rules, one rule per line.
|
|
||||||
|
|
||||||
*FilterURLs*::
|
|
||||||
|
|
||||||
If this boolean option is set to `Yes` or `On`, filtering is
|
|
||||||
performed for URLs rather than for domains. The default is to
|
|
||||||
filter based on domains.
|
|
||||||
|
|
||||||
*FilterExtended*::
|
|
||||||
|
|
||||||
If this boolean option is set to `Yes`, then extended POSIX
|
|
||||||
regular expressions are used for matching the filter rules.
|
|
||||||
The default is to use basic POSIX regular expressions.
|
|
||||||
|
|
||||||
*FilterCaseSensitive*::
|
|
||||||
|
|
||||||
If this boolean option is set to `Yes`, then the filter rules
|
|
||||||
are matched in a case sensitive manner. The default is to
|
|
||||||
match case-insensitively.
|
|
||||||
|
|
||||||
*FilterDefaultDeny*::
|
|
||||||
|
|
||||||
The default filtering policy is to allow everything that is
|
|
||||||
not matched by a filtering rule. Setting `FilterDefaultDeny`
|
|
||||||
to `Yes` changes the policy do deny everything but the domains
|
|
||||||
or URLs matched by the filtering rules.
|
|
||||||
|
|
||||||
*Anonymous*::
|
|
||||||
|
|
||||||
If an `Anonymous` keyword is present, then anonymous proxying
|
|
||||||
is enabled. The headers listed with `Anonymous` are allowed
|
|
||||||
through, while all others are denied. If no Anonymous keyword
|
|
||||||
is present, then all headers are allowed through. You must
|
|
||||||
include quotes around the headers.
|
|
||||||
+
|
|
||||||
Most sites require cookies to be enabled for them to work correctly, so
|
|
||||||
you will need to allow cookies through if you access those sites.
|
|
||||||
+
|
|
||||||
Example:
|
|
||||||
+
|
|
||||||
----
|
|
||||||
Anonymous "Host"
|
|
||||||
Anonymous "Authorization"
|
|
||||||
Anonymous "Cookie"
|
|
||||||
----
|
|
||||||
|
|
||||||
*ConnectPort*::
|
|
||||||
|
|
||||||
This option can be used to specify the ports allowed for the
|
|
||||||
CONNECT method. If no `ConnectPort` line is found, then all
|
|
||||||
ports are allowed. To disable CONNECT altogether, include a
|
|
||||||
single ConnectPort line with a value of `0`.
|
|
||||||
|
|
||||||
*ReversePath*::
|
|
||||||
|
|
||||||
Configure one or more ReversePath directives to enable reverse proxy
|
|
||||||
support. With reverse proxying it's possible to make a number of
|
|
||||||
sites appear as if they were part of a single site.
|
|
||||||
+
|
|
||||||
If you uncomment the following two directives and run Tinyproxy
|
|
||||||
on your own computer at port 8888, you can access example.com,
|
|
||||||
using http://localhost:8888/example/.
|
|
||||||
+
|
|
||||||
----
|
|
||||||
ReversePath "/example/" "http://www.example.com/"
|
|
||||||
----
|
|
||||||
|
|
||||||
*ReverseOnly*::
|
|
||||||
|
|
||||||
When using Tinyproxy as a reverse proxy, it is STRONGLY
|
|
||||||
recommended that the normal proxy is turned off by setting
|
|
||||||
this boolean option to `Yes`.
|
|
||||||
|
|
||||||
*ReverseMagic*::
|
|
||||||
|
|
||||||
Setting this option to `Yes`, makes Tinyproxy use a cookie to
|
|
||||||
track reverse proxy mappings. If you need to reverse proxy
|
|
||||||
sites which have absolute links you must use this option.
|
|
||||||
|
|
||||||
*ReverseBaseURL*::
|
|
||||||
|
|
||||||
The URL that is used to access this reverse proxy. The URL is
|
|
||||||
used to rewrite HTTP redirects so that they won't escape the
|
|
||||||
proxy. If you have a chain of reverse proxies, you'll need to
|
|
||||||
put the outermost URL here (the address which the end user
|
|
||||||
types into his/her browser). If this option is not set then
|
|
||||||
no rewriting of redirects occurs.
|
|
||||||
|
|
||||||
|
|
||||||
BUGS
|
|
||||||
----
|
|
||||||
|
|
||||||
To report bugs in Tinyproxy, please visit
|
|
||||||
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
|
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
|
||||||
--------
|
|
||||||
tinyproxy(8)
|
|
||||||
|
|
||||||
|
|
||||||
AUTHOR
|
|
||||||
------
|
|
||||||
|
|
||||||
Written by the Tinyproxy project team.
|
|
||||||
|
|
||||||
|
|
||||||
COPYRIGHT
|
|
||||||
---------
|
|
||||||
|
|
||||||
Copyright (c) 1998-2000 Steven Young;
|
|
||||||
Copyright (c) 2000-2001 Robert James Kaes;
|
|
||||||
Copyright (c) 2009-2010 Mukund Sivaraman;
|
|
||||||
Copyright (c) 2009-2010 Michael Adam.
|
|
||||||
|
|
||||||
This program is distributed under the terms of the GNU General Public
|
|
||||||
License version 2 or above. See the COPYING file for additional
|
|
||||||
information.
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
*.8
|
|
||||||
*.xml
|
|
||||||
*.txt
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
MAN8_FILES = \
|
|
||||||
tinyproxy.txt
|
|
||||||
|
|
||||||
A2X_ARGS = \
|
|
||||||
-d manpage \
|
|
||||||
-f manpage
|
|
||||||
|
|
||||||
man_MANS = \
|
|
||||||
$(MAN8_FILES:.txt=.8)
|
|
||||||
|
|
||||||
.txt.8:
|
|
||||||
if HAVE_A2X
|
|
||||||
$(AM_V_GEN) $(A2X) $(A2X_ARGS) $<
|
|
||||||
else
|
|
||||||
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
|
|
||||||
endif
|
|
||||||
|
|
||||||
CLEANFILES = \
|
|
||||||
$(MAN8_FILES:.txt=.8) \
|
|
||||||
$(MAN8_FILES:.txt=.xml)
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
TINYPROXY(8)
|
|
||||||
============
|
|
||||||
:man source: Version @VERSION@
|
|
||||||
:man manual: Tinyproxy manual
|
|
||||||
|
|
||||||
NAME
|
|
||||||
----
|
|
||||||
|
|
||||||
tinyproxy - A light-weight HTTP proxy daemon
|
|
||||||
|
|
||||||
|
|
||||||
SYNOPSIS
|
|
||||||
--------
|
|
||||||
|
|
||||||
*tinyproxy* [-vldch]
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
-----------
|
|
||||||
|
|
||||||
*tinyproxy* is a light-weight HTTP proxy daemon designed to consume a
|
|
||||||
minimum amount of system resources. It listens on a given TCP port and
|
|
||||||
handles HTTP proxy requests. Designed from the ground up to be fast and
|
|
||||||
yet small, it is an ideal solution for use cases such as embedded
|
|
||||||
deployments where a full featured HTTP proxy is required, but the system
|
|
||||||
resources for a larger proxy are unavailable.
|
|
||||||
|
|
||||||
|
|
||||||
OPTIONS
|
|
||||||
-------
|
|
||||||
|
|
||||||
*tinyproxy* accepts the following options:
|
|
||||||
|
|
||||||
*-c <config-file>*::
|
|
||||||
Use an alternate configuration file.
|
|
||||||
|
|
||||||
*-d*::
|
|
||||||
Don't daemonize and stay in the foreground. Useful for debugging purposes.
|
|
||||||
|
|
||||||
*-h*::
|
|
||||||
Display a short help screen of command line arguments and exit.
|
|
||||||
|
|
||||||
*-l*::
|
|
||||||
Display the licensing agreement.
|
|
||||||
|
|
||||||
*-v*::
|
|
||||||
Display version information and exit.
|
|
||||||
|
|
||||||
|
|
||||||
SIGNALS
|
|
||||||
-------
|
|
||||||
|
|
||||||
In addition to command-line options, there are also several signals that
|
|
||||||
can be sent to *tinyproxy* while it is running to generate debugging
|
|
||||||
information and to force certain events.
|
|
||||||
|
|
||||||
*SIGHUP*::
|
|
||||||
Force Tinyproxy to do a garbage collection on the current
|
|
||||||
connections linked list. This is usually done automatically after a
|
|
||||||
certain number of connections have been handled.
|
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE FILES
|
|
||||||
--------------
|
|
||||||
|
|
||||||
There are two occasions when Tinyproxy delivers HTML pages to
|
|
||||||
the client on it's own right:
|
|
||||||
|
|
||||||
. When an error occurred, a corresponding error page is returned.
|
|
||||||
. When a request for the stathost is made, a page summarizing the
|
|
||||||
connection statistics is returned. (See STATHOST below.)
|
|
||||||
|
|
||||||
The layout of both error pages and the statistics page can be
|
|
||||||
controlled via configurable HTML template files that are plain
|
|
||||||
HTML files that additionally understand a few template
|
|
||||||
variables.
|
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE VARIABLES
|
|
||||||
------------------
|
|
||||||
|
|
||||||
There are several standard HTML variables that are available in every
|
|
||||||
template file:
|
|
||||||
|
|
||||||
*request*::
|
|
||||||
The full HTTP request line.
|
|
||||||
|
|
||||||
*cause*::
|
|
||||||
The abbreviated cause of the error condition.
|
|
||||||
|
|
||||||
*clientip*::
|
|
||||||
The IP address of the client making the request.
|
|
||||||
|
|
||||||
*clienthost*::
|
|
||||||
The hostname of the client making the request.
|
|
||||||
|
|
||||||
*version*::
|
|
||||||
The version of Tinyproxy.
|
|
||||||
|
|
||||||
*package*::
|
|
||||||
The package name. Presently, resolves to 'tinyproxy'.
|
|
||||||
|
|
||||||
*date*::
|
|
||||||
The current date/time in HTTP format.
|
|
||||||
|
|
||||||
In addition, almost all templates support:
|
|
||||||
|
|
||||||
*detail*::
|
|
||||||
A detailed, plain English explanation of the error and possible
|
|
||||||
causes.
|
|
||||||
|
|
||||||
When Tinyproxy finds a variable name enclosed in braces, e.g.
|
|
||||||
"\{request}", then this is replaced by the value of the corresponding
|
|
||||||
variable before delivery of the page.
|
|
||||||
|
|
||||||
|
|
||||||
STATHOST
|
|
||||||
--------
|
|
||||||
|
|
||||||
Tinyproxy returns a HTML page with connection statistics when it
|
|
||||||
receives a HTTP request for a certain host -- the stathost. The
|
|
||||||
stathost name defaults to `@TINYPROXY_STATHOST@` and can be changed at
|
|
||||||
runtime to any name or IP address with the configuration variable
|
|
||||||
`StatHost`.
|
|
||||||
|
|
||||||
The stat file template can be changed at runtime through the
|
|
||||||
configuration variable `StatFile`.
|
|
||||||
|
|
||||||
|
|
||||||
FILES
|
|
||||||
-----
|
|
||||||
|
|
||||||
`/etc/tinyproxy/tinyproxy.conf`, `/var/run/tinyproxy/tinyproxy.pid`, `/var/log/tinyproxy/tinyproxy.log`
|
|
||||||
|
|
||||||
BUGS
|
|
||||||
----
|
|
||||||
|
|
||||||
To report bugs in Tinyproxy, please visit
|
|
||||||
<https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
|
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
|
||||||
--------
|
|
||||||
tinyproxy.conf(5)
|
|
||||||
|
|
||||||
|
|
||||||
AUTHOR
|
|
||||||
------
|
|
||||||
|
|
||||||
Written by the Tinyproxy project team.
|
|
||||||
|
|
||||||
|
|
||||||
COPYRIGHT
|
|
||||||
---------
|
|
||||||
|
|
||||||
Copyright (c) 1998-2000 Steven Young;
|
|
||||||
Copyright (c) 2000-2001 Robert James Kaes;
|
|
||||||
Copyright (c) 2009-2010 Mukund Sivaraman;
|
|
||||||
Copyright (c) 2009-2010 Michael Adam.
|
|
||||||
|
|
||||||
This program is distributed under the terms of the GNU General Public
|
|
||||||
License version 2 or above. See the COPYING file for additional
|
|
||||||
information.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
tinyproxy.conf
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
sysconf_DATA = \
|
|
||||||
tinyproxy.conf
|
|
||||||
|
|
||||||
EXTRA_DIST = \
|
|
||||||
tinyproxy.conf.in
|
|
||||||
|
|
||||||
edit = sed \
|
|
||||||
-e 's|@bindir[@]|$(bindir)|g' \
|
|
||||||
-e 's|@datadir[@]|$(datadir)|g' \
|
|
||||||
-e 's|@datarootdir[@]|$(datarootdir)|g' \
|
|
||||||
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
|
|
||||||
-e 's|@localstatedir[@]|$(localstatedir)|g' \
|
|
||||||
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
|
|
||||||
-e 's|@prefix[@]|$(prefix)|g' \
|
|
||||||
-e 's|@TINYPROXY_STATHOST[@]|$(TINYPROXY_STATHOST)|g'
|
|
||||||
|
|
||||||
tinyproxy.conf: $(top_srcdir)/etc/tinyproxy.conf.in Makefile
|
|
||||||
@rm -f $@ $@.tmp
|
|
||||||
$(AM_V_GEN) $(edit) $(top_srcdir)/etc/$@.in > $@.tmp
|
|
||||||
@mv $@.tmp $@
|
|
||||||
|
|
||||||
CLEANFILES = \
|
|
||||||
tinyproxy.conf
|
|
||||||
@@ -1,330 +0,0 @@
|
|||||||
##
|
|
||||||
## tinyproxy.conf -- tinyproxy daemon configuration file
|
|
||||||
##
|
|
||||||
## This example tinyproxy.conf file contains example settings
|
|
||||||
## with explanations in comments. For decriptions of all
|
|
||||||
## parameters, see the tinproxy.conf(5) manual page.
|
|
||||||
##
|
|
||||||
|
|
||||||
#
|
|
||||||
# User/Group: This allows you to set the user and group that will be
|
|
||||||
# used for tinyproxy after the initial binding to the port has been done
|
|
||||||
# as the root user. Either the user or group name or the UID or GID
|
|
||||||
# number may be used.
|
|
||||||
#
|
|
||||||
User nobody
|
|
||||||
Group nobody
|
|
||||||
|
|
||||||
#
|
|
||||||
# Port: Specify the port which tinyproxy will listen on. Please note
|
|
||||||
# that should you choose to run on a port lower than 1024 you will need
|
|
||||||
# to start tinyproxy using root.
|
|
||||||
#
|
|
||||||
Port 8888
|
|
||||||
|
|
||||||
#
|
|
||||||
# Listen: If you have multiple interfaces this allows you to bind to
|
|
||||||
# only one. If this is commented out, tinyproxy will bind to all
|
|
||||||
# interfaces present.
|
|
||||||
#
|
|
||||||
#Listen 192.168.0.1
|
|
||||||
|
|
||||||
#
|
|
||||||
# Bind: This allows you to specify which interface will be used for
|
|
||||||
# outgoing connections. This is useful for multi-home'd machines where
|
|
||||||
# you want all traffic to appear outgoing from one particular interface.
|
|
||||||
#
|
|
||||||
#Bind 192.168.0.1
|
|
||||||
|
|
||||||
#
|
|
||||||
# BindSame: If enabled, tinyproxy will bind the outgoing connection to the
|
|
||||||
# ip address of the incoming connection.
|
|
||||||
#
|
|
||||||
#BindSame yes
|
|
||||||
|
|
||||||
#
|
|
||||||
# Timeout: The maximum number of seconds of inactivity a connection is
|
|
||||||
# allowed to have before it is closed by tinyproxy.
|
|
||||||
#
|
|
||||||
Timeout 600
|
|
||||||
|
|
||||||
#
|
|
||||||
# ErrorFile: Defines the HTML file to send when a given HTTP error
|
|
||||||
# occurs. You will probably need to customize the location to your
|
|
||||||
# particular install. The usual locations to check are:
|
|
||||||
# /usr/local/share/tinyproxy
|
|
||||||
# /usr/share/tinyproxy
|
|
||||||
# /etc/tinyproxy
|
|
||||||
#
|
|
||||||
#ErrorFile 404 "@pkgdatadir@/404.html"
|
|
||||||
#ErrorFile 400 "@pkgdatadir@/400.html"
|
|
||||||
#ErrorFile 503 "@pkgdatadir@/503.html"
|
|
||||||
#ErrorFile 403 "@pkgdatadir@/403.html"
|
|
||||||
#ErrorFile 408 "@pkgdatadir@/408.html"
|
|
||||||
|
|
||||||
#
|
|
||||||
# DefaultErrorFile: The HTML file that gets sent if there is no
|
|
||||||
# HTML file defined with an ErrorFile keyword for the HTTP error
|
|
||||||
# that has occured.
|
|
||||||
#
|
|
||||||
DefaultErrorFile "@pkgdatadir@/default.html"
|
|
||||||
|
|
||||||
#
|
|
||||||
# StatHost: This configures the host name or IP address that is treated
|
|
||||||
# as the stat host: Whenever a request for this host is received,
|
|
||||||
# Tinyproxy will return an internal statistics page instead of
|
|
||||||
# forwarding the request to that host. The default value of StatHost is
|
|
||||||
# @TINYPROXY_STATHOST@.
|
|
||||||
#
|
|
||||||
#StatHost "@TINYPROXY_STATHOST@"
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# StatFile: The HTML file that gets sent when a request is made
|
|
||||||
# for the stathost. If this file doesn't exist a basic page is
|
|
||||||
# hardcoded in tinyproxy.
|
|
||||||
#
|
|
||||||
StatFile "@pkgdatadir@/stats.html"
|
|
||||||
|
|
||||||
#
|
|
||||||
# LogFile: Allows you to specify the location where information should
|
|
||||||
# be logged to. If you would prefer to log to syslog, then disable this
|
|
||||||
# and enable the Syslog directive. These directives are mutually
|
|
||||||
# exclusive.
|
|
||||||
#
|
|
||||||
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
|
|
||||||
|
|
||||||
#
|
|
||||||
# Syslog: Tell tinyproxy to use syslog instead of a logfile. This
|
|
||||||
# option must not be enabled if the Logfile directive is being used.
|
|
||||||
# These two directives are mutually exclusive.
|
|
||||||
#
|
|
||||||
#Syslog On
|
|
||||||
|
|
||||||
#
|
|
||||||
# LogLevel:
|
|
||||||
#
|
|
||||||
# Set the logging level. Allowed settings are:
|
|
||||||
# Critical (least verbose)
|
|
||||||
# Error
|
|
||||||
# Warning
|
|
||||||
# Notice
|
|
||||||
# Connect (to log connections without Info's noise)
|
|
||||||
# Info (most verbose)
|
|
||||||
#
|
|
||||||
# The LogLevel logs from the set level and above. For example, if the
|
|
||||||
# LogLevel was set to Warning, then all log messages from Warning to
|
|
||||||
# Critical would be output, but Notice and below would be suppressed.
|
|
||||||
#
|
|
||||||
LogLevel Info
|
|
||||||
|
|
||||||
#
|
|
||||||
# PidFile: Write the PID of the main tinyproxy thread to this file so it
|
|
||||||
# can be used for signalling purposes.
|
|
||||||
#
|
|
||||||
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
|
|
||||||
|
|
||||||
#
|
|
||||||
# XTinyproxy: Tell Tinyproxy to include the X-Tinyproxy header, which
|
|
||||||
# contains the client's IP address.
|
|
||||||
#
|
|
||||||
#XTinyproxy Yes
|
|
||||||
|
|
||||||
#
|
|
||||||
# Upstream:
|
|
||||||
#
|
|
||||||
# Turns on upstream proxy support.
|
|
||||||
#
|
|
||||||
# The upstream rules allow you to selectively route upstream connections
|
|
||||||
# based on the host/domain of the site being accessed.
|
|
||||||
#
|
|
||||||
# For example:
|
|
||||||
# # connection to test domain goes through testproxy
|
|
||||||
# upstream testproxy:8008 ".test.domain.invalid"
|
|
||||||
# upstream testproxy:8008 ".our_testbed.example.com"
|
|
||||||
# upstream testproxy:8008 "192.168.128.0/255.255.254.0"
|
|
||||||
#
|
|
||||||
# # no upstream proxy for internal websites and unqualified hosts
|
|
||||||
# no upstream ".internal.example.com"
|
|
||||||
# no upstream "www.example.com"
|
|
||||||
# no upstream "10.0.0.0/8"
|
|
||||||
# no upstream "192.168.0.0/255.255.254.0"
|
|
||||||
# no upstream "."
|
|
||||||
#
|
|
||||||
# # connection to these boxes go through their DMZ firewalls
|
|
||||||
# upstream cust1_firewall:8008 "testbed_for_cust1"
|
|
||||||
# upstream cust2_firewall:8008 "testbed_for_cust2"
|
|
||||||
#
|
|
||||||
# # default upstream is internet firewall
|
|
||||||
# upstream firewall.internal.example.com:80
|
|
||||||
#
|
|
||||||
# The LAST matching rule wins the route decision. As you can see, you
|
|
||||||
# can use a host, or a domain:
|
|
||||||
# name matches host exactly
|
|
||||||
# .name matches any host in domain "name"
|
|
||||||
# . matches any host with no domain (in 'empty' domain)
|
|
||||||
# IP/bits matches network/mask
|
|
||||||
# IP/mask matches network/mask
|
|
||||||
#
|
|
||||||
#Upstream some.remote.proxy:port
|
|
||||||
|
|
||||||
#
|
|
||||||
# MaxClients: This is the absolute highest number of threads which will
|
|
||||||
# be created. In other words, only MaxClients number of clients can be
|
|
||||||
# connected at the same time.
|
|
||||||
#
|
|
||||||
MaxClients 100
|
|
||||||
|
|
||||||
#
|
|
||||||
# MinSpareServers/MaxSpareServers: These settings set the upper and
|
|
||||||
# lower limit for the number of spare servers which should be available.
|
|
||||||
#
|
|
||||||
# If the number of spare servers falls below MinSpareServers then new
|
|
||||||
# server processes will be spawned. If the number of servers exceeds
|
|
||||||
# MaxSpareServers then the extras will be killed off.
|
|
||||||
#
|
|
||||||
MinSpareServers 5
|
|
||||||
MaxSpareServers 20
|
|
||||||
|
|
||||||
#
|
|
||||||
# StartServers: The number of servers to start initially.
|
|
||||||
#
|
|
||||||
StartServers 10
|
|
||||||
|
|
||||||
#
|
|
||||||
# MaxRequestsPerChild: The number of connections a thread will handle
|
|
||||||
# before it is killed. In practise this should be set to 0, which
|
|
||||||
# disables thread reaping. If you do notice problems with memory
|
|
||||||
# leakage, then set this to something like 10000.
|
|
||||||
#
|
|
||||||
MaxRequestsPerChild 0
|
|
||||||
|
|
||||||
#
|
|
||||||
# Allow: Customization of authorization controls. If there are any
|
|
||||||
# access control keywords then the default action is to DENY. Otherwise,
|
|
||||||
# the default action is ALLOW.
|
|
||||||
#
|
|
||||||
# The order of the controls are important. All incoming connections are
|
|
||||||
# tested against the controls based on order.
|
|
||||||
#
|
|
||||||
Allow 127.0.0.1
|
|
||||||
|
|
||||||
#
|
|
||||||
# AddHeader: Adds the specified headers to outgoing HTTP requests that
|
|
||||||
# Tinyproxy makes. Note that this option will not work for HTTPS
|
|
||||||
# traffic, as Tinyproxy has no control over what headers are exchanged.
|
|
||||||
#
|
|
||||||
#AddHeader "X-My-Header" "Powered by Tinyproxy"
|
|
||||||
|
|
||||||
#
|
|
||||||
# ViaProxyName: The "Via" header is required by the HTTP RFC, but using
|
|
||||||
# the real host name is a security concern. If the following directive
|
|
||||||
# is enabled, the string supplied will be used as the host name in the
|
|
||||||
# Via header; otherwise, the server's host name will be used.
|
|
||||||
#
|
|
||||||
ViaProxyName "tinyproxy"
|
|
||||||
|
|
||||||
#
|
|
||||||
# DisableViaHeader: When this is set to yes, Tinyproxy does NOT add
|
|
||||||
# the Via header to the requests. This virtually puts Tinyproxy into
|
|
||||||
# stealth mode. Note that RFC 2616 requires proxies to set the Via
|
|
||||||
# header, so by enabling this option, you break compliance.
|
|
||||||
# Don't disable the Via header unless you know what you are doing...
|
|
||||||
#
|
|
||||||
#DisableViaHeader Yes
|
|
||||||
|
|
||||||
#
|
|
||||||
# Filter: This allows you to specify the location of the filter file.
|
|
||||||
#
|
|
||||||
#Filter "@sysconfdir@/filter"
|
|
||||||
|
|
||||||
#
|
|
||||||
# FilterURLs: Filter based on URLs rather than domains.
|
|
||||||
#
|
|
||||||
#FilterURLs On
|
|
||||||
|
|
||||||
#
|
|
||||||
# FilterExtended: Use POSIX Extended regular expressions rather than
|
|
||||||
# basic.
|
|
||||||
#
|
|
||||||
#FilterExtended On
|
|
||||||
|
|
||||||
#
|
|
||||||
# FilterCaseSensitive: Use case sensitive regular expressions.
|
|
||||||
#
|
|
||||||
#FilterCaseSensitive On
|
|
||||||
|
|
||||||
#
|
|
||||||
# FilterDefaultDeny: Change the default policy of the filtering system.
|
|
||||||
# If this directive is commented out, or is set to "No" then the default
|
|
||||||
# policy is to allow everything which is not specifically denied by the
|
|
||||||
# filter file.
|
|
||||||
#
|
|
||||||
# However, by setting this directive to "Yes" the default policy becomes
|
|
||||||
# to deny everything which is _not_ specifically allowed by the filter
|
|
||||||
# file.
|
|
||||||
#
|
|
||||||
#FilterDefaultDeny Yes
|
|
||||||
|
|
||||||
#
|
|
||||||
# Anonymous: If an Anonymous keyword is present, then anonymous proxying
|
|
||||||
# is enabled. The headers listed are allowed through, while all others
|
|
||||||
# are denied. If no Anonymous keyword is present, then all headers are
|
|
||||||
# allowed through. You must include quotes around the headers.
|
|
||||||
#
|
|
||||||
# Most sites require cookies to be enabled for them to work correctly, so
|
|
||||||
# you will need to allow Cookies through if you access those sites.
|
|
||||||
#
|
|
||||||
#Anonymous "Host"
|
|
||||||
#Anonymous "Authorization"
|
|
||||||
#Anonymous "Cookie"
|
|
||||||
|
|
||||||
#
|
|
||||||
# ConnectPort: This is a list of ports allowed by tinyproxy when the
|
|
||||||
# CONNECT method is used. To disable the CONNECT method altogether, set
|
|
||||||
# the value to 0. If no ConnectPort line is found, all ports are
|
|
||||||
# allowed (which is not very secure.)
|
|
||||||
#
|
|
||||||
# The following two ports are used by SSL.
|
|
||||||
#
|
|
||||||
ConnectPort 443
|
|
||||||
ConnectPort 563
|
|
||||||
|
|
||||||
#
|
|
||||||
# Configure one or more ReversePath directives to enable reverse proxy
|
|
||||||
# support. With reverse proxying it's possible to make a number of
|
|
||||||
# sites appear as if they were part of a single site.
|
|
||||||
#
|
|
||||||
# If you uncomment the following two directives and run tinyproxy
|
|
||||||
# on your own computer at port 8888, you can access Google using
|
|
||||||
# http://localhost:8888/google/ and Wired News using
|
|
||||||
# http://localhost:8888/wired/news/. Neither will actually work
|
|
||||||
# until you uncomment ReverseMagic as they use absolute linking.
|
|
||||||
#
|
|
||||||
#ReversePath "/google/" "http://www.google.com/"
|
|
||||||
#ReversePath "/wired/" "http://www.wired.com/"
|
|
||||||
|
|
||||||
#
|
|
||||||
# When using tinyproxy as a reverse proxy, it is STRONGLY recommended
|
|
||||||
# that the normal proxy is turned off by uncommenting the next directive.
|
|
||||||
#
|
|
||||||
#ReverseOnly Yes
|
|
||||||
|
|
||||||
#
|
|
||||||
# Use a cookie to track reverse proxy mappings. If you need to reverse
|
|
||||||
# proxy sites which have absolute links you must uncomment this.
|
|
||||||
#
|
|
||||||
#ReverseMagic Yes
|
|
||||||
|
|
||||||
#
|
|
||||||
# The URL that's used to access this reverse proxy. The URL is used to
|
|
||||||
# rewrite HTTP redirects so that they won't escape the proxy. If you
|
|
||||||
# have a chain of reverse proxies, you'll need to put the outermost
|
|
||||||
# URL here (the address which the end user types into his/her browser).
|
|
||||||
#
|
|
||||||
# If not set then no rewriting occurs.
|
|
||||||
#
|
|
||||||
#ReverseBaseURL "http://localhost:8888/"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
EXTRA_DIST = \
|
|
||||||
as-compiler-flag.m4 \
|
|
||||||
argenable.m4 \
|
|
||||||
typecheck.m4
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
dnl $Id: argenable.m4,v 1.1 2004-08-24 18:40:21 rjkaes Exp $
|
|
||||||
dnl
|
|
||||||
dnl Define a new AC_ARG_ENABLE like macro which handles invalid inputs
|
|
||||||
dnl correctly. The macro takes three arguments:
|
|
||||||
dnl 1) the option name (used like --enable-option)
|
|
||||||
dnl 2) the help string
|
|
||||||
dnl 3) the default value (either yes or no)
|
|
||||||
dnl
|
|
||||||
dnl This macro also defines on variable in the form "option_enabled"
|
|
||||||
dnl set to either "yes" or "no".
|
|
||||||
dnl
|
|
||||||
AC_DEFUN([TP_ARG_ENABLE],
|
|
||||||
[AC_ARG_ENABLE([$1],
|
|
||||||
AS_HELP_STRING([--enable-$1], [$2]),
|
|
||||||
[case "${enableval}" in
|
|
||||||
yes) $1_enabled=yes ;;
|
|
||||||
no) $1_enabled=no ;;
|
|
||||||
*) AC_MSG_ERROR([bad value ${enableval} for --enable-$1]) ;;
|
|
||||||
esac],[$1_enabled=$3])])
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
dnl as-compiler-flag.m4 0.1.0
|
|
||||||
|
|
||||||
dnl autostars m4 macro for detection of compiler flags
|
|
||||||
|
|
||||||
dnl David Schleef <ds@schleef.org>
|
|
||||||
dnl Tim-Philipp Müller <tim centricular net>
|
|
||||||
|
|
||||||
dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
|
|
||||||
dnl Tries to compile with the given CFLAGS.
|
|
||||||
dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
|
|
||||||
dnl and ACTION-IF-NOT-ACCEPTED otherwise.
|
|
||||||
|
|
||||||
AC_DEFUN([AS_COMPILER_FLAG],
|
|
||||||
[
|
|
||||||
AC_MSG_CHECKING([to see if compiler understands $1])
|
|
||||||
|
|
||||||
save_CFLAGS="$CFLAGS"
|
|
||||||
CFLAGS="$CFLAGS $1"
|
|
||||||
|
|
||||||
AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
|
|
||||||
CFLAGS="$save_CFLAGS"
|
|
||||||
|
|
||||||
if test "X$flag_ok" = Xyes ; then
|
|
||||||
$2
|
|
||||||
true
|
|
||||||
else
|
|
||||||
$3
|
|
||||||
true
|
|
||||||
fi
|
|
||||||
AC_MSG_RESULT([$flag_ok])
|
|
||||||
])
|
|
||||||
|
|
||||||
dnl AS_CXX_COMPILER_FLAG(CPPFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
|
|
||||||
dnl Tries to compile with the given CPPFLAGS.
|
|
||||||
dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
|
|
||||||
dnl and ACTION-IF-NOT-ACCEPTED otherwise.
|
|
||||||
|
|
||||||
AC_DEFUN([AS_CXX_COMPILER_FLAG],
|
|
||||||
[
|
|
||||||
AC_REQUIRE([AC_PROG_CXX])
|
|
||||||
|
|
||||||
AC_MSG_CHECKING([to see if c++ compiler understands $1])
|
|
||||||
|
|
||||||
save_CPPFLAGS="$CPPFLAGS"
|
|
||||||
CPPFLAGS="$CPPFLAGS $1"
|
|
||||||
|
|
||||||
AC_LANG_PUSH(C++)
|
|
||||||
|
|
||||||
AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
|
|
||||||
CPPFLAGS="$save_CPPFLAGS"
|
|
||||||
|
|
||||||
if test "X$flag_ok" = Xyes ; then
|
|
||||||
$2
|
|
||||||
true
|
|
||||||
else
|
|
||||||
$3
|
|
||||||
true
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_LANG_POP(C++)
|
|
||||||
|
|
||||||
AC_MSG_RESULT([$flag_ok])
|
|
||||||
])
|
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm -f config.cache
|
||||||
|
echo "- aclocal."
|
||||||
|
aclocal
|
||||||
|
echo "- autoconf."
|
||||||
|
autoconf
|
||||||
|
echo "- autoheader."
|
||||||
|
autoheader
|
||||||
|
echo "- automake."
|
||||||
|
automake -a
|
||||||
|
exit
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
.deps
|
|
||||||
.libs
|
|
||||||
Makefile
|
|
||||||
Makefile.in
|
|
||||||
tinyproxy
|
|
||||||
*.o
|
|
||||||
*.pcno
|
|
||||||
+34
-40
@@ -1,53 +1,47 @@
|
|||||||
# tinyproxy - A fast light-weight HTTP proxy
|
# $Id: Makefile.am,v 1.3 2000-09-11 23:37:01 rjkaes Exp $
|
||||||
# Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License along
|
# Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
#
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# This program is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the
|
||||||
|
# Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
# later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
|
||||||
sbin_PROGRAMS = tinyproxy
|
YFLAGS = @YFLAGS@
|
||||||
|
|
||||||
AM_CPPFLAGS = \
|
bin_PROGRAMS = tinyproxy
|
||||||
-DSYSCONFDIR=\"${sysconfdir}\" \
|
|
||||||
-DLOCALSTATEDIR=\"${localstatedir}\"
|
|
||||||
|
|
||||||
tinyproxy_SOURCES = \
|
tinyproxy_SOURCES = \
|
||||||
acl.c acl.h \
|
|
||||||
anonymous.c anonymous.h \
|
|
||||||
buffer.c buffer.h \
|
buffer.c buffer.h \
|
||||||
child.c child.h \
|
dnscache.c dnscache.h \
|
||||||
common.h \
|
|
||||||
conf.c conf.h \
|
|
||||||
conns.c conns.h \
|
|
||||||
daemon.c daemon.h \
|
|
||||||
hashmap.c hashmap.h \
|
|
||||||
heap.c heap.h \
|
|
||||||
html-error.c html-error.h \
|
|
||||||
http-message.c http-message.h \
|
|
||||||
log.c log.h \
|
log.c log.h \
|
||||||
network.c network.h \
|
|
||||||
reqs.c reqs.h \
|
reqs.c reqs.h \
|
||||||
sock.c sock.h \
|
sock.c sock.h \
|
||||||
stats.c stats.h \
|
tinyproxy.c tinyproxy.h \
|
||||||
text.c text.h \
|
uri.c uri.h \
|
||||||
main.c main.h \
|
|
||||||
utils.c utils.h \
|
utils.c utils.h \
|
||||||
vector.c vector.h \
|
anonymous.c anonymous.h \
|
||||||
upstream.c upstream.h \
|
stats.c stats.h \
|
||||||
connect-ports.c connect-ports.h
|
thread.c thread.h \
|
||||||
|
grammar.y scanner.l \
|
||||||
|
acl.c acl.h \
|
||||||
|
ternary.c ternary.h \
|
||||||
|
regexp.h
|
||||||
|
|
||||||
EXTRA_tinyproxy_SOURCES = filter.c filter.h \
|
tinyproxy_LDADD = @LIBOBJS@
|
||||||
reverse-proxy.c reverse-proxy.h \
|
|
||||||
transparent-proxy.c transparent-proxy.h
|
EXTRA_DIST = gnuregex.c gnuregex.h \
|
||||||
tinyproxy_DEPENDENCIES = @ADDITIONAL_OBJECTS@
|
filter.c filter.h
|
||||||
tinyproxy_LDADD = @ADDITIONAL_OBJECTS@
|
|
||||||
|
EXTRA_tinyproxy_SOURCES = grammar.h
|
||||||
|
|
||||||
|
scanner.c: scanner.l grammar.h
|
||||||
|
$(LEX) $(AM_LFLAGS) $(LFLAGS) -i $< && mv $(LEX_OUTPUT_ROOT).c $@
|
||||||
@@ -1,128 +1,61 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: acl.c,v 1.4 2001-05-27 02:20:54 rjkaes Exp $
|
||||||
* Copyright (C) 2000, 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This system handles Access Control for use of this daemon. A list of
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This system handles Access Control for use of this daemon. A list of
|
|
||||||
* domains, or IP addresses (including IP blocks) are stored in a list
|
* domains, or IP addresses (including IP blocks) are stored in a list
|
||||||
* which is then used to compare incoming connections.
|
* which is then used to compare incoming connections.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "acl.h"
|
#include "acl.h"
|
||||||
#include "heap.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "network.h"
|
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "vector.h"
|
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
/* Define how long an IPv6 address is in bytes (128 bits, 16 bytes) */
|
|
||||||
#define IPV6_LEN 16
|
|
||||||
|
|
||||||
enum acl_type {
|
|
||||||
ACL_STRING,
|
|
||||||
ACL_NUMERIC
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hold the information about a particular access control. We store
|
|
||||||
* whether it's an ALLOW or DENY entry, and also whether it's a string
|
|
||||||
* entry (like a domain name) or an IP entry.
|
|
||||||
*/
|
|
||||||
struct acl_s {
|
struct acl_s {
|
||||||
acl_access_t access;
|
acl_access_t acl_access;
|
||||||
enum acl_type type;
|
enum { ACL_STRING, ACL_NUMERIC } type;
|
||||||
union {
|
char *location;
|
||||||
char *string;
|
int netmask;
|
||||||
struct {
|
struct acl_s *next;
|
||||||
unsigned char octet[IPV6_LEN];
|
|
||||||
unsigned char mask[IPV6_LEN];
|
|
||||||
} ip;
|
|
||||||
} address;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct acl_s *access_list = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fills in the netmask array given a numeric value.
|
* Take a netmask number (between 0 and 32) and returns a network ordered
|
||||||
*
|
* value for comparison. Somebody please clean this up. :)
|
||||||
* Returns:
|
|
||||||
* 0 on success
|
|
||||||
* -1 on failure (invalid mask value)
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
static int
|
static in_addr_t make_netmask(int netmask_num)
|
||||||
fill_netmask_array (char *bitmask_string, int v6,
|
|
||||||
unsigned char array[], size_t len)
|
|
||||||
{
|
{
|
||||||
unsigned int i;
|
static in_addr_t netmasks[] = {
|
||||||
unsigned long int mask;
|
0x00000000, 0x80000000, 0xc0000000, 0xe0000000,
|
||||||
char *endptr;
|
0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
|
||||||
|
0xff800000, 0xffc00000, 0xffe00000, 0xfff00000,
|
||||||
|
0xfff00000, 0xfff80000, 0xfffc0000, 0xfffe0000,
|
||||||
|
0xffff0000, 0xffff8000, 0xffffc000, 0xffffe000,
|
||||||
|
0xfffff000, 0xfffff800, 0xfffffc00, 0xfffffe00,
|
||||||
|
0xffffff00, 0xffffff80, 0xffffffc0, 0xffffffe0,
|
||||||
|
0xfffffff0, 0xfffffff8, 0xfffffffc, 0xfffffffe,
|
||||||
|
0xffffffff
|
||||||
|
};
|
||||||
|
|
||||||
errno = 0; /* to distinguish success/failure after call */
|
assert(netmask_num >= 0 && netmask_num <= 32);
|
||||||
mask = strtoul (bitmask_string, &endptr, 10);
|
|
||||||
|
|
||||||
/* check for various conversion errors */
|
return htonl(netmasks[netmask_num]);
|
||||||
if ((errno == ERANGE && mask == ULONG_MAX)
|
|
||||||
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (v6 == 0) {
|
|
||||||
/* The mask comparison is done as an IPv6 address, so
|
|
||||||
* convert to a longer mask in the case of IPv4
|
|
||||||
* addresses. */
|
|
||||||
mask += 12 * 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check valid range for a bit mask */
|
|
||||||
if (mask > (8 * len))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* we have a valid range to fill in the array */
|
|
||||||
for (i = 0; i != len; ++i) {
|
|
||||||
if (mask >= 8) {
|
|
||||||
array[i] = 0xff;
|
|
||||||
mask -= 8;
|
|
||||||
} else if (mask > 0) {
|
|
||||||
array[i] = (unsigned char) (0xff << (8 - mask));
|
|
||||||
mask = 0;
|
|
||||||
} else {
|
|
||||||
array[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the access list has not been set up, create it.
|
|
||||||
*/
|
|
||||||
static int init_access_list(vector_t *access_list)
|
|
||||||
{
|
|
||||||
if (!*access_list) {
|
|
||||||
*access_list = vector_create ();
|
|
||||||
if (!*access_list) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Unable to allocate memory for access list");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -134,262 +67,154 @@ static int init_access_list(vector_t *access_list)
|
|||||||
* -1 on failure
|
* -1 on failure
|
||||||
* 0 otherwise.
|
* 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
|
int insert_acl(char *location, acl_access_t access_type)
|
||||||
{
|
{
|
||||||
struct acl_s acl;
|
size_t i;
|
||||||
int ret;
|
struct acl_s **rev_acl_ptr, *acl_ptr, *new_acl_ptr;
|
||||||
char *p, ip_dst[IPV6_LEN];
|
char *nptr;
|
||||||
|
|
||||||
assert (location != NULL);
|
assert(location != NULL);
|
||||||
|
|
||||||
ret = init_access_list(access_list);
|
/*
|
||||||
if (ret != 0) {
|
* First check to see if the location is a string or numeric.
|
||||||
return -1;
|
*/
|
||||||
}
|
for (i = 0; i < strlen((char *)location); i++) {
|
||||||
|
if (isdigit((unsigned char)location[i]) != 0 && location[i] != '.') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start populating the access control structure.
|
* Add a new ACL to the list.
|
||||||
*/
|
*/
|
||||||
memset (&acl, 0, sizeof (struct acl_s));
|
rev_acl_ptr = &access_list;
|
||||||
acl.access = access_type;
|
acl_ptr = access_list;
|
||||||
|
while (acl_ptr) {
|
||||||
|
rev_acl_ptr = &acl_ptr->next;
|
||||||
|
acl_ptr = acl_ptr->next;
|
||||||
|
}
|
||||||
|
new_acl_ptr = malloc(sizeof(struct acl_s));
|
||||||
|
if (!new_acl_ptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
new_acl_ptr->acl_access = access_type;
|
||||||
* Check for a valid IP address (the simplest case) first.
|
|
||||||
*/
|
|
||||||
if (full_inet_pton (location, ip_dst) > 0) {
|
|
||||||
acl.type = ACL_NUMERIC;
|
|
||||||
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
|
|
||||||
memset (acl.address.ip.mask, 0xff, IPV6_LEN);
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* At this point we're either a hostname or an
|
|
||||||
* IP address with a slash.
|
|
||||||
*/
|
|
||||||
p = strchr (location, '/');
|
|
||||||
if (p != NULL) {
|
|
||||||
char dst[sizeof(struct in6_addr)];
|
|
||||||
int v6;
|
|
||||||
|
|
||||||
/*
|
if (i != strlen(location)) {
|
||||||
* We have a slash, so it's intended to be an
|
/* We did break early, so this a numeric location.
|
||||||
* IP address with mask
|
* Check for a netmask.
|
||||||
*/
|
*/
|
||||||
*p = '\0';
|
new_acl_ptr->type = ACL_NUMERIC;
|
||||||
if (full_inet_pton (location, ip_dst) <= 0)
|
nptr = strchr(location, '/');
|
||||||
return -1;
|
if (nptr) {
|
||||||
|
*nptr++ = '\0';
|
||||||
|
|
||||||
acl.type = ACL_NUMERIC;
|
new_acl_ptr->netmask = atoi(nptr);
|
||||||
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
|
if (new_acl_ptr->netmask < 0 || new_acl_ptr->netmask > 32) {
|
||||||
|
safefree(new_acl_ptr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new_acl_ptr->netmask = 32;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new_acl_ptr->type = ACL_STRING;
|
||||||
|
new_acl_ptr->netmask = 32;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if the IP address before the netmask is
|
new_acl_ptr->location = strdup(location);
|
||||||
* an IPv6 address */
|
if (!new_acl_ptr->location) {
|
||||||
if (inet_pton(AF_INET6, location, dst) > 0)
|
safefree(new_acl_ptr);
|
||||||
v6 = 1;
|
return -1;
|
||||||
else
|
}
|
||||||
v6 = 0;
|
|
||||||
|
|
||||||
if (fill_netmask_array
|
*rev_acl_ptr = new_acl_ptr;
|
||||||
(p + 1, v6, &(acl.address.ip.mask[0]), IPV6_LEN)
|
new_acl_ptr->next = acl_ptr;
|
||||||
< 0)
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
/* In all likelihood a string */
|
|
||||||
acl.type = ACL_STRING;
|
|
||||||
acl.address.string = safestrdup (location);
|
|
||||||
if (!acl.address.string)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = vector_append (*access_list, &acl, sizeof (struct acl_s));
|
return 0;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function is called whenever a "string" access control is found in
|
* Checks where file descriptor is allowed.
|
||||||
* the ACL. From here we do both a text based string comparison, along with
|
|
||||||
* a reverse name lookup comparison of the IP addresses.
|
|
||||||
*
|
|
||||||
* Return: 0 if host is denied
|
|
||||||
* 1 if host is allowed
|
|
||||||
* -1 if no tests match, so skip
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
acl_string_processing (struct acl_s *acl,
|
|
||||||
const char *ip_address, const char *string_address)
|
|
||||||
{
|
|
||||||
int match;
|
|
||||||
struct addrinfo hints, *res, *ressave;
|
|
||||||
size_t test_length, match_length;
|
|
||||||
char ipbuf[512];
|
|
||||||
|
|
||||||
assert (acl && acl->type == ACL_STRING);
|
|
||||||
assert (ip_address && strlen (ip_address) > 0);
|
|
||||||
assert (string_address && strlen (string_address) > 0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the first character of the ACL string is a period, we need to
|
|
||||||
* do a string based test only; otherwise, we can do a reverse
|
|
||||||
* lookup test as well.
|
|
||||||
*/
|
|
||||||
if (acl->address.string[0] != '.') {
|
|
||||||
memset (&hints, 0, sizeof (struct addrinfo));
|
|
||||||
hints.ai_family = AF_UNSPEC;
|
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
|
||||||
if (getaddrinfo (acl->address.string, NULL, &hints, &res) != 0)
|
|
||||||
goto STRING_TEST;
|
|
||||||
|
|
||||||
ressave = res;
|
|
||||||
|
|
||||||
match = FALSE;
|
|
||||||
do {
|
|
||||||
get_ip_string (res->ai_addr, ipbuf, sizeof (ipbuf));
|
|
||||||
if (strcmp (ip_address, ipbuf) == 0) {
|
|
||||||
match = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while ((res = res->ai_next) != NULL);
|
|
||||||
|
|
||||||
freeaddrinfo (ressave);
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
if (acl->access == ACL_DENY)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
STRING_TEST:
|
|
||||||
test_length = strlen (string_address);
|
|
||||||
match_length = strlen (acl->address.string);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the string length is shorter than AC string, return a -1 so
|
|
||||||
* that the "driver" will skip onto the next control in the list.
|
|
||||||
*/
|
|
||||||
if (test_length < match_length)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (strcasecmp
|
|
||||||
(string_address + (test_length - match_length),
|
|
||||||
acl->address.string) == 0) {
|
|
||||||
if (acl->access == ACL_DENY)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Indicate that no tests succeeded, so skip to next control. */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Compare the supplied numeric IP address with the supplied ACL structure.
|
|
||||||
*
|
|
||||||
* Return:
|
|
||||||
* 1 IP address is allowed
|
|
||||||
* 0 IP address is denied
|
|
||||||
* -1 neither allowed nor denied.
|
|
||||||
*/
|
|
||||||
static int check_numeric_acl (const struct acl_s *acl, const char *ip)
|
|
||||||
{
|
|
||||||
uint8_t addr[IPV6_LEN], x, y;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
assert (acl && acl->type == ACL_NUMERIC);
|
|
||||||
assert (ip && strlen (ip) > 0);
|
|
||||||
|
|
||||||
if (full_inet_pton (ip, &addr) <= 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (i = 0; i != IPV6_LEN; ++i) {
|
|
||||||
x = addr[i] & acl->address.ip.mask[i];
|
|
||||||
y = acl->address.ip.octet[i] & acl->address.ip.mask[i];
|
|
||||||
|
|
||||||
/* If x and y don't match, the IP addresses don't match */
|
|
||||||
if (x != y)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The addresses match, return the permission */
|
|
||||||
return (acl->access == ACL_ALLOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks whether a connection is allowed.
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 1 if allowed
|
* 1 if allowed
|
||||||
* 0 if denied
|
* 0 if denied
|
||||||
|
* -1 if error
|
||||||
*/
|
*/
|
||||||
int check_acl (const char *ip, const char *host, vector_t access_list)
|
int check_acl(int fd)
|
||||||
{
|
{
|
||||||
struct acl_s *acl;
|
struct acl_s *aclptr;
|
||||||
int perm = 0;
|
char ip_address[PEER_IP_LENGTH];
|
||||||
size_t i;
|
char string_address[PEER_STRING_LENGTH];
|
||||||
|
|
||||||
assert (ip != NULL);
|
assert(fd >= 0);
|
||||||
assert (host != NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there is no access list allow everything.
|
* If there is no access list allow everything.
|
||||||
*/
|
*/
|
||||||
if (!access_list)
|
aclptr = access_list;
|
||||||
return 1;
|
if (!aclptr)
|
||||||
|
return 1;
|
||||||
|
|
||||||
for (i = 0; i != (size_t) vector_length (access_list); ++i) {
|
/*
|
||||||
acl = (struct acl_s *) vector_getentry (access_list, i, NULL);
|
* Get the IP address and the string domain.
|
||||||
switch (acl->type) {
|
*/
|
||||||
case ACL_STRING:
|
getpeer_ip(fd, ip_address);
|
||||||
perm = acl_string_processing (acl, ip, host);
|
getpeer_string(fd, string_address);
|
||||||
break;
|
|
||||||
|
|
||||||
case ACL_NUMERIC:
|
while (aclptr) {
|
||||||
if (ip[0] == '\0')
|
if (aclptr->type == ACL_STRING) {
|
||||||
continue;
|
size_t test_length = strlen(string_address);
|
||||||
perm = check_numeric_acl (acl, ip);
|
size_t match_length = strlen(aclptr->location);
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
if (test_length < match_length) {
|
||||||
* Check the return value too see if the IP address is
|
aclptr = aclptr->next;
|
||||||
* allowed or denied.
|
continue;
|
||||||
*/
|
}
|
||||||
if (perm == 0)
|
|
||||||
break;
|
|
||||||
else if (perm == 1)
|
|
||||||
return perm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
if (strcasecmp(string_address + (test_length - match_length), aclptr->location) == 0) {
|
||||||
* Deny all connections by default.
|
if (aclptr->acl_access == ACL_DENY) {
|
||||||
*/
|
log_message(LOG_NOTICE, "Unauthorized access from %s", string_address);
|
||||||
log_message (LOG_NOTICE, "Unauthorized connection from \"%s\" [%s].",
|
return 0;
|
||||||
host, ip);
|
} else {
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void flush_access_list (vector_t access_list)
|
} else {
|
||||||
{
|
struct in_addr test_addr, match_addr;
|
||||||
struct acl_s *acl;
|
in_addr_t netmask_addr;
|
||||||
size_t i;
|
|
||||||
|
if (ip_address[0] == 0) {
|
||||||
if (!access_list) {
|
aclptr = aclptr->next;
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
inet_aton(ip_address, &test_addr);
|
||||||
* We need to free allocated data hanging off the acl entries
|
inet_aton(aclptr->location, &match_addr);
|
||||||
* before we can free the acl entries themselves.
|
|
||||||
* A hierarchical memory system would be great...
|
netmask_addr = make_netmask(aclptr->netmask);
|
||||||
*/
|
|
||||||
for (i = 0; i != (size_t) vector_length (access_list); ++i) {
|
if ((test_addr.s_addr & netmask_addr) == (match_addr.s_addr & netmask_addr)) {
|
||||||
acl = (struct acl_s *) vector_getentry (access_list, i, NULL);
|
if (aclptr->acl_access == ACL_DENY) {
|
||||||
if (acl->type == ACL_STRING) {
|
log_message(LOG_NOTICE, "Unauthorized access from %s", ip_address);
|
||||||
safefree (acl->address.string);
|
return 0;
|
||||||
}
|
} else {
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
vector_delete (access_list);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dropped through... go on to the next one.
|
||||||
|
*/
|
||||||
|
aclptr = aclptr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deny all connections by default.
|
||||||
|
*/
|
||||||
|
log_message(LOG_NOTICE, "Unauthorized connection from %s [%s]", string_address, ip_address);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,26 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: acl.h,v 1.2 2001-06-02 02:07:34 rjkaes Exp $
|
||||||
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* See 'acl.c' for detailed information.
|
||||||
* 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,
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'acl.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_ACL_H
|
#ifndef TINYPROXY_ACL_H
|
||||||
#define TINYPROXY_ACL_H
|
#define TINYPROXY_ACL_H
|
||||||
|
|
||||||
#include "vector.h"
|
|
||||||
|
|
||||||
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
|
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
|
||||||
|
|
||||||
extern int insert_acl (char *location, acl_access_t access_type,
|
extern int insert_acl(char *location, acl_access_t access_type);
|
||||||
vector_t *access_list);
|
extern int check_acl(int fd);
|
||||||
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
|
||||||
+35
-54
@@ -1,73 +1,54 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: anonymous.c,v 1.5 2001-05-27 02:21:37 rjkaes Exp $
|
||||||
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Handles insertion and searches for headers which should be let through when
|
||||||
* it under the terms of the GNU General Public License as published by
|
* the anonymous feature is turned on. The headers are stored in a Ternary
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* Search Tree. The initial code came from Dr. Dobb's Journal, April 1998
|
||||||
* (at your option) any later version.
|
* "Ternary Search Trees", Jon Bentley and Bob Sedgewick, pg 20-25.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Handles insertion and searches for headers which should be let through
|
#ifdef HAVE_CONFIG_H
|
||||||
* when the anonymous feature is turned on.
|
# include <config.h>
|
||||||
*/
|
#endif
|
||||||
|
|
||||||
#include "main.h"
|
#include <sys/types.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "anonymous.h"
|
#include "anonymous.h"
|
||||||
#include "hashmap.h"
|
#include "ternary.h"
|
||||||
#include "heap.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
short int is_anonymous_enabled (void)
|
static TERNARY anonymous_tree;
|
||||||
|
|
||||||
|
TERNARY new_anonymous(void)
|
||||||
{
|
{
|
||||||
return (config.anonymous_map != NULL) ? 1 : 0;
|
anonymous_tree = ternary_new();
|
||||||
|
return anonymous_tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int anon_search(char *s)
|
||||||
* Search for the header. This function returns a positive value greater than
|
|
||||||
* zero if the string was found, zero if it wasn't and negative upon error.
|
|
||||||
*/
|
|
||||||
int anonymous_search (const char *s)
|
|
||||||
{
|
{
|
||||||
assert (s != NULL);
|
assert(s != NULL);
|
||||||
assert (config.anonymous_map != NULL);
|
|
||||||
|
|
||||||
return hashmap_search (config.anonymous_map, s);
|
return ternary_search(anonymous_tree, s, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void anon_insert(char *s)
|
||||||
* Insert a new header.
|
|
||||||
*
|
|
||||||
* Return -1 if there is an error, otherwise a 0 is returned if the insert was
|
|
||||||
* successful.
|
|
||||||
*/
|
|
||||||
int anonymous_insert (const char *s)
|
|
||||||
{
|
{
|
||||||
char data = 1;
|
assert(s != NULL);
|
||||||
|
|
||||||
assert (s != NULL);
|
ternary_insert(anonymous_tree, s, NULL);
|
||||||
|
|
||||||
if (!config.anonymous_map) {
|
|
||||||
config.anonymous_map = hashmap_create (32);
|
|
||||||
if (!config.anonymous_map)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hashmap_search (config.anonymous_map, s) > 0) {
|
|
||||||
/* The key was already found, so return a positive number. */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Insert the new key */
|
|
||||||
return hashmap_insert (config.anonymous_map, s, &data, sizeof (data));
|
|
||||||
}
|
}
|
||||||
+17
-18
@@ -1,28 +1,27 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: anonymous.h,v 1.4 2001-05-27 02:21:37 rjkaes Exp $
|
||||||
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* See 'anonymous.c' for a detailed description.
|
||||||
* 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,
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'anonymous.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef _TINYPROXY_ANONYMOUS_H_
|
#ifndef _TINYPROXY_ANONYMOUS_H_
|
||||||
#define _TINYPROXY_ANONYMOUS_H_
|
#define _TINYPROXY_ANONYMOUS_H_
|
||||||
|
|
||||||
extern short int is_anonymous_enabled (void);
|
#include "ternary.h"
|
||||||
extern int anonymous_search (const char *s);
|
|
||||||
extern int anonymous_insert (const char *s);
|
extern TERNARY new_anonymous(void);
|
||||||
|
extern int anon_search(char *s);
|
||||||
|
extern void anon_insert(char *s);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+173
-218
@@ -1,323 +1,278 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: buffer.c,v 1.5 2001-05-27 02:23:08 rjkaes Exp $
|
||||||
* Copyright (C) 1999, 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* The buffer used in each connection is a linked list of lines. As the lines
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The buffer used in each connection is a linked list of lines. As the lines
|
|
||||||
* are read in and written out the buffer expands and contracts. Basically,
|
* are read in and written out the buffer expands and contracts. Basically,
|
||||||
* by using this method we can increase the buffer size dynamically. However,
|
* by using this method we can increase the buffer size dynamicly. However,
|
||||||
* we have a hard limit of 64 KB for the size of the buffer. The buffer can be
|
* we have a hard limit of 64 KB for the size of the buffer. The buffer can be
|
||||||
* thought of as a queue were we act on both the head and tail. The various
|
* thought of as a queue were we act on both the head and tail. The various
|
||||||
* functions act on each end (the names are taken from what Perl uses to act on
|
* functions act on each end (the names are taken from what Perl uses to act on
|
||||||
* the ends of an array. :)
|
* the ends of an array. :)
|
||||||
|
*
|
||||||
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "heap.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#define BUFFER_HEAD(x) (x)->head
|
#define BUFFER_HEAD(x) (((struct buffer_s *)(x))->head)
|
||||||
#define BUFFER_TAIL(x) (x)->tail
|
#define BUFFER_TAIL(x) (((struct buffer_s *)(x))->tail)
|
||||||
|
|
||||||
struct bufline_s {
|
struct bufline_s {
|
||||||
unsigned char *string; /* the actual string of data */
|
unsigned char *string; /* the actual string of data */
|
||||||
struct bufline_s *next; /* pointer to next in linked list */
|
struct bufline_s *next; /* pointer to next in linked list */
|
||||||
size_t length; /* length of the string of data */
|
size_t length; /* length of the string of data */
|
||||||
size_t pos; /* start sending from this offset */
|
size_t pos; /* start sending from this offset */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct buffer_s {
|
||||||
|
struct bufline_s *head; /* top of the buffer */
|
||||||
|
struct bufline_s *tail; /* bottom of the buffer */
|
||||||
|
size_t size; /* total size of the buffer */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The buffer structure points to the beginning and end of the buffer list
|
* Return the size of the supplied buffer.
|
||||||
* (and includes the total size)
|
|
||||||
*/
|
*/
|
||||||
struct buffer_s {
|
size_t buffer_size(struct buffer_s *buffptr)
|
||||||
struct bufline_s *head; /* top of the buffer */
|
{
|
||||||
struct bufline_s *tail; /* bottom of the buffer */
|
assert(buffptr != NULL);
|
||||||
size_t size; /* total size of the buffer */
|
|
||||||
};
|
return buffptr->size;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Take a string of data and a length and make a new line which can be added
|
* Take a string of data and a length and make a new line which can be added
|
||||||
* to the buffer. The data IS copied, so make sure if you allocated your
|
* to the buffer
|
||||||
* data buffer on the heap, delete it because you now have TWO copies.
|
|
||||||
*/
|
*/
|
||||||
static struct bufline_s *makenewline (unsigned char *data, size_t length)
|
static struct bufline_s *makenewline(unsigned char *data, size_t length)
|
||||||
{
|
{
|
||||||
struct bufline_s *newline;
|
struct bufline_s *newline;
|
||||||
|
|
||||||
assert (data != NULL);
|
assert(data != NULL);
|
||||||
assert (length > 0);
|
|
||||||
|
|
||||||
newline = (struct bufline_s *) safemalloc (sizeof (struct bufline_s));
|
if (!(newline = malloc(sizeof(struct bufline_s))))
|
||||||
if (!newline)
|
return NULL;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
newline->string = (unsigned char *) safemalloc (length);
|
newline->string = data;
|
||||||
if (!newline->string) {
|
newline->next = NULL;
|
||||||
safefree (newline);
|
newline->length = length;
|
||||||
return NULL;
|
newline->pos = 0;
|
||||||
}
|
|
||||||
|
|
||||||
memcpy (newline->string, data, length);
|
return newline;
|
||||||
|
|
||||||
newline->next = NULL;
|
|
||||||
newline->length = length;
|
|
||||||
|
|
||||||
/* Position our "read" pointer at the beginning of the data */
|
|
||||||
newline->pos = 0;
|
|
||||||
|
|
||||||
return newline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free the allocated buffer line
|
* Free the allocated buffer line
|
||||||
*/
|
*/
|
||||||
static void free_line (struct bufline_s *line)
|
static void free_line(struct bufline_s *line)
|
||||||
{
|
{
|
||||||
assert (line != NULL);
|
assert(line != NULL);
|
||||||
|
|
||||||
if (!line)
|
if (!line)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (line->string)
|
if (line->string) {
|
||||||
safefree (line->string);
|
safefree(line->string);
|
||||||
|
}
|
||||||
|
|
||||||
safefree (line);
|
safefree(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new buffer
|
* Create a new buffer
|
||||||
*/
|
*/
|
||||||
struct buffer_s *new_buffer (void)
|
struct buffer_s *new_buffer(void)
|
||||||
{
|
{
|
||||||
struct buffer_s *buffptr;
|
struct buffer_s *buffptr;
|
||||||
|
|
||||||
buffptr = (struct buffer_s *) safemalloc (sizeof (struct buffer_s));
|
if (!(buffptr = malloc(sizeof(struct buffer_s))))
|
||||||
if (!buffptr)
|
return NULL;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/*
|
buffptr->head = buffptr->tail = NULL;
|
||||||
* Since the buffer is initially empty, set the HEAD and TAIL
|
buffptr->size = 0;
|
||||||
* pointers to NULL since they can't possibly point anywhere at the
|
|
||||||
* moment.
|
|
||||||
*/
|
|
||||||
BUFFER_HEAD (buffptr) = BUFFER_TAIL (buffptr) = NULL;
|
|
||||||
buffptr->size = 0;
|
|
||||||
|
|
||||||
return buffptr;
|
return buffptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete all the lines in the buffer and the buffer itself
|
* Delete all the lines in the buffer and the buffer itself
|
||||||
*/
|
*/
|
||||||
void delete_buffer (struct buffer_s *buffptr)
|
void delete_buffer(struct buffer_s *buffptr)
|
||||||
{
|
{
|
||||||
struct bufline_s *next;
|
struct bufline_s *next;
|
||||||
|
|
||||||
assert (buffptr != NULL);
|
assert(buffptr != NULL);
|
||||||
|
|
||||||
while (BUFFER_HEAD (buffptr)) {
|
while (BUFFER_HEAD(buffptr)) {
|
||||||
next = BUFFER_HEAD (buffptr)->next;
|
next = BUFFER_HEAD(buffptr)->next;
|
||||||
free_line (BUFFER_HEAD (buffptr));
|
free_line(BUFFER_HEAD(buffptr));
|
||||||
BUFFER_HEAD (buffptr) = next;
|
BUFFER_HEAD(buffptr) = next;
|
||||||
}
|
}
|
||||||
|
BUFFER_HEAD(buffptr) = NULL;
|
||||||
|
BUFFER_TAIL(buffptr) = NULL;
|
||||||
|
|
||||||
safefree (buffptr);
|
safefree(buffptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current size of the buffer.
|
* Push a new line on to the end of the buffer
|
||||||
*/
|
*/
|
||||||
size_t buffer_size (struct buffer_s *buffptr)
|
static int add_to_buffer(struct buffer_s *buffptr, unsigned char *data,
|
||||||
|
size_t length)
|
||||||
{
|
{
|
||||||
return buffptr->size;
|
struct bufline_s *newline;
|
||||||
|
|
||||||
|
assert(buffptr != NULL);
|
||||||
|
assert(data != NULL);
|
||||||
|
|
||||||
|
if (!(newline = makenewline(data, length)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr))
|
||||||
|
BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = newline;
|
||||||
|
else
|
||||||
|
BUFFER_TAIL(buffptr) = (BUFFER_TAIL(buffptr)->next = newline);
|
||||||
|
|
||||||
|
buffptr->size += length;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Push a new line on to the end of the buffer.
|
* Shift a line off the top of the buffer (remove the line from the top of
|
||||||
|
* the buffer)
|
||||||
*/
|
*/
|
||||||
int add_to_buffer (struct buffer_s *buffptr, unsigned char *data, size_t length)
|
static struct bufline_s *remove_from_buffer(struct buffer_s *buffptr)
|
||||||
{
|
{
|
||||||
struct bufline_s *newline;
|
struct bufline_s *line;
|
||||||
|
|
||||||
assert (buffptr != NULL);
|
assert(buffptr != NULL);
|
||||||
assert (data != NULL);
|
|
||||||
assert (length > 0);
|
|
||||||
|
|
||||||
/*
|
if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr)) {
|
||||||
* Sanity check here. A buffer with a non-NULL head pointer must
|
line = BUFFER_HEAD(buffptr);
|
||||||
* have a size greater than zero, and vice-versa.
|
BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = NULL;
|
||||||
*/
|
buffptr->size = 0;
|
||||||
if (BUFFER_HEAD (buffptr) == NULL)
|
return line;
|
||||||
assert (buffptr->size == 0);
|
}
|
||||||
else
|
|
||||||
assert (buffptr->size > 0);
|
|
||||||
|
|
||||||
/*
|
line = BUFFER_HEAD(buffptr);
|
||||||
* Make a new line so we can add it to the buffer.
|
BUFFER_HEAD(buffptr) = line->next;
|
||||||
*/
|
|
||||||
if (!(newline = makenewline (data, length)))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (buffptr->size == 0)
|
if (!BUFFER_HEAD(buffptr))
|
||||||
BUFFER_HEAD (buffptr) = BUFFER_TAIL (buffptr) = newline;
|
BUFFER_TAIL(buffptr) = NULL;
|
||||||
else {
|
|
||||||
BUFFER_TAIL (buffptr)->next = newline;
|
|
||||||
BUFFER_TAIL (buffptr) = newline;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffptr->size += length;
|
buffptr->size -= line->length;
|
||||||
|
|
||||||
return 0;
|
return line;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove the first line from the top of the buffer
|
|
||||||
*/
|
|
||||||
static struct bufline_s *remove_from_buffer (struct buffer_s *buffptr)
|
|
||||||
{
|
|
||||||
struct bufline_s *line;
|
|
||||||
|
|
||||||
assert (buffptr != NULL);
|
|
||||||
assert (BUFFER_HEAD (buffptr) != NULL);
|
|
||||||
|
|
||||||
line = BUFFER_HEAD (buffptr);
|
|
||||||
BUFFER_HEAD (buffptr) = line->next;
|
|
||||||
|
|
||||||
buffptr->size -= line->length;
|
|
||||||
|
|
||||||
return line;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads the bytes from the socket, and adds them to the buffer.
|
* Reads the bytes from the socket, and adds them to the buffer.
|
||||||
* Takes a connection and returns the number of bytes read.
|
* Takes a connection and returns the number of bytes read.
|
||||||
*/
|
*/
|
||||||
#define READ_BUFFER_SIZE (1024 * 2)
|
ssize_t readbuff(int fd, struct buffer_s *buffptr)
|
||||||
ssize_t read_buffer (int fd, struct buffer_s * buffptr)
|
|
||||||
{
|
{
|
||||||
ssize_t bytesin;
|
ssize_t bytesin;
|
||||||
unsigned char *buffer;
|
unsigned char inbuf[MAXBUFFSIZE];
|
||||||
|
unsigned char *buffer;
|
||||||
|
|
||||||
assert (fd >= 0);
|
assert(fd >= 0);
|
||||||
assert (buffptr != NULL);
|
assert(buffptr != NULL);
|
||||||
|
|
||||||
/*
|
if (buffer_size(buffptr) >= MAXBUFFSIZE)
|
||||||
* Don't allow the buffer to grow larger than MAXBUFFSIZE
|
return 0;
|
||||||
*/
|
|
||||||
if (buffptr->size >= MAXBUFFSIZE)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
buffer = (unsigned char *) safemalloc (READ_BUFFER_SIZE);
|
bytesin = read(fd, inbuf, MAXBUFFSIZE - buffer_size(buffptr));
|
||||||
if (!buffer) {
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
bytesin = read (fd, buffer, READ_BUFFER_SIZE);
|
if (bytesin > 0) {
|
||||||
|
if (!(buffer = malloc(bytesin))) {
|
||||||
|
log_message(LOG_CRIT, "Could not allocate memory in readbuff() [%s:%d]", __FILE__, __LINE__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (bytesin > 0) {
|
memcpy(buffer, inbuf, bytesin);
|
||||||
if (add_to_buffer (buffptr, buffer, bytesin) < 0) {
|
if (add_to_buffer(buffptr, buffer, bytesin) < 0) {
|
||||||
log_message (LOG_ERR,
|
return -1;
|
||||||
"readbuff: add_to_buffer() error.");
|
}
|
||||||
bytesin = -1;
|
|
||||||
}
|
return bytesin;
|
||||||
} else {
|
} else if (bytesin == 0) {
|
||||||
if (bytesin == 0) {
|
/* connection was closed by client */
|
||||||
/* connection was closed by client */
|
return -1;
|
||||||
bytesin = -1;
|
} else {
|
||||||
} else {
|
switch (errno) {
|
||||||
switch (errno) {
|
|
||||||
#ifdef EWOULDBLOCK
|
#ifdef EWOULDBLOCK
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
#else
|
#else
|
||||||
# ifdef EAGAIN
|
# ifdef EAGAIN
|
||||||
case EAGAIN:
|
case EAGAIN:
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
case EINTR:
|
case EINTR:
|
||||||
bytesin = 0;
|
return 0;
|
||||||
break;
|
default:
|
||||||
default:
|
log_message(LOG_ERR, "readbuff: recv (%s)", strerror(errno));
|
||||||
log_message (LOG_ERR,
|
return -1;
|
||||||
"readbuff: recv() error \"%s\" on file descriptor %d",
|
}
|
||||||
strerror (errno), fd);
|
}
|
||||||
bytesin = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (buffer);
|
|
||||||
return bytesin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the bytes in the buffer to the socket.
|
* Write the bytes in the buffer to the socket.
|
||||||
* Takes a connection and returns the number of bytes written.
|
* Takes a connection and returns the number of bytes written.
|
||||||
*/
|
*/
|
||||||
ssize_t write_buffer (int fd, struct buffer_s * buffptr)
|
ssize_t writebuff(int fd, struct buffer_s *buffptr)
|
||||||
{
|
{
|
||||||
ssize_t bytessent;
|
ssize_t bytessent;
|
||||||
struct bufline_s *line;
|
struct bufline_s *line;
|
||||||
|
|
||||||
assert (fd >= 0);
|
assert(fd >= 0);
|
||||||
assert (buffptr != NULL);
|
assert(buffptr != NULL);
|
||||||
|
|
||||||
if (buffptr->size == 0)
|
line = BUFFER_HEAD(buffptr);
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Sanity check. It would be bad to be using a NULL pointer! */
|
if (buffer_size(buffptr) <= 0)
|
||||||
assert (BUFFER_HEAD (buffptr) != NULL);
|
return 0;
|
||||||
line = BUFFER_HEAD (buffptr);
|
|
||||||
|
|
||||||
bytessent =
|
bytessent = write(fd, line->string + line->pos, line->length - line->pos);
|
||||||
send (fd, line->string + line->pos, line->length - line->pos,
|
|
||||||
MSG_NOSIGNAL);
|
|
||||||
|
|
||||||
if (bytessent >= 0) {
|
if (bytessent >= 0) {
|
||||||
/* bytes sent, adjust buffer */
|
/* bytes sent, adjust buffer */
|
||||||
line->pos += bytessent;
|
line->pos += bytessent;
|
||||||
if (line->pos == line->length)
|
if (line->pos == line->length)
|
||||||
free_line (remove_from_buffer (buffptr));
|
free_line(remove_from_buffer(buffptr));
|
||||||
return bytessent;
|
return bytessent;
|
||||||
} else {
|
} else {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
#ifdef EWOULDBLOCK
|
#ifdef EWOULDBLOCK
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
#else
|
#else
|
||||||
# ifdef EAGAIN
|
# ifdef EAGAIN
|
||||||
case EAGAIN:
|
case EAGAIN:
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
case EINTR:
|
case EINTR:
|
||||||
return 0;
|
return 0;
|
||||||
case ENOBUFS:
|
case ENOBUFS:
|
||||||
case ENOMEM:
|
case ENOMEM:
|
||||||
log_message (LOG_ERR,
|
log_message(LOG_ERR, "writebuff: send [NOBUFS/NOMEM] %s", strerror(errno));
|
||||||
"writebuff: write() error [NOBUFS/NOMEM] \"%s\" on "
|
return 0;
|
||||||
"file descriptor %d", strerror (errno),
|
default:
|
||||||
fd);
|
log_message(LOG_ERR, "writebuff: send (%s)", strerror(errno));
|
||||||
return 0;
|
return -1;
|
||||||
default:
|
}
|
||||||
log_message (LOG_ERR,
|
}
|
||||||
"writebuff: write() error \"%s\" on file descriptor %d",
|
|
||||||
strerror (errno), fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+18
-30
@@ -1,40 +1,28 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: buffer.h,v 1.4 2001-05-27 02:23:08 rjkaes Exp $
|
||||||
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* See 'buffer.c' for a detailed description.
|
||||||
* 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,
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'buffer.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef _TINYPROXY_BUFFER_H_
|
#ifndef _TINYPROXY_BUFFER_H_
|
||||||
#define _TINYPROXY_BUFFER_H_
|
#define _TINYPROXY_BUFFER_H_
|
||||||
|
|
||||||
/* Forward declaration */
|
extern struct buffer_s *new_buffer(void);
|
||||||
struct buffer_s;
|
extern void delete_buffer(struct buffer_s *buffptr);
|
||||||
|
extern size_t buffer_size(struct buffer_s *buffptr);
|
||||||
|
|
||||||
extern struct buffer_s *new_buffer (void);
|
extern ssize_t readbuff(int fd, struct buffer_s *buffptr);
|
||||||
extern void delete_buffer (struct buffer_s *buffptr);
|
extern ssize_t writebuff(int fd, struct buffer_s *buffptr);
|
||||||
extern size_t buffer_size (struct buffer_s *buffptr);
|
|
||||||
|
|
||||||
/*
|
#endif /* __BUFFER_H_ */
|
||||||
* Add a new line to the given buffer. The data IS copied into the structure.
|
|
||||||
*/
|
|
||||||
extern int add_to_buffer (struct buffer_s *buffptr, unsigned char *data,
|
|
||||||
size_t length);
|
|
||||||
|
|
||||||
extern ssize_t read_buffer (int fd, struct buffer_s *buffptr);
|
|
||||||
extern ssize_t write_buffer (int fd, struct buffer_s *buffptr);
|
|
||||||
|
|
||||||
#endif /* __BUFFER_H_ */
|
|
||||||
-476
@@ -1,476 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Handles the creation/destruction of the various children required for
|
|
||||||
* processing incoming connections.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "child.h"
|
|
||||||
#include "daemon.h"
|
|
||||||
#include "filter.h"
|
|
||||||
#include "heap.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "reqs.h"
|
|
||||||
#include "sock.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
static int listenfd;
|
|
||||||
static socklen_t addrlen;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Stores the internal data needed for each child (connection)
|
|
||||||
*/
|
|
||||||
enum child_status_t { T_EMPTY, T_WAITING, T_CONNECTED };
|
|
||||||
struct child_s {
|
|
||||||
pid_t tid;
|
|
||||||
unsigned int connects;
|
|
||||||
enum child_status_t status;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A pointer to an array of children. A certain number of children are
|
|
||||||
* created when the program is started.
|
|
||||||
*/
|
|
||||||
static struct child_s *child_ptr;
|
|
||||||
|
|
||||||
static struct child_config_s {
|
|
||||||
unsigned int maxclients, maxrequestsperchild;
|
|
||||||
unsigned int maxspareservers, minspareservers, startservers;
|
|
||||||
} child_config;
|
|
||||||
|
|
||||||
static unsigned int *servers_waiting; /* servers waiting for a connection */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Lock/Unlock the "servers_waiting" variable so that two children cannot
|
|
||||||
* modify it at the same time.
|
|
||||||
*/
|
|
||||||
#define SERVER_COUNT_LOCK() _child_lock_wait()
|
|
||||||
#define SERVER_COUNT_UNLOCK() _child_lock_release()
|
|
||||||
|
|
||||||
/* START OF LOCKING SECTION */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These variables are required for the locking mechanism. Also included
|
|
||||||
* are the "private" functions for locking/unlocking.
|
|
||||||
*/
|
|
||||||
static struct flock lock_it, unlock_it;
|
|
||||||
static int lock_fd = -1;
|
|
||||||
|
|
||||||
static void _child_lock_init (void)
|
|
||||||
{
|
|
||||||
char lock_file[] = "/tmp/tinyproxy.servers.lock.XXXXXX";
|
|
||||||
|
|
||||||
/* Only allow u+rw bits. This may be required for some versions
|
|
||||||
* of glibc so that mkstemp() doesn't make us vulnerable.
|
|
||||||
*/
|
|
||||||
umask (0177);
|
|
||||||
|
|
||||||
lock_fd = mkstemp (lock_file);
|
|
||||||
unlink (lock_file);
|
|
||||||
|
|
||||||
lock_it.l_type = F_WRLCK;
|
|
||||||
lock_it.l_whence = SEEK_SET;
|
|
||||||
lock_it.l_start = 0;
|
|
||||||
lock_it.l_len = 0;
|
|
||||||
|
|
||||||
unlock_it.l_type = F_UNLCK;
|
|
||||||
unlock_it.l_whence = SEEK_SET;
|
|
||||||
unlock_it.l_start = 0;
|
|
||||||
unlock_it.l_len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _child_lock_wait (void)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
while ((rc = fcntl (lock_fd, F_SETLKW, &lock_it)) < 0) {
|
|
||||||
if (errno == EINTR)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _child_lock_release (void)
|
|
||||||
{
|
|
||||||
if (fcntl (lock_fd, F_SETLKW, &unlock_it) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* END OF LOCKING SECTION */
|
|
||||||
|
|
||||||
#define SERVER_INC() do { \
|
|
||||||
SERVER_COUNT_LOCK(); \
|
|
||||||
++(*servers_waiting); \
|
|
||||||
DEBUG2("INC: servers_waiting: %d", *servers_waiting); \
|
|
||||||
SERVER_COUNT_UNLOCK(); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define SERVER_DEC() do { \
|
|
||||||
SERVER_COUNT_LOCK(); \
|
|
||||||
assert(*servers_waiting > 0); \
|
|
||||||
--(*servers_waiting); \
|
|
||||||
DEBUG2("DEC: servers_waiting: %d", *servers_waiting); \
|
|
||||||
SERVER_COUNT_UNLOCK(); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the configuration values for the various child related settings.
|
|
||||||
*/
|
|
||||||
short int child_configure (child_config_t type, unsigned int val)
|
|
||||||
{
|
|
||||||
switch (type) {
|
|
||||||
case CHILD_MAXCLIENTS:
|
|
||||||
child_config.maxclients = val;
|
|
||||||
break;
|
|
||||||
case CHILD_MAXSPARESERVERS:
|
|
||||||
child_config.maxspareservers = val;
|
|
||||||
break;
|
|
||||||
case CHILD_MINSPARESERVERS:
|
|
||||||
child_config.minspareservers = val;
|
|
||||||
break;
|
|
||||||
case CHILD_STARTSERVERS:
|
|
||||||
child_config.startservers = val;
|
|
||||||
break;
|
|
||||||
case CHILD_MAXREQUESTSPERCHILD:
|
|
||||||
child_config.maxrequestsperchild = val;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DEBUG2 ("Invalid type (%d)", type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
static void child_main (struct child_s *ptr)
|
|
||||||
{
|
|
||||||
int connfd;
|
|
||||||
struct sockaddr *cliaddr;
|
|
||||||
socklen_t clilen;
|
|
||||||
|
|
||||||
cliaddr = (struct sockaddr *) safemalloc (addrlen);
|
|
||||||
if (!cliaddr) {
|
|
||||||
log_message (LOG_CRIT,
|
|
||||||
"Could not allocate memory for child address.");
|
|
||||||
exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr->connects = 0;
|
|
||||||
|
|
||||||
while (!config.quit) {
|
|
||||||
ptr->status = T_WAITING;
|
|
||||||
|
|
||||||
clilen = addrlen;
|
|
||||||
|
|
||||||
connfd = accept (listenfd, cliaddr, &clilen);
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
/*
|
|
||||||
* Enable the TINYPROXY_DEBUG environment variable if you
|
|
||||||
* want to use the GDB debugger.
|
|
||||||
*/
|
|
||||||
if (getenv ("TINYPROXY_DEBUG")) {
|
|
||||||
/* Pause for 10 seconds to allow us to connect debugger */
|
|
||||||
fprintf (stderr,
|
|
||||||
"Process has accepted connection: %ld\n",
|
|
||||||
(long int) ptr->tid);
|
|
||||||
sleep (10);
|
|
||||||
fprintf (stderr, "Continuing process: %ld\n",
|
|
||||||
(long int) ptr->tid);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Make sure no error occurred...
|
|
||||||
*/
|
|
||||||
if (connfd < 0) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Accept returned an error (%s) ... retrying.",
|
|
||||||
strerror (errno));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr->status = T_CONNECTED;
|
|
||||||
|
|
||||||
SERVER_DEC ();
|
|
||||||
|
|
||||||
handle_connection (connfd);
|
|
||||||
ptr->connects++;
|
|
||||||
|
|
||||||
if (child_config.maxrequestsperchild != 0) {
|
|
||||||
DEBUG2 ("%u connections so far...", ptr->connects);
|
|
||||||
|
|
||||||
if (ptr->connects == child_config.maxrequestsperchild) {
|
|
||||||
log_message (LOG_NOTICE,
|
|
||||||
"Child has reached MaxRequestsPerChild (%u). "
|
|
||||||
"Killing child.", ptr->connects);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SERVER_COUNT_LOCK ();
|
|
||||||
if (*servers_waiting > child_config.maxspareservers) {
|
|
||||||
/*
|
|
||||||
* There are too many spare children, kill ourself
|
|
||||||
* off.
|
|
||||||
*/
|
|
||||||
log_message (LOG_NOTICE,
|
|
||||||
"Waiting servers (%d) exceeds MaxSpareServers (%d). "
|
|
||||||
"Killing child.",
|
|
||||||
*servers_waiting,
|
|
||||||
child_config.maxspareservers);
|
|
||||||
SERVER_COUNT_UNLOCK ();
|
|
||||||
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
SERVER_COUNT_UNLOCK ();
|
|
||||||
}
|
|
||||||
|
|
||||||
SERVER_INC ();
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr->status = T_EMPTY;
|
|
||||||
|
|
||||||
safefree (cliaddr);
|
|
||||||
exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Fork a child "child" (or in our case a process) and then start up the
|
|
||||||
* child_main() function.
|
|
||||||
*/
|
|
||||||
static pid_t child_make (struct child_s *ptr)
|
|
||||||
{
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
if ((pid = fork ()) > 0)
|
|
||||||
return pid; /* parent */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reset the SIGNALS so that the child can be reaped.
|
|
||||||
*/
|
|
||||||
set_signal_handler (SIGCHLD, SIG_DFL);
|
|
||||||
set_signal_handler (SIGTERM, SIG_DFL);
|
|
||||||
set_signal_handler (SIGHUP, child_sighup_handler);
|
|
||||||
|
|
||||||
child_main (ptr); /* never returns */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a pool of children to handle incoming connections
|
|
||||||
*/
|
|
||||||
short int child_pool_create (void)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Make sure the number of MaxClients is not zero, since this
|
|
||||||
* variable determines the size of the array created for children
|
|
||||||
* later on.
|
|
||||||
*/
|
|
||||||
if (child_config.maxclients == 0) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"child_pool_create: \"MaxClients\" must be "
|
|
||||||
"greater than zero.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (child_config.startservers == 0) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"child_pool_create: \"StartServers\" must be "
|
|
||||||
"greater than zero.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
child_ptr =
|
|
||||||
(struct child_s *) calloc_shared_memory (child_config.maxclients,
|
|
||||||
sizeof (struct child_s));
|
|
||||||
if (!child_ptr) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Could not allocate memory for children.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
servers_waiting =
|
|
||||||
(unsigned int *) malloc_shared_memory (sizeof (unsigned int));
|
|
||||||
if (servers_waiting == MAP_FAILED) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Could not allocate memory for child counting.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*servers_waiting = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a "locking" file for use around the servers_waiting
|
|
||||||
* variable.
|
|
||||||
*/
|
|
||||||
_child_lock_init ();
|
|
||||||
|
|
||||||
if (child_config.startservers > child_config.maxclients) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Can not start more than \"MaxClients\" servers. "
|
|
||||||
"Starting %u servers instead.",
|
|
||||||
child_config.maxclients);
|
|
||||||
child_config.startservers = child_config.maxclients;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i != child_config.maxclients; i++) {
|
|
||||||
child_ptr[i].status = T_EMPTY;
|
|
||||||
child_ptr[i].connects = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i != child_config.startservers; i++) {
|
|
||||||
DEBUG2 ("Trying to create child %d of %d", i + 1,
|
|
||||||
child_config.startservers);
|
|
||||||
child_ptr[i].status = T_WAITING;
|
|
||||||
child_ptr[i].tid = child_make (&child_ptr[i]);
|
|
||||||
|
|
||||||
if (child_ptr[i].tid < 0) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Could not create child number %d of %d",
|
|
||||||
i, child_config.startservers);
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
log_message (LOG_INFO,
|
|
||||||
"Creating child number %d of %d ...",
|
|
||||||
i + 1, child_config.startservers);
|
|
||||||
|
|
||||||
SERVER_INC ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message (LOG_INFO, "Finished creating all children.");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Keep the proper number of servers running. This is the birth of the
|
|
||||||
* servers. It monitors this at least once a second.
|
|
||||||
*/
|
|
||||||
void child_main_loop (void)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (config.quit)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* If there are not enough spare servers, create more */
|
|
||||||
SERVER_COUNT_LOCK ();
|
|
||||||
if (*servers_waiting < child_config.minspareservers) {
|
|
||||||
log_message (LOG_NOTICE,
|
|
||||||
"Waiting servers (%d) is less than MinSpareServers (%d). "
|
|
||||||
"Creating new child.",
|
|
||||||
*servers_waiting,
|
|
||||||
child_config.minspareservers);
|
|
||||||
|
|
||||||
SERVER_COUNT_UNLOCK ();
|
|
||||||
|
|
||||||
for (i = 0; i != child_config.maxclients; i++) {
|
|
||||||
if (child_ptr[i].status == T_EMPTY) {
|
|
||||||
child_ptr[i].status = T_WAITING;
|
|
||||||
child_ptr[i].tid =
|
|
||||||
child_make (&child_ptr[i]);
|
|
||||||
if (child_ptr[i].tid < 0) {
|
|
||||||
log_message (LOG_NOTICE,
|
|
||||||
"Could not create child");
|
|
||||||
|
|
||||||
child_ptr[i].status = T_EMPTY;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
SERVER_INC ();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SERVER_COUNT_UNLOCK ();
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep (5);
|
|
||||||
|
|
||||||
/* Handle log rotation if it was requested */
|
|
||||||
if (received_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 */
|
|
||||||
|
|
||||||
/* propagate filter reload to all children */
|
|
||||||
child_kill_children (SIGHUP);
|
|
||||||
|
|
||||||
received_sighup = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Go through all the non-empty children and cancel them.
|
|
||||||
*/
|
|
||||||
void child_kill_children (int sig)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
for (i = 0; i != child_config.maxclients; i++) {
|
|
||||||
if (child_ptr[i].status != T_EMPTY)
|
|
||||||
kill (child_ptr[i].tid, sig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int child_listening_sock (uint16_t port)
|
|
||||||
{
|
|
||||||
listenfd = listen_sock (port, &addrlen);
|
|
||||||
return listenfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void child_close_sock (void)
|
|
||||||
{
|
|
||||||
close (listenfd);
|
|
||||||
}
|
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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 'child.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_CHILD_H
|
|
||||||
#define TINYPROXY_CHILD_H
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
CHILD_MAXCLIENTS,
|
|
||||||
CHILD_MAXSPARESERVERS,
|
|
||||||
CHILD_MINSPARESERVERS,
|
|
||||||
CHILD_STARTSERVERS,
|
|
||||||
CHILD_MAXREQUESTSPERCHILD
|
|
||||||
} child_config_t;
|
|
||||||
|
|
||||||
extern short int child_pool_create (void);
|
|
||||||
extern int child_listening_sock (uint16_t port);
|
|
||||||
extern void child_close_sock (void);
|
|
||||||
extern void child_main_loop (void);
|
|
||||||
extern void child_kill_children (int sig);
|
|
||||||
|
|
||||||
extern short int child_configure (child_config_t type, unsigned int val);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-200
@@ -1,200 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This file groups all the headers required throughout the tinyproxy
|
|
||||||
* system. All this information use to be in the "main.h" header,
|
|
||||||
* but various other "libraries" in the program need the same information,
|
|
||||||
* without the tinyproxy specific defines.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef COMMON_HEADER_H
|
|
||||||
#define COMMON_HEADER_H
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Include standard headers which are used through-out tinyproxy
|
|
||||||
*/
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
|
||||||
# include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_VALUES_H
|
|
||||||
# include <values.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_INTTYPES_H
|
|
||||||
# include <inttypes.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDDEF_H
|
|
||||||
# include <stddef.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDINT_H
|
|
||||||
# include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_IOCTL_H
|
|
||||||
# include <sys/ioctl.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SELECT_H
|
|
||||||
# include <sys/select.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
|
||||||
# include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
# include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TIME_WITH_SYS_TIME
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <time.h>
|
|
||||||
#else
|
|
||||||
# ifdef HAVE_SYS_TIME_H
|
|
||||||
# include <sys/time.h>
|
|
||||||
# else
|
|
||||||
# include <time.h>
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
# include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_UIO_H
|
|
||||||
# include <sys/uio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_UN_H
|
|
||||||
# include <sys/un.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_WAIT_H
|
|
||||||
# include <sys/wait.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_NETINET_IN_H
|
|
||||||
# include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ARPA_INET_H
|
|
||||||
# include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ALLOCA_H
|
|
||||||
# include <alloca.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ASSERT_H
|
|
||||||
# include <assert.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_CTYPE_H
|
|
||||||
# include <ctype.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ERRNO_H
|
|
||||||
# include <errno.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_FCNTL_H
|
|
||||||
# include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_GRP_H
|
|
||||||
# include <grp.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_MEMORY_H
|
|
||||||
# include <memory.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_NETDB_H
|
|
||||||
# include <netdb.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_PWD_H
|
|
||||||
# include <pwd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_REGEX_H
|
|
||||||
# include <regex.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SIGNAL_H
|
|
||||||
# include <signal.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDARG_H
|
|
||||||
# include <stdarg.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDIO_H
|
|
||||||
# include <stdio.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STDLIB_H
|
|
||||||
# include <stdlib.h>
|
|
||||||
#else
|
|
||||||
# ifdef HAVE_MALLOC_H
|
|
||||||
# include <malloc.h>
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STRING_H
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STRINGS_H
|
|
||||||
# include <strings.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYSEXITS_H
|
|
||||||
# include <sysexits.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
# include <syslog.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_WCHAR_H
|
|
||||||
# include <wchar.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_WCTYPE_H
|
|
||||||
# include <wctype.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_MMAN_H
|
|
||||||
# include <sys/mman.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If MSG_NOSIGNAL is not defined, define it to be zero so that it doesn't
|
|
||||||
* cause any problems.
|
|
||||||
*/
|
|
||||||
#ifndef MSG_NOSIGNAL
|
|
||||||
# define MSG_NOSIGNAL (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef SHUT_RD /* these three Posix.1g names are quite new */
|
|
||||||
# define SHUT_RD 0 /* shutdown for reading */
|
|
||||||
# define SHUT_WR 1 /* shutdown for writing */
|
|
||||||
# define SHUT_RDWR 2 /* shutdown for reading and writing */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAXLISTEN 1024 /* Max number of connections */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SunOS doesn't have INADDR_NONE defined.
|
|
||||||
*/
|
|
||||||
#ifndef INADDR_NONE
|
|
||||||
# define INADDR_NONE -1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define boolean values */
|
|
||||||
#ifndef FALSE
|
|
||||||
# define FALSE 0
|
|
||||||
# define TRUE (!FALSE)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Useful function macros */
|
|
||||||
#if !defined(min) || !defined(max)
|
|
||||||
# define min(a,b) ((a) < (b) ? (a) : (b))
|
|
||||||
# define max(a,b) ((a) > (b) ? (a) : (b))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-1085
File diff suppressed because it is too large.
Load diff
-120
@@ -1,120 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* See 'conf.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_CONF_H
|
|
||||||
#define TINYPROXY_CONF_H
|
|
||||||
|
|
||||||
#include "hashmap.h"
|
|
||||||
#include "vector.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Stores a HTTP header created using the AddHeader directive.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
char *name;
|
|
||||||
char *value;
|
|
||||||
} http_header_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hold all the configuration time information.
|
|
||||||
*/
|
|
||||||
struct config_s {
|
|
||||||
char *logf_name;
|
|
||||||
char *config_file;
|
|
||||||
unsigned int syslog; /* boolean */
|
|
||||||
unsigned int port;
|
|
||||||
char *stathost;
|
|
||||||
unsigned int godaemon; /* boolean */
|
|
||||||
unsigned int quit; /* boolean */
|
|
||||||
char *user;
|
|
||||||
char *group;
|
|
||||||
char *ipAddr;
|
|
||||||
#ifdef FILTER_ENABLE
|
|
||||||
char *filter;
|
|
||||||
unsigned int filter_url; /* boolean */
|
|
||||||
unsigned int filter_extended; /* boolean */
|
|
||||||
unsigned int filter_casesensitive; /* boolean */
|
|
||||||
#endif /* FILTER_ENABLE */
|
|
||||||
#ifdef XTINYPROXY_ENABLE
|
|
||||||
unsigned int add_xtinyproxy; /* boolean */
|
|
||||||
#endif
|
|
||||||
#ifdef REVERSE_SUPPORT
|
|
||||||
struct reversepath *reversepath_list;
|
|
||||||
unsigned int reverseonly; /* boolean */
|
|
||||||
unsigned int reversemagic; /* boolean */
|
|
||||||
char *reversebaseurl;
|
|
||||||
#endif
|
|
||||||
#ifdef UPSTREAM_SUPPORT
|
|
||||||
struct upstream *upstream_list;
|
|
||||||
#endif /* UPSTREAM_SUPPORT */
|
|
||||||
char *pidpath;
|
|
||||||
unsigned int idletimeout;
|
|
||||||
char *bind_address;
|
|
||||||
unsigned int bindsame;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The configured name to use in the HTTP "Via" header field.
|
|
||||||
*/
|
|
||||||
char *via_proxy_name;
|
|
||||||
|
|
||||||
unsigned int disable_viaheader; /* boolean */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Error page support. Map error numbers to file paths.
|
|
||||||
*/
|
|
||||||
hashmap_t errorpages;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Error page to be displayed if appropriate page cannot be located
|
|
||||||
* in the errorpages structure.
|
|
||||||
*/
|
|
||||||
char *errorpage_undef;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The HTML statistics page.
|
|
||||||
*/
|
|
||||||
char *statpage;
|
|
||||||
|
|
||||||
vector_t access_list;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Store the list of port allowed by CONNECT.
|
|
||||||
*/
|
|
||||||
vector_t connect_ports;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Map of headers which should be let through when the
|
|
||||||
* anonymous feature is turned on.
|
|
||||||
*/
|
|
||||||
hashmap_t anonymous_map;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Extra headers to be added to outgoing HTTP requests.
|
|
||||||
*/
|
|
||||||
vector_t add_headers;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern int reload_config_file (const char *config_fname, struct config_s *conf,
|
|
||||||
struct config_s *defaults);
|
|
||||||
|
|
||||||
int config_compile_regex (void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
|
||||||
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
* Copyright (C) 2009 Michael Adam <obnox@samba.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "connect-ports.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now, this routine adds a "port" to the list. It also creates the list if
|
|
||||||
* it hasn't already by done.
|
|
||||||
*/
|
|
||||||
void add_connect_port_allowed (int port, vector_t *connect_ports)
|
|
||||||
{
|
|
||||||
if (!*connect_ports) {
|
|
||||||
*connect_ports = vector_create ();
|
|
||||||
if (!*connect_ports) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Could not create a list of allowed CONNECT ports");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message (LOG_INFO,
|
|
||||||
"Adding Port [%d] to the list allowed by CONNECT", port);
|
|
||||||
vector_append (*connect_ports, (void **) &port, sizeof (port));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This routine checks to see if a port is allowed in the CONNECT method.
|
|
||||||
*
|
|
||||||
* Returns: 1 if allowed
|
|
||||||
* 0 if denied
|
|
||||||
*/
|
|
||||||
int check_allowed_connect_ports (int port, vector_t connect_ports)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int *data;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The absence of ConnectPort options in the config file
|
|
||||||
* meanas that all ports are allowed for CONNECT.
|
|
||||||
*/
|
|
||||||
if (!connect_ports)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
for (i = 0; i != (size_t) vector_length (connect_ports); ++i) {
|
|
||||||
data = (int *) vector_getentry (connect_ports, i, NULL);
|
|
||||||
if (data && *data == port)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free a connect_ports list.
|
|
||||||
*/
|
|
||||||
void free_connect_ports_list (vector_t connect_ports)
|
|
||||||
{
|
|
||||||
vector_delete (connect_ports);
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
/* 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_ */
|
|
||||||
-148
@@ -1,148 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Create and free the connection structure. One day there could be
|
|
||||||
* other connection related tasks put here, but for now the header
|
|
||||||
* file and this file are only used for create/free functions and the
|
|
||||||
* connection structure definition.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "buffer.h"
|
|
||||||
#include "conns.h"
|
|
||||||
#include "heap.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "stats.h"
|
|
||||||
|
|
||||||
struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
|
|
||||||
const char *string_addr,
|
|
||||||
const char *sock_ipaddr)
|
|
||||||
{
|
|
||||||
struct conn_s *connptr;
|
|
||||||
struct buffer_s *cbuffer, *sbuffer;
|
|
||||||
|
|
||||||
assert (client_fd >= 0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate the memory for all the internal components
|
|
||||||
*/
|
|
||||||
cbuffer = new_buffer ();
|
|
||||||
sbuffer = new_buffer ();
|
|
||||||
|
|
||||||
if (!cbuffer || !sbuffer)
|
|
||||||
goto error_exit;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate the space for the conn_s structure itself.
|
|
||||||
*/
|
|
||||||
connptr = (struct conn_s *) safemalloc (sizeof (struct conn_s));
|
|
||||||
if (!connptr)
|
|
||||||
goto error_exit;
|
|
||||||
|
|
||||||
connptr->client_fd = client_fd;
|
|
||||||
connptr->server_fd = -1;
|
|
||||||
|
|
||||||
connptr->cbuffer = cbuffer;
|
|
||||||
connptr->sbuffer = sbuffer;
|
|
||||||
|
|
||||||
connptr->request_line = NULL;
|
|
||||||
|
|
||||||
/* These store any error strings */
|
|
||||||
connptr->error_variables = NULL;
|
|
||||||
connptr->error_string = NULL;
|
|
||||||
connptr->error_number = -1;
|
|
||||||
|
|
||||||
connptr->connect_method = FALSE;
|
|
||||||
connptr->show_stats = FALSE;
|
|
||||||
|
|
||||||
connptr->protocol.major = connptr->protocol.minor = 0;
|
|
||||||
|
|
||||||
/* There is _no_ content length initially */
|
|
||||||
connptr->content_length.server = connptr->content_length.client = -1;
|
|
||||||
|
|
||||||
connptr->server_ip_addr = (sock_ipaddr ?
|
|
||||||
safestrdup (sock_ipaddr) : NULL);
|
|
||||||
connptr->client_ip_addr = safestrdup (ipaddr);
|
|
||||||
connptr->client_string_addr = safestrdup (string_addr);
|
|
||||||
|
|
||||||
connptr->upstream_proxy = NULL;
|
|
||||||
|
|
||||||
update_stats (STAT_OPEN);
|
|
||||||
|
|
||||||
#ifdef REVERSE_SUPPORT
|
|
||||||
connptr->reversepath = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return connptr;
|
|
||||||
|
|
||||||
error_exit:
|
|
||||||
/*
|
|
||||||
* If we got here, there was a problem allocating memory
|
|
||||||
*/
|
|
||||||
if (cbuffer)
|
|
||||||
delete_buffer (cbuffer);
|
|
||||||
if (sbuffer)
|
|
||||||
delete_buffer (sbuffer);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy_conn (struct conn_s *connptr)
|
|
||||||
{
|
|
||||||
assert (connptr != NULL);
|
|
||||||
|
|
||||||
if (connptr->client_fd != -1)
|
|
||||||
if (close (connptr->client_fd) < 0)
|
|
||||||
log_message (LOG_INFO, "Client (%d) close message: %s",
|
|
||||||
connptr->client_fd, strerror (errno));
|
|
||||||
if (connptr->server_fd != -1)
|
|
||||||
if (close (connptr->server_fd) < 0)
|
|
||||||
log_message (LOG_INFO, "Server (%d) close message: %s",
|
|
||||||
connptr->server_fd, strerror (errno));
|
|
||||||
|
|
||||||
if (connptr->cbuffer)
|
|
||||||
delete_buffer (connptr->cbuffer);
|
|
||||||
if (connptr->sbuffer)
|
|
||||||
delete_buffer (connptr->sbuffer);
|
|
||||||
|
|
||||||
if (connptr->request_line)
|
|
||||||
safefree (connptr->request_line);
|
|
||||||
|
|
||||||
if (connptr->error_variables)
|
|
||||||
hashmap_delete (connptr->error_variables);
|
|
||||||
|
|
||||||
if (connptr->error_string)
|
|
||||||
safefree (connptr->error_string);
|
|
||||||
|
|
||||||
if (connptr->server_ip_addr)
|
|
||||||
safefree (connptr->server_ip_addr);
|
|
||||||
if (connptr->client_ip_addr)
|
|
||||||
safefree (connptr->client_ip_addr);
|
|
||||||
if (connptr->client_string_addr)
|
|
||||||
safefree (connptr->client_string_addr);
|
|
||||||
|
|
||||||
#ifdef REVERSE_SUPPORT
|
|
||||||
if (connptr->reversepath)
|
|
||||||
safefree (connptr->reversepath);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
safefree (connptr);
|
|
||||||
|
|
||||||
update_stats (STAT_CLOSE);
|
|
||||||
}
|
|
||||||
-99
@@ -1,99 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 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 'conns.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_CONNS_H
|
|
||||||
#define TINYPROXY_CONNS_H
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "hashmap.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Connection Definition
|
|
||||||
*/
|
|
||||||
struct conn_s {
|
|
||||||
int client_fd;
|
|
||||||
int server_fd;
|
|
||||||
|
|
||||||
struct buffer_s *cbuffer;
|
|
||||||
struct buffer_s *sbuffer;
|
|
||||||
|
|
||||||
/* The request line (first line) from the client */
|
|
||||||
char *request_line;
|
|
||||||
|
|
||||||
/* Booleans */
|
|
||||||
unsigned int connect_method;
|
|
||||||
unsigned int show_stats;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure stores key -> value mappings for substitution
|
|
||||||
* in the error HTML files.
|
|
||||||
*/
|
|
||||||
hashmap_t error_variables;
|
|
||||||
|
|
||||||
int error_number;
|
|
||||||
char *error_string;
|
|
||||||
|
|
||||||
/* A Content-Length value from the remote server */
|
|
||||||
struct {
|
|
||||||
long int server;
|
|
||||||
long int client;
|
|
||||||
} content_length;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Store the server's IP (for BindSame)
|
|
||||||
*/
|
|
||||||
char *server_ip_addr;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Store the client's IP and hostname information
|
|
||||||
*/
|
|
||||||
char *client_ip_addr;
|
|
||||||
char *client_string_addr;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Store the incoming request's HTTP protocol.
|
|
||||||
*/
|
|
||||||
struct {
|
|
||||||
unsigned int major;
|
|
||||||
unsigned int minor;
|
|
||||||
} protocol;
|
|
||||||
|
|
||||||
#ifdef REVERSE_SUPPORT
|
|
||||||
/*
|
|
||||||
* Place to store the current per-connection reverse proxy path
|
|
||||||
*/
|
|
||||||
char *reversepath;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Pointer to upstream proxy.
|
|
||||||
*/
|
|
||||||
struct upstream *upstream_proxy;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Functions for the creation and destruction of a connection structure.
|
|
||||||
*/
|
|
||||||
extern struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
|
|
||||||
const char *string_addr,
|
|
||||||
const char *sock_ipaddr);
|
|
||||||
extern void destroy_conn (struct conn_s *connptr);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This file contains functions which are useful when writing a
|
|
||||||
* daemon process. The functions include a "makedaemon" function and
|
|
||||||
* a function to portably set a signal handler.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "daemon.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Fork a child process and then kill the parent so make the calling
|
|
||||||
* program a daemon process.
|
|
||||||
*/
|
|
||||||
void makedaemon (void)
|
|
||||||
{
|
|
||||||
if (fork () != 0)
|
|
||||||
exit (0);
|
|
||||||
|
|
||||||
setsid ();
|
|
||||||
set_signal_handler (SIGHUP, SIG_IGN);
|
|
||||||
|
|
||||||
if (fork () != 0)
|
|
||||||
exit (0);
|
|
||||||
|
|
||||||
if (chdir ("/") != 0) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Could not change directory to /");
|
|
||||||
}
|
|
||||||
|
|
||||||
umask (0177);
|
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
/*
|
|
||||||
* When not in debugging mode, close the standard file
|
|
||||||
* descriptors.
|
|
||||||
*/
|
|
||||||
close (0);
|
|
||||||
close (1);
|
|
||||||
close (2);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Pass a signal number and a signal handling function into this function
|
|
||||||
* to handle signals sent to the process.
|
|
||||||
*/
|
|
||||||
signal_func *set_signal_handler (int signo, signal_func * func)
|
|
||||||
{
|
|
||||||
struct sigaction act, oact;
|
|
||||||
|
|
||||||
act.sa_handler = func;
|
|
||||||
sigemptyset (&act.sa_mask);
|
|
||||||
act.sa_flags = 0;
|
|
||||||
if (signo == SIGALRM) {
|
|
||||||
#ifdef SA_INTERRUPT
|
|
||||||
act.sa_flags |= SA_INTERRUPT; /* SunOS 4.x */
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
#ifdef SA_RESTART
|
|
||||||
act.sa_flags |= SA_RESTART; /* SVR4, 4.4BSD */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sigaction (signo, &act, &oact) < 0)
|
|
||||||
return SIG_ERR;
|
|
||||||
|
|
||||||
return oact.sa_handler;
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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 'daemon.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_DAEMON_H
|
|
||||||
#define TINYPROXY_DAEMON_H
|
|
||||||
|
|
||||||
typedef void signal_func (int);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Pass a singal integer and a function to handle the signal.
|
|
||||||
*/
|
|
||||||
extern signal_func *set_signal_handler (int signo, signal_func * func);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Make a program a daemon process
|
|
||||||
*/
|
|
||||||
extern void makedaemon (void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
/* $Id: dnscache.c,v 1.9 2001-05-27 02:24:00 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* This is a caching DNS system. When a host name is needed we look it up here
|
||||||
|
* and see if there is already an answer for it. The domains are placed in a
|
||||||
|
* hashed linked list. If the name is not here, then we need to look it up and
|
||||||
|
* add it to the system. This really speeds up the connection to servers since
|
||||||
|
* the DNS name does not need to be looked up each time. It's kind of cool. :)
|
||||||
|
*
|
||||||
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
* Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "dnscache.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "ternary.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#define DNSEXPIRE (5 * 60)
|
||||||
|
|
||||||
|
struct dnscache_s {
|
||||||
|
struct in_addr ipaddr;
|
||||||
|
time_t expire;
|
||||||
|
};
|
||||||
|
|
||||||
|
static TERNARY dns_tree;
|
||||||
|
|
||||||
|
TERNARY new_dnscache(void)
|
||||||
|
{
|
||||||
|
dns_tree = ternary_new();
|
||||||
|
|
||||||
|
return dns_tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dns_lookup(struct in_addr *addr, char *domain)
|
||||||
|
{
|
||||||
|
struct dnscache_s *ptr;
|
||||||
|
|
||||||
|
assert(addr != NULL);
|
||||||
|
assert(domain != NULL);
|
||||||
|
|
||||||
|
if (TE_ISERROR(ternary_search(dns_tree, domain, (void *)&ptr)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (difftime(time(NULL), ptr->expire) > (double)DNSEXPIRE) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*addr = ptr->ipaddr;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int dns_insert(struct in_addr *addr, char *domain)
|
||||||
|
{
|
||||||
|
struct dnscache_s *newptr;
|
||||||
|
|
||||||
|
assert(addr != NULL);
|
||||||
|
assert(domain != NULL);
|
||||||
|
|
||||||
|
if (!(newptr = malloc(sizeof(struct dnscache_s)))) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
newptr->ipaddr = *addr;
|
||||||
|
newptr->expire = time(NULL);
|
||||||
|
|
||||||
|
if (TE_ISERROR(ternary_insert(dns_tree, domain, newptr)))
|
||||||
|
safefree(newptr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dnscache(struct in_addr *addr, char *domain)
|
||||||
|
{
|
||||||
|
struct hostent *resolv;
|
||||||
|
|
||||||
|
assert(addr != NULL);
|
||||||
|
assert(domain != NULL);
|
||||||
|
|
||||||
|
if (inet_aton(domain, (struct in_addr *) addr) != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Well, we're not dotted-decimal so we need to look it up */
|
||||||
|
if (dns_lookup(addr, domain) == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Okay, so not in the list... need to actually look it up. */
|
||||||
|
if (!(resolv = gethostbyname(domain)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length);
|
||||||
|
dns_insert(addr, domain);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/* $Id: dnscache.h,v 1.4 2001-05-27 02:24:00 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* See 'dnscache.c' for a detailed description.
|
||||||
|
*
|
||||||
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TINYPROXY_DNSCACHE_H_
|
||||||
|
#define _TINYPROXY_DNSCACHE_H_
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include "ternary.h"
|
||||||
|
|
||||||
|
extern TERNARY new_dnscache(void);
|
||||||
|
extern int dnscache(struct in_addr *addr, char *domain);
|
||||||
|
|
||||||
|
#endif
|
||||||
+102
-198
@@ -1,228 +1,132 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: filter.c,v 1.4 2001-05-27 02:24:40 rjkaes Exp $
|
||||||
* Copyright (C) 1999 George Talusan <gstalusan@uwaterloo.ca>
|
|
||||||
* Copyright (C) 2002 James E. Flemer <jflemer@acm.jhu.edu>
|
|
||||||
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
|
||||||
* 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,
|
* A substring of the domain to be filtered goes into the file
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* A substring of the domain to be filtered goes into the file
|
|
||||||
* pointed at by DEFAULT_FILTER.
|
* pointed at by DEFAULT_FILTER.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <sysexits.h>
|
||||||
|
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "heap.h"
|
#include "regexp.h"
|
||||||
#include "log.h"
|
#include "utils.h"
|
||||||
#include "reqs.h"
|
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
#define FILTER_BUFFER_LEN (512)
|
|
||||||
|
|
||||||
static int err;
|
static int err;
|
||||||
|
|
||||||
struct filter_list {
|
struct filter_list {
|
||||||
struct filter_list *next;
|
struct filter_list *next;
|
||||||
char *pat;
|
char *pat;
|
||||||
regex_t *cpat;
|
regex_t *cpat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct filter_list *fl = NULL;
|
static struct filter_list *fl = NULL;
|
||||||
static int already_init = 0;
|
static int already_init = 0;
|
||||||
static filter_policy_t default_policy = FILTER_DEFAULT_ALLOW;
|
|
||||||
|
|
||||||
/*
|
/* initializes a linked list of strings containing hosts to be filtered */
|
||||||
* Initializes a linked list of strings containing hosts/urls to be filtered
|
void filter_init(void)
|
||||||
*/
|
|
||||||
void filter_init (void)
|
|
||||||
{
|
{
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
struct filter_list *p;
|
struct filter_list *p;
|
||||||
char buf[FILTER_BUFFER_LEN];
|
char buf[255];
|
||||||
char *s;
|
char *s;
|
||||||
int cflags;
|
|
||||||
|
|
||||||
if (fl || already_init) {
|
if (!fl && !already_init) {
|
||||||
return;
|
fd = fopen(config.filter, "r");
|
||||||
}
|
if (fd) {
|
||||||
|
p = NULL;
|
||||||
|
|
||||||
fd = fopen (config.filter, "r");
|
while (fgets(buf, 255, fd)) {
|
||||||
if (!fd) {
|
s = buf;
|
||||||
return;
|
if (!p) /* head of list */
|
||||||
}
|
fl = p = (struct filter_list *)
|
||||||
|
malloc(sizeof
|
||||||
|
(struct filter_list));
|
||||||
|
else { /* next entry */
|
||||||
|
p->next = (struct filter_list *)
|
||||||
|
malloc(sizeof
|
||||||
|
(struct filter_list));
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
/* initialize space to zero */
|
||||||
|
memset(p, 0, sizeof(struct filter_list));
|
||||||
|
|
||||||
p = NULL;
|
/* replace first whitespace with \0 */
|
||||||
|
while (*s++)
|
||||||
|
if (isspace((unsigned char)*s))
|
||||||
|
*s = '\0';
|
||||||
|
|
||||||
cflags = REG_NEWLINE | REG_NOSUB;
|
p->pat = strdup(buf);
|
||||||
if (config.filter_extended)
|
p->cpat = malloc(sizeof(regex_t));
|
||||||
cflags |= REG_EXTENDED;
|
if ((err = regcomp(p->cpat, p->pat, REG_NEWLINE | REG_NOSUB)) != 0) {
|
||||||
if (!config.filter_casesensitive)
|
fprintf(stderr,
|
||||||
cflags |= REG_ICASE;
|
"Bad regex in %s: %s\n",
|
||||||
|
config.filter, p->pat);
|
||||||
while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
|
exit(EX_DATAERR);
|
||||||
/*
|
}
|
||||||
* Remove any trailing white space and
|
}
|
||||||
* comments.
|
already_init = 1;
|
||||||
*/
|
fclose(fd);
|
||||||
s = buf;
|
}
|
||||||
while (*s) {
|
}
|
||||||
if (isspace ((unsigned char) *s))
|
|
||||||
break;
|
|
||||||
if (*s == '#') {
|
|
||||||
/*
|
|
||||||
* If the '#' char is preceeded by
|
|
||||||
* an escape, it's not a comment
|
|
||||||
* string.
|
|
||||||
*/
|
|
||||||
if (s == buf || *(s - 1) != '\\')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
++s;
|
|
||||||
}
|
|
||||||
*s = '\0';
|
|
||||||
|
|
||||||
/* skip leading whitespace */
|
|
||||||
s = buf;
|
|
||||||
while (*s && isspace ((unsigned char) *s))
|
|
||||||
s++;
|
|
||||||
|
|
||||||
/* skip blank lines and comments */
|
|
||||||
if (*s == '\0')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!p) /* head of list */
|
|
||||||
fl = p =
|
|
||||||
(struct filter_list *)
|
|
||||||
safecalloc (1, sizeof (struct filter_list));
|
|
||||||
else { /* next entry */
|
|
||||||
p->next =
|
|
||||||
(struct filter_list *)
|
|
||||||
safecalloc (1, sizeof (struct filter_list));
|
|
||||||
p = p->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
p->pat = safestrdup (s);
|
|
||||||
p->cpat = (regex_t *) safemalloc (sizeof (regex_t));
|
|
||||||
err = regcomp (p->cpat, p->pat, cflags);
|
|
||||||
if (err != 0) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"Bad regex in %s: %s\n",
|
|
||||||
config.filter, p->pat);
|
|
||||||
exit (EX_DATAERR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ferror (fd)) {
|
|
||||||
perror ("fgets");
|
|
||||||
exit (EX_DATAERR);
|
|
||||||
}
|
|
||||||
fclose (fd);
|
|
||||||
|
|
||||||
already_init = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unlink the list */
|
/* unlink the list */
|
||||||
void filter_destroy (void)
|
void filter_destroy(void)
|
||||||
{
|
{
|
||||||
struct filter_list *p, *q;
|
struct filter_list *p, *q;
|
||||||
|
|
||||||
if (already_init) {
|
if (already_init) {
|
||||||
for (p = q = fl; p; p = q) {
|
for (p = q = fl; p; p = q) {
|
||||||
regfree (p->cpat);
|
regfree(p->cpat);
|
||||||
safefree (p->cpat);
|
safefree(p->cpat);
|
||||||
safefree (p->pat);
|
safefree(p->pat);
|
||||||
q = p->next;
|
q = p->next;
|
||||||
safefree (p);
|
safefree(p);
|
||||||
}
|
}
|
||||||
fl = NULL;
|
fl = NULL;
|
||||||
already_init = 0;
|
already_init = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* returns 0 if host is not an element of filter list, non-zero otherwise */
|
||||||
* reload the filter file if filtering is enabled
|
int filter_url(char *host)
|
||||||
*/
|
|
||||||
void filter_reload (void)
|
|
||||||
{
|
{
|
||||||
if (config.filter) {
|
struct filter_list *p;
|
||||||
log_message (LOG_NOTICE, "Re-reading filter file.");
|
char *s, *port;
|
||||||
filter_destroy ();
|
int result;
|
||||||
filter_init ();
|
|
||||||
}
|
if (!fl || !already_init)
|
||||||
}
|
return (0);
|
||||||
|
|
||||||
/* Return 0 to allow, non-zero to block */
|
/* strip off the port number */
|
||||||
int filter_domain (const char *host)
|
s = strdup(host);
|
||||||
{
|
port = strchr(s, ':');
|
||||||
struct filter_list *p;
|
if (port)
|
||||||
int result;
|
*port = '\0';
|
||||||
|
|
||||||
if (!fl || !already_init)
|
result = 0;
|
||||||
goto COMMON_EXIT;
|
|
||||||
|
for (p = fl; p; p = p->next) {
|
||||||
for (p = fl; p; p = p->next) {
|
result = !regexec(p->cpat, s, (size_t) 0, (regmatch_t *) 0, 0);
|
||||||
result =
|
|
||||||
regexec (p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0);
|
if (result)
|
||||||
|
break;
|
||||||
if (result == 0) {
|
}
|
||||||
if (default_policy == FILTER_DEFAULT_ALLOW)
|
safefree(s);
|
||||||
return 1;
|
return (result);
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
COMMON_EXIT:
|
|
||||||
if (default_policy == FILTER_DEFAULT_ALLOW)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* returns 0 to allow, non-zero to block */
|
|
||||||
int filter_url (const char *url)
|
|
||||||
{
|
|
||||||
struct filter_list *p;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
if (!fl || !already_init)
|
|
||||||
goto COMMON_EXIT;
|
|
||||||
|
|
||||||
for (p = fl; p; p = p->next) {
|
|
||||||
result =
|
|
||||||
regexec (p->cpat, url, (size_t) 0, (regmatch_t *) 0, 0);
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
if (default_policy == FILTER_DEFAULT_ALLOW)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
COMMON_EXIT:
|
|
||||||
if (default_policy == FILTER_DEFAULT_ALLOW)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the default filtering policy
|
|
||||||
*/
|
|
||||||
void filter_set_default_policy (filter_policy_t policy)
|
|
||||||
{
|
|
||||||
default_policy = policy;
|
|
||||||
}
|
}
|
||||||
+15
-27
@@ -1,37 +1,25 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: filter.h,v 1.3 2000-11-23 04:46:25 rjkaes Exp $
|
||||||
* Copyright (C) 1999 George Talusan <gstalusan@uwaterloo.ca>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* See 'filter.c' for a detailed description.
|
||||||
* 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,
|
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
|
||||||
* 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
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'filter.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef _TINYPROXY_FILTER_H_
|
#ifndef _TINYPROXY_FILTER_H_
|
||||||
#define _TINYPROXY_FILTER_H_
|
#define _TINYPROXY_FILTER_H_
|
||||||
|
|
||||||
typedef enum {
|
extern void filter_init(void);
|
||||||
FILTER_DEFAULT_ALLOW,
|
extern void filter_destroy(void);
|
||||||
FILTER_DEFAULT_DENY
|
extern int filter_url(char *host);
|
||||||
} filter_policy_t;
|
|
||||||
|
|
||||||
extern void filter_init (void);
|
|
||||||
extern void filter_destroy (void);
|
|
||||||
extern void filter_reload (void);
|
|
||||||
extern int filter_domain (const char *host);
|
|
||||||
extern int filter_url (const char *url);
|
|
||||||
|
|
||||||
extern void filter_set_default_policy (filter_policy_t policy);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+5880
File diff suppressed because it is too large.
Load diff
+542
@@ -0,0 +1,542 @@
|
|||||||
|
/* Definitions for data structures and routines for the regular
|
||||||
|
expression library, version 0.12.
|
||||||
|
Copyright (C) 1985,89,90,91,92,93,95,96,97,98 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is part of the GNU C Library. Its master source is NOT part of
|
||||||
|
the C library, however. The master source lives in /gd/gnu/lib.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public
|
||||||
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||||
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
|
#ifndef _REGEX_H
|
||||||
|
#define _REGEX_H 1
|
||||||
|
|
||||||
|
/* Allow the use in C++ code. */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* POSIX says that <sys/types.h> must be included (by the caller) before
|
||||||
|
<regex.h>. */
|
||||||
|
|
||||||
|
#if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS
|
||||||
|
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
|
||||||
|
should be there. */
|
||||||
|
# include <stddef.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The following two types have to be signed and unsigned integer type
|
||||||
|
wide enough to hold a value of a pointer. For most ANSI compilers
|
||||||
|
ptrdiff_t and size_t should be likely OK. Still size of these two
|
||||||
|
types is 2 for Microsoft C. Ugh... */
|
||||||
|
typedef long int s_reg_t;
|
||||||
|
typedef unsigned long int active_reg_t;
|
||||||
|
|
||||||
|
/* The following bits are used to determine the regexp syntax we
|
||||||
|
recognize. The set/not-set meanings are chosen so that Emacs syntax
|
||||||
|
remains the value 0. The bits are given in alphabetical order, and
|
||||||
|
the definitions shifted by one from the previous bit; thus, when we
|
||||||
|
add or remove a bit, only one other definition need change. */
|
||||||
|
typedef unsigned long int reg_syntax_t;
|
||||||
|
|
||||||
|
/* If this bit is not set, then \ inside a bracket expression is literal.
|
||||||
|
If set, then such a \ quotes the following character. */
|
||||||
|
#define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
|
||||||
|
|
||||||
|
/* If this bit is not set, then + and ? are operators, and \+ and \? are
|
||||||
|
literals.
|
||||||
|
If set, then \+ and \? are operators and + and ? are literals. */
|
||||||
|
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then character classes are supported. They are:
|
||||||
|
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
|
||||||
|
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
|
||||||
|
If not set, then character classes are not supported. */
|
||||||
|
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then ^ and $ are always anchors (outside bracket
|
||||||
|
expressions, of course).
|
||||||
|
If this bit is not set, then it depends:
|
||||||
|
^ is an anchor if it is at the beginning of a regular
|
||||||
|
expression or after an open-group or an alternation operator;
|
||||||
|
$ is an anchor if it is at the end of a regular expression, or
|
||||||
|
before a close-group or an alternation operator.
|
||||||
|
|
||||||
|
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
|
||||||
|
POSIX draft 11.2 says that * etc. in leading positions is undefined.
|
||||||
|
We already implemented a previous draft which made those constructs
|
||||||
|
invalid, though, so we haven't changed the code back. */
|
||||||
|
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then special characters are always special
|
||||||
|
regardless of where they are in the pattern.
|
||||||
|
If this bit is not set, then special characters are special only in
|
||||||
|
some contexts; otherwise they are ordinary. Specifically,
|
||||||
|
* + ? and intervals are only special when not after the beginning,
|
||||||
|
open-group, or alternation operator. */
|
||||||
|
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
|
||||||
|
immediately after an alternation or begin-group operator. */
|
||||||
|
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then . matches newline.
|
||||||
|
If not set, then it doesn't. */
|
||||||
|
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then . doesn't match NUL.
|
||||||
|
If not set, then it does. */
|
||||||
|
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, nonmatching lists [^...] do not match newline.
|
||||||
|
If not set, they do. */
|
||||||
|
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, either \{...\} or {...} defines an
|
||||||
|
interval, depending on RE_NO_BK_BRACES.
|
||||||
|
If not set, \{, \}, {, and } are literals. */
|
||||||
|
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, +, ? and | aren't recognized as operators.
|
||||||
|
If not set, they are. */
|
||||||
|
#define RE_LIMITED_OPS (RE_INTERVALS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, newline is an alternation operator.
|
||||||
|
If not set, newline is literal. */
|
||||||
|
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
|
||||||
|
are literals.
|
||||||
|
If not set, then `\{...\}' defines an interval. */
|
||||||
|
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, (...) defines a group, and \( and \) are literals.
|
||||||
|
If not set, \(...\) defines a group, and ( and ) are literals. */
|
||||||
|
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then \<digit> matches <digit>.
|
||||||
|
If not set, then \<digit> is a back-reference. */
|
||||||
|
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then | is an alternation operator, and \| is literal.
|
||||||
|
If not set, then \| is an alternation operator, and | is literal. */
|
||||||
|
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then an ending range point collating higher
|
||||||
|
than the starting range point, as in [z-a], is invalid.
|
||||||
|
If not set, then when ending range point collates higher than the
|
||||||
|
starting range point, the range is ignored. */
|
||||||
|
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then an unmatched ) is ordinary.
|
||||||
|
If not set, then an unmatched ) is invalid. */
|
||||||
|
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, succeed as soon as we match the whole pattern,
|
||||||
|
without further backtracking. */
|
||||||
|
#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, do not process the GNU regex operators.
|
||||||
|
If not set, then the GNU regex operators are recognized. */
|
||||||
|
#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, turn on internal regex debugging.
|
||||||
|
If not set, and debugging was on, turn it off.
|
||||||
|
This only works if regex.c is compiled -DDEBUG.
|
||||||
|
We define this bit always, so that all that's needed to turn on
|
||||||
|
debugging is to recompile regex.c; the calling code can always have
|
||||||
|
this bit set, and it won't affect anything in the normal case. */
|
||||||
|
#define RE_DEBUG (RE_NO_GNU_OPS << 1)
|
||||||
|
|
||||||
|
/* This global variable defines the particular regexp syntax to use (for
|
||||||
|
some interfaces). When a regexp is compiled, the syntax used is
|
||||||
|
stored in the pattern buffer, so changing this does not affect
|
||||||
|
already-compiled regexps. */
|
||||||
|
extern reg_syntax_t re_syntax_options;
|
||||||
|
|
||||||
|
/* Define combinations of the above bits for the standard possibilities.
|
||||||
|
(The [[[ comments delimit what gets put into the Texinfo file, so
|
||||||
|
don't delete them!) */
|
||||||
|
/* [[[begin syntaxes]]] */
|
||||||
|
#define RE_SYNTAX_EMACS 0
|
||||||
|
|
||||||
|
#define RE_SYNTAX_AWK \
|
||||||
|
(RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
|
||||||
|
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
||||||
|
| RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
|
||||||
|
| RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
|
||||||
|
| RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
|
||||||
|
|
||||||
|
#define RE_SYNTAX_GNU_AWK \
|
||||||
|
((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
|
||||||
|
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS))
|
||||||
|
|
||||||
|
#define RE_SYNTAX_POSIX_AWK \
|
||||||
|
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
|
||||||
|
| RE_INTERVALS | RE_NO_GNU_OPS)
|
||||||
|
|
||||||
|
#define RE_SYNTAX_GREP \
|
||||||
|
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \
|
||||||
|
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
|
||||||
|
| RE_NEWLINE_ALT)
|
||||||
|
|
||||||
|
#define RE_SYNTAX_EGREP \
|
||||||
|
(RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
|
||||||
|
| RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
|
||||||
|
| RE_NEWLINE_ALT | RE_NO_BK_PARENS \
|
||||||
|
| RE_NO_BK_VBAR)
|
||||||
|
|
||||||
|
#define RE_SYNTAX_POSIX_EGREP \
|
||||||
|
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
|
||||||
|
|
||||||
|
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
|
||||||
|
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
|
||||||
|
|
||||||
|
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
|
||||||
|
|
||||||
|
/* Syntax bits common to both basic and extended POSIX regex syntax. */
|
||||||
|
#define _RE_SYNTAX_POSIX_COMMON \
|
||||||
|
(RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
|
||||||
|
| RE_INTERVALS | RE_NO_EMPTY_RANGES)
|
||||||
|
|
||||||
|
#define RE_SYNTAX_POSIX_BASIC \
|
||||||
|
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
|
||||||
|
|
||||||
|
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
|
||||||
|
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
|
||||||
|
isn't minimal, since other operators, such as \`, aren't disabled. */
|
||||||
|
#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
|
||||||
|
(_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
|
||||||
|
|
||||||
|
#define RE_SYNTAX_POSIX_EXTENDED \
|
||||||
|
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
||||||
|
| RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
|
||||||
|
| RE_NO_BK_PARENS | RE_NO_BK_VBAR \
|
||||||
|
| RE_UNMATCHED_RIGHT_PAREN_ORD)
|
||||||
|
|
||||||
|
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
|
||||||
|
replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
|
||||||
|
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
|
||||||
|
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
||||||
|
| RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
|
||||||
|
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
||||||
|
| RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
|
||||||
|
/* [[[end syntaxes]]] */
|
||||||
|
|
||||||
|
/* Maximum number of duplicates an interval can allow. Some systems
|
||||||
|
(erroneously) define this in other header files, but we want our
|
||||||
|
value, so remove any previous define. */
|
||||||
|
#ifdef RE_DUP_MAX
|
||||||
|
# undef RE_DUP_MAX
|
||||||
|
#endif
|
||||||
|
/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */
|
||||||
|
#define RE_DUP_MAX (0x7fff)
|
||||||
|
|
||||||
|
|
||||||
|
/* POSIX `cflags' bits (i.e., information for `regcomp'). */
|
||||||
|
|
||||||
|
/* If this bit is set, then use extended regular expression syntax.
|
||||||
|
If not set, then use basic regular expression syntax. */
|
||||||
|
#define REG_EXTENDED 1
|
||||||
|
|
||||||
|
/* If this bit is set, then ignore case when matching.
|
||||||
|
If not set, then case is significant. */
|
||||||
|
#define REG_ICASE (REG_EXTENDED << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then anchors do not match at newline
|
||||||
|
characters in the string.
|
||||||
|
If not set, then anchors do match at newlines. */
|
||||||
|
#define REG_NEWLINE (REG_ICASE << 1)
|
||||||
|
|
||||||
|
/* If this bit is set, then report only success or fail in regexec.
|
||||||
|
If not set, then returns differ between not matching and errors. */
|
||||||
|
#define REG_NOSUB (REG_NEWLINE << 1)
|
||||||
|
|
||||||
|
|
||||||
|
/* POSIX `eflags' bits (i.e., information for regexec). */
|
||||||
|
|
||||||
|
/* If this bit is set, then the beginning-of-line operator doesn't match
|
||||||
|
the beginning of the string (presumably because it's not the
|
||||||
|
beginning of a line).
|
||||||
|
If not set, then the beginning-of-line operator does match the
|
||||||
|
beginning of the string. */
|
||||||
|
#define REG_NOTBOL 1
|
||||||
|
|
||||||
|
/* Like REG_NOTBOL, except for the end-of-line. */
|
||||||
|
#define REG_NOTEOL (1 << 1)
|
||||||
|
|
||||||
|
|
||||||
|
/* If any error codes are removed, changed, or added, update the
|
||||||
|
`re_error_msg' table in regex.c. */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
#ifdef _XOPEN_SOURCE
|
||||||
|
REG_ENOSYS = -1, /* This will never happen for this implementation. */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
REG_NOERROR = 0, /* Success. */
|
||||||
|
REG_NOMATCH, /* Didn't find a match (for regexec). */
|
||||||
|
|
||||||
|
/* POSIX regcomp return error codes. (In the order listed in the
|
||||||
|
standard.) */
|
||||||
|
REG_BADPAT, /* Invalid pattern. */
|
||||||
|
REG_ECOLLATE, /* Not implemented. */
|
||||||
|
REG_ECTYPE, /* Invalid character class name. */
|
||||||
|
REG_EESCAPE, /* Trailing backslash. */
|
||||||
|
REG_ESUBREG, /* Invalid back reference. */
|
||||||
|
REG_EBRACK, /* Unmatched left bracket. */
|
||||||
|
REG_EPAREN, /* Parenthesis imbalance. */
|
||||||
|
REG_EBRACE, /* Unmatched \{. */
|
||||||
|
REG_BADBR, /* Invalid contents of \{\}. */
|
||||||
|
REG_ERANGE, /* Invalid range end. */
|
||||||
|
REG_ESPACE, /* Ran out of memory. */
|
||||||
|
REG_BADRPT, /* No preceding re for repetition op. */
|
||||||
|
|
||||||
|
/* Error codes we've added. */
|
||||||
|
REG_EEND, /* Premature end. */
|
||||||
|
REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
|
||||||
|
REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
|
||||||
|
} reg_errcode_t;
|
||||||
|
|
||||||
|
/* This data structure represents a compiled pattern. Before calling
|
||||||
|
the pattern compiler, the fields `buffer', `allocated', `fastmap',
|
||||||
|
`translate', and `no_sub' can be set. After the pattern has been
|
||||||
|
compiled, the `re_nsub' field is available. All other fields are
|
||||||
|
private to the regex routines. */
|
||||||
|
|
||||||
|
#ifndef RE_TRANSLATE_TYPE
|
||||||
|
# define RE_TRANSLATE_TYPE char *
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct re_pattern_buffer
|
||||||
|
{
|
||||||
|
/* [[[begin pattern_buffer]]] */
|
||||||
|
/* Space that holds the compiled pattern. It is declared as
|
||||||
|
`unsigned char *' because its elements are
|
||||||
|
sometimes used as array indexes. */
|
||||||
|
unsigned char *buffer;
|
||||||
|
|
||||||
|
/* Number of bytes to which `buffer' points. */
|
||||||
|
unsigned long int allocated;
|
||||||
|
|
||||||
|
/* Number of bytes actually used in `buffer'. */
|
||||||
|
unsigned long int used;
|
||||||
|
|
||||||
|
/* Syntax setting with which the pattern was compiled. */
|
||||||
|
reg_syntax_t syntax;
|
||||||
|
|
||||||
|
/* Pointer to a fastmap, if any, otherwise zero. re_search uses
|
||||||
|
the fastmap, if there is one, to skip over impossible
|
||||||
|
starting points for matches. */
|
||||||
|
char *fastmap;
|
||||||
|
|
||||||
|
/* Either a translate table to apply to all characters before
|
||||||
|
comparing them, or zero for no translation. The translation
|
||||||
|
is applied to a pattern when it is compiled and to a string
|
||||||
|
when it is matched. */
|
||||||
|
RE_TRANSLATE_TYPE translate;
|
||||||
|
|
||||||
|
/* Number of subexpressions found by the compiler. */
|
||||||
|
size_t re_nsub;
|
||||||
|
|
||||||
|
/* Zero if this pattern cannot match the empty string, one else.
|
||||||
|
Well, in truth it's used only in `re_search_2', to see
|
||||||
|
whether or not we should use the fastmap, so we don't set
|
||||||
|
this absolutely perfectly; see `re_compile_fastmap' (the
|
||||||
|
`duplicate' case). */
|
||||||
|
unsigned can_be_null : 1;
|
||||||
|
|
||||||
|
/* If REGS_UNALLOCATED, allocate space in the `regs' structure
|
||||||
|
for `max (RE_NREGS, re_nsub + 1)' groups.
|
||||||
|
If REGS_REALLOCATE, reallocate space if necessary.
|
||||||
|
If REGS_FIXED, use what's there. */
|
||||||
|
#define REGS_UNALLOCATED 0
|
||||||
|
#define REGS_REALLOCATE 1
|
||||||
|
#define REGS_FIXED 2
|
||||||
|
unsigned regs_allocated : 2;
|
||||||
|
|
||||||
|
/* Set to zero when `regex_compile' compiles a pattern; set to one
|
||||||
|
by `re_compile_fastmap' if it updates the fastmap. */
|
||||||
|
unsigned fastmap_accurate : 1;
|
||||||
|
|
||||||
|
/* If set, `re_match_2' does not return information about
|
||||||
|
subexpressions. */
|
||||||
|
unsigned no_sub : 1;
|
||||||
|
|
||||||
|
/* If set, a beginning-of-line anchor doesn't match at the
|
||||||
|
beginning of the string. */
|
||||||
|
unsigned not_bol : 1;
|
||||||
|
|
||||||
|
/* Similarly for an end-of-line anchor. */
|
||||||
|
unsigned not_eol : 1;
|
||||||
|
|
||||||
|
/* If true, an anchor at a newline matches. */
|
||||||
|
unsigned newline_anchor : 1;
|
||||||
|
|
||||||
|
/* [[[end pattern_buffer]]] */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct re_pattern_buffer regex_t;
|
||||||
|
|
||||||
|
/* Type for byte offsets within the string. POSIX mandates this. */
|
||||||
|
typedef int regoff_t;
|
||||||
|
|
||||||
|
|
||||||
|
/* This is the structure we store register match data in. See
|
||||||
|
regex.texinfo for a full description of what registers match. */
|
||||||
|
struct re_registers
|
||||||
|
{
|
||||||
|
unsigned num_regs;
|
||||||
|
regoff_t *start;
|
||||||
|
regoff_t *end;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
|
||||||
|
`re_match_2' returns information about at least this many registers
|
||||||
|
the first time a `regs' structure is passed. */
|
||||||
|
#ifndef RE_NREGS
|
||||||
|
# define RE_NREGS 30
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* POSIX specification for registers. Aside from the different names than
|
||||||
|
`re_registers', POSIX uses an array of structures, instead of a
|
||||||
|
structure of arrays. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
regoff_t rm_so; /* Byte offset from string's start to substring's start. */
|
||||||
|
regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
|
||||||
|
} regmatch_t;
|
||||||
|
|
||||||
|
/* Declarations for routines. */
|
||||||
|
|
||||||
|
/* To avoid duplicating every routine declaration -- once with a
|
||||||
|
prototype (if we are ANSI), and once without (if we aren't) -- we
|
||||||
|
use the following macro to declare argument types. This
|
||||||
|
unfortunately clutters up the declarations a bit, but I think it's
|
||||||
|
worth it. */
|
||||||
|
|
||||||
|
#if __STDC__
|
||||||
|
|
||||||
|
# define _RE_ARGS(args) args
|
||||||
|
|
||||||
|
#else /* not __STDC__ */
|
||||||
|
|
||||||
|
# define _RE_ARGS(args) ()
|
||||||
|
|
||||||
|
#endif /* not __STDC__ */
|
||||||
|
|
||||||
|
/* Sets the current default syntax to SYNTAX, and return the old syntax.
|
||||||
|
You can also simply assign to the `re_syntax_options' variable. */
|
||||||
|
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
|
||||||
|
|
||||||
|
/* Compile the regular expression PATTERN, with length LENGTH
|
||||||
|
and syntax given by the global `re_syntax_options', into the buffer
|
||||||
|
BUFFER. Return NULL if successful, and an error string if not. */
|
||||||
|
extern const char *re_compile_pattern
|
||||||
|
_RE_ARGS ((const char *pattern, size_t length,
|
||||||
|
struct re_pattern_buffer *buffer));
|
||||||
|
|
||||||
|
|
||||||
|
/* Compile a fastmap for the compiled pattern in BUFFER; used to
|
||||||
|
accelerate searches. Return 0 if successful and -2 if was an
|
||||||
|
internal error. */
|
||||||
|
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
|
||||||
|
|
||||||
|
|
||||||
|
/* Search in the string STRING (with length LENGTH) for the pattern
|
||||||
|
compiled into BUFFER. Start searching at position START, for RANGE
|
||||||
|
characters. Return the starting position of the match, -1 for no
|
||||||
|
match, or -2 for an internal error. Also return register
|
||||||
|
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
|
||||||
|
extern int re_search
|
||||||
|
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
||||||
|
int length, int start, int range, struct re_registers *regs));
|
||||||
|
|
||||||
|
|
||||||
|
/* Like `re_search', but search in the concatenation of STRING1 and
|
||||||
|
STRING2. Also, stop searching at index START + STOP. */
|
||||||
|
extern int re_search_2
|
||||||
|
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
||||||
|
int length1, const char *string2, int length2,
|
||||||
|
int start, int range, struct re_registers *regs, int stop));
|
||||||
|
|
||||||
|
|
||||||
|
/* Like `re_search', but return how many characters in STRING the regexp
|
||||||
|
in BUFFER matched, starting at position START. */
|
||||||
|
extern int re_match
|
||||||
|
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
||||||
|
int length, int start, struct re_registers *regs));
|
||||||
|
|
||||||
|
|
||||||
|
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
|
||||||
|
extern int re_match_2
|
||||||
|
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
||||||
|
int length1, const char *string2, int length2,
|
||||||
|
int start, struct re_registers *regs, int stop));
|
||||||
|
|
||||||
|
|
||||||
|
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
|
||||||
|
ENDS. Subsequent matches using BUFFER and REGS will use this memory
|
||||||
|
for recording register information. STARTS and ENDS must be
|
||||||
|
allocated with malloc, and must each be at least `NUM_REGS * sizeof
|
||||||
|
(regoff_t)' bytes long.
|
||||||
|
|
||||||
|
If NUM_REGS == 0, then subsequent matches should allocate their own
|
||||||
|
register data.
|
||||||
|
|
||||||
|
Unless this function is called, the first search or match using
|
||||||
|
PATTERN_BUFFER will allocate its own register data, without
|
||||||
|
freeing the old data. */
|
||||||
|
extern void re_set_registers
|
||||||
|
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
|
||||||
|
unsigned num_regs, regoff_t *starts, regoff_t *ends));
|
||||||
|
|
||||||
|
#if defined _REGEX_RE_COMP || defined _LIBC
|
||||||
|
# ifndef _CRAY
|
||||||
|
/* 4.2 bsd compatibility. */
|
||||||
|
extern char *re_comp _RE_ARGS ((const char *));
|
||||||
|
extern int re_exec _RE_ARGS ((const char *));
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* POSIX compatibility. */
|
||||||
|
extern int regcomp _RE_ARGS ((regex_t *__preg, const char *__pattern,
|
||||||
|
int __cflags));
|
||||||
|
|
||||||
|
extern int regexec _RE_ARGS ((const regex_t *__preg,
|
||||||
|
const char *__string, size_t __nmatch,
|
||||||
|
regmatch_t __pmatch[], int __eflags));
|
||||||
|
|
||||||
|
extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
|
||||||
|
char *__errbuf, size_t __errbuf_size));
|
||||||
|
|
||||||
|
extern void regfree _RE_ARGS ((regex_t *__preg));
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* C++ */
|
||||||
|
|
||||||
|
#endif /* regex.h */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Local variables:
|
||||||
|
make-backup-files: t
|
||||||
|
version-control: t
|
||||||
|
trim-versions-without-asking: nil
|
||||||
|
End:
|
||||||
|
*/
|
||||||
+169
@@ -0,0 +1,169 @@
|
|||||||
|
/* $Id: grammar.y,v 1.3 2001-06-02 03:10:09 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* This is the grammar for tinyproxy's configuration file. It needs to be
|
||||||
|
* in sync with scanner.l. If you know more about yacc and lex than I do
|
||||||
|
* please update these files.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
%{
|
||||||
|
|
||||||
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
#include "acl.h"
|
||||||
|
#include "anonymous.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
void yyerror(char *s);
|
||||||
|
int yylex(void);
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
%union {
|
||||||
|
unsigned int num;
|
||||||
|
char *cptr;
|
||||||
|
void *ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* statements */
|
||||||
|
%token KW_PORT KW_LISTEN
|
||||||
|
%token KW_LOGFILE KW_PIDFILE KW_SYSLOG
|
||||||
|
%token KW_MAXCLIENTS KW_MAXSPARESERVERS KW_MINSPARESERVERS KW_STARTSERVERS
|
||||||
|
%token KW_MAXREQUESTSPERCHILD
|
||||||
|
%token KW_TIMEOUT
|
||||||
|
%token KW_USER KW_GROUP
|
||||||
|
%token KW_ANONYMOUS KW_FILTER KW_XTINYPROXY KW_TUNNEL
|
||||||
|
%token KW_ALLOW KW_DENY
|
||||||
|
|
||||||
|
/* yes/no switches */
|
||||||
|
%token KW_YES KW_NO
|
||||||
|
|
||||||
|
/* settings for loglevel */
|
||||||
|
%token KW_LOGLEVEL
|
||||||
|
%token KW_LOG_CRITICAL KW_LOG_ERROR KW_LOG_WARNING KW_LOG_NOTICE KW_LOG_INFO
|
||||||
|
|
||||||
|
%token <cptr> IDENTIFIER
|
||||||
|
%token <num> NUMBER
|
||||||
|
%token <cptr> STRING
|
||||||
|
%token <cptr> NUMERIC_ADDRESS
|
||||||
|
%token <cptr> STRING_ADDRESS
|
||||||
|
%token <cptr> NETMASK_ADDRESS
|
||||||
|
|
||||||
|
%type <num> yesno
|
||||||
|
%type <cptr> string
|
||||||
|
%type <cptr> network_address
|
||||||
|
%type <cptr> unique_address
|
||||||
|
%type <num> loglevels
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
start
|
||||||
|
: /* empty */
|
||||||
|
| start line
|
||||||
|
;
|
||||||
|
|
||||||
|
line
|
||||||
|
: '\n'
|
||||||
|
| statement '\n'
|
||||||
|
;
|
||||||
|
|
||||||
|
statement
|
||||||
|
: KW_PORT NUMBER { config.port = $2; }
|
||||||
|
| KW_TIMEOUT NUMBER { config.idletimeout = $2; }
|
||||||
|
| KW_SYSLOG yesno
|
||||||
|
{
|
||||||
|
#ifdef HAVE_SYSLOG_H
|
||||||
|
config.syslog = $2;
|
||||||
|
#else
|
||||||
|
log_message(LOG_WARNING, "Syslog support was not compiled in.");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
| KW_MAXCLIENTS NUMBER { thread_configure(THREAD_MAXCLIENTS, $2); }
|
||||||
|
| KW_MAXSPARESERVERS NUMBER { thread_configure(THREAD_MAXSPARESERVERS, $2); }
|
||||||
|
| KW_MINSPARESERVERS NUMBER { thread_configure(THREAD_MINSPARESERVERS, $2); }
|
||||||
|
| KW_STARTSERVERS NUMBER { thread_configure(THREAD_STARTSERVERS, $2); }
|
||||||
|
| KW_MAXREQUESTSPERCHILD NUMBER { thread_configure(THREAD_MAXREQUESTSPERCHILD, $2); }
|
||||||
|
| KW_LOGFILE string
|
||||||
|
{
|
||||||
|
config.logf_name = $2;
|
||||||
|
if (!config.logf_name) {
|
||||||
|
fprintf(stderr, "bad log file\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| KW_PIDFILE string { config.pidpath = $2; }
|
||||||
|
| KW_USER string { config.username = $2; }
|
||||||
|
| KW_GROUP string { config.group = $2; }
|
||||||
|
| KW_ANONYMOUS string { anon_insert($2); }
|
||||||
|
| KW_FILTER string
|
||||||
|
{
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
config.filter = $2;
|
||||||
|
#else
|
||||||
|
log_message(LOG_WARNING, "Filter support was not compiled in.");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
| KW_XTINYPROXY network_address { config.my_domain = $2; }
|
||||||
|
| KW_TUNNEL unique_address ':' NUMBER
|
||||||
|
{
|
||||||
|
#ifdef TUNNEL_SUPPORT
|
||||||
|
config.tunnel_name = $2;
|
||||||
|
config.tunnel_port = $4;
|
||||||
|
#else
|
||||||
|
log_message(LOG_WARNING, "Tunnel support was not compiled in.");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
| KW_LISTEN NUMERIC_ADDRESS { config.ipAddr = $2; }
|
||||||
|
| KW_ALLOW network_address { insert_acl($2, ACL_ALLOW); }
|
||||||
|
| KW_DENY network_address { insert_acl($2, ACL_DENY); }
|
||||||
|
| KW_LOGLEVEL loglevels { set_log_level($2); }
|
||||||
|
;
|
||||||
|
|
||||||
|
loglevels
|
||||||
|
: KW_LOG_CRITICAL { $$ = LOG_CRIT; }
|
||||||
|
| KW_LOG_ERROR { $$ = LOG_ERR; }
|
||||||
|
| KW_LOG_WARNING { $$ = LOG_WARNING; }
|
||||||
|
| KW_LOG_NOTICE { $$ = LOG_NOTICE; }
|
||||||
|
| KW_LOG_INFO { $$ = LOG_INFO; }
|
||||||
|
;
|
||||||
|
|
||||||
|
network_address
|
||||||
|
: unique_address
|
||||||
|
| NETMASK_ADDRESS
|
||||||
|
;
|
||||||
|
|
||||||
|
unique_address
|
||||||
|
: STRING_ADDRESS
|
||||||
|
| NUMERIC_ADDRESS
|
||||||
|
;
|
||||||
|
|
||||||
|
yesno
|
||||||
|
: KW_YES { $$ = 1; }
|
||||||
|
| KW_NO { $$ = 0; }
|
||||||
|
| NUMBER { $$ = $1; }
|
||||||
|
;
|
||||||
|
|
||||||
|
string
|
||||||
|
: IDENTIFIER
|
||||||
|
| STRING
|
||||||
|
;
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
extern unsigned int yylineno;
|
||||||
|
|
||||||
|
void yyerror(char *s)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Line %d: %s\n", yylineno, s);
|
||||||
|
}
|
||||||
-494
@@ -1,494 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* A hashmap implementation. The keys are case-insensitive NULL terminated
|
|
||||||
* strings, and the data is arbitrary lumps of data. Copies of both the
|
|
||||||
* key and the data in the hashmap itself, so you must free the original
|
|
||||||
* key and data to avoid a memory leak. The hashmap returns a pointer
|
|
||||||
* to the data when a key is searched for, so take care in modifying the
|
|
||||||
* data as it's modifying the data stored in the hashmap. (In other words,
|
|
||||||
* don't try to free the data, or realloc the memory. :)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "hashmap.h"
|
|
||||||
#include "heap.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These structures are the storage for the hashmap. Entries are stored in
|
|
||||||
* struct hashentry_s (the key, data, and length), and all the "buckets" are
|
|
||||||
* grouped together in hashmap_s. The hashmap_s.size member is for
|
|
||||||
* internal use. It stores the number of buckets the hashmap was created
|
|
||||||
* with.
|
|
||||||
*/
|
|
||||||
struct hashentry_s {
|
|
||||||
char *key;
|
|
||||||
void *data;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
struct hashentry_s *prev, *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hashbucket_s {
|
|
||||||
struct hashentry_s *head, *tail;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hashmap_s {
|
|
||||||
unsigned int size;
|
|
||||||
hashmap_iter end_iterator;
|
|
||||||
|
|
||||||
struct hashbucket_s *buckets;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A NULL terminated string is passed to this function and a "hash" value
|
|
||||||
* is produced within the range of [0 .. size) (In other words, 0 to one
|
|
||||||
* less than size.)
|
|
||||||
* The contents of the key are converted to lowercase, so this function
|
|
||||||
* is not case-sensitive.
|
|
||||||
*
|
|
||||||
* If any of the arguments are invalid a negative number is returned.
|
|
||||||
*/
|
|
||||||
static int hashfunc (const char *key, unsigned int size)
|
|
||||||
{
|
|
||||||
uint32_t hash;
|
|
||||||
|
|
||||||
if (key == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
if (size == 0)
|
|
||||||
return -ERANGE;
|
|
||||||
|
|
||||||
for (hash = tolower (*key++); *key != '\0'; key++) {
|
|
||||||
uint32_t bit = (hash & 1) ? (1 << (sizeof (uint32_t) - 1)) : 0;
|
|
||||||
|
|
||||||
hash >>= 1;
|
|
||||||
|
|
||||||
hash += tolower (*key) + bit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Keep the hash within the table limits */
|
|
||||||
return hash % size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a hashmap with the requested number of buckets. If "nbuckets" is
|
|
||||||
* not greater than zero a NULL is returned; otherwise, a _token_ to the
|
|
||||||
* hashmap is returned.
|
|
||||||
*
|
|
||||||
* NULLs are also returned if memory could not be allocated for hashmap.
|
|
||||||
*/
|
|
||||||
hashmap_t hashmap_create (unsigned int nbuckets)
|
|
||||||
{
|
|
||||||
struct hashmap_s *ptr;
|
|
||||||
|
|
||||||
if (nbuckets == 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ptr = (struct hashmap_s *) safecalloc (1, sizeof (struct hashmap_s));
|
|
||||||
if (!ptr)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ptr->size = nbuckets;
|
|
||||||
ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets,
|
|
||||||
sizeof (struct
|
|
||||||
hashbucket_s));
|
|
||||||
if (!ptr->buckets) {
|
|
||||||
safefree (ptr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This points to "one" past the end of the hashmap. */
|
|
||||||
ptr->end_iterator = 0;
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Follow the chain of hashentries and delete them (including the data and
|
|
||||||
* the key.)
|
|
||||||
*
|
|
||||||
* Returns: 0 if the function completed successfully
|
|
||||||
* negative number is returned if "entry" was NULL
|
|
||||||
*/
|
|
||||||
static int delete_hashbucket (struct hashbucket_s *bucket)
|
|
||||||
{
|
|
||||||
struct hashentry_s *nextptr;
|
|
||||||
struct hashentry_s *ptr;
|
|
||||||
|
|
||||||
if (bucket == NULL || bucket->head == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
ptr = bucket->head;
|
|
||||||
while (ptr) {
|
|
||||||
nextptr = ptr->next;
|
|
||||||
|
|
||||||
safefree (ptr->key);
|
|
||||||
safefree (ptr->data);
|
|
||||||
safefree (ptr);
|
|
||||||
|
|
||||||
ptr = nextptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Deletes a hashmap. All the key/data pairs are also deleted.
|
|
||||||
*
|
|
||||||
* Returns: 0 on success
|
|
||||||
* negative if a NULL "map" was supplied
|
|
||||||
*/
|
|
||||||
int hashmap_delete (hashmap_t map)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
if (map == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
for (i = 0; i != map->size; i++) {
|
|
||||||
if (map->buckets[i].head != NULL) {
|
|
||||||
delete_hashbucket (&map->buckets[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (map->buckets);
|
|
||||||
safefree (map);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Inserts a NULL terminated string (as the key), plus any arbitrary "data"
|
|
||||||
* of "len" bytes. Both the key and the data are copied, so the original
|
|
||||||
* key/data must be freed to avoid a memory leak.
|
|
||||||
* The "data" must be non-NULL and "len" must be greater than zero. You
|
|
||||||
* cannot insert NULL data in association with the key.
|
|
||||||
*
|
|
||||||
* Returns: 0 on success
|
|
||||||
* negative number if there are errors
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
|
|
||||||
{
|
|
||||||
struct hashentry_s *ptr;
|
|
||||||
int hash;
|
|
||||||
char *key_copy;
|
|
||||||
void *data_copy;
|
|
||||||
|
|
||||||
assert (map != NULL);
|
|
||||||
assert (key != NULL);
|
|
||||||
assert (data != NULL);
|
|
||||||
assert (len > 0);
|
|
||||||
|
|
||||||
if (map == NULL || key == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
if (!data || len < 1)
|
|
||||||
return -ERANGE;
|
|
||||||
|
|
||||||
hash = hashfunc (key, map->size);
|
|
||||||
if (hash < 0)
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* First make copies of the key and data in case there is a memory
|
|
||||||
* problem later.
|
|
||||||
*/
|
|
||||||
key_copy = safestrdup (key);
|
|
||||||
if (!key_copy)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
data_copy = safemalloc (len);
|
|
||||||
if (!data_copy) {
|
|
||||||
safefree (key_copy);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
memcpy (data_copy, data, len);
|
|
||||||
|
|
||||||
ptr = (struct hashentry_s *) safemalloc (sizeof (struct hashentry_s));
|
|
||||||
if (!ptr) {
|
|
||||||
safefree (key_copy);
|
|
||||||
safefree (data_copy);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr->key = key_copy;
|
|
||||||
ptr->data = data_copy;
|
|
||||||
ptr->len = len;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now add the entry to the end of the bucket chain.
|
|
||||||
*/
|
|
||||||
ptr->next = NULL;
|
|
||||||
ptr->prev = map->buckets[hash].tail;
|
|
||||||
if (map->buckets[hash].tail)
|
|
||||||
map->buckets[hash].tail->next = ptr;
|
|
||||||
|
|
||||||
map->buckets[hash].tail = ptr;
|
|
||||||
if (!map->buckets[hash].head)
|
|
||||||
map->buckets[hash].head = ptr;
|
|
||||||
|
|
||||||
map->end_iterator++;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get an iterator to the first entry.
|
|
||||||
*
|
|
||||||
* Returns: an negative value upon error.
|
|
||||||
*/
|
|
||||||
hashmap_iter hashmap_first (hashmap_t map)
|
|
||||||
{
|
|
||||||
assert (map != NULL);
|
|
||||||
|
|
||||||
if (!map)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (map->end_iterator == 0)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks to see if the iterator is pointing at the "end" of the entries.
|
|
||||||
*
|
|
||||||
* Returns: 1 if it is the end
|
|
||||||
* 0 otherwise
|
|
||||||
*/
|
|
||||||
int hashmap_is_end (hashmap_t map, hashmap_iter iter)
|
|
||||||
{
|
|
||||||
assert (map != NULL);
|
|
||||||
assert (iter >= 0);
|
|
||||||
|
|
||||||
if (!map || iter < 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (iter == map->end_iterator)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return a "pointer" to the first instance of the particular key. It can
|
|
||||||
* be tested against hashmap_is_end() to see if the key was not found.
|
|
||||||
*
|
|
||||||
* Returns: negative upon an error
|
|
||||||
* an "iterator" pointing at the first key
|
|
||||||
* an "end-iterator" if the key wasn't found
|
|
||||||
*/
|
|
||||||
hashmap_iter hashmap_find (hashmap_t map, const char *key)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
hashmap_iter iter = 0;
|
|
||||||
struct hashentry_s *ptr;
|
|
||||||
|
|
||||||
assert (map != NULL);
|
|
||||||
assert (key != NULL);
|
|
||||||
|
|
||||||
if (!map || !key)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Loop through all the keys and look for the first occurrence
|
|
||||||
* of a particular key.
|
|
||||||
*/
|
|
||||||
for (i = 0; i != map->size; i++) {
|
|
||||||
ptr = map->buckets[i].head;
|
|
||||||
|
|
||||||
while (ptr) {
|
|
||||||
if (strcasecmp (ptr->key, key) == 0) {
|
|
||||||
/* Found it, so return the current count */
|
|
||||||
return iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
iter++;
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Retrieve the data associated with a particular iterator.
|
|
||||||
*
|
|
||||||
* Returns: the length of the data block upon success
|
|
||||||
* negative upon error
|
|
||||||
*/
|
|
||||||
ssize_t
|
|
||||||
hashmap_return_entry (hashmap_t map, hashmap_iter iter, char **key, void **data)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
struct hashentry_s *ptr;
|
|
||||||
hashmap_iter count = 0;
|
|
||||||
|
|
||||||
assert (map != NULL);
|
|
||||||
assert (iter >= 0);
|
|
||||||
assert (iter != map->end_iterator);
|
|
||||||
assert (key != NULL);
|
|
||||||
assert (data != NULL);
|
|
||||||
|
|
||||||
if (!map || iter < 0 || !key || !data)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
for (i = 0; i != map->size; i++) {
|
|
||||||
ptr = map->buckets[i].head;
|
|
||||||
while (ptr) {
|
|
||||||
if (count == iter) {
|
|
||||||
/* This is the data so return it */
|
|
||||||
*key = ptr->key;
|
|
||||||
*data = ptr->data;
|
|
||||||
return ptr->len;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = ptr->next;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Searches for _any_ occurrences of "key" within the hashmap.
|
|
||||||
*
|
|
||||||
* Returns: negative upon an error
|
|
||||||
* zero if no key is found
|
|
||||||
* count found
|
|
||||||
*/
|
|
||||||
ssize_t hashmap_search (hashmap_t map, const char *key)
|
|
||||||
{
|
|
||||||
int hash;
|
|
||||||
struct hashentry_s *ptr;
|
|
||||||
ssize_t count = 0;
|
|
||||||
|
|
||||||
if (map == NULL || key == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
hash = hashfunc (key, map->size);
|
|
||||||
if (hash < 0)
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
ptr = map->buckets[hash].head;
|
|
||||||
|
|
||||||
/* All right, there is an entry here, now see if it's the one we want */
|
|
||||||
while (ptr) {
|
|
||||||
if (strcasecmp (ptr->key, key) == 0)
|
|
||||||
++count;
|
|
||||||
|
|
||||||
/* This entry didn't contain the key; move to the next one */
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the first entry (assuming there is more than one) for a particular
|
|
||||||
* key. The data MUST be non-NULL.
|
|
||||||
*
|
|
||||||
* Returns: negative upon error
|
|
||||||
* zero if no entry is found
|
|
||||||
* length of data for the entry
|
|
||||||
*/
|
|
||||||
ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, void **data)
|
|
||||||
{
|
|
||||||
int hash;
|
|
||||||
struct hashentry_s *ptr;
|
|
||||||
|
|
||||||
if (!map || !key || !data)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
hash = hashfunc (key, map->size);
|
|
||||||
if (hash < 0)
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
ptr = map->buckets[hash].head;
|
|
||||||
|
|
||||||
while (ptr) {
|
|
||||||
if (strcasecmp (ptr->key, key) == 0) {
|
|
||||||
*data = ptr->data;
|
|
||||||
return ptr->len;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Go through the hashmap and remove the particular key.
|
|
||||||
* NOTE: This will invalidate any iterators which have been created.
|
|
||||||
*
|
|
||||||
* Remove: negative upon error
|
|
||||||
* 0 if the key was not found
|
|
||||||
* positive count of entries deleted
|
|
||||||
*/
|
|
||||||
ssize_t hashmap_remove (hashmap_t map, const char *key)
|
|
||||||
{
|
|
||||||
int hash;
|
|
||||||
struct hashentry_s *ptr, *next;
|
|
||||||
short int deleted = 0;
|
|
||||||
|
|
||||||
if (map == NULL || key == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
hash = hashfunc (key, map->size);
|
|
||||||
if (hash < 0)
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
ptr = map->buckets[hash].head;
|
|
||||||
while (ptr) {
|
|
||||||
if (strcasecmp (ptr->key, key) == 0) {
|
|
||||||
/*
|
|
||||||
* Found the data, now need to remove everything
|
|
||||||
* and update the hashmap.
|
|
||||||
*/
|
|
||||||
next = ptr->next;
|
|
||||||
|
|
||||||
if (ptr->prev)
|
|
||||||
ptr->prev->next = ptr->next;
|
|
||||||
if (ptr->next)
|
|
||||||
ptr->next->prev = ptr->prev;
|
|
||||||
|
|
||||||
if (map->buckets[hash].head == ptr)
|
|
||||||
map->buckets[hash].head = ptr->next;
|
|
||||||
if (map->buckets[hash].tail == ptr)
|
|
||||||
map->buckets[hash].tail = ptr->prev;
|
|
||||||
|
|
||||||
safefree (ptr->key);
|
|
||||||
safefree (ptr->data);
|
|
||||||
safefree (ptr);
|
|
||||||
|
|
||||||
++deleted;
|
|
||||||
--map->end_iterator;
|
|
||||||
|
|
||||||
ptr = next;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This entry didn't contain the key; move to the next one */
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The key was not found, so return 0 */
|
|
||||||
return deleted;
|
|
||||||
}
|
|
||||||
-120
@@ -1,120 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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 'hashmap.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef _HASHMAP_H
|
|
||||||
#define _HASHMAP_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We're using a typedef here to "hide" the implementation details of the
|
|
||||||
* hash map. Sure, it's a pointer, but the struct is hidden in the C file.
|
|
||||||
* So, just use the hashmap_t like it's a cookie. :)
|
|
||||||
*/
|
|
||||||
typedef struct hashmap_s *hashmap_t;
|
|
||||||
typedef int hashmap_iter;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* hashmap_create() takes one argument, which is the number of buckets to
|
|
||||||
* use internally. hashmap_delete() is self explanatory.
|
|
||||||
*/
|
|
||||||
extern hashmap_t hashmap_create (unsigned int nbuckets);
|
|
||||||
extern int hashmap_delete (hashmap_t map);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* When the you insert a key/data pair into the hashmap it will the key
|
|
||||||
* and data are duplicated, so you must free your copy if it was created
|
|
||||||
* on the heap. The key must be a NULL terminated string. "data" must be
|
|
||||||
* non-NULL and length must be greater than zero.
|
|
||||||
*
|
|
||||||
* Returns: negative on error
|
|
||||||
* 0 upon successful insert
|
|
||||||
*/
|
|
||||||
extern int hashmap_insert (hashmap_t map, const char *key,
|
|
||||||
const void *data, size_t len);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get an iterator to the first entry.
|
|
||||||
*
|
|
||||||
* Returns: an negative value upon error.
|
|
||||||
*/
|
|
||||||
extern hashmap_iter hashmap_first (hashmap_t map);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks to see if the iterator is pointing at the "end" of the entries.
|
|
||||||
*
|
|
||||||
* Returns: 1 if it is the end
|
|
||||||
* 0 otherwise
|
|
||||||
*/
|
|
||||||
extern int hashmap_is_end (hashmap_t map, hashmap_iter iter);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return a "pointer" to the first instance of the particular key. It can
|
|
||||||
* be tested against hashmap_is_end() to see if the key was not found.
|
|
||||||
*
|
|
||||||
* Returns: negative upon an error
|
|
||||||
* an "iterator" pointing at the first key
|
|
||||||
* an "end-iterator" if the key wasn't found
|
|
||||||
*/
|
|
||||||
extern hashmap_iter hashmap_find (hashmap_t map, const char *key);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Retrieve the key/data associated with a particular iterator.
|
|
||||||
* NOTE: These are pointers to the actual data, so don't mess around with them
|
|
||||||
* too much.
|
|
||||||
*
|
|
||||||
* Returns: the length of the data block upon success
|
|
||||||
* negative upon error
|
|
||||||
*/
|
|
||||||
extern ssize_t hashmap_return_entry (hashmap_t map, hashmap_iter iter,
|
|
||||||
char **key, void **data);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the first entry (assuming there is more than one) for a particular
|
|
||||||
* key. The data MUST be non-NULL.
|
|
||||||
*
|
|
||||||
* Returns: negative upon error
|
|
||||||
* zero if no entry is found
|
|
||||||
* length of data for the entry
|
|
||||||
*/
|
|
||||||
extern ssize_t hashmap_entry_by_key (hashmap_t map, const char *key,
|
|
||||||
void **data);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Searches for _any_ occurrances of "key" within the hashmap and returns the
|
|
||||||
* number of matching entries.
|
|
||||||
*
|
|
||||||
* Returns: negative upon an error
|
|
||||||
* zero if no key is found
|
|
||||||
* count found (positive value)
|
|
||||||
*/
|
|
||||||
extern ssize_t hashmap_search (hashmap_t map, const char *key);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Go through the hashmap and remove the particular key.
|
|
||||||
* NOTE: This will invalidate any iterators which have been created.
|
|
||||||
*
|
|
||||||
* Remove: negative upon error
|
|
||||||
* 0 if the key was not found
|
|
||||||
* positive count of entries deleted
|
|
||||||
*/
|
|
||||||
extern ssize_t hashmap_remove (hashmap_t map, const char *key);
|
|
||||||
|
|
||||||
#endif /* _HASHMAP_H */
|
|
||||||
-157
@@ -1,157 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Debugging versions of various heap related functions are combined
|
|
||||||
* here. The debugging versions include assertions and also print
|
|
||||||
* (to standard error) the function called along with the amount
|
|
||||||
* of memory allocated, and where the memory is pointing. The
|
|
||||||
* format of the log message is standardized.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "heap.h"
|
|
||||||
#include "text.h"
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
|
|
||||||
void *debugging_calloc (size_t nmemb, size_t size, const char *file,
|
|
||||||
unsigned long line)
|
|
||||||
{
|
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
assert (nmemb > 0);
|
|
||||||
assert (size > 0);
|
|
||||||
|
|
||||||
ptr = calloc (nmemb, size);
|
|
||||||
fprintf (stderr, "{calloc: %p:%lu x %lu} %s:%lu\n", ptr,
|
|
||||||
(unsigned long) nmemb, (unsigned long) size, file, line);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *debugging_malloc (size_t size, const char *file, unsigned long line)
|
|
||||||
{
|
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
assert (size > 0);
|
|
||||||
|
|
||||||
ptr = malloc (size);
|
|
||||||
fprintf (stderr, "{malloc: %p:%lu} %s:%lu\n", ptr,
|
|
||||||
(unsigned long) size, file, line);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *debugging_realloc (void *ptr, size_t size, const char *file,
|
|
||||||
unsigned long line)
|
|
||||||
{
|
|
||||||
void *newptr;
|
|
||||||
|
|
||||||
assert (size > 0);
|
|
||||||
|
|
||||||
newptr = realloc (ptr, size);
|
|
||||||
fprintf (stderr, "{realloc: %p -> %p:%lu} %s:%lu\n", ptr, newptr,
|
|
||||||
(unsigned long) size, file, line);
|
|
||||||
return newptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void debugging_free (void *ptr, const char *file, unsigned long line)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "{free: %p} %s:%lu\n", ptr, file, line);
|
|
||||||
|
|
||||||
if (ptr != NULL)
|
|
||||||
free (ptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *debugging_strdup (const char *s, const char *file, unsigned long line)
|
|
||||||
{
|
|
||||||
char *ptr;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
assert (s != NULL);
|
|
||||||
|
|
||||||
len = strlen (s) + 1;
|
|
||||||
ptr = (char *) malloc (len);
|
|
||||||
if (!ptr)
|
|
||||||
return NULL;
|
|
||||||
memcpy (ptr, s, len);
|
|
||||||
|
|
||||||
fprintf (stderr, "{strdup: %p:%lu} %s:%lu\n", ptr,
|
|
||||||
(unsigned long) len, file, line);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* !NDEBUG */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate a block of memory in the "shared" memory region.
|
|
||||||
*
|
|
||||||
* FIXME: This uses the most basic (and slowest) means of creating a
|
|
||||||
* shared memory location. It requires the use of a temporary file. We might
|
|
||||||
* want to look into something like MM (Shared Memory Library) for a better
|
|
||||||
* solution.
|
|
||||||
*/
|
|
||||||
void *malloc_shared_memory (size_t size)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
void *ptr;
|
|
||||||
char buffer[32];
|
|
||||||
|
|
||||||
static const char *shared_file = "/tmp/tinyproxy.shared.XXXXXX";
|
|
||||||
|
|
||||||
assert (size > 0);
|
|
||||||
|
|
||||||
strlcpy (buffer, shared_file, sizeof (buffer));
|
|
||||||
|
|
||||||
/* Only allow u+rw bits. This may be required for some versions
|
|
||||||
* of glibc so that mkstemp() doesn't make us vulnerable.
|
|
||||||
*/
|
|
||||||
umask (0177);
|
|
||||||
|
|
||||||
if ((fd = mkstemp (buffer)) == -1)
|
|
||||||
return MAP_FAILED;
|
|
||||||
unlink (buffer);
|
|
||||||
|
|
||||||
if (ftruncate (fd, size) == -1)
|
|
||||||
return MAP_FAILED;
|
|
||||||
ptr = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate a block of memory from the "shared" region an initialize it to
|
|
||||||
* zero.
|
|
||||||
*/
|
|
||||||
void *calloc_shared_memory (size_t nmemb, size_t size)
|
|
||||||
{
|
|
||||||
void *ptr;
|
|
||||||
long length;
|
|
||||||
|
|
||||||
assert (nmemb > 0);
|
|
||||||
assert (size > 0);
|
|
||||||
|
|
||||||
length = nmemb * size;
|
|
||||||
|
|
||||||
ptr = malloc_shared_memory (length);
|
|
||||||
if (ptr == MAP_FAILED)
|
|
||||||
return ptr;
|
|
||||||
|
|
||||||
memset (ptr, 0, length);
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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 'heap.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_HEAP_H
|
|
||||||
#define TINYPROXY_HEAP_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The following is to allow for better memory checking.
|
|
||||||
*/
|
|
||||||
#ifndef NDEBUG
|
|
||||||
|
|
||||||
extern void *debugging_calloc (size_t nmemb, size_t size, const char *file,
|
|
||||||
unsigned long line);
|
|
||||||
extern void *debugging_malloc (size_t size, const char *file,
|
|
||||||
unsigned long line);
|
|
||||||
extern void debugging_free (void *ptr, const char *file, unsigned long line);
|
|
||||||
extern void *debugging_realloc (void *ptr, size_t size, const char *file,
|
|
||||||
unsigned long line);
|
|
||||||
extern char *debugging_strdup (const char *s, const char *file,
|
|
||||||
unsigned long line);
|
|
||||||
|
|
||||||
# define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
|
|
||||||
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
|
|
||||||
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
|
|
||||||
# define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
|
|
||||||
# define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL)
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
# define safecalloc(x, y) calloc(x, y)
|
|
||||||
# define safemalloc(x) malloc(x)
|
|
||||||
# define saferealloc(x, y) realloc(x, y)
|
|
||||||
# define safefree(x) (free (x), *(&(x)) = NULL)
|
|
||||||
# define safestrdup(x) strdup(x)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate memory from the "shared" region of memory.
|
|
||||||
*/
|
|
||||||
extern void *malloc_shared_memory (size_t size);
|
|
||||||
extern void *calloc_shared_memory (size_t nmemb, size_t size);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,317 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2003 Steven Young <sdyoung@miranda.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This file contains source code for the handling and display of
|
|
||||||
* HTML error pages with variable substitution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "buffer.h"
|
|
||||||
#include "conns.h"
|
|
||||||
#include "heap.h"
|
|
||||||
#include "html-error.h"
|
|
||||||
#include "network.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add an error number -> filename mapping to the errorpages list.
|
|
||||||
*/
|
|
||||||
#define ERRORNUM_BUFSIZE 8 /* this is more than required */
|
|
||||||
#define ERRPAGES_BUCKETCOUNT 16
|
|
||||||
|
|
||||||
int add_new_errorpage (char *filepath, unsigned int errornum)
|
|
||||||
{
|
|
||||||
char errornbuf[ERRORNUM_BUFSIZE];
|
|
||||||
|
|
||||||
config.errorpages = hashmap_create (ERRPAGES_BUCKETCOUNT);
|
|
||||||
if (!config.errorpages)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
|
|
||||||
|
|
||||||
if (hashmap_insert (config.errorpages, errornbuf,
|
|
||||||
filepath, strlen (filepath) + 1) < 0)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the file appropriate for a given error.
|
|
||||||
*/
|
|
||||||
static char *get_html_file (unsigned int errornum)
|
|
||||||
{
|
|
||||||
hashmap_iter result_iter;
|
|
||||||
char errornbuf[ERRORNUM_BUFSIZE];
|
|
||||||
char *key;
|
|
||||||
static char *val;
|
|
||||||
|
|
||||||
assert (errornum >= 100 && errornum < 1000);
|
|
||||||
|
|
||||||
if (!config.errorpages)
|
|
||||||
return (config.errorpage_undef);
|
|
||||||
|
|
||||||
snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
|
|
||||||
|
|
||||||
result_iter = hashmap_find (config.errorpages, errornbuf);
|
|
||||||
|
|
||||||
if (hashmap_is_end (config.errorpages, result_iter))
|
|
||||||
return (config.errorpage_undef);
|
|
||||||
|
|
||||||
if (hashmap_return_entry (config.errorpages, result_iter,
|
|
||||||
&key, (void **) &val) < 0)
|
|
||||||
return (config.errorpage_undef);
|
|
||||||
|
|
||||||
return (val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Look up the value for a variable.
|
|
||||||
*/
|
|
||||||
static char *lookup_variable (struct conn_s *connptr, const char *varname)
|
|
||||||
{
|
|
||||||
hashmap_iter result_iter;
|
|
||||||
char *key;
|
|
||||||
static char *data;
|
|
||||||
|
|
||||||
result_iter = hashmap_find (connptr->error_variables, varname);
|
|
||||||
|
|
||||||
if (hashmap_is_end (connptr->error_variables, result_iter))
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
if (hashmap_return_entry (connptr->error_variables, result_iter,
|
|
||||||
&key, (void **) &data) < 0)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
return (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send an already-opened file to the client with variable substitution.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
send_html_file (FILE *infile, struct conn_s *connptr)
|
|
||||||
{
|
|
||||||
char *inbuf;
|
|
||||||
char *varstart = NULL;
|
|
||||||
char *p;
|
|
||||||
const char *varval;
|
|
||||||
int in_variable = 0;
|
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
inbuf = (char *) safemalloc (4096);
|
|
||||||
|
|
||||||
while (fgets (inbuf, 4096, infile) != NULL) {
|
|
||||||
for (p = inbuf; *p; p++) {
|
|
||||||
switch (*p) {
|
|
||||||
case '}':
|
|
||||||
if (in_variable) {
|
|
||||||
*p = '\0';
|
|
||||||
varval = (const char *)
|
|
||||||
lookup_variable (connptr,
|
|
||||||
varstart);
|
|
||||||
if (!varval)
|
|
||||||
varval = "(unknown)";
|
|
||||||
r = write_message (connptr->client_fd,
|
|
||||||
"%s", varval);
|
|
||||||
in_variable = 0;
|
|
||||||
} else {
|
|
||||||
r = write_message (connptr->client_fd,
|
|
||||||
"%c", *p);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '{':
|
|
||||||
/* a {{ will print a single {. If we are NOT
|
|
||||||
* already in a { variable, then proceed with
|
|
||||||
* setup. If we ARE already in a { variable,
|
|
||||||
* this code will fallthrough to the code that
|
|
||||||
* just dumps a character to the client fd.
|
|
||||||
*/
|
|
||||||
if (!in_variable) {
|
|
||||||
varstart = p + 1;
|
|
||||||
in_variable++;
|
|
||||||
} else
|
|
||||||
in_variable = 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (!in_variable) {
|
|
||||||
r = write_message (connptr->client_fd,
|
|
||||||
"%c", *p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r)
|
|
||||||
break;
|
|
||||||
|
|
||||||
in_variable = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (inbuf);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int send_http_headers (struct conn_s *connptr, int code, const char *message)
|
|
||||||
{
|
|
||||||
const char *headers =
|
|
||||||
"HTTP/1.0 %d %s\r\n"
|
|
||||||
"Server: %s/%s\r\n"
|
|
||||||
"Content-Type: text/html\r\n" "Connection: close\r\n" "\r\n";
|
|
||||||
|
|
||||||
return (write_message (connptr->client_fd, headers,
|
|
||||||
code, message, PACKAGE, VERSION));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Display an error to the client.
|
|
||||||
*/
|
|
||||||
int send_http_error_message (struct conn_s *connptr)
|
|
||||||
{
|
|
||||||
char *error_file;
|
|
||||||
FILE *infile;
|
|
||||||
int ret;
|
|
||||||
const char *fallback_error =
|
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
|
||||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
|
|
||||||
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
|
|
||||||
"<html>\n"
|
|
||||||
"<head><title>%d %s</title></head>\n"
|
|
||||||
"<body>\n"
|
|
||||||
"<h1>%s</h1>\n"
|
|
||||||
"<p>%s</p>\n"
|
|
||||||
"<hr />\n"
|
|
||||||
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
|
|
||||||
"</html>\n";
|
|
||||||
|
|
||||||
send_http_headers (connptr, connptr->error_number,
|
|
||||||
connptr->error_string);
|
|
||||||
|
|
||||||
error_file = get_html_file (connptr->error_number);
|
|
||||||
if (!(infile = fopen (error_file, "r"))) {
|
|
||||||
char *detail = lookup_variable (connptr, "detail");
|
|
||||||
return (write_message (connptr->client_fd, fallback_error,
|
|
||||||
connptr->error_number,
|
|
||||||
connptr->error_string,
|
|
||||||
connptr->error_string,
|
|
||||||
detail, PACKAGE, VERSION));
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = send_html_file (infile, connptr);
|
|
||||||
fclose (infile);
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add a key -> value mapping for HTML file substitution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define ERRVAR_BUCKETCOUNT 16
|
|
||||||
|
|
||||||
int
|
|
||||||
add_error_variable (struct conn_s *connptr, const char *key, const char *val)
|
|
||||||
{
|
|
||||||
if (!connptr->error_variables)
|
|
||||||
if (!
|
|
||||||
(connptr->error_variables =
|
|
||||||
hashmap_create (ERRVAR_BUCKETCOUNT)))
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
return hashmap_insert (connptr->error_variables, key, val,
|
|
||||||
strlen (val) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ADD_VAR_RET(x, y) \
|
|
||||||
do { \
|
|
||||||
if (y == NULL) \
|
|
||||||
break; \
|
|
||||||
if (add_error_variable(connptr, x, y) < 0) \
|
|
||||||
return -1; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set some standard variables used by all HTML pages
|
|
||||||
*/
|
|
||||||
int add_standard_vars (struct conn_s *connptr)
|
|
||||||
{
|
|
||||||
char errnobuf[16];
|
|
||||||
char timebuf[30];
|
|
||||||
time_t global_time;
|
|
||||||
|
|
||||||
snprintf (errnobuf, sizeof errnobuf, "%d", connptr->error_number);
|
|
||||||
ADD_VAR_RET ("errno", errnobuf);
|
|
||||||
|
|
||||||
ADD_VAR_RET ("cause", connptr->error_string);
|
|
||||||
ADD_VAR_RET ("request", connptr->request_line);
|
|
||||||
ADD_VAR_RET ("clientip", connptr->client_ip_addr);
|
|
||||||
ADD_VAR_RET ("clienthost", connptr->client_string_addr);
|
|
||||||
|
|
||||||
/* The following value parts are all non-NULL and will
|
|
||||||
* trigger warnings in ADD_VAR_RET(), so we use
|
|
||||||
* add_error_variable() directly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
global_time = time (NULL);
|
|
||||||
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
|
|
||||||
gmtime (&global_time));
|
|
||||||
add_error_variable (connptr, "date", timebuf);
|
|
||||||
|
|
||||||
add_error_variable (connptr, "website",
|
|
||||||
"https://banu.com/tinyproxy/");
|
|
||||||
add_error_variable (connptr, "version", VERSION);
|
|
||||||
add_error_variable (connptr, "package", PACKAGE);
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add the error information to the conn structure.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
indicate_http_error (struct conn_s *connptr, int number,
|
|
||||||
const char *message, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char *key, *val;
|
|
||||||
|
|
||||||
va_start (ap, message);
|
|
||||||
|
|
||||||
while ((key = va_arg (ap, char *))) {
|
|
||||||
val = va_arg (ap, char *);
|
|
||||||
|
|
||||||
if (add_error_variable (connptr, key, val) == -1) {
|
|
||||||
va_end (ap);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
connptr->error_number = number;
|
|
||||||
connptr->error_string = safestrdup (message);
|
|
||||||
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
return (add_standard_vars (connptr));
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2003 Steven Young <sdyoung@miranda.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* See 'html-error.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_HTML_ERROR_H
|
|
||||||
#define TINYPROXY_HTML_ERROR_H
|
|
||||||
|
|
||||||
/* Forward declaration */
|
|
||||||
struct conn_s;
|
|
||||||
|
|
||||||
extern int add_new_errorpage (char *filepath, unsigned int errornum);
|
|
||||||
extern int send_http_error_message (struct conn_s *connptr);
|
|
||||||
extern int indicate_http_error (struct conn_s *connptr, int number,
|
|
||||||
const char *message, ...);
|
|
||||||
extern int add_error_variable (struct conn_s *connptr, const char *key,
|
|
||||||
const char *val);
|
|
||||||
extern int send_html_file (FILE * infile, struct conn_s *connptr);
|
|
||||||
extern int send_http_headers (struct conn_s *connptr, int code,
|
|
||||||
const char *message);
|
|
||||||
extern int add_standard_vars (struct conn_s *connptr);
|
|
||||||
|
|
||||||
#endif /* !TINYPROXY_HTML_ERROR_H */
|
|
||||||
@@ -1,271 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2003 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* See 'http-message.h' for detailed information. */
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "heap.h"
|
|
||||||
#include "http-message.h"
|
|
||||||
#include "network.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Package up an HTTP message into a nice little structure. As you can
|
|
||||||
* see this structure doesn't actually store any allocated strings;
|
|
||||||
* therefore, the caller must free any memory referenced by this struct.
|
|
||||||
* Also, the caller MUST NOT free the memory while the structure is
|
|
||||||
* still in use---bad things would happen.
|
|
||||||
*/
|
|
||||||
struct http_message_s {
|
|
||||||
/* Response string and code supplied on the HTTP status line */
|
|
||||||
struct {
|
|
||||||
const char *string;
|
|
||||||
int code;
|
|
||||||
} response;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A group of headers to be sent with this message. Right now
|
|
||||||
* the strings are referenced through pointers in an array.
|
|
||||||
* I might change this to a vector in the future.
|
|
||||||
*/
|
|
||||||
struct {
|
|
||||||
const char **strings;
|
|
||||||
unsigned int total;
|
|
||||||
unsigned int used;
|
|
||||||
} headers;
|
|
||||||
|
|
||||||
/* Body of the message (most likely an HTML message) */
|
|
||||||
struct {
|
|
||||||
const char *text;
|
|
||||||
size_t length;
|
|
||||||
} body;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if the HTTP message is validly formed. This is the one odd-ball
|
|
||||||
* function. It returns 0 if the message is invalid; otherwise, a positive
|
|
||||||
* number is returned. Useful for if() tests and assert() tests.
|
|
||||||
*/
|
|
||||||
static int is_http_message_valid (http_message_t msg)
|
|
||||||
{
|
|
||||||
if (msg == NULL)
|
|
||||||
return 0;
|
|
||||||
if (msg->headers.strings == NULL)
|
|
||||||
return 0;
|
|
||||||
if (msg->response.string == NULL)
|
|
||||||
return 0;
|
|
||||||
if (msg->response.code < 1 || msg->response.code > 999)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initially allocate space for 128 headers */
|
|
||||||
#define NUMBER_OF_HEADERS 128
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate a new http_message structure on the heap.
|
|
||||||
* If memory could not be allocated, return a NULL.
|
|
||||||
*/
|
|
||||||
http_message_t
|
|
||||||
http_message_create (int response_code, const char *response_string)
|
|
||||||
{
|
|
||||||
http_message_t msg;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
msg =
|
|
||||||
(struct http_message_s *) safecalloc (1,
|
|
||||||
sizeof (struct
|
|
||||||
http_message_s));
|
|
||||||
if (msg == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
msg->headers.strings = (const char **) safecalloc (NUMBER_OF_HEADERS,
|
|
||||||
sizeof (char *));
|
|
||||||
if (msg->headers.strings == NULL) {
|
|
||||||
safefree (msg);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg->headers.total = NUMBER_OF_HEADERS;
|
|
||||||
|
|
||||||
/* Store the HTTP response information in the structure */
|
|
||||||
ret = http_message_set_response (msg, response_code, response_string);
|
|
||||||
if (IS_HTTP_MSG_ERROR (ret)) {
|
|
||||||
safefree (msg->headers.strings);
|
|
||||||
safefree (msg);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Free up the space associated with this HTTP message structure.
|
|
||||||
* This DOES NOT free the pointers stored in this structure. That memory
|
|
||||||
* is the responsibility of the caller.
|
|
||||||
*/
|
|
||||||
int http_message_destroy (http_message_t msg)
|
|
||||||
{
|
|
||||||
assert (msg != NULL);
|
|
||||||
assert (msg->headers.strings != NULL);
|
|
||||||
|
|
||||||
/* Check for valid arguments */
|
|
||||||
if (msg == NULL)
|
|
||||||
return -EFAULT;
|
|
||||||
|
|
||||||
if (msg->headers.strings != NULL)
|
|
||||||
safefree (msg->headers.strings);
|
|
||||||
safefree (msg);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the HTTP response information for this structure. The response_string
|
|
||||||
* must be a NUL ('\0') terminated C string.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
http_message_set_response (http_message_t msg,
|
|
||||||
int response_code, const char *response_string)
|
|
||||||
{
|
|
||||||
/* Check for valid arguments */
|
|
||||||
if (msg == NULL)
|
|
||||||
return -EFAULT;
|
|
||||||
if (response_code < 1 || response_code > 999)
|
|
||||||
return -EINVAL;
|
|
||||||
if (response_string == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
if (strlen (response_string) == 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
msg->response.code = response_code;
|
|
||||||
msg->response.string = response_string;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the HTTP message body.
|
|
||||||
*/
|
|
||||||
int http_message_set_body (http_message_t msg, const char *body, size_t len)
|
|
||||||
{
|
|
||||||
/* Check for valid arguments */
|
|
||||||
if (msg == NULL)
|
|
||||||
return -EFAULT;
|
|
||||||
if (body == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
if (len == 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
msg->body.text = body;
|
|
||||||
msg->body.length = len;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add headers to the structure.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
http_message_add_headers (http_message_t msg, const char **headers,
|
|
||||||
unsigned int num_headers)
|
|
||||||
{
|
|
||||||
const char **new_headers;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
/* Check for valid arguments */
|
|
||||||
if (msg == NULL)
|
|
||||||
return -EFAULT;
|
|
||||||
if (headers == NULL)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the number of headers to add is greater than the space
|
|
||||||
* available, reallocate the memory.
|
|
||||||
*/
|
|
||||||
if (msg->headers.used + num_headers > msg->headers.total) {
|
|
||||||
new_headers =
|
|
||||||
(const char **) safecalloc (msg->headers.total * 2,
|
|
||||||
sizeof (char *));
|
|
||||||
if (new_headers == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
/* Copy the array */
|
|
||||||
for (i = 0; i != msg->headers.used; ++i)
|
|
||||||
new_headers[i] = msg->headers.strings[i];
|
|
||||||
|
|
||||||
/* Remove the old array and replace it with the new array */
|
|
||||||
safefree (msg->headers.strings);
|
|
||||||
msg->headers.strings = new_headers;
|
|
||||||
msg->headers.total *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add the new headers to the structure
|
|
||||||
*/
|
|
||||||
for (i = 0; i != num_headers; ++i)
|
|
||||||
msg->headers.strings[i + msg->headers.used] = headers[i];
|
|
||||||
msg->headers.used += num_headers;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send the completed HTTP message via the supplied file descriptor.
|
|
||||||
*/
|
|
||||||
int http_message_send (http_message_t msg, int fd)
|
|
||||||
{
|
|
||||||
char timebuf[30];
|
|
||||||
time_t global_time;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
assert (is_http_message_valid (msg));
|
|
||||||
|
|
||||||
/* Check for valid arguments */
|
|
||||||
if (msg == NULL)
|
|
||||||
return -EFAULT;
|
|
||||||
if (fd < 1)
|
|
||||||
return -EBADF;
|
|
||||||
if (!is_http_message_valid (msg))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* Write the response line */
|
|
||||||
write_message (fd, "HTTP/1.0 %d %s\r\n",
|
|
||||||
msg->response.code, msg->response.string);
|
|
||||||
|
|
||||||
/* Go through all the headers */
|
|
||||||
for (i = 0; i != msg->headers.used; ++i)
|
|
||||||
write_message (fd, "%s\r\n", msg->headers.strings[i]);
|
|
||||||
|
|
||||||
/* Output the date */
|
|
||||||
global_time = time (NULL);
|
|
||||||
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
|
|
||||||
gmtime (&global_time));
|
|
||||||
write_message (fd, "Date: %s\r\n", timebuf);
|
|
||||||
|
|
||||||
/* Output the content-length */
|
|
||||||
write_message (fd, "Content-length: %u\r\n", msg->body.length);
|
|
||||||
|
|
||||||
/* Write the separator between the headers and body */
|
|
||||||
safe_write (fd, "\r\n", 2);
|
|
||||||
|
|
||||||
/* If there's a body, send it! */
|
|
||||||
if (msg->body.length > 0)
|
|
||||||
safe_write (fd, msg->body.text, msg->body.length);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2003 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* HTTP Message API
|
|
||||||
* ----------------
|
|
||||||
* The idea behind this application programming interface (API) is to
|
|
||||||
* represent an HTTP response message as a concrete entity. The API
|
|
||||||
* functions allow the message to be built up systematically before
|
|
||||||
* transmission to a connected socket.
|
|
||||||
*
|
|
||||||
* The order of the functions in your program would look something like
|
|
||||||
* this:
|
|
||||||
* http_message_create()
|
|
||||||
* http_message_set_response()
|
|
||||||
* http_message_set_body() [optional if no body is required]
|
|
||||||
* http_message_add_headers() [optional if no additional headers are used]
|
|
||||||
* http_message_send()
|
|
||||||
* http_message_destroy()
|
|
||||||
*
|
|
||||||
* NOTE: No user data is stored in the http_message_t type; therefore,
|
|
||||||
* do not delete strings referenced by the http_message_t object
|
|
||||||
* before you call http_message_destroy(). By not copying data, the
|
|
||||||
* API functions are faster, but you must take greater care.
|
|
||||||
*
|
|
||||||
* (Side note: be _very_ careful when using stack allocated memory with
|
|
||||||
* this API. Bad things will happen if you try to pass the
|
|
||||||
* http_message_t out of the calling function since the stack
|
|
||||||
* allocated memory referenced by the http_message_t will no long
|
|
||||||
* exist.)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TINYPROXY_HTTP_MESSAGE_H_
|
|
||||||
#define _TINYPROXY_HTTP_MESSAGE_H_
|
|
||||||
|
|
||||||
/* Use the "http_message_t" as a cookie or handle to the structure. */
|
|
||||||
typedef struct http_message_s *http_message_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Macro to test if an error occurred with the API. All the HTTP message
|
|
||||||
* functions will return 0 if no error occurred, or a negative number if
|
|
||||||
* there was a problem.
|
|
||||||
*/
|
|
||||||
#define IS_HTTP_MSG_ERROR(x) (x < 0)
|
|
||||||
|
|
||||||
/* Initialize the internal structure of the HTTP message */
|
|
||||||
extern http_message_t http_message_create (int response_code,
|
|
||||||
const char *response_string);
|
|
||||||
|
|
||||||
/* Free up an _internal_ resources */
|
|
||||||
extern int http_message_destroy (http_message_t msg);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send an HTTP message via the supplied file descriptor. This function
|
|
||||||
* will add the "Date" header before it's sent.
|
|
||||||
*/
|
|
||||||
extern int http_message_send (http_message_t msg, int fd);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Change the internal state of the HTTP message. Either set the
|
|
||||||
* body of the message, update the response information, or
|
|
||||||
* add a new set of headers.
|
|
||||||
*/
|
|
||||||
extern int http_message_set_body (http_message_t msg,
|
|
||||||
const char *body, size_t len);
|
|
||||||
extern int http_message_set_response (http_message_t msg,
|
|
||||||
int response_code,
|
|
||||||
const char *response_string);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the headers for this HTTP message. Each string must be NUL ('\0')
|
|
||||||
* terminated, but DO NOT include any carriage returns (CR) or
|
|
||||||
* line-feeds (LF) since they will be included when the http_message is
|
|
||||||
* sent.
|
|
||||||
*/
|
|
||||||
extern int http_message_add_headers (http_message_t msg,
|
|
||||||
const char **headers,
|
|
||||||
unsigned int num_headers);
|
|
||||||
|
|
||||||
#endif /* _TINYPROXY_HTTP_MESSAGE_H_ */
|
|
||||||
@@ -1,297 +1,103 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: log.c,v 1.6 2001-06-02 03:38:02 rjkaes Exp $
|
||||||
* 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
|
* Logs the various messages which tinyproxy produces to either a log file or
|
||||||
* it under the terms of the GNU General Public License as published by
|
* the syslog daemon. Not much to it...
|
||||||
* 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,
|
* Copyright (C) 1998 Steven Young
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* 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
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Logs the various messages which tinyproxy produces to either a log file
|
#include "tinyproxy.h"
|
||||||
* or the syslog daemon. Not much to it...
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "heap.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "vector.h"
|
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
static const char *syslog_level[] = {
|
static char *syslog_level[] = {
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
"CRITICAL",
|
"CRITICAL",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
"WARNING",
|
"WARNING",
|
||||||
"NOTICE",
|
"NOTICE",
|
||||||
"INFO",
|
"INFO",
|
||||||
"DEBUG",
|
"DEBUG"
|
||||||
"CONNECT"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TIME_LENGTH 16
|
#define TIME_LENGTH 16
|
||||||
#define STRING_LENGTH 800
|
#define STRING_LENGTH 800
|
||||||
|
|
||||||
/*
|
|
||||||
* Global file descriptor for the log file
|
|
||||||
*/
|
|
||||||
int log_file_fd = -1;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Store the log level setting.
|
* Store the log level setting.
|
||||||
*/
|
*/
|
||||||
static int log_level = LOG_INFO;
|
static short int log_level = LOG_ERR;
|
||||||
|
|
||||||
/*
|
|
||||||
* Hold a listing of log messages which need to be sent once the log
|
|
||||||
* file has been established.
|
|
||||||
* The key is the actual messages (already filled in full), and the value
|
|
||||||
* is the log level.
|
|
||||||
*/
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
int open_log_file (const char *log_file_name)
|
|
||||||
{
|
|
||||||
log_file_fd = create_file_safely (log_file_name, FALSE);
|
|
||||||
return log_file_fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Close the log file
|
|
||||||
*/
|
|
||||||
void close_log_file (void)
|
|
||||||
{
|
|
||||||
if (log_file_fd < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
close (log_file_fd);
|
|
||||||
log_file_fd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the log level for writing to the log file.
|
* Set the log level for writing to the log file.
|
||||||
*/
|
*/
|
||||||
void set_log_level (int level)
|
void set_log_level(short int level)
|
||||||
{
|
{
|
||||||
log_level = level;
|
log_level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine logs messages to either the log file or the syslog function.
|
* This routine logs messages to either the log file or the syslog function.
|
||||||
*/
|
*/
|
||||||
void log_message (int level, const char *fmt, ...)
|
void log_message(short int level, char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
time_t nowtime;
|
time_t nowtime;
|
||||||
|
FILE *cf;
|
||||||
|
|
||||||
char time_string[TIME_LENGTH];
|
char time_string[TIME_LENGTH];
|
||||||
char str[STRING_LENGTH];
|
#if defined(HAVE_SYSLOG_H) && !defined(HAVE_VSYSLOG_H)
|
||||||
|
char str[STRING_LENGTH];
|
||||||
ssize_t ret;
|
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
/*
|
|
||||||
* Figure out if we should write the message or not.
|
|
||||||
*/
|
|
||||||
if (log_level == LOG_CONN) {
|
|
||||||
if (level == LOG_INFO)
|
|
||||||
return;
|
|
||||||
} else if (log_level == LOG_INFO) {
|
|
||||||
if (level > LOG_INFO && level != LOG_CONN)
|
|
||||||
return;
|
|
||||||
} else if (level > log_level)
|
|
||||||
return;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (config.syslog && level == LOG_CONN)
|
/*
|
||||||
level = LOG_INFO;
|
* Figure out if we should write the message or not.
|
||||||
|
*/
|
||||||
|
if (level > log_level)
|
||||||
|
return;
|
||||||
|
|
||||||
va_start (args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
/*
|
#ifdef HAVE_SYSLOG_H
|
||||||
* If the config file hasn't been processed, then we need to store
|
if (config.syslog) {
|
||||||
* the messages for later processing.
|
# ifdef HAVE_VSYSLOG_H
|
||||||
*/
|
vsyslog(level, fmt, args);
|
||||||
if (!logging_initialized) {
|
# else
|
||||||
char *entry_buffer;
|
vsnprintf(str, STRING_LENGTH, fmt, args);
|
||||||
|
syslog(level, str);
|
||||||
if (!log_message_storage) {
|
# endif
|
||||||
log_message_storage = vector_create ();
|
} else {
|
||||||
if (!log_message_storage)
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
vsnprintf (str, STRING_LENGTH, fmt, args);
|
|
||||||
|
|
||||||
entry_buffer = (char *) safemalloc (strlen (str) + 6);
|
|
||||||
if (!entry_buffer)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
sprintf (entry_buffer, "%d %s", level, str);
|
|
||||||
vector_append (log_message_storage, entry_buffer,
|
|
||||||
strlen (entry_buffer) + 1);
|
|
||||||
|
|
||||||
safefree (entry_buffer);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.syslog) {
|
|
||||||
#ifdef HAVE_VSYSLOG_H
|
|
||||||
vsyslog (level, fmt, args);
|
|
||||||
#else
|
|
||||||
vsnprintf (str, STRING_LENGTH, fmt, args);
|
|
||||||
syslog (level, "%s", str);
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
nowtime = time(NULL);
|
||||||
char *p;
|
/* Format is month day hour:minute:second (24 time) */
|
||||||
|
strftime(time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
||||||
|
localtime(&nowtime));
|
||||||
|
|
||||||
nowtime = time (NULL);
|
if (!(cf = config.logf))
|
||||||
/* Format is month day hour:minute:second (24 time) */
|
cf = stderr;
|
||||||
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
|
||||||
localtime (&nowtime));
|
|
||||||
|
|
||||||
snprintf (str, STRING_LENGTH, "%-9s %s [%ld]: ",
|
fprintf(cf, "%-9s %s [%u]: ", syslog_level[level],
|
||||||
syslog_level[level], time_string,
|
time_string, getpid());
|
||||||
(long int) getpid ());
|
vfprintf(cf, fmt, args);
|
||||||
|
fprintf(cf, "\n");
|
||||||
/*
|
fflush(cf);
|
||||||
* Overwrite the '\0' and leave room for a trailing '\n'
|
#ifdef HAVE_SYSLOG_H
|
||||||
* be added next.
|
}
|
||||||
*/
|
|
||||||
p = str + strlen(str);
|
|
||||||
vsnprintf (p, STRING_LENGTH - strlen(str) - 1, fmt, args);
|
|
||||||
|
|
||||||
p = str + strlen(str);
|
|
||||||
*p = '\n';
|
|
||||||
*(p+1) = '\0';
|
|
||||||
|
|
||||||
assert (log_file_fd >= 0);
|
|
||||||
|
|
||||||
ret = write (log_file_fd, str, strlen (str));
|
|
||||||
if (ret == -1) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Could not write to log file");
|
|
||||||
}
|
|
||||||
|
|
||||||
fsync (log_file_fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
va_end (args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This needs to send any stored log messages.
|
|
||||||
*/
|
|
||||||
void send_stored_logs (void)
|
|
||||||
{
|
|
||||||
char *string;
|
|
||||||
char *ptr;
|
|
||||||
int level;
|
|
||||||
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) {
|
|
||||||
string =
|
|
||||||
(char *) vector_getentry (log_message_storage, i, NULL);
|
|
||||||
|
|
||||||
ptr = strchr (string, ' ') + 1;
|
|
||||||
level = atoi (string);
|
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
if (log_level == LOG_CONN && level == LOG_INFO)
|
|
||||||
continue;
|
|
||||||
else if (log_level == LOG_INFO) {
|
|
||||||
if (level > LOG_INFO && level != LOG_CONN)
|
|
||||||
continue;
|
|
||||||
} else if (level > log_level)
|
|
||||||
continue;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
log_message (level, "%s", ptr);
|
va_end(args);
|
||||||
}
|
|
||||||
|
|
||||||
vector_delete (log_message_storage);
|
|
||||||
log_message_storage = NULL;
|
|
||||||
|
|
||||||
log_message(LOG_DEBUG, "done sending stored logs");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the logging subsystem, based on the configuration.
|
|
||||||
* Returns 0 upon success, -1 upon failure.
|
|
||||||
*
|
|
||||||
* This function uses fprintf() instead of log_message(), since
|
|
||||||
* the logging is not yet set up...
|
|
||||||
*/
|
|
||||||
int setup_logging (void)
|
|
||||||
{
|
|
||||||
if (!config.syslog) {
|
|
||||||
if (open_log_file (config.logf_name) < 0) {
|
|
||||||
/*
|
|
||||||
* If opening the log file fails, we try
|
|
||||||
* to fall back to syslog logging...
|
|
||||||
*/
|
|
||||||
config.syslog = TRUE;
|
|
||||||
|
|
||||||
log_message (LOG_CRIT, "ERROR: Could not create log "
|
|
||||||
"file %s: %s.\n",
|
|
||||||
config.logf_name, strerror (errno));
|
|
||||||
log_message (LOG_CRIT,
|
|
||||||
"Falling back to syslog logging\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.syslog) {
|
|
||||||
if (config.godaemon == TRUE)
|
|
||||||
openlog ("tinyproxy", LOG_PID, LOG_DAEMON);
|
|
||||||
else
|
|
||||||
openlog ("tinyproxy", LOG_PID, LOG_USER);
|
|
||||||
}
|
|
||||||
|
|
||||||
logging_initialized = TRUE;
|
|
||||||
send_stored_logs ();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop the logging subsystem.
|
|
||||||
*/
|
|
||||||
void shutdown_logging (void)
|
|
||||||
{
|
|
||||||
if (!logging_initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.syslog) {
|
|
||||||
closelog ();
|
|
||||||
} else {
|
|
||||||
close_log_file ();
|
|
||||||
}
|
|
||||||
|
|
||||||
logging_initialized = FALSE;
|
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,21 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: log.h,v 1.6 2001-06-02 03:09:27 rjkaes Exp $
|
||||||
* 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
|
* See 'log.c' for a detailed description.
|
||||||
* 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,
|
* Copyright (C) 1998 Steven Young
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* 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
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'log.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_LOG_H
|
#ifndef TINYPROXY_LOG_H
|
||||||
#define TINYPROXY_LOG_H
|
#define TINYPROXY_LOG_H
|
||||||
|
|
||||||
@@ -33,17 +29,14 @@
|
|||||||
* can see them below and I'll describe what each level should be for.
|
* can see them below and I'll describe what each level should be for.
|
||||||
* Hopefully tinyproxy will remain consistent with these levels.
|
* Hopefully tinyproxy will remain consistent with these levels.
|
||||||
* -- rjkaes
|
* -- rjkaes
|
||||||
* Sorry but I had to destroy the hope ;-) There was a need to log
|
|
||||||
* connections without the INFO stuff and not to have them as NOTICE.
|
|
||||||
* -- hgb
|
|
||||||
*
|
*
|
||||||
* Level Description
|
* Level Description
|
||||||
* ----- -----------
|
* ----- -----------
|
||||||
* LOG_CRIT This is catastrophic. Basically, tinyproxy can not recover
|
* LOG_CRIT This is catastrophic. Basically, tinyproxy can not recover
|
||||||
* from this and will either close the child (if we're lucky),
|
* from this and will either close the thread (if we're lucky),
|
||||||
* or the entire daemon. I would relegate this to conditions
|
* or the entire daemon. I would relegate this to conditions
|
||||||
* like unable to create the listening socket, or unable to
|
* like unable to create the listening socket, or unable to
|
||||||
* create a child. If you're going to log at this level provide
|
* create a thread. If you're going to log at this level provide
|
||||||
* as much information as possible.
|
* as much information as possible.
|
||||||
*
|
*
|
||||||
* LOG_ERR Okay, something bad happened. We can recover from this, but
|
* LOG_ERR Okay, something bad happened. We can recover from this, but
|
||||||
@@ -60,14 +53,9 @@
|
|||||||
*
|
*
|
||||||
* LOG_NOTICE This is for a special condition. Nothing has gone wrong, but
|
* LOG_NOTICE This is for a special condition. Nothing has gone wrong, but
|
||||||
* it is more important than the common LOG_INFO level. Right
|
* it is more important than the common LOG_INFO level. Right
|
||||||
* now it is used for actions like creating/destroying children,
|
* now it is used for actions like creating/destroying threads,
|
||||||
* unauthorized access, signal handling, etc.
|
* unauthorized access, signal handling, etc.
|
||||||
*
|
*
|
||||||
* LOG_CONN This additional level is for logging connections only, so
|
|
||||||
* it is easy to control only the requests in the logfile.
|
|
||||||
* If we log through syslog, this is set to LOG_INFO.
|
|
||||||
* -- hgb
|
|
||||||
*
|
|
||||||
* LOG_INFO Everything else ends up here. Logging for incoming
|
* LOG_INFO Everything else ends up here. Logging for incoming
|
||||||
* connections, denying due to filtering rules, unable to
|
* connections, denying due to filtering rules, unable to
|
||||||
* connect to remote server, etc.
|
* connect to remote server, etc.
|
||||||
@@ -88,36 +76,20 @@
|
|||||||
# define LOG_DEBUG 7
|
# define LOG_DEBUG 7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LOG_CONN 8 /* extra to log connections without the INFO stuff */
|
|
||||||
|
|
||||||
/* Suppress warnings when GCC is in -pedantic mode and not -std=c99 */
|
|
||||||
#if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
|
|
||||||
#pragma GCC system_header
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use this for debugging. The format is specific:
|
* Use this for debugging. The format is specific:
|
||||||
* DEBUG1("There was a major problem");
|
* DEBUG1("There was a major problem");
|
||||||
* DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr);
|
* DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr);
|
||||||
*/
|
*/
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
# define DEBUG1(x) \
|
# define DEBUG1(x) log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__)
|
||||||
log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__)
|
# define DEBUG2(x, y...) log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__, ## y)
|
||||||
# define DEBUG2(x, y...) \
|
|
||||||
log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__, ## y)
|
|
||||||
#else
|
#else
|
||||||
# define DEBUG1(x) do { } while(0)
|
# define DEBUG1(x) do { } while(0)
|
||||||
# define DEBUG2(x, y...) do { } while(0)
|
# define DEBUG2(x, y...) do { } while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int open_log_file (const char *file);
|
extern void log_message(short int level, char *fmt, ...);
|
||||||
extern void close_log_file (void);
|
extern void set_log_level(short int level);
|
||||||
|
|
||||||
extern void log_message (int level, const char *fmt, ...);
|
|
||||||
extern void set_log_level (int level);
|
|
||||||
extern void send_stored_logs (void);
|
|
||||||
|
|
||||||
extern int setup_logging (void);
|
|
||||||
extern void shutdown_logging (void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
-484
@@ -1,484 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
*
|
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
|
||||||
* Copyright (C) 1998-2002 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
|
|
||||||
* Copyright (C) 2009-2010 Mukund Sivaraman <muks@banu.com>
|
|
||||||
* Copyright (C) 2009-2010 Michael Adam <obnox@samba.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The initialize routine. Basically sets up all the initial stuff (logfile,
|
|
||||||
* listening socket, config options, etc.) and then sits there and loops
|
|
||||||
* over the new connections until the daemon is closed. Also has additional
|
|
||||||
* functions to handle the "user friendly" aspects of a program (usage,
|
|
||||||
* stats, etc.) Like any good program, most of the work is actually done
|
|
||||||
* elsewhere.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "anonymous.h"
|
|
||||||
#include "buffer.h"
|
|
||||||
#include "conf.h"
|
|
||||||
#include "daemon.h"
|
|
||||||
#include "heap.h"
|
|
||||||
#include "filter.h"
|
|
||||||
#include "child.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "reqs.h"
|
|
||||||
#include "sock.h"
|
|
||||||
#include "stats.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Global Structures
|
|
||||||
*/
|
|
||||||
struct config_s config;
|
|
||||||
struct config_s config_defaults;
|
|
||||||
unsigned int received_sighup = FALSE; /* boolean */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Handle a signal
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
takesig (int sig)
|
|
||||||
{
|
|
||||||
pid_t pid;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
switch (sig) {
|
|
||||||
case SIGHUP:
|
|
||||||
received_sighup = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SIGTERM:
|
|
||||||
config.quit = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SIGCHLD:
|
|
||||||
while ((pid = waitpid (-1, &status, WNOHANG)) > 0) ;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Display the version information for the user.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
display_version (void)
|
|
||||||
{
|
|
||||||
printf ("%s %s\n", PACKAGE, VERSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Display the copyright and license for this program.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
display_license (void)
|
|
||||||
{
|
|
||||||
display_version ();
|
|
||||||
|
|
||||||
printf ("\
|
|
||||||
Copyright 1998 Steven Young (sdyoung@well.com)\n\
|
|
||||||
Copyright 1998-2002 Robert James Kaes (rjkaes@users.sourceforge.net)\n\
|
|
||||||
Copyright 1999 George Talusan (gstalusan@uwaterloo.ca)\n\
|
|
||||||
Copyright 2000 Chris Lightfoot (chris@ex-parrot.com)\n\
|
|
||||||
Copyright 2009-2010 Mukund Sivaraman (muks@banu.com)\n\
|
|
||||||
Copyright 2009-2010 Michael Adam (obnox@samba.org)\n\
|
|
||||||
\n\
|
|
||||||
This program is free software; you can redistribute it and/or modify\n\
|
|
||||||
it under the terms of the GNU General Public License as published by\n\
|
|
||||||
the Free Software Foundation; either version 2, or (at your option)\n\
|
|
||||||
any later version.\n\
|
|
||||||
\n\
|
|
||||||
This program is distributed in the hope that it will be useful,\n\
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
|
|
||||||
GNU General Public License for more details.\n\
|
|
||||||
\n\
|
|
||||||
You should have received a copy of the GNU General Public License\n\
|
|
||||||
along with this program; if not, write to the Free Software\n\
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Display usage to the user.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
display_usage (void)
|
|
||||||
{
|
|
||||||
int features = 0;
|
|
||||||
|
|
||||||
printf ("Usage: %s [options]\n", PACKAGE);
|
|
||||||
printf ("\n"
|
|
||||||
"Options are:\n"
|
|
||||||
" -d Do not daemonize (run in foreground).\n"
|
|
||||||
" -c FILE Use an alternate configuration file.\n"
|
|
||||||
" -h Display this usage information.\n"
|
|
||||||
" -l Display the license.\n"
|
|
||||||
" -v Display version information.\n");
|
|
||||||
|
|
||||||
/* Display the modes compiled into tinyproxy */
|
|
||||||
printf ("\nFeatures compiled in:\n");
|
|
||||||
|
|
||||||
#ifdef XTINYPROXY_ENABLE
|
|
||||||
printf (" XTinyproxy header\n");
|
|
||||||
features++;
|
|
||||||
#endif /* XTINYPROXY */
|
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
|
||||||
printf (" Filtering\n");
|
|
||||||
features++;
|
|
||||||
#endif /* FILTER_ENABLE */
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
printf (" Debugging code\n");
|
|
||||||
features++;
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
|
|
||||||
#ifdef TRANSPARENT_PROXY
|
|
||||||
printf (" Transparent proxy support\n");
|
|
||||||
features++;
|
|
||||||
#endif /* TRANSPARENT_PROXY */
|
|
||||||
|
|
||||||
#ifdef REVERSE_SUPPORT
|
|
||||||
printf (" Reverse proxy support\n");
|
|
||||||
features++;
|
|
||||||
#endif /* REVERSE_SUPPORT */
|
|
||||||
|
|
||||||
#ifdef UPSTREAM_SUPPORT
|
|
||||||
printf (" Upstream proxy support\n");
|
|
||||||
features++;
|
|
||||||
#endif /* UPSTREAM_SUPPORT */
|
|
||||||
|
|
||||||
if (0 == features)
|
|
||||||
printf (" None\n");
|
|
||||||
|
|
||||||
printf ("\n"
|
|
||||||
"For bug reporting instructions, please see:\n"
|
|
||||||
"<https://banu.com/tinyproxy/>.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
get_id (char *str)
|
|
||||||
{
|
|
||||||
char *tstr;
|
|
||||||
|
|
||||||
if (str == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
tstr = str;
|
|
||||||
while (*tstr != 0) {
|
|
||||||
if (!isdigit (*tstr))
|
|
||||||
return -1;
|
|
||||||
tstr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return atoi (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* process_cmdline:
|
|
||||||
* @argc: argc as passed to main()
|
|
||||||
* @argv: argv as passed to main()
|
|
||||||
*
|
|
||||||
* This function parses command line arguments.
|
|
||||||
**/
|
|
||||||
static void
|
|
||||||
process_cmdline (int argc, char **argv, struct config_s *conf)
|
|
||||||
{
|
|
||||||
int opt;
|
|
||||||
|
|
||||||
while ((opt = getopt (argc, argv, "c:vldh")) != EOF) {
|
|
||||||
switch (opt) {
|
|
||||||
case 'v':
|
|
||||||
display_version ();
|
|
||||||
exit (EX_OK);
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
display_license ();
|
|
||||||
exit (EX_OK);
|
|
||||||
|
|
||||||
case 'd':
|
|
||||||
conf->godaemon = FALSE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'c':
|
|
||||||
if (conf->config_file != NULL) {
|
|
||||||
safefree (conf->config_file);
|
|
||||||
}
|
|
||||||
conf->config_file = safestrdup (optarg);
|
|
||||||
if (!conf->config_file) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Could not allocate memory.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'h':
|
|
||||||
display_usage ();
|
|
||||||
exit (EX_OK);
|
|
||||||
|
|
||||||
default:
|
|
||||||
display_usage ();
|
|
||||||
exit (EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* change_user:
|
|
||||||
* @program: The name of the program. Pass argv[0] here.
|
|
||||||
*
|
|
||||||
* This function tries to change UID and GID to the ones specified in
|
|
||||||
* the config file. This function is typically called during
|
|
||||||
* initialization when the effective user is root.
|
|
||||||
**/
|
|
||||||
static void
|
|
||||||
change_user (const char *program)
|
|
||||||
{
|
|
||||||
if (config.group && strlen (config.group) > 0) {
|
|
||||||
int gid = get_id (config.group);
|
|
||||||
|
|
||||||
if (gid < 0) {
|
|
||||||
struct group *thisgroup = getgrnam (config.group);
|
|
||||||
|
|
||||||
if (!thisgroup) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Unable to find group \"%s\".\n",
|
|
||||||
program, config.group);
|
|
||||||
exit (EX_NOUSER);
|
|
||||||
}
|
|
||||||
|
|
||||||
gid = thisgroup->gr_gid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setgid (gid) < 0) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Unable to change to group \"%s\".\n",
|
|
||||||
program, config.group);
|
|
||||||
exit (EX_NOPERM);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message (LOG_INFO, "Now running as group \"%s\".",
|
|
||||||
config.group);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.user && strlen (config.user) > 0) {
|
|
||||||
int uid = get_id (config.user);
|
|
||||||
|
|
||||||
if (uid < 0) {
|
|
||||||
struct passwd *thisuser = getpwnam (config.user);
|
|
||||||
|
|
||||||
if (!thisuser) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Unable to find user \"%s\".\n",
|
|
||||||
program, config.user);
|
|
||||||
exit (EX_NOUSER);
|
|
||||||
}
|
|
||||||
|
|
||||||
uid = thisuser->pw_uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setuid (uid) < 0) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Unable to change to user \"%s\".\n",
|
|
||||||
program, config.user);
|
|
||||||
exit (EX_NOPERM);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message (LOG_INFO, "Now running as user \"%s\".",
|
|
||||||
config.user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void initialize_config_defaults (struct config_s *conf)
|
|
||||||
{
|
|
||||||
memset (conf, 0, sizeof(*conf));
|
|
||||||
|
|
||||||
conf->config_file = safestrdup (SYSCONFDIR "/tinyproxy.conf");
|
|
||||||
if (!conf->config_file) {
|
|
||||||
fprintf (stderr, PACKAGE ": Could not allocate memory.\n");
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
conf->godaemon = TRUE;
|
|
||||||
/*
|
|
||||||
* Make sure the HTML error pages array is NULL to begin with.
|
|
||||||
* (FIXME: Should have a better API for all this)
|
|
||||||
*/
|
|
||||||
conf->errorpages = NULL;
|
|
||||||
conf->stathost = safestrdup (TINYPROXY_STATHOST);
|
|
||||||
conf->idletimeout = MAX_IDLE_TIME;
|
|
||||||
conf->logf_name = safestrdup (LOCALSTATEDIR "/log/tinyproxy/tinyproxy.log");
|
|
||||||
conf->pidpath = safestrdup (LOCALSTATEDIR "/run/tinyproxy/tinyproxy.pid");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* convenience wrapper around reload_config_file
|
|
||||||
* that also re-initializes logging.
|
|
||||||
*/
|
|
||||||
int reload_config (void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
shutdown_logging ();
|
|
||||||
|
|
||||||
ret = reload_config_file (config_defaults.config_file, &config,
|
|
||||||
&config_defaults);
|
|
||||||
if (ret != 0) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = setup_logging ();
|
|
||||||
|
|
||||||
done:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
/* Only allow u+rw bits. This may be required for some versions
|
|
||||||
* of glibc so that mkstemp() doesn't make us vulnerable.
|
|
||||||
*/
|
|
||||||
umask (0177);
|
|
||||||
|
|
||||||
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
|
|
||||||
|
|
||||||
if (config_compile_regex()) {
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
|
|
||||||
initialize_config_defaults (&config_defaults);
|
|
||||||
process_cmdline (argc, argv, &config_defaults);
|
|
||||||
|
|
||||||
if (reload_config_file (config_defaults.config_file,
|
|
||||||
&config,
|
|
||||||
&config_defaults)) {
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
|
|
||||||
init_stats ();
|
|
||||||
|
|
||||||
/* If ANONYMOUS is turned on, make sure that Content-Length is
|
|
||||||
* in the list of allowed headers, since it is required in a
|
|
||||||
* HTTP/1.0 request. Also add the Content-Type header since it
|
|
||||||
* goes hand in hand with Content-Length. */
|
|
||||||
if (is_anonymous_enabled ()) {
|
|
||||||
anonymous_insert ("Content-Length");
|
|
||||||
anonymous_insert ("Content-Type");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.godaemon == TRUE)
|
|
||||||
makedaemon ();
|
|
||||||
|
|
||||||
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
|
|
||||||
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_OSERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
|
||||||
if (config.filter)
|
|
||||||
filter_init ();
|
|
||||||
#endif /* FILTER_ENABLE */
|
|
||||||
|
|
||||||
/* Start listening on the selected port. */
|
|
||||||
if (child_listening_sock (config.port) < 0) {
|
|
||||||
fprintf (stderr, "%s: Could not create listening socket.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_OSERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Switch to a different user if we're running as root */
|
|
||||||
if (geteuid () == 0)
|
|
||||||
change_user (argv[0]);
|
|
||||||
else
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Not running as root, so not changing UID/GID.");
|
|
||||||
|
|
||||||
/* Create log file after we drop privileges */
|
|
||||||
if (setup_logging ()) {
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create pid file after we drop privileges */
|
|
||||||
if (config.pidpath) {
|
|
||||||
if (pidfile_create (config.pidpath) < 0) {
|
|
||||||
fprintf (stderr, "%s: Could not create PID file.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_OSERR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child_pool_create () < 0) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"%s: Could not create the pool of children.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_SOFTWARE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* These signals are only for the parent process. */
|
|
||||||
log_message (LOG_INFO, "Setting the various signals.");
|
|
||||||
|
|
||||||
if (set_signal_handler (SIGCHLD, takesig) == SIG_ERR) {
|
|
||||||
fprintf (stderr, "%s: Could not set the \"SIGCHLD\" signal.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_OSERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (set_signal_handler (SIGTERM, takesig) == SIG_ERR) {
|
|
||||||
fprintf (stderr, "%s: Could not set the \"SIGTERM\" signal.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_OSERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (set_signal_handler (SIGHUP, takesig) == SIG_ERR) {
|
|
||||||
fprintf (stderr, "%s: Could not set the \"SIGHUP\" signal.\n",
|
|
||||||
argv[0]);
|
|
||||||
exit (EX_OSERR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the main loop */
|
|
||||||
log_message (LOG_INFO, "Starting main loop. Accepting connections.");
|
|
||||||
|
|
||||||
child_main_loop ();
|
|
||||||
|
|
||||||
log_message (LOG_INFO, "Shutting down.");
|
|
||||||
|
|
||||||
child_kill_children (SIGTERM);
|
|
||||||
child_close_sock ();
|
|
||||||
|
|
||||||
/* Remove the PID file */
|
|
||||||
if (unlink (config.pidpath) < 0) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Could not remove PID file \"%s\": %s.",
|
|
||||||
config.pidpath, strerror (errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef FILTER_ENABLE
|
|
||||||
if (config.filter)
|
|
||||||
filter_destroy ();
|
|
||||||
#endif /* FILTER_ENABLE */
|
|
||||||
|
|
||||||
shutdown_logging ();
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
-37
@@ -1,37 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
|
||||||
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* See 'main.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef __MAIN_H__
|
|
||||||
#define __MAIN_H__
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
/* Global variables for the main controls of the program */
|
|
||||||
#define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */
|
|
||||||
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
|
|
||||||
|
|
||||||
/* Global Structures used in the program */
|
|
||||||
extern struct config_s config;
|
|
||||||
extern unsigned int received_sighup; /* boolean */
|
|
||||||
|
|
||||||
extern int reload_config (void);
|
|
||||||
|
|
||||||
#endif /* __MAIN_H__ */
|
|
||||||
-323
@@ -1,323 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002, 2004 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The functions found here are used for communicating across a
|
|
||||||
* network. They include both safe reading and writing (which are
|
|
||||||
* the basic building blocks) along with two functions for
|
|
||||||
* easily reading a line of text from the network, and a function
|
|
||||||
* to write an arbitrary amount of data to the network.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "heap.h"
|
|
||||||
#include "network.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the buffer to the socket. If an EINTR occurs, pick up and try
|
|
||||||
* again. Keep sending until the buffer has been sent.
|
|
||||||
*/
|
|
||||||
ssize_t safe_write (int fd, const char *buffer, size_t count)
|
|
||||||
{
|
|
||||||
ssize_t len;
|
|
||||||
size_t bytestosend;
|
|
||||||
|
|
||||||
assert (fd >= 0);
|
|
||||||
assert (buffer != NULL);
|
|
||||||
assert (count > 0);
|
|
||||||
|
|
||||||
bytestosend = count;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
len = send (fd, buffer, bytestosend, MSG_NOSIGNAL);
|
|
||||||
|
|
||||||
if (len < 0) {
|
|
||||||
if (errno == EINTR)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((size_t) len == bytestosend)
|
|
||||||
break;
|
|
||||||
|
|
||||||
buffer += len;
|
|
||||||
bytestosend -= len;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Matched pair for safe_write(). If an EINTR occurs, pick up and try
|
|
||||||
* again.
|
|
||||||
*/
|
|
||||||
ssize_t safe_read (int fd, char *buffer, size_t count)
|
|
||||||
{
|
|
||||||
ssize_t len;
|
|
||||||
|
|
||||||
do {
|
|
||||||
len = read (fd, buffer, count);
|
|
||||||
} while (len < 0 && errno == EINTR);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send a "message" to the file descriptor provided. This handles the
|
|
||||||
* differences between the various implementations of vsnprintf. This code
|
|
||||||
* was basically stolen from the snprintf() man page of Debian Linux
|
|
||||||
* (although I did fix a memory leak. :)
|
|
||||||
*/
|
|
||||||
int write_message (int fd, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
ssize_t n;
|
|
||||||
size_t size = (1024 * 8); /* start with 8 KB and go from there */
|
|
||||||
char *buf, *tmpbuf;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
if ((buf = (char *) safemalloc (size)) == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
va_start (ap, fmt);
|
|
||||||
n = vsnprintf (buf, size, fmt, ap);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
/* If that worked, break out so we can send the buffer */
|
|
||||||
if (n > -1 && (size_t) n < size)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Else, try again with more space */
|
|
||||||
if (n > -1)
|
|
||||||
/* precisely what is needed (glibc2.1) */
|
|
||||||
size = n + 1;
|
|
||||||
else
|
|
||||||
/* twice the old size (glibc2.0) */
|
|
||||||
size *= 2;
|
|
||||||
|
|
||||||
if ((tmpbuf = (char *) saferealloc (buf, size)) == NULL) {
|
|
||||||
safefree (buf);
|
|
||||||
return -1;
|
|
||||||
} else
|
|
||||||
buf = tmpbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (safe_write (fd, buf, n) < 0) {
|
|
||||||
safefree (buf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (buf);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read in a "line" from the socket. It might take a few loops through
|
|
||||||
* the read sequence. The full string is allocate off the heap and stored
|
|
||||||
* at the whole_buffer pointer. The caller needs to free the memory when
|
|
||||||
* it is no longer in use. The returned line is NULL terminated.
|
|
||||||
*
|
|
||||||
* Returns the length of the buffer on success (not including the NULL
|
|
||||||
* termination), 0 if the socket was closed, and -1 on all other errors.
|
|
||||||
*/
|
|
||||||
#define SEGMENT_LEN (512)
|
|
||||||
#define MAXIMUM_BUFFER_LENGTH (128 * 1024)
|
|
||||||
ssize_t readline (int fd, char **whole_buffer)
|
|
||||||
{
|
|
||||||
ssize_t whole_buffer_len;
|
|
||||||
char buffer[SEGMENT_LEN];
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
ssize_t ret;
|
|
||||||
ssize_t diff;
|
|
||||||
|
|
||||||
struct read_lines_s {
|
|
||||||
char *data;
|
|
||||||
size_t len;
|
|
||||||
struct read_lines_s *next;
|
|
||||||
};
|
|
||||||
struct read_lines_s *first_line, *line_ptr;
|
|
||||||
|
|
||||||
first_line =
|
|
||||||
(struct read_lines_s *) safecalloc (sizeof (struct read_lines_s),
|
|
||||||
1);
|
|
||||||
if (!first_line)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
line_ptr = first_line;
|
|
||||||
|
|
||||||
whole_buffer_len = 0;
|
|
||||||
for (;;) {
|
|
||||||
ret = recv (fd, buffer, SEGMENT_LEN, MSG_PEEK);
|
|
||||||
if (ret <= 0)
|
|
||||||
goto CLEANUP;
|
|
||||||
|
|
||||||
ptr = (char *) memchr (buffer, '\n', ret);
|
|
||||||
if (ptr)
|
|
||||||
diff = ptr - buffer + 1;
|
|
||||||
else
|
|
||||||
diff = ret;
|
|
||||||
|
|
||||||
whole_buffer_len += diff;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Don't allow the buffer to grow without bound. If we
|
|
||||||
* get to more than MAXIMUM_BUFFER_LENGTH close.
|
|
||||||
*/
|
|
||||||
if (whole_buffer_len > MAXIMUM_BUFFER_LENGTH) {
|
|
||||||
ret = -ERANGE;
|
|
||||||
goto CLEANUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
line_ptr->data = (char *) safemalloc (diff);
|
|
||||||
if (!line_ptr->data) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto CLEANUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
recv (fd, line_ptr->data, diff, 0);
|
|
||||||
line_ptr->len = diff;
|
|
||||||
|
|
||||||
if (ptr) {
|
|
||||||
line_ptr->next = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
line_ptr->next =
|
|
||||||
(struct read_lines_s *)
|
|
||||||
safecalloc (sizeof (struct read_lines_s), 1);
|
|
||||||
if (!line_ptr->next) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto CLEANUP;
|
|
||||||
}
|
|
||||||
line_ptr = line_ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
*whole_buffer = (char *) safemalloc (whole_buffer_len + 1);
|
|
||||||
if (!*whole_buffer) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto CLEANUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
*(*whole_buffer + whole_buffer_len) = '\0';
|
|
||||||
|
|
||||||
whole_buffer_len = 0;
|
|
||||||
line_ptr = first_line;
|
|
||||||
while (line_ptr) {
|
|
||||||
memcpy (*whole_buffer + whole_buffer_len, line_ptr->data,
|
|
||||||
line_ptr->len);
|
|
||||||
whole_buffer_len += line_ptr->len;
|
|
||||||
|
|
||||||
line_ptr = line_ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = whole_buffer_len;
|
|
||||||
|
|
||||||
CLEANUP:
|
|
||||||
do {
|
|
||||||
line_ptr = first_line->next;
|
|
||||||
if (first_line->data)
|
|
||||||
safefree (first_line->data);
|
|
||||||
safefree (first_line);
|
|
||||||
first_line = line_ptr;
|
|
||||||
} while (first_line);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert the network address into either a dotted-decimal or an IPv6
|
|
||||||
* hex string.
|
|
||||||
*/
|
|
||||||
char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
|
|
||||||
{
|
|
||||||
assert (sa != NULL);
|
|
||||||
assert (buf != NULL);
|
|
||||||
assert (buflen != 0);
|
|
||||||
buf[0] = '\0'; /* start with an empty string */
|
|
||||||
|
|
||||||
switch (sa->sa_family) {
|
|
||||||
case AF_INET:
|
|
||||||
{
|
|
||||||
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
|
|
||||||
|
|
||||||
inet_ntop (AF_INET, &sa_in->sin_addr, buf, buflen);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AF_INET6:
|
|
||||||
{
|
|
||||||
struct sockaddr_in6 *sa_in6 =
|
|
||||||
(struct sockaddr_in6 *) sa;
|
|
||||||
|
|
||||||
inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, buflen);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
/* no valid family */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert a numeric character string into an IPv6 network address
|
|
||||||
* (in binary form.) The function works just like inet_pton(), but it
|
|
||||||
* will accept both IPv4 and IPv6 numeric addresses.
|
|
||||||
*
|
|
||||||
* Returns the same as inet_pton().
|
|
||||||
*/
|
|
||||||
int full_inet_pton (const char *ip, void *dst)
|
|
||||||
{
|
|
||||||
char buf[24], tmp[24]; /* IPv4->IPv6 = ::FFFF:xxx.xxx.xxx.xxx\0 */
|
|
||||||
int n;
|
|
||||||
|
|
||||||
assert (ip != NULL && strlen (ip) != 0);
|
|
||||||
assert (dst != NULL);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if the string is an IPv4 numeric address. We use the
|
|
||||||
* older inet_aton() call since it handles more IPv4 numeric
|
|
||||||
* address formats.
|
|
||||||
*/
|
|
||||||
n = inet_aton (ip, (struct in_addr *) dst);
|
|
||||||
if (n == 0) {
|
|
||||||
/*
|
|
||||||
* Simple case: "ip" wasn't an IPv4 numeric address, so
|
|
||||||
* try doing the conversion as an IPv6 address. This
|
|
||||||
* will either succeed or fail, but we can't do any
|
|
||||||
* more processing anyway.
|
|
||||||
*/
|
|
||||||
return inet_pton (AF_INET6, ip, dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* "ip" was an IPv4 address, so we need to convert it to
|
|
||||||
* an IPv4-mapped IPv6 address and do the conversion
|
|
||||||
* again to get the IPv6 network structure.
|
|
||||||
*
|
|
||||||
* We convert the IPv4 binary address back into the
|
|
||||||
* standard dotted-decimal format using inet_ntop()
|
|
||||||
* so we can be sure that inet_pton will accept the
|
|
||||||
* full string.
|
|
||||||
*/
|
|
||||||
snprintf (buf, sizeof (buf), "::ffff:%s",
|
|
||||||
inet_ntop (AF_INET, dst, tmp, sizeof (tmp)));
|
|
||||||
return inet_pton (AF_INET6, buf, dst);
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002, 2004 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 'network.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_NETWORK_H
|
|
||||||
#define TINYPROXY_NETWORK_H
|
|
||||||
|
|
||||||
extern ssize_t safe_write (int fd, const char *buffer, size_t count);
|
|
||||||
extern ssize_t safe_read (int fd, char *buffer, size_t count);
|
|
||||||
|
|
||||||
extern int write_message (int fd, const char *fmt, ...);
|
|
||||||
extern ssize_t readline (int fd, char **whole_buffer);
|
|
||||||
|
|
||||||
extern char *get_ip_string (struct sockaddr *sa, char *buf, size_t len);
|
|
||||||
extern int full_inet_pton (const char *ip, void *dst);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/* $Id: regexp.h,v 1.2 2000-09-11 23:50:07 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* We need this little header to help distinguish whether to use the REGEX
|
||||||
|
* library installed in the system, or to include our own version (the GNU
|
||||||
|
* version to be exact.)
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TINYPROXY_REGEXP_H_
|
||||||
|
#define _TINYPROXY_REGEXP_H_
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_GNU_REGEX
|
||||||
|
# include "gnuregex.h"
|
||||||
|
#else
|
||||||
|
# include <regex.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
+520
-1375
File diff suppressed because it is too large.
Load diff
+14
-38
@@ -1,48 +1,24 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: reqs.h,v 1.2 2000-09-12 00:04:42 rjkaes Exp $
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
|
||||||
* Copyright (C) 1999 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* See 'reqs.c' for a detailed description.
|
||||||
* 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,
|
* Copyright (C) 1998 Steven Young
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* 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
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'reqs.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef _TINYPROXY_REQS_H_
|
#ifndef _TINYPROXY_REQS_H_
|
||||||
#define _TINYPROXY_REQS_H_
|
#define _TINYPROXY_REQS_H_
|
||||||
|
|
||||||
#include "common.h"
|
extern void handle_connection(int fd);
|
||||||
|
|
||||||
/*
|
|
||||||
* Port constants for HTTP (80) and SSL (443)
|
|
||||||
*/
|
|
||||||
#define HTTP_PORT 80
|
|
||||||
#define HTTP_PORT_SSL 443
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure holds the information pulled from a URL request.
|
|
||||||
*/
|
|
||||||
struct request_s {
|
|
||||||
char *method;
|
|
||||||
char *protocol;
|
|
||||||
|
|
||||||
char *host;
|
|
||||||
uint16_t port;
|
|
||||||
|
|
||||||
char *path;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern void handle_connection (int fd);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Allow tinyproxy to be used as a reverse proxy. */
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "reverse-proxy.h"
|
|
||||||
|
|
||||||
#include "conns.h"
|
|
||||||
#include "heap.h"
|
|
||||||
#include "html-error.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add entry to the reversepath list
|
|
||||||
*/
|
|
||||||
void reversepath_add (const char *path, const char *url,
|
|
||||||
struct reversepath **reversepath_list)
|
|
||||||
{
|
|
||||||
struct reversepath *reverse;
|
|
||||||
|
|
||||||
if (url == NULL) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Illegal reverse proxy rule: missing url");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strstr (url, "://")) {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Skipping reverse proxy rule: '%s' is not a valid url",
|
|
||||||
url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path && *path != '/') {
|
|
||||||
log_message (LOG_WARNING,
|
|
||||||
"Skipping reverse proxy rule: path '%s' "
|
|
||||||
"doesn't start with a /", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reverse = (struct reversepath *) safemalloc (sizeof
|
|
||||||
(struct reversepath));
|
|
||||||
if (!reverse) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Unable to allocate memory in reversepath_add()");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!path)
|
|
||||||
reverse->path = safestrdup ("/");
|
|
||||||
else
|
|
||||||
reverse->path = safestrdup (path);
|
|
||||||
|
|
||||||
reverse->url = safestrdup (url);
|
|
||||||
|
|
||||||
reverse->next = *reversepath_list;
|
|
||||||
*reversepath_list = reverse;
|
|
||||||
|
|
||||||
log_message (LOG_INFO,
|
|
||||||
"Added reverse proxy rule: %s -> %s", reverse->path,
|
|
||||||
reverse->url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if a request url is in the reversepath list
|
|
||||||
*/
|
|
||||||
struct reversepath *reversepath_get (char *url, struct reversepath *reverse)
|
|
||||||
{
|
|
||||||
while (reverse) {
|
|
||||||
if (strstr (url, reverse->path) == url)
|
|
||||||
return reverse;
|
|
||||||
|
|
||||||
reverse = reverse->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free a reversepath list
|
|
||||||
*/
|
|
||||||
|
|
||||||
void free_reversepath_list (struct reversepath *reverse)
|
|
||||||
{
|
|
||||||
while (reverse) {
|
|
||||||
struct reversepath *tmp = reverse;
|
|
||||||
reverse = reverse->next;
|
|
||||||
safefree (tmp->url);
|
|
||||||
safefree (tmp->path);
|
|
||||||
safefree (tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Rewrite the URL for reverse proxying.
|
|
||||||
*/
|
|
||||||
char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
|
|
||||||
char *url)
|
|
||||||
{
|
|
||||||
char *rewrite_url = NULL;
|
|
||||||
char *cookie = NULL;
|
|
||||||
char *cookieval;
|
|
||||||
struct reversepath *reverse = NULL;
|
|
||||||
|
|
||||||
/* Reverse requests always start with a slash */
|
|
||||||
if (*url == '/') {
|
|
||||||
/* First try locating the reverse mapping by request url */
|
|
||||||
reverse = reversepath_get (url, config.reversepath_list);
|
|
||||||
if (reverse) {
|
|
||||||
rewrite_url = (char *)
|
|
||||||
safemalloc (strlen (url) + strlen (reverse->url) +
|
|
||||||
1);
|
|
||||||
strcpy (rewrite_url, reverse->url);
|
|
||||||
strcat (rewrite_url, url + strlen (reverse->path));
|
|
||||||
} else if (config.reversemagic
|
|
||||||
&& hashmap_entry_by_key (hashofheaders,
|
|
||||||
"cookie",
|
|
||||||
(void **) &cookie) > 0) {
|
|
||||||
|
|
||||||
/* No match - try the magical tracking cookie next */
|
|
||||||
if ((cookieval = strstr (cookie, REVERSE_COOKIE "="))
|
|
||||||
&& (reverse =
|
|
||||||
reversepath_get (cookieval +
|
|
||||||
strlen (REVERSE_COOKIE) + 1,
|
|
||||||
config.reversepath_list)))
|
|
||||||
{
|
|
||||||
|
|
||||||
rewrite_url = (char *) safemalloc
|
|
||||||
(strlen (url) +
|
|
||||||
strlen (reverse->url) +
|
|
||||||
1);
|
|
||||||
strcpy (rewrite_url, reverse->url);
|
|
||||||
strcat (rewrite_url, url + 1);
|
|
||||||
|
|
||||||
log_message (LOG_INFO,
|
|
||||||
"Magical tracking cookie says: %s",
|
|
||||||
reverse->path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Forward proxy support off and no reverse path match found */
|
|
||||||
if (config.reverseonly && !rewrite_url) {
|
|
||||||
log_message (LOG_ERR, "Bad request");
|
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
|
||||||
"detail",
|
|
||||||
"Request has an invalid URL", "url", url,
|
|
||||||
NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message (LOG_CONN, "Rewriting URL: %s -> %s", url, rewrite_url);
|
|
||||||
|
|
||||||
/* Store reverse path so that the magical tracking cookie can be set */
|
|
||||||
if (config.reversemagic && reverse)
|
|
||||||
connptr->reversepath = safestrdup (reverse->path);
|
|
||||||
|
|
||||||
return rewrite_url;
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2005 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* See 'reverse-proxy.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_REVERSE_PROXY_H
|
|
||||||
#define TINYPROXY_REVERSE_PROXY_H
|
|
||||||
|
|
||||||
#include "conns.h"
|
|
||||||
|
|
||||||
struct reversepath {
|
|
||||||
struct reversepath *next;
|
|
||||||
char *path;
|
|
||||||
char *url;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define REVERSE_COOKIE "yummy_magical_cookie"
|
|
||||||
|
|
||||||
extern void reversepath_add (const char *path, const char *url,
|
|
||||||
struct reversepath **reversepath_list);
|
|
||||||
extern struct reversepath *reversepath_get (char *url,
|
|
||||||
struct reversepath *reverse);
|
|
||||||
void free_reversepath_list (struct reversepath *reverse);
|
|
||||||
extern char *reverse_rewrite_url (struct conn_s *connptr,
|
|
||||||
hashmap_t hashofheaders, char *url);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+154
@@ -0,0 +1,154 @@
|
|||||||
|
/* $Id: scanner.l,v 1.3 2001-06-02 03:10:09 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* This builds the scanner for the tinyproxy configuration file. This
|
||||||
|
* file needs to stay in sync with grammar.y. If someone knows lex and yacc
|
||||||
|
* better than I do, please update these files.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
%{
|
||||||
|
|
||||||
|
#include "tinyproxy.h"
|
||||||
|
#include "grammar.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
struct keyword {
|
||||||
|
char *kw_name;
|
||||||
|
int kw_token;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct keyword keywords[] = {
|
||||||
|
/* statements */
|
||||||
|
{ "port", KW_PORT },
|
||||||
|
{ "logfile", KW_LOGFILE },
|
||||||
|
{ "syslog", KW_SYSLOG },
|
||||||
|
{ "maxclients", KW_MAXCLIENTS },
|
||||||
|
{ "maxspareservers", KW_MAXSPARESERVERS },
|
||||||
|
{ "minspareservers", KW_MINSPARESERVERS },
|
||||||
|
{ "startservers", KW_STARTSERVERS },
|
||||||
|
{ "maxrequestsperchild", KW_MAXREQUESTSPERCHILD },
|
||||||
|
{ "pidfile", KW_PIDFILE },
|
||||||
|
{ "timeout", KW_TIMEOUT },
|
||||||
|
{ "listen", KW_LISTEN },
|
||||||
|
{ "user", KW_USER },
|
||||||
|
{ "group", KW_GROUP },
|
||||||
|
{ "anonymous", KW_ANONYMOUS },
|
||||||
|
{ "filter", KW_FILTER },
|
||||||
|
{ "xtinyproxy", KW_XTINYPROXY },
|
||||||
|
{ "tunnel", KW_TUNNEL },
|
||||||
|
{ "allow", KW_ALLOW },
|
||||||
|
{ "deny", KW_DENY },
|
||||||
|
|
||||||
|
/* loglevel and the settings */
|
||||||
|
{ "loglevel", KW_LOGLEVEL },
|
||||||
|
{ "critical", KW_LOG_CRITICAL },
|
||||||
|
{ "error", KW_LOG_ERROR },
|
||||||
|
{ "warning", KW_LOG_WARNING },
|
||||||
|
{ "notice", KW_LOG_NOTICE },
|
||||||
|
{ "info", KW_LOG_INFO },
|
||||||
|
|
||||||
|
/* on/off switches */
|
||||||
|
{ "yes", KW_YES },
|
||||||
|
{ "on", KW_YES },
|
||||||
|
{ "no", KW_NO },
|
||||||
|
{ "off", KW_NO }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#define YY_NO_UNPUT 1
|
||||||
|
|
||||||
|
#define MAX_REGEXP_LEN 1024
|
||||||
|
|
||||||
|
unsigned int yylineno = 1;
|
||||||
|
char tiny_buf[MAX_REGEXP_LEN];
|
||||||
|
char *tiny_str;
|
||||||
|
|
||||||
|
static int check_reserved_words(char *token);
|
||||||
|
static void append_string(int length, char *str);
|
||||||
|
static void append_char(char c);
|
||||||
|
%}
|
||||||
|
|
||||||
|
%option noyywrap
|
||||||
|
|
||||||
|
white [ \t]
|
||||||
|
digit [0-9]
|
||||||
|
alpha [a-zA-Z]
|
||||||
|
alphanum [a-zA-Z0-9]
|
||||||
|
word [^ \#'"\(\)\{\}\\;\n\t,|\.]
|
||||||
|
|
||||||
|
%x string
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
\#.*$ ;
|
||||||
|
\n { yylineno++; return '\n'; }
|
||||||
|
: { return ':'; }
|
||||||
|
{white}+ ;
|
||||||
|
0x{digit}+ { yylval.num = strtol(yytext, NULL, 16); return NUMBER; }
|
||||||
|
0{digit}+ { yylval.num = strtol(yytext, NULL, 8); return NUMBER; }
|
||||||
|
{digit}+ { yylval.num = atoi(yytext); return NUMBER; }
|
||||||
|
{alpha}+ { return check_reserved_words(yytext); }
|
||||||
|
\" {
|
||||||
|
tiny_str = tiny_buf;
|
||||||
|
BEGIN(string);
|
||||||
|
}
|
||||||
|
<string>\\a { append_char(7); }
|
||||||
|
<string>\\n { append_char(10); }
|
||||||
|
<string>\\r { append_char(13); }
|
||||||
|
<string>\\t { append_char(9); }
|
||||||
|
<string>\\v { append_char(11); }
|
||||||
|
<string>\\[^anrtv] { append_string(1, yytext + 1); }
|
||||||
|
<string>\" {
|
||||||
|
BEGIN(INITIAL);
|
||||||
|
yylval.cptr = strdup(tiny_buf);
|
||||||
|
return STRING;
|
||||||
|
}
|
||||||
|
<string>[^"\\]+ { append_string(strlen(yytext), yytext); }
|
||||||
|
|
||||||
|
|
||||||
|
({digit}{1,3}\.){3}{digit}{1,3} { yylval.cptr = strdup(yytext); return NUMERIC_ADDRESS; }
|
||||||
|
({digit}{1,3}\.){3}{digit}{1,3}\/{digit}+ { yylval.cptr = strdup(yytext); return NETMASK_ADDRESS; }
|
||||||
|
([-_a-z0-9]+\.)+[a-z]+ { yylval.cptr = strdup(yytext); return STRING_ADDRESS; }
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
int check_reserved_words(char *token)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < (sizeof(keywords) / sizeof(struct keyword)); i++) {
|
||||||
|
if (strcasecmp(keywords[i].kw_name, token) == 0) {
|
||||||
|
return keywords[i].kw_token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yylval.cptr = strdup(token);
|
||||||
|
return IDENTIFIER;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void append_string(int length, char *s)
|
||||||
|
{
|
||||||
|
int to_copy = min(MAX_REGEXP_LEN - (tiny_str - tiny_buf) - 1, length);
|
||||||
|
|
||||||
|
memcpy(tiny_str, s, to_copy);
|
||||||
|
tiny_str += to_copy;
|
||||||
|
*tiny_str = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void append_char(char c)
|
||||||
|
{
|
||||||
|
*tiny_str = c;
|
||||||
|
tiny_str++;
|
||||||
|
*tiny_str = 0;
|
||||||
|
}
|
||||||
+170
-210
@@ -1,286 +1,246 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: sock.c,v 1.5 2001-05-27 02:31:20 rjkaes Exp $
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
|
||||||
* Copyright (C) 1999, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
* Copyright (C) 2000 Chris Lightfoot <chris@ex-parrot.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Sockets are created and destroyed here. When a new connection comes in from
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Sockets are created and destroyed here. When a new connection comes in from
|
|
||||||
* a client, we need to copy the socket and the create a second socket to the
|
* a client, we need to copy the socket and the create a second socket to the
|
||||||
* remote server the client is trying to connect to. Also, the listening
|
* remote server the client is trying to connect to. Also, the listening
|
||||||
* socket is created and destroyed here. Sounds more impressive than it
|
* socket is created and destroyed here. Sounds more impressive than it
|
||||||
* actually is.
|
* actually is.
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 Steven Young
|
||||||
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
* Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
#include "dnscache.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "heap.h"
|
|
||||||
#include "network.h"
|
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "text.h"
|
#include "utils.h"
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind the given socket to the supplied address. The socket is
|
* The mutex is used for locking around the calls to the dnscache since I
|
||||||
* returned if the bind succeeded. Otherwise, -1 is returned
|
* don't want multiple threads accessing the linked list at the same time.
|
||||||
* to indicate an error.
|
* This should be more fine grained, but it will do for now.
|
||||||
|
* - rjkaes
|
||||||
*/
|
*/
|
||||||
static int
|
static pthread_mutex_t sock_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
bind_socket (int sockfd, const char *addr, int family)
|
|
||||||
{
|
|
||||||
struct addrinfo hints, *res, *ressave;
|
|
||||||
|
|
||||||
assert (sockfd >= 0);
|
#define SOCK_LOCK() pthread_mutex_lock(&sock_mutex);
|
||||||
assert (addr != NULL && strlen (addr) != 0);
|
#define SOCK_UNLOCK() pthread_mutex_unlock(&sock_mutex);
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (struct addrinfo));
|
|
||||||
hints.ai_family = family;
|
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
|
||||||
|
|
||||||
/* The local port it not important */
|
/* This routine is so old I can't even remember writing it. But I do
|
||||||
if (getaddrinfo (addr, NULL, &hints, &res) != 0)
|
* remember that it was an .h file because I didn't know putting code in a
|
||||||
return -1;
|
* header was bad magic yet. anyway, this routine opens a connection to a
|
||||||
|
* system and returns the fd.
|
||||||
ressave = res;
|
* - steve
|
||||||
|
*
|
||||||
/* Loop through the addresses and try to bind to each */
|
* Cleaned up some of the code to use memory routines which are now the
|
||||||
do {
|
* default. Also, the routine first checks to see if the address is in
|
||||||
if (bind (sockfd, res->ai_addr, res->ai_addrlen) == 0)
|
* dotted-decimal form before it does a name lookup.
|
||||||
break; /* success */
|
* - rjkaes
|
||||||
} while ((res = res->ai_next) != NULL);
|
|
||||||
|
|
||||||
freeaddrinfo (ressave);
|
|
||||||
if (res == NULL) /* was not able to bind to any address */
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return sockfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Open a connection to a remote host. It's been re-written to use
|
|
||||||
* the getaddrinfo() library function, which allows for a protocol
|
|
||||||
* independent implementation (mostly for IPv4 and IPv6 addresses.)
|
|
||||||
*/
|
*/
|
||||||
int opensock (const char *host, int port, const char *bind_to)
|
int opensock(char *ip_addr, uint16_t port)
|
||||||
{
|
{
|
||||||
int sockfd, n;
|
int sock_fd;
|
||||||
struct addrinfo hints, *res, *ressave;
|
struct sockaddr_in port_info;
|
||||||
char portstr[6];
|
int ret;
|
||||||
|
|
||||||
assert (host != NULL);
|
assert(ip_addr != NULL);
|
||||||
assert (port > 0);
|
assert(port > 0);
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (struct addrinfo));
|
memset((struct sockaddr*)&port_info, 0, sizeof(port_info));
|
||||||
hints.ai_family = AF_UNSPEC;
|
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
|
||||||
|
|
||||||
snprintf (portstr, sizeof (portstr), "%d", port);
|
port_info.sin_family = AF_INET;
|
||||||
|
|
||||||
n = getaddrinfo (host, portstr, &hints, &res);
|
/* chris - Could block; neet to ensure that this is never called
|
||||||
if (n != 0) {
|
* before a non-blocking DNS query happens for this address. Not
|
||||||
log_message (LOG_ERR,
|
* relevant in the code as it stands.
|
||||||
"opensock: Could not retrieve info for %s", host);
|
*/
|
||||||
return -1;
|
SOCK_LOCK();
|
||||||
}
|
ret = dnscache(&port_info.sin_addr, ip_addr);
|
||||||
|
SOCK_UNLOCK();
|
||||||
|
|
||||||
ressave = res;
|
if (ret < 0) {
|
||||||
do {
|
log_message(LOG_ERR, "opensock: Could not lookup address: %s", ip_addr);
|
||||||
sockfd =
|
return -1;
|
||||||
socket (res->ai_family, res->ai_socktype, res->ai_protocol);
|
}
|
||||||
if (sockfd < 0)
|
|
||||||
continue; /* ignore this one */
|
|
||||||
|
|
||||||
/* Bind to the specified address */
|
port_info.sin_port = htons(port);
|
||||||
if (bind_to) {
|
|
||||||
if (bind_socket (sockfd, bind_to,
|
|
||||||
res->ai_family) < 0) {
|
|
||||||
close (sockfd);
|
|
||||||
continue; /* can't bind, so try again */
|
|
||||||
}
|
|
||||||
} else if (config.bind_address) {
|
|
||||||
if (bind_socket (sockfd, config.bind_address,
|
|
||||||
res->ai_family) < 0) {
|
|
||||||
close (sockfd);
|
|
||||||
continue; /* can't bind, so try again */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0)
|
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||||
break; /* success */
|
log_message(LOG_ERR, "opensock: socket (%s)", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
close (sockfd);
|
if (connect(sock_fd, (struct sockaddr*)&port_info, sizeof(port_info)) < 0) {
|
||||||
} while ((res = res->ai_next) != NULL);
|
log_message(LOG_ERR, "connecting socket");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
freeaddrinfo (ressave);
|
return sock_fd;
|
||||||
if (res == NULL) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"opensock: Could not establish a connection to %s",
|
|
||||||
host);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sockfd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the socket to non blocking -rjkaes
|
* Set the socket to non blocking -rjkaes
|
||||||
*/
|
*/
|
||||||
int socket_nonblocking (int sock)
|
int socket_nonblocking(int sock)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
assert (sock >= 0);
|
assert(sock >= 0);
|
||||||
|
|
||||||
flags = fcntl (sock, F_GETFL, 0);
|
flags = fcntl(sock, F_GETFL, 0);
|
||||||
return fcntl (sock, F_SETFL, flags | O_NONBLOCK);
|
return fcntl(sock, F_SETFL, flags | O_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the socket to blocking -rjkaes
|
* Set the socket to blocking -rjkaes
|
||||||
*/
|
*/
|
||||||
int socket_blocking (int sock)
|
int socket_blocking(int sock)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
assert (sock >= 0);
|
assert(sock >= 0);
|
||||||
|
|
||||||
flags = fcntl (sock, F_GETFL, 0);
|
flags = fcntl(sock, F_GETFL, 0);
|
||||||
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.
|
* Start listening to a socket. Create a socket with the selected port.
|
||||||
* The size of the socket address will be returned to the caller through
|
* The size of the socket address will be returned to the caller through
|
||||||
* the pointer, while the socket is returned as a default return.
|
* the pointer, while the socket is returned as a default return.
|
||||||
* - rjkaes
|
* - rjkaes
|
||||||
*/
|
*/
|
||||||
int listen_sock (uint16_t port, socklen_t * addrlen)
|
int listen_sock(uint16_t port, socklen_t *addrlen)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *result, *rp;
|
int listenfd;
|
||||||
char portstr[6];
|
const int on = 1;
|
||||||
int listenfd;
|
struct sockaddr_in addr;
|
||||||
const int on = 1;
|
|
||||||
|
|
||||||
assert (port > 0);
|
assert(port > 0);
|
||||||
assert (addrlen != NULL);
|
assert(addrlen != NULL);
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (struct addrinfo));
|
listenfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
hints.ai_family = AF_UNSPEC;
|
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
|
||||||
hints.ai_flags = AI_PASSIVE;
|
|
||||||
|
|
||||||
snprintf (portstr, sizeof (portstr), "%d", port);
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
if (getaddrinfo (config.ipAddr, portstr, &hints, &result) != 0) {
|
if (config.ipAddr) {
|
||||||
log_message (LOG_ERR,
|
addr.sin_addr.s_addr = inet_addr(config.ipAddr);
|
||||||
"Unable to getaddrinfo() because of %s",
|
} else {
|
||||||
strerror (errno));
|
addr.sin_addr.s_addr = inet_addr("0.0.0.0");
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
bind(listenfd, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
listenfd = socket (rp->ai_family, rp->ai_socktype,
|
|
||||||
rp->ai_protocol);
|
|
||||||
if (listenfd == -1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on,
|
listen(listenfd, MAXLISTEN);
|
||||||
sizeof (on));
|
|
||||||
|
|
||||||
if (bind (listenfd, rp->ai_addr, rp->ai_addrlen) == 0)
|
*addrlen = sizeof(addr);
|
||||||
break; /* success */
|
|
||||||
|
|
||||||
close (listenfd);
|
return listenfd;
|
||||||
}
|
|
||||||
|
|
||||||
if (rp == NULL) {
|
|
||||||
/* was not able to bind to any address */
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Unable to bind listening socket "
|
|
||||||
"to any address.");
|
|
||||||
|
|
||||||
freeaddrinfo (result);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listen (listenfd, MAXLISTEN) < 0) {
|
|
||||||
log_message (LOG_ERR,
|
|
||||||
"Unable to start listening socket because of %s",
|
|
||||||
strerror (errno));
|
|
||||||
|
|
||||||
close (listenfd);
|
|
||||||
freeaddrinfo (result);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*addrlen = rp->ai_addrlen;
|
|
||||||
|
|
||||||
freeaddrinfo (result);
|
|
||||||
|
|
||||||
return listenfd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Takes a socket descriptor and returns the socket's IP address.
|
* Takes a socket descriptor and returns the string contain the peer's
|
||||||
|
* IP address.
|
||||||
*/
|
*/
|
||||||
int getsock_ip (int fd, char *ipaddr)
|
char *getpeer_ip(int fd, char *ipaddr)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage name;
|
struct sockaddr_in name;
|
||||||
socklen_t namelen = sizeof (name);
|
size_t namelen = sizeof(name);
|
||||||
|
|
||||||
assert (fd >= 0);
|
assert(fd >= 0);
|
||||||
|
assert(ipaddr != NULL);
|
||||||
|
|
||||||
if (getsockname (fd, (struct sockaddr *) &name, &namelen) != 0) {
|
if (getpeername(fd, (struct sockaddr*)&name, &namelen) != 0) {
|
||||||
log_message (LOG_ERR, "getsock_ip: getsockname() error: %s",
|
log_message(LOG_ERR, "Connect: 'could not get peer name'");
|
||||||
strerror (errno));
|
} else {
|
||||||
return -1;
|
strlcpy(ipaddr,
|
||||||
}
|
inet_ntoa(*(struct in_addr*)&name.sin_addr.s_addr),
|
||||||
|
PEER_IP_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_ip_string ((struct sockaddr *) &name, ipaddr, IP_LENGTH) ==
|
return ipaddr;
|
||||||
NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the peer's socket information.
|
* Takes a socket descriptor and returns the string containing the peer's
|
||||||
|
* address.
|
||||||
*/
|
*/
|
||||||
int getpeer_information (int fd, char *ipaddr, char *string_addr)
|
char *getpeer_string(int fd, char *string)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage sa;
|
struct sockaddr_in name;
|
||||||
socklen_t salen = sizeof sa;
|
size_t namelen = sizeof(name);
|
||||||
|
struct hostent *peername;
|
||||||
|
|
||||||
assert (fd >= 0);
|
assert(fd >= 0);
|
||||||
assert (ipaddr != NULL);
|
assert(string != NULL);
|
||||||
assert (string_addr != NULL);
|
|
||||||
|
|
||||||
/* Set the strings to default values */
|
if (getpeername(fd, (struct sockaddr *)&name, &namelen) != 0) {
|
||||||
ipaddr[0] = '\0';
|
log_message(LOG_ERR, "Connect: 'could not get peer name'");
|
||||||
strlcpy (string_addr, "[unknown]", HOSTNAME_LENGTH);
|
} else {
|
||||||
|
SOCK_LOCK();
|
||||||
|
peername = gethostbyaddr((char *)&name.sin_addr.s_addr,
|
||||||
|
sizeof(name.sin_addr.s_addr),
|
||||||
|
AF_INET);
|
||||||
|
if (peername) {
|
||||||
|
strlcpy(string, peername->h_name, PEER_STRING_LENGTH);
|
||||||
|
}
|
||||||
|
SOCK_UNLOCK();
|
||||||
|
}
|
||||||
|
|
||||||
/* Look up the IP address */
|
return string;
|
||||||
if (getpeername (fd, (struct sockaddr *) &sa, &salen) != 0)
|
}
|
||||||
return -1;
|
|
||||||
|
/*
|
||||||
if (get_ip_string ((struct sockaddr *) &sa, ipaddr, IP_LENGTH) == NULL)
|
* Reads in a line of text one character at a time. Finishes when either a
|
||||||
return -1;
|
* newline is detected, or maxlen characters have been read. The function
|
||||||
|
* will actually copy one less than maxlen into the buffer. In other words,
|
||||||
/* Get the full host name */
|
* the returned string will _always_ be '\0' terminated.
|
||||||
return getnameinfo ((struct sockaddr *) &sa, salen,
|
*/
|
||||||
string_addr, HOSTNAME_LENGTH, NULL, 0, 0);
|
ssize_t readline(int fd, char *ptr, size_t maxlen)
|
||||||
|
{
|
||||||
|
size_t n;
|
||||||
|
ssize_t rc;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
assert(fd >= 0);
|
||||||
|
assert(ptr != NULL);
|
||||||
|
|
||||||
|
for (n = 1; n < maxlen; n++) {
|
||||||
|
again:
|
||||||
|
if ((rc = read(fd, &c, 1)) == 1) {
|
||||||
|
*ptr++ = c;
|
||||||
|
if (c == '\n')
|
||||||
|
break;
|
||||||
|
} else if (rc == 0) {
|
||||||
|
if (n == 1)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if (errno == EINTR)
|
||||||
|
goto again;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tack a NIL to the end to make is a standard "C" string */
|
||||||
|
*ptr = '\0';
|
||||||
|
return (ssize_t)n;
|
||||||
}
|
}
|
||||||
+27
-25
@@ -1,40 +1,42 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: sock.h,v 1.4 2001-06-02 02:07:34 rjkaes Exp $
|
||||||
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
|
|
||||||
* Copyright (C) 1999, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* See 'sock.c' for a detailed description.
|
||||||
* 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,
|
* Copyright (C) 1998 Steven Young
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* 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
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'sock.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_SOCK_H
|
#ifndef TINYPROXY_SOCK_H
|
||||||
#define TINYPROXY_SOCK_H
|
#define TINYPROXY_SOCK_H
|
||||||
|
|
||||||
/* The IP length is set to 48, since IPv6 can be that long */
|
#ifdef HAVE_CONFIG_H
|
||||||
#define IP_LENGTH 48
|
# include <config.h>
|
||||||
#define HOSTNAME_LENGTH 1024
|
#endif
|
||||||
|
|
||||||
|
#define PEER_IP_LENGTH 16
|
||||||
|
#define PEER_STRING_LENGTH 256
|
||||||
|
|
||||||
#define MAXLINE (1024 * 4)
|
#define MAXLINE (1024 * 4)
|
||||||
|
|
||||||
extern int opensock (const char *host, int port, const char *bind_to);
|
extern int opensock(char *ip_addr, uint16_t port);
|
||||||
extern int listen_sock (uint16_t port, socklen_t * addrlen);
|
extern int listen_sock(uint16_t port, socklen_t *addrlen);
|
||||||
|
|
||||||
extern int socket_nonblocking (int sock);
|
extern int socket_nonblocking(int sock);
|
||||||
extern int socket_blocking (int sock);
|
extern int socket_blocking(int sock);
|
||||||
|
|
||||||
extern int getsock_ip (int fd, char *ipaddr);
|
extern char *getpeer_ip(int fd, char *ipaddr);
|
||||||
extern int getpeer_information (int fd, char *ipaddr, char *string_addr);
|
extern char *getpeer_string(int fd, char *string);
|
||||||
|
|
||||||
|
extern ssize_t readline(int fd, char *ptr, size_t maxlen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+88
-119
@@ -1,156 +1,125 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: stats.c,v 1.4 2001-05-27 02:26:53 rjkaes Exp $
|
||||||
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This module handles the statistics for tinyproxy. There are only two
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This module handles the statistics for tinyproxy. There are only two
|
|
||||||
* public API functions. The reason for the functions, rather than just a
|
* public API functions. The reason for the functions, rather than just a
|
||||||
* external structure is that tinyproxy is now multi-threaded and we can
|
* external structure is that tinyproxy is now multi-threaded and we can
|
||||||
* not allow more than one child to access the statistics at the same
|
* not allow more than one thread to access the statistics at the same
|
||||||
* time. This is prevented by a mutex. If there is a need for more
|
* time. This is prevented by a mutex. If there is a need for more
|
||||||
* statistics in the future, just add to the structure, enum (in the header),
|
* statistics in the future, just add to the structure, enum (in the header),
|
||||||
* and the switch statement in update_stats().
|
* and the switch statement in update_stats().
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "heap.h"
|
|
||||||
#include "html-error.h"
|
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
struct stat_s {
|
struct stat_s {
|
||||||
unsigned long int num_reqs;
|
unsigned long int num_reqs;
|
||||||
unsigned long int num_badcons;
|
unsigned long int num_badcons;
|
||||||
unsigned long int num_open;
|
unsigned long int num_open;
|
||||||
unsigned long int num_refused;
|
unsigned long int num_refused;
|
||||||
unsigned long int num_denied;
|
unsigned long int num_denied;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct stat_s *stats;
|
static struct stat_s stats;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the statistics information to zero.
|
* Locking when we're accessing the statistics, since I don't want multiple
|
||||||
|
* threads changing the information at the same time.
|
||||||
*/
|
*/
|
||||||
void init_stats (void)
|
pthread_mutex_t stats_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
{
|
#define LOCK() pthread_mutex_lock(&stats_mutex)
|
||||||
stats = (struct stat_s *) malloc_shared_memory (sizeof (struct stat_s));
|
#define UNLOCK() pthread_mutex_unlock(&stats_mutex)
|
||||||
if (stats == MAP_FAILED)
|
|
||||||
return;
|
|
||||||
|
|
||||||
memset (stats, 0, sizeof (struct stat_s));
|
/*
|
||||||
|
* Initialise the statistics information to zero.
|
||||||
|
*/
|
||||||
|
void init_stats(void)
|
||||||
|
{
|
||||||
|
LOCK();
|
||||||
|
memset(&stats, 0, sizeof(stats));
|
||||||
|
UNLOCK();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display the statics of the tinyproxy server.
|
* Display the statics of the tinyproxy server.
|
||||||
*/
|
*/
|
||||||
int
|
int showstats(struct conn_s *connptr)
|
||||||
showstats (struct conn_s *connptr)
|
|
||||||
{
|
{
|
||||||
char *message_buffer;
|
static char *msg = "HTTP/1.0 200 OK\r\n" \
|
||||||
char opens[16], reqs[16], badconns[16], denied[16], refused[16];
|
"Content-type: text/html\r\n\r\n" \
|
||||||
FILE *statfile;
|
"<html><head><title>%s (%s) stats</title></head>\r\n" \
|
||||||
|
"<body>\r\n" \
|
||||||
|
"<center><h2>%s (%s) run-time statistics</h2></center><hr>\r\n" \
|
||||||
|
"<blockquote>\r\n" \
|
||||||
|
"Number of open connections: %lu<br>\r\n" \
|
||||||
|
"Number of requests: %lu<br>\r\n" \
|
||||||
|
"Number of bad connections: %lu<br>\r\n" \
|
||||||
|
"Number of denied connections: %lu<br>\r\n" \
|
||||||
|
"Number of refused connections due to high load: %lu\r\n" \
|
||||||
|
"</blockquote>\r\n</body></html>\r\n";
|
||||||
|
|
||||||
snprintf (opens, sizeof (opens), "%lu", stats->num_open);
|
connptr->output_message = malloc(MAXBUFFSIZE);
|
||||||
snprintf (reqs, sizeof (reqs), "%lu", stats->num_reqs);
|
if (!connptr->output_message) {
|
||||||
snprintf (badconns, sizeof (badconns), "%lu", stats->num_badcons);
|
log_message(LOG_CRIT, "Out of memory!");
|
||||||
snprintf (denied, sizeof (denied), "%lu", stats->num_denied);
|
return -1;
|
||||||
snprintf (refused, sizeof (refused), "%lu", stats->num_refused);
|
}
|
||||||
|
|
||||||
if (!config.statpage || (!(statfile = fopen (config.statpage, "r")))) {
|
LOCK();
|
||||||
message_buffer = (char *) safemalloc (MAXBUFFSIZE);
|
snprintf(connptr->output_message, MAXBUFFSIZE, msg,
|
||||||
if (!message_buffer)
|
PACKAGE, VERSION, PACKAGE, VERSION,
|
||||||
return -1;
|
stats.num_open,
|
||||||
|
stats.num_reqs,
|
||||||
|
stats.num_badcons,
|
||||||
|
stats.num_denied,
|
||||||
|
stats.num_refused);
|
||||||
|
UNLOCK();
|
||||||
|
|
||||||
snprintf
|
return 0;
|
||||||
(message_buffer, MAXBUFFSIZE,
|
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
|
||||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
|
|
||||||
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
|
|
||||||
"<html>\n"
|
|
||||||
"<head><title>%s version %s run-time statistics</title></head>\n"
|
|
||||||
"<body>\n"
|
|
||||||
"<h1>%s version %s run-time statistics</h1>\n"
|
|
||||||
"<p>\n"
|
|
||||||
"Number of open connections: %lu<br />\n"
|
|
||||||
"Number of requests: %lu<br />\n"
|
|
||||||
"Number of bad connections: %lu<br />\n"
|
|
||||||
"Number of denied connections: %lu<br />\n"
|
|
||||||
"Number of refused connections due to high load: %lu\n"
|
|
||||||
"</p>\n"
|
|
||||||
"<hr />\n"
|
|
||||||
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
|
|
||||||
"</html>\n",
|
|
||||||
PACKAGE, VERSION, PACKAGE, VERSION,
|
|
||||||
stats->num_open,
|
|
||||||
stats->num_reqs,
|
|
||||||
stats->num_badcons, stats->num_denied,
|
|
||||||
stats->num_refused, PACKAGE, VERSION);
|
|
||||||
|
|
||||||
if (send_http_message (connptr, 200, "OK",
|
|
||||||
message_buffer) < 0) {
|
|
||||||
safefree (message_buffer);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
safefree (message_buffer);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_error_variable (connptr, "opens", opens);
|
|
||||||
add_error_variable (connptr, "reqs", reqs);
|
|
||||||
add_error_variable (connptr, "badconns", badconns);
|
|
||||||
add_error_variable (connptr, "deniedconns", denied);
|
|
||||||
add_error_variable (connptr, "refusedconns", refused);
|
|
||||||
add_standard_vars (connptr);
|
|
||||||
send_http_headers (connptr, 200, "Statistic requested");
|
|
||||||
send_html_file (statfile, connptr);
|
|
||||||
fclose (statfile);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the value of the statistics. The update_level is defined in
|
* Update the value of the statistics. The update_level is defined in
|
||||||
* stats.h
|
* stats.h
|
||||||
*/
|
*/
|
||||||
int update_stats (status_t update_level)
|
int update_stats(status_t update_level)
|
||||||
{
|
{
|
||||||
switch (update_level) {
|
LOCK();
|
||||||
case STAT_BADCONN:
|
switch(update_level) {
|
||||||
++stats->num_badcons;
|
case STAT_BADCONN:
|
||||||
break;
|
stats.num_badcons++;
|
||||||
case STAT_OPEN:
|
break;
|
||||||
++stats->num_open;
|
case STAT_OPEN:
|
||||||
++stats->num_reqs;
|
stats.num_open++;
|
||||||
break;
|
stats.num_reqs++;
|
||||||
case STAT_CLOSE:
|
break;
|
||||||
--stats->num_open;
|
case STAT_CLOSE:
|
||||||
break;
|
stats.num_open--;
|
||||||
case STAT_REFUSE:
|
break;
|
||||||
++stats->num_refused;
|
case STAT_REFUSE:
|
||||||
break;
|
stats.num_refused++;
|
||||||
case STAT_DENIED:
|
break;
|
||||||
++stats->num_denied;
|
case STAT_DENIED:
|
||||||
break;
|
stats.num_denied++;
|
||||||
default:
|
break;
|
||||||
return -1;
|
default:
|
||||||
}
|
UNLOCK();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
UNLOCK();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+20
-25
@@ -1,44 +1,39 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
/* $Id: stats.h,v 1.1 2000-09-12 00:06:09 rjkaes Exp $
|
||||||
* Copyright (C) 2000 Robert James Kaes <rjkaes@users.sourceforge.net>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* See 'stats.h' for a detailed description.
|
||||||
* 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,
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* under the terms of the GNU General Public License as published by the
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* See 'stats.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef _TINYPROXY_STATS_H_
|
#ifndef _TINYPROXY_STATS_H_
|
||||||
#define _TINYPROXY_STATS_H_
|
#define _TINYPROXY_STATS_H_
|
||||||
|
|
||||||
#include "conns.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Various logable statistics
|
* Various logable statistics
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STAT_BADCONN, /* bad connection, for unknown reason */
|
STAT_BADCONN, /* bad connection, for unknonw reason */
|
||||||
STAT_OPEN, /* connection opened */
|
STAT_OPEN, /* connection opened */
|
||||||
STAT_CLOSE, /* connection closed */
|
STAT_CLOSE, /* connection closed */
|
||||||
STAT_REFUSE, /* connection refused (to outside world) */
|
STAT_REFUSE, /* connection refused (to outside world) */
|
||||||
STAT_DENIED /* connection denied to tinyproxy itself */
|
STAT_DENIED /* connection denied to tinyproxy itself */
|
||||||
} status_t;
|
} status_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Public API to the statistics for tinyproxy
|
* Public API to the statistics for tinyproxy
|
||||||
*/
|
*/
|
||||||
extern void init_stats (void);
|
extern void init_stats(void);
|
||||||
extern int showstats (struct conn_s *connptr);
|
extern int showstats(struct conn_s *connptr);
|
||||||
extern int update_stats (status_t update_level);
|
extern int update_stats(status_t update_level);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+398
@@ -0,0 +1,398 @@
|
|||||||
|
/* $Id: ternary.c,v 1.5 2001-05-23 17:59:53 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* This module creates a Ternary Search Tree which can store both string
|
||||||
|
* keys, and arbitrary data for each key. It works similar to a hash, and
|
||||||
|
* a binary search tree. The idea (and some code) is taken from Dr. Dobb's
|
||||||
|
* Journal, April 1998 "Ternary Search Trees", Jon Bentley and Bob
|
||||||
|
* Sedgewick, pg 20-25. The supplied code was then made "production" ready.
|
||||||
|
* Hopefully, the comments in the code should make the API self
|
||||||
|
* explanatory.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined HAVE_SYS_TYPES_H
|
||||||
|
# include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "ternary.h"
|
||||||
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macros for the tree structures (limits)
|
||||||
|
*/
|
||||||
|
#define MAXTREES 1024 /* max. number of trees */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The structure for each individual node of the ternary tree.
|
||||||
|
*/
|
||||||
|
typedef struct tnode {
|
||||||
|
char splitchar;
|
||||||
|
struct tnode *lokid, *eqkid, *hikid;
|
||||||
|
} Tnode;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The structure for each root of a ternary tree.
|
||||||
|
*/
|
||||||
|
#define BUFSIZE 1000
|
||||||
|
#define BUFARRAY 10000
|
||||||
|
typedef struct ttree {
|
||||||
|
TERNARY token; /* contains unique ternary tree ID */
|
||||||
|
Tnode *tree_root;
|
||||||
|
Tnode *buf;
|
||||||
|
int bufn, freen;
|
||||||
|
Tnode *freearr[BUFARRAY];
|
||||||
|
} Ttree;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* variables shared by library routines.
|
||||||
|
*/
|
||||||
|
static Ttree *trees[MAXTREES]; /* the array of trees */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nonce generator -- this MUST be non-zero _always_
|
||||||
|
*/
|
||||||
|
#define IOFFSET 0x1221 /* used to hide index number in token */
|
||||||
|
#define NOFFSET 0x0502 /* initial nonce */
|
||||||
|
static unsigned int noncectr = NOFFSET;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Contains any error messages from the functions.
|
||||||
|
*/
|
||||||
|
char te_errbuf[256];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generate a token; this is an integer: index number + OFFSET,,none
|
||||||
|
* WARNING: Each quantity must fix into 16 bits
|
||||||
|
*
|
||||||
|
* Parameters: int index index number
|
||||||
|
* Returned: TERNARY token of corresponding tree
|
||||||
|
* Errors: TE_INTINCON * index + OFFSET is too big
|
||||||
|
* * nonce is too big
|
||||||
|
* * index is out of range
|
||||||
|
* (te_errbuf has disambiguating string)
|
||||||
|
* Exceptions: none
|
||||||
|
*/
|
||||||
|
static TERNARY create_token_ref(unsigned int ind)
|
||||||
|
{
|
||||||
|
unsigned int high; /* high 16 bits of token (index) */
|
||||||
|
unsigned int low; /* low 16 bits of token (nonce) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanity check argument; called internally...
|
||||||
|
*/
|
||||||
|
if (ind > MAXTREES) {
|
||||||
|
ERRBUF3("create_token_ref: index %u exceeds %d", ind, MAXTREES);
|
||||||
|
return TE_INTINCON;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the high part of the token (index into tree array, offset by
|
||||||
|
* some arbitrary amount)
|
||||||
|
* SANITY CHECK: Be sure index + OFFSET fits into 16 bits as positive.
|
||||||
|
*/
|
||||||
|
high = (ind + IOFFSET) & 0x7fff;
|
||||||
|
if (high != ind + IOFFSET) {
|
||||||
|
ERRBUF3("create_token_ref: index %u larger than %u", ind,
|
||||||
|
0x7fff - IOFFSET);
|
||||||
|
return TE_INTINCON;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the low part of the token (nonce)
|
||||||
|
* SANITY CHECK: Be sure nonce fits into 16 bits
|
||||||
|
*/
|
||||||
|
low = noncectr & 0xffff;
|
||||||
|
if ((low != noncectr++) || low == 0) {
|
||||||
|
ERRBUF3("create_token_ref: generation number %u exceeds %u",
|
||||||
|
noncectr - 1, 0xffff - NOFFSET);
|
||||||
|
return TE_INTINCON;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (TERNARY)((high << 16) | low);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check a token number and turn it into an index.
|
||||||
|
*
|
||||||
|
* Parameters: TERNARY tno ternary token from the user
|
||||||
|
* Returned: int index from the ticket
|
||||||
|
* Errors: TE_BADTOKEN ternary token is invalid because:
|
||||||
|
* * index out of range [0 .. MAXTREES]
|
||||||
|
* * index is for unused slot
|
||||||
|
* * nonce is of old tree
|
||||||
|
* (te_errbuf has disambiguating string)
|
||||||
|
* TE_INTINCON tree is internally inconsistent because:
|
||||||
|
* * nonce is 0
|
||||||
|
* (te_errbuf has disambiguating string)
|
||||||
|
* EXCEPTIONS: none
|
||||||
|
*/
|
||||||
|
static int read_token_ref(TERNARY tno)
|
||||||
|
{
|
||||||
|
unsigned int ind; /* index of current tree */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the index number and check it for validity
|
||||||
|
*/
|
||||||
|
ind = ((tno >> 16) & 0xffff) - IOFFSET;
|
||||||
|
if (ind >= MAXTREES) {
|
||||||
|
ERRBUF3("read_token_ref: index %u exceeds %d", ind, MAXTREES);
|
||||||
|
return TE_BADTOKEN;
|
||||||
|
}
|
||||||
|
if (trees[ind] == NULL) {
|
||||||
|
ERRBUF2("readbuf: token refers to unused tree index %u", ind);
|
||||||
|
return TE_BADTOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We have a valid index; now validate the nonce; note we store the
|
||||||
|
* token in the tree, so just check that (same thing)
|
||||||
|
*/
|
||||||
|
if (trees[ind]->token != tno) {
|
||||||
|
ERRBUF3("readbuf: token refers to old tree (new=%u, old=%u)",
|
||||||
|
(unsigned int)((trees[ind]->token) & 0xffff) - IOFFSET,
|
||||||
|
(unsigned int)(tno & 0xffff) - NOFFSET);
|
||||||
|
return TE_BADTOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for internal consistencies
|
||||||
|
*/
|
||||||
|
if ((trees[ind]->token & 0xffff) == 0) {
|
||||||
|
ERRBUF("read_token_ref: internal inconsistency: nonce = 0");
|
||||||
|
return TE_INTINCON;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new tree
|
||||||
|
*
|
||||||
|
* Parameters: none
|
||||||
|
* Returned: TERNARY token (if > 0); error number (if < 0)
|
||||||
|
* Errors: TE_BADPARAM parameter is NULL
|
||||||
|
* TE_TOOMANYTS too many trees allocated already
|
||||||
|
* TE_NOROOM no memory to allocate new trees
|
||||||
|
* (te_errbuf has descriptive string)
|
||||||
|
* Exceptions: none
|
||||||
|
*/
|
||||||
|
TERNARY ternary_new(void)
|
||||||
|
{
|
||||||
|
int cur; /* index of current tree */
|
||||||
|
TERNARY token; /* new token for current tree */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for array full
|
||||||
|
*/
|
||||||
|
for (cur = 0; cur < MAXTREES; cur++)
|
||||||
|
if (trees[cur] == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (cur == MAXTREES) {
|
||||||
|
ERRBUF2("ternary_new: too many trees (max %d)", MAXTREES);
|
||||||
|
return TE_TOOMANYTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate a new tree
|
||||||
|
*/
|
||||||
|
if ((trees[cur] = malloc(sizeof(Ttree))) == NULL) {
|
||||||
|
ERRBUF("ternary_new: malloc: no more memory");
|
||||||
|
return TE_NOROOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generate token
|
||||||
|
*/
|
||||||
|
if (TE_ISERROR(token = create_token_ref(cur))) {
|
||||||
|
/* error in token generation -- clean up and return */
|
||||||
|
safefree(trees[cur]);
|
||||||
|
trees[cur] = NULL;
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now initialize tree entry
|
||||||
|
*/
|
||||||
|
trees[cur]->token = token;
|
||||||
|
trees[cur]->tree_root = trees[cur]->buf = NULL;
|
||||||
|
trees[cur]->bufn = trees[cur]->freen = 0;
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete an exisiting tree
|
||||||
|
*
|
||||||
|
* Parameters: TERNARY tno token for the tree to be deleted
|
||||||
|
* Returned: uint16_t error code
|
||||||
|
* Errors: TE_BADPARAM parameter refers to deleted, unallocated,
|
||||||
|
* or invalid tree (from read_token_ref()).
|
||||||
|
* TE_INTINCON tree is internally inconsistent (from
|
||||||
|
* read_token_ref()).
|
||||||
|
* Exceptions: none
|
||||||
|
*/
|
||||||
|
int ternary_destroy(TERNARY tno, void (*freeptr)(void *))
|
||||||
|
{
|
||||||
|
int cur; /* index of current tree */
|
||||||
|
unsigned int i, j;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check that tno refers to an existing tree;
|
||||||
|
* read_token_ref sets error code
|
||||||
|
*/
|
||||||
|
if (TE_ISERROR(cur = read_token_ref(tno)))
|
||||||
|
return cur;
|
||||||
|
|
||||||
|
for (i = 0; i < trees[cur]->freen; i++) {
|
||||||
|
for (j = 0; j < BUFSIZE; j++) {
|
||||||
|
Tnode *ptr = (trees[cur]->freearr[i] + j);
|
||||||
|
if (ptr->splitchar == 0)
|
||||||
|
(*freeptr)(ptr->eqkid);
|
||||||
|
safefree(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trees[cur]->token = 0;
|
||||||
|
trees[cur]->tree_root = trees[cur]->buf = NULL;
|
||||||
|
trees[cur]->bufn = trees[cur]->freen = 0;
|
||||||
|
|
||||||
|
return TE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Insert the key/value into an existing tree
|
||||||
|
*
|
||||||
|
* Parameters: TERNARY tno tree to insert data into
|
||||||
|
* char *s NULL terminated string (key)
|
||||||
|
* void *data data to associate with key (can be NULL)
|
||||||
|
* Returned: int error code
|
||||||
|
* Errors: TE_BADPARAM parameter refers to deleted, unallocated, or
|
||||||
|
* invalid tree (from read_token_ref()).
|
||||||
|
* TE_INTINCON tree is internally inconsistent (from
|
||||||
|
* read_token_ref()).
|
||||||
|
* TE_TOOFULL tree is full, so no new elements can be added.
|
||||||
|
* Exceptions: none
|
||||||
|
*/
|
||||||
|
int ternary_insert(TERNARY tno, const char *s, void *data)
|
||||||
|
{
|
||||||
|
int cur; /* index of current tree */
|
||||||
|
Ttree *tree; /* pointer to tree structure */
|
||||||
|
int d;
|
||||||
|
Tnode *pp, **p;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check that tno refers to an existing tree; read_token_ref sets error
|
||||||
|
* code.
|
||||||
|
*/
|
||||||
|
if (TE_ISERROR(cur = read_token_ref(tno)))
|
||||||
|
return cur;
|
||||||
|
|
||||||
|
tree = trees[cur];
|
||||||
|
p = &(tree->tree_root);
|
||||||
|
|
||||||
|
while ((pp = *p)) {
|
||||||
|
if ((d = *s - pp->splitchar) == 0) {
|
||||||
|
if (*s++ == 0) {
|
||||||
|
return TE_EXISTS;
|
||||||
|
}
|
||||||
|
p = &(pp->eqkid);
|
||||||
|
} else if (d < 0)
|
||||||
|
p = &(pp->lokid);
|
||||||
|
else
|
||||||
|
p = &(pp->hikid);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (tree->bufn-- == 0) {
|
||||||
|
tree->buf = calloc(BUFSIZE, sizeof(Tnode));
|
||||||
|
if (!tree->buf) {
|
||||||
|
ERRBUF("ternary_insert: malloc: no more memory");
|
||||||
|
return TE_NOROOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tree->freen == BUFARRAY - 1) {
|
||||||
|
ERRBUF3("ternary_insert: freen %u equals %u",
|
||||||
|
tree->freen,
|
||||||
|
BUFARRAY - 1);
|
||||||
|
return TE_TOOFULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
tree->freearr[tree->freen++] = tree->buf;
|
||||||
|
tree->bufn = BUFSIZE - 1;
|
||||||
|
}
|
||||||
|
*p = tree->buf++;
|
||||||
|
|
||||||
|
pp = *p;
|
||||||
|
pp->splitchar = *s;
|
||||||
|
pp->lokid = pp->eqkid = pp->hikid = NULL;
|
||||||
|
if (*s++ == 0) {
|
||||||
|
pp->eqkid = (Tnode *) data;
|
||||||
|
return TE_NONE;
|
||||||
|
}
|
||||||
|
p = &(pp->eqkid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the data stored with the string
|
||||||
|
*
|
||||||
|
* Parameters: TERNARY tno token for the tree involved
|
||||||
|
* char *s the name the data is stored under
|
||||||
|
* void **d the data (or NULL if you don't care about data)
|
||||||
|
* Returned: int error codes
|
||||||
|
* Errors:
|
||||||
|
* Exceptions:
|
||||||
|
*/
|
||||||
|
int ternary_search(TERNARY tno, const char *s, void **data)
|
||||||
|
{
|
||||||
|
int cur;
|
||||||
|
Tnode *p;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check that tno refers to an existing tree; read_token_ref sets error
|
||||||
|
* code
|
||||||
|
*/
|
||||||
|
if (TE_ISERROR(cur = read_token_ref(tno)))
|
||||||
|
return cur;
|
||||||
|
|
||||||
|
p = trees[cur]->tree_root;
|
||||||
|
|
||||||
|
while (p) {
|
||||||
|
if (*s < p->splitchar)
|
||||||
|
p = p->lokid;
|
||||||
|
else if (*s == p->splitchar) {
|
||||||
|
if (*s++ == 0) {
|
||||||
|
if (data)
|
||||||
|
*data = (void *)p->eqkid;
|
||||||
|
return TE_NONE;
|
||||||
|
}
|
||||||
|
p = p->eqkid;
|
||||||
|
} else
|
||||||
|
p = p->hikid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
*data = (void *)NULL;
|
||||||
|
return TE_EMPTY;
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/* $Id: ternary.h,v 1.2 2000-09-26 04:59:20 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* See 'ternary.c' for a detailed description.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TINYPROXY_TERNARY_H_
|
||||||
|
#define _TINYPROXY_TERNARY_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Holds our token for a ternary tree.
|
||||||
|
*/
|
||||||
|
typedef long int TERNARY;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macros for testing for errors from the various functions.
|
||||||
|
*/
|
||||||
|
#define TE_ISERROR(x) ((x) < 0) /* true if x is tlib error code */
|
||||||
|
#define TE_NONE 0 /* no errors */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Contains any error messages from the functions.
|
||||||
|
*/
|
||||||
|
extern char te_errbuf[256];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macros to fill in te_errbuf
|
||||||
|
*/
|
||||||
|
#define ERRBUF(str) strncpy(te_errbuf, str, sizeof(te_errbuf))
|
||||||
|
#define ERRBUF2(str,n) sprintf(te_errbuf, str, n)
|
||||||
|
#define ERRBUF3(str,n,m) sprintf(te_errbuf, str, n, m)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Error return codes
|
||||||
|
*/
|
||||||
|
#define TE_BADTOKEN -3 /* back token for the trees */
|
||||||
|
#define TE_EMPTY -4 /* there is no data found */
|
||||||
|
#define TE_TOOFULL -5 /* the buffers are filled */
|
||||||
|
#define TE_NOROOM -6 /* can't allocate space (sys err) */
|
||||||
|
#define TE_TOOMANYTS -7 /* too many trees in use */
|
||||||
|
#define TE_INTINCON -8 /* internal inconsistency */
|
||||||
|
#define TE_EXISTS -9 /* key already exists in tree */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Library functions.
|
||||||
|
*/
|
||||||
|
extern TERNARY ternary_new(void);
|
||||||
|
extern int ternary_destroy(TERNARY tno, void (*freeptr)(void *));
|
||||||
|
|
||||||
|
extern int ternary_insert(TERNARY tno, const char *s, void *data);
|
||||||
|
extern int ternary_search(TERNARY tno, const char *s, void **data);
|
||||||
|
|
||||||
|
#endif
|
||||||
-109
@@ -1,109 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The functions included here are useful for text manipulation. They
|
|
||||||
* replace or augment the standard C string library. These functions
|
|
||||||
* are either safer replacements, or they provide services not included
|
|
||||||
* with the standard C string library.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include "text.h"
|
|
||||||
|
|
||||||
#ifndef HAVE_STRLCPY
|
|
||||||
/*
|
|
||||||
* Function API taken from OpenBSD. Like strncpy(), but does not 0 fill the
|
|
||||||
* buffer, and always NULL terminates the buffer. size is the size of the
|
|
||||||
* destination buffer.
|
|
||||||
*/
|
|
||||||
size_t strlcpy (char *dst, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t len = strlen (src);
|
|
||||||
size_t ret = len;
|
|
||||||
|
|
||||||
if (len >= size)
|
|
||||||
len = size - 1;
|
|
||||||
|
|
||||||
memcpy (dst, src, len);
|
|
||||||
dst[len] = '\0';
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAVE_STRLCAT
|
|
||||||
/*
|
|
||||||
* Function API taken from OpenBSD. Like strncat(), but does not 0 fill the
|
|
||||||
* buffer, and always NULL terminates the buffer. size is the length of the
|
|
||||||
* buffer, which should be one more than the maximum resulting string
|
|
||||||
* length.
|
|
||||||
*/
|
|
||||||
size_t strlcat (char *dst, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t len1 = strlen (dst);
|
|
||||||
size_t len2 = strlen (src);
|
|
||||||
size_t ret = len1 + len2;
|
|
||||||
|
|
||||||
if (len1 + len2 >= size)
|
|
||||||
len2 = size - len1 - 1;
|
|
||||||
if (len2 > 0) {
|
|
||||||
memcpy (dst + len1, src, len2);
|
|
||||||
dst[len1 + len2] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Removes any new-line or carriage-return characters from the end of the
|
|
||||||
* string. This function is named after the same function in Perl.
|
|
||||||
* "length" should be the number of characters in the buffer, not including
|
|
||||||
* the trailing NULL.
|
|
||||||
*
|
|
||||||
* Returns the number of characters removed from the end of the string. A
|
|
||||||
* negative return value indicates an error.
|
|
||||||
*/
|
|
||||||
ssize_t chomp (char *buffer, size_t length)
|
|
||||||
{
|
|
||||||
size_t chars;
|
|
||||||
|
|
||||||
assert (buffer != NULL);
|
|
||||||
assert (length > 0);
|
|
||||||
|
|
||||||
/* Make sure the arguments are valid */
|
|
||||||
if (buffer == NULL)
|
|
||||||
return -EFAULT;
|
|
||||||
if (length < 1)
|
|
||||||
return -ERANGE;
|
|
||||||
|
|
||||||
chars = 0;
|
|
||||||
|
|
||||||
--length;
|
|
||||||
while (buffer[length] == '\r' || buffer[length] == '\n') {
|
|
||||||
buffer[length] = '\0';
|
|
||||||
chars++;
|
|
||||||
|
|
||||||
/* Stop once we get to zero to prevent wrap-around */
|
|
||||||
if (length-- == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return chars;
|
|
||||||
}
|
|
||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
/* tinyproxy - A fast light-weight HTTP proxy
|
|
||||||
* Copyright (C) 2002 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 'text.c' for detailed information. */
|
|
||||||
|
|
||||||
#ifndef TINYPROXY_TEXT_H
|
|
||||||
#define TINYPROXY_TEXT_H
|
|
||||||
|
|
||||||
#ifndef HAVE_STRLCAT
|
|
||||||
extern size_t strlcat (char *dst, const char *src, size_t size);
|
|
||||||
#endif /* HAVE_STRLCAT */
|
|
||||||
|
|
||||||
#ifndef HAVE_STRLCPY
|
|
||||||
extern size_t strlcpy (char *dst, const char *src, size_t size);
|
|
||||||
#endif /* HAVE_STRLCPY */
|
|
||||||
|
|
||||||
extern ssize_t chomp (char *buffer, size_t length);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+227
@@ -0,0 +1,227 @@
|
|||||||
|
/* $Id: thread.c,v 1.5 2001-05-27 02:33:35 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* Handles the creation/destruction of the various threads required for
|
||||||
|
* processing incoming connections.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "reqs.h"
|
||||||
|
#include "sock.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
static int listenfd;
|
||||||
|
static socklen_t addrlen;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stores the internal data needed for each thread (connection)
|
||||||
|
*/
|
||||||
|
struct thread_s {
|
||||||
|
pthread_t tid;
|
||||||
|
enum { T_EMPTY, T_WAITING, T_CONNECTED } status;
|
||||||
|
unsigned int connects;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A pointer to an array of threads. A certain number of threads are
|
||||||
|
* created when the program is started.
|
||||||
|
*/
|
||||||
|
static struct thread_s *thread_ptr;
|
||||||
|
static pthread_mutex_t mlock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
static struct thread_config_s {
|
||||||
|
unsigned int maxclients, maxrequestsperchild;
|
||||||
|
unsigned int maxspareservers, minspareservers, startservers;
|
||||||
|
} thread_config;
|
||||||
|
|
||||||
|
static unsigned int servers_waiting; /* servers waiting for a connection */
|
||||||
|
static pthread_mutex_t servers_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
#define SERVER_INC() do { \
|
||||||
|
pthread_mutex_lock(&servers_mutex); \
|
||||||
|
servers_waiting++; \
|
||||||
|
pthread_mutex_unlock(&servers_mutex); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define SERVER_DEC() do { \
|
||||||
|
pthread_mutex_lock(&servers_mutex); \
|
||||||
|
servers_waiting--; \
|
||||||
|
pthread_mutex_unlock(&servers_mutex); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the configuration values for the various thread related settings.
|
||||||
|
*/
|
||||||
|
int thread_configure(thread_config_t type, unsigned int val)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case THREAD_MAXCLIENTS:
|
||||||
|
thread_config.maxclients = val;
|
||||||
|
break;
|
||||||
|
case THREAD_MAXSPARESERVERS:
|
||||||
|
thread_config.maxspareservers = val;
|
||||||
|
break;
|
||||||
|
case THREAD_MINSPARESERVERS:
|
||||||
|
thread_config.minspareservers = val;
|
||||||
|
break;
|
||||||
|
case THREAD_STARTSERVERS:
|
||||||
|
thread_config.startservers = val;
|
||||||
|
break;
|
||||||
|
case THREAD_MAXREQUESTSPERCHILD:
|
||||||
|
thread_config.maxrequestsperchild = val;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DEBUG2("Invalid type (%d)", type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the main (per thread) loop.
|
||||||
|
*/
|
||||||
|
static void *thread_main(void *arg)
|
||||||
|
{
|
||||||
|
int connfd;
|
||||||
|
struct sockaddr *cliaddr;
|
||||||
|
socklen_t clilen;
|
||||||
|
struct thread_s *ptr;
|
||||||
|
|
||||||
|
ptr = (struct thread_s *)arg;
|
||||||
|
|
||||||
|
cliaddr = malloc(addrlen);
|
||||||
|
if (!cliaddr) {
|
||||||
|
log_message(LOG_ERR, "Could not allocate memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( ; ; ) {
|
||||||
|
clilen = addrlen;
|
||||||
|
pthread_mutex_lock(&mlock);
|
||||||
|
connfd = accept(listenfd, cliaddr, &clilen);
|
||||||
|
pthread_mutex_unlock(&mlock);
|
||||||
|
|
||||||
|
ptr->status = T_CONNECTED;
|
||||||
|
|
||||||
|
SERVER_DEC();
|
||||||
|
|
||||||
|
handle_connection(connfd);
|
||||||
|
close(connfd);
|
||||||
|
|
||||||
|
if (thread_config.maxrequestsperchild != 0) {
|
||||||
|
ptr->connects++;
|
||||||
|
|
||||||
|
if (ptr->connects >= thread_config.maxrequestsperchild) {
|
||||||
|
log_message(LOG_NOTICE, "Thread has reached MaxRequestsPerChild... closing.");
|
||||||
|
ptr->status = T_EMPTY;
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
ptr->status = T_WAITING;
|
||||||
|
|
||||||
|
SERVER_INC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create the initial pool of threads.
|
||||||
|
*/
|
||||||
|
int thread_pool_create(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (thread_config.maxclients == 0) {
|
||||||
|
log_message(LOG_ERR, "You must set MaxClients to a value greater than 0");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (thread_config.startservers == 0) {
|
||||||
|
log_message(LOG_ERR, "You must set StartServers to a value greate than 0");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_ptr = calloc((size_t)thread_config.maxclients, sizeof(struct thread_s));
|
||||||
|
if (!thread_ptr)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (thread_config.startservers > thread_config.maxclients) {
|
||||||
|
log_message(LOG_WARNING, "Can not start more than 'MaxClients' servers. Starting %d servers", thread_config.maxclients);
|
||||||
|
thread_config.startservers = thread_config.maxclients;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < thread_config.startservers; i++) {
|
||||||
|
thread_ptr[i].status = T_WAITING;
|
||||||
|
servers_waiting++;
|
||||||
|
pthread_create(&thread_ptr[i].tid, NULL, &thread_main, &thread_ptr[i]);
|
||||||
|
}
|
||||||
|
for (i = thread_config.startservers; i < thread_config.maxclients; i++) {
|
||||||
|
thread_ptr[i].status = T_EMPTY;
|
||||||
|
thread_ptr[i].connects = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keep the proper number of servers running. This is the birth and death
|
||||||
|
* of the servers. It monitors this at least once a second.
|
||||||
|
*/
|
||||||
|
int thread_main_loop(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* If there are not enough spare servers, create more */
|
||||||
|
if (servers_waiting < thread_config.minspareservers) {
|
||||||
|
for (i = 0; i < thread_config.maxclients; i++) {
|
||||||
|
if (thread_ptr[i].status == T_EMPTY) {
|
||||||
|
pthread_create(&thread_ptr[i].tid, NULL, &thread_main, &thread_ptr[i]);
|
||||||
|
thread_ptr[i].status = T_WAITING;
|
||||||
|
thread_ptr[i].connects = 0;
|
||||||
|
|
||||||
|
SERVER_INC();
|
||||||
|
|
||||||
|
log_message(LOG_NOTICE, "Created a new thread.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (servers_waiting > thread_config.maxspareservers) {
|
||||||
|
for (i = 0; i < thread_config.maxclients; i++) {
|
||||||
|
if (thread_ptr[i].status == T_WAITING) {
|
||||||
|
pthread_join(thread_ptr[i].tid, NULL);
|
||||||
|
|
||||||
|
SERVER_DEC();
|
||||||
|
|
||||||
|
thread_ptr[i].status = T_EMPTY;
|
||||||
|
log_message(LOG_NOTICE, "Killed off a thread.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int thread_listening_sock(uint16_t port)
|
||||||
|
{
|
||||||
|
listenfd = listen_sock(port, &addrlen);
|
||||||
|
return listenfd;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void thread_close_sock(void)
|
||||||
|
{
|
||||||
|
close(listenfd);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* $Id: thread.h,v 1.2 2001-05-27 02:33:35 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* See 'thread.c' for more information.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TINYPROXY_THREAD_H_
|
||||||
|
#define _TINYPROXY_THREAD_H_
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
THREAD_MAXCLIENTS,
|
||||||
|
THREAD_MAXSPARESERVERS,
|
||||||
|
THREAD_MINSPARESERVERS,
|
||||||
|
THREAD_STARTSERVERS,
|
||||||
|
THREAD_MAXREQUESTSPERCHILD
|
||||||
|
} thread_config_t;
|
||||||
|
|
||||||
|
extern int thread_pool_create(void);
|
||||||
|
extern int thread_listening_sock(uint16_t port);
|
||||||
|
extern void thread_close_sock(void);
|
||||||
|
extern int thread_main_loop(void);
|
||||||
|
|
||||||
|
extern int thread_configure(thread_config_t type, unsigned int val);
|
||||||
|
|
||||||
|
#endif
|
||||||
+374
@@ -0,0 +1,374 @@
|
|||||||
|
/* $Id: tinyproxy.c,v 1.10 2001-06-02 03:10:34 rjkaes Exp $
|
||||||
|
*
|
||||||
|
* The initialise routine. Basically sets up all the initial stuff (logfile,
|
||||||
|
* listening socket, config options, etc.) and then sits there and loops
|
||||||
|
* over the new connections until the daemon is closed. Also has additional
|
||||||
|
* functions to handle the "user friendly" aspects of a program (usage,
|
||||||
|
* stats, etc.) Like any good program, most of the work is actually done
|
||||||
|
* elsewhere.
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 Steven Young
|
||||||
|
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
|
||||||
|
* Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tinyproxy.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
# include <sys/resource.h>
|
||||||
|
#endif /* HAVE_SYS_RESOUCE_H */
|
||||||
|
#include <grp.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sysexits.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include "anonymous.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
#include "dnscache.h"
|
||||||
|
#include "filter.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "reqs.h"
|
||||||
|
#include "sock.h"
|
||||||
|
#include "stats.h"
|
||||||
|
#include "thread.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
void takesig(int sig);
|
||||||
|
|
||||||
|
extern int yyparse(void);
|
||||||
|
extern FILE *yyin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Global Structures
|
||||||
|
*/
|
||||||
|
struct config_s config;
|
||||||
|
float load = 0.00;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handle a signal
|
||||||
|
*/
|
||||||
|
void takesig(int sig)
|
||||||
|
{
|
||||||
|
switch (sig) {
|
||||||
|
case SIGHUP:
|
||||||
|
if (config.logf)
|
||||||
|
ftruncate(fileno(config.logf), 0);
|
||||||
|
|
||||||
|
log_message(LOG_NOTICE, "SIGHUP received, cleaning up...");
|
||||||
|
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
if (config.filter) {
|
||||||
|
filter_destroy();
|
||||||
|
filter_init();
|
||||||
|
}
|
||||||
|
log_message(LOG_NOTICE, "Re-reading filter file.");
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
log_message(LOG_NOTICE, "Finished cleaning memory/connections.");
|
||||||
|
break;
|
||||||
|
case SIGTERM:
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
if (config.filter)
|
||||||
|
filter_destroy();
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
config.quit = TRUE;
|
||||||
|
log_message(LOG_INFO, "SIGTERM received.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sig != SIGTERM)
|
||||||
|
signal(sig, takesig);
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display the version information for the user.
|
||||||
|
*/
|
||||||
|
static void versiondisp(void)
|
||||||
|
{
|
||||||
|
printf("tinyproxy " VERSION "\n");
|
||||||
|
printf("\
|
||||||
|
Copyright 1998 Steven Young (sdyoung@well.com)\n\
|
||||||
|
Copyright 1998-2000 Robert James Kaes (rjkaes@flarenet.com)\n\
|
||||||
|
Copyright 2000 Chris Lightfoot (chris@ex-parrot.com)\n\
|
||||||
|
\n\
|
||||||
|
This program is free software; you can redistribute it and/or modify it\n\
|
||||||
|
under the terms of the GNU General Public License as published by the Free\n\
|
||||||
|
Software Foundation; either version 2, or (at your option) any later\n\
|
||||||
|
version.\n\
|
||||||
|
\n\
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT\n\
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n\
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\n\
|
||||||
|
more details.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display usage to the user.
|
||||||
|
*/
|
||||||
|
static void usagedisp(void)
|
||||||
|
{
|
||||||
|
printf("\
|
||||||
|
Usage: tinyproxy [options]\n\
|
||||||
|
Options:\n\
|
||||||
|
-d Operate in DEBUG mode.\n\
|
||||||
|
-c FILE Use an alternate configuration file.\n\
|
||||||
|
-h Display this usage information.\n\
|
||||||
|
-v Display the version number.\n");
|
||||||
|
|
||||||
|
|
||||||
|
/* Display the modes compiled into tinyproxy */
|
||||||
|
printf("\nFeatures Compiled In:\n");
|
||||||
|
#ifdef XTINYPROXY_ENABLE
|
||||||
|
printf(" XTinyproxy Header\n");
|
||||||
|
#endif /* XTINYPROXY */
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
printf(" Filtering\n");
|
||||||
|
printf(" * with Regular Expression support\n");
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
#ifndef NDEBUG
|
||||||
|
printf(" Debugging code\n");
|
||||||
|
#endif /* NDEBUG */
|
||||||
|
#ifdef TUNNEL_SUPPORT
|
||||||
|
printf(" TCP Tunneling\n");
|
||||||
|
#endif /* TUNNEL_SUPPORT */
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int optch;
|
||||||
|
bool_t godaemon = TRUE;
|
||||||
|
struct passwd *thisuser = NULL;
|
||||||
|
struct group *thisgroup = NULL;
|
||||||
|
char *conf_file = DEFAULT_CONF_FILE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disable the creation of CORE files right up front.
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_SETRLIMIT
|
||||||
|
struct rlimit core_limit = {0, 0};
|
||||||
|
if (setrlimit(RLIMIT_CORE, &core_limit) < 0) {
|
||||||
|
log_message(LOG_CRIT, "tinyproxy: could not set the core limit to zero.");
|
||||||
|
exit(EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
#endif /* HAVE_SETRLIMIT */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Process the various options
|
||||||
|
*/
|
||||||
|
while ((optch = getopt(argc, argv, "c:vdh")) !=
|
||||||
|
EOF) {
|
||||||
|
switch (optch) {
|
||||||
|
case 'v':
|
||||||
|
versiondisp();
|
||||||
|
exit(EX_OK);
|
||||||
|
case 'd':
|
||||||
|
godaemon = FALSE;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
conf_file = strdup(optarg);
|
||||||
|
if (!conf_file) {
|
||||||
|
log_message(LOG_EMERG, "tinyproxy: could not allocate memory");
|
||||||
|
exit(EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
default:
|
||||||
|
usagedisp();
|
||||||
|
exit(EX_OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read in the settings from the config file.
|
||||||
|
*/
|
||||||
|
yyin = fopen(conf_file, "r");
|
||||||
|
if (!yyin) {
|
||||||
|
log_message(LOG_ERR, "Could not open %s file", conf_file);
|
||||||
|
exit(EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
yyparse();
|
||||||
|
|
||||||
|
/* Open the log file if not using syslog */
|
||||||
|
if (config.syslog == FALSE) {
|
||||||
|
if (!config.logf_name) {
|
||||||
|
log_message(LOG_INFO, "Setting Logfile to \"%s\"", DEFAULT_LOG);
|
||||||
|
config.logf_name = DEFAULT_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(config.logf = fopen(config.logf_name, "a"))) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unable to open logfile %s for appending!\n",
|
||||||
|
config.logf_name);
|
||||||
|
exit(EX_CANTCREAT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (godaemon == TRUE)
|
||||||
|
openlog("tinyproxy", LOG_PID, LOG_DAEMON);
|
||||||
|
else
|
||||||
|
openlog("tinyproxy", LOG_PID, LOG_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message(LOG_INFO, PACKAGE " " VERSION " starting...");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the default values if they were not set in the config file.
|
||||||
|
*/
|
||||||
|
if (config.port == 0) {
|
||||||
|
log_message(LOG_INFO, "Setting Port to %u", DEFAULT_PORT);
|
||||||
|
config.port = DEFAULT_PORT;
|
||||||
|
}
|
||||||
|
if (!config.stathost) {
|
||||||
|
log_message(LOG_INFO, "Setting stathost to \"%s\"", DEFAULT_STATHOST);
|
||||||
|
config.stathost = DEFAULT_STATHOST;
|
||||||
|
}
|
||||||
|
if (!config.username) {
|
||||||
|
log_message(LOG_INFO, "Setting user to \"%s\"", DEFAULT_USER);
|
||||||
|
config.username = DEFAULT_USER;
|
||||||
|
}
|
||||||
|
if (config.idletimeout == 0) {
|
||||||
|
log_message(LOG_INFO, "Setting idle timeout to %u seconds", MAX_IDLE_TIME);
|
||||||
|
config.idletimeout = MAX_IDLE_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_stats();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If ANONYMOUS is turned on, make sure that Content-Length is
|
||||||
|
* in the list of allowed headers, since it is required in a
|
||||||
|
* HTTP/1.0 request. Also add the Content-Type header since it goes
|
||||||
|
* hand in hand with Content-Length.
|
||||||
|
* - rjkaes
|
||||||
|
*/
|
||||||
|
if (config.anonymous) {
|
||||||
|
anon_insert("Content-Length:");
|
||||||
|
anon_insert("Content-Type:");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (godaemon == TRUE)
|
||||||
|
makedaemon();
|
||||||
|
|
||||||
|
if (config.pidpath) {
|
||||||
|
pidfile_create(config.pidpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||||
|
log_message(LOG_CRIT, "Could not set SIGPIPE\n");
|
||||||
|
exit(EX_OSERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
if (config.filter)
|
||||||
|
filter_init();
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start listening on the selected port.
|
||||||
|
*/
|
||||||
|
if (thread_listening_sock(config.port) < 0) {
|
||||||
|
log_message(LOG_CRIT, "Problem creating listening socket");
|
||||||
|
exit(EX_OSERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch to a different user.
|
||||||
|
*/
|
||||||
|
if (geteuid() == 0) {
|
||||||
|
if (config.group && strlen(config.group) > 0) {
|
||||||
|
thisgroup = getgrnam(config.group);
|
||||||
|
if (!thisgroup) {
|
||||||
|
log_message(LOG_ERR, "Unable to find group '%s'!", config.group);
|
||||||
|
exit(EX_NOUSER);
|
||||||
|
}
|
||||||
|
if (setgid(thisgroup->gr_gid) < 0) {
|
||||||
|
log_message(LOG_ERR, "Unable to change to group '%s'", config.group);
|
||||||
|
exit(EX_CANTCREAT);
|
||||||
|
}
|
||||||
|
log_message(LOG_INFO, "Now running as group %s", config.group);
|
||||||
|
}
|
||||||
|
if (config.username && strlen(config.username) > 0) {
|
||||||
|
thisuser = getpwnam(config.username);
|
||||||
|
if (!thisuser) {
|
||||||
|
log_message(LOG_ERR, "Unable to find user '%s'!", config.username);
|
||||||
|
exit(EX_NOUSER);
|
||||||
|
}
|
||||||
|
if (setuid(thisuser->pw_uid) < 0) {
|
||||||
|
log_message(LOG_ERR, "Unable to change to user '%s'", config.username);
|
||||||
|
exit(EX_CANTCREAT);
|
||||||
|
}
|
||||||
|
log_message(LOG_INFO, "Now running as user %s", config.username);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_message(LOG_WARNING, "Not running as root, so not changing UID/GID.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thread_pool_create() < 0) {
|
||||||
|
log_message(LOG_ERR, "Could not create the pool of threads");
|
||||||
|
exit(EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These signals are only for the main thread.
|
||||||
|
*/
|
||||||
|
log_message(LOG_INFO, "Setting the various signals.");
|
||||||
|
if (signal(SIGTERM, takesig) == SIG_ERR) {
|
||||||
|
log_message(LOG_CRIT, "Could not set SIGTERM\n");
|
||||||
|
exit(EX_OSERR);
|
||||||
|
}
|
||||||
|
if (signal(SIGHUP, takesig) == SIG_ERR) {
|
||||||
|
log_message(LOG_CRIT, "Could not set SIGHUP\n");
|
||||||
|
exit(EX_OSERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize the various subsystems...
|
||||||
|
*/
|
||||||
|
log_message(LOG_INFO, "Starting the DNS caching subsystem.");
|
||||||
|
if (!new_dnscache())
|
||||||
|
exit(EX_SOFTWARE);
|
||||||
|
log_message(LOG_INFO, "Starting the Anonymous header subsystem.");
|
||||||
|
if (!new_anonymous())
|
||||||
|
exit(EX_SOFTWARE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the main loop.
|
||||||
|
*/
|
||||||
|
log_message(LOG_INFO, "Starting main loop. Accepting connections.");
|
||||||
|
do {
|
||||||
|
thread_main_loop();
|
||||||
|
sleep(1);
|
||||||
|
} while (!config.quit);
|
||||||
|
|
||||||
|
log_message(LOG_INFO, "Shutting down.");
|
||||||
|
thread_close_sock();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove the PID file.
|
||||||
|
*/
|
||||||
|
if (unlink(config.pidpath) < 0) {
|
||||||
|
log_message(LOG_WARNING, "Could not remove PID file %s: %s",
|
||||||
|
config.pidpath, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef FILTER_ENABLE
|
||||||
|
if (config.filter)
|
||||||
|
filter_destroy();
|
||||||
|
#endif /* FILTER_ENABLE */
|
||||||
|
|
||||||
|
if (config.syslog == FALSE)
|
||||||
|
fclose(config.logf);
|
||||||
|
else
|
||||||
|
closelog();
|
||||||
|
|
||||||
|
exit(EX_OK);
|
||||||
|
}
|
||||||
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user