--- lbbs/src/net_server.c 2025/11/28 03:23:58 1.97 +++ lbbs/src/net_server.c 2025/12/16 13:16:47 1.104 @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -114,6 +115,11 @@ static int auth_password(ssh_session ses else { ret = check_user(user, password); + if (ret == 2) // Enforce update user agreement + { + BBS_update_eula = 1; + ret = 0; + } } if (ret == 0) @@ -422,6 +428,8 @@ static int fork_server(void) log_error("Error setting SSH options: %s\n", ssh_get_error(SSH_session)); goto cleanup; } + + ssh_set_blocking(SSH_session, 0); } // Redirect Input @@ -507,6 +515,7 @@ cleanup: int net_server(const char *hostaddr, in_port_t port[]) { + struct stat file_stat; unsigned int addrlen; int ret; int flags_server[2]; @@ -536,7 +545,7 @@ int net_server(const char *hostaddr, in_ if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_RSA_KEY_FILE) < 0) { - log_error("Error setting SSH RSA key: %s\n", SSH_HOST_RSA_KEY_FILE); + log_error("Error loading SSH RSA key: %s\n", SSH_HOST_RSA_KEY_FILE); } else { @@ -544,7 +553,15 @@ int net_server(const char *hostaddr, in_ } if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ED25519_KEY_FILE) < 0) { - log_error("Error setting SSH ED25519 key: %s\n", SSH_HOST_ED25519_KEY_FILE); + log_error("Error loading SSH ED25519 key: %s\n", SSH_HOST_ED25519_KEY_FILE); + } + else + { + ssh_key_valid = 1; + } + if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ECDSA_KEY_FILE) < 0) + { + log_error("Error loading SSH ECDSA key: %s\n", SSH_HOST_ECDSA_KEY_FILE); } else { @@ -560,7 +577,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_ALGORITHMS, "ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-ed25519") < 0 || + ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "+ssh-rsa") < 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)); @@ -638,6 +655,8 @@ int net_server(const char *hostaddr, in_ fcntl(socket_server[i], F_SETFL, flags_server[i] | O_NONBLOCK); } + ssh_bind_set_blocking(sshbind, 0); + hash_dict_pid_sockaddr = hash_dict_create(MAX_CLIENT_LIMIT); if (hash_dict_pid_sockaddr == NULL) { @@ -791,6 +810,16 @@ int net_server(const char *hostaddr, in_ log_error("Reload BWF conf failed\n"); } + // Get EULA modification tm + if (stat(DATA_EULA, &file_stat) == -1) + { + log_error("stat(%s) error\n", DATA_EULA, errno); + } + else + { + BBS_eula_tm = file_stat.st_mtim.tv_sec; + } + if (detach_menu_shm(&bbs_menu) < 0) { log_error("detach_menu_shm(bbs_menu) error\n"); @@ -810,6 +839,7 @@ int net_server(const char *hostaddr, in_ log_error("load_menu(top10_menu) error\n"); unload_menu(&top10_menu); } + top10_menu.allow_exit = 1; for (int i = 0; i < data_files_load_startup_count; i++) { @@ -907,8 +937,6 @@ int net_server(const char *hostaddr, in_ port_client = ntohs(sin.sin_port); - 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) { j = 0; @@ -920,6 +948,9 @@ int net_server(const char *hostaddr, in_ if (j < BBS_max_client_per_ip) { + log_common("Accept %s connection from %s:%d, already have %d connections\n", + (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client, j); + if ((pid = fork_server()) < 0) { log_error("fork_server() error\n"); @@ -935,18 +966,20 @@ int net_server(const char *hostaddr, in_ ret = hash_dict_inc(hash_dict_sockaddr_count, (uint64_t)sin.sin_addr.s_addr, 1); if (ret < 0) { - log_error("hash_dict_inc(hash_dict_sockaddr_count, %s, %d) error\n", hostaddr_client, 1); + log_error("hash_dict_inc(hash_dict_sockaddr_count, %s, 1) error\n", hostaddr_client); } } } else { - log_error("Rejected client connection from %s over limit per IP (%d)\n", hostaddr_client, BBS_max_client_per_ip); + log_error("Rejected %s connection from %s:%d over limit per IP (%d)\n", + (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client, BBS_max_client_per_ip); } } else { - log_error("Rejected client connection over limit (%d)\n", SYS_child_process_count - 1); + log_error("Rejected %s connection from %s:%d over limit (%d)\n", + (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client, SYS_child_process_count - 1); } if (close(socket_client) == -1)