diff --git a/tests/server/test_server/CMakeLists.txt b/tests/server/test_server/CMakeLists.txt index 7e0f88c1..9b46641b 100644 --- a/tests/server/test_server/CMakeLists.txt +++ b/tests/server/test_server/CMakeLists.txt @@ -11,7 +11,8 @@ set(server_SRCS add_library(testserver STATIC test_server.c default_cb.c - sftpserver_cb.c) + sftpserver_cb.c + testserver_common.c) if (WITH_COVERAGE) append_coverage_compiler_flags_to_target(testserver) endif (WITH_COVERAGE) @@ -32,7 +33,7 @@ if (UNIX AND NOT WIN32) add_executable(test_server ${server_SRCS}) target_compile_options(test_server PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) target_link_libraries(test_server - PRIVATE testserver ssh::ssh ${ARGP_LIBRARIES} util) + PRIVATE testserver ${TORTURE_LINK_LIBRARIES} ${ARGP_LIBRARIES} util) if (WITH_COVERAGE) append_coverage_compiler_flags_to_target(test_server) endif (WITH_COVERAGE) diff --git a/tests/server/test_server/default_cb.c b/tests/server/test_server/default_cb.c index db6b71c3..a6df448c 100644 --- a/tests/server/test_server/default_cb.c +++ b/tests/server/test_server/default_cb.c @@ -21,9 +21,11 @@ * MA 02111-1307, USA. */ + #include "config.h" #include "test_server.h" #include "default_cb.h" +#include "testserver_common.h" #include #include @@ -448,9 +450,11 @@ static int exec_pty(const char *mode, case 0: close(cdata->pty_master); if (login_tty(cdata->pty_slave) != 0) { + finalize_openssl(); exit(1); } execl("/bin/sh", "sh", mode, command, NULL); + finalize_openssl(); exit(0); default: close(cdata->pty_slave); @@ -500,6 +504,7 @@ static int exec_nopty(const char *command, struct channel_data_st *cdata) close(err[1]); /* exec the requested command. */ execl("/bin/sh", "sh", "-c", command, NULL); + finalize_openssl(); exit(0); } diff --git a/tests/server/test_server/test_server.c b/tests/server/test_server/test_server.c index a75f6f8b..295af3ed 100644 --- a/tests/server/test_server/test_server.c +++ b/tests/server/test_server/test_server.c @@ -22,6 +22,7 @@ */ #include "test_server.h" +#include "testserver_common.h" #include #include @@ -288,6 +289,7 @@ int run_server(struct server_state_st *state) free_server_state(state); SAFE_FREE(state); + finalize_openssl(); exit(0); case -1: fprintf(stderr, "Failed to fork\n"); @@ -355,11 +357,8 @@ fork_run_server(struct server_state_st *state, /* The child process starts a server which will listen for connections */ rc = run_server(state); - if (rc != 0) { - exit(rc); - } - - exit(0); + finalize_openssl(); + exit(rc); case -1: strerror_r(errno, err_str, 1024); fprintf(stderr, "Failed to fork: %s\n", diff --git a/tests/server/test_server/testserver_common.c b/tests/server/test_server/testserver_common.c new file mode 100644 index 00000000..c0970738 --- /dev/null +++ b/tests/server/test_server/testserver_common.c @@ -0,0 +1,36 @@ +/* + * This file is part of the SSH Library + * + * Copyright (c) 2025 by Red Hat, Inc. + * + * Author: Jakub Jelen + * + * The SSH Library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * The SSH Library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the SSH Library; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#include "testserver_common.h" + +#if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI) +/* for OPENSSL_cleanup() of GSSAPI's OpenSSL context */ +#include +#endif + +void finalize_openssl(void) +{ +#if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI) + OPENSSL_cleanup(); +#endif +} diff --git a/tests/server/test_server/testserver_common.h b/tests/server/test_server/testserver_common.h new file mode 100644 index 00000000..01a9c57f --- /dev/null +++ b/tests/server/test_server/testserver_common.h @@ -0,0 +1,26 @@ +/* + * This file is part of the SSH Library + * + * Copyright (c) 2025 by Red Hat, Inc. + * + * Author: Jakub Jelen + * + * The SSH Library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * The SSH Library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the SSH Library; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#include "config.h" + +void finalize_openssl(void);