migrate sslh-fork to new log system

This commit is contained in:
yrutschle 2021-09-19 20:29:43 +02:00
parent f7b6f669a4
commit 673c40954e
2 changed files with 10 additions and 14 deletions

View File

@ -24,6 +24,7 @@
#include "probe.h" #include "probe.h"
#include "sslh-conf.h" #include "sslh-conf.h"
#include "udp-listener.h" #include "udp-listener.h"
#include "log.h"
#ifdef LIBBSD #ifdef LIBBSD
#include <bsd/unistd.h> #include <bsd/unistd.h>
@ -58,8 +59,7 @@ int shovel(struct connection *cnx)
if (FD_ISSET(cnx->q[i].fd, &fds)) { if (FD_ISSET(cnx->q[i].fd, &fds)) {
res = fd2fd(&cnx->q[1-i], &cnx->q[i]); res = fd2fd(&cnx->q[1-i], &cnx->q[i]);
if (res == FD_CNXCLOSED) { if (res == FD_CNXCLOSED) {
if (cfg.verbose) print_message(msg_fd, "%s %s", i ? "client" : "server", "socket closed\n");
fprintf(stderr, "%s %s", i ? "client" : "server", "socket closed\n");
return res; return res;
} }
} }
@ -100,7 +100,7 @@ void start_shoveler(int in_socket)
/* Timed out: it's necessarily SSH */ /* Timed out: it's necessarily SSH */
cnx.proto = timeout_protocol(); cnx.proto = timeout_protocol();
if (cfg.verbose) if (cfg.verbose)
log_message(LOG_INFO, "timed out, connect to %s\n", cnx.proto->name); print_message(msg_fd, "timed out, connect to %s\n", cnx.proto->name);
break; break;
} }
} }
@ -129,8 +129,7 @@ void start_shoveler(int in_socket)
close(in_socket); close(in_socket);
close(out_socket); close(out_socket);
if (cfg.verbose) print_message(msg_fd, "connection closed down\n");
fprintf(stderr, "connection closed down\n");
exit(0); exit(0);
} }
@ -179,10 +178,10 @@ void tcp_listener(struct listen_endpoint* endpoint, int num_endpoints, int activ
while (1) { while (1) {
in_socket = accept(endpoint[active_endpoint].socketfd, 0, 0); in_socket = accept(endpoint[active_endpoint].socketfd, 0, 0);
if (cfg.verbose) fprintf(stderr, "accepted fd %d\n", in_socket); print_message(msg_fd, "accepted fd %d\n", in_socket);
switch(fork()) { switch(fork()) {
case -1: log_message(LOG_ERR, "fork failed: err %d: %s\n", errno, strerror(errno)); case -1: print_message(msg_system_error, "fork failed: err %d: %s\n", errno, strerror(errno));
break; break;
case 0: /* In child process */ case 0: /* In child process */
@ -214,13 +213,13 @@ void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen)
listener_pid[i] = fork(); listener_pid[i] = fork();
switch(listener_pid[i]) { switch(listener_pid[i]) {
/* Log if fork() fails for some reason */ /* Log if fork() fails for some reason */
case -1: log_message(LOG_ERR, "fork failed: err %d: %s\n", errno, strerror(errno)); case -1: print_message(msg_system_error, "fork failed: err %d: %s\n", errno, strerror(errno));
break; break;
/* We're in the child, we have work to do */ /* We're in the child, we have work to do */
case 0: case 0:
set_listen_procname(&listen_sockets[i]); set_listen_procname(&listen_sockets[i]);
if (listen_sockets[i].type == SOCK_DGRAM) if (listen_sockets[i].type == SOCK_DGRAM)
log_message(LOG_ERR, "UDP not (yet?) supported in sslh-fork\n"); print_message(msg_config_error, "UDP not (yet?) supported in sslh-fork\n");
else else
tcp_listener(listen_sockets, num_addr_listen, i); tcp_listener(listen_sockets, num_addr_listen, i);
break; break;

View File

@ -83,7 +83,7 @@ static int tidy_connection(struct connection *cnx, struct select_info* fd_info)
* and FD_CLR. Need to drop connections if we go above that limit */ * and FD_CLR. Need to drop connections if we go above that limit */
static int fd_is_in_range(int fd) { static int fd_is_in_range(int fd) {
if (fd >= FD_SETSIZE) { if (fd >= FD_SETSIZE) {
log_message(LOG_ERR, "too many open file descriptor to monitor them all -- dropping connection\n"); print_message(msg_system_error, "too many open file descriptor to monitor them all -- dropping connection\n");
return 0; return 0;
} }
return 1; return 1;
@ -286,10 +286,7 @@ static void probing_read_process(struct connection* cnx,
* data so probe the protocol */ * data so probe the protocol */
if ((cnx->probe_timeout < time(NULL))) { if ((cnx->probe_timeout < time(NULL))) {
cnx->proto = timeout_protocol(); cnx->proto = timeout_protocol();
if (cfg.verbose) print_message(msg_fd, "timed out, connect to %s\n", cnx->proto->name);
log_message(LOG_INFO,
"timed out, connect to %s\n",
cnx->proto->name);
} else { } else {
res = probe_client_protocol(cnx); res = probe_client_protocol(cnx);
if (res == PROBE_AGAIN) if (res == PROBE_AGAIN)