--- lbbs/src/test_ssh_server.c 2025/06/21 02:15:18 1.9 +++ lbbs/src/test_ssh_server.c 2025/11/04 14:58:56 1.13 @@ -1,18 +1,10 @@ -/*************************************************************************** - test_ssh_server.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * test_ssh_server + * - tester for network server with SSH support + * + * Copyright (C) 2004-2025 Leaflet + */ // This test was written based on libssh example/proxy.c @@ -87,7 +79,7 @@ struct ssh_channel_callbacks_struct chan .channel_pty_request_function = pty_request, .channel_shell_request_function = shell_request}; -static ssh_channel new_session_channel(ssh_session session, void *userdata) +static ssh_channel channel_open(ssh_session session, void *userdata) { (void)session; (void)userdata; @@ -112,7 +104,9 @@ int ssh_server(const char *hostaddr, uns struct ssh_server_callbacks_struct cb = { .userdata = NULL, .auth_password_function = auth_password, - .channel_open_request_session_function = new_session_channel}; + .channel_open_request_session_function = channel_open}; + + long int ssh_timeout = 0; char buf[BUF_SIZE]; char host[128] = ""; @@ -163,10 +157,19 @@ int ssh_server(const char *hostaddr, uns ssh_callbacks_init(&cb); ssh_set_server_callbacks(session, &cb); + ssh_timeout = 60; // second + if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) + { + log_error("Error setting SSH options: %s\n", ssh_get_error(session)); + ssh_disconnect(session); + _exit(1); + } + if (ssh_handle_key_exchange(session)) { log_error("ssh_handle_key_exchange: %s\n", ssh_get_error(session)); - return 1; + ssh_disconnect(session); + _exit(1); } ssh_set_auth_methods(session, SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_GSSAPI_MIC); @@ -196,6 +199,14 @@ int ssh_server(const char *hostaddr, uns log_common("Authenticated and got a channel\n"); } + ssh_timeout = 0; + if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) + { + log_error("Error setting SSH options: %s\n", ssh_get_error(session)); + ssh_disconnect(session); + _exit(1); + } + snprintf(buf, sizeof(buf), "Hello, welcome to the Sample SSH proxy.\r\nPlease select your destination: "); ssh_channel_write(SSH_channel, buf, (uint32_t)strlen(buf)); do