Compare commits

..
52 Commits
Author SHA1 Message Date
cvs2svn 7b09d88a75 This commit was manufactured by cvs2svn to create tag 'rel_1-4-2-2'. 2001-09-04 18:31:44 +00:00
Robert James Kaes 05cc60042e New news. :) 2001-09-04 18:31:43 +00:00
Robert James Kaes 11cbe6cb5b More updates. 2001-09-04 18:22:12 +00:00
Robert James Kaes c937858ec1 Moved the compare_header() test after the skip header test. 2001-09-04 18:22:00 +00:00
Robert James Kaes 667b9d5d53 Switched to a case insensitive search method. 2001-09-04 17:53:41 +00:00
Robert James Kaes 0094d2755b Bumped the version number. 2001-09-04 16:52:04 +00:00
Robert James Kaes b095c7a84d Updates. 2001-09-04 16:50:45 +00:00
Robert James Kaes 45a021a18b Fixed a format string bug with the syslog function. 2001-09-04 16:50:22 +00:00
Robert James Kaes aac5f60602 Headers MUST have quotes around them. 2001-08-31 15:20:56 +00:00
Robert James Kaes 2857b4be36 Spelling and grammar fixes. 2001-08-30 22:00:36 +00:00
Robert James Kaes 2577811738 New information for Thursday, August 30, 2001 2001-08-30 16:58:41 +00:00
Robert James Kaes 66012c4e8e Another new version. 2001-08-30 16:54:04 +00:00
Robert James Kaes c825db8d56 More fixes. 2001-08-30 16:53:36 +00:00
Robert James Kaes fc94a56f56 Removed the xstrstr() function since it is no longer used. reqs.c was the
only place it was called from, and strstr() will do the same work.
2001-08-30 16:52:56 +00:00
Robert James Kaes a328cefbf0 Renamed ternary_insert() to ternary_insert_replace() and added the ability
to replace existing data (without a memory leak.) Added two DEFINES
ternary_insert() and ternary_replace() to aid in coding.
2001-08-30 16:52:09 +00:00
Robert James Kaes 22bdb8123d Replaced the call to xstrstr() with strstr(). 2001-08-30 16:51:10 +00:00
Robert James Kaes c83c92a0d1 Removed the insert_data() function and made the LOCKing go around the
entire dnscache() function. Replaced the "replace" code in dns_insert()
with a call to ternary_replace().
2001-08-30 16:50:42 +00:00
Robert James Kaes f68f30c7aa New style and new information. 2001-08-29 15:56:48 +00:00
Robert James Kaes c165c83f55 New minor version number. 2001-08-29 15:29:29 +00:00
Robert James Kaes 5584d30eed More change logs. 2001-08-29 04:06:00 +00:00
Robert James Kaes 551e7cf39f Fixed a problem where the REGEX library was included even if the system
already had a working library.
2001-08-29 04:05:33 +00:00
Robert James Kaes 51e4ebb293 Text clean up. 2001-08-29 04:04:01 +00:00
Robert James Kaes d06ddc50ab Removed the new_dnscache() call. 2001-08-29 04:01:05 +00:00
Robert James Kaes fcff398f31 Cleaned up the locking code to make it more fine grained. Did this since
dncache.c has locking itself now.
2001-08-29 04:00:22 +00:00
Robert James Kaes 9bdfa623ba Changed how we handle when compiled with debug code. 2001-08-29 03:59:12 +00:00
Robert James Kaes 4c24890f17 Removed the new_dnscache() function and the ternary.h include. 2001-08-29 03:58:39 +00:00
Robert James Kaes c9a772e36b Added a more fine grained locking system for multiple threads.
Removed the new_dnscache() function and moved it into dnscache().
Fixed a memory leak in dns_insert().
2001-08-29 03:57:51 +00:00
Robert James Kaes f864ff281f Update regarding the log level problems. 2001-08-28 15:54:52 +00:00
Robert James Kaes 1dd459c9ec New version number. 2001-08-28 15:52:53 +00:00
Robert James Kaes 42849c7d66 Fixed a problem in log.c 2001-08-28 15:52:40 +00:00
Robert James Kaes 9a61faa716 The logging levels _now_ output the correct information depending on where
the config file sets it.
2001-08-28 15:51:58 +00:00
Robert James Kaes 4dbc4a637b More changes. 2001-08-28 04:35:03 +00:00
Robert James Kaes ee892c109b Added an extra CRNL to the end of the HTML body. 2001-08-28 04:33:54 +00:00
Robert James Kaes fd65072f1f Changed the default stack size to 128 KB. 2001-08-28 04:33:21 +00:00
Robert James Kaes f9d0fcd1a2 Moved the strip new line/carriage return from the end of a line into a
separate function.
2001-08-28 04:32:14 +00:00
Robert James Kaes 298784d80e Fixed a problem with the POSIX threading on FreeBSD systems. 2001-08-27 19:57:24 +00:00
Robert James Kaes 88e4aed397 More news of course. 2001-08-27 17:51:40 +00:00
Robert James Kaes 1c2a42af9c Stop CVS from giving me an error. 2001-08-27 17:48:27 +00:00
Robert James Kaes f61c275395 More changes as per usual. :) 2001-08-27 17:47:40 +00:00
Robert James Kaes 23b44e67df Bumped up the version number.
Added a test for FreeBSD so that it can set GCC to compile with POSIX
threading.
2001-08-27 17:47:25 +00:00
Robert James Kaes f7d0ea8784 Changed the MIME type to text/html rather than the incorrect text/mime. 2001-08-27 17:46:50 +00:00
Robert James Kaes be9ce3ad26 Moved some of the includes around so that FreeBSD can compile correctly. 2001-08-27 17:46:20 +00:00
Robert James Kaes e88c426966 Changed the default stack size since some OS's have a stack size which is
too small.
2001-08-27 17:45:50 +00:00
Robert James Kaes bf7a671d87 Fixed a problem where the connect messages were not getting logged if the
log level was set to INFO.
2001-08-27 17:44:55 +00:00
Robert James Kaes f72ebfe0d8 More information regarding the various changes. 2001-08-27 03:52:05 +00:00
Robert James Kaes c25c7a947f Updated the version number. 2001-08-27 03:47:47 +00:00
Robert James Kaes 194e1ad9cc New change log entries. 2001-08-27 03:46:51 +00:00
Robert James Kaes 3b5e17d579 Split the headers from the message body. Also now include proper headers
like Date, Server, Content-Length, etc. Also, fixed the type for an error
message to be const char*.
2001-08-27 03:45:34 +00:00
Robert James Kaes 771425700d Fixed a SEGV problem with invalid requests. 2001-08-27 03:44:22 +00:00
Robert James Kaes 7be408859d Update the items which still need to be worked on. 2001-08-27 01:05:32 +00:00
Robert James Kaes 7889aa4951 Don't include ./reconf in the tarball. 2001-08-27 01:05:06 +00:00
Robert James Kaes f590a7d738 More changes. 2001-08-27 01:04:48 +00:00
18 changed files with 340 additions and 183 deletions

No files matched your search

+84
View File
@@ -1,5 +1,89 @@
2001-09-04 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (process_client_headers): Moved the skip header test
in front of the compare_header() function.
* src/ternary.c (ternary_search): Switched to doing case
insensitive searching.
* src/log.c (log_message): Thanks to NeilK for finding and fixing
a problem with the syslog code which can lead to a format string
attack.
2001-08-30 Robert James Kaes <rjkaes@flarenet.com>
* src/dnscache.c: Removed the insert_data() function and replaced
the "replace" logic in dns_insert() with a call to
ternary_replace(). This fixes the segmentation fault problem which
I introduced when I "tried" to fix the memory leak. Also changed
the LOCKing to be around the entire dnscache() again since I still
need to work out how locking should be done when accessing the
ternary tree.
* src/ternary.c (ternary_insert_replace): Renamed ternary_insert()
to ternary_insert_replace() and added a extra argument. The
function can now "replace" data already in the tree without
causing a memory leak. Added two DEFINES to make coding easier:
ternary_insert() and ternary_replace() which both call this
function with the right arguments.
* src/utils.c: Removed xstrstr() since it was only used in one
place, and could be safely replaced with strstr. I can't even
remember why we had this function to begin with.
* src/reqs.c (compare_header): Removed the call to xstrstr() since
it's been removed from the source.
2001-08-28 Robert James Kaes <rjkaes@flarenet.com>
* src/log.c (log_message): Handle a debug enabled compile better.
* src/dnscache.c (dns_insert): Fixed a memory leak if the same
information was inserted into the ternary tree twice.
* configure.in: Fixed the test regarding the REGEX library. Even
if a working REGEX was found on the system, the included REGEX was
being compiled in. Double Doh.
* src/log.c (log_message): Finally got the log levels worked out
properly. I've tested all the levels and they now produce the
correct output.
2001-08-27 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (trim): Moved the trim functionality out of
process_request() and added a test to make sure we don't back the
pointer past the beginning of the string.
* src/log.c (log_message): Fixed a problem where the connect
messages were not getting through if the log level was set to
INFO.
* src/tinyproxy.h: Moved some of the includes around so that
tinyproxy can compile correctly on FreeBSD systems.
* src/thread.c: Added the pthread_attr_t structure since we're
going to be using a non-default sized stack because some OS's have
a stack size which is too small.
* configure.in: Added a test for detecting FreeBSD's -pthread
mechanism for telling GCC to use POSIX threading.
* src/utils.c (httperr): Fixed the MIME type. Should be be
text/html, not text/mime. Fix one bug, add two new ones. Sigh.
2001-08-26 Robert James Kaes <rjkaes@flarenet.com>
* src/utils.c (httperr): Split the headers from the actual message
and include more headers like Date, Server, Content-Length,
etc. Also set the type for the error message to const char*.
* src/reqs.c (process_method): Fixed a SEGV problem if an invalid
request was submitted.
* Makefile.am (EXTRA_DIST): Don't include ./reconf in the
tarball.
* src/log.c (log_message): Fixed a problem with the new LOG_CONN
log level.
+1 -1
View File
@@ -1,2 +1,2 @@
EXTRA_DIST = configure acconfig.h aclocal.m4 acinclude.m4 reconf
EXTRA_DIST = configure acconfig.h aclocal.m4 acinclude.m4
SUBDIRS = src doc
+21 -18
View File
@@ -1,23 +1,26 @@
Tuesday, September 4, 2001
--------------------------
NEWS
====
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.
Well so much for the 1.4.0 version being the best tinyproxy---there
were bugs. The most serious was that anonymous filtering was not
actually working. Another bug fix is that on Debian systems (and
maybe others) child threads would not be closed if they had been
created after tinyproxy had been started. Finally, if
MaxClientRequests was set to 0, the status of the thread was not going
back to T_WAITING.
-- Robert
Okay, now on to the new features. There is only one feature which is
the new Connect log level. This is basically "Info" without info's
noise.
There are a couple of features which I'm working on for the next
release. There has been requests for logging on tunnelled
connections. Also, some people would like HTTP filtering on tunnelled
connections.
Thursday, August 30, 2001
-------------------------
So, the above bugs are fixed, hopefully there are no other ones. The
new features will be worked into the next few releases.
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.
-- Robert
+30 -25
View File
@@ -1,4 +1,4 @@
dnl $Id: configure.in,v 1.17 2001-08-26 23:36:48 rjkaes Exp $
dnl $Id: configure.in,v 1.25 2001-09-04 16:52:04 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.1)
AM_INIT_AUTOMAKE(tinyproxy,1.4.2.2)
AM_CONFIG_HEADER(config.h)
dnl
@@ -58,7 +58,7 @@ AC_ARG_ENABLE(filter,
[ --enable-filter Enable filtering of domains/URLs [default=yes]],
filter_enabled=yes, filter_enabled=yes)
if test "$filter_enabled" = "yes"; then
LIBOBJS="$LIBOBJS filter.o"
LIBOBJS="filter.o $LIBOBJS"
AC_DEFINE(FILTER_ENABLE)
fi
@@ -105,10 +105,15 @@ else
AC_CHECK_LIB(pthreads, pthread_create)
if test "$ac_cv_lib_pthreads_pthread_create" = "yes"; then
CFLAGS="-D_REENTRANT $CFLAGS"
else
AC_CHECK_LIB(c_r, pthread_create)
if test "$ac_cv_lib_c_r_pthread_create" = "yes"; then
CFLAGS="-pthread -D_REENTRANT $CFLAGS"
else
AC_MSG_ERROR(You must have a POSIX compliant threading library installed)
fi
fi
fi
AC_CHECK_LIB(socket, socket, , AC_CHECK_LIB(socket, htonl))
@@ -195,27 +200,6 @@ AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
AC_TYPE_PID_T
AC_TYPE_SIGNAL
dnl
dnl Compiler characteristics
dnl
dnl Enable the debugging flags (by checking for the GCC compiler)
CFLAGS="-Wall $CFLAGS"
if test "$enable_debug" = "yes" ; then
dnl Add the warnings if we have the GCC compiler
if test x$ac_cv_prog_gcc = xyes ; then
CFLAGS="-Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes $CFLAGS"
CFLAGS="-Wmissing-prototypes -Wmissing-declarations $CFLAGS"
CFLAGS="-Wpointer-arith -Waggregate-return -Wnested-externs $CFLAGS"
fi
CFLAGS="-DYYDEBUG $CFLAGS"
YFLAGS="-v -d"
else
dnl No debugging information, include the optimizations
CFLAGS="-DNDEBUG $CFLAGS"
YFLAGS="-d"
fi
dnl
dnl Checks for functions
dnl
@@ -241,6 +225,27 @@ if test "$ac_cv_func_vprintf" != "yes"; then
AC_CHECK_FUNC(_doprnt, AC_DEFINE(HAVE_DOPRNT))
fi
dnl
dnl Compiler characteristics
dnl
dnl Enable the debugging flags (by checking for the GCC compiler)
CFLAGS="-Wall $CFLAGS"
if test "$enable_debug" = "yes" ; then
dnl Add the warnings if we have the GCC compiler
if test x$ac_cv_prog_gcc = xyes ; then
CFLAGS="-Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes $CFLAGS"
CFLAGS="-Wmissing-prototypes -Wmissing-declarations $CFLAGS"
CFLAGS="-Wpointer-arith -Waggregate-return -Wnested-externs $CFLAGS"
fi
CFLAGS="-DYYDEBUG $CFLAGS"
YFLAGS="-v -d"
else
dnl No debugging information, include the optimizations
CFLAGS="-DNDEBUG $CFLAGS"
YFLAGS="-d"
fi
dnl
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
dnl
@@ -256,7 +261,7 @@ if test "$socks_enabled" = "yes"; then
fi
dnl Handle the REGEX library
if test "$ac_cv_func_regex" != "yes"; then
if test "$ac_cv_func_regexec" != "yes"; then
dnl We don't have a functioning REGEX so include our copy
tinyproxy_use_our_regex=yes
else
+6 -5
View File
@@ -15,10 +15,11 @@ against the current tree and I'll integrate it if possible.
much of a problem. Just need to modify the process_method() code
to look up the URL and rewrite it. If we want to go really fancy
with RegEx mapping this could get ugly. :)
- Ed Avis suggests having tinyproxy have the ability to send the data
from the connections through an external filtering program. I kind of
like this idea, but I don't really have a good way of doing it yet.
- 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
- Handle Secure Socket Layer (SSL) connections (usually port 443).
- Allow selective logging. For example a person may only want to log
error messages.
- Include the ability to rewrite both incoming and outgoing headers.
- Log requests for tunnelled connections
- Allow HTTP header filtering through tunnelled connections
+3 -2
View File
@@ -114,6 +114,7 @@ Allow 192.168.1.0/25
# 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
#Anonymous "Host"
#Anonymous "Authorization"
+40 -18
View File
@@ -1,4 +1,4 @@
/* $Id: dnscache.c,v 1.9 2001-05-27 02:24:00 rjkaes Exp $
/* $Id: dnscache.c,v 1.11 2001-08-30 16:50:42 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
@@ -34,6 +34,14 @@
#include "ternary.h"
#include "utils.h"
/*
* The mutex is used for locking around accesses to the ternary tree.
*/
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
#define LOCK() pthread_mutex_lock(&mutex);
#define UNLOCK() pthread_mutex_unlock(&mutex);
#define DNSEXPIRE (5 * 60)
struct dnscache_s {
@@ -41,30 +49,25 @@ struct dnscache_s {
time_t expire;
};
static TERNARY dns_tree;
TERNARY new_dnscache(void)
{
dns_tree = ternary_new();
return dns_tree;
}
static TERNARY dns_tree = -1;
static int dns_lookup(struct in_addr *addr, char *domain)
{
int ret;
struct dnscache_s *ptr;
assert(addr != NULL);
assert(domain != NULL);
if (TE_ISERROR(ternary_search(dns_tree, domain, (void *)&ptr)))
return -1;
ret = ternary_search(dns_tree, domain, (void *)&ptr);
if (difftime(time(NULL), ptr->expire) > (double)DNSEXPIRE) {
if (TE_ISERROR(ret)
|| difftime(time(NULL), ptr->expire) > DNSEXPIRE) {
return -1;
}
*addr = ptr->ipaddr;
memcpy(addr, &ptr->ipaddr, sizeof(struct in_addr));
return 0;
}
@@ -75,15 +78,19 @@ static int dns_insert(struct in_addr *addr, char *domain)
assert(addr != NULL);
assert(domain != NULL);
DEBUG2("Inserting [%s] into DNS cache", domain);
if (!(newptr = malloc(sizeof(struct dnscache_s)))) {
return -1;
}
newptr->ipaddr = *addr;
memcpy(&newptr->ipaddr, addr, sizeof(struct in_addr));
newptr->expire = time(NULL);
if (TE_ISERROR(ternary_insert(dns_tree, domain, newptr)))
if (TE_ISERROR(ternary_replace(dns_tree, domain, newptr))) {
safefree(newptr);
return -1;
}
return 0;
}
@@ -95,19 +102,34 @@ int dnscache(struct in_addr *addr, char *domain)
assert(addr != NULL);
assert(domain != NULL);
if (inet_aton(domain, (struct in_addr *) addr) != 0)
LOCK();
/* If the DNS tree doesn't exist, build a new one */
if (dns_tree < 0)
dns_tree = ternary_new();
if (inet_aton(domain, (struct in_addr *)addr) != 0) {
UNLOCK();
return 0;
}
/* Well, we're not dotted-decimal so we need to look it up */
if (dns_lookup(addr, domain) == 0)
if (dns_lookup(addr, domain) == 0) {
UNLOCK();
return 0;
}
/* Okay, so not in the list... need to actually look it up. */
if (!(resolv = gethostbyname(domain)))
if (!(resolv = gethostbyname(domain))) {
UNLOCK();
return -1;
}
memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length);
dns_insert(addr, domain);
UNLOCK();
return 0;
}
+2 -4
View File
@@ -1,8 +1,8 @@
/* $Id: dnscache.h,v 1.4 2001-05-27 02:24:00 rjkaes Exp $
/* $Id: dnscache.h,v 1.5 2001-08-29 03:58:39 rjkaes Exp $
*
* See 'dnscache.c' for a detailed description.
*
* Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com
* 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
@@ -19,9 +19,7 @@
#define _TINYPROXY_DNSCACHE_H_
#include <arpa/inet.h>
#include "ternary.h"
extern TERNARY new_dnscache(void);
extern int dnscache(struct in_addr *addr, char *domain);
#endif
+11 -13
View File
@@ -1,4 +1,4 @@
/* $Id: log.c,v 1.10 2001-08-26 23:37:26 rjkaes Exp $
/* $Id: log.c,v 1.14 2001-09-04 16:50:22 rjkaes Exp $
*
* Logs the various messages which tinyproxy produces to either a log file or
* the syslog daemon. Not much to it...
@@ -48,15 +48,7 @@ static short int log_level = LOG_ERR;
*/
void set_log_level(short int level)
{
#ifndef NDEBUG
/*
* If we're running with debugging enabled, then set the log level
* to DEBUG regardless of what's in the configuration file.
*/
log_level = LOG_DEBUG;
#else
log_level = level;
#endif
}
/*
@@ -73,14 +65,20 @@ void log_message(short int level, char *fmt, ...)
char str[STRING_LENGTH];
#endif
#ifdef NDEBUG
/*
* Figure out if we should write the message or not.
*/
if (level == LOG_INFO && log_level == LOG_CONN)
if (log_level == LOG_CONN) {
if (level == LOG_INFO)
return;
} else if (log_level == LOG_INFO) {
if (level > LOG_INFO && level != LOG_CONN)
return;
} else if (level > log_level)
return;
#endif
if (level > log_level)
return;
#ifdef HAVE_SYSLOG_H
if (config.syslog && level == LOG_CONN)
@@ -95,7 +93,7 @@ void log_message(short int level, char *fmt, ...)
vsyslog(level, fmt, args);
# else
vsnprintf(str, STRING_LENGTH, fmt, args);
syslog(level, str);
syslog(level, "%s", str);
# endif
} else {
#endif
+38 -16
View File
@@ -1,10 +1,10 @@
/* $Id: reqs.c,v 1.15 2001-08-26 21:11:55 rjkaes Exp $
/* $Id: reqs.c,v 1.19 2001-09-04 18:22:00 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
* processes the headers from the client, the response from the server,
* and then relays the bytes between the two.
* If the UPSTEAM_PROXY is enabled, then tinyproxy will actually work
* If TUNNEL_SUPPORT is enabled, then tinyproxy will actually work
* as a simple buffering TCP tunnel. Very cool! (Robert actually uses
* this feature for a buffering NNTP tunnel.)
*
@@ -81,6 +81,29 @@ static ssize_t safe_read(int fd, void *buffer, size_t count)
return len;
}
/*
* Remove any new lines or carriage returns from the end of a string.
*/
static inline void trim(char *string, unsigned int len)
{
char *ptr;
assert(string != NULL);
assert(len > 0);
ptr = string + len - 1;
while (*ptr == '\r' || *ptr == '\n') {
*ptr-- = '\0';
/*
* Don't let the ptr back past the beginning of the
* string.
*/
if (ptr < string)
return;
}
}
/*
* Parse a client HTTP request and then establish connection.
*/
@@ -89,7 +112,6 @@ static int process_method(struct conn_s *connptr)
URI *uri = NULL;
char inbuf[LINE_LENGTH];
char *buffer = NULL, *request = NULL, *port = NULL;
char *inbuf_ptr = NULL;
regex_t preg;
regmatch_t pmatch[NMATCH];
@@ -112,9 +134,7 @@ static int process_method(struct conn_s *connptr)
/*
* Strip the newline and character return from the string.
*/
inbuf_ptr = inbuf + len - 1;
while (*inbuf_ptr == '\r' || *inbuf_ptr == '\n')
*inbuf_ptr-- = '\0';
trim(inbuf, len);
log_message(LOG_CONN, "Request: %s", inbuf);
@@ -122,14 +142,14 @@ static int process_method(struct conn_s *connptr)
log_message(LOG_ERR, "clientreq: regcomp");
httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN);
goto COMMON_EXIT;
goto EARLY_EXIT;
}
if (regexec(&preg, inbuf, NMATCH, pmatch, 0) != 0) {
log_message(LOG_ERR, "clientreq: regexec");
regfree(&preg);
httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN);
goto COMMON_EXIT;
goto EARLY_EXIT;
}
regfree(&preg);
@@ -147,7 +167,7 @@ static int process_method(struct conn_s *connptr)
peer_ipaddr, inbuf);
httperr(connptr, 400, HTTP400ERROR);
update_stats(STAT_BADCONN);
goto COMMON_EXIT;
goto EARLY_EXIT;
}
len = pmatch[URI_IND].rm_eo - pmatch[URI_IND].rm_so;
@@ -157,7 +177,7 @@ static int process_method(struct conn_s *connptr)
peer_ipaddr);
httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN);
goto COMMON_EXIT;
goto EARLY_EXIT;
}
memcpy(buffer, inbuf + pmatch[URI_IND].rm_so, len);
buffer[len] = '\0';
@@ -166,7 +186,7 @@ static int process_method(struct conn_s *connptr)
log_message(LOG_ERR, "clientreq: Problem with explode_uri");
httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN);
goto COMMON_EXIT;
goto EARLY_EXIT;
}
safefree(buffer);
@@ -288,8 +308,10 @@ static int process_method(struct conn_s *connptr)
return 0;
COMMON_EXIT:
safefree(request);
free_uri(uri);
EARLY_EXIT:
safefree(request);
return -1;
}
@@ -304,7 +326,7 @@ static int compare_header(char *line)
char *ptr;
int ret;
if ((ptr = xstrstr(line, ":", strlen(line), FALSE)) == NULL)
if ((ptr = strstr(line, ":")) == NULL)
return -1;
if ((buffer = malloc(ptr - line + 1)) == NULL)
@@ -402,9 +424,6 @@ static int process_client_headers(struct conn_s *connptr)
if (connptr->output_message)
continue;
if (is_anonymous_enabled() && compare_header(header) < 0)
continue;
/*
* Don't send certain headers.
*/
@@ -416,6 +435,9 @@ static int process_client_headers(struct conn_s *connptr)
if (i != (sizeof(skipheaders) / sizeof(char *)))
continue;
if (is_anonymous_enabled() && compare_header(header) < 0)
continue;
if (content_length == -1
&& strncasecmp(header, "content-length", 14) == 0) {
char *content_ptr = strchr(header, ':') + 1;
+10 -18
View File
@@ -1,4 +1,4 @@
/* $Id: sock.c,v 1.5 2001-05-27 02:31:20 rjkaes Exp $
/* $Id: sock.c,v 1.6 2001-08-29 04:00:22 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
@@ -29,16 +29,14 @@
#include "utils.h"
/*
* The mutex is used for locking around the calls to the dnscache since I
* don't want multiple threads accessing the linked list at the same time.
* This should be more fine grained, but it will do for now.
* The mutex is used for locking around any calls which access global
* variables.
* - rjkaes
*/
static pthread_mutex_t sock_mutex = PTHREAD_MUTEX_INITIALIZER;
#define SOCK_LOCK() pthread_mutex_lock(&sock_mutex);
#define SOCK_UNLOCK() pthread_mutex_unlock(&sock_mutex);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
#define LOCK() pthread_mutex_lock(&mutex);
#define UNLOCK() pthread_mutex_unlock(&mutex);
/* This routine is so old I can't even remember writing it. But I do
* remember that it was an .h file because I didn't know putting code in a
@@ -64,13 +62,8 @@ int opensock(char *ip_addr, uint16_t port)
port_info.sin_family = AF_INET;
/* chris - Could block; neet to ensure that this is never called
* before a non-blocking DNS query happens for this address. Not
* relevant in the code as it stands.
*/
SOCK_LOCK();
/* Lookup and return the address if possible */
ret = dnscache(&port_info.sin_addr, ip_addr);
SOCK_UNLOCK();
if (ret < 0) {
log_message(LOG_ERR, "opensock: Could not lookup address: %s", ip_addr);
@@ -194,14 +187,13 @@ char *getpeer_string(int fd, char *string)
if (getpeername(fd, (struct sockaddr *)&name, &namelen) != 0) {
log_message(LOG_ERR, "Connect: 'could not get peer name'");
} else {
SOCK_LOCK();
LOCK();
peername = gethostbyaddr((char *)&name.sin_addr.s_addr,
sizeof(name.sin_addr.s_addr),
AF_INET);
if (peername) {
if (peername)
strlcpy(string, peername->h_name, PEER_STRING_LENGTH);
}
SOCK_UNLOCK();
UNLOCK();
}
return string;
+12 -4
View File
@@ -1,4 +1,4 @@
/* $Id: ternary.c,v 1.5 2001-05-23 17:59:53 rjkaes Exp $
/* $Id: ternary.c,v 1.7 2001-09-04 17:53:41 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
@@ -29,6 +29,7 @@
# include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -294,7 +295,8 @@ int ternary_destroy(TERNARY tno, void (*freeptr)(void *))
* TE_TOOFULL tree is full, so no new elements can be added.
* Exceptions: none
*/
int ternary_insert(TERNARY tno, const char *s, void *data)
int ternary_insert_replace(TERNARY tno, const char *s, void *data,
short int replace)
{
int cur; /* index of current tree */
Ttree *tree; /* pointer to tree structure */
@@ -314,7 +316,13 @@ int ternary_insert(TERNARY tno, const char *s, void *data)
while ((pp = *p)) {
if ((d = *s - pp->splitchar) == 0) {
if (*s++ == 0) {
if (!replace)
return TE_EXISTS;
else {
free(pp->eqkid);
pp->eqkid = (Tnode *)data;
return TE_NONE;
}
}
p = &(pp->eqkid);
} else if (d < 0)
@@ -379,9 +387,9 @@ int ternary_search(TERNARY tno, const char *s, void **data)
p = trees[cur]->tree_root;
while (p) {
if (*s < p->splitchar)
if (toupper(*s) < toupper(p->splitchar))
p = p->lokid;
else if (*s == p->splitchar) {
else if (toupper(*s) == toupper(p->splitchar)) {
if (*s++ == 0) {
if (data)
*data = (void *)p->eqkid;
+6 -2
View File
@@ -1,4 +1,4 @@
/* $Id: ternary.h,v 1.2 2000-09-26 04:59:20 rjkaes Exp $
/* $Id: ternary.h,v 1.3 2001-08-30 16:52:09 rjkaes Exp $
*
* See 'ternary.c' for a detailed description.
*
@@ -58,7 +58,11 @@ extern char te_errbuf[256];
extern TERNARY ternary_new(void);
extern int ternary_destroy(TERNARY tno, void (*freeptr)(void *));
extern int ternary_insert(TERNARY tno, const char *s, void *data);
#define ternary_insert(x, y, z) ternary_insert_replace(x, y, z, 0)
#define ternary_replace(x, y, z) ternary_insert_replace(x, y, z, 1)
extern int ternary_insert_replace(TERNARY tno, const char *s, void *data,
short int replace);
extern int ternary_search(TERNARY tno, const char *s, void **data);
#endif
+19 -3
View File
@@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.6 2001-08-26 21:14:30 rjkaes Exp $
/* $Id: thread.c,v 1.8 2001-08-28 04:33:21 rjkaes Exp $
*
* Handles the creation/destruction of the various threads required for
* processing incoming connections.
@@ -23,6 +23,12 @@
#include "sock.h"
#include "thread.h"
/*
* This is the stack frame size used by all the threads. We'll start by
* setting it to 128 KB.
*/
#define THREAD_STACK_SIZE (1024 * 128)
static int listenfd;
static socklen_t addrlen;
@@ -42,6 +48,9 @@ struct thread_s {
static struct thread_s *thread_ptr;
static pthread_mutex_t mlock = PTHREAD_MUTEX_INITIALIZER;
/* Used to override the default statck size. */
static pthread_attr_t thread_attr;
static struct thread_config_s {
unsigned int maxclients, maxrequestsperchild;
unsigned int maxspareservers, minspareservers, startservers;
@@ -146,6 +155,13 @@ int thread_pool_create(void)
{
unsigned int i;
/*
* Initialize thread_attr to contain a non-default stack size
* because the default on some OS's is too small.
*/
pthread_attr_init(&thread_attr);
pthread_attr_setstacksize(&thread_attr, THREAD_STACK_SIZE);
if (thread_config.maxclients == 0) {
log_message(LOG_ERR, "You must set MaxClients to a value greater than 0");
return -1;
@@ -167,7 +183,7 @@ int thread_pool_create(void)
for (i = 0; i < thread_config.startservers; i++) {
thread_ptr[i].status = T_WAITING;
servers_waiting++;
pthread_create(&thread_ptr[i].tid, NULL, &thread_main, &thread_ptr[i]);
pthread_create(&thread_ptr[i].tid, &thread_attr, &thread_main, &thread_ptr[i]);
}
for (i = thread_config.startservers; i < thread_config.maxclients; i++) {
thread_ptr[i].status = T_EMPTY;
@@ -189,7 +205,7 @@ int thread_main_loop(void)
if (servers_waiting < thread_config.minspareservers) {
for (i = 0; i < thread_config.maxclients; i++) {
if (thread_ptr[i].status == T_EMPTY) {
pthread_create(&thread_ptr[i].tid, NULL, &thread_main, &thread_ptr[i]);
pthread_create(&thread_ptr[i].tid, &thread_attr, &thread_main, &thread_ptr[i]);
thread_ptr[i].status = T_WAITING;
thread_ptr[i].connects = 0;
+1 -8
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.c,v 1.12 2001-08-26 21:17:30 rjkaes Exp $
/* $Id: tinyproxy.c,v 1.13 2001-08-29 04:01:05 rjkaes Exp $
*
* The initialise routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops
@@ -347,13 +347,6 @@ int main(int argc, char **argv)
exit(EX_OSERR);
}
/*
* Initialize the various subsystems...
*/
log_message(LOG_INFO, "Starting the DNS caching subsystem.");
if (!new_dnscache())
exit(EX_SOFTWARE);
/*
* Start the main loop.
*/
+4 -4
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.h,v 1.11 2001-08-26 21:18:04 rjkaes Exp $
/* $Id: tinyproxy.h,v 1.13 2001-08-29 04:04:01 rjkaes Exp $
*
* See 'tinyproxy.c' for a detailed description.
*
@@ -26,6 +26,7 @@
/*
* Include standard headers which are used through-out tinyproxy
*/
#include <sys/types.h>
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
@@ -41,10 +42,9 @@
# include <time.h>
# endif
#endif
#include <sys/types.h>
#include <sys/uio.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
@@ -70,7 +70,7 @@
#endif
/* Global variables for the main controls of the program */
#define MAXBUFFSIZE (size_t)(1024 * 48) /* Max size of buffer */
#define MAXBUFFSIZE ((size_t)(1024 * 48)) /* Max size of buffer */
#define MAXLISTEN 1024 /* Max number of connections */
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
+50 -37
View File
@@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.4 2001-05-27 02:38:46 rjkaes Exp $
/* $Id: utils.c,v 1.8 2001-08-30 16:52:56 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,
@@ -30,56 +30,69 @@
#include "sock.h"
#include "utils.h"
/*
* Find the start of the needle in the haystack. Limits the search to less
* than "length" characters. Returns NULL if the needle is not found.
*/
char *xstrstr(char *haystack, char *needle, size_t length,
bool_t case_sensitive)
{
unsigned int i;
/* Used to specify which function to use... need the decl. */
int (*fn) (const char *s1, const char *s2, size_t n);
if (case_sensitive)
fn = strncmp;
else
fn = strncasecmp;
if (strlen(needle) > length)
return NULL;
for (i = 0; i <= length - strlen(needle); i++) {
if ((*fn) (haystack + i, needle, strlen(needle)) == 0)
return (haystack + i);
}
return NULL;
}
/*
* Display an error to the client.
*/
int httperr(struct conn_s *connptr, int err, char *msg)
#define HEADER_SIZE (1024 * 8)
int httperr(struct conn_s *connptr, int err, const char *msg)
{
static char *premsg = "HTTP/1.0 %d %s\r\n" \
"Content-type: text/html\r\n\r\n" \
static char *headers = \
"HTTP/1.0 %d %s\r\n" \
"Server: %s/%s\r\n" \
"Date: %s\r\n" \
"Content-Type: text/html\r\n" \
"Content-Length: %d\r\n" \
"Connection: close\r\n" \
"\r\n";
static char *message = \
"<html><head><title>%s</title></head>\r\n" \
"<body>\r\n" \
"<font size=\"+2\">Cache Error!</font><br>\r\n" \
"An error of type %d occurred: %s\r\n" \
"<hr>\r\n" \
"<font size=\"-1\"><em>Generated by %s</em></font>\r\n" \
"</body></html>\r\n";
"<font size=\"-1\"><em>Generated by %s (%s)</em></font>\r\n" \
"</body></html>\r\n\r\n";
connptr->output_message = malloc(MAXBUFFSIZE);
if (!connptr->output_message) {
char *header_buffer;
char *message_buffer;
int output_size;
char timebuf[30];
time_t global_time;
header_buffer = malloc(HEADER_SIZE);
if (!header_buffer) {
log_message(LOG_CRIT, "Out of memory!");
return -1;
}
snprintf(connptr->output_message, MAXBUFFSIZE, premsg, err, msg, msg, err, msg, VERSION);
message_buffer = malloc(MAXBUFFSIZE);
if (!message_buffer) {
log_message(LOG_CRIT, "Out of memory!");
safefree(header_buffer);
return -1;
}
global_time = time(NULL);
strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&global_time));
snprintf(message_buffer, MAXBUFFSIZE - 1, message, msg, err, msg, PACKAGE, VERSION);
snprintf(header_buffer, HEADER_SIZE - 1, headers, err, msg, PACKAGE, VERSION, timebuf, strlen(message_buffer));
output_size = strlen(message_buffer) + strlen(header_buffer);
connptr->output_message = malloc(output_size + 1);
if (!connptr->output_message) {
log_message(LOG_CRIT, "Out of memory!");
safefree(header_buffer);
safefree(message_buffer);
return -1;
}
strlcpy(connptr->output_message, header_buffer, output_size);
strlcat(connptr->output_message, message_buffer, output_size);
safefree(header_buffer);
safefree(message_buffer);
return 0;
}
+2 -5
View File
@@ -1,4 +1,4 @@
/* $Id: utils.h,v 1.4 2001-05-27 02:38:46 rjkaes Exp $
/* $Id: utils.h,v 1.6 2001-08-30 16:52:56 rjkaes Exp $
*
* See 'utils.h' for a detailed description.
*
@@ -21,10 +21,7 @@
#include "tinyproxy.h"
extern char *xstrstr(char *haystack, char *needle, size_t length,
bool_t case_sensitive);
extern int httperr(struct conn_s *connptr, int err, char *msg);
extern int httperr(struct conn_s *connptr, int err, const char *msg);
extern void makedaemon(void);
extern void pidfile_create(const char *path);