aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml22
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/Modules/FindABIMap.cmake26
-rw-r--r--doc/forwarding.dox2
-rw-r--r--include/libssh/packet.h2
-rw-r--r--src/channels.c3
-rw-r--r--src/connect.c3
-rw-r--r--src/external/ed25519.c8
-rw-r--r--src/libmbedcrypto.c4
-rw-r--r--src/sftp.c119
-rw-r--r--src/threads/winlocks.c1
-rw-r--r--tests/client/CMakeLists.txt1
-rw-r--r--tests/client/torture_sftp_init.c106
-rw-r--r--tests/torture.c31
-rw-r--r--tests/torture.h1
15 files changed, 256 insertions, 77 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1a887203..fd865981 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -27,7 +27,7 @@ stages:
- free -h
- mkdir -p obj && cd obj
script:
- - cmake $CMAKE_OPTIONS $CMAKE_ADDTIONAL_OPTIONS .. &&
+ - cmake $CMAKE_OPTIONS $CMAKE_ADDITIONAL_OPTIONS .. &&
make -j$(nproc) &&
make -j$(nproc) install
# Do not use after_script as it does not make the targets fail
@@ -47,7 +47,7 @@ stages:
# This is needed to prevent passing artifacts from previous stages
dependencies: []
script:
- - cmake $CMAKE_OPTIONS $CMAKE_ADDTIONAL_OPTIONS .. &&
+ - cmake $CMAKE_OPTIONS $CMAKE_ADDITIONAL_OPTIONS .. &&
make -j$(nproc) &&
ctest --output-on-failure
# Do not use after_script as it does not make the targets fail
@@ -56,7 +56,7 @@ stages:
extends: .tests
image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
variables:
- CMAKE_ADDTIONAL_OPTIONS: -DWITH_PKCS11_URI=ON
+ CMAKE_ADDITIONAL_OPTIONS: -DWITH_PKCS11_URI=ON
.tumbleweed:
extends: .tests
@@ -90,6 +90,12 @@ fedora/docs:
script:
- cmake .. && make docs
+fedora/ninja:
+ extends: .fedora
+ image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
+ script:
+ - cmake -G Ninja $CMAKE_OPTIONS ../ && ninja && ninja test
+
fedora/openssl_1.1.x/x86_64:
extends: .fedora
@@ -184,12 +190,12 @@ fedora/undefined-sanitizer:
fedora/libgcrypt/x86_64:
extends: .fedora
variables:
- CMAKE_ADDTIONAL_OPTIONS: "-DWITH_GCRYPT=ON -DWITH_DEBUG_CRYPTO=ON"
+ CMAKE_ADDITIONAL_OPTIONS: "-DWITH_GCRYPT=ON -DWITH_DEBUG_CRYPTO=ON"
fedora/mbedtls/x86_64:
extends: .fedora
variables:
- CMAKE_ADDTIONAL_OPTIONS: "-DWITH_MBEDTLS=ON -DWITH_DEBUG_CRYPTO=ON -DWITH_DSA=OFF"
+ CMAKE_ADDITIONAL_OPTIONS: "-DWITH_MBEDTLS=ON -DWITH_DEBUG_CRYPTO=ON -DWITH_DSA=OFF"
# Unit testing only, no client and pkd testing, because cwrap is not available
# for MinGW
@@ -304,7 +310,7 @@ ubuntu/openssl_1.1.x/x86_64:
tumbleweed/openssl_1.1.x/x86_64/gcc:
extends: .tumbleweed
variables:
- CMAKE_ADDTIONAL_OPTIONS: "-DKRB5_CONFIG=/usr/lib/mit/bin/krb5-config"
+ CMAKE_ADDITIONAL_OPTIONS: "-DKRB5_CONFIG=/usr/lib/mit/bin/krb5-config"
tumbleweed/openssl_1.1.x/x86/gcc:
extends: .tumbleweed
@@ -322,7 +328,7 @@ tumbleweed/openssl_1.1.x/x86/gcc:
tumbleweed/openssl_1.1.x/x86_64/gcc7:
extends: .tumbleweed
variables:
- CMAKE_ADDTIONAL_OPTIONS: "-DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 -DKRB5_CONFIG=/usr/lib/mit/bin/krb5-config"
+ CMAKE_ADDITIONAL_OPTIONS: "-DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 -DKRB5_CONFIG=/usr/lib/mit/bin/krb5-config"
tumbleweed/openssl_1.1.x/x86/gcc7:
extends: .tumbleweed
@@ -339,7 +345,7 @@ tumbleweed/openssl_1.1.x/x86/gcc7:
tumbleweed/openssl_1.1.x/x86_64/clang:
extends: .tumbleweed
variables:
- CMAKE_ADDTIONAL_OPTIONS: "-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DKRB5_CONFIG=/usr/lib/mit/bin/krb5-config"
+ CMAKE_ADDITIONAL_OPTIONS: "-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DKRB5_CONFIG=/usr/lib/mit/bin/krb5-config"
tumbleweed/static-analysis:
extends: .tests
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b8b4b0bc..1f1925ef 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -216,10 +216,10 @@ if (WITH_SYMBOL_VERSIONING AND ABIMAP_FOUND)
endif(UPDATE_ABI)
endif (WITH_SYMBOL_VERSIONING AND ABIMAP_FOUND)
-add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source DEPENDS ${_SYMBOL_TARGET})
+add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source DEPENDS ${_SYMBOL_TARGET} VERBATIM)
# Link compile database for clangd
-execute_process(COMMAND cmake -E create_symlink
+execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
"${CMAKE_BINARY_DIR}/compile_commands.json"
"${CMAKE_SOURCE_DIR}/compile_commands.json")
diff --git a/cmake/Modules/FindABIMap.cmake b/cmake/Modules/FindABIMap.cmake
index e0520abd..5117b498 100644
--- a/cmake/Modules/FindABIMap.cmake
+++ b/cmake/Modules/FindABIMap.cmake
@@ -302,12 +302,13 @@ function(get_file_list _TARGET_NAME)
add_custom_target(
${_TARGET_NAME}_int ALL
COMMAND ${CMAKE_COMMAND}
- -DOUTPUT_PATH="${_get_files_list_OUTPUT_PATH}"
- -DDIRECTORIES="${_get_files_list_DIRECTORIES}"
- -DFILES_PATTERNS="${_get_files_list_FILES_PATTERNS}"
+ -DOUTPUT_PATH=${_get_files_list_OUTPUT_PATH}
+ -DDIRECTORIES=${_get_files_list_DIRECTORIES}
+ -DFILES_PATTERNS=${_get_files_list_FILES_PATTERNS}
-P ${_GET_FILES_LIST_SCRIPT}
COMMENT
"Searching for files"
+ VERBATIM
)
if (DEFINED _get_files_list_COPY_TO)
@@ -318,6 +319,7 @@ function(get_file_list _TARGET_NAME)
${_FILES_LIST_OUTPUT_PATH} ${_get_files_list_COPY_TO}
DEPENDS ${_TARGET_NAME}_int
COMMENT "Copying ${_TARGET_NAME} to ${_get_files_list_COPY_TO}"
+ VERBATIM
)
else()
add_custom_target(${_TARGET_NAME} ALL
@@ -369,12 +371,13 @@ function(extract_symbols _TARGET_NAME)
add_custom_target(
${_TARGET_NAME}_int ALL
COMMAND ${CMAKE_COMMAND}
- -DOUTPUT_PATH="${_SYMBOLS_OUTPUT_PATH}"
- -DHEADERS_LIST_FILE="${_HEADERS_LIST_FILE}"
+ -DOUTPUT_PATH=${_SYMBOLS_OUTPUT_PATH}
+ -DHEADERS_LIST_FILE=${_HEADERS_LIST_FILE}
-DFILTER_PATTERN=${_extract_symbols_FILTER_PATTERN}
-P ${_EXTRACT_SYMBOLS_SCRIPT}
DEPENDS ${_extract_symbols_HEADERS_LIST}
COMMENT "Extracting symbols from headers"
+ VERBATIM
)
if (DEFINED _extract_symbols_COPY_TO)
@@ -385,6 +388,7 @@ function(extract_symbols _TARGET_NAME)
${_SYMBOLS_OUTPUT_PATH} ${_extract_symbols_COPY_TO}
DEPENDS ${_TARGET_NAME}_int
COMMENT "Copying ${_TARGET_NAME} to ${_extract_symbols_COPY_TO}"
+ VERBATIM
)
else()
add_custom_target(${_TARGET_NAME} ALL
@@ -449,35 +453,37 @@ function(generate_map_file _TARGET_NAME)
${_TARGET_NAME}_int ALL
COMMAND ${CMAKE_COMMAND}
-DABIMAP_EXECUTABLE=${ABIMAP_EXECUTABLE}
- -DSYMBOLS="${_SYMBOLS_FILE}"
+ -DSYMBOLS=${_SYMBOLS_FILE}
-DCURRENT_MAP=${_generate_map_file_CURRENT_MAP}
- -DOUTPUT_PATH="${_MAP_OUTPUT_PATH}"
+ -DOUTPUT_PATH=${_MAP_OUTPUT_PATH}
-DFINAL=${_generate_map_file_FINAL}
-DBREAK_ABI=${_generate_map_file_BREAK_ABI}
-DRELEASE_NAME_VERSION=${_generate_map_file_RELEASE_NAME_VERSION}
-P ${_GENERATE_MAP_SCRIPT}
DEPENDS ${_generate_map_file_SYMBOLS}
COMMENT "Generating the map ${_TARGET_NAME}"
+ VERBATIM
)
# Add a custom command setting the map as OUTPUT to allow it to be added as
# a generated source
add_custom_command(
OUTPUT ${_MAP_OUTPUT_PATH}
- DEPENDS ${_TARGET_NAME}
+ DEPENDS ${_TARGET_NAME}_copy
)
if (DEFINED _generate_map_file_COPY_TO)
# Copy the generated map back to the COPY_TO
- add_custom_target(${_TARGET_NAME} ALL
+ add_custom_target(${_TARGET_NAME}_copy ALL
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${_MAP_OUTPUT_PATH}
${_generate_map_file_COPY_TO}
DEPENDS ${_TARGET_NAME}_int
COMMENT "Copying ${_MAP_OUTPUT_PATH} to ${_generate_map_file_COPY_TO}"
+ VERBATIM
)
else()
- add_custom_target(${_TARGET_NAME} ALL
+ add_custom_target(${_TARGET_NAME}_copy ALL
DEPENDS ${_TARGET_NAME}_int
)
endif()
diff --git a/doc/forwarding.dox b/doc/forwarding.dox
index bb93c7b1..ca3b94f8 100644
--- a/doc/forwarding.dox
+++ b/doc/forwarding.dox
@@ -101,7 +101,7 @@ used to retrieve google's home page from the remote SSH server.
int direct_forwarding(ssh_session session)
{
ssh_channel forwarding_channel;
- int rc;
+ int rc = SSH_ERROR;
char *http_get = "GET / HTTP/1.1\nHost: www.google.com\n\n";
int nbytes, nwritten;
diff --git a/include/libssh/packet.h b/include/libssh/packet.h
index 8fc7ce42..561bba8e 100644
--- a/include/libssh/packet.h
+++ b/include/libssh/packet.h
@@ -80,7 +80,7 @@ int ssh_packet_decrypt(ssh_session session, uint8_t *destination, uint8_t *sourc
size_t start, size_t encrypted_size);
unsigned char *ssh_packet_encrypt(ssh_session session,
void *packet,
- unsigned int len);
+ uint32_t len);
int ssh_packet_hmac_verify(ssh_session session, const void *data, size_t len,
unsigned char *mac, enum ssh_hmac_e type);
int ssh_packet_set_newkeys(ssh_session session,
diff --git a/src/channels.c b/src/channels.c
index 11a9413a..b3a0d494 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -29,6 +29,9 @@
#include <errno.h>
#include <time.h>
#include <stdbool.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif /* HAVE_SYS_TIME_H */
#ifndef _WIN32
#include <netinet/in.h>
diff --git a/src/connect.c b/src/connect.c
index 252e2c63..ce4d58df 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -29,6 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif /* HAVE_SYS_TIME_H */
#include "libssh/libssh.h"
#include "libssh/misc.h"
diff --git a/src/external/ed25519.c b/src/external/ed25519.c
index 8cd58591..41b5f289 100644
--- a/src/external/ed25519.c
+++ b/src/external/ed25519.c
@@ -77,8 +77,8 @@ static void get_hram(unsigned char *hram,
}
-int crypto_sign_ed25519_keypair(unsigned char *pk,
- unsigned char *sk)
+int crypto_sign_ed25519_keypair(ed25519_pubkey pk,
+ ed25519_privkey sk)
{
sc25519 scsk;
ge25519 gepk;
@@ -114,7 +114,7 @@ int crypto_sign_ed25519(unsigned char *sm,
uint64_t *smlen,
const unsigned char *m,
uint64_t mlen,
- const unsigned char *sk)
+ const ed25519_privkey sk)
{
sc25519 sck, scs, scsk;
ge25519 ger;
@@ -177,7 +177,7 @@ int crypto_sign_ed25519_open(unsigned char *m,
uint64_t *mlen,
const unsigned char *sm,
uint64_t smlen,
- const unsigned char *pk)
+ const ed25519_pubkey pk)
{
unsigned int i;
int ret;
diff --git a/src/libmbedcrypto.c b/src/libmbedcrypto.c
index 79f8ecc2..35e750e4 100644
--- a/src/libmbedcrypto.c
+++ b/src/libmbedcrypto.c
@@ -693,7 +693,7 @@ static void cipher_encrypt(struct ssh_cipher_struct *cipher,
}
static void cipher_encrypt_cbc(struct ssh_cipher_struct *cipher, void *in, void *out,
- unsigned long len)
+ size_t len)
{
size_t outlen = 0;
int rc = 0;
@@ -751,7 +751,7 @@ static void cipher_decrypt(struct ssh_cipher_struct *cipher,
}
static void cipher_decrypt_cbc(struct ssh_cipher_struct *cipher, void *in, void *out,
- unsigned long len)
+ size_t len)
{
size_t outlen = 0;
int rc = 0;
diff --git a/src/sftp.c b/src/sftp.c
index 07cb1c0e..2abe2ed5 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -32,6 +32,9 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif /* HAVE_SYS_TIME_H */
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
@@ -173,69 +176,95 @@ error:
return NULL;
}
-sftp_session sftp_new_channel(ssh_session session, ssh_channel channel){
- sftp_session sftp;
+sftp_session
+sftp_new_channel(ssh_session session, ssh_channel channel)
+{
+ sftp_session sftp = NULL;
- if (session == NULL) {
- return NULL;
- }
+ if (session == NULL) {
+ return NULL;
+ }
- sftp = calloc(1, sizeof(struct sftp_session_struct));
- if (sftp == NULL) {
- ssh_set_error_oom(session);
+ sftp = calloc(1, sizeof(struct sftp_session_struct));
+ if (sftp == NULL) {
+ ssh_set_error_oom(session);
+ return NULL;
+ }
- return NULL;
- }
+ sftp->ext = sftp_ext_new();
+ if (sftp->ext == NULL) {
+ ssh_set_error_oom(session);
+ goto error;
+ }
- sftp->ext = sftp_ext_new();
- if (sftp->ext == NULL) {
- ssh_set_error_oom(session);
- SAFE_FREE(sftp);
+ sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct));
+ if (sftp->read_packet == NULL) {
+ ssh_set_error_oom(session);
+ goto error;
+ }
- return NULL;
- }
+ sftp->read_packet->payload = ssh_buffer_new();
+ if (sftp->read_packet->payload == NULL) {
+ ssh_set_error_oom(session);
+ goto error;
+ }
+
+ sftp->session = session;
+ sftp->channel = channel;
- sftp->session = session;
- sftp->channel = channel;
+ return sftp;
- return sftp;
+error:
+ if (sftp->ext != NULL) {
+ sftp_ext_free(sftp->ext);
+ }
+ if (sftp->read_packet != NULL) {
+ if (sftp->read_packet->payload != NULL) {
+ SSH_BUFFER_FREE(sftp->read_packet->payload);
+ }
+ SAFE_FREE(sftp->read_packet);
+ }
+ SAFE_FREE(sftp);
+ return NULL;
}
#ifdef WITH_SERVER
-sftp_session sftp_server_new(ssh_session session, ssh_channel chan){
- sftp_session sftp = NULL;
+sftp_session
+sftp_server_new(ssh_session session, ssh_channel chan)
+{
+ sftp_session sftp = NULL;
- sftp = calloc(1, sizeof(struct sftp_session_struct));
- if (sftp == NULL) {
- ssh_set_error_oom(session);
- return NULL;
- }
+ sftp = calloc(1, sizeof(struct sftp_session_struct));
+ if (sftp == NULL) {
+ ssh_set_error_oom(session);
+ return NULL;
+ }
- sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct));
- if (sftp->read_packet == NULL) {
- goto error;
- }
+ sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct));
+ if (sftp->read_packet == NULL) {
+ goto error;
+ }
- sftp->read_packet->payload = ssh_buffer_new();
- if (sftp->read_packet->payload == NULL) {
- goto error;
- }
+ sftp->read_packet->payload = ssh_buffer_new();
+ if (sftp->read_packet->payload == NULL) {
+ goto error;
+ }
- sftp->session = session;
- sftp->channel = chan;
+ sftp->session = session;
+ sftp->channel = chan;
- return sftp;
+ return sftp;
error:
- ssh_set_error_oom(session);
- if (sftp->read_packet != NULL) {
- if (sftp->read_packet->payload != NULL) {
- SSH_BUFFER_FREE(sftp->read_packet->payload);
+ ssh_set_error_oom(session);
+ if (sftp->read_packet != NULL) {
+ if (sftp->read_packet->payload != NULL) {
+ SSH_BUFFER_FREE(sftp->read_packet->payload);
+ }
+ SAFE_FREE(sftp->read_packet);
}
- SAFE_FREE(sftp->read_packet);
- }
- SAFE_FREE(sftp);
- return NULL;
+ SAFE_FREE(sftp);
+ return NULL;
}
int sftp_server_init(sftp_session sftp){
diff --git a/src/threads/winlocks.c b/src/threads/winlocks.c
index a1799531..da600418 100644
--- a/src/threads/winlocks.c
+++ b/src/threads/winlocks.c
@@ -26,6 +26,7 @@
#include <windows.h>
#include <winbase.h>
#include <errno.h>
+#include <stdlib.h>
static int ssh_winlock_mutex_init (void **priv)
{
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt
index e6adfe36..71e5182e 100644
--- a/tests/client/CMakeLists.txt
+++ b/tests/client/CMakeLists.txt
@@ -43,6 +43,7 @@ if (WITH_SFTP)
endif()
set(LIBSSH_CLIENT_TESTS
${LIBSSH_CLIENT_TESTS}
+ torture_sftp_init
torture_sftp_ext
torture_sftp_canonicalize_path
torture_sftp_dir
diff --git a/tests/client/torture_sftp_init.c b/tests/client/torture_sftp_init.c
new file mode 100644
index 00000000..a17f01fe
--- /dev/null
+++ b/tests/client/torture_sftp_init.c
@@ -0,0 +1,106 @@
+#include "config.h"
+
+#define LIBSSH_STATIC
+
+#include "torture.h"
+#include "sftp.c"
+
+#include <sys/types.h>
+#include <pwd.h>
+#include <errno.h>
+
+static int sshd_setup(void **state)
+{
+ torture_setup_sshd_server(state, false);
+
+ return 0;
+}
+
+static int sshd_teardown(void **state) {
+ torture_teardown_sshd_server(state);
+
+ return 0;
+}
+
+static void session_setup(void **state)
+{
+ struct torture_state *s = *state;
+ struct passwd *pwd;
+ int rc;
+
+ pwd = getpwnam("bob");
+ assert_non_null(pwd);
+
+ rc = setuid(pwd->pw_uid);
+ assert_return_code(rc, errno);
+
+ s->ssh.session = torture_ssh_session(s,
+ TORTURE_SSH_SERVER,
+ NULL,
+ TORTURE_SSH_USER_ALICE,
+ NULL);
+ assert_non_null(s->ssh.session);
+
+ s->ssh.tsftp = torture_sftp_session(s->ssh.session);
+ assert_non_null(s->ssh.tsftp);
+}
+
+static void session_setup_channel(void **state)
+{
+ struct torture_state *s = *state;
+ struct passwd *pwd = NULL;
+ ssh_channel c = NULL;
+ int rc;
+
+ pwd = getpwnam("bob");
+ assert_non_null(pwd);
+
+ rc = setuid(pwd->pw_uid);
+ assert_return_code(rc, errno);
+
+ s->ssh.session = torture_ssh_session(s,
+ TORTURE_SSH_SERVER,
+ NULL,
+ TORTURE_SSH_USER_ALICE,
+ NULL);
+ assert_non_null(s->ssh.session);
+
+ c = ssh_channel_new(s->ssh.session);
+ assert_non_null(c);
+
+ s->ssh.tsftp = torture_sftp_session_channel(s->ssh.session, c);
+ assert_non_null(s->ssh.tsftp);
+}
+
+static int session_teardown(void **state)
+{
+ struct torture_state *s = *state;
+
+ torture_rmdirs(s->ssh.tsftp->testdir);
+ torture_sftp_close(s->ssh.tsftp);
+ ssh_disconnect(s->ssh.session);
+ ssh_free(s->ssh.session);
+
+ return 0;
+}
+
+int torture_run_tests(void) {
+ int rc;
+ struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(session_setup,
+ NULL,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(session_setup_channel,
+ NULL,
+ session_teardown)
+ };
+
+ ssh_init();
+
+ torture_filter_tests(tests);
+ rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown);
+
+ ssh_finalize();
+
+ return rc;
+}
diff --git a/tests/torture.c b/tests/torture.c
index 4ac1ec66..61209185 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -426,7 +426,8 @@ ssh_bind torture_ssh_bind(const char *addr,
#ifdef WITH_SFTP
-struct torture_sftp *torture_sftp_session(ssh_session session) {
+struct torture_sftp *torture_sftp_session_channel(ssh_session session, ssh_channel channel)
+{
struct torture_sftp *t;
char template[] = "/tmp/ssh_torture_XXXXXX";
char *p;
@@ -442,9 +443,26 @@ struct torture_sftp *torture_sftp_session(ssh_session session) {
}
t->ssh = session;
- t->sftp = sftp_new(session);
- if (t->sftp == NULL) {
- goto failed;
+ if (channel == NULL) {
+ t->sftp = sftp_new(session);
+ if (t->sftp == NULL) {
+ goto failed;
+ }
+ } else {
+ t->sftp = sftp_new_channel(session, channel);
+ if (t->sftp == NULL) {
+ goto failed;
+ }
+
+ rc = ssh_channel_open_session(channel);
+ if (rc != SSH_OK) {
+ goto failed;
+ }
+
+ rc = ssh_channel_request_sftp(channel);
+ if (rc != SSH_OK) {
+ goto failed;
+ }
}
rc = sftp_init(t->sftp);
@@ -475,6 +493,11 @@ failed:
return NULL;
}
+struct torture_sftp *torture_sftp_session(ssh_session session)
+{
+ return torture_sftp_session_channel(session, NULL);
+}
+
void torture_sftp_close(struct torture_sftp *t) {
if (t == NULL) {
return;
diff --git a/tests/torture.h b/tests/torture.h
index b9b87b6a..599b53ea 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -113,6 +113,7 @@ ssh_bind torture_ssh_bind(const char *addr,
const char *private_key_file);
struct torture_sftp *torture_sftp_session(ssh_session session);
+struct torture_sftp *torture_sftp_session_channel(ssh_session session, ssh_channel channel);
void torture_sftp_close(struct torture_sftp *t);
void torture_write_file(const char *filename, const char *data);