Compare commits

...
42 Commits
Author SHA1 Message Date
cvs2svn 0895438900 This commit was manufactured by cvs2svn to create tag 'rel_1-4-3'. 2001-11-21 19:35:53 +00:00
cvs2svn ad99033ae4 This commit was manufactured by cvs2svn to create branch
'release_1_4_3_patches'.
2001-11-21 19:35:52 +00:00
Robert James Kaes 757d341d96 Bumped the version number to release status. 2001-11-21 19:35:51 +00:00
Robert James Kaes b92e2fc457 New NEWS file read for release. 2001-11-21 19:35:22 +00:00
Robert James Kaes a30eb425e3 #if 0'd the code handling the "Via" header in the process_client_headers()
function since I'm not completely happy with the code.
2001-11-21 19:19:46 +00:00
Robert James Kaes bc8c3ff399 Include the protocol variables in the conn_s structure. 2001-11-21 01:00:09 +00:00
Robert James Kaes 90ee7e01ca Extract the version from the request line and store it in the conn_s
structure.
Don't send a Connection header to the remote connection.
Handle the Via header correctly.
2001-11-21 00:59:33 +00:00
Robert James Kaes dde4e9adcc Changed the read() call into a recv() call with a flag of NOSIGNAL since I
don't want signals messing up my calling conventions.
2001-11-12 21:10:51 +00:00
Robert James Kaes 99488cbd5e Added profiling flags to the DEBUG version of CFLAGS. 2001-11-05 15:25:39 +00:00
Robert James Kaes fffdc76681 Made is_anonymous_enabled() an inline function. 2001-11-05 15:24:42 +00:00
Robert James Kaes d2f2750a37 Added a clean rule to remove the gprof files. 2001-11-05 15:24:01 +00:00
Robert James Kaes ddb002d57e Replaced all calls to buffer_size() with the macro BUFFER_SIZE(). 2001-11-05 15:23:34 +00:00
Robert James Kaes 270af08171 Removed the buffer_size() function and turned it into BUFFER_SIZE() macro.
Moved the struct buffer_s into the header file. Added more assert() calls
to better document the assumptions the functions make. Removed incorrect
code in remove_from_buffer() which was never actually called anyway.
2001-11-05 15:23:05 +00:00
Robert James Kaes 3d9a64d54e ACL fixes. Use a better differentiation between string and numeric
addresses.
2001-11-03 06:10:08 +00:00
Robert James Kaes 9f0c8f18fb Tightened the string/numeric ACL checks. 2001-11-03 06:08:37 +00:00
Robert James Kaes e61424a7bf Informing the user of the connection to the tunnel is a INFO type message,
not a CONN level message.
2001-11-02 21:19:46 +00:00
Robert James Kaes 4680546c65 Removed all the aclocal.m4, acconfig.h, etc. files since they are included
automatically by the autoconf scripts.
2001-10-26 03:09:18 +00:00
Robert James Kaes 84ff99013a No longer needs the file. When somebody helps with tinyproxy they will be
thanked in the ChangeLog entry relating to the problem solved.
2001-10-26 03:04:30 +00:00
Robert James Kaes 4ecb6d1a3d Changes reflecting the new conns.* files and the organization of the
header files.
2001-10-25 17:39:52 +00:00
Robert James Kaes 4ac03908fc Header reorganization. Basically all system headers are now included in
tinyproxy.h and all the other files include the tinyproxy.h header. This
moves all the dependancy issues into one file.
2001-10-25 17:27:39 +00:00
Robert James Kaes 722a7d2142 Changed the included headers to be only the "tinyproxy.h" since it
contains all the code for properly bringing in the system headers (in the
correct order and with proper dependancies.)
2001-10-25 17:02:50 +00:00
Robert James Kaes d3b099140f Some code clean up due to the creation of the conns.{c,h} files which now
store the creation/destruction and definition of the connection structure.
2001-10-25 16:58:50 +00:00
Robert James Kaes f8ad0dced3 Moved the connection creation/destruction and definition into it's own
files.
2001-10-25 16:58:09 +00:00
Robert James Kaes ecbcc332cc Updated the news file. 2001-10-25 16:35:27 +00:00
Robert James Kaes e820fecf53 Fixed a few spelling problems and added additional information regarding
the new configure arguments and information about the mailing lists.
2001-10-25 16:28:24 +00:00
Robert James Kaes ff95117d9d Moved the code to include the TODO file into the top level Makefile.am 2001-10-25 16:17:14 +00:00
Robert James Kaes 70ce1cda1f Moving the TODO list from the doc directory to the root directory so that
it's more visible.
2001-10-25 16:16:32 +00:00
Robert James Kaes 274d7730ca Bumped up the pre-version. 2001-10-25 05:13:46 +00:00
Robert James Kaes 2da1378f53 Changes to reflect the various fixes to have CONNECT upstream proxying
work.
2001-10-25 05:13:18 +00:00
Robert James Kaes 1bbf32f04c Fixed the problems with sending/not sending headers so that the CONNECT
(SSL) method would work with upstream proxying!
2001-10-25 05:12:46 +00:00
Robert James Kaes 28b4477f48 Added the upstream flag to the conn_s structure. 2001-10-25 05:10:57 +00:00
Robert James Kaes 5f8ee4fae3 Bit of source code clean up. 2001-10-25 05:10:32 +00:00
Robert James Kaes 3e91392c8a More changes to reqs.c and buffer.c 2001-10-25 04:42:32 +00:00
Robert James Kaes 6afa56ba09 Changed the way relay_connection() works by having the both buffers
emptied when either socket is closed. This should be better for the tunnel
connections.
Change the connect_to_upstream() function to better utilize the
establish_http_connection() function. Code re-use is cool. :)
2001-10-25 04:40:48 +00:00
Robert James Kaes f8d43bd423 Lowered the size of the read buffer to 2K since Ethernet seems to work
with 1400 byte segments.
2001-10-25 04:39:10 +00:00
Robert James Kaes b7b4d08758 Error message cleanup to make the information more informative. 2001-10-24 00:37:23 +00:00
Robert James Kaes 7d7958b0d7 Fixed a spelling problem in a log message. 2001-10-23 16:43:08 +00:00
Robert James Kaes 98ffd0a3fe Update to reflect the current maintainer (Robert) again. 2001-10-23 15:46:43 +00:00
Robert James Kaes d090c02476 New changes to getpeer_string(). 2001-10-23 03:58:40 +00:00
Robert James Kaes a746b9d0b2 Moved the zero-length string setting to outside the tests in getpeer_*()
functions. Also added a more robust error reporting for DNS errors.
2001-10-23 03:57:34 +00:00
Robert James Kaes 56a9766529 Hopefully cleaned up the source a bit. 2001-10-23 03:55:39 +00:00
Robert James Kaes 1abc300112 Cleaned up the file and added the request for a more consistent error
system.
2001-10-23 03:55:01 +00:00
33 changed files with 555 additions and 363 deletions

No files matched your search

+4 -1
View File
@@ -3,7 +3,10 @@
From versions 0-1.1, Steven Young was the primary maintainer.
From 1.2 to 1.3.0, Robert James Kaes was the primary maintainer.
As of 1.3.1, Steven Young will once again be the primary maintainer.
As of 1.3.1, Steven Young was once again be the primary maintainer.
But, Robert James Kaes was again the maintainer starting with 1.4.0.
Place your bets as to when the maintainer will change again. :) Kidding!
Please see the ChangeLog for futher details as to who did what. :)
+50
View File
@@ -1,5 +1,55 @@
2001-11-03 Robert James Kaes <rjkaes@flarenet.com>
* src/buffer.c (remove_from_buffer): This function is never
called with an empty buffer, so removed some inaccurate code which
would have removed an invalid line from the buffer if it was
empty. What was I thinking when I wrote that? Good thing is was
never called.
(add_to_buffer): Add a bit of a sanity check to make sure the
buffer structure hasn't been messed up some how.
2001-11-02 Robert James Kaes <rjkaes@flarenet.com>
* src/acl.c (insert_acl): Tightened the check regarding whether an
ACL is a string or a numeric address.
2001-10-25 Robert James Kaes <rjkaes@flarenet.com>
* Moved all the system header included into the tinyproxy.h header
and changed all the other files to include it. This should
centralise the header dependency issue into one file.
* src/conns.c: Brought back the conns.{c,h} files which contain
the connection structure definition plus the creation/destruction
routines.
* src/reqs.c (process_client_headers): Selectively send headers
based on whether we're using an upstream with a CONNECT
request. The short answer: all methods work correctly with
Upstream proxying and normal proxying.
* src/tinyproxy.h: Added a upstream flag to the conn_s structure
so we can figure out when to send headers and when not to send
headers. This is extremely important when trying to do upstream
proxying of the CONNECT method.
* src/reqs.c (relay_connection): Empty the contents of both
buffers when either socket is closed. This is more in line with
what a tunnel should do. Since either end could close with
information still in the buffers.
(connect_to_upstream): Cleaned up the code to re-use the
establish_http_connection() function.
* src/buffer.c (readbuff): Changed the memory allocation to 2K
from 48K since an Ethernet connection is usually around 1400
bytes. There's little point in allocating a huge amount of memory,
only to shrink the memory map in the next breath.
2001-10-22 Robert James Kaes <rjkaes@flarenet.com>
* src/sock.c (getpeer_string): Added logging in case the
gethostbyaddr() function fails.
* src/reqs.c (free_request_struct): Added a test to return if the
pointer is NULL.
(handle_connection): Cleaned up the code to better handle the
+1 -1
View File
@@ -1,2 +1,2 @@
EXTRA_DIST = configure acconfig.h aclocal.m4 acinclude.m4
EXTRA_DIST = TODO
SUBDIRS = src doc
+29 -20
View File
@@ -1,26 +1,35 @@
Tuesday, September 4, 2001
--------------------------
I finally fixed a problem with the anonymous header code. The searches
are now all case insensitive. This fixes a problem where the spelling
of the HTTP headers could be different. It also helps with various
spellings of domain names. There is also a security fix for a format
string problem with the syslog feature. This problem doesn't affect
you if you use the log file instead.
NEWS
====
-- Robert
There are a few problems with this version of tinyproxy, but I'm hoping
the benefits outweigh the negative. For some reason tinyproxy is not
able to handle requests to *.x10.com sites. (As someone mentioned: "maybe
this is a feature?" :) There also seem to be a few other random sites
where tinyproxy is not communicating with the server correctly. If you
find any such sites, let me know so I can add it to the list of domains
where tinyproxy is failing. I'll need this information for the regression
tests I plan on performing on the next release.
As for the next release (1.5.0), I will not be adding new features.
tinyproxy doesn't currently conform correctly to either the HTTP/1.0
or the HTTP/1.1 standards. The goal of the 1.5 release therefore is
to achieve standards compliance with at least HTTP/1.0. If you have
looked at the tinyproxy code you will have noticed that all the real
work of the proxy is performed in the reqs.c file. Therefore, other
than bug fixes in the other files, only reqs.c should be changed in
the 1.5.0 release. Basically, I'm hoping to just gut and replace the
reqs.c file with a standards compliant version and release a new version.
Thursday, August 30, 2001
-------------------------
Depending on my schedule I should have the new version ready for
pre-testing sometime next week. If you have any suggestions for improving
tinyproxy please let me know, but I will not be incorporating them until
1.6 (which _hopefully_ should come out fairly quickly after 1.5 has
stabilised.)
Maybe I just shouldn't be working on the code base this week. The
memory fix I added in the last release contained a serious bug which
would cause a segmentation fault. I actually fixed this by removing
the code I added and just fixing the problem in ternary_insert()
instead. I don't know why I didn't do this in the first place. I also
removed the xstrstr() function since strstr() will do what tinyproxy
needs. Removing code is _always_ a good idea. Less code, less chance
of bugs.
"Thank you" go out to all who have helped find bugs in the 1.4.3
candidates. You know who you are, and if you don't look in the ChangeLog
for your name. :)
-- Robert
Robert James Kaes
November 21, 2001
+29 -10
View File
@@ -19,9 +19,14 @@
------------
To install this package under a Unix derivative, read the INSTALL
file. tinyproxy uses a standard GNU configure script. There are
additional command line arguments you can supply to configure. They
include:
file. tinyproxy uses a standard GNU configure script (basically you
should be able to do:
./configure ; make ; make install
in the top level directory to compile and install tinyproxy). There
are additional command line arguments you can supply to configure.
They include:
--enable-debug If you would like to turn on full
debugging support
@@ -35,6 +40,10 @@
--enable-tunnel Provides the option of having
tinyproxy act as TCP tunnel, rather
than a HTTP proxy.
--enable-upstream Enable support for proxying connections
through another proxy server.
--enable-static Compile a static version of tinyproxy
Options for file locations etc.
--with-stathost=HOST Set the default name of the stats host
@@ -46,28 +55,38 @@
directory. This will send an email to the authors reporting your
version, and a few bits of information concerning the memory usage of
tinyproxy. Alternatively, you could just send an email stating the
version. Which ever you prefer.
version, whichever you prefer.
SUPPORT
-------
If you are having problems with tinyproxy, please report the problem
to:
to either:
Robert James Kaes <rjkaes@users.sourceforge.net>
Steven Young <sdyoung@users.sourceforge.net>
You may also wish to subscribe to the tinyproxy-user mailing list. To
do so please visit:
http://lists.sourceforge.net/lists/listinfo/tinyproxy-users
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. 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:
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) set args -c location_of_tinyproxy_conf -d
(gdb) run
(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:
-45
View File
@@ -1,45 +0,0 @@
Tinyproxy wouldn't be possible in its current form without the help of
the following people. Thanks a lot, guys (sorted in no particular
order). Note that in the case of entries listed under 'numerous others',
only the first person to report it is listed.
Steven Young - Wrote version 1.0 - 1.1
Robert James Kaes - Wrote versions from 1.2 to 1.3 and
autoconf enabled the source tree and
well just look at the ChangeLog for all
the rest. :)
Albert Ragnarsson - Made an RPM out of the 1.0d .tar.gz archive.
Alan W Black - Misc. bug reports and fixes.
Ed Boraas - Various suggestions, helped beta test 1.0d.
Abhijit Menon-Sen - Beta tested 1.1, numerous bugs fixed
and features improved. Also helped
establish world peace and eliminate
hunger and poverty. Generally
credited with the singlehanded
abolition of all crime and dishonesty.
Jay Kominek - Made the 1.1 DEB.
Eran Tromer - Provided webspace at attacca.com.
Bruno Viaris - Found and provided initial fix for
bug in the clientreq() routine when
dealing with broken requests from clients.
Alexander Loehr - Found and provided fix for a bug in
the listen_sock routine.
Bob Grabau - Added additional logging of URLs to
incoming connections.
Mitsuru Yoshida - Made the FreeBSD port
Ian Holsman - Suggested the selective listening option
Peter Meerwald - Portability suggests and improvements
Shaun Johnson - Fixed a problem with compiling with
syslog enabled on a SunOS box. Should
help other systems too.
Timothy E. Newsome - SOCKS firewall enabled tinyproxy
George Talusan - Bug testing
Chris Lightfoot - Provided patches to give tinyproxy adns
support.
Michael Pearson - Reported connptr bug with patch.
Raja Subramanian - Reported fd leak bug, with patch.
J.D. Bronson - Helped make version 1.4.0 release ready
Hans-Georg Bork - Fixed a problem with the thread_main()
function and added the LOG_CONN log level.
numerous others - Reported null requests bug.
+43
View File
@@ -0,0 +1,43 @@
TODO List
---------
The following are features that I would like to add to tinyproxy in the
future. Where possible, I've listed the person who suggested it. This
list is in no particular order. And hey, if you want to implement one of
these, or another idea you have, go right ahead. Just mail me the diff
against the current tree and I'll integrate it if possible.
[ Actually, the ordering has become kind of important as of
late. Basically, I'm adding new ideas to the bottom of the list
as I go. ]
* Include hooks so other types of proxies can be modularly added to
the source tree. Then people can simply choose which types of
proxies (ftp, www, etc) they'd like enabled in tinyproxy.h
Suggested: Tarun Tuli.
* Find a more elegant solution to embedding HTML documents in the
source than the current method. (see httperr() and showstats() for
examples of how it's done right now).
* Include a function to rewrite the incoming requests. Should not be
much of a problem. Just need to modify the process_method() code
to look up the URL and rewrite it. If we want to go really fancy
with RegEx mapping this could get ugly. :)
* Have the ability to send the data from the connections through an
external filtering program. I kind of like this idea, but I don't
really have a good way of doing it yet.
Suggested: Ed Avis
* Include the ability to rewrite both incoming and outgoing headers.
* Enable an option for chroot() jailing tinyproxy.
* Add an option which allows the blocking of connections to certain
ports (like 25, 110, etc.) that might be used for "bad" things. :)
* Come up with a more consistent (and elegant) way of logging errors
for the administrators. Right now it's more a hodge-podge
collections of error messages without a _real_ standard. I would
prefer a more uniform look.
+3 -2
View File
@@ -1,4 +1,4 @@
dnl $Id: configure.in,v 1.32 2001-10-22 21:30:18 rjkaes Exp $
dnl $Id: configure.in,v 1.35 2001-11-21 19:35:51 rjkaes Exp $
dnl Devlopers, please strive to achieve this order:
dnl
@@ -19,7 +19,7 @@ AC_INIT()
AC_CANONICAL_SYSTEM
AC_DEFINE_UNQUOTED(TARGET_SYSTEM, "$target")
AM_INIT_AUTOMAKE(tinyproxy,1.4.3pre6)
AM_INIT_AUTOMAKE(tinyproxy,1.4.3)
AM_CONFIG_HEADER(config.h)
dnl
@@ -253,6 +253,7 @@ CFLAGS="-O2 $CFLAGS"
if test "$enable_debug" = "yes" ; then
dnl Add the warnings if we have the GCC compiler
if test "$ac_cv_prog_gcc" = "yes" ; then
CFLAGS="-pg -fprofile-arcs $CFLAGS"
CFLAGS="-Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes $CFLAGS"
CFLAGS="-Wmissing-prototypes -Wmissing-declarations $CFLAGS"
CFLAGS="-Wpointer-arith -Waggregate-return -Wnested-externs $CFLAGS"
+1 -1
View File
@@ -1,2 +1,2 @@
EXTRA_DIST = tinyproxy.8 tinyproxy.conf HTTP_ERROR_CODES RFC_INFO TODO report.sh
EXTRA_DIST = tinyproxy.8 tinyproxy.conf HTTP_ERROR_CODES RFC_INFO report.sh
man_MANS = tinyproxy.8
-25
View File
@@ -1,25 +0,0 @@
The following are some features that I'd like to add to tinyproxy in the
future. Where possible, I've listed the person who suggested it. This
list is in no particular order. And hey, if you want to implement one of
these, or another idea you have, go right ahead. Just mail me the diff
against the current tree and I'll integrate it if possible.
- Include hooks so other types of proxies can be modularly added to
the source tree. Then people can simply choose which types of
proxies (ftp, www, etc) they'd like enabled in tinyproxy.h
Suggested: Tarun Tuli.
- Find a more elegant solution to embedding HTML documents in the
source than the current method. (see httperr() and showstats() for
examples of how it's done right now).
- Include a function to rewrite the incoming requests. Should not be
much of a problem. Just need to modify the process_method() code
to look up the URL and rewrite it. If we want to go really fancy
with RegEx mapping this could get ugly. :)
- Have the ability to send the data from the connections through an
external filtering program. I kind of like this idea, but I don't
really have a good way of doing it yet.
Suggested: Ed Avis
- Include the ability to rewrite both incoming and outgoing headers.
- Enable an option for chroot() jailing tinyproxy.
- Add an option which allows the blocking of connections certain ports
(like 25, 110, etc.) that might be used for "bad" things. :)
+1 -1
View File
@@ -5,7 +5,7 @@ date
echo "uname: "
uname -a
echo "ps: "
ps -auxw | grep [t]inyproxy -
ps -auxw | grep '[t]inyproxy' -
echo "ver: "
if [ -x /usr/local/bin/tinyproxy ]; then
/usr/local/bin/tinyproxy -v
+6 -1
View File
@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.5 2001-10-01 04:01:10 rjkaes Exp $
# $Id: Makefile.am,v 1.7 2001-11-05 15:24:01 rjkaes Exp $
#
#
#
@@ -21,6 +21,7 @@ LDFLAGS = @LDFLAGS@
bin_PROGRAMS = tinyproxy
tinyproxy_SOURCES = \
conns.c conns.h \
buffer.c buffer.h \
dnscache.c dnscache.h \
log.c log.h \
@@ -45,3 +46,7 @@ EXTRA_tinyproxy_SOURCES = grammar.h
scanner.c: scanner.l grammar.h
$(LEX) $(AM_LFLAGS) $(LFLAGS) -i $< && mv $(LEX_OUTPUT_ROOT).c $@
clean:
rm -f *.da
rm -f gmon.out
+13 -8
View File
@@ -1,4 +1,4 @@
/* $Id: acl.c,v 1.8 2001-09-15 21:21:01 rjkaes Exp $
/* $Id: acl.c,v 1.10 2001-11-03 06:08:37 rjkaes Exp $
*
* 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
@@ -19,8 +19,6 @@
#include "tinyproxy.h"
#include <ctype.h>
#include "acl.h"
#include "log.h"
#include "sock.h"
@@ -79,8 +77,11 @@ int insert_acl(char *location, acl_access_t access_type)
/*
* First check to see if the location is a string or numeric.
*/
for (i = 0; i < strlen((char *)location); i++) {
if (isdigit((unsigned char)location[i]) != 0 && location[i] != '.') {
for (i = 0; location[i] != '\0'; i++) {
/*
* Numeric strings can not contain letters, so test on it.
*/
if (isalpha((unsigned char)location[i])) {
break;
}
}
@@ -101,9 +102,11 @@ int insert_acl(char *location, acl_access_t access_type)
new_acl_ptr->acl_access = access_type;
if (i != strlen(location)) {
if (location[i] == '\0') {
DEBUG2("ACL \"%s\" is a number.", location);
/*
* We did break early, so this a numeric location.
* We did not break early, so this a numeric location.
* Check for a netmask.
*/
new_acl_ptr->type = ACL_NUMERIC;
@@ -111,7 +114,7 @@ int insert_acl(char *location, acl_access_t access_type)
if (nptr) {
*nptr++ = '\0';
new_acl_ptr->netmask = atoi(nptr);
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;
@@ -120,6 +123,8 @@ int insert_acl(char *location, acl_access_t access_type)
new_acl_ptr->netmask = 32;
}
} else {
DEBUG2("ACL \"%s\" is a string.", location);
new_acl_ptr->type = ACL_STRING;
new_acl_ptr->netmask = 32;
}
+3 -11
View File
@@ -1,4 +1,4 @@
/* $Id: anonymous.c,v 1.6 2001-08-26 21:07:27 rjkaes Exp $
/* $Id: anonymous.c,v 1.8 2001-11-05 15:24:42 rjkaes Exp $
*
* Handles insertion and searches for headers which should be let through when
* the anonymous feature is turned on. The headers are stored in a Ternary
@@ -18,15 +18,7 @@
* General Public License for more details.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include "tinyproxy.h"
#include "anonymous.h"
#include "log.h"
@@ -40,7 +32,7 @@ static TERNARY anonymous_tree = 0;
*/
static short int anonymous_is_enabled = 0;
short int is_anonymous_enabled(void)
inline short int is_anonymous_enabled(void)
{
return anonymous_is_enabled;
}
+59 -65
View File
@@ -1,4 +1,4 @@
/* $Id: buffer.c,v 1.12 2001-10-18 21:45:54 rjkaes Exp $
/* $Id: buffer.c,v 1.15 2001-11-05 15:23:05 rjkaes Exp $
*
* 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,
@@ -27,8 +27,8 @@
#include "log.h"
#include "utils.h"
#define BUFFER_HEAD(x) (((struct buffer_s *)(x))->head)
#define BUFFER_TAIL(x) (((struct buffer_s *)(x))->tail)
#define BUFFER_HEAD(x) (x)->head
#define BUFFER_TAIL(x) (x)->tail
struct bufline_s {
unsigned char *string; /* the actual string of data */
@@ -37,31 +37,18 @@ struct bufline_s {
size_t pos; /* start sending from this offset */
};
struct buffer_s {
struct bufline_s *head; /* top of the buffer */
struct bufline_s *tail; /* bottom of the buffer */
size_t size; /* total size of the buffer */
};
/*
* Return the size of the supplied buffer.
*/
size_t buffer_size(struct buffer_s *buffptr)
{
assert(buffptr != NULL);
return buffptr->size;
}
/*
* Take a string of data and a length and make a new line which can be added
* to the buffer
* to the buffer. We don't make a copy of the data, but simply copy the
* pointer into the structure. In other words, when you insert data into the
* buffer, the buffer becomes responsible for freeing it.
*/
static struct bufline_s *makenewline(unsigned char *data, size_t length)
{
struct bufline_s *newline;
assert(data != NULL);
assert(length > 0);
if (!(newline = safemalloc(sizeof(struct bufline_s))))
return NULL;
@@ -69,6 +56,8 @@ static struct bufline_s *makenewline(unsigned char *data, size_t length)
newline->string = data;
newline->next = NULL;
newline->length = length;
/* Position our "read" pointer at the beginning of the data */
newline->pos = 0;
return newline;
@@ -100,8 +89,13 @@ struct buffer_s *new_buffer(void)
if (!(buffptr = safemalloc(sizeof(struct buffer_s))))
return NULL;
buffptr->head = buffptr->tail = NULL;
buffptr->size = 0;
/*
* Since the buffer is initially empty, set the HEAD and TAIL
* pointers to NULL since they can't possibly point anywhere at the
* moment.
*/
BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = NULL;
BUFFER_SIZE(buffptr) = 0;
return buffptr;
}
@@ -120,8 +114,6 @@ void delete_buffer(struct buffer_s *buffptr)
free_line(BUFFER_HEAD(buffptr));
BUFFER_HEAD(buffptr) = next;
}
BUFFER_HEAD(buffptr) = NULL;
BUFFER_TAIL(buffptr) = NULL;
safefree(buffptr);
}
@@ -136,43 +128,46 @@ static int add_to_buffer(struct buffer_s *buffptr, unsigned char *data,
assert(buffptr != NULL);
assert(data != NULL);
assert(length > 0);
/*
* Sanity check here. A buffer with a non-NULL head pointer must
* have a size greater than zero, and vice-versa.
*/
if (BUFFER_HEAD(buffptr) == NULL)
assert(BUFFER_SIZE(buffptr) == 0);
else
assert(BUFFER_SIZE(buffptr) > 0);
/*
* Make a new line so we can add it to the buffer.
*/
if (!(newline = makenewline(data, length)))
return -1;
if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr))
if (BUFFER_SIZE(buffptr) == 0)
BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = newline;
else
BUFFER_TAIL(buffptr) = (BUFFER_TAIL(buffptr)->next = newline);
buffptr->size += length;
BUFFER_SIZE(buffptr) += length;
return 0;
}
/*
* Shift a line off the top of the buffer (remove the 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)
{
struct bufline_s *line;
assert(buffptr != NULL);
if (!BUFFER_HEAD(buffptr) && !BUFFER_TAIL(buffptr)) {
line = BUFFER_HEAD(buffptr);
BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = NULL;
buffptr->size = 0;
return line;
}
assert(BUFFER_HEAD(buffptr) != NULL);
line = BUFFER_HEAD(buffptr);
BUFFER_HEAD(buffptr) = line->next;
if (!BUFFER_HEAD(buffptr))
BUFFER_TAIL(buffptr) = NULL;
buffptr->size -= line->length;
return line;
@@ -182,6 +177,7 @@ static struct bufline_s *remove_from_buffer(struct buffer_s *buffptr)
* Reads the bytes from the socket, and adds them to the buffer.
* Takes a connection and returns the number of bytes read.
*/
#define READ_BUFFER_SIZE (1024 * 2)
ssize_t readbuff(int fd, struct buffer_s *buffptr)
{
ssize_t bytesin;
@@ -191,14 +187,14 @@ ssize_t readbuff(int fd, struct buffer_s *buffptr)
assert(fd >= 0);
assert(buffptr != NULL);
if (buffer_size(buffptr) >= MAXBUFFSIZE)
if (BUFFER_SIZE(buffptr) >= READ_BUFFER_SIZE)
return 0;
buffer = safemalloc(MAXBUFFSIZE);
buffer = safemalloc(READ_BUFFER_SIZE);
if (!buffer)
return 0;
bytesin = read(fd, buffer, MAXBUFFSIZE - buffer_size(buffptr));
bytesin = read(fd, buffer, READ_BUFFER_SIZE - BUFFER_SIZE(buffptr));
if (bytesin > 0) {
newbuffer = saferealloc(buffer, bytesin);
@@ -208,31 +204,31 @@ ssize_t readbuff(int fd, struct buffer_s *buffptr)
}
if (add_to_buffer(buffptr, newbuffer, bytesin) < 0) {
log_message(LOG_ERR, "readbuff: add_to_buffer() error.");
return -1;
}
return bytesin;
} else if (bytesin == 0) {
/* connection was closed by client */
safefree(buffer);
return -1;
} else {
switch (errno) {
safefree(buffer);
if (bytesin == 0) {
/* connection was closed by client */
return -1;
} else {
switch (errno) {
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
case EWOULDBLOCK:
#else
# ifdef EAGAIN
case EAGAIN:
case EAGAIN:
# endif
#endif
case EINTR:
safefree(buffer);
return 0;
default:
log_message(LOG_ERR, "recv error (fd %d: %s:%d) in 'readbuff'.",
fd, strerror(errno), errno);
safefree(buffer);
return -1;
case EINTR:
return 0;
default:
log_message(LOG_ERR, "readbuff: recv() error \"%s\" on file descriptor %d", strerror(errno), fd);
return -1;
}
}
}
}
@@ -249,11 +245,13 @@ ssize_t writebuff(int fd, struct buffer_s *buffptr)
assert(fd >= 0);
assert(buffptr != NULL);
line = BUFFER_HEAD(buffptr);
if (buffer_size(buffptr) <= 0)
if (BUFFER_SIZE(buffptr) == 0)
return 0;
/* Sanity check. It would be bad to be using a NULL pointer! */
assert(BUFFER_HEAD(buffptr) != NULL);
line = BUFFER_HEAD(buffptr);
bytessent = write(fd, line->string + line->pos, line->length - line->pos);
if (bytessent >= 0) {
@@ -275,14 +273,10 @@ ssize_t writebuff(int fd, struct buffer_s *buffptr)
return 0;
case ENOBUFS:
case ENOMEM:
log_message(LOG_ERR,
"write error [NOBUFS/NOMEM] (%s) in 'writebuff'.",
strerror(errno));
log_message(LOG_ERR, "writebuff: write() error [NOBUFS/NOMEM] \"%s\" on file descriptor %d", strerror(errno), fd);
return 0;
default:
log_message(LOG_ERR,
"write error (fd %d: %s:%d) in 'writebuff'.",
fd, strerror(errno), errno);
log_message(LOG_ERR, "writebuff: write() error \"%s\" on file descriptor %d", strerror(errno), fd);
return -1;
}
}
+16 -2
View File
@@ -1,4 +1,4 @@
/* $Id: buffer.h,v 1.4 2001-05-27 02:23:08 rjkaes Exp $
/* $Id: buffer.h,v 1.5 2001-11-05 15:23:05 rjkaes Exp $
*
* See 'buffer.c' for a detailed description.
*
@@ -18,9 +18,23 @@
#ifndef _TINYPROXY_BUFFER_H_
#define _TINYPROXY_BUFFER_H_
/*
* This structure contains the total size of a buffer, plus pointers to the
* head and tail of the buffer.
*/
struct buffer_s {
struct bufline_s *head; /* top of the buffer */
struct bufline_s *tail; /* bottom of the buffer */
size_t size; /* total size of the buffer */
};
/*
* Return the size of a buffer (pass a pointer to a buffer_s structure.)
*/
#define BUFFER_SIZE(x) (x)->size
extern struct buffer_s *new_buffer(void);
extern void delete_buffer(struct buffer_s *buffptr);
extern size_t buffer_size(struct buffer_s *buffptr);
extern ssize_t readbuff(int fd, struct buffer_s *buffptr);
extern ssize_t writebuff(int fd, struct buffer_s *buffptr);
+60
View File
@@ -0,0 +1,60 @@
/* $Id: conns.c,v 1.4 2001-11-21 01:00:08 rjkaes Exp $
*
* Create and free the connection structure. One day there could be
* other connnection related tasks put here, but for now the header
* file and this file are only used for create/free functions and the
* connection structure definition.
*
* Copyright (C) 2001 Robert James Kaes (rjkaes@flarenet.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include "tinyproxy.h"
#include "buffer.h"
#include "conns.h"
#include "stats.h"
#include "utils.h"
void initialize_conn(struct conn_s *connptr)
{
connptr->client_fd = connptr->server_fd = -1;
connptr->cbuffer = new_buffer();
connptr->sbuffer = new_buffer();
connptr->send_message = FALSE;
connptr->simple_req = FALSE;
connptr->ssl = FALSE;
connptr->upstream = FALSE;
connptr->protocol.major = connptr->protocol.minor = 0;
update_stats(STAT_OPEN);
}
void destroy_conn(struct conn_s *connptr)
{
if (connptr->client_fd != -1)
close(connptr->client_fd);
if (connptr->server_fd != -1)
close(connptr->server_fd);
if (connptr->cbuffer)
delete_buffer(connptr->cbuffer);
if (connptr->sbuffer)
delete_buffer(connptr->sbuffer);
safefree(connptr);
update_stats(STAT_CLOSE);
}
+45
View File
@@ -0,0 +1,45 @@
/* $Id: conns.h,v 1.4 2001-11-21 01:00:09 rjkaes Exp $
*
* See 'conns.c' for a detailed description.
*
* 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.
*/
#ifndef TINYPROXY_CONNS_H
#define TINYPROXY_CONNS_H
/*
* Connection Definition
*/
struct conn_s {
int client_fd;
int server_fd;
struct buffer_s *cbuffer;
struct buffer_s *sbuffer;
bool_t simple_req;
bool_t ssl;
bool_t upstream;
bool_t send_message;
struct {
unsigned short int major;
unsigned short int minor;
} protocol;
};
/*
* Functions for the creation and destruction of a connection structure.
*/
extern void initialize_conn(struct conn_s *connptr);
extern void destroy_conn(struct conn_s *connptr);
#endif
+2 -9
View File
@@ -1,4 +1,4 @@
/* $Id: dnscache.c,v 1.16 2001-09-12 03:32:24 rjkaes Exp $
/* $Id: dnscache.c,v 1.17 2001-10-25 17:27:39 rjkaes Exp $
*
* This is a caching DNS system. When a host name is needed we look it up here
* and see if there is already an answer for it. The domains are placed in a
@@ -20,14 +20,7 @@
* General Public License for more details.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <unistd.h>
#include "tinyproxy.h"
#include "dnscache.h"
#include "log.h"
+2 -3
View File
@@ -1,4 +1,4 @@
/* $Id: dnscache.h,v 1.6 2001-10-18 03:44:06 rjkaes Exp $
/* $Id: dnscache.h,v 1.7 2001-10-25 17:02:50 rjkaes Exp $
*
* See 'dnscache.c' for a detailed description.
*
@@ -18,8 +18,7 @@
#ifndef _TINYPROXY_DNSCACHE_H_
#define _TINYPROXY_DNSCACHE_H_
#include <netinet/in.h>
#include <arpa/inet.h>
#include "tinyproxy.h"
extern int dnscache(struct in_addr *addr, char *domain);
+1 -4
View File
@@ -1,4 +1,4 @@
/* $Id: filter.c,v 1.6 2001-09-12 03:32:54 rjkaes Exp $
/* $Id: filter.c,v 1.7 2001-10-25 17:27:39 rjkaes Exp $
*
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
*
@@ -18,9 +18,6 @@
#include "tinyproxy.h"
#include <ctype.h>
#include <sysexits.h>
#include "filter.h"
#include "regexp.h"
#include "utils.h"
+1 -3
View File
@@ -1,4 +1,4 @@
/* $Id: log.c,v 1.14 2001-09-04 16:50:22 rjkaes Exp $
/* $Id: log.c,v 1.15 2001-10-25 17:27:39 rjkaes Exp $
*
* Logs the various messages which tinyproxy produces to either a log file or
* the syslog daemon. Not much to it...
@@ -19,8 +19,6 @@
#include "tinyproxy.h"
#include <stdarg.h>
#include "log.h"
static char *syslog_level[] = {
+118 -78
View File
@@ -1,4 +1,4 @@
/* $Id: reqs.c,v 1.31 2001-10-22 16:08:29 rjkaes Exp $
/* $Id: reqs.c,v 1.39 2001-11-21 19:19:46 rjkaes Exp $
*
* This is where all the work in tinyproxy is actually done. Incoming
* connections have a new thread created for them. The thread then
@@ -28,6 +28,7 @@
#include "acl.h"
#include "anonymous.h"
#include "buffer.h"
#include "conns.h"
#include "filter.h"
#include "log.h"
#include "regexp.h"
@@ -81,7 +82,7 @@ static char *read_request_line(struct conn_s *connptr)
len = readline(connptr->client_fd, request_buffer, LINE_LENGTH);
if (len <= 0) {
log_message(LOG_ERR, "Client (file descriptor: %d) closed socket before read.", connptr->client_fd);
log_message(LOG_ERR, "read_request_line: Client (file descriptor: %d) closed socket before read.", connptr->client_fd);
safefree(request_buffer);
return NULL;
}
@@ -148,7 +149,7 @@ static int extract_http_url(const char *url, struct request_s *request)
request->port = 80;
strcpy(request->path, "/");
} else {
log_message(LOG_ERR, "Can't parse URL.");
log_message(LOG_ERR, "extract_http_url: Can't parse URL.");
safefree(request->host);
safefree(request->path);
@@ -173,7 +174,7 @@ static int extract_ssl_url(const char *url, struct request_s *request)
else if (sscanf(url, "%s", request->host) == 1)
request->port = 443;
else {
log_message(LOG_ERR, "Can't parse URL.");
log_message(LOG_ERR, "extract_ssl_url: Can't parse URL.");
safefree(request->host);
return -1;
@@ -281,7 +282,7 @@ static struct request_s *process_request(struct conn_s *connptr,
ret = sscanf(request_line, "%[^ ] %[^ ] %[^ ]", request->method, url, request->protocol);
if (ret < 2) {
log_message(LOG_ERR, "Bad Request on file descriptor %d", connptr->client_fd);
log_message(LOG_ERR, "process_request: Bad Request on file descriptor %d", connptr->client_fd);
httperr(connptr, 400, "Bad Request. No request found.");
safefree(url);
@@ -293,7 +294,7 @@ static struct request_s *process_request(struct conn_s *connptr,
}
if (!url) {
log_message(LOG_ERR, "Null URL on file descriptor %d", connptr->client_fd);
log_message(LOG_ERR, "process_request: Null URL on file descriptor %d", connptr->client_fd);
httperr(connptr, 400, "Bad Request. Null URL.");
safefree(url);
@@ -326,7 +327,7 @@ static struct request_s *process_request(struct conn_s *connptr,
}
connptr->ssl = TRUE;
} else {
log_message(LOG_ERR, "Unknown URL type on file descriptor %d", connptr->client_fd);
log_message(LOG_ERR, "process_request: Unknown URL type on file descriptor %d", connptr->client_fd);
httperr(connptr, 400, "Bad Request. Unknown URL type.");
safefree(url);
@@ -345,7 +346,7 @@ static struct request_s *process_request(struct conn_s *connptr,
if (filter_url(request->host)) {
update_stats(STAT_DENIED);
log_message(LOG_ERR, "Proxying refused on filtered domain \"%s\"", request->host);
log_message(LOG_NOTICE, "Proxying refused on filtered domain \"%s\"", request->host);
httperr(connptr, 404, "Connection to filtered domain is now allowed.");
free_request_struct(request);
@@ -359,7 +360,7 @@ static struct request_s *process_request(struct conn_s *connptr,
* Check to see if they're requesting the stat host
*/
if (config.stathost && strcmp(config.stathost, request->host) == 0) {
log_message(LOG_NOTICE, "tinyproxy stathost request.");
log_message(LOG_NOTICE, "Request for the stathost.");
free_request_struct(request);
@@ -367,6 +368,14 @@ static struct request_s *process_request(struct conn_s *connptr,
return NULL;
}
/*
* Break apart the protocol and update the connection structure.
*/
if (strncasecmp(request->protocol, "http", 4) == 0) {
memcpy(request->protocol, "HTTP", 4);
sscanf(request->protocol, "HTTP/%hu.%hu", &connptr->protocol.major, &connptr->protocol.minor);
}
return request;
}
@@ -445,6 +454,12 @@ static int add_xtinyproxy_header(struct conn_s *connptr)
char xtinyproxy[32];
int length;
/*
* Don't try to send if we have an invalid server handle.
*/
if (connptr->server_fd == -1)
return 0;
length = snprintf(xtinyproxy, sizeof(xtinyproxy),
"X-Tinyproxy: %s\r\n",
getpeer_ip(connptr->client_fd, ipaddr));
@@ -465,10 +480,16 @@ static int process_client_headers(struct conn_s *connptr)
{
char *header;
long content_length = -1;
#if 0
short int sent_via_header = 0;
#endif
static char *skipheaders[] = {
"proxy-connection",
"host",
"keep-alive",
"proxy-authenticate",
"proxy-authorization",
"connection"
};
int i;
@@ -479,6 +500,7 @@ static int process_client_headers(struct conn_s *connptr)
for ( ; ; ) {
if (readline(connptr->client_fd, header, LINE_LENGTH) <= 0) {
DEBUG2("Client (file descriptor %d) closed connection.", connptr->client_fd);
safefree(header);
return -1;
}
@@ -492,11 +514,32 @@ static int process_client_headers(struct conn_s *connptr)
continue;
/*
* Don't send any of the headers if we're in SSL mode.
* Don't send any of the headers if we're in SSL mode and
* NOT using an upstream proxy.
*/
if (connptr->ssl)
if (connptr->ssl && !connptr->upstream)
continue;
#if 0
/*
* If we find a Via header we need to append our information
* to the end of it.
*/
if (strncasecmp(header, "via", 3) == 0) {
char hostname[128];
char via_header_buffer[256];
sent_via_header = 1;
gethostname(hostname, sizeof(hostname));
snprintf(via_header_buffer, sizeof(via_header_buffer), ", %hu.%hu %s (%s/%s)\r\n", connptr->protocol.major, connptr->protocol.minor, hostname, PACKAGE, VERSION);
trim(header, strlen(header));
strlcat(header, via_header_buffer, LINE_LENGTH);
}
#endif
/*
* Don't send certain headers.
*/
@@ -517,13 +560,28 @@ static int process_client_headers(struct conn_s *connptr)
content_length = atol(content_ptr);
}
if (safe_write(connptr->server_fd, header, strlen(header)) < 0) {
if ((connptr->server_fd != -1) && safe_write(connptr->server_fd, header, strlen(header)) < 0) {
safefree(header);
return -1;
}
}
if (!connptr->send_message && !connptr->ssl) {
#if 0
if (sent_via_header == 0) {
/*
* We're the first proxy so send the first Via header.
*/
char via_header_buffer[256];
char hostname[128];
gethostname(hostname, sizeof(hostname));
snprintf(via_header_buffer, sizeof(via_header_buffer), "Via: %hu.%hu %s (%s/%s)\r\n", connptr->protocol.major, connptr->protocol.minor, hostname, PACKAGE, VERSION);
safe_write(connptr->server_fd, via_header_buffer, strlen(via_header_buffer));
}
#endif
if (!connptr->send_message && (connptr->upstream || !connptr->ssl)) {
#ifdef XTINYPROXY_ENABLE
if (config.my_domain
&& add_xtinyproxy_header(connptr) < 0) {
@@ -532,7 +590,7 @@ static int process_client_headers(struct conn_s *connptr)
}
#endif /* XTINYPROXY */
if (safe_write(connptr->server_fd, header, strlen(header)) < 0) {
if ((connptr->server_fd != -1) && safe_write(connptr->server_fd, header, strlen(header)) < 0) {
safefree(header);
return -1;
}
@@ -563,6 +621,7 @@ static int process_server_headers(struct conn_s *connptr)
for ( ; ; ) {
if (readline(connptr->server_fd, header, LINE_LENGTH) <= 0) {
DEBUG2("Server (file descriptor %d) closed connection.", connptr->server_fd);
safefree(header);
return -1;
}
@@ -618,13 +677,13 @@ static void relay_connection(struct conn_s *connptr)
tv.tv_sec = config.idletimeout - difftime(time(NULL), last_access);
tv.tv_usec = 0;
if (buffer_size(connptr->sbuffer) > 0)
if (BUFFER_SIZE(connptr->sbuffer) > 0)
FD_SET(connptr->client_fd, &wset);
if (buffer_size(connptr->cbuffer) > 0)
if (BUFFER_SIZE(connptr->cbuffer) > 0)
FD_SET(connptr->server_fd, &wset);
if (buffer_size(connptr->sbuffer) < MAXBUFFSIZE)
if (BUFFER_SIZE(connptr->sbuffer) < MAXBUFFSIZE)
FD_SET(connptr->server_fd, &rset);
if (buffer_size(connptr->cbuffer) < MAXBUFFSIZE)
if (BUFFER_SIZE(connptr->cbuffer) < MAXBUFFSIZE)
FD_SET(connptr->client_fd, &rset);
ret = select(maxfd, &rset, &wset, NULL, &tv);
@@ -638,7 +697,7 @@ static void relay_connection(struct conn_s *connptr)
continue;
}
} else if (ret < 0) {
log_message(LOG_ERR, "Received an error in select() [\"%s\", %d], so closing connection (client_fd:%d, server_fd:%d)", strerror(errno), errno, connptr->client_fd, connptr->server_fd);
log_message(LOG_ERR, "relay_connection: select() error \"%s\". Closing connection (client_fd:%d, server_fd:%d)", strerror(errno), connptr->client_fd, connptr->server_fd);
return;
} else {
/*
@@ -649,21 +708,19 @@ static void relay_connection(struct conn_s *connptr)
if (FD_ISSET(connptr->server_fd, &rset)
&& readbuff(connptr->server_fd, connptr->sbuffer) < 0) {
shutdown(connptr->server_fd, SHUT_WR);
break;
}
if (FD_ISSET(connptr->client_fd, &rset)
&& readbuff(connptr->client_fd, connptr->cbuffer) < 0) {
return;
break;
}
if (FD_ISSET(connptr->server_fd, &wset)
&& writebuff(connptr->server_fd, connptr->cbuffer) < 0) {
shutdown(connptr->server_fd, SHUT_WR);
break;
}
if (FD_ISSET(connptr->client_fd, &wset)
&& writebuff(connptr->client_fd, connptr->sbuffer) < 0) {
return;
break;
}
}
@@ -672,45 +729,23 @@ static void relay_connection(struct conn_s *connptr)
* remainder to the client and then exit.
*/
socket_blocking(connptr->client_fd);
while (buffer_size(connptr->sbuffer) > 0) {
while (BUFFER_SIZE(connptr->sbuffer) > 0) {
if (writebuff(connptr->client_fd, connptr->sbuffer) < 0)
return;
break;
}
/*
* Try to send any remaining data to the server if we can.
*/
socket_blocking(connptr->server_fd);
while (BUFFER_SIZE(connptr->cbuffer) > 0) {
if (writebuff(connptr->client_fd, connptr->cbuffer) < 0)
break;
}
return;
}
static void initialize_conn(struct conn_s *connptr)
{
connptr->client_fd = connptr->server_fd = -1;
connptr->cbuffer = new_buffer();
connptr->sbuffer = new_buffer();
connptr->send_message = FALSE;
connptr->simple_req = FALSE;
connptr->ssl = FALSE;
update_stats(STAT_OPEN);
}
static void destroy_conn(struct conn_s *connptr)
{
if (connptr->client_fd != -1)
close(connptr->client_fd);
if (connptr->server_fd != -1)
close(connptr->server_fd);
if (connptr->cbuffer)
delete_buffer(connptr->cbuffer);
if (connptr->sbuffer)
delete_buffer(connptr->sbuffer);
safefree(connptr);
update_stats(STAT_CLOSE);
}
#ifdef UPSTREAM_SUPPORT
/*
* Establish a connection to the upstream proxy server.
@@ -718,7 +753,7 @@ static void destroy_conn(struct conn_s *connptr)
static int connect_to_upstream(struct conn_s *connptr,
struct request_s *request)
{
char *combined_host_path;
char *combined_string;
int len;
connptr->server_fd = opensock(config.upstream_name, config.upstream_port);
@@ -731,29 +766,32 @@ static int connect_to_upstream(struct conn_s *connptr,
log_message(LOG_CONN, "Established connection to upstream proxy \"%s\" using file descriptor %d.", config.upstream_name, connptr->server_fd);
if (connptr->ssl) {
safe_write(connptr->server_fd, "CONNECT ", 8);
safe_write(connptr->server_fd, request->host, strlen(request->host));
safe_write(connptr->server_fd, ":443 HTTP/1.0\r\n", 15);
return 0;
}
/*
* Since we're going to use the establish_http_connection() function
* we need to rebuild the "path" by combining the host, port, and
* path so we can use the common send functions.
* We need to re-write the "path" part of the request so that we
* can reuse the establish_http_connection() function. It expects a
* method and path.
*/
len = strlen(request->host) + strlen(request->path) + 14;
combined_host_path = safemalloc(len + 1);
if (!combined_host_path) {
return -1;
}
if (connptr->ssl) {
len = strlen(request->host) + 6;
snprintf(combined_host_path, len, "http://%s:%d%s", request->host, request->port, request->path);
combined_string = safemalloc(len + 1);
if (!combined_string) {
return -1;
}
snprintf(combined_string, len, "%s:%d", request->host, request->port);
} else {
len = strlen(request->host) + strlen(request->path) + 14;
combined_string = safemalloc(len + 1);
if (!combined_string) {
return -1;
}
snprintf(combined_string, len, "http://%s:%d%s", request->host, request->port, request->path);
}
safefree(request->path);
request->path = combined_host_path;
request->path = combined_string;
return establish_http_connection(connptr, request);
}
@@ -816,7 +854,7 @@ void handle_connection(int fd)
goto internal_proxy;
}
log_message(LOG_CONN, "Established a connection to the tunnel \"%s\" using file descriptor %d.", config.tunnel_name, connptr->server_fd);
log_message(LOG_INFO, "Established a connection to the tunnel \"%s\" using file descriptor %d.", config.tunnel_name, connptr->server_fd);
/*
* I know GOTOs are evil, but duplicating the code is even
@@ -849,6 +887,8 @@ internal_proxy:
#ifdef UPSTREAM_SUPPORT
if (config.upstream_name && config.upstream_port != -1) {
connptr->upstream = TRUE;
if (connect_to_upstream(connptr, request) < 0)
goto send_error;
} else {
@@ -885,7 +925,7 @@ send_error:
return;
}
if (!connptr->ssl || config.upstream_name) {
if (!connptr->ssl || connptr->upstream) {
if (process_server_headers(connptr) < 0) {
update_stats(STAT_BADCONN);
destroy_conn(connptr);
@@ -893,7 +933,7 @@ send_error:
}
} else {
if (send_ssl_response(connptr) < 0) {
log_message(LOG_ERR, "Could not send SSL greeting to client.");
log_message(LOG_ERR, "handle_connection: Could not send SSL greeting to client.");
update_stats(STAT_BADCONN);
destroy_conn(connptr);
return;
+2 -3
View File
@@ -1,4 +1,4 @@
/* $Id: scanner.l,v 1.5 2001-09-16 20:08:24 rjkaes Exp $
/* $Id: scanner.l,v 1.6 2001-10-25 17:27:39 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
@@ -19,9 +19,8 @@
%{
#include "tinyproxy.h"
#include "grammar.h"
#include <string.h>
#include <stdio.h>
struct keyword {
char *kw_name;
+27 -11
View File
@@ -1,4 +1,4 @@
/* $Id: sock.c,v 1.10 2001-10-22 16:52:34 rjkaes Exp $
/* $Id: sock.c,v 1.15 2001-11-12 21:10:51 rjkaes Exp $
*
* 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
@@ -66,19 +66,19 @@ int opensock(char *ip_addr, uint16_t port)
ret = dnscache(&port_info.sin_addr, ip_addr);
if (ret < 0) {
log_message(LOG_ERR, "Could not lookup address [%s].", ip_addr);
log_message(LOG_ERR, "opensock: Could not lookup address \"%s\".", ip_addr);
return -1;
}
port_info.sin_port = htons(port);
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
log_message(LOG_ERR, "Could not create socket because of '%s'.", strerror(errno));
log_message(LOG_ERR, "opensock: socket() error \"%s\".", strerror(errno));
return -1;
}
if (connect(sock_fd, (struct sockaddr*)&port_info, sizeof(port_info)) < 0) {
log_message(LOG_ERR, "Could not connect socket because of '%s'", strerror(errno));
log_message(LOG_ERR, "opensock: connect() error \"%s\".", strerror(errno));
return -1;
}
@@ -160,9 +160,13 @@ char *getpeer_ip(int fd, char *ipaddr)
assert(fd >= 0);
assert(ipaddr != NULL);
/*
* Make sure the user's buffer is initialized to an empty string.
*/
*ipaddr = '\0';
if (getpeername(fd, (struct sockaddr*)&name, &namelen) != 0) {
log_message(LOG_ERR, "geetpeer_ip: 'could not get peer name' (\"%s\": %d)", strerror(errno), errno);
*ipaddr = '\0';
log_message(LOG_ERR, "getpeer_ip: getpeername() error \"%s\".", strerror(errno));
} else {
strlcpy(ipaddr,
inet_ntoa(*(struct in_addr*)&name.sin_addr.s_addr),
@@ -185,9 +189,13 @@ char *getpeer_string(int fd, char *string)
assert(fd >= 0);
assert(string != NULL);
/*
* Make sure the user's buffer is initialized to an empty string.
*/
*string = '\0';
if (getpeername(fd, (struct sockaddr *)&name, &namelen) != 0) {
log_message(LOG_ERR, "getpeer_string: 'could not get peer name' (\"%s\": %d)", strerror(errno), errno);
*string = '\0';
log_message(LOG_ERR, "getpeer_string: getpeername() error \"%s\".", strerror(errno));
} else {
LOCK();
peername = gethostbyaddr((char *)&name.sin_addr.s_addr,
@@ -195,6 +203,9 @@ char *getpeer_string(int fd, char *string)
AF_INET);
if (peername)
strlcpy(string, peername->h_name, PEER_STRING_LENGTH);
else
log_message(LOG_ERR, "getpeer_string: gethostbyaddr() error \"%s\".", hstrerror(h_errno));
UNLOCK();
}
@@ -248,23 +259,28 @@ ssize_t readline(int fd, char *ptr, size_t maxlen)
for (n = 1; n < maxlen; n++) {
again:
if ((rc = read(fd, &c, 1)) == 1) {
if ((rc = recv(fd, &c, 1, MSG_NOSIGNAL)) == 1) {
*ptr++ = c;
if (c == '\n')
break;
} else if (rc == 0) {
if (n == 1)
if (n == 1) {
DEBUG2("File_Desc: %d Closed.", fd);
return 0;
else
} else
break;
} else {
if (errno == EINTR)
goto again;
DEBUG2("File_Desc: %d \"%s\" (%d)", fd, strerror(errno), errno);
return -1;
}
}
/* Tack a NIL to the end to make is a standard "C" string */
*ptr = '\0';
return (ssize_t)n;
}
+2 -4
View File
@@ -1,4 +1,4 @@
/* $Id: sock.h,v 1.5 2001-09-16 20:11:07 rjkaes Exp $
/* $Id: sock.h,v 1.6 2001-10-25 17:02:50 rjkaes Exp $
*
* See 'sock.c' for a detailed description.
*
@@ -19,9 +19,7 @@
#ifndef TINYPROXY_SOCK_H
#define TINYPROXY_SOCK_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "tinyproxy.h"
#define PEER_IP_LENGTH 16
#define PEER_STRING_LENGTH 256
+3 -1
View File
@@ -1,4 +1,4 @@
/* $Id: stats.h,v 1.2 2001-09-16 20:11:24 rjkaes Exp $
/* $Id: stats.h,v 1.3 2001-10-25 16:58:50 rjkaes Exp $
*
* See 'stats.h' for a detailed description.
*
@@ -18,6 +18,8 @@
#ifndef _TINYPROXY_STATS_H_
#define _TINYPROXY_STATS_H_
#include "conns.h"
/*
* Various logable statistics
*/
+5 -17
View File
@@ -1,4 +1,4 @@
/* $Id: ternary.c,v 1.10 2001-09-08 18:58:02 rjkaes Exp $
/* $Id: ternary.c,v 1.11 2001-10-25 17:27:39 rjkaes Exp $
*
* This module creates a Ternary Search Tree which can store both string
* keys, and arbitrary data for each key. It works similar to a hash, and
@@ -21,23 +21,11 @@
* General Public License for more details.
*/
#if defined HAVE_CONFIG_H
# include <config.h>
#endif
#include "tinyproxy.h"
#if defined HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
#include "ternary.h"
#include "tinyproxy.h"
#include "utils.h"
#include "log.h"
#include "ternary.h"
#include "utils.h"
/*
* Macros for the tree structures (limits)
+4 -4
View File
@@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.16 2001-09-15 21:28:25 rjkaes Exp $
/* $Id: thread.c,v 1.17 2001-10-24 00:37:23 rjkaes Exp $
*
* Handles the creation/destruction of the various threads required for
* processing incoming connections.
@@ -196,11 +196,11 @@ short int thread_pool_create(void)
pthread_attr_setstacksize(&thread_attr, THREAD_STACK_SIZE);
if (thread_config.maxclients == 0) {
log_message(LOG_ERR, "'MaxClients' must be greater than zero.");
log_message(LOG_ERR, "thread_pool_create: \"MaxClients\" must be greater than zero.");
return -1;
}
if (thread_config.startservers == 0) {
log_message(LOG_ERR, "'StartServers' must be greater than zero.");
log_message(LOG_ERR, "thread_pool_create: \"StartServers\" must be greater than zero.");
return -1;
}
@@ -209,7 +209,7 @@ short int thread_pool_create(void)
return -1;
if (thread_config.startservers > thread_config.maxclients) {
log_message(LOG_WARNING, "Can not start more than 'MaxClients' servers. Starting %u servers instead.", thread_config.maxclients);
log_message(LOG_WARNING, "Can not start more than \"MaxClients\" servers. Starting %u servers instead.", thread_config.maxclients);
thread_config.startservers = thread_config.maxclients;
}
+1 -10
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.c,v 1.17 2001-09-16 20:11:54 rjkaes Exp $
/* $Id: tinyproxy.c,v 1.18 2001-10-25 17:27:39 rjkaes Exp $
*
* The initialise routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops
@@ -24,15 +24,6 @@
#include "tinyproxy.h"
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif /* HAVE_SYS_RESOUCE_H */
#include <grp.h>
#include <pwd.h>
#include <signal.h>
#include <sysexits.h>
#include <syslog.h>
#include "anonymous.h"
#include "buffer.h"
#include "dnscache.h"
+12 -10
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.h,v 1.16 2001-09-16 20:12:29 rjkaes Exp $
/* $Id: tinyproxy.h,v 1.19 2001-10-25 17:27:39 rjkaes Exp $
*
* See 'tinyproxy.c' for a detailed description.
*
@@ -27,6 +27,9 @@
* Include standard headers which are used through-out tinyproxy
*/
#include <sys/types.h>
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
@@ -45,12 +48,18 @@
#include <sys/uio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <netdb.h>
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#include <pwd.h>
#include <signal.h>
#include <stdarg.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
@@ -60,8 +69,9 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <sysexits.h>
#include <syslog.h>
#include <unistd.h>
#include <assert.h>
#ifndef SHUT_RD /* these three Posix.1g names are quite new */
# define SHUT_RD 0 /* shutdown for reading */
@@ -113,14 +123,6 @@ struct config_s {
};
struct conn_s {
int client_fd, server_fd;
struct buffer_s *cbuffer, *sbuffer;
bool_t simple_req;
bool_t ssl;
bool_t send_message;
};
/* Global Structures used in the program */
extern struct config_s config;
+9 -12
View File
@@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.13 2001-09-16 20:13:52 rjkaes Exp $
/* $Id: utils.c,v 1.16 2001-10-25 17:27:39 rjkaes Exp $
*
* 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,
@@ -21,11 +21,8 @@
#include "tinyproxy.h"
#include <ctype.h>
#include <signal.h>
#include <sysexits.h>
#include "buffer.h"
#include "conns.h"
#include "log.h"
#include "sock.h"
#include "utils.h"
@@ -173,7 +170,7 @@ int create_file_safely(const char *filename)
* existing", exit.
*/
if (errno != ENOENT) {
log_message(LOG_ERR, "Error checking PID file %s: %s.",
log_message(LOG_ERR, "create_file_safely: Error checking PID file %s: %s.",
filename, strerror(errno));
return -1;
}
@@ -184,7 +181,7 @@ int create_file_safely(const char *filename)
* and open()
*/
if ((fildes = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) {
log_message(LOG_ERR, "Could not create PID file %s: %s.",
log_message(LOG_ERR, "create_file_safely: Could not create PID file %s: %s.",
filename, strerror(errno));
return -1;
}
@@ -195,7 +192,7 @@ int create_file_safely(const char *filename)
* Open an existing file.
*/
if ((fildes = open(filename, O_RDWR)) < 0) {
log_message(LOG_ERR, "Could not open PID file %s: %s.",
log_message(LOG_ERR, "create_file_safely: Could not open PID file %s: %s.",
filename, strerror(errno));
return -1;
}
@@ -208,7 +205,7 @@ int create_file_safely(const char *filename)
|| lstatinfo.st_mode != fstatinfo.st_mode
|| lstatinfo.st_ino != fstatinfo.st_ino
|| lstatinfo.st_dev != fstatinfo.st_dev) {
log_message(LOG_ERR, "The PID file %s has been changed before it could be opened.",
log_message(LOG_ERR, "create_file_safely: The PID file %s has been changed before it could be opened.",
filename);
close(fildes);
return -1;
@@ -222,7 +219,7 @@ int create_file_safely(const char *filename)
* st_mode check would also find this)
*/
if (fstatinfo.st_nlink > 1 || !S_ISREG(lstatinfo.st_mode)) {
log_message(LOG_ERR, "The PID file %s has too many links, or is not a regular file: %s.",
log_message(LOG_ERR, "create_file_safely: The PID file %s has too many links, or is not a regular file: %s.",
filename, strerror(errno));
close(fildes);
return -1;
@@ -241,7 +238,7 @@ int create_file_safely(const char *filename)
#else
close(fildes);
if ((fildes = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) {
log_message(LOG_ERR, "Could not open PID file %s: %s.",
log_message(LOG_ERR, "create_file_safely: Could not open PID file %s: %s.",
filename, strerror(errno));
return -1;
}
@@ -269,7 +266,7 @@ void pidfile_create(const char *filename)
* Open a stdio file over the low-level one.
*/
if ((fd = fdopen(fildes, "w")) == NULL) {
log_message(LOG_ERR, "fdopen() error on PID file %s: %s.",
log_message(LOG_ERR, "pidfile_create: fdopen() error on PID file %s: %s.",
filename, strerror(errno));
close(fildes);
unlink(filename);
+3 -1
View File
@@ -1,4 +1,4 @@
/* $Id: utils.h,v 1.9 2001-09-15 21:29:59 rjkaes Exp $
/* $Id: utils.h,v 1.10 2001-10-25 16:58:50 rjkaes Exp $
*
* See 'utils.h' for a detailed description.
*
@@ -21,6 +21,8 @@
#include "tinyproxy.h"
#include "conns.h"
extern int send_http_message(struct conn_s* connptr, int http_code,
const char *error_title, const char *message);
extern int httperr(struct conn_s *connptr, int err, const char *msg);