| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#define _XOPEN_SOURCE 500 |
|
|
#define _POSIX_C_SOURCE 200809L |
|
|
#define _GNU_SOURCE |
|
|
|
|
|
#include "net_server.h" |
|
|
#include "common.h" |
|
|
#include "bbs_main.h" |
|
| 17 |
#include "bbs.h" |
#include "bbs.h" |
| 18 |
#include "log.h" |
#include "bbs_main.h" |
| 19 |
|
#include "common.h" |
| 20 |
|
#include "database.h" |
| 21 |
|
#include "file_loader.h" |
| 22 |
#include "io.h" |
#include "io.h" |
| 23 |
#include "init.h" |
#include "init.h" |
| 24 |
#include "menu.h" |
#include "log.h" |
|
#include "database.h" |
|
| 25 |
#include "login.h" |
#include "login.h" |
| 26 |
#include "file_loader.h" |
#include "menu.h" |
| 27 |
|
#include "net_server.h" |
| 28 |
|
#include "section_list.h" |
| 29 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 30 |
#include <errno.h> |
#include <errno.h> |
| 31 |
#include <fcntl.h> |
#include <fcntl.h> |
|
#include <string.h> |
|
| 32 |
#include <signal.h> |
#include <signal.h> |
| 33 |
#include <stdlib.h> |
#include <stdlib.h> |
| 34 |
|
#include <string.h> |
| 35 |
#include <unistd.h> |
#include <unistd.h> |
|
#include <sys/syscall.h> |
|
|
#include <sys/socket.h> |
|
|
#include <sys/wait.h> |
|
|
#include <sys/epoll.h> |
|
| 36 |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
| 37 |
#include <netinet/in.h> |
#include <libssh/callbacks.h> |
|
#include <systemd/sd-daemon.h> |
|
| 38 |
#include <libssh/libssh.h> |
#include <libssh/libssh.h> |
| 39 |
#include <libssh/server.h> |
#include <libssh/server.h> |
| 40 |
#include <libssh/callbacks.h> |
#include <netinet/in.h> |
| 41 |
|
#include <sys/epoll.h> |
| 42 |
|
#include <sys/socket.h> |
| 43 |
|
#include <sys/syscall.h> |
| 44 |
|
#include <sys/types.h> |
| 45 |
|
#include <sys/wait.h> |
| 46 |
|
#include <systemd/sd-daemon.h> |
| 47 |
|
|
| 48 |
struct process_sockaddr_t |
struct process_sockaddr_t |
| 49 |
{ |
{ |
| 259 |
int nfds, epollfd; |
int nfds, epollfd; |
| 260 |
siginfo_t siginfo; |
siginfo_t siginfo; |
| 261 |
int sd_notify_stopping = 0; |
int sd_notify_stopping = 0; |
| 262 |
MENU_SET *p_bbs_menu_new; |
MENU_SET bbs_menu_new; |
| 263 |
int i, j; |
int i, j; |
| 264 |
pid_t pid; |
pid_t pid; |
| 265 |
int ssh_log_level = SSH_LOG_NOLOG; |
int ssh_log_level = SSH_LOG_NOLOG; |
| 271 |
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 || |
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 || |
| 272 |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 || |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 || |
| 273 |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_KEYFILE) < 0 || |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_KEYFILE) < 0 || |
| 274 |
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "ssh-rsa,rsa-sha2-512,rsa-sha2-256") < 0 || |
| 275 |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) |
| 276 |
{ |
{ |
| 277 |
log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind)); |
log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind)); |
| 353 |
{ |
{ |
| 354 |
if (SYS_server_exit && !sd_notify_stopping) |
if (SYS_server_exit && !sd_notify_stopping) |
| 355 |
{ |
{ |
|
signal(SIGHUP, SIG_IGN); |
|
|
|
|
| 356 |
sd_notify(0, "STOPPING=1"); |
sd_notify(0, "STOPPING=1"); |
| 357 |
sd_notify_stopping = 1; |
sd_notify_stopping = 1; |
| 358 |
} |
} |
| 407 |
} |
} |
| 408 |
|
|
| 409 |
sd_notifyf(0, "STATUS=Waiting for %d child process to exit", SYS_child_process_count); |
sd_notifyf(0, "STATUS=Waiting for %d child process to exit", SYS_child_process_count); |
| 410 |
|
|
| 411 |
|
sleep(1); // Sleep for a while to avoid notifying child processes too frequently |
| 412 |
} |
} |
| 413 |
|
|
| 414 |
if (SYS_conf_reload && !SYS_server_exit) |
if (SYS_conf_reload && !SYS_server_exit) |
| 422 |
log_error("Reload conf failed\n"); |
log_error("Reload conf failed\n"); |
| 423 |
} |
} |
| 424 |
|
|
| 425 |
p_bbs_menu_new = calloc(1, sizeof(MENU_SET)); |
if (load_menu(&bbs_menu_new, CONF_MENU) < 0) |
|
if (p_bbs_menu_new == NULL) |
|
|
{ |
|
|
log_error("OOM: calloc(MENU_SET)\n"); |
|
|
} |
|
|
else if (load_menu(p_bbs_menu_new, CONF_MENU) < 0) |
|
| 426 |
{ |
{ |
| 427 |
unload_menu(p_bbs_menu_new); |
unload_menu(&bbs_menu_new); |
|
free(p_bbs_menu_new); |
|
|
p_bbs_menu_new = NULL; |
|
|
|
|
| 428 |
log_error("Reload menu failed\n"); |
log_error("Reload menu failed\n"); |
| 429 |
} |
} |
| 430 |
else |
else |
| 431 |
{ |
{ |
| 432 |
unload_menu(p_bbs_menu); |
unload_menu(&bbs_menu); |
| 433 |
free(p_bbs_menu); |
memcpy(&bbs_menu, &bbs_menu_new, sizeof(bbs_menu_new)); |
|
|
|
|
p_bbs_menu = p_bbs_menu_new; |
|
|
p_bbs_menu_new = NULL; |
|
|
|
|
| 434 |
log_common("Reload menu successfully\n"); |
log_common("Reload menu successfully\n"); |
| 435 |
} |
} |
| 436 |
|
|
|
sd_notify(0, "READY=1"); |
|
|
} |
|
|
|
|
|
if (SYS_data_file_reload && !SYS_server_exit) |
|
|
{ |
|
|
SYS_data_file_reload = 0; |
|
|
sd_notify(0, "RELOADING=1"); |
|
|
|
|
| 437 |
for (int i = 0; i < data_files_load_startup_count; i++) |
for (int i = 0; i < data_files_load_startup_count; i++) |
| 438 |
{ |
{ |
| 439 |
if (load_file(data_files_load_startup[i]) < 0) |
if (load_file(data_files_load_startup[i]) < 0) |
| 441 |
log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]); |
log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]); |
| 442 |
} |
} |
| 443 |
} |
} |
|
|
|
| 444 |
log_common("Reload data files successfully\n"); |
log_common("Reload data files successfully\n"); |
|
sd_notify(0, "READY=1"); |
|
|
} |
|
| 445 |
|
|
| 446 |
if (SYS_section_list_reload && !SYS_server_exit) |
// Load section config and gen_ex |
| 447 |
{ |
if (load_section_config_from_db(1) < 0) |
| 448 |
SYS_section_list_reload = 0; |
{ |
| 449 |
|
log_error("load_section_config_from_db(1) error\n"); |
| 450 |
if (section_list_loader_reload() < 0) |
} |
| 451 |
|
else |
| 452 |
{ |
{ |
| 453 |
log_error("ksection_list_loader_reload() failed\n"); |
log_common("Reload section config and gen_ex successfully\n"); |
| 454 |
} |
} |
| 455 |
|
|
| 456 |
|
sd_notify(0, "READY=1"); |
| 457 |
} |
} |
| 458 |
|
|
| 459 |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |
| 506 |
|
|
| 507 |
port_client = ntohs(sin.sin_port); |
port_client = ntohs(sin.sin_port); |
| 508 |
|
|
| 509 |
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); |
| 510 |
|
|
| 511 |
if (SYS_child_process_count - 1 < BBS_max_client) |
if (SYS_child_process_count - 1 < BBS_max_client) |
| 512 |
{ |
{ |