Fiz whitespaces

This commit is contained in:
Markus Moeller 2020-01-12 19:14:38 +00:00
parent a9edc77d0c
commit 585882edd2
11 changed files with 205 additions and 218 deletions

View File

@ -23,6 +23,6 @@
/* calculates number of bytes base64-encoded stream of N bytes will take. */ /* calculates number of bytes base64-encoded stream of N bytes will take. */
#define BASE64ENC_BYTES(N) (((N+2)/3)*4) #define BASE64ENC_BYTES(N) (((N+2)/3)*4)
void base64enc (char *dst, const void *src, size_t count); void base64enc(char *dst, const void* src, size_t count);
#endif #endif

View File

@ -24,11 +24,11 @@
#include <stddef.h> #include <stddef.h>
#include "vector.h" #include "vector.h"
extern ssize_t basicauth_string (const char *user, const char *pass, extern ssize_t basicauth_string(const char *user, const char *pass,
char *buf, size_t bufsize); char *buf, size_t bufsize);
extern void basicauth_add (vector_t authlist, extern void basicauth_add (vector_t authlist,
const char *user, const char *pass); const char *user, const char *pass);
extern int basicauth_check (vector_t authlist, const char *authstring); extern int basicauth_check (vector_t authlist, const char *authstring);

View File

@ -26,7 +26,7 @@
#define COMMON_HEADER_H #define COMMON_HEADER_H
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> # include <config.h>
#endif #endif
/* /*
@ -42,57 +42,57 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
/* standard POSIX headers - they need to be there as well. */ /* standard POSIX headers - they need to be there as well. */
#include <errno.h> # include <errno.h>
#include <fcntl.h> # include <fcntl.h>
#include <netdb.h> # include <netdb.h>
#include <signal.h> # include <signal.h>
#include <stdarg.h> # include <stdarg.h>
#include <strings.h> # include <strings.h>
#include <syslog.h> # include <syslog.h>
#include <wchar.h> # include <wchar.h>
#include <wctype.h> # include <wctype.h>
#include <sys/mman.h> # include <sys/mman.h>
#include <sys/select.h> # include <sys/select.h>
#include <sys/socket.h> # include <sys/socket.h>
#include <sys/stat.h> # include <sys/stat.h>
#include <sys/types.h> # include <sys/types.h>
#include <sys/wait.h> # include <sys/wait.h>
#include <sys/uio.h> # include <sys/uio.h>
#include <sys/un.h> # include <sys/un.h>
#include <sys/time.h> # include <sys/time.h>
#include <time.h> # include <time.h>
#include <inttypes.h> # include <inttypes.h>
#include <sys/resource.h> # include <sys/resource.h>
#include <netinet/in.h> # include <netinet/in.h>
#include <assert.h> # include <assert.h>
#include <arpa/inet.h> # include <arpa/inet.h>
#include <grp.h> # include <grp.h>
#include <pwd.h> # include <pwd.h>
#include <regex.h> # include <regex.h>
/* rest - some oddball headers */ /* rest - some oddball headers */
#ifdef HAVE_VALUES_H #ifdef HAVE_VALUES_H
#include <values.h> # include <values.h>
#endif #endif
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
#ifdef HAVE_ALLOCA_H #ifdef HAVE_ALLOCA_H
#include <alloca.h> # include <alloca.h>
#endif #endif
#ifdef HAVE_MEMORY_H #ifdef HAVE_MEMORY_H
#include <memory.h> # include <memory.h>
#endif #endif
#ifdef HAVE_MALLOC_H #ifdef HAVE_MALLOC_H
#include <malloc.h> # include <malloc.h>
#endif #endif
#ifdef HAVE_SYSEXITS_H #ifdef HAVE_SYSEXITS_H
#include <sysexits.h> # include <sysexits.h>
#endif #endif
/* /*
@ -100,13 +100,13 @@
* cause any problems. * cause any problems.
*/ */
#ifndef MSG_NOSIGNAL #ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL (0) # define MSG_NOSIGNAL (0)
#endif #endif
#ifndef SHUT_RD /* these three Posix.1g names are quite new */ #ifndef SHUT_RD /* these three Posix.1g names are quite new */
#define SHUT_RD 0 /* shutdown for reading */ # define SHUT_RD 0 /* shutdown for reading */
#define SHUT_WR 1 /* shutdown for writing */ # define SHUT_WR 1 /* shutdown for writing */
#define SHUT_RDWR 2 /* shutdown for reading and writing */ # define SHUT_RDWR 2 /* shutdown for reading and writing */
#endif #endif
#define MAXLISTEN 1024 /* Max number of connections */ #define MAXLISTEN 1024 /* Max number of connections */
@ -115,19 +115,19 @@
* SunOS doesn't have INADDR_NONE defined. * SunOS doesn't have INADDR_NONE defined.
*/ */
#ifndef INADDR_NONE #ifndef INADDR_NONE
#define INADDR_NONE -1 # define INADDR_NONE -1
#endif #endif
/* Define boolean values */ /* Define boolean values */
#ifndef FALSE #ifndef FALSE
#define FALSE 0 # define FALSE 0
#define TRUE (!FALSE) # define TRUE (!FALSE)
#endif #endif
/* Useful function macros */ /* Useful function macros */
#if !defined(min) || !defined(max) #if !defined(min) || !defined(max)
#define min(a,b) ((a) < (b) ? (a) : (b)) # define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b)) # define max(a,b) ((a) > (b) ? (a) : (b))
#endif #endif
#endif #endif

View File

@ -239,7 +239,7 @@ struct {
STDCONF ("basicauth", ALNUM WS ALNUM, handle_basicauth), 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),
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
/* filtering */ /* filtering */
STDCONF ("filter", STR, handle_filter), STDCONF ("filter", STR, handle_filter),
@ -259,7 +259,6 @@ struct {
{ {
BEGIN "(upstream)" WS "(none)" WS STR END, handle_upstream_no, NULL BEGIN "(upstream)" WS "(none)" WS STR END, handle_upstream_no, NULL
}, },
{ {
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS BEGIN "(upstream)" WS "(http|socks4|socks5)" WS
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?" "(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
@ -388,7 +387,8 @@ static int check_match (struct config_s *conf, const char *line,
unsigned int i; unsigned int i;
assert (ndirectives > 0); assert (ndirectives > 0);
for (i = 0; i != ndirectives; ++i) {
for (i = 0; i != ndirectives; ++i) {
assert (directives[i].cre); assert (directives[i].cre);
if (!regexec if (!regexec
(directives[i].cre, line, RE_MAX_MATCHES, match, 0)) (directives[i].cre, line, RE_MAX_MATCHES, match, 0))
@ -756,7 +756,7 @@ static HANDLE_FUNC (handle_disableviaheader)
return r; return r;
} }
log_message (LOG_INFO, log_message (LOG_INFO,
"Disabling transmission of the \"Via\" header."); "Disabling transmission of the \"Via\" header.");
return 0; return 0;
} }
@ -902,9 +902,9 @@ static HANDLE_FUNC (handle_listen)
if (conf->listen_addrs == NULL) { if (conf->listen_addrs == NULL) {
conf->listen_addrs = vector_create(); conf->listen_addrs = vector_create();
if (conf->listen_addrs == NULL) { if (conf->listen_addrs == NULL) {
log_message (LOG_WARNING, "Could not create a list " log_message(LOG_WARNING, "Could not create a list "
"of listen addresses."); "of listen addresses.");
safefree (arg); safefree(arg);
return -1; return -1;
} }
} }
@ -1095,17 +1095,17 @@ static HANDLE_FUNC (handle_reversepath)
static enum proxy_type pt_from_string(const char *s) static enum proxy_type pt_from_string(const char *s)
{ {
static const char pt_map[][7] = { static const char pt_map[][7] = {
[PT_NONE] = "none", [PT_NONE] = "none",
[PT_HTTP] = "http", [PT_HTTP] = "http",
[PT_SOCKS4] = "socks4", [PT_SOCKS4] = "socks4",
[PT_SOCKS5] = "socks5", [PT_SOCKS5] = "socks5",
}; };
unsigned i; unsigned i;
for (i = 0; i < sizeof (pt_map) / sizeof (pt_map[0]); i++) for (i = 0; i < sizeof (pt_map) / sizeof (pt_map[0]); i++)
if (!strcmp (pt_map[i], s)) if (!strcmp (pt_map[i], s))
return i; return i;
return PT_NONE; return PT_NONE;
} }
static HANDLE_FUNC (handle_upstream) static HANDLE_FUNC (handle_upstream)
@ -1126,7 +1126,7 @@ static HANDLE_FUNC (handle_upstream)
user = get_string_arg (line, &match[mi]); user = get_string_arg (line, &match[mi]);
mi++; mi++;
if (match[mi].rm_so != -1) if (match[mi].rm_so != -1)
pass = get_string_arg (line, &match[mi]); pass = get_string_arg (line, &match[mi]);
mi++; mi++;
plist->host = get_string_arg (line, &match[mi]); plist->host = get_string_arg (line, &match[mi]);

View File

@ -56,7 +56,7 @@ struct config_s {
unsigned int filter_casesensitive; /* boolean */ unsigned int filter_casesensitive; /* boolean */
#endif /* FILTER_ENABLE */ #endif /* FILTER_ENABLE */
#ifdef XTINYPROXY_ENABLE #ifdef XTINYPROXY_ENABLE
unsigned int add_xtinyproxy; /* boolean */ unsigned int add_xtinyproxy; /* boolean */
#endif #endif
#ifdef REVERSE_SUPPORT #ifdef REVERSE_SUPPORT
struct reversepath *reversepath_list; struct reversepath *reversepath_list;

View File

@ -24,7 +24,7 @@
#include "common.h" #include "common.h"
#include "vector.h" #include "vector.h"
extern void add_connect_port_allowed (int port, vector_t * connect_ports); extern void add_connect_port_allowed (int port, vector_t *connect_ports);
int check_allowed_connect_ports (int port, vector_t connect_ports); int check_allowed_connect_ports (int port, vector_t connect_ports);
void free_connect_ports_list (vector_t connect_ports); void free_connect_ports_list (vector_t connect_ports);

View File

@ -36,19 +36,19 @@ extern void *debugging_realloc (void *ptr, size_t size, const char *file,
extern char *debugging_strdup (const char *s, const char *file, extern char *debugging_strdup (const char *s, const char *file,
unsigned long line); unsigned long line);
#define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__) # define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
#define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__) # define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
#define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__) # define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
#define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__) # define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
#define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL) # define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL)
#else #else
#define safecalloc(x, y) calloc(x, y) # define safecalloc(x, y) calloc(x, y)
#define safemalloc(x) malloc(x) # define safemalloc(x) malloc(x)
#define saferealloc(x, y) realloc(x, y) # define saferealloc(x, y) realloc(x, y)
#define safefree(x) (free (x), *(&(x)) = NULL) # define safefree(x) (free (x), *(&(x)) = NULL)
#define safestrdup(x) strdup(x) # define safestrdup(x) strdup(x)
#endif #endif

View File

@ -24,7 +24,7 @@
#define TINYPROXY_LOG_H #define TINYPROXY_LOG_H
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> # include <config.h>
#endif #endif
/* /*
@ -92,13 +92,13 @@
* DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr); * DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr);
*/ */
#ifndef NDEBUG #ifndef NDEBUG
#define DEBUG1(x) \ # define DEBUG1(x) \
log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__) log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__)
#define DEBUG2(x, y...) \ # define DEBUG2(x, y...) \
log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__, ## y) log_message(LOG_DEBUG, "[%s:%d] " x, __FILE__, __LINE__, ## y)
#else #else
#define DEBUG1(x) do { } while(0) # define DEBUG1(x) do { } while(0)
#define DEBUG2(x, y...) do { } while(0) # define DEBUG2(x, y...) do { } while(0)
#endif #endif
extern int open_log_file (const char *file); extern int open_log_file (const char *file);

View File

@ -486,6 +486,7 @@ BAD_REQUEST_ERROR:
} }
#endif #endif
/* /*
* Check to see if they're requesting the stat host * Check to see if they're requesting the stat host
*/ */
@ -544,7 +545,7 @@ static int pull_client_data (struct conn_s *connptr, long int length)
ret = socket_nonblocking (connptr->client_fd); ret = socket_nonblocking (connptr->client_fd);
if (ret != 0) { if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket " log_message(LOG_ERR, "Failed to set the client socket "
"to non-blocking: %s", strerror (errno)); "to non-blocking: %s", strerror(errno));
goto ERROR_EXIT; goto ERROR_EXIT;
} }
@ -553,7 +554,7 @@ static int pull_client_data (struct conn_s *connptr, long int length)
ret = socket_blocking (connptr->client_fd); ret = socket_blocking (connptr->client_fd);
if (ret != 0) { if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket " log_message(LOG_ERR, "Failed to set the client socket "
"to blocking: %s", strerror (errno)); "to blocking: %s", strerror(errno));
goto ERROR_EXIT; goto ERROR_EXIT;
} }
@ -874,7 +875,7 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
* http proxy is in use.) * http 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 && ! UPSTREAM_IS_HTTP(connptr))) {
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;
@ -1166,14 +1167,14 @@ static void relay_connection (struct conn_s *connptr)
ret = socket_nonblocking (connptr->client_fd); ret = socket_nonblocking (connptr->client_fd);
if (ret != 0) { if (ret != 0) {
log_message(LOG_ERR, "Failed to set the client socket " log_message(LOG_ERR, "Failed to set the client socket "
"to non-blocking: %s", strerror (errno)); "to non-blocking: %s", strerror(errno));
return; return;
} }
ret = socket_nonblocking (connptr->server_fd); ret = socket_nonblocking (connptr->server_fd);
if (ret != 0) { if (ret != 0) {
log_message(LOG_ERR, "Failed to set the server socket " log_message(LOG_ERR, "Failed to set the server socket "
"to non-blocking: %s", strerror (errno)); "to non-blocking: %s", strerror(errno));
return; return;
} }
@ -1269,9 +1270,9 @@ static void relay_connection (struct conn_s *connptr)
*/ */
ret = socket_blocking (connptr->server_fd); ret = socket_blocking (connptr->server_fd);
if (ret != 0) { if (ret != 0) {
log_message (LOG_ERR, log_message(LOG_ERR,
"Failed to set server socket to blocking: %s", "Failed to set server socket to blocking: %s",
strerror (errno)); strerror(errno));
return; return;
} }
@ -1287,125 +1288,114 @@ static int
connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request) connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
{ {
unsigned len; unsigned len;
unsigned char buff[512]; /* won't use more than 7 + 255 */ unsigned char buff[512]; /* won't use more than 7 + 255 */
unsigned short port; unsigned short port;
size_t ulen, passlen; size_t ulen, passlen;
struct hostent *host; struct hostent *host;
struct upstream *cur_upstream = connptr->upstream_proxy; struct upstream *cur_upstream = connptr->upstream_proxy;
ulen = cur_upstream->ua.user ? strlen (cur_upstream->ua.user) : 0; ulen = cur_upstream->ua.user ? strlen(cur_upstream->ua.user) : 0;
passlen = cur_upstream->pass ? strlen (cur_upstream->pass) : 0; passlen = cur_upstream->pass ? strlen(cur_upstream->pass) : 0;
log_message (LOG_CONN, log_message(LOG_CONN,
"Established connection to %s proxy \"%s\" using file descriptor %d.", "Established connection to %s proxy \"%s\" using file descriptor %d.",
proxy_type_name (cur_upstream->type), cur_upstream->host, proxy_type_name (cur_upstream->type), cur_upstream->host, connptr->server_fd);
connptr->server_fd);
if (cur_upstream->type == PT_SOCKS4) { if (cur_upstream->type == PT_SOCKS4) {
buff[0] = 4; /* socks version */ buff[0] = 4; /* socks version */
buff[1] = 1; /* connect command */ buff[1] = 1; /* connect command */
port = htons (request->port); port = htons(request->port);
memcpy (&buff[2], &port, 2); /* dest port */ memcpy (&buff[2], &port, 2); /* dest port */
host = gethostbyname (request->host); host = gethostbyname(request->host);
memcpy (&buff[4], host->h_addr_list[0], 4); /* dest ip */ memcpy (&buff[4], host->h_addr_list[0], 4); /* dest ip */
buff[8] = 0; /* user */ buff[8] = 0; /* user */
if (9 != safe_write (connptr->server_fd, buff, 9)) if (9 != safe_write(connptr->server_fd, buff, 9))
return -1; return -1;
if (8 != safe_read (connptr->server_fd, buff, 8)) if (buff[0]!=0 || buff[1]!=90)
return -1; return -1;
if (buff[0] != 0 || buff[1] != 90)
return -1;
} else if (cur_upstream->type == PT_SOCKS5) { } 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;
/* init */ if (buff[1] == 2) {
int n_methods = ulen ? 2 : 1; /* authentication */
buff[0] = 5; /* socks version */ char in[2];
buff[1] = n_methods; /* number of methods */ char out[515];
buff[2] = 0; /* no auth method */ char *cur = out;
if (ulen) size_t c;
buff[3] = 2; /* auth method -> username / password */ *cur++ = 1; /* version */
if (2 + n_methods != c = ulen & 0xFF;
safe_write (connptr->server_fd, buff, 2 + n_methods)) *cur++ = c;
return -1; memcpy(cur, cur_upstream->ua.user, c);
if (2 != safe_read (connptr->server_fd, buff, 2)) cur += c;
return -1; c = passlen & 0xFF;
if (buff[0] != 5 || (buff[1] != 0 && buff[1] != 2)) *cur++ = c;
return -1; memcpy(cur, cur_upstream->pass, c);
cur += c;
if (buff[1] == 2) { if ((cur - out) != safe_write(connptr->server_fd, out, cur - out))
/* authentication */ return -1;
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) != if (2 != safe_read(connptr->server_fd, in, 2))
safe_write (connptr->server_fd, out, cur - out)) return -1;
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 (2 != safe_read (connptr->server_fd, in, 2)) if (connptr->connect_method)
return -1; return 0;
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 establish_http_connection (connptr, request);
return 0;
return establish_http_connection (connptr, request);
} }
/* /*
* Establish a connection to the upstream proxy server. * Establish a connection to the upstream proxy server.
*/ */
@ -1478,8 +1468,8 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
return -1; return -1;
} }
if (cur_upstream->type != PT_HTTP) if (cur_upstream->type != PT_HTTP)
return connect_to_upstream_proxy (connptr, request); 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\" "
@ -1521,7 +1511,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
} }
static int static int
get_request_entity (struct conn_s *connptr) get_request_entity(struct conn_s *connptr)
{ {
int ret; int ret;
fd_set rset; fd_set rset;
@ -1549,7 +1539,7 @@ get_request_entity (struct conn_s *connptr)
ret = -1; ret = -1;
} else { } else {
log_message (LOG_INFO, log_message (LOG_INFO,
"Read request entity of %d bytes", "Read request entity of %d bytes",
nread); nread);
ret = 0; ret = 0;
} }
@ -1563,6 +1553,7 @@ get_request_entity (struct conn_s *connptr)
return ret; return ret;
} }
/* /*
* This is the main drive for each connection. As you can tell, for the * This is the main drive for each connection. As you can tell, for the
* first few steps we are using a blocking socket. If you remember the * first few steps we are using a blocking socket. If you remember the
@ -1670,7 +1661,7 @@ void handle_connection (int fd, union sockaddr_union* addr)
if (len == 0 && config.stathost) { if (len == 0 && config.stathost) {
len = hashmap_entry_by_key (hashofheaders, "host", len = hashmap_entry_by_key (hashofheaders, "host",
(void **) &authstring); (void **) &authstring);
if (len && !strncmp (authstring, config.stathost, strlen(config.stathost))) { if (len && !strncmp(authstring, config.stathost, strlen(config.stathost))) {
len = hashmap_entry_by_key (hashofheaders, "authorization", len = hashmap_entry_by_key (hashofheaders, "authorization",
(void **) &authstring); (void **) &authstring);
stathost_connect = 1; stathost_connect = 1;
@ -1687,8 +1678,8 @@ void handle_connection (int fd, union sockaddr_union* addr)
goto fail; goto fail;
} }
if ( /* currently only "basic" auth supported */ if ( /* currently only "basic" auth supported */
(strncmp (authstring, "Basic ", 6) == 0 || (strncmp(authstring, "Basic ", 6) == 0 ||
strncmp (authstring, "basic ", 6) == 0) && strncmp(authstring, "basic ", 6) == 0) &&
basicauth_check (config.basicauth_list, authstring + 6) == 1) basicauth_check (config.basicauth_list, authstring + 6) == 1)
failure = 0; failure = 0;
if(failure) { if(failure) {
@ -1788,7 +1779,7 @@ fail:
* to send our data properly. * to send our data properly.
*/ */
if (get_request_entity (connptr) < 0) { if (get_request_entity (connptr) < 0) {
log_message (LOG_WARNING, log_message (LOG_WARNING,
"Could not retrieve request entity"); "Could not retrieve request entity");
indicate_http_error (connptr, 400, "Bad Request", indicate_http_error (connptr, 400, "Bad Request",
"detail", "detail",

View File

@ -144,20 +144,16 @@ static char *get_hostip (int *lookup_err, char *host, in_addr_t ip,
return safestrdup (hostip); return safestrdup (hostip);
} }
const char *proxy_type_name (proxy_type type) const char *
proxy_type_name (proxy_type type)
{ {
switch (type) { switch (type) {
case PT_NONE: case PT_NONE: return "none";
return "none"; case PT_HTTP: return "http";
case PT_HTTP: case PT_SOCKS4: return "socks4";
return "http"; case PT_SOCKS5: return "socks5";
case PT_SOCKS4: default: return "unknown";
return "socks4"; }
case PT_SOCKS5:
return "socks5";
default:
return "unknown";
}
} }
static struct upstream_proxy_list *uplcpy (const struct upstream_proxy_list static struct upstream_proxy_list *uplcpy (const struct upstream_proxy_list
@ -250,9 +246,9 @@ static struct upstream *upstream_build (const struct upstream_proxy_list *plist,
up->ip = up->mask = 0; up->ip = up->mask = 0;
if (user) { if (user) {
if (type == PT_HTTP) { if (type == PT_HTTP) {
char b[BASE64ENC_BYTES ((256 + 2) - 1) + 1]; char b[BASE64ENC_BYTES((256+2) - 1) + 1];
ssize_t ret; ssize_t ret;
ret = basicauth_string (user, pass, b, sizeof b); ret = basicauth_string(user, pass, b, sizeof b);
if (ret == 0) { if (ret == 0) {
log_message (LOG_ERR, log_message (LOG_ERR,
"User / pass in upstream config too long"); "User / pass in upstream config too long");

View File

@ -33,10 +33,10 @@
* structure still needs to be defined. * structure still needs to be defined.
*/ */
typedef enum proxy_type { typedef enum proxy_type {
PT_NONE = 0, PT_NONE = 0,
PT_HTTP, PT_HTTP,
PT_SOCKS4, PT_SOCKS4,
PT_SOCKS5 PT_SOCKS5
} proxy_type; } proxy_type;
typedef struct upstream_proxy_list { typedef struct upstream_proxy_list {
@ -67,7 +67,7 @@ struct upstream {
}; };
#ifdef UPSTREAM_SUPPORT #ifdef UPSTREAM_SUPPORT
const char *proxy_type_name (proxy_type type); const char *proxy_type_name(proxy_type type);
extern void upstream_add (const struct upstream_proxy_list *phost, extern void upstream_add (const struct upstream_proxy_list *phost,
const char *domain, const char *user, const char *domain, const char *user,
const char *pass, proxy_type type, const char *pass, proxy_type type,