| 40 |
#include <netinet/in.h> |
#include <netinet/in.h> |
| 41 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
| 42 |
#include <sys/socket.h> |
#include <sys/socket.h> |
| 43 |
|
#include <sys/stat.h> |
| 44 |
#include <sys/types.h> |
#include <sys/types.h> |
| 45 |
#include <sys/wait.h> |
#include <sys/wait.h> |
| 46 |
|
|
| 423 |
log_error("Error setting SSH options: %s\n", ssh_get_error(SSH_session)); |
log_error("Error setting SSH options: %s\n", ssh_get_error(SSH_session)); |
| 424 |
goto cleanup; |
goto cleanup; |
| 425 |
} |
} |
| 426 |
|
|
| 427 |
|
ssh_set_blocking(SSH_session, 0); |
| 428 |
} |
} |
| 429 |
|
|
| 430 |
// Redirect Input |
// Redirect Input |
| 449 |
|
|
| 450 |
SYS_child_process_count = 0; |
SYS_child_process_count = 0; |
| 451 |
|
|
| 452 |
|
// BWF compile |
| 453 |
|
if (bwf_compile() < 0) |
| 454 |
|
{ |
| 455 |
|
log_error("bwf_compile() error\n"); |
| 456 |
|
goto cleanup; |
| 457 |
|
} |
| 458 |
|
|
| 459 |
bbs_main(); |
bbs_main(); |
| 460 |
|
|
| 461 |
cleanup: |
cleanup: |
| 492 |
ssh_free(SSH_session); |
ssh_free(SSH_session); |
| 493 |
ssh_finalize(); |
ssh_finalize(); |
| 494 |
|
|
| 495 |
|
// BWF cleanup |
| 496 |
|
bwf_cleanup(); |
| 497 |
|
|
| 498 |
// Close Input and Output for client |
// Close Input and Output for client |
| 499 |
io_cleanup(); |
io_cleanup(); |
| 500 |
close(STDIN_FILENO); |
close(STDIN_FILENO); |
| 510 |
|
|
| 511 |
int net_server(const char *hostaddr, in_port_t port[]) |
int net_server(const char *hostaddr, in_port_t port[]) |
| 512 |
{ |
{ |
| 513 |
|
struct stat file_stat; |
| 514 |
unsigned int addrlen; |
unsigned int addrlen; |
| 515 |
int ret; |
int ret; |
| 516 |
int flags_server[2]; |
int flags_server[2]; |
| 527 |
time_t tm_notify_child_exit = time(NULL); |
time_t tm_notify_child_exit = time(NULL); |
| 528 |
int i, j; |
int i, j; |
| 529 |
pid_t pid; |
pid_t pid; |
| 530 |
|
int ssh_key_valid = 0; |
| 531 |
int ssh_log_level = SSH_LOG_NOLOG; |
int ssh_log_level = SSH_LOG_NOLOG; |
| 532 |
|
|
| 533 |
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 538 |
|
|
| 539 |
sshbind = ssh_bind_new(); |
sshbind = ssh_bind_new(); |
| 540 |
|
|
| 541 |
|
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_RSA_KEY_FILE) < 0) |
| 542 |
|
{ |
| 543 |
|
log_error("Error loading SSH RSA key: %s\n", SSH_HOST_RSA_KEY_FILE); |
| 544 |
|
} |
| 545 |
|
else |
| 546 |
|
{ |
| 547 |
|
ssh_key_valid = 1; |
| 548 |
|
} |
| 549 |
|
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ED25519_KEY_FILE) < 0) |
| 550 |
|
{ |
| 551 |
|
log_error("Error loading SSH ED25519 key: %s\n", SSH_HOST_ED25519_KEY_FILE); |
| 552 |
|
} |
| 553 |
|
else |
| 554 |
|
{ |
| 555 |
|
ssh_key_valid = 1; |
| 556 |
|
} |
| 557 |
|
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ECDSA_KEY_FILE) < 0) |
| 558 |
|
{ |
| 559 |
|
log_error("Error loading SSH ECDSA key: %s\n", SSH_HOST_ECDSA_KEY_FILE); |
| 560 |
|
} |
| 561 |
|
else |
| 562 |
|
{ |
| 563 |
|
ssh_key_valid = 1; |
| 564 |
|
} |
| 565 |
|
|
| 566 |
|
if (!ssh_key_valid) |
| 567 |
|
{ |
| 568 |
|
log_error("Error: no valid SSH host key\n"); |
| 569 |
|
ssh_bind_free(sshbind); |
| 570 |
|
return -1; |
| 571 |
|
} |
| 572 |
|
|
| 573 |
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 || |
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 || |
| 574 |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 || |
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 || |
| 575 |
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") < 0 || |
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "ssh-rsa,rsa-sha2-512,rsa-sha2-256") < 0 || |
|
| 576 |
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) |
| 577 |
{ |
{ |
| 578 |
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)); |
| 650 |
fcntl(socket_server[i], F_SETFL, flags_server[i] | O_NONBLOCK); |
fcntl(socket_server[i], F_SETFL, flags_server[i] | O_NONBLOCK); |
| 651 |
} |
} |
| 652 |
|
|
| 653 |
|
ssh_bind_set_blocking(sshbind, 0); |
| 654 |
|
|
| 655 |
hash_dict_pid_sockaddr = hash_dict_create(MAX_CLIENT_LIMIT); |
hash_dict_pid_sockaddr = hash_dict_create(MAX_CLIENT_LIMIT); |
| 656 |
if (hash_dict_pid_sockaddr == NULL) |
if (hash_dict_pid_sockaddr == NULL) |
| 657 |
{ |
{ |
| 805 |
log_error("Reload BWF conf failed\n"); |
log_error("Reload BWF conf failed\n"); |
| 806 |
} |
} |
| 807 |
|
|
| 808 |
|
// Get EULA modification tm |
| 809 |
|
if (stat(DATA_EULA, &file_stat) == -1) |
| 810 |
|
{ |
| 811 |
|
log_error("stat(%s) error\n", DATA_EULA, errno); |
| 812 |
|
} |
| 813 |
|
else |
| 814 |
|
{ |
| 815 |
|
BBS_eula_tm = file_stat.st_mtim.tv_sec; |
| 816 |
|
} |
| 817 |
|
|
| 818 |
if (detach_menu_shm(&bbs_menu) < 0) |
if (detach_menu_shm(&bbs_menu) < 0) |
| 819 |
{ |
{ |
| 820 |
log_error("detach_menu_shm(bbs_menu) error\n"); |
log_error("detach_menu_shm(bbs_menu) error\n"); |