Compare commits

..
47 Commits
Author SHA1 Message Date
Mukund Sivaraman a46a02dbf7 Tweak configure.ac a bit 2008-08-24 12:26:11 +05:30
Mukund Sivaraman 7518fbb956 Update the bugmail address 2008-08-24 12:15:26 +05:30
Mukund Sivaraman 08b4e06247 Fix leak of args 2008-08-24 12:09:17 +05:30
Mukund Sivaraman fc815b12c1 Move buffer to the heap due to its size 2008-08-24 12:07:24 +05:30
Mukund Sivaraman b6bd791e24 Set umask before mkstemp() for some versions of glibc 2008-08-24 12:02:54 +05:30
Mukund Sivaraman ee70057f76 Fix leak of entry_buffer 2008-08-24 11:59:24 +05:30
Mukund Sivaraman a7f379fafc pos can never be less than 0 as it's of type size_t
Also fix the type which is passed in from various places.
2008-08-24 11:55:22 +05:30
Mukund Sivaraman 1e44781c4d Remove unused autoconf macro calls 2008-07-30 19:35:48 +05:30
Mukund Sivaraman bb5bbb6431 Fix the bug-report field 2008-07-30 18:53:17 +05:30
Jeremy Hinegardner fbb43fb72b fix building of Makefiles in packaging subtree
When ./configure is run, the Makfiles in the packaging subtree's
Makefiles are not created.  As a result, the 'make dist' command will
fail when it attempts to recurse through ./packaging.

Signed-off-by: Jeremy Hinegardner <jeremy@hinegardner.org>
2008-06-24 12:33:17 +05:30
Mukund Sivaraman 20ac984707 Add new Fedora packaging files
These spec files were made by Jeremy Hinegardner <jeremy@hinegardner.org>
and backported from master to the 1.6 branch by me.

X-Banu-Bugzilla-Ids: 11
2008-06-19 22:09:22 +05:30
Mukund Sivaraman 4a993787ca Remove obsolete packaging files 2008-06-19 22:09:22 +05:30
Mukund Sivaraman 100cc20291 Remove releases.txt from EXTRA_DIST 2008-06-19 22:09:22 +05:30
Mukund Sivaraman e9c5ecedba Bump version to 1.6.4 2008-06-19 22:09:21 +05:30
Mukund Sivaraman f4af613d48 Don't use config directory for aclocal 2008-06-19 22:09:21 +05:30
Mukund Sivaraman 742248b600 Remove Id tag from configure.ac 2008-06-19 22:09:21 +05:30
Mukund Sivaraman 7f189fb730 Ignore ylwrap 2008-06-19 22:09:21 +05:30
Mukund Sivaraman 02054cef92 Add src/.gitignore 2008-06-19 22:09:21 +05:30
Mukund Sivaraman 8784e32e25 Add top-level .gitignore 2008-06-19 22:09:20 +05:30
Mukund Sivaraman 61f8ab527c Fix format strings for size_t 2008-06-19 22:09:20 +05:30
Mukund Sivaraman 92f5bdce14 Use socklen_t for sizeof sockaddr_in 2008-05-31 19:11:25 +05:30
Mukund Sivaraman 0a16445b69 Don't override YFLAGS and LDFLAGS 2008-05-31 19:08:56 +05:30
Mukund Sivaraman 1df038294b Removed the clean target from the src directory 2008-05-11 16:11:59 +05:30
Mukund Sivaraman 893aaabe9c Added autogen.sh 2008-05-11 16:09:17 +05:30
Mukund Sivaraman c82f07a021 Added required file NEWS 2008-05-11 16:09:05 +05:30
Mukund Sivaraman 9f37380de5 Added required file ltmain.sh 2008-05-11 16:08:59 +05:30
Robert James Kaes 1768fc0755 # Updated changelog to reflect that 1.6.3 is released today. 2004-08-10 20:03:16 +00:00
Robert James Kaes bebc78a7e6 # Updated changelog 2004-08-10 15:34:48 +00:00
Robert James Kaes 4a8c4d55f0 Close the standard file descriptors (stdin, stdout, and stderr) when
compiling in production mode (no debugging information.)
2004-08-10 03:38:13 +00:00
Robert James Kaes c6711d7d38 # Real update. The last changelog update also included updates from HEAD 2004-08-09 20:43:02 +00:00
Robert James Kaes c120c62fd9 # Updated changelog 2004-08-09 18:52:23 +00:00
Robert James Kaes 05ed84f04c # Updated version number 2004-08-09 18:48:48 +00:00
Robert James Kaes 385fae593d [Fixes Bug 996518]
Merged in a patch from Hans-Dieter that fixes a problem with upstream
proxy support.
2004-08-06 16:56:55 +00:00
Robert James Kaes cde61e2fac child_configure(): Change the "val" type to a signed integer. 2004-06-14 20:49:57 +00:00
Robert James Kaes cc3a893f5a Changed the fields in the child_config_s structure to use regular
signed integers since the servers_waiting variable is signed and
therefore, all the tests must use signed arithmetic.
2004-06-14 20:08:12 +00:00
Robert James Kaes cd9c768c59 (upstream_add): Fixed a spelling mistake with "Nonsence" 2003-11-19 19:20:18 +00:00
Robert James Kaes acb5026545 # Updated ChangeLog 2003-10-17 15:43:33 +00:00
Robert James Kaes 53ad8ef067 # Bumped up the version number 2003-10-17 15:39:23 +00:00
Robert James Kaes d475d44cc0 Removed a redundant "mkdir" command, since the $(mkinstalldirs)
command handles it correctly.
2003-10-17 15:38:28 +00:00
Robert James Kaes b1d126c4bb (filter_init): Fixed up the comment handling code. Closes bug 822226
[https://sourceforge.net/tracker/index.php?func=detail&aid=822226&group_id=2632&atid=102632]
2003-10-16 21:19:09 +00:00
Robert James Kaes b8d7ee66a5 Added a missing $(DESTDIR) to the tinyproxy-html-files rule. Thanks
to Ed Boraas for pointing this out.
2003-08-14 15:13:24 +00:00
Robert James Kaes 4f48cb16c7 # Bumped up the version number 2003-08-06 20:52:08 +00:00
Robert James Kaes 074af84f63 # Updated changelog 2003-08-06 20:51:45 +00:00
Robert James Kaes e04dd2ee69 # Misspelled the __cplusplus define. 2003-08-06 20:46:04 +00:00
Robert James Kaes c315bce11b (debugging_realloc): Remove the assert on the ptr being NULL since a
NULL pointer is allowed by the realloc() spec.
2003-08-06 20:44:09 +00:00
Robert James Kaes 6a11a9c909 (child_main): Fixed an off-by-one error with the maxrequestsperchild
variable.  [Fix proposed by Yannick Koehler]
2003-08-06 20:23:06 +00:00
cvs2svn 4beea1ac67 This commit was manufactured by cvs2svn to create branch
'release_1_6_patches'.
2003-07-14 17:45:12 +00:00
106 changed files with 10200 additions and 6823 deletions

No files matched your search

+3 -1
View File
@@ -1,3 +1,4 @@
COPYING
INSTALL INSTALL
Makefile Makefile
Makefile.in Makefile.in
@@ -14,8 +15,9 @@ depcomp
install-sh install-sh
libtool libtool
missing missing
mkinstalldirs
stamp-h1 stamp-h1
ylwrap
autom4te.cache autom4te.cache
cscope.files cscope.files
cscope.out cscope.out
*~
+8 -15
View File
@@ -1,19 +1,12 @@
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 was once again be the primary maintainer.
Robert James Kaes is the current maintainer and lead programmer. He But, Robert James Kaes was again the maintainer starting with 1.4.0.
also maintained the project between versions 1.2 and 1.3.0, and again Place your bets as to when the maintainer will change again. :) Kidding!
starting with version 1.4.0.
Please see the ChangeLog for futher details as to who did what. :)
Major Additions/Improvements
----------------------------
James E. Flemer <jflemer@acm.jhu.edu> - URL/domain filtering
Kim Holviala <kim@holviala.com> - Reverse proxy support
Petr Lampa <lampa@fit.vutbr.cz> - Transparent proxy support
George Talusan <gstalusan@uwaterloo.ca> - URL/domain filtering
-339
View File
@@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
+19 -11
View File
@@ -1,23 +1,31 @@
2004-08-10 Robert James Kaes <rjkaes@users.sourceforge.net> 2004-08-10 Robert James Kaes <rjkaes@users.sourceforge.net>
Merged in changes from 1.6.3. Released tinyproxy 1.6.3 (2004-08-10)
2004-01-26 Robert James Kaes <rjkaes@flarenet.com> * src/daemon.c (makedaemon): Close the standard file descriptors
when compiling a production executable. I only need these left
open when doing debugging.
Released tinyproxy 1.7.0 (2004-01-26) 2004-08-06 Robert James Kaes <rjkaes@users.sourceforge.net>
* configure.ac, doc/tinyproxy.conf, src/conns.c, src/conns.h, src/grammar.y, src/reqs.c, src/reqs.h, src/scanner.l, src/tinyproxy.c, src/tinyproxy.h: * src/conns.c, src/conns.h, src/reqs.c, src/tinyproxy.h:
Added reverse proxy support from Kim Holviala. [Fixes Bug 996518]
Merged in a patch from Hans-Dieter that fixes a problem with upstream
proxy support.
2003-11-19 Robert James Kaes <rjkaes@flarenet.com> 2004-06-14 Robert James Kaes <rjkaes@users.sourceforge.net>
* src/reqs.c (upstream_add): Fixed a spelling mistake with "Nonsence" * src/child.h (child_configure): Change the "val" type to a
signed integer.
2003-10-17 Robert James Kaes <rjkaes@flarenet.com> * src/child.c: Changed the fields in the child_config_s structure
to use regular signed integers since the servers_waiting variable
is signed and therefore, all the tests must use signed arithmetic.
* src/filter.c, ChangeLog, Makefile.am, configure.ac: 2003-11-19 Robert James Kaes <rjkaes@users.sourceforge.net>
Merged in changes from the 1.6.2 release. (Fixes for the filtering code
and the HTML installation script.) * src/reqs.c (upstream_add): Fixed a spelling mistake with
"Nonsence"
2003-10-17 Robert James Kaes <rjkaes@flarenet.com> 2003-10-17 Robert James Kaes <rjkaes@flarenet.com>
+34 -18
View File
@@ -1,22 +1,38 @@
SUBDIRS = \ EXTRA_DIST = $(CONFIG_FILES) TODO autogen.sh
src \ SUBDIRS = src doc packaging
data \
etc \
docs \
m4macros \
packaging \
tests
# tools want this on a single line install-data-local: tinyproxy-configure-file tinyproxy-html-files
ACLOCAL_AMFLAGS = -I m4macros
EXTRA_DIST = \ # Install the configuration file if it doesn't already exist
autogen.sh \ tinyproxy-configure-file:
tinyproxy-indent.sh \ $(mkinstalldirs) $(DESTDIR)@TINYPROXY_CONFIG_DIR@
TODO $(INSTALL) -m 600 $(srcdir)/doc/tinyproxy.conf \
$(DESTDIR)@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@-dist
test -f $(DESTDIR)@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@ \
|| $(INSTALL) -m 600 $(srcdir)/doc/tinyproxy.conf \
$(DESTDIR)@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@
@echo ""
@echo "A configuration file has been copied to:"
@echo ""
@echo "@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@-dist"
@echo ""
@echo "You will need to rename this file to:"
@echo ""
@echo "@TINYPROXY_CONFIG_DIR@/@TINYPROXY_CONFIG_FILE@"
@echo ""
@echo "and modify the values to suit your local system."
@echo ""
@echo "All the configuration directives are commented in the file, so"
@echo "you should not have any problems configuring your system."
@echo ""
test: all # Install the HTML files
./tests/scripts/run_tests.sh tinyproxy-html-files:
$(mkinstalldirs) $(DESTDIR)$(datadir)/tinyproxy
valgrind-test: all for file in debug default stats; do \
./tests/scripts/run_tests_valgrind.sh $(INSTALL) -m 644 $(srcdir)/doc/$$file.html $(DESTDIR)$(datadir)/tinyproxy/$$file.html.dist ; \
test -f $(DESTDIR)$(datadir)/tinyproxy/$$file.html || \
$(INSTALL) -m 644 $(srcdir)/doc/$$file.html $(DESTDIR)$(datadir)/tinyproxy/$$file.html ; \
done
$(INSTALL) -m 644 $(srcdir)/doc/HTML_VARIABLES $(DESTDIR)$(datadir)/tinyproxy/HTML_VARIABLES
-26
View File
@@ -1,26 +0,0 @@
Tinyproxy NEWS
==============
Version 1.7.1
-------------
* Fixed all warnings reported by GCC
* Wrote improved asciidoc manpages
* Cleaned up build system
* Fixed various other bugs
Bugs fixed since version 1.7.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#2: Fix Tinyproxy for requests like www.site.com:8001
* BB#5: Move templates from the doc directory to its own directory
* BB#8: Update README, INSTALL, NEWS and the manpage
* BB#10: Do not filter out transfer-encoding header
* BB#18: Fix pointer aliasing issues
* BB#53: Add a GPLv2 COPYING file
Contributors
~~~~~~~~~~~~
Andrew Stribblehill, Jeremy Hinegardner, Matthew Dempsky, Michael Adam,
Mukund Sivaraman, Robert James Kaes.
+74 -65
View File
@@ -1,97 +1,106 @@
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 tinyproxy is a small, efficient HTTP/SSL proxy daemon released under
connection concept. In effect, Tinyproxy will buffer a high speed the GNU General Public License (GPL). tinyproxy is very useful in a
response from a server, and then relay it to a client at the highest small network setting, where a larger proxy like Squid would either
speed the client will accept. This feature greatly reduces the problems be too resource intensive, or a security risk. One of the key
with sluggishness on the Internet. If you are sharing an Internet features of tinyproxy is the buffering connection concept. In
connection with a small network, and you only want to allow HTTP effect, tinyproxy will buffer a high speed response from a server,
requests to be allowed, then Tinyproxy is a great tool for the network 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. administrator.
For more info, please visit:
https://www.banu.com/tinyproxy/ 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 (basically you
be able to do: should be able to do:
---- ./configure ; make ; make install
./configure
make
make install
----
in the top level directory to compile and install Tinyproxy. There are in the top level directory to compile and install tinyproxy). There
additional command line arguments you can supply to `configure`. They are additional command line arguments you can supply to configure.
include: 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-upstream Enable support for proxying connections
through another proxy server. through another proxy server.
--enable-transparent-proxy --enable-transparent-proxy
Allow Tinyproxy to be used as a Allow tinyproxy to be used as a
transparent proxy daemon transparent proxy daemon
--enable-static Compile a static version of Tinyproxy --enable-static Compile a static version of tinyproxy
Options for file locations etc.
--with-stathost=HOST Set the default name of the stats host --with-stathost=HOST Set the default name of the stats host
--with-config=FILE Set the default location of the
configuration file
Once you have completed your installation, if you would like to
report your success please execute the report.sh script in the doc
directory. This will send an email to the authors reporting your
version, and a few bits of information concerning the memory usage of
tinyproxy. Alternatively, you could just send an email stating the
version, whichever you prefer.
Support SUPPORT
------- -------
If you are having problems with Tinyproxy, please submit a bug report If you are having problems with tinyproxy, please submit a bug to the
using Tinyproxy as the component at: tinyproxy Bug Tracking system hosted by SourceForge and located at:
https://www.banu.com/bugzilla/ http://sourceforge.net/tracker/?group_id=2632
You may also wish to subscribe to the Tinyproxy mailing lists. To do so You may also wish to subscribe to the tinyproxy-user mailing list. To
please visit: do so please visit:
https://www.banu.com/mailman/listinfo/tinyproxy-announce-list http://lists.sourceforge.net/lists/listinfo/tinyproxy-users
https://www.banu.com/mailman/listinfo/tinyproxy-users-list
https://www.banu.com/mailman/listinfo/tinyproxy-developers-list
for more information on how to subscribe and post messages to the lists. for more information on how to subscribe and post messages to the
list.
Please recompile tinyproxy with full debug support (--enable-debug)
and include a copy of the log file, and any assert errors reported by
tinyproxy. Note that tinyproxy will output memory statistics to
standard error if compiled with debugging support so you might want
to redirect the output to a file for later examination. Also, if you
feel up to it, try running tinyproxy under your debugger and report
the error your received and a context listing of the location. Under
gdb you would run tinyproxy like so:
gdb tinyproxy
(gdb) run -c location_of_tinyproxy_conf -d 2>/dev/null
Now access the port tinyproxy is on until you receive a break in the
gdb. You can now type:
(gbd) l
to produce a context listing of the location of the error. Send a
copy to the authors.
Contributing HOW TO CONTRIBUTE TO tinyproxy
------------ ------------------------------
If you would like to contribute a feature, or a bug fix to the Tinyproxy If you would like to contribute a feature, or a bug fix to the
source, please send a patch (preferably as a unified diff. i.e. `diff tinyproxy source, please send a diff (preferable a unified
-u` against the "master" branch of the Tinyproxy source code git diff. i.e. "diff -u") against the latest release of tinyproxy. Also,
repository to tinyproxy-developers-list. Please include a description if you could include a brief description of what your patch does.
of what your patch does.
Tinyproxy's git repository is git://www.banu.com/tinyproxy.git. The
following command creates a local copy:
----
git clone git://www.banu.com/tinyproxy.git
----
The easiest and preferred way to create a patch for submission is to
check in your changes locally and use `git format-patch` to generate a
mbox-style commit file that contains the diff along with the commit
message and author information. Such a format-patch file can be
integrated into the upstream repository, automatically keeping the
commit message and author information.
You can also meet developers and discuss development issues and patches
in the #tinyproxy IRC channel on Freenode (irc.freenode.net).
File renamed without changes.
+7 -24
View File
@@ -1,30 +1,13 @@
#!/bin/sh #!/bin/sh
# -*- sh -*-
srcdir=`dirname $0` #
test -z "$srcdir" && srcdir=. # Make the Autotools scripts after checking out the source code from CVS.
ORIGDIR=`pwd` # This script was taken from the Autotool Book. I wonder if autoreconf
# can now be used...
#
set -x set -x
aclocal \
cd $srcdir
aclocal -I m4macros \
&& autoheader \ && autoheader \
&& automake --gnu --add-missing \ && automake --gnu --add-missing \
&& autoconf && autoconf
cd $ORIGDIR
set -
echo $srcdir/configure --enable-maintainer-mode "$@"
$srcdir/configure --enable-maintainer-mode "$@"
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."
+172 -132
View File
@@ -1,84 +1,88 @@
# Process this file with autoconf to produce a configure script.
# Portions of this file were adapted from GIMP.
AC_PREREQ(2.54) AC_PREREQ(2.54)
m4_define([tinyproxy_major_version], [1]) AC_INIT([Tinyproxy], [1.6.4], [https://dev.banu.com/bugzilla/enter_bug.cgi?product=Tinyproxy], [tinyproxy])
m4_define([tinyproxy_minor_version], [7])
m4_define([tinyproxy_micro_version], [1])
m4_define([tinyproxy_real_version],
[tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
m4_define([tinyproxy_version], [tinyproxy_real_version])
# For overriding the version string. Comment out if not needed.
# m4_define([tinyproxy_version], [0.7.0])
m4_define([tinyproxy_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://www.banu.com/bugzilla/enter_bug.cgi?product=Tinyproxy],
[tinyproxy])
AC_CANONICAL_TARGET AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
AC_CONFIG_MACRO_DIR([m4macros])
AM_MAINTAINER_MODE AM_MAINTAINER_MODE
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([no])])
TINYPROXY_MAJOR_VERSION=tinyproxy_major_version AH_TEMPLATE([TARGET_SYSTEM],
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version [A string containing the target system for which tinyproxy was built.])
TINYPROXY_MICRO_VERSION=tinyproxy_micro_version AC_DEFINE_UNQUOTED(TARGET_SYSTEM, ["$target"])
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 :) dnl Check if we're compiling on a weird platform :)
AC_USE_SYSTEM_EXTENSIONS AC_AIX
AC_GNU_SOURCE
AC_MINIX
dnl
dnl Command line options
dnl
dnl Set the domain name for find the statistics of tinyproxy dnl Set the URL name for find the statistics of tinyproxy
AH_TEMPLATE([TINYPROXY_STATHOST], AH_TEMPLATE([DEFAULT_STATHOST],
[This controls remote proxy stats display.]) [This controls remote proxy stats display.])
AC_ARG_WITH(stathost, AC_ARG_WITH(stathost,
[AC_HELP_STRING([--with-stathost=HOST], [Default status host])], [AC_HELP_STRING([--with-stathost=HOST], [Default status host])],
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "$withval")], [AC_DEFINE_UNQUOTED(DEFAULT_STATHOST, "$withval")],
[AC_DEFINE_UNQUOTED(TINYPROXY_STATHOST, "tinyproxy.stats")]) [AC_DEFINE_UNQUOTED(DEFAULT_STATHOST, "tinyproxy.stats")])
dnl Set the default configuration file location
test "$prefix" = "NONE" && prefix=/usr/local
AH_TEMPLATE([DEFAULT_CONF_FILE],
[This is the default file name for the configuration file.])
AC_ARG_WITH(config,
[AC_HELP_STRING([--with-config=FILE],
[Set the default location of the config file])],
[tp_config_file="$withval"],
[tp_config_file="tinyproxy.conf"])
# If the first character is a slash, it's an absolute path
if [[ `echo $tp_config_file | cut -c1` = "/" ]]; then
TINYPROXY_CONFIG_DIR=`echo "$tp_config_file" | sed 's/^\(.*\)\/[[^\/]]*$/\1/'`
TINYPROXY_CONFIG_FILE=`echo "$tp_config_file" | sed 's/^.*\/\([[^\/]]*\)$/\1/'`
else
# If sysconfdir is /usr/etc, change it to /etc (since /usr/etc doesn't exist)
if [[ "/usr/etc" = `eval echo $sysconfdir` -a "/usr" = "$prefix" ]]; then
TINYPROXY_CONFIG_DIR="/etc/tinyproxy"
else
TINYPROXY_CONFIG_DIR=`eval echo $sysconfdir/tinyproxy`
fi
TINYPROXY_CONFIG_FILE="$tp_config_file"
fi
AC_DEFINE_UNQUOTED(DEFAULT_CONF_FILE, "$TINYPROXY_CONFIG_DIR/$TINYPROXY_CONFIG_FILE")
AC_MSG_NOTICE([Default config location and file is: $TINYPROXY_CONFIG_DIR/$TINYPROXY_CONFIG_FILE])
dnl Add compiler-specific optimization flags dnl Add compiler-specific optimization flags
TP_ARG_ENABLE(debug, AC_ARG_ENABLE(debug,
[Enable debugging support code and methods (default is NO)], [AC_HELP_STRING([--enable-debug],
no) [Disable aggressive optimizations (default is NO)])],
debug_enabled=$enableval, debug_enabled=no)
dnl Add in profiling information
AC_ARG_ENABLE(profiling,
[AC_HELP_STRING([--enable-profiling],
[Enable profiling information (default is NO)])],
profiling_enabled=$enableval, profiling_enabled=no)
dnl Include SOCKS support
AC_ARG_ENABLE(socks,
[AC_HELP_STRING([--enable-socks],
[Enable SOCKS support (default is NO)])],
socks_enabled=$enableval, socks_enabled=no)
dnl Check to see if the XTinyproxy header is to be included dnl Check to see if the XTinyproxy header is to be included
AH_TEMPLATE([XTINYPROXY_ENABLE], AH_TEMPLATE([XTINYPROXY_ENABLE],
[Define if you want to have the peer's IP address included in a XTinyproxy header sent to the server.]) [Define if you want to have the peer's IP address included in a XTinyproxy header sent to the server.])
TP_ARG_ENABLE(xtinyproxy, AC_ARG_ENABLE(xtinyproxy,
[Include the X-Tinyproxy header (default is YES)], [AC_HELP_STRING([--enable-xtinyproxy],
yes) [Include X-Tinyproxy header (default is YES)])],
xtinyproxy_enabled=$enableval, xtinyproxy_enabled=yes)
if test x"$xtinyproxy_enabled" = x"yes"; then if test x"$xtinyproxy_enabled" = x"yes"; then
AC_DEFINE(XTINYPROXY_ENABLE) AC_DEFINE(XTINYPROXY_ENABLE)
@@ -87,9 +91,10 @@ fi
dnl Include filtering for domain/URLs dnl Include filtering for domain/URLs
AH_TEMPLATE([FILTER_ENABLE], AH_TEMPLATE([FILTER_ENABLE],
[Defined if you would like filtering code included.]) [Defined if you would like filtering code included.])
TP_ARG_ENABLE(filter, AC_ARG_ENABLE(filter,
[Enable filtering of domains/URLS (default is YES)], [AC_HELP_STRING([--enable-filter],
yes) [Enable filtering of domains/URLs (default is YES)])],
filter_enabled=$enableval, filter_enabled=yes)
if test x"$filter_enabled" = x"yes"; then if test x"$filter_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS filter.o" ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS filter.o"
@@ -99,37 +104,55 @@ fi
dnl Include support for upstream proxies? dnl Include support for upstream proxies?
AH_TEMPLATE([UPSTREAM_SUPPORT], AH_TEMPLATE([UPSTREAM_SUPPORT],
[Include support for connecting to an upstream proxy.]) [Include support for connecting to an upstream proxy.])
TP_ARG_ENABLE(upstream, AC_ARG_ENABLE(upstream,
[Enable upstream proxying (default is YES)], [AC_HELP_STRING([--enable-upstream],
yes) [Enable support for upstream proxies (default is YES)])],
upstream_enabled=$enableval, upstream_enabled=yes)
if test x"$upstream_enabled" = x"yes"; then if test x"$upstream_enabled" = x"yes"; then
AC_DEFINE(UPSTREAM_SUPPORT) AC_DEFINE(UPSTREAM_SUPPORT)
fi fi
dnl Include support for reverse proxy?
AH_TEMPLATE([REVERSE_SUPPORT],
[Include support for reverse proxy.])
TP_ARG_ENABLE(reverse,
[Enable reverse proxying (default is NO)],
no)
if test x"$reverse_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
AC_DEFINE(REVERSE_SUPPORT)
fi
dnl Include the transparent proxy support dnl Include the transparent proxy support
AH_TEMPLATE([TRANSPARENT_PROXY], AH_TEMPLATE([TRANSPARENT_PROXY],
[Include support for using tinyproxy as a transparent proxy.]) [Include support for using tinyproxy as a transparent proxy.])
TP_ARG_ENABLE(transparent, AC_ARG_ENABLE(transparent-proxy,
[Enable transparent proxying code (default is NO)], [AC_HELP_STRING([--enable-transparent-proxy],
no) [Enable transparent proxy support (default is NO)])],
transparent_enabled=$enableval, transparent_enabled=no)
if test x"$transparent_enabled" = x"yes"; then if test x"$transparent_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
AC_DEFINE(TRANSPARENT_PROXY) AC_DEFINE(TRANSPARENT_PROXY)
fi fi
# This is required to build test programs below dnl Include support for a statically compiled tinyproxy
AC_ARG_ENABLE(static,
[AC_HELP_STRING([--enable-static],
[Statically link tinyproxy (default is NO)])],
[LDFLAGS="-static $LDFLAGS"])
dnl
dnl Checks for programs
dnl
AC_PROG_MAKE_SET
AC_PROG_CC AC_PROG_CC
AC_ISC_POSIX
AC_PROG_INSTALL
AM_PROG_LEX
AC_PROG_YACC
dnl If a CFLAGS variable was passed during configure, set the initial
dnl CFLAGS variable to it; otherwise, start with an empty CFLAGS
if test x"$ac_env_CFLAGS_set" = x"set" ; then
CFLAGS=$ac_env_CFLAGS_value
else
CFLAGS=""
fi
dnl Make sure YACC is actually bison
if test x"$YACC" != x"bison -y"; then
AC_MSG_WARN([You will need bison if you want to regenerate the parser.])
fi
dnl dnl
dnl Checks for libraries dnl Checks for libraries
@@ -151,20 +174,19 @@ if test x"$tinyproxy_no_nsl_checks" != x"yes"; then
fi fi
AC_CHECK_LIB(resolv, inet_aton) AC_CHECK_LIB(resolv, inet_aton)
AC_CHECK_LIB(socks, main, socks_library=yes, socks_library=no)
dnl dnl
dnl Checks for headers dnl Checks for headers
dnl dnl
AC_HEADER_STDC AC_HEADER_STDC
AC_HEADER_TIME AC_HEADER_TIME
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \ AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \
sys/select.h sys/socket.h sys/time.h sys/uio.h \ sys/select.h sys/socket.h sys/time.h sys/uio.h \
sys/un.h arpa/inet.h netinet/in.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 \ 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 \ netdb.h pwd.h regex.h signal.h stdarg.h stddef.h stdio.h \
sysexits.h syslog.h time.h wchar.h wctype.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 OpenBSD machines don't like having malloc included (even if it's present)
dnl as they expect you to use stdlib.h dnl as they expect you to use stdlib.h
@@ -173,10 +195,18 @@ case "$target" in
*) AC_CHECK_HEADER(malloc.h);; *) AC_CHECK_HEADER(malloc.h);;
esac esac
AC_CHECK_HEADER(socks.h, socks_header=yes, socks_header=no)
dnl
dnl Checks for types dnl Checks for types
dnl
AM_C_PROTOTYPES
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T AC_TYPE_SIZE_T
AC_TYPE_PID_T AC_TYPE_PID_T
AC_TYPE_SIGNAL
AC_UNP_CHECK_TYPE(uint8_t, unsigned char) AC_UNP_CHECK_TYPE(uint8_t, unsigned char)
AC_UNP_CHECK_TYPE(int16_t, short) AC_UNP_CHECK_TYPE(int16_t, short)
AC_UNP_CHECK_TYPE(uint16_t, unsigned short) AC_UNP_CHECK_TYPE(uint16_t, unsigned short)
@@ -187,42 +217,65 @@ AC_UNP_CHECK_TYPE(socklen_t, unsigned int)
AC_UNP_CHECK_TYPE(in_addr_t, uint32_t) AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
dnl
dnl Checks for libary functions dnl Checks for libary functions
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK dnl
AC_FUNC_MALLOC AC_FUNC_ALLOCA
AC_FUNC_REALLOC
AC_CHECK_FUNCS([gethostname inet_ntoa memchr memset select socket strcasecmp \ AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regexec])
strchr strdup strerror strncasecmp strpbrk strstr strtol])
AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regcomp regexec])
AC_CHECK_FUNCS([strlcpy strlcat]) AC_CHECK_FUNCS([strlcpy strlcat])
dnl
dnl Compiler characteristics
dnl
dnl Enable extra warnings dnl If profiling is enabled, then enable the debugging code
DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -pedantic -Wc++-compat -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common" if test x"$profiling_enabled" = x"yes" ; then
AC_MSG_NOTICE([profiling is enabled, therefore enabling debugging code.])
if test -n "${MAINTAINER_MODE_FALSE}"; then debug_enabled=yes
DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
fi fi
for flag in $DESIRED_FLAGS; do dnl Enable the debugging flags (by checking for the GCC compiler)
AS_COMPILER_FLAG([$flag], [CFLAGS="$CFLAGS $flag"]) if test x"$debug_enabled" = x"yes" ; then
done dnl Add the warnings if we have the GCC compiler
if test x"$GCC" = x"yes" ; then
dnl Disable debugging if it's not specified if test x"$profiling_enabled" = x"yes" ; then
if test x"$debug_enabled" != x"yes" ; then CFLAGS="-pg -fprofile-arcs $CFLAGS"
CFLAGS="-DNDEBUG $CFLAGS"
fi fi
CFLAGS="-Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes $CFLAGS"
CFLAGS="-Wmissing-prototypes -Wmissing-declarations $CFLAGS"
CFLAGS="-Wpointer-arith -Waggregate-return -Wnested-externs $CFLAGS"
fi
CFLAGS="-Wall -g -DYYDEBUG $CFLAGS"
YFLAGS="-v -d"
LDFLAGS="-Wl,-z,defs" if test x"$ac_cv_prog_LEX" = x"flex" ; then
LEX_FLAGS="--warn --debug"
fi
else
dnl No debugging information, include the optimizations
CFLAGS="-O2 -DNDEBUG $CFLAGS"
YFLAGS="-d"
fi
dnl dnl
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff. dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
dnl dnl
dnl Handle the SOCKS support
if test x"$socks_enabled" = x"yes"; then
if test x"$socks_header" = x"yes" -a x"$socks_library" = x"yes"; then
CFLAGS="-I/usr/include/sock.h -DSOCKS $CFLAGS"
LIBS="-lsocks $LIBS"
else
AC_MSG_ERROR([Could not include the SOCKS library or header])
fi
fi
dnl Handle the REGEX library dnl Handle the REGEX library
if test x"$ac_cv_func_regexec" != x"yes"; then if test x"$ac_cv_func_regexec" != x"yes"; then
AC_MSG_ERROR([Could not locate the regexec() function]) dnl We don't have a functioning REGEX so include our copy
tinyproxy_use_our_regex=yes
else else
AC_MSG_CHECKING([whether the system's regex library is broken]) AC_MSG_CHECKING([whether the system's regex library is broken])
AC_CACHE_VAL(tinyproxy_cv_regex_broken, AC_CACHE_VAL(tinyproxy_cv_regex_broken,
@@ -236,9 +289,6 @@ else
#if HAVE_REGEX_H #if HAVE_REGEX_H
# include <regex.h> # include <regex.h>
#endif #endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
int main(void) int main(void)
{ {
regex_t blah; regex_t blah;
@@ -259,40 +309,30 @@ int main(void)
AC_MSG_RESULT([$tinyproxy_cv_regex_broken]) AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
AC_MSG_ERROR([Your system's regexec() function is broken.]) AC_MSG_NOTICE([Using the included GNU regex instead.])
tinyproxy_use_our_regex=yes
fi fi
fi fi
AH_TEMPLATE([USE_GNU_REGEX],
[Defined if you want to use the included regex routines.])
if test x"$tinyproxy_use_our_regex" = x"yes" ; then
AC_DEFINE(USE_GNU_REGEX)
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS gnuregex.o"
fi
dnl dnl
dnl Substitute the variables into the various Makefiles dnl Substitute the variables into the various Makefiles
dnl dnl
AC_SUBST(CFLAGS) AC_SUBST(CFLAGS)
AC_SUBST(LDFLAGS) AC_SUBST(LDFLAGS)
AC_SUBST(YFLAGS)
AC_SUBST(CPPFLAGS) AC_SUBST(CPPFLAGS)
AC_SUBST(LEX_FLAGS)
AC_SUBST(LIBS) AC_SUBST(LIBS)
AC_SUBST(ADDITIONAL_OBJECTS) AC_SUBST(ADDITIONAL_OBJECTS)
AC_SUBST(TINYPROXY_CONFIG_DIR)
AC_SUBST(TINYPROXY_CONFIG_FILE)
# Check for asciidoc AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile packaging/Makefile packaging/fedora/Makefile packaging/fedora/tinyproxy.spec])
AC_PATH_PROG(A2X, a2x, no)
AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno")
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
packaging/Makefile
packaging/fedora/tinyproxy.spec
packaging/fedora/Makefile
tests/Makefile
tests/scripts/Makefile
])
AC_OUTPUT AC_OUTPUT
-2
View File
@@ -1,2 +0,0 @@
SUBDIRS = \
templates
-12
View File
@@ -1,12 +0,0 @@
templatesdir = $(pkgdatadir)
TEMPLATES = \
debug.html \
default.html \
stats.html
templates_DATA = \
$(TEMPLATES)
EXTRA_DIST = \
$(TEMPLATES)
-56
View File
@@ -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>
-23
View File
@@ -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>
-69
View File
@@ -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>
+15
View File
@@ -0,0 +1,15 @@
There are several standard HTML variables that are available in every .html
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 - Presently, resolves to 'tinyproxy'.
date - The current date/time in HTTP format.
In addition, almost all pages support:
detail - A detailed, plain English explanation of the error and possible
causes. You might consider this the Microsoftian error message.
File renamed without changes.
+22
View File
@@ -0,0 +1,22 @@
# HTML Variable Substitution Files
HTML_VAR_SUBST = HTML_VARIABLES debug.html default.html stats.html
man_MANS = tinyproxy.8
EXTRA_DIST = $(man_MANS) tinyproxy.conf \
HTTP_ERROR_CODES RFC_INFO \
filter-howto.txt \
report.sh.tmpl \
$(HTML_VAR_SUBST)
install-exec-local: report.sh
# Build the report.sh script
report.sh: $(srcdir)/report.sh.tmpl
sed -e "s,@TINYPROXY_LOCATION@,$(DESTDIR)$(sbindir)," < $(srcdir)/report.sh.tmpl > $(top_builddir)/doc/report.sh
chmod 755 $(top_builddir)/doc/report.sh
@echo ""
@echo "Report tinyproxy"
@echo "----------------"
@echo "Run the $(top_builddir)/doc/report.sh script to report a"
@echo "successful installation to the authors."
@echo ""
View File
File renamed without changes.
+48
View File
@@ -0,0 +1,48 @@
<html>
<head>
<title>
Request failed - {cause}
</title>
</head>
<body>
<center>{cause}</center>
<blockquote>
The request you made failed. Here are the error variables:
<dt>
request
<dd>
{request}
<dt>
cause
<dd>
{cause}
<dt>
clientip
<dd>
{clientip}
<dt>
clienthost
<dd>
{clienthost}
<dt>
version
<dd>
{version}
<dt>
package
<dd>
{package}
<dt>
date
<dd>
{date}
<dt>
detail
<dd>
{detail}
<dt>
url
<dd>
{url}
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
<html><head><title>{cause}</title></head>
<body>
<font size=\+2\>Cache Error!</font><br>
The following error has occured: {detail}
<hr>
<font size=\-1\><em>Generated by {package} ({version})</em></font>
</body></html>
File renamed without changes.
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
TINYPROXY_BIN=@TINYPROXY_LOCATION@/tinyproxy
(echo "date: "
date
echo "uname: "
uname -a
echo "ps: "
ps -ef | grep '[t]inyproxy'
echo "ver: "
if [ -x $TINYPROXY_BIN ]; then
$TINYPROXY_BIN -v
else
echo no ver available.
fi;) 2>&1 | mail -s 'tinyproxy install report' rjkaes@users.sourceforge.net
+10
View File
@@ -0,0 +1,10 @@
<html><head><title>{package} ({version}) stats</title></head>
<body>
<center><h2>{package} ({version}) run-time statistics</h2></center><hr>
<blockquote>
Number of open connections: {opens}<br>
Number of requests: {reqs}<br>
Number of bad connections: {badconns}<br>
Number of denied connections: {deniedconns}<br>
Number of refused connections due to high load: {refusedconns}<br>
</blockquote></body></html>
+60
View File
@@ -0,0 +1,60 @@
.\" -*- nroff -*-
.\"
.\" tinyproxy.8
.\"
.\" 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 8 .\" "tinyproxy Manual" "January 27, 2003"
.SH NAME
tinyproxy - A small HTTP proxy server
.SH SYNTAX
\fBtinyproxy\fR [ \fBoptions\fR ]
.SH VERSION
This man page documents tinyproxy
.SH DESCRIPTION
\fBtinyproxy\fR is an HTTP proxy server designed to consume a minimum of
system resources. It listens on a given TCP port and handles HTTP proxy
requests.
.SH OPTIONS
.IP "-c config_file"
Use an alternate configuration file.
.IP -d
Don't daemonize; stay in the foreground. Useful for debugging purposes.
.IP -h
Display a short help screen of command line arguments and exit.
.IP -l
Displays the licensing agreement.
.IP -v
Display version information and exit.
.SH SIGNALS
In addition to these command line options, there are also several signals
that can be sent to tinyproxy while it is running to generate debugging
information and to force certain events.
.TP 5
.B SIGHUP
Force \fBtinyproxy\fR to do a garbage collection on the current connections
linked list. This is usually done automatically after a certain number of
connections have been handled.
.SH FILES
.nf
/etc/tinyproxy/tinyproxy.conf
/var/run/tinyproxy.pid
/var/log/tinyproxy.log
.fi
.SH AUTHORS
.nf
Robert James Kaes (rjkaes@flarenet.com)
Steven Young (sdyoung@users.sourceforge.net)
.fi
.SH COPYRIGHT
\fBtinyproxy\fR is distributed under the GNU Public License (GPL). For more
information on the GPL, please see the file COPYING which should have been
included in the archive with \fBtinyproxy\fR. Failing that,
http://www.fsf.org/ will doubtless have a copy up for you to peruse. Please
don't use this software if you don't agree to the terms specified therein.
.SH AVAILABILITY
The latest version of \fBtinyproxy\fR can be acquired from: http://tinyproxy.sourceforge.net/
+228
View File
@@ -0,0 +1,228 @@
##
## tinyproxy.conf -- tinyproxy daemon configuration file
##
#
# Name of the user the tinyproxy daemon should switch to after the port
# has been bound.
#
User nobody
Group nogroup
#
# Port to listen on.
#
Port 8888
#
# If you have multiple interfaces this allows you to bind to only one. If
# this is commented out, tinyproxy will bind to all interfaces present.
#
#Listen 192.168.0.1
#
# The Bind directive allows you to bind the outgoing connections to a
# particular IP address.
#
#Bind 192.168.0.1
#
# Timeout: The number of seconds of inactivity a connection is allowed to
# have before it closed by tinyproxy.
#
Timeout 600
#
# 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 "/usr/share/tinyproxy/404.html"
# ErrorFile 400 "/usr/share/tinyproxy/400.html"
# ErrorFile 503 "/usr/share/tinyproxy/503.html"
# ErrorFile 403 "/usr/share/tinyproxy/403.html"
# ErrorFile 408 "/usr/share/tinyproxy/408.html"
#
# DefaultErrorFile: The HTML file that gets sent if there is no
# HTML file defined with an ErrorFile keyword for the HTTP error
# that has occured.
#
DefaultErrorFile "/usr/share/tinyproxy/default.html"
#
# StatFile: The HTML file that gets sent when a request is made
# for the stathost. If this file doesn't exist a basic page is
# hardcoded in tinyproxy.
#
StatFile "/usr/share/tinyproxy/stats.html"
#
# Where to log the information. Either LogFile or Syslog should be set,
# but not both.
#
Logfile "/var/log/tinyproxy.log"
# Syslog On
#
# Set the logging level. Allowed settings are:
# Critical (least verbose)
# Error
# Warning
# Notice
# Connect (to log connections without Info's noise)
# Info (most verbose)
# The LogLevel logs from the set level and above. For example, if the LogLevel
# was set to Warning, than all log messages from Warning to Critical would be
# output, but Notice and below would be suppressed.
#
LogLevel Info
#
# PidFile: Write the PID of the main tinyproxy thread to this file so it
# can be used for signalling purposes.
#
PidFile "/var/run/tinyproxy.pid"
#
# Include the X-Tinyproxy header, which has the client's IP address when
# connecting to the sites listed.
#
#XTinyproxy mydomain.com
#
# Turns on upstream proxy support.
#
# 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
#
# This is the absolute highest number of threads which will be created. In
# other words, only MaxClients number of clients can be connected at the
# same time.
#
MaxClients 100
#
# These settings set the upper and lower limit for the number of
# spare servers which should be available. If the number of spare servers
# falls below MinSpareServers then new ones will be created. If the number
# of servers exceeds MaxSpareServers then the extras will be killed off.
#
MinSpareServers 5
MaxSpareServers 20
#
# Number of servers to start initially.
#
StartServers 10
#
# MaxRequestsPerChild is the number of connections a thread will handle
# before it is killed. In practise this should be set to 0, which disables
# thread reaping. If you do notice problems with memory leakage, then set
# this to something like 10000
#
MaxRequestsPerChild 0
#
# The following is the authorization controls. If there are any access
# control keywords then the default action is to DENY. Otherwise, the
# default action is ALLOW.
#
# Also the order of the controls are important. The incoming connections
# are tested against the controls based on order.
#
Allow 127.0.0.1
Allow 192.168.1.0/25
#
# 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"
#
# The location of the filter file.
#
#Filter "/etc/tinyproxy/filter"
#
# Filter based on URLs rather than domains.
#
#FilterURLs On
#
# Use POSIX Extended regular expressions rather than basic.
#
#FilterExtended On
#
# Use case sensitive regular expressions.
#
#FilterCaseSensitive On
#
# Change the default policy of the filtering system. If this directive is
# commented out, or is set to "No" then the default policy is to allow
# everything which is not specifically denied by the filter file.
#
# However, by setting this directive to "Yes" the default policy becomes to
# deny everything which is _not_ specifically allowed by the filter file.
#
#FilterDefaultDeny Yes
#
# If an Anonymous keyword is present, then anonymous proxying is enabled.
# The headers listed are allowed through, while all others are denied. If
# no Anonymous keyword is present, then all header are allowed through.
# You must include quotes around the headers.
#
#Anonymous "Host"
#Anonymous "Authorization"
#
# This is a list of ports allowed by tinyproxy when the CONNECT method
# is used. To disable the CONNECT method altogether, set the value to 0.
# If no ConnectPort line is found, all ports are allowed (which is not
# very secure.)
#
# The following two ports are used by SSL.
#
ConnectPort 443
ConnectPort 563
-3
View File
@@ -1,3 +0,0 @@
Makefile
Makefile.in
report.sh
-9
View File
@@ -1,9 +0,0 @@
SUBDIRS = \
man5 \
man8
EXTRA_DIST = \
http-error-codes.txt \
http-rfcs.txt \
filter-howto.txt
-3
View File
@@ -1,3 +0,0 @@
*.5
*.xml
*.txt
-23
View File
@@ -1,23 +0,0 @@
MAN5_FILES = \
tinyproxy.conf.txt
A2X_ARGS = \
-d manpage \
-f manpage
man_MANS = \
$(MAN5_FILES:.txt=.5)
.txt.5:
if HAVE_A2X
a2x $(A2X_ARGS) $<
else
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
endif
EXTRA_DIST = \
$(man_MANS)
CLEANFILES = \
$(MAN5_FILES:.txt=.5) \
$(MAN5_FILES:.txt=.xml)
-330
View File
@@ -1,330 +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.
*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*::
This sets the log level. Allowed values are:
* Critical (least verbose)
* Error
* Warning
* Notice
* Connect (log connections without Info's noise)
* Info (most verbose)
The LogLevel logs from the set level and above. For example, if
the LogLevel was set to Warning, than all log messages from
Warning to Critical would be output, but Notice and below would be
suppressed.
*PidFile*::
This option controls the location of the file where the main
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.
*[No] Upstream*::
This option allows you to set up a set of rules for deciding
whether an upstream a proxy server is to be used, based on the
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 `Access` or `Deny` lines, then all clients are
allowed. Otherwise, the default action is to deny access.
The argument to `Access` or `Deny` can be a single IP address
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`.
*ViaProxyName*::
RFC 2616 requires proxies to add a `Via` header to the HTTP
requests, but using the real host name can be a security
concern. If the `ViaProxyname` option is present, than its
string value will be used as the host name in the Via header.
Otherwise, the server's host name will be used.
*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/support/[https://www.banu.com/tinyproxy/support/]>.
COPYRIGHT
---------
Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009 Mukund Sivaraman;
Copyright (c) 2009 Michael Adam.
This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional
information.
-3
View File
@@ -1,3 +0,0 @@
*.8
*.xml
*.txt
-23
View File
@@ -1,23 +0,0 @@
MAN8_FILES = \
tinyproxy.txt
A2X_ARGS = \
-d manpage \
-f manpage
man_MANS = \
$(MAN8_FILES:.txt=.8)
.txt.8:
if HAVE_A2X
a2x $(A2X_ARGS) $<
else
@echo "*** a2x (asciidoc) is required to regenerate $(@) ***"; exit 1;
endif
EXTRA_DIST = \
$(man_MANS)
CLEANFILES = \
$(MAN8_FILES:.txt=.8) \
$(MAN8_FILES:.txt=.xml)
-152
View File
@@ -1,152 +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.stats` and can be changed at
compile-time with the configure switch `--with-stathost` to any name or
IP address.
The stat file template can be changed at runtime through the
configuration variable `StatFile`.
FILES
-----
`/etc/tinyproxy/tinyproxy.conf`, `/var/run/tinyproxy.pid`, `/var/log/tinyproxy.log`
BUGS
----
To report bugs in Tinyproxy, please visit
<https://www.banu.com/tinyproxy/support/[https://www.banu.com/tinyproxy/support/]>.
COPYRIGHT
---------
Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009 Mukund Sivaraman;
Copyright (c) 2009 Michael Adam.
This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional
information.
-5
View File
@@ -1,5 +0,0 @@
sysconf_DATA = \
tinyproxy.conf
EXTRA_DIST = \
$(sysconf_DATA)
-304
View File
@@ -1,304 +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 "/usr/share/tinyproxy/404.html"
#ErrorFile 400 "/usr/share/tinyproxy/400.html"
#ErrorFile 503 "/usr/share/tinyproxy/503.html"
#ErrorFile 403 "/usr/share/tinyproxy/403.html"
#ErrorFile 408 "/usr/share/tinyproxy/408.html"
#
# DefaultErrorFile: The HTML file that gets sent if there is no
# HTML file defined with an ErrorFile keyword for the HTTP error
# that has occured.
#
DefaultErrorFile "/usr/share/tinyproxy/default.html"
#
# StatFile: The HTML file that gets sent when a request is made
# for the stathost. If this file doesn't exist a basic page is
# hardcoded in tinyproxy.
#
StatFile "/usr/share/tinyproxy/stats.html"
#
# Logfile: Allows you to specify the location where information should
# be logged to. If you would prefer to log to syslog, then disable this
# and enable the Syslog directive. These directives are mutually
# exclusive.
#
Logfile "/var/log/tinyproxy.log"
#
# 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, 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"
#
# 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
#
# 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"
#
# Filter: This allows you to specify the location of the filter file.
#
#Filter "/etc/tinyproxy/filter"
#
# FilterURLs: Filter based on URLs rather than domains.
#
#FilterURLs On
#
# FilterExtended: Use POSIX Extended regular expressions rather than
# basic.
#
#FilterExtended On
#
# FilterCaseSensitive: Use case sensitive regular expressions.
#
#FilterCaseSensitive On
#
# FilterDefaultDeny: Change the default policy of the filtering system.
# If this directive is commented out, or is set to "No" then the default
# policy is to allow everything which is not specifically denied by the
# filter file.
#
# However, by setting this directive to "Yes" the default policy becomes
# to deny everything which is _not_ specifically allowed by the filter
# file.
#
#FilterDefaultDeny Yes
#
# Anonymous: If an Anonymous keyword is present, then anonymous proxying
# is enabled. The headers listed are allowed through, while all others
# are denied. If no Anonymous keyword is present, then all headers are
# allowed through. You must include quotes around the headers.
#
# Most sites require cookies to be enabled for them to work correctly, so
# you will need to allow Cookies through if you access those sites.
#
#Anonymous "Host"
#Anonymous "Authorization"
#Anonymous "Cookie"
#
# ConnectPort: This is a list of ports allowed by tinyproxy when the
# CONNECT method is used. To disable the CONNECT method altogether, set
# the value to 0. If no ConnectPort line is found, all ports are
# allowed (which is not very secure.)
#
# The following two ports are used by SSL.
#
ConnectPort 443
ConnectPort 563
#
# Configure one or more ReversePath directives to enable reverse proxy
# support. With reverse proxying it's possible to make a number of
# sites appear as if they were part of a single site.
#
# If you uncomment the following two directives and run tinyproxy
# on your own computer at port 8888, you can access Google using
# http://localhost:8888/google/ and Wired News using
# http://localhost:8888/wired/news/. Neither will actually work
# until you uncomment ReverseMagic as they use absolute linking.
#
#ReversePath "/google/" "http://www.google.com/"
#ReversePath "/wired/" "http://www.wired.com/"
#
# When using tinyproxy as a reverse proxy, it is STRONGLY recommended
# that the normal proxy is turned off by uncommenting the next directive.
#
#ReverseOnly Yes
#
# Use a cookie to track reverse proxy mappings. If you need to reverse
# proxy sites which have absolute links you must uncomment this.
#
#ReverseMagic Yes
#
# The URL that's used to access this reverse proxy. The URL is used to
# rewrite HTTP redirects so that they won't escape the proxy. If you
# have a chain of reverse proxies, you'll need to put the outermost
# URL here (the address which the end user types into his/her browser).
#
# If not set then no rewriting occurs.
#
#ReverseBaseURL "http://localhost:8888/"
-4
View File
@@ -1,4 +0,0 @@
EXTRA_DIST = \
as-compiler-flag.m4 \
argenable.m4 \
typecheck.m4
-19
View File
@@ -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])])
-64
View File
@@ -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])
])
+7 -10
View File
@@ -4,14 +4,14 @@
Name: tinyproxy Name: tinyproxy
Version: @VERSION@ Version: @VERSION@
Release: 2%{?dist} Release: 2%{?dist}
Summary: A light-weight HTTP proxy daemon Summary: A small, efficient HTTP/SSL proxy daemon
Group: System Environment/Daemons Group: System Environment/Daemons
License: GPLv2+ License: GPLv2+
URL: https://www.banu.com/tinyproxy/ URL: http://tinyproxy.banu.com/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Source0: https://www.banu.com/pub/tinyproxy/1.7/%{name}-%{version}.tar.gz Source0: http://files.banu.com/pub/tinyproxy/1.6/%{name}-%{version}.tar.gz
Source1: %{name}.init Source1: %{name}.init
Source2: %{name}.conf Source2: %{name}.conf
@@ -20,13 +20,10 @@ Requires(preun): chkconfig
Requires(preun): initscripts Requires(preun): initscripts
%description %description
Tinyproxy is a light-weight HTTP proxy daemon designed to consume a tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
minimum amount of system resources. It listens on a given TCP port and GNU General Public License (GPL). tinyproxy is very useful in a small
handles HTTP proxy requests. Designed from the ground up to be fast and network setting, where a larger proxy like Squid would either be too
yet small, it is an ideal solution for use cases such as embedded resource intensive, or a security risk.
deployments where a full featured HTTP proxy is required, but the system
resources for a larger proxy are unavailable.
%prep %prep
%setup -q %setup -q
+4
View File
@@ -2,6 +2,10 @@
.libs .libs
Makefile Makefile
Makefile.in Makefile.in
grammar.c
grammar.h
grammar.output
scanner.c
tinyproxy tinyproxy
*.o *.o
*.pcno *.pcno
+23 -24
View File
@@ -1,50 +1,49 @@
# tinyproxy - A fast light-weight HTTP proxy # $Id: Makefile.am,v 1.17 2003-06-26 18:23: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 # Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
# 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, # This program is free software; you can redistribute it and/or modify it
# but WITHOUT ANY WARRANTY; without even the implied warranty of # under the terms of the GNU General Public License as published by the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # Free Software Foundation; either version 2, or (at your option) any
# GNU General Public License for more details. # 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.
sbin_PROGRAMS = tinyproxy sbin_PROGRAMS = tinyproxy
AM_CPPFLAGS = \
-DSYSCONFDIR=\"${sysconfdir}\"
tinyproxy_SOURCES = \ tinyproxy_SOURCES = \
acl.c acl.h \ acl.c acl.h \
anonymous.c anonymous.h \ anonymous.c anonymous.h \
buffer.c buffer.h \ buffer.c buffer.h \
child.c child.h \ child.c child.h \
common.h \ common.h \
conf.c conf.h \
conns.c conns.h \ conns.c conns.h \
daemon.c daemon.h \ daemon.c daemon.h \
hashmap.c hashmap.h \ hashmap.c hashmap.h \
heap.c heap.h \ heap.c heap.h \
html-error.c html-error.h \ htmlerror.c htmlerror.h \
http-message.c http-message.h \ http_message.c http_message.h \
log.c log.h \ log.c log.h \
network.c network.h \ network.c network.h \
reqs.c reqs.h \ reqs.c reqs.h \
sock.c sock.h \ sock.c sock.h \
stats.c stats.h \ stats.c stats.h \
text.c text.h \ text.c text.h \
main.c main.h \ tinyproxy.c tinyproxy.h \
utils.c utils.h \ utils.c utils.h \
vector.c vector.h vector.c vector.h \
grammar.y scanner.l \
regexp.h
EXTRA_tinyproxy_SOURCES = filter.c filter.h \ EXTRA_DIST = gnuregex.c gnuregex.h
reverse-proxy.c reverse-proxy.h \ EXTRA_tinyproxy_SOURCES = filter.c filter.h grammar.h
transparent-proxy.c transparent-proxy.h
tinyproxy_DEPENDENCIES = @ADDITIONAL_OBJECTS@ tinyproxy_DEPENDENCIES = @ADDITIONAL_OBJECTS@
tinyproxy_LDADD = @ADDITIONAL_OBJECTS@ tinyproxy_LDADD = @ADDITIONAL_OBJECTS@
scanner.c: scanner.l grammar.h
$(LEX) $(LEX_FLAGS) $(LFLAGS) -i $< && mv $(LEX_OUTPUT_ROOT).c $@
+161 -237
View File
@@ -1,109 +1,49 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: acl.c,v 1.16 2002-06-05 16:59:21 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,2002 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "acl.h" #include "acl.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "network.h"
#include "sock.h" #include "sock.h"
#include "vector.h"
#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;
* All the access lists are stored in a vector.
*/
static vector_t 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.
* Returns:
* 0 on success
* -1 on failure (invalid mask value)
*
*/ */
static int static in_addr_t
fill_netmask_array (char *bitmask_string, unsigned char array[], make_netmask(int netmask_num)
unsigned int len)
{ {
unsigned int i; assert(netmask_num >= 0 && netmask_num <= 32);
long int mask;
char *endptr;
errno = 0; /* to distinguish success/failure after call */ return htonl(~((1 << (32 - netmask_num)) - 1));
mask = strtol (bitmask_string, &endptr, 10);
/* check for various conversion errors */
if ((errno == ERANGE && (mask == LONG_MIN || mask == LONG_MAX))
|| (errno != 0 && mask == 0) || (endptr == bitmask_string))
return -1;
/* valid range for a bit mask */
if (mask < 0 || 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;
} }
/* /*
@@ -115,76 +55,81 @@ fill_netmask_array (char *bitmask_string, unsigned char array[],
* -1 on failure * -1 on failure
* 0 otherwise. * 0 otherwise.
*/ */
int insert_acl (char *location, acl_access_t access_type) int
insert_acl(char *location, acl_access_t access_type)
{ {
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);
/* /*
* If the access list has not been set up, create it. * First check to see if the location is a string or numeric.
*/ */
if (!access_list) { for (i = 0; location[i] != '\0'; i++) {
access_list = vector_create (); /*
if (!access_list) { * Numeric strings can not contain letters, so test on it.
log_message (LOG_ERR, */
"Unable to allocate memory for access list"); if (isalpha((unsigned char) location[i])) {
break;
}
}
/*
* Add a new ACL to the list.
*/
rev_acl_ptr = &access_list;
acl_ptr = access_list;
while (acl_ptr) {
rev_acl_ptr = &acl_ptr->next;
acl_ptr = acl_ptr->next;
}
new_acl_ptr = safemalloc(sizeof(struct acl_s));
if (!new_acl_ptr) {
return -1; return -1;
} }
new_acl_ptr->acl_access = access_type;
if (location[i] == '\0') {
DEBUG2("ACL \"%s\" is a number.", location);
/*
* We did not break early, so this a numeric location.
* Check for a netmask.
*/
new_acl_ptr->type = ACL_NUMERIC;
nptr = strchr(location, '/');
if (nptr) {
*nptr++ = '\0';
new_acl_ptr->netmask = strtol(nptr, NULL, 10);
if (new_acl_ptr->netmask < 0
|| new_acl_ptr->netmask > 32) {
safefree(new_acl_ptr);
return -1;
} }
/*
* Start populating the access control structure.
*/
memset (&acl, 0, sizeof (struct acl_s));
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 { } else {
/* new_acl_ptr->netmask = 32;
* At this point we're either a hostname or an }
* IP address with a slash.
*/
p = strchr (location, '/');
if (p != NULL) {
/*
* We have a slash, so it's intended to be an
* IP address with mask
*/
*p = '\0';
if (full_inet_pton (location, ip_dst) <= 0)
return -1;
acl.type = ACL_NUMERIC;
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
if (fill_netmask_array
(p + 1, &(acl.address.ip.mask[0]), IPV6_LEN)
< 0)
return -1;
} else { } else {
/* In all likelihood a string */ DEBUG2("ACL \"%s\" is a string.", location);
acl.type = ACL_STRING;
acl.address.string = safestrdup (location); new_acl_ptr->type = ACL_STRING;
if (!acl.address.string) new_acl_ptr->netmask = 32;
return -1;
}
} }
/* new_acl_ptr->location = safestrdup(location);
* Add the entry and then clean up. if (!new_acl_ptr->location) {
*/ safefree(new_acl_ptr);
ret = vector_append (access_list, &acl, sizeof (struct acl_s)); return -1;
safefree (acl.address.string); }
return ret;
*rev_acl_ptr = new_acl_ptr;
new_acl_ptr->next = acl_ptr;
return 0;
} }
/* /*
@@ -196,55 +141,48 @@ int insert_acl (char *location, acl_access_t access_type)
* 1 if host is allowed * 1 if host is allowed
* -1 if no tests match, so skip * -1 if no tests match, so skip
*/ */
static int static inline int
acl_string_processing (struct acl_s *acl, acl_string_processing(struct acl_s* aclptr,
const char *ip_address, const char *string_address) const char* ip_address,
const char* string_address)
{ {
int match; int i;
struct addrinfo hints, *res, *ressave; struct hostent* result;
size_t test_length, match_length; size_t test_length, match_length;
char ipbuf[512];
assert (acl && acl->type == ACL_STRING);
assert (ip_address && strlen (ip_address) > 0);
assert (string_address && strlen (string_address) > 0);
/* /*
* If the first character of the ACL string is a period, we need to * If the first character of the ACL string is a period, we need to
* do a string based test only; otherwise, we can do a reverse * do a string based test only; otherwise, we can do a reverse
* lookup test as well. * lookup test as well.
*/ */
if (acl->address.string[0] != '.') { if (aclptr->location[0] != '.') {
memset (&hints, 0, sizeof (struct addrinfo)); /* It is not a partial domain, so do a reverse lookup. */
hints.ai_family = AF_UNSPEC; result = gethostbyname(aclptr->location);
hints.ai_socktype = SOCK_STREAM; if (!result)
if (getaddrinfo (acl->address.string, NULL, &hints, &res) != 0)
goto STRING_TEST; goto STRING_TEST;
ressave = res; for (i = 0; result->h_addr_list[i]; ++i) {
if (strcmp(ip_address,
match = FALSE; inet_ntoa(*((struct in_addr*)result->h_addr_list[i]))) == 0) {
do { /* We have a match */
get_ip_string (res->ai_addr, ipbuf, sizeof (ipbuf)); if (aclptr->acl_access == ACL_DENY) {
if (strcmp (ip_address, ipbuf) == 0) {
match = TRUE;
break;
}
} while ((res = res->ai_next) != NULL);
freeaddrinfo (ressave);
if (match) {
if (acl->access == ACL_DENY)
return 0; return 0;
else } else {
DEBUG2("Matched using reverse domain lookup: %s", ip_address);
return 1; return 1;
} }
} }
}
/*
* If we got this far, the reverse didn't match, so drop down
* to a standard string test.
*/
}
STRING_TEST: STRING_TEST:
test_length = strlen(string_address); test_length = strlen(string_address);
match_length = strlen (acl->address.string); match_length = strlen(aclptr->location);
/* /*
* If the string length is shorter than AC string, return a -1 so * If the string length is shorter than AC string, return a -1 so
@@ -253,10 +191,8 @@ STRING_TEST:
if (test_length < match_length) if (test_length < match_length)
return -1; return -1;
if (strcasecmp if (strcasecmp(string_address + (test_length - match_length), aclptr->location) == 0) {
(string_address + (test_length - match_length), if (aclptr->acl_access == ACL_DENY)
acl->address.string) == 0) {
if (acl->access == ACL_DENY)
return 0; return 0;
else else
return 1; return 1;
@@ -267,87 +203,75 @@ STRING_TEST:
} }
/* /*
* Compare the supplied numeric IP address with the supplied ACL structure. * Checks whether file descriptor is allowed.
*
* 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 0;
}
/* The addresses match, return the permission */
return (acl->access == ACL_ALLOW);
}
/*
* Checks whether a connection is allowed.
* *
* Returns: * Returns:
* 1 if allowed * 1 if allowed
* 0 if denied * 0 if denied
*/ */
int check_acl (const char *ip, const char *host) int
check_acl(int fd, const char* ip_address, const char* string_address)
{ {
struct acl_s *acl; struct acl_s* aclptr;
int perm = 0; int ret;
size_t i;
assert (ip != NULL); assert(fd >= 0);
assert (host != NULL); assert(ip_address != NULL);
assert(string_address != NULL);
/* /*
* If there is no access list allow everything. * If there is no access list allow everything.
*/ */
if (!access_list) aclptr = access_list;
if (!aclptr)
return 1; return 1;
for (i = 0; i != (size_t) vector_length (access_list); ++i) { while (aclptr) {
acl = (struct acl_s *) vector_getentry (access_list, i, NULL); if (aclptr->type == ACL_STRING) {
switch (acl->type) { ret = acl_string_processing(aclptr,
case ACL_STRING: ip_address,
perm = acl_string_processing (acl, ip, host); string_address);
break; if (ret == 0)
goto UNAUTHORIZED;
else if (ret == 1)
return 1;
case ACL_NUMERIC: aclptr = aclptr->next;
if (ip[0] == '\0')
continue; continue;
perm = check_numeric_acl (acl, ip); } else {
break; struct in_addr test_addr, match_addr;
in_addr_t netmask_addr;
if (ip_address[0] == 0) {
aclptr = aclptr->next;
continue;
}
inet_aton(ip_address, &test_addr);
inet_aton(aclptr->location, &match_addr);
netmask_addr = make_netmask(aclptr->netmask);
if ((test_addr.s_addr & netmask_addr) ==
(match_addr.s_addr & netmask_addr)) {
if (aclptr->acl_access == ACL_DENY)
goto UNAUTHORIZED;
else
return 1;
}
} }
/* /*
* Check the return value too see if the IP address is * Dropped through... go on to the next one.
* allowed or denied.
*/ */
if (perm == 0) aclptr = aclptr->next;
break;
else if (perm == 1)
return perm;
} }
/* /*
* Deny all connections by default. * Deny all connections by default.
*/ */
UNAUTHORIZED:
log_message(LOG_NOTICE, "Unauthorized connection from \"%s\" [%s].", log_message(LOG_NOTICE, "Unauthorized connection from \"%s\" [%s].",
host, ip); string_address, ip_address);
return 0; return 0;
} }
+13 -16
View File
@@ -1,29 +1,26 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: acl.h,v 1.3 2002-04-17 20:52:45 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
typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t; typedef enum { ACL_ALLOW, ACL_DENY } acl_access_t;
extern int insert_acl(char *location, acl_access_t access_type); extern int insert_acl(char *location, acl_access_t access_type);
extern int check_acl (const char *ip_address, const char *string_address); extern int check_acl(int fd, const char* ip_address, const char* string_address);
#endif #endif
+20 -21
View File
@@ -1,26 +1,22 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: anonymous.c,v 1.14 2002-05-23 18:20:27 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 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.
*/ */
/* Handles insertion and searches for headers which should be let through #include "tinyproxy.h"
* when the anonymous feature is turned on.
*/
#include "main.h"
#include "anonymous.h" #include "anonymous.h"
#include "hashmap.h" #include "hashmap.h"
@@ -29,7 +25,8 @@
static hashmap_t anonymous_map = NULL; static hashmap_t anonymous_map = NULL;
short int is_anonymous_enabled (void) short int
is_anonymous_enabled(void)
{ {
return (anonymous_map != NULL) ? 1 : 0; return (anonymous_map != NULL) ? 1 : 0;
} }
@@ -38,7 +35,8 @@ short int is_anonymous_enabled (void)
* Search for the header. This function returns a positive value greater than * Search for the header. This function returns a positive value greater than
* zero if the string was found, zero if it wasn't and negative upon error. * zero if the string was found, zero if it wasn't and negative upon error.
*/ */
int anonymous_search (const char *s) int
anonymous_search(char *s)
{ {
assert(s != NULL); assert(s != NULL);
assert(anonymous_map != NULL); assert(anonymous_map != NULL);
@@ -52,7 +50,8 @@ int anonymous_search (const char *s)
* Return -1 if there is an error, otherwise a 0 is returned if the insert was * Return -1 if there is an error, otherwise a 0 is returned if the insert was
* successful. * successful.
*/ */
int anonymous_insert (const char *s) int
anonymous_insert(char *s)
{ {
char data = 1; char data = 1;
+14 -17
View File
@@ -1,28 +1,25 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: anonymous.h,v 1.6 2001-12-15 20:08:24 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); extern short int is_anonymous_enabled(void);
extern int anonymous_search (const char *s); extern int anonymous_search(char *s);
extern int anonymous_insert (const char *s); extern int anonymous_insert(char *s);
#endif #endif
+38 -39
View File
@@ -1,31 +1,27 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: buffer.c,v 1.22 2002-05-24 04:45:32 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 dynamically. However,
* we have a hard limit of 64 KB for the size of the buffer. The buffer can be * we have a hard limit of 64 KB for the size of the buffer. The buffer can be
* thought of as a queue were we act on both the head and tail. The various * thought of as a queue were we act on both the head and tail. The various
* functions act on each end (the names are taken from what Perl uses to act on * functions act on each end (the names are taken from what Perl uses to act on
* the ends of an array. :) * the ends of an array. :)
*
* Copyright (C) 1999,2001 Robert James Kaes (rjkaes@users.sourceforge.net)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "buffer.h" #include "buffer.h"
#include "heap.h" #include "heap.h"
@@ -56,19 +52,18 @@ struct buffer_s {
* to the buffer. The data IS copied, so make sure if you allocated your * to the buffer. The data IS copied, so make sure if you allocated your
* data buffer on the heap, delete it because you now have TWO copies. * data buffer on the heap, delete it because you now have TWO copies.
*/ */
static struct bufline_s *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); assert(length > 0);
newline = (struct bufline_s *) safemalloc (sizeof (struct bufline_s)); if (!(newline = safemalloc(sizeof(struct bufline_s))))
if (!newline)
return NULL; return NULL;
newline->string = (unsigned char *) safemalloc (length); if (!(newline->string = safemalloc(length))) {
if (!newline->string) {
safefree(newline); safefree(newline);
return NULL; return NULL;
} }
@@ -87,7 +82,8 @@ static struct bufline_s *makenewline (unsigned char *data, size_t length)
/* /*
* 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);
@@ -103,12 +99,12 @@ static void free_line (struct bufline_s *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 = safemalloc(sizeof(struct buffer_s))))
if (!buffptr)
return NULL; return NULL;
/* /*
@@ -125,7 +121,8 @@ struct buffer_s *new_buffer (void)
/* /*
* Delete all the lines in the buffer and the buffer itself * Delete all the lines in the buffer and the buffer itself
*/ */
void delete_buffer (struct buffer_s *buffptr) void
delete_buffer(struct buffer_s *buffptr)
{ {
struct bufline_s *next; struct bufline_s *next;
@@ -151,7 +148,8 @@ size_t buffer_size (struct buffer_s *buffptr)
/* /*
* Push a new line on to the end of the buffer. * Push a new line on to the end of the buffer.
*/ */
int add_to_buffer (struct buffer_s *buffptr, unsigned char *data, size_t length) int
add_to_buffer(struct buffer_s *buffptr, unsigned char *data, size_t length)
{ {
struct bufline_s *newline; struct bufline_s *newline;
@@ -189,7 +187,8 @@ int add_to_buffer (struct buffer_s *buffptr, unsigned char *data, size_t length)
/* /*
* Remove the first line from the top of the buffer * Remove the first line from the top of the buffer
*/ */
static struct bufline_s *remove_from_buffer (struct buffer_s *buffptr) static struct bufline_s *
remove_from_buffer(struct buffer_s *buffptr)
{ {
struct bufline_s *line; struct bufline_s *line;
@@ -209,7 +208,8 @@ static struct bufline_s *remove_from_buffer (struct buffer_s *buffptr)
* Takes a connection and returns the number of bytes read. * Takes a connection and returns the number of bytes read.
*/ */
#define READ_BUFFER_SIZE (1024 * 2) #define READ_BUFFER_SIZE (1024 * 2)
ssize_t read_buffer (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 *buffer;
@@ -223,7 +223,7 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
if (buffptr->size >= MAXBUFFSIZE) if (buffptr->size >= MAXBUFFSIZE)
return 0; return 0;
buffer = (unsigned char *) safemalloc (READ_BUFFER_SIZE); buffer = safemalloc(READ_BUFFER_SIZE);
if (!buffer) { if (!buffer) {
return -ENOMEM; return -ENOMEM;
} }
@@ -270,7 +270,8 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
* 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
write_buffer(int fd, struct buffer_s * buffptr)
{ {
ssize_t bytessent; ssize_t bytessent;
struct bufline_s *line; struct bufline_s *line;
@@ -286,8 +287,7 @@ ssize_t write_buffer (int fd, struct buffer_s * buffptr)
line = BUFFER_HEAD(buffptr); line = BUFFER_HEAD(buffptr);
bytessent = bytessent =
send (fd, line->string + line->pos, line->length - line->pos, send(fd, line->string + line->pos, line->length - line->pos, MSG_NOSIGNAL);
MSG_NOSIGNAL);
if (bytessent >= 0) { if (bytessent >= 0) {
/* bytes sent, adjust buffer */ /* bytes sent, adjust buffer */
@@ -309,9 +309,8 @@ ssize_t write_buffer (int fd, struct buffer_s * buffptr)
case ENOBUFS: case ENOBUFS:
case ENOMEM: case ENOMEM:
log_message(LOG_ERR, log_message(LOG_ERR,
"writebuff: write() error [NOBUFS/NOMEM] \"%s\" on " "writebuff: write() error [NOBUFS/NOMEM] \"%s\" on file descriptor %d",
"file descriptor %d", strerror (errno), strerror(errno), fd);
fd);
return 0; return 0;
default: default:
log_message(LOG_ERR, log_message(LOG_ERR,
+12 -15
View File
@@ -1,23 +1,20 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: buffer.h,v 1.8 2002-05-14 00:43:38 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_
+65 -77
View File
@@ -1,26 +1,22 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: child.c,v 1.11.2.2 2004-06-14 20:08:12 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 the creation/destruction of the various children required for
* 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. * 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 "main.h" #include "tinyproxy.h"
#include "child.h" #include "child.h"
#include "daemon.h" #include "daemon.h"
@@ -37,11 +33,10 @@ static socklen_t addrlen;
/* /*
* Stores the internal data needed for each child (connection) * Stores the internal data needed for each child (connection)
*/ */
enum child_status_t { T_EMPTY, T_WAITING, T_CONNECTED };
struct child_s { struct child_s {
pid_t tid; pid_t tid;
unsigned int connects; unsigned int connects;
enum child_status_t status; enum { T_EMPTY, T_WAITING, T_CONNECTED } status;
}; };
/* /*
@@ -51,11 +46,11 @@ struct child_s {
static struct child_s *child_ptr; static struct child_s *child_ptr;
static struct child_config_s { static struct child_config_s {
unsigned int maxclients, maxrequestsperchild; int maxclients, maxrequestsperchild;
unsigned int maxspareservers, minspareservers, startservers; int maxspareservers, minspareservers, startservers;
} child_config; } child_config;
static unsigned int *servers_waiting; /* servers waiting for a connection */ static int* servers_waiting; /* servers waiting for a connection */
/* /*
* Lock/Unlock the "servers_waiting" variable so that two children cannot * Lock/Unlock the "servers_waiting" variable so that two children cannot
@@ -73,7 +68,8 @@ static unsigned int *servers_waiting; /* servers waiting for a connection */
static struct flock lock_it, unlock_it; static struct flock lock_it, unlock_it;
static int lock_fd = -1; static int lock_fd = -1;
static void _child_lock_init (void) static void
_child_lock_init(void)
{ {
char lock_file[] = "/tmp/tinyproxy.servers.lock.XXXXXX"; char lock_file[] = "/tmp/tinyproxy.servers.lock.XXXXXX";
@@ -96,7 +92,8 @@ static void _child_lock_init (void)
unlock_it.l_len = 0; unlock_it.l_len = 0;
} }
static void _child_lock_wait (void) static void
_child_lock_wait(void)
{ {
int rc; int rc;
@@ -108,7 +105,8 @@ static void _child_lock_wait (void)
} }
} }
static void _child_lock_release (void) static void
_child_lock_release(void)
{ {
if (fcntl(lock_fd, F_SETLKW, &unlock_it) < 0) if (fcntl(lock_fd, F_SETLKW, &unlock_it) < 0)
return; return;
@@ -125,7 +123,6 @@ static void _child_lock_release (void)
#define SERVER_DEC() do { \ #define SERVER_DEC() do { \
SERVER_COUNT_LOCK(); \ SERVER_COUNT_LOCK(); \
assert(*servers_waiting > 0); \
--(*servers_waiting); \ --(*servers_waiting); \
DEBUG2("DEC: servers_waiting: %d", *servers_waiting); \ DEBUG2("DEC: servers_waiting: %d", *servers_waiting); \
SERVER_COUNT_UNLOCK(); \ SERVER_COUNT_UNLOCK(); \
@@ -134,7 +131,8 @@ static void _child_lock_release (void)
/* /*
* Set the configuration values for the various child related settings. * Set the configuration values for the various child related settings.
*/ */
short int child_configure (child_config_t type, unsigned int val) short int
child_configure(child_config_t type, int val)
{ {
switch (type) { switch (type) {
case CHILD_MAXCLIENTS: case CHILD_MAXCLIENTS:
@@ -163,13 +161,14 @@ short int child_configure (child_config_t type, unsigned int val)
/* /*
* This is the main (per child) loop. * This is the main (per child) loop.
*/ */
static void child_main (struct child_s *ptr) static void
child_main(struct child_s* ptr)
{ {
int connfd; int connfd;
struct sockaddr *cliaddr; struct sockaddr *cliaddr;
socklen_t clilen; socklen_t clilen;
cliaddr = (struct sockaddr *) safemalloc (addrlen); cliaddr = safemalloc(addrlen);
if (!cliaddr) { if (!cliaddr) {
log_message(LOG_CRIT, log_message(LOG_CRIT,
"Could not allocate memory for child address."); "Could not allocate memory for child address.");
@@ -193,11 +192,9 @@ static void child_main (struct child_s *ptr)
if (getenv("TINYPROXY_DEBUG")) { if (getenv("TINYPROXY_DEBUG")) {
/* Pause for 10 seconds to allow us to connect debugger */ /* Pause for 10 seconds to allow us to connect debugger */
fprintf(stderr, fprintf(stderr,
"Process has accepted connection: %ld\n", "Process has accepted connection: %u\n", ptr->tid);
(long int) ptr->tid);
sleep(10); sleep(10);
fprintf (stderr, "Continuing process: %ld\n", fprintf(stderr, "Continuing process: %u\n", ptr->tid);
(long int) ptr->tid);
} }
#endif #endif
@@ -205,9 +202,7 @@ static void child_main (struct child_s *ptr)
* Make sure no error occurred... * Make sure no error occurred...
*/ */
if (connfd < 0) { if (connfd < 0) {
log_message (LOG_ERR, log_message(LOG_ERR, "Accept returned an error (%s) ... retrying.", strerror(errno));
"Accept returned an error (%s) ... retrying.",
strerror (errno));
continue; continue;
} }
@@ -216,15 +211,16 @@ static void child_main (struct child_s *ptr)
SERVER_DEC(); SERVER_DEC();
handle_connection(connfd); handle_connection(connfd);
ptr->connects++;
if (child_config.maxrequestsperchild != 0) { if (child_config.maxrequestsperchild != 0) {
ptr->connects++;
DEBUG2("%u connections so far...", ptr->connects); DEBUG2("%u connections so far...", ptr->connects);
if (ptr->connects == child_config.maxrequestsperchild) { if (ptr->connects == child_config.maxrequestsperchild) {
log_message(LOG_NOTICE, log_message(LOG_NOTICE,
"Child has reached MaxRequestsPerChild (%u). " "Child has reached MaxRequestsPerChild (%u). Killing child.",
"Killing child.", ptr->connects); ptr->connects);
break; break;
} }
} }
@@ -236,10 +232,8 @@ static void child_main (struct child_s *ptr)
* off. * off.
*/ */
log_message(LOG_NOTICE, log_message(LOG_NOTICE,
"Waiting servers (%d) exceeds MaxSpareServers (%d). " "Waiting servers (%d) exceeds MaxSpareServers (%d). Killing child.",
"Killing child.", *servers_waiting, child_config.maxspareservers);
*servers_waiting,
child_config.maxspareservers);
SERVER_COUNT_UNLOCK(); SERVER_COUNT_UNLOCK();
break; break;
@@ -260,7 +254,8 @@ static void child_main (struct child_s *ptr)
* Fork a child "child" (or in our case a process) and then start up the * Fork a child "child" (or in our case a process) and then start up the
* child_main() function. * child_main() function.
*/ */
static pid_t child_make (struct child_s *ptr) static int
child_make(struct child_s* ptr)
{ {
pid_t pid; pid_t pid;
@@ -281,7 +276,8 @@ static pid_t child_make (struct child_s *ptr)
/* /*
* Create a pool of children to handle incoming connections * Create a pool of children to handle incoming connections
*/ */
short int child_pool_create (void) short int
child_pool_create(void)
{ {
unsigned int i; unsigned int i;
@@ -292,31 +288,25 @@ short int child_pool_create (void)
*/ */
if (child_config.maxclients == 0) { if (child_config.maxclients == 0) {
log_message(LOG_ERR, log_message(LOG_ERR,
"child_pool_create: \"MaxClients\" must be " "child_pool_create: \"MaxClients\" must be greater than zero.");
"greater than zero.");
return -1; return -1;
} }
if (child_config.startservers == 0) { if (child_config.startservers == 0) {
log_message(LOG_ERR, log_message(LOG_ERR,
"child_pool_create: \"StartServers\" must be " "child_pool_create: \"StartServers\" must be greater than zero.");
"greater than zero.");
return -1; return -1;
} }
child_ptr = child_ptr = calloc_shared_memory(child_config.maxclients,
(struct child_s *) calloc_shared_memory (child_config.maxclients,
sizeof(struct child_s)); sizeof(struct child_s));
if (!child_ptr) { if (!child_ptr) {
log_message (LOG_ERR, log_message(LOG_ERR, "Could not allocate memory for children.");
"Could not allocate memory for children.");
return -1; return -1;
} }
servers_waiting = servers_waiting = malloc_shared_memory(sizeof(int));
(unsigned int *) malloc_shared_memory (sizeof (unsigned int));
if (servers_waiting == MAP_FAILED) { if (servers_waiting == MAP_FAILED) {
log_message (LOG_ERR, log_message(LOG_ERR, "Could not allocate memory for child counting.");
"Could not allocate memory for child counting.");
return -1; return -1;
} }
*servers_waiting = 0; *servers_waiting = 0;
@@ -329,8 +319,7 @@ short int child_pool_create (void)
if (child_config.startservers > child_config.maxclients) { if (child_config.startservers > child_config.maxclients) {
log_message(LOG_WARNING, log_message(LOG_WARNING,
"Can not start more than \"MaxClients\" servers. " "Can not start more than \"MaxClients\" servers. Starting %u servers instead.",
"Starting %u servers instead.",
child_config.maxclients); child_config.maxclients);
child_config.startservers = child_config.maxclients; child_config.startservers = child_config.maxclients;
} }
@@ -341,8 +330,7 @@ short int child_pool_create (void)
} }
for (i = 0; i != child_config.startservers; i++) { for (i = 0; i != child_config.startservers; i++) {
DEBUG2 ("Trying to create child %d of %d", i + 1, DEBUG2("Trying to create child %d of %d", i + 1, child_config.startservers);
child_config.startservers);
child_ptr[i].status = T_WAITING; child_ptr[i].status = T_WAITING;
child_ptr[i].tid = child_make(&child_ptr[i]); child_ptr[i].tid = child_make(&child_ptr[i]);
@@ -369,9 +357,10 @@ short int child_pool_create (void)
* Keep the proper number of servers running. This is the birth of the * Keep the proper number of servers running. This is the birth of the
* servers. It monitors this at least once a second. * servers. It monitors this at least once a second.
*/ */
void child_main_loop (void) void
child_main_loop(void)
{ {
unsigned int i; int i;
while (1) { while (1) {
if (config.quit) if (config.quit)
@@ -381,18 +370,15 @@ void child_main_loop (void)
SERVER_COUNT_LOCK(); SERVER_COUNT_LOCK();
if (*servers_waiting < child_config.minspareservers) { if (*servers_waiting < child_config.minspareservers) {
log_message(LOG_NOTICE, log_message(LOG_NOTICE,
"Waiting servers (%d) is less than MinSpareServers (%d). " "Waiting servers (%d) is less than MinSpareServers (%d). Creating new child.",
"Creating new child.", *servers_waiting, child_config.minspareservers);
*servers_waiting,
child_config.minspareservers);
SERVER_COUNT_UNLOCK(); SERVER_COUNT_UNLOCK();
for (i = 0; i != child_config.maxclients; i++) { for (i = 0; i != child_config.maxclients; i++) {
if (child_ptr[i].status == T_EMPTY) { if (child_ptr[i].status == T_EMPTY) {
child_ptr[i].status = T_WAITING; child_ptr[i].status = T_WAITING;
child_ptr[i].tid = child_ptr[i].tid = child_make(&child_ptr[i]);
child_make (&child_ptr[i]);
if (child_ptr[i].tid < 0) { if (child_ptr[i].tid < 0) {
log_message(LOG_NOTICE, log_message(LOG_NOTICE,
"Could not create child"); "Could not create child");
@@ -418,11 +404,10 @@ void child_main_loop (void)
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
if (config.filter) { if (config.filter) {
log_message (LOG_NOTICE,
"Re-reading filter file.");
filter_destroy(); filter_destroy();
filter_init(); filter_init();
} }
log_message(LOG_NOTICE, "Re-reading filter file.");
#endif /* FILTER_ENABLE */ #endif /* FILTER_ENABLE */
received_sighup = FALSE; received_sighup = FALSE;
@@ -433,9 +418,10 @@ void child_main_loop (void)
/* /*
* Go through all the non-empty children and cancel them. * Go through all the non-empty children and cancel them.
*/ */
void child_kill_children (void) void
child_kill_children(void)
{ {
unsigned int i; int i;
for (i = 0; i != child_config.maxclients; i++) { for (i = 0; i != child_config.maxclients; i++) {
if (child_ptr[i].status != T_EMPTY) if (child_ptr[i].status != T_EMPTY)
@@ -443,13 +429,15 @@ void child_kill_children (void)
} }
} }
int child_listening_sock (uint16_t port) int
child_listening_sock(uint16_t port)
{ {
listenfd = listen_sock(port, &addrlen); listenfd = listen_sock(port, &addrlen);
return listenfd; return listenfd;
} }
void child_close_sock (void) void
child_close_sock(void)
{ {
close(listenfd); close(listenfd);
} }
+13 -16
View File
@@ -1,23 +1,20 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: child.h,v 1.1.2.1 2004-06-14 20:49:57 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * See 'child.c' for more 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) 2002 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 'child.c' for detailed information. */
#ifndef TINYPROXY_CHILD_H #ifndef TINYPROXY_CHILD_H
#define TINYPROXY_CHILD_H #define TINYPROXY_CHILD_H
@@ -35,6 +32,6 @@ extern void child_close_sock (void);
extern void child_main_loop(void); extern void child_main_loop(void);
extern void child_kill_children(void); extern void child_kill_children(void);
extern short int child_configure (child_config_t type, unsigned int val); extern short int child_configure(child_config_t type, int val);
#endif #endif
+18 -25
View File
@@ -1,25 +1,21 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: common.h,v 1.6 2003-06-25 18:20:22 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This file groups all the headers required throughout the tinyproxy
* it under the terms of the GNU General Public License as published by * system. All this information use to be in the "tinyproxy.h" header,
* 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, * but various other "libraries" in the program need the same information,
* without the tinyproxy specific defines. * without the tinyproxy specific defines.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#ifndef COMMON_HEADER_H #ifndef COMMON_HEADER_H
@@ -35,9 +31,6 @@
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#ifdef HAVE_VALUES_H
# include <values.h>
#endif
#ifdef HAVE_INTTYPES_H #ifdef HAVE_INTTYPES_H
# include <inttypes.h> # include <inttypes.h>
#endif #endif
@@ -118,9 +111,6 @@
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
# include <pwd.h> # include <pwd.h>
#endif #endif
#ifdef HAVE_REGEX_H
# include <regex.h>
#endif
#ifdef HAVE_SIGNAL_H #ifdef HAVE_SIGNAL_H
# include <signal.h> # include <signal.h>
#endif #endif
@@ -152,6 +142,9 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#ifdef HAVE_VFORK_H
# include <vfork.h>
#endif
#ifdef HAVE_WCHAR_H #ifdef HAVE_WCHAR_H
# include <wchar.h> # include <wchar.h>
#endif #endif
-760
View File
@@ -1,760 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 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.
*/
/* Parses the configuration file and sets up the config_s structure for
* use by the application. This file replaces the old grammar.y and
* scanner.l files. It takes up less space and _I_ think is easier to
* add new directives to. Who knows if I'm right though.
*/
#include "main.h"
#include "conf.h"
#include "acl.h"
#include "anonymous.h"
#include "child.h"
#include "filter.h"
#include "heap.h"
#include "html-error.h"
#include "log.h"
#include "reqs.h"
#include "reverse-proxy.h"
/*
* The configuration directives are defined in the structure below. Each
* directive requires a regular expression to match against, and a
* function to call when the regex is matched.
*
* Below are defined certain constant regular expression strings that
* can (and likely should) be used when building the regex for the
* given directive.
*/
#define WS "[[:space:]]+"
#define STR "\"([^\"]+)\""
#define BOOL "(yes|on|no|off)"
#define INT "((0x)?[[:digit:]]+)"
#define ALNUM "([-a-z0-9._]+)"
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
#define IPMASK "(" IP "(/[[:digit:]]+)?)"
#define BEGIN "^[[:space:]]*"
#define END "[[:space:]]*$"
/*
* Limit the maximum number of substring matches to a reasonably high
* number. Given the usual structure of the configuration file, sixteen
* substring matches should be plenty.
*/
#define RE_MAX_MATCHES 16
/*
* All configuration handling functions are REQUIRED to be defined
* with the same function template as below.
*/
typedef int (*CONFFILE_HANDLER) (struct config_s *, const char *, regmatch_t[]);
/*
* Define the pattern used by any directive handling function. The
* following arguments are defined:
*
* struct config_s* conf pointer to the current configuration structure
* const char* line full line matched by the regular expression
* regmatch_t match[] offsets to the substrings matched
*
* The handling function must return 0 if the directive was processed
* properly. Any errors are reported by returning a non-zero value.
*/
#define HANDLE_FUNC(func) \
int func(struct config_s* conf, const char* line, \
regmatch_t match[])
/*
* List all the handling functions. These are defined later, but they need
* to be in-scope before the big structure below.
*/
static HANDLE_FUNC (handle_nop)
{
return 0;
} /* do nothing function */
static HANDLE_FUNC (handle_allow);
static HANDLE_FUNC (handle_anonymous);
static HANDLE_FUNC (handle_bind);
static HANDLE_FUNC (handle_bindsame);
static HANDLE_FUNC (handle_connectport);
static HANDLE_FUNC (handle_defaulterrorfile);
static HANDLE_FUNC (handle_deny);
static HANDLE_FUNC (handle_errorfile);
#ifdef FILTER_ENABLE
static HANDLE_FUNC (handle_filter);
static HANDLE_FUNC (handle_filtercasesensitive);
static HANDLE_FUNC (handle_filterdefaultdeny);
static HANDLE_FUNC (handle_filterextended);
static HANDLE_FUNC (handle_filterurls);
#endif
static HANDLE_FUNC (handle_group);
static HANDLE_FUNC (handle_listen);
static HANDLE_FUNC (handle_logfile);
static HANDLE_FUNC (handle_loglevel);
static HANDLE_FUNC (handle_maxclients);
static HANDLE_FUNC (handle_maxrequestsperchild);
static HANDLE_FUNC (handle_maxspareservers);
static HANDLE_FUNC (handle_minspareservers);
static HANDLE_FUNC (handle_pidfile);
static HANDLE_FUNC (handle_port);
#ifdef REVERSE_SUPPORT
static HANDLE_FUNC (handle_reversebaseurl);
static HANDLE_FUNC (handle_reversemagic);
static HANDLE_FUNC (handle_reverseonly);
static HANDLE_FUNC (handle_reversepath);
#endif
static HANDLE_FUNC (handle_startservers);
static HANDLE_FUNC (handle_statfile);
static HANDLE_FUNC (handle_stathost);
static HANDLE_FUNC (handle_syslog);
static HANDLE_FUNC (handle_timeout);
static HANDLE_FUNC (handle_user);
static HANDLE_FUNC (handle_viaproxyname);
static HANDLE_FUNC (handle_xtinyproxy);
#ifdef UPSTREAM_SUPPORT
static HANDLE_FUNC (handle_upstream);
static HANDLE_FUNC (handle_upstream_no);
#endif
/*
* This macro can be used to make standard directives in the form:
* directive arguments [arguments ...]
*
* The directive itself will be the first matched substring.
*
* Note that this macro is not required. As you can see below, the
* comment and blank line elements are defined explicitly since they
* do not follow the pattern above. This macro is for convenience
* only.
*/
#define STDCONF(d, re, func) { BEGIN "(" d ")" WS re END, func, NULL }
/*
* Holds the regular expression used to match the configuration directive,
* the function pointer to the routine to handle the directive, and
* for internal use, a pointer to the compiled regex so it only needs
* to be compiled one.
*/
struct {
const char *re;
CONFFILE_HANDLER handler;
regex_t *cre;
} directives[] = {
/* comments */
{
BEGIN "#", handle_nop, NULL
},
/* blank lines */
{
"^[[:space:]]+$", handle_nop, NULL
},
/* string arguments */
STDCONF ("logfile", STR, handle_logfile),
STDCONF ("pidfile", STR, handle_pidfile),
STDCONF ("anonymous", STR, handle_anonymous),
STDCONF ("viaproxyname", STR, handle_viaproxyname),
STDCONF ("defaulterrorfile", STR, handle_defaulterrorfile),
STDCONF ("statfile", STR, handle_statfile),
STDCONF ("stathost", STR, handle_stathost),
STDCONF ("xtinyproxy", BOOL, handle_xtinyproxy),
/* boolean arguments */
STDCONF ("syslog", BOOL, handle_syslog),
STDCONF ("bindsame", BOOL, handle_bindsame),
/* integer arguments */
STDCONF ("port", INT, handle_port),
STDCONF ("maxclients", INT, handle_maxclients),
STDCONF ("maxspareservers", INT, handle_maxspareservers),
STDCONF ("minspareservers", INT, handle_minspareservers),
STDCONF ("startservers", INT, handle_startservers),
STDCONF ("maxrequestsperchild", INT, handle_maxrequestsperchild),
STDCONF ("timeout", INT, handle_timeout),
STDCONF ("connectport", INT, handle_connectport),
/* alphanumeric arguments */
STDCONF ("user", ALNUM, handle_user),
STDCONF ("group", ALNUM, handle_group),
/* ip arguments */
STDCONF ("listen", IP, handle_listen),
STDCONF ("allow", "(" IPMASK "|" ALNUM ")", handle_allow),
STDCONF ("deny", "(" IPMASK "|" ALNUM ")", handle_deny),
STDCONF ("bind", IP, handle_bind),
/* error files */
STDCONF ("errorfile", INT WS STR, handle_errorfile),
#ifdef FILTER_ENABLE
/* filtering */
STDCONF ("filter", STR, handle_filter),
STDCONF ("filterurls", BOOL, handle_filterurls),
STDCONF ("filterextended", BOOL, handle_filterextended),
STDCONF ("filterdefaultdeny", BOOL, handle_filterdefaultdeny),
STDCONF ("filtercasesensitive", BOOL, handle_filtercasesensitive),
#endif
#ifdef REVERSE_SUPPORT
/* Reverse proxy arguments */
STDCONF ("reversebaseurl", STR, handle_reversebaseurl),
STDCONF ("reverseonly", BOOL, handle_reverseonly),
STDCONF ("reversemagic", BOOL, handle_reversemagic),
STDCONF ("reversepath", STR WS "(" STR ")?", handle_reversepath),
#endif
#ifdef UPSTREAM_SUPPORT
/* upstream is rather complicated */
{
BEGIN "(no" WS "upstream)" WS STR END, handle_upstream_no, NULL
},
{
BEGIN "(upstream)" WS "(" IP "|" ALNUM ")" ":" INT "(" WS STR
")?" END, handle_upstream, NULL
},
#endif
/* loglevel */
STDCONF ("loglevel", "(critical|error|warning|notice|connect|info)",
handle_loglevel)
};
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
/*
* Compiles the regular expressions used by the configuration file. This
* routine MUST be called before trying to parse the configuration file.
*
* Returns 0 on success; negative upon failure.
*/
int config_compile (void)
{
unsigned int i, r;
for (i = 0; i != ndirectives; ++i) {
assert (directives[i].handler);
assert (!directives[i].cre);
directives[i].cre = (regex_t *) safemalloc (sizeof (regex_t));
if (!directives[i].cre)
return -1;
r = regcomp (directives[i].cre,
directives[i].re,
REG_EXTENDED | REG_ICASE | REG_NEWLINE);
if (r)
return r;
}
return 0;
}
/*
* Attempt to match the supplied line with any of the configuration
* regexes defined above. If a match is found, call the handler
* function to process the directive.
*
* Returns 0 if a match was found and successfully processed; otherwise,
* a negative number is returned.
*/
static int check_match (struct config_s *conf, const char *line)
{
regmatch_t match[RE_MAX_MATCHES];
unsigned int i;
assert (ndirectives > 0);
for (i = 0; i != ndirectives; ++i) {
assert (directives[i].cre);
if (!regexec
(directives[i].cre, line, RE_MAX_MATCHES, match, 0))
return (*directives[i].handler) (conf, line, match);
}
return -1;
}
/*
* Parse the previously opened configuration stream.
*/
int config_parse (struct config_s *conf, FILE * f)
{
char buffer[1024]; /* 1KB lines should be plenty */
unsigned long lineno = 1;
while (fgets (buffer, sizeof (buffer), f)) {
if (check_match (conf, buffer)) {
printf ("Syntax error on line %ld\n", lineno);
return 1;
}
++lineno;
}
return 0;
}
/***********************************************************************
*
* The following are basic data extraction building blocks that can
* be used to simplify the parsing of a directive.
*
***********************************************************************/
static char *get_string_arg (const char *line, regmatch_t * match)
{
char *p;
const unsigned int len = match->rm_eo - match->rm_so;
assert (line);
assert (len > 0);
p = (char *) safemalloc (len + 1);
if (!p)
return NULL;
memcpy (p, line + match->rm_so, len);
p[len] = '\0';
return p;
}
static int set_string_arg (char **var, const char *line, regmatch_t * match)
{
char *arg = get_string_arg (line, match);
if (!arg)
return -1;
*var = safestrdup (arg);
safefree (arg);
return *var ? 0 : -1;
}
static int get_bool_arg (const char *line, regmatch_t * match)
{
const char *p = line + match->rm_so;
assert (line);
assert (match && match->rm_so != -1);
/* "y"es or o"n" map as true, otherwise it's false. */
if (tolower (p[0]) == 'y' || tolower (p[1]) == 'n')
return 1;
else
return 0;
}
static int
set_bool_arg (unsigned int *var, const char *line, regmatch_t * match)
{
assert (var);
assert (line);
assert (match && match->rm_so != -1);
*var = get_bool_arg (line, match);
return 0;
}
static unsigned long int
get_int_arg (const char *line, regmatch_t * match)
{
assert (line);
assert (match && match->rm_so != -1);
return strtoul (line + match->rm_so, NULL, 0);
}
static int
set_int_arg (unsigned long int *var, const char *line, regmatch_t * match)
{
assert (var);
assert (line);
assert (match);
*var = get_int_arg (line, match);
return 0;
}
/***********************************************************************
*
* Below are all the directive handling functions. You will notice
* that most of the directives delegate to one of the basic data
* extraction routines. This is deliberate. To add a new directive
* to tinyproxy only requires you to define the regular expression
* above and then figure out what data extract routine to use.
*
* However, you will also notice that more complicated directives are
* possible. You can make your directive as complicated as you require
* to express a solution to the problem you're tackling.
*
* See the definition/comment about the HANDLE_FUNC() macro to learn
* what arguments are supplied to the handler, and to determine what
* values to return.
*
***********************************************************************/
static HANDLE_FUNC (handle_logfile)
{
return set_string_arg (&conf->logf_name, line, &match[2]);
}
static HANDLE_FUNC (handle_pidfile)
{
return set_string_arg (&conf->pidpath, line, &match[2]);
}
static HANDLE_FUNC (handle_anonymous)
{
char *arg = get_string_arg (line, &match[2]);
if (!arg)
return -1;
anonymous_insert (arg);
safefree (arg);
return 0;
}
static HANDLE_FUNC (handle_viaproxyname)
{
int r = set_string_arg (&conf->via_proxy_name, line, &match[2]);
if (r)
return r;
log_message (LOG_INFO,
"Setting \"Via\" header proxy to %s",
conf->via_proxy_name);
return 0;
}
static HANDLE_FUNC (handle_defaulterrorfile)
{
return set_string_arg (&conf->errorpage_undef, line, &match[2]);
}
static HANDLE_FUNC (handle_statfile)
{
return set_string_arg (&conf->statpage, line, &match[2]);
}
static HANDLE_FUNC (handle_stathost)
{
int r = set_string_arg (&conf->stathost, line, &match[2]);
if (r)
return r;
log_message (LOG_INFO, "Stathost set to \"%s\"", conf->stathost);
return 0;
}
static HANDLE_FUNC (handle_xtinyproxy)
{
#ifdef XTINYPROXY_ENABLE
return set_bool_arg (&conf->add_xtinyproxy, line, &match[2]);
#else
fprintf (stderr,
"XTinyproxy NOT Enabled! Recompile with --enable-xtinyproxy\n");
return 1;
#endif
}
static HANDLE_FUNC (handle_syslog)
{
#ifdef HAVE_SYSLOG_H
return set_bool_arg (&conf->syslog, line, &match[2]);
#else
fprintf (stderr, "Syslog support not compiled in executable.\n");
return 1;
#endif
}
static HANDLE_FUNC (handle_bindsame)
{
int r = set_bool_arg (&conf->bindsame, line, &match[2]);
if (r)
return r;
log_message (LOG_INFO, "Binding outgoing connection to incoming IP");
return 0;
}
static HANDLE_FUNC (handle_port)
{
return set_int_arg ((unsigned long int *) &conf->port, line, &match[2]);
}
static HANDLE_FUNC (handle_maxclients)
{
child_configure (CHILD_MAXCLIENTS, get_int_arg (line, &match[2]));
return 0;
}
static HANDLE_FUNC (handle_maxspareservers)
{
child_configure (CHILD_MAXSPARESERVERS, get_int_arg (line, &match[2]));
return 0;
}
static HANDLE_FUNC (handle_minspareservers)
{
child_configure (CHILD_MINSPARESERVERS, get_int_arg (line, &match[2]));
return 0;
}
static HANDLE_FUNC (handle_startservers)
{
child_configure (CHILD_STARTSERVERS, get_int_arg (line, &match[2]));
return 0;
}
static HANDLE_FUNC (handle_maxrequestsperchild)
{
child_configure (CHILD_MAXREQUESTSPERCHILD,
get_int_arg (line, &match[2]));
return 0;
}
static HANDLE_FUNC (handle_timeout)
{
return set_int_arg ((unsigned long int *) &conf->idletimeout, line,
&match[2]);
}
static HANDLE_FUNC (handle_connectport)
{
add_connect_port_allowed (get_int_arg (line, &match[2]));
return 0;
}
static HANDLE_FUNC (handle_user)
{
return set_string_arg (&conf->user, line, &match[2]);
}
static HANDLE_FUNC (handle_group)
{
return set_string_arg (&conf->group, line, &match[2]);
}
static HANDLE_FUNC (handle_allow)
{
char *arg = get_string_arg (line, &match[2]);
insert_acl (arg, ACL_ALLOW);
safefree (arg);
return 0;
}
static HANDLE_FUNC (handle_deny)
{
char *arg = get_string_arg (line, &match[2]);
insert_acl (arg, ACL_DENY);
safefree (arg);
return 0;
}
static HANDLE_FUNC (handle_bind)
{
#ifndef TRANSPARENT_PROXY
int r = set_string_arg (&conf->bind_address, line, &match[2]);
if (r)
return r;
log_message (LOG_INFO,
"Outgoing connections bound to IP %s", conf->bind_address);
return 0;
#else
fprintf (stderr,
"\"Bind\" cannot be used with transparent support enabled.\n");
return 1;
#endif
}
static HANDLE_FUNC (handle_listen)
{
int r = set_string_arg (&conf->ipAddr, line, &match[2]);
if (r)
return r;
log_message (LOG_INFO, "Listing on IP %s", conf->ipAddr);
return 0;
}
static HANDLE_FUNC (handle_errorfile)
{
/*
* Because an integer is defined as ((0x)?[[:digit:]]+) _two_
* match places are used. match[2] matches the full digit
* string, while match[3] matches only the "0x" part if
* present. This is why the "string" is located at
* match[4] (rather than the more intuitive match[3].
*/
unsigned long int err = get_int_arg (line, &match[2]);
char *page = get_string_arg (line, &match[4]);
add_new_errorpage (page, err);
safefree (page);
return 0;
}
/*
* Log level's strings.
*/
struct log_levels_s {
const char *string;
int level;
};
static struct log_levels_s log_levels[] = {
{"critical", LOG_CRIT},
{"error", LOG_ERR},
{"warning", LOG_WARNING},
{"notice", LOG_NOTICE},
{"connect", LOG_CONN},
{"info", LOG_INFO}
};
static HANDLE_FUNC (handle_loglevel)
{
static const unsigned int nlevels =
sizeof (log_levels) / sizeof (log_levels[0]);
unsigned int i;
char *arg = get_string_arg (line, &match[2]);
for (i = 0; i != nlevels; ++i) {
if (!strcasecmp (arg, log_levels[i].string)) {
set_log_level (log_levels[i].level);
safefree (arg);
return 0;
}
}
safefree (arg);
return -1;
}
#ifdef FILTER_ENABLE
static HANDLE_FUNC (handle_filter)
{
return set_string_arg (&conf->filter, line, &match[2]);
}
static HANDLE_FUNC (handle_filterurls)
{
return set_bool_arg (&conf->filter_url, line, &match[2]);
}
static HANDLE_FUNC (handle_filterextended)
{
return set_bool_arg (&conf->filter_extended, line, &match[2]);
}
static HANDLE_FUNC (handle_filterdefaultdeny)
{
assert (match[2].rm_so != -1);
if (get_bool_arg (line, &match[2]))
filter_set_default_policy (FILTER_DEFAULT_DENY);
return 0;
}
static HANDLE_FUNC (handle_filtercasesensitive)
{
return set_bool_arg (&conf->filter_casesensitive, line, &match[2]);
}
#endif
#ifdef REVERSE_SUPPORT
static HANDLE_FUNC (handle_reverseonly)
{
return set_bool_arg (&conf->reverseonly, line, &match[2]);
}
static HANDLE_FUNC (handle_reversemagic)
{
return set_bool_arg (&conf->reversemagic, line, &match[2]);
}
static HANDLE_FUNC (handle_reversebaseurl)
{
return set_string_arg (&conf->reversebaseurl, line, &match[2]);
}
static HANDLE_FUNC (handle_reversepath)
{
/*
* The second string argument is optional.
*/
char *arg1, *arg2;
arg1 = get_string_arg (line, &match[2]);
if (!arg1)
return -1;
if (match[3].rm_so != -1) {
arg2 = get_string_arg (line, &match[3]);
if (!arg2) {
safefree (arg1);
return -1;
}
reversepath_add (arg1, arg2);
safefree (arg1);
safefree (arg2);
} else {
reversepath_add (NULL, arg1);
safefree (arg1);
}
return 0;
}
#endif
#ifdef UPSTREAM_SUPPORT
static HANDLE_FUNC (handle_upstream)
{
char *ip;
int port;
char *domain;
ip = get_string_arg (line, &match[2]);
if (!ip)
return -1;
port = (int) get_int_arg (line, &match[7]);
if (match[9].rm_so != -1) {
domain = get_string_arg (line, &match[9]);
if (domain) {
upstream_add (ip, port, domain);
safefree (domain);
}
} else {
upstream_add (ip, port, NULL);
}
safefree (ip);
return 0;
}
static HANDLE_FUNC (handle_upstream_no)
{
char *domain;
domain = get_string_arg (line, &match[2]);
if (!domain)
return -1;
upstream_add (NULL, 0, domain);
safefree (domain);
return 0;
}
#endif
-27
View File
@@ -1,27 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 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 'conf.c' for detailed information. */
#ifndef TINYPROXY_CONF_H
#define TINYPROXY_CONF_H
extern int config_compile (void);
extern int config_parse (struct config_s *conf, FILE * f);
#endif
+32 -38
View File
@@ -1,28 +1,24 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: conns.c,v 1.17.2.1 2004-08-06 16:56:55 rjkaes Exp $
* Copyright (C) 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * Create and free the connection structure. One day there could be
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* Create and free the connection structure. One day there could be
* other connection related tasks put here, but for now the header * other connection related tasks put here, but for now the header
* file and this file are only used for create/free functions and the * file and this file are only used for create/free functions and the
* connection structure definition. * connection structure definition.
*
* Copyright (C) 2001 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "buffer.h" #include "buffer.h"
#include "conns.h" #include "conns.h"
@@ -30,9 +26,8 @@
#include "log.h" #include "log.h"
#include "stats.h" #include "stats.h"
struct conn_s *initialize_conn (int client_fd, const char *ipaddr, struct conn_s *
const char *string_addr, initialize_conn(int client_fd, const char* ipaddr, const char* string_addr)
const char *sock_ipaddr)
{ {
struct conn_s *connptr; struct conn_s *connptr;
struct buffer_s *cbuffer, *sbuffer; struct buffer_s *cbuffer, *sbuffer;
@@ -51,7 +46,7 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
/* /*
* Allocate the space for the conn_s structure itself. * Allocate the space for the conn_s structure itself.
*/ */
connptr = (struct conn_s *) safemalloc (sizeof (struct conn_s)); connptr = safemalloc(sizeof(struct conn_s));
if (!connptr) if (!connptr)
goto error_exit; goto error_exit;
@@ -65,6 +60,7 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
/* These store any error strings */ /* These store any error strings */
connptr->error_variables = NULL; connptr->error_variables = NULL;
connptr->error_variable_count = 0;
connptr->error_string = NULL; connptr->error_string = NULL;
connptr->error_number = -1; connptr->error_number = -1;
@@ -76,7 +72,6 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
/* There is _no_ content length initially */ /* There is _no_ content length initially */
connptr->content_length.server = connptr->content_length.client = -1; connptr->content_length.server = connptr->content_length.client = -1;
connptr->server_ip_addr = sock_ipaddr ? safestrdup (sock_ipaddr) : 0;
connptr->client_ip_addr = safestrdup(ipaddr); connptr->client_ip_addr = safestrdup(ipaddr);
connptr->client_string_addr = safestrdup(string_addr); connptr->client_string_addr = safestrdup(string_addr);
@@ -84,10 +79,6 @@ struct conn_s *initialize_conn (int client_fd, const char *ipaddr,
update_stats(STAT_OPEN); update_stats(STAT_OPEN);
#ifdef REVERSE_SUPPORT
connptr->reversepath = NULL;
#endif
return connptr; return connptr;
error_exit: error_exit:
@@ -102,7 +93,8 @@ error_exit:
return NULL; return NULL;
} }
void destroy_conn (struct conn_s *connptr) void
destroy_conn(struct conn_s *connptr)
{ {
assert(connptr != NULL); assert(connptr != NULL);
@@ -123,24 +115,26 @@ void destroy_conn (struct conn_s *connptr)
if (connptr->request_line) if (connptr->request_line)
safefree(connptr->request_line); safefree(connptr->request_line);
if (connptr->error_variables) if (connptr->error_variables) {
hashmap_delete (connptr->error_variables); int i;
for (i = 0; i != connptr->error_variable_count; ++i) {
safefree(connptr->error_variables[i]->error_key);
safefree(connptr->error_variables[i]->error_val);
safefree(connptr->error_variables[i]);
}
safefree(connptr->error_variables);
}
if (connptr->error_string) if (connptr->error_string)
safefree(connptr->error_string); safefree(connptr->error_string);
if (connptr->server_ip_addr)
safefree (connptr->server_ip_addr);
if (connptr->client_ip_addr) if (connptr->client_ip_addr)
safefree(connptr->client_ip_addr); safefree(connptr->client_ip_addr);
if (connptr->client_string_addr) if (connptr->client_string_addr)
safefree(connptr->client_string_addr); safefree(connptr->client_string_addr);
#ifdef REVERSE_SUPPORT
if (connptr->reversepath)
safefree (connptr->reversepath);
#endif
safefree(connptr); safefree(connptr);
update_stats(STAT_CLOSE); update_stats(STAT_CLOSE);
+20 -33
View File
@@ -1,28 +1,24 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: conns.h,v 1.14.2.1 2004-08-06 16:56:55 rjkaes Exp $
* Copyright (C) 2001 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * See 'conns.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) 2001 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 'conns.c' for detailed information. */
#ifndef TINYPROXY_CONNS_H #ifndef TINYPROXY_CONNS_H
#define TINYPROXY_CONNS_H #define TINYPROXY_CONNS_H
#include "main.h" #include "tinyproxy.h"
#include "hashmap.h"
/* /*
* Connection Definition * Connection Definition
@@ -42,10 +38,15 @@ struct conn_s {
unsigned int show_stats; unsigned int show_stats;
/* /*
* Store the error response if there is one.
* This structure stores key -> value mappings for substitution * This structure stores key -> value mappings for substitution
* in the error HTML files. * in the error HTML files.
*/ */
hashmap_t error_variables; struct error_variable_s {
char *error_key;
char *error_val;
} **error_variables;
int error_variable_count;
int error_number; int error_number;
char *error_string; char *error_string;
@@ -56,11 +57,6 @@ struct conn_s {
long int client; long int client;
} content_length; } content_length;
/*
* Store the server's IP (for BindSame)
*/
char *server_ip_addr;
/* /*
* Store the client's IP and hostname information * Store the client's IP and hostname information
*/ */
@@ -74,14 +70,6 @@ struct conn_s {
unsigned int major; unsigned int major;
unsigned int minor; unsigned int minor;
} protocol; } protocol;
#ifdef REVERSE_SUPPORT
/*
* Place to store the current per-connection reverse proxy path
*/
char *reversepath;
#endif
/* /*
* Pointer to upstream proxy. * Pointer to upstream proxy.
*/ */
@@ -92,8 +80,7 @@ struct conn_s {
* Functions for the creation and destruction of a connection structure. * Functions for the creation and destruction of a connection structure.
*/ */
extern struct conn_s* initialize_conn(int client_fd, const char* ipaddr, extern struct conn_s* initialize_conn(int client_fd, const char* ipaddr,
const char *string_addr, const char* string_addr);
const char *sock_ipaddr);
extern void destroy_conn(struct conn_s *connptr); extern void destroy_conn(struct conn_s *connptr);
#endif #endif
+20 -27
View File
@@ -1,36 +1,32 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: daemon.c,v 1.2.2.1 2004-08-10 03:38:13 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This file contains functions which are useful when writing a
* 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 * daemon process. The functions include a "makedaemon" function and
* a function to portably set a signal handler. * a function to portably set a signal handler.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "daemon.h" #include "daemon.h"
#include "log.h"
/* /*
* Fork a child process and then kill the parent so make the calling * Fork a child process and then kill the parent so make the calling
* program a daemon process. * program a daemon process.
*/ */
void makedaemon (void) void
makedaemon(void)
{ {
if (fork() != 0) if (fork() != 0)
exit(0); exit(0);
@@ -41,11 +37,7 @@ void makedaemon (void)
if (fork() != 0) if (fork() != 0)
exit(0); exit(0);
if (chdir ("/") != 0) { chdir("/");
log_message (LOG_WARNING,
"Could not change directory to /");
}
umask(0177); umask(0177);
#if NDEBUG #if NDEBUG
@@ -63,7 +55,8 @@ void makedaemon (void)
* Pass a signal number and a signal handling function into this function * Pass a signal number and a signal handling function into this function
* to handle signals sent to the process. * to handle signals sent to the process.
*/ */
signal_func *set_signal_handler (int signo, signal_func * func) signal_func *
set_signal_handler(int signo, signal_func *func)
{ {
struct sigaction act, oact; struct sigaction act, oact;
+12 -15
View File
@@ -1,23 +1,20 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: daemon.h,v 1.1 2002-05-23 04:39:32 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * See 'daemon.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) 2002 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 'daemon.c' for detailed information. */
#ifndef TINYPROXY_DAEMON_H #ifndef TINYPROXY_DAEMON_H
#define TINYPROXY_DAEMON_H #define TINYPROXY_DAEMON_H
+43 -48
View File
@@ -1,32 +1,29 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: filter.c,v 1.16.2.1 2003-10-16 21:19:09 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 * Copyright (c) 2002 James E. Flemer (jflemer@acm.jhu.edu)
* the Free Software Foundation; either version 2 of the License, or * Copyright (c) 2002 Robert James Kaes (rjkaes@flarenet.com)
* (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 "filter.h" #include "filter.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "regexp.h"
#include "reqs.h" #include "reqs.h"
#define FILTER_BUFFER_LEN (512) #define FILTER_BUFFER_LEN (512)
@@ -46,7 +43,8 @@ static filter_policy_t default_policy = FILTER_DEFAULT_ALLOW;
/* /*
* Initializes a linked list of strings containing hosts/urls to be filtered * Initializes a linked list of strings containing hosts/urls to be filtered
*/ */
void filter_init (void) void
filter_init(void)
{ {
FILE *fd; FILE *fd;
struct filter_list *p; struct filter_list *p;
@@ -54,15 +52,9 @@ void filter_init (void)
char *s; char *s;
int cflags; int cflags;
if (fl || already_init) { if (!fl && !already_init) {
return;
}
fd = fopen(config.filter, "r"); fd = fopen(config.filter, "r");
if (!fd) { if (fd) {
return;
}
p = NULL; p = NULL;
cflags = REG_NEWLINE | REG_NOSUB; cflags = REG_NEWLINE | REG_NOSUB;
@@ -78,8 +70,7 @@ void filter_init (void)
*/ */
s = buf; s = buf;
while (*s) { while (*s) {
if (isspace ((unsigned char) *s)) if (isspace((unsigned char)*s)) break;
break;
if (*s == '#') { if (*s == '#') {
/* /*
* If the '#' char is preceeded by * If the '#' char is preceeded by
@@ -104,21 +95,21 @@ void filter_init (void)
if (!p) /* head of list */ if (!p) /* head of list */
fl = p = fl = p =
(struct filter_list *) safecalloc(1,
safecalloc (1, sizeof (struct filter_list)); sizeof(struct
filter_list));
else { /* next entry */ else { /* next entry */
p->next = p->next =
(struct filter_list *) safecalloc(1,
safecalloc (1, sizeof (struct filter_list)); sizeof(struct
filter_list));
p = p->next; p = p->next;
} }
p->pat = safestrdup(s); p->pat = safestrdup(s);
p->cpat = (regex_t *) safemalloc (sizeof (regex_t)); p->cpat = safemalloc(sizeof(regex_t));
err = regcomp (p->cpat, p->pat, cflags); if ((err = regcomp(p->cpat, p->pat, cflags)) != 0) {
if (err != 0) { fprintf(stderr, "Bad regex in %s: %s\n",
fprintf (stderr,
"Bad regex in %s: %s\n",
config.filter, p->pat); config.filter, p->pat);
exit(EX_DATAERR); exit(EX_DATAERR);
} }
@@ -131,9 +122,12 @@ void filter_init (void)
already_init = 1; 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;
@@ -151,7 +145,8 @@ void filter_destroy (void)
} }
/* Return 0 to allow, non-zero to block */ /* Return 0 to allow, non-zero to block */
int filter_domain (const char *host) int
filter_domain(const char *host)
{ {
struct filter_list *p; struct filter_list *p;
int result; int result;
@@ -160,8 +155,7 @@ int filter_domain (const char *host)
goto COMMON_EXIT; goto COMMON_EXIT;
for (p = fl; p; p = p->next) { for (p = fl; p; p = p->next) {
result = result = regexec(p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0);
regexec (p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0);
if (result == 0) { if (result == 0) {
if (default_policy == FILTER_DEFAULT_ALLOW) if (default_policy == FILTER_DEFAULT_ALLOW)
@@ -179,7 +173,8 @@ COMMON_EXIT:
} }
/* returns 0 to allow, non-zero to block */ /* returns 0 to allow, non-zero to block */
int filter_url (const char *url) int
filter_url(const char *url)
{ {
struct filter_list *p; struct filter_list *p;
int result; int result;
@@ -188,8 +183,7 @@ int filter_url (const char *url)
goto COMMON_EXIT; goto COMMON_EXIT;
for (p = fl; p; p = p->next) { for (p = fl; p; p = p->next) {
result = result = regexec(p->cpat, url, (size_t) 0, (regmatch_t *) 0, 0);
regexec (p->cpat, url, (size_t) 0, (regmatch_t *) 0, 0);
if (result == 0) { if (result == 0) {
if (default_policy == FILTER_DEFAULT_ALLOW) if (default_policy == FILTER_DEFAULT_ALLOW)
@@ -209,7 +203,8 @@ COMMON_EXIT:
/* /*
* Set the default filtering policy * Set the default filtering policy
*/ */
void filter_set_default_policy (filter_policy_t policy) void
filter_set_default_policy(filter_policy_t policy)
{ {
default_policy = policy; default_policy = policy;
} }
+13 -16
View File
@@ -1,29 +1,26 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: filter.h,v 1.5 2002-06-07 18:36:21 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 { typedef enum {
FILTER_DEFAULT_ALLOW, FILTER_DEFAULT_ALLOW,
FILTER_DEFAULT_DENY FILTER_DEFAULT_DENY,
} filter_policy_t; } filter_policy_t;
extern void filter_init(void); extern void filter_init(void);
+5880
View File
File diff suppressed because it is too large. Load diff
+542
View File
@@ -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:
*/
+270
View File
@@ -0,0 +1,270 @@
/* $Id: grammar.y,v 1.23 2003-06-26 18:17: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 "child.h"
#include "filter.h"
#include "htmlerror.h"
#include "log.h"
#include "reqs.h"
void yyerror(char *s);
int yylex(void);
%}
%union {
unsigned int num;
char *cptr;
}
/* statements */
%token KW_PORT KW_LISTEN
%token KW_LOGFILE KW_PIDFILE KW_SYSLOG
%token KW_MAXCLIENTS KW_MAXSPARESERVERS KW_MINSPARESERVERS KW_STARTSERVERS
%token KW_MAXREQUESTSPERCHILD
%token KW_TIMEOUT
%token KW_USER KW_GROUP
%token KW_ANONYMOUS KW_XTINYPROXY
%token KW_FILTER KW_FILTERURLS KW_FILTEREXTENDED KW_FILTER_DEFAULT_DENY
%token KW_FILTER_CASESENSITIVE
%token KW_UPSTREAM
%token KW_CONNECTPORT KW_BIND
%token KW_STATHOST
%token KW_ALLOW KW_DENY
%token KW_ERRORPAGE KW_DEFAULT_ERRORPAGE
%token KW_STATPAGE
%token KW_VIA_PROXY_NAME
/* yes/no switches */
%token KW_YES KW_NO
/* settings for loglevel */
%token KW_LOGLEVEL
%token KW_LOG_CRITICAL KW_LOG_ERROR KW_LOG_WARNING KW_LOG_NOTICE KW_LOG_CONNECT KW_LOG_INFO
%token <cptr> IDENTIFIER
%token <num> NUMBER
%token <cptr> STRING
%token <cptr> NUMERIC_ADDRESS
%token <cptr> NETMASK_ADDRESS
%type <num> yesno
%type <cptr> string
%type <cptr> network_address
%type <cptr> unique_address
%type <num> loglevels
%%
start
: /* empty */
| start line
;
line
: '\n'
| statement '\n'
;
statement
: KW_PORT NUMBER { config.port = $2; }
| KW_TIMEOUT NUMBER { config.idletimeout = $2; }
| KW_SYSLOG yesno
{
#ifdef HAVE_SYSLOG_H
config.syslog = $2;
#else
log_message(LOG_WARNING, "Syslog support was not compiled in.");
#endif
}
| KW_MAXCLIENTS NUMBER { child_configure(CHILD_MAXCLIENTS, $2); }
| KW_MAXSPARESERVERS NUMBER { child_configure(CHILD_MAXSPARESERVERS, $2); }
| KW_MINSPARESERVERS NUMBER { child_configure(CHILD_MINSPARESERVERS, $2); }
| KW_STARTSERVERS NUMBER { child_configure(CHILD_STARTSERVERS, $2); }
| KW_MAXREQUESTSPERCHILD NUMBER { child_configure(CHILD_MAXREQUESTSPERCHILD, $2); }
| KW_LOGFILE string
{
config.logf_name = $2;
if (!config.logf_name) {
fprintf(stderr, "bad log file\n");
}
}
| KW_PIDFILE string { config.pidpath = $2; }
| KW_USER string { config.username = $2; }
| KW_GROUP string { config.group = $2; }
| KW_ANONYMOUS string { anonymous_insert($2); }
| KW_ERRORPAGE NUMBER string { add_new_errorpage($3, $2); }
| KW_DEFAULT_ERRORPAGE string { config.errorpage_undef = $2; }
| KW_STATPAGE string { config.statpage = $2; }
| KW_FILTER string
{
#ifdef FILTER_ENABLE
config.filter = $2;
#else
log_message(LOG_WARNING, "Filter support was not compiled in.");
#endif
}
| KW_FILTERURLS yesno
{
#ifdef FILTER_ENABLE
config.filter_url = $2;
#else
log_message(LOG_WARNING, "Filter support wss not compiled in.");
#endif
}
| KW_FILTEREXTENDED yesno
{
#ifdef FILTER_ENABLE
config.filter_extended = $2;
#else
log_message(LOG_WARNING, "Filter support was not compiled in.");
#endif
}
| KW_FILTER_CASESENSITIVE yesno
{
#ifdef FILTER_ENABLE
config.filter_casesensitive = $2;
#else
log_message(LOG_WARNING, "Filter support was not compiled in.");
#endif
}
| KW_FILTER_DEFAULT_DENY yesno
{
#ifdef FILTER_ENABLE
if ($2)
filter_set_default_policy(FILTER_DEFAULT_DENY);
#else
log_message(LOG_WARNING, "FIlter support was not compiled in.");
#endif
}
| KW_XTINYPROXY network_address
{
#ifdef XTINYPROXY_ENABLE
config.my_domain = $2;
#else
log_message(LOG_WARNING, "X-Tinyproxy header support was not compiled in.");
#endif
}
| KW_UPSTREAM unique_address ':' NUMBER
{
#ifdef UPSTREAM_SUPPORT
upstream_add($2, $4, NULL);
#else
log_message(LOG_WARNING, "Upstream proxy support was not compiled in.");
#endif
}
| KW_UPSTREAM unique_address ':' NUMBER STRING
{
#ifdef UPSTREAM_SUPPORT
upstream_add($2, $4, $5);
#else
log_message(LOG_WARNING, "Upstream proxy support was not compiled in.");
#endif
}
| KW_NO KW_UPSTREAM STRING
{
#ifdef UPSTREAM_SUPPORT
upstream_add(NULL, 0, $3);
#else
log_message(LOG_WARNING, "Upstream proxy support was not compiled in.");
#endif
}
| KW_LISTEN NUMERIC_ADDRESS
{
log_message(LOG_INFO, "Establishing listening socket on IP %s", $2);
config.ipAddr = $2;
}
| KW_ALLOW network_address { insert_acl($2, ACL_ALLOW); }
| KW_DENY network_address { insert_acl($2, ACL_DENY); }
| KW_LOGLEVEL loglevels { set_log_level($2); }
| KW_CONNECTPORT NUMBER { add_connect_port_allowed($2); }
| KW_BIND NUMERIC_ADDRESS
{
#ifndef TRANSPARENT_PROXY
log_message(LOG_INFO, "Binding outgoing connections to %s", $2);
config.bind_address = $2;
#else
log_message(LOG_WARNING, "The 'Bind' directive can not be used with transparent proxy support. Ignoring the directive.");
#endif
}
| KW_VIA_PROXY_NAME string
{
log_message(LOG_INFO, "Setting \"Via\" proxy name to: %s", $2);
config.via_proxy_name = $2;
}
| KW_STATHOST string
{
log_message(LOG_INFO, "Stathost is set to \"%s\"", $2);
config.stathost = $2;
}
;
loglevels
: KW_LOG_CRITICAL { $$ = LOG_CRIT; }
| KW_LOG_ERROR { $$ = LOG_ERR; }
| KW_LOG_WARNING { $$ = LOG_WARNING; }
| KW_LOG_NOTICE { $$ = LOG_NOTICE; }
| KW_LOG_CONNECT { $$ = LOG_CONN; }
| KW_LOG_INFO { $$ = LOG_INFO; }
;
network_address
: unique_address
| NETMASK_ADDRESS
;
unique_address
: IDENTIFIER
| NUMERIC_ADDRESS
;
yesno
: KW_YES { $$ = 1; }
| KW_NO { $$ = 0; }
| NUMBER { $$ = $1; }
;
string
: IDENTIFIER
| STRING
;
%%
extern int yylineno;
void
yyerror(char *s)
{
static int headerdisplayed = 0;
if (!headerdisplayed) {
fprintf(stderr, "Errors in configuration file:\n");
headerdisplayed = 1;
}
fprintf(stderr, "\t%s:%d: %s\n", config.config_file, yylineno, s);
exit(EXIT_FAILURE);
}
+82 -70
View File
@@ -1,5 +1,14 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: hashmap.c,v 1.12 2003-05-31 23:02:21 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net> *
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
* key and the data in the hashmap itself, so you must free the original
* key and data to avoid a memory leak. The hashmap returns a pointer
* to the data when a key is searched for, so take care in modifying the
* data as it's modifying the data stored in the hashmap. (In other words,
* don't try to free the data, or realloc the memory. :)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -11,21 +20,12 @@
* 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
*/ */
/* A hashmap implementation. The keys are case-insensitive NULL terminated #include "tinyproxy.h"
* strings, and the data is arbitrary lumps of data. Copies of both the
* key and the data in the hashmap itself, so you must free the original
* key and data to avoid a memory leak. The hashmap returns a pointer
* to the data when a key is searched for, so take care in modifying the
* data as it's modifying the data stored in the hashmap. (In other words,
* don't try to free the data, or realloc the memory. :)
*/
#include "main.h"
#include "hashmap.h" #include "hashmap.h"
#include "heap.h" #include "heap.h"
@@ -44,16 +44,11 @@ struct hashentry_s {
struct hashentry_s *prev, *next; struct hashentry_s *prev, *next;
}; };
struct hashbucket_s {
struct hashentry_s *head, *tail;
};
struct hashmap_s { struct hashmap_s {
unsigned int size; unsigned int size;
hashmap_iter end_iterator; hashmap_iter end_iterator;
struct hashbucket_s *buckets; struct hashentry_s **buckets;
}; };
/* /*
@@ -65,7 +60,8 @@ struct hashmap_s {
* *
* If any of the arguments are invalid a negative number is returned. * If any of the arguments are invalid a negative number is returned.
*/ */
static int hashfunc (const char *key, unsigned int size) static int
hashfunc(const char *key, unsigned int size)
{ {
uint32_t hash; uint32_t hash;
@@ -75,8 +71,8 @@ static int hashfunc (const char *key, unsigned int size)
return -ERANGE; return -ERANGE;
for (hash = tolower(*key++); *key != '\0'; key++) { for (hash = tolower(*key++); *key != '\0'; key++) {
uint32_t bit = (hash & 1) ? (1 << (sizeof (uint32_t) - 1)) : 0; uint32_t bit =
(hash & 1) ? (1 << (sizeof(uint32_t) - 1)) : 0;
hash >>= 1; hash >>= 1;
hash += tolower(*key) + bit; hash += tolower(*key) + bit;
@@ -93,21 +89,20 @@ static int hashfunc (const char *key, unsigned int size)
* *
* NULLs are also returned if memory could not be allocated for hashmap. * NULLs are also returned if memory could not be allocated for hashmap.
*/ */
hashmap_t hashmap_create (unsigned int nbuckets) hashmap_t
hashmap_create(unsigned int nbuckets)
{ {
struct hashmap_s* ptr; struct hashmap_s* ptr;
if (nbuckets == 0) if (nbuckets == 0)
return NULL; return NULL;
ptr = (struct hashmap_s *) safecalloc (1, sizeof (struct hashmap_s)); ptr = safecalloc(1, sizeof(struct hashmap_s));
if (!ptr) if (!ptr)
return NULL; return NULL;
ptr->size = nbuckets; ptr->size = nbuckets;
ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets, ptr->buckets = safecalloc(nbuckets, sizeof(struct hashentry_s *));
sizeof (struct
hashbucket_s));
if (!ptr->buckets) { if (!ptr->buckets) {
safefree(ptr); safefree(ptr);
return NULL; return NULL;
@@ -126,15 +121,16 @@ hashmap_t hashmap_create (unsigned int nbuckets)
* Returns: 0 if the function completed successfully * Returns: 0 if the function completed successfully
* negative number is returned if "entry" was NULL * negative number is returned if "entry" was NULL
*/ */
static int delete_hashbucket (struct hashbucket_s *bucket) static inline int
delete_hashbucket(struct hashentry_s* entry)
{ {
struct hashentry_s *nextptr; struct hashentry_s *nextptr;
struct hashentry_s *ptr; struct hashentry_s *ptr;
if (bucket == NULL || bucket->head == NULL) if (entry == NULL)
return -EINVAL; return -EINVAL;
ptr = bucket->head; ptr = entry;
while (ptr) { while (ptr) {
nextptr = ptr->next; nextptr = ptr->next;
@@ -154,7 +150,8 @@ static int delete_hashbucket (struct hashbucket_s *bucket)
* Returns: 0 on success * Returns: 0 on success
* negative if a NULL "map" was supplied * negative if a NULL "map" was supplied
*/ */
int hashmap_delete (hashmap_t map) int
hashmap_delete(hashmap_t map)
{ {
unsigned int i; unsigned int i;
@@ -162,8 +159,9 @@ int hashmap_delete (hashmap_t map)
return -EINVAL; return -EINVAL;
for (i = 0; i != map->size; i++) { for (i = 0; i != map->size; i++) {
if (map->buckets[i].head != NULL) { if (map->buckets[i] != NULL) {
delete_hashbucket (&map->buckets[i]); delete_hashbucket(map->buckets[i]);
map->buckets[i] = NULL;
} }
} }
@@ -184,7 +182,8 @@ int hashmap_delete (hashmap_t map)
* negative number if there are errors * negative number if there are errors
*/ */
int int
hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len) hashmap_insert(hashmap_t map, const char *key,
const void *data, size_t len)
{ {
struct hashentry_s *ptr; struct hashentry_s *ptr;
int hash; int hash;
@@ -213,14 +212,18 @@ hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
if (!key_copy) if (!key_copy)
return -ENOMEM; return -ENOMEM;
if (data) {
data_copy = safemalloc(len); data_copy = safemalloc(len);
if (!data_copy) { if (!data_copy) {
safefree(key_copy); safefree(key_copy);
return -ENOMEM; return -ENOMEM;
} }
memcpy(data_copy, data, len); memcpy(data_copy, data, len);
} else {
data_copy = NULL;
}
ptr = (struct hashentry_s *) safemalloc (sizeof (struct hashentry_s)); ptr = safemalloc(sizeof(struct hashentry_s));
if (!ptr) { if (!ptr) {
safefree(key_copy); safefree(key_copy);
safefree(data_copy); safefree(data_copy);
@@ -232,16 +235,14 @@ hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
ptr->len = len; ptr->len = len;
/* /*
* Now add the entry to the end of the bucket chain. * Put the entry at the beginning of the chain. This is a constant
* time insert. Thanks to Justin Guyett for the code.
*/ */
ptr->next = NULL; ptr->prev = NULL;
ptr->prev = map->buckets[hash].tail; ptr->next = map->buckets[hash];
if (map->buckets[hash].tail) map->buckets[hash] = ptr;
map->buckets[hash].tail->next = ptr; if (ptr->next)
ptr->next->prev = ptr;
map->buckets[hash].tail = ptr;
if (!map->buckets[hash].head)
map->buckets[hash].head = ptr;
map->end_iterator++; map->end_iterator++;
return 0; return 0;
@@ -252,7 +253,8 @@ hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
* *
* Returns: an negative value upon error. * Returns: an negative value upon error.
*/ */
hashmap_iter hashmap_first (hashmap_t map) hashmap_iter
hashmap_first(hashmap_t map)
{ {
assert(map != NULL); assert(map != NULL);
@@ -271,7 +273,8 @@ hashmap_iter hashmap_first (hashmap_t map)
* Returns: 1 if it is the end * Returns: 1 if it is the end
* 0 otherwise * 0 otherwise
*/ */
int hashmap_is_end (hashmap_t map, hashmap_iter iter) int
hashmap_is_end(hashmap_t map, hashmap_iter iter)
{ {
assert(map != NULL); assert(map != NULL);
assert(iter >= 0); assert(iter >= 0);
@@ -293,7 +296,8 @@ int hashmap_is_end (hashmap_t map, hashmap_iter iter)
* an "iterator" pointing at the first key * an "iterator" pointing at the first key
* an "end-iterator" if the key wasn't found * an "end-iterator" if the key wasn't found
*/ */
hashmap_iter hashmap_find (hashmap_t map, const char *key) hashmap_iter
hashmap_find(hashmap_t map, const char* key)
{ {
unsigned int i; unsigned int i;
hashmap_iter iter = 0; hashmap_iter iter = 0;
@@ -310,7 +314,7 @@ hashmap_iter hashmap_find (hashmap_t map, const char *key)
* of a particular key. * of a particular key.
*/ */
for (i = 0; i != map->size; i++) { for (i = 0; i != map->size; i++) {
ptr = map->buckets[i].head; ptr = map->buckets[i];
while (ptr) { while (ptr) {
if (strcasecmp(ptr->key, key) == 0) { if (strcasecmp(ptr->key, key) == 0) {
@@ -333,7 +337,8 @@ hashmap_iter hashmap_find (hashmap_t map, const char *key)
* negative upon error * negative upon error
*/ */
ssize_t ssize_t
hashmap_return_entry (hashmap_t map, hashmap_iter iter, char **key, void **data) hashmap_return_entry(hashmap_t map, hashmap_iter iter,
char** key, void** data)
{ {
unsigned int i; unsigned int i;
struct hashentry_s* ptr; struct hashentry_s* ptr;
@@ -349,7 +354,7 @@ hashmap_return_entry (hashmap_t map, hashmap_iter iter, char **key, void **data)
return -EINVAL; return -EINVAL;
for (i = 0; i != map->size; i++) { for (i = 0; i != map->size; i++) {
ptr = map->buckets[i].head; ptr = map->buckets[i];
while (ptr) { while (ptr) {
if (count == iter) { if (count == iter) {
/* This is the data so return it */ /* This is the data so return it */
@@ -373,7 +378,8 @@ hashmap_return_entry (hashmap_t map, hashmap_iter iter, char **key, void **data)
* zero if no key is found * zero if no key is found
* count found * count found
*/ */
ssize_t hashmap_search (hashmap_t map, const char *key) ssize_t
hashmap_search(hashmap_t map, const char *key)
{ {
int hash; int hash;
struct hashentry_s* ptr; struct hashentry_s* ptr;
@@ -386,7 +392,7 @@ ssize_t hashmap_search (hashmap_t map, const char *key)
if (hash < 0) if (hash < 0)
return hash; return hash;
ptr = map->buckets[hash].head; ptr = map->buckets[hash];
/* All right, there is an entry here, now see if it's the one we want */ /* All right, there is an entry here, now see if it's the one we want */
while (ptr) { while (ptr) {
@@ -408,7 +414,8 @@ ssize_t hashmap_search (hashmap_t map, const char *key)
* zero if no entry is found * zero if no entry is found
* length of data for the entry * length of data for the entry
*/ */
ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, void **data) ssize_t
hashmap_entry_by_key(hashmap_t map, const char* key, void** data)
{ {
int hash; int hash;
struct hashentry_s* ptr; struct hashentry_s* ptr;
@@ -420,7 +427,7 @@ ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, void **data)
if (hash < 0) if (hash < 0)
return hash; return hash;
ptr = map->buckets[hash].head; ptr = map->buckets[hash];
while (ptr) { while (ptr) {
if (strcasecmp(ptr->key, key) == 0) { if (strcasecmp(ptr->key, key) == 0) {
@@ -442,10 +449,11 @@ ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, void **data)
* 0 if the key was not found * 0 if the key was not found
* positive count of entries deleted * positive count of entries deleted
*/ */
ssize_t hashmap_remove (hashmap_t map, const char *key) ssize_t
hashmap_remove(hashmap_t map, const char *key)
{ {
int hash; int hash;
struct hashentry_s *ptr, *next; struct hashentry_s* ptr;
short int deleted = 0; short int deleted = 0;
if (map == NULL || key == NULL) if (map == NULL || key == NULL)
@@ -455,24 +463,24 @@ ssize_t hashmap_remove (hashmap_t map, const char *key)
if (hash < 0) if (hash < 0)
return hash; return hash;
ptr = map->buckets[hash].head; ptr = map->buckets[hash];
while (ptr) { while (ptr) {
if (strcasecmp(ptr->key, key) == 0) { if (strcasecmp(ptr->key, key) == 0) {
/* /*
* Found the data, now need to remove everything * Found the data, now need to remove everything
* and update the hashmap. * and update the hashmap.
*/ */
next = ptr->next; struct hashentry_s* prevptr = ptr->prev;
if (prevptr != NULL) {
if (ptr->prev) prevptr->next = ptr->next;
ptr->prev->next = ptr->next;
if (ptr->next) if (ptr->next)
ptr->next->prev = ptr->prev; ptr->next->prev = prevptr;
} else {
if (map->buckets[hash].head == ptr) /* Entry was first in map */
map->buckets[hash].head = ptr->next; map->buckets[hash] = ptr->next;
if (map->buckets[hash].tail == ptr) if (ptr->next)
map->buckets[hash].tail = ptr->prev; ptr->next->prev = NULL;
}
safefree(ptr->key); safefree(ptr->key);
safefree(ptr->data); safefree(ptr->data);
@@ -481,7 +489,11 @@ ssize_t hashmap_remove (hashmap_t map, const char *key)
++deleted; ++deleted;
--map->end_iterator; --map->end_iterator;
ptr = next; if (prevptr)
ptr = prevptr;
else
ptr = map->buckets[hash];
continue; continue;
} }
+24 -9
View File
@@ -1,5 +1,14 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: hashmap.h,v 1.2 2002-04-25 18:55:56 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net> *
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
* key and the data in the hashmap itself, so you must free the original
* key and data to avoid a memory leak. The hashmap returns a pointer
* to the data when a key is searched for, so take care in modifying the
* data as it's modifying the data stored in the hashmap. (In other words,
* don't try to free the data, or realloc the memory. :)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -11,16 +20,19 @@
* 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
*/ */
/* See 'hashmap.c' for detailed information. */
#ifndef _HASHMAP_H #ifndef _HASHMAP_H
#define _HASHMAP_H #define _HASHMAP_H
/* Allow the use in C++ code. */
#if defined(__cplusplus)
extern "C" {
#endif
/* /*
* We're using a typedef here to "hide" the implementation details of the * We're using a typedef here to "hide" the implementation details of the
* hash map. Sure, it's a pointer, but the struct is hidden in the C file. * hash map. Sure, it's a pointer, but the struct is hidden in the C file.
@@ -92,8 +104,7 @@ extern ssize_t hashmap_return_entry (hashmap_t map, hashmap_iter iter,
* zero if no entry is found * zero if no entry is found
* length of data for the entry * length of data for the entry
*/ */
extern ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, extern ssize_t hashmap_entry_by_key(hashmap_t map, const char* key, void** data);
void **data);
/* /*
* Searches for _any_ occurrances of "key" within the hashmap and returns the * Searches for _any_ occurrances of "key" within the hashmap and returns the
@@ -115,4 +126,8 @@ extern ssize_t hashmap_search (hashmap_t map, const char *key);
*/ */
extern ssize_t hashmap_remove(hashmap_t map, const char *key); extern ssize_t hashmap_remove(hashmap_t map, const char *key);
#if defined(__cplusplus)
}
#endif /* C++ */
#endif /* _HASHMAP_H */ #endif /* _HASHMAP_H */
+42 -41
View File
@@ -1,35 +1,30 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: heap.c,v 1.6.2.1 2003-08-06 20:44:09 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * Debugging versions of various heap related functions are combined
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* Debugging versions of various heap related functions are combined
* here. The debugging versions include assertions and also print * here. The debugging versions include assertions and also print
* (to standard error) the function called along with the amount * (to standard error) the function called along with the amount
* of memory allocated, and where the memory is pointing. The * of memory allocated, and where the memory is pointing. The
* format of the log message is standardized. * format of the log message is standardized.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "heap.h" #include "heap.h"
#include "text.h" #include "text.h"
#ifndef NDEBUG void *
debugging_calloc(size_t nmemb, size_t size, const char *file,
void *debugging_calloc (size_t nmemb, size_t size, const char *file,
unsigned long line) unsigned long line)
{ {
void *ptr; void *ptr;
@@ -38,36 +33,39 @@ void *debugging_calloc (size_t nmemb, size_t size, const char *file,
assert(size > 0); assert(size > 0);
ptr = calloc(nmemb, size); ptr = calloc(nmemb, size);
fprintf (stderr, "{calloc: %p:%zu x %zu} %s:%lu\n", ptr, nmemb, size, fprintf(stderr, "{calloc: %p:%zu x %zu} %s:%lu\n",
file, line); ptr, nmemb, size, file, line);
return ptr; return ptr;
} }
void *debugging_malloc (size_t size, const char *file, unsigned long line) void *
debugging_malloc(size_t size, const char *file, unsigned long line)
{ {
void *ptr; void *ptr;
assert(size > 0); assert(size > 0);
ptr = malloc(size); ptr = malloc(size);
fprintf (stderr, "{malloc: %p:%zu} %s:%lu\n", ptr, size, file, line); fprintf(stderr, "{malloc: %p:%zu} %s:%lu\n",
ptr, size, file, line);
return ptr; return ptr;
} }
void *debugging_realloc (void *ptr, size_t size, const char *file, void *
unsigned long line) debugging_realloc(void *ptr, size_t size, const char *file, unsigned long line)
{ {
void *newptr; void *newptr;
assert(size > 0); assert(size > 0);
newptr = realloc(ptr, size); newptr = realloc(ptr, size);
fprintf (stderr, "{realloc: %p -> %p:%zu} %s:%lu\n", ptr, newptr, size, fprintf(stderr, "{realloc: %p -> %p:%zu} %s:%lu\n",
file, line); ptr, newptr, size, file, line);
return newptr; return newptr;
} }
void debugging_free (void *ptr, const char *file, unsigned long line) void
debugging_free(void *ptr, const char *file, unsigned long line)
{ {
fprintf(stderr, "{free: %p} %s:%lu\n", ptr, file, line); fprintf(stderr, "{free: %p} %s:%lu\n", ptr, file, line);
@@ -76,7 +74,8 @@ void debugging_free (void *ptr, const char *file, unsigned long line)
return; return;
} }
char *debugging_strdup (const char *s, const char *file, unsigned long line) char*
debugging_strdup(const char *s, const char *file, unsigned long line)
{ {
char* ptr; char* ptr;
size_t len; size_t len;
@@ -84,17 +83,16 @@ char *debugging_strdup (const char *s, const char *file, unsigned long line)
assert(s != NULL); assert(s != NULL);
len = strlen(s) + 1; len = strlen(s) + 1;
ptr = (char *) malloc (len); ptr = malloc(len);
if (!ptr) if (!ptr)
return NULL; return NULL;
memcpy(ptr, s, len); memcpy(ptr, s, len);
fprintf (stderr, "{strdup: %p:%zu} %s:%lu\n", ptr, len, file, line); fprintf(stderr, "{strdup: %p:%zu} %s:%lu\n",
ptr, len, file, line);
return ptr; return ptr;
} }
#endif /* !NDEBUG */
/* /*
* Allocate a block of memory in the "shared" memory region. * Allocate a block of memory in the "shared" memory region.
* *
@@ -103,13 +101,14 @@ char *debugging_strdup (const char *s, const char *file, unsigned long line)
* want to look into something like MM (Shared Memory Library) for a better * want to look into something like MM (Shared Memory Library) for a better
* solution. * solution.
*/ */
void *malloc_shared_memory (size_t size) void*
malloc_shared_memory(size_t size)
{ {
int fd; int fd;
void* ptr; void* ptr;
char buffer[32]; char buffer[32];
static const char *shared_file = "/tmp/tinyproxy.shared.XXXXXX"; static char* shared_file = "/tmp/tinyproxy.shared.XXXXXX";
assert(size > 0); assert(size > 0);
@@ -121,11 +120,11 @@ void *malloc_shared_memory (size_t size)
umask(0177); umask(0177);
if ((fd = mkstemp(buffer)) == -1) if ((fd = mkstemp(buffer)) == -1)
return MAP_FAILED; return (void *)MAP_FAILED;
unlink(buffer); unlink(buffer);
if (ftruncate(fd, size) == -1) if (ftruncate(fd, size) == -1)
return MAP_FAILED; return (void *)MAP_FAILED;
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
return ptr; return ptr;
@@ -135,7 +134,8 @@ void *malloc_shared_memory (size_t size)
* Allocate a block of memory from the "shared" region an initialize it to * Allocate a block of memory from the "shared" region an initialize it to
* zero. * zero.
*/ */
void *calloc_shared_memory (size_t nmemb, size_t size) void*
calloc_shared_memory(size_t nmemb, size_t size)
{ {
void* ptr; void* ptr;
long length; long length;
@@ -153,3 +153,4 @@ void *calloc_shared_memory (size_t nmemb, size_t size)
return ptr; return ptr;
} }
+22 -20
View File
@@ -1,23 +1,20 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: heap.h,v 1.3 2003-05-31 23:04:15 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * See 'heap.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) 2002 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 'heap.c' for detailed information. */
#ifndef TINYPROXY_HEAP_H #ifndef TINYPROXY_HEAP_H
#define TINYPROXY_HEAP_H #define TINYPROXY_HEAP_H
@@ -40,16 +37,21 @@ extern char *debugging_strdup (const char *s, const char *file,
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__) # define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__) # define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
# define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__) # define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
# define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL) # define safefree(x) do { \
void **__safefree_tmp = (void *)&(x); \
debugging_free(*__safefree_tmp, __FILE__, __LINE__); \
*__safefree_tmp = NULL; \
} while (0)
#else #else
# define safecalloc(x, y) calloc(x, y) # define safecalloc(x, y) calloc(x, y)
# define safemalloc(x) malloc(x) # define safemalloc(x) malloc(x)
# define saferealloc(x, y) realloc(x, y) # define saferealloc(x, y) realloc(x, y)
# define safefree(x) (free (x), *(&(x)) = NULL) # define safefree(x) do { \
void **__safefree_tmp = (void *)&(x); \
free(*__safefree_tmp); \
*__safefree_tmp = NULL; \
} while (0)
# define safestrdup(x) strdup(x) # define safestrdup(x) strdup(x)
#endif #endif
/* /*
-309
View File
@@ -1,309 +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"
/*
* 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);
}
#define HTML_BUFSIZE 4096
/*
* Send an already-opened file to the client with variable substitution.
*/
int send_html_file (FILE * infile, struct conn_s *connptr)
{
char inbuf[HTML_BUFSIZE], *varstart = NULL, *p;
const char *varval;
int in_variable = 0, writeret;
while (fgets (inbuf, HTML_BUFSIZE, 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)";
writeret =
write_message (connptr->client_fd,
"%s", varval);
if (writeret)
return (writeret);
in_variable = 0;
} else {
writeret =
write_message (connptr->client_fd,
"%c", *p);
if (writeret)
return (writeret);
}
break;
case '{':
/* a {{ will print a single {. If we are NOT
* already in a { variable, then proceed with
* 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) {
writeret =
write_message (connptr->client_fd,
"%c", *p);
if (writeret)
return (writeret);
}
}
}
in_variable = 0;
}
return (0);
}
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",
"http://www.banu.com/tinyproxy/");
add_error_variable (connptr, "version", VERSION);
add_error_variable (connptr, "package", PACKAGE);
return (0);
}
/*
* Add the error information to the conn structure.
*/
int
indicate_http_error (struct conn_s *connptr, int number,
const char *message, ...)
{
va_list ap;
char *key, *val;
va_start (ap, message);
while ((key = va_arg (ap, char *))) {
val = va_arg (ap, char *);
if (add_error_variable (connptr, key, val) == -1) {
va_end (ap);
return (-1);
}
}
connptr->error_number = number;
connptr->error_string = safestrdup (message);
va_end (ap);
return (add_standard_vars (connptr));
}
-38
View File
@@ -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 */
+275
View File
@@ -0,0 +1,275 @@
/* $Id: htmlerror.c,v 1.6 2003-07-14 17:42:43 rjkaes Exp $
*
* This file contains source code for the handling and display of
* HTML error pages with variable substitution.
*
* Copyright (C) 2003 Steven Young <sdyoung@well.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 "common.h"
#include "buffer.h"
#include "conns.h"
#include "heap.h"
#include "htmlerror.h"
#include "network.h"
#include "utils.h"
/*
* Add an error number -> filename mapping to the errorpages list.
*/
int
add_new_errorpage(char *filepath, unsigned int errornum) {
static int errorpage_count = 1;
/* First, add space for another pointer to the errorpages array. */
config.errorpages = saferealloc(config.errorpages, sizeof(struct error_pages_s *) * (errorpage_count + 1));
if(!config.errorpages)
return(-1);
/* Allocate space for an actual structure */
config.errorpages[errorpage_count - 1] = safemalloc(sizeof(struct error_pages_s));
if(!config.errorpages[errorpage_count - 1])
return(-1);
/* Set values for errorpage structure. */
config.errorpages[errorpage_count - 1]->errorpage_path = safestrdup(filepath);
if(!config.errorpages[errorpage_count - 1]->errorpage_path)
return(-1);
config.errorpages[errorpage_count - 1]->errorpage_errnum = errornum;
/* Set NULL to denote end of array */
config.errorpages[errorpage_count] = NULL;
errorpage_count++;
return(0);
}
/*
* Get the file appropriate for a given error.
*/
static char*
get_html_file(int errornum) {
int i;
if (!config.errorpages) return(config.errorpage_undef);
for (i = 0; config.errorpages[i]; i++) {
if (config.errorpages[i]->errorpage_errnum == errornum)
return config.errorpages[i]->errorpage_path;
}
return(config.errorpage_undef);
}
/*
* Look up the value for a variable.
*/
static char*
lookup_variable(struct conn_s *connptr, char *varname) {
int i;
for (i = 0; i != connptr->error_variable_count; i++) {
if (!strcasecmp(connptr->error_variables[i]->error_key, varname))
return connptr->error_variables[i]->error_val;
}
return(NULL);
}
#define HTML_BUFSIZE 4096
/*
* Send an already-opened file to the client with variable substitution.
*/
int
send_html_file(FILE *infile, struct conn_s *connptr) {
char inbuf[HTML_BUFSIZE], *varstart = NULL, *p;
char *varval;
int in_variable = 0, writeret;
while(fgets(inbuf, HTML_BUFSIZE, infile) != NULL) {
for (p = inbuf; *p; p++) {
switch(*p) {
case '}':
if(in_variable) {
*p = '\0';
if(!(varval = lookup_variable(connptr, varstart)))
varval = "(unknown)";
writeret = write_message(connptr->client_fd, "%s",
varval);
if(writeret) return(writeret);
in_variable = 0;
} else {
writeret = write_message(connptr->client_fd, "%c", *p);
if (writeret) return(writeret);
}
break;
case '{':
/* a {{ will print a single {. If we are NOT
* already in a { variable, then proceed with
* 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) {
writeret = write_message(connptr->client_fd, "%c",
*p);
if(writeret) return(writeret);
}
}
}
in_variable = 0;
}
return(0);
}
int
send_http_headers(struct conn_s *connptr, int code, char *message) {
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;
char *fallback_error = \
"<html><head><title>%s</title></head>" \
"<body><blockquote><i>%s %s</i><br>" \
"The page you requested was unavailable. The error code is listed " \
"below. In addition, the HTML file which has been configured as the " \
"page to be displayed when an error of this type was unavailable, " \
"with the error code %d (%s). Please contact your administrator." \
"<center>%s</center>" \
"</body></html>" \
"\r\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")))
return(write_message(connptr->client_fd, fallback_error,
connptr->error_string,
PACKAGE, VERSION,
errno, strerror(errno),
connptr->error_string));
ret = send_html_file(infile, connptr);
fclose(infile);
return(ret);
}
/*
* Add a key -> value mapping for HTML file substitution.
*/
int
add_error_variable(struct conn_s *connptr, char *key, char *val)
{
connptr->error_variable_count++;
/* Add space for a new pointer to the error_variables structure. */
if (!connptr->error_variables)
connptr->error_variables = safemalloc(sizeof(struct error_variables_s *) * connptr->error_variable_count);
else
connptr->error_variables = saferealloc(connptr->error_variables, sizeof(struct error_variable_s *) * connptr->error_variable_count);
if(!connptr->error_variables)
return(-1);
/* Allocate a new variable mapping structure. */
connptr->error_variables[connptr->error_variable_count - 1] = safemalloc(sizeof(struct error_variable_s));
if(!connptr->error_variables[connptr->error_variable_count - 1])
return(-1);
/* Set values for variable mapping. */
connptr->error_variables[connptr->error_variable_count - 1]->error_key = safestrdup(key);
connptr->error_variables[connptr->error_variable_count - 1]->error_val = safestrdup(val);
if((!connptr->error_variables[connptr->error_variable_count - 1]->error_key)
|| (!connptr->error_variables[connptr->error_variable_count - 1]->error_val))
return(-1);
return(0);
}
#define ADD_VAR_RET(x, y) if(y) { if(add_error_variable(connptr, x, y) == -1) return(-1); }
/*
* Set some standard variables used by all HTML pages
*/
int
add_standard_vars(struct conn_s *connptr) {
char timebuf[30];
time_t global_time = time(NULL);
strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT",
gmtime(&global_time));
ADD_VAR_RET("request", connptr->request_line);
ADD_VAR_RET("cause", connptr->error_string);
ADD_VAR_RET("clientip", connptr->client_ip_addr);
ADD_VAR_RET("clienthost", connptr->client_string_addr);
ADD_VAR_RET("version", VERSION);
ADD_VAR_RET("package", PACKAGE);
ADD_VAR_RET("date", timebuf);
return(0);
}
/*
* Add the error information to the conn structure.
*/
int
indicate_http_error(struct conn_s* connptr, int number, 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));
}
+33
View File
@@ -0,0 +1,33 @@
/* $Id: htmlerror.h,v 1.2 2003-03-14 22:45:59 rjkaes Exp $
*
* Contains header declarations for the HTML error functions in
* htmlerror.c
*
* Copyright (C) 2003 Steven Young <sdyoung@well.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_HTMLERROR_H
#define TINYPROXY_HTMLERROR_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, char *message, ...);
extern int add_error_variable(struct conn_s *connptr, char *key, char *val);
extern int send_html_file(FILE *infile, struct conn_s *connptr);
extern int send_http_headers(struct conn_s *connptr, int code, char *message);
extern int add_standard_vars(struct conn_s *connptr);
#endif /* !TINYPROXY_HTMLERROR_H */
-271
View File
@@ -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;
}
+252
View File
@@ -0,0 +1,252 @@
/* $Id: http_message.c,v 1.2 2003-05-31 23:02:21 rjkaes Exp $
*
* See 'http_message.h' for a detailed description.
*
* Copyright (C) 2003 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 "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 {
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 = safecalloc(1, sizeof(struct http_message_s));
if (msg == NULL)
return NULL;
msg->headers.strings = 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, char** headers,
int num_headers)
{
char** new_headers;
int i;
/* Check for valid arguments */
if (msg == NULL) return -EFAULT;
if (headers == NULL) return -EINVAL;
if (num_headers < 1) 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 = 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;
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;
}
+16 -20
View File
@@ -1,22 +1,6 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: http_message.h,v 1.1 2003-03-13 05:25:30 rjkaes Exp $
* Copyright (C) 2003 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * HTTP Message API
* 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 * The idea behind this application programming interface (API) is to
* represent an HTTP response message as a concrete entity. The API * represent an HTTP response message as a concrete entity. The API
@@ -42,6 +26,18 @@
* http_message_t out of the calling function since the stack * http_message_t out of the calling function since the stack
* allocated memory referenced by the http_message_t will no long * allocated memory referenced by the http_message_t will no long
* exist.) * exist.)
*
* Copyright (C) 2003 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_HTTP_MESSAGE_H_ #ifndef _TINYPROXY_HTTP_MESSAGE_H_
@@ -88,7 +84,7 @@ extern int http_message_set_response (http_message_t msg,
* sent. * sent.
*/ */
extern int http_message_add_headers(http_message_t msg, extern int http_message_add_headers(http_message_t msg,
const char **headers, char** headers,
unsigned int num_headers); int num_headers);
#endif /* _TINYPROXY_HTTP_MESSAGE_H_ */ #endif /* _TINYPROXY_HTTP_MESSAGE_H_ */
+50 -65
View File
@@ -1,34 +1,30 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: log.c,v 1.26 2003-05-31 23:02:21 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 * 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 "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "utils.h" #include "utils.h"
#include "vector.h" #include "vector.h"
static const char *syslog_level[] = { static char *syslog_level[] = {
NULL, NULL,
NULL, NULL,
"CRITICAL", "CRITICAL",
@@ -64,7 +60,8 @@ static vector_t log_message_storage;
/* /*
* Open the log file and store the file descriptor in a global location. * Open the log file and store the file descriptor in a global location.
*/ */
int open_log_file (const char *log_file_name) int
open_log_file(const char* log_file_name)
{ {
log_file_fd = create_file_safely(log_file_name, FALSE); log_file_fd = create_file_safely(log_file_name, FALSE);
return log_file_fd; return log_file_fd;
@@ -73,7 +70,8 @@ int open_log_file (const char *log_file_name)
/* /*
* Close the log file * Close the log file
*/ */
void close_log_file (void) void
close_log_file(void)
{ {
close(log_file_fd); close(log_file_fd);
} }
@@ -81,19 +79,18 @@ void close_log_file (void)
/* /*
* Truncate log file to a zero length. * Truncate log file to a zero length.
*/ */
void truncate_log_file (void) void
truncate_log_file(void)
{ {
lseek(log_file_fd, 0, SEEK_SET); lseek(log_file_fd, 0, SEEK_SET);
if (ftruncate (log_file_fd, 0) != 0) { ftruncate(log_file_fd, 0);
log_message (LOG_WARNING,
"Unable to truncate log file to zero length");
}
} }
/* /*
* 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(int level)
{ {
log_level = level; log_level = level;
} }
@@ -101,7 +98,8 @@ void set_log_level (int level)
/* /*
* This routine logs messages to either the log file or the syslog function. * This routine logs messages to either the log file or the syslog function.
*/ */
void log_message (int level, const char *fmt, ...) void
log_message(int level, char *fmt, ...)
{ {
va_list args; va_list args;
time_t nowtime; time_t nowtime;
@@ -109,8 +107,6 @@ void log_message (int level, const char *fmt, ...)
char time_string[TIME_LENGTH]; char time_string[TIME_LENGTH];
char str[STRING_LENGTH]; char str[STRING_LENGTH];
ssize_t ret;
#ifdef NDEBUG #ifdef NDEBUG
/* /*
* Figure out if we should write the message or not. * Figure out if we should write the message or not.
@@ -141,23 +137,30 @@ void log_message (int level, const char *fmt, ...)
if (!log_message_storage) { if (!log_message_storage) {
log_message_storage = vector_create(); log_message_storage = vector_create();
if (!log_message_storage) if (!log_message_storage) {
goto out; va_end(args);
return;
}
} }
vsnprintf(str, STRING_LENGTH, fmt, args); vsnprintf(str, STRING_LENGTH, fmt, args);
entry_buffer = (char *) safemalloc (strlen (str) + 6); entry_buffer = safemalloc(strlen(str) + 6);
if (!entry_buffer) if (!entry_buffer) {
goto out; va_end(args);
return;
}
sprintf(entry_buffer, "%d %s", level, str); sprintf(entry_buffer, "%d %s", level, str);
vector_append(log_message_storage, entry_buffer, vector_append(log_message_storage, entry_buffer,
strlen(entry_buffer) + 1); strlen(entry_buffer) + 1);
safefree(entry_buffer); safefree(entry_buffer);
goto out; va_end(args);
return;
} }
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
if (config.syslog) { if (config.syslog) {
# ifdef HAVE_VSYSLOG_H # ifdef HAVE_VSYSLOG_H
@@ -173,45 +176,28 @@ void log_message (int level, const char *fmt, ...)
strftime(time_string, TIME_LENGTH, "%b %d %H:%M:%S", strftime(time_string, TIME_LENGTH, "%b %d %H:%M:%S",
localtime(&nowtime)); localtime(&nowtime));
snprintf (str, STRING_LENGTH, "%-9s %s [%ld]: ", snprintf(str, STRING_LENGTH, "%-9s %s [%ld]: ", syslog_level[level],
syslog_level[level], time_string, time_string, (long int) getpid());
(long int) getpid ());
assert(log_file_fd >= 0); assert(log_file_fd >= 0);
ret = write (log_file_fd, str, strlen (str)); write(log_file_fd, str, strlen(str));
if (ret == -1) {
log_message (LOG_WARNING,
"Could not write to log file");
}
vsnprintf(str, STRING_LENGTH, fmt, args); vsnprintf(str, STRING_LENGTH, fmt, args);
ret = write (log_file_fd, str, strlen (str)); write(log_file_fd, str, strlen(str));
if (ret == -1) { write(log_file_fd, "\n", 1);
log_message (LOG_WARNING,
"Could not write to log file");
}
ret = write (log_file_fd, "\n", 1);
if (ret == -1) {
log_message (LOG_WARNING,
"Could not write to log file");
}
fsync (log_file_fd);
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
} }
#endif #endif
out:
va_end(args); va_end(args);
} }
/* /*
* This needs to send any stored log messages. * This needs to send any stored log messages.
*/ */
void send_stored_logs (void) void
send_stored_logs(void)
{ {
char *string; char *string;
char *ptr; char *ptr;
@@ -220,14 +206,13 @@ void send_stored_logs (void)
size_t i; size_t i;
for (i = 0; (ssize_t) i != vector_length (log_message_storage); ++i) { for (i = 0; i != vector_length(log_message_storage); ++i) {
string = string = vector_getentry(log_message_storage, i, NULL);
(char *) vector_getentry (log_message_storage, i, NULL);
ptr = strchr(string, ' ') + 1; ptr = strchr(string, ' ') + 1;
level = atoi(string); level = atoi(string);
#ifdef NDEBUG #if NDEBUG
if (log_level == LOG_CONN && level == LOG_INFO) if (log_level == LOG_CONN && level == LOG_INFO)
continue; continue;
else if (log_level == LOG_INFO) { else if (log_level == LOG_INFO) {
+16 -26
View File
@@ -1,24 +1,21 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: log.h,v 1.11 2002-10-03 20:49:57 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 '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
@@ -89,21 +86,14 @@
#define LOG_CONN 8 /* extra to log connections without the INFO stuff */ #define LOG_CONN 8 /* extra to log connections without the INFO stuff */
/* Suppress warnings when GCC is in -pedantic mode and not -std=c99 */
#if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
#pragma GCC system_header
#endif
/* /*
* Use this for debugging. The format is specific: * Use this for debugging. The format is specific:
* DEBUG1("There was a major problem"); * DEBUG1("There was a major problem");
* DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr); * DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr);
*/ */
#ifndef NDEBUG #ifndef NDEBUG
# define DEBUG1(x) \ # 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)
@@ -113,7 +103,7 @@ extern int open_log_file (const char *file);
extern void close_log_file(void); extern void close_log_file(void);
extern void truncate_log_file(void); extern void truncate_log_file(void);
extern void log_message (int level, const char *fmt, ...); extern void log_message(int level, char *fmt, ...);
extern void set_log_level(int level); extern void set_log_level(int level);
extern void send_stored_logs(void); extern void send_stored_logs(void);
-492
View File
@@ -1,492 +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>
*
* 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;
unsigned int received_sighup = FALSE; /* boolean */
unsigned int processed_config_file = 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\
\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 */
if (0 == features)
printf (" None\n");
printf ("\n"
"For bug reporting instructions, please see:\n"
"<https://www.banu.com/tinyproxy/support/>.\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)
{
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':
config.godaemon = FALSE;
break;
case 'c':
config.config_file = safestrdup (optarg);
if (!config.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);
}
}
int
main (int argc, char **argv)
{
FILE *config_file;
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask (0177);
config.config_file = SYSCONFDIR "/tinyproxy.conf";
config.godaemon = TRUE;
process_cmdline (argc, argv);
log_message (LOG_INFO, "Initializing " PACKAGE " ...");
/*
* Make sure the HTML error pages array is NULL to begin with.
* (FIXME: Should have a better API for all this)
*/
config.errorpages = NULL;
/* Read in the settings from the config file */
config_file = fopen (config.config_file, "r");
if (!config_file) {
fprintf (stderr,
"%s: Could not open config file \"%s\".\n",
argv[0], config.config_file);
exit (EX_SOFTWARE);
}
if (config_compile () || config_parse (&config, config_file)) {
fprintf (stderr, "Unable to parse config file. "
"Not starting.\n");
exit (EX_SOFTWARE);
}
fclose (config_file);
/* Write to a user supplied log file if it's defined. This will
* override using the syslog even if syslog is defined. */
if (config.logf_name) {
if (open_log_file (config.logf_name) < 0) {
fprintf (stderr,
"%s: Could not create log file.\n", argv[0]);
exit (EX_SOFTWARE);
}
config.syslog = FALSE; /* disable syslog */
} else if (config.syslog) {
if (config.godaemon == TRUE)
openlog ("tinyproxy", LOG_PID, LOG_DAEMON);
else
openlog ("tinyproxy", LOG_PID, LOG_USER);
} else {
fprintf (stderr, "%s: Either define a logfile or "
"enable syslog logging.\n", argv[0]);
exit (EX_SOFTWARE);
}
processed_config_file = TRUE;
send_stored_logs ();
/* Set the default values if they were not set in the config
* file. */
if (config.port == 0) {
fprintf (stderr, "%s: You MUST set a Port in the "
"config file.\n", argv[0]);
exit (EX_SOFTWARE);
}
if (!config.stathost) {
log_message (LOG_INFO, "Setting stathost to \"%s\".",
TINYPROXY_STATHOST);
config.stathost = strdup (TINYPROXY_STATHOST);
}
if (!config.user) {
log_message (LOG_WARNING, "You SHOULD set a UserName in the "
"config file. Using current user instead.");
}
if (config.idletimeout == 0) {
log_message (LOG_WARNING, "Invalid idle time setting. "
"Only values greater than zero are allowed. "
"Therefore setting idle timeout to %u seconds.",
MAX_IDLE_TIME);
config.idletimeout = MAX_IDLE_TIME;
}
init_stats ();
/* 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 (config.pidpath) {
if (pidfile_create (config.pidpath) < 0) {
fprintf (stderr, "%s: Could not create PID file.\n",
argv[0]);
exit (EX_OSERR);
}
}
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
argv[0]);
exit (EX_OSERR);
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_init ();
#endif /* FILTER_ENABLE */
/* Start listening on the selected port. */
if (child_listening_sock (config.port) < 0) {
fprintf (stderr, "%s: Could not create listening socket.\n",
argv[0]);
exit (EX_OSERR);
}
/* Switch to a different user if we're running as root */
if (geteuid () == 0)
change_user (argv[0]);
else
log_message (LOG_WARNING,
"Not running as root, so not changing UID/GID.");
if (child_pool_create () < 0) {
fprintf (stderr,
"%s: Could not create the pool of children.\n",
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 ();
child_close_sock ();
/* Remove the PID file */
if (unlink (config.pidpath) < 0) {
log_message (LOG_WARNING,
"Could not remove PID file \"%s\": %s.",
config.pidpath, strerror (errno));
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy ();
#endif /* FILTER_ENABLE */
if (config.syslog)
closelog ();
else
close_log_file ();
return EXIT_SUCCESS;
}
-108
View File
@@ -1,108 +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"
#include "hashmap.h"
/* Global variables for the main controls of the program */
#define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
/*
* Even if upstream support is not compiled into tinyproxy, this
* structure still needs to be defined.
*/
struct upstream {
struct upstream *next;
char *domain; /* optional */
char *host;
int port;
in_addr_t ip, mask;
};
/*
* Hold all the configuration time information.
*/
struct config_s {
char *logf_name;
const char *config_file;
unsigned int syslog; /* boolean */
int port;
char *stathost;
unsigned int godaemon; /* boolean */
unsigned int quit; /* boolean */
char *user;
char *group;
char *ipAddr;
#ifdef FILTER_ENABLE
char *filter;
unsigned int filter_url; /* boolean */
unsigned int filter_extended; /* boolean */
unsigned int filter_casesensitive; /* boolean */
#endif /* FILTER_ENABLE */
#ifdef XTINYPROXY_ENABLE
unsigned int add_xtinyproxy; /* boolean */
#endif
#ifdef REVERSE_SUPPORT
struct reversepath *reversepath_list;
unsigned int reverseonly; /* boolean */
unsigned int reversemagic; /* boolean */
char *reversebaseurl;
#endif
#ifdef UPSTREAM_SUPPORT
struct upstream *upstream_list;
#endif /* UPSTREAM_SUPPORT */
char *pidpath;
unsigned int idletimeout;
char *bind_address;
unsigned int bindsame;
/*
* The configured name to use in the HTTP "Via" header field.
*/
char *via_proxy_name;
/*
* Error page support. Map error numbers to file paths.
*/
hashmap_t errorpages;
/*
* Error page to be displayed if appropriate page cannot be located
* in the errorpages structure.
*/
char *errorpage_undef;
/*
* The HTML statistics page.
*/
char *statpage;
};
/* Global Structures used in the program */
extern struct config_s config;
extern unsigned int received_sighup; /* boolean */
extern unsigned int processed_config_file; /* boolean */
#endif /* __MAIN_H__ */
+32 -117
View File
@@ -1,29 +1,25 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: network.c,v 1.1 2002-05-23 04:41:48 rjkaes Exp $
* Copyright (C) 2002, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * The functions found here are used for communicating across a
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* The functions found here are used for communicating across a
* network. They include both safe reading and writing (which are * network. They include both safe reading and writing (which are
* the basic building blocks) along with two functions for * the basic building blocks) along with two functions for
* easily reading a line of text from the network, and a function * easily reading a line of text from the network, and a function
* to write an arbitrary amount of data to the network. * to write an arbitrary amount of data to the network.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "heap.h" #include "heap.h"
#include "network.h" #include "network.h"
@@ -32,7 +28,8 @@
* Write the buffer to the socket. If an EINTR occurs, pick up and try * Write the buffer to the socket. If an EINTR occurs, pick up and try
* again. Keep sending until the buffer has been sent. * again. Keep sending until the buffer has been sent.
*/ */
ssize_t safe_write (int fd, const char *buffer, size_t count) ssize_t
safe_write(int fd, const char *buffer, size_t count)
{ {
ssize_t len; ssize_t len;
size_t bytestosend; size_t bytestosend;
@@ -53,7 +50,7 @@ ssize_t safe_write (int fd, const char *buffer, size_t count)
return -errno; return -errno;
} }
if ((size_t) len == bytestosend) if (len == bytestosend)
break; break;
buffer += len; buffer += len;
@@ -67,7 +64,8 @@ ssize_t safe_write (int fd, const char *buffer, size_t count)
* Matched pair for safe_write(). If an EINTR occurs, pick up and try * Matched pair for safe_write(). If an EINTR occurs, pick up and try
* again. * again.
*/ */
ssize_t safe_read (int fd, char *buffer, size_t count) ssize_t
safe_read(int fd, char *buffer, size_t count)
{ {
ssize_t len; ssize_t len;
@@ -84,14 +82,15 @@ ssize_t safe_read (int fd, char *buffer, size_t count)
* was basically stolen from the snprintf() man page of Debian Linux * was basically stolen from the snprintf() man page of Debian Linux
* (although I did fix a memory leak. :) * (although I did fix a memory leak. :)
*/ */
int write_message (int fd, const char *fmt, ...) int
write_message(int fd, const char *fmt, ...)
{ {
ssize_t n; ssize_t n;
size_t size = (1024 * 8); /* start with 8 KB and go from there */ size_t size = (1024 * 8); /* start with 8 KB and go from there */
char *buf, *tmpbuf; char *buf, *tmpbuf;
va_list ap; va_list ap;
if ((buf = (char *) safemalloc (size)) == NULL) if ((buf = safemalloc(size)) == NULL)
return -1; return -1;
while (1) { while (1) {
@@ -100,7 +99,7 @@ int write_message (int fd, const char *fmt, ...)
va_end(ap); va_end(ap);
/* If that worked, break out so we can send the buffer */ /* If that worked, break out so we can send the buffer */
if (n > -1 && (size_t) n < size) if (n > -1 && n < size)
break; break;
/* Else, try again with more space */ /* Else, try again with more space */
@@ -111,7 +110,7 @@ int write_message (int fd, const char *fmt, ...)
/* twice the old size (glibc2.0) */ /* twice the old size (glibc2.0) */
size *= 2; size *= 2;
if ((tmpbuf = (char *) saferealloc (buf, size)) == NULL) { if ((tmpbuf = saferealloc(buf, size)) == NULL) {
safefree(buf); safefree(buf);
return -1; return -1;
} else } else
@@ -138,7 +137,8 @@ int write_message (int fd, const char *fmt, ...)
*/ */
#define SEGMENT_LEN (512) #define SEGMENT_LEN (512)
#define MAXIMUM_BUFFER_LENGTH (128 * 1024) #define MAXIMUM_BUFFER_LENGTH (128 * 1024)
ssize_t readline (int fd, char **whole_buffer) ssize_t
readline(int fd, char **whole_buffer)
{ {
ssize_t whole_buffer_len; ssize_t whole_buffer_len;
char buffer[SEGMENT_LEN]; char buffer[SEGMENT_LEN];
@@ -154,9 +154,7 @@ ssize_t readline (int fd, char **whole_buffer)
}; };
struct read_lines_s *first_line, *line_ptr; struct read_lines_s *first_line, *line_ptr;
first_line = first_line = safecalloc(sizeof(struct read_lines_s), 1);
(struct read_lines_s *) safecalloc (sizeof (struct read_lines_s),
1);
if (!first_line) if (!first_line)
return -ENOMEM; return -ENOMEM;
@@ -168,7 +166,7 @@ ssize_t readline (int fd, char **whole_buffer)
if (ret <= 0) if (ret <= 0)
goto CLEANUP; goto CLEANUP;
ptr = (char *) memchr (buffer, '\n', ret); ptr = memchr(buffer, '\n', ret);
if (ptr) if (ptr)
diff = ptr - buffer + 1; diff = ptr - buffer + 1;
else else
@@ -185,7 +183,7 @@ ssize_t readline (int fd, char **whole_buffer)
goto CLEANUP; goto CLEANUP;
} }
line_ptr->data = (char *) safemalloc (diff); line_ptr->data = safemalloc(diff);
if (!line_ptr->data) { if (!line_ptr->data) {
ret = -ENOMEM; ret = -ENOMEM;
goto CLEANUP; goto CLEANUP;
@@ -199,9 +197,7 @@ ssize_t readline (int fd, char **whole_buffer)
break; break;
} }
line_ptr->next = line_ptr->next = safecalloc(sizeof(struct read_lines_s), 1);
(struct read_lines_s *)
safecalloc (sizeof (struct read_lines_s), 1);
if (!line_ptr->next) { if (!line_ptr->next) {
ret = -ENOMEM; ret = -ENOMEM;
goto CLEANUP; goto CLEANUP;
@@ -209,7 +205,7 @@ ssize_t readline (int fd, char **whole_buffer)
line_ptr = line_ptr->next; line_ptr = line_ptr->next;
} }
*whole_buffer = (char *) safemalloc (whole_buffer_len + 1); *whole_buffer = safemalloc(whole_buffer_len + 1);
if (!*whole_buffer) { if (!*whole_buffer) {
ret = -ENOMEM; ret = -ENOMEM;
goto CLEANUP; goto CLEANUP;
@@ -240,84 +236,3 @@ CLEANUP:
return ret; return ret;
} }
/*
* Convert the network address into either a dotted-decimal or an IPv6
* hex string.
*/
char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{
assert (sa != NULL);
assert (buf != NULL);
assert (buflen != 0);
buf[0] = '\0'; /* start with an empty string */
switch (sa->sa_family) {
case AF_INET:
{
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
inet_ntop (AF_INET, &sa_in->sin_addr, buf, buflen);
break;
}
case AF_INET6:
{
struct sockaddr_in6 *sa_in6 =
(struct sockaddr_in6 *) sa;
inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, buflen);
break;
}
default:
/* no valid family */
return NULL;
}
return buf;
}
/*
* Convert a numeric character string into an IPv6 network address
* (in binary form.) The function works just like inet_pton(), but it
* will accept both IPv4 and IPv6 numeric addresses.
*
* Returns the same as inet_pton().
*/
int full_inet_pton (const char *ip, void *dst)
{
char buf[24], tmp[24]; /* IPv4->IPv6 = ::FFFF:xxx.xxx.xxx.xxx\0 */
int n;
assert (ip != NULL && strlen (ip) != 0);
assert (dst != NULL);
/*
* Check if the string is an IPv4 numeric address. We use the
* older inet_aton() call since it handles more IPv4 numeric
* address formats.
*/
n = inet_aton (ip, (struct in_addr *) dst);
if (n == 0) {
/*
* Simple case: "ip" wasn't an IPv4 numeric address, so
* try doing the conversion as an IPv6 address. This
* will either succeed or fail, but we can't do any
* more processing anyway.
*/
return inet_pton (AF_INET6, ip, dst);
}
/*
* "ip" was an IPv4 address, so we need to convert it to
* an IPv4-mapped IPv6 address and do the conversion
* again to get the IPv6 network structure.
*
* We convert the IPv4 binary address back into the
* standard dotted-decimal format using inet_ntop()
* so we can be sure that inet_pton will accept the
* full string.
*/
snprintf (buf, sizeof (buf), "::ffff:%s",
inet_ntop (AF_INET, dst, tmp, sizeof (tmp)));
return inet_pton (AF_INET6, buf, dst);
}
+12 -18
View File
@@ -1,23 +1,20 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: network.h,v 1.1 2002-05-23 04:41:48 rjkaes Exp $
* Copyright (C) 2002, 2004 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * See 'network.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) 2002 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 'network.c' for detailed information. */
#ifndef TINYPROXY_NETWORK_H #ifndef TINYPROXY_NETWORK_H
#define TINYPROXY_NETWORK_H #define TINYPROXY_NETWORK_H
@@ -27,7 +24,4 @@ extern ssize_t safe_read (int fd, char *buffer, size_t count);
extern int write_message(int fd, const char *fmt, ...); extern int write_message(int fd, const char *fmt, ...);
extern ssize_t readline(int fd, char **whole_buffer); extern ssize_t readline(int fd, char **whole_buffer);
extern char *get_ip_string (struct sockaddr *sa, char *buf, size_t len);
extern int full_inet_pton (const char *ip, void *dst);
#endif #endif
+35
View File
@@ -0,0 +1,35 @@
/* $Id: regexp.h,v 1.3 2001-11-25 22:06:54 rjkaes Exp $
*
* We need this little header to help distinguish whether to use the REGEX
* library installed in the system, or to include our own version (the GNU
* version to be exact.)
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#ifndef _TINYPROXY_REGEXP_H_
#define _TINYPROXY_REGEXP_H_
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef USE_GNU_REGEX
# include "gnuregex.h"
#else
# ifdef HAVE_REGEX_H
# include <regex.h>
# endif
#endif
#endif
+358 -435
View File
File diff suppressed because it is too large. Load diff
+13 -37
View File
@@ -1,48 +1,24 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: reqs.h,v 1.4 2003-05-29 19:43:57 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"
/*
* Port constants for HTTP (80) and SSL (443)
*/
#define HTTP_PORT 80
#define HTTP_PORT_SSL 443
/*
* This structure holds the information pulled from a URL request.
*/
struct request_s {
char *method;
char *protocol;
char *host;
uint16_t port;
char *path;
};
extern void handle_connection(int fd); extern void handle_connection(int fd);
extern void add_connect_port_allowed(int port); extern void add_connect_port_allowed(int port);
extern void upstream_add(const char *host, int port, const char *domain); extern void upstream_add(const char *host, int port, const char *domain);
-160
View File
@@ -1,160 +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"
/*
* Add entry to the reversepath list
*/
void reversepath_add (const char *path, const char *url)
{
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 = config.reversepath_list;
config.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 = config.reversepath_list;
while (reverse) {
if (strstr (url, reverse->path) == url)
return reverse;
reverse = reverse->next;
}
return NULL;
}
/*
* 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);
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))) {
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;
}
-39
View File
@@ -1,39 +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);
extern struct reversepath *reversepath_get (char *url);
extern char *reverse_rewrite_url (struct conn_s *connptr,
hashmap_t hashofheaders, char *url);
#endif
+168
View File
@@ -0,0 +1,168 @@
/* $Id: scanner.l,v 1.22 2003-06-26 18:26:10 rjkaes Exp $
*
* This builds the scanner for the tinyproxy configuration file. This
* file needs to stay in sync with grammar.y. If someone knows lex and yacc
* better than I do, please update these files.
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
%{
#include "tinyproxy.h"
#include "grammar.h"
struct keyword {
char *kw_name;
int kw_token;
};
static struct keyword keywords[] = {
/* statements */
{ "port", KW_PORT },
{ "logfile", KW_LOGFILE },
{ "syslog", KW_SYSLOG },
{ "maxclients", KW_MAXCLIENTS },
{ "maxspareservers", KW_MAXSPARESERVERS },
{ "minspareservers", KW_MINSPARESERVERS },
{ "startservers", KW_STARTSERVERS },
{ "maxrequestsperchild", KW_MAXREQUESTSPERCHILD },
{ "pidfile", KW_PIDFILE },
{ "timeout", KW_TIMEOUT },
{ "listen", KW_LISTEN },
{ "user", KW_USER },
{ "group", KW_GROUP },
{ "anonymous", KW_ANONYMOUS },
{ "filter", KW_FILTER },
{ "filterurls", KW_FILTERURLS },
{ "filterextended", KW_FILTEREXTENDED },
{ "filterdefaultdeny", KW_FILTER_DEFAULT_DENY },
{ "filtercasesensitive", KW_FILTER_CASESENSITIVE },
{ "xtinyproxy", KW_XTINYPROXY },
{ "upstream", KW_UPSTREAM },
{ "allow", KW_ALLOW },
{ "deny", KW_DENY },
{ "connectport", KW_CONNECTPORT },
{ "bind", KW_BIND },
{ "viaproxyname", KW_VIA_PROXY_NAME },
{ "stathost", KW_STATHOST },
{ "errorfile", KW_ERRORPAGE },
{ "defaulterrorfile", KW_DEFAULT_ERRORPAGE },
{ "statfile", KW_STATPAGE },
/* loglevel and the settings */
{ "loglevel", KW_LOGLEVEL },
{ "critical", KW_LOG_CRITICAL },
{ "error", KW_LOG_ERROR },
{ "warning", KW_LOG_WARNING },
{ "notice", KW_LOG_NOTICE },
{ "connect", KW_LOG_CONNECT },
{ "info", KW_LOG_INFO },
/* on/off switches */
{ "yes", KW_YES },
{ "on", KW_YES },
{ "no", KW_NO },
{ "off", KW_NO }
};
#define YY_NO_UNPUT 1
#define MAX_REGEXP_LEN 1024
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 batch yylineno
white [ \t]
digit [0-9]
alpha [a-zA-Z]
alphanum [a-zA-Z0-9]
word [^ \#'"\(\)\{\}\\;\n\t,|\.]
%x string
%%
\#.*$ ;
\n { 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}({alphanum}|[-._])+ { 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; }
%%
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;
}
+111 -137
View File
@@ -1,141 +1,127 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: sock.c,v 1.39 2002-10-03 20:50:59 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 "log.h" #include "log.h"
#include "heap.h" #include "heap.h"
#include "network.h"
#include "sock.h" #include "sock.h"
#include "text.h" #include "text.h"
/* /*
* Bind the given socket to the supplied address. The socket is * Take a string host address and return a struct in_addr so we can connect
* returned if the bind succeeded. Otherwise, -1 is returned * to the remote host.
* to indicate an error. *
* Return a negative if there is a problem.
*/ */
static int bind_socket (int sockfd, const char *addr) static int
lookup_domain(struct in_addr *addr, const char *domain)
{ {
struct addrinfo hints, *res, *ressave; struct hostent* result;
assert (sockfd >= 0); assert(domain != NULL);
assert (addr != NULL && strlen (addr) != 0);
memset (&hints, 0, sizeof (struct addrinfo)); result = gethostbyname(domain);
hints.ai_family = AF_UNSPEC; if (result) {
hints.ai_socktype = SOCK_STREAM; memcpy(addr, result->h_addr_list[0], result->h_length);
return 0;
/* The local port it not important */ } else
if (getaddrinfo (addr, NULL, &hints, &res) != 0)
return -1; return -1;
ressave = res;
/* Loop through the addresses and try to bind to each */
do {
if (bind (sockfd, res->ai_addr, res->ai_addrlen) == 0)
break; /* success */
} while ((res = res->ai_next) != NULL);
freeaddrinfo (ressave);
if (res == NULL) /* was not able to bind to any address */
return -1;
return sockfd;
} }
/* /* This routine is so old I can't even remember writing it. But I do
* Open a connection to a remote host. It's been re-written to use * remember that it was an .h file because I didn't know putting code in a
* the getaddrinfo() library function, which allows for a protocol * header was bad magic yet. anyway, this routine opens a connection to a
* independent implementation (mostly for IPv4 and IPv6 addresses.) * system and returns the fd.
* - steve
*
* Cleaned up some of the code to use memory routines which are now the
* default. Also, the routine first checks to see if the address is in
* dotted-decimal form before it does a name lookup.
* - rjkaes
*/ */
int 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]; struct sockaddr_in bind_addr;
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); /* Lookup and return the address if possible */
if (n != 0) { ret = lookup_domain(&port_info.sin_addr, ip_addr);
if (ret < 0) {
log_message(LOG_ERR, log_message(LOG_ERR,
"opensock: Could not retrieve info for %s", host); "opensock: Could not lookup address \"%s\".",
ip_addr);
return -1; return -1;
} }
ressave = res; port_info.sin_port = htons(port);
do {
sockfd = if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
socket (res->ai_family, res->ai_socktype, res->ai_protocol); log_message(LOG_ERR, "opensock: socket() error \"%s\".",
if (sockfd < 0) strerror(errno));
continue; /* ignore this one */ return -1;
}
/* Bind to the specified address */ /* Bind to the specified address */
if (bind_to) { if (config.bind_address) {
if (bind_socket (sockfd, bind_to) < 0) { memset(&bind_addr, 0, sizeof(bind_addr));
close (sockfd); bind_addr.sin_family = AF_INET;
continue; /* can't bind, so try again */ bind_addr.sin_addr.s_addr = inet_addr(config.bind_address);
}
} else if (config.bind_address) { ret = bind(sock_fd, (struct sockaddr *)&bind_addr, sizeof(bind_addr));
if (bind_socket (sockfd, config.bind_address) < 0) { if (ret < 0) {
close (sockfd); log_message(LOG_ERR, "Could not bind local address \"%\" because of %s",
continue; /* can't bind, so try again */ config.bind_address,
strerror(errno));
return -1;
} }
} }
if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0) if (connect(sock_fd, (struct sockaddr *) &port_info, sizeof(port_info)) < 0) {
break; /* success */ log_message(LOG_ERR, "opensock: connect() error \"%s\".",
strerror(errno));
close (sockfd);
} while ((res = res->ai_next) != NULL);
freeaddrinfo (ressave);
if (res == NULL) {
log_message (LOG_ERR,
"opensock: Could not establish a connection to %s",
host);
return -1; return -1;
} }
return sockfd; return sock_fd;
} }
/* /*
* 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;
@@ -148,7 +134,8 @@ int socket_nonblocking (int sock)
/* /*
* 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;
@@ -164,7 +151,8 @@ int socket_blocking (int sock)
* 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)
{ {
int listenfd; int listenfd;
const int on = 1; const int on = 1;
@@ -187,15 +175,13 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
} }
if (bind(listenfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { if (bind(listenfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
log_message (LOG_ERR, log_message(LOG_ERR, "Unable to bind listening socket because of %s",
"Unable to bind listening socket because of %s",
strerror(errno)); strerror(errno));
return -1; return -1;
} }
if (listen(listenfd, MAXLISTEN) < 0) { if (listen(listenfd, MAXLISTEN) < 0) {
log_message (LOG_ERR, log_message(LOG_ERR, "Unable to start listening socket because of %s",
"Unable to start listening socket because of %s",
strerror(errno)); strerror(errno));
return -1; return -1;
} }
@@ -205,53 +191,41 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
return listenfd; return listenfd;
} }
/*
* Takes a socket descriptor and returns the socket's IP address.
*/
int getsock_ip (int fd, char *ipaddr)
{
struct sockaddr_storage name;
socklen_t namelen = sizeof (name);
assert (fd >= 0);
if (getsockname (fd, (struct sockaddr *) &name, &namelen) != 0) {
log_message (LOG_ERR, "getsock_ip: getsockname() error: %s",
strerror (errno));
return -1;
}
if (get_ip_string ((struct sockaddr *) &name, ipaddr, IP_LENGTH) ==
NULL)
return -1;
return 0;
}
/* /*
* Return the peer's socket information. * Return the peer's socket information.
*/ */
int getpeer_information (int fd, char *ipaddr, char *string_addr) int
getpeer_information(int fd, char* ipaddr, char* string_addr)
{ {
struct sockaddr_storage sa; struct sockaddr_in name;
socklen_t salen = sizeof sa; socklen_t namelen = sizeof(name);
struct hostent* result;
assert(fd >= 0); assert(fd >= 0);
assert(ipaddr != NULL); assert(ipaddr != NULL);
assert(string_addr != NULL); assert(string_addr != NULL);
/* Set the strings to default values */ /*
ipaddr[0] = '\0'; * Clear the memory.
strlcpy (string_addr, "[unknown]", HOSTNAME_LENGTH); */
memset(ipaddr, '\0', PEER_IP_LENGTH);
memset(string_addr, '\0', PEER_STRING_LENGTH);
/* Look up the IP address */ if (getpeername(fd, (struct sockaddr *)&name, &namelen) != 0) {
if (getpeername (fd, (struct sockaddr *) &sa, &salen) != 0) log_message(LOG_ERR, "getpeer_information: getpeername() error: %s",
strerror(errno));
return -1; return -1;
} else {
if (get_ip_string ((struct sockaddr *) &sa, ipaddr, IP_LENGTH) == NULL) strlcpy(ipaddr,
return -1; inet_ntoa(*(struct in_addr *)&name.sin_addr.s_addr),
PEER_IP_LENGTH);
/* Get the full host name */ }
return getnameinfo ((struct sockaddr *) &sa, salen,
string_addr, HOSTNAME_LENGTH, NULL, 0, 0); result = gethostbyaddr((char *)&name.sin_addr.s_addr, 4, AF_INET);
if (result) {
strlcpy(string_addr, result->h_name, PEER_STRING_LENGTH);
return 0;
} else {
return -1;
}
} }
+16 -21
View File
@@ -1,40 +1,35 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: sock.h,v 1.11 2003-01-27 18:45:25 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 */ #define PEER_IP_LENGTH 16
#define IP_LENGTH 48 #define PEER_STRING_LENGTH 256
#define HOSTNAME_LENGTH 1024
#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 int getpeer_information(int fd, char* ipaddr, char* string_addr); extern int getpeer_information(int fd, char* ipaddr, char* string_addr);
#endif #endif
+40 -50
View File
@@ -1,35 +1,31 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: stats.c,v 1.13 2003-03-13 21:31:03 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 child to access the statistics at the same
* time. This is prevented by a mutex. If there is a need for more * time. This is prevented by a mutex. If there is a need for more
* statistics in the future, just add to the structure, enum (in the header), * statistics in the future, just add to the structure, enum (in the header),
* and the switch statement in update_stats(). * and the switch statement in update_stats().
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "log.h" #include "log.h"
#include "heap.h" #include "heap.h"
#include "html-error.h" #include "htmlerror.h"
#include "stats.h" #include "stats.h"
#include "utils.h" #include "utils.h"
@@ -46,13 +42,14 @@ static struct stat_s *stats;
/* /*
* Initialize the statistics information to zero. * Initialize the statistics information to zero.
*/ */
void init_stats (void) void
init_stats(void)
{ {
stats = (struct stat_s *) malloc_shared_memory (sizeof (struct stat_s)); stats = malloc_shared_memory(sizeof(struct stat_s));
if (stats == MAP_FAILED) if (stats == MAP_FAILED)
return; return;
memset (stats, 0, sizeof (struct stat_s)); memset(stats, 0, sizeof(struct stat));
} }
/* /*
@@ -61,6 +58,18 @@ void init_stats (void)
int int
showstats(struct conn_s *connptr) showstats(struct conn_s *connptr)
{ {
static char *msg =
"<html><head><title>%s (%s) stats</title></head>\r\n"
"<body>\r\n"
"<center><h2>%s (%s) run-time statistics</h2></center><hr>\r\n"
"<blockquote>\r\n"
"Number of open connections: %lu<br>\r\n"
"Number of requests: %lu<br>\r\n"
"Number of bad connections: %lu<br>\r\n"
"Number of denied connections: %lu<br>\r\n"
"Number of refused connections due to high load: %lu\r\n"
"</blockquote>\r\n</body></html>\r\n";
char *message_buffer; char *message_buffer;
char opens[16], reqs[16], badconns[16], denied[16], refused[16]; char opens[16], reqs[16], badconns[16], denied[16], refused[16];
FILE *statfile; FILE *statfile;
@@ -72,37 +81,17 @@ showstats (struct conn_s *connptr)
snprintf(refused, sizeof(refused), "%lu", stats->num_refused); snprintf(refused, sizeof(refused), "%lu", stats->num_refused);
if (!config.statpage || (!(statfile = fopen(config.statpage, "r")))) { if (!config.statpage || (!(statfile = fopen(config.statpage, "r")))) {
message_buffer = (char *) safemalloc (MAXBUFFSIZE); message_buffer = safemalloc(MAXBUFFSIZE);
if (!message_buffer) if (!message_buffer)
return -1; return -1;
snprintf snprintf(message_buffer, MAXBUFFSIZE, msg,
(message_buffer, MAXBUFFSIZE,
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
"<html>\n"
"<head><title>%s version %s run-time statistics</title></head>\n"
"<body>\n"
"<h1>%s version %s run-time statistics</h1>\n"
"<p>\n"
"Number of open connections: %lu<br />\n"
"Number of requests: %lu<br />\n"
"Number of bad connections: %lu<br />\n"
"Number of denied connections: %lu<br />\n"
"Number of refused connections due to high load: %lu\n"
"</p>\n"
"<hr />\n"
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
"</html>\n",
PACKAGE, VERSION, PACKAGE, VERSION, PACKAGE, VERSION, PACKAGE, VERSION,
stats->num_open, stats->num_open,
stats->num_reqs, stats->num_reqs,
stats->num_badcons, stats->num_denied, stats->num_badcons, stats->num_denied, stats->num_refused);
stats->num_refused, PACKAGE, VERSION);
if (send_http_message (connptr, 200, "OK", if (send_http_message(connptr, 200, "OK", message_buffer) < 0) {
message_buffer) < 0) {
safefree(message_buffer); safefree(message_buffer);
return -1; return -1;
} }
@@ -114,8 +103,8 @@ showstats (struct conn_s *connptr)
add_error_variable(connptr, "opens", opens); add_error_variable(connptr, "opens", opens);
add_error_variable(connptr, "reqs", reqs); add_error_variable(connptr, "reqs", reqs);
add_error_variable(connptr, "badconns", badconns); add_error_variable(connptr, "badconns", badconns);
add_error_variable (connptr, "deniedconns", denied); add_error_variable(connptr, "denied", denied);
add_error_variable (connptr, "refusedconns", refused); add_error_variable(connptr, "refused", refused);
add_standard_vars(connptr); add_standard_vars(connptr);
send_http_headers(connptr, 200, "Statistic requested"); send_http_headers(connptr, 200, "Statistic requested");
send_html_file(statfile, connptr); send_html_file(statfile, connptr);
@@ -128,7 +117,8 @@ showstats (struct conn_s *connptr)
* 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) { switch (update_level) {
case STAT_BADCONN: case STAT_BADCONN:
+12 -15
View File
@@ -1,23 +1,20 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: stats.h,v 1.4 2001-11-22 00:31:10 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_
+24 -28
View File
@@ -1,28 +1,24 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: text.c,v 1.3 2003-03-13 05:20:06 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * The functions included here are useful for text manipulation. They
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* The functions included here are useful for text manipulation. They
* replace or augment the standard C string library. These functions * replace or augment the standard C string library. These functions
* are either safer replacements, or they provide services not included * are either safer replacements, or they provide services not included
* with the standard C string library. * with the standard C string library.
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/ */
#include "main.h" #include "tinyproxy.h"
#include "text.h" #include "text.h"
@@ -32,7 +28,8 @@
* buffer, and always NULL terminates the buffer. size is the size of the * buffer, and always NULL terminates the buffer. size is the size of the
* destination buffer. * destination buffer.
*/ */
size_t strlcpy (char *dst, const char *src, size_t size) size_t
strlcpy(char *dst, const char *src, size_t size)
{ {
size_t len = strlen(src); size_t len = strlen(src);
size_t ret = len; size_t ret = len;
@@ -54,7 +51,8 @@ size_t strlcpy (char *dst, const char *src, size_t size)
* buffer, which should be one more than the maximum resulting string * buffer, which should be one more than the maximum resulting string
* length. * length.
*/ */
size_t strlcat (char *dst, const char *src, size_t size) size_t
strlcat(char *dst, const char *src, size_t size)
{ {
size_t len1 = strlen(dst); size_t len1 = strlen(dst);
size_t len2 = strlen(src); size_t len2 = strlen(src);
@@ -80,7 +78,8 @@ size_t strlcat (char *dst, const char *src, size_t size)
* Returns the number of characters removed from the end of the string. A * Returns the number of characters removed from the end of the string. A
* negative return value indicates an error. * negative return value indicates an error.
*/ */
ssize_t chomp (char *buffer, size_t length) ssize_t
chomp(char *buffer, size_t length)
{ {
size_t chars; size_t chars;
@@ -88,10 +87,8 @@ ssize_t chomp (char *buffer, size_t length)
assert(length > 0); assert(length > 0);
/* Make sure the arguments are valid */ /* Make sure the arguments are valid */
if (buffer == NULL) if (buffer == NULL) return -EFAULT;
return -EFAULT; if (length < 1) return -ERANGE;
if (length < 1)
return -ERANGE;
chars = 0; chars = 0;
@@ -101,8 +98,7 @@ ssize_t chomp (char *buffer, size_t length)
chars++; chars++;
/* Stop once we get to zero to prevent wrap-around */ /* Stop once we get to zero to prevent wrap-around */
if (length-- == 0) if (length-- == 0) break;
break;
} }
return chars; return chars;
+12 -15
View File
@@ -1,23 +1,20 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: text.h,v 1.2 2003-03-13 05:20:06 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * See 'text.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) 2002 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 'text.c' for detailed information. */
#ifndef TINYPROXY_TEXT_H #ifndef TINYPROXY_TEXT_H
#define TINYPROXY_TEXT_H #define TINYPROXY_TEXT_H
+421
View File
@@ -0,0 +1,421 @@
/* $Id: tinyproxy.c,v 1.46 2003-03-17 04:24:19 rjkaes Exp $
*
* The initialize routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops
* over the new connections until the daemon is closed. Also has additional
* functions to handle the "user friendly" aspects of a program (usage,
* stats, etc.) Like any good program, most of the work is actually done
* elsewhere.
*
* Copyright (C) 1998 Steven Young
* Copyright (C) 1998-2002 Robert James Kaes (rjkaes@flarenet.com)
* Copyright (C) 2000 Chris Lightfoot (chris@ex-parrot.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include "tinyproxy.h"
#include "anonymous.h"
#include "buffer.h"
#include "daemon.h"
#include "heap.h"
#include "filter.h"
#include "child.h"
#include "log.h"
#include "reqs.h"
#include "sock.h"
#include "stats.h"
#include "utils.h"
void takesig(int sig);
extern int yyparse(void);
extern FILE *yyin;
/*
* Global Structures
*/
struct config_s config;
float load = 0.00;
unsigned int received_sighup = FALSE; /* boolean */
unsigned int processed_config_file = FALSE; /* boolean */
/*
* Handle a signal
*/
void
takesig(int sig)
{
pid_t pid;
int status;
switch (sig) {
case SIGHUP:
received_sighup = TRUE;
break;
case SIGTERM:
config.quit = TRUE;
break;
case SIGCHLD:
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
;
break;
}
return;
}
/*
* Display the version information for the user.
*/
static void
display_version(void)
{
printf("%s %s (%s)\n", PACKAGE, VERSION, TARGET_SYSTEM);
}
/*
* Display the copyright and license for this program.
*/
static void
display_license(void)
{
display_version();
printf("\
Copyright 1998 Steven Young (sdyoung@well.com)\n\
Copyright 1998-2002 Robert James Kaes (rjkaes@users.sourceforge.net)\n\
Copyright 1999 George Talusan (gstalusan@uwaterloo.ca)\n\
Copyright 2000 Chris Lightfoot (chris@ex-parrot.com)\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation; either version 2, or (at your option)\n\
any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n");
}
/*
* Display usage to the user.
*/
static void
display_usage(void)
{
printf("Usage: %s [options]\n", PACKAGE);
printf("\
Options:\n\
-d Operate in DEBUG mode.\n\
-c FILE Use an alternate configuration file.\n\
-h Display this usage information.\n\
-l Display the license.\n\
-v Display the version number.\n");
/* Display the modes compiled into tinyproxy */
printf("\nFeatures Compiled In:\n");
#ifdef XTINYPROXY_ENABLE
printf(" XTinyproxy Header\n");
#endif /* XTINYPROXY */
#ifdef FILTER_ENABLE
printf(" Filtering\n");
#endif /* FILTER_ENABLE */
#ifndef NDEBUG
printf(" Debugging code\n");
#endif /* NDEBUG */
#ifdef TRANSPARENT_PROXY
printf(" Transparent Proxy Support\n");
#endif /* TRANSPARENT_PROXY */
}
int
main(int argc, char **argv)
{
int optch;
unsigned int godaemon = TRUE; /* boolean */
struct passwd *thisuser = NULL;
struct group *thisgroup = NULL;
/*
* Disable the creation of CORE files right up front.
*/
#if defined(HAVE_SETRLIMIT) && defined(NDEBUG)
struct rlimit core_limit = { 0, 0 };
if (setrlimit(RLIMIT_CORE, &core_limit) < 0) {
fprintf(stderr, "%s: Could not set the core limit to zero.\n",
argv[0]);
exit(EX_SOFTWARE);
}
#endif /* HAVE_SETRLIMIT */
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask(0177);
/* Default configuration file location */
config.config_file = DEFAULT_CONF_FILE;
/*
* Process the various options
*/
while ((optch = getopt(argc, argv, "c:vldh")) != EOF) {
switch (optch) {
case 'v':
display_version();
exit(EX_OK);
case 'l':
display_license();
exit(EX_OK);
case 'd':
godaemon = FALSE;
break;
case 'c':
config.config_file = safestrdup(optarg);
if (!config.config_file) {
fprintf(stderr,
"%s: Could not allocate memory.\n",
argv[0]);
exit(EX_SOFTWARE);
}
break;
case 'h':
default:
display_usage();
exit(EX_OK);
}
}
log_message(LOG_INFO, "Initializing " PACKAGE " ...");
/*
* Make sure the HTML error pages array is NULL to begin with.
* (FIXME: Should have a better API for all this)
*/
config.errorpages = NULL;
/*
* Read in the settings from the config file.
*/
yyin = fopen(config.config_file, "r");
if (!yyin) {
fprintf(stderr,
"%s: Could not open configuration file \"%s\".\n",
argv[0], config.config_file);
exit(EX_SOFTWARE);
}
yyparse();
/* Open the log file if not using syslog */
if (config.syslog == FALSE) {
if (!config.logf_name) {
fprintf(stderr,
"%s: You MUST set a LogFile in the configuration file.\n",
argv[0]);
exit(EX_SOFTWARE);
} else {
if (open_log_file(config.logf_name) < 0) {
fprintf(stderr,
"%s: Could not create log file.\n",
argv[0]);
exit(EX_SOFTWARE);
}
}
} else {
if (godaemon == TRUE)
openlog("tinyproxy", LOG_PID, LOG_DAEMON);
else
openlog("tinyproxy", LOG_PID, LOG_USER);
}
processed_config_file = TRUE;
send_stored_logs();
/*
* Set the default values if they were not set in the config file.
*/
if (config.port == 0) {
fprintf(stderr,
"%s: You MUST set a Port in the configuration file.\n",
argv[0]);
exit(EX_SOFTWARE);
}
if (!config.stathost) {
log_message(LOG_INFO, "Setting stathost to \"%s\".",
DEFAULT_STATHOST);
config.stathost = DEFAULT_STATHOST;
}
if (!config.username) {
log_message(LOG_WARNING,
"You SHOULD set a UserName in the configuration file. Using current user instead.");
}
if (config.idletimeout == 0) {
log_message(LOG_WARNING, "Invalid idle time setting. Only values greater than zero allowed; therefore setting idle timeout to %u seconds.",
MAX_IDLE_TIME);
config.idletimeout = MAX_IDLE_TIME;
}
init_stats();
/*
* If ANONYMOUS is turned on, make sure that Content-Length is
* in the list of allowed headers, since it is required in a
* HTTP/1.0 request. Also add the Content-Type header since it goes
* hand in hand with Content-Length.
* - rjkaes
*/
if (is_anonymous_enabled()) {
anonymous_insert("Content-Length");
anonymous_insert("Content-Type");
}
if (godaemon == TRUE)
makedaemon();
if (config.pidpath) {
if (pidfile_create(config.pidpath) < 0) {
fprintf(stderr, "%s: Could not create PID file.\n",
argv[0]);
exit(EX_OSERR);
}
}
if (set_signal_handler(SIGPIPE, SIG_IGN) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_init();
#endif /* FILTER_ENABLE */
/*
* Start listening on the selected port.
*/
if (child_listening_sock(config.port) < 0) {
fprintf(stderr, "%s: Could not create listening socket.\n",
argv[0]);
exit(EX_OSERR);
}
/*
* Switch to a different user.
*/
if (geteuid() == 0) {
if (config.group && strlen(config.group) > 0) {
thisgroup = getgrnam(config.group);
if (!thisgroup) {
fprintf(stderr,
"%s: Unable to find group \"%s\".\n",
argv[0], config.group);
exit(EX_NOUSER);
}
if (setgid(thisgroup->gr_gid) < 0) {
fprintf(stderr,
"%s: Unable to change to group \"%s\".\n",
argv[0], config.group);
exit(EX_CANTCREAT);
}
log_message(LOG_INFO, "Now running as group \"%s\".",
config.group);
}
if (config.username && strlen(config.username) > 0) {
thisuser = getpwnam(config.username);
if (!thisuser) {
fprintf(stderr,
"%s: Unable to find user \"%s\".",
argv[0], config.username);
exit(EX_NOUSER);
}
if (setuid(thisuser->pw_uid) < 0) {
fprintf(stderr,
"%s: Unable to change to user \"%s\".",
argv[0], config.username);
exit(EX_CANTCREAT);
}
log_message(LOG_INFO, "Now running as user \"%s\".",
config.username);
}
} else {
log_message(LOG_WARNING,
"Not running as root, so not changing UID/GID.");
}
if (child_pool_create() < 0) {
fprintf(stderr, "%s: Could not create the pool of children.",
argv[0]);
exit(EX_SOFTWARE);
}
/*
* These signals are only for the parent process.
*/
log_message(LOG_INFO, "Setting the various signals.");
if (set_signal_handler(SIGCHLD, takesig) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGCHLD\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
if (set_signal_handler(SIGTERM, takesig) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGTERM\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
if (set_signal_handler(SIGHUP, takesig) == SIG_ERR) {
fprintf(stderr, "%s: Could not set the \"SIGHUP\" signal.\n",
argv[0]);
exit(EX_OSERR);
}
/*
* Start the main loop.
*/
log_message(LOG_INFO, "Starting main loop. Accepting connections.");
child_main_loop();
log_message(LOG_INFO, "Shutting down.");
child_kill_children();
child_close_sock();
/*
* Remove the PID file.
*/
if (unlink(config.pidpath) < 0) {
log_message(LOG_WARNING,
"Could not remove PID file \"%s\": %s.",
config.pidpath, strerror(errno));
}
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy();
#endif /* FILTER_ENABLE */
if (config.syslog)
closelog();
else
close_log_file();
exit(EX_OK);
}
+98
View File
@@ -0,0 +1,98 @@
/* $Id: tinyproxy.h,v 1.41.2.1 2004-08-06 16:56:55 rjkaes Exp $
*
* See 'tinyproxy.c' for a detailed description.
*
* Copyright (C) 1998 Steven Young
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#ifndef TINYPROXY_TINYPROXY_H
#define TINYPROXY_TINYPROXY_H
#include "common.h"
/* Global variables for the main controls of the program */
#define MAXBUFFSIZE ((size_t)(1024 * 96)) /* Max size of buffer */
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
/*
* Even if upstream support is not compiled into tinyproxy, this
* structure still needs to be defined.
*/
struct upstream {
struct upstream *next;
char *domain; /* optional */
char *host;
int port;
in_addr_t ip, mask;
};
struct config_s {
char *logf_name;
char *config_file;
unsigned int syslog; /* boolean */
int port;
char *stathost;
unsigned int quit; /* boolean */
char *username;
char *group;
char *ipAddr;
#ifdef FILTER_ENABLE
char *filter;
unsigned int filter_url; /* boolean */
unsigned int filter_extended; /* boolean */
unsigned int filter_casesensitive; /* boolean */
#endif /* FILTER_ENABLE */
#ifdef XTINYPROXY_ENABLE
char *my_domain;
#endif
#ifdef UPSTREAM_SUPPORT
struct upstream *upstream_list;
#endif /* UPSTREAM_SUPPORT */
char *pidpath;
unsigned int idletimeout;
char* bind_address;
/*
* The configured name to use in the HTTP "Via" header field.
*/
char* via_proxy_name;
/*
* Error page support. This is an array of pointers to structures
* which describe the error page path, and what HTTP error it handles.
* an example would be { "/usr/local/etc/tinyproxy/404.html", 404 }
* Ending of array is noted with NULL, 0.
*/
struct error_pages_s {
char *errorpage_path;
unsigned int errorpage_errnum;
} **errorpages;
/*
* Error page to be displayed if appropriate page cannot be located
* in the errorpages structure.
*/
char *errorpage_undef;
/*
* The HTML statistics page.
*/
char *statpage;
};
/* Global Structures used in the program */
extern struct config_s config;
extern unsigned int received_sighup; /* boolean */
extern unsigned int processed_config_file; /* boolean */
#endif
-116
View File
@@ -1,116 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2002 Petr Lampa <lampa@fit.vutbr.cz>
* Copyright (C) 2008 Robert James Kaes <rjk@wormbytes.ca>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* This section of code is used for the transparent proxy option. You will
* need to configure your firewall to redirect all connections for HTTP
* traffic to tinyproxy for this to work properly.
*/
#include "main.h"
#include "transparent-proxy.h"
#include "conns.h"
#include "heap.h"
#include "html-error.h"
#include "log.h"
#include "reqs.h"
/*
* Build a URL from parts.
*/
static int build_url (char **url, const char *host, int port, const char *path)
{
int len;
assert (url != NULL);
assert (host != NULL);
assert (port > 0 && port < 32768);
assert (path != NULL);
len = strlen (host) + strlen (path) + 14;
*url = (char *) safemalloc (len);
if (*url == NULL)
return -1;
return snprintf (*url, len, "http://%s:%d%s", host, port, path);
}
int
do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
struct request_s *request, struct config_s *conf,
char *url)
{
socklen_t length;
char *data;
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
if (length <= 0) {
struct sockaddr_in dest_addr;
if (getsockname
(connptr->client_fd, (struct sockaddr *) &dest_addr,
&length) < 0) {
log_message (LOG_ERR,
"process_request: cannot get destination IP for %d",
connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Unknown destination",
"url", url, NULL);
return 0;
}
request->host = (char *) safemalloc (17);
strcpy (request->host, inet_ntoa (dest_addr.sin_addr));
request->port = ntohs (dest_addr.sin_port);
request->path = (char *) safemalloc (strlen (url) + 1);
strcpy (request->path, url);
safefree (url);
build_url (&url, request->host, request->port, request->path);
log_message (LOG_INFO,
"process_request: trans IP %s %s for %d",
request->method, url, connptr->client_fd);
} else {
request->host = (char *) safemalloc (length + 1);
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
2) {
strcpy (request->host, data);
request->port = HTTP_PORT;
}
request->path = (char *) safemalloc (strlen (url) + 1);
strcpy (request->path, url);
safefree (url);
build_url (&url, request->host, request->port, request->path);
log_message (LOG_INFO,
"process_request: trans Host %s %s for %d",
request->method, url, connptr->client_fd);
}
if (conf->ipAddr && strcmp (request->host, conf->ipAddr) == 0) {
log_message (LOG_ERR,
"process_request: destination IP is localhost %d",
connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request",
"detail",
"You tried to connect to the machine "
"the proxy is running on", "url", url,
NULL);
return 0;
}
return 1;
}
-39
View File
@@ -1,39 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2008 Robert James Kaes <rjk@wormbytes.ca>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'transparent-proxy.c' for detailed information. */
#ifndef TINYPROXY_TRANSPARENT_PROXY_H
#define TINYPROXY_TRANSPARENT_PROXY_H
#include "common.h"
#ifdef TRANSPARENT_PROXY
#include "conns.h"
#include "hashmap.h"
#include "reqs.h"
extern int do_transparent_proxy (struct conn_s *connptr,
hashmap_t hashofheaders,
struct request_s *request,
struct config_s *config, char *url);
#endif
#endif
+31 -41
View File
@@ -1,34 +1,30 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: utils.c,v 1.38 2003-03-14 06:15:27 rjkaes Exp $
* Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
* Copyright (C) 1999-2003 Robert James Kaes <rjkaes@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * Misc. routines which are used by the various functions to handle strings
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also, * and memory allocation and pretty much anything else we can think of. Also,
* the load cutoff routine is in here. Could not think of a better place for * the load cutoff routine is in here. Could not think of a better place for
* it, so it's in here. * it, so it's in here.
*
* Copyright (C) 1998 Steven Young
* Copyright (C) 1999,2001,2003 by
* 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 "conns.h" #include "conns.h"
#include "heap.h" #include "heap.h"
#include "http-message.h" #include "http_message.h"
#include "log.h"
#include "utils.h" #include "utils.h"
/* /*
@@ -38,7 +34,7 @@ int
send_http_message(struct conn_s *connptr, int http_code, send_http_message(struct conn_s *connptr, int http_code,
const char *error_title, const char *message) const char *error_title, const char *message)
{ {
static const char *headers[] = { static char* headers[] = {
"Server: " PACKAGE "/" VERSION, "Server: " PACKAGE "/" VERSION,
"Content-type: text/html", "Content-type: text/html",
"Connection: close" "Connection: close"
@@ -61,7 +57,8 @@ send_http_message (struct conn_s *connptr, int http_code,
/* /*
* Safely creates filename and returns the low-level file descriptor. * Safely creates filename and returns the low-level file descriptor.
*/ */
int create_file_safely (const char *filename, unsigned int truncate_file) int
create_file_safely(const char *filename, unsigned int truncate_file)
{ {
struct stat lstatinfo; struct stat lstatinfo;
int fildes; int fildes;
@@ -90,7 +87,8 @@ int create_file_safely (const char *filename, unsigned int truncate_file)
*/ */
if ((fildes = if ((fildes =
open(filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) { open(filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) {
fprintf (stderr, "%s: Could not create file %s: %s\n", fprintf(stderr,
"%s: Could not create file %s: %s\n",
PACKAGE, filename, strerror(errno)); PACKAGE, filename, strerror(errno));
return fildes; return fildes;
} }
@@ -136,8 +134,7 @@ int create_file_safely (const char *filename, unsigned int truncate_file)
*/ */
if (fstatinfo.st_nlink > 1 || !S_ISREG(lstatinfo.st_mode)) { if (fstatinfo.st_nlink > 1 || !S_ISREG(lstatinfo.st_mode)) {
fprintf(stderr, fprintf(stderr,
"%s: The file %s has too many links, " "%s: The file %s has too many links, or is not a regular file: %s\n",
"or is not a regular file: %s\n",
PACKAGE, filename, strerror(errno)); PACKAGE, filename, strerror(errno));
close(fildes); close(fildes);
return -EMLINK; return -EMLINK;
@@ -159,15 +156,13 @@ int create_file_safely (const char *filename, unsigned int truncate_file)
* ("Little sympathy has been extended") * ("Little sympathy has been extended")
*/ */
#ifdef HAVE_FTRUNCATE #ifdef HAVE_FTRUNCATE
if (ftruncate (fildes, 0) != 0) { ftruncate(fildes, 0);
log_message (LOG_WARNING,
"Unable to truncate file '%s'", filename);
}
#else #else
close(fildes); close(fildes);
if ((fildes = if ((fildes =
open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) { open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) {
fprintf (stderr, "%s: Could not open file %s: %s.", fprintf(stderr,
"%s: Could not open file %s: %s.",
PACKAGE, filename, strerror(errno)); PACKAGE, filename, strerror(errno));
return fildes; return fildes;
} }
@@ -177,14 +172,9 @@ int create_file_safely (const char *filename, unsigned int truncate_file)
return fildes; return fildes;
} }
/** /*
* pidfile_create: * Write the PID of the program to the specified file.
* @filename: The name of the file which should be created. */
*
* Creates a file with the PID of the Tinyproxy process.
*
* Returns: %0 on success, non-zero values on errors.
**/
int int
pidfile_create(const char *filename) pidfile_create(const char *filename)
{ {
@@ -209,7 +199,7 @@ pidfile_create (const char *filename)
return -EIO; return -EIO;
} }
fprintf (fd, "%d\n", getpid ()); fprintf(fd, "%ld\n", (long) getpid());
fclose(fd); fclose(fd);
return 0; return 0;
} }
+14 -18
View File
@@ -1,24 +1,21 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: utils.h,v 1.23 2003-03-13 21:34:37 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 'utils.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) 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 'utils.c' for detailed information. */
#ifndef TINYPROXY_UTILS_H #ifndef TINYPROXY_UTILS_H
#define TINYPROXY_UTILS_H #define TINYPROXY_UTILS_H
@@ -31,7 +28,6 @@ extern int send_http_message (struct conn_s *connptr, int http_code,
const char *error_title, const char *message); const char *error_title, const char *message);
extern int pidfile_create(const char *path); extern int pidfile_create(const char *path);
extern int create_file_safely (const char *filename, extern int create_file_safely(const char *filename, unsigned int truncate_file);
unsigned int truncate_file);
#endif #endif
+27 -21
View File
@@ -1,5 +1,10 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: vector.c,v 1.9 2003-05-30 16:21:48 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net> *
* A vector implementation. The vector can be of an arbitrary length, and
* the data for each entry is an lump of data (the size is stored in the
* vector.)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -11,17 +16,12 @@
* 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
*/ */
/* A vector implementation. The vector can be of an arbitrary length, and #include "tinyproxy.h"
* the data for each entry is an lump of data (the size is stored in the
* vector.)
*/
#include "main.h"
#include "heap.h" #include "heap.h"
#include "vector.h" #include "vector.h"
@@ -53,11 +53,12 @@ struct vector_s {
* A NULL is returned if memory could not be allocated for the * A NULL is returned if memory could not be allocated for the
* vector. * vector.
*/ */
vector_t vector_create (void) vector_t
vector_create(void)
{ {
vector_t vector; vector_t vector;
vector = (vector_t) safemalloc (sizeof (struct vector_s)); vector = safemalloc(sizeof(struct vector_s));
if (!vector) if (!vector)
return NULL; return NULL;
@@ -73,7 +74,8 @@ vector_t vector_create (void)
* Returns: 0 on success * Returns: 0 on success
* negative if a NULL vector is supplied * negative if a NULL vector is supplied
*/ */
int vector_delete (vector_t vector) int
vector_delete(vector_t vector)
{ {
struct vectorentry_s *ptr, *next; struct vectorentry_s *ptr, *next;
@@ -107,7 +109,8 @@ int vector_delete (vector_t vector)
#define INSERT_PREPEND 0 #define INSERT_PREPEND 0
#define INSERT_APPEND 1 #define INSERT_APPEND 1
static int vector_insert (vector_t vector, void *data, size_t len, int pos) static int
vector_insert(vector_t vector, void *data, ssize_t len, int pos)
{ {
struct vectorentry_s *entry; struct vectorentry_s *entry;
@@ -115,8 +118,7 @@ static int vector_insert (vector_t vector, void *data, size_t len, int pos)
(pos != INSERT_PREPEND && pos != INSERT_APPEND)) (pos != INSERT_PREPEND && pos != INSERT_APPEND))
return -EINVAL; return -EINVAL;
entry = entry = safemalloc(sizeof(struct vectorentry_s));
(struct vectorentry_s *) safemalloc (sizeof (struct vectorentry_s));
if (!entry) if (!entry)
return -ENOMEM; return -ENOMEM;
@@ -153,12 +155,14 @@ static int vector_insert (vector_t vector, void *data, size_t len, int pos)
* can see they simply call the vector_insert() function with appropriate * can see they simply call the vector_insert() function with appropriate
* arguments. * arguments.
*/ */
int vector_append (vector_t vector, void *data, size_t len) int
vector_append(vector_t vector, void *data, ssize_t len)
{ {
return vector_insert(vector, data, len, INSERT_APPEND); return vector_insert(vector, data, len, INSERT_APPEND);
} }
int vector_prepend (vector_t vector, void *data, size_t len) int
vector_prepend(vector_t vector, void *data, ssize_t len)
{ {
return vector_insert(vector, data, len, INSERT_PREPEND); return vector_insert(vector, data, len, INSERT_PREPEND);
} }
@@ -170,7 +174,8 @@ int vector_prepend (vector_t vector, void *data, size_t len)
* Returns: negative upon an error * Returns: negative upon an error
* length of data if position is valid * length of data if position is valid
*/ */
void *vector_getentry (vector_t vector, size_t pos, size_t * size) void *
vector_getentry(vector_t vector, size_t pos, size_t* size)
{ {
struct vectorentry_s *ptr; struct vectorentry_s *ptr;
size_t loc; size_t loc;
@@ -198,7 +203,8 @@ void *vector_getentry (vector_t vector, size_t pos, size_t * size)
* Returns: negative if vector is not valid * Returns: negative if vector is not valid
* positive length of vector otherwise * positive length of vector otherwise
*/ */
ssize_t vector_length (vector_t vector) ssize_t
vector_length(vector_t vector)
{ {
if (!vector) if (!vector)
return -EINVAL; return -EINVAL;
+21 -9
View File
@@ -1,5 +1,10 @@
/* tinyproxy - A fast light-weight HTTP proxy /* $Id: vector.h,v 1.4.2.1 2003-08-06 20:46:04 rjkaes Exp $
* Copyright (C) 2002 Robert James Kaes <rjkaes@users.sourceforge.net> *
* A vector implementation. The vector can be of an arbritrary length, and
* the data for each entry is an lump of data (the size is stored in the
* vector.)
*
* Copyright (C) 2002 Robert James Kaes (rjkaes@flarenet.com)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -11,16 +16,19 @@
* 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
*/ */
/* See 'vector.c' for detailed information. */
#ifndef _VECTOR_H #ifndef _VECTOR_H
#define _VECTOR_H #define _VECTOR_H
/* Allow the use in C++ code. */
#if defined(__cplusplus)
extern "C" {
#endif
/* /*
* We're using a typedef here to "hide" the implementation details of the * We're using a typedef here to "hide" the implementation details of the
* vector. Sure, it's a pointer, but the struct is hidden in the C file. * vector. Sure, it's a pointer, but the struct is hidden in the C file.
@@ -43,8 +51,8 @@ extern int vector_delete (vector_t vector);
* Returns: negative on error * Returns: negative on error
* 0 upon successful insert. * 0 upon successful insert.
*/ */
extern int vector_append (vector_t vector, void *data, size_t len); extern int vector_append(vector_t vector, void *data, ssize_t len);
extern int vector_prepend (vector_t vector, void *data, size_t len); extern int vector_prepend(vector_t vector, void *data, ssize_t len);
/* /*
* A pointer to the data at position "pos" (zero based) is returned and the * A pointer to the data at position "pos" (zero based) is returned and the
@@ -72,4 +80,8 @@ extern void *vector_getentry (vector_t vector, size_t pos, size_t * size);
*/ */
extern ssize_t vector_length(vector_t vector); extern ssize_t vector_length(vector_t vector);
#if defined(__cplusplus)
}
#endif /* C++ */
#endif /* _VECTOR_H */ #endif /* _VECTOR_H */
-1
View File
@@ -1 +0,0 @@
SUBDIRS = scripts
Loaded 100 of 106 files, more files were not shown because too many files have changed in this diff. Show more