Commit Graph

176 Commits

Author SHA1 Message Date
Mukund Sivaraman
62ddbd5e74 pos can never be less than 0 as it's of type size_t
Also fix the type which is passed in from various places.
2008-08-24 10:58:16 +05:30
Robert James Kaes
5ea289d82e Moved transparent proxy code into its own file
Extracted the transparent proxy logic from reqs.c and placed it into a
separate file.

Signed-off-by: Robert James Kaes <rjk@wormbytes.ca>
2008-06-09 10:01:14 +05:30
Mukund Sivaraman
b0a3568de0 Renamed htmlerror.[ch] to html-error.[ch] 2008-05-24 13:47:14 +05:30
Mukund Sivaraman
249d4b7f33 Updated copyright, license notices in source code
The notices have been changed to a more GNU look. Documentation
comments have been separated from the copyright header. I've tried to
keep all copyright notices intact. Some author contact details have
been updated.
2008-05-24 13:35:49 +05:30
Mukund Sivaraman
d5472ec0bd Renamed file to replace underscores in it with dashes 2008-03-13 15:07:37 -07:00
Robert James Kaes
4c58663041 * [Refactor] Moved Reverse Proxy Code
Moved the reverse proxy code from reqs.c into it's own files
(reverse_proxy.c).  The code in reqs.c is way too complicated, so I
want to move unrelated code into their own files to simplify the main
concepts in reqs.c.
2005-08-16 04:03:19 +00:00
Robert James Kaes
c0299e1868 * [Indent] Ran Source Through indent
I re-indented the source code using indent with the following options:

indent -kr -bad -bap -nut -i8 -l80 -psl -sob -ss -ncs

There are now _no_ tabs in the source files, and all indentation is
eight spaces.  Lines are 80 characters long, and the procedure type is
on it's own line.  Read the indent manual for more information about
what each option means.
2005-08-15 03:54:31 +00:00
Robert James Kaes
a59117c7ca * Updated Copyright Email Addresses
Updated the copyright email addresses for Robert James Kaes.  The
users.sourceforge.net address should always exist.
2005-07-12 17:39:44 +00:00
Robert James Kaes
6042483a0e Removed the proxy-* headers from the list of headers to skip. Since
tinyproxy does not prompt for any proxy information from the client, it
should not be eating the proxy headers.  They are most likely needed by
an upstream proxy.
2005-07-06 21:44:08 +00:00
Robert James Kaes
c446e19003 Added code to handle HTTP/0.9 simple GET requests. 2004-08-24 16:35:27 +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
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
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
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
fd23cd4aed # Fixed a comment to actually reflect what the function does. 2003-08-05 16:11:59 +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
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
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
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
8ab278998f # Renamed the vector_insert() calls to vector_append() 2003-05-29 20:48:25 +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
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
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
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
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
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
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
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
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
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
f47685c861 A bunch of changes from Petr Lampa that add transparent proxy support to tinyproxy. The additional code is in process_request(), but Petr also had to change around some of the other functions (like process_client_headers and handle_connection.) Note: Right now this code has not been tested, but it is believed to work. To enable run ./configure --enable-transparent-proxy 2002-06-06 20:32:30 +00:00
Robert James Kaes
26a983b467 (process_server_headers): Since we're stripping off the carriage return and newline, we need to add them back on when sending the response header to the client. 2002-05-31 18:09:09 +00:00
Robert James Kaes
9b13e9bda8 (add_header_to_connection): Removed the "double_cgi" boolean, since tinyproxy now ignores all the headers after a "double CGI" situation has occurred.
(get_all_headers): Instead of dropping duplicate headers when the "double CGI" situation occurs, tinyproxy will now drop _all_ the headers from the "inner" HTTP response.
2002-05-29 18:11:57 +00:00
Robert James Kaes
e7fcb5fc7d (add_header_to_connection): Added a boolean to indicate that a "Double CGI" situation is in affect. This is needed to solve a problem with some sites (like cgi.ebay.com) where they are sending two HTTP response lines (and associated headers) with a response.
(get_all_headers): Detect if a "Double CGI" situation has occured.
2002-05-28 20:40:01 +00:00
Robert James Kaes
cf2bd809fb (get_all_headers): Added code to ignore a "response" line in a header. This was pointed out as being a problem with eBay (cgi.ebay.com)
(process_server_headers): Added code to make skip blank lines before a response line.
2002-05-28 04:53:33 +00:00
Robert James Kaes
4ce9674365 (process_request): Changed the filtering code around to handle both domains and URLs. 2002-05-27 02:00:22 +00:00
Robert James Kaes
63f481c61a Spelling changes (from thread to child.) 2002-05-26 18:55:19 +00:00
Robert James Kaes
391a408eee Fixed a tonne of spelling mistakes. 2002-05-24 04:45:32 +00:00
Robert James Kaes
47ab97a347 Fixed up a spelling mistake and changed various bits of code to take
advantage of the fact that the peer's socket information is now stored
inside the connection structure.
2002-05-23 18:24:46 +00:00
Robert James Kaes
e4e78e0f1b request->host might have been freed by the time we get to
free_request_struct(), so make sure it's pointing to memory.
2002-05-17 16:34:42 +00:00
Robert James Kaes
bb9f206529 Moved the definition of the struct buffer_s into the buffer.c file and out
of the buffer.h file.  This also required the removal of the BUFFER_SIZE
macro, and replace it with the buffer_size() function.
2002-05-14 00:43:38 +00:00
Robert James Kaes
cf2ecb83b8 Removed the request logging in the tunnel because it breaks the tunnel
concept since it blocks waiting for information from the client before any
data from the remote is relayed.
2002-05-08 03:29:23 +00:00
Robert James Kaes
ed90a4676f Added more error checking in process_client_headers() and
process_server_headers() functions.

Also, better reporting of errors back to the client.
2002-04-28 20:03:18 +00:00
Robert James Kaes
1a8c914dd2 Changed the len type to ssize_t because we need to detect errors in the
recv() call.  Thanks to Tom Cross for discovering this bug.
2002-04-26 19:33:09 +00:00
Robert James Kaes
0e7182533c Need to check the return value of hashmap_first() since it could be
negative.
2002-04-26 16:43:20 +00:00
Robert James Kaes
6992c74bba Check to see if request->path is actually allocated before trying to free
it.
2002-04-25 19:20:56 +00:00
Robert James Kaes
b4ef24844f First change all the hashmap related calls to use the new API.
The remove_connection_headers() function now handles both the Connection
header _and_ the Proxy-Connection header.
2002-04-25 18:58:08 +00:00
Robert James Kaes
335d787018 Fixed a couple of problems where tinyproxy was trying to free a memory
block which had not been allocated.

Also, the "proxy-connection" to the list of headers we don't pass.
2002-04-24 16:47:19 +00:00
Robert James Kaes
1953348c90 Added the "Proxy-Connection" header to the list of client headers which
are not passed along.
2002-04-22 19:34:50 +00:00
Robert James Kaes
60f0a86c75 The stats now wait until after the client has finished sending all its
headers before sending the HTTP response back.  This should be more
standards compliant.
2002-04-18 21:43:53 +00:00
Robert James Kaes
a66aae880c Fixed a memory leak in reading in headers from the client or server. 2002-04-18 17:58:52 +00:00
Robert James Kaes
1d85484c3a If the initialize_conn() function fails, close the socket and return.
Also, changed the call to check_acl() to include the peer's IP and string
addresses.
2002-04-17 20:55:21 +00:00
Robert James Kaes
ca10b1353d Various code clean up. There is nothing new here, just mechanical changes
to the source to either remove code which is not needed, or consolidate
common code into a common section.
2002-04-16 03:20:43 +00:00
Robert James Kaes
550145d49e Changed the variable type in read_request_line() to an unsigned variable
in order to detect negative returns.
2002-04-15 04:14:03 +00:00
Robert James Kaes
a5d3212751 Changed the error boolean flag into a pointer to an error string and an
error code.  We're storing this information because tinyproxy doesn't
output the error information until _after_ the client has sent it's
information.
2002-04-15 02:07:27 +00:00
Robert James Kaes
ecb249f424 Added code to support the new ConnectPort directive which is needed to
improve security of the tinyproxy system.  This new directive allows the
admin to block CONNECT methods to illegal ports.
2002-04-12 17:00:42 +00:00
Robert James Kaes
f1a451faea Added a write_via_header() function which is now used in both header
processing functions.  Also, added a list of headers to drop in the
process server header functions.
2002-04-12 03:09:04 +00:00
Robert James Kaes
85a82af5f5 Did a bit of consolidation by moving code into remove_connection_headers()
and added the get_content_length() function.

The process_server_headers() function was rewritten to remove the
Connection header correctly, and also retrieve the Content-Length value.
This value is needed in the relay_connection() function since there are
some remote machines which do not properly close down the connection once
the body has been retrieved.  Thanks to James Flemer for finding a test
case for this problem.
2002-04-11 20:44:15 +00:00
Robert James Kaes
eef4559783 Removed the compare_header() function since it's been replaced by a call
the anonymous_search().

Added a few more log_message() calls to better explain error conditions.

Fixed up a problem with X-Tinyproxy sending logic.
2002-04-09 20:06:24 +00:00
Robert James Kaes
fb736ec3fb A _tonne_ of changes. It would almost be easier to just read the source
itself to find out all the changes.  Changed the process_client_header()
function to use the hashmap and vector modules.  I've made this change to
better handle the Connection header.  The Connection header, it it's
present, lists all the headers which should _not_ be transmitted any
further along.  An HTTP/1.1 proxy must respect this.

Other changes are basically cosmetic.
2002-04-07 21:35:59 +00:00
Robert James Kaes
475e526a48 Moved write_message() into sock.c because I'm using it in other places. 2001-12-24 00:01:02 +00:00
Robert James Kaes
c3124815a1 Cleaned up the code which sends the "Via" header. It now uses
write_message().
2001-12-23 21:55:08 +00:00
Robert James Kaes
93f0406b7e Created the CHECK_CRLF() macro to handle the tests for the appropriate
control characters in a string.
2001-12-20 04:48:32 +00:00
Robert James Kaes
63a1fa96cc Removed duplicate code from process_server_headers() and removed the calls
to strlen(); readline() already returns the length of the string, so use
that instead.
2001-12-19 20:40:23 +00:00
Robert James Kaes
e964cf0d35 Damn---removed the debugging code from write_message(). 2001-12-19 05:20:01 +00:00
Robert James Kaes
5140f01d5c Opps! Fixed a problem with negative numbers. :) 2001-12-19 05:19:03 +00:00
Robert James Kaes
56b541d76b Redefined HTTP_LINE_LENGTH to be based on MAXBUFFSIZE (and set to around
16 KB.)

Added the TUNNEL_CONFIGURED() macro to help with testing for the tunnel
support code.

Create the write_message() function to encapsulate the code which sends
the information to the file descriptor.

Moved the tunnel code into it's own function.
2001-12-19 05:13:40 +00:00
Robert James Kaes
17103bf8fe Updated the list of headers to ignore. 2001-12-18 05:01:03 +00:00
Robert James Kaes
faf655c5db Added the code to log the request when in tunnelling mode. 2001-12-17 19:10:56 +00:00
Robert James Kaes
9448787ff2 Added UPSTREAM_CONFIGURED() macro to help clean up the code.
Ignore any blank lines when tinyproxy is expecting a request line.

Instead of sending the request line to the remote server in pieces,
tinyproxy nows sends it in once go. This was done to fix a problem with
some sites like www.heise.de.

Changed all calls to connptr->ssl to connptr->connect_method.

Changed all calls to connptr->send_message to
connptr->send_response_message.

Moved the call to Via header code to inside to the tests to handle if
tinyproxy is sending an error message (don't need to send any headers.)
2001-12-17 00:11:32 +00:00
Robert James Kaes
c6c7427e8d Removed the trim() function and move it into chomp()/utils.c 2001-11-23 01:17:19 +00:00
Robert James Kaes
787ece6c01 Reformated text. 2001-11-22 00:31:10 +00:00
Robert James Kaes
1fa9d257c2 Replaced the calls to the old readline() function with calls to the new
version.
2001-11-22 00:19:45 +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
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
ddb002d57e Replaced all calls to buffer_size() with the macro BUFFER_SIZE(). 2001-11-05 15:23:34 +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
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
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
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
b7b4d08758 Error message cleanup to make the information more informative. 2001-10-24 00:37:23 +00:00
Robert James Kaes
358b2781af Cleaned up the code in handle_connection() and added a NULL pointer test
in the free request function.
2001-10-22 16:08:29 +00:00
Robert James Kaes
b40e382e5a More moving around of the source code. Still can't get CONNECT to work
with an upstream proxy.
2001-10-19 18:03:49 +00:00
Robert James Kaes
7a613287ee Trying to allow CONNECT methods through an Upstream proxy. 2001-10-17 04:15:35 +00:00
Robert James Kaes
08baf6b01b Moved the safe_read() and safe_write() functions into the sock.c file
since they're now used in other places.

Added support for a true upstream proxy connection. This involved some
rewriting of the handle_connection() function and some of the support
functions so that they do perform the domain filtering and anonymous
filtering while still connecting to the upstream proxy. I think the code
should be cleaned up further.
2001-09-16 20:10:19 +00:00
Robert James Kaes
b7fc58333b Removed the log messages related to memory allocation.
Move the SSL response header into into own function.
Added support for the status host.
2001-09-15 21:26:14 +00:00