| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
#ifdef HAVE_CONFIG_H |
| 10 |
|
#include "config.h" |
| 11 |
|
#endif |
| 12 |
|
|
| 13 |
#include "bbs.h" |
#include "bbs.h" |
| 14 |
#include "bbs_main.h" |
#include "bbs_main.h" |
| 15 |
|
#include "bwf.h" |
| 16 |
#include "common.h" |
#include "common.h" |
| 17 |
#include "database.h" |
#include "database.h" |
| 18 |
#include "file_loader.h" |
#include "file_loader.h" |
| 19 |
|
#include "hash_dict.h" |
| 20 |
#include "io.h" |
#include "io.h" |
| 21 |
#include "init.h" |
#include "init.h" |
| 22 |
#include "log.h" |
#include "log.h" |
| 43 |
#include <sys/syscall.h> |
#include <sys/syscall.h> |
| 44 |
#include <sys/types.h> |
#include <sys/types.h> |
| 45 |
#include <sys/wait.h> |
#include <sys/wait.h> |
|
#include <systemd/sd-daemon.h> |
|
| 46 |
|
|
| 47 |
#define WAIT_CHILD_PROCESS_EXIT_TIMEOUT 5 // second |
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 48 |
#define WAIT_CHILD_PROCESS_KILL_TIMEOUT 1 // second |
#include <systemd/sd-daemon.h> |
| 49 |
|
#endif |
| 50 |
|
|
| 51 |
struct process_sockaddr_t |
enum _net_server_constant_t |
| 52 |
{ |
{ |
| 53 |
pid_t pid; |
WAIT_CHILD_PROCESS_EXIT_TIMEOUT = 5, // second |
| 54 |
in_addr_t s_addr; |
WAIT_CHILD_PROCESS_KILL_TIMEOUT = 1, // second |
|
}; |
|
|
typedef struct process_sockaddr_t PROCESS_SOCKADDR; |
|
|
|
|
|
static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT]; |
|
|
|
|
|
#define SSH_AUTH_MAX_DURATION (60 * 1000) // milliseconds |
|
| 55 |
|
|
| 56 |
#define SFTP_SERVER_PATH "/usr/lib/sftp-server" |
SSH_AUTH_MAX_DURATION = 60 * 1000, // milliseconds |
| 57 |
|
}; |
| 58 |
|
|
| 59 |
/* A userdata struct for session. */ |
/* A userdata struct for session. */ |
| 60 |
struct session_data_struct |
struct session_data_struct |
| 82 |
struct winsize *winsize; |
struct winsize *winsize; |
| 83 |
}; |
}; |
| 84 |
|
|
| 85 |
|
static int socket_server[2]; |
| 86 |
|
static int socket_client; |
| 87 |
|
static int epollfd_server = -1; |
| 88 |
|
static ssh_bind sshbind; |
| 89 |
|
|
| 90 |
|
static HASH_DICT *hash_dict_pid_sockaddr = NULL; |
| 91 |
|
static HASH_DICT *hash_dict_sockaddr_count = NULL; |
| 92 |
|
|
| 93 |
|
static const char SFTP_SERVER_PATH[] = "/usr/lib/sftp-server"; |
| 94 |
|
|
| 95 |
static int auth_password(ssh_session session, const char *user, |
static int auth_password(ssh_session session, const char *user, |
| 96 |
const char *password, void *userdata) |
const char *password, void *userdata) |
| 97 |
{ |
{ |
| 318 |
} |
} |
| 319 |
|
|
| 320 |
// Child process |
// Child process |
| 321 |
|
if (close(epollfd_server) < 0) |
| 322 |
|
{ |
| 323 |
|
log_error("close(epollfd_server) error (%d)\n"); |
| 324 |
|
} |
| 325 |
|
|
| 326 |
if (close(socket_server[0]) == -1 || close(socket_server[1]) == -1) |
for (i = 0; i < 2; i++) |
| 327 |
{ |
{ |
| 328 |
log_error("Close server socket failed\n"); |
if (close(socket_server[i]) == -1) |
| 329 |
|
{ |
| 330 |
|
log_error("Close server socket failed\n"); |
| 331 |
|
} |
| 332 |
} |
} |
| 333 |
|
|
| 334 |
|
hash_dict_destroy(hash_dict_pid_sockaddr); |
| 335 |
|
hash_dict_destroy(hash_dict_sockaddr_count); |
| 336 |
|
|
| 337 |
SSH_session = ssh_new(); |
SSH_session = ssh_new(); |
| 338 |
|
|
| 339 |
if (SSH_v2) |
if (SSH_v2) |
| 414 |
} |
} |
| 415 |
|
|
| 416 |
// Redirect Input |
// Redirect Input |
|
close(STDIN_FILENO); |
|
| 417 |
if (dup2(socket_client, STDIN_FILENO) == -1) |
if (dup2(socket_client, STDIN_FILENO) == -1) |
| 418 |
{ |
{ |
| 419 |
log_error("Redirect stdin to client socket failed\n"); |
log_error("Redirect stdin to client socket failed\n"); |
| 421 |
} |
} |
| 422 |
|
|
| 423 |
// Redirect Output |
// Redirect Output |
|
close(STDOUT_FILENO); |
|
| 424 |
if (dup2(socket_client, STDOUT_FILENO) == -1) |
if (dup2(socket_client, STDOUT_FILENO) == -1) |
| 425 |
{ |
{ |
| 426 |
log_error("Redirect stdout to client socket failed\n"); |
log_error("Redirect stdout to client socket failed\n"); |
| 427 |
goto cleanup; |
goto cleanup; |
| 428 |
} |
} |
| 429 |
|
|
| 430 |
|
if (io_init() < 0) |
| 431 |
|
{ |
| 432 |
|
log_error("io_init() error\n"); |
| 433 |
|
goto cleanup; |
| 434 |
|
} |
| 435 |
|
|
| 436 |
SYS_child_process_count = 0; |
SYS_child_process_count = 0; |
| 437 |
|
|
| 438 |
bbs_main(); |
bbs_main(); |
| 443 |
|
|
| 444 |
if (SSH_v2) |
if (SSH_v2) |
| 445 |
{ |
{ |
| 446 |
close(cdata.pty_master); |
if (cdata.pty_master != -1) |
| 447 |
close(cdata.child_stdin); |
{ |
| 448 |
close(cdata.child_stdout); |
close(cdata.pty_master); |
| 449 |
close(cdata.child_stderr); |
} |
| 450 |
|
if (cdata.child_stdin != -1) |
| 451 |
|
{ |
| 452 |
|
close(cdata.child_stdin); |
| 453 |
|
} |
| 454 |
|
if (cdata.child_stdout != -1) |
| 455 |
|
{ |
| 456 |
|
close(cdata.child_stdout); |
| 457 |
|
} |
| 458 |
|
if (cdata.child_stderr != -1) |
| 459 |
|
{ |
| 460 |
|
close(cdata.child_stderr); |
| 461 |
|
} |
| 462 |
|
|
| 463 |
ssh_channel_free(SSH_channel); |
ssh_channel_free(SSH_channel); |
| 464 |
ssh_disconnect(SSH_session); |
ssh_disconnect(SSH_session); |
| 472 |
ssh_finalize(); |
ssh_finalize(); |
| 473 |
|
|
| 474 |
// Close Input and Output for client |
// Close Input and Output for client |
| 475 |
|
io_cleanup(); |
| 476 |
close(STDIN_FILENO); |
close(STDIN_FILENO); |
| 477 |
close(STDOUT_FILENO); |
close(STDOUT_FILENO); |
| 478 |
|
|
| 488 |
{ |
{ |
| 489 |
unsigned int addrlen; |
unsigned int addrlen; |
| 490 |
int ret; |
int ret; |
| 491 |
int flags[2]; |
int flags_server[2]; |
| 492 |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
| 493 |
struct epoll_event ev, events[MAX_EVENTS]; |
struct epoll_event ev, events[MAX_EVENTS]; |
| 494 |
int nfds, epollfd; |
int nfds; |
| 495 |
siginfo_t siginfo; |
siginfo_t siginfo; |
| 496 |
int notify_child_exit = 0; |
int notify_child_exit = 0; |
| 497 |
time_t tm_notify_child_exit = time(NULL); |
time_t tm_notify_child_exit = time(NULL); |
|
int sd_notify_stopping = 0; |
|
| 498 |
MENU_SET bbs_menu_new; |
MENU_SET bbs_menu_new; |
| 499 |
MENU_SET top10_menu_new; |
MENU_SET top10_menu_new; |
| 500 |
int i, j; |
int i, j; |
| 501 |
pid_t pid; |
pid_t pid; |
| 502 |
int ssh_log_level = SSH_LOG_NOLOG; |
int ssh_log_level = SSH_LOG_NOLOG; |
| 503 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 504 |
|
int sd_notify_stopping = 0; |
| 505 |
|
#endif |
| 506 |
|
|
| 507 |
ssh_init(); |
ssh_init(); |
| 508 |
|
|
| 519 |
return -1; |
return -1; |
| 520 |
} |
} |
| 521 |
|
|
| 522 |
epollfd = epoll_create1(0); |
epollfd_server = epoll_create1(0); |
| 523 |
if (epollfd < 0) |
if (epollfd_server == -1) |
| 524 |
{ |
{ |
| 525 |
log_error("epoll_create1() error (%d)\n", errno); |
log_error("epoll_create1() error (%d)\n", errno); |
| 526 |
return -1; |
return -1; |
| 542 |
sin.sin_port = htons(port[i]); |
sin.sin_port = htons(port[i]); |
| 543 |
|
|
| 544 |
// Reuse address and port |
// Reuse address and port |
| 545 |
flags[i] = 1; |
flags_server[i] = 1; |
| 546 |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEADDR, &flags[i], sizeof(flags[i])) < 0) |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEADDR, &flags_server[i], sizeof(flags_server[i])) < 0) |
| 547 |
{ |
{ |
| 548 |
log_error("setsockopt SO_REUSEADDR error (%d)\n", errno); |
log_error("setsockopt SO_REUSEADDR error (%d)\n", errno); |
| 549 |
} |
} |
| 550 |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEPORT, &flags[i], sizeof(flags[i])) < 0) |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEPORT, &flags_server[i], sizeof(flags_server[i])) < 0) |
| 551 |
{ |
{ |
| 552 |
log_error("setsockopt SO_REUSEPORT error (%d)\n", errno); |
log_error("setsockopt SO_REUSEPORT error (%d)\n", errno); |
| 553 |
} |
} |
| 569 |
|
|
| 570 |
ev.events = EPOLLIN; |
ev.events = EPOLLIN; |
| 571 |
ev.data.fd = socket_server[i]; |
ev.data.fd = socket_server[i]; |
| 572 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, socket_server[i], &ev) == -1) |
if (epoll_ctl(epollfd_server, EPOLL_CTL_ADD, socket_server[i], &ev) == -1) |
| 573 |
{ |
{ |
| 574 |
log_error("epoll_ctl(socket_server[%d]) error (%d)\n", i, errno); |
log_error("epoll_ctl(socket_server[%d]) error (%d)\n", i, errno); |
| 575 |
if (close(epollfd) < 0) |
if (close(epollfd_server) < 0) |
| 576 |
{ |
{ |
| 577 |
log_error("close(epoll) error (%d)\n"); |
log_error("close(epoll) error (%d)\n"); |
| 578 |
} |
} |
| 579 |
return -1; |
return -1; |
| 580 |
} |
} |
| 581 |
|
|
| 582 |
flags[i] = fcntl(socket_server[i], F_GETFL, 0); |
flags_server[i] = fcntl(socket_server[i], F_GETFL, 0); |
| 583 |
fcntl(socket_server[i], F_SETFL, flags[i] | O_NONBLOCK); |
fcntl(socket_server[i], F_SETFL, flags_server[i] | O_NONBLOCK); |
| 584 |
|
} |
| 585 |
|
|
| 586 |
|
hash_dict_pid_sockaddr = hash_dict_create(MAX_CLIENT_LIMIT); |
| 587 |
|
if (hash_dict_pid_sockaddr == NULL) |
| 588 |
|
{ |
| 589 |
|
log_error("hash_dict_create(hash_dict_pid_sockaddr) error\n"); |
| 590 |
|
return -1; |
| 591 |
|
} |
| 592 |
|
hash_dict_sockaddr_count = hash_dict_create(MAX_CLIENT_LIMIT); |
| 593 |
|
if (hash_dict_sockaddr_count == NULL) |
| 594 |
|
{ |
| 595 |
|
log_error("hash_dict_create(hash_dict_sockaddr_count) error\n"); |
| 596 |
|
return -1; |
| 597 |
} |
} |
| 598 |
|
|
| 599 |
// Startup complete |
// Startup complete |
| 600 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 601 |
sd_notifyf(0, "READY=1\n" |
sd_notifyf(0, "READY=1\n" |
| 602 |
"STATUS=Listening at %s:%d (Telnet) and %s:%d (SSH2)\n" |
"STATUS=Listening at %s:%d (Telnet) and %s:%d (SSH2)\n" |
| 603 |
"MAINPID=%d", |
"MAINPID=%d", |
| 604 |
hostaddr, port[0], hostaddr, port[1], getpid()); |
hostaddr, port[0], hostaddr, port[1], getpid()); |
| 605 |
|
#endif |
| 606 |
|
|
| 607 |
while (!SYS_server_exit || SYS_child_process_count > 0) |
while (!SYS_server_exit || SYS_child_process_count > 0) |
| 608 |
{ |
{ |
| 609 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 610 |
if (SYS_server_exit && !sd_notify_stopping) |
if (SYS_server_exit && !sd_notify_stopping) |
| 611 |
{ |
{ |
| 612 |
sd_notify(0, "STOPPING=1"); |
sd_notify(0, "STOPPING=1"); |
| 613 |
sd_notify_stopping = 1; |
sd_notify_stopping = 1; |
| 614 |
} |
} |
| 615 |
|
#endif |
| 616 |
|
|
| 617 |
while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0) |
while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0) |
| 618 |
{ |
{ |
| 629 |
|
|
| 630 |
if (siginfo.si_pid != section_list_loader_pid) |
if (siginfo.si_pid != section_list_loader_pid) |
| 631 |
{ |
{ |
| 632 |
i = 0; |
j = 0; |
| 633 |
for (; i < BBS_max_client; i++) |
ret = hash_dict_get(hash_dict_pid_sockaddr, (uint64_t)siginfo.si_pid, (int64_t *)&j); |
| 634 |
|
if (ret < 0) |
| 635 |
{ |
{ |
| 636 |
if (process_sockaddr_pool[i].pid == siginfo.si_pid) |
log_error("hash_dict_get(hash_dict_pid_sockaddr, %d) error\n", siginfo.si_pid); |
|
{ |
|
|
process_sockaddr_pool[i].pid = 0; |
|
|
break; |
|
|
} |
|
| 637 |
} |
} |
| 638 |
if (i >= BBS_max_client) |
else |
| 639 |
{ |
{ |
| 640 |
log_error("Child process (%d) not found in process sockaddr pool\n", siginfo.si_pid); |
ret = hash_dict_inc(hash_dict_sockaddr_count, (uint64_t)j, -1); |
| 641 |
|
if (ret < 0) |
| 642 |
|
{ |
| 643 |
|
log_error("hash_dict_inc(hash_dict_sockaddr_count, %d, -1) error\n", j); |
| 644 |
|
} |
| 645 |
|
|
| 646 |
|
ret = hash_dict_del(hash_dict_pid_sockaddr, (uint64_t)siginfo.si_pid); |
| 647 |
|
if (ret < 0) |
| 648 |
|
{ |
| 649 |
|
log_error("hash_dict_del(hash_dict_pid_sockaddr, %d) error\n", siginfo.si_pid); |
| 650 |
|
} |
| 651 |
} |
} |
| 652 |
} |
} |
| 653 |
} |
} |
| 666 |
{ |
{ |
| 667 |
if (notify_child_exit == 0) |
if (notify_child_exit == 0) |
| 668 |
{ |
{ |
| 669 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 670 |
sd_notifyf(0, "STATUS=Notify %d child process to exit", SYS_child_process_count); |
sd_notifyf(0, "STATUS=Notify %d child process to exit", SYS_child_process_count); |
| 671 |
log_common("Notify %d child process to exit\n", SYS_child_process_count); |
log_common("Notify %d child process to exit\n", SYS_child_process_count); |
| 672 |
|
#endif |
| 673 |
|
|
| 674 |
if (kill(0, SIGTERM) < 0) |
if (kill(-getpid(), SIGTERM) < 0) |
| 675 |
{ |
{ |
| 676 |
log_error("Send SIGTERM signal failed (%d)\n", errno); |
log_error("Send SIGTERM signal failed (%d)\n", errno); |
| 677 |
} |
} |
| 681 |
} |
} |
| 682 |
else if (notify_child_exit == 1 && time(NULL) - tm_notify_child_exit >= WAIT_CHILD_PROCESS_EXIT_TIMEOUT) |
else if (notify_child_exit == 1 && time(NULL) - tm_notify_child_exit >= WAIT_CHILD_PROCESS_EXIT_TIMEOUT) |
| 683 |
{ |
{ |
| 684 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 685 |
sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count); |
sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count); |
| 686 |
|
#endif |
| 687 |
|
|
| 688 |
for (i = 0; i < BBS_max_client; i++) |
if (kill(-getpid(), SIGKILL) < 0) |
| 689 |
{ |
{ |
| 690 |
if (process_sockaddr_pool[i].pid != 0) |
log_error("Send SIGKILL signal failed (%d)\n", errno); |
|
{ |
|
|
log_error("Kill child process (pid=%d)\n", process_sockaddr_pool[i].pid); |
|
|
if (kill(process_sockaddr_pool[i].pid, SIGKILL) < 0) |
|
|
{ |
|
|
log_error("Send SIGKILL signal failed (%d)\n", errno); |
|
|
} |
|
|
} |
|
| 691 |
} |
} |
| 692 |
|
|
| 693 |
notify_child_exit = 2; |
notify_child_exit = 2; |
| 703 |
if (SYS_conf_reload && !SYS_server_exit) |
if (SYS_conf_reload && !SYS_server_exit) |
| 704 |
{ |
{ |
| 705 |
SYS_conf_reload = 0; |
SYS_conf_reload = 0; |
| 706 |
|
|
| 707 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 708 |
sd_notify(0, "RELOADING=1"); |
sd_notify(0, "RELOADING=1"); |
| 709 |
|
#endif |
| 710 |
|
|
| 711 |
|
// Restart log |
| 712 |
|
if (log_restart() < 0) |
| 713 |
|
{ |
| 714 |
|
log_error("Restart logging failed\n"); |
| 715 |
|
} |
| 716 |
|
|
| 717 |
// Reload configuration |
// Reload configuration |
| 718 |
if (load_conf(CONF_BBSD) < 0) |
if (load_conf(CONF_BBSD) < 0) |
| 720 |
log_error("Reload conf failed\n"); |
log_error("Reload conf failed\n"); |
| 721 |
} |
} |
| 722 |
|
|
| 723 |
|
// Reload BWF config |
| 724 |
|
if (bwf_load(CONF_BWF) < 0) |
| 725 |
|
{ |
| 726 |
|
log_error("Reload BWF conf failed\n"); |
| 727 |
|
} |
| 728 |
|
|
| 729 |
if (load_menu(&bbs_menu_new, CONF_MENU) < 0) |
if (load_menu(&bbs_menu_new, CONF_MENU) < 0) |
| 730 |
{ |
{ |
| 731 |
unload_menu(&bbs_menu_new); |
unload_menu(&bbs_menu_new); |
| 770 |
log_common("Reload section config and gen_ex successfully\n"); |
log_common("Reload section config and gen_ex successfully\n"); |
| 771 |
} |
} |
| 772 |
|
|
| 773 |
|
// Notify child processes to reload configuration |
| 774 |
|
if (kill(-getpid(), SIGUSR1) < 0) |
| 775 |
|
{ |
| 776 |
|
log_error("Send SIGUSR1 signal failed (%d)\n", errno); |
| 777 |
|
} |
| 778 |
|
|
| 779 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 780 |
sd_notify(0, "READY=1"); |
sd_notify(0, "READY=1"); |
| 781 |
|
#endif |
| 782 |
} |
} |
| 783 |
|
|
| 784 |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |
nfds = epoll_wait(epollfd_server, events, MAX_EVENTS, 100); // 0.1 second |
| 785 |
|
|
| 786 |
if (nfds < 0) |
if (nfds < 0) |
| 787 |
{ |
{ |
| 836 |
if (SYS_child_process_count - 1 < BBS_max_client) |
if (SYS_child_process_count - 1 < BBS_max_client) |
| 837 |
{ |
{ |
| 838 |
j = 0; |
j = 0; |
| 839 |
for (i = 0; i < BBS_max_client; i++) |
ret = hash_dict_get(hash_dict_sockaddr_count, (uint64_t)sin.sin_addr.s_addr, (int64_t *)&j); |
| 840 |
|
if (ret < 0) |
| 841 |
{ |
{ |
| 842 |
if (process_sockaddr_pool[i].pid != 0 && process_sockaddr_pool[i].s_addr == sin.sin_addr.s_addr) |
log_error("hash_dict_get(hash_dict_sockaddr_count, %s) error\n", hostaddr_client); |
|
{ |
|
|
j++; |
|
|
if (j >= BBS_max_client_per_ip) |
|
|
{ |
|
|
log_common("Too many client connections (%d) from %s\n", j, hostaddr_client); |
|
|
break; |
|
|
} |
|
|
} |
|
| 843 |
} |
} |
| 844 |
|
|
| 845 |
if (j < BBS_max_client_per_ip) |
if (j < BBS_max_client_per_ip) |
| 850 |
} |
} |
| 851 |
else if (pid > 0) |
else if (pid > 0) |
| 852 |
{ |
{ |
| 853 |
i = 0; |
ret = hash_dict_set(hash_dict_pid_sockaddr, (uint64_t)pid, sin.sin_addr.s_addr); |
| 854 |
for (; i < BBS_max_client; i++) |
if (ret < 0) |
| 855 |
{ |
{ |
| 856 |
if (process_sockaddr_pool[i].pid == 0) |
log_error("hash_dict_set(hash_dict_pid_sockaddr, %d, %s) error\n", pid, hostaddr_client); |
|
{ |
|
|
break; |
|
|
} |
|
| 857 |
} |
} |
| 858 |
|
|
| 859 |
if (i >= BBS_max_client) |
ret = hash_dict_inc(hash_dict_sockaddr_count, (uint64_t)sin.sin_addr.s_addr, 1); |
| 860 |
{ |
if (ret < 0) |
|
log_error("Process sockaddr pool depleted\n"); |
|
|
} |
|
|
else |
|
| 861 |
{ |
{ |
| 862 |
process_sockaddr_pool[i].pid = pid; |
log_error("hash_dict_inc(hash_dict_sockaddr_count, %s, %d) error\n", hostaddr_client, 1); |
|
process_sockaddr_pool[i].s_addr = sin.sin_addr.s_addr; |
|
| 863 |
} |
} |
| 864 |
} |
} |
| 865 |
} |
} |
| 866 |
|
else |
| 867 |
|
{ |
| 868 |
|
log_error("Rejected client connection from %s over limit per IP (%d)\n", hostaddr_client, BBS_max_client_per_ip); |
| 869 |
|
} |
| 870 |
} |
} |
| 871 |
else |
else |
| 872 |
{ |
{ |
| 882 |
} |
} |
| 883 |
} |
} |
| 884 |
|
|
| 885 |
if (close(epollfd) < 0) |
if (close(epollfd_server) < 0) |
| 886 |
{ |
{ |
| 887 |
log_error("close(epoll) error (%d)\n"); |
log_error("close(epollfd_server) error (%d)\n"); |
| 888 |
} |
} |
| 889 |
|
|
| 890 |
for (i = 0; i < 2; i++) |
for (i = 0; i < 2; i++) |
| 891 |
{ |
{ |
|
fcntl(socket_server[i], F_SETFL, flags[i]); |
|
|
|
|
| 892 |
if (close(socket_server[i]) == -1) |
if (close(socket_server[i]) == -1) |
| 893 |
{ |
{ |
| 894 |
log_error("Close server socket failed\n"); |
log_error("Close server socket failed\n"); |
| 895 |
} |
} |
| 896 |
} |
} |
| 897 |
|
|
| 898 |
|
hash_dict_destroy(hash_dict_pid_sockaddr); |
| 899 |
|
hash_dict_destroy(hash_dict_sockaddr_count); |
| 900 |
|
|
| 901 |
ssh_bind_free(sshbind); |
ssh_bind_free(sshbind); |
| 902 |
ssh_finalize(); |
ssh_finalize(); |
| 903 |
|
|