| 40 |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
| 41 |
#include <netinet/in.h> |
#include <netinet/in.h> |
| 42 |
#include <systemd/sd-daemon.h> |
#include <systemd/sd-daemon.h> |
| 43 |
|
#include <libssh/server.h> |
| 44 |
|
|
| 45 |
struct process_sockaddr_t |
struct process_sockaddr_t |
| 46 |
{ |
{ |
| 53 |
|
|
| 54 |
int net_server(const char *hostaddr, in_port_t port) |
int net_server(const char *hostaddr, in_port_t port) |
| 55 |
{ |
{ |
| 56 |
|
ssh_bind sshbind; |
| 57 |
unsigned int namelen; |
unsigned int namelen; |
| 58 |
int ret; |
int ret; |
| 59 |
int flags; |
int flags; |
| 65 |
MENU_SET *p_bbs_menu_new; |
MENU_SET *p_bbs_menu_new; |
| 66 |
int i, j; |
int i, j; |
| 67 |
pid_t pid; |
pid_t pid; |
| 68 |
|
int ssh_log_level = SSH_LOG_NOLOG; |
| 69 |
|
|
| 70 |
|
ssh_init(); |
| 71 |
|
|
| 72 |
|
sshbind = ssh_bind_new(); |
| 73 |
|
|
| 74 |
|
if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 || |
| 75 |
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 || |
| 76 |
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_KEYFILE) < 0 || |
| 77 |
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) |
| 78 |
|
{ |
| 79 |
|
log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind)); |
| 80 |
|
ssh_bind_free(sshbind); |
| 81 |
|
return -1; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 85 |
|
|
| 86 |
if (socket_server < 0) |
if (socket_server < 0) |
| 345 |
|
|
| 346 |
if (j < BBS_max_client_per_ip) |
if (j < BBS_max_client_per_ip) |
| 347 |
{ |
{ |
| 348 |
if ((pid = fork_server()) < 0) |
if ((pid = fork_server(sshbind)) < 0) |
| 349 |
{ |
{ |
| 350 |
log_error("fork_server() error\n"); |
log_error("fork_server() error\n"); |
| 351 |
} |
} |
| 398 |
log_error("Close server socket failed\n"); |
log_error("Close server socket failed\n"); |
| 399 |
} |
} |
| 400 |
|
|
| 401 |
|
ssh_bind_free(sshbind); |
| 402 |
|
ssh_finalize(); |
| 403 |
|
|
| 404 |
return 0; |
return 0; |
| 405 |
} |
} |