--- lbbs/src/net_server.c 2025/06/07 02:38:28 1.56 +++ lbbs/src/net_server.c 2025/06/25 01:50:14 1.66 @@ -14,38 +14,35 @@ * * ***************************************************************************/ -#define _XOPEN_SOURCE 500 -#define _POSIX_C_SOURCE 200809L -#define _GNU_SOURCE - -#include "net_server.h" -#include "common.h" -#include "bbs_main.h" #include "bbs.h" -#include "log.h" +#include "bbs_main.h" +#include "common.h" +#include "database.h" +#include "file_loader.h" #include "io.h" #include "init.h" -#include "menu.h" -#include "database.h" +#include "log.h" #include "login.h" -#include "file_loader.h" +#include "menu.h" +#include "net_server.h" #include "section_list_loader.h" #include #include -#include #include #include +#include #include -#include -#include -#include -#include #include -#include -#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include struct process_sockaddr_t { @@ -56,7 +53,7 @@ typedef struct process_sockaddr_t PROCES static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT]; -#define SSH_AUTH_MAX_DURATION 60 // seconds +#define SSH_AUTH_MAX_DURATION (60 * 1000) // milliseconds struct ssl_server_cb_data_t { @@ -67,26 +64,18 @@ struct ssl_server_cb_data_t static int auth_password(ssh_session session, const char *user, const char *password, void *userdata) { - MYSQL *db; struct ssl_server_cb_data_t *p_data = userdata; int ret; - if ((db = db_open()) == NULL) - { - return SSH_AUTH_ERROR; - } - if (strcmp(user, "guest") == 0) { - ret = load_guest_info(db); + ret = load_guest_info(); } else { - ret = check_user(db, user, password); + ret = check_user(user, password); } - mysql_close(db); - if (ret == 0) { return SSH_AUTH_SUCCESS; @@ -193,9 +182,9 @@ static int fork_server(void) event = ssh_event_new(); ssh_event_add_session(event, SSH_session); - for (i = 0; i < SSH_AUTH_MAX_DURATION && !SYS_server_exit && !cb_data.error && SSH_channel == NULL; i++) + for (i = 0; i < SSH_AUTH_MAX_DURATION && !SYS_server_exit && !cb_data.error && SSH_channel == NULL; i += 100) { - ret = ssh_event_dopoll(event, 1000); // 1 second + ret = ssh_event_dopoll(event, 100); // 0.1 second if (ret == SSH_ERROR) { log_error("ssh_event_dopoll() error: %s\n", ssh_get_error(SSH_session)); @@ -269,7 +258,7 @@ int net_server(const char *hostaddr, in_ int nfds, epollfd; siginfo_t siginfo; int sd_notify_stopping = 0; - MENU_SET *p_bbs_menu_new; + MENU_SET bbs_menu_new; int i, j; pid_t pid; int ssh_log_level = SSH_LOG_NOLOG; @@ -281,6 +270,7 @@ int net_server(const char *hostaddr, in_ 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_HOSTKEY_ALGORITHMS, "ssh-rsa,rsa-sha2-512,rsa-sha2-256") < 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)); @@ -429,27 +419,14 @@ int net_server(const char *hostaddr, in_ log_error("Reload conf failed\n"); } - p_bbs_menu_new = calloc(1, sizeof(MENU_SET)); - if (p_bbs_menu_new == NULL) + if (load_menu(&bbs_menu_new, CONF_MENU) < 0) { - log_error("OOM: calloc(MENU_SET)\n"); - } - else if (load_menu(p_bbs_menu_new, CONF_MENU) < 0) - { - unload_menu(p_bbs_menu_new); - free(p_bbs_menu_new); - p_bbs_menu_new = NULL; - + unload_menu(&bbs_menu_new); log_error("Reload menu failed\n"); } else { - unload_menu(p_bbs_menu); - free(p_bbs_menu); - - p_bbs_menu = p_bbs_menu_new; - p_bbs_menu_new = NULL; - + memcpy(&bbs_menu, &bbs_menu_new, sizeof(bbs_menu_new)); log_common("Reload menu successfully\n"); } @@ -479,7 +456,7 @@ int net_server(const char *hostaddr, in_ if (section_list_loader_reload() < 0) { - log_error("ksection_list_loader_reload() failed\n"); + log_error("section_list_loader_reload() failed\n"); } } @@ -533,7 +510,7 @@ int net_server(const char *hostaddr, in_ port_client = ntohs(sin.sin_port); - log_common("Accept %sconnection from %s:%d\n", (SSH_v2 ? "" : "SSH2 "), hostaddr_client, port_client); + log_common("Accept %s connection from %s:%d\n", (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client); if (SYS_child_process_count - 1 < BBS_max_client) {