Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69c86b987b | ||
|
|
c2d3470a35 | ||
|
|
734ba1d970 | ||
|
|
e666e4a35b | ||
|
|
b131f45cbb | ||
|
|
dc41b35333 | ||
|
|
f44d0f387b | ||
|
|
04f68e21e7 | ||
|
|
9f4ed46c0a |
No files matched your search
+4
-2
@@ -4,7 +4,8 @@ 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
|
||||||
@@ -20,7 +21,8 @@ dist_doc_DATA = \
|
|||||||
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
|
||||||
|
|||||||
+2
-18
@@ -3,15 +3,7 @@
|
|||||||
|
|
||||||
AC_PREREQ(2.54)
|
AC_PREREQ(2.54)
|
||||||
|
|
||||||
m4_define([tinyproxy_major_version], [1])
|
m4_define([tinyproxy_version], esyscmd(sh scripts/version.sh | tr -d '\n'))
|
||||||
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])
|
|
||||||
|
|
||||||
AC_INIT([Tinyproxy], [tinyproxy_version],
|
AC_INIT([Tinyproxy], [tinyproxy_version],
|
||||||
[https://tinyproxy.github.io/],
|
[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
|
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
|
||||||
@@ -227,6 +210,7 @@ docs/man8/tinyproxy.txt
|
|||||||
m4macros/Makefile
|
m4macros/Makefile
|
||||||
tests/Makefile
|
tests/Makefile
|
||||||
tests/scripts/Makefile
|
tests/scripts/Makefile
|
||||||
|
scripts/Makefile
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ tinyproxy - A light-weight HTTP proxy daemon
|
|||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
|
|
||||||
*tinyproxy* [-vldch]
|
*tinyproxy* [-vdch]
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ 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.
|
# BasicAuth: HTTP "Basic Authentication" for accessing the proxy.
|
||||||
# If there are any entries specified, access is only granted for authenticated
|
# If there are any entries specified, access is only granted for authenticated
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
EXTRA_DIST = \
|
||||||
|
version.sh
|
||||||
Executable
+15
@@ -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
@@ -206,27 +206,27 @@ static void child_main (struct child_s *ptr)
|
|||||||
* We have to wait for connections on multiple fds,
|
* We have to wait for connections on multiple fds,
|
||||||
* so use select.
|
* 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) {
|
while (!config.quit) {
|
||||||
|
|
||||||
int listenfd = -1;
|
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 = sizeof(struct sockaddr_storage);
|
||||||
|
|||||||
+3
-1
@@ -52,6 +52,8 @@
|
|||||||
#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 "(" \
|
||||||
@@ -257,7 +259,7 @@ struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS
|
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS
|
||||||
"(" ALNUM /*username*/ ":" ALNUM /*password*/ "@" ")?"
|
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
|
||||||
"(" IP "|" ALNUM ")"
|
"(" IP "|" ALNUM ")"
|
||||||
":" INT "(" WS STR ")?"
|
":" INT "(" WS STR ")?"
|
||||||
END, handle_upstream, NULL
|
END, handle_upstream, NULL
|
||||||
|
|||||||
+8
-7
@@ -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;
|
char *s, *start;
|
||||||
int cflags;
|
int cflags;
|
||||||
|
|
||||||
if (fl || already_init) {
|
if (fl || already_init) {
|
||||||
@@ -73,11 +73,16 @@ 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;
|
||||||
@@ -93,11 +98,7 @@ 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')
|
||||||
|
|||||||
+6
-2
@@ -164,13 +164,17 @@ int send_http_headers (struct conn_s *connptr, int code, const char *message)
|
|||||||
"%s"
|
"%s"
|
||||||
"Connection: close\r\n" "\r\n";
|
"Connection: close\r\n" "\r\n";
|
||||||
|
|
||||||
const char auth_str[] =
|
const char p_auth_str[] =
|
||||||
"Proxy-Authenticate: Basic realm=\""
|
"Proxy-Authenticate: Basic realm=\""
|
||||||
PACKAGE_NAME "\"\r\n";
|
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
|
/* according to rfc7235, the 407 error must be accompanied by
|
||||||
a Proxy-Authenticate header field. */
|
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,
|
return (write_message (connptr->client_fd, headers,
|
||||||
code, message, PACKAGE, VERSION,
|
code, message, PACKAGE, VERSION,
|
||||||
|
|||||||
+13
-1
@@ -1611,11 +1611,22 @@ void handle_connection (int fd)
|
|||||||
if (config.basicauth_list != NULL) {
|
if (config.basicauth_list != NULL) {
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
char *authstring;
|
char *authstring;
|
||||||
int failure = 1;
|
int failure = 1, stathost_connect = 0;
|
||||||
len = hashmap_entry_by_key (hashofheaders, "proxy-authorization",
|
len = hashmap_entry_by_key (hashofheaders, "proxy-authorization",
|
||||||
(void **) &authstring);
|
(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 (len == 0) {
|
||||||
|
if (stathost_connect) goto e401;
|
||||||
update_stats (STAT_DENIED);
|
update_stats (STAT_DENIED);
|
||||||
indicate_http_error (connptr, 407, "Proxy Authentication Required",
|
indicate_http_error (connptr, 407, "Proxy Authentication Required",
|
||||||
"detail",
|
"detail",
|
||||||
@@ -1629,6 +1640,7 @@ void handle_connection (int fd)
|
|||||||
basicauth_check (config.basicauth_list, authstring + 6) == 1)
|
basicauth_check (config.basicauth_list, authstring + 6) == 1)
|
||||||
failure = 0;
|
failure = 0;
|
||||||
if(failure) {
|
if(failure) {
|
||||||
|
e401:
|
||||||
update_stats (STAT_DENIED);
|
update_stats (STAT_DENIED);
|
||||||
indicate_http_error (connptr, 401, "Unauthorized",
|
indicate_http_error (connptr, 401, "Unauthorized",
|
||||||
"detail",
|
"detail",
|
||||||
|
|||||||
+30
-10
@@ -34,6 +34,17 @@
|
|||||||
#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
|
||||||
@@ -43,6 +54,7 @@ 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);
|
||||||
@@ -51,9 +63,13 @@ 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 it not important */
|
/* The local port is not important */
|
||||||
if (getaddrinfo (addr, NULL, &hints, &res) != 0)
|
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;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
ressave = res;
|
ressave = res;
|
||||||
|
|
||||||
@@ -96,7 +112,7 @@ 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 info for %s", host);
|
"opensock: Could not retrieve address info for %s:%d: %s", host, port, get_gai_error (n));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,8 +150,9 @@ 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",
|
"opensock: Could not establish a connection to %s:%d",
|
||||||
host);
|
host,
|
||||||
|
port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,8 +203,7 @@ static int listen_on_one_socket(struct addrinfo *ad)
|
|||||||
ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
|
ret = getnameinfo(ad->ai_addr, ad->ai_addrlen,
|
||||||
numerichost, NI_MAXHOST, NULL, 0, flags);
|
numerichost, NI_MAXHOST, NULL, 0, flags);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
log_message(LOG_ERR, "error calling getnameinfo: %s",
|
log_message(LOG_ERR, "getnameinfo failed: %s", get_gai_error (ret));
|
||||||
gai_strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,6 +272,7 @@ int listen_sock (const char *addr, uint16_t port, vector_t listen_fds)
|
|||||||
struct addrinfo hints, *result, *rp;
|
struct addrinfo hints, *result, *rp;
|
||||||
char portstr[6];
|
char portstr[6];
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
int n;
|
||||||
|
|
||||||
assert (port > 0);
|
assert (port > 0);
|
||||||
assert (listen_fds != NULL);
|
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);
|
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,
|
log_message (LOG_ERR,
|
||||||
"Unable to getaddrinfo() because of %s",
|
"Unable to getaddrinfo() for %s:%d because of %s",
|
||||||
strerror (errno));
|
addr,
|
||||||
|
port,
|
||||||
|
get_gai_error (n));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user