Fix more whitespaces
This commit is contained in:
parent
585882edd2
commit
917b68f28c
@ -26,3 +26,4 @@
|
|||||||
void base64enc(char *dst, const void* src, size_t count);
|
void base64enc(char *dst, const void* src, size_t count);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@
|
|||||||
#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);
|
||||||
|
|
||||||
|
32
src/common.h
32
src/common.h
@ -45,30 +45,30 @@
|
|||||||
# 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
|
||||||
@ -80,19 +80,19 @@
|
|||||||
#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
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -104,8 +104,8 @@
|
|||||||
#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
|
||||||
|
|
||||||
@ -126,8 +126,8 @@
|
|||||||
|
|
||||||
/* 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
|
||||||
|
26
src/conf.c
26
src/conf.c
@ -388,7 +388,7 @@ static int check_match (struct config_s *conf, const char *line,
|
|||||||
|
|
||||||
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))
|
||||||
@ -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]);
|
||||||
|
160
src/reqs.c
160
src/reqs.c
@ -1255,7 +1255,7 @@ static void relay_connection (struct conn_s *connptr)
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
log_message(LOG_ERR,
|
log_message(LOG_ERR,
|
||||||
"Failed to set client socket to blocking: %s",
|
"Failed to set client socket to blocking: %s",
|
||||||
strerror (errno));
|
strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1298,8 +1298,9 @@ connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
|
|||||||
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,
|
|
||||||
"Established connection to %s proxy \"%s\" using file descriptor %d.",
|
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);
|
proxy_type_name (cur_upstream->type), cur_upstream->host, connptr->server_fd);
|
||||||
|
|
||||||
if (cur_upstream->type == PT_SOCKS4) {
|
if (cur_upstream->type == PT_SOCKS4) {
|
||||||
@ -1307,92 +1308,95 @@ connect_to_upstream_proxy(struct conn_s *connptr, struct request_s *request)
|
|||||||
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))
|
||||||
|
return -1;
|
||||||
if (buff[0]!=0 || buff[1]!=90)
|
if (buff[0]!=0 || buff[1]!=90)
|
||||||
return -1;
|
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;
|
|
||||||
|
|
||||||
if (buff[1] == 2) {
|
/* init */
|
||||||
/* authentication */
|
int n_methods = ulen ? 2 : 1;
|
||||||
char in[2];
|
buff[0] = 5; /* socks version */
|
||||||
char out[515];
|
buff[1] = n_methods; /* number of methods */
|
||||||
char *cur = out;
|
buff[2] = 0; /* no auth method */
|
||||||
size_t c;
|
if (ulen) buff[3] = 2; /* auth method -> username / password */
|
||||||
*cur++ = 1; /* version */
|
if (2 + n_methods != safe_write(connptr->server_fd, buff, 2 + n_methods))
|
||||||
c = ulen & 0xFF;
|
return -1;
|
||||||
*cur++ = c;
|
if (2 != safe_read(connptr->server_fd, buff, 2))
|
||||||
memcpy(cur, cur_upstream->ua.user, c);
|
return -1;
|
||||||
cur += c;
|
if (buff[0] != 5 || (buff[1] != 0 && buff[1] != 2))
|
||||||
c = passlen & 0xFF;
|
return -1;
|
||||||
*cur++ = c;
|
|
||||||
memcpy(cur, cur_upstream->pass, c);
|
|
||||||
cur += c;
|
|
||||||
|
|
||||||
if ((cur - out) != safe_write(connptr->server_fd, out, cur - out))
|
if (buff[1] == 2) {
|
||||||
return -1;
|
/* 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 (2 != safe_read(connptr->server_fd, in, 2))
|
if ((cur - out) != 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 (connptr->connect_method)
|
if (2 != safe_read(connptr->server_fd, in, 2))
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
return establish_http_connection (connptr, request);
|
if (connptr->connect_method)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return establish_http_connection (connptr, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1468,8 +1472,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\" "
|
||||||
|
@ -145,15 +145,15 @@ static char *get_hostip (int *lookup_err, char *host, in_addr_t ip,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
proxy_type_name (proxy_type type)
|
proxy_type_name(proxy_type type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PT_NONE: return "none";
|
case PT_NONE: return "none";
|
||||||
case PT_HTTP: return "http";
|
case PT_HTTP: return "http";
|
||||||
case PT_SOCKS4: return "socks4";
|
case PT_SOCKS4: return "socks4";
|
||||||
case PT_SOCKS5: return "socks5";
|
case PT_SOCKS5: return "socks5";
|
||||||
default: return "unknown";
|
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
|
||||||
@ -246,7 +246,7 @@ 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) {
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user