Commit Graph

538 Commits

Author SHA1 Message Date
Robert James Kaes
1d2e4fc2c3 Change the code to use the new config_parse() method rather than the
flex/bison based configuration system.
2004-08-13 21:03:11 +00:00
Robert James Kaes
9d04667848 Added the new configuration parsing system (conffile.c and
conffile.h.)  The new system is intended to replace the existing
grammar.y and scanner.l files.  I don't want to depend on flex/bison
any longer.
2004-08-13 20:19:50 +00:00
Robert James Kaes
b3943c21f2 (check_allowed_connect_ports): By default DENY any CONNECT requests
unless explicitly allowed by a configuration directive.
2004-08-12 20:15:04 +00:00
Robert James Kaes
28dd133623 (add_xtinyproxy_header): Removed the runtime error checking of the
connptr->server_fd variable and moved it into an assert since we
should never be called with invalid data.  Also made the function an
inline function since it's only called in one place.
2004-08-12 19:57:15 +00:00
Robert James Kaes
924da17c17 Completely rewrote the ACL functionality. The new system is intended
to handle IPv6 style addresses along with the existing IPv4 and string
addresses.  In addition, the hand-rolled "list" code has been replaced
with a vector (code reuse.)  Also, the code should be a little easier
to understand (relatively speaking.)

I do need to add some kind of testing framework (in general) to check
that the new code does work with all the formats that will be thrown
at it.
2004-08-11 20:09:20 +00:00
Robert James Kaes
fd4b67bbb4 (strip_username_password): Removed one of the pointer variables since
it's no longer needed.  Reorganized the function to make it more
obvious what was actually being done.
2004-08-11 02:49:05 +00:00
Robert James Kaes
badc7673d0 Merged in changes from 1.6.3 2004-08-10 21:24:24 +00:00
Robert James Kaes
18df4910a4 Added the "BindSame" configure directive from Oswald Buddenhagen.
This allows tinyproxy to respond to a request bound to the same
interface that the request came in on.  As Oswald explains:

  "attached is a patch that adds the BindSame option. it causes
  binding an outgoing connection to the ip address of the respective
  incoming connection. that way one can simulate an entire proxy farm
  with a single instance of tinyproxy on a multi-homed machine."

Cool.
2004-04-27 18:53:14 +00:00
Robert James Kaes
3b961ec66b (init_stats): Fixed a memset bug, where the structure was not cleared
properly.  (The sizeof "struct stat" was being used rather than the
proper "struct stat_s".  On my system, "struct stat" is 88 bytes long,
while "struct stat_s" is 20 bytes long.  Quite a difference!)
2004-04-27 18:48:53 +00:00
Robert James Kaes
095d0d0142 These files list all the other files that CVS should ignore. It makes
looking at the CVS status information a little cleaner.
2004-04-27 18:28:45 +00:00
Robert James Kaes
5ecd9157ce Converted the various socket functions to work with both IPv4 and IPv6
addresses.
2004-02-18 20:18:53 +00:00
Robert James Kaes
c21df1ea0f Added two functions:
- get_ip_string() converts a binary network address into either a
   dotted-decimal IPv4 address, or a IPv6 hex-string
 - full_inet_pton() converts a numeric character string into an IPv6
   network address (binary form).  It's like the system inet_pton()
   function, but it will work with bot IPv4 and IPv6 character
   strings.

These functions are required for the conversion to Internet protocol
independence.  (Or to put it more clearly: allow tinyproxy to work in
an IPv6 network.)
2004-02-18 20:17:18 +00:00
Robert James Kaes
aee5a63849 Removed unnecessary casts (mostly dealing with memory allocation.) I
should never have added them in the first place.  They don't really
buy anything, and they can hide bugs.
2004-02-13 21:27:42 +00:00
Robert James Kaes
bf22966f55 (strip_return_port): Patch from "alex" to strip the port from the host
string and return the port.  I cleaned up and added error handling to
the code, but it's basically "alex"'s fix.

(extract_http_url): Rewrote this function to remove all the sscanf()
calls.  It's much easier to just split on the path slash (if it's
present) and then strip the user name/password and port from the host
string.  Less code, handles more cases!
2004-02-04 19:57:40 +00:00
Robert James Kaes
0a8e4e4d8d Added reverse proxy support from Kim Holviala. His comments regarding
this addition follow:

  The patch implements a simple reverse proxy (with one funky extra
  feature). It has all the regular features: mapping remote servers to local
  namespace (ReversePath), disabling forward proxying (ReverseOnly) and HTTP
  redirect rewriting (ReverseBaseURL).

  The funky feature is this: You map Google to /google/ and the Google front
  page opens up fine. Type in stuff and click "Google Search" and you'll get
  an error from tinyproxy. Reason for this is that Google's form submits to
  "/search" which unfortunately bypasses our /google/ mapping (if they'd
  submit to "search" without the slash it would have worked ok). Turn on
  ReverseMagic and it starts working....

  ReverseMagic "hijacks" one cookie which it sends to the client browser.
  This cookie contains the current reverse proxy path mapping (in the above
  case /google/) so that even if the site uses absolute links the reverse
  proxy still knows where to map the request.

  And yes, it works. No, I've never seen this done before - I couldn't find
  _any_ working OSS reverse proxies, and the commercial ones I've seen try
  to parse the page and fix all links (in the above case changing "/search"
  to "/google/search"). The problem with modifying the html is that it might
  not be parsable (very common) or it might be encoded so that the proxy
  can't read it (mod_gzip or likes).

  Hope you like that patch. One caveat - I haven't coded with C in like
  three years so my code might be a bit messy.... There shouldn't be any
  security problems thou, but you never know. I did all the stuff out of my
  memory without reading any RFC's, but I tested everything with Moz, Konq,
  IE6, Links and Lynx and they all worked fine.
2004-01-26 19:11:52 +00:00
Robert James Kaes
f2d846d057 Merged in changes from the 1.6.2 release. (Fixes for the filtering code
and the HTML installation script.)
2003-10-17 16:11:00 +00:00
Robert James Kaes
d2098f638f tinyproxy no longer includes a fall-back regular expression library,
so these files needed to be modified to only use the system's
installed regular expression library.
2003-08-07 16:32:12 +00:00
Robert James Kaes
d72fa83245 Removed the included regular expression library, since it should come
standard on any reasonably modern system.
2003-08-07 16:29:54 +00:00
Robert James Kaes
7eb4eba381 # Merged in changes from the stable 1.6 branch. 2003-08-07 15:31:20 +00:00
Robert James Kaes
fd23cd4aed # Fixed a comment to actually reflect what the function does. 2003-08-05 16:11:59 +00:00
Robert James Kaes
a117ed9cb0 Included patches from Steven Young to use the hashmap functionality to
manage the HTML error pages.  It simplifies the source, and also make
the object file smaller.  Nice.  Also added any casting from (void*)
to ensure that the code compiles using a C++ compiler.
2003-08-01 00:14:34 +00:00
Robert James Kaes
15870a9582 Added appropriate casts (void*) casts to allow the code to compile
cleanly using a C++ compiler.

Changed the servers_waiting variable to an unsigned int, since the
number of servers waiting can never be negative, and added an assert()
to ensure this invariant.
2003-07-31 23:44:52 +00:00
Robert James Kaes
bc77dfb492 (debugging_realloc): Removed the assert for the NULL pointer, since
realloc() can take a NULL pointer, as defined by the realloc() man
page.

Fixed the cast in both safefree() macros to compile cleaning using a
C++ compiler.
2003-07-31 23:42:51 +00:00
Robert James Kaes
5a2af49e58 Fixed the cast in both safefree() macros to compile cleaning using a
C++ compiler.
2003-07-31 23:41:26 +00:00
Robert James Kaes
8a6a94db0a # Fixed a preprocessor test (misspelled __cplusplus) 2003-07-31 23:40:16 +00:00
Robert James Kaes
6aaa863432 Added appropriate casts from (void*) so that the code will compile
cleanly with a C++ compiler.  (Tested using GCC 3.3)
2003-07-31 23:38:28 +00:00
Robert James Kaes
7c96935552 (indicate_http_error): Added calls to va_end() before leaving the
function.
2003-07-14 17:42:43 +00:00
Robert James Kaes
a4cd3eb9ec # Removed the debugging information. 2003-06-26 18:26:10 +00:00
Robert James Kaes
a8798e999b # Added debugging flags for the flex scanner. 2003-06-26 18:23:01 +00:00
Robert James Kaes
1cb032a934 (upstream_add): Rewrote the function to actually handle the various
types of upstream configurations correctly.  Hopefully, the code is
also a little clearer in it's implementation.
2003-06-26 18:19:57 +00:00
Robert James Kaes
988f243286 # Removed the STRING_ADDRESS token since it was conflicting with the
IDENTIFIER directive and also the keyword directives.
2003-06-26 18:17:09 +00:00
Robert James Kaes
db142b6e23 Modified the patterns to allow the new upstream directives to work as
defined in the tinyproxy.conf documentation.
2003-06-26 18:16:09 +00:00
Robert James Kaes
2736a19518 (debugging_free): Rather than assert on a NULL pointer, log the NULL
pointer and return.
2003-06-26 18:14:13 +00:00
Robert James Kaes
ddcac5ae09 Added a test to define INADDR_NONE if it's not present. For example,
SunOS (solaris 2.8) does not include this define.  [Thank to Ben
Hartshorne for pointing this out.]
2003-06-25 18:20:22 +00:00
Robert James Kaes
4c9141aac6 Removed the "ViaHeader" directive and replaced it with the
"ViaProxyName" directive.  The "Via" HTTP header is _required_ by the
HTTP spec, so the code has been changed to always send the header.
However, including the proxy's host name could be considered a
security threat, so the "ViaProxyName" directive is used to set the
token sent in the "Via" header.  If the directive is not enabled the
proxy's host name will be used.
2003-06-20 17:02:13 +00:00
Robert James Kaes
b081019d5a (connect_to_upstream): Fixed an off-by-one error in the snprintf()
call used to build the URL for the upstream proxy. [Patch suggested by
David T. Pierso]
2003-06-06 16:14:50 +00:00
Robert James Kaes
91e082671a (upstream_get):
(upstream_add): Added support to allow ip addresses and networks to be
used when matching an upstream proxy directive.
[Code by Peter da Silva]
2003-06-02 21:55:14 +00:00
Robert James Kaes
ea50171a95 Changed the safefree() macro to make it safe to use a conditional
statement, and also safe to use with a rvalue that has a side
effect.  [Bug fix recommended by Peter da Silva]
2003-05-31 23:04:15 +00:00
Robert James Kaes
77ca1c8ce0 # Changed all the for calls to use the != test rather than < test.
The change was recommended in the C/C++ User Journal magazine.
2003-05-31 23:02:21 +00:00
Robert James Kaes
af5e1e29f6 # Changed the calls to vector_getentry() to use the new calling
convention.
2003-05-30 16:22:30 +00:00
Robert James Kaes
1955dcd47b (vector_getentry): Changed the API to return the data pointer and have
the length returned in a argument variable pointer.  This should be a
more natural way of using the function.
2003-05-30 16:21:48 +00:00
Robert James Kaes
c3eaebd1c5 # Added a vector_prepend() function and recoded the old vector_insert()
to be a general "insert" for both vector_append() and vector_prepend()
2003-05-29 21:07:22 +00:00
Robert James Kaes
8ab278998f # Renamed the vector_insert() calls to vector_append() 2003-05-29 20:48:25 +00:00
Robert James Kaes
42f9f37afc (vector_append): Renamed the vector_insert() function to more
accurately indicate that entries are appended to the end of the
vector.
2003-05-29 20:47:52 +00:00
Robert James Kaes
4a377a712d Improved the upstream proxy support by making the upstream proxy
server configurable based on the destination host.  [Code written by
Peter da Silva]
2003-05-29 19:44:00 +00:00
Robert James Kaes
5e1303ecd1 (establish_http_connection): If the port being requested is not a
standard HTTP port (80 or 443) append the port string to the host
header; otherwise, leave the host string with only the host's domain
name.

Replaced all occurrences of constant 80 and 443 with defines HTTP_PORT
and HTTP_PORT_SSL.
2003-05-05 16:46:05 +00:00
Robert James Kaes
ac88af1f71 Fixed a bug that would kill a child process because of an invalid
safefree() call.  Basically, destroy_conn() was trying to free memory
not allocated by malloc.  [Fix by David T. Pierson]
2003-05-04 04:35:10 +00:00
Robert James Kaes
c94bfa8223 (build_url): Rebuild the URL from the component pieces. This function
is used by the transparent proxy code.  [Anatole Shaw]
(process_request): Fixed up the transparent proxy code so that
filtering can be done on the whole URL.  [Anatole Shaw]

(pull_client_data): Added a bug fix for Internet Explorer (IE).  IE
will leave an extra CR and LF after the data in an HTTP POST.  The new
code will eat the extra bytes if they're present.  Thanks to Yannick
Koehler for finding the bug and offering an explanation as to why it
was happening.

Changed all calls of connptr->remote_content_length to
connptr->content_length.server
2003-04-16 18:11:58 +00:00
Robert James Kaes
648e8f1438 # Changed it again to this time use the TINYPROXY_DEBUG environment
variable to determine whether to wait for a connection from GDB.
2003-04-16 18:04:58 +00:00
Robert James Kaes
4a942bc59a # The programmer is now made to _explicitly_ enable the GDB support in
the child handling function.
2003-04-16 16:39:23 +00:00
Robert James Kaes
6ff4192069 Removed the remote_content_length field in the "conn" structure and
replaced it with a smaller structure containing both the remote/server
and the local/client content-length fields if they're present in the
HTTP response headers.
2003-04-16 16:37:59 +00:00
Robert James Kaes
bcf25dc67e (add_error_variable): Test whether connptr->error_variable is NULL,
and if so call safemalloc().  This is needed since saferealloc() will
assert() if the first argument is a NULL pointer.
2003-04-01 16:41:33 +00:00
Robert James Kaes
7cd19206cc (establish_http_connection): Always include the port number for the
requested server.  This fixes a problem when the server is not
listening on the default port, 80.
[Fix suggested by duncan@sapio.co.uk]
2003-03-26 16:47:30 +00:00
Robert James Kaes
63a7914830 # Moved the location of the "initializing" log message to below the
processing of the command line options.
2003-03-17 04:24:19 +00:00
Robert James Kaes
d2c9ffac23 Made get_html_file() and lookup_variable() static functions since they
are only used with this file.
2003-03-14 22:49:03 +00:00
Robert James Kaes
5faa0879ec # Added copyright notices for Steve. Reformatted the source code to
better match the existing tinyproxy practise.  Included a few bug
  fixes from Steve.
2003-03-14 22:45:59 +00:00
Robert James Kaes
cc90414b29 (send_http_message): Changed the function to use the new http_message
API.
2003-03-14 06:15:27 +00:00
Robert James Kaes
c76183a3f0 # Updated all the calls to indicate_http_error() to include a
terminating NULL.  The va_arg() function requires it to work
  properly.
2003-03-14 06:13:04 +00:00
Robert James Kaes
75dd0b22c4 Allow the URL for the statistic page to be controlled from the
configuration file, rather than being hard-coded in the program.
[John M Wright]
2003-03-13 21:42:46 +00:00
Robert James Kaes
a46bfdc2e0 Moved the send_http_error_message() and indicate_http_error()
functions into the htmlerror.c file, and recoded them to use the new
variable substitution system. [Steven Young]
2003-03-13 21:34:38 +00:00
Robert James Kaes
badd237fe6 # Added variables to config structure to keep track of the files to be
displayed for various HTTP errors and the stats page. [Steven Young]
2003-03-13 21:32:33 +00:00
Robert James Kaes
b06f26cba1 # Changed showstats() to use the HTML variable functions when
possible.  It still retains the hard-coded page for when an HTML file
  is not available. [Steven Young]
2003-03-13 21:31:03 +00:00
Robert James Kaes
cb8aaf521e # Changed calls to indicate_http_error() to use the new HTML variable
substitution mechanism. [Steven Young]
2003-03-13 21:29:45 +00:00
Robert James Kaes
7995027c8c # Added parser support for the error file configuration keywords
(ErrorFile, DefaultErrorFile, StatFile) [Steven Young]
2003-03-13 21:28:37 +00:00
Robert James Kaes
056bbf84bd # Added variables to keep track of the variables to be substituted in
.html files displayed to the client [Steven Young]
2003-03-13 21:27:29 +00:00
Robert James Kaes
a830af5097 # Steve Young's code to implement file based HTML error messages,
rather than the hard coded string.
2003-03-13 21:25:06 +00:00
Robert James Kaes
d28d9fb195 # Added htmlerror.c and htmlerror.h 2003-03-13 21:23:01 +00:00
Robert James Kaes
2057ffdb50 # Changed the wording of the header comment to remove the reference to
"dnsserver"
2003-03-13 19:31:09 +00:00
Robert James Kaes
99ec965544 # (child_main): If this is a debugging build output the child process
ID and wait for 10 seconds so we have time to connect gdb to the
  child.  This is needed if we want to use gdb against the child
  process.
2003-03-13 19:30:19 +00:00
Robert James Kaes
0a3a1d7c71 Fixed up the include order for the <sys/time.h> and <time.h> headers. 2003-03-13 16:56:28 +00:00
Robert James Kaes
e04ff12768 # Include the http_message.[ch] into the compiled tinyproxy object. 2003-03-13 05:28:46 +00:00
Robert James Kaes
686826c3b0 An API to handle HTTP messages as concrete entities. 2003-03-13 05:25:30 +00:00
Robert James Kaes
2f9370afe7 (chomp): Fixed up the code to prevent negative array access. Added
code to make sure the supplied arguments are valid.
2003-03-13 05:20:06 +00:00
Robert James Kaes
20d3008c38 (main): Removed duplicate code calling the filter_destroy() function.
Once is enough.  [Detected by John M Wright]
2003-02-26 22:37:38 +00:00
Robert James Kaes
40c4d3c57a # (connect_to_upstream): Improved the preprocessor directives to make
sure the function would compile cleanly regardless of how the
  directive was set.
2003-01-28 21:21:55 +00:00
Robert James Kaes
2f98fec1aa # Style clean up. 2003-01-27 18:45:25 +00:00
Robert James Kaes
abbf826445 (display_usage): Removed the output line mentioning that regular
expression support was included.  It will be there always.
2003-01-27 18:44:43 +00:00
Robert James Kaes
2fc9c76969 (connect_to_upstream): Reorganized the preprocessor directives to make
sure the function's symbol name is stored, even if upstream was not
compiled it.  This should keep some compilers from reporting errors.
2003-01-27 18:42:18 +00:00
Robert James Kaes
cb7e3eef04 Added support for conditionally using case sensitive filtering files.
Code changes from James E. Flemer.
2003-01-27 17:57:45 +00:00
Robert James Kaes
212abd64d7 (process_client_headers): Fixed inverted anonymous header logic. Fix
comes from the FreeBSD port through James E. Flemer.
2003-01-27 17:39:02 +00:00
Robert James Kaes
59ec5dc69f (strip_username_password): New function to remove any
username/password part from the host URI.

(extract_http_url), (extract_ssl_url): Use the new
strip_username_password function to remove any non-host information
from the URI.
2002-12-04 17:36:48 +00:00
Robert James Kaes
0a20bdd5b4 Removed the "bool_t" type since it conflicts with the newer C standards.
The type was just replaced by "unsigned int" types.
2002-12-04 17:06:14 +00:00
Robert James Kaes
d069b4fce9 (extract_http_url): Removed the leading "http://" from all the tests,
since it's skipped by the caller before the URL is passed to this
function.

(process_request): Include code to handle proxy FTP requests as
well.  This also lead to a bit of a cleanup in the calling conventions
of extract_http_url function.  tinyproxy can handle both types of
resources by skipping the leading :// part.
2002-11-29 19:25:59 +00:00
Robert James Kaes
e58343012f Included code to disable the sending of the Via header. This is now
controlled by the ViaHeader configure directive.
2002-11-26 21:44:43 +00:00
Robert James Kaes
c826b18437 (child_main): Cleaned up the notice string to be more clear why a
child is being closed.
2002-11-21 21:54:09 +00:00
Robert James Kaes
22df8c29e4 (main): Check to see if the PID file was created successfully, and if
not report this to the user and close the program.
2002-11-21 21:52:59 +00:00
Robert James Kaes
48df7d401c # Changed the return type for pidfile_create() to int from void. 2002-11-21 21:52:03 +00:00
Robert James Kaes
820832a647 (create_file_safely): Rather than exiting the program if there is an
error, a negative "error code" is returned to the program.  The
various callers then need to decide what to do.

(pidfile_create): Returns an error status depending on whether the PID
file was created successfully.
2002-11-21 21:51:34 +00:00
Robert James Kaes
d40a4e8af7 (relay_connection): Shutdown the client socket for writing once all
the data has been sent.
2002-11-13 17:48:48 +00:00
Robert James Kaes
a1e24ac839 (destroy_conn): Added code to log any error messages when the sockets
are closed.
2002-11-13 17:47:40 +00:00
Robert James Kaes
3b2be8ae88 Removed all the code supporting the TCP tunnelling feature of
tinyproxy.  There is really no need for this code, since there are
perfectly good programs out there (like rinetd) which are designed for
TCP tunnelling.  tinyproxy should be a good HTTP proxy, nothing more,
and nothing less; therefore, the tunnelling code is gone.
2002-11-03 17:10:33 +00:00
Robert James Kaes
69be2b84d7 (relay_connection): Ivan pointed out a bug with the code to send any
remaining data to the server when the connections are being closed.
It was a one line fix.
2002-10-17 19:27:08 +00:00
Robert James Kaes
1d39f204ca Fixed up the storing and sending of the internal tinyproxy logs prior
to when the log file is created.  Also, the log file is created with
the proper owner permissions.
2002-10-03 20:53:11 +00:00
Robert James Kaes
745c40650b #Style formatting change. 2002-10-03 20:50:59 +00:00
Robert James Kaes
942f22989a The internal log structure now uses a vector rather than a hash. This
change was required to actually display all the logs in the correct
order.  Also, all log lines are stored internally while tinyproxy is
starting.  At the appropriate point all the logs are written to the
log file.
2002-10-03 20:49:57 +00:00
Robert James Kaes
7fd291f407 Filtering is now case insensitive. 2002-10-03 20:40:39 +00:00
Robert James Kaes
2b44dbd7e4 #(makedaemon): Commented out the closing of the standard file
descriptors since we need them to display error messages.
2002-10-03 20:38:06 +00:00
Robert James Kaes
ac881909bf (child_main): Check to make sure memory could be allocated to handle
the child request.
(child_main_loop): Added a call to truncate_log_file() when the log
file is to be rotated.
2002-10-03 20:33:09 +00:00
Robert James Kaes
f8b5fe53e7 (main): Fixed up a bug reported by Oswald Buddenha where the log file was being initially created with the initial user's permissions, which is obviously a problem if tinyproxy is not running as the initial user. This is now fixed by delaying the creation of the log file until _after_ tinyproxy has been switched to the user it will run as. Confused yet? 2002-07-12 17:02:02 +00:00
Robert James Kaes
ab574cbec0 (create_file_safely):
(pidfile_create): Changed all the error logging to write to standard error and then exit the program.  This will prevent segmentation fault problems from occurring because the log file could not be created properly.
2002-07-09 19:02:57 +00:00