diff --git a/CMakeLists.txt b/CMakeLists.txt index b331bb7..1e66493 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,14 @@ cmake_minimum_required(VERSION 3.5) project(vfs.sftp) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) find_package(Kodi REQUIRED) -find_package(p8-platform REQUIRED) find_package(OpenSSL REQUIRED) find_package(SSH REQUIRED) find_package(ZLIB REQUIRED) include_directories(${KODI_INCLUDE_DIR}/.. - ${p8-platform_INCLUDE_DIRS} ${SSH_INCLUDE_DIRS}) set(SFTP_SOURCES src/SFTPSession.cpp @@ -22,9 +16,8 @@ set(SFTP_SOURCES src/SFTPSession.cpp set(SFTP_HEADERS src/SFTPSession.h) -set(DEPLIBS ${p8-platform_LIBRARIES} +set(DEPLIBS ${OPENSSL_LIBRARIES} ${SSH_LIBRARIES} - ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES}) add_definitions( -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) diff --git a/depends/common/libssh/01-removelegacy.patch b/depends/common/libssh/01-removelegacy.patch index bdec257..d6aa95f 100644 --- a/depends/common/libssh/01-removelegacy.patch +++ b/depends/common/libssh/01-removelegacy.patch @@ -1,6 +1,6 @@ --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt -@@ -134,7 +134,6 @@ +@@ -114,7 +114,6 @@ set(libssh_SRCS kex.c known_hosts.c knownhosts.c @@ -8,3 +8,4 @@ log.c match.c messages.c + diff --git a/depends/common/libssh/02-build-static.patch b/depends/common/libssh/02-build-static.patch deleted file mode 100644 index 0536dee..0000000 --- a/depends/common/libssh/02-build-static.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- a/src/CMakeLists.txt -+++ b/src/CMakeLists.txt -@@ -312,6 +312,7 @@ - ) - endif (WITH_SYMBOL_VERSIONING AND HAVE_LD_VERSION_SCRIPT AND ABIMAP_FOUND) - -+if(OFF) - add_library(${LIBSSH_SHARED_LIBRARY} SHARED ${libssh_SRCS}) - target_compile_options(${LIBSSH_SHARED_LIBRARY} - PRIVATE -@@ -361,6 +362,7 @@ - ARCHIVE DESTINATION ${LIB_INSTALL_DIR} - COMPONENT libraries - ) -+endif() - - if (BUILD_STATIC_LIB) - add_library(${LIBSSH_STATIC_LIBRARY} STATIC ${libssh_SRCS}) diff --git a/depends/common/libssh/03-md5.patch b/depends/common/libssh/02-md5.patch similarity index 72% rename from depends/common/libssh/03-md5.patch rename to depends/common/libssh/02-md5.patch index d228b0a..7c1d3e3 100644 --- a/depends/common/libssh/03-md5.patch +++ b/depends/common/libssh/02-md5.patch @@ -1,6 +1,6 @@ --- a/include/libssh/wrapper.h +++ b/include/libssh/wrapper.h -@@ -74,7 +74,7 @@ +@@ -66,7 +66,7 @@ struct ssh_cipher_struct; struct ssh_crypto_struct; typedef struct ssh_mac_ctx_struct *ssh_mac_ctx; @@ -11,7 +11,7 @@ --- a/src/libcrypto.c +++ b/src/libcrypto.c -@@ -316,7 +316,7 @@ +@@ -316,7 +316,7 @@ void sha512(const unsigned char *digest, int len, unsigned char *hash) } } @@ -22,7 +22,7 @@ MD5CTX c = EVP_MD_CTX_create(); --- a/src/libgcrypt.c +++ b/src/libgcrypt.c -@@ -198,7 +198,7 @@ +@@ -198,7 +198,7 @@ void sha512(const unsigned char *digest, int len, unsigned char *hash) { gcry_md_hash_buffer(GCRY_MD_SHA512, hash, digest, len); } @@ -33,7 +33,7 @@ --- a/src/libmbedcrypto.c +++ b/src/libmbedcrypto.c -@@ -338,7 +338,7 @@ +@@ -338,7 +338,7 @@ void sha512(const unsigned char *digest, int len, unsigned char *hash) } } @@ -44,7 +44,7 @@ int rc; --- a/src/pki_gcrypt.c +++ b/src/pki_gcrypt.c -@@ -256,7 +256,7 @@ +@@ -256,7 +256,7 @@ static int passphrase_to_key(char *data, unsigned int datalen, unsigned int md_not_empty; for (j = 0, md_not_empty = 0; j < keylen; ) { @@ -55,7 +55,7 @@ } --- a/src/session.c +++ b/src/session.c -@@ -987,7 +987,7 @@ +@@ -1003,7 +1003,7 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) return SSH_ERROR; } @@ -64,7 +64,7 @@ if (ctx == NULL) { SAFE_FREE(h); return SSH_ERROR; -@@ -1177,7 +1177,7 @@ +@@ -1193,7 +1193,7 @@ int ssh_get_publickey_hash(const ssh_key key, goto out; } @@ -73,3 +73,4 @@ if (ctx == NULL) { free(h); rc = -1; + diff --git a/depends/common/libssh/04-stack-protector.patch b/depends/common/libssh/03-stack-protector.patch similarity index 97% rename from depends/common/libssh/04-stack-protector.patch rename to depends/common/libssh/03-stack-protector.patch index 8723e3a..695b7de 100644 --- a/depends/common/libssh/04-stack-protector.patch +++ b/depends/common/libssh/03-stack-protector.patch @@ -1,6 +1,6 @@ --- a/CompilerChecks.cmake +++ b/CompilerChecks.cmake -@@ -66,20 +66,20 @@ +@@ -67,20 +67,20 @@ if (UNIX) endif() endif() diff --git a/depends/common/libssh/05-android.patch b/depends/common/libssh/04-android.patch similarity index 76% rename from depends/common/libssh/05-android.patch rename to depends/common/libssh/04-android.patch index c93fdd5..cf23c87 100644 --- a/depends/common/libssh/05-android.patch +++ b/depends/common/libssh/04-android.patch @@ -1,6 +1,6 @@ --- a/src/misc.c +++ b/src/misc.c -@@ -215,6 +215,9 @@ +@@ -240,6 +240,9 @@ int ssh_is_ipaddr(const char *str) { char *ssh_get_user_home_dir(void) { @@ -10,7 +10,7 @@ char *szPath = NULL; struct passwd pwd; struct passwd *pwdbuf = NULL; -@@ -235,6 +238,7 @@ +@@ -260,6 +263,7 @@ char *ssh_get_user_home_dir(void) szPath = strdup(pwd.pw_dir); return szPath; @@ -18,7 +18,7 @@ } /* we have read access on file */ -@@ -249,6 +253,17 @@ +@@ -299,6 +303,17 @@ int ssh_dir_writeable(const char *path) char *ssh_get_local_username(void) { @@ -36,7 +36,7 @@ struct passwd pwd; struct passwd *pwdbuf = NULL; char buf[NSS_BUFLEN_PASSWD]; -@@ -262,6 +277,7 @@ +@@ -312,6 +327,7 @@ char *ssh_get_local_username(void) name = strdup(pwd.pw_name); diff --git a/depends/common/libssh/06-windows.patch b/depends/common/libssh/05-windows.patch similarity index 89% rename from depends/common/libssh/06-windows.patch rename to depends/common/libssh/05-windows.patch index 5913a34..0d3e9fb 100644 --- a/depends/common/libssh/06-windows.patch +++ b/depends/common/libssh/05-windows.patch @@ -1,6 +1,6 @@ --- a/include/libssh/sftp.h +++ b/include/libssh/sftp.h -@@ -57,7 +57,7 @@ +@@ -57,7 +57,7 @@ extern "C" { # ifndef _SSIZE_T_DEFINED # undef ssize_t # include @@ -11,8 +11,8 @@ --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt -@@ -372,7 +372,7 @@ - -D_GNU_SOURCE) +@@ -384,7 +384,7 @@ if (BUILD_STATIC_LIB) + add_library(ssh::static ALIAS ssh-static) if (MSVC) - set(OUTPUT_SUFFIX static) @@ -48,3 +48,4 @@ #include #include #if _MSC_VER >= 1400 + diff --git a/depends/common/libssh/07-windowsstore.patch b/depends/common/libssh/06-windowsstore.patch similarity index 69% rename from depends/common/libssh/07-windowsstore.patch rename to depends/common/libssh/06-windowsstore.patch index f58d992..0fb46b0 100644 --- a/depends/common/libssh/07-windowsstore.patch +++ b/depends/common/libssh/06-windowsstore.patch @@ -1,16 +1,6 @@ ---- a/CompilerChecks.cmake -+++ b/CompilerChecks.cmake -@@ -105,6 +105,7 @@ - add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1" SUPPORTED_COMPILER_FLAGS) - add_c_compiler_flag("/D _CRT_NONSTDC_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) - add_c_compiler_flag("/D _CRT_SECURE_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) -+ add_c_compiler_flag("/D _WINSOCK_DEPRECATED_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) - endif() - - # This removes this annoying warning --- a/src/external/curve25519_ref.c +++ b/src/external/curve25519_ref.c -@@ -61,7 +61,14 @@ +@@ -61,7 +61,14 @@ static void freeze(unsigned int a[32]) for (j = 0;j < 32;++j) aorig[j] = a[j]; add(a,a,minusp); @@ -27,7 +17,7 @@ --- a/src/external/fe25519.c +++ b/src/external/fe25519.c -@@ -87,7 +87,14 @@ +@@ -87,7 +87,14 @@ void fe25519_freeze(fe25519 *r) } m &= ge(r->v[0],237); @@ -42,7 +32,7 @@ r->v[31] -= m&127; for (i = 30; i > 0; i--) { -@@ -159,7 +166,14 @@ +@@ -159,7 +166,14 @@ void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b) int i; uint32_t mask = b; @@ -78,7 +68,7 @@ char tmp[MAX_PATH] = {0}; char *szPath = NULL; -@@ -117,6 +122,7 @@ +@@ -117,6 +122,7 @@ char *ssh_get_user_home_dir(void) { strcpy(szPath, tmp); return szPath; } @@ -86,7 +76,7 @@ return NULL; } -@@ -147,6 +153,7 @@ +@@ -172,6 +178,7 @@ int gettimeofday(struct timeval *__p, void *__t) { } char *ssh_get_local_username(void) { @@ -94,7 +84,7 @@ DWORD size = 0; char *user; -@@ -161,6 +168,7 @@ +@@ -186,6 +193,7 @@ char *ssh_get_local_username(void) { if (GetUserName(user, &size)) { return user; } @@ -104,7 +94,7 @@ } --- a/src/options.c +++ b/src/options.c -@@ -1667,7 +1667,7 @@ +@@ -1674,7 +1674,7 @@ int ssh_bind_options_set(ssh_bind sshbind, enum ssh_bind_options_e type, int key_type; ssh_key key; ssh_key *bind_key_loc = NULL; @@ -113,14 +103,4 @@ rc = ssh_pki_import_privkey_file(value, NULL, NULL, NULL, &key); if (rc != SSH_OK) { ---- a/src/pki_container_openssh.c -+++ b/src/pki_container_openssh.c -@@ -112,7 +112,7 @@ - char passphrase_buffer[128]; - size_t key_material_len; - ssh_buffer buffer; -- ssh_string salt; -+ ssh_string salt = NULL; - uint32_t rounds; - int cmp; - int rc; + diff --git a/depends/common/libssh/08-static-openssl.patch b/depends/common/libssh/07-static-openssl.patch similarity index 56% rename from depends/common/libssh/08-static-openssl.patch rename to depends/common/libssh/07-static-openssl.patch index ad45a90..04901da 100644 --- a/depends/common/libssh/08-static-openssl.patch +++ b/depends/common/libssh/07-static-openssl.patch @@ -1,6 +1,16 @@ +--- a/CompilerChecks.cmake ++++ b/CompilerChecks.cmake +@@ -106,6 +106,7 @@ if (MSVC) + add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("/D _CRT_NONSTDC_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("/D _CRT_SECURE_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) ++ add_c_compiler_flag("/D _WINSOCK_DEPRECATED_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) + endif() + + # This removes this annoying warning --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake -@@ -77,6 +77,15 @@ +@@ -74,6 +74,15 @@ if (WIN32) endif (WIN32) if (OPENSSL_FOUND) @@ -16,7 +26,7 @@ set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) check_include_file(openssl/des.h HAVE_OPENSSL_DES_H) if (NOT HAVE_OPENSSL_DES_H) -@@ -104,35 +113,35 @@ +@@ -101,53 +110,53 @@ if (OPENSSL_FOUND) check_include_file(openssl/ecdsa.h HAVE_OPENSSL_ECDSA_H) set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) @@ -56,7 +66,39 @@ set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) ++ set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LINK_LIBRARIES}) + check_function_exists(FIPS_mode HAVE_OPENSSL_FIPS_MODE) + + set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) +- set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) + set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LINK_LIBRARIES}) check_function_exists(RAND_priv_bytes HAVE_OPENSSL_RAND_PRIV_BYTES) + set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) +- set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) ++ set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LINK_LIBRARIES}) + check_function_exists(EVP_DigestSign HAVE_OPENSSL_EVP_DIGESTSIGN) + + set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) +- set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) ++ set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LINK_LIBRARIES}) + check_function_exists(EVP_DigestVerify HAVE_OPENSSL_EVP_DIGESTVERIFY) + check_function_exists(OPENSSL_ia32cap_loc HAVE_OPENSSL_IA32CAP_LOC) + + set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) +- set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) ++ set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LINK_LIBRARIES}) + check_symbol_exists(EVP_PKEY_ED25519 "openssl/evp.h" FOUND_OPENSSL_ED25519) + + if (HAVE_OPENSSL_EVP_DIGESTSIGN AND HAVE_OPENSSL_EVP_DIGESTVERIFY AND +@@ -156,7 +165,7 @@ if (OPENSSL_FOUND) + endif() + + set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) +- set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) ++ set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LINK_LIBRARIES}) + check_symbol_exists(EVP_PKEY_X25519 "openssl/evp.h" HAVE_OPENSSL_X25519) + + unset(CMAKE_REQUIRED_INCLUDES) + diff --git a/depends/common/libssh/09-werror.patch b/depends/common/libssh/08-werror.patch similarity index 86% rename from depends/common/libssh/09-werror.patch rename to depends/common/libssh/08-werror.patch index 5532dcd..73915ee 100644 --- a/depends/common/libssh/09-werror.patch +++ b/depends/common/libssh/08-werror.patch @@ -1,6 +1,6 @@ --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake -@@ -380,6 +380,9 @@ +@@ -402,6 +402,9 @@ if (NOT WIN32) }" HAVE_UNUSED_ATTRIBUTE) endif() @@ -10,7 +10,7 @@ check_c_source_compiles(" #include -@@ -418,9 +421,6 @@ +@@ -440,9 +443,6 @@ int main(void) { }" HAVE_GCC_BOUNDED_ATTRIBUTE) endif(OPENBSD) @@ -20,3 +20,4 @@ # Check for version script support file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "VERS_1 { global: sym; + diff --git a/depends/common/libssh/10-tvos.patch b/depends/common/libssh/09-tvos.patch similarity index 88% rename from depends/common/libssh/10-tvos.patch rename to depends/common/libssh/09-tvos.patch index f67daad..0205618 100644 --- a/depends/common/libssh/10-tvos.patch +++ b/depends/common/libssh/09-tvos.patch @@ -12,7 +12,7 @@ struct ssh_poll_handle_struct; /* socket.c */ -@@ -37,9 +42,11 @@ +@@ -37,9 +42,11 @@ void ssh_socket_set_fd(ssh_socket s, socket_t fd); socket_t ssh_socket_get_fd(ssh_socket s); #ifndef _WIN32 int ssh_socket_unix(ssh_socket s, const char *path); @@ -37,7 +37,7 @@ #define set_status(session, status) do {\ if (session->common.callbacks && session->common.callbacks->connect_status_function) \ session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \ -@@ -563,7 +567,7 @@ +@@ -563,7 +567,7 @@ int ssh_connect(ssh_session session) { session->session_state=SSH_SESSION_STATE_SOCKET_CONNECTED; ssh_socket_set_fd(session->socket, session->opts.fd); ret=SSH_OK; @@ -48,7 +48,7 @@ session->opts.ProxyCommand); --- a/src/socket.c +++ b/src/socket.c -@@ -58,6 +58,10 @@ +@@ -58,6 +58,10 @@ typedef intptr_t ssize_t; #include "libssh/poll.h" #include "libssh/session.h" @@ -59,7 +59,7 @@ /** * @internal * -@@ -832,7 +836,7 @@ +@@ -833,7 +837,7 @@ int ssh_socket_connect(ssh_socket s, return SSH_OK; } @@ -68,3 +68,4 @@ /** * @internal * @brief executes a command and redirect input and outputs + diff --git a/depends/common/libssh/flags.txt b/depends/common/libssh/flags.txt index c3a0df7..30ebf39 100644 --- a/depends/common/libssh/flags.txt +++ b/depends/common/libssh/flags.txt @@ -1 +1 @@ --DWITH_STATIC_LIB=1 -DBUILD_SHARED_LIBS=0 -DTHREADS_PTHREAD_ARG=0 -DWITH_EXAMPLES=0 -DWITH_GSSAPI=0 +-DBUILD_STATIC_LIB=1 -DBUILD_SHARED_LIBS=0 -DTHREADS_PTHREAD_ARG=0 -DWITH_EXAMPLES=0 -DWITH_GSSAPI=0 diff --git a/depends/common/libssh/libssh.sha256 b/depends/common/libssh/libssh.sha256 index e243f5b..2e2a19e 100644 --- a/depends/common/libssh/libssh.sha256 +++ b/depends/common/libssh/libssh.sha256 @@ -1 +1 @@ -25303c2995e663cd169fdd902bae88106f48242d7e96311d74f812023482c7a5 +2c8b5f894dced58b3d629f16f3afa6562c20b4bdc894639163cf657833688f0c diff --git a/depends/common/libssh/libssh.txt b/depends/common/libssh/libssh.txt index fed1ec6..11fce7b 100644 --- a/depends/common/libssh/libssh.txt +++ b/depends/common/libssh/libssh.txt @@ -1 +1 @@ -libssh http://mirrors.kodi.tv/build-deps/sources/libssh-0.9.0.tar.xz +libssh http://mirrors.kodi.tv/build-deps/sources/libssh-0.9.3.tar.xz diff --git a/depends/common/openssl/01-android.patch b/depends/common/openssl/01-android.patch index b8e664d..41bc6a3 100644 --- a/depends/common/openssl/01-android.patch +++ b/depends/common/openssl/01-android.patch @@ -1,6 +1,20 @@ --- a/Configurations/15-android.conf +++ b/Configurations/15-android.conf -@@ -89,7 +89,6 @@ +@@ -112,18 +112,17 @@ + # *after* announcement that gcc is being phased out, so + # favouring clang is considered adequate. Those who insist + # have option to enforce test for gcc with CC=gcc. +- if (which("$triarch-$cc") !~ m|^$ndk|) { +- die "no NDK $triarch-$cc on \$PATH"; ++ if (realpath(which("$cc")) !~ m|^$ndk|) { ++ die "no NDK $cc on \$PATH"; + } + $user{CC} = $cc; +- $user{CROSS_COMPILE} = "$triarch-"; ++ $user{CROSS_COMPILE} = ""; + } elsif ($user{CC} eq "clang") { + die "no NDK clang on \$PATH"; + } else { if (which("$triarch-gcc") !~ m|^$ndk/.*/prebuilt/([^/]+)/|) { die "no NDK $triarch-gcc on \$PATH"; } @@ -8,12 +22,13 @@ $user{CROSS_COMPILE} = "$triarch-"; } -@@ -105,7 +104,7 @@ +@@ -139,7 +138,7 @@ $sysroot =~ s|^$ndk/||; $android_ndk = { -- cflags => "$cflags --sysroot=\$(ANDROID_NDK)/$sysroot", +- cflags => "$cflags --sysroot=\$($ndk_var)/$sysroot", + cflags => $cflags, cppflags => $cppflags, bn_ops => $arch =~ m/64$/ ? "SIXTY_FOUR_BIT_LONG" : "BN_LLONG", + diff --git a/depends/common/openssl/02-android-standalone-toolchain.patch b/depends/common/openssl/02-android-standalone-toolchain.patch deleted file mode 100644 index a3d511b..0000000 --- a/depends/common/openssl/02-android-standalone-toolchain.patch +++ /dev/null @@ -1,143 +0,0 @@ -From a66c361a773e697b5c6bb805ae37d2c4c8d32cb1 Mon Sep 17 00:00:00 2001 -From: Andy Polyakov -Date: Sun, 14 Oct 2018 15:19:41 +0200 -Subject: [PATCH] Configurations/15-android.conf: add support for "standalone - toolchain". - -Reviewed-by: Richard Levitte -(Merged from https://github.com/openssl/openssl/pull/7400) - -(cherry picked from commit 03ad7c009e16a233c733098db3169c560142ccd3) ---- - Configurations/15-android.conf | 41 +++++++++++++++++++++++++--------- - NOTES.ANDROID | 18 ++++++++++----- - 2 files changed, 44 insertions(+), 15 deletions(-) - -diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf -index d3b428b6cb4..a6b0d7a06d2 100644 ---- a/Configurations/15-android.conf -+++ b/Configurations/15-android.conf -@@ -24,7 +24,12 @@ - - my $ndk = $ENV{ANDROID_NDK}; - die "\$ANDROID_NDK is not defined" if (!$ndk); -- die "\$ANDROID_NDK=$ndk is invalid" if (!-d "$ndk/platforms"); -+ if (!-d "$ndk/platforms" && !-f "$ndk/AndroidVersion.txt") { -+ # $ndk/platforms is traditional "all-inclusive" NDK, while -+ # $ndk/AndroidVersion.txt is so-called standalone toolchain -+ # tailored for specific target down to API level. -+ die "\$ANDROID_NDK=$ndk is invalid"; -+ } - $ndk = canonpath($ndk); - - my $ndkver = undef; -@@ -40,10 +45,18 @@ - close $fh; - } - -- my $sysroot; -+ my ($sysroot, $api, $arch); -+ -+ $config{target} =~ m|[^-]+-([^-]+)$|; # split on dash -+ $arch = $1; - -- if (!($sysroot = $ENV{CROSS_SYSROOT})) { -- my $api = "*"; -+ if ($sysroot = $ENV{CROSS_SYSROOT}) { -+ $sysroot =~ m|/android-([0-9]+)/arch-(\w+)/?$|; -+ ($api, $arch) = ($1, $2); -+ } elsif (-f "$ndk/AndroidVersion.txt") { -+ $sysroot = "$ndk/sysroot"; -+ } else { -+ $api = "*"; - - # see if user passed -D__ANDROID_API__=N - foreach (@{$useradd{CPPDEFINES}}, @{$user{CPPFLAGS}}) { -@@ -59,19 +72,15 @@ - } glob("$ndk/platforms/android-$api"); - die "no $ndk/platforms/android-$api" if ($#platforms < 0); - -- $config{target} =~ m|[^-]+-([^-]+)$|; # split on dash -- $sysroot = "@platforms[$#platforms]/arch-$1"; -+ $sysroot = "@platforms[$#platforms]/arch-$arch"; - } - die "no sysroot=$sysroot" if (!-d $sysroot); - -- $sysroot =~ m|/android-([0-9]+)/arch-(\w+)/?$|; -- my ($api, $arch) = ($1, $2); -- - my $triarch = $triplet{$arch}; - my $cflags; - my $cppflags; - -- # see if there is NDK clang on $PATH -+ # see if there is NDK clang on $PATH, "universal" or "standalone" - if (which("clang") =~ m|^$ndk/.*/prebuilt/([^/]+)/|) { - my $host=$1; - # harmonize with gcc default -@@ -83,6 +92,18 @@ - . "/$tritools-4.9/prebuilt/$host"; - $user{CC} = "clang" if ($user{CC} !~ m|clang|); - $user{CROSS_COMPILE} = undef; -+ } elsif (-f "$ndk/AndroidVersion.txt") { #"standalone toolchain" -+ my $cc = $user{CC} // "clang"; -+ # One can probably argue that both clang and gcc should be -+ # probed, but support for "standalone toolchain" was added -+ # *after* announcement that gcc is being phased out, so -+ # favouring clang is considered adequate. Those who insist -+ # have option to enforce test for gcc with CC=gcc. -+ if (which("$triarch-$cc") !~ m|^$ndk|) { -+ die "no NDK $triarch-$cc on \$PATH"; -+ } -+ $user{CC} = $cc; -+ $user{CROSS_COMPILE} = "$triarch-"; - } elsif ($user{CC} eq "clang") { - die "no NDK clang on \$PATH"; - } else { -diff --git a/NOTES.ANDROID b/NOTES.ANDROID -index d13f47d6675..bbbd8e4db92 100644 ---- a/NOTES.ANDROID -+++ b/NOTES.ANDROID -@@ -24,16 +24,18 @@ - in order to invoke $(CROSS_COMPILE)gcc and company. (Configure will fail - and give you a hint if you get it wrong.) Apart from PATH adjustment - you need to set ANDROID_NDK environment to point at NDK directory -- as /some/where/android-ndk-. NDK customarily supports multiple -+ as /some/where/android-ndk-. Both variables are significant at both -+ configuration and compilation times. NDK customarily supports multiple - Android API levels, e.g. android-14, android-21, etc. By default latest - one available is chosen. If you need to target older platform, pass - additional -D__ANDROID_API__=N to Configure. N is numeric value of the - target platform version. For example, to compile for ICS on ARM with - NDK 10d: - -- ANDROID_NDK=/some/where/android-ndk-10d -+ export ANDROID_NDK=/some/where/android-ndk-10d - PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:$PATH - ./Configure android-arm -D__ANDROID_API__=14 -+ make - - Caveat lector! Earlier OpenSSL versions relied on additional CROSS_SYSROOT - variable set to $ANDROID_NDK/platforms/android-/arch- to -@@ -43,12 +45,18 @@ - conflict, and mixing the two is therefore not supported. Migration to - CROSS_SYSROOT-less setup is recommended. - -- One can engage clang by adjusting PATH to cover NDK's clang. Just keep -- in mind that if you miss it, Configure will try to use gcc... Also, -- PATH would need even further adjustment to cover unprefixed, yet -+ One can engage clang by adjusting PATH to cover same NDK's clang. Just -+ keep in mind that if you miss it, Configure will try to use gcc... -+ Also, PATH would need even further adjustment to cover unprefixed, yet - target-specific, ar and ranlib. It's possible that you don't need to - bother, if binutils-multiarch is installed on your Linux system. - -+ Another option is to create so called "standalone toolchain" tailored -+ for single specific platform including Android API level, and assign its -+ location to ANDROID_NDK. In such case you have to pass matching target -+ name to Configure and shouldn't use -D__ANDROID_API__=N. PATH adjusment -+ becomes simpler, $ANDROID_NDK/bin:$PATH suffices. -+ - Running tests (on Linux) - ------------------------ - diff --git a/depends/common/openssl/03-android-cc.patch b/depends/common/openssl/03-android-cc.patch deleted file mode 100644 index 204ae33..0000000 --- a/depends/common/openssl/03-android-cc.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- a/Configurations/15-android.conf -+++ b/Configurations/15-android.conf -@@ -99,11 +99,11 @@ - # *after* announcement that gcc is being phased out, so - # favouring clang is considered adequate. Those who insist - # have option to enforce test for gcc with CC=gcc. -- if (which("$triarch-$cc") !~ m|^$ndk|) { -- die "no NDK $triarch-$cc on \$PATH"; -+ if (realpath(which("$cc")) !~ m|^$ndk|) { -+ die "no NDK $cc on \$PATH"; - } - $user{CC} = $cc; -- $user{CROSS_COMPILE} = "$triarch-"; -+ $user{CROSS_COMPILE} = ""; - } elsif ($user{CC} eq "clang") { - die "no NDK clang on \$PATH"; - } else { diff --git a/depends/common/openssl/openssl.sha256 b/depends/common/openssl/openssl.sha256 index a11c35c..20e81ad 100644 --- a/depends/common/openssl/openssl.sha256 +++ b/depends/common/openssl/openssl.sha256 @@ -1 +1 @@ -2836875a0f89c03d0fdf483941512613a50cfb421d6fd94b9f41d7279d586a3d +1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30b40b8b711f2 diff --git a/depends/common/openssl/openssl.txt b/depends/common/openssl/openssl.txt index 6e7e56d..fc8996d 100644 --- a/depends/common/openssl/openssl.txt +++ b/depends/common/openssl/openssl.txt @@ -1 +1 @@ -openssl http://mirrors.kodi.tv/build-deps/sources/openssl-1.1.1.tar.gz +openssl http://mirrors.kodi.tv/build-deps/sources/openssl-1.1.1d.tar.gz diff --git a/depends/windows/openssl/01-quote-cc.patch b/depends/windows/openssl/01-quote-cc.patch index 017bdce..537cc46 100644 --- a/depends/windows/openssl/01-quote-cc.patch +++ b/depends/windows/openssl/01-quote-cc.patch @@ -1,6 +1,6 @@ --- a/Configurations/windows-makefile.tmpl +++ b/Configurations/windows-makefile.tmpl -@@ -162,8 +162,8 @@ +@@ -164,8 +164,8 @@ libdir={- file_name_is_absolute($libdir) ##### User defined commands and flags ################################ @@ -11,3 +11,4 @@ CPPFLAGS={- our $cppflags1 = join(" ", (map { "-D".$_} @{$config{CPPDEFINES}}), (map { " /I ".$_} @{$config{CPPINCLUDES}}), + diff --git a/depends/windows/openssl/openssl.sha256 b/depends/windows/openssl/openssl.sha256 index a11c35c..20e81ad 100644 --- a/depends/windows/openssl/openssl.sha256 +++ b/depends/windows/openssl/openssl.sha256 @@ -1 +1 @@ -2836875a0f89c03d0fdf483941512613a50cfb421d6fd94b9f41d7279d586a3d +1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30b40b8b711f2 diff --git a/depends/windows/openssl/openssl.txt b/depends/windows/openssl/openssl.txt index 6e7e56d..fc8996d 100644 --- a/depends/windows/openssl/openssl.txt +++ b/depends/windows/openssl/openssl.txt @@ -1 +1 @@ -openssl http://mirrors.kodi.tv/build-deps/sources/openssl-1.1.1.tar.gz +openssl http://mirrors.kodi.tv/build-deps/sources/openssl-1.1.1d.tar.gz diff --git a/depends/windows/strawberryperl/CMakeLists.txt b/depends/windows/strawberryperl/CMakeLists.txt index 837dda6..95f3531 100644 --- a/depends/windows/strawberryperl/CMakeLists.txt +++ b/depends/windows/strawberryperl/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -project(strawberryperl VERSION 5.28.0.1) +project(strawberryperl VERSION 5.30.1.1) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/StrawberryPerlConfig.cmake "set(STRAWBERRYPERL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/perl/bin)\n") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/StrawberryPerlConfig.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/depends/windows/strawberryperl/strawberryperl.sha256 b/depends/windows/strawberryperl/strawberryperl.sha256 index 502c4a1..527ab86 100644 --- a/depends/windows/strawberryperl/strawberryperl.sha256 +++ b/depends/windows/strawberryperl/strawberryperl.sha256 @@ -1 +1 @@ -dcdc5f4d54e6def73a472bbd4820aa7a22d336f6004fc35e180818f3d388c7e1 +45d6bc187ab40f59ebd1a44d4014703c5cda23316ea7f2fb5eac182ea2972f0b diff --git a/depends/windows/strawberryperl/strawberryperl.txt b/depends/windows/strawberryperl/strawberryperl.txt index 27624b6..cef4e01 100644 --- a/depends/windows/strawberryperl/strawberryperl.txt +++ b/depends/windows/strawberryperl/strawberryperl.txt @@ -1 +1 @@ -strawberryperl http://strawberryperl.com/download/5.28.0.1/strawberry-perl-5.28.0.1-64bit-portable.zip +strawberryperl http://mirrors.kodi.tv/build-deps/win32/strawberry-perl-5.30.1.1-64bit-portable.zip diff --git a/depends/windowsstore/openssl/CMakeLists.txt b/depends/windowsstore/openssl/CMakeLists.txt index d129825..8abfbc7 100644 --- a/depends/windowsstore/openssl/CMakeLists.txt +++ b/depends/windowsstore/openssl/CMakeLists.txt @@ -7,9 +7,9 @@ check_symbol_exists(_AMD64_ "Windows.h" _X64_) check_symbol_exists(_ARM_ "Windows.h" _ARM_) if(_X86_) - set(OPENSSL_ARCHIVE_NAME openssl-1.0.2o-win10-Win32-v141) + set(OPENSSL_ARCHIVE_NAME openssl-1.1.1b-win10-Win32-v141) elseif(_X64_) - set(OPENSSL_ARCHIVE_NAME openssl-1.0.2o-win10-x64-v141) + set(OPENSSL_ARCHIVE_NAME openssl-1.1.1b-win10-x64-v141) elseif(_ARM_) set(OPENSSL_ARCHIVE_NAME openssl-1.0.2o-win10-ARM-v141) else() diff --git a/src/SFTPFile.cpp b/src/SFTPFile.cpp index 152be96..44a7bab 100644 --- a/src/SFTPFile.cpp +++ b/src/SFTPFile.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2005-2013 Team XBMC - * http://xbmc.org + * Copyright (C) 2005-2019 Team Kodi + * https://kodi.tv * * 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 @@ -13,16 +13,15 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see + * along with Kodi; see the file COPYING. If not, see * . * */ -#include -#include -#include #include "SFTPSession.h" +#include +#include #include #include @@ -38,7 +37,7 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS public: CSFTPFile(KODI_HANDLE instance) : CInstanceVFS(instance) { } - virtual void* Open(const VFSURL& url) override + void* Open(const VFSURL& url) override { SFTPContext* result = new SFTPContext; @@ -58,9 +57,9 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS return nullptr; } - virtual ssize_t Read(void* context, void* buffer, size_t uiBufSize) override + ssize_t Read(void* context, void* buffer, size_t uiBufSize) override { - SFTPContext* ctx = (SFTPContext*)context; + SFTPContext* ctx = static_cast(context); if (ctx && ctx->session && ctx->sftp_handle) { int rc = ctx->session->Read(ctx->sftp_handle, buffer, uiBufSize); @@ -76,9 +75,9 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS return -1; } - virtual int64_t Seek(void* context, int64_t iFilePosition, int whence) override + int64_t Seek(void* context, int64_t iFilePosition, int whence) override { - SFTPContext* ctx = (SFTPContext*)context; + SFTPContext* ctx = static_cast(context); if (ctx && ctx->session && ctx->sftp_handle) { uint64_t position = 0; @@ -101,9 +100,9 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS } } - virtual int64_t GetLength(void* context) override + int64_t GetLength(void* context) override { - SFTPContext* ctx = (SFTPContext*)context; + SFTPContext* ctx = static_cast(context); struct __stat64 buffer; if (ctx->session->Stat(ctx->file.c_str(), &buffer) != 0) return 0; @@ -111,9 +110,9 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS return buffer.st_size; } - virtual int64_t GetPosition(void* context) override + int64_t GetPosition(void* context) override { - SFTPContext* ctx = (SFTPContext*)context; + SFTPContext* ctx = static_cast(context); if (ctx->session && ctx->sftp_handle) return ctx->session->GetPosition(ctx->sftp_handle); @@ -121,7 +120,7 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS return 0; } - virtual int IoControl(void* context, XFILE::EIoControl request, void* param) override + int IoControl(void* context, XFILE::EIoControl request, void* param) override { if(request == XFILE::IOCTRL_SEEK_POSSIBLE) return 1; @@ -129,7 +128,7 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS return -1; } - virtual int Stat(const VFSURL& url, struct __stat64* buffer) override + int Stat(const VFSURL& url, struct __stat64* buffer) override { CSFTPSessionPtr session = CSFTPSessionManager::Get().CreateSession(url); if (session) @@ -141,9 +140,9 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS } } - virtual bool Close(void* context) override + bool Close(void* context) override { - SFTPContext* ctx = (SFTPContext*)context; + SFTPContext* ctx = static_cast(context); if (ctx->session && ctx->sftp_handle) ctx->session->CloseFileHandle(ctx->sftp_handle); delete ctx; @@ -151,7 +150,7 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS return true; } - virtual bool Exists(const VFSURL& url) override + bool Exists(const VFSURL& url) override { CSFTPSessionPtr session = CSFTPSessionManager::Get().CreateSession(url); if (session) @@ -163,17 +162,17 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS } } - virtual void ClearOutIdle() override + void ClearOutIdle() override { CSFTPSessionManager::Get().ClearOutIdleSessions(); } - virtual void DisconnectAll() override + void DisconnectAll() override { CSFTPSessionManager::Get().DisconnectAllSessions(); } - virtual bool DirectoryExists(const VFSURL& url) override + bool DirectoryExists(const VFSURL& url) override { CSFTPSessionPtr session = CSFTPSessionManager::Get().CreateSession(url); if (session) @@ -185,9 +184,9 @@ class ATTRIBUTE_HIDDEN CSFTPFile : public kodi::addon::CInstanceVFS } } - virtual bool GetDirectory(const VFSURL& url, - std::vector& items, - CVFSCallbacks callbacks) override + bool GetDirectory(const VFSURL& url, + std::vector& items, + CVFSCallbacks callbacks) override { CSFTPSessionPtr session = CSFTPSessionManager::Get().CreateSession(url); std::stringstream str; @@ -211,7 +210,7 @@ class ATTRIBUTE_HIDDEN CMyAddon : public kodi::addon::CAddonBase ssh_finalize(); } - virtual ADDON_STATUS CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance) override + ADDON_STATUS CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance) override { addonInstance = new CSFTPFile(instance); return ADDON_STATUS_OK; diff --git a/src/SFTPSession.cpp b/src/SFTPSession.cpp index 717995b..1693029 100644 --- a/src/SFTPSession.cpp +++ b/src/SFTPSession.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2005-2013 Team XBMC - * http://xbmc.org + * Copyright (C) 2005-2019 Team Kodi + * https://kodi.tv * * 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 @@ -13,13 +13,13 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see + * along with Kodi; see the file COPYING. If not, see * . * */ #include "SFTPSession.h" -#include + #include #include #include @@ -82,16 +82,16 @@ static const char * SFTPErrorText(int sftp_error) CSFTPSession::CSFTPSession(const VFSURL& url) { kodi::Log(ADDON_LOG_INFO, "SFTPSession: Creating new session on host '%s:%d' with user '%s'", url.hostname, url.port, url.username); - P8PLATFORM::CLockObject lock(m_lock); + std::unique_lock lock(m_lock); if (!Connect(url)) Disconnect(); - m_LastActive = P8PLATFORM::GetTimeMs(); + m_LastActive = std::chrono::high_resolution_clock::now(); } CSFTPSession::~CSFTPSession() { - P8PLATFORM::CLockObject lock(m_lock); + std::unique_lock lock(m_lock); Disconnect(); } @@ -99,8 +99,8 @@ sftp_file CSFTPSession::CreateFileHande(const std::string& file) { if (m_connected) { - P8PLATFORM::CLockObject lock(m_lock); - m_LastActive = P8PLATFORM::GetTimeMs(); + std::unique_lock lock(m_lock); + m_LastActive = std::chrono::high_resolution_clock::now(); sftp_file handle = sftp_open(m_sftp_session, CorrectPath(file).c_str(), O_RDONLY, 0); if (handle) { @@ -113,12 +113,12 @@ sftp_file CSFTPSession::CreateFileHande(const std::string& file) else kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Not connected and can't create file handle for '%s'", file.c_str()); - return NULL; + return nullptr; } void CSFTPSession::CloseFileHandle(sftp_file handle) { - P8PLATFORM::CLockObject lock(m_lock); + std::unique_lock lock(m_lock); sftp_close(handle); } @@ -128,17 +128,17 @@ bool CSFTPSession::GetDirectory(const std::string& base, const std::string& fold int sftp_error = SSH_FX_OK; if (m_connected) { - sftp_dir dir = NULL; + sftp_dir dir = nullptr; - P8PLATFORM::CLockObject lock(m_lock); - m_LastActive = P8PLATFORM::GetTimeMs(); + std::unique_lock lock(m_lock); + m_LastActive = std::chrono::high_resolution_clock::now(); dir = sftp_opendir(m_sftp_session, CorrectPath(folder).c_str()); //Doing as little work as possible within the critical section if (!dir) sftp_error = sftp_get_error(m_sftp_session); - lock.Unlock(); + lock.unlock(); if (!dir) { @@ -149,18 +149,18 @@ bool CSFTPSession::GetDirectory(const std::string& base, const std::string& fold bool read = true; while (read) { - sftp_attributes attributes = NULL; + sftp_attributes attributes = nullptr; - lock.Lock(); + lock.lock(); read = sftp_dir_eof(dir) == 0; attributes = sftp_readdir(m_sftp_session, dir); - lock.Unlock(); + lock.unlock(); - if (attributes && (attributes->name == NULL || strcmp(attributes->name, "..") == 0 || strcmp(attributes->name, ".") == 0)) + if (attributes && (attributes->name == nullptr || strcmp(attributes->name, "..") == 0 || strcmp(attributes->name, ".") == 0)) { - lock.Lock(); + lock.lock(); sftp_attributes_free(attributes); - lock.Unlock(); + lock.unlock(); continue; } @@ -172,11 +172,11 @@ bool CSFTPSession::GetDirectory(const std::string& base, const std::string& fold if (attributes->type == SSH_FILEXFER_TYPE_SYMLINK) { - lock.Lock(); + lock.lock(); sftp_attributes_free(attributes); attributes = sftp_stat(m_sftp_session, CorrectPath(localPath).c_str()); - lock.Unlock(); - if (attributes == NULL) + lock.unlock(); + if (attributes == nullptr) continue; } @@ -200,17 +200,17 @@ bool CSFTPSession::GetDirectory(const std::string& base, const std::string& fold entry.SetPath(base+localPath); items.push_back(entry); - lock.Lock(); + lock.lock(); sftp_attributes_free(attributes); - lock.Unlock(); + lock.unlock(); } else read = false; } - lock.Lock(); + lock.lock(); sftp_closedir(dir); - lock.Unlock(); + lock.unlock(); return true; } @@ -241,8 +241,8 @@ int CSFTPSession::Stat(const char *path, struct __stat64* buffer) { if(m_connected) { - P8PLATFORM::CLockObject lock(m_lock); - m_LastActive = P8PLATFORM::GetTimeMs(); + std::unique_lock lock(m_lock); + m_LastActive = std::chrono::high_resolution_clock::now(); sftp_attributes attributes = sftp_stat(m_sftp_session, CorrectPath(path).c_str()); if (attributes) @@ -275,35 +275,65 @@ int CSFTPSession::Stat(const char *path, struct __stat64* buffer) int CSFTPSession::Seek(sftp_file handle, uint64_t position) { - P8PLATFORM::CLockObject lock(m_lock); - m_LastActive = P8PLATFORM::GetTimeMs(); + std::unique_lock lock(m_lock); + m_LastActive = std::chrono::high_resolution_clock::now(); int result = sftp_seek64(handle, position); return result; } int CSFTPSession::Read(sftp_file handle, void *buffer, size_t length) { - P8PLATFORM::CLockObject lock(m_lock); - m_LastActive = P8PLATFORM::GetTimeMs(); + std::unique_lock lock(m_lock); + m_LastActive = std::chrono::high_resolution_clock::now(); int result=sftp_read(handle, buffer, length); return result; } int64_t CSFTPSession::GetPosition(sftp_file handle) { - P8PLATFORM::CLockObject lock(m_lock); - m_LastActive = P8PLATFORM::GetTimeMs(); + std::unique_lock lock(m_lock); + m_LastActive = std::chrono::high_resolution_clock::now(); int64_t result = sftp_tell64(handle); return result; } bool CSFTPSession::IsIdle() { - return (P8PLATFORM::GetTimeMs() - m_LastActive) > 90000; + std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); + return static_cast(std::chrono::duration_cast(now - m_LastActive).count()) > 90000; } bool CSFTPSession::VerifyKnownHost(ssh_session session) { +#if !(LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR < 8) + // Code used on libssh 0.8.0 and above + // See https://api.libssh.org/stable/deprecated.html + switch (ssh_session_is_known_server(session)) + { + case SSH_KNOWN_HOSTS_OK: + return true; + case SSH_KNOWN_HOSTS_CHANGED: + kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Server that was known has changed"); + return false; + case SSH_KNOWN_HOSTS_OTHER: + kodi::Log(ADDON_LOG_ERROR, "SFTPSession: The host key for this server was not found but an other type of key exists. An attacker might change the default server key to confuse your client into thinking the key does not exist"); + return false; + case SSH_KNOWN_HOSTS_NOT_FOUND: + kodi::Log(ADDON_LOG_INFO, "SFTPSession: Server file was not found, creating a new one"); + case SSH_KNOWN_HOSTS_UNKNOWN: + kodi::Log(ADDON_LOG_INFO, "SFTPSession: Server unkown, we trust it for now"); + if (ssh_session_update_known_hosts(session) != SSH_OK) + { + kodi::Log(ADDON_LOG_ERROR, "CSFTPSession: Failed to save host '%s'", strerror(errno)); + return false; + } + + return true; + case SSH_KNOWN_HOSTS_ERROR: + kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Failed to verify host '%s'", ssh_get_error(session)); + return false; + } +#else switch (ssh_is_server_known(session)) { case SSH_SERVER_KNOWN_OK: @@ -329,6 +359,7 @@ bool CSFTPSession::VerifyKnownHost(ssh_session session) kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Failed to verify host '%s'", ssh_get_error(session)); return false; } +#endif return false; } @@ -337,11 +368,11 @@ bool CSFTPSession::Connect(const VFSURL& url) { int timeout = SFTP_TIMEOUT; m_connected = false; - m_session = NULL; - m_sftp_session = NULL; + m_session = nullptr; + m_sftp_session = nullptr; m_session=ssh_new(); - if (m_session == NULL) + if (m_session == nullptr) { kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Failed to initialize session for host '%s'", url.hostname); return false; @@ -390,17 +421,17 @@ bool CSFTPSession::Connect(const VFSURL& url) } int noAuth = SSH_AUTH_DENIED; - if ((noAuth = ssh_userauth_none(m_session, NULL)) == SSH_AUTH_ERROR) + if ((noAuth = ssh_userauth_none(m_session, nullptr)) == SSH_AUTH_ERROR) { kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Failed to authenticate via guest '%s'", ssh_get_error(m_session)); return false; } - int method = ssh_userauth_list(m_session, NULL); + int method = ssh_userauth_list(m_session, nullptr); // Try to authenticate with public key first int publicKeyAuth = SSH_AUTH_DENIED; - if (method & SSH_AUTH_METHOD_PUBLICKEY && (publicKeyAuth = ssh_userauth_publickey_auto(m_session, NULL, NULL)) == SSH_AUTH_ERROR) + if (method & SSH_AUTH_METHOD_PUBLICKEY && (publicKeyAuth = ssh_userauth_publickey_auto(m_session, nullptr, nullptr)) == SSH_AUTH_ERROR) { kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Failed to authenticate via publickey '%s'", ssh_get_error(m_session)); return false; @@ -426,7 +457,7 @@ bool CSFTPSession::Connect(const VFSURL& url) { m_sftp_session = sftp_new(m_session); - if (m_sftp_session == NULL) + if (m_sftp_session == nullptr) { kodi::Log(ADDON_LOG_ERROR, "SFTPSession: Failed to initialize channel '%s'", ssh_get_error(m_session)); return false; @@ -459,8 +490,8 @@ void CSFTPSession::Disconnect() ssh_free(m_session); } - m_sftp_session = NULL; - m_session = NULL; + m_sftp_session = nullptr; + m_session = nullptr; } /*! @@ -472,7 +503,7 @@ void CSFTPSession::Disconnect() bool CSFTPSession::GetItemPermissions(const char *path, uint32_t &permissions) { bool gotPermissions = false; - P8PLATFORM::CLockObject lock(m_lock); + std::unique_lock lock(m_lock); if(m_connected) { sftp_attributes attributes = sftp_stat(m_sftp_session, CorrectPath(path).c_str()); @@ -509,11 +540,11 @@ CSFTPSessionPtr CSFTPSessionManager::CreateSession(const VFSURL& url) itoa << url2.port; std::string portstr = itoa.str(); - P8PLATFORM::CLockObject lock(m_lock); + std::unique_lock lock(m_lock); std::string key = std::string(url2.username) + ":" + url2.password + "@" + url2.hostname + ":" + portstr; CSFTPSessionPtr ptr = sessions[key]; - if (ptr == NULL) + if (ptr == nullptr) { ptr = CSFTPSessionPtr(new CSFTPSession(url2)); sessions[key] = ptr; @@ -524,7 +555,7 @@ CSFTPSessionPtr CSFTPSessionManager::CreateSession(const VFSURL& url) void CSFTPSessionManager::ClearOutIdleSessions() { - P8PLATFORM::CLockObject lock(m_lock); + std::unique_lock lock(m_lock); for(std::map::iterator iter = sessions.begin(); iter != sessions.end();) { if (iter->second->IsIdle()) @@ -536,6 +567,6 @@ void CSFTPSessionManager::ClearOutIdleSessions() void CSFTPSessionManager::DisconnectAllSessions() { - P8PLATFORM::CLockObject lock(m_lock); + std::unique_lock lock(m_lock); sessions.clear(); } diff --git a/src/SFTPSession.h b/src/SFTPSession.h index 25079a2..f623782 100644 --- a/src/SFTPSession.h +++ b/src/SFTPSession.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2005-2013 Team XBMC - * http://xbmc.org + * Copyright (C) 2005-2019 Team Kodi + * https://kodi.tv * * 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 @@ -13,17 +13,18 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see + * along with Kodi; see the file COPYING. If not, see * . * */ -#include +#include +#include #include #include -#include "kodi/addon-instance/VFS.h" -#include #include +#include +#include #include #include @@ -44,17 +45,18 @@ class CSFTPSession int Read(sftp_file handle, void *buffer, size_t length); int64_t GetPosition(sftp_file handle); bool IsIdle(); + private: bool VerifyKnownHost(ssh_session session); bool Connect(const VFSURL& url); void Disconnect(); bool GetItemPermissions(const char *path, uint32_t &permissions); - P8PLATFORM::CMutex m_lock; + std::recursive_mutex m_lock; bool m_connected; ssh_session m_session; sftp_session m_sftp_session; - int m_LastActive; + std::chrono::high_resolution_clock::time_point m_LastActive; }; typedef std::shared_ptr CSFTPSessionPtr; @@ -66,9 +68,10 @@ class CSFTPSessionManager CSFTPSessionPtr CreateSession(const VFSURL& url); void ClearOutIdleSessions(); void DisconnectAllSessions(); + private: CSFTPSessionManager() {} CSFTPSessionManager& operator=(const CSFTPSessionManager&); - P8PLATFORM::CMutex m_lock; + std::recursive_mutex m_lock; std::map sessions; }; diff --git a/vfs.sftp/addon.xml.in b/vfs.sftp/addon.xml.in index 9dd2a24..1a4e68e 100644 --- a/vfs.sftp/addon.xml.in +++ b/vfs.sftp/addon.xml.in @@ -1,7 +1,7 @@ @ADDON_DEPENDS@ @@ -22,8 +22,12 @@ zeroconf="_sftp-ssh._tcp" library_@PLATFORM@="@LIBRARY_FILENAME@"/> - SFTP support - SFTP support + SSH File Transfer Protocol support + The SSH File Transfer Protocol (also Secure File Transfer Protocol, or SFTP) is a network protocol that provides file access, file transfer, and file management over any reliable data stream. + +This addon allows file access to data in it. @PLATFORM@ + GPL-2.0 + https://github.com/xbmc/vfs.sftp diff --git a/vfs.sftp/icon.png b/vfs.sftp/icon.png new file mode 100644 index 0000000..441ef8e Binary files /dev/null and b/vfs.sftp/icon.png differ