--- lbbs/src/net_server.c 2025/06/03 13:27:49 1.47 +++ lbbs/src/net_server.c 2025/06/05 05:24:56 1.51 @@ -40,6 +40,7 @@ #include #include #include +#include struct process_sockaddr_t { @@ -48,10 +49,11 @@ struct process_sockaddr_t }; typedef struct process_sockaddr_t PROCESS_SOCKADDR; -static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENTS_LIMIT]; +static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT]; int net_server(const char *hostaddr, in_port_t port) { + ssh_bind sshbind; unsigned int namelen; int ret; int flags; @@ -63,7 +65,22 @@ int net_server(const char *hostaddr, in_ MENU_SET *p_bbs_menu_new; int i, j; pid_t pid; + int ssh_log_level = SSH_LOG_NOLOG; + ssh_init(); + + sshbind = ssh_bind_new(); + + if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 || + ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 || + ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_KEYFILE) < 0 || + ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) + { + log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind)); + ssh_bind_free(sshbind); + return -1; + } + socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (socket_server < 0) @@ -106,7 +123,7 @@ int net_server(const char *hostaddr, in_ port_server = ntohs(sin.sin_port); namelen = sizeof(sin); - log_std("Listening at %s:%d\n", hostaddr_server, port_server); + log_common("Listening at %s:%d\n", hostaddr_server, port_server); epollfd = epoll_create1(0); if (epollfd < 0) @@ -155,7 +172,7 @@ int net_server(const char *hostaddr, in_ SYS_child_exit = 1; // Retry waitid SYS_child_process_count--; - log_std("Child process (%d) exited\n", siginfo.si_pid); + log_common("Child process (%d) exited\n", siginfo.si_pid); if (siginfo.si_pid != section_list_loader_pid) { @@ -187,7 +204,7 @@ int net_server(const char *hostaddr, in_ if (SYS_server_exit && !SYS_child_exit && SYS_child_process_count > 0) { - log_std("Notify %d child process to exit\n", SYS_child_process_count); + log_common("Notify %d child process to exit\n", SYS_child_process_count); if (kill(0, SIGTERM) < 0) { log_error("Send SIGTERM signal failed (%d)\n", errno); @@ -228,7 +245,7 @@ int net_server(const char *hostaddr, in_ p_bbs_menu = p_bbs_menu_new; p_bbs_menu_new = NULL; - log_std("Reload menu successfully\n"); + log_common("Reload menu successfully\n"); } sd_notify(0, "READY=1"); @@ -247,7 +264,7 @@ int net_server(const char *hostaddr, in_ } } - log_std("Reload data files successfully\n"); + log_common("Reload data files successfully\n"); sd_notify(0, "READY=1"); } @@ -308,7 +325,7 @@ int net_server(const char *hostaddr, in_ port_client = ntohs(sin.sin_port); - log_std("Accept connection from %s:%d\n", hostaddr_client, port_client); + log_common("Accept connection from %s:%d\n", hostaddr_client, port_client); if (SYS_child_process_count - 1 < BBS_max_client) { @@ -320,7 +337,7 @@ int net_server(const char *hostaddr, in_ j++; if (j >= BBS_max_client_per_ip) { - log_error("Too many client connections (%d) from %s\n", j, hostaddr_client); + log_common("Too many client connections (%d) from %s\n", j, hostaddr_client); break; } } @@ -328,7 +345,7 @@ int net_server(const char *hostaddr, in_ if (j < BBS_max_client_per_ip) { - if ((pid = fork_server()) < 0) + if ((pid = fork_server(sshbind)) < 0) { log_error("fork_server() error\n"); } @@ -381,5 +398,8 @@ int net_server(const char *hostaddr, in_ log_error("Close server socket failed\n"); } + ssh_bind_free(sshbind); + ssh_finalize(); + return 0; }