Fiz whitespaces
This commit is contained in:
parent
a9edc77d0c
commit
585882edd2
@ -23,6 +23,6 @@
|
||||
|
||||
/* 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);
|
||||
void base64enc(char *dst, const void* src, size_t count);
|
||||
|
||||
#endif
|
||||
|
@ -24,11 +24,11 @@
|
||||
#include <stddef.h>
|
||||
#include "vector.h"
|
||||
|
||||
extern ssize_t basicauth_string (const char *user, const char *pass,
|
||||
char *buf, size_t bufsize);
|
||||
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);
|
||||
const char *user, const char *pass);
|
||||
|
||||
extern int basicauth_check (vector_t authlist, const char *authstring);
|
||||
|
||||
|
86
src/common.h
86
src/common.h
@ -26,7 +26,7 @@
|
||||
#define COMMON_HEADER_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -42,57 +42,57 @@
|
||||
#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/wait.h>
|
||||
#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>
|
||||
# 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/wait.h>
|
||||
# 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
|
||||
#include <values.h>
|
||||
# include <values.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MEMORY_H
|
||||
#include <memory.h>
|
||||
# include <memory.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYSEXITS_H
|
||||
#include <sysexits.h>
|
||||
# include <sysexits.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -100,13 +100,13 @@
|
||||
* cause any problems.
|
||||
*/
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL (0)
|
||||
# define MSG_NOSIGNAL (0)
|
||||
#endif
|
||||
|
||||
#ifndef SHUT_RD /* these three Posix.1g names are quite new */
|
||||
#define SHUT_RD 0 /* shutdown for reading */
|
||||
#define SHUT_WR 1 /* shutdown for writing */
|
||||
#define SHUT_RDWR 2 /* shutdown for reading and writing */
|
||||
# define SHUT_RD 0 /* shutdown for reading */
|
||||
# define SHUT_WR 1 /* shutdown for writing */
|
||||
# define SHUT_RDWR 2 /* shutdown for reading and writing */
|
||||
#endif
|
||||
|
||||
#define MAXLISTEN 1024 /* Max number of connections */
|
||||
@ -115,19 +115,19 @@
|
||||
* SunOS doesn't have INADDR_NONE defined.
|
||||
*/
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE -1
|
||||
# define INADDR_NONE -1
|
||||
#endif
|
||||
|
||||
/* Define boolean values */
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE (!FALSE)
|
||||
# define FALSE 0
|
||||
# define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
/* Useful function macros */
|
||||
#if !defined(min) || !defined(max)
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
# define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
# define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
38
src/conf.c
38
src/conf.c
@ -239,7 +239,7 @@ struct {
|
||||
STDCONF ("basicauth", ALNUM WS ALNUM, handle_basicauth),
|
||||
STDCONF ("errorfile", INT WS STR, handle_errorfile),
|
||||
STDCONF ("addheader", STR WS STR, handle_addheader),
|
||||
|
||||
|
||||
#ifdef FILTER_ENABLE
|
||||
/* filtering */
|
||||
STDCONF ("filter", STR, handle_filter),
|
||||
@ -259,7 +259,6 @@ struct {
|
||||
{
|
||||
BEGIN "(upstream)" WS "(none)" WS STR END, handle_upstream_no, NULL
|
||||
},
|
||||
|
||||
{
|
||||
BEGIN "(upstream)" WS "(http|socks4|socks5)" WS
|
||||
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
|
||||
@ -388,7 +387,8 @@ static int check_match (struct config_s *conf, const char *line,
|
||||
unsigned int i;
|
||||
|
||||
assert (ndirectives > 0);
|
||||
for (i = 0; i != ndirectives; ++i) {
|
||||
|
||||
for (i = 0; i != ndirectives; ++i) {
|
||||
assert (directives[i].cre);
|
||||
if (!regexec
|
||||
(directives[i].cre, line, RE_MAX_MATCHES, match, 0))
|
||||
@ -756,7 +756,7 @@ static HANDLE_FUNC (handle_disableviaheader)
|
||||
return r;
|
||||
}
|
||||
|
||||
log_message (LOG_INFO,
|
||||
log_message (LOG_INFO,
|
||||
"Disabling transmission of the \"Via\" header.");
|
||||
return 0;
|
||||
}
|
||||
@ -902,9 +902,9 @@ static HANDLE_FUNC (handle_listen)
|
||||
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);
|
||||
log_message(LOG_WARNING, "Could not create a list "
|
||||
"of listen addresses.");
|
||||
safefree(arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1095,17 +1095,17 @@ static HANDLE_FUNC (handle_reversepath)
|
||||
|
||||
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 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)
|
||||
@ -1126,7 +1126,7 @@ static HANDLE_FUNC (handle_upstream)
|
||||
user = get_string_arg (line, &match[mi]);
|
||||
mi++;
|
||||
|
||||
if (match[mi].rm_so != -1)
|
||||
if (match[mi].rm_so != -1)
|
||||
pass = get_string_arg (line, &match[mi]);
|
||||
mi++;
|
||||
plist->host = get_string_arg (line, &match[mi]);
|
||||
|
@ -56,7 +56,7 @@ struct config_s {
|
||||
unsigned int filter_casesensitive; /* boolean */
|
||||
#endif /* FILTER_ENABLE */
|
||||
#ifdef XTINYPROXY_ENABLE
|
||||
unsigned int add_xtinyproxy; /* boolean */
|
||||
unsigned int add_xtinyproxy; /* boolean */
|
||||
#endif
|
||||
#ifdef REVERSE_SUPPORT
|
||||
struct reversepath *reversepath_list;
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "common.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);
|
||||
void free_connect_ports_list (vector_t connect_ports);
|
||||
|
||||
|
20
src/heap.h
20
src/heap.h
@ -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,
|
||||
unsigned long line);
|
||||
|
||||
#define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
|
||||
#define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
|
||||
#define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
|
||||
#define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
|
||||
#define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL)
|
||||
# define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
|
||||
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
|
||||
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
|
||||
# define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
|
||||
# define safefree(x) (debugging_free(x, __FILE__, __LINE__), *(&(x)) = NULL)
|
||||
|
||||
#else
|
||||
|
||||
#define safecalloc(x, y) calloc(x, y)
|
||||
#define safemalloc(x) malloc(x)
|
||||
#define saferealloc(x, y) realloc(x, y)
|
||||
#define safefree(x) (free (x), *(&(x)) = NULL)
|
||||
#define safestrdup(x) strdup(x)
|
||||
# define safecalloc(x, y) calloc(x, y)
|
||||
# define safemalloc(x) malloc(x)
|
||||
# define saferealloc(x, y) realloc(x, y)
|
||||
# define safefree(x) (free (x), *(&(x)) = NULL)
|
||||
# define safestrdup(x) strdup(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
10
src/log.h
10
src/log.h
@ -24,7 +24,7 @@
|
||||
#define TINYPROXY_LOG_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -92,13 +92,13 @@
|
||||
* DEBUG2("There was a big problem: %s in connptr %p", "hello", connptr);
|
||||
*/
|
||||
#ifndef NDEBUG
|
||||
#define DEBUG1(x) \
|
||||
# define DEBUG1(x) \
|
||||
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)
|
||||
#else
|
||||
#define DEBUG1(x) do { } while(0)
|
||||
#define DEBUG2(x, y...) do { } while(0)
|
||||
# define DEBUG1(x) do { } while(0)
|
||||
# define DEBUG2(x, y...) do { } while(0)
|
||||
#endif
|
||||
|
||||
extern int open_log_file (const char *file);
|
||||
|
221
src/reqs.c
221
src/reqs.c
@ -486,6 +486,7 @@ BAD_REQUEST_ERROR:
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* 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);
|
||||
if (ret != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -553,7 +554,7 @@ static int pull_client_data (struct conn_s *connptr, long int length)
|
||||
ret = socket_blocking (connptr->client_fd);
|
||||
if (ret != 0) {
|
||||
log_message(LOG_ERR, "Failed to set the client socket "
|
||||
"to blocking: %s", strerror (errno));
|
||||
"to blocking: %s", strerror(errno));
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
@ -874,7 +875,7 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
|
||||
* http proxy is in use.)
|
||||
*/
|
||||
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,
|
||||
"Not sending client headers to remote machine");
|
||||
return 0;
|
||||
@ -1166,14 +1167,14 @@ static void relay_connection (struct conn_s *connptr)
|
||||
ret = socket_nonblocking (connptr->client_fd);
|
||||
if (ret != 0) {
|
||||
log_message(LOG_ERR, "Failed to set the client socket "
|
||||
"to non-blocking: %s", strerror (errno));
|
||||
"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));
|
||||
"to non-blocking: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1269,9 +1270,9 @@ static void relay_connection (struct conn_s *connptr)
|
||||
*/
|
||||
ret = socket_blocking (connptr->server_fd);
|
||||
if (ret != 0) {
|
||||
log_message (LOG_ERR,
|
||||
"Failed to set server socket to blocking: %s",
|
||||
strerror (errno));
|
||||
log_message(LOG_ERR,
|
||||
"Failed to set server socket to blocking: %s",
|
||||
strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1287,125 +1288,114 @@ 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 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;
|
||||
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);
|
||||
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))
|
||||
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))
|
||||
if (buff[0]!=0 || buff[1]!=90)
|
||||
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 */
|
||||
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 (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 ((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 (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;
|
||||
|
||||
if (connptr->connect_method)
|
||||
return 0;
|
||||
|
||||
return establish_http_connection (connptr, request);
|
||||
return establish_http_connection (connptr, request);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
if (cur_upstream->type != PT_HTTP)
|
||||
return connect_to_upstream_proxy (connptr, request);
|
||||
if (cur_upstream->type != PT_HTTP)
|
||||
return connect_to_upstream_proxy (connptr, request);
|
||||
|
||||
log_message (LOG_CONN,
|
||||
"Established connection to upstream proxy \"%s\" "
|
||||
@ -1521,7 +1511,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
|
||||
}
|
||||
|
||||
static int
|
||||
get_request_entity (struct conn_s *connptr)
|
||||
get_request_entity(struct conn_s *connptr)
|
||||
{
|
||||
int ret;
|
||||
fd_set rset;
|
||||
@ -1549,7 +1539,7 @@ get_request_entity (struct conn_s *connptr)
|
||||
ret = -1;
|
||||
} else {
|
||||
log_message (LOG_INFO,
|
||||
"Read request entity of %d bytes",
|
||||
"Read request entity of %d bytes",
|
||||
nread);
|
||||
ret = 0;
|
||||
}
|
||||
@ -1563,6 +1553,7 @@ get_request_entity (struct conn_s *connptr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
@ -1670,7 +1661,7 @@ void handle_connection (int fd, union sockaddr_union* addr)
|
||||
if (len == 0 && config.stathost) {
|
||||
len = hashmap_entry_by_key (hashofheaders, "host",
|
||||
(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",
|
||||
(void **) &authstring);
|
||||
stathost_connect = 1;
|
||||
@ -1687,8 +1678,8 @@ void handle_connection (int fd, union sockaddr_union* addr)
|
||||
goto fail;
|
||||
}
|
||||
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)
|
||||
failure = 0;
|
||||
if(failure) {
|
||||
@ -1788,7 +1779,7 @@ fail:
|
||||
* to send our data properly.
|
||||
*/
|
||||
if (get_request_entity (connptr) < 0) {
|
||||
log_message (LOG_WARNING,
|
||||
log_message (LOG_WARNING,
|
||||
"Could not retrieve request entity");
|
||||
indicate_http_error (connptr, 400, "Bad Request",
|
||||
"detail",
|
||||
|
@ -144,20 +144,16 @@ static char *get_hostip (int *lookup_err, char *host, in_addr_t ip,
|
||||
return safestrdup (hostip);
|
||||
}
|
||||
|
||||
const char *proxy_type_name (proxy_type type)
|
||||
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";
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
if (user) {
|
||||
if (type == PT_HTTP) {
|
||||
char b[BASE64ENC_BYTES ((256 + 2) - 1) + 1];
|
||||
char b[BASE64ENC_BYTES((256+2) - 1) + 1];
|
||||
ssize_t ret;
|
||||
ret = basicauth_string (user, pass, b, sizeof b);
|
||||
ret = basicauth_string(user, pass, b, sizeof b);
|
||||
if (ret == 0) {
|
||||
log_message (LOG_ERR,
|
||||
"User / pass in upstream config too long");
|
||||
|
@ -33,10 +33,10 @@
|
||||
* structure still needs to be defined.
|
||||
*/
|
||||
typedef enum proxy_type {
|
||||
PT_NONE = 0,
|
||||
PT_HTTP,
|
||||
PT_SOCKS4,
|
||||
PT_SOCKS5
|
||||
PT_NONE = 0,
|
||||
PT_HTTP,
|
||||
PT_SOCKS4,
|
||||
PT_SOCKS5
|
||||
} proxy_type;
|
||||
|
||||
typedef struct upstream_proxy_list {
|
||||
@ -67,7 +67,7 @@ struct upstream {
|
||||
};
|
||||
|
||||
#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,
|
||||
const char *domain, const char *user,
|
||||
const char *pass, proxy_type type,
|
||||
|
Loading…
Reference in New Issue
Block a user