Compare commits

..
43 Commits
Author SHA1 Message Date
Mukund Sivaraman 4b64de4c31 Change wording in NEWS 2010-06-05 09:29:58 +05:30
Mukund Sivaraman 7fa544c3d8 Bump version in configure.ac 2010-06-02 10:40:23 +05:30
Mukund Sivaraman a5a3741291 Add BB#74 to NEWS 2010-06-02 10:39:56 +05:30
Mukund Sivaraman 784d458b82 [BB#74] Create log and pid files after we drop privs 2010-06-02 10:19:49 +05:30
Mukund Sivaraman 94edc4f4c5 Remove excessive code 2010-06-02 10:11:10 +05:30
Mukund Sivaraman be63d2ca19 Add BB#89 to NEWS 2010-06-02 05:05:30 +05:30
Mukund Sivaraman a905437242 Add NEWS for 1.8.2 2010-06-01 08:12:29 +05:30
John van der Kamp 3127e726d0 [BB#89] Don't recompile regular expressions
This is a modification of a patch originally written by
John van der Kamp <john@kirika.demon.nl> at
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579427#12>

The modification was done by the committer.
2010-06-01 07:58:02 +05:30
Mukund Sivaraman 5bb184c54d Fix typo in manpage 2010-05-30 10:02:45 +05:30
Jordi Mallach 505ff803e9 [BB#83] Use output of id instead of $USER 2010-04-21 21:01:59 +05:30
Dmitry Semyonov d03e3a52e5 Fix crash in send_stored_logs() 2010-04-21 20:32:41 +05:30
Mukund Sivaraman fe9444d585 Fix compiler warning about dereferencing type-punned pointers
This is a backport of commit 19b9bff888
from the master branch.
2010-04-21 20:21:22 +05:30
Mukund Sivaraman b37135524d Revert "main: drop privileges right after reading the config"
This reverts commit 965664798c. It should
fix the issue in bug #87.
2010-04-21 20:09:20 +05:30
Mukund Sivaraman 7f053670c0 Just fix the support URLs
These should always point to the top-level Tinyproxy homepage.
2010-03-28 10:29:56 +05:30
Mukund Sivaraman b28e438cdf Revert "Update Tinyproxy website URLs"
This reverts commit e495bdf129.
2010-03-28 10:27:45 +05:30
Mukund Sivaraman e495bdf129 Update Tinyproxy website URLs 2010-03-27 08:19:53 +05:30
Mukund Sivaraman 287a7ae649 Revert "Revert "Pass address family when binding to outgoing socket""
This reverts commit 577ac16cf1. It looks
like bug #69 needs this fix after all.
2010-03-09 17:07:14 +05:30
Mukund Sivaraman 315e129f12 Pull BB#69 out of NEWS for 1.8.1 2010-03-09 06:58:24 +05:30
Mukund Sivaraman 7cb30dd9ee Separate different versions in NEWS with newlines 2010-03-09 06:55:25 +05:30
Mukund Sivaraman 9927d411bf Add the contributors section to 1.8.1 NEWS 2010-03-03 15:37:10 +05:30
Mukund Sivaraman 0f28221ec5 Minor grammatical change 2010-03-03 15:33:40 +05:30
Mukund Sivaraman 57d90c8bf7 Update NEWS for 1.8.1 2010-03-03 15:31:46 +05:30
Mukund Sivaraman 8de8634b8b Bump version to 1.8.1 2010-03-03 15:21:25 +05:30
Mukund Sivaraman ce149cc7a6 Use AI_PASSIVE flag to make tinyproxy listen on wildcard interface
Signed-off-by: Michael Adam <obnox@samba.org>
2010-03-03 09:27:22 +01:00
Michael Adam 410eaf107c Comment out the LogFile and PidFile options in the example tinyproxy.conf.
These are compiled in defaults now.

Michael
2010-03-03 01:06:25 +01:00
Michael Adam e6cbaf7b6e change the default pid file location to "@LOCALSTATEDIR@/run/tinyproxy/tinyproxy.pid"
I.e., add a tinyproxy subdirectory.
This is meant to ease running tinyproxy as non-root user.
The subdirectory can be used to give the tinyproxy user
write permission.

Michael
2010-03-03 01:06:25 +01:00
Michael Adam 2d0192b8a8 change the default log file location to "@LOCALSTATEDIR@/log/tinyproxy/tinyproxy.log"
i.e. add a tinyproxy subdirectory.
This is meant to ease running tinyproxy as non-root user
the subdirectory can be used to give the tinyproxy user
write permission.

Michael
2010-03-03 01:06:25 +01:00
Michael Adam 643d52ac5a main: some tabs->spaces 2010-03-03 01:06:25 +01:00
Michael Adam b92792fd8d main: move a log message. 2010-03-03 01:06:25 +01:00
Michael Adam 965664798c main: drop privileges right after reading the config
This is the second part of fixing bug #74.
I lets tinyproxy create its log and pid files as the
user as which it is running, so that later on at SIGHUP,
the log file can successfully be reopened.

Michael
2010-03-03 01:06:25 +01:00
Michael Adam 6d5709de38 main: separate loading of config and setup_logging at startup
This is the first part of a fix for bug #74
(making reloading of config work if running as non-privileged user)

Michael
2010-03-03 01:06:25 +01:00
Michael Adam 107f9117d0 tinyproxy.conf: fix LogFile to proper CamelCase for consistency 2010-03-03 01:06:24 +01:00
Michael Adam 1b3dd058d1 tests: fix bug #80: keep track of errors in return codes
Michael
(cherry picked from commit 3f1632603c)
2010-02-23 00:19:26 +01:00
Michael Adam 333d722d56 tests: fix a typo in run_tests.sh
(cherry picked from commit 7c15563430)
2010-02-23 00:19:23 +01:00
Michael Adam 6f0abb7339 test: add make target "make valgrind-test-wait"
(cherry picked from commit ee1f1e38f2)
2010-02-22 23:32:08 +01:00
Michael Adam a19f758743 tests: add a new make target "make test-wait"
(cherry picked from commit 752e4419a6)
2010-02-22 23:21:18 +01:00
Michael Adam f63730c77e tests: Fix bug #79. Finish "make test" without waiting for user input.
Old behaviour is preserved by passing in the environment variable
TINYPROXY_TESTS_WAIT=yes.

Michael
(cherry picked from commit d133eee36b)
2010-02-22 23:21:13 +01:00
Mukund Sivaraman ed3ada7c26 Use format string when logging messages 2010-02-19 21:08:00 +05:30
Mukund Sivaraman b9e6d9742d Fix pkgdatadir path in tinyproxy.conf 2010-02-19 21:07:58 +05:30
Mukund Sivaraman fbc434e26d Display upstream proxy support in usage message 2010-02-17 23:18:50 +05:30
Mukund Sivaraman cc74869e71 Fix typo in manpage 2010-01-25 19:35:41 +05:30
Mukund Sivaraman 577ac16cf1 Revert "Pass address family when binding to outgoing socket"
This reverts commit 65ef313cc4.
This patch could've been the reason for BB#69.
2010-01-24 11:18:27 +05:30
Mukund Sivaraman 810b9ae49a Remove completed items from TODO list 2010-01-18 16:01:16 +05:30
52 changed files with 3170 additions and 1592 deletions

No files matched your search

-1
View File
@@ -18,6 +18,5 @@ stamp-h1
autom4te.cache autom4te.cache
cscope.files cscope.files
cscope.out cscope.out
compile
*~ *~
tags tags
-18
View File
@@ -1,18 +0,0 @@
language: C
dist: trusty
sudo: true
before_install:
- sudo apt-get update -qq
- sudo apt-get install --assume-yes asciidoc valgrind
script:
- ./autogen.sh
- ./configure
- make
- make test
- ./configure --enable-debug --enable-transparent --enable-reverse
- make
- make test
- make valgrind-test
- make distcheck
+19 -39
View File
@@ -1,39 +1,19 @@
Andrew Stribblehill Early History
bertliao -------------
Bob Showalter
Brian Cain Steven Young is the original author and was the primary maintainer of
cvs2svn tinyproxy until version 1.1. He also maintained the project from
Daniel Egger version 1.3.1 until 1.4.0.
Daniel M. Drucker
David Shanks Robert James Kaes is the current maintainer and lead programmer. He
Dmitry Semyonov also maintained the project between versions 1.2 and 1.3.0, and again
dmz-uk starting with version 1.4.0.
Drew G. Wallace
Frank Morgner
gary-wzl77 Major Additions/Improvements
Gaudenz Steinlin ----------------------------
goba62000374
Gonzalo Tornaria James E. Flemer <jflemer@acm.jhu.edu> - URL/domain filtering
Greg Kim Holviala <kim@holviala.com> - Reverse proxy support
Jeremy Hinegardner Petr Lampa <lampa@fit.vutbr.cz> - Transparent proxy support
John Spencer George Talusan <gstalusan@uwaterloo.ca> - URL/domain filtering
John van der Kamp
John Weldon
Jordi
Jordi Mallach
Julien Hartmann
kikuchan
Mathew Mrosko
Matthew Dempsky
Michael Adam
Mike Mead
Mukund Sivaraman
Pablo Panero
Peter H. Froehlich
Robert James Kaes
rofl0r
Stephan Leemburg
Steven Conaway
Steven Young
Valen Blanco
Vladimir Belov
+2155 -1
View File
File diff suppressed because it is too large. Load diff
+2 -12
View File
@@ -4,25 +4,15 @@ SUBDIRS = \
etc \ etc \
docs \ docs \
m4macros \ m4macros \
tests \ tests
scripts
# tools want this on a single line # tools want this on a single line
ACLOCAL_AMFLAGS = -I m4macros ACLOCAL_AMFLAGS = -I m4macros
all-local:
dist_doc_DATA = \
AUTHORS \
NEWS \
README \
README.md
EXTRA_DIST = \ EXTRA_DIST = \
autogen.sh \ autogen.sh \
tinyproxy-indent.sh \ tinyproxy-indent.sh \
TODO \ TODO
VERSION
test: all test: all
./tests/scripts/run_tests.sh ./tests/scripts/run_tests.sh
+134 -1
View File
@@ -1 +1,134 @@
See git log for recent changes in Tinyproxy. Tinyproxy NEWS
==============
Version 1.8.2
-------------
* Minor formatting changes and typo fixes were made.
Bugs resolved since version 1.8.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#69: INET6 not available when configured to Listen and Bind in v4,
and vice versa
* BB#74: tinyproxy unable to reopen log files after receiving HUP
* BB#78: Warn if configuration results in an open proxy
* BB#82: https access not working
* BB#83: run_tests.sh relies on $USER
* BB#84: Unaligned access error on ia64 and alpha
* BB#87: Unable to listen on ports less than 1024 (regression in 1.8.1)
* BB#88: Crashes when reloading configuration
* BB#89: tinyproxy leaks memory over time
Contributors
~~~~~~~~~~~~
Dmitry Semyonov, John van der Kamp, Jordi Mallach, Michael Adam,
Mukund Sivaraman.
Version 1.8.1
-------------
* Tinyproxy now drops `root` user privileges more quickly.
* The log and pid files are now stored in a sub-directory in `/var/`.
* A format string vulnerability was fixed.
* Minor formatting changes and typo fixes were made.
Bugs fixed since version 1.8.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#74: tinyproxy unable to reopen log files after receiving HUP
* BB#79: Make the testsuite uninteractive
* BB#80: Handle errors in testsuite
* BB#81: Listen directive doesn't work as expected
* BB#72: upstream support is not reported with tinyproxy -h
* BB#73: generated tinyproxy.conf has the wrong location for the html
file installation
Contributors
~~~~~~~~~~~~
Michael Adam, Mukund Sivaraman.
Version 1.8.0
-------------
* Tinyproxy now reloads its configuration upon SIGHUP signal.
* Tinyproxy reopens its log file (instead of truncation) upon SIGHUP
signal. This is to play more nicely with logrotate.
* File logging is now the default.
Syslog is chosen if and only if "SysLog Yes" is in the config,
i.e., a present "SysLog Yes" in the config file now overrides
any LogFile setting.
* The XTinyProxy option is now documented as a global boolean.
Before it was documented to build a list of sites to add a
X-Tinyproxy header for, but it was implemented as global boolean.
* A new config option AddHeader allows the user to configure a list of
custom headers to send in outgoing HTTP requests.
* A new config option DisableViaHeader allows the user to disable
sending of the "Via:" header.
* Tinyproxy is now IPv6 capable.
* The config option PidFile now has a compiled in default.
Bugs fixed since version 1.7.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#9: Add support for the IPv6 protocol
* BB#17: Add support for custom headers
* BB#55: Error message response omits body when request has a body
* BB#60: Add config option to disable Via header
* BB#61: SIGHUP does not refresh filter list
* BB#62: Make tinyproxy reload the config upon SIGHUP
* BB#64: Config parsing error with reverse proxy option
* BB#65: Format string compile warnings
* BB#67: ACL processing error with multiple Allow statements
Contributors
~~~~~~~~~~~~
David Shanks, Mathew Mrosko, Michael Adam, Mukund Sivaraman.
Version 1.7.1
-------------
* Fixed all warnings reported by GCC.
* The tinyproxy manpage has been extended and converted to asciidoc.
* There is a new tinyproxy.conf manpage that describes all the options.
* The build system has been considerably cleaned up.
* Various other bugs have been fixed.
Bugs fixed since version 1.7.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* BB#2: Fix Tinyproxy for requests like www.site.com:8001
* BB#5: Move templates from the doc directory to its own directory
* BB#8: Update README, INSTALL, NEWS and the manpage
* BB#10: Do not filter out transfer-encoding header
* BB#18: Fix pointer aliasing issues
* BB#53: Add a GPLv2 COPYING file
Contributors
~~~~~~~~~~~~
Andrew Stribblehill, Jeremy Hinegardner, Matthew Dempsky, Michael Adam,
Mukund Sivaraman, Robert James Kaes.
Version 1.7.0
-------------
* There is now support for reverse proxying.
* Tinyproxy does not bundle a vendor regular expressions library
anymore. It uses the system installed regular expressions library.
* The documentation has been updated.
* Tinyproxy now contains some code optimizations such as the use of a
hashmap internally for looking up error pages.
* Various other bugs have been fixed.
Contributors
~~~~~~~~~~~~
Kim Holviala, Marc Silver, Robert James Kaes, Steven Young.
+97 -1
View File
@@ -1 +1,97 @@
see README.md Tinyproxy
=========
Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
GNU General Public License. Tinyproxy is very useful in a small network
setting, where a larger proxy would either be too resource intensive, or
a security risk. One of the key features of Tinyproxy is the buffering
connection concept. In effect, Tinyproxy will buffer a high speed
response from a server, and then relay it to a client at the highest
speed the client will accept. This feature greatly reduces the problems
with sluggishness on the Internet. If you are sharing an Internet
connection with a small network, and you only want to allow HTTP
requests to be allowed, then Tinyproxy is a great tool for the network
administrator.
For more info, please visit:
https://www.banu.com/tinyproxy/
Installation
------------
To install this package under a UNIX derivative, read the INSTALL 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
--enable-xtinyproxy Compile in support for the XTinyproxy
header, which is sent to any web
server in your domain.
--enable-filter Allows Tinyproxy to filter out certain
domains and URLs.
--enable-upstream Enable support for proxying connections
through another proxy server.
--enable-transparent-proxy
Allow Tinyproxy to be used as a
transparent proxy daemon
--enable-static Compile a static version of Tinyproxy
--with-stathost=HOST Set the default name of the stats host
Support
-------
If you are having problems with Tinyproxy, please submit a bug report
using Tinyproxy as the product at:
https://www.banu.com/bugzilla/
You may also wish to subscribe to the Tinyproxy mailing lists. To do so
please visit:
https://www.banu.com/mailman/listinfo/tinyproxy-announce-list
https://www.banu.com/mailman/listinfo/tinyproxy-users-list
https://www.banu.com/mailman/listinfo/tinyproxy-developers-list
for more information on how to subscribe and post messages to the lists.
Contributing
------------
If you would like to contribute a feature, or a bug fix to the Tinyproxy
source, please send a patch (preferably as a unified diff. i.e. `diff
-u` against the "master" branch of the Tinyproxy source code git
repository to tinyproxy-developers-list. Please include a description
of what your patch does.
Tinyproxy's git repository is git://www.banu.com/tinyproxy.git. The
following command creates a local copy:
----
git clone git://www.banu.com/tinyproxy.git
----
The easiest and preferred way to create a patch for submission is to
check in your changes locally and use `git format-patch` to generate a
mbox-style commit file that contains the diff along with the commit
message and author information. Such a format-patch file can be
integrated into the upstream repository, automatically keeping the
commit message and author information.
You can also meet developers and discuss development issues and patches
in the #tinyproxy IRC channel on Freenode (irc.freenode.net).
-89
View File
@@ -1,89 +0,0 @@
# Tinyproxy
Tinyproxy is a small, efficient HTTP/SSL proxy daemon released under the
GNU General Public License. Tinyproxy is very useful in a small network
setting, where a larger proxy would either be too resource intensive, or
a security risk. One of the key features of Tinyproxy is the buffering
connection concept. In effect, Tinyproxy will buffer a high speed
response from a server, and then relay it to a client at the highest
speed the client will accept. This feature greatly reduces the problems
with sluggishness on the Internet. If you are sharing an Internet
connection with a small network, and you only want to allow HTTP
requests to be allowed, then Tinyproxy is a great tool for the network
administrator.
For more info, please visit [the Tinyproxy web site](https://tinyproxy.github.io/).
## Installation
Tinyproxy uses a standard GNU `configure` script based on the automake
system. If compiling from a git checkout, you need to first run
```
./autogen.sh
```
from the top level directory to generate the `configure` script.
The release tarball contains the pre-created `configure` script,
so when building from a release, you can skip this step.
Then basically all you need to do is
```
./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.
- `--enable-xtinyproxy`:
Compile in support for the XTinyproxy header, which is sent to any
web server in your domain.
- `--enable-filter`:
Allows Tinyproxy to filter out certain domains and URLs.
- `--enable-upstream`:
Enable support for proxying connections through another proxy server.
- `--enable-transparent`:
Allow Tinyproxy to be used as a transparent proxy daemon.
- `--enable-reverse`:
Enable reverse proxying.
- `--with-stathost=HOST`:
Set the default name of the stats host.
For more information about the build system, read the INSTALL file
that is generated by `autogen.sh` and comes with the release tar ball.
## Support
If you are having problems with Tinyproxy, please raise an
[issue on github](https://github.com/tinyproxy/tinyproxy/issues).
## Contributing
If you would like to contribute a feature, or a bug fix to the Tinyproxy
source, please clone the
[git repository from github](https://github.com/tinyproxy/tinyproxy.git)
and create a [pull request](https://github.com/tinyproxy/tinyproxy/pulls).
## Community
You can meet developers and users to discuss development,
patches and deployment issues in the `#tinyproxy` IRC channel on
Freenode (`irc.freenode.net`).
+1 -1
View File
@@ -38,7 +38,7 @@ against the current tree and I'll integrate it if possible.
* Include user authentication for accessing tinyproxy itself. * Include user authentication for accessing tinyproxy itself.
Administrators should be allowed to selectively allow certain users Administrators should be allowed to selectively allow certain users
access to tinyproxy via a user name/password pair. Check the access to tinyproxy via a user name/password pair. Check the
HTTP/1.1 RFC for more information. HTTP/1.1 RFC for more information. [Suggested: Tyrone Tranmer]
==> https://www.banu.com/bugzilla/show_bug.cgi?id=13 ==> https://www.banu.com/bugzilla/show_bug.cgi?id=13
-1
View File
@@ -1 +0,0 @@
1.10.0
+129 -54
View File
@@ -3,22 +3,57 @@
AC_PREREQ(2.54) AC_PREREQ(2.54)
m4_define([tinyproxy_version], esyscmd(sh scripts/version.sh | tr -d '\n')) m4_define([tinyproxy_major_version], [1])
m4_define([tinyproxy_minor_version], [8])
m4_define([tinyproxy_micro_version], [2])
m4_define([tinyproxy_real_version],
[tinyproxy_major_version.tinyproxy_minor_version.tinyproxy_micro_version])
m4_define([tinyproxy_version], [tinyproxy_real_version])
# For overriding the version string. Comment out if not needed.
# m4_define([tinyproxy_version], [1.8.2])
m4_define([tinyproxy_unstable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [1], [yes], [no]))
m4_define([tinyproxy_stable],
m4_if(m4_eval(tinyproxy_minor_version % 2), [0], [yes], [no]))
AC_INIT([Tinyproxy], [tinyproxy_version], AC_INIT([Tinyproxy], [tinyproxy_version],
[https://tinyproxy.github.io/], [https://www.banu.com/tinyproxy/],
[tinyproxy]) [tinyproxy])
AC_CANONICAL_TARGET AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([dist-bzip2 dist-xz]) AM_INIT_AUTOMAKE([dist-bzip2])
AC_CONFIG_HEADERS(config.h) AM_CONFIG_HEADER(config.h)
AC_CONFIG_MACRO_DIR([m4macros]) AC_CONFIG_MACRO_DIR([m4macros])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
TINYPROXY_MAJOR_VERSION=tinyproxy_major_version
TINYPROXY_MINOR_VERSION=tinyproxy_minor_version
TINYPROXY_MICRO_VERSION=tinyproxy_micro_version
TINYPROXY_REAL_VERSION=tinyproxy_real_version
TINYPROXY_VERSION=tinyproxy_version
TINYPROXY_UNSTABLE=tinyproxy_unstable
AC_SUBST(TINYPROXY_MAJOR_VERSION)
AC_SUBST(TINYPROXY_MINOR_VERSION)
AC_SUBST(TINYPROXY_MICRO_VERSION)
AC_SUBST(TINYPROXY_REAL_VERSION)
AC_SUBST(TINYPROXY_VERSION)
AC_SUBST(TINYPROXY_UNSTABLE)
dnl Temporarily defined here until we get tinyproxy-version.h dnl Temporarily defined here until we get tinyproxy-version.h
AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number]) AC_DEFINE(TINYPROXY_VERSION, "tinyproxy_version", [Tinyproxy version number])
# The symbol TINYPROXY_UNSTABLE is defined above for substitution in
# Makefiles and conditionally defined here as a preprocessor symbol
# and automake conditional.
if test "x$TINYPROXY_UNSTABLE" = "xyes"; then
AC_DEFINE(TINYPROXY_UNSTABLE, 1,
[Define to 1 if this is an unstable version of Tinyproxy])
fi
AM_CONDITIONAL(TINYPROXY_UNSTABLE, test "x$TINYPROXY_UNSTABLE" = "xyes")
dnl Check if we're compiling on a weird platform :) dnl Check if we're compiling on a weird platform :)
AC_USE_SYSTEM_EXTENSIONS AC_USE_SYSTEM_EXTENSIONS
@@ -78,8 +113,8 @@ dnl Include support for reverse proxy?
AH_TEMPLATE([REVERSE_SUPPORT], AH_TEMPLATE([REVERSE_SUPPORT],
[Include support for reverse proxy.]) [Include support for reverse proxy.])
TP_ARG_ENABLE(reverse, TP_ARG_ENABLE(reverse,
[Enable reverse proxying (default is YES)], [Enable reverse proxying (default is NO)],
yes) no)
if test x"$reverse_enabled" = x"yes"; then if test x"$reverse_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o" ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS reverse-proxy.o"
AC_DEFINE(REVERSE_SUPPORT) AC_DEFINE(REVERSE_SUPPORT)
@@ -89,13 +124,18 @@ dnl Include the transparent proxy support
AH_TEMPLATE([TRANSPARENT_PROXY], AH_TEMPLATE([TRANSPARENT_PROXY],
[Include support for using tinyproxy as a transparent proxy.]) [Include support for using tinyproxy as a transparent proxy.])
TP_ARG_ENABLE(transparent, TP_ARG_ENABLE(transparent,
[Enable transparent proxying code (default is YES)], [Enable transparent proxying code (default is NO)],
yes) no)
if test x"$transparent_enabled" = x"yes"; then if test x"$transparent_enabled" = x"yes"; then
ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o" ADDITIONAL_OBJECTS="$ADDITIONAL_OBJECTS transparent-proxy.o"
AC_DEFINE(TRANSPARENT_PROXY) AC_DEFINE(TRANSPARENT_PROXY)
fi fi
dnl Check for broken regex library
TP_ARG_ENABLE(regexcheck,
[Check for working regex library (default is YES)],
yes)
# This is required to build test programs below # This is required to build test programs below
AC_PROG_CC AC_PROG_CC
@@ -126,19 +166,48 @@ dnl
AC_HEADER_STDC AC_HEADER_STDC
AC_HEADER_TIME AC_HEADER_TIME
AC_HEADER_SYS_WAIT AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([sys/ioctl.h alloca.h memory.h malloc.h sysexits.h \ AC_CHECK_HEADERS([sys/ioctl.h sys/mman.h sys/resource.h \
sys/select.h sys/socket.h sys/time.h sys/uio.h \
sys/un.h arpa/inet.h netinet/in.h \
assert.h ctype.h errno.h fcntl.h grp.h io.h libintl.h \
netdb.h pwd.h regex.h signal.h stdarg.h stddef.h stdio.h \
sysexits.h syslog.h time.h wchar.h wctype.h \
values.h]) values.h])
dnl OpenBSD machines don't like having malloc included (even if it's present)
dnl as they expect you to use stdlib.h
case "$target" in
*-openbsd*) ;;
*) AC_CHECK_HEADER(malloc.h);;
esac
dnl Checks for types
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_UNP_CHECK_TYPE(uint8_t, unsigned char)
AC_UNP_CHECK_TYPE(int16_t, short)
AC_UNP_CHECK_TYPE(uint16_t, unsigned short)
AC_UNP_CHECK_TYPE(int32_t, int)
AC_UNP_CHECK_TYPE(uint32_t, unsigned int)
AC_UNP_CHECK_TYPE(ssize_t, int)
AC_UNP_CHECK_TYPE(socklen_t, unsigned int)
AC_UNP_CHECK_TYPE(in_addr_t, uint32_t)
dnl Checks for libary functions dnl Checks for libary functions
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MALLOC AC_FUNC_MALLOC
AC_FUNC_REALLOC AC_FUNC_REALLOC
AC_CHECK_FUNCS([inet_ntoa strdup]) AC_CHECK_FUNCS([gethostname inet_ntoa memchr memset select socket strcasecmp \
AC_CHECK_FUNCS([strlcpy strlcat setgroups]) strchr strdup strerror strncasecmp strpbrk strstr strtol])
AC_CHECK_FUNCS([isascii memcpy setrlimit ftruncate regcomp regexec])
AC_CHECK_FUNCS([strlcpy strlcat])
dnl Enable extra warnings dnl Enable extra warnings
DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -Wno-overlength-strings -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common" DESIRED_FLAGS="-fdiagnostics-show-option -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wfloat-equal -Wundef -Wformat=2 -Wlogical-op -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Waggregate-return -Winit-self -Wpacked --std=c89 -ansi -pedantic -Wc++-compat -Wno-long-long -Wno-overlength-strings -Wdeclaration-after-statement -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-qual -Wcast-align -Wwrite-strings -Wp,-D_FORTIFY_SOURCE=2 -fno-common"
if test -n "${MAINTAINER_MODE_FALSE}"; then if test -n "${MAINTAINER_MODE_FALSE}"; then
DESIRED_FLAGS="-Werror $DESIRED_FLAGS" DESIRED_FLAGS="-Werror $DESIRED_FLAGS"
@@ -153,17 +222,57 @@ if test x"$debug_enabled" != x"yes" ; then
CFLAGS="-DNDEBUG $CFLAGS" CFLAGS="-DNDEBUG $CFLAGS"
fi fi
AS_ECHO_N(["checking to see if linker understands -z,defs... "]) LDFLAGS="-Wl,-z,defs"
LDFLAGS_OLD="-Wl $LDFLAGS"
LDFLAGS="-Wl,-z,defs $LDFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM()],
AS_ECHO("yes"),
AS_ECHO("no"); LDFLAGS="$LDFLAGS_OLD")
dnl dnl
dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff. dnl Make sure we can actually handle the "--with-*" and "--enable-*" stuff.
dnl dnl
dnl Handle the REGEX library
if test x"$ac_cv_func_regexec" != x"yes"; then
AC_MSG_ERROR([Could not locate the regexec() function])
else
if test x"$regexcheck_enabled" = x"yes" ; then
AC_MSG_CHECKING([whether the system's regex library is broken])
AC_CACHE_VAL(tinyproxy_cv_regex_broken,
[AC_TRY_RUN([
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_REGEX_H
# include <regex.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
int main(void)
{
regex_t blah;
if (regcomp(&blah, "foo.*bar", REG_NOSUB) != 0)
exit(1);
if (regexec(&blah, "foobar", 0, NULL, 0) != 0)
exit(1);
else
exit(0);
return 0;
}
],
tinyproxy_cv_regex_broken=no,
tinyproxy_cv_regex_broken=yes,
tinyproxy_cv_regex_broken=yes)])
AC_MSG_RESULT([$tinyproxy_cv_regex_broken])
if test x"$tinyproxy_cv_regex_broken" = x"yes" ; then
AC_MSG_ERROR([Your system's regexec() function is broken.])
fi
fi
fi
dnl dnl
dnl Substitute the variables into the various Makefiles dnl Substitute the variables into the various Makefiles
dnl dnl
@@ -173,28 +282,12 @@ AC_SUBST(CPPFLAGS)
AC_SUBST(LIBS) AC_SUBST(LIBS)
AC_SUBST(ADDITIONAL_OBJECTS) AC_SUBST(ADDITIONAL_OBJECTS)
# Check for xml tools
AC_PATH_PROG(XSLTPROC, xsltproc, no)
AM_CONDITIONAL(HAVE_XSLTPROC, test "x$XSLTPROC" != "xno")
# Check for asciidoc # Check for asciidoc
AC_PATH_PROG(A2X, a2x, no) AC_PATH_PROG(A2X, a2x, no)
AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno") AM_CONDITIONAL(HAVE_A2X, test "x$A2X" != "xno")
if test x"$A2X" = x"no"; then
# checking xmllint AC_MSG_ERROR([Test for asciidoc failed. See the file 'INSTALL' for help.])
AC_PATH_PROG(XMLLINT, xmllint, no)
if test "x$XMLLINT" != "xno"; then
AS_ECHO_N("testing xmllint... ")
echo "TEST" > conftest.txt
if $A2X -f docbook conftest.txt 2>/dev/null; then
AS_ECHO("ok")
else
AS_ECHO("failed")
XMLLINT="no"
fi
rm -f conftest.txt conftest.xml
fi fi
AM_CONDITIONAL(HAVE_XMLLINT, test "x$XMLLINT" != "xno")
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
@@ -210,24 +303,6 @@ docs/man8/tinyproxy.txt
m4macros/Makefile m4macros/Makefile
tests/Makefile tests/Makefile
tests/scripts/Makefile tests/scripts/Makefile
scripts/Makefile
]) ])
AC_OUTPUT AC_OUTPUT
# the manpages are shipped in the release tarball and we don't want them to
# get regenerated if a2x is not available. the intermediate files from
# AC_CONFIG_FILES are created with config.status, which is created at configure
# runtime, so we need to touch them after config.status terminated to prevent
# make from rebuild them.
if test "x$A2X" = "xno"; then
touch docs/man5/tinyproxy.conf.txt
touch docs/man8/tinyproxy.txt
if test -e docs/man5/tinyproxy.conf.5 ; then
touch docs/man5/tinyproxy.conf.5
fi
if test -e docs/man8/tinyproxy.8 ; then
touch docs/man8/tinyproxy.8
fi
fi
+3 -8
View File
@@ -1,11 +1,9 @@
MAN5_FILES = \ MAN5_FILES = \
tinyproxy.conf.txt tinyproxy.conf.txt
if HAVE_XMLLINT A2X_ARGS = \
A2X_ARGS = -d manpage -f manpage -d manpage \
else -f manpage
A2X_ARGS = -d manpage -f manpage -L
endif
man_MANS = \ man_MANS = \
$(MAN5_FILES:.txt=.5) $(MAN5_FILES:.txt=.5)
@@ -20,6 +18,3 @@ endif
CLEANFILES = \ CLEANFILES = \
$(MAN5_FILES:.txt=.5) \ $(MAN5_FILES:.txt=.5) \
$(MAN5_FILES:.txt=.xml) $(MAN5_FILES:.txt=.xml)
EXTRA_DIST = \
$(MAN5_FILES:.txt=.5)
+13 -14
View File
@@ -144,25 +144,21 @@ The possible keywords and their descriptions are as follows:
`X-Tinyproxy` containing the client's IP address to the request. `X-Tinyproxy` containing the client's IP address to the request.
*Upstream*:: *Upstream*::
*No Upstream*::
This option allows you to set up a set of rules for deciding This option allows you to set up a set of rules for deciding
whether an upstream proxy server is to be used, based on the whether an upstream proxy server is to be used, based on the
host or domain of the site being accessed. The rules are stored host or domain of the site being accessed. The rules are stored
in the order encountered in the configuration file and the in the order encountered in the configuration file and the
LAST matching rule wins. The following forms for specifying upstream LAST matching rule wins. There are three possible forms for
rules exist: specifying upstream rules:
* 'upstream type host:port' turns proxy upstream support on generally. * 'upstream host:port' turns proxy upstream support on generally.
* 'upstream type user:pass@host:port' does the same, but uses the * 'upstream host:port "site_spec"' turns on the upstream proxy for
supplied credentials for authentication. the sites matching `site_spec`.
* 'upstream type host:port "site_spec"' turns on the upstream proxy * 'no upstream "site_spec"' turns off upstream support for sites
for the sites matching `site_spec`.
`type` can be one of `http`, `socks4`, `socks5`, `none`.
* 'upstream none "site_spec"' turns off upstream support for sites
matching `site_spec`. matching `site_spec`.
The site can be specified in various forms as a hostname, domain The site can be specified in various forms as a hostname, domain
@@ -347,7 +343,7 @@ BUGS
---- ----
To report bugs in Tinyproxy, please visit To report bugs in Tinyproxy, please visit
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>. <https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
SEE ALSO SEE ALSO
@@ -358,13 +354,16 @@ tinyproxy(8)
AUTHOR AUTHOR
------ ------
This manpage was written by the Tinyproxy project team. Written by the Tinyproxy project team.
COPYRIGHT COPYRIGHT
--------- ---------
Copyright (c) 1998-2018 the Tinyproxy authors. Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009-2010 Mukund Sivaraman;
Copyright (c) 2009-2010 Michael Adam.
This program is distributed under the terms of the GNU General Public This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional License version 2 or above. See the COPYING file for additional
+4 -9
View File
@@ -1,11 +1,9 @@
MAN8_FILES = \ MAN8_FILES = \
tinyproxy.txt tinyproxy.txt
if HAVE_XMLLINT A2X_ARGS = \
A2X_ARGS = -d manpage -f manpage -d manpage \
else -f manpage
A2X_ARGS = -d manpage -f manpage -L
endif
man_MANS = \ man_MANS = \
$(MAN8_FILES:.txt=.8) $(MAN8_FILES:.txt=.8)
@@ -20,6 +18,3 @@ endif
CLEANFILES = \ CLEANFILES = \
$(MAN8_FILES:.txt=.8) \ $(MAN8_FILES:.txt=.8) \
$(MAN8_FILES:.txt=.xml) $(MAN8_FILES:.txt=.xml)
EXTRA_DIST= \
$(MAN8_FILES:.txt=.8)
+10 -4
View File
@@ -12,7 +12,7 @@ tinyproxy - A light-weight HTTP proxy daemon
SYNOPSIS SYNOPSIS
-------- --------
*tinyproxy* [-vdch] *tinyproxy* [-vldch]
DESCRIPTION DESCRIPTION
@@ -40,6 +40,9 @@ OPTIONS
*-h*:: *-h*::
Display a short help screen of command line arguments and exit. Display a short help screen of command line arguments and exit.
*-l*::
Display the licensing agreement.
*-v*:: *-v*::
Display version information and exit. Display version information and exit.
@@ -133,7 +136,7 @@ BUGS
---- ----
To report bugs in Tinyproxy, please visit To report bugs in Tinyproxy, please visit
<https://tinyproxy.github.io/[https://tinyproxy.github.io/]>. <https://www.banu.com/tinyproxy/[https://www.banu.com/tinyproxy/]>.
SEE ALSO SEE ALSO
@@ -144,13 +147,16 @@ tinyproxy.conf(5)
AUTHOR AUTHOR
------ ------
This manpage was written by the Tinyproxy project team. Written by the Tinyproxy project team.
COPYRIGHT COPYRIGHT
--------- ---------
Copyright (c) 1998-2018 the Tinyproxy authors. Copyright (c) 1998-2000 Steven Young;
Copyright (c) 2000-2001 Robert James Kaes;
Copyright (c) 2009-2010 Mukund Sivaraman;
Copyright (c) 2009-2010 Michael Adam.
This program is distributed under the terms of the GNU General Public This program is distributed under the terms of the GNU General Public
License version 2 or above. See the COPYING file for additional License version 2 or above. See the COPYING file for additional
+2 -4
View File
@@ -1,6 +1,4 @@
pkgsysconfdir = $(sysconfdir)/$(PACKAGE) sysconf_DATA = \
pkgsysconf_DATA = \
tinyproxy.conf tinyproxy.conf
EXTRA_DIST = \ EXTRA_DIST = \
@@ -10,7 +8,7 @@ edit = sed \
-e 's|@bindir[@]|$(bindir)|g' \ -e 's|@bindir[@]|$(bindir)|g' \
-e 's|@datadir[@]|$(datadir)|g' \ -e 's|@datadir[@]|$(datadir)|g' \
-e 's|@datarootdir[@]|$(datarootdir)|g' \ -e 's|@datarootdir[@]|$(datarootdir)|g' \
-e 's|@pkgsysconfdir[@]|$(pkgsysconfdir)|g' \ -e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@localstatedir[@]|$(localstatedir)|g' \ -e 's|@localstatedir[@]|$(localstatedir)|g' \
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \ -e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
-e 's|@prefix[@]|$(prefix)|g' \ -e 's|@prefix[@]|$(prefix)|g' \
+18 -38
View File
@@ -90,8 +90,7 @@ StatFile "@pkgdatadir@/stats.html"
# LogFile: Allows you to specify the location where information should # LogFile: Allows you to specify the location where information should
# be logged to. If you would prefer to log to syslog, then disable this # be logged to. If you would prefer to log to syslog, then disable this
# and enable the Syslog directive. These directives are mutually # and enable the Syslog directive. These directives are mutually
# exclusive. If neither Syslog nor LogFile are specified, output goes # exclusive.
# to stdout.
# #
#LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log" #LogFile "@localstatedir@/log/tinyproxy/tinyproxy.log"
@@ -103,7 +102,7 @@ StatFile "@pkgdatadir@/stats.html"
#Syslog On #Syslog On
# #
# LogLevel: Warning # LogLevel:
# #
# Set the logging level. Allowed settings are: # Set the logging level. Allowed settings are:
# Critical (least verbose) # Critical (least verbose)
@@ -122,7 +121,6 @@ LogLevel Info
# #
# PidFile: Write the PID of the main tinyproxy thread to this file so it # PidFile: Write the PID of the main tinyproxy thread to this file so it
# can be used for signalling purposes. # can be used for signalling purposes.
# If not specified, no pidfile will be written.
# #
#PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid" #PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid"
@@ -140,37 +138,25 @@ LogLevel Info
# The upstream rules allow you to selectively route upstream connections # The upstream rules allow you to selectively route upstream connections
# based on the host/domain of the site being accessed. # based on the host/domain of the site being accessed.
# #
# Syntax: upstream type (user:pass@)ip:port ("domain")
# Or: upstream none "domain"
# The parts in parens are optional.
# Possible types are http, socks4, socks5, none
#
# For example: # For example:
# # connection to test domain goes through testproxy # # connection to test domain goes through testproxy
# upstream http testproxy:8008 ".test.domain.invalid" # upstream testproxy:8008 ".test.domain.invalid"
# upstream http testproxy:8008 ".our_testbed.example.com" # upstream testproxy:8008 ".our_testbed.example.com"
# upstream http testproxy:8008 "192.168.128.0/255.255.254.0" # upstream testproxy:8008 "192.168.128.0/255.255.254.0"
#
# # upstream proxy using basic authentication
# upstream http user:pass@testproxy:8008 ".test.domain.invalid"
# #
# # no upstream proxy for internal websites and unqualified hosts # # no upstream proxy for internal websites and unqualified hosts
# upstream none ".internal.example.com" # no upstream ".internal.example.com"
# upstream none "www.example.com" # no upstream "www.example.com"
# upstream none "10.0.0.0/8" # no upstream "10.0.0.0/8"
# upstream none "192.168.0.0/255.255.254.0" # no upstream "192.168.0.0/255.255.254.0"
# upstream none "." # no upstream "."
# #
# # connection to these boxes go through their DMZ firewalls # # connection to these boxes go through their DMZ firewalls
# upstream http cust1_firewall:8008 "testbed_for_cust1" # upstream cust1_firewall:8008 "testbed_for_cust1"
# upstream http cust2_firewall:8008 "testbed_for_cust2" # upstream cust2_firewall:8008 "testbed_for_cust2"
# #
# # default upstream is internet firewall # # default upstream is internet firewall
# upstream http firewall.internal.example.com:80 # upstream firewall.internal.example.com:80
#
# You may also use SOCKS4/SOCKS5 upstream proxies:
# upstream socks4 127.0.0.1:9050
# upstream socks5 socksproxy:1080
# #
# The LAST matching rule wins the route decision. As you can see, you # The LAST matching rule wins the route decision. As you can see, you
# can use a host, or a domain: # can use a host, or a domain:
@@ -180,7 +166,7 @@ LogLevel Info
# IP/bits matches network/mask # IP/bits matches network/mask
# IP/mask matches network/mask # IP/mask matches network/mask
# #
#Upstream http some.remote.proxy:port #Upstream some.remote.proxy:port
# #
# MaxClients: This is the absolute highest number of threads which will # MaxClients: This is the absolute highest number of threads which will
@@ -222,12 +208,6 @@ MaxRequestsPerChild 0
# tested against the controls based on order. # tested against the controls based on order.
# #
Allow 127.0.0.1 Allow 127.0.0.1
Allow ::1
# BasicAuth: HTTP "Basic Authentication" for accessing the proxy.
# If there are any entries specified, access is only granted for authenticated
# users.
#BasicAuth user password
# #
# AddHeader: Adds the specified headers to outgoing HTTP requests that # AddHeader: Adds the specified headers to outgoing HTTP requests that
@@ -256,7 +236,7 @@ ViaProxyName "tinyproxy"
# #
# Filter: This allows you to specify the location of the filter file. # Filter: This allows you to specify the location of the filter file.
# #
#Filter "@pkgsysconfdir@/filter" #Filter "@sysconfdir@/filter"
# #
# FilterURLs: Filter based on URLs rather than domains. # FilterURLs: Filter based on URLs rather than domains.
@@ -303,12 +283,12 @@ ViaProxyName "tinyproxy"
# ConnectPort: This is a list of ports allowed by tinyproxy when the # ConnectPort: This is a list of ports allowed by tinyproxy when the
# CONNECT method is used. To disable the CONNECT method altogether, set # CONNECT method is used. To disable the CONNECT method altogether, set
# the value to 0. If no ConnectPort line is found, all ports are # the value to 0. If no ConnectPort line is found, all ports are
# allowed. # allowed (which is not very secure.)
# #
# The following two ports are used by SSL. # The following two ports are used by SSL.
# #
#ConnectPort 443 ConnectPort 443
#ConnectPort 563 ConnectPort 563
# #
# Configure one or more ReversePath directives to enable reverse proxy # Configure one or more ReversePath directives to enable reverse proxy
+2 -1
View File
@@ -1,3 +1,4 @@
EXTRA_DIST = \ EXTRA_DIST = \
as-compiler-flag.m4 \ as-compiler-flag.m4 \
argenable.m4 argenable.m4 \
typecheck.m4
+103
View File
@@ -0,0 +1,103 @@
dnl Taken from Unix Network Programming, W. Richard Stevens
dnl ##################################################################
dnl We cannot use the AC_CHECK_TYPE macros becasue AC_CHECK_TYPE
dnl #includes only <sys/types.h>, <stdlib.h>, and <stddef.h>.
dnl Unfortunately, many implementations today hide typedefs in wierd
dnl locations: Solaris 2.5.1 has uint8_t and uint32_t in <pthread.h>.
dnl SunOS 4.1.x has int8_t in <sys/bittypes.h>.
dnl So we define our own macro AC_UNP_CHECK_TYPE that does the same
dnl #includes as "unp.h", and then looks for the typedef.
dnl
dnl This macro should be invoked after all the header checks have been
dnl performed, since we #include "confdefs.h" below, and then use the
dnl HAVE_foo_H values that is can #define.
dnl
AC_DEFUN([AC_UNP_CHECK_TYPE],
[AC_MSG_CHECKING(if $1 defined)
AC_CACHE_VAL(ac_cv_type_$1,
[AC_TRY_COMPILE(
[
#include "confdefs.h" /* the header built by configure so far */
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_FILIO_H
# include <sys/filio.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
],
[ $1 foo ],
[ac_cv_type_$1=yes],
[ac_cv_type_$1=no])])
AC_MSG_RESULT([$ac_cv_type_$1])
if test $ac_cv_type_$1 = no ; then
AH_TEMPLATE([$1], [Defined with the proper type.])
AC_DEFINE($1, $2)
fi
])
-2
View File
@@ -1,2 +0,0 @@
EXTRA_DIST = \
version.sh
-10
View File
@@ -1,10 +0,0 @@
#!/bin/sh
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
AUTHORS_FILE="${BASE_DIR}/AUTHORS"
type git > /dev/null || exit
test -d "${BASE_DIR}/.git" || exit
git log --all --format='%aN' | sort -u > "${AUTHORS_FILE}"
-15
View File
@@ -1,15 +0,0 @@
#!/bin/sh
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
GIT_DIR="${SCRIPT_DIR}/../.git"
if test -d "${GIT_DIR}" ; then
if type git >/dev/null 2>&1 ; then
git describe --match '[0-9]*.[0-9]*.[0-9]*' 2>/dev/null \
| sed -e 's/-/-git-/'
else
sed 's/$/-git/' < VERSION
fi
else
cat VERSION
fi
+2 -6
View File
@@ -15,12 +15,10 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
pkgsysconfdir = $(sysconfdir)/$(PACKAGE) sbin_PROGRAMS = tinyproxy
bin_PROGRAMS = tinyproxy
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-DSYSCONFDIR=\"${pkgsysconfdir}\" \ -DSYSCONFDIR=\"${sysconfdir}\" \
-DLOCALSTATEDIR=\"${localstatedir}\" -DLOCALSTATEDIR=\"${localstatedir}\"
tinyproxy_SOURCES = \ tinyproxy_SOURCES = \
@@ -46,8 +44,6 @@ tinyproxy_SOURCES = \
utils.c utils.h \ utils.c utils.h \
vector.c vector.h \ vector.c vector.h \
upstream.c upstream.h \ upstream.c upstream.h \
basicauth.c basicauth.h \
base64.c base64.h \
connect-ports.c connect-ports.h connect-ports.c connect-ports.h
EXTRA_tinyproxy_SOURCES = filter.c filter.h \ EXTRA_tinyproxy_SOURCES = filter.c filter.h \
+9 -32
View File
@@ -51,7 +51,7 @@ struct acl_s {
union { union {
char *string; char *string;
struct { struct {
unsigned char network[IPV6_LEN]; unsigned char octet[IPV6_LEN];
unsigned char mask[IPV6_LEN]; unsigned char mask[IPV6_LEN];
} ip; } ip;
} address; } address;
@@ -66,8 +66,8 @@ struct acl_s {
* *
*/ */
static int static int
fill_netmask_array (char *bitmask_string, int v6, fill_netmask_array (char *bitmask_string, unsigned char array[],
unsigned char array[], size_t len) size_t len)
{ {
unsigned int i; unsigned int i;
unsigned long int mask; unsigned long int mask;
@@ -81,14 +81,7 @@ fill_netmask_array (char *bitmask_string, int v6,
|| (errno != 0 && mask == 0) || (endptr == bitmask_string)) || (errno != 0 && mask == 0) || (endptr == bitmask_string))
return -1; return -1;
if (v6 == 0) { /* valid range for a bit mask */
/* The mask comparison is done as an IPv6 address, so
* convert to a longer mask in the case of IPv4
* addresses. */
mask += 12 * 8;
}
/* check valid range for a bit mask */
if (mask > (8 * len)) if (mask > (8 * len))
return -1; return -1;
@@ -134,8 +127,7 @@ static int init_access_list(vector_t *access_list)
* -1 on failure * -1 on failure
* 0 otherwise. * 0 otherwise.
*/ */
int int insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
{ {
struct acl_s acl; struct acl_s acl;
int ret; int ret;
@@ -159,20 +151,15 @@ insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
*/ */
if (full_inet_pton (location, ip_dst) > 0) { if (full_inet_pton (location, ip_dst) > 0) {
acl.type = ACL_NUMERIC; acl.type = ACL_NUMERIC;
memcpy (acl.address.ip.network, ip_dst, IPV6_LEN); memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
memset (acl.address.ip.mask, 0xff, IPV6_LEN); memset (acl.address.ip.mask, 0xff, IPV6_LEN);
} else { } else {
int i;
/* /*
* At this point we're either a hostname or an * At this point we're either a hostname or an
* IP address with a slash. * IP address with a slash.
*/ */
p = strchr (location, '/'); p = strchr (location, '/');
if (p != NULL) { if (p != NULL) {
char dst[sizeof(struct in6_addr)];
int v6;
/* /*
* We have a slash, so it's intended to be an * We have a slash, so it's intended to be an
* IP address with mask * IP address with mask
@@ -182,22 +169,12 @@ insert_acl (char *location, acl_access_t access_type, vector_t *access_list)
return -1; return -1;
acl.type = ACL_NUMERIC; acl.type = ACL_NUMERIC;
memcpy (acl.address.ip.octet, ip_dst, IPV6_LEN);
/* Check if the IP address before the netmask is
* an IPv6 address */
if (inet_pton(AF_INET6, location, dst) > 0)
v6 = 1;
else
v6 = 0;
if (fill_netmask_array if (fill_netmask_array
(p + 1, v6, &(acl.address.ip.mask[0]), IPV6_LEN) (p + 1, &(acl.address.ip.mask[0]), IPV6_LEN)
< 0) < 0)
return -1; return -1;
for (i = 0; i < IPV6_LEN; i++)
acl.address.ip.network[i] = ip_dst[i] &
acl.address.ip.mask[i];
} else { } else {
/* In all likelihood a string */ /* In all likelihood a string */
acl.type = ACL_STRING; acl.type = ACL_STRING;
@@ -311,7 +288,7 @@ static int check_numeric_acl (const struct acl_s *acl, const char *ip)
for (i = 0; i != IPV6_LEN; ++i) { for (i = 0; i != IPV6_LEN; ++i) {
x = addr[i] & acl->address.ip.mask[i]; x = addr[i] & acl->address.ip.mask[i];
y = acl->address.ip.network[i]; y = acl->address.ip.octet[i] & acl->address.ip.mask[i];
/* If x and y don't match, the IP addresses don't match */ /* If x and y don't match, the IP addresses don't match */
if (x != y) if (x != y)
-57
View File
@@ -1,57 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* this file Copyright (C) 2016-2018 rofl0r
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "base64.h"
static const char base64_tbl[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/*
rofl0r's base64 impl (taken from libulz)
takes count bytes from src, writing base64 encoded string into dst.
dst needs to be at least BASE64ENC_BYTES(count) + 1 bytes in size.
the string in dst will be zero-terminated.
*/
void base64enc(char *dst, const void* src, size_t count)
{
unsigned const char *s = src;
char* d = dst;
while(count) {
int i = 0, n = *s << 16;
s++;
count--;
if(count) {
n |= *s << 8;
s++;
count--;
i++;
}
if(count) {
n |= *s;
s++;
count--;
i++;
}
*d++ = base64_tbl[(n >> 18) & 0x3f];
*d++ = base64_tbl[(n >> 12) & 0x3f];
*d++ = i ? base64_tbl[(n >> 6) & 0x3f] : '=';
*d++ = i == 2 ? base64_tbl[n & 0x3f] : '=';
}
*d = 0;
}
-29
View File
@@ -1,29 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* this file Copyright (C) 2016-2018 rofl0r
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef TINYPROXY_BASE64_H
#define TINYPROXY_BASE64_H
#include <stddef.h>
/* calculates number of bytes base64-encoded stream of N bytes will take. */
#define BASE64ENC_BYTES(N) (((N+2)/3)*4)
void base64enc(char *dst, const void* src, size_t count);
#endif
-98
View File
@@ -1,98 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* This file: Copyright (C) 2016-2017 rofl0r
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "main.h"
#include "basicauth.h"
#include "conns.h"
#include "heap.h"
#include "html-error.h"
#include "log.h"
#include "conf.h"
#include "base64.h"
/*
* Create basic-auth token in buf.
* Returns strlen of token on success,
* -1 if user/pass missing
* 0 if user/pass too long
*/
ssize_t basicauth_string(const char *user, const char *pass,
char *buf, size_t bufsize)
{
char tmp[256+2];
int l;
if (!user || !pass) return -1;
l = snprintf(tmp, sizeof tmp, "%s:%s", user, pass);
if (l < 0 || l >= (ssize_t) sizeof tmp) return 0;
if (bufsize < (BASE64ENC_BYTES((unsigned)l) + 1)) return 0;
base64enc(buf, tmp, l);
return BASE64ENC_BYTES(l);
}
/*
* Add entry to the basicauth list
*/
void basicauth_add (vector_t authlist,
const char *user, const char *pass)
{
char b[BASE64ENC_BYTES((256+2)-1) + 1];
ssize_t ret;
ret = basicauth_string(user, pass, b, sizeof b);
if (ret == -1) {
log_message (LOG_WARNING,
"Illegal basicauth rule: missing user or pass");
return;
} else if (ret == 0) {
log_message (LOG_WARNING,
"User / pass in basicauth rule too long");
return;
}
if (vector_append(authlist, b, ret + 1) == -ENOMEM) {
log_message (LOG_ERR,
"Unable to allocate memory in basicauth_add()");
return;
}
log_message (LOG_INFO,
"Added basic auth user : %s", user);
}
/*
* Check if a user/password combination (encoded as base64)
* is in the basicauth list.
* return 1 on success, 0 on failure.
*/
int basicauth_check (vector_t authlist, const char *authstring)
{
ssize_t vl, i;
size_t el;
const char* entry;
vl = vector_length (authlist);
if (vl == -EINVAL) return 0;
for (i = 0; i < vl; i++) {
entry = vector_getentry (authlist, i, &el);
if (strcmp (authstring, entry) == 0)
return 1;
}
return 0;
}
-35
View File
@@ -1,35 +0,0 @@
/* tinyproxy - A fast light-weight HTTP proxy
* Copyright (C) 2005 Robert James Kaes <rjkaes@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* See 'basicauth.c' for detailed information. */
#ifndef TINYPROXY_BASICAUTH_H
#define TINYPROXY_BASICAUTH_H
#include <stddef.h>
#include "vector.h"
extern ssize_t basicauth_string(const char *user, const char *pass,
char *buf, size_t bufsize);
extern void basicauth_add (vector_t authlist,
const char *user, const char *pass);
extern int basicauth_check (vector_t authlist, const char *authstring);
#endif
+17 -15
View File
@@ -236,27 +236,29 @@ ssize_t read_buffer (int fd, struct buffer_s * buffptr)
"readbuff: add_to_buffer() error."); "readbuff: add_to_buffer() error.");
bytesin = -1; bytesin = -1;
} }
} else if (bytesin == 0) {
/* connection was closed by client */
bytesin = -1;
} else { } else {
switch (errno) { if (bytesin == 0) {
/* connection was closed by client */
bytesin = -1;
} else {
switch (errno) {
#ifdef EWOULDBLOCK #ifdef EWOULDBLOCK
case EWOULDBLOCK: case EWOULDBLOCK:
#else #else
# ifdef EAGAIN # ifdef EAGAIN
case EAGAIN: case EAGAIN:
# endif # endif
#endif #endif
case EINTR: case EINTR:
bytesin = 0; bytesin = 0;
break; break;
default: default:
log_message (LOG_ERR, log_message (LOG_ERR,
"read_buffer: read() failed on fd %d: %s", "readbuff: recv() error \"%s\" on file descriptor %d",
fd, strerror(errno)); strerror (errno), fd);
bytesin = -1; bytesin = -1;
break; break;
}
} }
} }
+8 -136
View File
@@ -32,7 +32,8 @@
#include "utils.h" #include "utils.h"
#include "conf.h" #include "conf.h"
static vector_t listen_fds; static int listenfd;
static socklen_t addrlen;
/* /*
* Stores the internal data needed for each child (connection) * Stores the internal data needed for each child (connection)
@@ -186,13 +187,8 @@ static void child_main (struct child_s *ptr)
int connfd; int connfd;
struct sockaddr *cliaddr; struct sockaddr *cliaddr;
socklen_t clilen; socklen_t clilen;
fd_set rfds;
int maxfd = 0;
ssize_t i;
int ret;
cliaddr = (struct sockaddr *) cliaddr = (struct sockaddr *) safemalloc (addrlen);
safemalloc (sizeof(struct sockaddr_storage));
if (!cliaddr) { if (!cliaddr) {
log_message (LOG_CRIT, log_message (LOG_CRIT,
"Could not allocate memory for child address."); "Could not allocate memory for child address.");
@@ -200,82 +196,11 @@ static void child_main (struct child_s *ptr)
} }
ptr->connects = 0; ptr->connects = 0;
srand(time(NULL));
/*
* We have to wait for connections on multiple fds,
* so use select.
*/
while (!config.quit) { while (!config.quit) {
int listenfd = -1;
FD_ZERO(&rfds);
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
ret = socket_nonblocking(*fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the listening "
"socket %d to non-blocking: %s",
fd, strerror(errno));
exit(1);
}
FD_SET(*fd, &rfds);
maxfd = max(maxfd, *fd);
}
ptr->status = T_WAITING; ptr->status = T_WAITING;
clilen = sizeof(struct sockaddr_storage); clilen = addrlen;
ret = select(maxfd + 1, &rfds, NULL, NULL, NULL);
if (ret == -1) {
if (errno == EINTR) {
continue;
}
log_message (LOG_ERR, "error calling select: %s",
strerror(errno));
exit(1);
} else if (ret == 0) {
log_message (LOG_WARNING, "Strange: select returned 0 "
"but we did not specify a timeout...");
continue;
}
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
if (FD_ISSET(*fd, &rfds)) {
/*
* only accept the connection on the first
* fd that we find readable. - fair?
*/
listenfd = *fd;
break;
}
}
if (listenfd == -1) {
log_message(LOG_WARNING, "Strange: None of our listen "
"fds was readable after select");
continue;
}
ret = socket_blocking(listenfd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set listening "
"socket %d to blocking for accept: %s",
listenfd, strerror(errno));
exit(1);
}
/*
* We have a socket that is readable.
* Continue handling this connection.
*/
connfd = accept (listenfd, cliaddr, &clilen); connfd = accept (listenfd, cliaddr, &clilen);
@@ -539,66 +464,13 @@ void child_kill_children (int sig)
} }
} }
int child_listening_sock (uint16_t port)
/**
* Listen on the various configured interfaces
*/
int child_listening_sockets(vector_t listen_addrs, uint16_t port)
{ {
int ret; listenfd = listen_sock (port, &addrlen);
ssize_t i; return listenfd;
assert (port > 0);
if (listen_fds == NULL) {
listen_fds = vector_create();
if (listen_fds == NULL) {
log_message (LOG_ERR, "Could not create the list "
"of listening fds");
return -1;
}
}
if ((listen_addrs == NULL) ||
(vector_length(listen_addrs) == 0))
{
/*
* no Listen directive:
* listen on the wildcard address(es)
*/
ret = listen_sock(NULL, port, listen_fds);
return ret;
}
for (i = 0; i < vector_length(listen_addrs); i++) {
const char *addr;
addr = (char *)vector_getentry(listen_addrs, i, NULL);
if (addr == NULL) {
log_message(LOG_WARNING,
"got NULL from listen_addrs - skipping");
continue;
}
ret = listen_sock(addr, port, listen_fds);
if (ret != 0) {
return ret;
}
}
return 0;
} }
void child_close_sock (void) void child_close_sock (void)
{ {
ssize_t i; close (listenfd);
for (i = 0; i < vector_length(listen_fds); i++) {
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
close (*fd);
}
vector_delete(listen_fds);
listen_fds = NULL;
} }
+1 -3
View File
@@ -21,8 +21,6 @@
#ifndef TINYPROXY_CHILD_H #ifndef TINYPROXY_CHILD_H
#define TINYPROXY_CHILD_H #define TINYPROXY_CHILD_H
#include "vector.h"
typedef enum { typedef enum {
CHILD_MAXCLIENTS, CHILD_MAXCLIENTS,
CHILD_MAXSPARESERVERS, CHILD_MAXSPARESERVERS,
@@ -32,7 +30,7 @@ typedef enum {
} child_config_t; } child_config_t;
extern short int child_pool_create (void); extern short int child_pool_create (void);
extern int child_listening_sockets (vector_t listen_addrs, uint16_t port); extern int child_listening_sock (uint16_t port);
extern void child_close_sock (void); extern void child_close_sock (void);
extern void child_main_loop (void); extern void child_main_loop (void);
extern void child_kill_children (int sig); extern void child_kill_children (int sig);
+111 -44
View File
@@ -32,67 +32,134 @@
/* /*
* Include standard headers which are used through-out tinyproxy * Include standard headers which are used through-out tinyproxy
*/ */
#ifdef HAVE_SYS_TYPES_H
/* standard C headers - we can safely assume they exist. */
#include <stddef.h>
#include <stdint.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* standard POSIX headers - they need to be there as well. */
# include <errno.h>
# include <fcntl.h>
# include <netdb.h>
# include <signal.h>
# include <stdarg.h>
# include <strings.h>
# include <syslog.h>
# include <wchar.h>
# include <wctype.h>
# include <sys/mman.h>
# include <sys/select.h>
# include <sys/socket.h>
# include <sys/stat.h>
# include <sys/types.h> # include <sys/types.h>
# include <sys/wait.h> #endif
# include <sys/uio.h>
# include <sys/un.h>
# include <sys/time.h>
# include <time.h>
# include <inttypes.h>
# include <sys/resource.h>
# include <netinet/in.h>
# include <assert.h>
# include <arpa/inet.h>
# include <grp.h>
# include <pwd.h>
# include <regex.h>
/* rest - some oddball headers */
#ifdef HAVE_VALUES_H #ifdef HAVE_VALUES_H
# include <values.h> # include <values.h>
#endif #endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_ALLOCA_H #ifdef HAVE_ALLOCA_H
# include <alloca.h> # include <alloca.h>
#endif #endif
#ifdef HAVE_ASSERT_H
# include <assert.h>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_GRP_H
# include <grp.h>
#endif
#ifdef HAVE_MEMORY_H #ifdef HAVE_MEMORY_H
# include <memory.h> # include <memory.h>
#endif #endif
#ifdef HAVE_NETDB_H
#ifdef HAVE_MALLOC_H # include <netdb.h>
# include <malloc.h> #endif
#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#ifdef HAVE_REGEX_H
# include <regex.h>
#endif
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
# ifdef HAVE_MALLOC_H
# include <malloc.h>
# endif
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif #endif
#ifdef HAVE_SYSEXITS_H #ifdef HAVE_SYSEXITS_H
# include <sysexits.h> # include <sysexits.h>
#endif
#ifdef HAVE_SYSLOG_H
# include <syslog.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_WCHAR_H
# include <wchar.h>
#endif
#ifdef HAVE_WCTYPE_H
# include <wctype.h>
#endif
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif #endif
/* /*
+38 -122
View File
@@ -36,7 +36,6 @@
#include "reverse-proxy.h" #include "reverse-proxy.h"
#include "upstream.h" #include "upstream.h"
#include "connect-ports.h" #include "connect-ports.h"
#include "basicauth.h"
/* /*
* The configuration directives are defined in the structure below. Each * The configuration directives are defined in the structure below. Each
@@ -52,8 +51,6 @@
#define BOOL "(yes|on|no|off)" #define BOOL "(yes|on|no|off)"
#define INT "((0x)?[[:digit:]]+)" #define INT "((0x)?[[:digit:]]+)"
#define ALNUM "([-a-z0-9._]+)" #define ALNUM "([-a-z0-9._]+)"
#define USERNAME "([^:]*)"
#define PASSWORD "([^@]*)"
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})" #define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
#define IPMASK "(" IP "(/[[:digit:]]+)?)" #define IPMASK "(" IP "(/[[:digit:]]+)?)"
#define IPV6 "(" \ #define IPV6 "(" \
@@ -119,7 +116,6 @@ static HANDLE_FUNC (handle_nop)
} /* do nothing function */ } /* do nothing function */
static HANDLE_FUNC (handle_allow); static HANDLE_FUNC (handle_allow);
static HANDLE_FUNC (handle_basicauth);
static HANDLE_FUNC (handle_anonymous); static HANDLE_FUNC (handle_anonymous);
static HANDLE_FUNC (handle_bind); static HANDLE_FUNC (handle_bind);
static HANDLE_FUNC (handle_bindsame); static HANDLE_FUNC (handle_bindsame);
@@ -234,7 +230,6 @@ struct {
handle_deny), handle_deny),
STDCONF ("bind", "(" IP "|" IPV6 ")", handle_bind), STDCONF ("bind", "(" IP "|" IPV6 ")", handle_bind),
/* other */ /* other */
STDCONF ("basicauth", ALNUM WS ALNUM, handle_basicauth),
STDCONF ("errorfile", INT WS STR, handle_errorfile), STDCONF ("errorfile", INT WS STR, handle_errorfile),
STDCONF ("addheader", STR WS STR, handle_addheader), STDCONF ("addheader", STR WS STR, handle_addheader),
@@ -254,15 +249,13 @@ struct {
STDCONF ("reversepath", STR "(" WS STR ")?", handle_reversepath), STDCONF ("reversepath", STR "(" WS STR ")?", handle_reversepath),
#endif #endif
#ifdef UPSTREAM_SUPPORT #ifdef UPSTREAM_SUPPORT
/* upstream is rather complicated */
{ {
BEGIN "(upstream)" WS "(none)" WS STR END, handle_upstream_no, NULL BEGIN "(no" WS "upstream)" WS STR END, handle_upstream_no, NULL
}, },
{ {
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS BEGIN "(upstream)" WS "(" IP "|" ALNUM ")" ":" INT "(" WS STR
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?" ")?" END, handle_upstream, NULL
"(" IP "|" ALNUM ")"
":" INT "(" WS STR ")?"
END, handle_upstream, NULL
}, },
#endif #endif
/* loglevel */ /* loglevel */
@@ -295,8 +288,7 @@ static void free_config (struct config_s *conf)
safefree (conf->stathost); safefree (conf->stathost);
safefree (conf->user); safefree (conf->user);
safefree (conf->group); safefree (conf->group);
vector_delete(conf->listen_addrs); safefree (conf->ipAddr);
vector_delete(conf->basicauth_list);
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
safefree (conf->filter); safefree (conf->filter);
#endif /* FILTER_ENABLE */ #endif /* FILTER_ENABLE */
@@ -473,18 +465,8 @@ static void initialize_with_defaults (struct config_s *conf,
conf->group = safestrdup (defaults->group); conf->group = safestrdup (defaults->group);
} }
if (defaults->listen_addrs) { if (defaults->ipAddr) {
ssize_t i; conf->ipAddr = safestrdup (defaults->ipAddr);
conf->listen_addrs = vector_create();
for (i=0; i < vector_length(defaults->listen_addrs); i++) {
char *addr;
size_t size;
addr = (char *)vector_getentry(defaults->listen_addrs,
i, &size);
vector_append(conf->listen_addrs, addr, size);
}
} }
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
@@ -777,7 +759,12 @@ static HANDLE_FUNC (handle_xtinyproxy)
static HANDLE_FUNC (handle_syslog) static HANDLE_FUNC (handle_syslog)
{ {
#ifdef HAVE_SYSLOG_H
return set_bool_arg (&conf->syslog, line, &match[2]); return set_bool_arg (&conf->syslog, line, &match[2]);
#else
fprintf (stderr, "Syslog support not compiled in executable.\n");
return 1;
#endif
} }
static HANDLE_FUNC (handle_bindsame) static HANDLE_FUNC (handle_bindsame)
@@ -792,15 +779,7 @@ static HANDLE_FUNC (handle_bindsame)
static HANDLE_FUNC (handle_port) static HANDLE_FUNC (handle_port)
{ {
set_int_arg (&conf->port, line, &match[2]); return set_int_arg (&conf->port, line, &match[2]);
if (conf->port > 65535) {
fprintf (stderr, "Bad port number (%d) supplied for Port.\n",
conf->port);
return 1;
}
return 0;
} }
static HANDLE_FUNC (handle_maxclients) static HANDLE_FUNC (handle_maxclients)
@@ -878,6 +857,7 @@ static HANDLE_FUNC (handle_deny)
static HANDLE_FUNC (handle_bind) static HANDLE_FUNC (handle_bind)
{ {
#ifndef TRANSPARENT_PROXY
int r = set_string_arg (&conf->bind_address, line, &match[2]); int r = set_string_arg (&conf->bind_address, line, &match[2]);
if (r) if (r)
@@ -885,31 +865,20 @@ static HANDLE_FUNC (handle_bind)
log_message (LOG_INFO, log_message (LOG_INFO,
"Outgoing connections bound to IP %s", conf->bind_address); "Outgoing connections bound to IP %s", conf->bind_address);
return 0; return 0;
#else
fprintf (stderr,
"\"Bind\" cannot be used with transparent support enabled.\n");
return 1;
#endif
} }
static HANDLE_FUNC (handle_listen) static HANDLE_FUNC (handle_listen)
{ {
char *arg = get_string_arg (line, &match[2]); int r = set_string_arg (&conf->ipAddr, line, &match[2]);
if (arg == NULL) { if (r)
return -1; return r;
} log_message (LOG_INFO, "Listening on IP %s", conf->ipAddr);
if (conf->listen_addrs == NULL) {
conf->listen_addrs = vector_create();
if (conf->listen_addrs == NULL) {
log_message(LOG_WARNING, "Could not create a list "
"of listen addresses.");
safefree(arg);
return -1;
}
}
vector_append (conf->listen_addrs, arg, strlen(arg) + 1);
log_message(LOG_INFO, "Added address [%s] to listen addresses.", arg);
safefree (arg);
return 0; return 0;
} }
@@ -956,7 +925,6 @@ static HANDLE_FUNC (handle_addheader)
/* /*
* Log level's strings. * Log level's strings.
*/ */
struct log_levels_s { struct log_levels_s {
const char *string; const char *string;
@@ -991,27 +959,6 @@ static HANDLE_FUNC (handle_loglevel)
return -1; return -1;
} }
static HANDLE_FUNC (handle_basicauth)
{
char *user, *pass;
user = get_string_arg(line, &match[2]);
if (!user)
return -1;
pass = get_string_arg(line, &match[3]);
if (!pass) {
safefree (user);
return -1;
}
if (!conf->basicauth_list) {
conf->basicauth_list = vector_create ();
}
basicauth_add (conf->basicauth_list, user, pass);
safefree (user);
safefree (pass);
return 0;
}
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
static HANDLE_FUNC (handle_filter) static HANDLE_FUNC (handle_filter)
{ {
@@ -1088,58 +1035,27 @@ static HANDLE_FUNC (handle_reversepath)
#endif #endif
#ifdef UPSTREAM_SUPPORT #ifdef UPSTREAM_SUPPORT
static enum proxy_type pt_from_string(const char *s)
{
static const char pt_map[][7] = {
[PT_NONE] = "none",
[PT_HTTP] = "http",
[PT_SOCKS4] = "socks4",
[PT_SOCKS5] = "socks5",
};
unsigned i;
for (i = 0; i < sizeof(pt_map)/sizeof(pt_map[0]); i++)
if (!strcmp(pt_map[i], s))
return i;
return PT_NONE;
}
static HANDLE_FUNC (handle_upstream) static HANDLE_FUNC (handle_upstream)
{ {
char *ip; char *ip;
int port, mi = 2; int port;
char *domain = 0, *user = 0, *pass = 0, *tmp; char *domain;
enum proxy_type pt;
tmp = get_string_arg (line, &match[mi]); ip = get_string_arg (line, &match[2]);
pt = pt_from_string(tmp);
safefree(tmp);
mi += 2;
if (match[mi].rm_so != -1)
user = get_string_arg (line, &match[mi]);
mi++;
if (match[mi].rm_so != -1)
pass = get_string_arg (line, &match[mi]);
mi++;
ip = get_string_arg (line, &match[mi]);
if (!ip) if (!ip)
return -1; return -1;
mi += 5; port = (int) get_long_arg (line, &match[7]);
port = (int) get_long_arg (line, &match[mi]); if (match[9].rm_so != -1) {
mi += 3; domain = get_string_arg (line, &match[9]);
if (domain) {
upstream_add (ip, port, domain, &conf->upstream_list);
safefree (domain);
}
} else {
upstream_add (ip, port, NULL, &conf->upstream_list);
}
if (match[mi].rm_so != -1)
domain = get_string_arg (line, &match[mi]);
upstream_add (ip, port, domain, user, pass, pt, &conf->upstream_list);
safefree (user);
safefree (pass);
safefree (domain);
safefree (ip); safefree (ip);
return 0; return 0;
@@ -1149,11 +1065,11 @@ static HANDLE_FUNC (handle_upstream_no)
{ {
char *domain; char *domain;
domain = get_string_arg (line, &match[3]); domain = get_string_arg (line, &match[2]);
if (!domain) if (!domain)
return -1; return -1;
upstream_add (NULL, 0, domain, 0, 0, PT_NONE, &conf->upstream_list); upstream_add (NULL, 0, domain, &conf->upstream_list);
safefree (domain); safefree (domain);
return 0; return 0;
+1 -2
View File
@@ -37,7 +37,6 @@ typedef struct {
* Hold all the configuration time information. * Hold all the configuration time information.
*/ */
struct config_s { struct config_s {
vector_t basicauth_list;
char *logf_name; char *logf_name;
char *config_file; char *config_file;
unsigned int syslog; /* boolean */ unsigned int syslog; /* boolean */
@@ -47,7 +46,7 @@ struct config_s {
unsigned int quit; /* boolean */ unsigned int quit; /* boolean */
char *user; char *user;
char *group; char *group;
vector_t listen_addrs; char *ipAddr;
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
char *filter; char *filter;
unsigned int filter_url; /* boolean */ unsigned int filter_url; /* boolean */
+1 -1
View File
@@ -38,7 +38,7 @@ void add_connect_port_allowed (int port, vector_t *connect_ports)
log_message (LOG_INFO, log_message (LOG_INFO,
"Adding Port [%d] to the list allowed by CONNECT", port); "Adding Port [%d] to the list allowed by CONNECT", port);
vector_append (*connect_ports, &port, sizeof (port)); vector_append (*connect_ports, (void **) &port, sizeof (port));
} }
/* /*
+7 -8
View File
@@ -52,7 +52,7 @@ void filter_init (void)
FILE *fd; FILE *fd;
struct filter_list *p; struct filter_list *p;
char buf[FILTER_BUFFER_LEN]; char buf[FILTER_BUFFER_LEN];
char *s, *start; char *s;
int cflags; int cflags;
if (fl || already_init) { if (fl || already_init) {
@@ -73,16 +73,11 @@ void filter_init (void)
cflags |= REG_ICASE; cflags |= REG_ICASE;
while (fgets (buf, FILTER_BUFFER_LEN, fd)) { while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
/* skip leading whitespace */
s = buf;
while (*s && isspace ((unsigned char) *s))
s++;
start = s;
/* /*
* Remove any trailing white space and * Remove any trailing white space and
* comments. * comments.
*/ */
s = buf;
while (*s) { while (*s) {
if (isspace ((unsigned char) *s)) if (isspace ((unsigned char) *s))
break; break;
@@ -98,7 +93,11 @@ void filter_init (void)
++s; ++s;
} }
*s = '\0'; *s = '\0';
s = start;
/* skip leading whitespace */
s = buf;
while (*s && isspace ((unsigned char) *s))
s++;
/* skip blank lines and comments */ /* skip blank lines and comments */
if (*s == '\0') if (*s == '\0')
+11 -33
View File
@@ -50,7 +50,6 @@ struct hashbucket_s {
}; };
struct hashmap_s { struct hashmap_s {
uint32_t seed;
unsigned int size; unsigned int size;
hashmap_iter end_iterator; hashmap_iter end_iterator;
@@ -64,12 +63,9 @@ struct hashmap_s {
* The contents of the key are converted to lowercase, so this function * The contents of the key are converted to lowercase, so this function
* is not case-sensitive. * is not case-sensitive.
* *
* This is Dan Bernstein's hash function as described, for example, here:
* http://www.cse.yorku.ca/~oz/hash.html
*
* If any of the arguments are invalid a negative number is returned. * If any of the arguments are invalid a negative number is returned.
*/ */
static int hashfunc (const char *key, unsigned int size, uint32_t seed) static int hashfunc (const char *key, unsigned int size)
{ {
uint32_t hash; uint32_t hash;
@@ -78,8 +74,12 @@ static int hashfunc (const char *key, unsigned int size, uint32_t seed)
if (size == 0) if (size == 0)
return -ERANGE; return -ERANGE;
for (hash = seed; *key != '\0'; key++) { for (hash = tolower (*key++); *key != '\0'; key++) {
hash = ((hash << 5) + hash) ^ tolower (*key); uint32_t bit = (hash & 1) ? (1 << (sizeof (uint32_t) - 1)) : 0;
hash >>= 1;
hash += tolower (*key) + bit;
} }
/* Keep the hash within the table limits */ /* Keep the hash within the table limits */
@@ -104,7 +104,6 @@ hashmap_t hashmap_create (unsigned int nbuckets)
if (!ptr) if (!ptr)
return NULL; return NULL;
ptr->seed = (uint32_t)rand();
ptr->size = nbuckets; ptr->size = nbuckets;
ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets, ptr->buckets = (struct hashbucket_s *) safecalloc (nbuckets,
sizeof (struct sizeof (struct
@@ -202,7 +201,7 @@ hashmap_insert (hashmap_t map, const char *key, const void *data, size_t len)
if (!data || len < 1) if (!data || len < 1)
return -ERANGE; return -ERANGE;
hash = hashfunc (key, map->size, map->seed); hash = hashfunc (key, map->size);
if (hash < 0) if (hash < 0)
return hash; return hash;
@@ -383,7 +382,7 @@ ssize_t hashmap_search (hashmap_t map, const char *key)
if (map == NULL || key == NULL) if (map == NULL || key == NULL)
return -EINVAL; return -EINVAL;
hash = hashfunc (key, map->size, map->seed); hash = hashfunc (key, map->size);
if (hash < 0) if (hash < 0)
return hash; return hash;
@@ -417,7 +416,7 @@ ssize_t hashmap_entry_by_key (hashmap_t map, const char *key, void **data)
if (!map || !key || !data) if (!map || !key || !data)
return -EINVAL; return -EINVAL;
hash = hashfunc (key, map->size, map->seed); hash = hashfunc (key, map->size);
if (hash < 0) if (hash < 0)
return hash; return hash;
@@ -452,7 +451,7 @@ ssize_t hashmap_remove (hashmap_t map, const char *key)
if (map == NULL || key == NULL) if (map == NULL || key == NULL)
return -EINVAL; return -EINVAL;
hash = hashfunc (key, map->size, map->seed); hash = hashfunc (key, map->size);
if (hash < 0) if (hash < 0)
return hash; return hash;
@@ -493,24 +492,3 @@ ssize_t hashmap_remove (hashmap_t map, const char *key)
/* The key was not found, so return 0 */ /* The key was not found, so return 0 */
return deleted; return deleted;
} }
/*
* Look up the value for a variable.
*/
char *lookup_variable (hashmap_t map, const char *varname)
{
hashmap_iter result_iter;
char *key;
char *data;
result_iter = hashmap_find (map, varname);
if (hashmap_is_end (map, result_iter))
return (NULL);
if (hashmap_return_entry (map, result_iter,
&key, (void **) &data) < 0)
return (NULL);
return (data);
}
-5
View File
@@ -117,9 +117,4 @@ extern ssize_t hashmap_search (hashmap_t map, const char *key);
*/ */
extern ssize_t hashmap_remove (hashmap_t map, const char *key); extern ssize_t hashmap_remove (hashmap_t map, const char *key);
/*
* Look up the value for a variable.
*/
extern char *lookup_variable (hashmap_t map, const char *varname);
#endif /* _HASHMAP_H */ #endif /* _HASHMAP_H */
+28 -23
View File
@@ -62,7 +62,7 @@ static char *get_html_file (unsigned int errornum)
hashmap_iter result_iter; hashmap_iter result_iter;
char errornbuf[ERRORNUM_BUFSIZE]; char errornbuf[ERRORNUM_BUFSIZE];
char *key; char *key;
char *val; static char *val;
assert (errornum >= 100 && errornum < 1000); assert (errornum >= 100 && errornum < 1000);
@@ -83,6 +83,27 @@ static char *get_html_file (unsigned int errornum)
return (val); return (val);
} }
/*
* Look up the value for a variable.
*/
static char *lookup_variable (struct conn_s *connptr, const char *varname)
{
hashmap_iter result_iter;
char *key;
static char *data;
result_iter = hashmap_find (connptr->error_variables, varname);
if (hashmap_is_end (connptr->error_variables, result_iter))
return (NULL);
if (hashmap_return_entry (connptr->error_variables, result_iter,
&key, (void **) &data) < 0)
return (NULL);
return (data);
}
/* /*
* Send an already-opened file to the client with variable substitution. * Send an already-opened file to the client with variable substitution.
*/ */
@@ -105,7 +126,7 @@ send_html_file (FILE *infile, struct conn_s *connptr)
if (in_variable) { if (in_variable) {
*p = '\0'; *p = '\0';
varval = (const char *) varval = (const char *)
lookup_variable (connptr->error_variables, lookup_variable (connptr,
varstart); varstart);
if (!varval) if (!varval)
varval = "(unknown)"; varval = "(unknown)";
@@ -132,7 +153,6 @@ send_html_file (FILE *infile, struct conn_s *connptr)
} else } else
in_variable = 0; in_variable = 0;
/* FALL THROUGH */
default: default:
if (!in_variable) { if (!in_variable) {
r = write_message (connptr->client_fd, r = write_message (connptr->client_fd,
@@ -157,28 +177,13 @@ send_html_file (FILE *infile, struct conn_s *connptr)
int send_http_headers (struct conn_s *connptr, int code, const char *message) int send_http_headers (struct conn_s *connptr, int code, const char *message)
{ {
const char headers[] = const char *headers =
"HTTP/1.0 %d %s\r\n" "HTTP/1.0 %d %s\r\n"
"Server: %s/%s\r\n" "Server: %s/%s\r\n"
"Content-Type: text/html\r\n" "Content-Type: text/html\r\n" "Connection: close\r\n" "\r\n";
"%s"
"Connection: close\r\n" "\r\n";
const char p_auth_str[] =
"Proxy-Authenticate: Basic realm=\""
PACKAGE_NAME "\"\r\n";
const char w_auth_str[] =
"WWW-Authenticate: Basic realm=\""
PACKAGE_NAME "\"\r\n";
/* according to rfc7235, the 407 error must be accompanied by
a Proxy-Authenticate header field. */
const char *add = code == 407 ? p_auth_str : (code == 401 ? w_auth_str : "");
return (write_message (connptr->client_fd, headers, return (write_message (connptr->client_fd, headers,
code, message, PACKAGE, VERSION, code, message, PACKAGE, VERSION));
add));
} }
/* /*
@@ -207,7 +212,7 @@ int send_http_error_message (struct conn_s *connptr)
error_file = get_html_file (connptr->error_number); error_file = get_html_file (connptr->error_number);
if (!(infile = fopen (error_file, "r"))) { if (!(infile = fopen (error_file, "r"))) {
char *detail = lookup_variable (connptr->error_variables, "detail"); char *detail = lookup_variable (connptr, "detail");
return (write_message (connptr->client_fd, fallback_error, return (write_message (connptr->client_fd, fallback_error,
connptr->error_number, connptr->error_number,
connptr->error_string, connptr->error_string,
@@ -275,7 +280,7 @@ int add_standard_vars (struct conn_s *connptr)
add_error_variable (connptr, "date", timebuf); add_error_variable (connptr, "date", timebuf);
add_error_variable (connptr, "website", add_error_variable (connptr, "website",
"https://tinyproxy.github.io/"); "https://www.banu.com/tinyproxy/");
add_error_variable (connptr, "version", VERSION); add_error_variable (connptr, "version", VERSION);
add_error_variable (connptr, "package", PACKAGE); add_error_variable (connptr, "package", PACKAGE);
+7 -22
View File
@@ -70,14 +70,7 @@ static unsigned int logging_initialized = FALSE; /* boolean */
*/ */
int open_log_file (const char *log_file_name) int open_log_file (const char *log_file_name)
{ {
if (log_file_name == NULL) { log_file_fd = create_file_safely (log_file_name, FALSE);
if(config.godaemon == FALSE)
log_file_fd = fileno(stdout);
else
log_file_fd = -1;
} else {
log_file_fd = create_file_safely (log_file_name, FALSE);
}
return log_file_fd; return log_file_fd;
} }
@@ -86,7 +79,7 @@ int open_log_file (const char *log_file_name)
*/ */
void close_log_file (void) void close_log_file (void)
{ {
if (log_file_fd < 0 || log_file_fd == fileno(stdout)) { if (log_file_fd < 0) {
return; return;
} }
@@ -161,9 +154,6 @@ void log_message (int level, const char *fmt, ...)
goto out; goto out;
} }
if(!config.syslog && log_file_fd == -1)
goto out;
if (config.syslog) { if (config.syslog) {
#ifdef HAVE_VSYSLOG_H #ifdef HAVE_VSYSLOG_H
vsyslog (level, fmt, args); vsyslog (level, fmt, args);
@@ -198,13 +188,8 @@ void log_message (int level, const char *fmt, ...)
ret = write (log_file_fd, str, strlen (str)); ret = write (log_file_fd, str, strlen (str));
if (ret == -1) { if (ret == -1) {
config.syslog = TRUE; log_message (LOG_WARNING,
"Could not write to log file");
log_message(LOG_CRIT, "ERROR: Could not write to log "
"file %s: %s.",
config.logf_name, strerror(errno));
log_message(LOG_CRIT,
"Falling back to syslog logging");
} }
fsync (log_file_fd); fsync (log_file_fd);
@@ -217,7 +202,7 @@ out:
/* /*
* This needs to send any stored log messages. * This needs to send any stored log messages.
*/ */
static void send_stored_logs (void) void send_stored_logs (void)
{ {
char *string; char *string;
char *ptr; char *ptr;
@@ -273,10 +258,10 @@ int setup_logging (void)
config.syslog = TRUE; config.syslog = TRUE;
log_message (LOG_CRIT, "ERROR: Could not create log " log_message (LOG_CRIT, "ERROR: Could not create log "
"file %s: %s.", "file %s: %s.\n",
config.logf_name, strerror (errno)); config.logf_name, strerror (errno));
log_message (LOG_CRIT, log_message (LOG_CRIT,
"Falling back to syslog logging."); "Falling back to syslog logging\n");
} }
} }
+11 -1
View File
@@ -77,7 +77,16 @@
* don't advocate this, but it could be useful at times.) * don't advocate this, but it could be useful at times.)
*/ */
#include <syslog.h> #ifdef HAVE_SYSLOG_H
# include <syslog.h>
#else
# define LOG_CRIT 2
# define LOG_ERR 3
# define LOG_WARNING 4
# define LOG_NOTICE 5
# define LOG_INFO 6
# define LOG_DEBUG 7
#endif
#define LOG_CONN 8 /* extra to log connections without the INFO stuff */ #define LOG_CONN 8 /* extra to log connections without the INFO stuff */
@@ -106,6 +115,7 @@ extern void close_log_file (void);
extern void log_message (int level, const char *fmt, ...); extern void log_message (int level, const char *fmt, ...);
extern void set_log_level (int level); extern void set_log_level (int level);
extern void send_stored_logs (void);
extern int setup_logging (void); extern int setup_logging (void);
extern void shutdown_logging (void); extern void shutdown_logging (void);
+54 -33
View File
@@ -86,6 +86,37 @@ display_version (void)
printf ("%s %s\n", PACKAGE, VERSION); printf ("%s %s\n", PACKAGE, VERSION);
} }
/*
* Display the copyright and license for this program.
*/
static void
display_license (void)
{
display_version ();
printf ("\
Copyright 1998 Steven Young (sdyoung@well.com)\n\
Copyright 1998-2002 Robert James Kaes (rjkaes@users.sourceforge.net)\n\
Copyright 1999 George Talusan (gstalusan@uwaterloo.ca)\n\
Copyright 2000 Chris Lightfoot (chris@ex-parrot.com)\n\
Copyright 2009-2010 Mukund Sivaraman (muks@banu.com)\n\
Copyright 2009-2010 Michael Adam (obnox@samba.org)\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation; either version 2, or (at your option)\n\
any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n");
}
/* /*
* Display usage to the user. * Display usage to the user.
*/ */
@@ -100,6 +131,7 @@ display_usage (void)
" -d Do not daemonize (run in foreground).\n" " -d Do not daemonize (run in foreground).\n"
" -c FILE Use an alternate configuration file.\n" " -c FILE Use an alternate configuration file.\n"
" -h Display this usage information.\n" " -h Display this usage information.\n"
" -l Display the license.\n"
" -v Display version information.\n"); " -v Display version information.\n");
/* Display the modes compiled into tinyproxy */ /* Display the modes compiled into tinyproxy */
@@ -139,8 +171,8 @@ display_usage (void)
printf (" None\n"); printf (" None\n");
printf ("\n" printf ("\n"
"For support and bug reporting instructions, please visit\n" "For bug reporting instructions, please see:\n"
"<https://tinyproxy.github.io/>.\n"); "<https://www.banu.com/tinyproxy/>.\n");
} }
static int static int
@@ -173,12 +205,16 @@ process_cmdline (int argc, char **argv, struct config_s *conf)
{ {
int opt; int opt;
while ((opt = getopt (argc, argv, "c:vdh")) != EOF) { while ((opt = getopt (argc, argv, "c:vldh")) != EOF) {
switch (opt) { switch (opt) {
case 'v': case 'v':
display_version (); display_version ();
exit (EX_OK); exit (EX_OK);
case 'l':
display_license ();
exit (EX_OK);
case 'd': case 'd':
conf->godaemon = FALSE; conf->godaemon = FALSE;
break; break;
@@ -241,16 +277,6 @@ change_user (const char *program)
exit (EX_NOPERM); exit (EX_NOPERM);
} }
#ifdef HAVE_SETGROUPS
/* Drop all supplementary groups, otherwise these are inherited from the calling process */
if (setgroups (0, NULL) < 0) {
fprintf (stderr,
"%s: Unable to drop supplementary groups.\n",
program);
exit (EX_NOPERM);
}
#endif
log_message (LOG_INFO, "Now running as group \"%s\".", log_message (LOG_INFO, "Now running as group \"%s\".",
config.group); config.group);
} }
@@ -300,8 +326,8 @@ static void initialize_config_defaults (struct config_s *conf)
conf->errorpages = NULL; conf->errorpages = NULL;
conf->stathost = safestrdup (TINYPROXY_STATHOST); conf->stathost = safestrdup (TINYPROXY_STATHOST);
conf->idletimeout = MAX_IDLE_TIME; conf->idletimeout = MAX_IDLE_TIME;
conf->logf_name = NULL; conf->logf_name = safestrdup (LOCALSTATEDIR "/log/tinyproxy/tinyproxy.log");
conf->pidpath = NULL; conf->pidpath = safestrdup (LOCALSTATEDIR "/run/tinyproxy/tinyproxy.pid");
} }
/** /**
@@ -360,13 +386,8 @@ main (int argc, char **argv)
anonymous_insert ("Content-Type"); anonymous_insert ("Content-Type");
} }
if (config.godaemon == TRUE) { if (config.godaemon == TRUE)
if (!config.syslog && config.logf_name == NULL)
fprintf(stderr, "WARNING: logging deactivated "
"(can't log to stdout when daemonized)\n");
makedaemon (); makedaemon ();
}
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) { if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n", fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
@@ -380,21 +401,12 @@ main (int argc, char **argv)
#endif /* FILTER_ENABLE */ #endif /* FILTER_ENABLE */
/* Start listening on the selected port. */ /* Start listening on the selected port. */
if (child_listening_sockets(config.listen_addrs, config.port) < 0) { if (child_listening_sock (config.port) < 0) {
fprintf (stderr, "%s: Could not create listening sockets.\n", fprintf (stderr, "%s: Could not create listening socket.\n",
argv[0]); argv[0]);
exit (EX_OSERR); exit (EX_OSERR);
} }
/* Create pid file before we drop privileges */
if (config.pidpath) {
if (pidfile_create (config.pidpath) < 0) {
fprintf (stderr, "%s: Could not create PID file.\n",
argv[0]);
exit (EX_OSERR);
}
}
/* Switch to a different user if we're running as root */ /* Switch to a different user if we're running as root */
if (geteuid () == 0) if (geteuid () == 0)
change_user (argv[0]); change_user (argv[0]);
@@ -407,6 +419,15 @@ main (int argc, char **argv)
exit (EX_SOFTWARE); exit (EX_SOFTWARE);
} }
/* Create pid file after we drop privileges */
if (config.pidpath) {
if (pidfile_create (config.pidpath) < 0) {
fprintf (stderr, "%s: Could not create PID file.\n",
argv[0]);
exit (EX_OSERR);
}
}
if (child_pool_create () < 0) { if (child_pool_create () < 0) {
fprintf (stderr, fprintf (stderr,
"%s: Could not create the pool of children.\n", "%s: Could not create the pool of children.\n",
@@ -446,7 +467,7 @@ main (int argc, char **argv)
child_close_sock (); child_close_sock ();
/* Remove the PID file */ /* Remove the PID file */
if (config.pidpath != NULL && unlink (config.pidpath) < 0) { if (unlink (config.pidpath) < 0) {
log_message (LOG_WARNING, log_message (LOG_WARNING,
"Could not remove PID file \"%s\": %s.", "Could not remove PID file \"%s\": %s.",
config.pidpath, strerror (errno)); config.pidpath, strerror (errno));
+7 -16
View File
@@ -32,11 +32,10 @@
* Write the buffer to the socket. If an EINTR occurs, pick up and try * Write the buffer to the socket. If an EINTR occurs, pick up and try
* again. Keep sending until the buffer has been sent. * again. Keep sending until the buffer has been sent.
*/ */
ssize_t safe_write (int fd, const void *buf, size_t count) ssize_t safe_write (int fd, const char *buffer, size_t count)
{ {
ssize_t len; ssize_t len;
size_t bytestosend; size_t bytestosend;
const char *buffer = buf;
assert (fd >= 0); assert (fd >= 0);
assert (buffer != NULL); assert (buffer != NULL);
@@ -68,7 +67,7 @@ ssize_t safe_write (int fd, const void *buf, size_t count)
* Matched pair for safe_write(). If an EINTR occurs, pick up and try * Matched pair for safe_write(). If an EINTR occurs, pick up and try
* again. * again.
*/ */
ssize_t safe_read (int fd, void *buffer, size_t count) ssize_t safe_read (int fd, char *buffer, size_t count)
{ {
ssize_t len; ssize_t len;
@@ -192,11 +191,7 @@ ssize_t readline (int fd, char **whole_buffer)
goto CLEANUP; goto CLEANUP;
} }
ret = recv (fd, line_ptr->data, diff, 0); recv (fd, line_ptr->data, diff, 0);
if (ret == -1) {
goto CLEANUP;
}
line_ptr->len = diff; line_ptr->len = diff;
if (ptr) { if (ptr) {
@@ -250,10 +245,8 @@ CLEANUP:
* Convert the network address into either a dotted-decimal or an IPv6 * Convert the network address into either a dotted-decimal or an IPv6
* hex string. * hex string.
*/ */
const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen) char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{ {
const char *result;
assert (sa != NULL); assert (sa != NULL);
assert (buf != NULL); assert (buf != NULL);
assert (buflen != 0); assert (buflen != 0);
@@ -264,8 +257,7 @@ const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{ {
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa; struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
result = inet_ntop (AF_INET, &sa_in->sin_addr, buf, inet_ntop (AF_INET, &sa_in->sin_addr, buf, buflen);
buflen);
break; break;
} }
case AF_INET6: case AF_INET6:
@@ -273,8 +265,7 @@ const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
struct sockaddr_in6 *sa_in6 = struct sockaddr_in6 *sa_in6 =
(struct sockaddr_in6 *) sa; (struct sockaddr_in6 *) sa;
result = inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, buflen);
buflen);
break; break;
} }
default: default:
@@ -282,7 +273,7 @@ const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
return NULL; return NULL;
} }
return result; return buf;
} }
/* /*
+3 -3
View File
@@ -21,13 +21,13 @@
#ifndef TINYPROXY_NETWORK_H #ifndef TINYPROXY_NETWORK_H
#define TINYPROXY_NETWORK_H #define TINYPROXY_NETWORK_H
extern ssize_t safe_write (int fd, const void *buf, size_t count); extern ssize_t safe_write (int fd, const char *buffer, size_t count);
extern ssize_t safe_read (int fd, void *buf, size_t count); extern ssize_t safe_read (int fd, char *buffer, size_t count);
extern int write_message (int fd, const char *fmt, ...); extern int write_message (int fd, const char *fmt, ...);
extern ssize_t readline (int fd, char **whole_buffer); extern ssize_t readline (int fd, char **whole_buffer);
extern const char *get_ip_string (struct sockaddr *sa, char *buf, size_t len); extern char *get_ip_string (struct sockaddr *sa, char *buf, size_t len);
extern int full_inet_pton (const char *ip, void *dst); extern int full_inet_pton (const char *ip, void *dst);
#endif #endif
+68 -303
View File
@@ -48,7 +48,6 @@
#include "upstream.h" #include "upstream.h"
#include "connect-ports.h" #include "connect-ports.h"
#include "conf.h" #include "conf.h"
#include "basicauth.h"
/* /*
* Maximum length of a HTTP line * Maximum length of a HTTP line
@@ -62,11 +61,9 @@
#ifdef UPSTREAM_SUPPORT #ifdef UPSTREAM_SUPPORT
# define UPSTREAM_CONFIGURED() (config.upstream_list != NULL) # define UPSTREAM_CONFIGURED() (config.upstream_list != NULL)
# define UPSTREAM_HOST(host) upstream_get(host, config.upstream_list) # define UPSTREAM_HOST(host) upstream_get(host, config.upstream_list)
# define UPSTREAM_IS_HTTP(conn) (conn->upstream_proxy != NULL && conn->upstream_proxy->type == PT_HTTP)
#else #else
# define UPSTREAM_CONFIGURED() (0) # define UPSTREAM_CONFIGURED() (0)
# define UPSTREAM_HOST(host) (NULL) # define UPSTREAM_HOST(host) (NULL)
# define UPSTREAM_IS_HTTP(up) (0)
#endif #endif
/* /*
@@ -170,18 +167,12 @@ static void strip_username_password (char *host)
static int strip_return_port (char *host) static int strip_return_port (char *host)
{ {
char *ptr1; char *ptr1;
char *ptr2;
int port; int port;
ptr1 = strrchr (host, ':'); ptr1 = strchr (host, ':');
if (ptr1 == NULL) if (ptr1 == NULL)
return 0; return 0;
/* Check for IPv6 style literals */
ptr2 = strchr (ptr1, ']');
if (ptr2 != NULL)
return 0;
*ptr1++ = '\0'; *ptr1++ = '\0';
if (sscanf (ptr1, "%d", &port) != 1) /* one conversion required */ if (sscanf (ptr1, "%d", &port) != 1) /* one conversion required */
return 0; return 0;
@@ -189,22 +180,18 @@ static int strip_return_port (char *host)
} }
/* /*
* Pull the information out of the URL line. * Pull the information out of the URL line. This will handle both HTTP
* This expects urls with the initial '<proto>://' * and FTP (proxied) URLs.
* part stripped and hence can handle http urls,
* (proxied) ftp:// urls and https-requests that
* come in without the proto:// part via CONNECT.
*/ */
static int extract_url (const char *url, int default_port, static int extract_http_url (const char *url, struct request_s *request)
struct request_s *request)
{ {
char *p; char *p;
int len;
int port; int port;
/* Split the URL on the slash to separate host from path */ /* Split the URL on the slash to separate host from path */
p = strchr (url, '/'); p = strchr (url, '/');
if (p != NULL) { if (p != NULL) {
int len;
len = p - url; len = p - url;
request->host = (char *) safemalloc (len + 1); request->host = (char *) safemalloc (len + 1);
memcpy (request->host, url, len); memcpy (request->host, url, len);
@@ -223,17 +210,7 @@ static int extract_url (const char *url, int default_port,
/* Find a proper port in www.site.com:8001 URLs */ /* Find a proper port in www.site.com:8001 URLs */
port = strip_return_port (request->host); port = strip_return_port (request->host);
request->port = (port != 0) ? port : default_port; request->port = (port != 0) ? port : HTTP_PORT;
/* Remove any surrounding '[' and ']' from IPv6 literals */
p = strrchr (request->host, ']');
if (p && (*(request->host) == '[')) {
memmove(request->host, request->host + 1,
strlen(request->host) - 2);
*p = '\0';
p--;
*p = '\0';
}
return 0; return 0;
@@ -246,6 +223,31 @@ ERROR_EXIT:
return -1; return -1;
} }
/*
* Extract the URL from a SSL connection.
*/
static int extract_ssl_url (const char *url, struct request_s *request)
{
request->host = (char *) safemalloc (strlen (url) + 1);
if (!request->host)
return -1;
if (sscanf (url, "%[^:]:%hu", request->host, &request->port) == 2) ;
else if (sscanf (url, "%s", request->host) == 1)
request->port = HTTP_PORT_SSL;
else {
log_message (LOG_ERR, "extract_ssl_url: Can't parse URL.");
safefree (request->host);
return -1;
}
/* Remove the username/password if they're present */
strip_username_password (request->host);
return 0;
}
/* /*
* Create a connection for HTTP connections. * Create a connection for HTTP connections.
*/ */
@@ -253,7 +255,6 @@ static int
establish_http_connection (struct conn_s *connptr, struct request_s *request) establish_http_connection (struct conn_s *connptr, struct request_s *request)
{ {
char portbuff[7]; char portbuff[7];
char dst[sizeof(struct in6_addr)];
/* Build a port string if it's not a standard port */ /* Build a port string if it's not a standard port */
if (request->port != HTTP_PORT && request->port != HTTP_PORT_SSL) if (request->port != HTTP_PORT && request->port != HTTP_PORT_SSL)
@@ -261,34 +262,12 @@ establish_http_connection (struct conn_s *connptr, struct request_s *request)
else else
portbuff[0] = '\0'; portbuff[0] = '\0';
if (inet_pton(AF_INET6, request->host, dst) > 0) { return write_message (connptr->server_fd,
/* host is an IPv6 address literal, so surround it with "%s %s HTTP/1.0\r\n"
* [] */ "Host: %s%s\r\n"
return write_message (connptr->server_fd, "Connection: close\r\n",
"%s %s HTTP/1.0\r\n" request->method, request->path,
"Host: [%s]%s\r\n" request->host, portbuff);
"Connection: close\r\n",
request->method, request->path,
request->host, portbuff);
} else if (connptr->upstream_proxy &&
connptr->upstream_proxy->type == PT_HTTP &&
connptr->upstream_proxy->ua.authstr) {
return write_message (connptr->server_fd,
"%s %s HTTP/1.0\r\n"
"Host: %s%s\r\n"
"Connection: close\r\n"
"Proxy-Authorization: Basic %s\r\n",
request->method, request->path,
request->host, portbuff,
connptr->upstream_proxy->ua.authstr);
} else {
return write_message (connptr->server_fd,
"%s %s HTTP/1.0\r\n"
"Host: %s%s\r\n"
"Connection: close\r\n",
request->method, request->path,
request->host, portbuff);
}
} }
/* /*
@@ -371,6 +350,15 @@ BAD_REQUEST_ERROR:
goto fail; goto fail;
} }
if (!url) {
log_message (LOG_ERR,
"process_request: Null URL on file descriptor %d",
connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Request has an empty URL",
"url", url, NULL);
goto fail;
}
#ifdef REVERSE_SUPPORT #ifdef REVERSE_SUPPORT
if (config.reversepath_list != NULL) { if (config.reversepath_list != NULL) {
/* /*
@@ -383,18 +371,12 @@ BAD_REQUEST_ERROR:
reverse_url = reverse_rewrite_url (connptr, hashofheaders, url); reverse_url = reverse_rewrite_url (connptr, hashofheaders, url);
if (reverse_url != NULL) { if (!reverse_url) {
safefree (url);
url = reverse_url;
} else if (config.reverseonly) {
log_message (LOG_ERR,
"Bad request, no mapping for '%s' found",
url);
indicate_http_error (connptr, 400, "Bad Request",
"detail", "No mapping found for "
"requested url", "url", url, NULL);
goto fail; goto fail;
} }
safefree (url);
url = reverse_url;
} }
#endif #endif
@@ -403,14 +385,14 @@ BAD_REQUEST_ERROR:
{ {
char *skipped_type = strstr (url, "//") + 2; char *skipped_type = strstr (url, "//") + 2;
if (extract_url (skipped_type, HTTP_PORT, request) < 0) { if (extract_http_url (skipped_type, request) < 0) {
indicate_http_error (connptr, 400, "Bad Request", indicate_http_error (connptr, 400, "Bad Request",
"detail", "Could not parse URL", "detail", "Could not parse URL",
"url", url, NULL); "url", url, NULL);
goto fail; goto fail;
} }
} else if (strcmp (request->method, "CONNECT") == 0) { } else if (strcmp (request->method, "CONNECT") == 0) {
if (extract_url (url, HTTP_PORT_SSL, request) < 0) { if (extract_ssl_url (url, request) < 0) {
indicate_http_error (connptr, 400, "Bad Request", indicate_http_error (connptr, 400, "Bad Request",
"detail", "Could not parse URL", "detail", "Could not parse URL",
"url", url, NULL); "url", url, NULL);
@@ -436,7 +418,7 @@ BAD_REQUEST_ERROR:
} else { } else {
#ifdef TRANSPARENT_PROXY #ifdef TRANSPARENT_PROXY
if (!do_transparent_proxy if (!do_transparent_proxy
(connptr, hashofheaders, request, &config, &url)) { (connptr, hashofheaders, request, &config, url)) {
goto fail; goto fail;
} }
#else #else
@@ -511,7 +493,6 @@ static int pull_client_data (struct conn_s *connptr, long int length)
{ {
char *buffer; char *buffer;
ssize_t len; ssize_t len;
int ret;
buffer = buffer =
(char *) safemalloc (min (MAXBUFFSIZE, (unsigned long int) length)); (char *) safemalloc (min (MAXBUFFSIZE, (unsigned long int) length));
@@ -537,30 +518,18 @@ static int pull_client_data (struct conn_s *connptr, long int length)
* return and line feed) at the end of a POST message. These * return and line feed) at the end of a POST message. These
* need to be eaten for tinyproxy to work correctly. * need to be eaten for tinyproxy to work correctly.
*/ */
ret = socket_nonblocking (connptr->client_fd); socket_nonblocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket "
"to non-blocking: %s", strerror(errno));
goto ERROR_EXIT;
}
len = recv (connptr->client_fd, buffer, 2, MSG_PEEK); len = recv (connptr->client_fd, buffer, 2, MSG_PEEK);
socket_blocking (connptr->client_fd);
ret = socket_blocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket "
"to blocking: %s", strerror(errno));
goto ERROR_EXIT;
}
if (len < 0 && errno != EAGAIN) if (len < 0 && errno != EAGAIN)
goto ERROR_EXIT; goto ERROR_EXIT;
if ((len == 2) && CHECK_CRLF (buffer, len)) { if ((len == 2) && CHECK_CRLF (buffer, len)) {
ssize_t bytes_read; ssize_t ret;
bytes_read = read (connptr->client_fd, buffer, 2); ret = read (connptr->client_fd, buffer, 2);
if (bytes_read == -1) { if (ret == -1) {
log_message log_message
(LOG_WARNING, (LOG_WARNING,
"Could not read two bytes from POST message"); "Could not read two bytes from POST message");
@@ -616,13 +585,6 @@ add_header_to_connection (hashmap_t hashofheaders, char *header, size_t len)
return hashmap_insert (hashofheaders, header, sep, len); return hashmap_insert (hashofheaders, header, sep, len);
} }
/*
* Define maximum number of headers that we accept.
* This should be big enough to handle legitimate cases,
* but limited to avoid DoS.
*/
#define MAX_HEADERS 10000
/* /*
* Read all the headers from the stream * Read all the headers from the stream
*/ */
@@ -630,7 +592,6 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
{ {
char *line = NULL; char *line = NULL;
char *header = NULL; char *header = NULL;
int count;
char *tmp; char *tmp;
ssize_t linelen; ssize_t linelen;
ssize_t len = 0; ssize_t len = 0;
@@ -639,7 +600,7 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
assert (fd >= 0); assert (fd >= 0);
assert (hashofheaders != NULL); assert (hashofheaders != NULL);
for (count = 0; count < MAX_HEADERS; count++) { for (;;) {
if ((linelen = readline (fd, &line)) <= 0) { if ((linelen = readline (fd, &line)) <= 0) {
safefree (header); safefree (header);
safefree (line); safefree (line);
@@ -705,14 +666,6 @@ static int get_all_headers (int fd, hashmap_t hashofheaders)
safefree (line); safefree (line);
} }
/*
* If we get here, this means we reached MAX_HEADERS count.
* Bail out with error.
*/
safefree (header);
safefree (line);
return -1;
} }
/* /*
@@ -839,7 +792,7 @@ done:
/* /*
* Number of buckets to use internally in the hashmap. * Number of buckets to use internally in the hashmap.
*/ */
#define HEADER_BUCKETS 256 #define HEADER_BUCKETS 32
/* /*
* Here we loop through all the headers the client is sending. If we * Here we loop through all the headers the client is sending. If we
@@ -867,10 +820,10 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
/* /*
* Don't send headers if there's already an error, if the request was * Don't send headers if there's already an error, if the request was
* a stats request, or if this was a CONNECT method (unless upstream * a stats request, or if this was a CONNECT method (unless upstream
* http proxy is in use.) * proxy is in use.)
*/ */
if (connptr->server_fd == -1 || connptr->show_stats if (connptr->server_fd == -1 || connptr->show_stats
|| (connptr->connect_method && ! UPSTREAM_IS_HTTP(connptr))) { || (connptr->connect_method && (connptr->upstream_proxy == NULL))) {
log_message (LOG_INFO, log_message (LOG_INFO,
"Not sending client headers to remote machine"); "Not sending client headers to remote machine");
return 0; return 0;
@@ -1159,19 +1112,8 @@ static void relay_connection (struct conn_s *connptr)
int maxfd = max (connptr->client_fd, connptr->server_fd) + 1; int maxfd = max (connptr->client_fd, connptr->server_fd) + 1;
ssize_t bytes_received; ssize_t bytes_received;
ret = socket_nonblocking (connptr->client_fd); socket_nonblocking (connptr->client_fd);
if (ret != 0) { socket_nonblocking (connptr->server_fd);
log_message(LOG_ERR, "Failed to set the client socket "
"to non-blocking: %s", strerror(errno));
return;
}
ret = socket_nonblocking (connptr->server_fd);
if (ret != 0) {
log_message(LOG_ERR, "Failed to set the server socket "
"to non-blocking: %s", strerror(errno));
return;
}
last_access = time (NULL); last_access = time (NULL);
@@ -1246,14 +1188,7 @@ static void relay_connection (struct conn_s *connptr)
* Here the server has closed the connection... write the * Here the server has closed the connection... write the
* remainder to the client and then exit. * remainder to the client and then exit.
*/ */
ret = socket_blocking (connptr->client_fd); socket_blocking (connptr->client_fd);
if (ret != 0) {
log_message(LOG_ERR,
"Failed to set client socket to blocking: %s",
strerror(errno));
return;
}
while (buffer_size (connptr->sbuffer) > 0) { while (buffer_size (connptr->sbuffer) > 0) {
if (write_buffer (connptr->client_fd, connptr->sbuffer) < 0) if (write_buffer (connptr->client_fd, connptr->sbuffer) < 0)
break; break;
@@ -1263,14 +1198,7 @@ static void relay_connection (struct conn_s *connptr)
/* /*
* Try to send any remaining data to the server if we can. * Try to send any remaining data to the server if we can.
*/ */
ret = socket_blocking (connptr->server_fd); socket_blocking (connptr->server_fd);
if (ret != 0) {
log_message(LOG_ERR,
"Failed to set server socket to blocking: %s",
strerror(errno));
return;
}
while (buffer_size (connptr->cbuffer) > 0) { while (buffer_size (connptr->cbuffer) > 0) {
if (write_buffer (connptr->server_fd, connptr->cbuffer) < 0) if (write_buffer (connptr->server_fd, connptr->cbuffer) < 0)
break; break;
@@ -1279,122 +1207,6 @@ static void relay_connection (struct conn_s *connptr)
return; return;
} }
static int
connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
{
unsigned len;
unsigned char buff[512]; /* won't use more than 7 + 255 */
unsigned short port;
size_t ulen, passlen;
struct hostent *host;
struct upstream *cur_upstream = connptr->upstream_proxy;
ulen = cur_upstream->ua.user ? strlen(cur_upstream->ua.user) : 0;
passlen = cur_upstream->pass ? strlen(cur_upstream->pass) : 0;
log_message(LOG_CONN,
"Established connection to %s proxy \"%s\" using file descriptor %d.",
proxy_type_name(cur_upstream->type), cur_upstream->host, connptr->server_fd);
if (cur_upstream->type == PT_SOCKS4) {
buff[0] = 4; /* socks version */
buff[1] = 1; /* connect command */
port = htons(request->port);
memcpy(&buff[2], &port, 2); /* dest port */
host = gethostbyname(request->host);
memcpy(&buff[4], host->h_addr_list[0], 4); /* dest ip */
buff[8] = 0; /* user */
if (9 != safe_write(connptr->server_fd, buff, 9))
return -1;
if (8 != safe_read(connptr->server_fd, buff, 8))
return -1;
if (buff[0]!=0 || buff[1]!=90)
return -1;
} else if (cur_upstream->type == PT_SOCKS5) {
/* init */
int n_methods = ulen ? 2 : 1;
buff[0] = 5; /* socks version */
buff[1] = n_methods; /* number of methods */
buff[2] = 0; /* no auth method */
if (ulen) buff[3] = 2; /* auth method -> username / password */
if (2+n_methods != safe_write(connptr->server_fd, buff, 2+n_methods))
return -1;
if (2 != safe_read(connptr->server_fd, buff, 2))
return -1;
if (buff[0] != 5 || (buff[1] != 0 && buff[1] != 2))
return -1;
if (buff[1] == 2) {
/* authentication */
char in[2];
char out[515];
char *cur = out;
size_t c;
*cur++ = 1; /* version */
c = ulen & 0xFF;
*cur++ = c;
memcpy(cur, cur_upstream->ua.user, c);
cur += c;
c = passlen & 0xFF;
*cur++ = c;
memcpy(cur, cur_upstream->pass, c);
cur += c;
if((cur - out) != safe_write(connptr->server_fd, out, cur - out))
return -1;
if(2 != safe_read(connptr->server_fd, in, 2))
return -1;
if(in[1] != 0 || !(in[0] == 5 || in[0] == 1)) {
return -1;
}
}
/* connect */
buff[0] = 5; /* socks version */
buff[1] = 1; /* connect */
buff[2] = 0; /* reserved */
buff[3] = 3; /* domainname */
len=strlen(request->host);
if(len>255)
return -1;
buff[4] = len; /* length of domainname */
memcpy(&buff[5], request->host, len); /* dest ip */
port = htons(request->port);
memcpy(&buff[5+len], &port, 2); /* dest port */
if (7+len != safe_write(connptr->server_fd, buff, 7+len))
return -1;
if (4 != safe_read(connptr->server_fd, buff, 4))
return -1;
if (buff[0]!=5 || buff[1]!=0)
return -1;
switch(buff[3]) {
case 1: len=4; break; /* ip v4 */
case 4: len=16; break; /* ip v6 */
case 3: /* domainname */
if (1 != safe_read(connptr->server_fd, buff, 1))
return -1;
len = buff[0]; /* max = 255 */
break;
default: return -1;
}
if (2+len != safe_read(connptr->server_fd, buff, 2+len))
return -1;
} else {
return -1;
}
if (connptr->connect_method)
return 0;
return establish_http_connection(connptr, request);
}
/* /*
* Establish a connection to the upstream proxy server. * Establish a connection to the upstream proxy server.
*/ */
@@ -1438,9 +1250,6 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
return -1; return -1;
} }
if (cur_upstream->type != PT_HTTP)
return connect_to_upstream_proxy(connptr, request);
log_message (LOG_CONN, log_message (LOG_CONN,
"Established connection to upstream proxy \"%s\" " "Established connection to upstream proxy \"%s\" "
"using file descriptor %d.", "using file descriptor %d.",
@@ -1504,7 +1313,7 @@ get_request_entity(struct conn_s *connptr)
nread = read_buffer (connptr->client_fd, connptr->cbuffer); nread = read_buffer (connptr->client_fd, connptr->cbuffer);
if (nread < 0) { if (nread < 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"Error reading readable client_fd %d", "Error reading readble client_fd %d",
connptr->client_fd); connptr->client_fd);
ret = -1; ret = -1;
} else { } else {
@@ -1608,50 +1417,6 @@ void handle_connection (int fd)
goto fail; goto fail;
} }
if (config.basicauth_list != NULL) {
ssize_t len;
char *authstring;
int failure = 1, stathost_connect = 0;
len = hashmap_entry_by_key (hashofheaders, "proxy-authorization",
(void **) &authstring);
if (len == 0 && config.stathost) {
len = hashmap_entry_by_key (hashofheaders, "host",
(void **) &authstring);
if (len && !strncmp(authstring, config.stathost, strlen(config.stathost))) {
len = hashmap_entry_by_key (hashofheaders, "authorization",
(void **) &authstring);
stathost_connect = 1;
} else len = 0;
}
if (len == 0) {
if (stathost_connect) goto e401;
update_stats (STAT_DENIED);
indicate_http_error (connptr, 407, "Proxy Authentication Required",
"detail",
"This proxy requires authentication.",
NULL);
goto fail;
}
if ( /* currently only "basic" auth supported */
(strncmp(authstring, "Basic ", 6) == 0 ||
strncmp(authstring, "basic ", 6) == 0) &&
basicauth_check (config.basicauth_list, authstring + 6) == 1)
failure = 0;
if(failure) {
e401:
update_stats (STAT_DENIED);
indicate_http_error (connptr, 401, "Unauthorized",
"detail",
"The administrator of this proxy has not configured "
"it to service requests from you.",
NULL);
goto fail;
}
hashmap_remove (hashofheaders, "proxy-authorization");
}
/* /*
* Add any user-specified headers (AddHeader directive) to the * Add any user-specified headers (AddHeader directive) to the
* outgoing HTTP request. * outgoing HTTP request.
@@ -1704,7 +1469,7 @@ e401:
goto fail; goto fail;
} }
if (!connptr->connect_method || UPSTREAM_IS_HTTP(connptr)) { if (!(connptr->connect_method && (connptr->upstream_proxy == NULL))) {
if (process_server_headers (connptr) < 0) { if (process_server_headers (connptr) < 0) {
update_stats (STAT_BADCONN); update_stats (STAT_BADCONN);
goto fail; goto fail;
+7 -1
View File
@@ -156,7 +156,13 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
} }
} }
if (rewrite_url == NULL) { /* Forward proxy support off and no reverse path match found */
if (config.reverseonly && !rewrite_url) {
log_message (LOG_ERR, "Bad request");
indicate_http_error (connptr, 400, "Bad Request",
"detail",
"Request has an invalid URL", "url", url,
NULL);
return NULL; return NULL;
} }
+45 -139
View File
@@ -34,17 +34,6 @@
#include "text.h" #include "text.h"
#include "conf.h" #include "conf.h"
/*
* Return a human readable error for getaddrinfo() and getnameinfo().
*/
static const char * get_gai_error (int n)
{
if (n == EAI_SYSTEM)
return strerror (errno);
else
return gai_strerror (n);
}
/* /*
* Bind the given socket to the supplied address. The socket is * Bind the given socket to the supplied address. The socket is
* returned if the bind succeeded. Otherwise, -1 is returned * returned if the bind succeeded. Otherwise, -1 is returned
@@ -54,7 +43,6 @@ static int
bind_socket (int sockfd, const char *addr, int family) bind_socket (int sockfd, const char *addr, int family)
{ {
struct addrinfo hints, *res, *ressave; struct addrinfo hints, *res, *ressave;
int n;
assert (sockfd >= 0); assert (sockfd >= 0);
assert (addr != NULL && strlen (addr) != 0); assert (addr != NULL && strlen (addr) != 0);
@@ -63,13 +51,9 @@ bind_socket (int sockfd, const char *addr, int family)
hints.ai_family = family; hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
/* The local port is not important */ /* The local port it not important */
n = getaddrinfo (addr, NULL, &hints, &res); if (getaddrinfo (addr, NULL, &hints, &res) != 0)
if (n != 0) {
log_message (LOG_INFO,
"bind_socket: getaddrinfo failed for %s: ", addr, get_gai_error (n));
return -1; return -1;
}
ressave = res; ressave = res;
@@ -100,9 +84,6 @@ int opensock (const char *host, int port, const char *bind_to)
assert (host != NULL); assert (host != NULL);
assert (port > 0); assert (port > 0);
log_message(LOG_INFO,
"opensock: opening connection to %s:%d", host, port);
memset (&hints, 0, sizeof (struct addrinfo)); memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
@@ -112,13 +93,10 @@ int opensock (const char *host, int port, const char *bind_to)
n = getaddrinfo (host, portstr, &hints, &res); n = getaddrinfo (host, portstr, &hints, &res);
if (n != 0) { if (n != 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"opensock: Could not retrieve address info for %s:%d: %s", host, port, get_gai_error (n)); "opensock: Could not retrieve info for %s", host);
return -1; return -1;
} }
log_message(LOG_INFO,
"opensock: getaddrinfo returned for %s:%d", host, port);
ressave = res; ressave = res;
do { do {
sockfd = sockfd =
@@ -150,9 +128,8 @@ int opensock (const char *host, int port, const char *bind_to)
freeaddrinfo (ressave); freeaddrinfo (ressave);
if (res == NULL) { if (res == NULL) {
log_message (LOG_ERR, log_message (LOG_ERR,
"opensock: Could not establish a connection to %s:%d", "opensock: Could not establish a connection to %s",
host, host);
port);
return -1; return -1;
} }
@@ -185,100 +162,21 @@ int socket_blocking (int sock)
return fcntl (sock, F_SETFL, flags & ~O_NONBLOCK); return fcntl (sock, F_SETFL, flags & ~O_NONBLOCK);
} }
/**
* Try to listen on one socket based on the addrinfo
* as returned from getaddrinfo.
*
* Return the file descriptor upon success, -1 upon error.
*/
static int listen_on_one_socket(struct addrinfo *ad)
{
int listenfd;
int ret;
const int on = 1;
char numerichost[NI_MAXHOST];
int flags = NI_NUMERICHOST;
ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
numerichost, NI_MAXHOST, NULL, 0, flags);
if (ret != 0) {
log_message(LOG_ERR, "getnameinfo failed: %s", get_gai_error (ret));
return -1;
}
log_message(LOG_INFO, "trying to listen on host[%s], family[%d], "
"socktype[%d], proto[%d]", numerichost,
ad->ai_family, ad->ai_socktype, ad->ai_protocol);
listenfd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
if (listenfd == -1) {
log_message(LOG_ERR, "socket() failed: %s", strerror(errno));
return -1;
}
ret = setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (ret != 0) {
log_message(LOG_ERR,
"setsockopt failed to set SO_REUSEADDR: %s",
strerror(errno));
close(listenfd);
return -1;
}
if (ad->ai_family == AF_INET6) {
ret = setsockopt(listenfd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on));
if (ret != 0) {
log_message(LOG_ERR,
"setsockopt failed to set IPV6_V6ONLY: %s",
strerror(errno));
close(listenfd);
return -1;
}
}
ret = bind(listenfd, ad->ai_addr, ad->ai_addrlen);
if (ret != 0) {
log_message(LOG_ERR, "bind failed: %s", strerror (errno));
close(listenfd);
return -1;
}
ret = listen(listenfd, MAXLISTEN);
if (ret != 0) {
log_message(LOG_ERR, "listen failed: %s", strerror(errno));
close(listenfd);
return -1;
}
log_message(LOG_INFO, "listening on fd [%d]", listenfd);
return listenfd;
}
/* /*
* Start listening on a socket. Create a socket with the selected port. * Start listening to a socket. Create a socket with the selected port.
* If the provided address is NULL, we may listen on multiple sockets, * The size of the socket address will be returned to the caller through
* e.g. the wildcard addresse for IPv4 and IPv6, depending on what is * the pointer, while the socket is returned as a default return.
* supported. If the address is not NULL, we only listen on the first * - rjkaes
* address reported by getaddrinfo that works.
*
* Upon success, the listen-fds are added to the listen_fds list
* and 0 is returned. Upon error, -1 is returned.
*/ */
int listen_sock (const char *addr, uint16_t port, vector_t listen_fds) int listen_sock (uint16_t port, socklen_t * addrlen)
{ {
struct addrinfo hints, *result, *rp; struct addrinfo hints, *result, *rp;
char portstr[6]; char portstr[6];
int ret = -1; int listenfd;
int n; const int on = 1;
assert (port > 0); assert (port > 0);
assert (listen_fds != NULL); assert (addrlen != NULL);
log_message(LOG_INFO, "listen_sock called with addr = '%s'",
addr == NULL ? "(NULL)" : addr);
memset (&hints, 0, sizeof (struct addrinfo)); memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
@@ -287,45 +185,53 @@ int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
snprintf (portstr, sizeof (portstr), "%d", port); snprintf (portstr, sizeof (portstr), "%d", port);
n = getaddrinfo (addr, portstr, &hints, &result); if (getaddrinfo (config.ipAddr, portstr, &hints, &result) != 0) {
if (n != 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"Unable to getaddrinfo() for %s:%d because of %s", "Unable to getaddrinfo() because of %s",
addr, strerror (errno));
port,
get_gai_error (n));
return -1; return -1;
} }
for (rp = result; rp != NULL; rp = rp->ai_next) { for (rp = result; rp != NULL; rp = rp->ai_next) {
int listenfd; listenfd = socket (rp->ai_family, rp->ai_socktype,
rp->ai_protocol);
listenfd = listen_on_one_socket(rp); if (listenfd == -1)
if (listenfd == -1) {
continue; continue;
}
vector_append (listen_fds, &listenfd, sizeof(int)); setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof (on));
/* success */ if (bind (listenfd, rp->ai_addr, rp->ai_addrlen) == 0)
ret = 0; break; /* success */
if (addr != NULL) { close (listenfd);
/*
* Unless wildcard is requested, only listen
* on the first result that works.
*/
break;
}
} }
if (ret != 0) { if (rp == NULL) {
log_message (LOG_ERR, "Unable to listen on any address."); /* was not able to bind to any address */
log_message (LOG_ERR,
"Unable to bind listening socket "
"to any address.");
freeaddrinfo (result);
return -1;
} }
if (listen (listenfd, MAXLISTEN) < 0) {
log_message (LOG_ERR,
"Unable to start listening socket because of %s",
strerror (errno));
close (listenfd);
freeaddrinfo (result);
return -1;
}
*addrlen = rp->ai_addrlen;
freeaddrinfo (result); freeaddrinfo (result);
return ret; return listenfd;
} }
/* /*
+1 -3
View File
@@ -28,10 +28,8 @@
#define MAXLINE (1024 * 4) #define MAXLINE (1024 * 4)
#include "vector.h"
extern int opensock (const char *host, int port, const char *bind_to); extern int opensock (const char *host, int port, const char *bind_to);
extern int listen_sock (const char *addr, uint16_t port, vector_t listen_fds); extern int listen_sock (uint16_t port, socklen_t * addrlen);
extern int socket_nonblocking (int sock); extern int socket_nonblocking (int sock);
extern int socket_blocking (int sock); extern int socket_blocking (int sock);
+26 -33
View File
@@ -45,7 +45,7 @@ static int build_url (char **url, const char *host, int port, const char *path)
assert (path != NULL); assert (path != NULL);
len = strlen (host) + strlen (path) + 14; len = strlen (host) + strlen (path) + 14;
*url = (char *) saferealloc (*url, len); *url = (char *) safemalloc (len);
if (*url == NULL) if (*url == NULL)
return -1; return -1;
@@ -55,12 +55,11 @@ static int build_url (char **url, const char *host, int port, const char *path)
int int
do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders, do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
struct request_s *request, struct config_s *conf, struct request_s *request, struct config_s *conf,
char **url) char *url)
{ {
socklen_t length; socklen_t length;
char *data; char *data;
size_t ulen = strlen (*url); size_t ulen = strlen (url);
ssize_t i;
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data); length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
if (length <= 0) { if (length <= 0) {
@@ -74,7 +73,7 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
connptr->client_fd); connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request", indicate_http_error (connptr, 400, "Bad Request",
"detail", "Unknown destination", "detail", "Unknown destination",
"url", *url, NULL); "url", url, NULL);
return 0; return 0;
} }
@@ -84,12 +83,15 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
request->port = ntohs (dest_addr.sin_port); request->port = ntohs (dest_addr.sin_port);
request->path = (char *) safemalloc (ulen + 1); request->path = (char *) safemalloc (ulen + 1);
strlcpy (request->path, *url, ulen + 1); strlcpy (request->path, url, ulen + 1);
build_url (url, request->host, request->port, request->path); /* url overwritten by the call below is the url passed
* to this function, and is not the url variable in the
* caller. */
build_url (&url, request->host, request->port, request->path);
log_message (LOG_INFO, log_message (LOG_INFO,
"process_request: trans IP %s %s for %d", "process_request: trans IP %s %s for %d",
request->method, *url, connptr->client_fd); request->method, url, connptr->client_fd);
} else { } else {
request->host = (char *) safemalloc (length + 1); request->host = (char *) safemalloc (length + 1);
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) != if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
@@ -99,35 +101,26 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
} }
request->path = (char *) safemalloc (ulen + 1); request->path = (char *) safemalloc (ulen + 1);
strlcpy (request->path, *url, ulen + 1); strlcpy (request->path, url, ulen + 1);
build_url (url, request->host, request->port, request->path); /* url overwritten by the call below is the url passed
* to this function, and is not the url variable in the
* caller. */
build_url (&url, request->host, request->port, request->path);
log_message (LOG_INFO, log_message (LOG_INFO,
"process_request: trans Host %s %s for %d", "process_request: trans Host %s %s for %d",
request->method, *url, connptr->client_fd); request->method, url, connptr->client_fd);
} }
if (conf->ipAddr && strcmp (request->host, conf->ipAddr) == 0) {
if (conf->listen_addrs == NULL) { log_message (LOG_ERR,
return 1; "process_request: destination IP is localhost %d",
} connptr->client_fd);
indicate_http_error (connptr, 400, "Bad Request",
for (i = 0; i < vector_length(conf->listen_addrs); i++) { "detail",
const char *addr; "You tried to connect to the machine "
"the proxy is running on", "url", url,
addr = (char *)vector_getentry(conf->listen_addrs, i, NULL); NULL);
return 0;
if (addr && strcmp(request->host, addr) == 0) {
log_message(LOG_ERR,
"transparent: destination IP %s is local "
"on socket fd %d",
request->host, connptr->client_fd);
indicate_http_error(connptr, 400, "Bad Request",
"detail",
"You tried to connect to the "
"machine the proxy is running on",
"url", *url, NULL);
return 0;
}
} }
return 1; return 1;
+1 -1
View File
@@ -32,7 +32,7 @@
extern int do_transparent_proxy (struct conn_s *connptr, extern int do_transparent_proxy (struct conn_s *connptr,
hashmap_t hashofheaders, hashmap_t hashofheaders,
struct request_s *request, struct request_s *request,
struct config_s *config, char **url); struct config_s *config, char *url);
#endif #endif
+13 -49
View File
@@ -27,28 +27,12 @@
#include "upstream.h" #include "upstream.h"
#include "heap.h" #include "heap.h"
#include "log.h" #include "log.h"
#include "base64.h"
#include "basicauth.h"
#ifdef UPSTREAM_SUPPORT #ifdef UPSTREAM_SUPPORT
const char *
proxy_type_name(proxy_type type)
{
switch(type) {
case PT_NONE: return "none";
case PT_HTTP: return "http";
case PT_SOCKS4: return "socks4";
case PT_SOCKS5: return "socks5";
default: return "unknown";
}
}
/** /**
* Construct an upstream struct from input data. * Construct an upstream struct from input data.
*/ */
static struct upstream *upstream_build (const char *host, int port, const char *domain, static struct upstream *upstream_build (const char *host, int port, const char *domain)
const char *user, const char *pass,
proxy_type type)
{ {
char *ptr; char *ptr;
struct upstream *up; struct upstream *up;
@@ -60,25 +44,8 @@ static struct upstream *upstream_build (const char *host, int port, const char *
return NULL; return NULL;
} }
up->type = type; up->host = up->domain = NULL;
up->host = up->domain = up->ua.user = up->pass = NULL;
up->ip = up->mask = 0; up->ip = up->mask = 0;
if (user) {
if (type == PT_HTTP) {
char b[BASE64ENC_BYTES((256+2)-1) + 1];
ssize_t ret;
ret = basicauth_string(user, pass, b, sizeof b);
if (ret == 0) {
log_message (LOG_ERR,
"User / pass in upstream config too long");
return NULL;
}
up->ua.authstr = safestrdup (b);
} else {
up->ua.user = safestrdup (user);
up->pass = safestrdup (pass);
}
}
if (domain == NULL) { if (domain == NULL) {
if (!host || host[0] == '\0' || port < 1) { if (!host || host[0] == '\0' || port < 1) {
@@ -90,9 +57,9 @@ static struct upstream *upstream_build (const char *host, int port, const char *
up->host = safestrdup (host); up->host = safestrdup (host);
up->port = port; up->port = port;
log_message (LOG_INFO, "Added upstream %s %s:%d for [default]", log_message (LOG_INFO, "Added upstream %s:%d for [default]",
proxy_type_name(type), host, port); host, port);
} else if (host == NULL || type == PT_NONE) { } else if (host == NULL) {
if (!domain || domain[0] == '\0') { if (!domain || domain[0] == '\0') {
log_message (LOG_WARNING, log_message (LOG_WARNING,
"Nonsense no-upstream rule: empty domain"); "Nonsense no-upstream rule: empty domain");
@@ -124,7 +91,7 @@ static struct upstream *upstream_build (const char *host, int port, const char *
log_message (LOG_INFO, "Added no-upstream for %s", domain); log_message (LOG_INFO, "Added no-upstream for %s", domain);
} else { } else {
if (!host || host[0] == '\0' || port < 1 || !domain if (!host || host[0] == '\0' || port < 1 || !domain
|| domain[0] == '\0') { || domain == '\0') {
log_message (LOG_WARNING, log_message (LOG_WARNING,
"Nonsense upstream rule: invalid parameters"); "Nonsense upstream rule: invalid parameters");
goto fail; goto fail;
@@ -134,15 +101,13 @@ static struct upstream *upstream_build (const char *host, int port, const char *
up->port = port; up->port = port;
up->domain = safestrdup (domain); up->domain = safestrdup (domain);
log_message (LOG_INFO, "Added upstream %s %s:%d for %s", log_message (LOG_INFO, "Added upstream %s:%d for %s",
proxy_type_name(type), host, port, domain); host, port, domain);
} }
return up; return up;
fail: fail:
safefree (up->ua.user);
safefree (up->pass);
safefree (up->host); safefree (up->host);
safefree (up->domain); safefree (up->domain);
safefree (up); safefree (up);
@@ -154,12 +119,11 @@ fail:
* Add an entry to the upstream list * Add an entry to the upstream list
*/ */
void upstream_add (const char *host, int port, const char *domain, void upstream_add (const char *host, int port, const char *domain,
const char *user, const char *pass, struct upstream **upstream_list)
proxy_type type, struct upstream **upstream_list)
{ {
struct upstream *up; struct upstream *up;
up = upstream_build (host, port, domain, user, pass, type); up = upstream_build (host, port, domain);
if (up == NULL) { if (up == NULL) {
return; return;
} }
@@ -238,10 +202,10 @@ struct upstream *upstream_get (char *host, struct upstream *up)
up = NULL; up = NULL;
if (up) if (up)
log_message (LOG_INFO, "Found upstream proxy %s %s:%d for %s", log_message (LOG_INFO, "Found proxy %s:%d for %s",
proxy_type_name(up->type), up->host, up->port, host); up->host, up->port, host);
else else
log_message (LOG_INFO, "No upstream proxy for %s", host); log_message (LOG_INFO, "No proxy for %s", host);
return up; return up;
} }
+1 -16
View File
@@ -31,32 +31,17 @@
* Even if upstream support is not compiled into tinyproxy, this * Even if upstream support is not compiled into tinyproxy, this
* structure still needs to be defined. * structure still needs to be defined.
*/ */
typedef enum proxy_type {
PT_NONE = 0,
PT_HTTP,
PT_SOCKS4,
PT_SOCKS5
} proxy_type;
struct upstream { struct upstream {
struct upstream *next; struct upstream *next;
char *domain; /* optional */ char *domain; /* optional */
char *host; char *host;
union {
char *user;
char *authstr;
} ua;
char *pass;
int port; int port;
in_addr_t ip, mask; in_addr_t ip, mask;
proxy_type type;
}; };
#ifdef UPSTREAM_SUPPORT #ifdef UPSTREAM_SUPPORT
const char *proxy_type_name(proxy_type type);
extern void upstream_add (const char *host, int port, const char *domain, extern void upstream_add (const char *host, int port, const char *domain,
const char *user, const char *pass, struct upstream **upstream_list);
proxy_type type, struct upstream **upstream_list);
extern struct upstream *upstream_get (char *host, struct upstream *up); extern struct upstream *upstream_get (char *host, struct upstream *up);
extern void free_upstream_list (struct upstream *up); extern void free_upstream_list (struct upstream *up);
#endif /* UPSTREAM_SUPPORT */ #endif /* UPSTREAM_SUPPORT */