Compare commits

...
9 Commits
Author SHA1 Message Date
Martin Kutschker 69c86b987b Use gai_strerror() to report errors of getaddrinfo() and getnameinfo() 2019-11-27 20:31:48 +00:00
Andre Mas c2d3470a35 Fixes #256 Provides ::1 as allowed 2019-08-20 21:52:02 +01:00
rofl0r 734ba1d970 fix usage of stathost in combination with basic auth
http protocol requires different treatment of proxy auth vs server auth.

fixes #246
2019-06-14 01:18:19 +01:00
Janosch Hoffmann e666e4a35b filter file: Don't ignore lines with leading whitespace (#239)
The new code skips leading whitespaces before removing trailing
whitespaces and comments.
Without doing this, lines with leading whitespace are treated like empty
lines (i.e. they are ignored).
2019-05-05 19:13:38 +01:00
rofl0r b131f45cbb child.c: properly initialize fdset for each select() call (#216)
it was reported that because the fdset was only initialized once,
tinyproxy would fail to properly listen on more than one interface.

closes #214
closes #127
2018-12-15 17:09:04 +00:00
Vasily dc41b35333 Basic Auth: allow almost all possible characters for user/pass
previously was restricted to alphanumeric chars only.
2018-11-23 14:59:03 +00:00
Michael Adam f44d0f387b build: Remove now unused TINYPROXY_UNSTABLE variable from configure
Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-05 01:34:51 +02:00
rofl0r 04f68e21e7 tinyproxy.8: remove l flag from short options 2018-09-05 00:57:23 +02:00
Michael Adam 9f4ed46c0a build: add new version mechanism based on VERSION file and a version.sh script
If this is a git checkout, and git is available, then git describe is
used. Otherwise, the new checked in VERSION file is taken for the version.

This mechanism uses a version.sh script inspired by
http://git.musl-libc.org/cgit/musl/tree/tools/version.sh

Signed-off-by: Michael Adam <obnox@samba.org>
2018-09-05 00:56:31 +02:00
13 changed files with 104 additions and 60 deletions

No files matched your search

+4 -2
View File
@@ -4,7 +4,8 @@ SUBDIRS = \
etc \
docs \
m4macros \
tests
tests \
scripts
# tools want this on a single line
ACLOCAL_AMFLAGS = -I m4macros
@@ -20,7 +21,8 @@ dist_doc_DATA = \
EXTRA_DIST = \
autogen.sh \
tinyproxy-indent.sh \
TODO
TODO \
VERSION
test: all
./tests/scripts/run_tests.sh
+1
View File
@@ -0,0 +1 @@
1.10.0
+2 -18
View File
@@ -3,15 +3,7 @@
AC_PREREQ(2.54)
m4_define([tinyproxy_major_version], [1])
m4_define([tinyproxy_minor_version], [10])
m4_define([tinyproxy_micro_version], [0])
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.10.0])
m4_define([tinyproxy_version], esyscmd(sh scripts/version.sh | tr -d '\n'))
AC_INIT([Tinyproxy], [tinyproxy_version],
[https://tinyproxy.github.io/],
@@ -27,15 +19,6 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
dnl Temporarily defined here until we get tinyproxy-version.h
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 :)
AC_USE_SYSTEM_EXTENSIONS
@@ -227,6 +210,7 @@ docs/man8/tinyproxy.txt
m4macros/Makefile
tests/Makefile
tests/scripts/Makefile
scripts/Makefile
])
AC_OUTPUT
+1 -1
View File
@@ -12,7 +12,7 @@ tinyproxy - A light-weight HTTP proxy daemon
SYNOPSIS
--------
*tinyproxy* [-vldch]
*tinyproxy* [-vdch]
DESCRIPTION
+1
View File
@@ -222,6 +222,7 @@ MaxRequestsPerChild 0
# tested against the controls based on order.
#
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
+2
View File
@@ -0,0 +1,2 @@
EXTRA_DIST = \
version.sh
+15
View File
@@ -0,0 +1,15 @@
#!/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
+18 -18
View File
@@ -206,27 +206,27 @@ static void child_main (struct child_s *ptr)
* We have to wait for connections on multiple fds,
* so use select.
*/
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);
}
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;
clilen = sizeof(struct sockaddr_storage);
+3 -1
View File
@@ -52,6 +52,8 @@
#define BOOL "(yes|on|no|off)"
#define INT "((0x)?[[:digit:]]+)"
#define ALNUM "([-a-z0-9._]+)"
#define USERNAME "([^:]*)"
#define PASSWORD "([^@]*)"
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
#define IPMASK "(" IP "(/[[:digit:]]+)?)"
#define IPV6 "(" \
@@ -257,7 +259,7 @@ struct {
},
{
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS
"(" ALNUM /*username*/ ":" ALNUM /*password*/ "@" ")?"
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
"(" IP "|" ALNUM ")"
":" INT "(" WS STR ")?"
END, handle_upstream, NULL
+8 -7
View File
@@ -52,7 +52,7 @@ void filter_init (void)
FILE *fd;
struct filter_list *p;
char buf[FILTER_BUFFER_LEN];
char *s;
char *s, *start;
int cflags;
if (fl || already_init) {
@@ -73,11 +73,16 @@ void filter_init (void)
cflags |= REG_ICASE;
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
* comments.
*/
s = buf;
while (*s) {
if (isspace ((unsigned char) *s))
break;
@@ -93,11 +98,7 @@ void filter_init (void)
++s;
}
*s = '\0';
/* skip leading whitespace */
s = buf;
while (*s && isspace ((unsigned char) *s))
s++;
s = start;
/* skip blank lines and comments */
if (*s == '\0')
+6 -2
View File
@@ -164,13 +164,17 @@ int send_http_headers (struct conn_s *connptr, int code, const char *message)
"%s"
"Connection: close\r\n" "\r\n";
const char auth_str[] =
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 ? auth_str : "";
const char *add = code == 407 ? p_auth_str : (code == 401 ? w_auth_str : "");
return (write_message (connptr->client_fd, headers,
code, message, PACKAGE, VERSION,
+13 -1
View File
@@ -1611,11 +1611,22 @@ void handle_connection (int fd)
if (config.basicauth_list != NULL) {
ssize_t len;
char *authstring;
int failure = 1;
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",
@@ -1629,6 +1640,7 @@ void handle_connection (int fd)
basicauth_check (config.basicauth_list, authstring + 6) == 1)
failure = 0;
if(failure) {
e401:
update_stats (STAT_DENIED);
indicate_http_error (connptr, 401, "Unauthorized",
"detail",
+30 -10
View File
@@ -34,6 +34,17 @@
#include "text.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
* returned if the bind succeeded. Otherwise, -1 is returned
@@ -43,6 +54,7 @@ static int
bind_socket (int sockfd, const char *addr, int family)
{
struct addrinfo hints, *res, *ressave;
int n;
assert (sockfd >= 0);
assert (addr != NULL && strlen (addr) != 0);
@@ -51,9 +63,13 @@ bind_socket (int sockfd, const char *addr, int family)
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
/* The local port it not important */
if (getaddrinfo (addr, NULL, &hints, &res) != 0)
/* The local port is not important */
n = getaddrinfo (addr, NULL, &hints, &res);
if (n != 0) {
log_message (LOG_INFO,
"bind_socket: getaddrinfo failed for %s: ", addr, get_gai_error (n));
return -1;
}
ressave = res;
@@ -96,7 +112,7 @@ int opensock (const char *host, int port, const char *bind_to)
n = getaddrinfo (host, portstr, &hints, &res);
if (n != 0) {
log_message (LOG_ERR,
"opensock: Could not retrieve info for %s", host);
"opensock: Could not retrieve address info for %s:%d: %s", host, port, get_gai_error (n));
return -1;
}
@@ -134,8 +150,9 @@ int opensock (const char *host, int port, const char *bind_to)
freeaddrinfo (ressave);
if (res == NULL) {
log_message (LOG_ERR,
"opensock: Could not establish a connection to %s",
host);
"opensock: Could not establish a connection to %s:%d",
host,
port);
return -1;
}
@@ -186,8 +203,7 @@ static int listen_on_one_socket(struct addrinfo *ad)
ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
numerichost, NI_MAXHOST, NULL, 0, flags);
if (ret != 0) {
log_message(LOG_ERR, "error calling getnameinfo: %s",
gai_strerror(errno));
log_message(LOG_ERR, "getnameinfo failed: %s", get_gai_error (ret));
return -1;
}
@@ -256,6 +272,7 @@ int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
struct addrinfo hints, *result, *rp;
char portstr[6];
int ret = -1;
int n;
assert (port > 0);
assert (listen_fds != NULL);
@@ -270,10 +287,13 @@ int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
snprintf (portstr, sizeof (portstr), "%d", port);
if (getaddrinfo (addr, portstr, &hints, &result) != 0) {
n = getaddrinfo (addr, portstr, &hints, &result);
if (n != 0) {
log_message (LOG_ERR,
"Unable to getaddrinfo() because of %s",
strerror (errno));
"Unable to getaddrinfo() for %s:%d because of %s",
addr,
port,
get_gai_error (n));
return -1;
}