diff --git a/ChangeLog b/ChangeLog index 4bd195a..0d1f94f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +vNEXT: + Fix segmentation fault in sslh-fork. + v2.3.0: Added `max_connections` setting to `listen` and `protocol` configuration; see the diff --git a/common.c b/common.c index 82dd173..e27c50f 100644 --- a/common.c +++ b/common.c @@ -899,7 +899,7 @@ int check_access_rights(int in_socket, const char* service) } if (!hosts_ctl((char*)service, host, addr_str, STRING_UNKNOWN)) { - print_message(msg_connections, "connection from %s(%s): access denied", host, addr_str); + print_message(msg_connections, "connection from %s(%s): access denied\n", host, addr_str); close(in_socket); return -1; } diff --git a/common.h b/common.h index 0aac1d4..df58ebf 100644 --- a/common.h +++ b/common.h @@ -204,7 +204,7 @@ extern int hosts_ctl(); #endif /* sslh-fork.c */ -void start_shoveler(int); +void main_inetd(void); void main_loop(struct listen_endpoint *listen_sockets, int num_addr_listen); diff --git a/sslh-ev.c b/sslh-ev.c index 12a486e..f9b82ed 100644 --- a/sslh-ev.c +++ b/sslh-ev.c @@ -221,7 +221,7 @@ void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen) ev_run(EV_A_ 0); } -void start_shoveler(int listen_socket) { +void main_inetd(void) { print_message(msg_config_error, "inetd mode is not supported in libev mode\n"); exit(1); } diff --git a/sslh-fork.c b/sslh-fork.c index 02db38c..eec6009 100644 --- a/sslh-fork.c +++ b/sslh-fork.c @@ -69,7 +69,7 @@ int shovel(struct connection *cnx) /* Child process that finds out what to connect to and proxies */ -void start_shoveler(int in_socket) +static void start_shoveler(int in_socket, struct listen_endpoint* endpoint) { fd_set fds; struct timeval tv; @@ -79,6 +79,7 @@ void start_shoveler(int in_socket) init_cnx(&cnx); cnx.q[0].fd = in_socket; + cnx.endpoint = endpoint; FD_ZERO(&fds); FD_SET(in_socket, &fds); @@ -130,6 +131,22 @@ void start_shoveler(int in_socket) exit(0); } + +void main_inetd(void) +{ + struct listen_endpoint endpoint = {0}; + struct sslhcfg_listen_item endpoint_cfg = {0}; + + /* Empty configuration: no connection limits, not proxyprotocol... */ + endpoint.endpoint_cfg = &endpoint_cfg; + + close(fileno(stderr)); /* Make sure no error will go to client */ + tcp_init(); + start_shoveler(0, &endpoint); + exit(0); +} + + static pid_t *listener_pid; static int listener_pid_number = 0; @@ -252,7 +269,7 @@ void tcp_listener(struct listen_endpoint* endpoint, int num_endpoints, int activ /* Shoveler processes don't need to hog file descriptors */ for (i = 0; i < num_endpoints; i++) close(endpoint[i].socketfd); - start_shoveler(in_socket); + start_shoveler(in_socket, endpoint); exit(0); default: /* In parent process */ diff --git a/sslh-main.c b/sslh-main.c index 94cd6c6..fd4a967 100644 --- a/sslh-main.c +++ b/sslh-main.c @@ -308,10 +308,7 @@ int main(int argc, char *argv[], char* envp[]) if (cfg.inetd) { - close(fileno(stderr)); /* Make sure no error will go to client */ - tcp_init(); - start_shoveler(0); - exit(0); + main_inetd(); /* Does not return */ } printsettings(); diff --git a/sslh-select.c b/sslh-select.c index 5893123..376ff6a 100644 --- a/sslh-select.c +++ b/sslh-select.c @@ -292,7 +292,7 @@ void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen) } -void start_shoveler(int listen_socket) { +void main_inetd(void) { print_message(msg_config_error, "inetd mode is not supported in select mode\n"); exit(1); }