| 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_loader.h" |
#include "section_list_loader.h" |
| 29 |
#include <errno.h> |
#include <errno.h> |
| 30 |
#include <fcntl.h> |
#include <fcntl.h> |
|
#include <string.h> |
|
| 31 |
#include <signal.h> |
#include <signal.h> |
| 32 |
#include <stdlib.h> |
#include <stdlib.h> |
| 33 |
|
#include <string.h> |
| 34 |
#include <unistd.h> |
#include <unistd.h> |
|
#include <sys/syscall.h> |
|
|
#include <sys/socket.h> |
|
|
#include <sys/wait.h> |
|
|
#include <sys/epoll.h> |
|
| 35 |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
| 36 |
#include <netinet/in.h> |
#include <libssh/callbacks.h> |
|
#include <systemd/sd-daemon.h> |
|
| 37 |
#include <libssh/libssh.h> |
#include <libssh/libssh.h> |
| 38 |
#include <libssh/server.h> |
#include <libssh/server.h> |
| 39 |
#include <libssh/callbacks.h> |
#include <netinet/in.h> |
| 40 |
|
#include <sys/epoll.h> |
| 41 |
|
#include <sys/socket.h> |
| 42 |
|
#include <sys/syscall.h> |
| 43 |
|
#include <sys/types.h> |
| 44 |
|
#include <sys/wait.h> |
| 45 |
|
#include <systemd/sd-daemon.h> |
| 46 |
|
|
| 47 |
struct process_sockaddr_t |
struct process_sockaddr_t |
| 48 |
{ |
{ |
| 53 |
|
|
| 54 |
static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT]; |
static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT]; |
| 55 |
|
|
| 56 |
#define SSH_AUTH_MAX_DURATION 60 // seconds |
#define SSH_AUTH_MAX_DURATION (60 * 1000) // milliseconds |
| 57 |
|
|
| 58 |
struct ssl_server_cb_data_t |
struct ssl_server_cb_data_t |
| 59 |
{ |
{ |
| 64 |
static int auth_password(ssh_session session, const char *user, |
static int auth_password(ssh_session session, const char *user, |
| 65 |
const char *password, void *userdata) |
const char *password, void *userdata) |
| 66 |
{ |
{ |
|
MYSQL *db; |
|
| 67 |
struct ssl_server_cb_data_t *p_data = userdata; |
struct ssl_server_cb_data_t *p_data = userdata; |
| 68 |
int ret; |
int ret; |
| 69 |
|
|
|
if ((db = db_open()) == NULL) |
|
|
{ |
|
|
return SSH_AUTH_ERROR; |
|
|
} |
|
|
|
|
| 70 |
if (strcmp(user, "guest") == 0) |
if (strcmp(user, "guest") == 0) |
| 71 |
{ |
{ |
| 72 |
ret = load_guest_info(db); |
ret = load_guest_info(); |
| 73 |
} |
} |
| 74 |
else |
else |
| 75 |
{ |
{ |
| 76 |
ret = check_user(db, user, password); |
ret = check_user(user, password); |
| 77 |
} |
} |
| 78 |
|
|
|
mysql_close(db); |
|
|
|
|
| 79 |
if (ret == 0) |
if (ret == 0) |
| 80 |
{ |
{ |
| 81 |
return SSH_AUTH_SUCCESS; |
return SSH_AUTH_SUCCESS; |
| 182 |
event = ssh_event_new(); |
event = ssh_event_new(); |
| 183 |
ssh_event_add_session(event, SSH_session); |
ssh_event_add_session(event, SSH_session); |
| 184 |
|
|
| 185 |
for (i = 0; i < SSH_AUTH_MAX_DURATION && !SYS_server_exit && !cb_data.error && SSH_channel == NULL; i++) |
for (i = 0; i < SSH_AUTH_MAX_DURATION && !SYS_server_exit && !cb_data.error && SSH_channel == NULL; i += 100) |
| 186 |
{ |
{ |
| 187 |
ret = ssh_event_dopoll(event, 1000); // 1 second |
ret = ssh_event_dopoll(event, 100); // 0.1 second |
| 188 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 189 |
{ |
{ |
| 190 |
log_error("ssh_event_dopoll() error: %s\n", ssh_get_error(SSH_session)); |
log_error("ssh_event_dopoll() error: %s\n", ssh_get_error(SSH_session)); |