| 54 |
STATION_PER_LINE = 4, |
STATION_PER_LINE = 4, |
| 55 |
USERNAME_MAX_LEN = 20, |
USERNAME_MAX_LEN = 20, |
| 56 |
PASSWORD_MAX_LEN = 20, |
PASSWORD_MAX_LEN = 20, |
| 57 |
|
SSH_CONNECT_TIMEOUT = 5, // seconds |
| 58 |
}; |
}; |
| 59 |
|
|
| 60 |
struct _bbsnet_conf |
struct _bbsnet_conf |
| 62 |
char org_name[40]; |
char org_name[40]; |
| 63 |
char site_name[40]; |
char site_name[40]; |
| 64 |
char host_name[IP_ADDR_LEN]; |
char host_name[IP_ADDR_LEN]; |
| 65 |
in_port_t port; |
char port[6]; |
| 66 |
int8_t use_ssh; |
int8_t use_ssh; |
| 67 |
char charset[CHARSET_MAX_LEN + 1]; |
char charset[CHARSET_MAX_LEN + 1]; |
| 68 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 143 |
unload_bbsnet_conf(); |
unload_bbsnet_conf(); |
| 144 |
return -3; |
return -3; |
| 145 |
} |
} |
| 146 |
bbsnet_conf[menu_item_id].port = (in_port_t)port; |
strncpy(bbsnet_conf[menu_item_id].port, t4, sizeof(bbsnet_conf[menu_item_id].port) - 1); |
| 147 |
|
bbsnet_conf[menu_item_id].port[sizeof(bbsnet_conf[menu_item_id].port) - 1] = '\0'; |
| 148 |
bbsnet_conf[menu_item_id].use_ssh = (toupper(t5[0]) == 'Y'); |
bbsnet_conf[menu_item_id].use_ssh = (toupper(t5[0]) == 'Y'); |
| 149 |
strncpy(bbsnet_conf[menu_item_id].charset, t6, sizeof(bbsnet_conf[menu_item_id].charset) - 1); |
strncpy(bbsnet_conf[menu_item_id].charset, t6, sizeof(bbsnet_conf[menu_item_id].charset) - 1); |
| 150 |
bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0'; |
bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0'; |
| 274 |
int stdout_write_wait = 0; |
int stdout_write_wait = 0; |
| 275 |
int sock_read_wait = 0; |
int sock_read_wait = 0; |
| 276 |
int sock_write_wait = 0; |
int sock_write_wait = 0; |
| 277 |
struct hostent *p_host = NULL; |
struct addrinfo hints, *res = NULL; |
| 278 |
int tos; |
int tos; |
| 279 |
char remote_addr[IP_ADDR_LEN]; |
char remote_addr[INET_ADDRSTRLEN]; |
| 280 |
int remote_port; |
int remote_port; |
| 281 |
char local_addr[IP_ADDR_LEN]; |
char local_addr[INET_ADDRSTRLEN]; |
| 282 |
int local_port; |
int local_port; |
| 283 |
socklen_t sock_len; |
socklen_t sock_len; |
| 284 |
|
time_t t_begin; |
| 285 |
time_t t_used = time(NULL); |
time_t t_used = time(NULL); |
| 286 |
struct tm *tm_used; |
struct tm *tm_used; |
| 287 |
int ch; |
int ch; |
| 291 |
ssh_channel channel = NULL; |
ssh_channel channel = NULL; |
| 292 |
int ssh_process_config = 0; |
int ssh_process_config = 0; |
| 293 |
int ssh_log_level = SSH_LOG_NOLOG; |
int ssh_log_level = SSH_LOG_NOLOG; |
|
long ssh_timeout = 0; |
|
| 294 |
|
|
| 295 |
if (user_online_update("BBS_NET") < 0) |
if (user_online_update("BBS_NET") < 0) |
| 296 |
{ |
{ |
| 343 |
bbsnet_conf[n].site_name, bbsnet_conf[n].host_name); |
bbsnet_conf[n].site_name, bbsnet_conf[n].host_name); |
| 344 |
iflush(); |
iflush(); |
| 345 |
|
|
| 346 |
p_host = gethostbyname(bbsnet_conf[n].host_name); |
memset(&hints, 0, sizeof(hints)); |
| 347 |
|
hints.ai_family = AF_INET; |
| 348 |
|
hints.ai_socktype = SOCK_STREAM; |
| 349 |
|
hints.ai_protocol = IPPROTO_TCP; |
| 350 |
|
|
| 351 |
if (p_host == NULL) |
if ((ret = getaddrinfo(BBS_address, NULL, &hints, &res)) != 0) |
| 352 |
{ |
{ |
| 353 |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
log_error("getaddrinfo() error (%d)\n", ret); |
|
press_any_key(); |
|
| 354 |
goto cleanup; |
goto cleanup; |
| 355 |
} |
} |
| 356 |
|
|
| 357 |
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr), local_addr, sizeof(local_addr)) == NULL) |
| 358 |
|
{ |
| 359 |
|
log_error("inet_ntop() error (%d)\n", errno); |
| 360 |
|
goto cleanup; |
| 361 |
|
} |
| 362 |
|
local_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
| 363 |
|
|
| 364 |
|
sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
| 365 |
if (sock < 0) |
if (sock < 0) |
| 366 |
{ |
{ |
| 367 |
prints("\033[1;31m无法创建socket!\033[m\r\n"); |
log_error("socket() error (%d)\n", errno); |
|
press_any_key(); |
|
| 368 |
goto cleanup; |
goto cleanup; |
| 369 |
} |
} |
| 370 |
|
|
| 371 |
sin.sin_family = AF_INET; |
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) |
|
sin.sin_addr.s_addr = (BBS_address[0] != '\0' ? inet_addr(BBS_address) : INADDR_ANY); |
|
|
sin.sin_port = 0; |
|
|
|
|
|
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
|
| 372 |
{ |
{ |
| 373 |
log_error("Bind address %s:%u failed (%d)\n", |
log_error("bind(%s:%u) error (%d)\n", local_addr, local_port, errno); |
|
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno); |
|
| 374 |
goto cleanup; |
goto cleanup; |
| 375 |
} |
} |
| 376 |
|
|
| 377 |
memset(&sin, 0, sizeof(sin)); |
freeaddrinfo(res); |
| 378 |
sin.sin_family = AF_INET; |
res = NULL; |
|
sin.sin_addr = *(struct in_addr *)p_host->h_addr_list[0]; |
|
|
sin.sin_port = htons(bbsnet_conf[n].port); |
|
| 379 |
|
|
| 380 |
strncpy(remote_addr, inet_ntoa(sin.sin_addr), sizeof(remote_addr) - 1); |
memset(&hints, 0, sizeof(hints)); |
| 381 |
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
hints.ai_family = AF_INET; |
| 382 |
remote_port = ntohs(sin.sin_port); |
hints.ai_flags = AI_NUMERICSERV; |
| 383 |
|
hints.ai_socktype = SOCK_STREAM; |
| 384 |
|
hints.ai_protocol = IPPROTO_TCP; |
| 385 |
|
|
| 386 |
|
if ((ret = getaddrinfo(bbsnet_conf[n].host_name, bbsnet_conf[n].port, &hints, &res)) != 0) |
| 387 |
|
{ |
| 388 |
|
log_error("getaddrinfo() error (%d)\n", ret); |
| 389 |
|
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
| 390 |
|
press_any_key(); |
| 391 |
|
goto cleanup; |
| 392 |
|
} |
| 393 |
|
|
| 394 |
|
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr), remote_addr, sizeof(remote_addr)) == NULL) |
| 395 |
|
{ |
| 396 |
|
log_error("inet_ntop() error (%d)\n", errno); |
| 397 |
|
goto cleanup; |
| 398 |
|
} |
| 399 |
|
remote_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
| 400 |
|
|
| 401 |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
| 402 |
process_bar(0, MAX_PROCESS_BAR_LEN); |
process_bar(0, MAX_PROCESS_BAR_LEN); |
| 462 |
|
|
| 463 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 464 |
{ |
{ |
| 465 |
if ((ret = connect(sock, (struct sockaddr *)&sin, sizeof(sin))) < 0) |
if ((ret = connect(sock, res->ai_addr, res->ai_addrlen)) < 0) |
| 466 |
{ |
{ |
| 467 |
if (errno == EAGAIN || errno == EALREADY || errno == EINPROGRESS) |
if (errno == EAGAIN || errno == EALREADY || errno == EINPROGRESS) |
| 468 |
{ |
{ |
| 478 |
else |
else |
| 479 |
{ |
{ |
| 480 |
log_error("connect(socket) error (%d)\n", errno); |
log_error("connect(socket) error (%d)\n", errno); |
|
|
|
| 481 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 482 |
press_any_key(); |
press_any_key(); |
|
|
|
| 483 |
goto cleanup; |
goto cleanup; |
| 484 |
} |
} |
| 485 |
} |
} |
| 562 |
{ |
{ |
| 563 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 564 |
press_any_key(); |
press_any_key(); |
|
|
|
| 565 |
goto cleanup; |
goto cleanup; |
| 566 |
} |
} |
| 567 |
|
|
| 603 |
goto cleanup; |
goto cleanup; |
| 604 |
} |
} |
| 605 |
|
|
| 606 |
ssh_timeout = 5; // second |
ssh_set_blocking(session, 0); |
|
if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) |
|
|
{ |
|
|
log_error("Error setting SSH options: %s\n", ssh_get_error(session)); |
|
|
goto cleanup; |
|
|
} |
|
| 607 |
|
|
| 608 |
while (!SYS_server_exit) |
t_begin = time(NULL); |
| 609 |
|
ret = SSH_ERROR; |
| 610 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 611 |
{ |
{ |
| 612 |
ret = ssh_connect(session); |
ret = ssh_connect(session); |
| 613 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 614 |
{ |
{ |
| 615 |
break; |
break; |
| 616 |
} |
} |
| 617 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 618 |
|
{ |
| 619 |
|
// log_error("ssh_connect() error: SSH_AGAIN\n"); |
| 620 |
|
} |
| 621 |
|
else // if (ret == SSH_ERROR) |
| 622 |
{ |
{ |
| 623 |
log_error("ssh_connect() error\n"); |
log_error("ssh_connect() error: SSH_ERROR\n"); |
| 624 |
goto cleanup; |
goto cleanup; |
| 625 |
} |
} |
| 626 |
} |
} |
| 627 |
|
if (ret != SSH_OK) |
| 628 |
|
{ |
| 629 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 630 |
|
press_any_key(); |
| 631 |
|
goto cleanup; |
| 632 |
|
} |
| 633 |
|
|
| 634 |
ret = ssh_session_is_known_server(session); |
ret = ssh_session_is_known_server(session); |
| 635 |
switch (ret) |
switch (ret) |
| 639 |
if (ssh_session_update_known_hosts(session) != SSH_OK) |
if (ssh_session_update_known_hosts(session) != SSH_OK) |
| 640 |
{ |
{ |
| 641 |
log_error("ssh_session_update_known_hosts(%s) error\n", bbsnet_conf[n].host_name); |
log_error("ssh_session_update_known_hosts(%s) error\n", bbsnet_conf[n].host_name); |
| 642 |
prints("\033[1;31m无法添加服务器证书\033[m"); |
prints("\033[1;31m无法添加服务器证书\033[m\r\n"); |
| 643 |
press_any_key(); |
press_any_key(); |
| 644 |
goto cleanup; |
goto cleanup; |
| 645 |
} |
} |
| 649 |
case SSH_KNOWN_HOSTS_CHANGED: |
case SSH_KNOWN_HOSTS_CHANGED: |
| 650 |
case SSH_KNOWN_HOSTS_OTHER: |
case SSH_KNOWN_HOSTS_OTHER: |
| 651 |
log_error("ssh_session_is_known_server(%s) error: %d\n", bbsnet_conf[n].host_name, ret); |
log_error("ssh_session_is_known_server(%s) error: %d\n", bbsnet_conf[n].host_name, ret); |
| 652 |
prints("\033[1;31m服务器证书已变更\033[m"); |
prints("\033[1;31m服务器证书已变更\033[m\r\n"); |
| 653 |
press_any_key(); |
press_any_key(); |
| 654 |
goto cleanup; |
goto cleanup; |
| 655 |
} |
} |
| 656 |
|
|
| 657 |
for (int i = 0; !SYS_server_exit;) |
ret = SSH_AUTH_ERROR; |
| 658 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 659 |
{ |
{ |
| 660 |
ret = ssh_userauth_password(session, NULL, remote_pass); |
ret = ssh_userauth_password(session, NULL, remote_pass); |
| 661 |
if (ret == SSH_AUTH_SUCCESS) |
if (ret == SSH_AUTH_SUCCESS) |
| 664 |
} |
} |
| 665 |
else if (ret == SSH_AUTH_AGAIN) |
else if (ret == SSH_AUTH_AGAIN) |
| 666 |
{ |
{ |
| 667 |
#ifdef _DEBUG |
// log_error("ssh_userauth_password() error: SSH_AUTH_AGAIN\n"); |
|
log_error("ssh_userauth_password() error: SSH_AUTH_AGAIN\n"); |
|
|
#endif |
|
| 668 |
} |
} |
| 669 |
else if (ret == SSH_AUTH_ERROR) |
else if (ret == SSH_AUTH_ERROR) |
| 670 |
{ |
{ |
| 671 |
log_error("ssh_userauth_password() error: %d\n", ret); |
log_error("ssh_userauth_password() error: SSH_AUTH_ERROR\n"); |
| 672 |
goto cleanup; |
goto cleanup; |
| 673 |
} |
} |
| 674 |
else // if (ret == SSH_AUTH_DENIED) |
else // if (ret == SSH_AUTH_DENIED) |
| 675 |
{ |
{ |
| 676 |
|
log_error("ssh_userauth_password() error: SSH_AUTH_DENIED\n"); |
| 677 |
prints("\033[1;31m身份验证失败!\033[m\r\n"); |
prints("\033[1;31m身份验证失败!\033[m\r\n"); |
| 678 |
i++; |
press_any_key(); |
| 679 |
if (i < BBS_login_retry_times) |
goto cleanup; |
|
{ |
|
|
prints("请输入密码: "); |
|
|
iflush(); |
|
|
if (str_input(remote_pass, sizeof(remote_pass), NOECHO) < 0) |
|
|
{ |
|
|
goto cleanup; |
|
|
} |
|
|
if (remote_pass[0] == '\0') |
|
|
{ |
|
|
goto cleanup; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
goto cleanup; |
|
|
} |
|
| 680 |
} |
} |
| 681 |
} |
} |
| 682 |
|
if (ret != SSH_AUTH_SUCCESS) |
| 683 |
|
{ |
| 684 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 685 |
|
press_any_key(); |
| 686 |
|
goto cleanup; |
| 687 |
|
} |
| 688 |
|
|
| 689 |
channel = ssh_channel_new(session); |
channel = ssh_channel_new(session); |
| 690 |
if (channel == NULL) |
if (channel == NULL) |
| 693 |
goto cleanup; |
goto cleanup; |
| 694 |
} |
} |
| 695 |
|
|
| 696 |
while (!SYS_server_exit) |
ret = SSH_ERROR; |
| 697 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 698 |
{ |
{ |
| 699 |
ret = ssh_channel_open_session(channel); |
ret = ssh_channel_open_session(channel); |
| 700 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 701 |
{ |
{ |
| 702 |
break; |
break; |
| 703 |
} |
} |
| 704 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 705 |
|
{ |
| 706 |
|
// log_error("ssh_channel_open_session() error: SSH_AGAIN\n"); |
| 707 |
|
} |
| 708 |
|
else // if (ret == SSH_ERROR) |
| 709 |
{ |
{ |
| 710 |
log_error("ssh_channel_open_session() error\n"); |
log_error("ssh_channel_open_session() error: SSH_ERROR\n"); |
| 711 |
goto cleanup; |
goto cleanup; |
| 712 |
} |
} |
| 713 |
} |
} |
| 714 |
|
if (ret != SSH_OK) |
| 715 |
|
{ |
| 716 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 717 |
|
press_any_key(); |
| 718 |
|
goto cleanup; |
| 719 |
|
} |
| 720 |
|
|
| 721 |
while (!SYS_server_exit) |
ret = SSH_ERROR; |
| 722 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 723 |
{ |
{ |
| 724 |
ret = ssh_channel_request_pty(channel); |
ret = ssh_channel_request_pty(channel); |
| 725 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 726 |
{ |
{ |
| 727 |
break; |
break; |
| 728 |
} |
} |
| 729 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 730 |
|
{ |
| 731 |
|
// log_error("ssh_channel_request_pty() error: SSH_AGAIN\n"); |
| 732 |
|
} |
| 733 |
|
else // if (ret == SSH_ERROR) |
| 734 |
{ |
{ |
| 735 |
log_error("ssh_channel_request_pty() error\n"); |
log_error("ssh_channel_request_pty() error: SSH_ERROR\n"); |
| 736 |
goto cleanup; |
goto cleanup; |
| 737 |
} |
} |
| 738 |
} |
} |
| 739 |
|
if (ret != SSH_OK) |
| 740 |
|
{ |
| 741 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 742 |
|
press_any_key(); |
| 743 |
|
goto cleanup; |
| 744 |
|
} |
| 745 |
|
|
| 746 |
while (!SYS_server_exit) |
ret = SSH_ERROR; |
| 747 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 748 |
{ |
{ |
| 749 |
ret = ssh_channel_request_shell(channel); |
ret = ssh_channel_request_shell(channel); |
| 750 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 751 |
{ |
{ |
| 752 |
break; |
break; |
| 753 |
} |
} |
| 754 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 755 |
|
{ |
| 756 |
|
// log_error("ssh_channel_request_shell() error: SSH_AGAIN\n"); |
| 757 |
|
} |
| 758 |
|
else // if (ret == SSH_ERROR) |
| 759 |
{ |
{ |
| 760 |
log_error("ssh_channel_request_shell() error\n"); |
log_error("ssh_channel_request_shell() error: SSH_ERROR\n"); |
| 761 |
goto cleanup; |
goto cleanup; |
| 762 |
} |
} |
| 763 |
} |
} |
| 764 |
|
if (ret != SSH_OK) |
|
ssh_timeout = 0; // second |
|
|
if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) |
|
| 765 |
{ |
{ |
| 766 |
log_error("Error setting SSH options: %s\n", ssh_get_error(session)); |
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 767 |
|
press_any_key(); |
| 768 |
goto cleanup; |
goto cleanup; |
| 769 |
} |
} |
|
|
|
|
ssh_set_blocking(session, 0); |
|
| 770 |
} |
} |
| 771 |
|
|
| 772 |
prints("\033[1;31m连接成功!\033[m\r\n"); |
prints("\033[1;31m连接成功!\033[m\r\n"); |
| 817 |
{ |
{ |
| 818 |
if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) |
if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) |
| 819 |
{ |
{ |
| 820 |
|
#ifdef _DEBUG |
| 821 |
log_error("SSH channel is closed\n"); |
log_error("SSH channel is closed\n"); |
| 822 |
|
#endif |
| 823 |
loop = 0; |
loop = 0; |
| 824 |
break; |
break; |
| 825 |
} |
} |
| 826 |
|
|
| 827 |
if (bbsnet_conf[n].use_ssh && ssh_channel_is_closed(channel)) |
if (bbsnet_conf[n].use_ssh && ssh_channel_is_closed(channel)) |
| 828 |
{ |
{ |
| 829 |
|
#ifdef _DEBUG |
| 830 |
log_error("Remote SSH channel is closed\n"); |
log_error("Remote SSH channel is closed\n"); |
| 831 |
|
#endif |
| 832 |
loop = 0; |
loop = 0; |
| 833 |
break; |
break; |
| 834 |
} |
} |
| 923 |
ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0); |
ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0); |
| 924 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 925 |
{ |
{ |
| 926 |
|
#ifdef _DEBUG |
| 927 |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); |
| 928 |
|
#endif |
| 929 |
loop = 0; |
loop = 0; |
| 930 |
break; |
break; |
| 931 |
} |
} |
| 1028 |
ret = ssh_channel_write(channel, input_conv + input_conv_offset, (uint32_t)(input_conv_len - input_conv_offset)); |
ret = ssh_channel_write(channel, input_conv + input_conv_offset, (uint32_t)(input_conv_len - input_conv_offset)); |
| 1029 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1030 |
{ |
{ |
| 1031 |
|
#ifdef _DEBUG |
| 1032 |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(session)); |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(session)); |
| 1033 |
|
#endif |
| 1034 |
loop = 0; |
loop = 0; |
| 1035 |
break; |
break; |
| 1036 |
} |
} |
| 1052 |
} |
} |
| 1053 |
else |
else |
| 1054 |
{ |
{ |
| 1055 |
|
#ifdef _DEBUG |
| 1056 |
log_error("write(socket) error (%d)\n", errno); |
log_error("write(socket) error (%d)\n", errno); |
| 1057 |
|
#endif |
| 1058 |
loop = 0; |
loop = 0; |
| 1059 |
break; |
break; |
| 1060 |
} |
} |
| 1092 |
(uint32_t)(sizeof(output_buf) - (size_t)output_buf_len), 0); |
(uint32_t)(sizeof(output_buf) - (size_t)output_buf_len), 0); |
| 1093 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1094 |
{ |
{ |
| 1095 |
|
#ifdef _DEBUG |
| 1096 |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(session)); |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(session)); |
| 1097 |
|
#endif |
| 1098 |
loop = 0; |
loop = 0; |
| 1099 |
break; |
break; |
| 1100 |
} |
} |
| 1127 |
} |
} |
| 1128 |
else |
else |
| 1129 |
{ |
{ |
| 1130 |
|
#ifdef _DEBUG |
| 1131 |
log_error("read(socket) error (%d)\n", errno); |
log_error("read(socket) error (%d)\n", errno); |
| 1132 |
|
#endif |
| 1133 |
loop = 0; |
loop = 0; |
| 1134 |
break; |
break; |
| 1135 |
} |
} |
| 1170 |
ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset)); |
ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset)); |
| 1171 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1172 |
{ |
{ |
| 1173 |
|
#ifdef _DEBUG |
| 1174 |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
| 1175 |
|
#endif |
| 1176 |
loop = 0; |
loop = 0; |
| 1177 |
break; |
break; |
| 1178 |
} |
} |
| 1194 |
} |
} |
| 1195 |
else |
else |
| 1196 |
{ |
{ |
| 1197 |
|
#ifdef _DEBUG |
| 1198 |
log_error("write(STDOUT) error (%d)\n", errno); |
log_error("write(STDOUT) error (%d)\n", errno); |
| 1199 |
|
#endif |
| 1200 |
loop = 0; |
loop = 0; |
| 1201 |
break; |
break; |
| 1202 |
} |
} |
| 1256 |
} |
} |
| 1257 |
|
|
| 1258 |
// Restore STDIN/STDOUT flags |
// Restore STDIN/STDOUT flags |
| 1259 |
if (flags_stdin != -1 &&fcntl(STDIN_FILENO, F_SETFL, flags_stdin) == -1) |
if (flags_stdin != -1 && fcntl(STDIN_FILENO, F_SETFL, flags_stdin) == -1) |
| 1260 |
{ |
{ |
| 1261 |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 1262 |
} |
} |
| 1270 |
log_error("Close socket failed\n"); |
log_error("Close socket failed\n"); |
| 1271 |
} |
} |
| 1272 |
|
|
| 1273 |
|
if (res) |
| 1274 |
|
{ |
| 1275 |
|
freeaddrinfo(res); |
| 1276 |
|
} |
| 1277 |
|
|
| 1278 |
t_used = time(NULL) - t_used; |
t_used = time(NULL) - t_used; |
| 1279 |
tm_used = gmtime(&t_used); |
tm_used = gmtime(&t_used); |
| 1280 |
|
|
| 1281 |
log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
| 1282 |
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
tm_used->tm_yday, tm_used->tm_hour, tm_used->tm_min, tm_used->tm_sec); |
|
tm_used->tm_sec); |
|
| 1283 |
|
|
| 1284 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 1285 |
|
|
| 1325 |
prints("|"); |
prints("|"); |
| 1326 |
moveto(21, 1); |
moveto(21, 1); |
| 1327 |
clrtoeol(); |
clrtoeol(); |
| 1328 |
prints("|\033[1m连往: \033[1;33m%-20s\033[m 端口: \033[1;33m%-5d\033[m 编码: \033[1;33m%s\033[m", |
prints("|\033[1m连往: \033[1;33m%-20s\033[m 端口: \033[1;33m%-5s\033[m 编码: \033[1;33m%s\033[m", |
| 1329 |
bbsnet_conf[i].host_name, bbsnet_conf[i].port, bbsnet_conf[i].charset); |
bbsnet_conf[i].host_name, bbsnet_conf[i].port, bbsnet_conf[i].charset); |
| 1330 |
moveto(21, 80); |
moveto(21, 80); |
| 1331 |
prints("|"); |
prints("|"); |
| 1363 |
switch (ch) |
switch (ch) |
| 1364 |
{ |
{ |
| 1365 |
case KEY_NULL: // broken pipe |
case KEY_NULL: // broken pipe |
| 1366 |
|
#ifdef _DEBUG |
| 1367 |
log_error("KEY_NULL\n"); |
log_error("KEY_NULL\n"); |
| 1368 |
|
#endif |
| 1369 |
goto cleanup; |
goto cleanup; |
| 1370 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 1371 |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |