access config via a pointer, not a hardcoded struct address

this is required so we can elegantly swap out an old config for a
new one in the future and remove lots of boilerplate from config
initialization code.

unfortunately this is a quite intrusive change as the config struct
was accessed in numerous places, but frankly it should have been
done via a pointer right from the start.

right now, we simply point to a static struct in main.c, so there
shouldn't be any noticeable changes in behaviour.
This commit is contained in:
rofl0r 2020-01-15 16:09:41 +00:00
parent bffa705005
commit c63d5d26b4
11 changed files with 107 additions and 103 deletions

View File

@ -30,7 +30,7 @@
short int is_anonymous_enabled (void) short int is_anonymous_enabled (void)
{ {
return (config.anonymous_map != NULL) ? 1 : 0; return (config->anonymous_map != NULL) ? 1 : 0;
} }
/* /*
@ -40,9 +40,9 @@ short int is_anonymous_enabled (void)
int anonymous_search (const char *s) int anonymous_search (const char *s)
{ {
assert (s != NULL); assert (s != NULL);
assert (config.anonymous_map != NULL); assert (config->anonymous_map != NULL);
return hashmap_search (config.anonymous_map, s); return hashmap_search (config->anonymous_map, s);
} }
/* /*
@ -57,17 +57,17 @@ int anonymous_insert (const char *s)
assert (s != NULL); assert (s != NULL);
if (!config.anonymous_map) { if (!config->anonymous_map) {
config.anonymous_map = hashmap_create (32); config->anonymous_map = hashmap_create (32);
if (!config.anonymous_map) if (!config->anonymous_map)
return -1; return -1;
} }
if (hashmap_search (config.anonymous_map, s) > 0) { if (hashmap_search (config->anonymous_map, s) > 0) {
/* The key was already found, so return a positive number. */ /* The key was already found, so return a positive number. */
return 0; return 0;
} }
/* Insert the new key */ /* Insert the new key */
return hashmap_insert (config.anonymous_map, s, &data, sizeof (data)); return hashmap_insert (config->anonymous_map, s, &data, sizeof (data));
} }

View File

@ -86,7 +86,7 @@ void child_main_loop (void)
pthread_attr_t *attrp, attr; pthread_attr_t *attrp, attr;
struct child *child; struct child *child;
childs = sblist_new(sizeof (struct child*), config.maxclients); childs = sblist_new(sizeof (struct child*), config->maxclients);
loop_records_init(); loop_records_init();
@ -94,11 +94,11 @@ void child_main_loop (void)
* We have to wait for connections on multiple fds, * We have to wait for connections on multiple fds,
* so use select. * so use select.
*/ */
while (!config.quit) { while (!config->quit) {
collect_threads(); collect_threads();
if (sblist_getsize(childs) >= config.maxclients) { if (sblist_getsize(childs) >= config->maxclients) {
if (!was_full) if (!was_full)
log_message (LOG_NOTICE, log_message (LOG_NOTICE,
"Maximum number of connections reached. " "Maximum number of connections reached. "

View File

@ -59,7 +59,7 @@ void filter_init (void)
return; return;
} }
fd = fopen (config.filter, "r"); fd = fopen (config->filter, "r");
if (!fd) { if (!fd) {
return; return;
} }
@ -67,9 +67,9 @@ void filter_init (void)
p = NULL; p = NULL;
cflags = REG_NEWLINE | REG_NOSUB; cflags = REG_NEWLINE | REG_NOSUB;
if (config.filter_extended) if (config->filter_extended)
cflags |= REG_EXTENDED; cflags |= REG_EXTENDED;
if (!config.filter_casesensitive) if (!config->filter_casesensitive)
cflags |= REG_ICASE; cflags |= REG_ICASE;
while (fgets (buf, FILTER_BUFFER_LEN, fd)) { while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
@ -121,7 +121,7 @@ void filter_init (void)
if (err != 0) { if (err != 0) {
fprintf (stderr, fprintf (stderr,
"Bad regex in %s: %s\n", "Bad regex in %s: %s\n",
config.filter, p->pat); config->filter, p->pat);
exit (EX_DATAERR); exit (EX_DATAERR);
} }
} }
@ -157,7 +157,7 @@ void filter_destroy (void)
*/ */
void filter_reload (void) void filter_reload (void)
{ {
if (config.filter) { if (config->filter) {
log_message (LOG_NOTICE, "Re-reading filter file."); log_message (LOG_NOTICE, "Re-reading filter file.");
filter_destroy (); filter_destroy ();
filter_init (); filter_init ();

View File

@ -41,13 +41,13 @@ int add_new_errorpage (char *filepath, unsigned int errornum)
{ {
char errornbuf[ERRORNUM_BUFSIZE]; char errornbuf[ERRORNUM_BUFSIZE];
config.errorpages = hashmap_create (ERRPAGES_BUCKETCOUNT); config->errorpages = hashmap_create (ERRPAGES_BUCKETCOUNT);
if (!config.errorpages) if (!config->errorpages)
return (-1); return (-1);
snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum); snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
if (hashmap_insert (config.errorpages, errornbuf, if (hashmap_insert (config->errorpages, errornbuf,
filepath, strlen (filepath) + 1) < 0) filepath, strlen (filepath) + 1) < 0)
return (-1); return (-1);
@ -66,19 +66,19 @@ static char *get_html_file (unsigned int errornum)
assert (errornum >= 100 && errornum < 1000); assert (errornum >= 100 && errornum < 1000);
if (!config.errorpages) if (!config->errorpages)
return (config.errorpage_undef); return (config->errorpage_undef);
snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum); snprintf (errornbuf, ERRORNUM_BUFSIZE, "%u", errornum);
result_iter = hashmap_find (config.errorpages, errornbuf); result_iter = hashmap_find (config->errorpages, errornbuf);
if (hashmap_is_end (config.errorpages, result_iter)) if (hashmap_is_end (config->errorpages, result_iter))
return (config.errorpage_undef); return (config->errorpage_undef);
if (hashmap_return_entry (config.errorpages, result_iter, if (hashmap_return_entry (config->errorpages, result_iter,
&key, (void **) &val) < 0) &key, (void **) &val) < 0)
return (config.errorpage_undef); return (config->errorpage_undef);
return (val); return (val);
} }

View File

@ -129,7 +129,7 @@ void log_message (int level, const char *fmt, ...)
return; return;
#endif #endif
if (config.syslog && level == LOG_CONN) if (config && config->syslog && level == LOG_CONN)
level = LOG_INFO; level = LOG_INFO;
va_start (args, fmt); va_start (args, fmt);
@ -161,10 +161,10 @@ void log_message (int level, const char *fmt, ...)
goto out; goto out;
} }
if(!config.syslog && log_file_fd == -1) if(!config->syslog && log_file_fd == -1)
goto out; goto out;
if (config.syslog) { if (config->syslog) {
pthread_mutex_lock(&log_mutex); pthread_mutex_lock(&log_mutex);
#ifdef HAVE_VSYSLOG_H #ifdef HAVE_VSYSLOG_H
vsyslog (level, fmt, args); vsyslog (level, fmt, args);
@ -203,11 +203,11 @@ void log_message (int level, const char *fmt, ...)
pthread_mutex_unlock(&log_mutex); pthread_mutex_unlock(&log_mutex);
if (ret == -1) { if (ret == -1) {
config.syslog = TRUE; config->syslog = TRUE;
log_message(LOG_CRIT, "ERROR: Could not write to log " log_message(LOG_CRIT, "ERROR: Could not write to log "
"file %s: %s.", "file %s: %s.",
config.logf_name, strerror(errno)); config->logf_name, strerror(errno));
log_message(LOG_CRIT, log_message(LOG_CRIT,
"Falling back to syslog logging"); "Falling back to syslog logging");
} }
@ -272,23 +272,23 @@ static void send_stored_logs (void)
*/ */
int setup_logging (void) int setup_logging (void)
{ {
if (!config.syslog) { if (!config->syslog) {
if (open_log_file (config.logf_name) < 0) { if (open_log_file (config->logf_name) < 0) {
/* /*
* If opening the log file fails, we try * If opening the log file fails, we try
* to fall back to syslog logging... * to fall back to syslog logging...
*/ */
config.syslog = TRUE; config->syslog = TRUE;
log_message (LOG_CRIT, "ERROR: Could not create log " log_message (LOG_CRIT, "ERROR: Could not create log "
"file %s: %s.", "file %s: %s.",
config.logf_name, strerror (errno)); config->logf_name, strerror (errno));
log_message (LOG_CRIT, log_message (LOG_CRIT,
"Falling back to syslog logging."); "Falling back to syslog logging.");
} }
} }
if (config.syslog) { if (config->syslog) {
openlog ("tinyproxy", LOG_PID, LOG_USER); openlog ("tinyproxy", LOG_PID, LOG_USER);
} }
@ -307,7 +307,7 @@ void shutdown_logging (void)
return; return;
} }
if (config.syslog) { if (config->syslog) {
closelog (); closelog ();
} else { } else {
close_log_file (); close_log_file ();

View File

@ -47,8 +47,9 @@
/* /*
* Global Structures * Global Structures
*/ */
struct config_s config; struct config_s *config;
struct config_s config_defaults; static struct config_s config_main;
static struct config_s config_defaults;
static const char* config_file; static const char* config_file;
unsigned int received_sighup = FALSE; /* boolean */ unsigned int received_sighup = FALSE; /* boolean */
@ -68,7 +69,7 @@ takesig (int sig)
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
config.quit = TRUE; config->quit = TRUE;
break; break;
case SIGCHLD: case SIGCHLD:
@ -174,16 +175,16 @@ get_id (char *str)
static void static void
change_user (const char *program) change_user (const char *program)
{ {
if (config.group && strlen (config.group) > 0) { if (config->group && strlen (config->group) > 0) {
int gid = get_id (config.group); int gid = get_id (config->group);
if (gid < 0) { if (gid < 0) {
struct group *thisgroup = getgrnam (config.group); struct group *thisgroup = getgrnam (config->group);
if (!thisgroup) { if (!thisgroup) {
fprintf (stderr, fprintf (stderr,
"%s: Unable to find group \"%s\".\n", "%s: Unable to find group \"%s\".\n",
program, config.group); program, config->group);
exit (EX_NOUSER); exit (EX_NOUSER);
} }
@ -193,7 +194,7 @@ change_user (const char *program)
if (setgid (gid) < 0) { if (setgid (gid) < 0) {
fprintf (stderr, fprintf (stderr,
"%s: Unable to change to group \"%s\".\n", "%s: Unable to change to group \"%s\".\n",
program, config.group); program, config->group);
exit (EX_NOPERM); exit (EX_NOPERM);
} }
@ -208,19 +209,19 @@ change_user (const char *program)
#endif #endif
log_message (LOG_INFO, "Now running as group \"%s\".", log_message (LOG_INFO, "Now running as group \"%s\".",
config.group); config->group);
} }
if (config.user && strlen (config.user) > 0) { if (config->user && strlen (config->user) > 0) {
int uid = get_id (config.user); int uid = get_id (config->user);
if (uid < 0) { if (uid < 0) {
struct passwd *thisuser = getpwnam (config.user); struct passwd *thisuser = getpwnam (config->user);
if (!thisuser) { if (!thisuser) {
fprintf (stderr, fprintf (stderr,
"%s: Unable to find user \"%s\".\n", "%s: Unable to find user \"%s\".\n",
program, config.user); program, config->user);
exit (EX_NOUSER); exit (EX_NOUSER);
} }
@ -230,12 +231,12 @@ change_user (const char *program)
if (setuid (uid) < 0) { if (setuid (uid) < 0) {
fprintf (stderr, fprintf (stderr,
"%s: Unable to change to user \"%s\".\n", "%s: Unable to change to user \"%s\".\n",
program, config.user); program, config->user);
exit (EX_NOPERM); exit (EX_NOPERM);
} }
log_message (LOG_INFO, "Now running as user \"%s\".", log_message (LOG_INFO, "Now running as user \"%s\".",
config.user); config->user);
} }
} }
@ -249,12 +250,14 @@ int reload_config (void)
shutdown_logging (); shutdown_logging ();
ret = reload_config_file (config_file, &config, ret = reload_config_file (config_file, &config_main,
&config_defaults); &config_defaults);
if (ret != 0) { if (ret != 0) {
goto done; goto done;
} }
config = &config_main;
ret = setup_logging (); ret = setup_logging ();
done: done:
@ -308,10 +311,11 @@ main (int argc, char **argv)
initialize_config_defaults (&config_defaults); initialize_config_defaults (&config_defaults);
if (reload_config_file (config_file, if (reload_config_file (config_file,
&config, &config_main,
&config_defaults)) { &config_defaults)) {
exit (EX_SOFTWARE); exit (EX_SOFTWARE);
} }
config = &config_main;
init_stats (); init_stats ();
@ -325,7 +329,7 @@ main (int argc, char **argv)
} }
if (daemonized == TRUE) { if (daemonized == TRUE) {
if (!config.syslog && config.logf_name == NULL) if (!config->syslog && config->logf_name == NULL)
fprintf(stderr, "WARNING: logging deactivated " fprintf(stderr, "WARNING: logging deactivated "
"(can't log to stdout when daemonized)\n"); "(can't log to stdout when daemonized)\n");
@ -339,20 +343,20 @@ main (int argc, char **argv)
} }
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
if (config.filter) if (config->filter)
filter_init (); filter_init ();
#endif /* FILTER_ENABLE */ #endif /* FILTER_ENABLE */
/* Start listening on the selected port. */ /* Start listening on the selected port. */
if (child_listening_sockets(config.listen_addrs, config.port) < 0) { if (child_listening_sockets(config->listen_addrs, config->port) < 0) {
fprintf (stderr, "%s: Could not create listening sockets.\n", fprintf (stderr, "%s: Could not create listening sockets.\n",
argv[0]); argv[0]);
exit (EX_OSERR); exit (EX_OSERR);
} }
/* Create pid file before we drop privileges */ /* Create pid file before we drop privileges */
if (config.pidpath) { if (config->pidpath) {
if (pidfile_create (config.pidpath) < 0) { if (pidfile_create (config->pidpath) < 0) {
fprintf (stderr, "%s: Could not create PID file.\n", fprintf (stderr, "%s: Could not create PID file.\n",
argv[0]); argv[0]);
exit (EX_OSERR); exit (EX_OSERR);
@ -403,14 +407,14 @@ main (int argc, char **argv)
child_close_sock (); child_close_sock ();
/* Remove the PID file */ /* Remove the PID file */
if (config.pidpath != NULL && unlink (config.pidpath) < 0) { if (config->pidpath != NULL && unlink (config->pidpath) < 0) {
log_message (LOG_WARNING, log_message (LOG_WARNING,
"Could not remove PID file \"%s\": %s.", "Could not remove PID file \"%s\": %s.",
config.pidpath, strerror (errno)); config->pidpath, strerror (errno));
} }
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
if (config.filter) if (config->filter)
filter_destroy (); filter_destroy ();
#endif /* FILTER_ENABLE */ #endif /* FILTER_ENABLE */

View File

@ -29,7 +29,7 @@
#define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */ #define MAX_IDLE_TIME (60 * 10) /* 10 minutes of no activity */
/* Global Structures used in the program */ /* Global Structures used in the program */
extern struct config_s config; extern struct config_s *config;
extern unsigned int received_sighup; /* boolean */ extern unsigned int received_sighup; /* boolean */
extern int reload_config (void); extern int reload_config (void);

View File

@ -61,8 +61,8 @@
* enabled. * enabled.
*/ */
#ifdef UPSTREAM_SUPPORT #ifdef UPSTREAM_SUPPORT
# define UPSTREAM_CONFIGURED() (config.upstream_list != NULL) # define UPSTREAM_CONFIGURED() (config->upstream_list != NULL)
# define UPSTREAM_HOST(host) upstream_get(host, config.upstream_list) # define UPSTREAM_HOST(host) upstream_get(host, config->upstream_list)
# define UPSTREAM_IS_HTTP(conn) (conn->upstream_proxy != NULL && conn->upstream_proxy->type == PT_HTTP) # define UPSTREAM_IS_HTTP(conn) (conn->upstream_proxy != NULL && conn->upstream_proxy->type == PT_HTTP)
#else #else
# define UPSTREAM_CONFIGURED() (0) # define UPSTREAM_CONFIGURED() (0)
@ -373,7 +373,7 @@ BAD_REQUEST_ERROR:
} }
#ifdef REVERSE_SUPPORT #ifdef REVERSE_SUPPORT
if (config.reversepath_list != NULL) { if (config->reversepath_list != NULL) {
/* /*
* Rewrite the URL based on the reverse path. After calling * Rewrite the URL based on the reverse path. After calling
* reverse_rewrite_url "url" can be freed since we either * reverse_rewrite_url "url" can be freed since we either
@ -387,7 +387,7 @@ BAD_REQUEST_ERROR:
if (reverse_url != NULL) { if (reverse_url != NULL) {
safefree (url); safefree (url);
url = reverse_url; url = reverse_url;
} else if (config.reverseonly) { } else if (config->reverseonly) {
log_message (LOG_ERR, log_message (LOG_ERR,
"Bad request, no mapping for '%s' found", "Bad request, no mapping for '%s' found",
url); url);
@ -420,7 +420,7 @@ BAD_REQUEST_ERROR:
/* Verify that the port in the CONNECT method is allowed */ /* Verify that the port in the CONNECT method is allowed */
if (!check_allowed_connect_ports (request->port, if (!check_allowed_connect_ports (request->port,
config.connect_ports)) config->connect_ports))
{ {
indicate_http_error (connptr, 403, "Access violation", indicate_http_error (connptr, 403, "Access violation",
"detail", "detail",
@ -437,7 +437,7 @@ BAD_REQUEST_ERROR:
} else { } else {
#ifdef TRANSPARENT_PROXY #ifdef TRANSPARENT_PROXY
if (!do_transparent_proxy if (!do_transparent_proxy
(connptr, hashofheaders, request, &config, &url)) { (connptr, hashofheaders, request, config, &url)) {
goto fail; goto fail;
} }
#else #else
@ -455,8 +455,8 @@ BAD_REQUEST_ERROR:
/* /*
* Filter restricted domains/urls * Filter restricted domains/urls
*/ */
if (config.filter) { if (config->filter) {
if (config.filter_url) if (config->filter_url)
ret = filter_url (url); ret = filter_url (url);
else else
ret = filter_domain (request->host); ret = filter_domain (request->host);
@ -464,7 +464,7 @@ BAD_REQUEST_ERROR:
if (ret) { if (ret) {
update_stats (STAT_DENIED); update_stats (STAT_DENIED);
if (config.filter_url) if (config->filter_url)
log_message (LOG_NOTICE, log_message (LOG_NOTICE,
"Proxying refused on filtered url \"%s\"", "Proxying refused on filtered url \"%s\"",
url); url);
@ -486,7 +486,7 @@ BAD_REQUEST_ERROR:
/* /*
* Check to see if they're requesting the stat host * Check to see if they're requesting the stat host
*/ */
if (config.stathost && strcmp (config.stathost, request->host) == 0) { if (config->stathost && strcmp (config->stathost, request->host) == 0) {
log_message (LOG_NOTICE, "Request for the stathost."); log_message (LOG_NOTICE, "Request for the stathost.");
connptr->show_stats = TRUE; connptr->show_stats = TRUE;
goto fail; goto fail;
@ -804,13 +804,13 @@ write_via_header (int fd, hashmap_t hashofheaders,
char *data; char *data;
int ret; int ret;
if (config.disable_viaheader) { if (config->disable_viaheader) {
ret = 0; ret = 0;
goto done; goto done;
} }
if (config.via_proxy_name) { if (config->via_proxy_name) {
strlcpy (hostname, config.via_proxy_name, sizeof (hostname)); strlcpy (hostname, config->via_proxy_name, sizeof (hostname));
} else if (gethostname (hostname, sizeof (hostname)) < 0) { } else if (gethostname (hostname, sizeof (hostname)) < 0) {
strlcpy (hostname, "unknown", 512); strlcpy (hostname, "unknown", 512);
} }
@ -938,7 +938,7 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
} }
} }
#if defined(XTINYPROXY_ENABLE) #if defined(XTINYPROXY_ENABLE)
if (config.add_xtinyproxy) if (config->add_xtinyproxy)
add_xtinyproxy_header (connptr); add_xtinyproxy_header (connptr);
#endif #endif
@ -981,7 +981,7 @@ static int process_server_headers (struct conn_s *connptr)
int ret; int ret;
#ifdef REVERSE_SUPPORT #ifdef REVERSE_SUPPORT
struct reversepath *reverse = config.reversepath_list; struct reversepath *reverse = config->reversepath_list;
#endif #endif
/* Get the response line from the remote server. */ /* Get the response line from the remote server. */
@ -1073,7 +1073,7 @@ retry:
#ifdef REVERSE_SUPPORT #ifdef REVERSE_SUPPORT
/* Write tracking cookie for the magical reverse proxy path hack */ /* Write tracking cookie for the magical reverse proxy path hack */
if (config.reversemagic && connptr->reversepath) { if (config->reversemagic && connptr->reversepath) {
ret = write_message (connptr->client_fd, ret = write_message (connptr->client_fd,
"Set-Cookie: " REVERSE_COOKIE "Set-Cookie: " REVERSE_COOKIE
"=%s; path=/\r\n", connptr->reversepath); "=%s; path=/\r\n", connptr->reversepath);
@ -1082,7 +1082,7 @@ retry:
} }
/* Rewrite the HTTP redirect if needed */ /* Rewrite the HTTP redirect if needed */
if (config.reversebaseurl && if (config->reversebaseurl &&
hashmap_entry_by_key (hashofheaders, "location", hashmap_entry_by_key (hashofheaders, "location",
(void **) &header) > 0) { (void **) &header) > 0) {
@ -1100,14 +1100,14 @@ retry:
ret = ret =
write_message (connptr->client_fd, write_message (connptr->client_fd,
"Location: %s%s%s\r\n", "Location: %s%s%s\r\n",
config.reversebaseurl, config->reversebaseurl,
(reverse->path + 1), (header + len)); (reverse->path + 1), (header + len));
if (ret < 0) if (ret < 0)
goto ERROR_EXIT; goto ERROR_EXIT;
log_message (LOG_INFO, log_message (LOG_INFO,
"Rewriting HTTP redirect: %s -> %s%s%s", "Rewriting HTTP redirect: %s -> %s%s%s",
header, config.reversebaseurl, header, config->reversebaseurl,
(reverse->path + 1), (header + len)); (reverse->path + 1), (header + len));
hashmap_remove (hashofheaders, "location"); hashmap_remove (hashofheaders, "location");
} }
@ -1181,7 +1181,7 @@ static void relay_connection (struct conn_s *connptr)
FD_ZERO (&wset); FD_ZERO (&wset);
tv.tv_sec = tv.tv_sec =
config.idletimeout - difftime (time (NULL), last_access); config->idletimeout - difftime (time (NULL), last_access);
tv.tv_usec = 0; tv.tv_usec = 0;
if (buffer_size (connptr->sbuffer) > 0) if (buffer_size (connptr->sbuffer) > 0)
@ -1197,10 +1197,10 @@ static void relay_connection (struct conn_s *connptr)
if (ret == 0) { if (ret == 0) {
tdiff = difftime (time (NULL), last_access); tdiff = difftime (time (NULL), last_access);
if (tdiff > config.idletimeout) { if (tdiff > config->idletimeout) {
log_message (LOG_INFO, log_message (LOG_INFO,
"Idle Timeout (after select) as %g > %u.", "Idle Timeout (after select) as %g > %u.",
tdiff, config.idletimeout); tdiff, config->idletimeout);
return; return;
} else { } else {
continue; continue;
@ -1546,16 +1546,16 @@ void handle_connection (int fd, union sockaddr_union* addr)
getpeer_information (addr, peer_ipaddr, sizeof(peer_ipaddr)); getpeer_information (addr, peer_ipaddr, sizeof(peer_ipaddr));
if (config.bindsame) if (config->bindsame)
getsock_ip (fd, sock_ipaddr); getsock_ip (fd, sock_ipaddr);
log_message (LOG_CONN, config.bindsame ? log_message (LOG_CONN, config->bindsame ?
"Connect (file descriptor %d): %s at [%s]" : "Connect (file descriptor %d): %s at [%s]" :
"Connect (file descriptor %d): %s", "Connect (file descriptor %d): %s",
fd, peer_ipaddr, sock_ipaddr); fd, peer_ipaddr, sock_ipaddr);
connptr = initialize_conn (fd, peer_ipaddr, connptr = initialize_conn (fd, peer_ipaddr,
config.bindsame ? sock_ipaddr : NULL); config->bindsame ? sock_ipaddr : NULL);
if (!connptr) { if (!connptr) {
close (fd); close (fd);
return; return;
@ -1575,7 +1575,7 @@ void handle_connection (int fd, union sockaddr_union* addr)
} }
if (check_acl (peer_ipaddr, addr, config.access_list) <= 0) { if (check_acl (peer_ipaddr, addr, config->access_list) <= 0) {
update_stats (STAT_DENIED); update_stats (STAT_DENIED);
indicate_http_error (connptr, 403, "Access denied", indicate_http_error (connptr, 403, "Access denied",
"detail", "detail",
@ -1622,17 +1622,17 @@ void handle_connection (int fd, union sockaddr_union* addr)
goto fail; goto fail;
} }
if (config.basicauth_list != NULL) { if (config->basicauth_list != NULL) {
ssize_t len; ssize_t len;
char *authstring; char *authstring;
int failure = 1, stathost_connect = 0; 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) { 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;
@ -1651,7 +1651,7 @@ void handle_connection (int fd, union sockaddr_union* addr)
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) {
e401: e401:
@ -1670,9 +1670,9 @@ e401:
* Add any user-specified headers (AddHeader directive) to the * Add any user-specified headers (AddHeader directive) to the
* outgoing HTTP request. * outgoing HTTP request.
*/ */
for (i = 0; i < vector_length (config.add_headers); i++) { for (i = 0; i < vector_length (config->add_headers); i++) {
http_header_t *header = (http_header_t *) http_header_t *header = (http_header_t *)
vector_getentry (config.add_headers, i, NULL); vector_getentry (config->add_headers, i, NULL);
hashmap_insert (hashofheaders, hashmap_insert (hashofheaders,
header->name, header->name,

View File

@ -122,14 +122,14 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
/* Reverse requests always start with a slash */ /* Reverse requests always start with a slash */
if (*url == '/') { if (*url == '/') {
/* First try locating the reverse mapping by request url */ /* First try locating the reverse mapping by request url */
reverse = reversepath_get (url, config.reversepath_list); reverse = reversepath_get (url, config->reversepath_list);
if (reverse) { if (reverse) {
rewrite_url = (char *) rewrite_url = (char *)
safemalloc (strlen (url) + strlen (reverse->url) + safemalloc (strlen (url) + strlen (reverse->url) +
1); 1);
strcpy (rewrite_url, reverse->url); strcpy (rewrite_url, reverse->url);
strcat (rewrite_url, url + strlen (reverse->path)); strcat (rewrite_url, url + strlen (reverse->path));
} else if (config.reversemagic } else if (config->reversemagic
&& hashmap_entry_by_key (hashofheaders, && hashmap_entry_by_key (hashofheaders,
"cookie", "cookie",
(void **) &cookie) > 0) { (void **) &cookie) > 0) {
@ -139,7 +139,7 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
&& (reverse = && (reverse =
reversepath_get (cookieval + reversepath_get (cookieval +
strlen (REVERSE_COOKIE) + 1, strlen (REVERSE_COOKIE) + 1,
config.reversepath_list))) config->reversepath_list)))
{ {
rewrite_url = (char *) safemalloc rewrite_url = (char *) safemalloc
@ -163,7 +163,7 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
log_message (LOG_CONN, "Rewriting URL: %s -> %s", url, rewrite_url); log_message (LOG_CONN, "Rewriting URL: %s -> %s", url, rewrite_url);
/* Store reverse path so that the magical tracking cookie can be set */ /* Store reverse path so that the magical tracking cookie can be set */
if (config.reversemagic && reverse) if (config->reversemagic && reverse)
connptr->reversepath = safestrdup (reverse->path); connptr->reversepath = safestrdup (reverse->path);
return rewrite_url; return rewrite_url;

View File

@ -134,8 +134,8 @@ int opensock (const char *host, int port, const char *bind_to)
close (sockfd); close (sockfd);
continue; /* can't bind, so try again */ continue; /* can't bind, so try again */
} }
} else if (config.bind_address) { } else if (config->bind_address) {
if (bind_socket (sockfd, config.bind_address, if (bind_socket (sockfd, config->bind_address,
res->ai_family) < 0) { res->ai_family) < 0) {
close (sockfd); close (sockfd);
continue; /* can't bind, so try again */ continue; /* can't bind, so try again */
@ -147,7 +147,7 @@ int opensock (const char *host, int port, const char *bind_to)
int af = res->ai_addr->sa_family; int af = res->ai_addr->sa_family;
unsigned dport = ntohs(af == AF_INET ? p->v4.sin_port : p->v6.sin6_port); unsigned dport = ntohs(af == AF_INET ? p->v4.sin_port : p->v6.sin6_port);
socklen_t slen = sizeof u; socklen_t slen = sizeof u;
if (dport == config.port) { if (dport == config->port) {
getsockname(sockfd, (void*)&u, &slen); getsockname(sockfd, (void*)&u, &slen);
loop_records_add(&u); loop_records_add(&u);
} }

View File

@ -77,7 +77,7 @@ showstats (struct conn_s *connptr)
pthread_mutex_lock(&stats_file_lock); pthread_mutex_lock(&stats_file_lock);
if (!config.statpage || (!(statfile = fopen (config.statpage, "r")))) { if (!config->statpage || (!(statfile = fopen (config->statpage, "r")))) {
message_buffer = (char *) safemalloc (MAXBUFFSIZE); message_buffer = (char *) safemalloc (MAXBUFFSIZE);
if (!message_buffer) { if (!message_buffer) {
err_minus_one: err_minus_one: