From a4fc97bf0a3859cf1d38d4bc2d85262c8c3fa9b2 Mon Sep 17 00:00:00 2001 From: Laurent Stacul Date: Mon, 30 Aug 2021 18:59:27 +0200 Subject: [PATCH 001/424] Makefile.am: Add missing key in case openssl > 1.1.0 (#617) File: Makefile.am Notes: fix missing test keys Credit: Laurent Stacul --- tests/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 27ddc2dfa7..582c914153 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,6 +30,9 @@ EXTRA_DIST = \ key_dsa_wrong.pub \ key_ecdsa \ key_ecdsa.pub \ + signed_key_ecdsa \ + signed_key_ecdsa.pub \ + signed_key_ecdsa-cert.pub \ key_ed25519 \ key_ed25519.pub \ key_ed25519_encrypted \ From af4a4d3f35ffe54e1acca943ca4419d515320daa Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Tue, 31 Aug 2021 09:51:25 -0700 Subject: [PATCH 002/424] Update .gitignore Add .DS_Store files for macOS --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b6d6b5cb05..d256f68b74 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ tags libssh2.pc TAGS *~ +.DS_Store From d9b4222ef1c5ab9b9e499fe6234556e5cca7c4fe Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Thu, 2 Sep 2021 13:13:53 -0700 Subject: [PATCH 003/424] Update CI to use latest Ubuntu #624 (#625) File: ci.yml Notes: Update CI to use latest Ubuntu #624 Also removed 32 bit building in the matrix. Credit: Will Cosgrove --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3333d9c006..00846b1bb4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,18 +8,18 @@ on: jobs: style-check: - runs-on: ubuntu-16.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Check Style run: ./ci/checksrc.sh build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: compiler: [gcc, clang] - address_size: [32, 64] + address_size: [64] crypto_backend: [OpenSSL, Libgcrypt, mbedTLS] build_shared_libs: [OFF, ON] enable_zlib_compression: [OFF, ON] @@ -59,7 +59,7 @@ jobs: if: ${{ matrix.address_size == 64 }} run: | sudo apt-get install -y libssl-dev - sudo apt-get install -y libgcrypt11-dev + sudo apt-get install -y libgcrypt-dev - name: Install mbedTLS Dependencies if: ${{ matrix.crypto_backend == 'mbedTLS' }} run: | @@ -91,7 +91,7 @@ jobs: CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test cmake --build . --target package fuzzer: - runs-on: ubuntu-16.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: From f0417cb1967331c8dcb38a96ab889ecdf71f6dcb Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Thu, 2 Sep 2021 13:14:46 -0700 Subject: [PATCH 004/424] openssh_fixture.c: fix warning (#621) File: openssh_fixture.c Notes: Fix `portable_sleep` return type warning Credit: Will Cosgrove --- tests/openssh_fixture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 0480c5d542..97f154e9ae 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -208,7 +208,7 @@ static int is_running_inside_a_container() #endif } -static unsigned int portable_sleep(unsigned int seconds) +static void portable_sleep(unsigned int seconds) { #ifdef WIN32 Sleep(seconds); From 7daee037d110bbdb003ea75ca68d357ffa9d8fa8 Mon Sep 17 00:00:00 2001 From: Laurent Stacul Date: Thu, 2 Sep 2021 22:17:35 +0200 Subject: [PATCH 005/424] openssh_fixture.c: Fix openssh_server build not working (#616) (#620) File: openssh_fixture.c Notes: fixes too long of output lines building docker image Credit: Laurent Stacul --- tests/openssh_fixture.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 97f154e9ae..474b20aa0f 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -145,7 +145,8 @@ static int run_command(char **output, const char *command, ...) static int build_openssh_server_docker_image(void) { - return run_command(NULL, "docker build -t libssh2/openssh_server " + return run_command(NULL, "docker build --quiet " + "-t libssh2/openssh_server " "openssh_server"); } From 6eb132f1594684276134616476225e1740f5dcf0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 3 Sep 2021 09:17:18 +0200 Subject: [PATCH 006/424] mailing list: moved to lists.haxx.se --- README | 2 +- README.md | 2 +- configure.ac | 2 +- os400/libssh2_config.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README b/README index 8a148568cf..89639ba7d2 100644 --- a/README +++ b/README @@ -6,7 +6,7 @@ the revised BSD license. Web site: https://www.libssh2.org/ -Mailing list: https://cool.haxx.se/mailman/listinfo/libssh2-devel +Mailing list: https://lists.haxx.se/listinfo/libssh2-devel License: see COPYING diff --git a/README.md b/README.md index a4c741f68c..14153a3e5c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ the revised BSD license. [Web site](https://www.libssh2.org/) -[Mailing list](https://cool.haxx.se/mailman/listinfo/libssh2-devel) +[Mailing list](https://lists.haxx.se/listinfo/libssh2-devel) [BSD Licensed](https://libssh2.org/license.html) diff --git a/configure.ac b/configure.ac index c4fc3e4e30..b51bb4b947 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # AC_PREREQ(2.57) -AC_INIT(libssh2, [-], libssh2-devel@cool.haxx.se) +AC_INIT(libssh2, [-], libssh2-devel@lists.haxx.se) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([src]) AC_CONFIG_HEADERS([src/libssh2_config.h]) diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 2e34c4c372..c6ef132798 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -230,7 +230,7 @@ #define PACKAGE "libssh2" /* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "libssh2-devel@cool.haxx.se" +#define PACKAGE_BUGREPORT "libssh2-devel@lists.haxx.se" /* Define to the full name of this package. */ #define PACKAGE_NAME "libssh2" From 4bcf8415a728d8a2148920a47ad7c5a589bb7abe Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Sep 2021 12:56:20 +0200 Subject: [PATCH 007/424] libssh2.h: bump it to 1.10.1-dev --- include/libssh2.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index f17b502e04..6af8cbaf38 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -1,5 +1,5 @@ /* Copyright (c) 2004-2009, Sara Golemon - * Copyright (c) 2009-2015 Daniel Stenberg + * Copyright (c) 2009-2021 Daniel Stenberg * Copyright (c) 2010 Simon Josefsson * All rights reserved. * @@ -40,19 +40,19 @@ #ifndef LIBSSH2_H #define LIBSSH2_H 1 -#define LIBSSH2_COPYRIGHT "2004-2019 The libssh2 project and its contributors." +#define LIBSSH2_COPYRIGHT "2004-2021 The libssh2 project and its contributors." /* We use underscore instead of dash when appending DEV in dev versions just to make the BANNER define (used by src/session.c) be a valid SSH banner. Release versions have no appended strings and may of course not have dashes either. */ -#define LIBSSH2_VERSION "1.9.0_DEV" +#define LIBSSH2_VERSION "1.10.1_DEV" /* The numeric version number is also available "in parts" by using these defines: */ #define LIBSSH2_VERSION_MAJOR 1 -#define LIBSSH2_VERSION_MINOR 9 -#define LIBSSH2_VERSION_PATCH 0 +#define LIBSSH2_VERSION_MINOR 10 +#define LIBSSH2_VERSION_PATCH 1 /* This is the numeric version of the libssh2 version number, meant for easier parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will @@ -69,7 +69,7 @@ and it is always a greater number in a more recent release. It makes comparisons with greater than and less than work. */ -#define LIBSSH2_VERSION_NUM 0x010900 +#define LIBSSH2_VERSION_NUM 0x010a01 /* * This is the date and time when the full source package was created. The From db34d2c4004fcd7282532221bf6648b925bd5a44 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 25 Sep 2021 16:21:33 +0200 Subject: [PATCH 008/424] README: use www.libssh2.org for the license link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14153a3e5c..caa0b6708a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ the revised BSD license. [Mailing list](https://lists.haxx.se/listinfo/libssh2-devel) -[BSD Licensed](https://libssh2.org/license.html) +[BSD Licensed](https://www.libssh2.org/license.html) [Web site source code](https://github.com/libssh2/www) From d39e9ccc5e08a6441075049f1f79ffcb2bbe5a52 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 1 Oct 2021 20:09:03 +0000 Subject: [PATCH 009/424] windows: fix clang and WinCNG warnings Fix these categories of warning: - in `wincng.c` disagreement in signed/unsigned char when passing around the passphrase string: `warning: pointer targets in passing argument [...] differ in signedness [-Wpointer-sign]` Fixed by using `const unsigned char *` in all static functions and applying/updating casts as necessary. - in each use of `libssh2_*_init()` macros where the result is not used: `warning: value computed is not used [-Wunused-value]` Fixed by using `(void)` casts. - `channel.c:1171:7: warning: 'rc' may be used uninitialized in this function [-Wmaybe-uninitialized]` Fixed by initializing this variable with `LIBSSH2_ERROR_CHANNEL_UNKNOWN`. While there I replaced a few 0 literals with `LIBSSH2_ERROR_NONE`. - in `sftp.c`, several of these two warnings: `warning: 'data' may be used uninitialized in this function [-Wmaybe-uninitialized]` `warning: 'data_len' may be used uninitialized in this function [-Wmaybe-uninitialized]` Fixed by initializing these variables with NULL and 0 respectively. - Also removed the exec attribute from `wincng.h`. Notes: - There are many pre-existing checksrc issues. - The `sftp.c` and `channel.c` warnings may apply to other platforms as well. Closes #628 --- src/bcrypt_pbkdf.c | 6 +++--- src/channel.c | 10 ++++++--- src/hostkey.c | 6 +++--- src/kex.c | 12 +++++------ src/sftp.c | 52 +++++++++++++++++++++++----------------------- src/wincng.c | 27 ++++++++++++------------ src/wincng.h | 0 7 files changed, 59 insertions(+), 54 deletions(-) mode change 100755 => 100644 src/wincng.h diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index f782bcac5f..50d542093f 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -127,7 +127,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, memcpy(countsalt, salt, saltlen); /* collapse password */ - libssh2_sha512_init(&ctx); + (void)libssh2_sha512_init(&ctx); libssh2_sha512_update(ctx, pass, passlen); libssh2_sha512_final(ctx, sha2pass); @@ -139,7 +139,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, countsalt[saltlen + 3] = count & 0xff; /* first round, salt is salt */ - libssh2_sha512_init(&ctx); + (void)libssh2_sha512_init(&ctx); libssh2_sha512_update(ctx, countsalt, saltlen + 4); libssh2_sha512_final(ctx, sha2salt); @@ -148,7 +148,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, for(i = 1; i < rounds; i++) { /* subsequent rounds, salt is previous output */ - libssh2_sha512_init(&ctx); + (void)libssh2_sha512_init(&ctx); libssh2_sha512_update(ctx, tmpout, sizeof(tmpout)); libssh2_sha512_final(ctx, sha2salt); diff --git a/src/channel.c b/src/channel.c index 78ed40e877..59133f8ae1 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1140,6 +1140,8 @@ libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel) if(!channel) return LIBSSH2_ERROR_BAD_USE; + rc = LIBSSH2_ERROR_CHANNEL_UNKNOWN; + /* The current RFC draft for agent forwarding says you're supposed to * send "auth-agent-req," but most SSH servers out there right now * actually expect "auth-agent-req@openssh.com", so we try that @@ -1152,7 +1154,8 @@ libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel) /* If we failed (but not with EAGAIN), then we move onto * the next step to try another request type. */ - if(rc != 0 && rc != LIBSSH2_ERROR_EAGAIN) + if(rc != LIBSSH2_ERROR_NONE && + rc != LIBSSH2_ERROR_EAGAIN) channel->req_auth_agent_try_state = libssh2_NB_state_sent; } @@ -1163,12 +1166,13 @@ libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel) /* If we failed without an EAGAIN, then move on with this * state machine. */ - if(rc != 0 && rc != LIBSSH2_ERROR_EAGAIN) + if(rc != LIBSSH2_ERROR_NONE && + rc != LIBSSH2_ERROR_EAGAIN) channel->req_auth_agent_try_state = libssh2_NB_state_sent1; } /* If things are good, reset the try state. */ - if(rc == 0) + if(rc == LIBSSH2_ERROR_NONE) channel->req_auth_agent_try_state = libssh2_NB_state_idle; return rc; diff --git a/src/hostkey.c b/src/hostkey.c index d87a4c744f..d126b611f2 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -211,7 +211,7 @@ hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session, unsigned char hash[SHA_DIGEST_LENGTH]; libssh2_sha1_ctx ctx; - libssh2_sha1_init(&ctx); + (void)libssh2_sha1_init(&ctx); for(i = 0; i < veccount; i++) { libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len); } @@ -438,7 +438,7 @@ hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session, *signature_len = 2 * SHA_DIGEST_LENGTH; - libssh2_sha1_init(&ctx); + (void)libssh2_sha1_init(&ctx); for(i = 0; i < veccount; i++) { libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len); } @@ -683,7 +683,7 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session, unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ libssh2_sha##digest_type##_ctx ctx; \ int i; \ - libssh2_sha##digest_type##_init(&ctx); \ + (void)libssh2_sha##digest_type##_init(&ctx); \ for(i = 0; i < veccount; i++) { \ libssh2_sha##digest_type##_update(ctx, datavec[i].iov_base, \ datavec[i].iov_len); \ diff --git a/src/kex.c b/src/kex.c index 9f3ef79925..c300ecb728 100644 --- a/src/kex.c +++ b/src/kex.c @@ -78,7 +78,7 @@ } \ if(value) \ while(len < (unsigned long)reqlen) { \ - libssh2_sha##digest_type##_init(&hash); \ + (void)libssh2_sha##digest_type##_init(&hash); \ libssh2_sha##digest_type##_update(hash, \ exchange_state->k_value, \ exchange_state->k_value_len); \ @@ -108,16 +108,16 @@ static void _libssh2_sha_algo_ctx_init(int sha_algo, void *ctx) { if(sha_algo == 512) { - libssh2_sha512_init((libssh2_sha512_ctx*)ctx); + (void)libssh2_sha512_init((libssh2_sha512_ctx*)ctx); } else if(sha_algo == 384) { - libssh2_sha384_init((libssh2_sha384_ctx*)ctx); + (void)libssh2_sha384_init((libssh2_sha384_ctx*)ctx); } else if(sha_algo == 256) { - libssh2_sha256_init((libssh2_sha256_ctx*)ctx); + (void)libssh2_sha256_init((libssh2_sha256_ctx*)ctx); } else if(sha_algo == 1) { - libssh2_sha1_init((libssh2_sha1_ctx*)ctx); + (void)libssh2_sha1_init((libssh2_sha1_ctx*)ctx); } else { assert(0); @@ -1600,7 +1600,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange { \ libssh2_sha##digest_type##_ctx ctx; \ exchange_state->exchange_hash = (void *)&ctx; \ - libssh2_sha##digest_type##_init(&ctx); \ + (void)libssh2_sha##digest_type##_init(&ctx); \ if(session->local.banner) { \ _libssh2_htonu32(exchange_state->h_sig_comp, \ strlen((char *) session->local.banner) - 2); \ diff --git a/src/sftp.c b/src/sftp.c index ac7ee01621..b1a53527a8 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -765,7 +765,7 @@ LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor) static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) { unsigned char *data; - size_t data_len; + size_t data_len = 0; ssize_t rc; LIBSSH2_SFTP *sftp_handle; struct string_buf buf; @@ -1561,7 +1561,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, while(chunk) { unsigned char *data; - size_t data_len; + size_t data_len = 0; uint32_t rc32; static const unsigned char read_responses[2] = { SSH_FXP_DATA, SSH_FXP_STATUS @@ -1751,7 +1751,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, LIBSSH2_SFTP *sftp = handle->sftp; LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; uint32_t num_names; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ uint32_t packet_len = handle->handle_len + 13; @@ -2017,10 +2017,10 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, LIBSSH2_SFTP *sftp = handle->sftp; LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; uint32_t retcode; uint32_t packet_len; - unsigned char *s, *data; + unsigned char *s, *data = NULL; ssize_t rc; struct sftp_pipeline_chunk *chunk; struct sftp_pipeline_chunk *next; @@ -2245,8 +2245,8 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle) /* 34 = packet_len(4) + packet_type(1) + request_id(4) + string_len(4) + strlen("fsync@openssh.com")(17) + handle_len(4) */ uint32_t packet_len = handle->handle_len + 34; - size_t data_len; - unsigned char *packet, *s, *data; + size_t data_len = 0; + unsigned char *packet, *s, *data = NULL; ssize_t rc; uint32_t retcode; @@ -2350,11 +2350,11 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP *sftp = handle->sftp; LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ uint32_t packet_len = handle->handle_len + 13 + (setstat ? sftp_attrsize(attrs->flags) : 0); - unsigned char *s, *data; + unsigned char *s, *data = NULL; static const unsigned char fstat_responses[2] = { SSH_FXP_ATTRS, SSH_FXP_STATUS }; ssize_t rc; @@ -2575,7 +2575,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) LIBSSH2_SFTP *sftp = handle->sftp; LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ uint32_t packet_len = handle->handle_len + 13; unsigned char *s, *data = NULL; @@ -2705,11 +2705,11 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, { LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; int retcode; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) */ uint32_t packet_len = filename_len + 13; - unsigned char *s, *data; + unsigned char *s, *data = NULL; int rc; if(sftp->unlink_state == libssh2_NB_state_idle) { @@ -2809,14 +2809,14 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, { LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; int retcode; uint32_t packet_len = source_filename_len + dest_filename_len + 17 + (sftp->version >= 5 ? 4 : 0); /* packet_len(4) + packet_type(1) + request_id(4) + source_filename_len(4) + dest_filename_len(4) + flags(4){SFTP5+) */ - unsigned char *data; + unsigned char *data = NULL; ssize_t rc; if(sftp->version < 2) { @@ -2949,12 +2949,12 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) LIBSSH2_SFTP *sftp = handle->sftp; LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; /* 17 = packet_len(4) + packet_type(1) + request_id(4) + ext_len(4) + handle_len (4) */ /* 20 = strlen ("fstatvfs@openssh.com") */ uint32_t packet_len = handle->handle_len + 20 + 17; - unsigned char *packet, *s, *data; + unsigned char *packet, *s, *data = NULL; ssize_t rc; unsigned int flag; static const unsigned char responses[2] = @@ -3085,12 +3085,12 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, { LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; /* 17 = packet_len(4) + packet_type(1) + request_id(4) + ext_len(4) + path_len (4) */ /* 19 = strlen ("statvfs@openssh.com") */ uint32_t packet_len = path_len + 19 + 17; - unsigned char *packet, *s, *data; + unsigned char *packet, *s, *data = NULL; ssize_t rc; unsigned int flag; static const unsigned char responses[2] = @@ -3225,10 +3225,10 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_SFTP_ATTRIBUTES attrs = { 0, 0, 0, 0, 0, 0, 0 }; - size_t data_len; + size_t data_len = 0; int retcode; ssize_t packet_len; - unsigned char *packet, *s, *data; + unsigned char *packet, *s, *data = NULL; int rc; if(mode != LIBSSH2_SFTP_DEFAULT_MODE) { @@ -3340,11 +3340,11 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, { LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; int retcode; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */ ssize_t packet_len = path_len + 13; - unsigned char *s, *data; + unsigned char *s, *data = NULL; int rc; if(sftp->rmdir_state == libssh2_NB_state_idle) { @@ -3442,13 +3442,13 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, { LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len; + size_t data_len = 0; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */ ssize_t packet_len = path_len + 13 + ((stat_type == LIBSSH2_SFTP_SETSTAT) ? sftp_attrsize(attrs->flags) : 0); - unsigned char *s, *data; + unsigned char *s, *data = NULL; static const unsigned char stat_responses[2] = { SSH_FXP_ATTRS, SSH_FXP_STATUS }; int rc; @@ -3580,12 +3580,12 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, { LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; - size_t data_len, link_len; + size_t data_len = 0, link_len; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */ ssize_t packet_len = path_len + 13 + ((link_type == LIBSSH2_SFTP_SYMLINK) ? (4 + target_len) : 0); - unsigned char *s, *data; + unsigned char *s, *data = NULL; static const unsigned char link_responses[2] = { SSH_FXP_NAME, SSH_FXP_STATUS }; int retcode; diff --git a/src/wincng.c b/src/wincng.c index cbb2b61cb2..9ae8ddeedb 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -664,7 +664,7 @@ _libssh2_wincng_key_sha1_verify(_libssh2_wincng_key_ctx *ctx, static int _libssh2_wincng_load_pem(LIBSSH2_SESSION *session, const char *filename, - const char *passphrase, + const unsigned char *passphrase, const char *headerbegin, const char *headerend, unsigned char **data, @@ -690,7 +690,7 @@ _libssh2_wincng_load_pem(LIBSSH2_SESSION *session, static int _libssh2_wincng_load_private(LIBSSH2_SESSION *session, const char *filename, - const char *passphrase, + const unsigned char *passphrase, unsigned char **ppbEncoded, unsigned long *pcbEncoded, int tryLoadRSA, int tryLoadDSA) @@ -723,7 +723,7 @@ static int _libssh2_wincng_load_private_memory(LIBSSH2_SESSION *session, const char *privatekeydata, size_t privatekeydata_len, - const char *passphrase, + const unsigned char *passphrase, unsigned char **ppbEncoded, unsigned long *pcbEncoded, int tryLoadRSA, int tryLoadDSA) @@ -1148,8 +1148,7 @@ _libssh2_wincng_rsa_new_private(libssh2_rsa_ctx **rsa, (void)session; - ret = _libssh2_wincng_load_private(session, filename, - (const char *)passphrase, + ret = _libssh2_wincng_load_private(session, filename, passphrase, &pbEncoded, &cbEncoded, 1, 0); if(ret) { return -1; @@ -1173,7 +1172,7 @@ _libssh2_wincng_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, LIBSSH2_SESSION *session, const char *filedata, size_t filedata_len, - unsigned const char *passphrase) + const unsigned char *passphrase) { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; @@ -1183,7 +1182,7 @@ _libssh2_wincng_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, (void)session; ret = _libssh2_wincng_load_private_memory(session, filedata, filedata_len, - (const char *)passphrase, + passphrase, &pbEncoded, &cbEncoded, 1, 0); if(ret) { return -1; @@ -1447,8 +1446,7 @@ _libssh2_wincng_dsa_new_private(libssh2_dsa_ctx **dsa, unsigned long cbEncoded; int ret; - ret = _libssh2_wincng_load_private(session, filename, - (const char *)passphrase, + ret = _libssh2_wincng_load_private(session, filename, passphrase, &pbEncoded, &cbEncoded, 0, 1); if(ret) { return -1; @@ -1472,7 +1470,7 @@ _libssh2_wincng_dsa_new_private_frommemory(libssh2_dsa_ctx **dsa, LIBSSH2_SESSION *session, const char *filedata, size_t filedata_len, - unsigned const char *passphrase) + const unsigned char *passphrase) { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; @@ -1480,7 +1478,7 @@ _libssh2_wincng_dsa_new_private_frommemory(libssh2_dsa_ctx **dsa, int ret; ret = _libssh2_wincng_load_private_memory(session, filedata, filedata_len, - (const char *)passphrase, + passphrase, &pbEncoded, &cbEncoded, 0, 1); if(ret) { return -1; @@ -1728,7 +1726,8 @@ _libssh2_wincng_pub_priv_keyfile(LIBSSH2_SESSION *session, unsigned long cbEncoded; int ret; - ret = _libssh2_wincng_load_private(session, privatekey, passphrase, + ret = _libssh2_wincng_load_private(session, privatekey, + (const unsigned char *)passphrase, &pbEncoded, &cbEncoded, 1, 1); if(ret) { return -1; @@ -1767,7 +1766,9 @@ _libssh2_wincng_pub_priv_keyfilememory(LIBSSH2_SESSION *session, int ret; ret = _libssh2_wincng_load_private_memory(session, privatekeydata, - privatekeydata_len, passphrase, + privatekeydata_len, + (const unsigned char *) + passphrase, &pbEncoded, &cbEncoded, 1, 1); if(ret) { return -1; diff --git a/src/wincng.h b/src/wincng.h old mode 100755 new mode 100644 From 1f0fe7443a1ecddd320f2c693607b2afee9bbe2f Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Tue, 26 Oct 2021 18:21:56 +0200 Subject: [PATCH 010/424] Use libssh2_EXPORTS as an alternative to _WINDLL (#470) Files: libssh2.h Notes: `_WINDLL` is only defined when a Visual Studio CMake generator is used, `libssh2_EXPORTS` is used though for all CMake generator if a shared libssh2 library is being built. Credit: Uwe L. Korn --- include/libssh2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libssh2.h b/include/libssh2.h index 6af8cbaf38..d064b3161e 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -100,7 +100,7 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API # ifdef LIBSSH2_WIN32 -# ifdef _WINDLL +# if defined(_WINDLL) || defined(libssh2_EXPORTS) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) # else From 1a799d30ca17f30a9823914037649ecd575b0f4a Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Wed, 27 Oct 2021 15:55:56 +0100 Subject: [PATCH 011/424] ci: Add CIFuzz integration Notes: Add CIFuzz integration to run fuzzer using the OSS-Fuzz infrastructure at each PR. Signed-off-by: David Korczynski Closes #635 --- .github/workflows/cifuzz.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/cifuzz.yml diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml new file mode 100644 index 0000000000..13e80ea319 --- /dev/null +++ b/.github/workflows/cifuzz.yml @@ -0,0 +1,26 @@ +name: CIFuzz +on: [pull_request] +jobs: + Fuzzing: + runs-on: ubuntu-latest + steps: + - name: Build Fuzzers + id: build + uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master + with: + oss-fuzz-project-name: 'libssh2' + dry-run: false + language: c + - name: Run Fuzzers + uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master + with: + oss-fuzz-project-name: 'libssh2' + fuzz-seconds: 600 + dry-run: false + language: c + - name: Upload Crash + uses: actions/upload-artifact@v1 + if: failure() && steps.build.outcome == 'success' + with: + name: artifacts + path: ./out/artifacts From a77ca0fcd3225dbd88b4a73e765068022614f6e0 Mon Sep 17 00:00:00 2001 From: Jun Tseng Date: Thu, 11 Nov 2021 08:09:04 +0800 Subject: [PATCH 012/424] CMake update minimum version to 2.8.12 (#639) File: CMakeLists.txt Notes: Following CMake's advice, Update the minimum required version. Credit: Jun Tseng --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6c95c888c..6f2a222a95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 2.8.12) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) From 3332d95396a3ad91100e62127f7a5393ff9a6555 Mon Sep 17 00:00:00 2001 From: cntrump Date: Fri, 12 Nov 2021 03:35:47 +0800 Subject: [PATCH 013/424] Update maketgz for macOS (#543) File: maketgz Notes: Fix error on macOS: sed: -e: No such file or directory Credit: cntrump --- maketgz | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/maketgz b/maketgz index b88d9608e4..0a3da5dddf 100755 --- a/maketgz +++ b/maketgz @@ -37,7 +37,7 @@ fi datestamp=`LC_TIME=C date -u` # Replace in-place version number in header file: -sed -i -e 's/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION "'$libversion'"/g' \ +sed -i.bak -e 's/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION "'$libversion'"/g' \ -e 's/^#define LIBSSH2_VERSION_NUM .*/#define LIBSSH2_VERSION_NUM 0x'$numeric'/g' \ -e 's/^#define LIBSSH2_VERSION_MAJOR .*/#define LIBSSH2_VERSION_MAJOR '$major'/g' \ -e 's/^#define LIBSSH2_VERSION_MINOR .*/#define LIBSSH2_VERSION_MINOR '$minor'/g' \ @@ -45,6 +45,8 @@ sed -i -e 's/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION "'$libversion'" -e "s/^#define LIBSSH2_TIMESTAMP .*/#define LIBSSH2_TIMESTAMP \"$datestamp\"/g" \ $HEADER +rm -f "$HEADER.bak" + echo "libssh2 version $libversion" echo "libssh2 numerical $numeric" echo "datestamp $datestamp" From 69f3cf0bea540ba1096403ed92eaff58ed7450ad Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Thu, 18 Nov 2021 10:38:32 -0800 Subject: [PATCH 014/424] Fix error message in memory_read_privatekey #636 file: userauth.c note: fix error message credit: volund --- src/userauth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/userauth.c b/src/userauth.c index 40ef9153af..f627d2c651 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -687,7 +687,7 @@ memory_read_privatekey(LIBSSH2_SESSION * session, (unsigned char *) passphrase, hostkey_abstract)) { return _libssh2_error(session, LIBSSH2_ERROR_FILE, - "Unable to initialize private key from file"); + "Unable to initialize private key from memory"); } return 0; From 9990b38d27a63e310a94edd11e6284878a1a34f7 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Tue, 30 Nov 2021 13:21:36 -0800 Subject: [PATCH 015/424] hostkey_method_ssh_ed25519_init() check key bounds (#645) * hostkey_method_ssh_ed25519_init() check key bounds File: hostkey.c Notes: Additional key length checking before calling _libssh2_ed25519_new_public() Credit: Will Cosgrove --- src/hostkey.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/hostkey.c b/src/hostkey.c index d126b611f2..c0e2c6322b 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -841,9 +841,10 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session, size_t hostkey_data_len, void **abstract) { - const unsigned char *s; - unsigned long len, key_len; + size_t key_len; + unsigned char *key; libssh2_ed25519_ctx *ctx = NULL; + struct string_buf buf; if(*abstract) { hostkey_method_ssh_ed25519_dtor(session, abstract); @@ -856,21 +857,18 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session, return -1; } - s = hostkey_data; - len = _libssh2_ntohu32(s); - s += 4; + buf.data = (unsigned char *)hostkey_data; + buf.dataptr = buf.data; + buf.len = hostkey_data_len; - if(len != 11 || strncmp((char *) s, "ssh-ed25519", 11) != 0) { + if(_libssh2_match_string(&buf, "ssh-ed25519")) return -1; - } - - s += 11; /* public key */ - key_len = _libssh2_ntohu32(s); - s += 4; + if(_libssh2_get_string(&buf, &key, &key_len)) + return -1; - if(_libssh2_ed25519_new_public(&ctx, session, s, key_len) != 0) { + if(_libssh2_ed25519_new_public(&ctx, session, key, key_len) != 0) { return -1; } From 1494e6c9f41457414de3ec2ef162ed22532f1379 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Dec 2021 16:48:53 +0100 Subject: [PATCH 016/424] .github/SECURITY.md: add security policy --- .github/SECURITY.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/SECURITY.md diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000000..8d9def05f5 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +See [SECURITY.md](../docs/SECURITY.md) for full details. + +## Reporting a Vulnerability + +If you have found or just suspect a security problem somewhere in libssh2, +email `libssh2-security@haxx.se` about it. + +**Do not submit suspected security issues in the public bug tracker!** + +We treat security issues with confidentiality until controlled and disclosed +responsibly. From 6c662e7b17a9c3ee1f8b03b057d9c6617095dfdd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Dec 2021 16:50:20 +0100 Subject: [PATCH 017/424] .github/SECURITY.md: fix the URL --- .github/SECURITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 8d9def05f5..bc8dcc480a 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -1,6 +1,6 @@ # Security Policy -See [SECURITY.md](../docs/SECURITY.md) for full details. +See [SECURITY.md](https://github.com/libssh2/libssh2/blob/master/docs/SECURITY.md) for full details. ## Reporting a Vulnerability From 37ee0aa214655b63e7869d1d74ff1ec9f9818a5e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Dec 2021 17:46:29 +0100 Subject: [PATCH 018/424] userauth: check for too large userauth_kybd_auth_name_len (#650) ... before using it. Reported-by: MarcoPoloPie Fixes #649 --- src/userauth.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/userauth.c b/src/userauth.c index f627d2c651..8b6da32c9a 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1769,6 +1769,11 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, if(session->userauth_kybd_data_len >= 5) { /* string name (ISO-10646 UTF-8) */ session->userauth_kybd_auth_name_len = _libssh2_ntohu32(s); + if(session->userauth_kybd_auth_name_len > + session->userauth_kybd_data_len - 5) + return _libssh2_error(session, + LIBSSH2_ERROR_OUT_OF_BOUNDARY, + "Bad keyboard auth name"); s += 4; } else { From 552e20df38d443aa8ceb9c1c0cfa69121a1b2f37 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Dec 2021 17:56:29 +0100 Subject: [PATCH 019/424] agent: handle overly large comment lengths (#651) Reported-by: Harry Sintonen --- src/agent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/agent.c b/src/agent.c index 85c3e34afc..a526c779da 100644 --- a/src/agent.c +++ b/src/agent.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2009 by Daiki Ueno - * Copyright (C) 2010-2014 by Daniel Stenberg + * Copyright (C) 2010-2021 by Daniel Stenberg * All rights reserved. * * Redistribution and use in source and binary forms, @@ -541,7 +541,7 @@ agent_list_identities(LIBSSH2_AGENT *agent) while(num_identities--) { struct agent_publickey *identity; - ssize_t comment_len; + size_t comment_len; /* Read the length of the blob */ len -= 4; @@ -586,14 +586,14 @@ agent_list_identities(LIBSSH2_AGENT *agent) comment_len = _libssh2_ntohu32(s); s += 4; - /* Read the comment */ - len -= comment_len; - if(len < 0) { + if(comment_len > (size_t)len) { rc = LIBSSH2_ERROR_AGENT_PROTOCOL; LIBSSH2_FREE(agent->session, identity->external.blob); LIBSSH2_FREE(agent->session, identity); goto error; } + /* Read the comment */ + len -= comment_len; identity->external.comment = LIBSSH2_ALLOC(agent->session, comment_len + 1); From 967792c89625440fe86e0e55ce84082eea9e71a6 Mon Sep 17 00:00:00 2001 From: xalopp Date: Wed, 5 Jan 2022 19:35:26 +0100 Subject: [PATCH 020/424] fix: use userauth name length to check memory boundaries for userauth name, fixes #653 (#654) File: userauth.c Notes: Fixes `userauth_kybd_auth_name_len` length check Co-authored-by: Xaver Lopenstedt --- src/userauth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/userauth.c b/src/userauth.c index 8b6da32c9a..4442eee5c0 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1794,7 +1794,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, "request field"); goto cleanup; } - if(s + session->userauth_list_data_len <= + if(s + session->userauth_kybd_auth_name_len <= session->userauth_kybd_data + session->userauth_kybd_data_len) { memcpy(session->userauth_kybd_auth_name, s, From 64a555d6f5aafed504a10e5b756e85c91b1d56ce Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Thu, 6 Jan 2022 09:50:58 -0800 Subject: [PATCH 021/424] RSA SHA2 256/512 key upgrade support RFC 8332 #536 (#626) Notes: * Host Key RSA 256/512 support #536 * Client side key hash upgrading for RFC 8332 * Support for server-sig-algs, ext-info-c server messages * Customizing preferred server-sig-algs via the preference LIBSSH2_METHOD_SIGN_ALGO Credit: Anders Borum, Will Cosgrove --- docs/HACKING-CRYPTO | 37 ++++++ docs/libssh2_session_methods.3 | 7 +- include/libssh2.h | 1 + src/crypto.h | 32 ++++++ src/hostkey.c | 198 ++++++++++++++++++++++++++++++++- src/kex.c | 22 ++++ src/libgcrypt.c | 18 +++ src/libgcrypt.h | 1 + src/libssh2_priv.h | 8 ++ src/mbedtls.c | 19 ++++ src/mbedtls.h | 1 + src/openssl.c | 94 +++++++++++++++- src/openssl.h | 2 + src/os400qc3.c | 18 +++ src/os400qc3.h | 1 + src/packet.c | 69 ++++++++++++ src/userauth.c | 159 ++++++++++++++++++++++++-- src/wincng.c | 18 +++ src/wincng.h | 1 + 19 files changed, 685 insertions(+), 21 deletions(-) diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index ca94772861..85d813aa62 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -637,6 +637,32 @@ Note: this procedure is not used if macro _libssh2_rsa_sha1_signv() is defined. void _libssh2_rsa_free(libssh2_rsa_ctx *rsactx); Releases the RSA computation context at rsactx. +LIBSSH2_RSA_SHA2 +#define as 1 if the crypto library supports RSA SHA2 256/512, else 0. +If defined as 0, the rest of this section can be omitted. + +int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, + libssh2_rsa_ctx * rsactx, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, + size_t *signature_len); +RSA signs the (hash, hashlen) SHA-2 hash bytes based on hash length and stores +the allocated signature at (signature, signature_len). +Signature buffer must be allocated from the given session. +Returns 0 if OK, else -1. +This procedure is already prototyped in crypto.h. +Note: this procedure is not used if macro _libssh2_rsa_sha1_signv() is defined. + +int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsa, + size_t hash_len, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, unsigned long m_len); +Verify (sig, sig_len) signature of (m, m_len) using an SHA-2 hash based on +hash length and the RSA context. +Return 0 if OK, else -1. +This procedure is already prototyped in crypto.h. 7.2) DSA LIBSSH2_DSA @@ -900,3 +926,14 @@ If this is not needed, it should be defined as an empty macro. int _libssh2_random(unsigned char *buf, int len); Store len random bytes at buf. Returns 0 if OK, else -1. + +const char * _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, + unsigned char *key_method, + size_t key_method_len); + +This function is for implementing key hash upgrading as defined in RFC 8332. + +Based on the incoming key_method value, this function will return a +list of supported algorithms that can upgrade the original key method algorithm +as a comma seperated list, if there is no upgrade option this function should +return NULL. diff --git a/docs/libssh2_session_methods.3 b/docs/libssh2_session_methods.3 index cc4f6d49f4..0e7f79fa96 100644 --- a/docs/libssh2_session_methods.3 +++ b/docs/libssh2_session_methods.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_methods 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_methods 3 "8 Nov 2021" "libssh2 1.11" "libssh2 manual" .SH NAME libssh2_session_methods - return the currently active algorithms .SH SYNOPSIS @@ -8,13 +8,14 @@ const char * libssh2_session_methods(LIBSSH2_SESSION *session, int method_type); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fImethod_type\fP - one of the method type constants: LIBSSH2_METHOD_KEX, LIBSSH2_METHOD_HOSTKEY, LIBSSH2_METHOD_CRYPT_CS, LIBSSH2_METHOD_CRYPT_SC, LIBSSH2_METHOD_MAC_CS, LIBSSH2_METHOD_MAC_SC, LIBSSH2_METHOD_COMP_CS, -LIBSSH2_METHOD_COMP_SC, LIBSSH2_METHOD_LANG_CS, LIBSSH2_METHOD_LANG_SC. +LIBSSH2_METHOD_COMP_SC, LIBSSH2_METHOD_LANG_CS, LIBSSH2_METHOD_LANG_SC, +LIBSSH2_METHOD_SIGN_ALGO. Returns the actual method negotiated for a particular transport parameter. .SH RETURN VALUE diff --git a/include/libssh2.h b/include/libssh2.h index d064b3161e..b9ae8092c8 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -356,6 +356,7 @@ typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE #define LIBSSH2_METHOD_COMP_SC 7 #define LIBSSH2_METHOD_LANG_CS 8 #define LIBSSH2_METHOD_LANG_SC 9 +#define LIBSSH2_METHOD_SIGN_ALGO 10 /* flags */ #define LIBSSH2_FLAG_SIGPIPE 1 diff --git a/src/crypto.h b/src/crypto.h index f512d60398..809aef7e99 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -93,6 +93,19 @@ int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, size_t hash_len, unsigned char **signature, size_t *signature_len); +#if LIBSSH2_RSA_SHA2 +int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, + libssh2_rsa_ctx * rsactx, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, + size_t *signature_len); +int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsa, + size_t hash_len, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, unsigned long m_len); +#endif int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, LIBSSH2_SESSION * session, const char *filedata, @@ -245,4 +258,23 @@ int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, size_t privatekeydata_len, const char *passphrase); + +/** + * @function _libssh2_supported_key_sign_algorithms + * @abstract Returns supported algorithms used for upgrading public + * key signing RFC 8332 + * @discussion Based on the incoming key_method value, this function + * will return supported algorithms that can upgrade the key method + * @related _libssh2_key_sign_algorithm() + * @param key_method current key method, usually the default key sig method + * @param key_method_len length of the key method buffer + * @result comma seperated list of supported upgrade options per RFC 8332, if + * there is no upgrade option return NULL + */ + +const char * +_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, + unsigned char *key_method, + size_t key_method_len); + #endif /* __LIBSSH2_CRYPTO_H */ diff --git a/src/hostkey.c b/src/hostkey.c index c0e2c6322b..f005d90fcb 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -64,8 +64,8 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, void **abstract) { libssh2_rsa_ctx *rsactx; - unsigned char *e, *n; - size_t e_len, n_len; + unsigned char *e, *n, *type; + size_t e_len, n_len, type_len; struct string_buf buf; if(*abstract) { @@ -83,8 +83,27 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, buf.dataptr = buf.data; buf.len = hostkey_data_len; - if(_libssh2_match_string(&buf, "ssh-rsa")) + if(_libssh2_get_string(&buf, &type, &type_len)) { return -1; + } + + /* we accept one of 3 header types */ + if(type_len == 7 && strncmp("ssh-rsa", (char *)type, 7) == 0) { + /* ssh-rsa */ + } +#if LIBSSH2_RSA_SHA2 + else if(type_len == 12 && strncmp("rsa-sha2-256", (char *)type, 12) == 0) { + /* rsa-sha2-256 */ + } + else if(type_len == 12 && strncmp("rsa-sha2-512", (char *)type, 12) == 0) { + /* rsa-sha2-512 */ + } +#endif + else { + _libssh2_debug(session, LIBSSH2_TRACE_ERROR, + "unexpected rsa type: %.*s", type_len, type); + return -1; + } if(_libssh2_get_string(&buf, &e, &e_len)) return -1; @@ -227,6 +246,146 @@ hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session, #endif } +/* + * hostkey_method_ssh_rsa_sha2_256_sig_verify + * + * Verify signature created by remote + */ +#if LIBSSH2_RSA_SHA2 + +static int +hostkey_method_ssh_rsa_sha2_256_sig_verify(LIBSSH2_SESSION * session, + const unsigned char *sig, + size_t sig_len, + const unsigned char *m, + size_t m_len, void **abstract) +{ + libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); + (void) session; + + /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-256"} + + signature_len(4) */ + if(sig_len < 20) + return -1; + + sig += 20; + sig_len -= 20; + return _libssh2_rsa_sha2_verify(rsactx, SHA256_DIGEST_LENGTH, sig, sig_len, + m, m_len); +} + +/* + * hostkey_method_ssh_rsa_sha2_256_signv + * + * Construct a signature from an array of vectors + */ + +static int +hostkey_method_ssh_rsa_sha2_256_signv(LIBSSH2_SESSION * session, + unsigned char **signature, + size_t *signature_len, + int veccount, + const struct iovec datavec[], + void **abstract) +{ + libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); + +#ifdef _libssh2_rsa_sha2_256_signv + return _libssh2_rsa_sha2_256_signv(session, signature, signature_len, + veccount, datavec, rsactx); +#else + int ret; + int i; + unsigned char hash[SHA256_DIGEST_LENGTH]; + libssh2_sha256_ctx ctx; + + libssh2_sha256_init(&ctx); + for(i = 0; i < veccount; i++) { + libssh2_sha256_update(ctx, datavec[i].iov_base, datavec[i].iov_len); + } + libssh2_sha256_final(ctx, hash); + + ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA256_DIGEST_LENGTH, + signature, signature_len); + if(ret) { + return -1; + } + + return 0; +#endif +} + +/* + * hostkey_method_ssh_rsa_sha2_512_sig_verify + * + * Verify signature created by remote + */ + +static int +hostkey_method_ssh_rsa_sha2_512_sig_verify(LIBSSH2_SESSION * session, + const unsigned char *sig, + size_t sig_len, + const unsigned char *m, + size_t m_len, void **abstract) +{ + libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); + (void) session; + + /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-512"} + + signature_len(4) */ + if(sig_len < 20) + return -1; + + sig += 20; + sig_len -= 20; + return _libssh2_rsa_sha2_verify(rsactx, SHA512_DIGEST_LENGTH, sig, + sig_len, m, m_len); +} + + +/* + * hostkey_method_ssh_rsa_sha2_512_signv + * + * Construct a signature from an array of vectors + */ +static int +hostkey_method_ssh_rsa_sha2_512_signv(LIBSSH2_SESSION * session, + unsigned char **signature, + size_t *signature_len, + int veccount, + const struct iovec datavec[], + void **abstract) +{ + libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); + +#ifdef _libssh2_rsa_sha2_512_signv + return _libssh2_rsa_sha2_512_signv(session, signature, signature_len, + veccount, datavec, rsactx); +#else + int ret; + int i; + unsigned char hash[SHA512_DIGEST_LENGTH]; + libssh2_sha512_ctx ctx; + + libssh2_sha512_init(&ctx); + for(i = 0; i < veccount; i++) { + libssh2_sha512_update(ctx, datavec[i].iov_base, datavec[i].iov_len); + } + libssh2_sha512_final(ctx, hash); + + ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA512_DIGEST_LENGTH, + signature, signature_len); + if(ret) { + return -1; + } + + return 0; +#endif +} + +#endif /* LIBSSH2_RSA_SHA2 */ + + /* * hostkey_method_ssh_rsa_dtor * @@ -260,6 +419,35 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = { NULL, /* encrypt */ hostkey_method_ssh_rsa_dtor, }; + +#if LIBSSH2_RSA_SHA2 + +static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_256 = { + "rsa-sha2-256", + SHA256_DIGEST_LENGTH, + hostkey_method_ssh_rsa_init, + hostkey_method_ssh_rsa_initPEM, + hostkey_method_ssh_rsa_initPEMFromMemory, + hostkey_method_ssh_rsa_sha2_256_sig_verify, + hostkey_method_ssh_rsa_sha2_256_signv, + NULL, /* encrypt */ + hostkey_method_ssh_rsa_dtor, +}; + +static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_512 = { + "rsa-sha2-512", + SHA512_DIGEST_LENGTH, + hostkey_method_ssh_rsa_init, + hostkey_method_ssh_rsa_initPEM, + hostkey_method_ssh_rsa_initPEMFromMemory, + hostkey_method_ssh_rsa_sha2_512_sig_verify, + hostkey_method_ssh_rsa_sha2_512_signv, + NULL, /* encrypt */ + hostkey_method_ssh_rsa_dtor, +}; + +#endif /* LIBSSH2_RSA_SHA2 */ + #endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA @@ -1041,6 +1229,10 @@ static const LIBSSH2_HOSTKEY_METHOD *hostkey_methods[] = { &hostkey_method_ssh_ed25519, #endif #if LIBSSH2_RSA +#if LIBSSH2_RSA_SHA2 + &hostkey_method_ssh_rsa_sha2_512, + &hostkey_method_ssh_rsa_sha2_256, +#endif /* LIBSSH2_RSA_SHA2 */ &hostkey_method_ssh_rsa, #endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA diff --git a/src/kex.c b/src/kex.c index c300ecb728..8f028084a9 100644 --- a/src/kex.c +++ b/src/kex.c @@ -3026,6 +3026,17 @@ kex_method_ssh_curve25519_sha256 = { }; #endif +/* this kex method signals that client can receive extensions + * as described in https://datatracker.ietf.org/doc/html/rfc8308 +*/ + +static const LIBSSH2_KEX_METHOD +kex_method_extension_negotiation = { + "ext-info-c", + NULL, + 0, +}; + static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { #if LIBSSH2_ED25519 &kex_method_ssh_curve25519_sha256, @@ -3043,6 +3054,7 @@ static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { &kex_method_diffie_helman_group14_sha1, &kex_method_diffie_helman_group1_sha1, &kex_method_diffie_helman_group_exchange_sha1, + &kex_method_extension_negotiation, NULL }; @@ -3978,6 +3990,11 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, mlist = NULL; break; + case LIBSSH2_METHOD_SIGN_ALGO: + prefvar = &session->sign_algo_prefs; + mlist = NULL; + break; + default: return _libssh2_error(session, LIBSSH2_ERROR_INVAL, "Invalid parameter specified for method_type"); @@ -4073,6 +4090,11 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, _libssh2_comp_methods(session); break; + case LIBSSH2_METHOD_SIGN_ALGO: + /* no built-in supported list due to backend support */ + mlist = NULL; + break; + default: return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, "Unknown method type"); diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 0aff176a61..f6e9b64a3c 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -664,4 +664,22 @@ _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx) *dhctx = NULL; } +/* _libssh2_supported_key_sign_algorithms + * + * Return supported key hash algo upgrades, see crypto.h + * + */ + +const char * +_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, + unsigned char *key_method, + size_t key_method_len) +{ + (void)session; + (void)key_method; + (void)key_method_len; + + return NULL; +} + #endif /* LIBSSH2_LIBGCRYPT */ diff --git a/src/libgcrypt.h b/src/libgcrypt.h index 298c65ed05..95876b96d1 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -55,6 +55,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA2 0 #define LIBSSH2_DSA 1 #define LIBSSH2_ECDSA 0 #define LIBSSH2_ED25519 0 diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index da488b744c..aff791e7cd 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -640,6 +640,13 @@ struct _LIBSSH2_SESSION unsigned char server_hostkey_sha256[SHA256_DIGEST_LENGTH]; int server_hostkey_sha256_valid; + /* public key algorithms accepted as comma separated list */ + char *server_sign_algorithms; + size_t server_sign_algorithms_len; + + /* key signing algorithm preferences -- NULL yields server order */ + char *sign_algo_prefs; + /* (remote as source of data -- packet_read ) */ libssh2_endpoint_data remote; @@ -1006,6 +1013,7 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...) #define SSH_MSG_DEBUG 4 #define SSH_MSG_SERVICE_REQUEST 5 #define SSH_MSG_SERVICE_ACCEPT 6 +#define SSH_MSG_EXT_INFO 7 #define SSH_MSG_KEXINIT 20 #define SSH_MSG_NEWKEYS 21 diff --git a/src/mbedtls.c b/src/mbedtls.c index 4629ce4a95..dc76ef59a9 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -1247,5 +1247,24 @@ _libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx) mbedtls_free(ctx); } + +/* _libssh2_supported_key_sign_algorithms + * + * Return supported key hash algo upgrades, see crypto.h + * + */ + +const char * +_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, + unsigned char *key_method, + size_t key_method_len) +{ + (void)session; + (void)key_method; + (void)key_method_len; + + return NULL; +} + #endif /* LIBSSH2_ECDSA */ #endif /* LIBSSH2_MBEDTLS */ diff --git a/src/mbedtls.h b/src/mbedtls.h index 671932c582..0450113f06 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -71,6 +71,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA2 0 #define LIBSSH2_DSA 0 #ifdef MBEDTLS_ECDSA_C # define LIBSSH2_ECDSA 1 diff --git a/src/openssl.c b/src/openssl.c index 7a6810f13c..72a85b3b63 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -154,21 +154,57 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, } int -_libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, +_libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, + size_t hash_len, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, unsigned long m_len) { - unsigned char hash[SHA_DIGEST_LENGTH]; int ret; + int nid_type; + unsigned char *hash = malloc(hash_len); + if(hash == NULL) + return -1; + + if(hash_len == SHA_DIGEST_LENGTH) { + nid_type = NID_sha1; + ret = _libssh2_sha1(m, m_len, hash); + } + else if(hash_len == SHA256_DIGEST_LENGTH) { + nid_type = NID_sha256; + ret = _libssh2_sha256(m, m_len, hash); + + } + else if(hash_len == SHA512_DIGEST_LENGTH) { + nid_type = NID_sha512; + ret = _libssh2_sha512(m, m_len, hash); + } + else + ret = -1; /* unsupported digest */ - if(_libssh2_sha1(m, m_len, hash)) + if(ret != 0) { + free(hash); return -1; /* failure */ - ret = RSA_verify(NID_sha1, hash, SHA_DIGEST_LENGTH, + } + + ret = RSA_verify(nid_type, hash, hash_len, (unsigned char *) sig, sig_len, rsactx); + + free(hash); + return (ret == 1) ? 0 : -1; } +int +_libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, unsigned long m_len) +{ + return _libssh2_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, sig, sig_len, m, + m_len); +} + #if LIBSSH2_DSA int _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, @@ -1876,7 +1912,7 @@ _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, int -_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, +_libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, libssh2_rsa_ctx * rsactx, const unsigned char *hash, size_t hash_len, @@ -1893,7 +1929,17 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, return -1; } - ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx); + if(hash_len == SHA_DIGEST_LENGTH) + ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx); + else if(hash_len == SHA256_DIGEST_LENGTH) + ret = RSA_sign(NID_sha256, hash, hash_len, sig, &sig_len, rsactx); + else if(hash_len == SHA512_DIGEST_LENGTH) + ret = RSA_sign(NID_sha512, hash, hash_len, sig, &sig_len, rsactx); + else { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Unsupported hash digest length"); + ret = -1; + } if(!ret) { LIBSSH2_FREE(session, sig); @@ -1906,6 +1952,19 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, return 0; } + +int +_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, + libssh2_rsa_ctx * rsactx, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, size_t *signature_len) +{ + return _libssh2_rsa_sha2_sign(session, rsactx, hash, hash_len, + signature, signature_len); +} + + #if LIBSSH2_DSA int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, @@ -3283,4 +3342,27 @@ _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx) *dhctx = NULL; } +/* _libssh2_supported_key_sign_algorithms + * + * Return supported key hash algo upgrades, see crypto.h + * + */ + +const char * +_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, + unsigned char *key_method, + size_t key_method_len) +{ + (void)session; + +#if LIBSSH2_RSA_SHA2 + if(key_method_len == 7 && + memcmp(key_method, "ssh-rsa", key_method_len) == 0) { + return "rsa-sha2-512,rsa-sha2-256,ssh-rsa"; + } +#endif + + return NULL; +} + #endif /* LIBSSH2_OPENSSL */ diff --git a/src/openssl.h b/src/openssl.h index 658b040d65..2a002b41e5 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -64,8 +64,10 @@ #ifdef OPENSSL_NO_RSA # define LIBSSH2_RSA 0 +# define LIBSSH2_RSA_SHA2 0 #else # define LIBSSH2_RSA 1 +# define LIBSSH2_RSA_SHA2 1 #endif #ifdef OPENSSL_NO_DSA diff --git a/src/os400qc3.c b/src/os400qc3.c index f05bfabf37..daed1e5d95 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -2409,6 +2409,24 @@ _libssh2_os400qc3_rsa_sha1_signv(LIBSSH2_SESSION *session, return 0; } +/* _libssh2_supported_key_sign_algorithms + * + * Return supported key hash algo upgrades, see crypto.h + * + */ + +const char * +_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, + unsigned char *key_method, + size_t key_method_len) +{ + (void)session; + (void)key_method; + (void)key_method_len; + + return NULL; +} + #endif /* LIBSSH2_OS400QC3 */ /* vim: set expandtab ts=4 sw=4: */ diff --git a/src/os400qc3.h b/src/os400qc3.h index e3602d9f92..7bcef23364 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -175,6 +175,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA2 0 #define LIBSSH2_DSA 0 #define LIBSSH2_ECDSA 0 #define LIBSSH2_ED25519 0 diff --git a/src/packet.c b/src/packet.c index 04937d62a7..686be5cc7c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -615,6 +615,75 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, session->packAdd_state = libssh2_NB_state_idle; return 0; + /* + byte SSH_MSG_EXT_INFO + uint32 nr-extensions + [repeat "nr-extensions" times] + string extension-name [RFC8308] + string extension-value (binary) + */ + + case SSH_MSG_EXT_INFO: + if(datalen >= 5) { + uint32_t nr_extensions = 0; + struct string_buf buf; + buf.data = (unsigned char *)data; + buf.dataptr = buf.data; + buf.len = datalen; + buf.dataptr += 1; /* advance past type */ + + if(_libssh2_get_u32(&buf, &nr_extensions) != 0) { + rc = _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Invalid extension info received"); + } + + while(rc == 0 && nr_extensions > 0) { + + size_t name_len = 0; + size_t value_len = 0; + unsigned char *name = NULL; + unsigned char *value = NULL; + + nr_extensions -= 1; + + _libssh2_get_string(&buf, &name, &name_len); + _libssh2_get_string(&buf, &value, &value_len); + + if(name != NULL && value != NULL) { + _libssh2_debug(session, + LIBSSH2_TRACE_KEX, + "Server to Client extension %.*s: %.*s", + name_len, name, value_len, value); + } + + if(name_len == 15 && + memcmp(name, "server-sig-algs", 15) == 0) { + if(session->server_sign_algorithms) { + LIBSSH2_FREE(session, + session->server_sign_algorithms); + } + + session->server_sign_algorithms = + LIBSSH2_ALLOC(session, + value_len); + + if(session->server_sign_algorithms) { + session->server_sign_algorithms_len = value_len; + memcpy(session->server_sign_algorithms, + value, value_len); + } + else { + rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "memory for server sign algo"); + } + } + } + } + + LIBSSH2_FREE(session, data); + session->packAdd_state = libssh2_NB_state_idle; + return rc; + /* byte SSH_MSG_GLOBAL_REQUEST string request name in US-ASCII only diff --git a/src/userauth.c b/src/userauth.c index 4442eee5c0..988dc17fff 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1086,6 +1086,148 @@ static int plain_method_len(const char *method, size_t method_len) return method_len; } +/** + * @function _libssh2_key_sign_algorithm + * @abstract Upgrades the algorithm used for public key signing RFC 8332 + * @discussion Based on the incoming key_method value, this function + * will upgrade the key method input based on user preferences, + * server support algos and crypto backend support + * @related _libssh2_supported_key_sign_algorithms() + * @param key_method current key method, usually the default key sig method + * @param key_method_len length of the key method buffer + * @result error code or zero on success + */ + +static int +_libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, + unsigned char **key_method, + size_t *key_method_len) +{ + const char *s = NULL; + const char *a = NULL; + const char *match = NULL; + const char *p = NULL; + const char *f = NULL; + char *i = NULL; + int p_len = 0; + int f_len = 0; + int rc = 0; + int match_len = 0; + char *filtered_algs = NULL; + + const char *supported_algs = + _libssh2_supported_key_sign_algorithms(session, + *key_method, + *key_method_len); + + if(supported_algs == NULL || session->server_sign_algorithms == NULL) { + /* no upgrading key algorithm supported, do nothing */ + return LIBSSH2_ERROR_NONE; + } + + filtered_algs = LIBSSH2_ALLOC(session, strlen(supported_algs) + 1); + if(!filtered_algs) { + rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate filtered algs"); + return rc; + } + + s = session->server_sign_algorithms; + i = filtered_algs; + + /* this walks the server algo list and the supported algo list and creates + a filtered list that includes matches */ + + while(s && *s) { + p = strchr(s, ','); + p_len = p ? (p - s) : (int) strlen(s); + a = supported_algs; + + while(a && *a) { + f = strchr(a, ','); + f_len = f ? (f - a) : (int) strlen(a); + + if(f_len == p_len && memcmp(a, s, p_len)) { + + if(i != filtered_algs) { + memcpy(i, ",", 1); + i += 1; + } + + memcpy(i, s, p_len); + i += p_len; + } + + a = f ? (f + 1) : NULL; + } + + s = p ? (p + 1) : NULL; + } + + filtered_algs[i - filtered_algs] = '\0'; + + if(session->sign_algo_prefs) { + s = session->sign_algo_prefs; + } + else { + s = supported_algs; + } + + /* now that we have the possible supported algos, match based on the prefs + or what is supported by the crypto backend, look for a match */ + + while(s && *s && !match) { + p = strchr(s, ','); + p_len = p ? (p - s) : (int) strlen(s); + a = filtered_algs; + + while(a && *a && !match) { + f = strchr(a, ','); + f_len = f ? (f - a) : (int) strlen(a); + + if(f_len == p_len && memcmp(a, s, p_len)) { + /* found a match, upgrade key method */ + match = s; + match_len = p_len; + } + else { + a = f ? (f + 1) : NULL; + } + } + + s = p ? (p + 1) : NULL; + } + + if(match != NULL) { + if(*key_method) + LIBSSH2_FREE(session, *key_method); + + *key_method = LIBSSH2_ALLOC(session, match_len); + if(key_method) { + memcpy(*key_method, match, match_len); + *key_method_len = match_len; + + _libssh2_debug(session, LIBSSH2_TRACE_KEX, + "Signing using %.*s", match_len, match); + } + else { + *key_method_len = 0; + rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate key method upgrade"); + } + } + else { + /* no match was found */ + rc = _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, + "No signing signature matched"); + } + + if(filtered_algs) + LIBSSH2_FREE(session, filtered_algs); + + return rc; +} + int _libssh2_userauth_publickey(LIBSSH2_SESSION *session, const char *username, @@ -1144,15 +1286,14 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, memcpy(session->userauth_pblc_method, pubkeydata + 4, session->userauth_pblc_method_len); } - /* - * The length of the method name read from plaintext prefix in the - * file must match length embedded in the key. - * TODO: The data should match too but we don't check that. Should we? - */ - else if(session->userauth_pblc_method_len != - _libssh2_ntohu32(pubkeydata)) - return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, - "Invalid public key"); + + /* upgrade key key signing algo needed */ + rc = _libssh2_key_sign_algorithm(session, + &session->userauth_pblc_method, + &session->userauth_pblc_method_len); + + if(rc) + return rc; /* * 45 = packet_type(1) + username_len(4) + servicename_len(4) + diff --git a/src/wincng.c b/src/wincng.c index 9ae8ddeedb..58e2251f20 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -2591,4 +2591,22 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, return _libssh2_wincng_bignum_mod_exp(secret, f, dhctx->bn, p); } +/* _libssh2_supported_key_sign_algorithms + * + * Return supported key hash algo upgrades, see crypto.h + * + */ + +const char * +_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, + unsigned char *key_method, + size_t key_method_len) +{ + (void)session; + (void)key_method; + (void)key_method_len; + + return NULL; +} + #endif /* LIBSSH2_WINCNG */ diff --git a/src/wincng.h b/src/wincng.h index eaf6f9051a..538cc4314f 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -63,6 +63,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA2 0 #define LIBSSH2_DSA 1 #define LIBSSH2_ECDSA 0 #define LIBSSH2_ED25519 0 From e24a4a9d48110c3095189e9336f85fac803b9ddf Mon Sep 17 00:00:00 2001 From: Bastien Durel Date: Thu, 6 Jan 2022 19:06:02 +0100 Subject: [PATCH 022/424] Runtime engine detection with libssh2_crypto_engine() (#643) File: version.c, HACKING-CRYPTO, libssh2.h, libssh2_crypto_engine.3, makefile. Notes: libssh2_crypto_engine() API to get crypto engine at runtime. Credit: Bastien Durel --- docs/CMakeLists.txt | 1 + docs/HACKING-CRYPTO | 4 ++++ docs/Makefile.am | 1 + docs/libssh2_crypto_engine.3 | 12 ++++++++++++ include/libssh2.h | 13 +++++++++++++ src/version.c | 16 ++++++++++++++++ 6 files changed, 47 insertions(+) create mode 100644 docs/libssh2_crypto_engine.3 diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 6abf0e4989..f439db719f 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -92,6 +92,7 @@ set(MAN_PAGES libssh2_channel_write_stderr.3 libssh2_channel_x11_req.3 libssh2_channel_x11_req_ex.3 + libssh2_crypto_engine.3 libssh2_exit.3 libssh2_free.3 libssh2_hostkey_hash.3 diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index 85d813aa62..c0fe3711a7 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -53,6 +53,10 @@ Initializes the crypto library. May be an empty macro if not needed. void libssh2_crypto_exit(void); Terminates the crypto library use. May be an empty macro if not needed. +1.1) Crypto runtime detection + +The libssh2_crypto_engine_t enum must include the new engine, and +libssh2_crypto_engine() must return it when it's built in. 2) HMAC diff --git a/docs/Makefile.am b/docs/Makefile.am index a80943122d..f0a71fc5a8 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -62,6 +62,7 @@ dist_man_MANS = \ libssh2_channel_write_stderr.3 \ libssh2_channel_x11_req.3 \ libssh2_channel_x11_req_ex.3 \ + libssh2_crypto_engine.3 \ libssh2_exit.3 \ libssh2_free.3 \ libssh2_hostkey_hash.3 \ diff --git a/docs/libssh2_crypto_engine.3 b/docs/libssh2_crypto_engine.3 new file mode 100644 index 0000000000..268ac0e517 --- /dev/null +++ b/docs/libssh2_crypto_engine.3 @@ -0,0 +1,12 @@ +.TH libssh2_crypto_engine 3 "22 Nov 2021" "libssh2 1.11" "libssh2 manual" +.SH NAME + - retrieve used crypto engine +.SH SYNOPSIS +#include + +libssh2_crypto_engine_t +libssh2_crypto_engine(); +.SH DESCRIPTION +Returns currently used crypto engine, as en enum value. +.SH AVAILABILITY +Added in libssh2 1.11 diff --git a/include/libssh2.h b/include/libssh2.h index b9ae8092c8..8db3015e78 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -940,8 +940,21 @@ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, LIBSSH2_API const char *libssh2_version(int req_version_num); +typedef enum { + libssh2_no_crypto = 0, + libssh2_openssl, + libssh2_gcrypt, + libssh2_mbedtls, + libssh2_wincng +} libssh2_crypto_engine_t; + +LIBSSH2_API +libssh2_crypto_engine_t libssh2_crypto_engine(void); + #define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */ #define HAVE_LIBSSH2_VERSION_API 0x010100 /* libssh2_version since 1.1 */ +#define HAVE_LIBSSH2_CRYPTOENGINE_API 0x011100 /* libssh2_crypto_engine + since 1.11 */ struct libssh2_knownhost { unsigned int magic; /* magic stored by the library */ diff --git a/src/version.c b/src/version.c index 408f83a398..0e2366694e 100644 --- a/src/version.c +++ b/src/version.c @@ -52,3 +52,19 @@ const char *libssh2_version(int req_version_num) return LIBSSH2_VERSION; return NULL; /* this is not a suitable library! */ } + +LIBSSH2_API +libssh2_crypto_engine_t libssh2_crypto_engine() +{ +#if defined LIBSSH2_OPENSSL + return libssh2_openssl; +#elif defined LIBSSH2_LIBGCRYPT + return libssh2_gcrypt; +#elif defined LIBSSH2_MBEDTLS + return libssh2_mbedtls; +#elif defined LIBSSH2_WINCNG + return libssh2_wincng; +#else + return libssh2_no_crypto; +#endif +} From 17c9c1fcdf48ea033a307ce77c432f039ead4584 Mon Sep 17 00:00:00 2001 From: Hayden Roche Date: Thu, 6 Jan 2022 10:25:34 -0800 Subject: [PATCH 023/424] Add support for a wolfSSL crypto backend. (#629) It uses wolfSSL's OpenSSL compatibility layer, so rather than introduce new wolfssl.h/c files, the new backend just reuses openssl.h/c. Additionally, replace EVP_Cipher() calls with EVP_CipherUpdate(), since EVP_Cipher() is not recommended. Credit: Hayden Roche --- Makefile.wolfSSL.inc | 3 +++ acinclude.m4 | 13 +++++++++++++ configure.ac | 1 + src/Makefile.am | 3 +++ src/crypto.h | 2 +- src/openssl.c | 16 +++++---------- src/openssl.h | 46 +++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 Makefile.wolfSSL.inc diff --git a/Makefile.wolfSSL.inc b/Makefile.wolfSSL.inc new file mode 100644 index 0000000000..24fed511f8 --- /dev/null +++ b/Makefile.wolfSSL.inc @@ -0,0 +1,3 @@ +CRYPTO_CSOURCES = openssl.c +CRYPTO_HHEADERS = openssl.h +CRYPTO_LTLIBS = -lwolfssl diff --git a/acinclude.m4 b/acinclude.m4 index 2066f0ec9b..63d5d5cdb3 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -431,6 +431,19 @@ m4_case([$1], ]) ], +[wolfssl], [ + if test "${with_libwolfssl_prefix+set}" = set; then + CPPFLAGS="$CPPFLAGS${CPPFLAGS:+ }-I${with_libwolfssl_prefix}/include/wolfssl" + else + AC_MSG_ERROR([When using wolfSSL, must specify prefix with --with-libwolfssl-prefix in order to find OpenSSL compatibility headers.]) + fi + LIBSSH2_LIB_HAVE_LINKFLAGS([wolfssl], [], [#include ], [ + AC_DEFINE(LIBSSH2_WOLFSSL, 1, [Use $1]) + LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }libwolfssl" + found_crypto="$1" + ]) +], + [libgcrypt], [ LIBSSH2_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include ], [ AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use $1]) diff --git a/configure.ac b/configure.ac index b51bb4b947..ca3cbee164 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,7 @@ m4_set_add([crypto_backends], [openssl]) m4_set_add([crypto_backends], [libgcrypt]) m4_set_add([crypto_backends], [mbedtls]) m4_set_add([crypto_backends], [wincng]) +m4_set_add([crypto_backends], [wolfssl]) AC_ARG_WITH([crypto], AC_HELP_STRING([--with-crypto=auto|]m4_set_contents([crypto_backends], [|]), diff --git a/src/Makefile.am b/src/Makefile.am index 31d58ed573..46cb88cf22 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,9 @@ AUTOMAKE_OPTIONS = foreign nostdinc if OPENSSL include ../Makefile.OpenSSL.inc endif +if WOLFSSL +include ../Makefile.wolfSSL.inc +endif if LIBGCRYPT include ../Makefile.libgcrypt.inc endif diff --git a/src/crypto.h b/src/crypto.h index 809aef7e99..7a99b4f3da 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -38,7 +38,7 @@ * OF SUCH DAMAGE. */ -#ifdef LIBSSH2_OPENSSL +#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) #include "openssl.h" #endif diff --git a/src/openssl.c b/src/openssl.c index 72a85b3b63..857110f3ca 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -40,7 +40,8 @@ #include "libssh2_priv.h" -#ifdef LIBSSH2_OPENSSL /* compile only if we build with openssl */ +/* compile only if we build with openssl or wolfSSL */ +#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) #include #include "misc.h" @@ -455,27 +456,20 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, { unsigned char buf[EVP_MAX_BLOCK_LENGTH]; int ret; + int outlen; (void) algo; (void) encrypt; #ifdef HAVE_OPAQUE_STRUCTS - ret = EVP_Cipher(*ctx, buf, block, blocksize); + ret = EVP_CipherUpdate(*ctx, buf, &outlen, block, blocksize); #else - ret = EVP_Cipher(ctx, buf, block, blocksize); + ret = EVP_CipherUpdate(ctx, buf, &outlen, block, blocksize); #endif -#if defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3 - if(ret != -1) { -#else if(ret == 1) { -#endif memcpy(block, buf, blocksize); } -#if defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3 - return ret != -1 ? 0 : 1; -#else return ret == 1 ? 0 : 1; -#endif } #if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR) diff --git a/src/openssl.h b/src/openssl.h index 2a002b41e5..3eef023687 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -39,6 +39,43 @@ * OF SUCH DAMAGE. */ +#ifdef LIBSSH2_WOLFSSL + +#include +#include + +#if defined(NO_DSA) || defined(HAVE_FIPS) +#define OPENSSL_NO_DSA +#endif + +#if defined(NO_MD5) || defined(HAVE_FIPS) +#define OPENSSL_NO_MD5 +#endif + +#if !defined(WOLFSSL_RIPEMD) || defined(HAVE_FIPS) +#define OPENSSL_NO_RIPEMD +#endif + +#if defined(NO_RC4) || defined(HAVE_FIPS) +#define OPENSSL_NO_RC4 +#endif + +#ifdef NO_DES3 +#define OPENSSL_NO_DES +#endif + +#ifdef EVP_aes_128_ctr +#define HAVE_EVP_AES_128_CTR +#endif + +/* wolfSSL doesn't support Blowfish or CAST. */ +#define OPENSSL_NO_BF +#define OPENSSL_NO_CAST +/* wolfSSL has no engine framework. */ +#define OPENSSL_NO_ENGINE + +#endif /* LIBSSH2_WOLFSSL */ + #include #include #include @@ -57,8 +94,10 @@ #include #include -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !defined(LIBRESSL_VERSION_NUMBER) +#if (OPENSSL_VERSION_NUMBER >= 0x10100000L && \ + !defined(LIBRESSL_VERSION_NUMBER)) || defined(LIBSSH2_WOLFSSL) +/* For wolfSSL, whether the structs are truly opaque or not, it's best to not + * rely on their internal data members being exposed publicly. */ # define HAVE_OPAQUE_STRUCTS 1 #endif @@ -105,7 +144,8 @@ #define LIBSSH2_HMAC_SHA256 1 #define LIBSSH2_HMAC_SHA512 1 -#if OPENSSL_VERSION_NUMBER >= 0x00907000L && !defined(OPENSSL_NO_AES) +#if (OPENSSL_VERSION_NUMBER >= 0x00907000L && !defined(OPENSSL_NO_AES)) || \ + (defined(LIBSSH2_WOLFSSL) && defined(WOLFSSL_AES_COUNTER)) # define LIBSSH2_AES_CTR 1 # define LIBSSH2_AES 1 #else From 13ad7b2f5cd67e0dc843098ce19ce8b208368c29 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Thu, 6 Jan 2022 13:56:22 -0800 Subject: [PATCH 024/424] Fix a memcmp errors in code that was changed from memmem to memcmp (#656) Notes: Fixed supported algo prefs list check when upgrading rsa keys Credit: Michael Buckley --- src/userauth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/userauth.c b/src/userauth.c index 988dc17fff..29f58bab98 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1147,7 +1147,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, f = strchr(a, ','); f_len = f ? (f - a) : (int) strlen(a); - if(f_len == p_len && memcmp(a, s, p_len)) { + if(f_len == p_len && memcmp(a, s, p_len) == 0) { if(i != filtered_algs) { memcpy(i, ",", 1); @@ -1185,7 +1185,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, f = strchr(a, ','); f_len = f ? (f - a) : (int) strlen(a); - if(f_len == p_len && memcmp(a, s, p_len)) { + if(f_len == p_len && memcmp(a, s, p_len) == 0) { /* found a match, upgrade key method */ match = s; match_len = p_len; From d5ed0e6536c801884045226cbf33f3f004675458 Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Wed, 2 Jun 2021 21:02:55 +0530 Subject: [PATCH 025/424] ssh: Add support for userauth banner. The new libssh2_userauth_banner API allows to get an optional userauth banner sent with SSH_MSG_USERAUTH_BANNER packet by the server. Closes #610 --- docs/CMakeLists.txt | 1 + docs/Makefile.am | 1 + docs/libssh2_userauth_banner.3 | 30 +++++++++++++ include/libssh2.h | 3 ++ src/libssh2_priv.h | 1 + src/session.c | 3 ++ src/userauth.c | 81 +++++++++++++++++++++++++++++++++- 7 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 docs/libssh2_userauth_banner.3 diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index f439db719f..a95b44c2d5 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -194,6 +194,7 @@ set(MAN_PAGES libssh2_trace.3 libssh2_trace_sethandler.3 libssh2_userauth_authenticated.3 + libssh2_userauth_banner.3 libssh2_userauth_hostbased_fromfile.3 libssh2_userauth_hostbased_fromfile_ex.3 libssh2_userauth_keyboard_interactive.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index f0a71fc5a8..d9df59ca5d 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -164,6 +164,7 @@ dist_man_MANS = \ libssh2_trace.3 \ libssh2_trace_sethandler.3 \ libssh2_userauth_authenticated.3 \ + libssh2_userauth_banner.3 \ libssh2_userauth_hostbased_fromfile.3 \ libssh2_userauth_hostbased_fromfile_ex.3 \ libssh2_userauth_keyboard_interactive.3 \ diff --git a/docs/libssh2_userauth_banner.3 b/docs/libssh2_userauth_banner.3 new file mode 100644 index 0000000000..1003b65add --- /dev/null +++ b/docs/libssh2_userauth_banner.3 @@ -0,0 +1,30 @@ +.TH libssh2_userauth_banner 3 "1 Jun 2021" "libssh2 1.9.0" "libssh2 manual" +.SH NAME +libssh2_userauth_banner - get the server's userauth banner message +.SH SYNOPSIS +.nf +#include + +int +libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner); +.SH DESCRIPTION +\fIsession\fP - Session instance as returned by +.BR libssh2_session_init_ex(3) + +\fIbanner\fP - Should point to a pointer that gets filled with banner message. + +After an authentication has been attempted, such as a +\fBSSH_USERAUTH_NONE\fP request sent by +.BR libssh2_userauth_list(3) , +this function can be called to retrieve the userauth banner sent by +the server. If no such banner is sent, or if an authentication has not +yet been attempted, returns LIBSSH2_ERROR_MISSING_USERAUTH_BANNER. +.SH RETURN VALUE +On success returns 0 and an UTF-8 NUL-terminated string is stored in the +\fIbanner\fP. This string is internally managed by libssh2 and will be +deallocated upon session termination. +On failure returns +LIBSSH2_ERROR_MISSING_USERAUTH_BANNER. +.SH SEE ALSO +.BR libssh2_session_init_ex(3), +.BR libssh2_userauth_list(3) diff --git a/include/libssh2.h b/include/libssh2.h index 8db3015e78..20ba548322 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -507,6 +507,7 @@ typedef struct _LIBSSH2_POLLFD { #define LIBSSH2_ERROR_CHANNEL_WINDOW_FULL -47 #define LIBSSH2_ERROR_KEYFILE_AUTH_FAILED -48 #define LIBSSH2_ERROR_RANDGEN -49 +#define LIBSSH2_ERROR_MISSING_USERAUTH_BANNER -50 /* this is a define to provide the old (<= 1.2.7) name */ #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV @@ -615,6 +616,8 @@ LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session); LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session, const char *username, unsigned int username_len); +LIBSSH2_API int libssh2_userauth_banner(LIBSSH2_SESSION *session, + char **banner); LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session); LIBSSH2_API int diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index aff791e7cd..f218a836d3 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -720,6 +720,7 @@ struct _LIBSSH2_SESSION libssh2_nonblocking_states userauth_list_state; unsigned char *userauth_list_data; size_t userauth_list_data_len; + char *userauth_banner; packet_requirev_state_t userauth_list_packet_requirev_state; /* State variables used in libssh2_userauth_password_ex() */ diff --git a/src/session.c b/src/session.c index 212560b885..0de5ab3fd1 100644 --- a/src/session.c +++ b/src/session.c @@ -994,6 +994,9 @@ session_free(LIBSSH2_SESSION *session) if(session->userauth_list_data) { LIBSSH2_FREE(session, session->userauth_list_data); } + if(session->userauth_banner) { + LIBSSH2_FREE(session, session->userauth_banner); + } if(session->userauth_pswd_data) { LIBSSH2_FREE(session, session->userauth_pswd_data); } diff --git a/src/userauth.c b/src/userauth.c index 29f58bab98..84285bf06e 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -63,11 +63,13 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, unsigned int username_len) { - static const unsigned char reply_codes[3] = - { SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE, 0 }; + unsigned char reply_codes[4] = + { SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE, + SSH_MSG_USERAUTH_BANNER, 0 }; /* packet_type(1) + username_len(4) + service_len(4) + service(14)"ssh-connection" + method_len(4) = 27 */ unsigned long methods_len; + unsigned int banner_len; unsigned char *s; int rc; @@ -134,6 +136,57 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, return NULL; } + if(session->userauth_list_data[0] == SSH_MSG_USERAUTH_BANNER) { + if(session->userauth_list_data_len < 5) { + LIBSSH2_FREE(session, session->userauth_list_data); + session->userauth_list_data = NULL; + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Unexpected packet size"); + return NULL; + } + banner_len = _libssh2_ntohu32(session->userauth_list_data + 1); + if(banner_len >= session->userauth_list_data_len - 5) { + LIBSSH2_FREE(session, session->userauth_list_data); + session->userauth_list_data = NULL; + _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, + "Unexpected userauth banner size"); + return NULL; + } + session->userauth_banner = LIBSSH2_ALLOC(session, banner_len); + if(!session->userauth_banner) { + LIBSSH2_FREE(session, session->userauth_list_data); + session->userauth_list_data = NULL; + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for userauth_banner"); + return NULL; + } + memmove(session->userauth_banner, session->userauth_list_data + 5, + banner_len); + session->userauth_banner[banner_len] = '\0'; + _libssh2_debug(session, LIBSSH2_TRACE_AUTH, + "Banner: %s", + session->userauth_banner); + LIBSSH2_FREE(session, session->userauth_list_data); + session->userauth_list_data = NULL; + /* SSH_MSG_USERAUTH_BANNER has been handled */ + reply_codes[2] = 0; + rc = _libssh2_packet_requirev(session, reply_codes, + &session->userauth_list_data, + &session->userauth_list_data_len, 0, + NULL, 0, + &session->userauth_list_packet_requirev_state); + if(rc == LIBSSH2_ERROR_EAGAIN) { + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block requesting userauth list"); + return NULL; + } + else if(rc || (session->userauth_list_data_len < 1)) { + _libssh2_error(session, rc, "Failed getting response"); + session->userauth_list_state = libssh2_NB_state_idle; + return NULL; + } + } + if(session->userauth_list_data[0] == SSH_MSG_USERAUTH_SUCCESS) { /* Wow, who'dve thought... */ _libssh2_error(session, LIBSSH2_ERROR_NONE, "No error"); @@ -189,6 +242,30 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *user, return ptr; } +/* libssh2_userauth_banner + * + * Retrieve banner message from server, if available. + * When no such message is sent by server or if no authentication attempt has + * been made, this function returns LIBSSH2_ERROR_MISSING_AUTH_BANNER. + */ +LIBSSH2_API int +libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner) +{ + if(NULL == session) + return LIBSSH2_ERROR_MISSING_USERAUTH_BANNER; + + if(!session->userauth_banner) { + return _libssh2_error(session, + LIBSSH2_ERROR_MISSING_USERAUTH_BANNER, + "Missing userauth banner"); + } + + if(banner != NULL) + *banner = session->userauth_banner; + + return LIBSSH2_ERROR_NONE; +} + /* * libssh2_userauth_authenticated * From 50a1262772fd9cdbdd8f747958e42ef480aecb2b Mon Sep 17 00:00:00 2001 From: Ian Hattendorf Date: Thu, 13 Jan 2022 16:05:53 -0700 Subject: [PATCH 026/424] Support rsa-sha2 agent flags (#661) File: agent.c Notes: implements rsa-sha2 flags used to tell the agent which signing algo to use. https://tools.ietf.org/id/draft-miller-ssh-agent-01.html#rfc.section.4.5.1 Credit: Ian Hattendorf --- src/agent.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/agent.c b/src/agent.c index a526c779da..bce7175ea8 100644 --- a/src/agent.c +++ b/src/agent.c @@ -94,6 +94,10 @@ #define SSH_AGENT_CONSTRAIN_LIFETIME 1 #define SSH_AGENT_CONSTRAIN_CONFIRM 2 +/* Signature request methods */ +#define SSH_AGENT_RSA_SHA2_256 2 +#define SSH_AGENT_RSA_SHA2_512 4 + #ifdef PF_UNIX static int agent_connect_unix(LIBSSH2_AGENT *agent) @@ -375,6 +379,7 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, ssize_t method_len; unsigned char *s; int rc; + uint32_t sign_flags = 0; /* Create a request to sign the data */ if(transctx->state == agent_NB_state_init) { @@ -391,7 +396,18 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, _libssh2_store_str(&s, (const char *)data, data_len); /* flags */ - _libssh2_store_u32(&s, 0); + if(session->userauth_pblc_method_len > 0 && + session->userauth_pblc_method) { + if(session->userauth_pblc_method_len == 12 && + !memcmp(session->userauth_pblc_method, "rsa-sha2-512", 12)) { + sign_flags = SSH_AGENT_RSA_SHA2_512; + } + else if(session->userauth_pblc_method_len == 12 && + !memcmp(session->userauth_pblc_method, "rsa-sha2-256", 12)) { + sign_flags = SSH_AGENT_RSA_SHA2_256; + } + } + _libssh2_store_u32(&s, sign_flags); transctx->request_len = s - transctx->request; transctx->send_recv_total = 0; From de7a74aff24c47b2f2e9815f0a98598195d602e4 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Fri, 14 Jan 2022 11:55:18 -0800 Subject: [PATCH 027/424] Legacy Agent support for rsa2 key upgrading/downgrading #659 (#662) Files: libssh2.h, agent.c, userauth.c Notes: Part 2 of the fix for #659. This adds rsa key downgrading for agents that don't support sha2 upgrading. It also adds better trace output for debugging/logging around key upgrading. Credit: Will Cosgrove (signed off by Michael Buckley) --- include/libssh2.h | 1 + src/agent.c | 27 +++++++++++++++++++++++++++ src/userauth.c | 43 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index 20ba548322..15dda6fcf6 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -508,6 +508,7 @@ typedef struct _LIBSSH2_POLLFD { #define LIBSSH2_ERROR_KEYFILE_AUTH_FAILED -48 #define LIBSSH2_ERROR_RANDGEN -49 #define LIBSSH2_ERROR_MISSING_USERAUTH_BANNER -50 +#define LIBSSH2_ERROR_ALGO_UNSUPPORTED -51 /* this is a define to provide the old (<= 1.2.7) name */ #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV diff --git a/src/agent.c b/src/agent.c index bce7175ea8..4ed79ac274 100644 --- a/src/agent.c +++ b/src/agent.c @@ -379,6 +379,7 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, ssize_t method_len; unsigned char *s; int rc; + unsigned char *method_name = NULL; uint32_t sign_flags = 0; /* Create a request to sign the data */ @@ -465,8 +466,28 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, rc = LIBSSH2_ERROR_AGENT_PROTOCOL; goto error; } + + /* method name */ + method_name = LIBSSH2_ALLOC(session, method_len); + if(!method_name) { + rc = LIBSSH2_ERROR_ALLOC; + goto error; + } + memcpy(method_name, s, method_len); s += method_len; + /* check to see if we match requested */ + if((size_t)method_len != session->userauth_pblc_method_len || + memcmp(method_name, session->userauth_pblc_method, method_len)) { + _libssh2_debug(session, + LIBSSH2_TRACE_KEX, + "Agent sign method %.*s", + method_len, method_name); + + rc = LIBSSH2_ERROR_ALGO_UNSUPPORTED; + goto error; + } + /* Read the signature */ len -= 4; if(len < 0) { @@ -489,12 +510,18 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, memcpy(*sig, s, *sig_len); error: + + if(method_name) + LIBSSH2_FREE(session, method_name); + LIBSSH2_FREE(session, transctx->request); transctx->request = NULL; LIBSSH2_FREE(session, transctx->response); transctx->response = NULL; + transctx->state = agent_NB_state_init; + return _libssh2_error(session, rc, "agent sign failure"); } diff --git a/src/userauth.c b/src/userauth.c index 84285bf06e..59b76ca9fe 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1283,9 +1283,6 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, if(key_method) { memcpy(*key_method, match, match_len); *key_method_len = match_len; - - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Signing using %.*s", match_len, match); } else { *key_method_len = 0; @@ -1321,6 +1318,10 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, }; int rc; unsigned char *s; + int auth_attempts = 0; + + retry_auth: + auth_attempts++; if(session->userauth_pblc_state == libssh2_NB_state_idle) { @@ -1364,13 +1365,26 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, session->userauth_pblc_method_len); } - /* upgrade key key signing algo needed */ - rc = _libssh2_key_sign_algorithm(session, - &session->userauth_pblc_method, - &session->userauth_pblc_method_len); + /* upgrade key signing algo if it is supported and + * it is our first auth attempt, otherwise fallback to + * the key default algo */ + if(auth_attempts == 1) { + rc = _libssh2_key_sign_algorithm(session, + &session->userauth_pblc_method, + &session->userauth_pblc_method_len); - if(rc) - return rc; + if(rc) + return rc; + } + + if(session->userauth_pblc_method_len && + session->userauth_pblc_method) { + _libssh2_debug(session, + LIBSSH2_TRACE_KEX, + "Signing using %.*s", + session->userauth_pblc_method_len, + session->userauth_pblc_method); + } /* * 45 = packet_type(1) + username_len(4) + servicename_len(4) + @@ -1528,6 +1542,17 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); } + else if(rc == LIBSSH2_ERROR_ALGO_UNSUPPORTED && auth_attempts == 1) { + /* try again with the default key algo */ + LIBSSH2_FREE(session, session->userauth_pblc_method); + session->userauth_pblc_method = NULL; + LIBSSH2_FREE(session, session->userauth_pblc_packet); + session->userauth_pblc_packet = NULL; + session->userauth_pblc_state = libssh2_NB_state_idle; + + rc = LIBSSH2_ERROR_NONE; + goto retry_auth; + } else if(rc) { LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; From 30fc410b972e6dec87c248c0fedbff28cfa18f17 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Tue, 18 Jan 2022 11:28:13 -0800 Subject: [PATCH 028/424] free RSA2 related memory (#664) Free `server_sign_algorithms` and `sign_algo_prefs`. --- src/session.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/session.c b/src/session.c index 0de5ab3fd1..ae6132c27b 100644 --- a/src/session.c +++ b/src/session.c @@ -981,6 +981,12 @@ session_free(LIBSSH2_SESSION *session) if(session->remote.lang_prefs) { LIBSSH2_FREE(session, session->remote.lang_prefs); } + if(session->server_sign_algorithms) { + LIBSSH2_FREE(session, session->server_sign_algorithms); + } + if(session->sign_algo_prefs) { + LIBSSH2_FREE(session, session->sign_algo_prefs); + } /* * Make sure all memory used in the state variables are free From 2a2aaed3b6c3c1dc25e35e11afcfb23f88a18510 Mon Sep 17 00:00:00 2001 From: tihmstar Date: Thu, 3 Feb 2022 19:11:36 +0100 Subject: [PATCH 029/424] NULL terminate server_sign_algorithms string (#669) files: packet.c, libssh2_priv.h notes: * Fix heap buffer overflow in _libssh2_key_sign_algorithm When allocating `session->server_sign_algorithms` which is a `char*` is is important to also allocate space for the string-terminating null byte at the end and make sure the string is actually null terminated. Without this fix, the `strchr()` call inside the `_libssh2_key_sign_algorithm` (line 1219) function will try to parse the string and go out of buffer on the last invocation. Credit: tihmstar Co-authored-by: Will Cosgrove --- src/libssh2_priv.h | 1 - src/packet.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index f218a836d3..be16ad2e31 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -642,7 +642,6 @@ struct _LIBSSH2_SESSION /* public key algorithms accepted as comma separated list */ char *server_sign_algorithms; - size_t server_sign_algorithms_len; /* key signing algorithm preferences -- NULL yields server order */ char *sign_algo_prefs; diff --git a/src/packet.c b/src/packet.c index 686be5cc7c..c3756a8ea0 100644 --- a/src/packet.c +++ b/src/packet.c @@ -665,12 +665,12 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, session->server_sign_algorithms = LIBSSH2_ALLOC(session, - value_len); + value_len + 1); if(session->server_sign_algorithms) { - session->server_sign_algorithms_len = value_len; memcpy(session->server_sign_algorithms, value, value_len); + session->server_sign_algorithms[value_len] = '\0'; } else { rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, From ead7000d28c986cf5c2458bf31b824000e16a4df Mon Sep 17 00:00:00 2001 From: xalopp Date: Thu, 3 Feb 2022 19:13:36 +0100 Subject: [PATCH 030/424] Fix formatting in manual page (#667) Fixed formatting of `LIBSSH2_ERROR_AUTHENTICATION_FAILED` in the errors section. credit: xalopp --- docs/libssh2_userauth_keyboard_interactive_ex.3 | 2 +- docs/libssh2_userauth_password_ex.3 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/libssh2_userauth_keyboard_interactive_ex.3 b/docs/libssh2_userauth_keyboard_interactive_ex.3 index ada012a2fa..222b2ba8c2 100644 --- a/docs/libssh2_userauth_keyboard_interactive_ex.3 +++ b/docs/libssh2_userauth_keyboard_interactive_ex.3 @@ -52,7 +52,7 @@ number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fLIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - failed, invalid username/password +\fILIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - failed, invalid username/password or public/private key. .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_userauth_password_ex.3 b/docs/libssh2_userauth_password_ex.3 index dc9e108335..03b90a11d1 100644 --- a/docs/libssh2_userauth_password_ex.3 +++ b/docs/libssh2_userauth_password_ex.3 @@ -51,7 +51,7 @@ Some of the errors this function may return include: \fILIBSSH2_ERROR_PASSWORD_EXPIRED\fP - -\fLIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - failed, invalid username/password +\fILIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - failed, invalid username/password or public/private key. .SH SEE ALSO .BR libssh2_session_init_ex(3) From 83853f8aea0e2f739cacd491632eb7fd3d03ad2d Mon Sep 17 00:00:00 2001 From: xalopp Date: Sun, 20 Feb 2022 00:46:40 +0100 Subject: [PATCH 031/424] Use modern API in userauth_keyboard_interactive() (#663) Files: userauth_kbd_packet.c, userauth_kbd_packet.h, test_keyboard_interactive_auth_info_request.c, userauth.c Notes: This refactors `SSH_MSG_USERAUTH_INFO_REQUEST` processing in `userauth_keyboard_interactive()` in order to improve robustness, correctness and readability or the code. * Refactor userauth_keyboard_interactive to use new api for packet parsing * add unit test for userauth_keyboard_interactive_parse_response() * add _libssh2_get_boolean() and _libssh2_get_byte() utility functions Credit: xalopp --- Makefile.inc | 1 + include/libssh2.h | 4 +- src/CMakeLists.txt | 2 + src/libssh2_priv.h | 8 +- src/misc.c | 23 ++ src/misc.h | 2 + src/userauth.c | 212 +---------- src/userauth_kbd_packet.c | 162 +++++++++ src/userauth_kbd_packet.h | 43 +++ tests/CMakeLists.txt | 36 ++ ...t_keyboard_interactive_auth_info_request.c | 335 ++++++++++++++++++ 11 files changed, 616 insertions(+), 212 deletions(-) create mode 100644 src/userauth_kbd_packet.c create mode 100644 src/userauth_kbd_packet.h create mode 100644 tests/test_keyboard_interactive_auth_info_request.c diff --git a/Makefile.inc b/Makefile.inc index 20d2ebeeb2..99afe0f58f 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -1,5 +1,6 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ + userauth_kbd_packet.c \ version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ blowfish.c bcrypt_pbkdf.c agent_win.c diff --git a/include/libssh2.h b/include/libssh2.h index 15dda6fcf6..ef3ce11508 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -272,8 +272,8 @@ typedef off_t libssh2_struct_stat_size; typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT { - char *text; - unsigned int length; + unsigned char *text; + size_t length; unsigned char echo; } LIBSSH2_USERAUTH_KBDINT_PROMPT; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eee1a80d4a..50c028c45a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -207,6 +207,8 @@ set(SOURCES sftp.h transport.c transport.h + userauth_kbd_packet.c + userauth_kbd_packet.h userauth.c userauth.h version.c) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index be16ad2e31..b3ce7af766 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -760,10 +760,10 @@ struct _LIBSSH2_SESSION size_t userauth_kybd_data_len; unsigned char *userauth_kybd_packet; size_t userauth_kybd_packet_len; - unsigned int userauth_kybd_auth_name_len; - char *userauth_kybd_auth_name; - unsigned userauth_kybd_auth_instruction_len; - char *userauth_kybd_auth_instruction; + size_t userauth_kybd_auth_name_len; + unsigned char *userauth_kybd_auth_name; + size_t userauth_kybd_auth_instruction_len; + unsigned char *userauth_kybd_auth_instruction; unsigned int userauth_kybd_num_prompts; int userauth_kybd_auth_failure; LIBSSH2_USERAUTH_KBDINT_PROMPT *userauth_kybd_prompts; diff --git a/src/misc.c b/src/misc.c index 594b2d1f77..5e4c4335ee 100644 --- a/src/misc.c +++ b/src/misc.c @@ -732,6 +732,29 @@ void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf) buf = NULL; } +int _libssh2_get_byte(struct string_buf *buf, unsigned char *out) +{ + if(!_libssh2_check_length(buf, 1)) { + return -1; + } + + *out = buf->dataptr[0]; + buf->dataptr += 1; + return 0; +} + +int _libssh2_get_boolean(struct string_buf *buf, unsigned char *out) +{ + if(!_libssh2_check_length(buf, 1)) { + return -1; + } + + + *out = buf->dataptr[0] == 0 ? 0 : 1; + buf->dataptr += 1; + return 0; +} + int _libssh2_get_u32(struct string_buf *buf, uint32_t *out) { if(!_libssh2_check_length(buf, 4)) { diff --git a/src/misc.h b/src/misc.h index 5481e666ca..3d4206dbf6 100644 --- a/src/misc.h +++ b/src/misc.h @@ -91,6 +91,8 @@ void _libssh2_explicit_zero(void *buf, size_t size); struct string_buf* _libssh2_string_buf_new(LIBSSH2_SESSION *session); void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf); +int _libssh2_get_boolean(struct string_buf *buf, unsigned char *out); +int _libssh2_get_byte(struct string_buf *buf, unsigned char *out); int _libssh2_get_u32(struct string_buf *buf, uint32_t *out); int _libssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out); int _libssh2_match_string(struct string_buf *buf, const char *match); diff --git a/src/userauth.c b/src/userauth.c index 59b76ca9fe..551f24d254 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -52,6 +52,7 @@ #include "transport.h" #include "session.h" #include "userauth.h" +#include "userauth_kbd_packet.h" /* libssh2_userauth_list * @@ -1878,13 +1879,13 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, ((*response_callback))) { unsigned char *s; + int rc; static const unsigned char reply_codes[4] = { SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE, SSH_MSG_USERAUTH_INFO_REQUEST, 0 }; - unsigned int language_tag_len; unsigned int i; if(session->userauth_kybd_state == libssh2_NB_state_idle) { @@ -2007,215 +2008,14 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, } /* server requested PAM-like conversation */ - s = session->userauth_kybd_data + 1; - - if(session->userauth_kybd_data_len >= 5) { - /* string name (ISO-10646 UTF-8) */ - session->userauth_kybd_auth_name_len = _libssh2_ntohu32(s); - if(session->userauth_kybd_auth_name_len > - session->userauth_kybd_data_len - 5) - return _libssh2_error(session, - LIBSSH2_ERROR_OUT_OF_BOUNDARY, - "Bad keyboard auth name"); - s += 4; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too small" - "to get length"); - goto cleanup; - } - - if(session->userauth_kybd_auth_name_len) { - session->userauth_kybd_auth_name = - LIBSSH2_ALLOC(session, - session->userauth_kybd_auth_name_len); - if(!session->userauth_kybd_auth_name) { - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive 'name' " - "request field"); - goto cleanup; - } - if(s + session->userauth_kybd_auth_name_len <= - session->userauth_kybd_data + - session->userauth_kybd_data_len) { - memcpy(session->userauth_kybd_auth_name, s, - session->userauth_kybd_auth_name_len); - s += session->userauth_kybd_auth_name_len; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too small" - "for auth name"); - goto cleanup; - } - } - - if(s + 4 <= session->userauth_kybd_data + - session->userauth_kybd_data_len) { - /* string instruction (ISO-10646 UTF-8) */ - session->userauth_kybd_auth_instruction_len = - _libssh2_ntohu32(s); - s += 4; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too small" - "for auth instruction length"); + if(userauth_keyboard_interactive_decode_info_request(session) + < 0) { goto cleanup; } - if(session->userauth_kybd_auth_instruction_len) { - session->userauth_kybd_auth_instruction = - LIBSSH2_ALLOC(session, - session->userauth_kybd_auth_instruction_len); - if(!session->userauth_kybd_auth_instruction) { - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive 'instruction' " - "request field"); - goto cleanup; - } - if(s + session->userauth_kybd_auth_instruction_len <= - session->userauth_kybd_data + - session->userauth_kybd_data_len) { - memcpy(session->userauth_kybd_auth_instruction, s, - session->userauth_kybd_auth_instruction_len); - s += session->userauth_kybd_auth_instruction_len; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too small" - "for auth instruction"); - goto cleanup; - } - } - - if(s + 4 <= session->userauth_kybd_data + - session->userauth_kybd_data_len) { - /* string language tag (as defined in [RFC-3066]) */ - language_tag_len = _libssh2_ntohu32(s); - s += 4; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too small" - "for auth language tag length"); - goto cleanup; - } - - if(s + language_tag_len <= session->userauth_kybd_data + - session->userauth_kybd_data_len) { - /* ignoring this field as deprecated */ - s += language_tag_len; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too small" - "for auth language tag"); - goto cleanup; - } - - if(s + 4 <= session->userauth_kybd_data + - session->userauth_kybd_data_len) { - /* int num-prompts */ - session->userauth_kybd_num_prompts = _libssh2_ntohu32(s); - s += 4; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too small" - "for auth num keyboard prompts"); - goto cleanup; - } - - if(session->userauth_kybd_num_prompts > 100) { - _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, - "Too many replies for " - "keyboard-interactive prompts"); - goto cleanup; - } - - if(session->userauth_kybd_num_prompts) { - session->userauth_kybd_prompts = - LIBSSH2_CALLOC(session, - sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) * - session->userauth_kybd_num_prompts); - if(!session->userauth_kybd_prompts) { - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive prompts array"); - goto cleanup; - } - - session->userauth_kybd_responses = - LIBSSH2_CALLOC(session, - sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) * - session->userauth_kybd_num_prompts); - if(!session->userauth_kybd_responses) { - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive responses array"); - goto cleanup; - } - - for(i = 0; i < session->userauth_kybd_num_prompts; i++) { - if(s + 4 <= session->userauth_kybd_data + - session->userauth_kybd_data_len) { - /* string prompt[1] (ISO-10646 UTF-8) */ - session->userauth_kybd_prompts[i].length = - _libssh2_ntohu32(s); - s += 4; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too " - "small for auth keyboard " - "prompt length"); - goto cleanup; - } - - session->userauth_kybd_prompts[i].text = - LIBSSH2_CALLOC(session, - session->userauth_kybd_prompts[i]. - length); - if(!session->userauth_kybd_prompts[i].text) { - _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive prompt message"); - goto cleanup; - } - - if(s + session->userauth_kybd_prompts[i].length <= - session->userauth_kybd_data + - session->userauth_kybd_data_len) { - memcpy(session->userauth_kybd_prompts[i].text, s, - session->userauth_kybd_prompts[i].length); - s += session->userauth_kybd_prompts[i].length; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too " - "small for auth keyboard prompt"); - goto cleanup; - } - if(s < session->userauth_kybd_data + - session->userauth_kybd_data_len) { - /* boolean echo[1] */ - session->userauth_kybd_prompts[i].echo = *s++; - } - else { - _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "userauth keyboard data buffer too " - "small for auth keyboard prompt echo"); - goto cleanup; - } - } - } - - response_callback(session->userauth_kybd_auth_name, + response_callback((const char *)session->userauth_kybd_auth_name, session->userauth_kybd_auth_name_len, + (const char *) session->userauth_kybd_auth_instruction, session->userauth_kybd_auth_instruction_len, session->userauth_kybd_num_prompts, diff --git a/src/userauth_kbd_packet.c b/src/userauth_kbd_packet.c new file mode 100644 index 0000000000..56cd0efef3 --- /dev/null +++ b/src/userauth_kbd_packet.c @@ -0,0 +1,162 @@ +/* Copyright (c) 2022, Xaver Loppenstedt + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the copyright holder nor the names + * of any other contributors may be used to endorse or + * promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#include "libssh2_priv.h" +#include "userauth_kbd_packet.h" + +int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *session) +{ + unsigned char *language_tag; + size_t language_tag_len; + unsigned int i; + unsigned char packet_type; + + struct string_buf decoded; + + decoded.data = session->userauth_kybd_data; + decoded.dataptr = session->userauth_kybd_data; + decoded.len = session->userauth_kybd_data_len; + + if(session->userauth_kybd_data_len < 17) { + _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "userauth keyboard data buffer too small " + "to get length"); + return -1; + } + + /* byte SSH_MSG_USERAUTH_INFO_REQUEST */ + _libssh2_get_byte(&decoded, &packet_type); + + /* string name (ISO-10646 UTF-8) */ + if(_libssh2_copy_string(session, &decoded, + &session->userauth_kybd_auth_name, + &session->userauth_kybd_auth_name_len) == -1) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to decode " + "keyboard-interactive 'name' " + "request field"); + return -1; + } + + /* string instruction (ISO-10646 UTF-8) */ + if(_libssh2_copy_string(session, &decoded, + &session->userauth_kybd_auth_instruction, + &session->userauth_kybd_auth_instruction_len) + == -1) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to decode " + "keyboard-interactive 'instruction' " + "request field"); + return -1; + } + + /* string language tag (as defined in [RFC-3066]) */ + if(_libssh2_get_string(&decoded, &language_tag, + &language_tag_len) == -1) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to decode " + "keyboard-interactive 'language tag' " + "request field"); + return -1; + } + + /* int num-prompts */ + if(_libssh2_get_u32(&decoded, &session->userauth_kybd_num_prompts) == -1) { + _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Unable to decode " + "keyboard-interactive number of keyboard prompts"); + return -1; + } + + if(session->userauth_kybd_num_prompts > 100) { + _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, + "Too many replies for " + "keyboard-interactive prompts"); + return -1; + } + + if(session->userauth_kybd_num_prompts == 0) { + return 0; + } + + session->userauth_kybd_prompts = + LIBSSH2_CALLOC(session, + sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) * + session->userauth_kybd_num_prompts); + if(!session->userauth_kybd_prompts) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive prompts array"); + return -1; + } + + session->userauth_kybd_responses = + LIBSSH2_CALLOC(session, + sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) * + session->userauth_kybd_num_prompts); + if(!session->userauth_kybd_responses) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive responses array"); + return -1; + } + + for(i = 0; i < session->userauth_kybd_num_prompts; i++) { + /* string prompt[1] (ISO-10646 UTF-8) */ + if(_libssh2_copy_string(session, &decoded, + &session->userauth_kybd_prompts[i].text, + &session->userauth_kybd_prompts[i].length) + == -1) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to decode " + "keyboard-interactive prompt message"); + return -1; + } + + /* boolean echo[1] */ + if(_libssh2_get_boolean(&decoded, + &session->userauth_kybd_prompts[i].echo) + == -1) { + _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Unable to decode " + "user auth keyboard prompt echo"); + return -1; + } + } + + return 0; +} diff --git a/src/userauth_kbd_packet.h b/src/userauth_kbd_packet.h new file mode 100644 index 0000000000..cce0a73168 --- /dev/null +++ b/src/userauth_kbd_packet.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2022, Xaver Loppenstedt + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the copyright holder nor the names + * of any other contributors may be used to endorse or + * promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#ifndef __LIBSSH2_USERAUTH_KBD_PARSE_H +#define __LIBSSH2_USERAUTH_KBD_PARSE_H + +int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *); + +#endif /* __LIBSSH2_USERAUTH_KBD_PARSE_H */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cf4b3f768a..26244309b1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -76,6 +76,8 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) if(OPENSSL_FOUND) set(CRYPTO_BACKEND "OpenSSL") + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL") + set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) endif() endif() @@ -85,6 +87,8 @@ if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) if(LIBGCRYPT_FOUND) set(CRYPTO_BACKEND "Libgcrypt") + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT") + set(CRYPTO_BACKEND_INCLUDE_DIR ${LIBGCRYPT_INCLUDE_DIRS}) endif() endif() @@ -95,6 +99,8 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) if(HAVE_BCRYPT_H) set(CRYPTO_BACKEND "WinCNG") + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG") + set(CRYPTO_BACKEND_INCLUDE_DIR "") endif() endif() @@ -104,6 +110,8 @@ if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) if(MBEDTLS_FOUND) set(CRYPTO_BACKEND "mbedTLS") + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS") + set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR}) endif() endif() @@ -166,6 +174,34 @@ foreach(test ${TESTS}) WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") endforeach() +if(WIN32 AND BUILD_SHARED_LIBS) + # Workaround for Visual Studio + add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c ../src/misc.c) +else() + add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) +endif() +target_compile_definitions(test_keyboard_interactive_auth_info_request PRIVATE "${CRYPTO_BACKEND_DEFINE}") +target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" "../src/" "${CRYPTO_BACKEND_INCLUDE_DIR}") +find_program(GCOV_PATH gcov) +if(CMAKE_COMPILER_IS_GNUCC AND GCOV_PATH) + target_compile_options(test_keyboard_interactive_auth_info_request BEFORE PRIVATE + -g --coverage -fprofile-abs-path) + target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2 gcov) +else() + target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2) +endif() +add_test( + NAME test_keyboard_interactive_auth_info_request COMMAND $ + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_custom_target(coverage + COMMAND gcovr -r "${CMAKE_SOURCE_DIR}" --exclude tests/* + COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/coverage/" + COMMAND gcovr -r "${CMAKE_SOURCE_DIR}" --exclude tests/* --html-details --output "${CMAKE_CURRENT_BINARY_DIR}/coverage/index.html") + +add_custom_target(clean-coverage + COMMAND rm -rf "${CMAKE_CURRENT_BINARY_DIR}/coverage/") + add_target_to_copy_dependencies( TARGET copy_test_dependencies DEPENDENCIES ${RUNTIME_DEPENDENCIES} diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c new file mode 100644 index 0000000000..da6989d6bb --- /dev/null +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -0,0 +1,335 @@ +/* Copyright (C) 2022 Xaver Loppenstedt + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the copyright holder nor the names + * of any other contributors may be used to endorse or + * promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#include + +#include "libssh2_priv.h" +#include "userauth_kbd_packet.h" + +#define PASS 0 +#define FAIL -1 + +struct expected { + int rc; + int last_error_code; + char *last_error_message; +}; +struct test_case { + char *data; + int data_len; + struct expected expected; +}; + +#define TEST_CASES_LEN 16 +struct test_case test_cases[TEST_CASES_LEN] = { + /* to small */ + { + NULL, 0, + {FAIL, -38, + "userauth keyboard data buffer too small to get length"}}, + /* to small */ + { + "1234", 4, + {FAIL, -38, + "userauth keyboard data buffer too small to get length"}}, + /* smalest valid packet possible */ + { + "<" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\0", 17, + {PASS, 0, ""}}, + /* overrun name */ + { + "<" + "\0\0\0\x7f" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\0", 17, + {FAIL, -6, + "Unable to decode keyboard-interactive 'name' request field"}}, + /* overrun instruction */ + { + "<" + "\0\0\0\0" + "\0\0\0\x7f" + "\0\0\0\0" + "\0\0\0\0", 17, + {FAIL, -6, + "Unable to decode keyboard-interactive 'instruction' " + "request field"}}, + /* overrun language */ + { + "<" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\x7f" + "\0\0\0\0", 17, + {FAIL, -6, "Unable to decode keyboard-interactive 'language tag' " + "request field"}}, + /* underrun prompt number */ + { + "<" + "\0\0\0\x01" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\0", 17, + {FAIL, -38, + "Unable to decode keyboard-interactive number of " + "keyboard prompts"}}, + /* too many prompts */ + { + "<" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\x7f", 17, + {FAIL, -41, "Too many replies for keyboard-interactive prompts"}}, + /* empty prompt */ + { + "<" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\0" + "\0\0\0\x01" + "\0\0\0\0" + "\0", 22, {PASS, 0, ""}}, + /* copied from OpenSSH */ + { + "<" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01" + "\0\0\0\x0aPassword: \0", 32, {PASS, 0, ""}}, + /* overrun in prompt text */ + { + "<" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01" + "\0\0\0\x7bPassword: \0", 32, + {FAIL, -6, "Unable to decode keyboard-interactive " + "prompt message"}}, + /* no echo prompt boolean */ + { + "<" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01" + "\0\0\0\x0bPassword: \0", 32, + {FAIL, -38, "Unable to decode user auth keyboard prompt echo"}}, + /* two prompts */ + { + "<" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x02" + "\0\0\0\x0aPassword: \0" + "\0\0\0\x07Token: \1", 44, + {PASS, 0, ""}}, + /* example from RFC 4256 */ + { + "<" + "\0\0\0\x19""CRYPTOCard Authentication" + "\0\0\0\x1b""The challenge is '14315716'" + "\0\0\0\x05""en-US" + "\0\0\0\x01" + "\0\0\0\x0aResponse: " + "\x01" + , 89, {PASS, 0, ""}}, + /* three prompts, 3rd missing*/ + { + "<" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x03" + "\0\0\0\x0aPassword: \0" + "\0\0\0\x07Token: \1", 44, + {FAIL, -6, + "Unable to decode keyboard-interactive prompt message"}}, + /* overflow language on 32 bit platform */ + { + "<" + "\0\0\0\x19" + "\0\0\0\x01" + "\0\0\0\x05""PWN3D\0\1\2\3\4\5\6\7\1\2\3" + "\x01" + "\0\0\0\x1b""The challenge is '14315716'" + "\xff\xff\xff\xc4""en-US" + "\0\0\0\x01" + "\0\0\0\x0aResponse: " + "\x01", + 89, + {FAIL, -6, + "Unable to decode keyboard-interactive 'language tag' " + "request field"}}, +}; + +#define FAILED_MALLOC_TEST_CASES_LEN 2 +struct test_case failed_malloc_test_cases[FAILED_MALLOC_TEST_CASES_LEN] = { + /* malloc fail */ + { + "<" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01" + "\0\0\0\x0aPassword: \0", 32, + {FAIL, -6, + "Unable to allocate memory for " + "keyboard-interactive prompts array"}}, + /* malloc fail */ + { + "<" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01" + "\0\0\0\x0aPassword: \0", 32, + {FAIL, -6, + "Unable to allocate memory for " + "keyboard-interactive responses array" + }} +}; + +static int alloc_count = 0; +static int free_count = 0; + +/* libssh2_default_alloc + */ +static +LIBSSH2_ALLOC_FUNC(test_alloc) +{ + alloc_count++; + + int *threshold_int_ptr = *abstract; + if (*abstract != NULL && *threshold_int_ptr == alloc_count) { + return NULL; + } + + return malloc(count); +} + +/* libssh2_default_free + */ +static +LIBSSH2_FREE_FUNC(test_free) +{ + (void) abstract; + free_count++; + free(ptr); +} + +static +int test_case(int num, + char *data, int data_len, void *abstract, + struct expected expected) +{ + alloc_count = 0; + free_count = 0; + LIBSSH2_SESSION *session = NULL; + session = libssh2_session_init_ex(test_alloc, test_free, NULL, abstract); + if(session == NULL) { + fprintf(stderr, "libssh2_session_init_ex failed\n"); + return 1; + } + + session->userauth_kybd_data = LIBSSH2_ALLOC(session, data_len); + session->userauth_kybd_data_len = data_len; + memcpy(session->userauth_kybd_data, data, data_len); + + int rc = userauth_keyboard_interactive_decode_info_request(session); + + if(rc != expected.rc) { + fprintf(stdout, + "Test case %d: expected return code to be %d got %d\n", + num, expected.rc, rc); + return 1; + } + + char *message; + int error_code = libssh2_session_last_error(session, &message, NULL, 0); + + if(expected.last_error_code != error_code) { + fprintf(stdout, + "Test case %d: expected last error code to be " + "\"%d\" got \"%d\"\n", + num, expected.last_error_code, error_code); + return 1; + } + + if(strcmp(expected.last_error_message, message) != 0) { + fprintf(stdout, + "Test case %d: expected last error message to be " + "\"%s\" got \"%s\"\n", + num, expected.last_error_message, message); + return 1; + } + libssh2_session_free(session); + + fprintf(stderr, "Test case %d passed\n", num); + + return 0; +} + +int main() +{ + int i; + + for(i = 0; i < TEST_CASES_LEN; i++) { + test_case(i + 1, + test_cases[i].data, test_cases[i].data_len, + NULL, + test_cases[i].expected); + } + + for(i = 0; i < FAILED_MALLOC_TEST_CASES_LEN; i++) { + int tc = i + TEST_CASES_LEN + 1; + int malloc_call_num = 5 + i; + test_case(tc, + failed_malloc_test_cases[i].data, + failed_malloc_test_cases[i].data_len, + &malloc_call_num, + failed_malloc_test_cases[i].expected); + } + + return 0; +} + +/* Workaround for Visual Studio */ +#ifdef _MSC_VER +int +bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, + size_t saltlen, + uint8_t *key, size_t keylen, unsigned int rounds) +{ + (void)pass; + (void)passlen; + (void)salt; + (void)saltlen; + (void)key; + (void)keylen; + (void)rounds; + + return -1; +} +#endif \ No newline at end of file From b60dca8b6450a9729670986d2899cca54ccdbb6d Mon Sep 17 00:00:00 2001 From: berney Date: Sun, 20 Feb 2022 10:50:48 +1100 Subject: [PATCH 032/424] Option to build both static and shared libraries (#547) files: cmakelists.txt Notes: * Option to build both static and shared libraries when using CMake Credit: berney --- src/CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50c028c45a..a5e2be555a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -217,9 +217,17 @@ if(WIN32) list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) endif() -add_library(libssh2 ${SOURCES}) -# we want it to be called libssh2 on all platforms -set_target_properties(libssh2 PROPERTIES PREFIX "") +add_library(libssh2 OBJECT ${SOURCES}) +if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) + add_library(libssh2-shared SHARED $) + # we want it to be called libssh2 on all platforms + set_target_properties(libssh2-shared PROPERTIES PREFIX "" OUTPUT_NAME "libssh2") + set_target_properties(libssh2 PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif() +if(BUILD_BOTH_LIBS OR NOT BUILD_SHARED_LIBS) + add_library(libssh2-static STATIC $) + set_target_properties(libssh2-static PROPERTIES PREFIX "" OUTPUT_NAME "libssh2") +endif() target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) target_include_directories(libssh2 @@ -238,6 +246,10 @@ endif(CLEAR_MEMORY) add_feature_info("Shared library" BUILD_SHARED_LIBS "creating libssh2 as a shared library (.so/.dll)") +option(BUILD_BOTH_LIBS "Build both static and shared libraries" OFF) +add_feature_info("Static and Shared libraries" BUILD_BOTH_LIBS + "creating libssh2 as a both a static (.a) and shared library (.so/.dll)") + option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression") add_feature_info(Compression ENABLE_ZLIB_COMPRESSION "using zlib for compression") @@ -374,6 +386,10 @@ else() target_link_libraries(libssh2 PRIVATE ${LIBRARIES}) endif() +if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) + target_link_libraries(libssh2-shared PUBLIC libssh2) +endif() + ## Installation install(FILES @@ -382,14 +398,28 @@ install(FILES ${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(TARGETS libssh2 - EXPORT Libssh2Config - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) + install(TARGETS libssh2 + EXPORT Libssh2Config + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(TARGETS libssh2-shared + EXPORT Libssh2Config + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() +if(BUILD_BOTH_LIBS OR NOT BUILD_SHARED_LIBS) + install(TARGETS libssh2-static + EXPORT Libssh2Config + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() -if(BUILD_SHARED_LIBS) - list(APPEND _RUNTIME_DEPENDENCIES $) +if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) + list(APPEND _RUNTIME_DEPENDENCIES $) endif() set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL @@ -421,9 +451,16 @@ install( ## Versioning -set_target_properties(libssh2 PROPERTIES - SOVERSION 1 - VERSION 1.0.1) +if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) + set_target_properties(libssh2-shared PROPERTIES + SOVERSION 1 + VERSION 1.0.1) +endif() +if(BUILD_BOTH_LIBS OR NOT BUILD_SHARED_LIBS) + set_target_properties(libssh2-static PROPERTIES + SOVERSION 1 + VERSION 1.0.1) +endif() include(CMakePackageConfigHelpers) write_basic_package_version_file( From ec7f782d7fba400fa9ffaf72c5f9bad4eca9965b Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Sat, 19 Feb 2022 15:57:12 -0800 Subject: [PATCH 033/424] Revert "Option to build both static and shared libraries (#547)" (#675) This reverts commit b60dca8b6450a9729670986d2899cca54ccdbb6d. #547 doesn't build clean anymore with the keyboard interactive changes. --- src/CMakeLists.txt | 63 ++++++++++------------------------------------ 1 file changed, 13 insertions(+), 50 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a5e2be555a..50c028c45a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -217,17 +217,9 @@ if(WIN32) list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) endif() -add_library(libssh2 OBJECT ${SOURCES}) -if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) - add_library(libssh2-shared SHARED $) - # we want it to be called libssh2 on all platforms - set_target_properties(libssh2-shared PROPERTIES PREFIX "" OUTPUT_NAME "libssh2") - set_target_properties(libssh2 PROPERTIES POSITION_INDEPENDENT_CODE ON) -endif() -if(BUILD_BOTH_LIBS OR NOT BUILD_SHARED_LIBS) - add_library(libssh2-static STATIC $) - set_target_properties(libssh2-static PROPERTIES PREFIX "" OUTPUT_NAME "libssh2") -endif() +add_library(libssh2 ${SOURCES}) +# we want it to be called libssh2 on all platforms +set_target_properties(libssh2 PROPERTIES PREFIX "") target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) target_include_directories(libssh2 @@ -246,10 +238,6 @@ endif(CLEAR_MEMORY) add_feature_info("Shared library" BUILD_SHARED_LIBS "creating libssh2 as a shared library (.so/.dll)") -option(BUILD_BOTH_LIBS "Build both static and shared libraries" OFF) -add_feature_info("Static and Shared libraries" BUILD_BOTH_LIBS - "creating libssh2 as a both a static (.a) and shared library (.so/.dll)") - option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression") add_feature_info(Compression ENABLE_ZLIB_COMPRESSION "using zlib for compression") @@ -386,10 +374,6 @@ else() target_link_libraries(libssh2 PRIVATE ${LIBRARIES}) endif() -if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) - target_link_libraries(libssh2-shared PUBLIC libssh2) -endif() - ## Installation install(FILES @@ -398,28 +382,14 @@ install(FILES ${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) - install(TARGETS libssh2 - EXPORT Libssh2Config - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(TARGETS libssh2-shared - EXPORT Libssh2Config - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif() -if(BUILD_BOTH_LIBS OR NOT BUILD_SHARED_LIBS) - install(TARGETS libssh2-static - EXPORT Libssh2Config - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif() +install(TARGETS libssh2 + EXPORT Libssh2Config + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) - list(APPEND _RUNTIME_DEPENDENCIES $) +if(BUILD_SHARED_LIBS) + list(APPEND _RUNTIME_DEPENDENCIES $) endif() set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL @@ -451,16 +421,9 @@ install( ## Versioning -if(BUILD_BOTH_LIBS OR BUILD_SHARED_LIBS) - set_target_properties(libssh2-shared PROPERTIES - SOVERSION 1 - VERSION 1.0.1) -endif() -if(BUILD_BOTH_LIBS OR NOT BUILD_SHARED_LIBS) - set_target_properties(libssh2-static PROPERTIES - SOVERSION 1 - VERSION 1.0.1) -endif() +set_target_properties(libssh2 PROPERTIES + SOVERSION 1 + VERSION 1.0.1) include(CMakePackageConfigHelpers) write_basic_package_version_file( From b0b2b3112c4860ed44fdc7f0223b421fbc35b58f Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Wed, 23 Feb 2022 09:20:38 -0800 Subject: [PATCH 034/424] Added crypto backend list to template Added OS version as well --- .github/ISSUE_TEMPLATE/bug_report.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index f883236e6b..b761680608 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -19,8 +19,9 @@ A recipe or example code that reproduces the problem? A stack trace from a crash A clear and concise description of what you expected to happen. **Version (please complete the following information):** - - OS: [e.g. iOS] - - libssh2 version [e.g. 1.8.0] + - OS and version: [e.g. iOS, macOS, Windows, Linux (distro)] + - libssh2 version: [e.g. 1.10.0] + - crypto backend: [OpenSSL, MbedTLS, Libgcrypt, WinCNG, OS400, WolfSSL, None] **Additional context** Add any other context about the problem here. From 292830abb80ff73f2b11fb750194346ff4694618 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Sat, 26 Feb 2022 10:53:14 -0800 Subject: [PATCH 035/424] Added LibreSSL to crypto backend list --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b761680608..b9754c6536 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -21,7 +21,7 @@ A clear and concise description of what you expected to happen. **Version (please complete the following information):** - OS and version: [e.g. iOS, macOS, Windows, Linux (distro)] - libssh2 version: [e.g. 1.10.0] - - crypto backend: [OpenSSL, MbedTLS, Libgcrypt, WinCNG, OS400, WolfSSL, None] + - crypto backend: [OpenSSL, MbedTLS, Libgcrypt, LibreSSL, WinCNG, OS400, WolfSSL, None] **Additional context** Add any other context about the problem here. From 87d208c95d712f2bcdd2cd9f6150b2e7f393336f Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Wed, 16 Mar 2022 04:29:31 +0100 Subject: [PATCH 036/424] CI: store and reuse OpenSSH Server docker image used for tests Supersedes #588 Fixes #665 Closes #685 --- .github/workflows/ci.yml | 6 +-- .github/workflows/openssh_server.yml | 66 ++++++++++++++++++++++++++++ .travis.yml | 7 ++- appveyor.yml | 4 +- tests/openssh_fixture.c | 27 +++++++++--- 5 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/openssh_server.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00846b1bb4..7546ff91ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,10 +85,8 @@ jobs: cd bin cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. cmake --build . - pushd ../tests - docker build -t libssh2/openssh_server openssh_server - popd - CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test + export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) + ctest -VV --output-on-failure cmake --build . --target package fuzzer: runs-on: ubuntu-latest diff --git a/.github/workflows/openssh_server.yml b/.github/workflows/openssh_server.yml new file mode 100644 index 0000000000..f4e0aebf0d --- /dev/null +++ b/.github/workflows/openssh_server.yml @@ -0,0 +1,66 @@ +# Copyright (c) 2022 Marc Hoersken +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +name: OpenSSH Server Docker Image + +on: + push: + branches: [ master ] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@v1 + + - shell: bash + id: hash + run: echo "::set-output name=hash::$(git rev-parse --short=20 HEAD:tests/openssh_server)" + + - shell: bash + id: poll + run: docker manifest inspect ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server:${{ steps.hash.outputs.hash }} + continue-on-error: true + + - uses: docker/metadata-action@v3 + id: meta + with: + images: ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server + tags: | + type=raw,value=${{ steps.hash.outputs.hash }} + if: ${{ steps.poll.outcome == 'failure' }} + + - uses: docker/build-push-action@v2 + with: + context: ./tests/openssh_server + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + if: ${{ steps.poll.outcome == 'failure' }} diff --git a/.travis.yml b/.travis.yml index ec290126ea..bc1a96ffda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -112,10 +112,9 @@ script: - | if [ "$B" = "cmake" ]; then mkdir bin - cd tests - docker build -t libssh2/openssh_server openssh_server - cd ../bin - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test && cmake --build . --target package + cd bin + export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) + cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && ctest -VV --output-on-failure && cmake --build . --target package fi - | if [ "$B" = "fuzzer" ]; then diff --git a/appveyor.yml b/appveyor.yml index c2731ca2bd..1c374b4712 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -103,8 +103,8 @@ before_test: } test_script: - - ps: cd _builds - - ps: ctest -VV -C $($env:CONFIGURATION) --output-on-failure + - ps: $env:OPENSSH_SERVER_IMAGE=[string] (& bash -c "echo ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)") + - ps: cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure on_failure: - ps: if(Test-Path _builds/CMakeFiles/CMakeOutput.log) { cat _builds/CMakeFiles/CMakeOutput.log } diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 474b20aa0f..1baf205236 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -143,8 +143,26 @@ static int run_command(char **output, const char *command, ...) return ret; } +static const char *openssh_server_image(void) +{ + return getenv("OPENSSH_SERVER_IMAGE"); +} + static int build_openssh_server_docker_image(void) { + const char *container_image_name = openssh_server_image(); + if(container_image_name != NULL) { + int ret = run_command(NULL, "docker pull --quiet %s", + container_image_name); + if(ret == 0) { + ret = run_command(NULL, "docker tag %s libssh2/openssh_server", + container_image_name); + if(ret == 0) { + return ret; + } + } + } + return run_command(NULL, "docker build --quiet " "-t libssh2/openssh_server " "openssh_server"); @@ -164,11 +182,10 @@ static int start_openssh_server(char **container_id_out) "libssh2/openssh_server", container_host_port); } - else { - return run_command(container_id_out, - "docker run --rm -d -p 22 " - "libssh2/openssh_server"); - } + + return run_command(container_id_out, + "docker run --rm -d -p 22 " + "libssh2/openssh_server"); } static int stop_openssh_server(char *container_id) From c2c877b70bd04157612a32bf1bcc9f09490c1af0 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Wed, 16 Mar 2022 22:54:33 +0100 Subject: [PATCH 037/424] tests/openssh_fixture.c: print command after variable expansion --- tests/openssh_fixture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 1baf205236..c6484ba5ce 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -91,7 +91,7 @@ static int run_command_varg(char **output, const char *command, va_list args) return -1; } - fprintf(stdout, "Command: %s\n", command); + fprintf(stdout, "Command: %s\n", command_buf); #ifdef WIN32 pipe = _popen(buf, "r"); #else From 049003c3d6c2ad5eb323c94512c62f402579ec80 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Wed, 16 Mar 2022 03:35:35 +0100 Subject: [PATCH 038/424] wincng: rename struct field referring to the DH private big number Closes #684 --- src/wincng.c | 29 +++++++++++++++-------------- src/wincng.h | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/wincng.c b/src/wincng.c index 58e2251f20..ee5f9e6dbd 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -2254,9 +2254,9 @@ void _libssh2_dh_init(_libssh2_dh_ctx *dhctx) { /* Random from client */ - dhctx->bn = NULL; dhctx->dh_handle = NULL; dhctx->dh_params = NULL; + dhctx->dh_privbn = NULL; } void @@ -2272,9 +2272,9 @@ _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx) free(dhctx->dh_params); dhctx->dh_params = NULL; } - if(dhctx->bn) { - _libssh2_wincng_bignum_free(dhctx->bn); - dhctx->bn = NULL; + if(dhctx->dh_privbn) { + _libssh2_wincng_bignum_free(dhctx->dh_privbn); + dhctx->dh_privbn = NULL; } } @@ -2419,25 +2419,26 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, if(dh_key_blob->dwMagic == BCRYPT_DH_PRIVATE_MAGIC) { /* BCRYPT_DH_PRIVATE_BLOB additionally contains the Private data */ - dhctx->bn = _libssh2_wincng_bignum_init(); - if(!dhctx->bn) { + dhctx->dh_privbn = _libssh2_wincng_bignum_init(); + if(!dhctx->dh_privbn) { _libssh2_wincng_safe_free(blob, key_length_bytes); return -1; } - if(_libssh2_wincng_bignum_resize(dhctx->bn, dh_key_blob->cbKey)) { + if(_libssh2_wincng_bignum_resize(dhctx->dh_privbn, + dh_key_blob->cbKey)) { _libssh2_wincng_safe_free(blob, key_length_bytes); return -1; } /* Copy the private key data into the dhctx bignum data buffer */ - memcpy(dhctx->bn->bignum, + memcpy(dhctx->dh_privbn->bignum, blob + sizeof(*dh_key_blob) + 3 * dh_key_blob->cbKey, dh_key_blob->cbKey); /* Make sure the private key is an odd number, because only * odd primes can be used with the RSA-based fallback while * DH itself does not seem to care about it being odd or not. */ - if(!(dhctx->bn->bignum[dhctx->bn->length-1] % 2)) { + if(!(dhctx->dh_privbn->bignum[dhctx->dh_privbn->length-1] % 2)) { _libssh2_wincng_safe_free(blob, key_length_bytes); /* discard everything first, then try again */ _libssh2_dh_dtor(dhctx); @@ -2450,12 +2451,12 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, } /* Generate x and e */ - dhctx->bn = _libssh2_wincng_bignum_init(); - if(!dhctx->bn) + dhctx->dh_privbn = _libssh2_wincng_bignum_init(); + if(!dhctx->dh_privbn) return -1; - if(_libssh2_wincng_bignum_rand(dhctx->bn, group_order * 8 - 1, 0, -1)) + if(_libssh2_wincng_bignum_rand(dhctx->dh_privbn, (group_order*8)-1, 0, -1)) return -1; - if(_libssh2_wincng_bignum_mod_exp(public, g, dhctx->bn, p)) + if(_libssh2_wincng_bignum_mod_exp(public, g, dhctx->dh_privbn, p)) return -1; return 0; @@ -2588,7 +2589,7 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, fb: /* Compute the shared secret */ - return _libssh2_wincng_bignum_mod_exp(secret, f, dhctx->bn, p); + return _libssh2_wincng_bignum_mod_exp(secret, f, dhctx->dh_privbn, p); } /* _libssh2_supported_key_sign_algorithms diff --git a/src/wincng.h b/src/wincng.h index 538cc4314f..ea7554531a 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -410,7 +410,7 @@ typedef struct { BCRYPT_DH_PARAMETER_HEADER *dh_params; /* records the parsed out private key component for * fallback if the DH API raw KDF is not supported */ - struct _libssh2_wincng_bignum *bn; + struct _libssh2_wincng_bignum *dh_privbn; } _libssh2_dh_ctx; #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) From e7e1312b0cbfa643e2f8bf5f2036ce5147ed797d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 21 Mar 2022 09:31:39 +0100 Subject: [PATCH 039/424] misc/libssh2_copy_string: avoid malloc zero bytes Avoids the inconsistent malloc return code for malloc(0) Closes #686 --- src/misc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/misc.c b/src/misc.c index 5e4c4335ee..4f1e0543fd 100644 --- a/src/misc.c +++ b/src/misc.c @@ -817,12 +817,18 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf, return -1; } - *outbuf = LIBSSH2_ALLOC(session, str_len); - if(*outbuf) { - memcpy(*outbuf, str, str_len); + if(str_len) { + *outbuf = LIBSSH2_ALLOC(session, str_len); + if(*outbuf) { + memcpy(*outbuf, str, str_len); + } + else { + return -1; + } } else { - return -1; + *outlen = 0; + *outbuf = NULL; } if(outlen) From 79855b37d290c43600944e7bb9cbe80625b02d38 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Mon, 4 Apr 2022 20:57:10 -0300 Subject: [PATCH 040/424] Add RSA-SHA2 support for the mbedtls backend (#688) File: mbedtls.c Notes: * Add sha2 support for RSA key upgrading to mbedTLS backend Credit: gbaraldi --- src/mbedtls.c | 93 +++++++++++++++++++++++++++++++++++++++++---------- src/mbedtls.h | 9 ++++- 2 files changed, 84 insertions(+), 18 deletions(-) diff --git a/src/mbedtls.c b/src/mbedtls.c index dc76ef59a9..4ff751b3a6 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -455,28 +455,58 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, } int -_libssh2_mbedtls_rsa_sha1_verify(libssh2_rsa_ctx *rsa, - const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, - unsigned long m_len) +_libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, + size_t hash_len, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, unsigned long m_len) { - unsigned char hash[SHA_DIGEST_LENGTH]; int ret; + int md_type; + unsigned char *hash = malloc(hash_len); + if(hash == NULL) + return -1; - ret = _libssh2_mbedtls_hash(m, m_len, MBEDTLS_MD_SHA1, hash); - if(ret) + if(hash_len == SHA_DIGEST_LENGTH) { + md_type = MBEDTLS_MD_SHA1; + } + else if(hash_len == SHA256_DIGEST_LENGTH) { + md_type = MBEDTLS_MD_SHA256; + } + else if(hash_len == SHA512_DIGEST_LENGTH) { + md_type = MBEDTLS_MD_SHA512; + } + else{ + free(hash); + return -1; /* unsupported digest */ + } + ret = _libssh2_mbedtls_hash(m, m_len, md_type, hash); + + if(ret != 0) { + free(hash); return -1; /* failure */ + } - ret = mbedtls_rsa_pkcs1_verify(rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, - MBEDTLS_MD_SHA1, SHA_DIGEST_LENGTH, + ret = mbedtls_rsa_pkcs1_verify(rsactx, NULL, NULL, MBEDTLS_RSA_PUBLIC, + md_type, hash_len, hash, sig); + free(hash); - return (ret == 0) ? 0 : -1; + return (ret == 1) ? 0 : -1; } int -_libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION *session, +_libssh2_mbedtls_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, unsigned long m_len) +{ + return _libssh2_mbedtls_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, + sig, sig_len, m, m_len); +} + +int +_libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, libssh2_rsa_ctx *rsa, const unsigned char *hash, size_t hash_len, @@ -486,7 +516,7 @@ _libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION *session, int ret; unsigned char *sig; unsigned int sig_len; - + int md_type; (void)hash_len; sig_len = rsa->len; @@ -494,9 +524,22 @@ _libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION *session, if(!sig) { return -1; } - + if(hash_len == SHA_DIGEST_LENGTH) { + md_type = MBEDTLS_MD_SHA1; + } + else if(hash_len == SHA256_DIGEST_LENGTH) { + md_type = MBEDTLS_MD_SHA256; + } + else if(hash_len == SHA512_DIGEST_LENGTH) { + md_type = MBEDTLS_MD_SHA512; + } + else { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Unsupported hash digest length"); + ret = -1; + } ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, - MBEDTLS_MD_SHA1, SHA_DIGEST_LENGTH, + md_type, hash_len, hash, sig); if(ret) { LIBSSH2_FREE(session, sig); @@ -509,6 +552,17 @@ _libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION *session, return (ret == 0) ? 0 : -1; } +int +_libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION * session, + libssh2_rsa_ctx * rsactx, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, size_t *signature_len) +{ + return _libssh2_mbedtls_rsa_sha2_sign(session, rsactx, hash, hash_len, + signature, signature_len); +} + void _libssh2_mbedtls_rsa_free(libssh2_rsa_ctx *ctx) { @@ -1260,8 +1314,13 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, size_t key_method_len) { (void)session; - (void)key_method; - (void)key_method_len; + +#if LIBSSH2_RSA_SHA2 + if(key_method_len == 7 && + memcmp(key_method, "ssh-rsa", key_method_len) == 0) { + return "rsa-sha2-512,rsa-sha2-256,ssh-rsa"; + } +#endif return NULL; } diff --git a/src/mbedtls.h b/src/mbedtls.h index 0450113f06..e86ebd26f5 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -71,7 +71,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 -#define LIBSSH2_RSA_SHA2 0 +#define LIBSSH2_RSA_SHA2 1 #define LIBSSH2_DSA 0 #ifdef MBEDTLS_ECDSA_C # define LIBSSH2_ECDSA 1 @@ -243,9 +243,16 @@ #define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \ _libssh2_mbedtls_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) +#define _libssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \ + _libssh2_mbedtls_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) + + #define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \ _libssh2_mbedtls_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) +#define _libssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \ + _libssh2_mbedtls_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) + #define _libssh2_rsa_free(rsactx) \ _libssh2_mbedtls_rsa_free(rsactx) From b95e75823923731a06c76a3637fa3654876c8737 Mon Sep 17 00:00:00 2001 From: Harry Sintonen Date: Tue, 5 Apr 2022 03:00:04 +0300 Subject: [PATCH 041/424] Fix build since openssl 1.1.0 when ECDSA and/or RIPEMD are disabled (#666) File: openssl.h Notes: In openssl 1.1.0 and later openssl decided to change some of the defines used to check if certain features are not compiled in the libraries. This updates the define checks. Credit: Harry Sintonen Co-authored-by: Harry Sintonen --- src/openssl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openssl.h b/src/openssl.h index 3eef023687..5704e1eb44 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -115,7 +115,7 @@ # define LIBSSH2_DSA 1 #endif -#ifdef OPENSSL_NO_ECDSA +#if defined(OPENSSL_NO_ECDSA) || defined(OPENSSL_NO_EC) # define LIBSSH2_ECDSA 0 #else # define LIBSSH2_ECDSA 1 @@ -135,7 +135,7 @@ # define LIBSSH2_MD5 1 #endif -#ifdef OPENSSL_NO_RIPEMD +#if defined(OPENSSL_NO_RIPEMD) || defined(OPENSSL_NO_RMD160) # define LIBSSH2_HMAC_RIPEMD 0 #else # define LIBSSH2_HMAC_RIPEMD 1 From 3489ee9a6fb8ceb674a4d72eeaf09b3ddfa60a2d Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Mon, 11 Apr 2022 09:46:52 -0700 Subject: [PATCH 042/424] NULL check before calling session_handshake --- tests/ossfuzz/ssh2_client_fuzzer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ossfuzz/ssh2_client_fuzzer.cc b/tests/ossfuzz/ssh2_client_fuzzer.cc index d9f5ab516c..f0a63f4fd9 100644 --- a/tests/ossfuzz/ssh2_client_fuzzer.cc +++ b/tests/ossfuzz/ssh2_client_fuzzer.cc @@ -61,7 +61,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) libssh2_session_set_blocking(session, 1); } - if(libssh2_session_handshake(session, socket_fds[0])) { + if(session && libssh2_session_handshake(session, socket_fds[0])) { goto EXIT_LABEL; } From dd0b5b2d2b8f5ef7af826e1e1aa1d48a0442c351 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Mon, 11 Apr 2022 09:49:00 -0700 Subject: [PATCH 043/424] Changed NULL check to avoid logic change --- tests/ossfuzz/ssh2_client_fuzzer.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ossfuzz/ssh2_client_fuzzer.cc b/tests/ossfuzz/ssh2_client_fuzzer.cc index f0a63f4fd9..320a601e3e 100644 --- a/tests/ossfuzz/ssh2_client_fuzzer.cc +++ b/tests/ossfuzz/ssh2_client_fuzzer.cc @@ -60,8 +60,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) if(session) { libssh2_session_set_blocking(session, 1); } + else { + goto EXIT_LABEL; + } - if(session && libssh2_session_handshake(session, socket_fds[0])) { + if(libssh2_session_handshake(session, socket_fds[0])) { goto EXIT_LABEL; } From dba9ad9d3dc99ffcecc90e2b1f538b68f18e0845 Mon Sep 17 00:00:00 2001 From: Zenju Date: Mon, 25 Apr 2022 20:49:11 +0200 Subject: [PATCH 044/424] Fix buffer overflow during SSH_MSG_USERAUTH_BANNER (#693) File: userauth.c Notes: This patch fixes application crashes due to heap corruption. Turns out the null terminator is written one byte outside of the allocated area. Credit: Zenju --- src/userauth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/userauth.c b/src/userauth.c index 551f24d254..d61d6b91dd 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -146,14 +146,14 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, return NULL; } banner_len = _libssh2_ntohu32(session->userauth_list_data + 1); - if(banner_len >= session->userauth_list_data_len - 5) { + if(banner_len > session->userauth_list_data_len - 5) { LIBSSH2_FREE(session, session->userauth_list_data); session->userauth_list_data = NULL; _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, "Unexpected userauth banner size"); return NULL; } - session->userauth_banner = LIBSSH2_ALLOC(session, banner_len); + session->userauth_banner = LIBSSH2_ALLOC(session, banner_len + 1); if(!session->userauth_banner) { LIBSSH2_FREE(session, session->userauth_list_data); session->userauth_list_data = NULL; @@ -161,7 +161,7 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, "Unable to allocate memory for userauth_banner"); return NULL; } - memmove(session->userauth_banner, session->userauth_list_data + 5, + memcpy(session->userauth_banner, session->userauth_list_data + 5, banner_len); session->userauth_banner[banner_len] = '\0'; _libssh2_debug(session, LIBSSH2_TRACE_AUTH, From 4b057bd2d9b4cccfbdbce861b8a47305ee147446 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Fri, 6 May 2022 08:40:19 -0700 Subject: [PATCH 045/424] Ensure KEX replies don't include extra bytes (#696) Addresses #695 Credit: Michael Buckley, reported by Harry Sintonen --- src/hostkey.c | 12 ++++++++++++ src/misc.c | 6 ++++++ src/misc.h | 1 + 3 files changed, 19 insertions(+) diff --git a/src/hostkey.c b/src/hostkey.c index f005d90fcb..90750b6502 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -111,6 +111,9 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, if(_libssh2_get_string(&buf, &n, &n_len)) return -1; + if(!_libssh2_eob(&buf)) + return -1; + if(_libssh2_rsa_new(&rsactx, e, e_len, n, n_len, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0)) { return -1; @@ -504,6 +507,9 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session, if(_libssh2_get_string(&buf, &y, &y_len)) return -1; + if(!_libssh2_eob(&buf)) + return -1; + if(_libssh2_dsa_new(&dsactx, p, p_len, q, q_len, g, g_len, y, y_len, NULL, 0)) { return -1; @@ -749,6 +755,9 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session, if(_libssh2_get_string(&buf, &public_key, &key_len)) return -1; + if(!_libssh2_eob(&buf)) + return -1; + if(_libssh2_ecdsa_curve_name_with_octal_new(&ecdsactx, public_key, key_len, type)) return -1; @@ -1056,6 +1065,9 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session, if(_libssh2_get_string(&buf, &key, &key_len)) return -1; + if(!_libssh2_eob(&buf)) + return -1; + if(_libssh2_ed25519_new_public(&ctx, session, key, key_len) != 0) { return -1; } diff --git a/src/misc.c b/src/misc.c index 4f1e0543fd..ae0fc91bcb 100644 --- a/src/misc.c +++ b/src/misc.c @@ -880,6 +880,12 @@ int _libssh2_check_length(struct string_buf *buf, size_t len) return ((len <= left) && (left <= buf->len)); } +int _libssh2_eob(struct string_buf *buf) +{ + unsigned char *endp = &buf->data[buf->len]; + return buf->dataptr >= endp; +} + /* Wrappers */ int _libssh2_bcrypt_pbkdf(const char *pass, diff --git a/src/misc.h b/src/misc.h index 3d4206dbf6..d4d6268430 100644 --- a/src/misc.h +++ b/src/misc.h @@ -103,6 +103,7 @@ int _libssh2_copy_string(LIBSSH2_SESSION* session, struct string_buf *buf, int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf, size_t *outlen); int _libssh2_check_length(struct string_buf *buf, size_t requested_len); +int _libssh2_eob(struct string_buf *buf); #if defined(LIBSSH2_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) /* provide a private one */ From b952674f120748174ed2c0fb93e7bd78cf355cac Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 19 May 2022 18:35:16 +0200 Subject: [PATCH 046/424] Openssl: add support for LibreSSL 3.5.x (#700) LibreSSL 3.5.0 made more structures opaque, so let's enable existing support for that when building against these LibreSSL versions. Ref: https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.5.0-relnotes.txt Credit: Viktor Szakats --- src/openssl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openssl.h b/src/openssl.h index 5704e1eb44..60c0c2c340 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -95,7 +95,8 @@ #include #if (OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !defined(LIBRESSL_VERSION_NUMBER)) || defined(LIBSSH2_WOLFSSL) + !defined(LIBRESSL_VERSION_NUMBER)) || defined(LIBSSH2_WOLFSSL) || \ + LIBRESSL_VERSION_NUMBER >= 0x3050000fL /* For wolfSSL, whether the structs are truly opaque or not, it's best to not * rely on their internal data members being exposed publicly. */ # define HAVE_OPAQUE_STRUCTS 1 From 3af1f4f446f19167678e24e4471cc82847f99d1f Mon Sep 17 00:00:00 2001 From: AyushiN <36621150+ANaphade@users.noreply.github.com> Date: Mon, 23 May 2022 23:05:28 +0530 Subject: [PATCH 047/424] Fixed typo #697 (#701) Credit: AyushiN --- src/kex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kex.c b/src/kex.c index 8f028084a9..20bf8b0dae 100644 --- a/src/kex.c +++ b/src/kex.c @@ -2603,7 +2603,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, session->session_id = LIBSSH2_ALLOC(session, digest_length); if(!session->session_id) { ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allxcocate buffer for " + "Unable to allocate buffer for " "SHA digest"); goto clean_exit; } From 3adc8e908160783d28fc3f9e2676b40c3d3e938c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 26 May 2022 09:02:22 +0000 Subject: [PATCH 048/424] cmake: do not add libssh2.rc to the static library --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50c028c45a..cb8fee1218 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -213,7 +213,7 @@ set(SOURCES userauth.h version.c) -if(WIN32) +if(WIN32 AND BUILD_SHARED_LIBS) list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) endif() From 7483edfada1f7e17cf8f9ac1c87ffa3d814c987e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 29 Jun 2022 18:37:33 +0000 Subject: [PATCH 049/424] configure: add --disable-tests option --- Makefile.am | 5 ++++- configure.ac | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 986441bd68..b0b58d1824 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,9 @@ AUTOMAKE_OPTIONS = foreign nostdinc -SUBDIRS = src tests docs +SUBDIRS = src docs +if ENABLE_TESTS +SUBDIRS += tests +endif if BUILD_EXAMPLES SUBDIRS += example endif diff --git a/configure.ac b/configure.ac index ca3cbee164..6fb7cc8260 100644 --- a/configure.ac +++ b/configure.ac @@ -265,6 +265,18 @@ AC_HELP_STRING([--disable-hidden-symbols],[Leave all symbols with default visibi AC_MSG_RESULT(no) ) +# Build tests? +AC_ARG_ENABLE([tests], + [AS_HELP_STRING([--disable-tests], [Disable tests @<:@default=enabled@:>@])], + [ + if ! test "x${enable_tests}" = "xyes"; then + enable_tests="no" + fi + ], + [enable_tests="yes"]) +AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" = xyes]) + + # Build example applications? AC_MSG_CHECKING([whether to build example applications]) AC_ARG_ENABLE([examples-build], From 4b21e49d9d2db74579b18804ed1f5eeb16578b2f Mon Sep 17 00:00:00 2001 From: Sandeep Bansal Date: Thu, 28 Jul 2022 08:57:34 -0700 Subject: [PATCH 050/424] Support RSA certificate authentication (#710) * Adding support for signed RSA keys and unit test Credit: Sandeep Bansal --- .gitignore | 1 + src/hostkey.c | 13 +++++ src/userauth.c | 6 +++ tests/CMakeLists.txt | 1 + tests/openssh_fixture.c | 2 +- tests/openssh_server/Dockerfile | 16 ++++-- tests/openssh_server/ca_rsa | 38 ++++++++++++++ tests/openssh_server/ca_rsa.pub | 1 + tests/signed_key_rsa | 49 +++++++++++++++++++ tests/signed_key_rsa-cert.pub | 1 + tests/signed_key_rsa.pub | 1 + ...uth_succeeds_with_correct_signed_rsa_key.c | 38 ++++++++++++++ 12 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 tests/openssh_server/ca_rsa create mode 100644 tests/openssh_server/ca_rsa.pub create mode 100644 tests/signed_key_rsa create mode 100644 tests/signed_key_rsa-cert.pub create mode 100644 tests/signed_key_rsa.pub create mode 100644 tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c diff --git a/.gitignore b/.gitignore index d256f68b74..f740e52894 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ libssh2.pc TAGS *~ .DS_Store +build \ No newline at end of file diff --git a/src/hostkey.c b/src/hostkey.c index 90750b6502..6004122d08 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -451,6 +451,18 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_512 = { #endif /* LIBSSH2_RSA_SHA2 */ +static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_cert = { + "ssh-rsa-cert-v01@openssh.com", + MD5_DIGEST_LENGTH, + NULL, + hostkey_method_ssh_rsa_initPEM, + hostkey_method_ssh_rsa_initPEMFromMemory, + NULL, + hostkey_method_ssh_rsa_signv, + NULL, /* encrypt */ + hostkey_method_ssh_rsa_dtor, +}; + #endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA @@ -1246,6 +1258,7 @@ static const LIBSSH2_HOSTKEY_METHOD *hostkey_methods[] = { &hostkey_method_ssh_rsa_sha2_256, #endif /* LIBSSH2_RSA_SHA2 */ &hostkey_method_ssh_rsa, + &hostkey_method_ssh_rsa_cert, #endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA &hostkey_method_ssh_dss, diff --git a/src/userauth.c b/src/userauth.c index d61d6b91dd..a09c3e9fd7 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1150,6 +1150,12 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, static int plain_method_len(const char *method, size_t method_len) { + if(!strncmp("ssh-rsa-cert-v01@openssh.com", + method, + method_len)) { + return 7; + } + if(!strncmp("ecdsa-sha2-nistp256-cert-v01@openssh.com", method, method_len) || diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 26244309b1..620c93939f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -140,6 +140,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL") public_key_auth_succeeds_with_correct_ed25519_key_from_mem public_key_auth_succeeds_with_correct_ecdsa_key public_key_auth_succeeds_with_correct_signed_ecdsa_key + public_key_auth_succeeds_with_correct_signed_rsa_key ) endif() endif() diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index c6484ba5ce..872058f865 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -416,4 +416,4 @@ void stop_openssh_fixture() int open_socket_to_openssh_server() { return open_socket_to_container(running_container_id); -} +} \ No newline at end of file diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index c5ce2224d0..ed33e867c4 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -FROM debian:jessie +FROM debian:bullseye RUN apt-get update \ && apt-get install -y openssh-server \ @@ -60,17 +60,27 @@ RUN chmod 600 /etc/ssh/ssh_host_ed25519_key COPY ca_ecdsa.pub /tmp/etc/ssh/ca_ecdsa.pub RUN mv /tmp/etc/ssh/ca_ecdsa.pub /etc/ssh/ca_ecdsa.pub -RUN chmod 600 /etc/ssh/ca_ecdsa.pub +RUN cp /etc/ssh/ca_ecdsa.pub /etc/ssh/ca_main.pub +RUN chmod 600 /etc/ssh/ca_main.pub COPY ca_ecdsa /tmp/etc/ssh/ca_ecdsa RUN mv /tmp/etc/ssh/ca_ecdsa /etc/ssh/ca_ecdsa RUN chmod 600 /etc/ssh/ca_ecdsa +COPY ca_rsa.pub /tmp/etc/ssh/ca_rsa.pub +RUN mv /tmp/etc/ssh/ca_rsa.pub /etc/ssh/ca_rsa.pub +RUN cat /etc/ssh/ca_rsa.pub >> /etc/ssh/ca_main.pub + +COPY ca_rsa /tmp/etc/ssh/ca_rsa +RUN mv /tmp/etc/ssh/ca_rsa /etc/ssh/ca_rsa +RUN chmod 600 /etc/ssh/ca_rsa + RUN adduser --disabled-password --gecos 'Test user for libssh2 integration tests' libssh2 RUN echo 'libssh2:my test password' | chpasswd RUN sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config -RUN echo "TrustedUserCAKeys /etc/ssh/ca_ecdsa.pub" >> /etc/ssh/sshd_config +RUN echo "TrustedUserCAKeys /etc/ssh/ca_main.pub" >> /etc/ssh/sshd_config +RUN echo "PubkeyAcceptedKeyTypes=+ssh-dss" >> /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd diff --git a/tests/openssh_server/ca_rsa b/tests/openssh_server/ca_rsa new file mode 100644 index 0000000000..8b5aa57c94 --- /dev/null +++ b/tests/openssh_server/ca_rsa @@ -0,0 +1,38 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn +NhAAAAAwEAAQAAAYEAxIgbEZbIoQoNJyRjalEYbMwmcNRcGZg6ZA+uC+hxX9lPxhVxYAwb +WCWfM3YLmvkQPRf0DYateDlHpiV9/R4IAKMfwHMINbyj5ulj2AG9wzMs10+MLN9kmxXeZX +f7EK6iVHjMWhS7tX9NnmNFLbUHuPpzI6DODHvfEIaO084KQyIJ/Z5bONko7eijPZrqkwSF +b+FEsIvSLBZ/ueHtAhI34IhclPP/Gx+r6da7TDwOpuL7oncrdqT+zxxZ1J4pEBrGhuJXTv +w/xtBRbTKj13gtcEFyOUR50Z7PU4iOhKd694euGSOYgWGXhtehZPp7hr7afli1hOZtNb3x +B3OaPqdPY/jYtZkOaZlKtwDjPzGTIfngpE7LZwsp4P2xxGUyCkItZ57uveDHKvFtb9+MID +MgTd27xOuTYYyHS7m5x7w4M1Z9du8IzxHXlQ/UobQAsTUuGusSQloOpZR1cs3s6p4+vLpl +63tNjLFy2xYpFf3xL1Dl1Kf6w3qPiyYs5NmxwJcpAAAFgFr4gLRa+IC0AAAAB3NzaC1yc2 +EAAAGBAMSIGxGWyKEKDSckY2pRGGzMJnDUXBmYOmQPrgvocV/ZT8YVcWAMG1glnzN2C5r5 +ED0X9A2GrXg5R6Ylff0eCACjH8BzCDW8o+bpY9gBvcMzLNdPjCzfZJsV3mV3+xCuolR4zF +oUu7V/TZ5jRS21B7j6cyOgzgx73xCGjtPOCkMiCf2eWzjZKO3ooz2a6pMEhW/hRLCL0iwW +f7nh7QISN+CIXJTz/xsfq+nWu0w8Dqbi+6J3K3ak/s8cWdSeKRAaxobiV078P8bQUW0yo9 +d4LXBBcjlEedGez1OIjoSneveHrhkjmIFhl4bXoWT6e4a+2n5YtYTmbTW98Qdzmj6nT2P4 +2LWZDmmZSrcA4z8xkyH54KROy2cLKeD9scRlMgpCLWee7r3gxyrxbW/fjCAzIE3du8Trk2 +GMh0u5uce8ODNWfXbvCM8R15UP1KG0ALE1LhrrEkJaDqWUdXLN7OqePry6Zet7TYyxctsW +KRX98S9Q5dSn+sN6j4smLOTZscCXKQAAAAMBAAEAAAGAAI1BRjNeLNWSY+G+RbYkk2mfUg +HGoGvE/jLtEit85f/+MVguEU73ZK/2WnaiYbUBTqqajM8r/YJrqRPB3swOybGrjSbFhyEY +dLWDCkA3AC1Mmu4mPpoB9k2BaleD5PAYlJQiPr6AKGpLFX7B2vb/Jo3NdPQmn/JZFfrKu9 +2AOeAGlyeyqd4yNzjH/IxKzE7e8Ql43+YEmQsXILZ5q9/ROFgpqmFk/faAzQ9FR1mD0QQi +ILqk7JhZ/srdlbM7+keY9dV/5AAdf9UvdepQghszERWB1ccq6tY1Cd8Pk1iXBAMhtGnpKZ +6nwAV+inPPCxCKRESSL0TKRazUsy6AvWye7zBBUP6zqzB66/Dm8K7CqHWj/yG27VSp6mjU +PIdysQK6WlnTRaQBWc7sjeBy5S702bWA+EwJoAgZ+8Yl6w6ltmhUfZONVrZSFLlrfk33Dm +2TYDTfS4c7FChh494MVE6Du30LlF8sm7qWws8TLJnBHIMuT/aW1eI/DRNgkw5wkx+BAAAA +wDC8XxvhkZiuqNiHyqy3q2nlBS4n87PR/dOwSkk108mU6S50zQXt1k8XkK0Dn8ZB/aWXym +rIDY0C3/xmUj2FswFmnDnvBa/dvCXzSZKjUufMnRXWBZWU+bhQP9ivzsiIKnDsfaJvIWo1 +4PN/BapwL1s+/6CwRLgoSerBrWpd4YTV0LEaMqpu0LA79wWUe+XSjr2H8PnQ2SURHwHn6C +OwYLqZISPcZZEfYGtOshWZQl0t6ElWWU1WRQScbhv/6hTTEgAAAMEA5FsniRNsgN5KUmIq +HYuCzjBVpkzCHI8C3Wnh2Zl7qUKNQlBVg0EQlRXb+NAcfQMg3izZf6JO0mSOxJmcU9rGUM +40QB2jF4DxYIJWHoCeYw/0vL88+AClCHnwAGisFNXLX+b+C60FiVc0c1mcxnL446/Ouenr +g9nsxG0nq3GzN41l+6OEpofgaYdCEMEik7GcVS/G6pxLZVCCxzLuXOQXJY9UzTRPrkZLGr +xi6xEYO8DNptpkfZRZIjxo0IEOe9xdAAAAwQDcUrNAVgr/bXIYWDvsawjY66iy9sAMimgt +ojoD3jCOEKcJcnW7mQ5Zw8V/KEpYOd91REX7j+NOVhRUqAOVbW2DmT6Lt7aaPF5RLKEvBV +oBR+VDyejOOBbUsimdeAriwL8jS/FwbM/NveRk3eeDsjGejl9oNqI0VsGogd5YuMC7ue3f +aNoNL9GK1i7Gkl2RgQ9K86PUOiK14n10CgZoYQ6K9LYaciZZ+GMGJO2TX1XMMx7vVNLVFv ++zcpm8rKEYGT0AAAAGY2FfcnNhAQIDBAU= +-----END OPENSSH PRIVATE KEY----- diff --git a/tests/openssh_server/ca_rsa.pub b/tests/openssh_server/ca_rsa.pub new file mode 100644 index 0000000000..7c6be99640 --- /dev/null +++ b/tests/openssh_server/ca_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDEiBsRlsihCg0nJGNqURhszCZw1FwZmDpkD64L6HFf2U/GFXFgDBtYJZ8zdgua+RA9F/QNhq14OUemJX39HggAox/Acwg1vKPm6WPYAb3DMyzXT4ws32SbFd5ld/sQrqJUeMxaFLu1f02eY0UttQe4+nMjoM4Me98Qho7TzgpDIgn9nls42Sjt6KM9muqTBIVv4USwi9IsFn+54e0CEjfgiFyU8/8bH6vp1rtMPA6m4vuidyt2pP7PHFnUnikQGsaG4ldO/D/G0FFtMqPXeC1wQXI5RHnRns9TiI6Ep3r3h64ZI5iBYZeG16Fk+nuGvtp+WLWE5m01vfEHc5o+p09j+Ni1mQ5pmUq3AOM/MZMh+eCkTstnCyng/bHEZTIKQi1nnu694Mcq8W1v34wgMyBN3bvE65NhjIdLubnHvDgzVn127wjPEdeVD9ShtACxNS4a6xJCWg6llHVyzezqnj68umXre02MsXLbFikV/fEvUOXUp/rDeo+LJizk2bHAlyk= ca_rsa diff --git a/tests/signed_key_rsa b/tests/signed_key_rsa new file mode 100644 index 0000000000..6ece64b88c --- /dev/null +++ b/tests/signed_key_rsa @@ -0,0 +1,49 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn +NhAAAAAwEAAQAAAgEAsDLVuq8/N4YAiqldV39ij4LVgOaZFQN42OAqLIFrFfK48EqavgDJ +gdcM1XU0/86xBMstoi6CMIgF0O8JaaNUEFpJZwoSHZW2sYPhdFLpZbGCGKBMay/vWDMERs +JndNMiHvzzh5QQmtdKngVn3TJo7eWQ5WpD1WMBY7yuZWdFFtRTNbnKl+R6CD4VTjX0XmaJ +wj/o8L4p+OCDGqrXWksuJO9UKu0bkWzGHk86TWsb9gm8bm72ORO8JQ60+O3tuQ5/13qFdl +RF/U/O2QDJ8Jnsg2yltg7+PJeGc3t2PL3lKI3x9zZQPxfftT8HU5airH+ORP1VS8k07Z9S +ictoS8rmr/ELeloHsONRthfWpQyWm9dbq3KIEYh8iP6D6NHOiptb4nheyH1u9shOUxU2bW +80jUvltBgqNcYeE1MfGwTVxzuPpgxbdoDQoF/h3+uBZT6jNJGmUlLQVSq1krqYE2zEl3x2 +0VeTSb0nRqT1FnhQ9Yn8WHD4ccCZc5011ULphIJQ7niDLJxPMihGI0RLbmqPP6/fjkban/ +Tj2bE/Y/m8ETnryxZymZM3w/cWEMlNmjK0Q7qPEekg+0oiOrV0cJaIXX5VwOp4PUUzcqlU +TkAzifeGxjw+W+AW55t9bNhoYVo6AckBpZDVuAUQxCZoBvbBPM7QMZe3fAldlfdwTorGj5 +MAAAdQLNFgDyzRYA8AAAAHc3NoLXJzYQAAAgEAsDLVuq8/N4YAiqldV39ij4LVgOaZFQN4 +2OAqLIFrFfK48EqavgDJgdcM1XU0/86xBMstoi6CMIgF0O8JaaNUEFpJZwoSHZW2sYPhdF +LpZbGCGKBMay/vWDMERsJndNMiHvzzh5QQmtdKngVn3TJo7eWQ5WpD1WMBY7yuZWdFFtRT +NbnKl+R6CD4VTjX0XmaJwj/o8L4p+OCDGqrXWksuJO9UKu0bkWzGHk86TWsb9gm8bm72OR +O8JQ60+O3tuQ5/13qFdlRF/U/O2QDJ8Jnsg2yltg7+PJeGc3t2PL3lKI3x9zZQPxfftT8H +U5airH+ORP1VS8k07Z9SictoS8rmr/ELeloHsONRthfWpQyWm9dbq3KIEYh8iP6D6NHOip +tb4nheyH1u9shOUxU2bW80jUvltBgqNcYeE1MfGwTVxzuPpgxbdoDQoF/h3+uBZT6jNJGm +UlLQVSq1krqYE2zEl3x20VeTSb0nRqT1FnhQ9Yn8WHD4ccCZc5011ULphIJQ7niDLJxPMi +hGI0RLbmqPP6/fjkban/Tj2bE/Y/m8ETnryxZymZM3w/cWEMlNmjK0Q7qPEekg+0oiOrV0 +cJaIXX5VwOp4PUUzcqlUTkAzifeGxjw+W+AW55t9bNhoYVo6AckBpZDVuAUQxCZoBvbBPM +7QMZe3fAldlfdwTorGj5MAAAADAQABAAACAAt65G4LaQUHGBXwvwIqbJOJJLwHSkYSOdd3 +k4fezslZTS9qzPZAOuDY0B9ASbm5D9OOIWUFvrnGwwo/6M8XMyz1lP6/qzp+PK8INrJLjK +VxkVZla1U4hFGs0USC+hakgv6d4Ige344XJOdy1reUxz1oza4E5HKMxtRmwL4eomPAZcOE +XWzUGBddZCn6Xfegmq0rWNQGr9llV2VvaCSb7V++sC8zz64D9kyXQOc2aVX4gGx5klVZsd +KASM5HQkviY/X4J6X0C7NbddCxunaQsNZHR+y6wVnVTY9MpgGDJeEkjnVa9pOFzK+UcbfC +gsrWbMCV+O69J1OsI8aSmDMH/0uvqT4QTvE8K4j2Cv/akCVkPb5/tC28fmYBL28/qKOTvI +JJpWOcJ3L0QZQkrTJYsO3eL9ZDd4hgI/LvPmUghphEmmqLeu7K7CPnDDjIXM5j/qaIAjXc +BZpkhFZBb63FyQWS4Z51XoNKs9F4iirs4MoMK9VGTNjqTSFr2DYeYLamUgEUPAM73AFGrq +yE2zzSNnh5BZC+rxhoh95Yn3dH8ysczhNP5drgbQ1oVTY0sdGPBZXmMNIVQSTg2snBabp3 +Kr9GdOji6VNkIov5Wcqz67lAVrb068GyrTJn1Ilrv5ND57UC62i682T5sA244dyrZO2WNb +7lEaPhUEXw/2r9E9xhAAABAQDOQtDK19iBmN93sPBrCCVf5QHRc2nEiecTFmYdvo8pj+na +v35Xkf/Jzlt3YXeyKRBOE5MvBP+A/wU86tjwz/2jZO70wkLB9jal67L5tBSrfTtnEQJL/L +2e9sCrcmcMoJWeG12GfEU9o08t4PW+l5lvjrqCQnD8dFQOfxrbcqGIwt3eTDa9JpebPnFV +qpsTREG2+09ut0NLQyXiGRhHVPP1hSpRWF2xL7qAEukxxr8kcYL+BucicBL33pzVBpoR99 +3l7VcJOb4LtTFwdniLN6UkItQQTGm8yKFoWXLYJv5N1zTkeyi/3UexD9kG+lTEskbolZ4o +Eg8B4JmfisFWfq+8AAABAQDcNR7xe9N91XxMN73Yr1xL/tdt0KzdVm9jWsNZ0DzNlR6UKU +ALWshKJozYtajEj+5HKJfpovDolNHWXCG9jj0Zj5jypzJkSWA1h+pO7ZckGOm0XRuHRgsa +ptAMklu+Vz7l9s/pAa/XmGSpG50bnRq0PL64aLR45dAXvCFGm5EmY/eb5CVwi892cC/XwY +JsvaoMDOjLillPOxB+UU7ggTLFue3uKzgbt3vez5HqtsLT5YLvXnxx0F9ezjFpT2XmFHRa +7mtRlMfdKqEzR6xQ9/ncMgzrUWbNMxw/52HHMlgqTaHfj6CBrXarEqOFbOUwo+SyLBJMd5 +d6BrRj6MZqw9J7AAABAQDM1n5T+2eznjYahX07VmdzMX9lzMUnH7cRbAcv0QZv4nZNgZkj +1h+kX6BzVvrARQW2GQ0dg4+03lMpd4fKtqUo6etptocl0zjHqTpIbYKDwWr1s9GUiRC9hL +O0gE8nuYZl3c/Z8lNwV9XaDr6a83g24TUcjlj4M3m8S2vi9FGp01ch3JJjzhvoosx7iqkd +4Eq6mk3vZHmCgppn8JswWE1ea6bXZFoECRrOnaKbcLImJKu0H+aEq7ra680XqBtNdRVPwg +Xex/tfw77hvUBZFZos1t1PUvXjHQtyMSCDbA2I9Jfe3lDwNsS0OG/zYa2/yKGqh8IT8NFR +Vq+eerPcc9fJAAAAFnNhYmFuc2FsQHNhYmFuc2FsLWRldjMBAgME +-----END OPENSSH PRIVATE KEY----- diff --git a/tests/signed_key_rsa-cert.pub b/tests/signed_key_rsa-cert.pub new file mode 100644 index 0000000000..34dd79d104 --- /dev/null +++ b/tests/signed_key_rsa-cert.pub @@ -0,0 +1 @@ +ssh-rsa-cert-v01@openssh.com AAAAHHNzaC1yc2EtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgqdnJWdHT2qMpEe6kVJ81q9c0U3ODMvcuWfJJkV8UVBoAAAADAQABAAACAQCwMtW6rz83hgCKqV1Xf2KPgtWA5pkVA3jY4CosgWsV8rjwSpq+AMmB1wzVdTT/zrEEyy2iLoIwiAXQ7wlpo1QQWklnChIdlbaxg+F0UullsYIYoExrL+9YMwRGwmd00yIe/POHlBCa10qeBWfdMmjt5ZDlakPVYwFjvK5lZ0UW1FM1ucqX5HoIPhVONfReZonCP+jwvin44IMaqtdaSy4k71Qq7RuRbMYeTzpNaxv2CbxubvY5E7wlDrT47e25Dn/XeoV2VEX9T87ZAMnwmeyDbKW2Dv48l4Zze3Y8veUojfH3NlA/F9+1PwdTlqKsf45E/VVLyTTtn1KJy2hLyuav8Qt6Wgew41G2F9alDJab11urcogRiHyI/oPo0c6Km1vieF7IfW72yE5TFTZtbzSNS+W0GCo1xh4TUx8bBNXHO4+mDFt2gNCgX+Hf64FlPqM0kaZSUtBVKrWSupgTbMSXfHbRV5NJvSdGpPUWeFD1ifxYcPhxwJlznTXVQumEglDueIMsnE8yKEYjREtuao8/r9+ORtqf9OPZsT9j+bwROevLFnKZkzfD9xYQyU2aMrRDuo8R6SD7SiI6tXRwlohdflXA6ng9RTNyqVROQDOJ94bGPD5b4Bbnm31s2GhhWjoByQGlkNW4BRDEJmgG9sE8ztAxl7d8CV2V93BOisaPkwAAAAAAAAABAAAAAQAAAAhpZGVudGl0eQAAAAsAAAAHbGlic3NoMgAAAAAAAAAA//////////8AAAAAAAAAggAAABVwZXJtaXQtWDExLWZvcndhcmRpbmcAAAAAAAAAF3Blcm1pdC1hZ2VudC1mb3J3YXJkaW5nAAAAAAAAABZwZXJtaXQtcG9ydC1mb3J3YXJkaW5nAAAAAAAAAApwZXJtaXQtcHR5AAAAAAAAAA5wZXJtaXQtdXNlci1yYwAAAAAAAAAAAAABlwAAAAdzc2gtcnNhAAAAAwEAAQAAAYEAxIgbEZbIoQoNJyRjalEYbMwmcNRcGZg6ZA+uC+hxX9lPxhVxYAwbWCWfM3YLmvkQPRf0DYateDlHpiV9/R4IAKMfwHMINbyj5ulj2AG9wzMs10+MLN9kmxXeZXf7EK6iVHjMWhS7tX9NnmNFLbUHuPpzI6DODHvfEIaO084KQyIJ/Z5bONko7eijPZrqkwSFb+FEsIvSLBZ/ueHtAhI34IhclPP/Gx+r6da7TDwOpuL7oncrdqT+zxxZ1J4pEBrGhuJXTvw/xtBRbTKj13gtcEFyOUR50Z7PU4iOhKd694euGSOYgWGXhtehZPp7hr7afli1hOZtNb3xB3OaPqdPY/jYtZkOaZlKtwDjPzGTIfngpE7LZwsp4P2xxGUyCkItZ57uveDHKvFtb9+MIDMgTd27xOuTYYyHS7m5x7w4M1Z9du8IzxHXlQ/UobQAsTUuGusSQloOpZR1cs3s6p4+vLpl63tNjLFy2xYpFf3xL1Dl1Kf6w3qPiyYs5NmxwJcpAAABlAAAAAxyc2Etc2hhMi01MTIAAAGAK6d2jj8qv89wqRuE2bUFKKJDH4aIs7PGzKclTjZFomlkGvjRF/bsdDeUgwWdJ98j2TPdUvsAMlQrDS1e0OrDicen6eHrFhirpQxVLsAxj/c56nLedvzpbA/BLh8cFcq1vUZ1QHb2WOgOqWRcRbH/3TZhlA+gJ46kKs3QEw9uYy6m906xGwCWRiBUetfll5hS1sWCbAP2LLnA/OJUbIK9vKynombePRApY3LuZ8Hr0JCGgeBnfsesFbWLN6Gb+jT0KR4ah7O39lqecmvdUOR5XcMaSp+sgPpdBr7CzA5lkZnoI/M2J7AV1P5SX/q7/khJMKHuKwAsYf5kNAQdnEnwrqNTp//+qIWe5KjAtc0N5UOF5aK0e1iNaBxSHZA08psRLCCUf3PW3zMIlphUF7qIrRfV+s5fUMW0iIS2iUqI8dTrD0OH0wU10ERKQPixNCqtxBSbJzOyhDWPkTNfBshS8zA2/OVfug0zuxaINpAnZaiCcMnyCjATuWtvWpad6yF9 signed_key_rsa diff --git a/tests/signed_key_rsa.pub b/tests/signed_key_rsa.pub new file mode 100644 index 0000000000..34376b1def --- /dev/null +++ b/tests/signed_key_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCwMtW6rz83hgCKqV1Xf2KPgtWA5pkVA3jY4CosgWsV8rjwSpq+AMmB1wzVdTT/zrEEyy2iLoIwiAXQ7wlpo1QQWklnChIdlbaxg+F0UullsYIYoExrL+9YMwRGwmd00yIe/POHlBCa10qeBWfdMmjt5ZDlakPVYwFjvK5lZ0UW1FM1ucqX5HoIPhVONfReZonCP+jwvin44IMaqtdaSy4k71Qq7RuRbMYeTzpNaxv2CbxubvY5E7wlDrT47e25Dn/XeoV2VEX9T87ZAMnwmeyDbKW2Dv48l4Zze3Y8veUojfH3NlA/F9+1PwdTlqKsf45E/VVLyTTtn1KJy2hLyuav8Qt6Wgew41G2F9alDJab11urcogRiHyI/oPo0c6Km1vieF7IfW72yE5TFTZtbzSNS+W0GCo1xh4TUx8bBNXHO4+mDFt2gNCgX+Hf64FlPqM0kaZSUtBVKrWSupgTbMSXfHbRV5NJvSdGpPUWeFD1ifxYcPhxwJlznTXVQumEglDueIMsnE8yKEYjREtuao8/r9+ORtqf9OPZsT9j+bwROevLFnKZkzfD9xYQyU2aMrRDuo8R6SD7SiI6tXRwlohdflXA6ng9RTNyqVROQDOJ94bGPD5b4Bbnm31s2GhhWjoByQGlkNW4BRDEJmgG9sE8ztAxl7d8CV2V93BOisaPkw== signed_key_rsa diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c new file mode 100644 index 0000000000..39130e652c --- /dev/null +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -0,0 +1,38 @@ +#include "session_fixture.h" + +#include + +#include + +/* configured in Dockerfile */ +static const char *USERNAME = "libssh2"; +static const char *KEY_FILE_PRIVATE = "signed_key_rsa"; +static const char *KEY_FILE_PUBLIC = "signed_key_rsa-cert.pub"; + +int test(LIBSSH2_SESSION *session) +{ + int rc; + + const char *userauth_list = + libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + if(userauth_list == NULL) { + print_last_session_error("libssh2_userauth_list"); + return 1; + } + + if(strstr(userauth_list, "publickey") == NULL) { + fprintf(stderr, "'publickey' was expected in userauth list: %s\n", + userauth_list); + return 1; + } + + rc = libssh2_userauth_publickey_fromfile_ex( + session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + NULL); + if(rc != 0) { + print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); + return 1; + } + + return 0; +} From 891ee16ab62f163c8b1fb2801db863d3242578d3 Mon Sep 17 00:00:00 2001 From: Ryan Kelley Date: Tue, 9 Aug 2022 20:05:35 -0400 Subject: [PATCH 051/424] Updating docs for libssh2_channel_flush_ex (#728) Notes: In #614 it was identified the docs do not accurately show how libssh2_channel_flush_ex() return value is set. I have updated the doc's to correctly show what the function is returning. Credit: Ryan Kelley --- docs/libssh2_channel_flush_ex.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/libssh2_channel_flush_ex.3 b/docs/libssh2_channel_flush_ex.3 index 1885176b37..6cd39b2c6c 100644 --- a/docs/libssh2_channel_flush_ex.3 +++ b/docs/libssh2_channel_flush_ex.3 @@ -27,6 +27,6 @@ Flush the read buffer for a given channel instance. Individual substreams may be flushed by number or using one of the provided macros. .SH RETURN VALUE -Return 0 on success or negative on failure. It returns -LIBSSH2_ERROR_EAGAIN when it would otherwise block. While +Return the number of bytes flushed or negative on failure. +It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. From 31ae48885d89b729a28dea03dcd4c730c1991c63 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Tue, 16 Aug 2022 09:09:47 -0700 Subject: [PATCH 052/424] Don't erroneously log SSH_MSG_REQUEST_FAILURE packets from keepalive (#727) Notes: When setting a ServerAliveInterval using libssh2_keepalive_config() with want_reply set to true, some servers will reply to the keep-alive requests with a single SSH_MSG_REQUEST_FAILURE packet. This is an allowed behavior in RFC 4254, section 4. Credit: Michael Buckley --- src/channel.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/channel.c b/src/channel.c index 59133f8ae1..86b6d2a647 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2045,8 +2045,13 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, if(readpkt->data_len < 5) { read_packet = read_next; - _libssh2_debug(channel->session, LIBSSH2_TRACE_ERROR, - "Unexpected packet length"); + + if(readpkt->data_len != 1 || + readpkt->data[0] != SSH_MSG_REQUEST_FAILURE) { + _libssh2_debug(channel->session, LIBSSH2_TRACE_ERROR, + "Unexpected packet length"); + } + continue; } From 6c59eea5a9ea77127ec0fa3d6815c8adc743dba3 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 16 Aug 2022 12:13:51 -0400 Subject: [PATCH 053/424] Document the obscure LIBSSH2_ERROR_BAD_USE when writing to a channel (#713) Document the obscure LIBSSH2_ERROR_BAD_USE when writing to a channel Credit: Miguel de Icaza --- docs/libssh2_channel_write_ex.3 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/libssh2_channel_write_ex.3 b/docs/libssh2_channel_write_ex.3 index 4ef7df173e..cb73648d83 100644 --- a/docs/libssh2_channel_write_ex.3 +++ b/docs/libssh2_channel_write_ex.3 @@ -41,6 +41,11 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_CHANNEL_CLOSED\fP - The channel has been closed. \fILIBSSH2_ERROR_CHANNEL_EOF_SENT\fP - The channel has been requested to be + +\fILIBSSH2_ERROR_BAD_USE\fP - This can be returned if you ignored a previous +return for LIBSSH2_ERROR_EAGAIN and rather than sending the original buffer with +the original size, you sent a new buffer with a different size. + closed. .SH SEE ALSO .BR libssh2_channel_open_ex(3) From 09f0ffd9fbd0fa1442b8fcb097df49eea3164db9 Mon Sep 17 00:00:00 2001 From: zhaochongliu Date: Wed, 7 Sep 2022 13:54:25 -0400 Subject: [PATCH 054/424] Support building with gcc < version 8 Files: CMakeLists.txt Notes: don't use gcc arguments that don't exist in gcc versions lower than 8 if building with older gcc. Credit: zhaochongliu --- tests/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 620c93939f..f3706bcf6f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -184,9 +184,13 @@ endif() target_compile_definitions(test_keyboard_interactive_auth_info_request PRIVATE "${CRYPTO_BACKEND_DEFINE}") target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" "../src/" "${CRYPTO_BACKEND_INCLUDE_DIR}") find_program(GCOV_PATH gcov) +set(TGT_OPTIONS -g --coverage -fprofile-abs-path) +if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) + set(TGT_OPTIONS -g --coverage) +endif() if(CMAKE_COMPILER_IS_GNUCC AND GCOV_PATH) target_compile_options(test_keyboard_interactive_auth_info_request BEFORE PRIVATE - -g --coverage -fprofile-abs-path) + ${TGT_OPTIONS}) target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2 gcov) else() target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2) From 91adeae486105ae25823949eea4d36c7587043bd Mon Sep 17 00:00:00 2001 From: bgermann Date: Wed, 21 Sep 2022 00:29:05 +0200 Subject: [PATCH 055/424] Drop advertisement clause on Blowfish (#747) Originally driven by https://github.com/pyca/bcrypt/issues/169, OpenBSD removed Niels Provos's BSD advertisement clause in version 7.1: https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/lib/libsa/blowfish.c.diff?r1=1.1&r2=1.2 https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/lib/libsa/blowfish.h.diff?r1=1.1&r2=1.2 This enables using libssh2 in GPL software. --- src/blf.h | 5 +---- src/blowfish.c | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/blf.h b/src/blf.h index 5b7c8aae06..cdd089ace4 100644 --- a/src/blf.h +++ b/src/blf.h @@ -15,10 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Niels Provos. - * 4. The name of the author may not be used to endorse or promote products + * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR diff --git a/src/blowfish.c b/src/blowfish.c index 4aefc66ac7..94bc0c6f16 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -14,10 +14,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Niels Provos. - * 4. The name of the author may not be used to endorse or promote products + * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR From bd9c65d68c4152ba0726f5588b4b611410972fbc Mon Sep 17 00:00:00 2001 From: Gabriel Smith Date: Fri, 23 Sep 2022 13:03:56 -0400 Subject: [PATCH 056/424] sftp: Prevent files from being skipped if the output buffer is too small (#746) Notes: LIBSSH2_ERROR_BUFFER_TOO_SMALL is returned if the buffer is too small to contain a returned directory entry. On this condition we jump to the label `end`. At this point the number of names left is decremented despite no name being returned. As suggested in #714, this commit moves the error label after the decrement of `names_left`. Fixes #714 Credit: Co-authored-by: Gabriel Smith --- src/sftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sftp.c b/src/sftp.c index b1a53527a8..2df918aaef 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1852,11 +1852,11 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, handle->u.dir.next_name = (char *) s; handle->u.dir.names_packet_len = names_packet_len; - end: if((--handle->u.dir.names_left) == 0) LIBSSH2_FREE(session, handle->u.dir.names_packet); + end: _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "libssh2_sftp_readdir_ex() return %d", filename_len); From 8b3a864c5bd69a72e7b14a2d94d57dd935aace2f Mon Sep 17 00:00:00 2001 From: skundu07 <36504923+skundu07@users.noreply.github.com> Date: Fri, 23 Sep 2022 22:41:20 +0530 Subject: [PATCH 057/424] Add RSA-SHA2 support for the WinCNG backend (#736) Notes: Added code to support RSA-SHA2 for WinCNG backend. Credit: skundu07 --- src/wincng.c | 79 +++++++++++++++++++++++++++++++++++++++++----------- src/wincng.h | 13 ++++++--- 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/src/wincng.c b/src/wincng.c index ee5f9e6dbd..ebf7929509 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -596,7 +596,8 @@ _libssh2_wincng_hmac_cleanup(_libssh2_wincng_hash_ctx *ctx) */ int -_libssh2_wincng_key_sha1_verify(_libssh2_wincng_key_ctx *ctx, +_libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, + size_t hashlen, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, @@ -604,30 +605,48 @@ _libssh2_wincng_key_sha1_verify(_libssh2_wincng_key_ctx *ctx, unsigned long flags) { BCRYPT_PKCS1_PADDING_INFO paddingInfoPKCS1; + BCRYPT_ALG_HANDLE hAlgHash; void *pPaddingInfo; unsigned char *data, *hash; - unsigned long datalen, hashlen; + unsigned long datalen; int ret; + if(hashlen == SHA_DIGEST_LENGTH) { + hAlgHash = _libssh2_wincng.hAlgHashSHA1; + paddingInfoPKCS1.pszAlgId = BCRYPT_SHA1_ALGORITHM; + } + else if(hashlen == SHA256_DIGEST_LENGTH) { + hAlgHash = _libssh2_wincng.hAlgHashSHA256; + paddingInfoPKCS1.pszAlgId = BCRYPT_SHA256_ALGORITHM; + } + else if(hashlen == SHA384_DIGEST_LENGTH) { + hAlgHash = _libssh2_wincng.hAlgHashSHA384; + paddingInfoPKCS1.pszAlgId = BCRYPT_SHA384_ALGORITHM; + } + else if(hashlen == SHA512_DIGEST_LENGTH) { + hAlgHash = _libssh2_wincng.hAlgHashSHA512; + paddingInfoPKCS1.pszAlgId = BCRYPT_SHA512_ALGORITHM; + } + else { + return -1; + } + datalen = m_len; data = malloc(datalen); if(!data) { return -1; } - hashlen = SHA_DIGEST_LENGTH; hash = malloc(hashlen); if(!hash) { free(data); return -1; } - memcpy(data, m, datalen); ret = _libssh2_wincng_hash(data, datalen, - _libssh2_wincng.hAlgHashSHA1, + hAlgHash, hash, hashlen); - _libssh2_wincng_safe_free(data, datalen); if(ret) { @@ -643,7 +662,6 @@ _libssh2_wincng_key_sha1_verify(_libssh2_wincng_key_ctx *ctx, } if(flags & BCRYPT_PAD_PKCS1) { - paddingInfoPKCS1.pszAlgId = BCRYPT_SHA1_ALGORITHM; pPaddingInfo = &paddingInfoPKCS1; } else @@ -1209,12 +1227,24 @@ _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, const unsigned char *m, unsigned long m_len) { - return _libssh2_wincng_key_sha1_verify(rsa, sig, sig_len, m, m_len, - BCRYPT_PAD_PKCS1); + return _libssh2_wincng_key_sha_verify(rsa, SHA_DIGEST_LENGTH, sig, sig_len, + m, m_len, BCRYPT_PAD_PKCS1); } int -_libssh2_wincng_rsa_sha1_sign(LIBSSH2_SESSION *session, +_libssh2_wincng_rsa_sha2_verify(libssh2_rsa_ctx* rsa, + size_t hash_len, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, + unsigned long m_len) +{ + return _libssh2_wincng_key_sha_verify(rsa, hash_len, sig, sig_len, m, + m_len, BCRYPT_PAD_PKCS1); +} + +int +_libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session, libssh2_rsa_ctx *rsa, const unsigned char *hash, size_t hash_len, @@ -1226,14 +1256,25 @@ _libssh2_wincng_rsa_sha1_sign(LIBSSH2_SESSION *session, unsigned long cbData, datalen, siglen; int ret; + if(hash_len == SHA_DIGEST_LENGTH) + paddingInfo.pszAlgId = BCRYPT_SHA1_ALGORITHM; + else if(hash_len == SHA256_DIGEST_LENGTH) + paddingInfo.pszAlgId = BCRYPT_SHA256_ALGORITHM; + else if(hash_len == SHA384_DIGEST_LENGTH) + paddingInfo.pszAlgId = BCRYPT_SHA384_ALGORITHM; + else if(hash_len == SHA512_DIGEST_LENGTH) + paddingInfo.pszAlgId = BCRYPT_SHA512_ALGORITHM; + else { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Unsupported hash digest length"); + return -1; + } + datalen = (unsigned long)hash_len; data = malloc(datalen); if(!data) { return -1; } - - paddingInfo.pszAlgId = BCRYPT_SHA1_ALGORITHM; - memcpy(data, hash, datalen); ret = BCryptSignHash(rsa->hKey, &paddingInfo, @@ -1504,7 +1545,8 @@ _libssh2_wincng_dsa_sha1_verify(libssh2_dsa_ctx *dsa, const unsigned char *m, unsigned long m_len) { - return _libssh2_wincng_key_sha1_verify(dsa, sig_fixed, 40, m, m_len, 0); + return _libssh2_wincng_key_sha_verify(dsa, SHA_DIGEST_LENGTH, sig_fixed, + 40, m, m_len, 0); } int @@ -2604,8 +2646,13 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, size_t key_method_len) { (void)session; - (void)key_method; - (void)key_method_len; + +#if LIBSSH2_RSA_SHA2 + if(key_method_len == 7 && + memcmp(key_method, "ssh-rsa", key_method_len) == 0) { + return "rsa-sha2-512,rsa-sha2-256,ssh-rsa"; + } +#endif return NULL; } diff --git a/src/wincng.h b/src/wincng.h index ea7554531a..a5f4506f8c 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -63,7 +63,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 -#define LIBSSH2_RSA_SHA2 0 +#define LIBSSH2_RSA_SHA2 1 #define LIBSSH2_DSA 1 #define LIBSSH2_ECDSA 0 #define LIBSSH2_ED25519 0 @@ -262,9 +262,13 @@ typedef struct __libssh2_wincng_key_ctx { _libssh2_wincng_rsa_new_private_frommemory(rsactx, s, filedata, \ filedata_len, passphrase) #define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \ - _libssh2_wincng_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) + _libssh2_wincng_rsa_sha_sign(s, rsactx, hash, hash_len, sig, sig_len) +#define _libssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \ + _libssh2_wincng_rsa_sha_sign(s, rsactx, hash, hash_len, sig, sig_len) #define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \ _libssh2_wincng_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) +#define _libssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \ + _libssh2_wincng_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) #define _libssh2_rsa_free(rsactx) \ _libssh2_wincng_rsa_free(rsactx) @@ -450,7 +454,8 @@ void _libssh2_wincng_hmac_cleanup(_libssh2_wincng_hash_ctx *ctx); int -_libssh2_wincng_key_sha1_verify(_libssh2_wincng_key_ctx *ctx, +_libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, + size_t hashlen, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, @@ -493,7 +498,7 @@ _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, const unsigned char *m, unsigned long m_len); int -_libssh2_wincng_rsa_sha1_sign(LIBSSH2_SESSION *session, +_libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session, libssh2_rsa_ctx *rsa, const unsigned char *hash, size_t hash_len, From ef292424bb5d136f888a2d2e92460de12c143ab4 Mon Sep 17 00:00:00 2001 From: "Y. Yang" Date: Sat, 24 Sep 2022 01:41:35 +0800 Subject: [PATCH 058/424] Fix DLL import library name (#711) Notes: Fix DLL import library name https://aur.archlinux.org/packages/mingw-w64-libssh2 https://cmake.org/cmake/help/latest/prop_tgt/IMPORT_PREFIX.html Credit: metab0t Y. Yang --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cb8fee1218..17ecefd07c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -220,6 +220,7 @@ endif() add_library(libssh2 ${SOURCES}) # we want it to be called libssh2 on all platforms set_target_properties(libssh2 PROPERTIES PREFIX "") +set_target_properties(libssh2 PROPERTIES IMPORT_PREFIX "") target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) target_include_directories(libssh2 From ed439a29bb0b4d1c3f681f87ccfcd3e5a66c3ba0 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Thu, 29 Sep 2022 09:05:34 -0700 Subject: [PATCH 059/424] Support for sk-ecdsa-sha2-nistp256 and sk-ssh-ed25519 keys, FIDO (#698) Notes: Add support for sk-ecdsa-sha2-nistp256@openssh.com and sk-ssh-ed25519@openssh.com key exchange for FIDO auth using the OpenSSL backend. Stub API for other backends. Credit: Michael Buckley --- docs/libssh2_sign_sk.3 | 85 ++ docs/libssh2_userauth_publickey_sk.3 | 133 +++ include/libssh2.h | 50 ++ src/crypto.h | 56 ++ src/libgcrypt.c | 20 + src/mbedtls.c | 20 + src/mbedtls.h | 4 + src/misc.c | 24 + src/misc.h | 3 + src/openssl.c | 769 +++++++++++++++++- src/os400qc3.c | 20 + src/userauth.c | 192 ++++- src/wincng.c | 20 + src/wincng.h | 5 +- ...teractive_auth_fails_with_wrong_response.c | 4 +- ...tive_auth_succeeds_with_correct_response.c | 4 +- 16 files changed, 1380 insertions(+), 29 deletions(-) create mode 100644 docs/libssh2_sign_sk.3 create mode 100644 docs/libssh2_userauth_publickey_sk.3 diff --git a/docs/libssh2_sign_sk.3 b/docs/libssh2_sign_sk.3 new file mode 100644 index 0000000000..7aa503d671 --- /dev/null +++ b/docs/libssh2_sign_sk.3 @@ -0,0 +1,85 @@ +.TH libssh2_sign_sk 3 "1 Jun 2022" "libssh2 1.10.0" "libssh2 manual" +.SH NAME +libssh2_sign_sk - Create a signature from a FIDO2 authenticator. +.SH SYNOPSIS +#include +.nf +int libssh2_sign_sk(LIBSSH2_SESSION *session, + unsigned char **sig, + size_t *sig_len, + const unsigned char *data, + size_t data_len, + void **abstract); + +typedef struct _LIBSSH2_PRIVKEY_SK { + int algorithm; + uint8_t flags; + const char *application; + const unsigned char *key_handle; + size_t handle_len; + LIBSSH2_USERAUTH_SK_SIGN_FUNC((*sign_callback)); + void **orig_abstract; +} LIBSSH2_PRIVKEY_SK; + +.SH DESCRIPTION +\fIsession\fP - Session instance as returned by +.BR libssh2_session_init_ex(3) + +\fIsig\fP - A pointer to a buffer in which to place the signature. The caller +is responsible for freeing the signature with LIBSSH2_FREE. + +\fIsig_len\fP - A pointer to the length of the sig parameter. + +\fIdata\fP - The data to sign. + +\fIdata_len\fP - The length of the data parameter. + +\fIabstract\fP - A pointer to a pointer to a LIBSSH2_PRIVKEY_SK. See +description below. + +Create a signature from a FIDO2 authenticator, using either the +sk-ssh-ed25519@openssh.com or sk-ecdsa-sha2-nistp256@openssh.com key +exchange algorithms. + +The abstract parameter is a pointer to a pointer due to the internal workings +of libssh2. The LIBSSH2_PRIVKEY_SK must be completely filled out, and the +caller is responsible for all memory management of its fields. + +\fIalgorithm\fP - The signing algorithm to use. Possible values are +LIBSSH2_HOSTKEY_TYPE_ED25519 and LIBSSH2_HOSTKEY_TYPE_ECDSA_256. + +\fIflags\fP - A bitmask specifying options for the authenticator. When +LIBSSH2_SK_PRESENCE_REQUIRED is set, the authenticator requires a touch. When +LIBSSH2_SK_VERIFICATION_REQUIRED is set, the authenticator requires a PIN. +Many servers and authenticators do not work properly when +LIBSSH2_SK_PRESENCE_REQUIRED is not set. + +\fIapplication\fP - A user-defined string to use as the RP name for the +authenticator. Usually "ssh:". + +\fIkey_handle\fP - The key handle to use for the authenticator's allow list. + +\fIhandle_len\fP - The length of the key_handle parameter. + +\fIabstract\fP - User-defined data. When a PIN is required, use this to pass in +the PIN, or a function pointer to retrieve the PIN. + +\fIkey_handle\fP The decoded key handle from the private key file. + +\fIhandle_len\fP The length of the key_handle parameter. + +\fIsign_callback\fP - Responsible for communicating with the hardware +authenticator to generate a signature. On success, the signature information +must be placed in the `\fIsig_info\fP sig_info parameter and the callback must +return 0. On failure, it should return a negative number. See +.BR libssh2_userauth_publickey_sk(3) + for more information. + +\fIorig_abstract\fP - User-defined data. When a PIN is required, use this to +pass in the PIN, or a function pointer to retrieve the PIN. + +.SH RETURN VALUE +Return 0 on success or negative on failure. + +.SH SEE ALSO +.BR libssh2_userauth_publickey_sk(3) diff --git a/docs/libssh2_userauth_publickey_sk.3 b/docs/libssh2_userauth_publickey_sk.3 new file mode 100644 index 0000000000..4ed54c906f --- /dev/null +++ b/docs/libssh2_userauth_publickey_sk.3 @@ -0,0 +1,133 @@ +.TH libssh2_userauth_publickey_sk 3 "1 Jun 2022" "libssh2 1.10.0" "libssh2 manual" +.SH NAME +libssh2_userauth_publickey_sk - authenticate a session with a FIDO2 authenticator +.SH SYNOPSIS +#include +.nf +int libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, + const char *username, + size_t username_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase, + LIBSSH2_USERAUTH_SK_SIGN_FUNC + ((*sign_callback)), + void **abstract); + +.SH CALLBACK +.nf +#define LIBSSH2_SK_PRESENCE_REQUIRED 0x01 +#define LIBSSH2_SK_VERIFICATION_REQUIRED 0x04 + +typedef struct _LIBSSH2_SK_SIG_INFO { + uint8_t flags; + uint32_t counter; + unsigned char *sig_r; + size_t sig_r_len; + unsigned char *sig_s; + size_t sig_s_len; +} LIBSSH2_SK_SIG_INFO; + +int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, + const unsigned char *data, size_t data_len, int algorithm, + uint8_t flags, const char *application, + const unsigned char *key_handle, size_t handle_len, + void **abstract); +.fi + +.SH DESCRIPTION +\fIsession\fP - Session instance as returned by +.BR libssh2_session_init_ex(3) + +\fIusername\fP - Name of user to attempt authentication for. + +\fIusername_len\fP - Length of username parameter. + +\fIprivatekeydata\fP - Buffer containing the contents of a private key file. + +\fIprivatekeydata_len\fP - Length of private key data. + +\fIpassphrase\fP - Passphrase to use when decoding private key file. + +\fIsign_callback\fP - Callback to communicate with FIDO2 authenticator. + +\fIabstract\fP - User-provided data to pass to callback. + +Attempt FIDO2 authentication. using either the sk-ssh-ed25519@openssh.com or +sk-ecdsa-sha2-nistp256@openssh.com key exchange algorithms. + +This function is only supported when libssh2 is backed by OpenSSL. + +.SH CALLBACK DESCRIPTION +\fIsession\fP - Session instance as returned by +.BR libssh2_session_init_ex(3) + +\fIsig_info\fP - Filled in by the callback with the signature and accompanying +information from the authenticator. + +\fIdata\fP - The data to sign. + +\fIdata_len\fP - The length of the data parameter. + +\fIalgorithm\fP - The signing algorithm to use. Possible values are +LIBSSH2_HOSTKEY_TYPE_ED25519 and LIBSSH2_HOSTKEY_TYPE_ECDSA_256. + +\fIflags\fP - A bitmask specifying options for the authenticator. When +LIBSSH2_SK_PRESENCE_REQUIRED is set, the authenticator requires a touch. When +LIBSSH2_SK_VERIFICATION_REQUIRED is set, the authenticator requires a PIN. +Many servers and authenticators do not work properly when +LIBSSH2_SK_PRESENCE_REQUIRED is not set. + +\fIapplication\fP - A user-defined string to use as the RP name for the +authenticator. Usually "ssh:". + +\fIkey_handle\fP - The key handle to use for the authenticator's allow list. + +\fIhandle_len\fP - The length of the key_handle parameter. + +\fIabstract\fP - User-defined data. When a PIN is required, use this to pass in +the PIN, or a function pointer to retrieve the PIN. + +The \fIsign_callback\fP is responsible for communicating with the hardware +authenticator to generate a signature. On success, the signature information +must be placed in the `\fIsig_info\fP sig_info parameter and the callback must +return 0. On failure, it should return a negative number. + +The fields of the LIBSSH2_SK_SIG_INFO are as follows. + +\fIflags\fP - A bitmask specifying options for the authenticator. This should +be read from the authenticator and not merely copied from the flags parameter +to the callback. + +\fIcounter\fP - A value returned from the authenticator. + +\fIsig_r\fP - For Ed25519 signatures, this contains the entire signature, as +returned directly from the authenticator. For ECDSA signatures, this contains +the r component of the signature in a big-endian binary representation. For +both algorithms, use LIBSSH2_ALLOC to allocate memory. It will be freed by the +caller. + +\fIsig_r_len\fP - The length of the sig_r parameter. + +\fIsig_s\fP - For ECDSA signatures, this contains the s component of the +signature in a big-endian binary representation. Use LIBSSH2_ALLOC to allocate +memory. It will be freed by the caller. For Ed25519 signatures, set this to +NULL. + +\fIsig_s_len\fP - The length of the sig_s parameter. + +.SH RETURN VALUE +Return 0 on success or negative on failure. It returns +LIBSSH2_ERROR_EAGAIN when it would otherwise block. While +LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. + +.SH ERRORS +Some of the errors this function may return include: + +\fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. + +\fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. + +\fILIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - failed, invalid username/key. +.SH SEE ALSO +.BR libssh2_session_init_ex(3) diff --git a/include/libssh2.h b/include/libssh2.h index ef3ce11508..b79569da31 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -283,6 +283,15 @@ typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE unsigned int length; } LIBSSH2_USERAUTH_KBDINT_RESPONSE; +typedef struct _LIBSSH2_SK_SIG_INFO { + uint8_t flags; + uint32_t counter; + unsigned char *sig_r; + size_t sig_r_len; + unsigned char *sig_s; + size_t sig_s_len; +} LIBSSH2_SK_SIG_INFO; + /* 'publickey' authentication callback */ #define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \ int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \ @@ -295,6 +304,17 @@ typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, \ LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract) +/* SK authentication callback */ +#define LIBSSH2_USERAUTH_SK_SIGN_FUNC(name) \ +int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, \ +const unsigned char *data, size_t data_len, int algorithm, uint8_t flags, \ +const char *application, const unsigned char *key_handle, size_t handle_len, \ +void **abstract) + +/* Flags for SK authentication */ +#define LIBSSH2_SK_PRESENCE_REQUIRED 0x01 +#define LIBSSH2_SK_VERIFICATION_REQUIRED 0x04 + /* Callbacks for special SSH packets */ #define LIBSSH2_IGNORE_FUNC(name) \ void name(LIBSSH2_SESSION *session, const char *message, int message_len, \ @@ -368,6 +388,25 @@ typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER; typedef struct _LIBSSH2_KNOWNHOSTS LIBSSH2_KNOWNHOSTS; typedef struct _LIBSSH2_AGENT LIBSSH2_AGENT; +/* SK signature callback */ +typedef struct _LIBSSH2_PRIVKEY_SK { + int algorithm; + uint8_t flags; + const char *application; + const unsigned char *key_handle; + size_t handle_len; + LIBSSH2_USERAUTH_SK_SIGN_FUNC((*sign_callback)); + void **orig_abstract; +} LIBSSH2_PRIVKEY_SK; + +int +libssh2_sign_sk(LIBSSH2_SESSION *session, + unsigned char **sig, + size_t *sig_len, + const unsigned char *data, + size_t data_len, + void **abstract); + typedef struct _LIBSSH2_POLLFD { unsigned char type; /* LIBSSH2_POLLFD_* below */ @@ -711,6 +750,17 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session, (unsigned int)strlen(username), \ (response_callback)) +LIBSSH2_API int +libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, + const char *username, + size_t username_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase, + LIBSSH2_USERAUTH_SK_SIGN_FUNC + ((*sign_callback)), + void **abstract); + LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeout); diff --git a/src/crypto.h b/src/crypto.h index 7a99b4f3da..0abbd5b881 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -147,12 +147,23 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ecdsactx, const unsigned char *k, size_t k_len, libssh2_curve_type type); + int _libssh2_ecdsa_new_private(libssh2_ecdsa_ctx ** ec_ctx, LIBSSH2_SESSION * session, const char *filename, unsigned const char *passphrase); +int +_libssh2_ecdsa_new_private_sk(libssh2_ecdsa_ctx ** ec_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION * session, + const char *filename, + unsigned const char *passphrase); + int _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx, const unsigned char *r, size_t r_len, @@ -182,6 +193,16 @@ int _libssh2_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx ** ec_ctx, size_t filedata_len, unsigned const char *passphrase); +int _libssh2_ecdsa_new_private_frommemory_sk(libssh2_ecdsa_ctx ** ec_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION * session, + const char *filedata, + size_t filedata_len, + unsigned const char *passphrase); + libssh2_curve_type _libssh2_ecdsa_get_curve_type(libssh2_ecdsa_ctx *ec_ctx); @@ -211,6 +232,16 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx **ed_ctx, LIBSSH2_SESSION *session, const char *filename, const uint8_t *passphrase); +int +_libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION *session, + const char *filename, + const uint8_t *passphrase); + int _libssh2_ed25519_new_public(libssh2_ed25519_ctx **ed_ctx, LIBSSH2_SESSION *session, @@ -229,6 +260,17 @@ _libssh2_ed25519_new_private_frommemory(libssh2_ed25519_ctx **ed_ctx, size_t filedata_len, unsigned const char *passphrase); +int +_libssh2_ed25519_new_private_frommemory_sk(libssh2_ed25519_ctx **ed_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION *session, + const char *filedata, + size_t filedata_len, + unsigned const char *passphrase); + #endif /* LIBSSH2_ED25519 */ @@ -259,6 +301,20 @@ int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, const char *passphrase); +int _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase); + /** * @function _libssh2_supported_key_sign_algorithms * @abstract Returns supported algorithms used for upgrading public diff --git a/src/libgcrypt.c b/src/libgcrypt.c index f6e9b64a3c..2e0a8db4ef 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -627,6 +627,26 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, "Method unimplemented in libgcrypt backend"); } +int +_libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase) +{ + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to extract public SK key from private key file: " + "Method unimplemented in libgcrypt backend"); +} + void _libssh2_init_aes_ctr(void) { /* no implementation */ diff --git a/src/mbedtls.c b/src/mbedtls.c index 4ff751b3a6..9de8ed6df1 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -741,6 +741,26 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, return ret; } +int +_libssh2_mbedtls_sk_pub_keyfilememory(LIBSSH2_SESSION *session, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase) +{ + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to extract public SK key from private key file: " + "Method unimplemented in mbedTLS backend"); +} + void _libssh2_init_aes_ctr(void) { /* no implementation */ diff --git a/src/mbedtls.h b/src/mbedtls.h index e86ebd26f5..891f07dab2 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -342,6 +342,10 @@ typedef enum { pk, pk_len, pw) \ _libssh2_mbedtls_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ pk, pk_len, pw) +#define _libssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ + f, kh, kh_len, pk, pk_len, pw) \ + _libssh2_mbedtls_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ + f, kh, kh_len, pk, pk_len, pw) /*******************************************************************/ diff --git a/src/misc.c b/src/misc.c index ae0fc91bcb..0c84fa4b8f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -243,6 +243,30 @@ void _libssh2_store_str(unsigned char **buf, const char *str, size_t len) } } +/* _libssh2_store_bignum2_bytes + */ +void _libssh2_store_bignum2_bytes(unsigned char **buf, + const unsigned char *bytes, + size_t len) +{ + int extraByte = 0; + const unsigned char *p; + for(p = bytes; len > 0 && *p == 0; --len, ++p) {} + + extraByte = (len > 0 && (p[0] & 0x80) != 0); + _libssh2_store_u32(buf, len + extraByte); + + if(extraByte) { + *buf[0] = 0; + *buf += 1; + } + + if(len > 0) { + memcpy(*buf, p, len); + *buf += len; + } +} + /* Base64 Conversion */ static const short base64_reverse_table[256] = { diff --git a/src/misc.h b/src/misc.h index d4d6268430..4e355fcd78 100644 --- a/src/misc.h +++ b/src/misc.h @@ -85,6 +85,9 @@ libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf); void _libssh2_htonu32(unsigned char *buf, uint32_t val); void _libssh2_store_u32(unsigned char **buf, uint32_t value); void _libssh2_store_str(unsigned char **buf, const char *str, size_t len); +void _libssh2_store_bignum2_bytes(unsigned char **buf, + const unsigned char *bytes, + size_t len); void *_libssh2_calloc(LIBSSH2_SESSION *session, size_t size); void _libssh2_explicit_zero(void *buf, size_t size); diff --git a/src/openssl.c b/src/openssl.c index 857110f3ca..ef56e938c1 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -57,6 +57,23 @@ read_openssh_private_key_from_memory(void **key_ctx, LIBSSH2_SESSION *session, size_t filedata_len, unsigned const char *passphrase); +static int +_libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, + void **key_ctx, + const char *key_type, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + unsigned const char *passphrase); + static unsigned char * write_bn(unsigned char *buf, const BIGNUM *bn, int bn_bytes) { @@ -1498,6 +1515,34 @@ _libssh2_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx ** ec_ctx, return rc; } +int _libssh2_ecdsa_new_private_frommemory_sk(libssh2_ecdsa_ctx ** ec_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION * session, + const char *filedata, + size_t filedata_len, + unsigned const char *passphrase) +{ + int algorithm; + return _libssh2_sk_pub_openssh_keyfilememory(session, + (void **)ec_ctx, + "sk-ecdsa-sha2-nistp256@openssh.com", + NULL, + NULL, + NULL, + NULL, + &algorithm, + flags, + application, + key_handle, + handle_len, + filedata, + filedata_len, + passphrase); +} + #endif /* LIBSSH2_ECDSA */ @@ -1780,6 +1825,160 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } +static int +gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, + struct string_buf *decrypted, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + libssh2_ed25519_ctx **out_ctx) +{ + const char *key_type = "sk-ssh-ed25519@openssh.com"; + + libssh2_ed25519_ctx *ctx = NULL; + unsigned char *method_buf = NULL; + unsigned char *key = NULL; + int ret = 0; + unsigned char *pub_key, *app; + size_t key_len = 0, app_len = 0, tmp_len = 0; + unsigned char *p; + + _libssh2_debug(session, + LIBSSH2_TRACE_AUTH, + "Computing sk-ED25519 keys from private key data"); + + if(_libssh2_get_string(decrypted, &pub_key, &tmp_len) || + tmp_len != LIBSSH2_ED25519_KEY_LEN) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Wrong public key length"); + return -1; + } + + if(_libssh2_get_string(decrypted, &app, &app_len)) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "No SK application."); + return -1; + } + + if(flags != NULL && _libssh2_get_byte(decrypted, flags)) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "No SK flags."); + return -1; + } + + if(key_handle != NULL && handle_len != NULL) { + unsigned char *handle = NULL; + if(_libssh2_get_string(decrypted, &handle, handle_len)) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "No SK key_handle."); + return -1; + } + + if(*handle_len > 0) { + *key_handle = LIBSSH2_ALLOC(session, *handle_len); + + if(key_handle) { + memcpy((void *)*key_handle, handle, *handle_len); + } + } + } + + ctx = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, + (const unsigned char *)pub_key, + LIBSSH2_ED25519_KEY_LEN); + + if(ret == 0) { + _libssh2_debug(session, + LIBSSH2_TRACE_AUTH, + "Computing public key from ED25519 " + "private key envelope"); + + /* sk-ssh-ed25519@openssh.com. */ + method_buf = LIBSSH2_ALLOC(session, strlen(key_type)); + if(method_buf == NULL) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for ED25519 key"); + goto clean_exit; + } + + /* Key form is: type_len(4) + type(26) + pub_key_len(4) + + pub_key(32) + application_len(4) + application(X). */ + key_len = LIBSSH2_ED25519_KEY_LEN + 38 + app_len; + key = LIBSSH2_CALLOC(session, key_len); + if(key == NULL) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for ED25519 key"); + goto clean_exit; + } + + p = key; + + _libssh2_store_str(&p, key_type, strlen(key_type)); + _libssh2_store_str(&p, (const char *)pub_key, LIBSSH2_ED25519_KEY_LEN); + _libssh2_store_str(&p, (const char *)app, app_len); + + if(application != NULL && app_len > 0) { + *application = (const char *)LIBSSH2_ALLOC(session, app_len + 1); + _libssh2_explicit_zero((void *)*application, app_len + 1); + memcpy((void *)*application, app, app_len); + } + + memcpy(method_buf, key_type, strlen(key_type)); + + if(method != NULL) + *method = method_buf; + else + LIBSSH2_FREE(session, method_buf); + + if(method_len != NULL) + *method_len = strlen(key_type); + + if(pubkeydata != NULL) + *pubkeydata = key; + else if(key != NULL) + LIBSSH2_FREE(session, key); + + if(pubkeydata_len != NULL) + *pubkeydata_len = key_len; + + if(out_ctx != NULL) + *out_ctx = ctx; + else if(ctx != NULL) + _libssh2_ed25519_free(ctx); + + return 0; + } + +clean_exit: + + if(ctx) + _libssh2_ed25519_free(ctx); + + if(method_buf) + LIBSSH2_FREE(session, method_buf); + + if(key) + LIBSSH2_FREE(session, key); + + if(application != NULL && *application != NULL) { + LIBSSH2_FREE(session, (void *)application); + *application = NULL; + } + + if(key_handle != NULL && *key_handle != NULL) { + LIBSSH2_FREE(session, (void *)key_handle); + *key_handle = NULL; + } + + return -1; +} + + int _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, LIBSSH2_SESSION * session, @@ -1847,6 +2046,82 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, return rc; } +int +_libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION *session, + const char *filename, + const uint8_t *passphrase) +{ + int rc; + FILE *fp; + unsigned char *buf; + struct string_buf *decrypted = NULL; + libssh2_ed25519_ctx *ctx = NULL; + + if(session == NULL) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Session is required"); + return -1; + } + + _libssh2_init_if_needed(); + + fp = fopen(filename, "r"); + if(!fp) { + _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to open ED25519 SK private key file"); + return -1; + } + + rc = _libssh2_openssh_pem_parse(session, passphrase, fp, &decrypted); + fclose(fp); + if(rc) { + return rc; + } + + /* We have a new key file, now try and parse it using supported types */ + rc = _libssh2_get_string(decrypted, &buf, NULL); + + if(rc != 0 || buf == NULL) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Public key type in decrypted key data not found"); + return -1; + } + + if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { + rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, + decrypted, + NULL, + NULL, + NULL, + NULL, + flags, + application, + key_handle, + handle_len, + &ctx); + } + else { + rc = -1; + } + + if(decrypted) + _libssh2_string_buf_free(session, decrypted); + + if(rc == 0) { + if(ed_ctx != NULL) + *ed_ctx = ctx; + else if(ctx != NULL) + _libssh2_ed25519_free(ctx); + } + + return rc; +} + int _libssh2_ed25519_new_private_frommemory(libssh2_ed25519_ctx ** ed_ctx, LIBSSH2_SESSION * session, @@ -1878,6 +2153,35 @@ _libssh2_ed25519_new_private_frommemory(libssh2_ed25519_ctx ** ed_ctx, passphrase); } +int +_libssh2_ed25519_new_private_frommemory_sk(libssh2_ed25519_ctx **ed_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION *session, + const char *filedata, + size_t filedata_len, + unsigned const char *passphrase) +{ + int algorithm; + return _libssh2_sk_pub_openssh_keyfilememory(session, + (void **)ed_ctx, + "sk-ssh-ed25519@openssh.com", + NULL, + NULL, + NULL, + NULL, + &algorithm, + flags, + application, + key_handle, + handle_len, + filedata, + filedata_len, + passphrase); +} + int _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, LIBSSH2_SESSION * session, @@ -2318,6 +2622,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, size_t *method_len, unsigned char **pubkeydata, size_t *pubkeydata_len, + int is_sk, EVP_PKEY *pk) { int rc = 0; @@ -2351,18 +2656,25 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, group = EC_KEY_get0_group(ec); type = _libssh2_ecdsa_get_curve_type(ec); - method_buf = LIBSSH2_ALLOC(session, 19); + if(is_sk) + *method_len = 34; + else + *method_len = 19; + + method_buf = LIBSSH2_ALLOC(session, *method_len); if(method_buf == NULL) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "out of memory"); } - if(type == LIBSSH2_EC_CURVE_NISTP256) - memcpy(method_buf, "ecdsa-sha2-nistp256", 19); + if(is_sk) + memcpy(method_buf, "sk-ecdsa-sha2-nistp256@openssh.com", *method_len); + else if(type == LIBSSH2_EC_CURVE_NISTP256) + memcpy(method_buf, "ecdsa-sha2-nistp256", *method_len); else if(type == LIBSSH2_EC_CURVE_NISTP384) - memcpy(method_buf, "ecdsa-sha2-nistp384", 19); + memcpy(method_buf, "ecdsa-sha2-nistp384", *method_len); else if(type == LIBSSH2_EC_CURVE_NISTP521) - memcpy(method_buf, "ecdsa-sha2-nistp521", 19); + memcpy(method_buf, "ecdsa-sha2-nistp521", *method_len); else { _libssh2_debug(session, LIBSSH2_TRACE_ERROR, @@ -2393,9 +2705,9 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, goto clean_exit; } - /* Key form is: type_len(4) + type(19) + domain_len(4) + domain(8) + - pub_key_len(4) + pub_key(~65). */ - key_len = 4 + 19 + 4 + 8 + 4 + octal_len; + /* Key form is: type_len(4) + type(method_len) + domain_len(4) + domain(8) + + pub_key_len(4) + pub_key(~65). */ + key_len = 4 + *method_len + 4 + 8 + 4 + octal_len; key = LIBSSH2_ALLOC(session, key_len); if(key == NULL) { rc = -1; @@ -2406,16 +2718,20 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, p = key; /* Key type */ - _libssh2_store_str(&p, (const char *)method_buf, 19); + _libssh2_store_str(&p, (const char *)method_buf, *method_len); /* Name domain */ - _libssh2_store_str(&p, (const char *)method_buf + 11, 8); + if(is_sk) { + _libssh2_store_str(&p, "nistp256", 8); + } + else { + _libssh2_store_str(&p, (const char *)method_buf + 11, 8); + } /* Public key */ _libssh2_store_str(&p, (const char *)octal_value, octal_len); *method = method_buf; - *method_len = 19; *pubkeydata = key; *pubkeydata_len = key_len; @@ -2504,7 +2820,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, rc = gen_publickey_from_ec_evp(session, method, method_len, pubkeydata, pubkeydata_len, - pk); + 0, pk); if(pk) EVP_PKEY_free(pk); @@ -2524,6 +2840,144 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return rc; } +static int +gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, + struct string_buf *decrypted, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + uint8_t *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + libssh2_ecdsa_ctx **ec_ctx) +{ + int rc = 0; + size_t curvelen, pointlen, key_len, app_len; + unsigned char *curve, *point_buf, *p, *key, *app; + EC_KEY *ec_key = NULL; + + _libssh2_debug(session, + LIBSSH2_TRACE_AUTH, + "Extracting ECDSA-SK public key"); + + if(_libssh2_get_string(decrypted, &curve, &curvelen) || + curvelen == 0) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "ECDSA no curve"); + return -1; + } + + if(_libssh2_get_string(decrypted, &point_buf, &pointlen)) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "ECDSA no point"); + return -1; + } + + if((rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, point_buf, + pointlen, LIBSSH2_EC_CURVE_NISTP256)) != 0) { + rc = -1; + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "ECDSA could not create key"); + goto fail; + } + + if(_libssh2_get_string(decrypted, &app, &app_len)) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "No SK application."); + goto fail; + } + + if(flags != NULL && _libssh2_get_byte(decrypted, flags)) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "No SK flags."); + goto fail; + } + + if(key_handle != NULL && handle_len != NULL) { + unsigned char *handle = NULL; + if(_libssh2_get_string(decrypted, &handle, handle_len)) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "No SK key_handle."); + goto fail; + } + + if(*handle_len > 0) { + *key_handle = LIBSSH2_ALLOC(session, *handle_len); + + if(*key_handle) { + memcpy((void *)*key_handle, handle, *handle_len); + } + } + } + + if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) { + EVP_PKEY *pk = EVP_PKEY_new(); + EVP_PKEY_set1_EC_KEY(pk, ec_key); + + rc = gen_publickey_from_ec_evp(session, method, method_len, + pubkeydata, pubkeydata_len, + 1, pk); + + if(pk) + EVP_PKEY_free(pk); + } + + if(rc == 0 && pubkeydata != NULL) { + key_len = *pubkeydata_len + app_len + 4; + key = LIBSSH2_ALLOC(session, key_len); + + if(key == NULL) { + rc = -1; + goto fail; + } + + p = key + *pubkeydata_len; + + memcpy(key, *pubkeydata, *pubkeydata_len); + _libssh2_store_str(&p, (const char *)app, app_len); + + if(application != NULL && app_len > 0) { + *application = (const char *)LIBSSH2_ALLOC(session, app_len + 1); + _libssh2_explicit_zero((void *)*application, app_len + 1); + memcpy((void *)*application, app, app_len); + } + + LIBSSH2_FREE(session, *pubkeydata); + *pubkeydata_len = key_len; + + if(pubkeydata != NULL) + *pubkeydata = key; + else if(key != NULL) + LIBSSH2_FREE(session, key); + } + + if(ec_ctx != NULL) + *ec_ctx = ec_key; + else + EC_KEY_free(ec_key); + + return rc; + +fail: + if(ec_key != NULL) + EC_KEY_free(ec_key); + + if(application != NULL && *application != NULL) { + LIBSSH2_FREE(session, (void *)application); + *application = NULL; + } + + if(key_handle != NULL && *key_handle != NULL) { + LIBSSH2_FREE(session, (void *)key_handle); + *key_handle = NULL; + } + + return rc; +} + + static int _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, LIBSSH2_SESSION * session, @@ -2583,6 +3037,72 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, return rc; } +static int +_libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, + uint8_t *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION * session, + const char *filename, + unsigned const char *passphrase) +{ + FILE *fp; + int rc; + unsigned char *buf = NULL; + struct string_buf *decrypted = NULL; + + if(session == NULL) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Session is required"); + return -1; + } + + _libssh2_init_if_needed(); + + fp = fopen(filename, "r"); + if(!fp) { + _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to open OpenSSH ECDSA private key file"); + return -1; + } + + rc = _libssh2_openssh_pem_parse(session, passphrase, fp, &decrypted); + fclose(fp); + if(rc) { + return rc; + } + + /* We have a new key file, now try and parse it using supported types */ + rc = _libssh2_get_string(decrypted, &buf, NULL); + + if(rc != 0 || buf == NULL) { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Public key type in decrypted key data not found"); + return -1; + } + + if(strcmp("sk-ecdsa-sha2-nistp256@openssh.com", (const char *)buf) == 0) { + rc = gen_publickey_from_sk_ecdsa_openssh_priv_data(session, + decrypted, + NULL, 0, + NULL, 0, + flags, + application, + key_handle, + handle_len, + ec_ctx); + } + else { + rc = -1; + } + + if(decrypted) + _libssh2_string_buf_free(session, decrypted); + + return rc; +} + int _libssh2_ecdsa_new_private(libssh2_ecdsa_ctx ** ec_ctx, LIBSSH2_SESSION * session, @@ -2605,6 +3125,40 @@ _libssh2_ecdsa_new_private(libssh2_ecdsa_ctx ** ec_ctx, return rc; } +int +_libssh2_ecdsa_new_private_sk(libssh2_ecdsa_ctx ** ec_ctx, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + LIBSSH2_SESSION * session, + const char *filename, + unsigned const char *passphrase) +{ + int rc; + + pem_read_bio_func read_ec = (pem_read_bio_func) &PEM_read_bio_ECPrivateKey; + + _libssh2_init_if_needed(); + + rc = read_private_key_from_file((void **) ec_ctx, read_ec, + filename, passphrase); + + if(rc) { + return _libssh2_ecdsa_new_openssh_private_sk(ec_ctx, + flags, + application, + key_handle, + handle_len, + session, + filename, + passphrase); + } + + return rc; +} + + /* * _libssh2_ecdsa_create_key * @@ -3078,7 +3632,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, #if LIBSSH2_ECDSA case EVP_PKEY_EC : st = gen_publickey_from_ec_evp( - session, method, method_len, pubkeydata, pubkeydata_len, pk); + session, method, method_len, pubkeydata, pubkeydata_len, 0, pk); break; #endif @@ -3153,6 +3707,23 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, (libssh2_ed25519_ctx**)key_ctx); } } + + if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { + if(key_type == NULL || + strcmp("sk-ssh-ed25519@openssh.com", key_type) == 0) { + rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, + decrypted, + method, + method_len, + pubkeydata, + pubkeydata_len, + NULL, + NULL, + NULL, + NULL, + (libssh2_ed25519_ctx**)key_ctx); + } + } #endif #if LIBSSH2_RSA if(strcmp("ssh-rsa", (const char *)buf) == 0) { @@ -3180,16 +3751,125 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, { libssh2_curve_type type; - if(_libssh2_ecdsa_curve_type_from_name((const char *)buf, &type) == 0) { - if(key_type == NULL || strcmp("ssh-ecdsa", key_type) == 0) { - rc = gen_publickey_from_ecdsa_openssh_priv_data(session, type, - decrypted, + if(strcmp("sk-ecdsa-sha2-nistp256@openssh.com", (const char *)buf) == 0) { + rc = gen_publickey_from_sk_ecdsa_openssh_priv_data(session, decrypted, method, method_len, pubkeydata, pubkeydata_len, + NULL, + NULL, NULL, + NULL, (libssh2_ecdsa_ctx**)key_ctx); + } + else if(_libssh2_ecdsa_curve_type_from_name((const char *)buf, &type) + == 0) { + if(key_type == NULL || strcmp("ssh-ecdsa", key_type) == 0) { + rc = gen_publickey_from_ecdsa_openssh_priv_data(session, type, + decrypted, + method, method_len, + pubkeydata, + pubkeydata_len, + (libssh2_ecdsa_ctx**)key_ctx); + } + } +} +#endif + + if(rc == LIBSSH2_ERROR_FILE) + rc = _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to extract public key from private key file: " + "invalid/unrecognized private key file format"); + + if(decrypted) + _libssh2_string_buf_free(session, decrypted); + + return rc; +} + +static int +_libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, + void **key_ctx, + const char *key_type, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + unsigned const char *passphrase) +{ + int rc; + unsigned char *buf = NULL; + struct string_buf *decrypted = NULL; + + if(key_ctx != NULL) + *key_ctx = NULL; + + if(session == NULL) + return _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Session is required"); + + if(key_type != NULL && strlen(key_type) < 7) + return _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "type is invalid"); + + _libssh2_init_if_needed(); + + rc = _libssh2_openssh_pem_parse_memory(session, passphrase, + privatekeydata, + privatekeydata_len, &decrypted); + + if(rc) + return rc; + + /* We have a new key file, now try and parse it using supported types */ + rc = _libssh2_get_string(decrypted, &buf, NULL); + + if(rc != 0 || buf == NULL) + return _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Public key type in decrypted " + "key data not found"); + + rc = LIBSSH2_ERROR_FILE; + +#if LIBSSH2_ED25519 + if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { + *algorithm = LIBSSH2_HOSTKEY_TYPE_ED25519; + if(key_type == NULL || + strcmp("sk-ssh-ed25519@openssh.com", key_type) == 0) { + rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, + decrypted, + method, + method_len, + pubkeydata, + pubkeydata_len, + flags, + application, + key_handle, + handle_len, + (libssh2_ed25519_ctx**)key_ctx); } } +#endif +#if LIBSSH2_ECDSA +{ + if(strcmp("sk-ecdsa-sha2-nistp256@openssh.com", (const char *)buf) == 0) { + *algorithm = LIBSSH2_HOSTKEY_TYPE_ECDSA_256; + rc = gen_publickey_from_sk_ecdsa_openssh_priv_data(session, decrypted, + method, method_len, + pubkeydata, + pubkeydata_len, + flags, + application, + key_handle, + handle_len, + (libssh2_ecdsa_ctx**)key_ctx); + } } #endif @@ -3286,7 +3966,8 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, #if LIBSSH2_ECDSA case EVP_PKEY_EC : st = gen_publickey_from_ec_evp(session, method, method_len, - pubkeydata, pubkeydata_len, pk); + pubkeydata, pubkeydata_len, + 0, pk); break; #endif /* LIBSSH2_ECDSA */ default : @@ -3302,6 +3983,58 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, return st; } +int +_libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase) +{ + int st = -1; + BIO* bp; + EVP_PKEY* pk; + + _libssh2_debug(session, + LIBSSH2_TRACE_AUTH, + "Computing public key from private key."); + + bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len); + if(!bp) + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory when" + "computing public key"); + BIO_reset(bp); + pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); + BIO_free(bp); + + if(pk == NULL) { + /* Try OpenSSH format */ + st = _libssh2_sk_pub_openssh_keyfilememory(session, NULL, NULL, + method, + method_len, + pubkeydata, + pubkeydata_len, + algorithm, + flags, + application, + key_handle, + handle_len, + privatekeydata, + privatekeydata_len, + (unsigned const char *)passphrase); + } + + return st; +} + void _libssh2_dh_init(_libssh2_dh_ctx *dhctx) { diff --git a/src/os400qc3.c b/src/os400qc3.c index daed1e5d95..22955a1585 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -2359,6 +2359,26 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, return ret; } +int +_libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase) +{ + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to extract public SK key from private key file: " + "Method unimplemented in OS/400 QC3 backend"); +} + int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa, const unsigned char *sig, unsigned long sig_len, diff --git a/src/userauth.c b/src/userauth.c index a09c3e9fd7..bbd22f84ee 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -890,7 +890,106 @@ sign_fromfile(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, return 0; } +int +libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, + const unsigned char *data, size_t data_len, void **abstract) +{ + int rc = LIBSSH2_ERROR_DECRYPT; + LIBSSH2_PRIVKEY_SK *sk_info = (LIBSSH2_PRIVKEY_SK *) (*abstract); + LIBSSH2_SK_SIG_INFO sig_info = { 0 }; + + if(sk_info->handle_len <= 0) { + return LIBSSH2_ERROR_DECRYPT; + } + + rc = sk_info->sign_callback(session, + &sig_info, + data, + data_len, + sk_info->algorithm, + sk_info->flags, + sk_info->application, + sk_info->key_handle, + sk_info->handle_len, + sk_info->orig_abstract); + + if(rc == 0 && sig_info.sig_r_len > 0 && sig_info.sig_r) { + unsigned char *p = NULL; + + if(sig_info.sig_s_len > 0 && sig_info.sig_s) { + /* sig length, sig_r, sig_s, flags, counter, plus 4 bytes for each + component's length, and up to 1 extra byte for each component */ + *sig_len = 4 + 5 + sig_info.sig_r_len + 5 + sig_info.sig_s_len + 5; + *sig = LIBSSH2_ALLOC(session, *sig_len); + + if(*sig) { + unsigned char *x = *sig; + p = *sig; + + _libssh2_store_u32(&p, 0); + + _libssh2_store_bignum2_bytes(&p, + sig_info.sig_r, + sig_info.sig_r_len); + + _libssh2_store_bignum2_bytes(&p, + sig_info.sig_s, + sig_info.sig_s_len); + + *sig_len = p - *sig; + + _libssh2_store_u32(&x, *sig_len - 4); + } + else { + _libssh2_debug(session, + LIBSSH2_ERROR_ALLOC, + "Unable to allocate ecdsa-sk signature."); + rc = LIBSSH2_ERROR_ALLOC; + } + } + else { + /* sig, flags, counter, plus 4 bytes for sig length. */ + *sig_len = 4 + sig_info.sig_r_len + 1 + 4; + *sig = LIBSSH2_ALLOC(session, *sig_len); + if(*sig) { + p = *sig; + + _libssh2_store_str(&p, + (const char *)sig_info.sig_r, + sig_info.sig_r_len); + } + else { + _libssh2_debug(session, + LIBSSH2_ERROR_ALLOC, + "Unable to allocate ed25519-sk signature."); + rc = LIBSSH2_ERROR_ALLOC; + } + } + + if(p) { + *p = sig_info.flags; + ++p; + _libssh2_store_u32(&p, sig_info.counter); + + *sig_len = p - *sig; + } + + LIBSSH2_FREE(session, sig_info.sig_r); + + if(sig_info.sig_s != NULL) { + LIBSSH2_FREE(session, sig_info.sig_s); + } + } + else { + _libssh2_debug(session, + LIBSSH2_ERROR_DECRYPT, + "sign_callback failed or returned invalid signature."); + *sig_len = 0; + } + + return rc; +} /* userauth_hostbased_fromfile * Authenticate using a keypair found in the named files @@ -1603,16 +1702,32 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, plain_method_len((const char *)session->userauth_pblc_method, session->userauth_pblc_method_len); - _libssh2_store_u32(&s, - 4 + session->userauth_pblc_method_len + 4 + - sig_len); - _libssh2_store_str(&s, (const char *)session->userauth_pblc_method, - session->userauth_pblc_method_len); + if(strncmp((const char *)session->userauth_pblc_method, + "sk-ecdsa-sha2-nistp256@openssh.com", + session->userauth_pblc_method_len) == 0 || + strncmp((const char *)session->userauth_pblc_method, + "sk-ssh-ed25519@openssh.com", + session->userauth_pblc_method_len) == 0) { + _libssh2_store_u32(&s, + 4 + session->userauth_pblc_method_len + + sig_len); + _libssh2_store_str(&s, (const char *)session->userauth_pblc_method, + session->userauth_pblc_method_len); + memcpy(s, sig, sig_len); + s += sig_len; + } + else { + _libssh2_store_u32(&s, + 4 + session->userauth_pblc_method_len + 4 + + sig_len); + _libssh2_store_str(&s, (const char *)session->userauth_pblc_method, + session->userauth_pblc_method_len); + _libssh2_store_str(&s, (const char *)sig, sig_len); + } LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; - _libssh2_store_str(&s, (const char *)sig, sig_len); LIBSSH2_FREE(session, sig); _libssh2_debug(session, LIBSSH2_TRACE_AUTH, @@ -2164,3 +2279,68 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION *session, response_callback)); return rc; } + +/* libssh2_userauth_publickey_sk + * Authenticate using an external callback function + */ +LIBSSH2_API int +libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, + const char *username, + size_t username_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase, + LIBSSH2_USERAUTH_SK_SIGN_FUNC + ((*sign_callback)), + void **abstract) +{ + unsigned char *pubkeydata = NULL; + size_t pubkeydata_len = 0; + LIBSSH2_PRIVKEY_SK sk_info = { 0 }; + void *sign_abstract = &sk_info; + int rc; + + sk_info.sign_callback = sign_callback; + sk_info.orig_abstract = abstract; + + if(privatekeydata_len && privatekeydata) { + + if(_libssh2_sk_pub_keyfilememory(session, + &session->userauth_pblc_method, + &session->userauth_pblc_method_len, + &pubkeydata, &pubkeydata_len, + &(sk_info.algorithm), + &(sk_info.flags), + &(sk_info.application), + &(sk_info.key_handle), + &(sk_info.handle_len), + privatekeydata, privatekeydata_len, + passphrase)) + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to extract public key " + "from private key."); + } + else { + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Invalid data in public and private key."); + } + + rc = _libssh2_userauth_publickey(session, username, username_len, + pubkeydata, pubkeydata_len, + libssh2_sign_sk, &sign_abstract); + + while(rc == LIBSSH2_ERROR_EAGAIN) { + rc = _libssh2_userauth_publickey(session, username, username_len, + pubkeydata, pubkeydata_len, + libssh2_sign_sk, &sign_abstract); + } + + if(pubkeydata) + LIBSSH2_FREE(session, pubkeydata); + + if(sk_info.application) { + LIBSSH2_FREE(session, (void *)sk_info.application); + } + + return rc; +} diff --git a/src/wincng.c b/src/wincng.c index ebf7929509..ad1e52ab26 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -1834,6 +1834,26 @@ _libssh2_wincng_pub_priv_keyfilememory(LIBSSH2_SESSION *session, #endif /* HAVE_LIBCRYPT32 */ } +int +_libssh2_wincng_sk_pub_keyfilememory(LIBSSH2_SESSION *session, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + int *algorithm, + unsigned char *flags, + const char **application, + const unsigned char **key_handle, + size_t *handle_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase) +{ + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to extract public SK key from private key file: " + "Method unimplemented in Windows CNG backend"); +} + /*******************************************************************/ /* * Windows CNG backend: Cipher functions diff --git a/src/wincng.h b/src/wincng.h index a5f4506f8c..f9791650f4 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -304,7 +304,10 @@ typedef struct __libssh2_wincng_key_ctx { pk, pk_len, pw) \ _libssh2_wincng_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ pk, pk_len, pw) - +#define _libssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ + f, kh, kh_len, pk, pk_len, pw) \ + _libssh2_wincng_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ + f, kh, kh_len, pk, pk_len, pw) /*******************************************************************/ /* diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c index 56b1ba5490..c1ab973069 100644 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c @@ -19,8 +19,8 @@ static void kbd_callback(const char *name, int name_len, fprintf(stdout, "Kb-int name: %.*s\n", name_len, name); fprintf(stdout, "Kb-int instruction: %.*s\n", instruct_len, instruct); for(i = 0; i < num_prompts; ++i) { - fprintf(stdout, "Kb-int prompt %d: %.*s\n", i, prompts[i].length, - prompts[i].text); + fprintf(stdout, "Kb-int prompt %d: %.*s\n", i, + (int)prompts[i].length, prompts[i].text); } if(num_prompts == 1) { diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c index 0ccf5dd903..093e4a22ab 100644 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c @@ -21,8 +21,8 @@ static void kbd_callback(const char *name, int name_len, fprintf(stdout, "Kb-int name: %.*s\n", name_len, name); fprintf(stdout, "Kb-int instruction: %.*s\n", instruct_len, instruct); for(i = 0; i < num_prompts; ++i) { - fprintf(stdout, "Kb-int prompt %d: %.*s\n", i, prompts[i].length, - prompts[i].text); + fprintf(stdout, "Kb-int prompt %d: %.*s\n", i, + (int)prompts[i].length, prompts[i].text); } if(num_prompts == 1) { From 70a85e9c6e12467ac2cf9e0950412af849ed32b7 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Fri, 7 Oct 2022 23:45:09 +0200 Subject: [PATCH 060/424] CI: report AppVeyor build status for each job (#754) Also give each job on AppVeyor CI a human-readable name. This aims to make job and therefore build failures more visible. --- .github/workflows/appveyor_status.yml | 56 +++++++++++++++++++++++++++ appveyor.yml | 24 ++++++++---- 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/appveyor_status.yml diff --git a/.github/workflows/appveyor_status.yml b/.github/workflows/appveyor_status.yml new file mode 100644 index 0000000000..0edc2b6940 --- /dev/null +++ b/.github/workflows/appveyor_status.yml @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Marc Hoersken +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +name: AppVeyor Status Report + +on: + status + +concurrency: + group: ${{ github.workflow }}-${{ github.event.sha }}-${{ github.event.target_url }} + cancel-in-progress: true + +jobs: + split: + runs-on: ubuntu-latest + if: ${{ github.event.sender.login == 'appveyor[bot]' }} + steps: + - name: Create individual AppVeyor build statuses + if: ${{ github.event.sha && github.event.target_url }} + env: + APPVEYOR_COMMIT_SHA: ${{ github.event.sha }} + APPVEYOR_TARGET_URL: ${{ github.event.target_url }} + APPVEYOR_REPOSITORY: ${{ github.event.repository.full_name }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo ${APPVEYOR_TARGET_URL} | sed 's/\/project\//\/api\/projects\//' | xargs -t -n1 curl -s | \ + jq -c '.build.jobs[] | {target_url: (($target_url | sub("s\\/\\d+"; "/job/")) + .jobId), + context: (.name | sub("^(Environment: )?"; "AppVeyor / ")), + state: (.status | sub("queued"; "pending") + | sub("running"; "pending") + | sub("failed"; "failure") + | sub("cancelled"; "error")), + description: .status}' \ + --arg target_url ${APPVEYOR_TARGET_URL} | parallel --pipe -j 1 -N 1 \ + gh api --silent --input - repos/${APPVEYOR_REPOSITORY}/statuses/${APPVEYOR_COMMIT_SHA} diff --git a/appveyor.yml b/appveyor.yml index 1c374b4712..e7023c2812 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,35 +28,43 @@ os: Visual Studio 2015 environment: matrix: - - GENERATOR: "Visual Studio 14 2015" + - job_name: "VS2015, OpenSSL, Shared" + GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: ON CRYPTO_BACKEND: "OpenSSL" - - GENERATOR: "Visual Studio 14 2015" + - job_name: "VS2015, OpenSSL, Static" + GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: OFF CRYPTO_BACKEND: "OpenSSL" - - GENERATOR: "Visual Studio 12 2013" + - job_name: "VS2013, OpenSSL, Shared" + GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: ON CRYPTO_BACKEND: "OpenSSL" - - GENERATOR: "Visual Studio 12 2013" + - job_name: "VS2013, OpenSSL, Static" + GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: OFF CRYPTO_BACKEND: "OpenSSL" - - GENERATOR: "Visual Studio 14 2015" + - job_name: "VS2015, WinCNG, Shared" + GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: ON CRYPTO_BACKEND: "WinCNG" - - GENERATOR: "Visual Studio 14 2015" + - job_name: "VS2015, WinCNG, Static" + GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: OFF CRYPTO_BACKEND: "WinCNG" - - GENERATOR: "Visual Studio 12 2013" + - job_name: "VS2013, WinCNG, Shared" + GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: ON CRYPTO_BACKEND: "WinCNG" - - GENERATOR: "Visual Studio 12 2013" + - job_name: "VS2013, WinCNG, Static" + GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: OFF CRYPTO_BACKEND: "WinCNG" From 752d90f2175f114ebb3c49cf88c1421bc469c77c Mon Sep 17 00:00:00 2001 From: Jeroen Ooms Date: Mon, 12 Sep 2022 08:36:25 +0200 Subject: [PATCH 061/424] Add CI for mingw-w64 via msys2 (#742) Credit: Jeroen Ooms --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7546ff91ed..7c179852bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,3 +101,31 @@ jobs: - uses: actions/checkout@v2 - name: Run Fuzzer run: GIT_REF=$GITHUB_REF ./ci/ossfuzz.sh + + build_msys2: + name: msys2 + runs-on: windows-latest + strategy: + matrix: + include: + - { sys: mingw64, env: x86_64 } + - { sys: mingw32, env: i686 } + - { sys: ucrt64, env: ucrt-x86_64 } + - { sys: clang64, env: clang-x86_64 } + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 + with: + msystem: ${{matrix.sys}} + install: >- + mingw-w64-${{matrix.env}}-cc + mingw-w64-${{matrix.env}}-autotools + mingw-w64-${{matrix.env}}-openssl + - name: Building libssh2 + shell: msys2 {0} + run: | + autoreconf -fi + ./configure --enable-debug --enable-static --disable-shared --with-crypto=openssl + make + make check From 612779b02c5aab2d964c003b1e34843e13811c27 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sun, 16 Oct 2022 21:23:56 +0200 Subject: [PATCH 062/424] Streamline names of CI workflow jobs --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c179852bc..e7954a264a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,13 +7,16 @@ on: branches: [ master ] jobs: - style-check: + check_style: + name: style-check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Check Style run: ./ci/checksrc.sh - build: + + build_linux: + name: linux runs-on: ubuntu-latest strategy: fail-fast: false @@ -88,6 +91,7 @@ jobs: export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) ctest -VV --output-on-failure cmake --build . --target package + fuzzer: runs-on: ubuntu-latest strategy: From fb8b84bc9f8b0800e08b072c43fd11875a35875c Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sun, 16 Oct 2022 21:26:42 +0200 Subject: [PATCH 063/424] Rename workflow file appveyor.yml to appveyor_docker.yml --- .github/workflows/{appveyor.yml => appveyor_docker.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{appveyor.yml => appveyor_docker.yml} (100%) diff --git a/.github/workflows/appveyor.yml b/.github/workflows/appveyor_docker.yml similarity index 100% rename from .github/workflows/appveyor.yml rename to .github/workflows/appveyor_docker.yml From 94bd3d87c58820795b5ad20da21de9dd6ef50630 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Mon, 17 Oct 2022 22:00:31 +0200 Subject: [PATCH 064/424] Remove OSSFuzz integration which was replaced with CIFuzz (#756) Confirmed-by: Max Dymond --- .github/workflows/ci.yml | 14 -------------- ci/ossfuzz.sh | 29 ----------------------------- 2 files changed, 43 deletions(-) delete mode 100755 ci/ossfuzz.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7954a264a..5a47946a4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,20 +92,6 @@ jobs: ctest -VV --output-on-failure cmake --build . --target package - fuzzer: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - compiler: [gcc, clang] - env: - CC: ${{ matrix.compiler }} - CC_FOR_BUILD: ${{ matrix.compiler }} - steps: - - uses: actions/checkout@v2 - - name: Run Fuzzer - run: GIT_REF=$GITHUB_REF ./ci/ossfuzz.sh - build_msys2: name: msys2 runs-on: windows-latest diff --git a/ci/ossfuzz.sh b/ci/ossfuzz.sh deleted file mode 100755 index 9ca9c165d3..0000000000 --- a/ci/ossfuzz.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -set -ex - -PROJECT_NAME=libssh2 - -# Clone the oss-fuzz repository -git clone https://github.com/google/oss-fuzz.git /tmp/ossfuzz - -if [[ ! -d /tmp/ossfuzz/projects/${PROJECT_NAME} ]] -then - echo "Could not find the ${PROJECT_NAME} project in ossfuzz" - - # Exit with a success code while the libssh2 project is not expected to exist - # on oss-fuzz. - exit 0 -fi - -# Modify the oss-fuzz Dockerfile so that we're checking out the current branch in the CI system. -sed -i \ - -e "s@--depth 1@--no-checkout@" \ - -e "s@/src/libssh2@/src/libssh2 ; git -C /src/libssh2 fetch origin $GIT_REF:ci; git -C /src/libssh2 checkout ci@" \ - /tmp/ossfuzz/projects/${PROJECT_NAME}/Dockerfile - -# Try and build the fuzzers -pushd /tmp/ossfuzz -python infra/helper.py build_image --pull ${PROJECT_NAME} -python infra/helper.py build_fuzzers ${PROJECT_NAME} -popd From 44379f4762f1d335a1f6a2f52ed15edeb060bac0 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Thu, 20 Oct 2022 20:57:21 +0200 Subject: [PATCH 065/424] CI: add missing permission section to AppVeyor status workflow Follow up to #754 --- .github/workflows/appveyor_status.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/appveyor_status.yml b/.github/workflows/appveyor_status.yml index 0edc2b6940..d7365bffdc 100644 --- a/.github/workflows/appveyor_status.yml +++ b/.github/workflows/appveyor_status.yml @@ -31,6 +31,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.sha }}-${{ github.event.target_url }} cancel-in-progress: true +permissions: + statuses: write + jobs: split: runs-on: ubuntu-latest From c2a7fad06b2173e7e54827daa8523797b5361262 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Fri, 21 Oct 2022 22:57:23 +0200 Subject: [PATCH 066/424] CI: fix AppVeyor job links only working for most recent build Ref: https://github.com/curl/curl/pull/9768#issuecomment-1286675916 Reported-by: Daniel Stenberg Follow up to #754 --- .github/workflows/appveyor_status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/appveyor_status.yml b/.github/workflows/appveyor_status.yml index d7365bffdc..a36b43c10c 100644 --- a/.github/workflows/appveyor_status.yml +++ b/.github/workflows/appveyor_status.yml @@ -48,7 +48,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo ${APPVEYOR_TARGET_URL} | sed 's/\/project\//\/api\/projects\//' | xargs -t -n1 curl -s | \ - jq -c '.build.jobs[] | {target_url: (($target_url | sub("s\\/\\d+"; "/job/")) + .jobId), + jq -c '.build.jobs[] | {target_url: ($target_url + "/job/" + .jobId), context: (.name | sub("^(Environment: )?"; "AppVeyor / ")), state: (.status | sub("queued"; "pending") | sub("running"; "pending") From ea5d83d330dcc804cca347cd52f8a5bdded9b473 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 00:11:07 +0000 Subject: [PATCH 067/424] win32/GNUmakefile: add mbedTLS support via `export MBEDTLS_PATH=`. --- win32/GNUmakefile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 0971d891cc..86bf0ed35f 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -171,6 +171,12 @@ ifdef WITH_WINCNG CFLAGS += -DLIBSSH2_WINCNG LDLIBS += -lbcrypt -lcrypt32 else +ifdef MBEDTLS_PATH +CFLAGS += -DLIBSSH2_MBEDTLS +CFLAGS += -I"$(MBEDTLS_PATH)/include" +LIBPATH += -L"$(MBEDTLS_PATH)/libs" +LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto +else CFLAGS += -DLIBSSH2_OPENSSL ifndef OPENSSL_INCLUDE ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" @@ -201,6 +207,7 @@ else LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) endif endif +endif ifeq ($(CC),mwcc) LDLIBS += -lkernel32.lib -luser32.lib -lwsock32.lib else @@ -225,8 +232,12 @@ vpath %.c $(PROOT)/src ifdef WITH_WINCNG include $(PROOT)/Makefile.WinCNG.inc else +ifdef MBEDTLS_PATH +include $(PROOT)/Makefile.mbedTLS.inc +else include $(PROOT)/Makefile.OpenSSL.inc endif +endif # include Makefile.inc to get CSOURCES define include $(PROOT)/Makefile.inc From e9561dd66e8276ebba312211b6e812ae5712f278 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 00:16:50 +0000 Subject: [PATCH 068/424] tests: add option to enable all trace messages in fixture via `export FIXTURE_TRACE_ALL=1`. --- tests/session_fixture.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 5d8fd2156e..1f7e0f9134 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -116,6 +116,9 @@ LIBSSH2_SESSION *start_session_fixture() } connected_session = libssh2_session_init_ex(NULL, NULL, NULL, NULL); + if(getenv("FIXTURE_TRACE_ALL")) { + libssh2_trace(connected_session, ~0); + } libssh2_session_set_blocking(connected_session, 1); if(connected_session == NULL) { fprintf(stderr, "libssh2_session_init_ex failed\n"); From 048a6b411fccd2876c07fda278c6c37037395dd6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Oct 2022 22:20:52 +0000 Subject: [PATCH 069/424] add mbedTLS 3.x support Make libssh2 compile cleanly with mbedTLS 3.x and later. This patch makes use of `MBEDTLS_PRIVATE()`, which is not the recommended, future-proof way to access mbedTLS data structures. This method may break with a minor upgrade, according to the authors. This is also the method used by libcurl. Also: - Fix a potentially uninitialized variable in `libssh2_mbedtls_rsa_sha2_sign()`. This happened in an error path, resulting in an unnecessary mbedTLS API call, with an uninitialized `md_type`. - Bump mbedTLS version used in CI tests to 3.2.1. Fixes #751 --- .github/workflows/ci.yml | 2 +- src/mbedtls.c | 156 ++++++++++++++++++++++++++++----------- src/mbedtls.h | 18 ++++- 3 files changed, 129 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a47946a4c..a8064dd4ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: - name: Install mbedTLS Dependencies if: ${{ matrix.crypto_backend == 'mbedTLS' }} run: | - MBEDTLSVER=mbedtls-2.7.0 + MBEDTLSVER=mbedtls-3.2.1 curl -L https://github.com/ARMmbed/mbedtls/archive/$MBEDTLSVER.tar.gz | tar -xzf - cd mbedtls-$MBEDTLSVER cmake $TOOLCHAIN_OPTION -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=../usr . diff --git a/src/mbedtls.c b/src/mbedtls.c index 9de8ed6df1..61fa3436f7 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -122,10 +122,14 @@ _libssh2_mbedtls_cipher_init(_libssh2_cipher_ctx *ctx, mbedtls_cipher_init(ctx); ret = mbedtls_cipher_setup(ctx, cipher_info); if(!ret) - ret = mbedtls_cipher_setkey(ctx, secret, cipher_info->key_bitlen, op); + ret = mbedtls_cipher_setkey(ctx, + secret, + mbedtls_cipher_info_get_key_bitlen(cipher_info), + op); if(!ret) - ret = mbedtls_cipher_set_iv(ctx, iv, cipher_info->iv_size); + ret = mbedtls_cipher_set_iv(ctx, iv, + mbedtls_cipher_info_get_iv_size(cipher_info)); return ret == 0 ? 0 : -1; } @@ -331,29 +335,33 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, ctx = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx)); if(ctx != NULL) { +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + mbedtls_rsa_init(ctx); +#else mbedtls_rsa_init(ctx, MBEDTLS_RSA_PKCS_V15, 0); +#endif } else return -1; /* !checksrc! disable ASSIGNWITHINCONDITION 1 */ - if((ret = mbedtls_mpi_read_binary(&(ctx->E), edata, elen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->N), ndata, nlen) ) != 0) { + if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(E)), edata, elen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(N)), ndata, nlen) ) != 0) { ret = -1; } if(!ret) { - ctx->len = mbedtls_mpi_size(&(ctx->N)); + ctx->MBEDTLS_PRIVATE(len) = mbedtls_mpi_size(&(ctx->MBEDTLS_PRIVATE(N))); } if(!ret && ddata) { /* !checksrc! disable ASSIGNWITHINCONDITION 1 */ - if((ret = mbedtls_mpi_read_binary(&(ctx->D), ddata, dlen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->P), pdata, plen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->Q), qdata, qlen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->DP), e1data, e1len) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->DQ), e2data, e2len) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->QP), coeffdata, coefflen) ) + if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(D)), ddata, dlen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(P)), pdata, plen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(Q)), qdata, qlen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DP)), e1data, e1len) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DQ)), e2data, e2len) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(QP)), coeffdata, coefflen) ) != 0) { ret = -1; } @@ -385,10 +393,20 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa, if(*rsa == NULL) return -1; +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + mbedtls_rsa_init(*rsa); +#else mbedtls_rsa_init(*rsa, MBEDTLS_RSA_PKCS_V15, 0); +#endif mbedtls_pk_init(&pkey); +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase, + mbedtls_ctr_drbg_random, + &_libssh2_mbedtls_ctr_drbg); +#else ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase); +#endif if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) { mbedtls_pk_free(&pkey); mbedtls_rsa_free(*rsa); @@ -434,9 +452,17 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, mbedtls_pk_init(&pkey); pwd_len = passphrase != NULL ? strlen((const char *)passphrase) : 0; +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata_nullterm, + filedata_len + 1, + passphrase, pwd_len, + mbedtls_ctr_drbg_random, + &_libssh2_mbedtls_ctr_drbg); +#else ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata_nullterm, filedata_len + 1, passphrase, pwd_len); +#endif _libssh2_mbedtls_safe_free(filedata_nullterm, filedata_len); if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) { @@ -487,9 +513,15 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, return -1; /* failure */ } +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + ret = mbedtls_rsa_pkcs1_verify(rsactx, + md_type, hash_len, + hash, sig); +#else ret = mbedtls_rsa_pkcs1_verify(rsactx, NULL, NULL, MBEDTLS_RSA_PUBLIC, md_type, hash_len, hash, sig); +#endif free(hash); return (ret == 1) ? 0 : -1; @@ -519,11 +551,12 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, int md_type; (void)hash_len; - sig_len = rsa->len; + sig_len = mbedtls_rsa_get_len(rsa); sig = LIBSSH2_ALLOC(session, sig_len); if(!sig) { return -1; } + ret = 0; if(hash_len == SHA_DIGEST_LENGTH) { md_type = MBEDTLS_MD_SHA1; } @@ -538,9 +571,19 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, "Unsupported hash digest length"); ret = -1; } - ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, - md_type, hash_len, - hash, sig); + if(ret == 0) { +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + ret = mbedtls_rsa_pkcs1_sign(rsa, + mbedtls_ctr_drbg_random, + &_libssh2_mbedtls_ctr_drbg, + md_type, hash_len, + hash, sig); +#else + ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, + md_type, hash_len, + hash, sig); +#endif + } if(ret) { LIBSSH2_FREE(session, sig); return -1; @@ -580,8 +623,8 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, unsigned char *key; unsigned char *p; - e_bytes = mbedtls_mpi_size(&rsa->E); - n_bytes = mbedtls_mpi_size(&rsa->N); + e_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E)); + n_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N)); /* Key form is "ssh-rsa" + e + n. */ len = 4 + 7 + 4 + e_bytes + 4 + n_bytes; @@ -601,11 +644,11 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, _libssh2_htonu32(p, e_bytes); p += 4; - mbedtls_mpi_write_binary(&rsa->E, p, e_bytes); + mbedtls_mpi_write_binary(&rsa->MBEDTLS_PRIVATE(E), p, e_bytes); _libssh2_htonu32(p, n_bytes); p += 4; - mbedtls_mpi_write_binary(&rsa->N, p, n_bytes); + mbedtls_mpi_write_binary(&rsa->MBEDTLS_PRIVATE(N), p, n_bytes); *keylen = (size_t)(p - key); return key; @@ -677,7 +720,13 @@ _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session, int ret; mbedtls_pk_init(&pkey); +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase, + mbedtls_ctr_drbg_random, + &_libssh2_mbedtls_ctr_drbg); +#else ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase); +#endif if(ret != 0) { mbedtls_strerror(ret, (char *)buf, sizeof(buf)); mbedtls_pk_free(&pkey); @@ -721,10 +770,19 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, mbedtls_pk_init(&pkey); pwd_len = passphrase != NULL ? strlen((const char *)passphrase) : 0; +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + ret = mbedtls_pk_parse_key(&pkey, + (unsigned char *)privatekeydata_nullterm, + privatekeydata_len + 1, + (const unsigned char *)passphrase, pwd_len, + mbedtls_ctr_drbg_random, + &_libssh2_mbedtls_ctr_drbg); +#else ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)privatekeydata_nullterm, privatekeydata_len + 1, (const unsigned char *)passphrase, pwd_len); +#endif _libssh2_mbedtls_safe_free(privatekeydata_nullterm, privatekeydata_len); if(ret != 0) { @@ -840,13 +898,13 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session, &_libssh2_mbedtls_ctr_drbg) != 0) goto failed; - plen = 2 * mbedtls_mpi_size(&(*privkey)->grp.P) + 1; + plen = 2 * mbedtls_mpi_size(&(*privkey)->MBEDTLS_PRIVATE(grp).P) + 1; *pubkey_oct = LIBSSH2_ALLOC(session, plen); if(*pubkey_oct == NULL) goto failed; - if(mbedtls_ecp_point_write_binary(&(*privkey)->grp, &(*privkey)->Q, + if(mbedtls_ecp_point_write_binary(&(*privkey)->MBEDTLS_PRIVATE(grp), &(*privkey)->MBEDTLS_PRIVATE(Q), MBEDTLS_ECP_PF_UNCOMPRESSED, pubkey_oct_len, *pubkey_oct, plen) == 0) return 0; @@ -879,13 +937,13 @@ _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ctx, mbedtls_ecdsa_init(*ctx); - if(mbedtls_ecp_group_load(&(*ctx)->grp, (mbedtls_ecp_group_id)curve) != 0) + if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), (mbedtls_ecp_group_id)curve) != 0) goto failed; - if(mbedtls_ecp_point_read_binary(&(*ctx)->grp, &(*ctx)->Q, k, k_len) != 0) + if(mbedtls_ecp_point_read_binary(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q), k, k_len) != 0) goto failed; - if(mbedtls_ecp_check_pubkey(&(*ctx)->grp, &(*ctx)->Q) == 0) + if(mbedtls_ecp_check_pubkey(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q)) == 0) return 0; failed: @@ -916,21 +974,21 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, mbedtls_ecp_point_init(&pubkey); - if(mbedtls_ecp_point_read_binary(&privkey->grp, &pubkey, + if(mbedtls_ecp_point_read_binary(&privkey->MBEDTLS_PRIVATE(grp), &pubkey, server_pubkey, server_pubkey_len) != 0) { rc = -1; goto cleanup; } - if(mbedtls_ecdh_compute_shared(&privkey->grp, *k, - &pubkey, &privkey->d, + if(mbedtls_ecdh_compute_shared(&privkey->MBEDTLS_PRIVATE(grp), *k, + &pubkey, &privkey->MBEDTLS_PRIVATE(d), mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg) != 0) { rc = -1; goto cleanup; } - if(mbedtls_ecp_check_privkey(&privkey->grp, *k) != 0) + if(mbedtls_ecp_check_privkey(&privkey->MBEDTLS_PRIVATE(grp), *k) != 0) rc = -1; cleanup: @@ -940,16 +998,16 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, return rc; } -#define LIBSSH2_MBEDTLS_ECDSA_VERIFY(digest_type) \ -{ \ - unsigned char hsh[SHA##digest_type##_DIGEST_LENGTH]; \ - \ - if(libssh2_sha##digest_type(m, m_len, hsh) == 0) { \ - rc = mbedtls_ecdsa_verify(&ctx->grp, hsh, \ - SHA##digest_type##_DIGEST_LENGTH, \ - &ctx->Q, &pr, &ps); \ - } \ - \ +#define LIBSSH2_MBEDTLS_ECDSA_VERIFY(digest_type) \ +{ \ + unsigned char hsh[SHA##digest_type##_DIGEST_LENGTH]; \ + \ + if(libssh2_sha##digest_type(m, m_len, hsh) == 0) { \ + rc = mbedtls_ecdsa_verify(&ctx->MBEDTLS_PRIVATE(grp), hsh, \ + SHA##digest_type##_DIGEST_LENGTH, \ + &ctx->MBEDTLS_PRIVATE(Q), &pr, &ps); \ + } \ + \ } /* _libssh2_ecdsa_sign @@ -1010,8 +1068,16 @@ _libssh2_mbedtls_parse_eckey(libssh2_ecdsa_ctx **ctx, pwd_len = pwd ? strlen((const char *) pwd) : 0; +#if MBEDTLS_VERSION_NUMBER >= 0x03000000 + if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len, + mbedtls_ctr_drbg_random, + &_libssh2_mbedtls_ctr_drbg) != 0) + + goto failed; +#else if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len) != 0) goto failed; +#endif if(mbedtls_pk_get_type(pkey) != MBEDTLS_PK_ECKEY) goto failed; @@ -1075,19 +1141,19 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx, mbedtls_ecdsa_init(*ctx); - if(mbedtls_ecp_group_load(&(*ctx)->grp, (mbedtls_ecp_group_id)type) != 0) + if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), (mbedtls_ecp_group_id)type) != 0) goto failed; - if(mbedtls_mpi_read_binary(&(*ctx)->d, exponent, exponentlen) != 0) + if(mbedtls_mpi_read_binary(&(*ctx)->MBEDTLS_PRIVATE(d), exponent, exponentlen) != 0) goto failed; - if(mbedtls_ecp_mul(&(*ctx)->grp, &(*ctx)->Q, - &(*ctx)->d, &(*ctx)->grp.G, + if(mbedtls_ecp_mul(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q), + &(*ctx)->MBEDTLS_PRIVATE(d), &(*ctx)->MBEDTLS_PRIVATE(grp).G, mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg) != 0) goto failed; - if(mbedtls_ecp_check_privkey(&(*ctx)->grp, &(*ctx)->d) == 0) + if(mbedtls_ecp_check_privkey(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(d)) == 0) goto cleanup; failed: @@ -1231,7 +1297,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, mbedtls_mpi_init(&pr); mbedtls_mpi_init(&ps); - if(mbedtls_ecdsa_sign(&ctx->grp, &pr, &ps, &ctx->d, + if(mbedtls_ecdsa_sign(&ctx->MBEDTLS_PRIVATE(grp), &pr, &ps, &ctx->MBEDTLS_PRIVATE(d), hash, hash_len, mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg) != 0) @@ -1278,7 +1344,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, libssh2_curve_type _libssh2_mbedtls_ecdsa_get_curve_type(libssh2_ecdsa_ctx *ctx) { - return (libssh2_curve_type) ctx->grp.id; + return (libssh2_curve_type) ctx->MBEDTLS_PRIVATE(grp).id; } /* _libssh2_ecdsa_curve_type_from_name diff --git a/src/mbedtls.h b/src/mbedtls.h index 891f07dab2..d1be96ca23 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -65,8 +65,16 @@ #define LIBSSH2_AES 1 #define LIBSSH2_AES_CTR 1 -#define LIBSSH2_BLOWFISH 1 +#ifdef MBEDTLS_CIPHER_BLOWFISH_CBC +# define LIBSSH2_BLOWFISH 1 +#else +# define LIBSSH2_BLOWFISH 0 +#endif +#ifdef MBEDTLS_CIPHER_ARC4_128 #define LIBSSH2_RC4 1 +#else +#define LIBSSH2_RC4 0 +#endif #define LIBSSH2_CAST 0 #define LIBSSH2_3DES 1 @@ -88,6 +96,12 @@ #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) +#if MBEDTLS_VERSION_NUMBER < 0x03000000 +#define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) +#define mbedtls_cipher_info_get_iv_size(c) (c->iv_size) +#define mbedtls_rsa_get_len(rsa) (rsa->len) +#define MBEDTLS_PRIVATE(m) m +#endif /*******************************************************************/ /* @@ -363,7 +377,9 @@ typedef enum { #define _libssh2_cipher_aes256 MBEDTLS_CIPHER_AES_256_CBC #define _libssh2_cipher_aes192 MBEDTLS_CIPHER_AES_192_CBC #define _libssh2_cipher_aes128 MBEDTLS_CIPHER_AES_128_CBC +#if LIBSSH2_BLOWFISH #define _libssh2_cipher_blowfish MBEDTLS_CIPHER_BLOWFISH_CBC +#endif #define _libssh2_cipher_arcfour MBEDTLS_CIPHER_ARC4_128 #define _libssh2_cipher_cast5 MBEDTLS_CIPHER_NULL #define _libssh2_cipher_3des MBEDTLS_CIPHER_DES_EDE3_CBC From c51a78657f3f9d7fde3ce1db2d6f7f370b21478c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 01:10:25 +0000 Subject: [PATCH 070/424] temporarily silence checksrc --- src/mbedtls.c | 5 +++++ src/mbedtls.h | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mbedtls.c b/src/mbedtls.c index 61fa3436f7..dde792212d 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -39,6 +39,11 @@ #ifdef LIBSSH2_MBEDTLS /* compile only if we build with mbedtls */ +#if MBEDTLS_VERSION_NUMBER < 0x03000000 +/* !checksrc! disable LONGLINE 1 */ +#define MBEDTLS_PRIVATE(m) m +#endif + /*******************************************************************/ /* * mbedTLS backend: Global context handles diff --git a/src/mbedtls.h b/src/mbedtls.h index d1be96ca23..604efbb8cb 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -100,7 +100,6 @@ #define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) #define mbedtls_cipher_info_get_iv_size(c) (c->iv_size) #define mbedtls_rsa_get_len(rsa) (rsa->len) -#define MBEDTLS_PRIVATE(m) m #endif /*******************************************************************/ From f0583d5608d4fcca4d573892caf95f50902dd431 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 01:11:42 +0000 Subject: [PATCH 071/424] cleanup --- src/mbedtls.c | 4 ++++ src/mbedtls.h | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/mbedtls.c b/src/mbedtls.c index dde792212d..c84e28a20d 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -40,6 +40,10 @@ #ifdef LIBSSH2_MBEDTLS /* compile only if we build with mbedtls */ #if MBEDTLS_VERSION_NUMBER < 0x03000000 +#define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) +#define mbedtls_cipher_info_get_iv_size(c) (c->iv_size) +#define mbedtls_rsa_get_len(rsa) (rsa->len) + /* !checksrc! disable LONGLINE 1 */ #define MBEDTLS_PRIVATE(m) m #endif diff --git a/src/mbedtls.h b/src/mbedtls.h index 604efbb8cb..5f2c24cd00 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -96,11 +96,6 @@ #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) -#if MBEDTLS_VERSION_NUMBER < 0x03000000 -#define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) -#define mbedtls_cipher_info_get_iv_size(c) (c->iv_size) -#define mbedtls_rsa_get_len(rsa) (rsa->len) -#endif /*******************************************************************/ /* From 5387c506b4a6e5fecadf5f543a71d9a7e1ee43d7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 01:24:13 +0000 Subject: [PATCH 072/424] fold long lines --- src/mbedtls.c | 59 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/mbedtls.c b/src/mbedtls.c index c84e28a20d..c924fce3ad 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -44,7 +44,6 @@ #define mbedtls_cipher_info_get_iv_size(c) (c->iv_size) #define mbedtls_rsa_get_len(rsa) (rsa->len) -/* !checksrc! disable LONGLINE 1 */ #define MBEDTLS_PRIVATE(m) m #endif @@ -354,23 +353,32 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, return -1; /* !checksrc! disable ASSIGNWITHINCONDITION 1 */ - if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(E)), edata, elen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(N)), ndata, nlen) ) != 0) { + if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(E)), + edata, elen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(N)), + ndata, nlen) ) != 0) { ret = -1; } if(!ret) { - ctx->MBEDTLS_PRIVATE(len) = mbedtls_mpi_size(&(ctx->MBEDTLS_PRIVATE(N))); + ctx->MBEDTLS_PRIVATE(len) = + mbedtls_mpi_size(&(ctx->MBEDTLS_PRIVATE(N))); } if(!ret && ddata) { /* !checksrc! disable ASSIGNWITHINCONDITION 1 */ - if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(D)), ddata, dlen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(P)), pdata, plen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(Q)), qdata, qlen) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DP)), e1data, e1len) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DQ)), e2data, e2len) ) != 0 || - (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(QP)), coeffdata, coefflen) ) + if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(D)), + ddata, dlen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(P)), + pdata, plen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(Q)), + qdata, qlen) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DP)), + e1data, e1len) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DQ)), + e2data, e2len) ) != 0 || + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(QP)), + coeffdata, coefflen) ) != 0) { ret = -1; } @@ -913,7 +921,8 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session, if(*pubkey_oct == NULL) goto failed; - if(mbedtls_ecp_point_write_binary(&(*privkey)->MBEDTLS_PRIVATE(grp), &(*privkey)->MBEDTLS_PRIVATE(Q), + if(mbedtls_ecp_point_write_binary(&(*privkey)->MBEDTLS_PRIVATE(grp), + &(*privkey)->MBEDTLS_PRIVATE(Q), MBEDTLS_ECP_PF_UNCOMPRESSED, pubkey_oct_len, *pubkey_oct, plen) == 0) return 0; @@ -946,13 +955,17 @@ _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ctx, mbedtls_ecdsa_init(*ctx); - if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), (mbedtls_ecp_group_id)curve) != 0) + if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), + (mbedtls_ecp_group_id)curve) != 0) goto failed; - if(mbedtls_ecp_point_read_binary(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q), k, k_len) != 0) + if(mbedtls_ecp_point_read_binary(&(*ctx)->MBEDTLS_PRIVATE(grp), + &(*ctx)->MBEDTLS_PRIVATE(Q), + k, k_len) != 0) goto failed; - if(mbedtls_ecp_check_pubkey(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q)) == 0) + if(mbedtls_ecp_check_pubkey(&(*ctx)->MBEDTLS_PRIVATE(grp), + &(*ctx)->MBEDTLS_PRIVATE(Q)) == 0) return 0; failed: @@ -1150,19 +1163,24 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx, mbedtls_ecdsa_init(*ctx); - if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), (mbedtls_ecp_group_id)type) != 0) + if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), + (mbedtls_ecp_group_id)type) != 0) goto failed; - if(mbedtls_mpi_read_binary(&(*ctx)->MBEDTLS_PRIVATE(d), exponent, exponentlen) != 0) + if(mbedtls_mpi_read_binary(&(*ctx)->MBEDTLS_PRIVATE(d), + exponent, exponentlen) != 0) goto failed; - if(mbedtls_ecp_mul(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q), - &(*ctx)->MBEDTLS_PRIVATE(d), &(*ctx)->MBEDTLS_PRIVATE(grp).G, + if(mbedtls_ecp_mul(&(*ctx)->MBEDTLS_PRIVATE(grp), + &(*ctx)->MBEDTLS_PRIVATE(Q), + &(*ctx)->MBEDTLS_PRIVATE(d), + &(*ctx)->MBEDTLS_PRIVATE(grp).G, mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg) != 0) goto failed; - if(mbedtls_ecp_check_privkey(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(d)) == 0) + if(mbedtls_ecp_check_privkey(&(*ctx)->MBEDTLS_PRIVATE(grp), + &(*ctx)->MBEDTLS_PRIVATE(d)) == 0) goto cleanup; failed: @@ -1306,7 +1324,8 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, mbedtls_mpi_init(&pr); mbedtls_mpi_init(&ps); - if(mbedtls_ecdsa_sign(&ctx->MBEDTLS_PRIVATE(grp), &pr, &ps, &ctx->MBEDTLS_PRIVATE(d), + if(mbedtls_ecdsa_sign(&ctx->MBEDTLS_PRIVATE(grp), &pr, &ps, + &ctx->MBEDTLS_PRIVATE(d), hash, hash_len, mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg) != 0) From 942b94a93782e628b7a257adcbcbb518b7ef1b05 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 01:27:24 +0000 Subject: [PATCH 073/424] formatting --- src/mbedtls.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mbedtls.c b/src/mbedtls.c index c924fce3ad..aba2d51225 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -996,14 +996,16 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, mbedtls_ecp_point_init(&pubkey); - if(mbedtls_ecp_point_read_binary(&privkey->MBEDTLS_PRIVATE(grp), &pubkey, + if(mbedtls_ecp_point_read_binary(&privkey->MBEDTLS_PRIVATE(grp), + &pubkey, server_pubkey, server_pubkey_len) != 0) { rc = -1; goto cleanup; } if(mbedtls_ecdh_compute_shared(&privkey->MBEDTLS_PRIVATE(grp), *k, - &pubkey, &privkey->MBEDTLS_PRIVATE(d), + &pubkey, + &privkey->MBEDTLS_PRIVATE(d), mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg) != 0) { rc = -1; From d46091b22e5f9b2c9860e954e5c7debccdb46e0a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 08:41:51 +0000 Subject: [PATCH 074/424] indent --- src/mbedtls.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mbedtls.h b/src/mbedtls.h index 5f2c24cd00..00973c6e53 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -71,9 +71,9 @@ # define LIBSSH2_BLOWFISH 0 #endif #ifdef MBEDTLS_CIPHER_ARC4_128 -#define LIBSSH2_RC4 1 +# define LIBSSH2_RC4 1 #else -#define LIBSSH2_RC4 0 +# define LIBSSH2_RC4 0 #endif #define LIBSSH2_CAST 0 #define LIBSSH2_3DES 1 From f1d60b1fb39b62abd7751df30c6dcd691918468e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 08:48:40 +0000 Subject: [PATCH 075/424] more feature guard cleanup --- src/mbedtls.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mbedtls.h b/src/mbedtls.h index 00973c6e53..ef25ab9f3a 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -371,10 +371,12 @@ typedef enum { #define _libssh2_cipher_aes256 MBEDTLS_CIPHER_AES_256_CBC #define _libssh2_cipher_aes192 MBEDTLS_CIPHER_AES_192_CBC #define _libssh2_cipher_aes128 MBEDTLS_CIPHER_AES_128_CBC -#if LIBSSH2_BLOWFISH +#ifdef MBEDTLS_CIPHER_BLOWFISH_CBC #define _libssh2_cipher_blowfish MBEDTLS_CIPHER_BLOWFISH_CBC #endif +#ifdef MBEDTLS_CIPHER_ARC4_128 #define _libssh2_cipher_arcfour MBEDTLS_CIPHER_ARC4_128 +#endif #define _libssh2_cipher_cast5 MBEDTLS_CIPHER_NULL #define _libssh2_cipher_3des MBEDTLS_CIPHER_DES_EDE3_CBC From b542466c7221eb35b23e3b0b8849cbfbda49a4f3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Oct 2022 08:50:32 +0000 Subject: [PATCH 076/424] delete cast5 - null-cipher mapping --- src/mbedtls.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mbedtls.h b/src/mbedtls.h index ef25ab9f3a..27b8c4f556 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -377,7 +377,6 @@ typedef enum { #ifdef MBEDTLS_CIPHER_ARC4_128 #define _libssh2_cipher_arcfour MBEDTLS_CIPHER_ARC4_128 #endif -#define _libssh2_cipher_cast5 MBEDTLS_CIPHER_NULL #define _libssh2_cipher_3des MBEDTLS_CIPHER_DES_EDE3_CBC From ca818c513436728b1fac26e6cfabf9060eba7a4d Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Mon, 24 Oct 2022 20:46:19 +0200 Subject: [PATCH 077/424] CI: fix AppVeyor status failing for starting jobs --- .github/workflows/appveyor_status.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/appveyor_status.yml b/.github/workflows/appveyor_status.yml index a36b43c10c..cd17a2974c 100644 --- a/.github/workflows/appveyor_status.yml +++ b/.github/workflows/appveyor_status.yml @@ -51,9 +51,10 @@ jobs: jq -c '.build.jobs[] | {target_url: ($target_url + "/job/" + .jobId), context: (.name | sub("^(Environment: )?"; "AppVeyor / ")), state: (.status | sub("queued"; "pending") + | sub("starting"; "pending") | sub("running"; "pending") | sub("failed"; "failure") | sub("cancelled"; "error")), description: .status}' \ - --arg target_url ${APPVEYOR_TARGET_URL} | parallel --pipe -j 1 -N 1 \ + --arg target_url ${APPVEYOR_TARGET_URL} | tee /dev/stderr | parallel --pipe -j 1 -N 1 \ gh api --silent --input - repos/${APPVEYOR_REPOSITORY}/statuses/${APPVEYOR_COMMIT_SHA} From 0ba6e74bec99c67c358f9fdb461c37c368479e06 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Wed, 26 Oct 2022 16:48:52 -0700 Subject: [PATCH 078/424] Fix regression with rsa_sha2_verify #758 (#763) Fixes comparison with the result value coming from `mbedtls_rsa_pkcs1_verify`. Success is 0, not 1. --- src/mbedtls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbedtls.c b/src/mbedtls.c index aba2d51225..6326981dfc 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -541,7 +541,7 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, #endif free(hash); - return (ret == 1) ? 0 : -1; + return (ret == 0) ? 0 : -1; } int From 0986fee58b002cd25bde682945b8cf692fcb6fbe Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Wed, 2 Nov 2022 09:28:45 -0700 Subject: [PATCH 079/424] Revert usage of EVP_CipherUpdate #764 #739 (#765) Revert usage of EVP_CipherUpdate from wolfSSL PR to fix #764 #739. --- src/openssl.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/openssl.c b/src/openssl.c index ef56e938c1..8e75833e59 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -473,20 +473,28 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, { unsigned char buf[EVP_MAX_BLOCK_LENGTH]; int ret; - int outlen; + int rc = 1; (void) algo; (void) encrypt; #ifdef HAVE_OPAQUE_STRUCTS - ret = EVP_CipherUpdate(*ctx, buf, &outlen, block, blocksize); + ret = EVP_Cipher(*ctx, buf, block, blocksize); #else - ret = EVP_CipherUpdate(ctx, buf, &outlen, block, blocksize); + ret = EVP_Cipher(ctx, buf, block, blocksize); #endif - if(ret == 1) { + +#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || \ + defined(LIBSSH2_WOLFSSL) + if(ret != -1) +#else + if(ret == 1) +#endif + { + rc = 0; memcpy(block, buf, blocksize); } - return ret == 1 ? 0 : 1; + return rc; } #if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR) From 5c3e53f0eea017851c27c3bf5199a0a948e1c13b Mon Sep 17 00:00:00 2001 From: Zenju Date: Tue, 8 Nov 2022 22:55:34 +0100 Subject: [PATCH 080/424] Fixed error handling of _libssh2_packet_requirev callers (#767) Notes: some callers of _libssh2_packet_requirev() fail to set _libssh2_error(). This creates the situation where e.g. libssh2_session_handshake() fails, but libssh2_session_last_error() confusingly returns LIBSSH2_ERROR_NONE. Credit: Zenju --- src/channel.c | 4 +++- src/session.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/channel.c b/src/channel.c index 86b6d2a647..e57ddf94f9 100644 --- a/src/channel.c +++ b/src/channel.c @@ -877,7 +877,9 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, } if(rc) { channel->setenv_state = libssh2_NB_state_idle; - return rc; + return _libssh2_error(session, rc, + "Failed getting response for " + "channel-setenv"); } else if(data_len < 1) { channel->setenv_state = libssh2_NB_state_idle; diff --git a/src/session.c b/src/session.c index ae6132c27b..3549152736 100644 --- a/src/session.c +++ b/src/session.c @@ -780,7 +780,9 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) &session->startup_data_len, 0, NULL, 0, &session->startup_req_state); if(rc) - return rc; + return _libssh2_error(session, rc, + "Failed to get response to " + "ssh-userauth request"); if(session->startup_data_len < 5) { return _libssh2_error(session, LIBSSH2_ERROR_PROTO, From 821d50dad313b53fb2782f26aec1f52f1be34fc0 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 9 Nov 2022 15:56:22 -0800 Subject: [PATCH 081/424] Skip leading \r and \n characters in banner_receive() (#769) Fixes #768 Credit: Michael Buckley --- src/session.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/session.c b/src/session.c index 3549152736..235ab95b9d 100644 --- a/src/session.c +++ b/src/session.c @@ -147,6 +147,10 @@ banner_receive(LIBSSH2_SESSION * session) return LIBSSH2_ERROR_SOCKET_DISCONNECT; } + if((c == '\r' || c == '\n') && banner_len == 0) { + continue; + } + if(c == '\0') { /* NULLs are not allowed in SSH banners */ session->banner_TxRx_state = libssh2_NB_state_idle; From f6694beb21518491fe9d02c56ae14a0319d79a8d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 12 Nov 2022 12:40:40 +0100 Subject: [PATCH 082/424] tests: add option to run tests without docker (#762) via `export OPENSSH_NO_DOCKER=1`. SSH server host can be set via: `export OPENSSH_SERVER_HOST=127.0.0.1` SSH server port via existing: `export OPENSSH_SERVER_PORT=4711` This requires more work to be usable out of the box. The necessery sshd config is (partly) embedded into `tests/openssh_server/Dockerfile`. After this patch, it is possible to run tests in envs where docker is not installed or not available, by running a preconfigured, non-containerized sshd. --- tests/openssh_fixture.c | 109 +++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 36 deletions(-) diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 872058f865..d4f7fd5424 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -59,6 +59,8 @@ #include #include +static int have_docker = 0; + static int run_command_varg(char **output, const char *command, va_list args) { FILE *pipe; @@ -150,22 +152,27 @@ static const char *openssh_server_image(void) static int build_openssh_server_docker_image(void) { - const char *container_image_name = openssh_server_image(); - if(container_image_name != NULL) { - int ret = run_command(NULL, "docker pull --quiet %s", - container_image_name); - if(ret == 0) { - ret = run_command(NULL, "docker tag %s libssh2/openssh_server", - container_image_name); + if(have_docker) { + const char *container_image_name = openssh_server_image(); + if(container_image_name != NULL) { + int ret = run_command(NULL, "docker pull --quiet %s", + container_image_name); if(ret == 0) { - return ret; + ret = run_command(NULL, "docker tag %s libssh2/openssh_server", + container_image_name); + if(ret == 0) { + return ret; + } } } - } - return run_command(NULL, "docker build --quiet " - "-t libssh2/openssh_server " - "openssh_server"); + return run_command(NULL, "docker build --quiet " + "-t libssh2/openssh_server " + "openssh_server"); + } + else { + return 0; + } } static const char *openssh_server_port(void) @@ -175,22 +182,33 @@ static const char *openssh_server_port(void) static int start_openssh_server(char **container_id_out) { - const char *container_host_port = openssh_server_port(); - if(container_host_port != NULL) { + if(have_docker) { + const char *container_host_port = openssh_server_port(); + if(container_host_port != NULL) { + return run_command(container_id_out, + "docker run --rm -d -p %s:22 " + "libssh2/openssh_server", + container_host_port); + } + return run_command(container_id_out, - "docker run --rm -d -p %s:22 " - "libssh2/openssh_server", - container_host_port); + "docker run --rm -d -p 22 " + "libssh2/openssh_server"); + } + else { + *container_id_out = strdup(""); + return 0; } - - return run_command(container_id_out, - "docker run --rm -d -p 22 " - "libssh2/openssh_server"); } static int stop_openssh_server(char *container_id) { - return run_command(NULL, "docker stop %s", container_id); + if(have_docker) { + return run_command(NULL, "docker stop %s", container_id); + } + else { + return 0; + } } static const char *docker_machine_name(void) @@ -307,20 +325,37 @@ static int open_socket_to_container(char *container_id) int sock; struct sockaddr_in sin; int counter = 0; + int ret; - int ret = ip_address_from_container(container_id, &ip_address); - if(ret != 0) { - fprintf(stderr, "Failed to get IP address for container %s\n", - container_id); - ret = -1; - goto cleanup; - } + if(have_docker) { + ret = ip_address_from_container(container_id, &ip_address); + if(ret != 0) { + fprintf(stderr, "Failed to get IP address for container %s\n", + container_id); + ret = -1; + goto cleanup; + } - ret = port_from_container(container_id, &port_string); - if(ret != 0) { - fprintf(stderr, "Failed to get port for container %s\n", - container_id); - ret = -1; + ret = port_from_container(container_id, &port_string); + if(ret != 0) { + fprintf(stderr, "Failed to get port for container %s\n", + container_id); + ret = -1; + } + } + else { + const char *env; + env = getenv("OPENSSH_SERVER_HOST"); + if(!env) { + env = "127.0.0.1"; + } + ip_address = strdup(env); + env = openssh_server_port(); + if(!env) { + env = "4711"; + } + port_string = strdup(env); + ret = 0; } /* 0.0.0.0 is returned by Docker for Windows, because the container @@ -391,6 +426,8 @@ int start_openssh_fixture() } #endif + have_docker = (getenv("OPENSSH_NO_DOCKER") == NULL); + ret = build_openssh_server_docker_image(); if(ret == 0) { return start_openssh_server(&running_container_id); @@ -408,7 +445,7 @@ void stop_openssh_fixture() free(running_container_id); running_container_id = NULL; } - else { + else if(have_docker) { fprintf(stderr, "Cannot stop container - none started"); } } @@ -416,4 +453,4 @@ void stop_openssh_fixture() int open_socket_to_openssh_server() { return open_socket_to_container(running_container_id); -} \ No newline at end of file +} From 9f8e69cca0b94266c174ae13a860a02c762a3f4a Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 5 Dec 2022 17:09:55 -0800 Subject: [PATCH 083/424] configure.ac: check for sys/param.h This file is required by glibc for the test suite. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6fb7cc8260..3e2d02f3ba 100644 --- a/configure.ac +++ b/configure.ac @@ -310,7 +310,7 @@ AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"]) # Checks for header files. # AC_HEADER_STDC -AC_CHECK_HEADERS([errno.h fcntl.h stdio.h stdlib.h unistd.h sys/uio.h]) +AC_CHECK_HEADERS([errno.h fcntl.h stdio.h stdlib.h unistd.h sys/param.h sys/uio.h]) AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) AC_CHECK_HEADERS([sys/un.h], [have_sys_un_h=yes], [have_sys_un_h=no]) From 2e2812dde8c1fc9b48eca592823770ab2e601f7a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 13 Dec 2022 22:11:13 +0100 Subject: [PATCH 084/424] openssl.h: enable ed25519 for LibreSSL 3.7.0 (#778) This brings LibreSSL libssh2 builds on par with OpenSSL. --- src/openssl.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/openssl.h b/src/openssl.h index 60c0c2c340..cc5c40d4d3 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -122,8 +122,9 @@ # define LIBSSH2_ECDSA 1 #endif -#if OPENSSL_VERSION_NUMBER >= 0x10101000L && \ -!defined(LIBRESSL_VERSION_NUMBER) +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && \ + !defined(LIBRESSL_VERSION_NUMBER)) || \ + LIBRESSL_VERSION_NUMBER >= 0x3070000fL # define LIBSSH2_ED25519 1 #else # define LIBSSH2_ED25519 0 From d4062feb3d35ac69d1c94523ab8edf2a4e42fabd Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 8 Dec 2022 18:06:46 -0800 Subject: [PATCH 085/424] Improve example/ssh2 to allow unmodified use of public key auth The previous hard-coded key file paths were not valid for normal users. Make the paths relative to the user's home directory instead so they can work out of the box. Add a banner showing what connection will be attempted to make it easier for the user to see what is being attempted. Enable trace debugging since this is designed as a test program. --- example/ssh2.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/example/ssh2.c b/example/ssh2.c index fa86f55139..efb245fe4d 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -4,7 +4,10 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "ssh2 host user password [-p|-i|-k]" + * Usage: ssh2 hostip user password [-p|-i|-k] + * -p authenticate using password + * -i authenticate using keyboard-interactive + * -k authenticate using public key (password argument decrypts keyfile) */ #include "libssh2_config.h" @@ -30,15 +33,19 @@ #include #endif +#include #include #include #include #include #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#define snprintf _snprintf +#endif -const char *keyfile1 = "~/.ssh/id_rsa.pub"; -const char *keyfile2 = "~/.ssh/id_rsa"; +const char *keyfile1 = ".ssh/id_rsa.pub"; +const char *keyfile2 = ".ssh/id_rsa"; const char *username = "username"; const char *password = "password"; @@ -112,6 +119,10 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; + + fprintf(stderr, "Connecting to %s as user %s\n", + inet_ntoa(sin.sin_addr), username); + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { fprintf(stderr, "failed to connect!\n"); @@ -190,14 +201,37 @@ int main(int argc, char *argv[]) } else if(auth_pw & 4) { /* Or by public key */ - if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, - keyfile2, password)) { + size_t fn1sz, fn2sz; + char *fn1, *fn2; + char const *h = getenv("HOME"); + if(!h || !*h) + h = "."; + fn1sz = strlen(h) + strlen(keyfile1) + 2; + fn2sz = strlen(h) + strlen(keyfile2) + 2; + fn1 = malloc(fn1sz); + fn2 = malloc(fn2sz); + if(!fn1 || !fn2) { + free(fn2); + free(fn1); + fprintf(stderr, "out of memory\n"); + goto shutdown; + } + /* Using asprintf() here would be much cleaner, but less portable */ + snprintf(fn1, fn1sz, "%s/%s", h, keyfile1); + snprintf(fn2, fn2sz, "%s/%s", h, keyfile2); + + if(libssh2_userauth_publickey_fromfile(session, username, fn1, + fn2, password)) { fprintf(stderr, "\tAuthentication by public key failed!\n"); + free(fn2); + free(fn1); goto shutdown; } else { fprintf(stderr, "\tAuthentication by public key succeeded.\n"); } + free(fn2); + free(fn1); } else { fprintf(stderr, "No supported authentication methods found!\n"); From 6cba487395e79775482fc80dcbc4146e3b17c773 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 8 Dec 2022 18:11:54 -0800 Subject: [PATCH 086/424] Enable trace debugging in example/ssh2 This is intended to be a test program, so debugging is likely to be useful by default. --- example/ssh2.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/example/ssh2.c b/example/ssh2.c index efb245fe4d..b8d320918e 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -133,6 +133,19 @@ int main(int argc, char *argv[]) * banners, exchange keys, and setup crypto, compression, and MAC layers */ session = libssh2_session_init(); + /* Enable all debugging when libssh2 was built with debugging enabled */ + libssh2_trace(session, + LIBSSH2_TRACE_TRANS | + LIBSSH2_TRACE_KEX | + LIBSSH2_TRACE_AUTH | + LIBSSH2_TRACE_CONN | + LIBSSH2_TRACE_SCP | + LIBSSH2_TRACE_SFTP | + LIBSSH2_TRACE_ERROR | + LIBSSH2_TRACE_PUBLICKEY | + LIBSSH2_TRACE_SOCKET + ); + if(libssh2_session_handshake(session, sock)) { fprintf(stderr, "Failure establishing SSH session\n"); return -1; From e3ce906cafbb4fe1dae49b4ed0d130a2979e9337 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 30 Dec 2022 13:54:51 -0800 Subject: [PATCH 087/424] tests: Fix gcc compile warnings These were mostly due to missing and non-ANSI prototypes. --- tests/CMakeLists.txt | 2 +- tests/Makefile.am | 1 + tests/openssh_fixture.c | 8 ++-- tests/openssh_fixture.h | 6 +-- tests/runner.c | 5 +-- tests/runner.h | 43 +++++++++++++++++++ tests/session_fixture.c | 8 ++-- tests/session_fixture.h | 4 +- tests/test_agent_forward_succeeds.c | 1 + tests/test_hostkey.c | 1 + tests/test_hostkey_hash.c | 1 + ...teractive_auth_fails_with_wrong_response.c | 1 + ...t_keyboard_interactive_auth_info_request.c | 29 +++++++------ ...tive_auth_succeeds_with_correct_response.c | 1 + ..._password_auth_fails_with_wrong_password.c | 1 + ..._password_auth_fails_with_wrong_username.c | 1 + ...d_auth_succeeds_with_correct_credentials.c | 1 + ...est_public_key_auth_fails_with_wrong_key.c | 1 + ...c_key_auth_succeeds_with_correct_dsa_key.c | 1 + ...key_auth_succeeds_with_correct_ecdsa_key.c | 1 + ...y_auth_succeeds_with_correct_ed25519_key.c | 1 + ...cceeds_with_correct_ed25519_key_from_mem.c | 1 + ...ceeds_with_correct_encrypted_ed25519_key.c | 1 + ..._succeeds_with_correct_encrypted_rsa_key.c | 1 + ...c_key_auth_succeeds_with_correct_rsa_key.c | 1 + ...th_succeeds_with_correct_rsa_openssh_key.c | 1 + ...h_succeeds_with_correct_signed_ecdsa_key.c | 1 + ...uth_succeeds_with_correct_signed_rsa_key.c | 1 + 28 files changed, 94 insertions(+), 31 deletions(-) create mode 100644 tests/runner.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f3706bcf6f..1f9764c49a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -159,7 +159,7 @@ add_library(session_fixture STATIC session_fixture.h session_fixture.c) target_link_libraries(session_fixture ${LIBRARIES} openssh_fixture libssh2) target_include_directories(session_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") -add_library(runner STATIC runner.c) +add_library(runner STATIC runner.h runner.c) target_link_libraries(runner session_fixture) target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/tests/Makefile.am b/tests/Makefile.am index 582c914153..0c01d91110 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -55,6 +55,7 @@ EXTRA_DIST = \ openssh_server/ssh_host_ed25519_key \ openssh_server/ssh_host_rsa_key \ runner.c \ + runner.h \ session_fixture.c \ session_fixture.h \ simple.c \ diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index d4f7fd5424..3a1588c236 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -216,7 +216,7 @@ static const char *docker_machine_name(void) return getenv("DOCKER_MACHINE_NAME"); } -static int is_running_inside_a_container() +static int is_running_inside_a_container(void) { #ifdef WIN32 return 0; @@ -413,7 +413,7 @@ static int open_socket_to_container(char *container_id) static char *running_container_id = NULL; -int start_openssh_fixture() +int start_openssh_fixture(void) { int ret; #ifdef HAVE_WINSOCK2_H @@ -438,7 +438,7 @@ int start_openssh_fixture() } } -void stop_openssh_fixture() +void stop_openssh_fixture(void) { if(running_container_id) { stop_openssh_server(running_container_id); @@ -450,7 +450,7 @@ void stop_openssh_fixture() } } -int open_socket_to_openssh_server() +int open_socket_to_openssh_server(void) { return open_socket_to_container(running_container_id); } diff --git a/tests/openssh_fixture.h b/tests/openssh_fixture.h index 2d2bb0adce..f8e3632ceb 100644 --- a/tests/openssh_fixture.h +++ b/tests/openssh_fixture.h @@ -38,8 +38,8 @@ #ifndef LIBSSH2_TESTS_OPENSSH_FIXTURE_H #define LIBSSH2_TESTS_OPENSSH_FIXTURE_H -int start_openssh_fixture(); -void stop_openssh_fixture(); -int open_socket_to_openssh_server(); +int start_openssh_fixture(void); +void stop_openssh_fixture(void); +int open_socket_to_openssh_server(void); #endif diff --git a/tests/runner.c b/tests/runner.c index b9f9328df7..f3522bba5a 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -36,10 +36,9 @@ */ #include "session_fixture.h" +#include "runner.h" -extern int test(LIBSSH2_SESSION *session); - -int main() +int main(void) { int exit_code = 1; LIBSSH2_SESSION *session = start_session_fixture(); diff --git a/tests/runner.h b/tests/runner.h new file mode 100644 index 0000000000..f32a7af258 --- /dev/null +++ b/tests/runner.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2016 Alexander Lamaison + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the copyright holder nor the names + * of any other contributors may be used to endorse or + * promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#ifndef LIBSSH2_TESTS_RUNNER_H +#define LIBSSH2_TESTS_RUNNER_H + +int test(LIBSSH2_SESSION *session); + +#endif diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 1f7e0f9134..18df662400 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -61,7 +61,7 @@ LIBSSH2_SESSION *connected_session = NULL; int connected_socket = -1; -static int connect_to_server() +static int connect_to_server(void) { int rc; connected_socket = open_socket_to_openssh_server(); @@ -78,7 +78,7 @@ static int connect_to_server() return 0; } -void setup_fixture_workdir() +static void setup_fixture_workdir(void) { char *wd = getenv("FIXTURE_WORKDIR"); #ifdef FIXTURE_WORKDIR @@ -99,7 +99,7 @@ void setup_fixture_workdir() chdir(wd); } -LIBSSH2_SESSION *start_session_fixture() +LIBSSH2_SESSION *start_session_fixture(void) { int rc; @@ -146,7 +146,7 @@ void print_last_session_error(const char *function) } } -void stop_session_fixture() +void stop_session_fixture(void) { if(connected_session) { libssh2_session_disconnect(connected_session, "test ended"); diff --git a/tests/session_fixture.h b/tests/session_fixture.h index d3824b7974..bbb8e596fe 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -40,8 +40,8 @@ #include -LIBSSH2_SESSION *start_session_fixture(); -void stop_session_fixture(); +LIBSSH2_SESSION *start_session_fixture(void); +void stop_session_fixture(void); void print_last_session_error(const char *function); #endif diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index daf7bd5ac1..569663b359 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index e33f68f960..80588b00c7 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_hostkey_hash.c b/tests/test_hostkey_hash.c index 112b491f2b..6f22d68fe0 100644 --- a/tests/test_hostkey_hash.c +++ b/tests/test_hostkey_hash.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include "libssh2_config.h" #include diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c index c1ab973069..f41d0ce6ac 100644 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index da6989d6bb..fc9e3d6aad 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -46,27 +46,27 @@ struct expected { int rc; int last_error_code; - char *last_error_message; + const char *last_error_message; }; struct test_case { - char *data; + const char *data; int data_len; struct expected expected; }; #define TEST_CASES_LEN 16 struct test_case test_cases[TEST_CASES_LEN] = { - /* to small */ + /* too small */ { NULL, 0, {FAIL, -38, "userauth keyboard data buffer too small to get length"}}, - /* to small */ + /* too small */ { "1234", 4, {FAIL, -38, "userauth keyboard data buffer too small to get length"}}, - /* smalest valid packet possible */ + /* smallest valid packet possible */ { "<" "\0\0\0\0" @@ -219,9 +219,8 @@ static int free_count = 0; static LIBSSH2_ALLOC_FUNC(test_alloc) { - alloc_count++; - int *threshold_int_ptr = *abstract; + alloc_count++; if (*abstract != NULL && *threshold_int_ptr == alloc_count) { return NULL; } @@ -241,12 +240,15 @@ LIBSSH2_FREE_FUNC(test_free) static int test_case(int num, - char *data, int data_len, void *abstract, + const char *data, int data_len, void *abstract, struct expected expected) { + int rc; + char *message; + int error_code; + LIBSSH2_SESSION *session = NULL; alloc_count = 0; free_count = 0; - LIBSSH2_SESSION *session = NULL; session = libssh2_session_init_ex(test_alloc, test_free, NULL, abstract); if(session == NULL) { fprintf(stderr, "libssh2_session_init_ex failed\n"); @@ -257,7 +259,7 @@ int test_case(int num, session->userauth_kybd_data_len = data_len; memcpy(session->userauth_kybd_data, data, data_len); - int rc = userauth_keyboard_interactive_decode_info_request(session); + rc = userauth_keyboard_interactive_decode_info_request(session); if(rc != expected.rc) { fprintf(stdout, @@ -266,8 +268,7 @@ int test_case(int num, return 1; } - char *message; - int error_code = libssh2_session_last_error(session, &message, NULL, 0); + error_code = libssh2_session_last_error(session, &message, NULL, 0); if(expected.last_error_code != error_code) { fprintf(stdout, @@ -291,7 +292,7 @@ int test_case(int num, return 0; } -int main() +int main(void) { int i; @@ -332,4 +333,4 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, return -1; } -#endif \ No newline at end of file +#endif diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c index 093e4a22ab..224189ae7f 100644 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_password_auth_fails_with_wrong_password.c b/tests/test_password_auth_fails_with_wrong_password.c index 2b895d08e8..d888c78ea0 100644 --- a/tests/test_password_auth_fails_with_wrong_password.c +++ b/tests/test_password_auth_fails_with_wrong_password.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_password_auth_fails_with_wrong_username.c b/tests/test_password_auth_fails_with_wrong_username.c index b78617a49c..e0630aa2ec 100644 --- a/tests/test_password_auth_fails_with_wrong_username.c +++ b/tests/test_password_auth_fails_with_wrong_username.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_password_auth_succeeds_with_correct_credentials.c b/tests/test_password_auth_succeeds_with_correct_credentials.c index 94b86b8797..48e623734b 100644 --- a/tests/test_password_auth_succeeds_with_correct_credentials.c +++ b/tests/test_password_auth_succeeds_with_correct_credentials.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c index dd2d254f5a..8b79edb685 100644 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ b/tests/test_public_key_auth_fails_with_wrong_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c index 187c1313fb..c04d7682c8 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c index 2ea3a3699a..febec6bb68 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c index c52830d94f..0ef9cf50b9 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index a79d1b5183..6553baeb7c 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c index 553023a99d..39e8cca5e3 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c index ba98ac7c4a..35cb504842 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c index 0cf2a6331d..40d9b80a86 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c index a067d729b8..22a9937f39 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c index 10b33cbb8d..398bfe381b 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c index 39130e652c..8843196fed 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -1,4 +1,5 @@ #include "session_fixture.h" +#include "runner.h" #include From 16619a8eddec35bb8582d1c334db0fc13b0817c4 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 30 Dec 2022 22:22:13 -0800 Subject: [PATCH 088/424] Add missing files to automake makefiles & build tests Many files have been added to the cmake build files but not the automake ones in recent years. Missing ones have been added so automake "make dist" will now create a usable tar ball. The integration tests using Docker are now built with automake as well (with "make check"). They are not run yet since they aren't working yet on Linux. --- Makefile.am | 4 +- Makefile.inc | 5 ++- docs/Makefile.am | 3 ++ example/Makefile.am | 2 +- tests/Makefile.am | 82 ++++++++++++++++++++++++--------------- tests/ossfuzz/Makefile.am | 2 + 6 files changed, 62 insertions(+), 36 deletions(-) diff --git a/Makefile.am b/Makefile.am index b0b58d1824..9198bfaa95 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,7 +48,8 @@ Makefile.os400qc3.inc EXTRA_DIST = $(WIN32FILES) $(NETWAREFILES) get_ver.awk \ maketgz NMakefile RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ - CMakeLists.txt cmake $(OS400FILES) + CMakeLists.txt cmake git2news.pl libssh2-style.el README.md $(OS400FILES) \ + buildconf ACLOCAL_AMFLAGS = -I m4 @@ -101,6 +102,7 @@ WIN32HEADERS = $(HHEADERS) libssh2_config.h $(DSP): win32/msvcproj.head win32/msvcproj.foot Makefile.am echo "creating $(DSP)" + -$(MKDIR_P) "`echo "$@" | sed 's@[/\\][^/\\]*$$@@'`" @( (cat $(srcdir)/win32/msvcproj.head; \ echo "# Begin Group \"Source Files\""; \ echo ""; \ diff --git a/Makefile.inc b/Makefile.inc index 99afe0f58f..651ff29ac5 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -2,7 +2,8 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ userauth_kbd_packet.c \ version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ - blowfish.c bcrypt_pbkdf.c agent_win.c + blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c os400qc3.h HHEADERS = libssh2_priv.h $(CRYPTO_HHEADERS) transport.h channel.h comp.h \ - mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h blf.h agent.h + mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h blf.h agent.h \ + userauth_kbd_packet.h diff --git a/docs/Makefile.am b/docs/Makefile.am index d9df59ca5d..30d6ef0b6b 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -41,6 +41,7 @@ dist_man_MANS = \ libssh2_channel_read_stderr.3 \ libssh2_channel_receive_window_adjust.3 \ libssh2_channel_receive_window_adjust2.3 \ + libssh2_channel_request_auth_agent.3 \ libssh2_channel_request_pty.3 \ libssh2_channel_request_pty_ex.3 \ libssh2_channel_request_pty_size.3 \ @@ -161,6 +162,7 @@ dist_man_MANS = \ libssh2_sftp_unlink.3 \ libssh2_sftp_unlink_ex.3 \ libssh2_sftp_write.3 \ + libssh2_sign_sk.3 \ libssh2_trace.3 \ libssh2_trace_sethandler.3 \ libssh2_userauth_authenticated.3 \ @@ -176,4 +178,5 @@ dist_man_MANS = \ libssh2_userauth_publickey_fromfile.3 \ libssh2_userauth_publickey_fromfile_ex.3 \ libssh2_userauth_publickey_frommemory.3 \ + libssh2_userauth_publickey_sk.3 \ libssh2_version.3 diff --git a/example/Makefile.am b/example/Makefile.am index ec542cd15f..2f91eb2b93 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign nostdinc -EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt +EXTRA_DIST = libssh2_config_cmake.h.in CMakeLists.txt # samples noinst_PROGRAMS = direct_tcpip ssh2 scp scp_nonblock scp_write \ diff --git a/tests/Makefile.am b/tests/Makefile.am index 0c01d91110..9dce308b88 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,19 +1,54 @@ SUBDIRS = ossfuzz AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include -I$(top_builddir)/src -LDADD = ../src/libssh2.la - -if SSHD -noinst_PROGRAMS = ssh2 -ssh2_SOURCES = ssh2.c -endif ctests = simple$(EXEEXT) TESTS = $(ctests) mansyntax.sh +check_PROGRAMS = $(ctests) + if SSHD TESTS += ssh2.sh +check_PROGRAMS += ssh2 endif -check_PROGRAMS = $(ctests) + +INTEGRATION_TESTS = \ + test_agent_forward_succeeds \ + test_hostkey \ + test_hostkey_hash \ + test_keyboard_interactive_auth_fails_with_wrong_response \ + test_keyboard_interactive_auth_info_request \ + test_keyboard_interactive_auth_succeeds_with_correct_response \ + test_password_auth_fails_with_wrong_password \ + test_password_auth_fails_with_wrong_username \ + test_password_auth_succeeds_with_correct_credentials \ + test_public_key_auth_fails_with_wrong_key \ + test_public_key_auth_succeeds_with_correct_dsa_key \ + test_public_key_auth_succeeds_with_correct_ecdsa_key \ + test_public_key_auth_succeeds_with_correct_ed25519_key \ + test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem \ + test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key \ + test_public_key_auth_succeeds_with_correct_encrypted_rsa_key \ + test_public_key_auth_succeeds_with_correct_rsa_key \ + test_public_key_auth_succeeds_with_correct_rsa_openssh_key \ + test_public_key_auth_succeeds_with_correct_signed_ecdsa_key \ + test_public_key_auth_succeeds_with_correct_signed_rsa_key + +# Integration tests using Docker +# Enable this once the tests are working +#TESTS += $(INTEGRATION_TESTS) +check_PROGRAMS += $(INTEGRATION_TESTS) +librunner_la_SOURCES = runner.c runner.h \ + session_fixture.c session_fixture.h \ + openssh_fixture.c openssh_fixture.h +LDADD = librunner.la +check_LTLIBRARIES = librunner.la + +# This program uses an internal libssh2 function so it needs to be statically +# linked against libssh2 +test_keyboard_interactive_auth_info_request_LDFLAGS = -static + +# This must be last in the list so it resolves symbols in previous libraries +LDADD += ../src/libssh2.la TESTS_ENVIRONMENT = SSHD=$(SSHD) EXEEXT=$(EXEEXT) TESTS_ENVIRONMENT += srcdir=$(top_srcdir)/tests builddir=$(top_builddir)/tests @@ -22,6 +57,7 @@ EXTRA_DIST = \ CMakeLists.txt \ etc/host \ etc/host.pub \ + etc/sshd_config \ etc/user \ etc/user.pub \ key_dsa \ @@ -33,6 +69,9 @@ EXTRA_DIST = \ signed_key_ecdsa \ signed_key_ecdsa.pub \ signed_key_ecdsa-cert.pub \ + signed_key_rsa \ + signed_key_rsa-cert.pub \ + signed_key_rsa.pub \ key_ed25519 \ key_ed25519.pub \ key_ed25519_encrypted \ @@ -45,38 +84,17 @@ EXTRA_DIST = \ key_rsa_openssh.pub \ libssh2_config_cmake.h.in \ mansyntax.sh \ - openssh_fixture.c \ - openssh_fixture.h \ openssh_server/Dockerfile \ openssh_server/authorized_keys \ + openssh_server/ca_rsa \ + openssh_server/ca_rsa.pub \ openssh_server/ca_ecdsa \ openssh_server/ca_ecdsa.pub \ openssh_server/ssh_host_ecdsa_key \ openssh_server/ssh_host_ed25519_key \ openssh_server/ssh_host_rsa_key \ - runner.c \ - runner.h \ - session_fixture.c \ - session_fixture.h \ simple.c \ + sshdwrap \ ssh2.c \ ssh2.sh \ - sshd_fixture.sh.in \ - test_agent_forward_succeeds.c \ - test_hostkey.c \ - test_hostkey_hash.c \ - test_keyboard_interactive_auth_fails_with_wrong_response.c \ - test_keyboard_interactive_auth_succeeds_with_correct_response.c \ - test_password_auth_fails_with_wrong_password.c \ - test_password_auth_fails_with_wrong_username.c \ - test_password_auth_succeeds_with_correct_credentials.c \ - test_public_key_auth_fails_with_wrong_key.c \ - test_public_key_auth_succeeds_with_correct_dsa_key.c \ - test_public_key_auth_succeeds_with_correct_ed25519_key.c \ - test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c \ - test_public_key_auth_succeeds_with_correct_ecdsa_key.c \ - test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c \ - test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c \ - test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c \ - test_public_key_auth_succeeds_with_correct_rsa_key.c \ - test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c + sshd_fixture.sh.in diff --git a/tests/ossfuzz/Makefile.am b/tests/ossfuzz/Makefile.am index a7e95825a9..9b621be84e 100644 --- a/tests/ossfuzz/Makefile.am +++ b/tests/ossfuzz/Makefile.am @@ -30,3 +30,5 @@ ssh2_client_fuzzer_LDFLAGS = $(AM_LDFLAGS) -static libstandaloneengine_a_SOURCES = standaloneengine.cc libstandaloneengine_a_CXXFLAGS = $(AM_CXXFLAGS) + +EXTRA_DIST = ossfuzz.sh From 1e1a74eb7e97b004ccad86a32c1874eb0d986d6f Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 6 Jan 2023 13:48:37 -0800 Subject: [PATCH 089/424] transport.c: Add some comments --- src/transport.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/transport.c b/src/transport.c index 17af3e4da1..04ced8f747 100644 --- a/src/transport.c +++ b/src/transport.c @@ -122,7 +122,8 @@ debugdump(LIBSSH2_SESSION * session, #endif -/* decrypt() decrypts 'len' bytes from 'source' to 'dest'. +/* decrypt() decrypts 'len' bytes from 'source' to 'dest' in units of + * blocksize. * * returns 0 on success and negative on failure */ @@ -274,13 +275,17 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) { int rc; struct transportpacket *p = &session->packet; - int remainbuf; - int remainpack; - int numbytes; - int numdecrypt; - unsigned char block[MAX_BLOCKSIZE]; - int blocksize; - int encrypted = 1; + int remainpack; /* how much there is left to add to the current payload + package */ + int remainbuf; /* how much data there is remaining in the buffer to deal + with before we should read more from the network */ + int numbytes; /* how much data to deal with from the buffer on this + iteration through the loop */ + int numdecrypt; /* number of bytes to decrypt this iteration */ + unsigned char block[MAX_BLOCKSIZE]; /* working block buffer */ + int blocksize; /* minimum number of bytes we need before we can + use them */ + int encrypted = 1; /* whether the packet is encrypted or not */ /* default clear the bit */ session->socket_block_directions &= ~LIBSSH2_SESSION_BLOCK_INBOUND; @@ -400,7 +405,9 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) numbytes = remainbuf; if(!p->total_num) { - size_t total_num; + size_t total_num; /* the number of bytes following the initial + (5 bytes) packet length and padding length + fields */ /* No payload package area allocated yet. To know the size of this payload, we need to decrypt the first From 879a2e4bf6cae37ac8c8cf40544c42f0b34d8069 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 6 Jan 2023 14:12:39 -0800 Subject: [PATCH 090/424] CI: update uses: dependencies to the latest versions We were seeing some deprecation warning messages on some of the older ones. --- .github/workflows/ci.yml | 4 ++-- .github/workflows/cifuzz.yml | 2 +- .github/workflows/openssh_server.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8064dd4ee..e4c21f8574 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: name: style-check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Check Style run: ./ci/checksrc.sh @@ -47,7 +47,7 @@ jobs: BUILD_SHARED_LIBS: ${{ matrix.build_shared_libs }} ENABLE_ZLIB_COMPRESSION: ${{ matrix.enable_zlib_compression }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install 32 Bit Dependencies if: ${{ matrix.address_size == 32 }} run: | diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index 13e80ea319..636b0c5426 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -19,7 +19,7 @@ jobs: dry-run: false language: c - name: Upload Crash - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 if: failure() && steps.build.outcome == 'success' with: name: artifacts diff --git a/.github/workflows/openssh_server.yml b/.github/workflows/openssh_server.yml index f4e0aebf0d..ea9529b042 100644 --- a/.github/workflows/openssh_server.yml +++ b/.github/workflows/openssh_server.yml @@ -32,13 +32,13 @@ jobs: build-and-push: runs-on: ubuntu-latest steps: - - uses: docker/login-action@v1 + - uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - shell: bash id: hash @@ -49,7 +49,7 @@ jobs: run: docker manifest inspect ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server:${{ steps.hash.outputs.hash }} continue-on-error: true - - uses: docker/metadata-action@v3 + - uses: docker/metadata-action@v4 id: meta with: images: ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server @@ -57,7 +57,7 @@ jobs: type=raw,value=${{ steps.hash.outputs.hash }} if: ${{ steps.poll.outcome == 'failure' }} - - uses: docker/build-push-action@v2 + - uses: docker/build-push-action@v3 with: context: ./tests/openssh_server push: true From eefc06f2efc541099e3c843283516a575dbfea03 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 7 Feb 2023 16:58:34 -0800 Subject: [PATCH 091/424] Reorder AES crypt methods so stronger ones are first This make it more likely that a stronger one will be negotiated rather than a weaker variant. --- src/crypt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/crypt.c b/src/crypt.c index 8d493b4847..b7d9e6c65b 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -310,11 +310,13 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_3des_cbc = { }; #endif +/* These are the crypt methods that are available to be negotiated. Methods + towards the start are chosen in preference to ones further down the list. */ static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = { #if LIBSSH2_AES_CTR - &libssh2_crypt_method_aes128_ctr, - &libssh2_crypt_method_aes192_ctr, &libssh2_crypt_method_aes256_ctr, + &libssh2_crypt_method_aes192_ctr, + &libssh2_crypt_method_aes128_ctr, #endif /* LIBSSH2_AES */ #if LIBSSH2_AES &libssh2_crypt_method_aes256_cbc, From af1e591eeec4fbb47e1e050a562d5d5237d3c563 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Tue, 14 Feb 2023 09:13:04 -0800 Subject: [PATCH 092/424] Add NULL session check to _libssh2_error_flags() (#796) Don't dereference null if a null session happens to make it into _libssh2_error_flags() --- src/misc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/misc.c b/src/misc.c index 0c84fa4b8f..84d165c2f5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -65,6 +65,12 @@ int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode, const char *errmsg, int errflags) { + if(session == NULL) { + if(errmsg != NULL) + fprintf(stderr, "Session is NULL, error: %s\n", errmsg); + return errcode; + } + if(session->err_flags & LIBSSH2_ERR_FLAG_DUP) LIBSSH2_FREE(session, (char *)session->err_msg); From 27ef3bbb254d049f33a5cc5082580263bbb25137 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 20 Feb 2023 16:29:10 -0800 Subject: [PATCH 093/424] Improve the ssh2 example program to run a command This performs better as an example since it shows more working code, and in the simplest possible way. It also turns the program into an actually useful tool out of the box, able to run an arbitrary command (with one restriction) on a remote machine and return the response, without needing to touch the source. Closes #800 --- example/ssh2.c | 91 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/example/ssh2.c b/example/ssh2.c index b8d320918e..9b1ce1d8f9 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -4,10 +4,11 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * Usage: ssh2 hostip user password [-p|-i|-k] + * Usage: ssh2 hostip user password [[-p|-i|-k] [command]] * -p authenticate using password * -i authenticate using keyboard-interactive * -k authenticate using public key (password argument decrypts keyfile) + * command executes on the remote machine */ #include "libssh2_config.h" @@ -82,11 +83,10 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc != 0) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -120,8 +120,8 @@ int main(int argc, char *argv[]) sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - fprintf(stderr, "Connecting to %s as user %s\n", - inet_ntoa(sin.sin_addr), username); + fprintf(stderr, "Connecting to %s:%d as user %s\n", + inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), username); if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { @@ -251,7 +251,7 @@ int main(int argc, char *argv[]) goto shutdown; } - /* Request a shell */ + /* Request a session channel on which to run a shell */ channel = libssh2_channel_open_session(session); if(!channel) { fprintf(stderr, "Unable to open a session\n"); @@ -264,33 +264,62 @@ int main(int argc, char *argv[]) libssh2_channel_setenv(channel, "FOO", "bar"); /* Request a terminal with 'vanilla' terminal emulation - * See /etc/termcap for more options + * See /etc/termcap for more options. This is useful when opening + * an interactive shell. */ - if(libssh2_channel_request_pty(channel, "vanilla")) { - fprintf(stderr, "Failed requesting pty\n"); - goto skip_shell; - } +// if(libssh2_channel_request_pty(channel, "vanilla")) { +// fprintf(stderr, "Failed requesting pty\n"); +// } - /* Open a SHELL on that pty */ - if(libssh2_channel_shell(channel)) { - fprintf(stderr, "Unable to request shell on allocated pty\n"); - goto shutdown; + if(argc > 5) { + if(libssh2_channel_exec(channel, argv[5])) { + fprintf(stderr, "Unable to request command on channel\n"); + goto shutdown; + } + /* Instead of just running a single command with libssh2_channel_exec, + * a shell can be opened on the channel instead, for interactive use. + * You usually want a pty allocated first in that case (see above). */ +// if(libssh2_channel_shell(channel)) { +// fprintf(stderr, "Unable to request shell on allocated pty\n"); +// goto shutdown; +// } + +/* At this point the shell can be interacted with using + * libssh2_channel_read() + * libssh2_channel_read_stderr() + * libssh2_channel_write() + * libssh2_channel_write_stderr() + * + * Blocking mode may be (en|dis)abled with: libssh2_channel_set_blocking() + * If the server send EOF, libssh2_channel_eof() will return non-0 + * To send EOF to the server use: libssh2_channel_send_eof() + * A channel can be closed with: libssh2_channel_close() + * A channel can be freed with: libssh2_channel_free() + */ + + /* Read and display all the data received on stdout (ignoring stderr) + * until the channel closes. This will eventually block if the command + * produces too much data on stderr; the loop must be rewritten to use + * non-blocking mode and include interspersed calls to + * libssh2_channel_read_stderr() to avoid this. See ssh2_echo.c for + * an idea of how such a loop might look. + */ + while(!libssh2_channel_eof(channel)) { + char buf[1024]; + ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf)); + if(err < 0) + fprintf(stderr, "Unable to read response: %zd\n", err); + else { + fwrite(buf, 1, err, stdout); + } + } } - /* At this point the shell can be interacted with using - * libssh2_channel_read() - * libssh2_channel_read_stderr() - * libssh2_channel_write() - * libssh2_channel_write_stderr() - * - * Blocking mode may be (en|dis)abled with: libssh2_channel_set_blocking() - * If the server send EOF, libssh2_channel_eof() will return non-0 - * To send EOF to the server use: libssh2_channel_send_eof() - * A channel can be closed with: libssh2_channel_close() - * A channel can be freed with: libssh2_channel_free() - */ + rc = libssh2_channel_get_exit_status(channel); + + if(libssh2_channel_close(channel)) + fprintf(stderr, "Unable to close channel\n"); - skip_shell: if(channel) { libssh2_channel_free(channel); channel = NULL; @@ -317,5 +346,5 @@ int main(int argc, char *argv[]) libssh2_exit(); - return 0; + return rc; } From 4c9ed51f962f542b98789b15bedaaa427f4029a2 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 22 Feb 2023 13:55:44 -0800 Subject: [PATCH 094/424] tests: Support running tests in out-of-tree builds Various files are found by referencing the srcdir environment variable in that case. Closes #801 --- tests/CMakeLists.txt | 2 +- tests/openssh_fixture.c | 10 ++++-- tests/session_fixture.c | 33 +++++++++++++++++++ tests/session_fixture.h | 1 + tests/test_agent_forward_succeeds.c | 3 +- ...est_public_key_auth_fails_with_wrong_key.c | 3 +- ...c_key_auth_succeeds_with_correct_dsa_key.c | 4 +-- ...key_auth_succeeds_with_correct_ecdsa_key.c | 3 +- ...y_auth_succeeds_with_correct_ed25519_key.c | 3 +- ...cceeds_with_correct_ed25519_key_from_mem.c | 2 +- ...ceeds_with_correct_encrypted_ed25519_key.c | 3 +- ..._succeeds_with_correct_encrypted_rsa_key.c | 3 +- ...c_key_auth_succeeds_with_correct_rsa_key.c | 3 +- ...th_succeeds_with_correct_rsa_openssh_key.c | 3 +- ...h_succeeds_with_correct_signed_ecdsa_key.c | 3 +- ...uth_succeeds_with_correct_signed_rsa_key.c | 3 +- 16 files changed, 65 insertions(+), 17 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1f9764c49a..1e02f01ddf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -153,7 +153,7 @@ endif() add_library(openssh_fixture STATIC openssh_fixture.h openssh_fixture.c) target_link_libraries(openssh_fixture ${LIBRARIES}) -target_include_directories(openssh_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") +target_include_directories(openssh_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" ../include) add_library(session_fixture STATIC session_fixture.h session_fixture.c) target_link_libraries(session_fixture ${LIBRARIES} openssh_fixture libssh2) diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 3a1588c236..50ff0d940c 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -36,6 +36,7 @@ */ #include "openssh_fixture.h" +#include "session_fixture.h" #include "libssh2_config.h" #ifdef HAVE_WINSOCK2_H @@ -153,6 +154,7 @@ static const char *openssh_server_image(void) static int build_openssh_server_docker_image(void) { if(have_docker) { + char buildcmd[1024]; const char *container_image_name = openssh_server_image(); if(container_image_name != NULL) { int ret = run_command(NULL, "docker pull --quiet %s", @@ -165,10 +167,12 @@ static int build_openssh_server_docker_image(void) } } } + buildcmd[sizeof(buildcmd)-1] = 0; + snprintf(buildcmd, sizeof(buildcmd)-1, + "docker build --quiet -t libssh2/openssh_server %s", + srcdir_path("openssh_server")); - return run_command(NULL, "docker build --quiet " - "-t libssh2/openssh_server " - "openssh_server"); + return run_command(NULL, buildcmd); } else { return 0; diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 18df662400..82682d1379 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -57,6 +57,7 @@ #ifdef HAVE_SYS_PARAM_H #include #endif +#include LIBSSH2_SESSION *connected_session = NULL; int connected_socket = -1; @@ -160,3 +161,35 @@ void stop_session_fixture(void) stop_openssh_fixture(); } + + +/* Return a static string that contains a file path relative to the srcdir + * variable, if found. It does so in a way that avoids leaking memory by using + * a fixed number of static buffers. + */ +#define NUMPATHS 3 +const char *srcdir_path(const char *file) +{ +#ifdef WIN32 + static char filepath[NUMPATHS][_MAX_PATH]; +#else + static char filepath[NUMPATHS][MAXPATHLEN]; +#endif + static int curpath; + char *p = getenv("srcdir"); + assert(curpath < NUMPATHS); + if(p) { + /* Ensure the final string is nul-terminated on Windows */ + filepath[curpath][sizeof(filepath[0])-1] = 0; + snprintf(filepath[curpath], sizeof(filepath[0])-1, "%s/%s", + p, file); + } + else { + /* Ensure the final string is nul-terminated on Windows */ + filepath[curpath][sizeof(filepath[0])-1] = 0; + snprintf(filepath[curpath], sizeof(filepath[0])-1, "%s", + file); + } + + return filepath[curpath++]; +} diff --git a/tests/session_fixture.h b/tests/session_fixture.h index bbb8e596fe..f42d1dc838 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -43,5 +43,6 @@ LIBSSH2_SESSION *start_session_fixture(void); void stop_session_fixture(void); void print_last_session_error(const char *function); +const char *srcdir_path(const char *file); #endif diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index 569663b359..9d203dc9d5 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -28,7 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c index 8b79edb685..44b459f8fe 100644 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ b/tests/test_public_key_auth_fails_with_wrong_key.c @@ -27,7 +27,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc == 0) { fprintf(stderr, "Public-key auth succeeded with wrong key\n"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c index c04d7682c8..01ea06e49d 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c @@ -28,8 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, - NULL); + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c index febec6bb68..1a55686dc3 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c @@ -28,7 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c index 0ef9cf50b9..ce15295e8a 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c @@ -28,7 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index 6553baeb7c..0a13edba67 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -30,7 +30,7 @@ int test(LIBSSH2_SESSION *session) return 1; } - if(read_file(KEY_FILE_ED25519_PRIVATE, &buffer, &len)) { + if(read_file(srcdir_path(KEY_FILE_ED25519_PRIVATE), &buffer, &len)) { fprintf(stderr, "Reading key file failed."); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c index 39e8cca5e3..998fa57233 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c @@ -29,7 +29,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), PASSWORD); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c index 35cb504842..d114f95a1d 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c @@ -29,7 +29,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), PASSWORD); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c index 40d9b80a86..aa0a79de0c 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c @@ -28,7 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c index 22a9937f39..c6b4cabb7c 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c @@ -28,7 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c index 398bfe381b..1fd7db0557 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c @@ -28,7 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c index 8843196fed..ef64d2985b 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -28,7 +28,8 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); From d8220ddbfff365b03da338fafdd86878ae218395 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 22 Feb 2023 14:35:49 -0800 Subject: [PATCH 095/424] Fix a couple of warnings of errors in MSVC builds Two warnings (in tests & examples) in particular would cause problems: bad format causing invalid data output or a bad chdir due to out of scope buffer use. --- example/scp_nonblock.c | 1 - example/scp_write.c | 4 ++-- example/sftpdir.c | 2 +- example/sftpdir_nonblock.c | 2 +- example/ssh2_agent_forwarding.c | 1 - example/ssh2_echo.c | 2 +- example/ssh2_exec.c | 1 - src/bcrypt_pbkdf.c | 2 +- src/packet.c | 6 +++--- tests/session_fixture.c | 10 +++++----- 10 files changed, 14 insertions(+), 17 deletions(-) diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index bc5bdb3dc1..b8317a279c 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -231,7 +231,6 @@ int main(int argc, char *argv[]) while(got < fileinfo.st_size) { char mem[1024*24]; - int rc; do { int amount = sizeof(mem); diff --git a/example/scp_write.c b/example/scp_write.c index 030232ec6c..150c5e470f 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -48,10 +48,10 @@ int main(int argc, char *argv[]) size_t nread; char *ptr; struct stat fileinfo; + int err; #ifdef WIN32 WSADATA wsadata; - int err; err = WSAStartup(MAKEWORD(2, 0), &wsadata); if(err != 0) { @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) if(!channel) { char *errmsg; int errlen; - int err = libssh2_session_last_error(session, &errmsg, &errlen, 0); + err = libssh2_session_last_error(session, &errmsg, &errlen, 0); fprintf(stderr, "Unable to open a session: (%d) %s\n", err, errmsg); goto shutdown; } diff --git a/example/sftpdir.c b/example/sftpdir.c index 8fb16b1e98..4b6af8869f 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -37,7 +37,7 @@ #include #ifdef WIN32 -#define __FILESIZE "I64" +#define __FILESIZE "I64u" #else #define __FILESIZE "llu" #endif diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index e9498d97cb..abc4ff4819 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -37,7 +37,7 @@ #include #ifdef WIN32 -#define __FILESIZE "I64" +#define __FILESIZE "I64u" #else #define __FILESIZE "llu" #endif diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index b99fc95fe7..f86079d83e 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -225,7 +225,6 @@ int main(int argc, char *argv[]) } for(;;) { /* loop until we block */ - int rc; do { char buffer[0x4000]; rc = libssh2_channel_read(channel, buffer, sizeof(buffer) ); diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index eae4165634..937c438c43 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -250,8 +250,8 @@ int main(int argc, char *argv[]) fds[0].events = LIBSSH2_POLLFD_POLLIN | LIBSSH2_POLLFD_POLLOUT; do { - int rc = (libssh2_poll(fds, 1, 10)); int act = 0; + rc = (libssh2_poll(fds, 1, 10)); if(rc < 1) continue; diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index d33c6d9a8d..1c11849e0d 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -254,7 +254,6 @@ int main(int argc, char *argv[]) } for(;;) { /* loop until we block */ - int rc; do { char buffer[0x4000]; rc = libssh2_channel_read(channel, buffer, sizeof(buffer) ); diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 50d542093f..822d117640 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -65,7 +65,7 @@ bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out) uint32_t cdata[BCRYPT_BLOCKS]; int i; uint16_t j; - size_t shalen = SHA512_DIGEST_LENGTH; + uint16_t shalen = SHA512_DIGEST_LENGTH; /* key expansion */ Blowfish_initstate(&state); diff --git a/src/packet.c b/src/packet.c index c3756a8ea0..40bd64c04e 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1392,9 +1392,9 @@ _libssh2_packet_requirev(LIBSSH2_SESSION *session, if(strchr((char *) packet_types, ret)) { /* Be lazy, let packet_ask pull it out of the brigade */ - int ret = _libssh2_packet_askv(session, packet_types, data, - data_len, match_ofs, match_buf, - match_len); + ret = _libssh2_packet_askv(session, packet_types, data, + data_len, match_ofs, match_buf, + match_len); state->start = 0; return ret; } diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 82682d1379..2d347007e8 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -81,6 +81,11 @@ static int connect_to_server(void) static void setup_fixture_workdir(void) { +#ifdef WIN32 + char wd_buf[_MAX_PATH]; +#else + char wd_buf[MAXPATHLEN]; +#endif char *wd = getenv("FIXTURE_WORKDIR"); #ifdef FIXTURE_WORKDIR if(!wd) { @@ -88,11 +93,6 @@ static void setup_fixture_workdir(void) } #endif if(!wd) { -#ifdef WIN32 - char wd_buf[_MAX_PATH]; -#else - char wd_buf[MAXPATHLEN]; -#endif getcwd(wd_buf, sizeof(wd_buf)); wd = wd_buf; } From 45d33da3c747d023a3459345066c27d055cc12f3 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Mon, 27 Feb 2023 11:46:47 -0800 Subject: [PATCH 096/424] Disable deprecated warnings for OpenSSL 3 #805 (#806) Disable deprecated warnings (for now) when building against OpenSSL 3 for a clean build. Reported: Daniel Stenberg --- src/openssl.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/openssl.h b/src/openssl.h index cc5c40d4d3..6d75007abd 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -39,6 +39,9 @@ * OF SUCH DAMAGE. */ +/* disable deprecated warnings in OpenSSL 3 */ +#define OPENSSL_SUPPRESS_DEPRECATED + #ifdef LIBSSH2_WOLFSSL #include From 5f88efdddc3abc5c779bc3c7c607b21eb118956c Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 28 Feb 2023 17:01:26 -0800 Subject: [PATCH 097/424] Add test to read lots of data over a channel Connects to the ssh server then downloads several MB of data. This tests the data transfer path as well as boundary cases in packet handling as data is split into smaller SSH blocks. --- tests/CMakeLists.txt | 1 + tests/Makefile.am | 3 +- tests/test_read.c | 108 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 tests/test_read.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1e02f01ddf..e45a94bc68 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -127,6 +127,7 @@ set(TESTS keyboard_interactive_auth_fails_with_wrong_response keyboard_interactive_auth_succeeds_with_correct_response agent_forward_succeeds + read ) if(CRYPTO_BACKEND STREQUAL "OpenSSL") diff --git a/tests/Makefile.am b/tests/Makefile.am index 9dce308b88..942d17da78 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -31,7 +31,8 @@ INTEGRATION_TESTS = \ test_public_key_auth_succeeds_with_correct_rsa_key \ test_public_key_auth_succeeds_with_correct_rsa_openssh_key \ test_public_key_auth_succeeds_with_correct_signed_ecdsa_key \ - test_public_key_auth_succeeds_with_correct_signed_rsa_key + test_public_key_auth_succeeds_with_correct_signed_rsa_key \ + test_read # Integration tests using Docker # Enable this once the tests are working diff --git a/tests/test_read.c b/tests/test_read.c new file mode 100644 index 0000000000..14d05240bf --- /dev/null +++ b/tests/test_read.c @@ -0,0 +1,108 @@ +/* libssh2 test receiving large amounts of data through a channel */ + +#include "session_fixture.h" +#include "runner.h" + +#include + +#include + +/* configured in Dockerfile */ +static const char *USERNAME = "libssh2"; +static const char *KEY_FILE_PRIVATE = "key_rsa"; +static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; + +/* Size and number of blocks to transfer + * This needs to be large to increase the chance of timing effects causing + * different code paths to be hit in the unframing code, but not so long that + * the integration tests take too long. 5 seconds of run time is probably a + * reasonable compromise. The block size is an odd number to increase the + * chance that various internal buffer and block boundaries are overlapped. */ +#define XFER_BS 997 +#define XFER_COUNT 140080 + +#define STRINGIFY(x) STRINGIFY2(x) +#define STRINGIFY2(x) #x + +/* command to transfer the desired amount of data */ +#define REMOTE_COMMAND "dd if=/dev/zero bs=" STRINGIFY(XFER_BS) \ + " count=" STRINGIFY(XFER_COUNT) " status=none" + +int test(LIBSSH2_SESSION *session) +{ + int rc; + long xfer_bytes = 0; + LIBSSH2_CHANNEL *channel; + + const char *userauth_list = + libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + if(userauth_list == NULL) { + print_last_session_error("libssh2_userauth_list"); + return 1; + } + + if(strstr(userauth_list, "publickey") == NULL) { + fprintf(stderr, "'publickey' was expected in userauth list: %s\n", + userauth_list); + return 1; + } + + rc = libssh2_userauth_publickey_fromfile_ex( + session, USERNAME, strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); + if(rc != 0) { + print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); + return 1; + } + + /* Request a session channel on which to run a shell */ + channel = libssh2_channel_open_session(session); + if(!channel) { + fprintf(stderr, "Unable to open a session\n"); + goto shutdown; + } + + /* Send the command to transfer data */ + if(libssh2_channel_exec(channel, REMOTE_COMMAND)) { + fprintf(stderr, "Unable to request command on channel\n"); + goto shutdown; + } + + /* Read data */ + while(!libssh2_channel_eof(channel)) { + char buf[1024]; + ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf)); + if(err < 0) + fprintf(stderr, "Unable to read response: %zd\n", err); + else { + int i; + for(i = 0; i < err; ++i) { + if(buf[i]) { + fprintf(stderr, "Bad data received\n"); + /* Test will fail below due to bad data length */ + break; + } + } + xfer_bytes += i; + } + } + + /* Shut down */ + if(libssh2_channel_close(channel)) + fprintf(stderr, "Unable to close channel\n"); + + if(channel) { + libssh2_channel_free(channel); + channel = NULL; + } + +shutdown: + + /* Test check */ + if(xfer_bytes != XFER_COUNT * XFER_BS) { + fprintf(stderr, "Not enough bytes received: %ld not %ld\n", + xfer_bytes, (long)XFER_COUNT * XFER_BS); + return 1; /* error */ + } + return 0; +} From 7487dcf4b4ddae54b2a850737789b57b4251b0ae Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 28 Feb 2023 22:21:48 -0800 Subject: [PATCH 098/424] Add tests to check individual crypt & HMAC methods One specific crypt or hmac method is requested to be negotiated, then several MB of data is transferred. --- tests/CMakeLists.txt | 37 +++++++++++++++++++++++++++++++ tests/Makefile.am | 30 ++++++++++++++++++++++++- tests/openssh_server/Dockerfile | 3 +++ tests/session_fixture.c | 29 +++++++++++++++++++++++- tests/test_read_3des-cbc | 2 ++ tests/test_read_3des-cbc.bat | 2 ++ tests/test_read_aes128-cbc | 2 ++ tests/test_read_aes128-cbc.bat | 2 ++ tests/test_read_aes128-ctr | 3 +++ tests/test_read_aes128-ctr.bat | 2 ++ tests/test_read_aes192-cbc | 2 ++ tests/test_read_aes192-cbc.bat | 2 ++ tests/test_read_aes192-ctr | 2 ++ tests/test_read_aes192-ctr.bat | 2 ++ tests/test_read_aes256-cbc | 2 ++ tests/test_read_aes256-cbc.bat | 2 ++ tests/test_read_aes256-ctr | 2 ++ tests/test_read_aes256-ctr.bat | 2 ++ tests/test_read_hmac-md5 | 2 ++ tests/test_read_hmac-md5-96 | 2 ++ tests/test_read_hmac-md5-96.bat | 2 ++ tests/test_read_hmac-md5.bat | 2 ++ tests/test_read_hmac-sha1 | 2 ++ tests/test_read_hmac-sha1-96 | 2 ++ tests/test_read_hmac-sha1-96.bat | 2 ++ tests/test_read_hmac-sha1.bat | 2 ++ tests/test_read_hmac-sha2-256 | 2 ++ tests/test_read_hmac-sha2-256.bat | 2 ++ tests/test_read_hmac-sha2-512 | 2 ++ tests/test_read_hmac-sha2-512.bat | 2 ++ tests/test_read_rijndael-cbc | 2 ++ tests/test_read_rijndael-cbc.bat | 2 ++ 32 files changed, 154 insertions(+), 2 deletions(-) create mode 100755 tests/test_read_3des-cbc create mode 100644 tests/test_read_3des-cbc.bat create mode 100755 tests/test_read_aes128-cbc create mode 100644 tests/test_read_aes128-cbc.bat create mode 100755 tests/test_read_aes128-ctr create mode 100644 tests/test_read_aes128-ctr.bat create mode 100755 tests/test_read_aes192-cbc create mode 100644 tests/test_read_aes192-cbc.bat create mode 100755 tests/test_read_aes192-ctr create mode 100644 tests/test_read_aes192-ctr.bat create mode 100755 tests/test_read_aes256-cbc create mode 100644 tests/test_read_aes256-cbc.bat create mode 100755 tests/test_read_aes256-ctr create mode 100644 tests/test_read_aes256-ctr.bat create mode 100755 tests/test_read_hmac-md5 create mode 100755 tests/test_read_hmac-md5-96 create mode 100644 tests/test_read_hmac-md5-96.bat create mode 100644 tests/test_read_hmac-md5.bat create mode 100755 tests/test_read_hmac-sha1 create mode 100755 tests/test_read_hmac-sha1-96 create mode 100644 tests/test_read_hmac-sha1-96.bat create mode 100644 tests/test_read_hmac-sha1.bat create mode 100755 tests/test_read_hmac-sha2-256 create mode 100644 tests/test_read_hmac-sha2-256.bat create mode 100755 tests/test_read_hmac-sha2-512 create mode 100644 tests/test_read_hmac-sha2-512.bat create mode 100755 tests/test_read_rijndael-cbc create mode 100644 tests/test_read_rijndael-cbc.bat diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e45a94bc68..8f231e27f5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -176,6 +176,43 @@ foreach(test ${TESTS}) WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") endforeach() +if(WIN32) + set(test_ext ".bat") +endif() + +foreach(test + read_aes128-ctr + read_aes192-ctr + read_aes256-ctr + read_hmac-md5 + read_hmac-md5-96 + read_hmac-sha1 + read_hmac-sha1-96 + read_hmac-sha2-256 + read_hmac-sha2-512 + ) + add_test( + NAME test_${test} COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_${test}${test_ext}") + set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "builddir=$") +endforeach() + +# Due to a bug with mbedTLS support, these crypt methods fail. Until that bug +# is fixed, don't run them there to avoid this known issue causing red tests. +# See https://github.com/libssh2/libssh2/issues/793 +if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") + foreach(test + read_3des-cbc + read_aes128-cbc + read_aes192-cbc + read_aes256-cbc + read_rijndael-cbc + ) + add_test( + NAME test_${test} COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_${test}${test_ext}") + set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "builddir=$") + endforeach() +endif() + if(WIN32 AND BUILD_SHARED_LIBS) # Workaround for Visual Studio add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c ../src/misc.c) diff --git a/tests/Makefile.am b/tests/Makefile.am index 942d17da78..fcaa96d4bf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -98,4 +98,32 @@ EXTRA_DIST = \ sshdwrap \ ssh2.c \ ssh2.sh \ - sshd_fixture.sh.in + sshd_fixture.sh.in \ + test_read_3des-cbc \ + test_read_3des-cbc.bat \ + test_read_aes128-cbc \ + test_read_aes128-cbc.bat \ + test_read_aes128-ctr \ + test_read_aes128-ctr.bat \ + test_read_aes192-cbc \ + test_read_aes192-cbc.bat \ + test_read_aes192-ctr \ + test_read_aes192-ctr.bat \ + test_read_aes256-cbc \ + test_read_aes256-cbc.bat \ + test_read_aes256-ctr \ + test_read_aes256-ctr.bat \ + test_read_hmac-md5 \ + test_read_hmac-md5-96 \ + test_read_hmac-md5-96.bat \ + test_read_hmac-md5.bat \ + test_read_hmac-sha1 \ + test_read_hmac-sha1-96 \ + test_read_hmac-sha1-96.bat \ + test_read_hmac-sha1.bat \ + test_read_hmac-sha2-256 \ + test_read_hmac-sha2-256.bat \ + test_read_hmac-sha2-512 \ + test_read_hmac-sha2-512.bat \ + test_read_rijndael-cbc \ + test_read_rijndael-cbc.bat diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index ed33e867c4..c2f5e14612 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -81,6 +81,9 @@ RUN echo 'libssh2:my test password' | chpasswd RUN sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config RUN echo "TrustedUserCAKeys /etc/ssh/ca_main.pub" >> /etc/ssh/sshd_config RUN echo "PubkeyAcceptedKeyTypes=+ssh-dss" >> /etc/ssh/sshd_config +RUN echo "MACs +hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512,hmac-md5,hmac-md5-96,umac-64@openssh.com,umac-128@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com" >> /etc/ssh/sshd_config +RUN echo "Ciphers +3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com" >> /etc/ssh/sshd_config + # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 2d347007e8..dc200b5c50 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -103,6 +103,7 @@ static void setup_fixture_workdir(void) LIBSSH2_SESSION *start_session_fixture(void) { int rc; + const char *env; setup_fixture_workdir(); @@ -120,12 +121,38 @@ LIBSSH2_SESSION *start_session_fixture(void) if(getenv("FIXTURE_TRACE_ALL")) { libssh2_trace(connected_session, ~0); } - libssh2_session_set_blocking(connected_session, 1); if(connected_session == NULL) { fprintf(stderr, "libssh2_session_init_ex failed\n"); return NULL; } + /* Override crypt algorithm for the test */ + env = getenv("FIXTURE_TEST_CRYPT"); + if(env) { + if(libssh2_session_method_pref(connected_session, + LIBSSH2_METHOD_CRYPT_CS, env) || + libssh2_session_method_pref(connected_session, + LIBSSH2_METHOD_CRYPT_SC, env)) { + fprintf(stderr, "libssh2_session_method_pref CRYPT failed " + "(probably disabled in the build)\n"); + return NULL; + } + } + /* Override mac algorithm for the test */ + env = getenv("FIXTURE_TEST_MAC"); + if(env) { + if(libssh2_session_method_pref(connected_session, + LIBSSH2_METHOD_MAC_CS, env) || + libssh2_session_method_pref(connected_session, + LIBSSH2_METHOD_MAC_SC, env)) { + fprintf(stderr, "libssh2_session_method_pref MAC failed " + "(probably disabled in the build)\n"); + return NULL; + } + } + + libssh2_session_set_blocking(connected_session, 1); + rc = connect_to_server(); if(rc != 0) { return NULL; diff --git a/tests/test_read_3des-cbc b/tests/test_read_3des-cbc new file mode 100755 index 0000000000..9e8db19bce --- /dev/null +++ b/tests/test_read_3des-cbc @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=3des-cbc exec ./test_read diff --git a/tests/test_read_3des-cbc.bat b/tests/test_read_3des-cbc.bat new file mode 100644 index 0000000000..4e9f0ba4b8 --- /dev/null +++ b/tests/test_read_3des-cbc.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=3des-cbc +%builddir%\test_read diff --git a/tests/test_read_aes128-cbc b/tests/test_read_aes128-cbc new file mode 100755 index 0000000000..30f31c3bf3 --- /dev/null +++ b/tests/test_read_aes128-cbc @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes128-cbc exec ./test_read diff --git a/tests/test_read_aes128-cbc.bat b/tests/test_read_aes128-cbc.bat new file mode 100644 index 0000000000..13e84fca22 --- /dev/null +++ b/tests/test_read_aes128-cbc.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=aes128-cbc +%builddir%\test_read diff --git a/tests/test_read_aes128-ctr b/tests/test_read_aes128-ctr new file mode 100755 index 0000000000..256ddd5681 --- /dev/null +++ b/tests/test_read_aes128-ctr @@ -0,0 +1,3 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes128-ctr exec ./test_read + diff --git a/tests/test_read_aes128-ctr.bat b/tests/test_read_aes128-ctr.bat new file mode 100644 index 0000000000..5d2d8ddf23 --- /dev/null +++ b/tests/test_read_aes128-ctr.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=aes128-ctr +%builddir%\test_read diff --git a/tests/test_read_aes192-cbc b/tests/test_read_aes192-cbc new file mode 100755 index 0000000000..6daaae2090 --- /dev/null +++ b/tests/test_read_aes192-cbc @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes192-cbc exec ./test_read diff --git a/tests/test_read_aes192-cbc.bat b/tests/test_read_aes192-cbc.bat new file mode 100644 index 0000000000..07c3641a1e --- /dev/null +++ b/tests/test_read_aes192-cbc.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=aes192-cbc +%builddir%\test_read diff --git a/tests/test_read_aes192-ctr b/tests/test_read_aes192-ctr new file mode 100755 index 0000000000..726d76b3c4 --- /dev/null +++ b/tests/test_read_aes192-ctr @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes192-ctr exec ./test_read diff --git a/tests/test_read_aes192-ctr.bat b/tests/test_read_aes192-ctr.bat new file mode 100644 index 0000000000..c16898e69e --- /dev/null +++ b/tests/test_read_aes192-ctr.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=aes192-ctr +%builddir%\test_read diff --git a/tests/test_read_aes256-cbc b/tests/test_read_aes256-cbc new file mode 100755 index 0000000000..61c6946e93 --- /dev/null +++ b/tests/test_read_aes256-cbc @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes256-cbc exec ./test_read diff --git a/tests/test_read_aes256-cbc.bat b/tests/test_read_aes256-cbc.bat new file mode 100644 index 0000000000..baff53c0b0 --- /dev/null +++ b/tests/test_read_aes256-cbc.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=aes256-cbc +%builddir%\test_read diff --git a/tests/test_read_aes256-ctr b/tests/test_read_aes256-ctr new file mode 100755 index 0000000000..1d0e5cd0dd --- /dev/null +++ b/tests/test_read_aes256-ctr @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes256-ctr exec ./test_read diff --git a/tests/test_read_aes256-ctr.bat b/tests/test_read_aes256-ctr.bat new file mode 100644 index 0000000000..e551a45e13 --- /dev/null +++ b/tests/test_read_aes256-ctr.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=aes256-ctr +%builddir%\test_read diff --git a/tests/test_read_hmac-md5 b/tests/test_read_hmac-md5 new file mode 100755 index 0000000000..c0ab4fffff --- /dev/null +++ b/tests/test_read_hmac-md5 @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_MAC=hmac-md5 exec ./test_read diff --git a/tests/test_read_hmac-md5-96 b/tests/test_read_hmac-md5-96 new file mode 100755 index 0000000000..deceff14c8 --- /dev/null +++ b/tests/test_read_hmac-md5-96 @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_MAC=hmac-md5-96 exec ./test_read diff --git a/tests/test_read_hmac-md5-96.bat b/tests/test_read_hmac-md5-96.bat new file mode 100644 index 0000000000..1211e5237f --- /dev/null +++ b/tests/test_read_hmac-md5-96.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_MAC=hmac-md5-96 +%builddir%\test_read diff --git a/tests/test_read_hmac-md5.bat b/tests/test_read_hmac-md5.bat new file mode 100644 index 0000000000..f3361552b8 --- /dev/null +++ b/tests/test_read_hmac-md5.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_MAC=hmac-md5 +%builddir%\test_read diff --git a/tests/test_read_hmac-sha1 b/tests/test_read_hmac-sha1 new file mode 100755 index 0000000000..6dc31374c9 --- /dev/null +++ b/tests/test_read_hmac-sha1 @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_MAC=hmac-sha1 exec ./test_read diff --git a/tests/test_read_hmac-sha1-96 b/tests/test_read_hmac-sha1-96 new file mode 100755 index 0000000000..40173ad004 --- /dev/null +++ b/tests/test_read_hmac-sha1-96 @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_MAC=hmac-sha1-96 exec ./test_read diff --git a/tests/test_read_hmac-sha1-96.bat b/tests/test_read_hmac-sha1-96.bat new file mode 100644 index 0000000000..5fb20077f5 --- /dev/null +++ b/tests/test_read_hmac-sha1-96.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_MAC=hmac-sha1-96 +%builddir%\test_read diff --git a/tests/test_read_hmac-sha1.bat b/tests/test_read_hmac-sha1.bat new file mode 100644 index 0000000000..1db5109cd5 --- /dev/null +++ b/tests/test_read_hmac-sha1.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_MAC=hmac-sha1 +%builddir%\test_read diff --git a/tests/test_read_hmac-sha2-256 b/tests/test_read_hmac-sha2-256 new file mode 100755 index 0000000000..15b2432309 --- /dev/null +++ b/tests/test_read_hmac-sha2-256 @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_MAC=hmac-sha2-256 exec ./test_read diff --git a/tests/test_read_hmac-sha2-256.bat b/tests/test_read_hmac-sha2-256.bat new file mode 100644 index 0000000000..a3a7ac886a --- /dev/null +++ b/tests/test_read_hmac-sha2-256.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_MAC=hmac-sha2-256 +%builddir%\test_read diff --git a/tests/test_read_hmac-sha2-512 b/tests/test_read_hmac-sha2-512 new file mode 100755 index 0000000000..77e5cee643 --- /dev/null +++ b/tests/test_read_hmac-sha2-512 @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_MAC=hmac-sha2-512 exec ./test_read diff --git a/tests/test_read_hmac-sha2-512.bat b/tests/test_read_hmac-sha2-512.bat new file mode 100644 index 0000000000..8ad9103ced --- /dev/null +++ b/tests/test_read_hmac-sha2-512.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_MAC=hmac-sha2-512 +%builddir%\test_read diff --git a/tests/test_read_rijndael-cbc b/tests/test_read_rijndael-cbc new file mode 100755 index 0000000000..85fb980ef4 --- /dev/null +++ b/tests/test_read_rijndael-cbc @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=rijndael-cbc@lysator.liu.se exec ./test_read diff --git a/tests/test_read_rijndael-cbc.bat b/tests/test_read_rijndael-cbc.bat new file mode 100644 index 0000000000..6889a0253e --- /dev/null +++ b/tests/test_read_rijndael-cbc.bat @@ -0,0 +1,2 @@ +set FIXTURE_TEST_CRYPT=rijndael-cbc@lysator.liu.se +%builddir%\test_read From 2addafb77b662e64248d156c71c69b91ba7b926e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 3 Mar 2023 13:30:03 +0000 Subject: [PATCH 099/424] build fixes and improvements (mostly for Windows) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - in `hostkey.c` check the result of `libssh2_sha256_init()` and `libssh2_sha512_init()` calls. This avoid the warning that we're ignoring the return values. - fix code using `int` (or `SOCKET`) for sockets. Use libssh2's dedicated `libssh2_socket_t` and `LIBSSH2_INVALID_SOCKET` instead. - fix compiler warnings due to `STATUS_*` macro redefinitions between `ntstatus.h` / `winnt.h`. Solve it by manually defining the single `STATUS` value we need from `ntstatus.h` and stop including the whole header. Fixes #733 - improve Windows UWP/WinRT builds by detecting it with code copied from the curl project. Then excluding problematic libssh2 parts according to PR by Dmitry Kostjučenko. Fixes #734 - always use `SecureZeroMemory()` on Windows. We can tweak this if not found or not inlined by a C compiler which we otherwise support. Same if it causes issues with UWP apps. Ref: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa366877(v=vs.85) Ref: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlsecurezeromemory - always enable `LIBSSH2_CLEAR_MEMORY` on Windows. CMake and curl-for-win builds already did that. Delete `SecureZeroMemory()` detection from autotools' WinCNG backend logic, that this setting used to depend on. TODO: Enable it for all platforms in a separate PR. TODO: For clearing buffers in WinCNG, call `_libssh2_explicit_zero()`, insead of a local function or explicit `SecureZeroMemory()`. - Makefile.inc: move `os400qc3.h` to `HEADERS`. This fixes compilation on non-unixy platforms. Recent regression. - `libssh2.rc`: replace copyright with plain ASCII, as in curl. Ref: curl/curl@1ca62bb Ref: curl/curl#7765 Ref: curl/curl#7776 - CMake fixes and improvements: - enable warnings with llvm/clang. - enable more comprehensive warnings with gcc and llvm/clang. Logic copied from curl: https://github.com/curl/curl/blob/233810bb5f6c5e7bedfc10bdd36607b958c0cfe4/CMakeLists.txt#L131-L148 - fix `Policy CMP0080` CMake warning by deleting that reference. - add `ENABLE_WERROR` (default: `OFF`) option. Ported from curl. - add `PICKY_COMPILER` (default: `ON`) option, as known from curl. It controls both the newly added picky warnings for llvm/clang and gcc, and also the pre-existing ones for MSVC. - `win32/GNUmakefile` fixes and improvements: - delete `_AMD64_` and add missing `-m64` for x64 builds under test. - add support for `ARCH=custom`. It disables hardcoded Intel 64-bit and Intel 32-bit options, allowing ARM64 builds. - add support for `LIBSSH2_RCFLAG_EXTRAS`. To pass custom options to windres, e.g. in ARM64 builds. - add support for `LIBSSH2_RC`. To override `windres`. - delete support for Metrowerks C. Last released in 2004. - `win32/libssh2_config.h`: delete unnecessary socket #includes `src/libssh2_priv.h` includes `winsock2.h` and `ws2tcpip.h` further down the line, triggered by `HAVE_WINSOCK2_H`. `mswsock.h` does not seem to be necessary anymore. Double-including these (before `windows.h`) caused compiler failures when building against BoringSSL and warnings with LibreSSL. We could work this around by passing `-DNOCRYPT`. Deleting the duplicates fixes these issues. Timeline: 2013: c910cd382dfa07fed2adaabf688af9e4a084fa1d deleted `mswsock.h` from `src/libssh2_priv.h` 2008: 8c43bc52b1e3de2c8fc7899a80aec0e98de4e2d8 added `winsock2.h` and `ws2tcpip.h` to `src/libssh2_priv.h` 2005: dc4bb1af967d2c53e90349f2f37324c622e714f5 added the now deleted #includes - delete or replace `LIBSSH2_WIN32` with `WIN32`. - replace hand-rolled `HAVE_WINDOWS_H` macro with `WIN32`. Also delete its detections/definitions. - delete unused `LIBSSH2_DARWIN` macro. - delete unused `writev()` Windows implementation There is no reference to `writev()` since 2007-02-02, commit 9d55db6501aa4e21f0858cf36cdc2ddc11b96e83. - fix a bunch of MSVC / llvm/clang / gcc compiler warnings: - `warning C4100: '...': unreferenced formal parameter` - using value of undefined PP macro `LIBSSH2DEBUG` - missing void from function definition - `if()` block missing in non-debug builds - unreferenced variable in non-debug builds - `warning: must specify at least one argument for '...' parameter of variadic macro [-Wgnu-zero-variadic-macro-arguments]` in `_libssh2_debug()` - `warning C4295: 'ciphertext' : array is too small to include a terminating null character` - `warning C4706: assignment within conditional expression` - `warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings` By suppressning it. Would be best to use inet_pton() as suggested. On Windows this needs Vista though. - `warning C4152: nonstandard extension, function/data pointer conversion in expression` (silenced locally) - `warning C4068: unknown pragma` Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46354480/job/j7d0m34qgq8rag5w Closes #808 --- Makefile.inc | 4 +-- acinclude.m4 | 2 -- cmake/max_warnings.cmake | 58 +++++++++++++++++++++++++++------ configure.ac | 2 -- example/direct_tcpip.c | 35 +++++++++----------- example/scp.c | 9 ++++- example/scp_nonblock.c | 11 +++++-- example/scp_write.c | 11 +++++-- example/scp_write_nonblock.c | 12 +++++-- example/sftp.c | 9 ++++- example/sftp_RW_nonblock.c | 5 +-- example/sftp_append.c | 9 ++++- example/sftp_mkdir.c | 9 ++++- example/sftp_mkdir_nonblock.c | 9 ++++- example/sftp_nonblock.c | 11 +++++-- example/sftp_write.c | 9 ++++- example/sftp_write_nonblock.c | 11 +++++-- example/sftp_write_sliding.c | 11 +++++-- example/sftpdir.c | 9 ++++- example/sftpdir_nonblock.c | 9 ++++- example/ssh2.c | 11 +++++-- example/ssh2_agent.c | 15 ++++++--- example/ssh2_agent_forwarding.c | 10 ++++-- example/ssh2_echo.c | 12 ++++--- example/ssh2_exec.c | 10 ++++-- example/subsystem_netconf.c | 17 +++++----- example/tcpip-forward.c | 25 +++++++------- include/libssh2.h | 6 ++-- os400/libssh2_config.h | 7 ---- src/CMakeLists.txt | 10 ------ src/agent.c | 8 ++--- src/agent_win.c | 4 +-- src/bcrypt_pbkdf.c | 7 ++-- src/hostkey.c | 8 +++-- src/kex.c | 8 ++--- src/libssh2_config_cmake.h.in | 1 - src/libssh2_priv.h | 40 ++++++++++++++--------- src/mbedtls.c | 6 ++-- src/misc.c | 13 ++------ src/misc.h | 2 +- src/pem.c | 4 +-- src/session.c | 19 ++++++++--- src/transport.c | 2 +- src/version.c | 2 +- src/wincng.c | 26 ++++++++++++--- tests/CMakeLists.txt | 2 -- tests/libssh2_config_cmake.h.in | 1 - tests/openssh_fixture.c | 8 ++++- tests/session_fixture.c | 2 +- tests/ssh2.c | 5 +-- win32/GNUmakefile | 39 +++++----------------- win32/Makefile.Watcom | 8 ++--- win32/config.mk | 3 -- win32/libssh2.rc | 2 +- win32/libssh2_config.h | 4 --- win32/msvcproj.head | 32 +++++++++--------- win32/test/GNUmakefile | 33 ++++--------------- win32/tests.dsp | 8 ++--- 58 files changed, 397 insertions(+), 268 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 651ff29ac5..29273f4aaf 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -2,8 +2,8 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ userauth_kbd_packet.c \ version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ - blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c os400qc3.h + blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c HHEADERS = libssh2_priv.h $(CRYPTO_HHEADERS) transport.h channel.h comp.h \ mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h blf.h agent.h \ - userauth_kbd_packet.h + userauth_kbd_packet.h os400qc3.h diff --git a/acinclude.m4 b/acinclude.m4 index 63d5d5cdb3..8afcd93c42 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -464,7 +464,6 @@ m4_case([$1], # Look for Windows Cryptography API: Next Generation AC_CHECK_HEADERS([ntdef.h ntstatus.h], [], [], [#include ]) - AC_CHECK_DECLS([SecureZeroMemory], [], [], [#include ]) LIBSSH2_LIB_HAVE_LINKFLAGS([crypt32], [], [ #include @@ -477,7 +476,6 @@ m4_case([$1], AC_DEFINE(LIBSSH2_WINCNG, 1, [Use $1]) found_crypto="$1" found_crypto_str="Windows Cryptography API: Next Generation" - support_clear_memory="$ac_cv_have_decl_SecureZeroMemory" ]) ], ) diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index b176d302d3..182738b72b 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -1,23 +1,61 @@ +include(CheckCCompilerFlag) + +option(ENABLE_WERROR "Turn compiler warnings into errors" OFF) +option(PICKY_COMPILER "Enable picky compiler options" ON) + +if(ENABLE_WERROR) + if(MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") + else() # llvm/clang and gcc style options + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + endif() +endif() + if(MSVC) # Use the highest warning level for visual studio. - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") - endif() - if(CMAKE_C_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") + if(PICKY_COMPILER) + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() + if(CMAKE_C_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") + endif() endif() # Disable broken warnings add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) -elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) +elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang") if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") endif() if(NOT CMAKE_C_FLAGS MATCHES "-Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") endif() + + if(PICKY_COMPILER) + foreach(_CCOPT -pedantic -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wfloat-equal -Wsign-compare -Wundef -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wvla -Wdouble-promotion -Wenum-conversion -Warith-conversion) + # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new + # test result in. + string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname) + check_c_compiler_flag(${_CCOPT} ${_optvarname}) + if(${_optvarname}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}") + endif() + endforeach() + foreach(_CCOPT long-long multichar format-nonliteral sign-conversion system-headers pedantic-ms-format) + # GCC only warns about unknown -Wno- options if there are also other diagnostic messages, + # so test for the positive form instead + string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname) + check_c_compiler_flag("-W${_CCOPT}" ${_optvarname}) + if(${_optvarname}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-${_CCOPT}") + endif() + endforeach() + endif() endif() diff --git a/configure.ac b/configure.ac index 3e2d02f3ba..24b851e4c6 100644 --- a/configure.ac +++ b/configure.ac @@ -33,11 +33,9 @@ AB_INIT AC_CANONICAL_HOST case "$host" in *-mingw*) - CFLAGS="$CFLAGS -DLIBSSH2_WIN32" LIBS="$LIBS -lws2_32" ;; *darwin*) - CFLAGS="$CFLAGS -DLIBSSH2_DARWIN" ;; *hpux*) ;; diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 4e1d90f489..5fb470264e 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -1,3 +1,9 @@ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -64,11 +70,12 @@ int main(int argc, char *argv[]) struct timeval tv; ssize_t len, wr; char buf[16384]; + libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; + libssh2_socket_t listensock = LIBSSH2_INVALID_SOCKET; + libssh2_socket_t forwardsock = LIBSSH2_INVALID_SOCKET; #ifdef WIN32 char sockopt; - SOCKET sock = INVALID_SOCKET; - SOCKET listensock = INVALID_SOCKET, forwardsock = INVALID_SOCKET; WSADATA wsadata; int err; @@ -78,8 +85,7 @@ int main(int argc, char *argv[]) return 1; } #else - int sockopt, sock = -1; - int listensock = -1, forwardsock = -1; + int sockopt; #endif if(argc > 1) @@ -105,17 +111,14 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if(sock == LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - if(sock == INVALID_SOCKET) { fprintf(stderr, "failed to open socket!\n"); - return -1; - } #else - if(sock == -1) { perror("socket"); +#endif return -1; } -#endif sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); @@ -193,17 +196,14 @@ int main(int argc, char *argv[]) } listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if(listensock == LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - if(listensock == INVALID_SOCKET) { fprintf(stderr, "failed to open listen socket!\n"); - return -1; - } #else - if(listensock == -1) { perror("socket"); +#endif return -1; } -#endif sin.sin_family = AF_INET; sin.sin_port = htons(local_listenport); @@ -229,17 +229,14 @@ int main(int argc, char *argv[]) inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); forwardsock = accept(listensock, (struct sockaddr *)&sin, &sinlen); + if(forwardsock == LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - if(forwardsock == INVALID_SOCKET) { fprintf(stderr, "failed to accept forward socket!\n"); - goto shutdown; - } #else - if(forwardsock == -1) { perror("accept"); +#endif goto shutdown; } -#endif shost = inet_ntoa(sin.sin_addr); sport = ntohs(sin.sin_port); diff --git a/example/scp.c b/example/scp.c index 9ad1e7d407..2076daa497 100644 --- a/example/scp.c +++ b/example/scp.c @@ -2,6 +2,12 @@ * Sample showing how to do a simple SCP transfer. */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -33,7 +39,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index b8317a279c..e2adc652ba 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -7,6 +7,12 @@ * "scp_nonblock 192.168.0.1 user password /tmp/secrets" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -47,7 +53,7 @@ static long tvdiff(struct timeval newer, struct timeval older) } #endif -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -80,7 +86,8 @@ static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/scp_write.c b/example/scp_write.c index 150c5e470f..58585bef8f 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -2,6 +2,12 @@ * Sample showing how to do an SCP upload. */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -33,7 +39,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session = NULL; @@ -98,7 +105,7 @@ int main(int argc, char *argv[]) * connection */ sock = socket(AF_INET, SOCK_STREAM, 0); - if(-1 == sock) { + if(sock == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "failed to create socket!\n"); return -1; } diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 9226322e9a..6179a0a59c 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -2,8 +2,13 @@ * Sample showing how to do an SCP non-blocking upload transfer. */ -#include "libssh2_config.h" +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif +#include "libssh2_config.h" #include #ifdef HAVE_WINSOCK2_H @@ -35,7 +40,7 @@ #include #include -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -68,7 +73,8 @@ static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session = NULL; diff --git a/example/sftp.c b/example/sftp.c index 8f67244a6c..d1e1d508e0 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -7,6 +7,12 @@ * "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -96,7 +102,8 @@ static void kbd_callback(const char *name, int name_len, int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 0; + libssh2_socket_t sock; + int i, auth_pw = 0; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 70d87db35d..8b57c30f82 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -43,7 +43,7 @@ example uses to store the downloaded file in */ -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -75,7 +75,8 @@ static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftp_append.c b/example/sftp_append.c index bfea1f7277..7ad7306838 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -7,6 +7,12 @@ * sftp_append 192.168.0.1 user password localfile /tmp/remotefile */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -36,7 +42,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 2347abe425..ab51a4f330 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -7,6 +7,12 @@ * "sftp 192.168.0.1 user password /tmp/sftp_mkdir" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -36,7 +42,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index 217cc4b3da..dfbf44c98a 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -7,6 +7,12 @@ * "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -36,7 +42,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 8ef091e1f2..7cbf8630d8 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -7,6 +7,12 @@ * "sftp_nonblock 192.168.0.1 user password /tmp/secrets" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -48,7 +54,7 @@ static long tvdiff(struct timeval newer, struct timeval older) } #endif -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -81,7 +87,8 @@ static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftp_write.c b/example/sftp_write.c index c1350e9cb5..758dc2549e 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -7,6 +7,12 @@ * "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -36,7 +42,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 934749ea73..16400c670b 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -7,6 +7,12 @@ * "sftp 192.168.0.1 user password thisfile /tmp/storehere" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -40,7 +46,7 @@ #include #include -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -73,7 +79,8 @@ static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 9a72140f44..2e9b75b600 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -7,6 +7,12 @@ * "sftp 192.168.0.1 user password file /tmp/storehere" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -40,7 +46,7 @@ #include #include -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -73,7 +79,8 @@ static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/sftpdir.c b/example/sftpdir.c index 4b6af8869f..3ca3bbf635 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -7,6 +7,12 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -69,7 +75,8 @@ static void kbd_callback(const char *name, int name_len, int main(int argc, char *argv[]) { unsigned long hostaddr; - int rc, sock, i, auth_pw = 0; + libssh2_socket_t sock; + int rc, i, auth_pw = 0; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index abc4ff4819..d8fa32fc7c 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -7,6 +7,12 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include @@ -45,7 +51,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 1; + libssh2_socket_t sock; + int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/ssh2.c b/example/ssh2.c index 9b1ce1d8f9..9fe7168b6a 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -11,11 +11,17 @@ * command executes on the remote machine */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include -#ifdef HAVE_WINDOWS_H +#ifdef WIN32 # include #endif #ifdef HAVE_WINSOCK2_H @@ -74,7 +80,8 @@ static void kbd_callback(const char *name, int name_len, int main(int argc, char *argv[]) { unsigned long hostaddr; - int rc, sock, i, auth_pw = 0; + libssh2_socket_t sock; + int rc, i, auth_pw = 0; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 1cc508442c..e4a713cb4f 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -6,11 +6,17 @@ * "ssh2_agent host user" */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include #include -#ifdef HAVE_WINDOWS_H +#ifdef WIN32 # include #endif #ifdef HAVE_WINSOCK2_H @@ -41,7 +47,8 @@ const char *username = "username"; int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock = -1, i, rc; + libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; + int i, rc; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; @@ -82,7 +89,7 @@ int main(int argc, char *argv[]) * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); - if(sock == -1) { + if(sock == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "failed to create socket!\n"); rc = 1; goto shutdown; @@ -237,7 +244,7 @@ int main(int argc, char *argv[]) libssh2_session_free(session); } - if(sock != -1) { + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 closesocket(sock); #else diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index f86079d83e..c65e00362a 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -13,6 +13,12 @@ * */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -45,7 +51,7 @@ #include #include -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -81,7 +87,7 @@ int main(int argc, char *argv[]) const char *commandline = "uptime"; const char *username = NULL; unsigned long hostaddr; - int sock; + libssh2_socket_t sock; struct sockaddr_in sin; LIBSSH2_SESSION *session; LIBSSH2_CHANNEL *channel; diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index 937c438c43..1ebd9e971c 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -8,6 +8,12 @@ * */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -41,7 +47,7 @@ #include #include -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -80,7 +86,7 @@ int main(int argc, char *argv[]) const char *username = "user"; const char *password = "password"; unsigned long hostaddr; - int sock; + libssh2_socket_t sock; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; @@ -231,7 +237,6 @@ int main(int argc, char *argv[]) int totsize = 1500000; int totwritten = 0; int totread = 0; - int partials = 0; int rereads = 0; int rewrites = 0; int i; @@ -297,7 +302,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "wrote %d bytes (%d in total)", n, totwritten); if(left >= bufsize && n != bufsize) { - partials++; fprintf(stderr, " PARTIAL"); } fprintf(stderr, "\n"); diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 1c11849e0d..2073e85ad7 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -10,6 +10,12 @@ * */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -43,7 +49,7 @@ #include #include -static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) +static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; int rc; @@ -80,7 +86,7 @@ int main(int argc, char *argv[]) const char *username = "user"; const char *password = "password"; unsigned long hostaddr; - int sock; + libssh2_socket_t sock; struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index cef25fee31..e53cfa5f4d 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -1,3 +1,9 @@ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -120,9 +126,9 @@ int main(int argc, char *argv[]) LIBSSH2_CHANNEL *channel = NULL; char buf[1048576]; /* avoid any buffer reallocation for simplicity */ ssize_t len; + libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; #ifdef WIN32 - SOCKET sock = INVALID_SOCKET; WSADATA wsadata; int err; @@ -131,8 +137,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "WSAStartup failed with error: %d\n", err); return 1; } -#else - int sock = -1; #endif if(argc > 1) @@ -150,17 +154,14 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if(sock == LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - if(sock == INVALID_SOCKET) { fprintf(stderr, "failed to open socket!\n"); - return -1; - } #else - if(sock == -1) { perror("socket"); +#endif return -1; } -#endif sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 51ca17ab15..6ed4466d16 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -1,3 +1,9 @@ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "libssh2_config.h" #include @@ -64,9 +70,10 @@ int main(int argc, char *argv[]) struct timeval tv; ssize_t len, wr; char buf[16384]; + libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; + libssh2_socket_t forwardsock = LIBSSH2_INVALID_SOCKET; #ifdef WIN32 - SOCKET sock = INVALID_SOCKET, forwardsock = INVALID_SOCKET; WSADATA wsadata; int err; @@ -75,8 +82,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "WSAStartup failed with error: %d\n", err); return 1; } -#else - int sock = -1, forwardsock = -1; #endif if(argc > 1) @@ -102,17 +107,14 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if(sock == LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - if(sock == INVALID_SOCKET) { fprintf(stderr, "failed to open socket!\n"); - return -1; - } #else - if(sock == -1) { perror("socket"); +#endif return -1; } -#endif sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); @@ -217,17 +219,14 @@ int main(int argc, char *argv[]) "Accepted remote connection. Connecting to local server %s:%d\n", local_destip, local_destport); forwardsock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if(forwardsock == LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - if(forwardsock == INVALID_SOCKET) { fprintf(stderr, "failed to open forward socket!\n"); - goto shutdown; - } #else - if(forwardsock == -1) { perror("socket"); +#endif goto shutdown; } -#endif sin.sin_family = AF_INET; sin.sin_port = htons(local_destport); diff --git a/include/libssh2.h b/include/libssh2.h index b79569da31..f7c95cbcfe 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -99,7 +99,7 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API -# ifdef LIBSSH2_WIN32 +# ifdef WIN32 # if defined(_WINDLL) || defined(libssh2_EXPORTS) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) @@ -109,9 +109,9 @@ extern "C" { # else # define LIBSSH2_API # endif -# else /* !LIBSSH2_WIN32 */ +# else /* !WIN32 */ # define LIBSSH2_API -# endif /* LIBSSH2_WIN32 */ +# endif /* WIN32 */ #endif /* LIBSSH2_API */ #ifdef HAVE_SYS_UIO_H diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index c6ef132798..6ec04da14a 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -59,10 +59,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_ARPA_INET_H 1 -/* Define to 1 if you have the declaration of `SecureZeroMemory', and to 0 if - you don't. */ -#undef HAVE_DECL_SECUREZEROMEMORY - /* disabled non-blocking sockets */ #undef HAVE_DISABLED_NONBLOCKING @@ -180,9 +176,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 -/* Define to 1 if you have the header file. */ -#undef HAVE_WINDOWS_H - /* Define to 1 if you have the header file. */ #undef HAVE_WINSOCK2_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 17ecefd07c..b086ac7f57 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -298,7 +298,6 @@ check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files(sys/un.h HAVE_SYS_UN_H) -check_include_files(windows.h HAVE_WINDOWS_H) check_include_files(ws2tcpip.h HAVE_WS2TCPIP_H) check_include_files(winsock2.h HAVE_WINSOCK2_H) @@ -354,15 +353,6 @@ configure_file( # to find generated header target_include_directories(libssh2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -# Check for the OS. -# Daniel's note: this should not be necessary and we need to work to -# get this removed. -if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - target_compile_definitions(libssh2 PRIVATE LIBSSH2_WIN32) -elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - target_compile_definitions(libssh2 PRIVATE LIBSSH2_DARWIN) -endif() - if(MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od") set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG") diff --git a/src/agent.c b/src/agent.c index 4ed79ac274..7fccce02d7 100644 --- a/src/agent.c +++ b/src/agent.c @@ -249,7 +249,7 @@ struct agent_ops agent_ops_unix = { }; #endif /* PF_UNIX */ -#ifdef WIN32 +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) /* Code to talk to Pageant was taken from PuTTY. * * Portions copyright Robert de Bath, Joris van Rantwijk, Delian @@ -352,16 +352,16 @@ struct agent_ops agent_ops_pageant = { agent_transact_pageant, agent_disconnect_pageant }; -#endif /* WIN32 */ +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) */ static struct { const char *name; struct agent_ops *ops; } supported_backends[] = { -#ifdef WIN32 +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) {"Pageant", &agent_ops_pageant}, {"OpenSSH", &agent_ops_openssh}, -#endif /* WIN32 */ +#endif #ifdef PF_UNIX {"Unix", &agent_ops_unix}, #endif /* PF_UNIX */ diff --git a/src/agent_win.c b/src/agent_win.c index a1605a95fc..4636140e82 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -55,7 +55,7 @@ #include #endif -#ifdef WIN32 +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) /* Code to talk to OpenSSH was taken and modified from the Win32 port of * Portable OpenSSH by the PowerShell team. Commit * 8ab565c53f3619d6a1f5ac229e212cad8a52852c of @@ -358,4 +358,4 @@ struct agent_ops agent_ops_openssh = { agent_transact_openssh, agent_disconnect_openssh }; -#endif /* WIN32 */ +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) */ diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 822d117640..98470c53fd 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -60,8 +60,11 @@ static void bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out) { blf_ctx state; - uint8_t ciphertext[BCRYPT_HASHSIZE] = - "OxychromaticBlowfishSwatDynamite"; + uint8_t ciphertext[BCRYPT_HASHSIZE] = { + 'O', 'x', 'y', 'c', 'h', 'r', 'o', 'm', 'a', 't', 'i', 'c', + 'B', 'l', 'o', 'w', 'f', 'i', 's', 'h', + 'S', 'w', 'a', 't', + 'D', 'y', 'n', 'a', 'm', 'i', 't', 'e' }; uint32_t cdata[BCRYPT_BLOCKS]; int i; uint16_t j; diff --git a/src/hostkey.c b/src/hostkey.c index 6004122d08..391af056b4 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -302,7 +302,9 @@ hostkey_method_ssh_rsa_sha2_256_signv(LIBSSH2_SESSION * session, unsigned char hash[SHA256_DIGEST_LENGTH]; libssh2_sha256_ctx ctx; - libssh2_sha256_init(&ctx); + if(!libssh2_sha256_init(&ctx)) { + return -1; + } for(i = 0; i < veccount; i++) { libssh2_sha256_update(ctx, datavec[i].iov_base, datavec[i].iov_len); } @@ -370,7 +372,9 @@ hostkey_method_ssh_rsa_sha2_512_signv(LIBSSH2_SESSION * session, unsigned char hash[SHA512_DIGEST_LENGTH]; libssh2_sha512_ctx ctx; - libssh2_sha512_init(&ctx); + if(!libssh2_sha512_init(&ctx)) { + return -1; + } for(i = 0; i < veccount; i++) { libssh2_sha512_update(ctx, datavec[i].iov_base, datavec[i].iov_len); } diff --git a/src/kex.c b/src/kex.c index 20bf8b0dae..a1d12b113e 100644 --- a/src/kex.c +++ b/src/kex.c @@ -144,7 +144,7 @@ static void _libssh2_sha_algo_ctx_update(int sha_algo, void *ctx, libssh2_sha1_update(*_ctx, data, len); } else { -#if LIBSSH2DEBUG +#ifdef LIBSSH2DEBUG assert(0); #endif } @@ -170,7 +170,7 @@ static void _libssh2_sha_algo_ctx_final(int sha_algo, void *ctx, libssh2_sha1_final(*_ctx, hash); } else { -#if LIBSSH2DEBUG +#ifdef LIBSSH2DEBUG assert(0); #endif } @@ -195,7 +195,7 @@ static void _libssh2_sha_algo_value_hash(int sha_algo, LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(1, *data, data_len, version); } else { -#if LIBSSH2DEBUG +#ifdef LIBSSH2DEBUG assert(0); #endif } @@ -3326,7 +3326,7 @@ kex_agree_instr(unsigned char *haystack, unsigned long haystack_len, /* Search until we run out of comas or we run out of haystack, whichever comes first */ - while((s = (unsigned char *) memchr((char *) s, ',', left))) { + while((s = (unsigned char *) memchr((char *) s, ',', left)) != NULL) { /* Advance buffer past coma if we can */ left = end_haystack - s; if((left >= 1) && (left <= haystack_len) && (left > needle_len)) { diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 62723ede84..4004792470 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -45,7 +45,6 @@ #cmakedefine HAVE_SYS_IOCTL_H #cmakedefine HAVE_SYS_TIME_H #cmakedefine HAVE_SYS_UN_H -#cmakedefine HAVE_WINDOWS_H #cmakedefine HAVE_WS2TCPIP_H #cmakedefine HAVE_WINSOCK2_H #cmakedefine HAVE_NTDEF_H diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index b3ce7af766..4bf17f9f41 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -42,12 +42,34 @@ #define LIBSSH2_LIBRARY #include "libssh2_config.h" -#ifdef HAVE_WINDOWS_H +#ifdef WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include #undef WIN32_LEAN_AND_MEAN + +/* Detect Windows App environment which has a restricted access + to the Win32 APIs. */ +# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ + defined(WINAPI_FAMILY) +# include +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define LIBSSH2_WINDOWS_APP +# endif +# endif + +/* TODO: Enable this unconditionally for all platforms. + Also delete autotools logic that enables it only for mbedTLS. + And CMake logic which already enabled it unconditionally. + The actual memory clearing logic uses SecureZeroMemory(), + memset_s() or plain memset(), whichever is available, and + does not depend on any crypto backend function. */ +#ifndef LIBSSH2_CLEAR_MEMORY +#define LIBSSH2_CLEAR_MEMORY +#endif + #endif #ifdef HAVE_WS2TCPIP_H @@ -119,20 +141,6 @@ struct iovec { #endif -/* Provide iovec / writev on WIN32 platform. */ -#ifdef WIN32 - -static inline int writev(int sock, struct iovec *iov, int nvecs) -{ - DWORD ret; - if(WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) { - return ret; - } - return -1; -} - -#endif /* WIN32 */ - #ifdef __OS400__ /* Force parameter type. */ #define send(s, b, l, f) send((s), (unsigned char *) (b), (l), (f)) @@ -976,7 +984,7 @@ void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ defined(__GNUC__) /* C99 supported and also by older GCC */ -#define _libssh2_debug(x,y,z,...) do {} while (0) +#define _libssh2_debug(x,y,...) do {} while (0) #else /* no gcc and not C99, do static and hopefully inline */ static inline void diff --git a/src/mbedtls.c b/src/mbedtls.c index 6326981dfc..ba0229a1ab 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -93,16 +93,14 @@ _libssh2_mbedtls_random(unsigned char *buf, int len) static void _libssh2_mbedtls_safe_free(void *buf, int len) { -#ifndef LIBSSH2_CLEAR_MEMORY - (void)len; -#endif - if(!buf) return; #ifdef LIBSSH2_CLEAR_MEMORY if(len > 0) _libssh2_explicit_zero(buf, len); +#else + (void)len; #endif mbedtls_free(buf); diff --git a/src/misc.c b/src/misc.c index 84d165c2f5..933a2041cb 100644 --- a/src/misc.c +++ b/src/misc.c @@ -53,11 +53,9 @@ #include #endif -#if defined(HAVE_DECL_SECUREZEROMEMORY) && HAVE_DECL_SECUREZEROMEMORY -#ifdef HAVE_WINDOWS_H +#ifdef WIN32 #include #endif -#endif #include #include @@ -717,21 +715,16 @@ void _libssh2_aes_ctr_increment(unsigned char *ctr, } } -#ifdef WIN32 -static void * (__cdecl * const volatile memset_libssh)(void *, int, size_t) = - memset; -#else +#if !defined(WIN32) && !defined(HAVE_MEMSET_S) static void * (* const volatile memset_libssh)(void *, int, size_t) = memset; #endif void _libssh2_explicit_zero(void *buf, size_t size) { -#if defined(HAVE_DECL_SECUREZEROMEMORY) && HAVE_DECL_SECUREZEROMEMORY +#ifdef WIN32 SecureZeroMemory(buf, size); - (void)memset_libssh; /* Silence unused variable warning */ #elif defined(HAVE_MEMSET_S) (void)memset_s(buf, size, 0, size); - (void)memset_libssh; /* Silence unused variable warning */ #else memset_libssh(buf, 0, size); #endif diff --git a/src/misc.h b/src/misc.h index 4e355fcd78..2e7af32af2 100644 --- a/src/misc.h +++ b/src/misc.h @@ -108,7 +108,7 @@ int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf, int _libssh2_check_length(struct string_buf *buf, size_t requested_len); int _libssh2_eob(struct string_buf *buf); -#if defined(LIBSSH2_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) +#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) /* provide a private one */ #undef HAVE_GETTIMEOFDAY int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp); diff --git a/src/pem.c b/src/pem.c index 3416bd528a..12405cf67f 100644 --- a/src/pem.c +++ b/src/pem.c @@ -141,7 +141,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, } all_methods = libssh2_crypt_methods(); - while((cur_method = *all_methods++)) { + while((cur_method = *all_methods++) != NULL) { if(*cur_method->pem_annotation && memcmp(line, cur_method->pem_annotation, strlen(cur_method->pem_annotation)) == 0) { @@ -490,7 +490,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, const LIBSSH2_CRYPT_METHOD **all_methods, *cur_method; all_methods = libssh2_crypt_methods(); - while((cur_method = *all_methods++)) { + while((cur_method = *all_methods++) != NULL) { if(*cur_method->name && memcmp(ciphername, cur_method->name, strlen(cur_method->name)) == 0) { diff --git a/src/session.c b/src/session.c index 235ab95b9d..608c254d1c 100644 --- a/src/session.c +++ b/src/session.c @@ -347,7 +347,7 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ * gets the given blocking or non-blocking state of the socket. */ static int -get_socket_nonblocking(int sockfd) +get_socket_nonblocking(libssh2_socket_t sockfd) { /* operate on this */ #undef GETBLOCK #define GETBLOCK 0 @@ -520,8 +520,14 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), * ALERT: this function relies on that we can typecast function pointers * to void pointers, which isn't allowed in ISO C! */ +#ifdef _MSC_VER +#pragma warning(push) +/* nonstandard extension, function/data pointer conversion in expression */ +#pragma warning(disable:4152) +#else #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" +#endif LIBSSH2_API void * libssh2_session_callback_set(LIBSSH2_SESSION * session, int cbtype, void *callback) @@ -569,7 +575,11 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session, return NULL; } +#ifdef _MSC_VER +#pragma warning(pop) +#else #pragma GCC diagnostic pop +#endif /* * _libssh2_wait_socket() @@ -876,7 +886,7 @@ session_free(LIBSSH2_SESSION *session) } if(session->free_state == libssh2_NB_state_created) { - while((ch = _libssh2_list_first(&session->channels))) { + while((ch = _libssh2_list_first(&session->channels)) != NULL) { rc = _libssh2_channel_free(ch); if(rc == LIBSSH2_ERROR_EAGAIN) @@ -887,7 +897,7 @@ session_free(LIBSSH2_SESSION *session) } if(session->free_state == libssh2_NB_state_sent) { - while((l = _libssh2_list_first(&session->listeners))) { + while((l = _libssh2_list_first(&session->listeners)) != NULL) { rc = _libssh2_channel_forward_cancel(l); if(rc == LIBSSH2_ERROR_EAGAIN) return rc; @@ -1073,7 +1083,7 @@ session_free(LIBSSH2_SESSION *session) } /* Cleanup all remaining packets */ - while((pkg = _libssh2_list_first(&session->packets))) { + while((pkg = _libssh2_list_first(&session->packets)) != NULL) { packets_left++; _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "packet left with id %d", pkg->data[0]); @@ -1084,6 +1094,7 @@ session_free(LIBSSH2_SESSION *session) LIBSSH2_FREE(session, pkg->data); LIBSSH2_FREE(session, pkg); } + (void)packets_left; _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Extra packets left %d", packets_left); diff --git a/src/transport.c b/src/transport.c index 04ced8f747..f591ce689f 100644 --- a/src/transport.c +++ b/src/transport.c @@ -118,7 +118,7 @@ debugdump(LIBSSH2_SESSION * session, } } #else -#define debugdump(a,x,y,z) +#define debugdump(a,x,y,z) do {} while(0) #endif diff --git a/src/version.c b/src/version.c index 0e2366694e..c54d57cd23 100644 --- a/src/version.c +++ b/src/version.c @@ -54,7 +54,7 @@ const char *libssh2_version(int req_version_num) } LIBSSH2_API -libssh2_crypto_engine_t libssh2_crypto_engine() +libssh2_crypto_engine_t libssh2_crypto_engine(void) { #if defined LIBSSH2_OPENSSL return libssh2_openssl; diff --git a/src/wincng.c b/src/wincng.c index ad1e52ab26..28ac1278e8 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -58,7 +58,6 @@ #include #include -#include #include #include "misc.h" @@ -75,6 +74,12 @@ #define PEM_DSA_FOOTER "-----END DSA PRIVATE KEY-----" +/* Define this manually to avoid including and thus + clashing with symbols. */ +#ifndef STATUS_NOT_SUPPORTED +#define STATUS_NOT_SUPPORTED ((NTSTATUS)0xC00000BB) +#endif + /*******************************************************************/ /* * Windows CNG backend: Missing definitions (for MinGW[-w64]) @@ -427,16 +432,14 @@ _libssh2_wincng_random(void *buf, int len) static void _libssh2_wincng_safe_free(void *buf, int len) { -#ifndef LIBSSH2_CLEAR_MEMORY - (void)len; -#endif - if(!buf) return; #ifdef LIBSSH2_CLEAR_MEMORY if(len > 0) SecureZeroMemory(buf, len); +#else + (void)len; #endif free(buf); @@ -1849,6 +1852,19 @@ _libssh2_wincng_sk_pub_keyfilememory(LIBSSH2_SESSION *session, size_t privatekeydata_len, const char *passphrase) { + (void)method; + (void)method_len; + (void)pubkeydata; + (void)pubkeydata_len; + (void)algorithm; + (void)flags; + (void)application; + (void)key_handle; + (void)handle_len; + (void)privatekeydata; + (void)privatekeydata_len; + (void)passphrase; + return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public SK key from private key file: " "Method unimplemented in Windows CNG backend"); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8f231e27f5..f391c86062 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,7 +36,6 @@ include(CheckIncludeFiles) include(CheckFunctionExists) include(CheckSymbolExists) -include(BundleUtilities) include(CopyRuntimeDependencies) include(SocketLibraries) @@ -46,7 +45,6 @@ check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(sys/param.h HAVE_SYS_PARAM_H) check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(arpa/inet.h HAVE_ARPA_INET_H) -check_include_files(windows.h HAVE_WINDOWS_H) check_include_files(winsock2.h HAVE_WINSOCK2_H) check_include_files(netinet/in.h HAVE_NETINET_IN_H) configure_file( diff --git a/tests/libssh2_config_cmake.h.in b/tests/libssh2_config_cmake.h.in index 4df27ecdc0..f75711a33b 100644 --- a/tests/libssh2_config_cmake.h.in +++ b/tests/libssh2_config_cmake.h.in @@ -41,7 +41,6 @@ #cmakedefine HAVE_SYS_SOCKET_H #cmakedefine HAVE_ARPA_INET_H #cmakedefine HAVE_NETINET_IN_H -#cmakedefine HAVE_WINDOWS_H #cmakedefine HAVE_WINSOCK2_H #cmakedefine HAVE_SNPRINTF diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 50ff0d940c..9c358eaea8 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -35,6 +35,12 @@ * OF SUCH DAMAGE. */ +#ifdef WIN32 +#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#endif +#endif + #include "openssh_fixture.h" #include "session_fixture.h" #include "libssh2_config.h" @@ -326,7 +332,7 @@ static int open_socket_to_container(char *container_id) char *ip_address = NULL; char *port_string = NULL; unsigned long hostaddr; - int sock; + libssh2_socket_t sock; struct sockaddr_in sin; int counter = 0; int ret; diff --git a/tests/session_fixture.c b/tests/session_fixture.c index dc200b5c50..6e836565d5 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -45,7 +45,7 @@ #include #endif -#ifdef HAVE_WINDOWS_H +#ifdef WIN32 #include #endif #ifdef HAVE_WINSOCK2_H diff --git a/tests/ssh2.c b/tests/ssh2.c index f903e07585..983cc05128 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -4,7 +4,7 @@ #include #include -#ifdef HAVE_WINDOWS_H +#ifdef WIN32 # include #endif #ifdef HAVE_WINSOCK2_H @@ -33,7 +33,8 @@ int main(int argc, char *argv[]) { unsigned long hostaddr; - int sock, i, auth_pw = 0; + libssh2_socket_t sock; + int i, auth_pw = 0; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 86bf0ed35f..4c74cd3529 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -86,6 +86,9 @@ CAT = type ECHONL = $(ComSpec) /c echo. endif +ifeq ($(LIBSSH2_RC),) +LIBSSH2_RC := $(CROSSPREFIX)windres +endif ifeq ($(LIBSSH2_CC),) LIBSSH2_CC := $(CROSSPREFIX)gcc endif @@ -101,12 +104,7 @@ endif libssh2_dll_LIBRARY = $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll -# The following line defines your compiler. -ifdef METROWERKS - CC = mwcc -else - CC = $(LIBSSH2_CC) -endif +CC = $(LIBSSH2_CC) # Set environment var ARCH to your architecture to override autodetection. ifndef ARCH @@ -125,27 +123,12 @@ endif -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) -DLIBSSH2_WIN32 -DHAVE_WINDOWS_H # -DHAVE_CONFIG_H +CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) LDFLAGS = $(LIBSSH2_LDFLAG_EXTRAS) -ifeq ($(CC),mwcc) -LD = mwld -RC = mwwinrc -LDFLAGS += -nostdlib -AR = $(LD) -ARFLAGS = -nostdlib -library -o -LIBEXT = lib -#RANLIB = -LIBPATH += -lr "$(METROWERKS)/MSL" -lr "$(METROWERKS)/Win32-x86 Support" -LDLIBS += -lMSL_Runtime_x86.lib -lMSL_C_x86.lib -lMSL_Extras_x86.lib -RCFLAGS = -CFLAGS += -nostdinc -gccinc -msgstyle gcc -inline off -opt nointrinsics -proc 586 -CFLAGS += -ir "$(METROWERKS)/MSL" -ir "$(METROWERKS)/Win32-x86 Support" -CFLAGS += -w on,nounused,nounusedexpr # -ansi strict -else LIBEXT = a LD = $(LIBSSH2_CC) -RC = $(CROSSPREFIX)windres +RC = $(LIBSSH2_RC) LDFLAGS += -s -shared -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT) AR = $(LIBSSH2_AR) ARFLAGS = cru @@ -155,10 +138,11 @@ CFLAGS += -fno-builtin CFLAGS += -fno-strict-aliasing CFLAGS += -Wall # -pedantic ifeq ($(ARCH),w64) -CFLAGS += -m64 -D_AMD64_ +CFLAGS += -m64 LDFLAGS += -m64 RCFLAGS += -F pe-x86-64 else +ifeq ($(ARCH),w32) CFLAGS += -m32 LDFLAGS += -m32 RCFLAGS += -F pe-i386 @@ -208,12 +192,7 @@ else endif endif endif -ifeq ($(CC),mwcc) -LDLIBS += -lkernel32.lib -luser32.lib -lwsock32.lib -else -#LDLIBS += -lwsock32 LDLIBS += -lws2_32 -endif ifdef WITH_ZLIB CFLAGS += -DLIBSSH2_HAVE_ZLIB @@ -338,7 +317,7 @@ $(libssh2_dll_LIBRARY) $(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT): $(OBJL) $(OBJDIR)/%.res: %.rc @echo Creating $@ - @$(RC) $(RCFLAGS) -i $< -o $@ + @$(RC) $(RCFLAGS) $(LIBSSH2_RCFLAG_EXTRAS) -i $< -o $@ $(DISTDIR)/readme.txt: GNUmakefile diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom index 1e8cede628..8aa9d31ba6 100644 --- a/win32/Makefile.Watcom +++ b/win32/Makefile.Watcom @@ -34,17 +34,17 @@ RC = wrc ! endif !endif -!if $(__VERSION__) < 1250 +!if $(__VERSION__) < 1250 RM = del /q /f 2>NUL -!else -RM = rm -f +!else +RM = rm -f !endif MD = mkdir RD = rmdir /q /s 2>NUL CP = copy CFLAGS = -3r -mf -hc -zff -zgf -zq -zm -zc -s -fr=nul -w2 -fpi -oilrtfm & - -wcd=201 -bt=nt -d+ -dWIN32 -DLIBSSH2_WIN32 & + -wcd=201 -bt=nt -d+ -dWIN32 & -I. -I..\include $(SYS_INCL) !ifdef %debug diff --git a/win32/config.mk b/win32/config.mk index 21fe2e551c..84ee608c2b 100644 --- a/win32/config.mk +++ b/win32/config.mk @@ -1,4 +1,3 @@ - # Tweak these for your system !if "$(OPENSSLINC)" == "" OPENSSLINC=..\openssl-0.9.8zc\inc32 @@ -50,5 +49,3 @@ DLLFLAGS=$(CFLAGS) $(DLLFLAGS) LIBS=$(LIBS) ws2_32.lib user32.lib advapi32.lib gdi32.lib INTDIR=$(TARGET)\$(SUBDIR) - - diff --git a/win32/libssh2.rc b/win32/libssh2.rc index f5d607a726..04a30a405e 100644 --- a/win32/libssh2.rc +++ b/win32/libssh2.rc @@ -33,7 +33,7 @@ BEGIN VALUE "OriginalFilename", "libssh2.dll\0" VALUE "ProductName", "The libssh2 library\0" VALUE "ProductVersion", LIBSSH2_VERSION "\0" - VALUE "LegalCopyright", " " LIBSSH2_COPYRIGHT "\0" + VALUE "LegalCopyright", "Copyright (C) " LIBSSH2_COPYRIGHT "\0" VALUE "License", "https://www.libssh2.org/license.html\0" END END diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 6ac2ef43eb..0da35c4851 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -7,9 +7,6 @@ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE 1 #endif /* _CRT_SECURE_NO_DEPRECATE */ -#include -#include -#include #ifdef __MINGW32__ #define HAVE_UNISTD_H @@ -44,4 +41,3 @@ #define LIBSSH2_DH_GEX_NEW 1 #endif /* LIBSSH2_CONFIG_H */ - diff --git a/win32/msvcproj.head b/win32/msvcproj.head index eb820201dc..b1569a99af 100644 --- a/win32/msvcproj.head +++ b/win32/msvcproj.head @@ -50,8 +50,8 @@ RSC=rc.exe # PROP Intermediate_Dir "Release_dll" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c # SUBTRACT CPP /YX # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 @@ -77,8 +77,8 @@ LINK32=link.exe # PROP Intermediate_Dir "Debug_dll" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c # SUBTRACT CPP /WX /YX # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 @@ -104,8 +104,8 @@ LINK32=link.exe # PROP Output_Dir "Release_lib" # PROP Intermediate_Dir "Release_lib" # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -128,8 +128,8 @@ LIB32=link.exe -lib # PROP Output_Dir "Debug_lib" # PROP Intermediate_Dir "Debug_lib" # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -152,8 +152,8 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "Release_dll" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c # SUBTRACT CPP /YX # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 @@ -179,8 +179,8 @@ LINK32=link.exe # PROP Intermediate_Dir "Debug_dll" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c # SUBTRACT CPP /WX /YX # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 @@ -206,8 +206,8 @@ LINK32=link.exe # PROP Output_Dir "Release_lib" # PROP Intermediate_Dir "Release_lib" # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -230,8 +230,8 @@ LIB32=link.exe -lib # PROP Output_Dir "Debug_lib" # PROP Intermediate_Dir "Debug_lib" # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/win32/test/GNUmakefile b/win32/test/GNUmakefile index 5cf6e8cf69..8cfedb622f 100644 --- a/win32/test/GNUmakefile +++ b/win32/test/GNUmakefile @@ -77,12 +77,7 @@ CAT = type ECHONL = $(ComSpec) /c echo. endif -# The following line defines your compiler. -ifdef METROWERKS - CC = mwcc -else - CC = $(CROSSPREFIX)gcc -endif +CC = $(CROSSPREFIX)gcc # Set environment var ARCH to your architecture to override autodetection. ifndef ARCH @@ -101,23 +96,8 @@ endif -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS = $(OPT) -D$(DB) -DLIBSSH2_WIN32 # -DHAVE_CONFIG_H - -ifeq ($(CC),mwcc) -LD = mwld -RC = mwwinrc -LDFLAGS = -nostdlib -AR = $(LD) -ARFLAGS = -nostdlib -library -o -LIBEXT = lib -LIBPATH += -lr "$(METROWERKS)/MSL" -lr "$(METROWERKS)/Win32-x86 Support" -LDLIBS += -lMSL_Runtime_x86.lib -lMSL_C_x86.lib -lMSL_Extras_x86.lib -LDLIBS += -lkernel32.lib -luser32.lib -lwsock32.lib -RCFLAGS = -CFLAGS += -nostdinc -gccinc -msgstyle gcc -inline off -opt nointrinsics -proc 586 -CFLAGS += -ir "$(METROWERKS)/MSL" -ir "$(METROWERKS)/Win32-x86 Support" -CFLAGS += -w on,nounused,nounusedexpr # -ansi strict -else +CFLAGS = $(OPT) -D$(DB) + LD = $(CROSSPREFIX)gcc RC = $(CROSSPREFIX)windres LDFLAGS = -s @@ -131,9 +111,10 @@ CFLAGS += -fno-builtin CFLAGS += -fno-strict-aliasing CFLAGS += -Wall #-Wno-unused #-pedantic ifeq ($(ARCH),w64) -CFLAGS += -D_AMD64_ +CFLAGS += -m64 RCFLAGS += -F pe-x86-64 else +ifeq ($(ARCH),w32) CFLAGS += -m32 RCFLAGS += -F pe-i386 endif @@ -230,7 +211,7 @@ $(OBJDIR): $(OBJDIR)/%.res: $(OBJDIR)/%.rc @echo Creating $@ - @$(RC) $(RCFLAGS) -i $< -o $@ + @$(RC) $(RCFLAGS) $(LIBSSH2_RCFLAG_EXTRAS) -i $< -o $@ $(OBJDIR)/%.rc: GNUmakefile $(OBJDIR)/version.inc @echo $(DL)1 VERSIONINFO$(DL) > $@ @@ -279,5 +260,3 @@ help: $(OBJDIR)/version.inc @echo $(DL)$(MAKE) clean$(DL) @echo $(DL)$(MAKE) objclean$(DL) @echo $(DL)===========================================================$(DL) - - diff --git a/win32/tests.dsp b/win32/tests.dsp index b6df32418f..b2a89dcc09 100644 --- a/win32/tests.dsp +++ b/win32/tests.dsp @@ -41,8 +41,8 @@ RSC=rc.exe # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -65,8 +65,8 @@ LINK32=link.exe # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe From 730c606b64f86b5899183655e8f07578a54b8f9e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 3 Mar 2023 21:33:26 +0000 Subject: [PATCH 100/424] cmake: build fixes with OpenSSL/LibreSSL on Windows - Link `bcrypt` for newer (non-fork) OpenSSL. - Link `bcrypt` and `ws2_32` when using (non-fork) OpenSSL or LibreSSL, to allow `Looking for EVP_aes_128_ctr` detecting this feature. With the feature available, but not found by CMake, build failed with: `openssl.c:636:21: error: incompatible integer to pointer conversion assigning to 'EVP_CIPHER *' (aka 'struct evp_cipher_st *') from 'int' [-Wint-conversion]` Closes #809 --- src/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b086ac7f57..cc8031f697 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,8 +73,8 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) if (WIN32) # Statically linking to OpenSSL requires crypt32 for some Windows APIs. # This should really be handled by FindOpenSSL.cmake. - list(APPEND LIBRARIES crypt32) - list(APPEND PC_LIBS -lcrypt32) + list(APPEND LIBRARIES crypt32 bcrypt) + list(APPEND PC_LIBS -lcrypt32 -lbcrypt) find_file(DLL_LIBEAY32 NAMES libeay32.dll crypto.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll @@ -102,6 +102,10 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) # Not all OpenSSL have AES-CTR functions. set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}) + if(WIN32) + # For OpenSSL and LibreSSL + set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}" "ws2_32" "bcrypt") + endif() check_function_exists(EVP_aes_128_ctr HAVE_EVP_AES_128_CTR) set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES}) endif() From 4cdf785cd313c3272d04c2ef7458a35d44533d8b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 7 Mar 2023 14:06:35 +0000 Subject: [PATCH 101/424] snprintf: unify fallback logic Before this patch, the `snprintf()` fallback logic for envs not supporting this function (i.e. Visual Studio 2013 and older) varied depending on build tool, and used different techniques in examples, tests and libssh2 itself. This patch aims to apply a common logic to libssh2 and examples/tests. - libssh2: use local `snprintf()` fallback with all build tools. We already had a local implementation, but only with CMake. Move that to the library as `_libssh2_snprintf()`, and map `snprintf()` to it when `HAVE_SNPRINTF` is not set. Also change the length type from `int` to `size_t`, and fix formatting. - set or detect `HAVE_SNPRINTF` in non-CMake builds. Detect in autotools. Keep existing logic in `win32/libssh2_config.h`. Always set for OS/400, NetWare and VMS, keeping existing behaviour. (OS/400 builds use a different local implementation) - examples/tests: drop the CMake-specific fallback logic and map `snprintf()` to `_snprintf()` for old MSVC versions, like we did before with other build tools. This is unsafe, but should be fine for these uses. - `win32/libssh2_config.h`: make it easier to read. Closes #812 --- configure.ac | 2 +- example/CMakeLists.txt | 2 -- example/libssh2_config_cmake.h.in | 2 -- example/subsystem_netconf.c | 6 ++--- nw/GNUmakefile | 1 + os400/libssh2_config.h | 4 +++ src/libssh2_config_cmake.h.in | 26 ------------------ src/libssh2_priv.h | 6 +++++ src/misc.c | 24 +++++++++++++++++ tests/libssh2_config_cmake.h.in | 27 ------------------- tests/session_fixture.h | 4 +++ vms/libssh2_config.h | 1 + win32/libssh2_config.h | 44 +++++++++++++++---------------- 13 files changed, 64 insertions(+), 85 deletions(-) diff --git a/configure.ac b/configure.ac index 24b851e4c6..489bddb219 100644 --- a/configure.ac +++ b/configure.ac @@ -341,7 +341,7 @@ case $host in ;; esac -AC_CHECK_FUNCS(gettimeofday select strtoll memset_s) +AC_CHECK_FUNCS(gettimeofday select strtoll memset_s snprintf) dnl Check for select() into ws2_32 for Msys/Mingw if test "$ac_cv_func_select" != "yes"; then diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 3dc115ef19..3198c4d65a 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -90,8 +90,6 @@ check_include_files(winsock2.h HAVE_WINSOCK2_H) check_symbol_exists(strcasecmp strings.h HAVE_STRCASECMP) check_symbol_exists(_stricmp string.h HAVE__STRICMP) -check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) -check_symbol_exists(_snprintf stdio.h HAVE__SNPRINTF) check_symbol_exists(__func__ "" HAVE___FUNC__) check_symbol_exists(__FUNCTION__ "" HAVE___FUNCTION__) diff --git a/example/libssh2_config_cmake.h.in b/example/libssh2_config_cmake.h.in index 12264f7fe6..bdcbe84969 100644 --- a/example/libssh2_config_cmake.h.in +++ b/example/libssh2_config_cmake.h.in @@ -48,8 +48,6 @@ /* Functions */ #cmakedefine HAVE_STRCASECMP #cmakedefine HAVE__STRICMP -#cmakedefine HAVE_SNPRINTF -#cmakedefine HAVE__SNPRINTF /* Workaround for platforms without POSIX strcasecmp (e.g. Windows) */ #ifndef HAVE_STRCASECMP diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index e53cfa5f4d..1b17bf67f8 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -37,10 +37,8 @@ #define INADDR_NONE (in_addr_t)~0 #endif -#ifndef HAVE_SNPRINTF -# ifdef HAVE__SNPRINTF -# define snprintf _snprintf -# endif +#if defined(_MSC_VER) && _MSC_VER < 1900 +#define snprintf _snprintf #endif const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; diff --git a/nw/GNUmakefile b/nw/GNUmakefile index 8899fdd8e4..4098b51fb5 100644 --- a/nw/GNUmakefile +++ b/nw/GNUmakefile @@ -424,6 +424,7 @@ ifdef ENABLE_IPV6 @echo $(DL)#define ENABLE_IPV6 1$(DL) >> $@ endif endif + @echo $(DL)#define HAVE_SNPRINTF 1$(DL) >> $@ @echo $(DL)#define HAVE_ARPA_INET_H 1$(DL) >> $@ @echo $(DL)#define HAVE_ASSERT_H 1$(DL) >> $@ @echo $(DL)#define HAVE_CTYPE_H 1$(DL) >> $@ diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 6ec04da14a..5aa8e20b2c 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -212,6 +212,10 @@ /* Use OS/400 Qc3 */ #define LIBSSH2_OS400QC3 +/* Use our platform-specific local implementation: + _libssh2_os400_snprintf */ +#define HAVE_SNPRINTF 1 + /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #define LT_OBJDIR ".libs/" diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 4004792470..4a915815b4 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -76,29 +76,3 @@ #cmakedefine HAVE_IOCTLSOCKET_CASE #cmakedefine HAVE_SO_NONBLOCK #cmakedefine HAVE_DISABLED_NONBLOCKING - -/* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible. - We provide a safe wrapper if snprintf not found */ -#ifndef HAVE_SNPRINTF -#include -#include -/* Want safe, 'n += snprintf(b + n ...)' like function. If cp_max_len is 1 -* then assume cp is pointing to a null char and do nothing. Returns number -* number of chars placed in cp excluding the trailing null char. So for -* cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len -* <= 0 the return value is 0 (and no chars are written to cp). */ -static int snprintf(char * cp, int cp_max_len, const char * fmt, ...) -{ - va_list args; - int n; - - if (cp_max_len < 2) - return 0; - va_start(args, fmt); - n = vsnprintf(cp, cp_max_len, fmt, args); - va_end(args); - return (n < cp_max_len) ? n : (cp_max_len - 1); -} - -#define HAVE_SNPRINTF -#endif diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 4bf17f9f41..44bfb12ecc 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -126,6 +126,12 @@ #define TRUE 1 #endif +/* Use local implementation when not available */ +#if !defined(HAVE_SNPRINTF) +#define LIBSSH2_SNPRINTF +#define snprintf _libssh2_snprintf +#endif + #ifdef _MSC_VER /* "inline" keyword is valid only with C++ engine! */ #define inline __inline diff --git a/src/misc.c b/src/misc.c index 933a2041cb..686401c13b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -60,6 +60,30 @@ #include #include +/* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible. + We provide a safe wrapper if snprintf not found */ +#ifdef LIBSSH2_SNPRINTF +#include + +/* Want safe, 'n += snprintf(b + n ...)' like function. If cp_max_len is 1 +* then assume cp is pointing to a null char and do nothing. Returns number +* number of chars placed in cp excluding the trailing null char. So for +* cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len +* <= 0 the return value is 0 (and no chars are written to cp). */ +int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...) +{ + va_list args; + int n; + + if(cp_max_len < 2) + return 0; + va_start(args, fmt); + n = vsnprintf(cp, cp_max_len, fmt, args); + va_end(args); + return (n < cp_max_len) ? n : (cp_max_len - 1); +} +#endif + int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode, const char *errmsg, int errflags) { diff --git a/tests/libssh2_config_cmake.h.in b/tests/libssh2_config_cmake.h.in index f75711a33b..cbcdec2330 100644 --- a/tests/libssh2_config_cmake.h.in +++ b/tests/libssh2_config_cmake.h.in @@ -42,30 +42,3 @@ #cmakedefine HAVE_ARPA_INET_H #cmakedefine HAVE_NETINET_IN_H #cmakedefine HAVE_WINSOCK2_H -#cmakedefine HAVE_SNPRINTF - -/* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible. - We provide a safe wrapper if snprintf not found */ -#ifndef HAVE_SNPRINTF -#include -#include -/* Want safe, 'n += snprintf(b + n ...)' like function. If cp_max_len is 1 -* then assume cp is pointing to a null char and do nothing. Returns number -* number of chars placed in cp excluding the trailing null char. So for -* cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len -* <= 0 the return value is 0 (and no chars are written to cp). */ -static int snprintf(char *cp, int cp_max_len, const char *fmt, ...) -{ - va_list args; - int n; - - if (cp_max_len < 2) - return 0; - va_start(args, fmt); - n = vsnprintf(cp, cp_max_len, fmt, args); - va_end(args); - return (n < cp_max_len) ? n : (cp_max_len - 1); -} - -#define HAVE_SNPRINTF -#endif diff --git a/tests/session_fixture.h b/tests/session_fixture.h index f42d1dc838..3820a5a94c 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -40,6 +40,10 @@ #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#define snprintf _snprintf +#endif + LIBSSH2_SESSION *start_session_fixture(void); void stop_session_fixture(void); void print_last_session_error(const char *function); diff --git a/vms/libssh2_config.h b/vms/libssh2_config.h index b8f73e2722..45a49b5ac7 100644 --- a/vms/libssh2_config.h +++ b/vms/libssh2_config.h @@ -25,6 +25,7 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ #define HAVE_ARPA_INET_H #define HAVE_GETTIMEOFDAY 1 +#define HAVE_SNPRINTF 1 #define POSIX_C_SOURCE diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 0da35c4851..a497eab518 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -4,38 +4,36 @@ #ifndef WIN32 #define WIN32 #endif + #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE 1 -#endif /* _CRT_SECURE_NO_DEPRECATE */ - -#ifdef __MINGW32__ -#define HAVE_UNISTD_H -#define HAVE_INTTYPES_H -#define HAVE_SYS_TIME_H -#define HAVE_GETTIMEOFDAY -#endif /* __MINGW32__ */ +#endif #define HAVE_LIBCRYPT32 #define HAVE_WINSOCK2_H #define HAVE_IOCTLSOCKET #define HAVE_SELECT +#define HAVE_SNPRINTF -#ifdef _MSC_VER -#if _MSC_VER < 1900 -#define snprintf _snprintf -#if _MSC_VER < 1500 -#define vsnprintf _vsnprintf -#endif -#define strdup _strdup -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif +#ifdef __MINGW32__ +# define HAVE_UNISTD_H +# define HAVE_INTTYPES_H +# define HAVE_SYS_TIME_H +# define HAVE_GETTIMEOFDAY +#elif defined(_MSC_VER) +# if _MSC_VER < 1900 +# undef HAVE_SNPRINTF +# if _MSC_VER < 1500 +# define vsnprintf _vsnprintf +# endif +# define strdup _strdup +# define strncasecmp _strnicmp +# define strcasecmp _stricmp +# endif #else -#ifndef __MINGW32__ -#define strncasecmp strnicmp -#define strcasecmp stricmp -#endif /* __MINGW32__ */ -#endif /* _MSC_VER */ +# define strncasecmp strnicmp +# define strcasecmp stricmp +#endif /* Enable newer diffie-hellman-group-exchange-sha1 syntax */ #define LIBSSH2_DH_GEX_NEW 1 From 505ea626b6e125b7ce15caf453b522192008a884 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 7 Mar 2023 14:14:07 +0000 Subject: [PATCH 102/424] cmake: bump minimum version to 3.1 (from 2.8.12) This allows to delete some fallback code. CMake release dates: - 2014-12-15: 3.1 - 2013-10-07: 2.8.12 Closes #813 --- CMakeLists.txt | 10 ++-------- src/CMakeLists.txt | 7 +------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f2a222a95..cd365776d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.1) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) @@ -41,13 +41,7 @@ project(libssh2 C) set(PROJECT_URL "https://www.libssh2.org/") set(PROJECT_DESCRIPTION "The SSH library") -if (CMAKE_VERSION VERSION_LESS "3.1") - if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - set (CMAKE_C_FLAGS "--std=gnu90 ${CMAKE_C_FLAGS}") - endif() -else() - set (CMAKE_C_STANDARD 90) -endif() +set(CMAKE_C_STANDARD 90) option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc8031f697..674e1ebfdc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -362,12 +362,7 @@ if(MSVC) set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG") endif() -if(CMAKE_VERSION VERSION_LESS "2.8.12") - # Fall back to over-linking dependencies - target_link_libraries(libssh2 ${LIBRARIES}) -else() - target_link_libraries(libssh2 PRIVATE ${LIBRARIES}) -endif() +target_link_libraries(libssh2 PRIVATE ${LIBRARIES}) ## Installation From a0e424a51c27cc27af611ba20d134f9a9ae35273 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 7 Mar 2023 14:21:46 +0000 Subject: [PATCH 103/424] src: enable clear memory on all platforms - convert `_libssh2_explicit_zero()` to macro. This allows inlining where supported (e.g. `SecureZeroMemory()`). - replace `SecureZeroMemory()` (in `wincng.c`) and `LIBSSH2_CLEAR_MEMORY`-guarded `memset()` (in `os400qc3.c`) with `_libssh2_explicit_zero()` macro. - delete `LIBSSH2_CLEAR_MEMORY` guards, which enables secure-zeroing universally. - add `LIBSSH2_NO_CLEAR_MEMORY` option to disable secure-zeroing. - while here, delete double/triple inclusion of `misc.h`. `libssh2_priv.h` included it already. Closes #810 --- acinclude.m4 | 1 - configure.ac | 23 ++++------------------- os400/libssh2_config.h | 3 --- src/CMakeLists.txt | 6 +++--- src/agent.c | 1 - src/agent.h | 1 - src/agent_win.c | 1 - src/hostkey.c | 1 - src/knownhost.c | 1 - src/libssh2_priv.h | 13 +------------ src/mbedtls.c | 4 ---- src/misc.c | 12 +++--------- src/misc.h | 18 +++++++++++++++++- src/openssl.c | 1 - src/os400qc3.c | 10 ++++------ src/session.c | 1 - src/wincng.c | 15 +++------------ 17 files changed, 35 insertions(+), 77 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 8afcd93c42..cc9463a267 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -456,7 +456,6 @@ m4_case([$1], AC_DEFINE(LIBSSH2_MBEDTLS, 1, [Use $1]) LIBS="$LIBS -lmbedcrypto" found_crypto="$1" - support_clear_memory=yes ]) ], diff --git a/configure.ac b/configure.ac index 489bddb219..61fa13aa2a 100644 --- a/configure.ac +++ b/configure.ac @@ -83,7 +83,6 @@ AC_SYS_LARGEFILE found_crypto=none found_crypto_str="" -support_clear_memory=no crypto_errors="" m4_set_add([crypto_backends], [openssl]) @@ -176,25 +175,11 @@ fi AC_ARG_ENABLE(clear-memory, AC_HELP_STRING([--disable-clear-memory],[Disable clearing of memory before being freed]), [CLEAR_MEMORY=$enableval]) -if test "$CLEAR_MEMORY" != "no"; then - if test "$support_clear_memory" = "yes"; then - AC_DEFINE(LIBSSH2_CLEAR_MEMORY, 1, [Enable clearing of memory before being freed]) - enable_clear_memory=yes - else - if test "$CLEAR_MEMORY" = "yes"; then - AC_MSG_ERROR([secure clearing/zeroing of memory is not supported by the selected crypto backend]) - else - AC_MSG_WARN([secure clearing/zeroing of memory is not supported by the selected crypto backend]) - fi - enable_clear_memory=unsupported - fi +if test "$CLEAR_MEMORY" = "no"; then + AC_DEFINE(LIBSSH2_NO_CLEAR_MEMORY, 1, [Disable clearing of memory before being freed]) + enable_clear_memory=no else - if test "$support_clear_memory" = "yes"; then - enable_clear_memory=no - else - AC_MSG_WARN([secure clearing/zeroing of memory is not supported by the selected crypto backend]) - enable_clear_memory=unsupported - fi + enable_clear_memory=yes fi dnl ************************************************************ diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 5aa8e20b2c..03158130b7 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -185,9 +185,6 @@ /* to make a symbol visible */ #undef LIBSSH2_API -/* Enable clearing of memory before being freed */ -#define LIBSSH2_CLEAR_MEMORY 1 - /* Enable "none" cipher -- NOT RECOMMENDED */ #undef LIBSSH2_CRYPT_NONE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 674e1ebfdc..c76071e696 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -236,9 +236,9 @@ target_include_directories(libssh2 ## Options option(CLEAR_MEMORY "Enable clearing of memory before being freed" ON) -if(CLEAR_MEMORY) - add_definitions(-DLIBSSH2_CLEAR_MEMORY) -endif(CLEAR_MEMORY) +if(NOT CLEAR_MEMORY) + add_definitions(-DLIBSSH2_NO_CLEAR_MEMORY) +endif() add_feature_info("Shared library" BUILD_SHARED_LIBS "creating libssh2 as a shared library (.so/.dll)") diff --git a/src/agent.c b/src/agent.c index 7fccce02d7..e3b1ff5b6b 100644 --- a/src/agent.c +++ b/src/agent.c @@ -39,7 +39,6 @@ #include "libssh2_priv.h" #include "agent.h" -#include "misc.h" #include #ifdef HAVE_SYS_UN_H #include diff --git a/src/agent.h b/src/agent.h index dfac0715c8..64bbfe0154 100644 --- a/src/agent.h +++ b/src/agent.h @@ -40,7 +40,6 @@ */ #include "libssh2_priv.h" -#include "misc.h" #include "session.h" #ifdef WIN32 #include diff --git a/src/agent_win.c b/src/agent_win.c index 4636140e82..a84d4794d0 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -39,7 +39,6 @@ #include "libssh2_priv.h" #include "agent.h" -#include "misc.h" #include #ifdef HAVE_SYS_UN_H #include diff --git a/src/hostkey.c b/src/hostkey.c index 391af056b4..23917d8e6c 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -37,7 +37,6 @@ */ #include "libssh2_priv.h" -#include "misc.h" /* Needed for struct iovec on some platforms */ #ifdef HAVE_SYS_UIO_H diff --git a/src/knownhost.c b/src/knownhost.c index 77798fbfde..6b3c0230f9 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -37,7 +37,6 @@ */ #include "libssh2_priv.h" -#include "misc.h" struct known_host { struct list_node node; diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 44bfb12ecc..0dfe60c8f2 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -59,17 +59,6 @@ # define LIBSSH2_WINDOWS_APP # endif # endif - -/* TODO: Enable this unconditionally for all platforms. - Also delete autotools logic that enables it only for mbedTLS. - And CMake logic which already enabled it unconditionally. - The actual memory clearing logic uses SecureZeroMemory(), - memset_s() or plain memset(), whichever is available, and - does not depend on any crypto backend function. */ -#ifndef LIBSSH2_CLEAR_MEMORY -#define LIBSSH2_CLEAR_MEMORY -#endif - #endif #ifdef HAVE_WS2TCPIP_H @@ -117,7 +106,7 @@ #include "libssh2.h" #include "libssh2_publickey.h" #include "libssh2_sftp.h" -#include "misc.h" /* for the linked list stuff */ +#include "misc.h" #ifndef FALSE #define FALSE 0 diff --git a/src/mbedtls.c b/src/mbedtls.c index ba0229a1ab..50a44373e5 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -96,12 +96,8 @@ _libssh2_mbedtls_safe_free(void *buf, int len) if(!buf) return; -#ifdef LIBSSH2_CLEAR_MEMORY if(len > 0) _libssh2_explicit_zero(buf, len); -#else - (void)len; -#endif mbedtls_free(buf); } diff --git a/src/misc.c b/src/misc.c index 686401c13b..269fccac20 100644 --- a/src/misc.c +++ b/src/misc.c @@ -739,20 +739,14 @@ void _libssh2_aes_ctr_increment(unsigned char *ctr, } } -#if !defined(WIN32) && !defined(HAVE_MEMSET_S) +#ifdef LIBSSH2_MEMZERO static void * (* const volatile memset_libssh)(void *, int, size_t) = memset; -#endif -void _libssh2_explicit_zero(void *buf, size_t size) +void _libssh2_memzero(void *buf, size_t size) { -#ifdef WIN32 - SecureZeroMemory(buf, size); -#elif defined(HAVE_MEMSET_S) - (void)memset_s(buf, size, 0, size); -#else memset_libssh(buf, 0, size); -#endif } +#endif /* String buffer */ diff --git a/src/misc.h b/src/misc.h index 2e7af32af2..e194d8f4e7 100644 --- a/src/misc.h +++ b/src/misc.h @@ -38,6 +38,23 @@ * OF SUCH DAMAGE. */ +#ifdef LIBSSH2_NO_CLEAR_MEMORY +#define _libssh2_explicit_zero(buf, size) do { \ + (void)buf; \ + (void)size; \ + } while(0) +#else +#ifdef WIN32 +#define _libssh2_explicit_zero(buf, size) SecureZeroMemory(buf, size) +#elif defined(HAVE_MEMSET_S) +#define _libssh2_explicit_zero(buf, size) (void)memset_s(buf, size, 0, size) +#else +#define LIBSSH2_MEMZERO +void _libssh2_memzero(void *buf, size_t size); +#define _libssh2_explicit_zero(buf, size) _libssh2_memzero(buf, size) +#endif +#endif + struct list_head { struct list_node *last; struct list_node *first; @@ -89,7 +106,6 @@ void _libssh2_store_bignum2_bytes(unsigned char **buf, const unsigned char *bytes, size_t len); void *_libssh2_calloc(LIBSSH2_SESSION *session, size_t size); -void _libssh2_explicit_zero(void *buf, size_t size); struct string_buf* _libssh2_string_buf_new(LIBSSH2_SESSION *session); void _libssh2_string_buf_free(LIBSSH2_SESSION *session, diff --git a/src/openssl.c b/src/openssl.c index 8e75833e59..b103644642 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -44,7 +44,6 @@ #if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) #include -#include "misc.h" #ifndef EVP_MAX_BLOCK_LENGTH #define EVP_MAX_BLOCK_LENGTH 32 diff --git a/src/os400qc3.c b/src/os400qc3.c index 22955a1585..6e3137b2fe 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -757,10 +757,9 @@ _libssh2_bn_free(_libssh2_bn *bn) { if(bn) { if(bn->bignum) { -#ifdef LIBSSH2_CLEAR_MEMORY if(bn->length) - memset((char *) bn->bignum, 0, bn->length); -#endif + _libssh2_explicit_zero(bn->bignum, bn->length); + free(bn->bignum); } @@ -781,10 +780,9 @@ _libssh2_bn_resize(_libssh2_bn *bn, size_t newlen) if(!bn->bignum) bignum = (unsigned char *) malloc(newlen); else { -#ifdef LIBSSH2_CLEAR_MEMORY if(newlen < bn->length) - memset((char *) bn->bignum + newlen, 0, bn->length - newlen); -#endif + _libssh2_explicit_zero(bn->bignum + newlen, bn->length - newlen); + if(!newlen) { free((char *) bn->bignum); bn->bignum = NULL; diff --git a/src/session.c b/src/session.c index 608c254d1c..63a73ec20e 100644 --- a/src/session.c +++ b/src/session.c @@ -56,7 +56,6 @@ #include "session.h" #include "channel.h" #include "mac.h" -#include "misc.h" /* libssh2_default_alloc */ diff --git a/src/wincng.c b/src/wincng.c index 28ac1278e8..6b24bf6f31 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -59,7 +59,6 @@ #include #include #include -#include "misc.h" #ifdef HAVE_STDLIB_H #include @@ -435,12 +434,8 @@ _libssh2_wincng_safe_free(void *buf, int len) if(!buf) return; -#ifdef LIBSSH2_CLEAR_MEMORY if(len > 0) - SecureZeroMemory(buf, len); -#else - (void)len; -#endif + _libssh2_explicit_zero(buf, len); free(buf); } @@ -2086,11 +2081,9 @@ _libssh2_wincng_bignum_resize(_libssh2_bn *bn, unsigned long length) if(length == bn->length) return 0; -#ifdef LIBSSH2_CLEAR_MEMORY if(bn->bignum && bn->length > 0 && length < bn->length) { - SecureZeroMemory(bn->bignum + length, bn->length - length); + _libssh2_explicit_zero(bn->bignum + length, bn->length - length); } -#endif bignum = realloc(bn->bignum, length); if(!bignum) @@ -2289,9 +2282,7 @@ _libssh2_wincng_bignum_from_bin(_libssh2_bn *bn, unsigned long len, if(offset > 0) { memmove(bn->bignum, bn->bignum + offset, length); -#ifdef LIBSSH2_CLEAR_MEMORY - SecureZeroMemory(bn->bignum + length, offset); -#endif + _libssh2_explicit_zero(bn->bignum + length, offset); bignum = realloc(bn->bignum, length); if(bignum) { From 23a21aa86c9aa494faf1947d985156cac6ab8a71 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 7 Mar 2023 14:25:00 +0000 Subject: [PATCH 104/424] cmake: make `test_read` runs cross-build-friendly Improve tests added in 7487dcf4b4ddae54b2a850737789b57b4251b0ae by running `test_read` commands directly. This makes external shell/batch files unnecessary, and is friendlier with cross-builds and when run from non-default shells, like MSYS2. Also extend CRYPT/MAC test error messages with the CRYPT/MAC name. External runner shell scripts kept for future use. Closes #814 --- tests/CMakeLists.txt | 53 +++++++++++++++---------------- tests/Makefile.am | 16 +--------- tests/session_fixture.c | 4 +-- tests/test_read_3des-cbc.bat | 2 -- tests/test_read_aes128-cbc.bat | 2 -- tests/test_read_aes128-ctr.bat | 2 -- tests/test_read_aes192-cbc.bat | 2 -- tests/test_read_aes192-ctr.bat | 2 -- tests/test_read_aes256-cbc.bat | 2 -- tests/test_read_aes256-ctr.bat | 2 -- tests/test_read_hmac-md5-96.bat | 2 -- tests/test_read_hmac-md5.bat | 2 -- tests/test_read_hmac-sha1-96.bat | 2 -- tests/test_read_hmac-sha1.bat | 2 -- tests/test_read_hmac-sha2-256.bat | 2 -- tests/test_read_hmac-sha2-512.bat | 2 -- tests/test_read_rijndael-cbc.bat | 2 -- 17 files changed, 29 insertions(+), 72 deletions(-) delete mode 100644 tests/test_read_3des-cbc.bat delete mode 100644 tests/test_read_aes128-cbc.bat delete mode 100644 tests/test_read_aes128-ctr.bat delete mode 100644 tests/test_read_aes192-cbc.bat delete mode 100644 tests/test_read_aes192-ctr.bat delete mode 100644 tests/test_read_aes256-cbc.bat delete mode 100644 tests/test_read_aes256-ctr.bat delete mode 100644 tests/test_read_hmac-md5-96.bat delete mode 100644 tests/test_read_hmac-md5.bat delete mode 100644 tests/test_read_hmac-sha1-96.bat delete mode 100644 tests/test_read_hmac-sha1.bat delete mode 100644 tests/test_read_hmac-sha2-256.bat delete mode 100644 tests/test_read_hmac-sha2-512.bat delete mode 100644 tests/test_read_rijndael-cbc.bat diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f391c86062..e7d8da52cf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -174,42 +174,41 @@ foreach(test ${TESTS}) WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") endforeach() -if(WIN32) - set(test_ext ".bat") -endif() - +# MAC tests foreach(test - read_aes128-ctr - read_aes192-ctr - read_aes256-ctr - read_hmac-md5 - read_hmac-md5-96 - read_hmac-sha1 - read_hmac-sha1-96 - read_hmac-sha2-256 - read_hmac-sha2-512 + hmac-md5 + hmac-md5-96 + hmac-sha1 + hmac-sha1-96 + hmac-sha2-256 + hmac-sha2-512 ) - add_test( - NAME test_${test} COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_${test}${test_ext}") - set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "builddir=$") + add_test(NAME test_${test} COMMAND "$") + set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_MAC=${test}") endforeach() +# CRYPT tests +set(TESTS + aes128-ctr + aes192-ctr + aes256-ctr + ) # Due to a bug with mbedTLS support, these crypt methods fail. Until that bug # is fixed, don't run them there to avoid this known issue causing red tests. # See https://github.com/libssh2/libssh2/issues/793 if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") - foreach(test - read_3des-cbc - read_aes128-cbc - read_aes192-cbc - read_aes256-cbc - read_rijndael-cbc - ) - add_test( - NAME test_${test} COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_${test}${test_ext}") - set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "builddir=$") - endforeach() + list(APPEND TESTS + 3des-cbc + aes128-cbc + aes192-cbc + aes256-cbc + rijndael-cbc@lysator.liu.se + ) endif() +foreach(test ${TESTS}) + add_test(NAME test_${test} COMMAND "$") + set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") +endforeach() if(WIN32 AND BUILD_SHARED_LIBS) # Workaround for Visual Studio diff --git a/tests/Makefile.am b/tests/Makefile.am index fcaa96d4bf..fb8c63299d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -100,30 +100,16 @@ EXTRA_DIST = \ ssh2.sh \ sshd_fixture.sh.in \ test_read_3des-cbc \ - test_read_3des-cbc.bat \ test_read_aes128-cbc \ - test_read_aes128-cbc.bat \ test_read_aes128-ctr \ - test_read_aes128-ctr.bat \ test_read_aes192-cbc \ - test_read_aes192-cbc.bat \ test_read_aes192-ctr \ - test_read_aes192-ctr.bat \ test_read_aes256-cbc \ - test_read_aes256-cbc.bat \ test_read_aes256-ctr \ - test_read_aes256-ctr.bat \ test_read_hmac-md5 \ test_read_hmac-md5-96 \ - test_read_hmac-md5-96.bat \ - test_read_hmac-md5.bat \ test_read_hmac-sha1 \ test_read_hmac-sha1-96 \ - test_read_hmac-sha1-96.bat \ - test_read_hmac-sha1.bat \ test_read_hmac-sha2-256 \ - test_read_hmac-sha2-256.bat \ test_read_hmac-sha2-512 \ - test_read_hmac-sha2-512.bat \ - test_read_rijndael-cbc \ - test_read_rijndael-cbc.bat + test_read_rijndael-cbc diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 6e836565d5..f494c7e5dd 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -134,7 +134,7 @@ LIBSSH2_SESSION *start_session_fixture(void) libssh2_session_method_pref(connected_session, LIBSSH2_METHOD_CRYPT_SC, env)) { fprintf(stderr, "libssh2_session_method_pref CRYPT failed " - "(probably disabled in the build)\n"); + "(probably disabled in the build): '%s'\n", env); return NULL; } } @@ -146,7 +146,7 @@ LIBSSH2_SESSION *start_session_fixture(void) libssh2_session_method_pref(connected_session, LIBSSH2_METHOD_MAC_SC, env)) { fprintf(stderr, "libssh2_session_method_pref MAC failed " - "(probably disabled in the build)\n"); + "(probably disabled in the build): '%s'\n", env); return NULL; } } diff --git a/tests/test_read_3des-cbc.bat b/tests/test_read_3des-cbc.bat deleted file mode 100644 index 4e9f0ba4b8..0000000000 --- a/tests/test_read_3des-cbc.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=3des-cbc -%builddir%\test_read diff --git a/tests/test_read_aes128-cbc.bat b/tests/test_read_aes128-cbc.bat deleted file mode 100644 index 13e84fca22..0000000000 --- a/tests/test_read_aes128-cbc.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=aes128-cbc -%builddir%\test_read diff --git a/tests/test_read_aes128-ctr.bat b/tests/test_read_aes128-ctr.bat deleted file mode 100644 index 5d2d8ddf23..0000000000 --- a/tests/test_read_aes128-ctr.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=aes128-ctr -%builddir%\test_read diff --git a/tests/test_read_aes192-cbc.bat b/tests/test_read_aes192-cbc.bat deleted file mode 100644 index 07c3641a1e..0000000000 --- a/tests/test_read_aes192-cbc.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=aes192-cbc -%builddir%\test_read diff --git a/tests/test_read_aes192-ctr.bat b/tests/test_read_aes192-ctr.bat deleted file mode 100644 index c16898e69e..0000000000 --- a/tests/test_read_aes192-ctr.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=aes192-ctr -%builddir%\test_read diff --git a/tests/test_read_aes256-cbc.bat b/tests/test_read_aes256-cbc.bat deleted file mode 100644 index baff53c0b0..0000000000 --- a/tests/test_read_aes256-cbc.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=aes256-cbc -%builddir%\test_read diff --git a/tests/test_read_aes256-ctr.bat b/tests/test_read_aes256-ctr.bat deleted file mode 100644 index e551a45e13..0000000000 --- a/tests/test_read_aes256-ctr.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=aes256-ctr -%builddir%\test_read diff --git a/tests/test_read_hmac-md5-96.bat b/tests/test_read_hmac-md5-96.bat deleted file mode 100644 index 1211e5237f..0000000000 --- a/tests/test_read_hmac-md5-96.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_MAC=hmac-md5-96 -%builddir%\test_read diff --git a/tests/test_read_hmac-md5.bat b/tests/test_read_hmac-md5.bat deleted file mode 100644 index f3361552b8..0000000000 --- a/tests/test_read_hmac-md5.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_MAC=hmac-md5 -%builddir%\test_read diff --git a/tests/test_read_hmac-sha1-96.bat b/tests/test_read_hmac-sha1-96.bat deleted file mode 100644 index 5fb20077f5..0000000000 --- a/tests/test_read_hmac-sha1-96.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_MAC=hmac-sha1-96 -%builddir%\test_read diff --git a/tests/test_read_hmac-sha1.bat b/tests/test_read_hmac-sha1.bat deleted file mode 100644 index 1db5109cd5..0000000000 --- a/tests/test_read_hmac-sha1.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_MAC=hmac-sha1 -%builddir%\test_read diff --git a/tests/test_read_hmac-sha2-256.bat b/tests/test_read_hmac-sha2-256.bat deleted file mode 100644 index a3a7ac886a..0000000000 --- a/tests/test_read_hmac-sha2-256.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_MAC=hmac-sha2-256 -%builddir%\test_read diff --git a/tests/test_read_hmac-sha2-512.bat b/tests/test_read_hmac-sha2-512.bat deleted file mode 100644 index 8ad9103ced..0000000000 --- a/tests/test_read_hmac-sha2-512.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_MAC=hmac-sha2-512 -%builddir%\test_read diff --git a/tests/test_read_rijndael-cbc.bat b/tests/test_read_rijndael-cbc.bat deleted file mode 100644 index 6889a0253e..0000000000 --- a/tests/test_read_rijndael-cbc.bat +++ /dev/null @@ -1,2 +0,0 @@ -set FIXTURE_TEST_CRYPT=rijndael-cbc@lysator.liu.se -%builddir%\test_read From 31fb8860dbaae3e0b7d38f2a647ee527b4b2a95f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 7 Mar 2023 15:14:22 +0000 Subject: [PATCH 105/424] build: more fixes and tidy-up (mostly for Windows) - cmake: always link `ws2_32` on Windows. Also add it to `libssh2.pc`. Fixes #745 - agent: fix gcc compiler warning: `src/agent.c:296:35: warning: 'snprintf' output truncated before the last format character [-Wformat-truncation=]` - autotools: fix `EVP_aes_128_ctr` detection with binutils `ld` The prerequisite for a successful detection is setting `LIBS=-lbcrypt` if the chosen openssl-compatible library requires it, e.g. libressl, or quictls/openssl built with `-DUSE_BCRYPTGENRANDOM`. With llvm `lld`, detection works out of the box. With binutils `ld`, it does not. The reason is `ld`s world-famous pickiness with lib order. To fix it, we pass all custom libs before and after the TLS libs. This ugly hack makes `ld` happy and detection succeed. - agent: fix Windows-specific warning: `src/agent.c:318:10: warning: implicit conversion loses integer precision: 'LRESULT' (aka 'long long') to 'int' [-Wshorten-64-to-32]` - src: fix llvm/clang compiler warning: `src/libssh2_priv.h:987:28: warning: variadic macros are a C99 feature [-Wvariadic-macros]` - src: support `inline` with `__GNUC__` (llvm/clang and gcc), fixing: ``` src/libssh2_priv.h:990:8: warning: extension used [-Wlanguage-extension-token] static inline void ^ ``` - blowfish: support `inline` keyword with MSVC. Also switch to `__inline__` (from `__inline`) for `__GNUC__`: https://gcc.gnu.org/onlinedocs/gcc/Inline.html https://clang.llvm.org/docs/UsersManual.html#differences-between-various-standard-modes - example/test: fix MSVC compiler warnings: - `example\direct_tcpip.c(209): warning C4244: 'function': conversion from 'unsigned int' to 'u_short', possible loss of data` - `tests\session_fixture.c(96): warning C4013: 'getcwd' undefined; assuming extern returning int` - `tests\session_fixture.c(100): warning C4013: 'chdir' undefined; assuming extern returning int` - delete unused macros: - `HAVE_SOCKET` - `HAVE_INET_ADDR` - `NEED_LIB_NSL` - `NEED_LIB_SOCKET` - `HAVE_NTSTATUS_H` - `HAVE_NTDEF_H` - build: delete stale zlib/openssl version numbers from path defaults. - cmake: convert tabs to spaces, add newline at EOFs. Closes #811 --- CMakeLists.txt | 4 ++ acinclude.m4 | 6 +- cmake/CheckFunctionExistsMayNeedLibrary.cmake | 12 ++-- cmake/CheckNonblockingSocketSupport.cmake | 16 ++--- cmake/FindLibgcrypt.cmake | 2 +- cmake/SocketLibraries.cmake | 64 ------------------- cmake/Toolchain-Linux-32.cmake | 2 +- example/CMakeLists.txt | 3 - example/direct_tcpip.c | 2 +- example/tcpip-forward.c | 2 +- nw/GNUmakefile | 8 +-- nw/test/GNUmakefile | 5 +- os400/libssh2_config.h | 6 -- src/CMakeLists.txt | 9 ++- src/agent.c | 4 +- src/blowfish.c | 6 +- src/libssh2_config_cmake.h.in | 4 -- src/libssh2_priv.h | 6 +- tests/CMakeLists.txt | 2 - tests/session_fixture.c | 5 ++ win32/GNUmakefile | 4 +- win32/Makefile.Watcom | 6 +- win32/config.mk | 8 +-- win32/test/GNUmakefile | 4 +- 24 files changed, 58 insertions(+), 132 deletions(-) delete mode 100644 cmake/SocketLibraries.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index cd365776d7..5dc3be3d93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,10 @@ install( include(max_warnings) include(FeatureSummary) +if(WIN32) + list(APPEND LIBRARIES ws2_32) +endif() + add_subdirectory(src) option(BUILD_EXAMPLES "Build libssh2 examples" ON) diff --git a/acinclude.m4 b/acinclude.m4 index cc9463a267..e4806b7356 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -422,7 +422,9 @@ m4_case([$1], # Not all OpenSSL have AES-CTR functions. libssh2_save_LIBS="$LIBS" - LIBS="$LIBS $LIBSSL" + # Duplicate $LIBS to make binutils ld (known to be fatally + # sensitive to lib order) happy. + LIBS="$LIBS $LIBSSL $LIBS" AC_CHECK_FUNCS(EVP_aes_128_ctr) LIBS="$libssh2_save_LIBS" @@ -462,8 +464,6 @@ m4_case([$1], [wincng], [ # Look for Windows Cryptography API: Next Generation - AC_CHECK_HEADERS([ntdef.h ntstatus.h], [], [], [#include ]) - LIBSSH2_LIB_HAVE_LINKFLAGS([crypt32], [], [ #include #include diff --git a/cmake/CheckFunctionExistsMayNeedLibrary.cmake b/cmake/CheckFunctionExistsMayNeedLibrary.cmake index 8ac61abe5e..2de0a70e3c 100644 --- a/cmake/CheckFunctionExistsMayNeedLibrary.cmake +++ b/cmake/CheckFunctionExistsMayNeedLibrary.cmake @@ -69,13 +69,13 @@ function(check_function_exists_may_need_library function variable) # new test check_library_exists(${lib} ${function} "" HAVE_${function}_IN_${lib}) if(HAVE_${function}_IN_${lib}) - set(${variable} 1 CACHE INTERNAL - "Function ${function} found in library ${lib}") - set(NEED_LIB_${UP_LIB} 1 CACHE INTERNAL - "Need to link ${lib}") - break() + set(${variable} 1 CACHE INTERNAL + "Function ${function} found in library ${lib}") + set(NEED_LIB_${UP_LIB} 1 CACHE INTERNAL + "Need to link ${lib}") + break() endif() endforeach() endif() -endfunction() \ No newline at end of file +endfunction() diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index 74f4776a68..ba771ed2bd 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -86,7 +86,7 @@ int main() HAVE_IOCTLSOCKET) if(NOT HAVE_IOCTLSOCKET) - check_c_source_compiles("/* IoctlSocket test (Amiga?) */ + check_c_source_compiles("/* IoctlSocket test (Amiga?) */ #include int main() @@ -97,7 +97,7 @@ int main() HAVE_IOCTLSOCKET_CASE) if(NOT HAVE_IOCTLSOCKET_CASE) - check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */ + check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */ #include int main() @@ -108,12 +108,12 @@ int main() }" HAVE_SO_NONBLOCK) - if(NOT HAVE_SO_NONBLOCK) - # No non-blocking socket method found - set(HAVE_DISABLED_NONBLOCKING 1) - endif() - endif() + if(NOT HAVE_SO_NONBLOCK) + # No non-blocking socket method found + set(HAVE_DISABLED_NONBLOCKING 1) + endif() + endif() endif() endif() endif() -endmacro() \ No newline at end of file +endmacro() diff --git a/cmake/FindLibgcrypt.cmake b/cmake/FindLibgcrypt.cmake index 44a79873d6..4de3888d1e 100644 --- a/cmake/FindLibgcrypt.cmake +++ b/cmake/FindLibgcrypt.cmake @@ -50,4 +50,4 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libgcrypt DEFAULT_MSG LIBGCRYPT_LIBRARY LIBGCRYPT_INCLUDE_DIR) -mark_as_advanced(LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY) \ No newline at end of file +mark_as_advanced(LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY) diff --git a/cmake/SocketLibraries.cmake b/cmake/SocketLibraries.cmake deleted file mode 100644 index bfbbd711e3..0000000000 --- a/cmake/SocketLibraries.cmake +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 2014 Alexander Lamaison -# -# Redistribution and use in source and binary forms, -# with or without modification, are permitted provided -# that the following conditions are met: -# -# Redistributions of source code must retain the above -# copyright notice, this list of conditions and the -# following disclaimer. -# -# Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# Neither the name of the copyright holder nor the names -# of any other contributors may be used to endorse or -# promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -# OF SUCH DAMAGE. - -# Some systems have their socket functions in a library. -# (Solaris -lsocket/-lnsl, Windows -lws2_32). This macro appends those -# libraries to the given list -macro(append_needed_socket_libraries LIBRARIES_LIST) - if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 4) - # x86 Windows uses STDCALL for these functions, so their names are mangled, - # meaning the platform checks don't work. Hardcoding these until we get - # a better solution. - set(HAVE_SOCKET 1) - set(HAVE_SELECT 1) - set(HAVE_INET_ADDR 1) - set(NEED_LIB_WS2_32 1) - else() - check_function_exists_may_need_library(socket HAVE_SOCKET socket ws2_32) - check_function_exists_may_need_library(select HAVE_SELECT ws2_32) - check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl ws2_32) - endif() - - if(NEED_LIB_SOCKET) - list(APPEND ${LIBRARIES_LIST} socket) - endif() - if(NEED_LIB_NSL) - list(APPEND ${LIBRARIES_LIST} nsl) - endif() - if(NEED_LIB_WS2_32) - list(APPEND ${LIBRARIES_LIST} ws2_32) - endif() - -endmacro() \ No newline at end of file diff --git a/cmake/Toolchain-Linux-32.cmake b/cmake/Toolchain-Linux-32.cmake index 6aad9b1e2d..9535a64621 100644 --- a/cmake/Toolchain-Linux-32.cmake +++ b/cmake/Toolchain-Linux-32.cmake @@ -39,4 +39,4 @@ set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_SYSTEM_PROCESSOR "i386") set(CMAKE_CXX_COMPILER_ARG1 "-m32") -set(CMAKE_C_COMPILER_ARG1 "-m32") \ No newline at end of file +set(CMAKE_C_COMPILER_ARG1 "-m32") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 3198c4d65a..e1fa939de0 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -36,7 +36,6 @@ include(CheckIncludeFiles) include(CheckSymbolExists) include(CopyRuntimeDependencies) -include(SocketLibraries) set(EXAMPLES direct_tcpip @@ -63,8 +62,6 @@ set(EXAMPLES subsystem_netconf tcpip-forward) -append_needed_socket_libraries(LIBRARIES) - foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) list(APPEND EXAMPLE_TARGETS example-${example}) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 5fb470264e..5261564a41 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -206,7 +206,7 @@ int main(int argc, char *argv[]) } sin.sin_family = AF_INET; - sin.sin_port = htons(local_listenport); + sin.sin_port = htons((unsigned short)local_listenport); sin.sin_addr.s_addr = inet_addr(local_listenip); if(INADDR_NONE == sin.sin_addr.s_addr) { perror("inet_addr"); diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 6ed4466d16..96d3a95cf2 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -229,7 +229,7 @@ int main(int argc, char *argv[]) } sin.sin_family = AF_INET; - sin.sin_port = htons(local_destport); + sin.sin_port = htons((unsigned short)local_destport); sin.sin_addr.s_addr = inet_addr(local_destip); if(INADDR_NONE == sin.sin_addr.s_addr) { perror("inet_addr"); diff --git a/nw/GNUmakefile b/nw/GNUmakefile index 4098b51fb5..764ac04b4a 100644 --- a/nw/GNUmakefile +++ b/nw/GNUmakefile @@ -14,12 +14,12 @@ endif # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../zlib-1.2.8 +ZLIB_PATH = ../../zlib endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../openssl-0.9.8zc +OPENSSL_PATH = ../../openssl endif # Edit the path below to point to your Distribution folder. @@ -436,7 +436,6 @@ endif @echo $(DL)#define HAVE_GETHOSTBYNAME 1$(DL) >> $@ @echo $(DL)#define HAVE_GETPROTOBYNAME 1$(DL) >> $@ @echo $(DL)#define HAVE_GMTIME_R 1$(DL) >> $@ - @echo $(DL)#define HAVE_INET_ADDR 1$(DL) >> $@ @echo $(DL)#define HAVE_INET_NTOA 1$(DL) >> $@ @echo $(DL)#define HAVE_LL 1$(DL) >> $@ @echo $(DL)#define HAVE_LOCALTIME_R 1$(DL) >> $@ @@ -447,7 +446,6 @@ endif @echo $(DL)#define HAVE_SIGNAL 1$(DL) >> $@ @echo $(DL)#define HAVE_SIGNAL_H 1$(DL) >> $@ @echo $(DL)#define HAVE_SIG_ATOMIC_T 1$(DL) >> $@ - @echo $(DL)#define HAVE_SOCKET 1$(DL) >> $@ @echo $(DL)#define HAVE_STDLIB_H 1$(DL) >> $@ @echo $(DL)#define HAVE_STRDUP 1$(DL) >> $@ @echo $(DL)#define HAVE_STRFTIME 1$(DL) >> $@ @@ -627,5 +625,3 @@ endif @echo $(DL)$(MAKE) objclean$(DL) @echo $(DL)$(MAKE) test$(DL) @echo $(DL)===========================================================$(DL) - - diff --git a/nw/test/GNUmakefile b/nw/test/GNUmakefile index 86bf6b6845..5749a377d9 100644 --- a/nw/test/GNUmakefile +++ b/nw/test/GNUmakefile @@ -13,12 +13,12 @@ endif # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib-1.2.8 +ZLIB_PATH = ../../../zlib endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8zc +OPENSSL_PATH = ../../../openssl endif # Edit the var below to enable static linking of libssh2 and libz @@ -308,4 +308,3 @@ ifdef LDLIBS endif @echo $(DL)output $(notdir $(@:.def=.nlm))$(DL) >> $@ endif - diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 03158130b7..c77ac80fa4 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -113,12 +113,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_NETINET_IN_H 1 -/* Define to 1 if you have the header file. */ -#undef HAVE_NTDEF_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NTSTATUS_H - /* use O_NONBLOCK for non-blocking sockets */ #define HAVE_O_NONBLOCK 1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c76071e696..a9ae1191fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,7 +40,6 @@ include(CheckIncludeFiles) include(CheckTypeSize) include(CheckSymbolExists) include(CheckNonblockingSocketSupport) -include(SocketLibraries) ## Cryptography backend choice @@ -139,9 +138,6 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) list(APPEND LIBRARIES bcrypt) list(APPEND PC_LIBS -lbcrypt) - check_include_files(ntdef.h HAVE_NTDEF_H) - check_include_files(ntstatus.h HAVE_NTSTATUS_H) - # Reading keys from files is optional and depends on Wincrypt check_include_files("windows.h;wincrypt.h" HAVE_WINCRYPT_H) @@ -342,7 +338,10 @@ else() check_function_exists(poll HAVE_POLL) endif() -append_needed_socket_libraries(LIBRARIES) +if(WIN32) + set(HAVE_SELECT 1) + list(APPEND PC_LIBS -lws2_32) +endif() # Non-blocking socket support tests. Must be after library tests to # link correctly diff --git a/src/agent.c b/src/agent.c index e3b1ff5b6b..f1a3582566 100644 --- a/src/agent.c +++ b/src/agent.c @@ -279,7 +279,7 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) HANDLE filemap; unsigned char *p; unsigned char *p2; - int id; + LRESULT id; COPYDATASTRUCT cds; if(!transctx || 4 + transctx->request_len > PAGEANT_MAX_MSGLEN) @@ -292,7 +292,7 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) "found no pageant"); snprintf(mapname, sizeof(mapname), - "PageantRequest%08x%c", (unsigned)GetCurrentThreadId(), '\0'); + "PageantRequest%08x", (unsigned)GetCurrentThreadId()); filemap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, PAGEANT_MAX_MSGLEN, mapname); diff --git a/src/blowfish.c b/src/blowfish.c index 94bc0c6f16..2535e9f578 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -53,10 +53,12 @@ #undef inline #ifdef __GNUC__ +#define inline __inline__ +#elif defined(_MSC_VER) #define inline __inline -#else /* !__GNUC__ */ +#else #define inline -#endif /* !__GNUC__ */ +#endif /* Function for Feistel Networks */ diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 4a915815b4..da9e68af53 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -47,8 +47,6 @@ #cmakedefine HAVE_SYS_UN_H #cmakedefine HAVE_WS2TCPIP_H #cmakedefine HAVE_WINSOCK2_H -#cmakedefine HAVE_NTDEF_H -#cmakedefine HAVE_NTSTATUS_H /* Libraries */ #cmakedefine HAVE_LIBCRYPT32 @@ -58,10 +56,8 @@ /* Functions */ #cmakedefine HAVE_GETTIMEOFDAY -#cmakedefine HAVE_INET_ADDR #cmakedefine HAVE_POLL #cmakedefine HAVE_SELECT -#cmakedefine HAVE_SOCKET #cmakedefine HAVE_STRTOLL #cmakedefine HAVE_STRTOI64 #cmakedefine HAVE_SNPRINTF diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 0dfe60c8f2..1274a661fb 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -121,8 +121,10 @@ #define snprintf _libssh2_snprintf #endif -#ifdef _MSC_VER /* "inline" keyword is valid only with C++ engine! */ +#ifdef __GNUC__ +#define inline __inline__ +#elif defined(_MSC_VER) #define inline __inline #endif @@ -977,7 +979,7 @@ void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...); #else #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ - defined(__GNUC__) + (defined(__GNUC__) && !defined(__clang__)) /* C99 supported and also by older GCC */ #define _libssh2_debug(x,y,...) do {} while (0) #else diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e7d8da52cf..54d82db300 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,7 +37,6 @@ include(CheckIncludeFiles) include(CheckFunctionExists) include(CheckSymbolExists) include(CopyRuntimeDependencies) -include(SocketLibraries) ## Platform checks check_include_files(inttypes.h HAVE_INTTYPES_H) @@ -50,7 +49,6 @@ check_include_files(netinet/in.h HAVE_NETINET_IN_H) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in" "${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h") -append_needed_socket_libraries(LIBRARIES) ## Cryptography backend choice diff --git a/tests/session_fixture.c b/tests/session_fixture.c index f494c7e5dd..521e60bff0 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -47,6 +47,11 @@ #ifdef WIN32 #include +#ifdef _MSC_VER +#include +#define getcwd _getcwd +#define chdir _chdir +#endif #endif #ifdef HAVE_WINSOCK2_H #include diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 4c74cd3529..eaafe233ff 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -9,12 +9,12 @@ # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../zlib-1.2.8 +ZLIB_PATH = ../../zlib endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../openssl-1.0.2d +OPENSSL_PATH = ../../openssl endif # Edit the path below to point to your Distribution folder. diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom index 8aa9d31ba6..8b39d51c0a 100644 --- a/win32/Makefile.Watcom +++ b/win32/Makefile.Watcom @@ -64,13 +64,13 @@ CFLAGS += -d_WIN32_WINNT=0x0501 -dENABLE_IPV6 !ifdef %zlib_root ZLIB_ROOT = $(%zlib_root) !else -ZLIB_ROOT = ..\..\zlib-1.2.8 +ZLIB_ROOT = ..\..\zlib !endif !ifdef %openssl_root OPENSSL_ROOT = $(%openssl_root) !else -OPENSSL_ROOT = ..\..\openssl-0.9.8zc +OPENSSL_ROOT = ..\..\openssl !endif !ifdef %use_zlib @@ -186,5 +186,3 @@ $(LINK_ARG): $(__MAKEFILES__) $(LIB_ARG): $(__MAKEFILES__) %create $^@ @for %f in ($(OBJS_STAT)) do @%append $^@ +- %f - - diff --git a/win32/config.mk b/win32/config.mk index 84ee608c2b..e57f8fe9f8 100644 --- a/win32/config.mk +++ b/win32/config.mk @@ -1,18 +1,18 @@ # Tweak these for your system !if "$(OPENSSLINC)" == "" -OPENSSLINC=..\openssl-0.9.8zc\inc32 +OPENSSLINC=..\openssl\include !endif !if "$(OPENSSLLIB)" == "" -OPENSSLLIB=..\openssl-0.9.8zc\out32dll +OPENSSLLIB=..\openssl\lib !endif !if "$(ZLIBINC)" == "" -ZLIBINC=..\zlib-1.2.8 +ZLIBINC=..\zlib !endif !if "$(ZLIBLIB)" == "" -ZLIBLIB=..\zlib-1.2.8 +ZLIBLIB=..\zlib !endif !if "$(TARGET)" == "" diff --git a/win32/test/GNUmakefile b/win32/test/GNUmakefile index 8cfedb622f..3be0095d74 100644 --- a/win32/test/GNUmakefile +++ b/win32/test/GNUmakefile @@ -9,12 +9,12 @@ # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib-1.2.8 +ZLIB_PATH = ../../../zlib endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8zc +OPENSSL_PATH = ../../../openssl endif # Project root From 05c7d128c8966f60ec168790432e6e76e91db9db Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 7 Mar 2023 19:30:51 +0100 Subject: [PATCH 106/424] cmake: restore non-Windows socket lib detection (#815) I mistakenly pruned some non-Windows logic, also missing the fact that our local `check_function_exists_may_need_library()` set the `NEED_*` variables. Oddly, only `src` imported this function, yet also `examples` and `tests` called it indirectly. The referenced `HAVE_SOCKET` / `HAVE_INET_ADDR` variables might be coming from an upstream CMake project? Leaving those there also, just in case. Regression from 31fb8860dbaae3e0b7d38f2a647ee527b4b2a95f --- CMakeLists.txt | 13 +++++++++++++ src/CMakeLists.txt | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dc3be3d93..cfcd7c9346 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,9 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") +include(CheckFunctionExistsMayNeedLibrary) + cmake_minimum_required(VERSION 3.1) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) @@ -79,8 +82,18 @@ install( include(max_warnings) include(FeatureSummary) +# Add socket libraries if(WIN32) list(APPEND LIBRARIES ws2_32) +else() + check_function_exists_may_need_library(socket HAVE_SOCKET socket) + if(NEED_LIB_SOCKET) + list(APPEND LIBRARIES socket) + endif() + check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl) + if(NEED_LIB_NSL) + list(APPEND LIBRARIES nsl) + endif() endif() add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a9ae1191fb..a0322ef5a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,7 +35,6 @@ include(CheckFunctionExists) include(CheckSymbolExists) -include(CheckFunctionExistsMayNeedLibrary) include(CheckIncludeFiles) include(CheckTypeSize) include(CheckSymbolExists) From 9f217a17f6f3c2047c4a1668a5c037a75a02abfd Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 09:34:37 +0100 Subject: [PATCH 107/424] cmake: add wolfSSL support (#817) Implement wolfSSL support for libssh2 when building with CMake. Configuration example from curl-for-win: ``` -DCRYPTO_BACKEND=wolfSSL -DWOLFSSL_LIBRARY=/path-to/wolfssl/lib/libwolfssl.a -DWOLFSSL_INCLUDE_DIR=/path-to/wolfssl/include ``` Module `cmake/Findwolfssl.cmake` copied from: https://github.com/ngtcp2/ngtcp2/blob/e4d920c4b7a350d63b6978c68b216b76faa12635/cmake/Findwolfssl.cmake via commit: https://github.com/ngtcp2/ngtcp2/commit/296396d3730b721ad97f9de22f525400f8524c0e by Stefan Eissing --- cmake/Findwolfssl.cmake | 41 +++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 19 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 cmake/Findwolfssl.cmake diff --git a/cmake/Findwolfssl.cmake b/cmake/Findwolfssl.cmake new file mode 100644 index 0000000000..47e1bbad3e --- /dev/null +++ b/cmake/Findwolfssl.cmake @@ -0,0 +1,41 @@ +# - Try to find wolfssl +# Once done this will define +# WOLFSSL_FOUND - System has wolfssl +# WOLFSSL_INCLUDE_DIR - The wolfssl include directories +# WOLFSSL_LIBRARIES - The libraries needed to use wolfssl + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_WOLFSSL QUIET wolfssl) + +find_path(WOLFSSL_INCLUDE_DIR + NAMES wolfssl/ssl.h + HINTS ${PC_WOLFSSL_INCLUDE_DIRS} +) +find_library(WOLFSSL_LIBRARY + NAMES wolfssl + HINTS ${PC_WOLFSSL_LIBRARY_DIRS} +) + +if(WOLFSSL_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+LIBWOLFSSL_VERSION_STRING[ \t]+\"([^\"]+)\".*") + file(STRINGS "${WOLFSSL_INCLUDE_DIR}/wolfssl/version.h" + WOLFSSL_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" + WOLFSSL_VERSION "${WOLFSSL_VERSION}") + unset(_version_regex) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set WOLFSSL_FOUND +# to TRUE if all listed variables are TRUE and the requested version +# matches. +find_package_handle_standard_args(wolfssl REQUIRED_VARS + WOLFSSL_LIBRARY WOLFSSL_INCLUDE_DIR + VERSION_VAR WOLFSSL_VERSION) + +if(WOLFSSL_FOUND) + set(WOLFSSL_LIBRARIES ${WOLFSSL_LIBRARY}) + set(WOLFSSL_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR}) +endif() + +mark_as_advanced(WOLFSSL_INCLUDE_DIR WOLFSSL_LIBRARY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0322ef5a0..501714df4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -109,6 +109,25 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) endif() endif() +if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) + + find_package(wolfssl ${SPECIFIC_CRYPTO_REQUIREMENT}) + + if(WOLFSSL_FOUND) + set(CRYPTO_BACKEND "wolfSSL") + set(CRYPTO_SOURCES openssl.c openssl.h) + list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_WOLFSSL) + list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl) + list(APPEND LIBRARIES ${WOLFSSL_LIBRARIES}) + list(APPEND PC_LIBS -lwolfssl) + + if (WIN32) + list(APPEND LIBRARIES crypt32) + list(APPEND PC_LIBS -lcrypt32) + endif() + endif() +endif() + if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT}) From 19884e5055b6c65f0df93d7cc776a01c518a2f06 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 09:36:11 +0100 Subject: [PATCH 108/424] cmake: update openssl dll list (#818) Add OpenSSL 3 and versionless DLL names. Also modernize warning messages and variable names. Do we need the OpenSSL-Windows-specific check and the related `RUNTIME_DEPENDENCIES` feature? The list of OpenSSL DLLs was out of date for 1.5 years without anybody noticing. Keeping it fresh is a chore and copying around DLL dependencies rarely helps as much as expected. This check also results in unuseful warnings in certain build scenarios, e.g. when linking to OpenSSL statically. --- src/CMakeLists.txt | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 501714df4f..363da0f26d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -74,26 +74,30 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) list(APPEND LIBRARIES crypt32 bcrypt) list(APPEND PC_LIBS -lcrypt32 -lbcrypt) - find_file(DLL_LIBEAY32 - NAMES libeay32.dll crypto.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll + find_file(DLL_LIBCRYPTO + NAMES libeay32.dll crypto.dll libcrypto.dll + libcrypto-1_1.dll libcrypto-1_1-x64.dll + libcrypto-3.dll libcrypto-3-x64.dll HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} PATH_SUFFIXES bin) - if (NOT DLL_LIBEAY32) + if(NOT DLL_LIBCRYPTO) message(WARNING - "Unable to find OpenSSL crypto (aka libeay32) DLL, executables may not run") + "Unable to find OpenSSL libcrypto DLL, executables may not run") endif() - find_file(DLL_SSLEAY32 - NAMES ssleay32.dll ssl.dll libssl-1_1.dll libssl-1_1-x64.dll + find_file(DLL_LIBSSL + NAMES ssleay32.dll ssl.dll libssl.dll + libssl-1_1.dll libssl-1_1-x64.dll + libssl-3.dll libssl-3-x64.dll HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} PATH_SUFFIXES bin) - if (NOT DLL_SSLEAY32) + if(NOT DLL_LIBSSL) message(WARNING - "Unable to find OpenSSL ssl (aka ssleay32) DLL, executables may not run") + "Unable to find OpenSSL libssl DLL, executables may not run") endif() - if(DLL_LIBEAY32 AND DLL_SSLEAY32) - list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBEAY32} ${DLL_SSLEAY32}) + if(DLL_LIBCRYPTO AND DLL_LIBSSL) + list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBCRYPTO} ${DLL_LIBSSL}) endif() endif() From 9ad1258f1fcca43545606953c1c3fe8c25bcbd0f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 13:56:01 +0100 Subject: [PATCH 109/424] cmake: use only needed socket libs when checking non-blocking sockets (#816) Based on patch by Christian Beier. Fixes #694 Closes #712 --- CMakeLists.txt | 7 ++++--- src/CMakeLists.txt | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfcd7c9346..df2c5f237c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,17 +84,18 @@ include(FeatureSummary) # Add socket libraries if(WIN32) - list(APPEND LIBRARIES ws2_32) + list(APPEND SOCKET_LIBRARIES ws2_32) else() check_function_exists_may_need_library(socket HAVE_SOCKET socket) if(NEED_LIB_SOCKET) - list(APPEND LIBRARIES socket) + list(APPEND SOCKET_LIBRARIES socket) endif() check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl) if(NEED_LIB_NSL) - list(APPEND LIBRARIES nsl) + list(APPEND SOCKET_LIBRARIES nsl) endif() endif() +list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 363da0f26d..06038d221c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -365,10 +365,11 @@ if(WIN32) list(APPEND PC_LIBS -lws2_32) endif() -# Non-blocking socket support tests. Must be after library tests to -# link correctly +# Non-blocking socket support tests. Use a separate, yet unset variable +# for the socket libraries to not link against the other configured +# dependencies which might not have been built yet. set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) -set(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES}) +set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES}) check_nonblocking_socket_support() set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES}) From 10c8beab1f57f62ac8fa80d6c1990ebee0748a9e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 13:59:59 +0100 Subject: [PATCH 110/424] build: silence bogus C4127 warnings with MSVS 2013 and earlier (#819) E.g.: `channel.c(370): warning C4127: conditional expression is constant` Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46437333/job/5rak1vcl9hue31ei#L190 --- src/libssh2_priv.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 1274a661fb..387ff5d38b 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -39,6 +39,11 @@ * OF SUCH DAMAGE. */ +/* Disable warnings: C4127: conditional expression is constant */ +#if defined(_MSC_VER) && _MSC_VER < 1900 +#pragma warning(disable:4127) +#endif + #define LIBSSH2_LIBRARY #include "libssh2_config.h" From 07a8b8e033b7d2dd0a98847b44c150b867d4a2a9 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 16:12:51 +0100 Subject: [PATCH 111/424] cmake: add os400qc3.c to SOURCES (#826) This re-syncs the list of compiled objects in cmake builds with non-cmake builds. Follow-up to 16619a8eddec35bb8582d1c334db0fc13b0817c4. --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 06038d221c..f9c6d5632d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -218,6 +218,7 @@ set(SOURCES mac.h misc.c misc.h + os400qc3.c packet.c packet.h pem.c From 7cce783081b86cfa691376c8c7f477607b553e21 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 16:18:44 +0100 Subject: [PATCH 112/424] build: set _FILE_OFFSET_BITS=64 for mingw-w64 (#821) autotools builds already did auto-detect and set this mingw-specific macro, but CMake and GNU Make builds did not. This patch fixes that. Necessary for `src/scp.c`. --- src/libssh2_priv.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 387ff5d38b..f80d55d4ca 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -44,9 +44,21 @@ #pragma warning(disable:4127) #endif +/* Define mingw-w64 version macros, eg __MINGW{32,64}_{MINOR,MAJOR}_VERSION */ +#ifdef __MINGW32__ +#include <_mingw.h> +#endif + #define LIBSSH2_LIBRARY #include "libssh2_config.h" +/* Number of bits in a file offset, on hosts where this is settable. */ +#if defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR) +# ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +# endif +#endif + #ifdef WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN From 57f1d381405028272e52d73a3b8291f370f4638a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 16:19:22 +0100 Subject: [PATCH 113/424] snprintf: add missing prototype for local replacement (#820) Should fix these warnings with MSVS 2013 and older: `agent.c(294): warning C4013: '_libssh2_snprintf' undefined; assuming extern returning int` Follow-up to 4cdf785cd313c3272d04c2ef7458a35d44533d8b. --- src/libssh2_priv.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index f80d55d4ca..358421a0b4 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -136,6 +136,7 @@ #if !defined(HAVE_SNPRINTF) #define LIBSSH2_SNPRINTF #define snprintf _libssh2_snprintf +int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...); #endif /* "inline" keyword is valid only with C++ engine! */ From 27318779a3a57c4a39168c4062b4e63267f9aa87 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 8 Mar 2023 22:13:09 +0100 Subject: [PATCH 114/424] fix compiling with LIBSSH2_NO_CLEAR_MEMORY and OpenSSL (#825) Regression from a0e424a51c27cc27af611ba20d134f9a9ae35273 Fixes #824 --- src/misc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc.h b/src/misc.h index e194d8f4e7..60c99de721 100644 --- a/src/misc.h +++ b/src/misc.h @@ -40,8 +40,8 @@ #ifdef LIBSSH2_NO_CLEAR_MEMORY #define _libssh2_explicit_zero(buf, size) do { \ - (void)buf; \ - (void)size; \ + (void)(buf); \ + (void)(size); \ } while(0) #else #ifdef WIN32 From 33b6d5f89d5328aa7677f542450cc48d825df595 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 9 Mar 2023 00:41:48 +0100 Subject: [PATCH 115/424] cmake: reposition ws2_32 to make binutils ld work again (#827) This restores socket libs to their pre-regression positions. Without this, `ld` doesn't find `ws2_32` symbols when referenced from TLS libs. Regression from 31fb8860dbaae3e0b7d38f2a647ee527b4b2a95f --- CMakeLists.txt | 1 - example/CMakeLists.txt | 2 ++ src/CMakeLists.txt | 2 ++ tests/CMakeLists.txt | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df2c5f237c..c83c914927 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,6 @@ else() list(APPEND SOCKET_LIBRARIES nsl) endif() endif() -list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_subdirectory(src) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index e1fa939de0..33db9c5349 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -62,6 +62,8 @@ set(EXAMPLES subsystem_netconf tcpip-forward) +list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) + foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) list(APPEND EXAMPLE_TARGETS example-${example}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9c6d5632d..81c04554e3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -361,6 +361,8 @@ else() check_function_exists(poll HAVE_POLL) endif() +list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) + if(WIN32) set(HAVE_SELECT 1) list(APPEND PC_LIBS -lws2_32) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 54d82db300..f1a7816e36 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,6 +50,8 @@ configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in" "${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h") +list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) + ## Cryptography backend choice set(CRYPTO_BACKEND From 99c1333ba7fd82f7459f8f4c0c0b62cc018a6f59 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 9 Mar 2023 10:46:40 +0100 Subject: [PATCH 116/424] example: silence MSVS 2013 C4127 warnings (#828) --- example/direct_tcpip.c | 4 ++-- example/scp_write.c | 4 ++++ example/sftp.c | 3 +++ example/sftp_RW_nonblock.c | 4 ++++ example/sftp_nonblock.c | 4 ++++ example/sftpdir.c | 4 ++++ example/sftpdir_nonblock.c | 4 ++++ example/ssh2_agent.c | 2 +- example/ssh2_agent_forwarding.c | 2 +- example/tcpip-forward.c | 4 ++-- example/x11.c | 2 +- 11 files changed, 30 insertions(+), 7 deletions(-) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 5261564a41..9a2af73287 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) /* Must use non-blocking IO hereafter due to the current libssh2 API */ libssh2_session_set_blocking(session, 0); - while(1) { + for(;;) { FD_ZERO(&fds); FD_SET(forwardsock, &fds); tv.tv_sec = 0; @@ -290,7 +290,7 @@ int main(int argc, char *argv[]) wr += i; } } - while(1) { + for(;;) { len = libssh2_channel_read(channel, buf, sizeof(buf)); if(LIBSSH2_ERROR_EAGAIN == len) break; diff --git a/example/scp_write.c b/example/scp_write.c index 58585bef8f..11e3860bc1 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -36,6 +36,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#pragma warning(disable:4127) +#endif + int main(int argc, char *argv[]) { unsigned long hostaddr; diff --git a/example/sftp.c b/example/sftp.c index d1e1d508e0..1f1ddaf3f7 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -42,6 +42,9 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#pragma warning(disable:4127) +#endif const char *keyfile1 = "~/.ssh/id_rsa.pub"; const char *keyfile2 = "~/.ssh/id_rsa"; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 8b57c30f82..5b8fecec5b 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -39,6 +39,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#pragma warning(disable:4127) +#endif + #define STORAGE "/tmp/sftp-storage" /* this is the local file name this example uses to store the downloaded file in */ diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 7cbf8630d8..e12c2a421d 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -45,6 +45,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#pragma warning(disable:4127) +#endif + #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/sftpdir.c b/example/sftpdir.c index 3ca3bbf635..5174d14e1a 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -42,6 +42,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#pragma warning(disable:4127) +#endif + #ifdef WIN32 #define __FILESIZE "I64u" #else diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index d8fa32fc7c..62de69db4d 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -42,6 +42,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1900 +#pragma warning(disable:4127) +#endif + #ifdef WIN32 #define __FILESIZE "I64u" #else diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index e4a713cb4f..a4cf5e15e6 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) rc = 1; goto shutdown; } - while(1) { + for(;;) { rc = libssh2_agent_get_identity(agent, &identity, prev_identity); if(rc == 1) break; diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index c65e00362a..9735f3971c 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) rc = 1; goto shutdown; } - while(1) { + for(;;) { rc = libssh2_agent_get_identity(agent, &identity, prev_identity); if(rc == 1) break; diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 96d3a95cf2..3f9e6d7ad1 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -246,7 +246,7 @@ int main(int argc, char *argv[]) /* Must use non-blocking IO hereafter due to the current libssh2 API */ libssh2_session_set_blocking(session, 0); - while(1) { + for(;;) { FD_ZERO(&fds); FD_SET(forwardsock, &fds); tv.tv_sec = 0; @@ -277,7 +277,7 @@ int main(int argc, char *argv[]) wr += i; } while(i > 0 && wr < len); } - while(1) { + for(;;) { len = libssh2_channel_read(channel, buf, sizeof(buf)); if(LIBSSH2_ERROR_EAGAIN == len) break; diff --git a/example/x11.c b/example/x11.c index c49b64ea9d..5406b21e7c 100644 --- a/example/x11.c +++ b/example/x11.c @@ -389,7 +389,7 @@ main (int argc, char *argv[]) memset(&w_size, 0, sizeof(struct winsize)); memset(&w_size_bck, 0, sizeof(struct winsize)); - while(1) { + for(;;) { FD_ZERO(&set); FD_SET(fileno(stdin), &set); From 8795d9c817250a9a57a92cf748049447c0b0375c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 9 Mar 2023 11:48:21 +0100 Subject: [PATCH 117/424] cmake: unset forced CMAKE_C_STANDARD 90 (#822) Added in cf80f2f4b5255cc85a04ee43b27a29c678c1edb1 (on 2016-08-14), with the title "Basic dockerised test suite". It's not clear why a C standard was explicitly set, but a side-effect of this is that CMake-built binaries diverged from ones built with autotools or GNU Make (using the same compiler and configuration). Another issue is that this may introduce ABI incompatibility with binaries built with a different C standard flag, e.g. the C compiler default or one used for other components of a final app. Seems unlikely, but if our tests require this option, we should set it for the CI builds only? --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c83c914927..dc66cf81c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,8 +44,6 @@ project(libssh2 C) set(PROJECT_URL "https://www.libssh2.org/") set(PROJECT_DESCRIPTION "The SSH library") -set(CMAKE_C_STANDARD 90) - option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) # Parse version From ae90a35d15d97154ac0c8554bce99ebfb18ee825 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 9 Mar 2023 19:49:20 +0100 Subject: [PATCH 118/424] cmake: detect HAVE_SNPRINTF for tests (#830) Turns out `test_keyboard_interactive_auth_info_request.c` requires `src/libssh2_priv.h`, which in turn requires a correctly set `HAVE_SNPRINTF`. Follow-up to 4cdf785cd313c3272d04c2ef7458a35d44533d8b. --- tests/CMakeLists.txt | 1 + tests/libssh2_config_cmake.h.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f1a7816e36..85753d1e7f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -46,6 +46,7 @@ check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(arpa/inet.h HAVE_ARPA_INET_H) check_include_files(winsock2.h HAVE_WINSOCK2_H) check_include_files(netinet/in.h HAVE_NETINET_IN_H) +check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in" "${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h") diff --git a/tests/libssh2_config_cmake.h.in b/tests/libssh2_config_cmake.h.in index cbcdec2330..4cf1d09934 100644 --- a/tests/libssh2_config_cmake.h.in +++ b/tests/libssh2_config_cmake.h.in @@ -42,3 +42,6 @@ #cmakedefine HAVE_ARPA_INET_H #cmakedefine HAVE_NETINET_IN_H #cmakedefine HAVE_WINSOCK2_H + +/* Functions */ +#cmakedefine HAVE_SNPRINTF From 40ac6b230a309d35c57aa65a8f6d7ab6654aa3d8 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 10 Mar 2023 00:53:55 +0100 Subject: [PATCH 119/424] tests: workaround for intermittent first test failures (#832) Flakiness got continously worse these last days. It didn't seem related to recent commits. Flakiness also picked up in GitHub CI runs, something rarely seen before. Manual restart consistently fixed them. The repeating pattern was the _first_ test (`test_hostkey`) failing, with `libssh2_session_handshake failed (-13): Failed getting banner`. Failures came after a lengthy wait, suggesting a timeout. I then reversed the order of the first two tests, and it turned out that the _first_ test failed again (`test_hostkey_hash`). Also pointing to a timeout issue. Then I added a dummy test to "warm up" whatever needs warming up in the layers of CI + Docker + ssh server and their interconnects. This helped, and GitHub CI tests run without failure right for the first time. AppVeyor CI also improved a little. This patch adds a new first test called `test_warmup`, that creates a new libssh2 session, and exits with success even if that attempt failed. A stop-gap solution at best, and there is no guarantee it will continue to fix this or similar future issues, but it's also untenable to have almost every CI run fail for intermittent reasons. In some [1] cases [2] it's not the first test failing intermittently. That's a different issue, and this patch doesn't fix it. [1] #804 [2] https://ci.appveyor.com/project/libssh2org/libssh2/builds/46440828/job/8rej6cq6itg7vc4w#L500 --- tests/CMakeLists.txt | 7 ++++++- tests/Makefile.am | 1 + tests/test_warmup.c | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/test_warmup.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 85753d1e7f..cc230d072c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -115,6 +115,7 @@ if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) endif() set(TESTS + warmup hostkey hostkey_hash password_auth_succeeds_with_correct_credentials @@ -165,7 +166,11 @@ target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") foreach(test ${TESTS}) add_executable(test_${test} test_${test}.c) - target_link_libraries(test_${test} libssh2 runner ${LIBRARIES}) + if(TESTS STREQUAL "warmup") + target_link_libraries(test_${test} libssh2 ${LIBRARIES}) + else() + target_link_libraries(test_${test} libssh2 runner ${LIBRARIES}) + endif() target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") list(APPEND TEST_TARGETS test_${test}) add_definitions(-DFIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/tests/Makefile.am b/tests/Makefile.am index fb8c63299d..e321dfc82f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,6 +12,7 @@ check_PROGRAMS += ssh2 endif INTEGRATION_TESTS = \ + test_warmup \ test_agent_forward_succeeds \ test_hostkey \ test_hostkey_hash \ diff --git a/tests/test_warmup.c b/tests/test_warmup.c new file mode 100644 index 0000000000..dfbf6fa3ae --- /dev/null +++ b/tests/test_warmup.c @@ -0,0 +1,27 @@ +/* Warm-up test. Always return 0. + Workaround for CI/docker/etc flakiness on the first run. */ + +#include "session_fixture.h" +#include "runner.h" + +#include + +#include + +int main(void) +{ + LIBSSH2_SESSION *session = start_session_fixture(); + if(session != NULL) { + size_t len = 0; + int type = 0; + const char *hostkey = libssh2_session_hostkey(session, &len, &type); + + (void)hostkey; + + fprintf(stdout, + "libssh2_session_hostkey returned len, type: %d, %d\n", + (int)len, type); + } + stop_session_fixture(); + return 0; +} From adac94af31674e9a1854480eb359f9bfd722c40e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 10 Mar 2023 00:55:37 +0100 Subject: [PATCH 120/424] cmake: add wolfSSL support to tests (#833) wolfSSL supports building with zlib as a dependency, that's the reason for the ZLIB logic in the patch. Also add it to `docs/INSTALL_CMAKE.md` and to the help text in `src/CMakeLists.txt`. Running tests not actually tested. Follow-up to 9f217a17f6f3c2047c4a1668a5c037a75a02abfd Ref: #817 --- docs/INSTALL_CMAKE.md | 1 + src/CMakeLists.txt | 4 ++-- tests/CMakeLists.txt | 25 +++++++++++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index c136fdcee8..69a9b6a45d 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -10,6 +10,7 @@ To build libssh2 you will need CMake v2.8 or later [1] and one of the following cryptography libraries: * OpenSSL +* wolfSSL * Libgcrypt * WinCNG * mbedTLS diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 81c04554e3..6ec9b1dbfe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,8 +46,8 @@ set(CRYPTO_BACKEND "" CACHE STRING - "The backend to use for cryptography: OpenSSL, Libgcrypt or WinCNG, mbedTLS -or empty to try any available") + "The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt, +WinCNG, mbedTLS, or empty to try any available") # If the crypto backend was given, rather than searching for the first # we are able to find, the find_package commands must abort configuration diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cc230d072c..e123b34114 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -59,8 +59,8 @@ set(CRYPTO_BACKEND "" CACHE STRING - "The backend to use for cryptography: OpenSSL, Libgcrypt or WinCNG, mbedTLS -or empty to try any available") + "The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt, +WinCNG, mbedTLS, or empty to try any available") # If the crypto backend was given, rather than searching for the first # we are able to find, the find_package commands must abort configuration @@ -80,6 +80,23 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) endif() endif() +if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) + + find_package(wolfssl ${SPECIFIC_CRYPTO_REQUIREMENT}) + + if(WOLFSSL_FOUND) + set(CRYPTO_BACKEND "wolfSSL") + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WOLFSSL") + set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl) + + find_package(ZLIB) + + if(ZLIB_FOUND) + set(CRYPTO_BACKEND_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} ${CRYPTO_BACKEND_INCLUDE_DIR}) + endif() + endif() +endif() + if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT}) @@ -130,11 +147,11 @@ set(TESTS read ) -if(CRYPTO_BACKEND STREQUAL "OpenSSL") +if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR CRYPTO_BACKEND STREQUAL "wolfSSL") list(APPEND TESTS public_key_auth_succeeds_with_correct_rsa_openssh_key ) - if(OPENSSL_VERSION VERSION_GREATER "1.1.0") + if(OPENSSL_VERSION VERSION_GREATER "1.1.0" OR CRYPTO_BACKEND STREQUAL "wolfSSL") list(APPEND TESTS public_key_auth_succeeds_with_correct_ed25519_key public_key_auth_succeeds_with_correct_encrypted_ed25519_key From 0c04f44fb96def089c975563ade83f7f52240195 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 10 Mar 2023 00:56:35 +0100 Subject: [PATCH 121/424] cmake: reflect minimum version in docs (#834) Follow-up to 505ea626b6e125b7ce15caf453b522192008a884 --- docs/INSTALL_CMAKE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 69a9b6a45d..7aa0708b5f 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -6,7 +6,7 @@ Web site source code: https://github.com/libssh2/www Installation instructions are in docs/INSTALL ======= -To build libssh2 you will need CMake v2.8 or later [1] and one of the +To build libssh2 you will need CMake v3.1 or later [1] and one of the following cryptography libraries: * OpenSSL From f0b729f79162c949476d73fed756c25503a016d8 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 10 Mar 2023 11:08:57 +0100 Subject: [PATCH 122/424] cmake: drop unnecessary exception for warmup build (#835) --- tests/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e123b34114..c748e81580 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -183,11 +183,7 @@ target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") foreach(test ${TESTS}) add_executable(test_${test} test_${test}.c) - if(TESTS STREQUAL "warmup") - target_link_libraries(test_${test} libssh2 ${LIBRARIES}) - else() - target_link_libraries(test_${test} libssh2 runner ${LIBRARIES}) - endif() + target_link_libraries(test_${test} libssh2 runner ${LIBRARIES}) target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") list(APPEND TEST_TARGETS test_${test}) add_definitions(-DFIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") From 0e8971f443a858281f68d5f374334b46dc5ad737 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 10 Mar 2023 14:06:17 +0100 Subject: [PATCH 123/424] ci: retry choco install on appveyor (#837) Trying to mitigate occasional intermittent failures while installing docker. Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46460704/job/g3t7bro6ta6n3pk6#L52 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index e7023c2812..ba82eac204 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -88,7 +88,7 @@ install: $env:OPENSSH_SERVER_PORT = Get-Random -Minimum 2000 -Maximum 2300 [System.Environment]::SetEnvironmentVariable("OPENSSH_SERVER_PORT", $env:OPENSSH_SERVER_PORT) - ps: .\ci\appveyor\docker-bridge.ps1 - - choco install -y docker-cli + - appveyor-retry choco install -y docker-cli build_script: - ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" } From a2738165212ab03578d036c961b48120b801c337 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 10 Mar 2023 18:53:38 +0100 Subject: [PATCH 124/424] win32: convert tabs to spaces [ci skip] (#838) Also strip stray newlines from `win32/rules.mk`. --- win32/GNUmakefile | 178 ++++++++++++++++++++--------------------- win32/rules.mk | 3 - win32/test/GNUmakefile | 164 ++++++++++++++++++------------------- 3 files changed, 171 insertions(+), 174 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index eaafe233ff..31ca150553 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -19,71 +19,71 @@ endif # Edit the path below to point to your Distribution folder. ifndef DISTDIR -DISTDIR = libssh2-$(LIBSSH2_VERSION_STR)-bin-$(ARCH) +DISTDIR = libssh2-$(LIBSSH2_VERSION_STR)-bin-$(ARCH) endif -DISTARC = $(DISTDIR).zip +DISTARC = $(DISTDIR).zip # Edit the path below to point to your Development folder. ifndef DEVLDIR -DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-$(ARCH) +DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-$(ARCH) endif -DEVLARC = $(DEVLDIR).zip +DEVLARC = $(DEVLDIR).zip # Project root -PROOT = .. +PROOT = .. # Edit the vars below to change target settings. -TARGET = libssh2 -WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(LIBSSH2_VERSION_STR) -#STACK = 64000 +TARGET = libssh2 +WWWURL = https://www.libssh2.org/ +DESCR = libssh2 $(LIBSSH2_VERSION_STR) +#STACK = 64000 # must be equal to DEBUG or NDEBUG ifndef DB - DB = NDEBUG - # DB = DEBUG + DB = NDEBUG +# DB = DEBUG endif # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release + OPT = -O2 + OBJDIR = release else - OPT = -g - OPT += -DLIBSSH2DEBUG - OBJDIR = debug + OPT = -g + OPT += -DLIBSSH2DEBUG + OBJDIR = debug endif # Here you can find a native Win32 binary of the original awk: # http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk -ZIP = zip -qzr9 +AWK = awk +ZIP = zip -qzr9 # Platform-dependent helper tool macros ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +#COPYR = -cp -afr $1/* $2 +COPYR = -rsync -aC $1/* $2 +TOUCH = touch $1 +CAT = cat +ECHONL = echo "" +DL = ' else ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) +DEL = -del 2>NUL $(subst /,\,$1) +RMDIR = -deltree 2>NUL /y $(subst /,\,$1) endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) +COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) +TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, +CAT = type +ECHONL = $(ComSpec) /c echo. endif ifeq ($(LIBSSH2_RC),) @@ -110,12 +110,12 @@ CC = $(LIBSSH2_CC) ifndef ARCH ifeq ($(findstring gcc,$(CC)),gcc) ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) -ARCH = w64 +ARCH = w64 else -ARCH = w32 +ARCH = w32 endif else -ARCH = w32 +ARCH = w32 endif endif @@ -123,37 +123,37 @@ endif -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) +CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) LDFLAGS = $(LIBSSH2_LDFLAG_EXTRAS) -LIBEXT = a -LD = $(LIBSSH2_CC) -RC = $(LIBSSH2_RC) -LDFLAGS += -s -shared -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT) -AR = $(LIBSSH2_AR) -ARFLAGS = cru -RANLIB = $(LIBSSH2_RANLIB) -RCFLAGS = -I $(PROOT)/include -O coff -CFLAGS += -fno-builtin -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall # -pedantic +LIBEXT = a +LD = $(LIBSSH2_CC) +RC = $(LIBSSH2_RC) +LDFLAGS += -s -shared -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT) +AR = $(LIBSSH2_AR) +ARFLAGS = cru +RANLIB = $(LIBSSH2_RANLIB) +RCFLAGS = -I $(PROOT)/include -O coff +CFLAGS += -fno-builtin +CFLAGS += -fno-strict-aliasing +CFLAGS += -Wall # -pedantic ifeq ($(ARCH),w64) -CFLAGS += -m64 +CFLAGS += -m64 LDFLAGS += -m64 -RCFLAGS += -F pe-x86-64 +RCFLAGS += -F pe-x86-64 else ifeq ($(ARCH),w32) -CFLAGS += -m32 +CFLAGS += -m32 LDFLAGS += -m32 -RCFLAGS += -F pe-i386 +RCFLAGS += -F pe-i386 endif endif INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include ifdef WITH_WINCNG -CFLAGS += -DLIBSSH2_WINCNG -LDLIBS += -lbcrypt -lcrypt32 +CFLAGS += -DLIBSSH2_WINCNG +LDLIBS += -lbcrypt -lcrypt32 else ifdef MBEDTLS_PATH CFLAGS += -DLIBSSH2_MBEDTLS @@ -161,50 +161,50 @@ CFLAGS += -I"$(MBEDTLS_PATH)/include" LIBPATH += -L"$(MBEDTLS_PATH)/libs" LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto else -CFLAGS += -DLIBSSH2_OPENSSL +CFLAGS += -DLIBSSH2_OPENSSL ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc - endif - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include - endif + ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + endif + ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + endif endif ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" $(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) endif INCLUDES += -I"$(OPENSSL_INCLUDE)" ifndef OPENSSL_LIBPATH - OPENSSL_LIBS_STAT = crypto ssl - ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/out - OPENSSL_LIBS_DYN = eay32 ssl32 - endif - ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib - OPENSSL_LIBS_DYN = crypto.dll ssl.dll - endif + OPENSSL_LIBS_STAT = crypto ssl + ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/out + OPENSSL_LIBS_DYN = eay32 ssl32 + endif + ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib + OPENSSL_LIBS_DYN = crypto.dll ssl.dll + endif endif ifdef LINK_OPENSSL_STATIC - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 else - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) endif endif endif -LDLIBS += -lws2_32 +LDLIBS += -lws2_32 ifdef WITH_ZLIB - CFLAGS += -DLIBSSH2_HAVE_ZLIB - INCLUDES += -I$(ZLIB_PATH) - ifdef LINK_ZLIB_STATIC - LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) - else - LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT) - endif + CFLAGS += -DLIBSSH2_HAVE_ZLIB + INCLUDES += -I$(ZLIB_PATH) + ifdef LINK_ZLIB_STATIC + LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) + else + LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT) + endif endif -CFLAGS += $(INCLUDES) +CFLAGS += $(INCLUDES) vpath %.c $(PROOT)/src @@ -221,9 +221,9 @@ endif # include Makefile.inc to get CSOURCES define include $(PROOT)/Makefile.inc -OBJECTS := $(patsubst %.c,%.o,$(CSOURCES)) -OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS)) -OBJL = $(OBJS) $(OBJDIR)/$(TARGET).res +OBJECTS := $(patsubst %.c,%.o,$(CSOURCES)) +OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS)) +OBJL = $(OBJS) $(OBJDIR)/$(TARGET).res all: lib dll diff --git a/win32/rules.mk b/win32/rules.mk index bfb7784764..e5bd1a9467 100644 --- a/win32/rules.mk +++ b/win32/rules.mk @@ -1,4 +1,3 @@ - all-sub: $(INTDIR) all clean-sub: clean @@ -11,5 +10,3 @@ $(INTDIR): {$(SUBDIR)}.c{$(INTDIR)}.obj:: $(CC) -c $(CFLAGS) /Fo"$(INTDIR)\\" $< - - diff --git a/win32/test/GNUmakefile b/win32/test/GNUmakefile index 3be0095d74..9195b3d029 100644 --- a/win32/test/GNUmakefile +++ b/win32/test/GNUmakefile @@ -18,30 +18,30 @@ OPENSSL_PATH = ../../../openssl endif # Project root -PROOT = ../.. +PROOT = ../.. # Edit the var below to enable static linking of libssh2 and libz LINK_STATIC = 1 # Edit the vars below to change target settings. -SAMPLES = $(PROOT)/example +SAMPLES = $(PROOT)/example TARGETS := $(filter-out x11.exe,$(patsubst $(SAMPLES)/%.c,%.exe,$(strip $(wildcard $(SAMPLES)/*.c)))) -WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR) -#STACK = 64000 +WWWURL = https://www.libssh2.org/ +DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR) +#STACK = 64000 # must be equal to DEBUG or NDEBUG ifndef DB - DB = NDEBUG - # DB = DEBUG + DB = NDEBUG +# DB = DEBUG endif # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release + OPT = -O2 + OBJDIR = release else - OPT = -g - OBJDIR = debug + OPT = -g + OBJDIR = debug endif # Here you can find a native Win32 binary of the original awk: @@ -51,30 +51,30 @@ ZIP = zip -qzr9 # Platform-dependent helper tool macros ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +#COPYR = -cp -afr $1/* $2 +COPYR = -rsync -aC $1/* $2 +TOUCH = touch $1 +CAT = cat +ECHONL = echo "" +DL = ' else ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) +DEL = -del 2>NUL $(subst /,\,$1) +RMDIR = -deltree 2>NUL /y $(subst /,\,$1) endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) +COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) +TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, +CAT = type +ECHONL = $(ComSpec) /c echo. endif CC = $(CROSSPREFIX)gcc @@ -83,12 +83,12 @@ CC = $(CROSSPREFIX)gcc ifndef ARCH ifeq ($(findstring gcc,$(CC)),gcc) ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) -ARCH = w64 +ARCH = w64 else -ARCH = w32 +ARCH = w32 endif else -ARCH = w32 +ARCH = w32 endif endif @@ -96,27 +96,27 @@ endif -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS = $(OPT) -D$(DB) - -LD = $(CROSSPREFIX)gcc -RC = $(CROSSPREFIX)windres -LDFLAGS = -s -AR = $(CROSSPREFIX)ar -ARFLAGS = -cq -LIBEXT = a -#LDLIBS += -lwsock32 -LDLIBS += -lws2_32 -RCFLAGS = -I $(PROOT)/include -O coff -CFLAGS += -fno-builtin -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall #-Wno-unused #-pedantic +CFLAGS = $(OPT) -D$(DB) + +LD = $(CROSSPREFIX)gcc +RC = $(CROSSPREFIX)windres +LDFLAGS = -s +AR = $(CROSSPREFIX)ar +ARFLAGS = -cq +LIBEXT = a +#LDLIBS += -lwsock32 +LDLIBS += -lws2_32 +RCFLAGS = -I $(PROOT)/include -O coff +CFLAGS += -fno-builtin +CFLAGS += -fno-strict-aliasing +CFLAGS += -Wall #-Wno-unused #-pedantic ifeq ($(ARCH),w64) -CFLAGS += -m64 -RCFLAGS += -F pe-x86-64 +CFLAGS += -m64 +RCFLAGS += -F pe-x86-64 else ifeq ($(ARCH),w32) -CFLAGS += -m32 -RCFLAGS += -F pe-i386 +CFLAGS += -m32 +RCFLAGS += -F pe-i386 endif endif @@ -124,59 +124,59 @@ INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include LIBPATH += -L$(PROOT)/win32 ifdef LINK_STATIC - LDLIBS += -llibssh2 + LDLIBS += -llibssh2 else - LDLIBS += -llibssh2dll + LDLIBS += -llibssh2dll endif ifdef WITH_WINCNG -# CFLAGS += -DLIBSSH2_WINCNG -LDLIBS += -lbcrypt -lcrypt32 +# CFLAGS += -DLIBSSH2_WINCNG +LDLIBS += -lbcrypt -lcrypt32 else -# CFLAGS += -DLIBSSH2_OPENSSL +# CFLAGS += -DLIBSSH2_OPENSSL ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc - endif - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include - endif + ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + endif + ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + endif endif ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" $(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) endif INCLUDES += -I"$(OPENSSL_INCLUDE)" ifndef OPENSSL_LIBPATH - OPENSSL_LIBS_STAT = crypto ssl - ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/out - OPENSSL_LIBS_DYN = eay32 ssl32 - endif - ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib - OPENSSL_LIBS_DYN = crypto.dll ssl.dll - endif + OPENSSL_LIBS_STAT = crypto ssl + ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/out + OPENSSL_LIBS_DYN = eay32 ssl32 + endif + ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib + OPENSSL_LIBS_DYN = crypto.dll ssl.dll + endif endif ifdef LINK_STATIC ifdef LINK_OPENSSL_STATIC - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 else - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) endif endif endif ifdef WITH_ZLIB - CFLAGS += -DLIBSSH2_HAVE_ZLIB - INCLUDES += -I$(ZLIB_PATH) - ifdef LINK_ZLIB_STATIC - LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) - else - LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT) - endif + CFLAGS += -DLIBSSH2_HAVE_ZLIB + INCLUDES += -I$(ZLIB_PATH) + ifdef LINK_ZLIB_STATIC + LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) + else + LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT) + endif endif -CFLAGS += $(INCLUDES) +CFLAGS += $(INCLUDES) vpath %.c $(PROOT)/example From 0621f97c7b59afb44b6a8a99a088e3103f33a699 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 11 Mar 2023 11:06:42 +0100 Subject: [PATCH 125/424] GNUmakefile: cleanups [ci skip] (#840) - indent - sync `test/GNUmakefile` with main - delete `RANLIB` - use `else if` - use more `?=` - use ASCII-7 copyright symbol (in test) --- win32/GNUmakefile | 152 ++++++++++++++------------------- win32/test/GNUmakefile | 187 ++++++++++++++++++++--------------------- 2 files changed, 155 insertions(+), 184 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 31ca150553..e7d3849864 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -7,15 +7,14 @@ # ######################################################################### +# Project root +PROOT := .. + # Edit the path below to point to the base of your Zlib sources. -ifndef ZLIB_PATH -ZLIB_PATH = ../../zlib -endif +ZLIB_PATH ?= $(PROOT)/../zlib # Edit the path below to point to the base of your OpenSSL package. -ifndef OPENSSL_PATH -OPENSSL_PATH = ../../openssl -endif +OPENSSL_PATH ?= $(PROOT)/../openssl # Edit the path below to point to your Distribution folder. ifndef DISTDIR @@ -29,9 +28,6 @@ DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-$(ARCH) endif DEVLARC = $(DEVLDIR).zip -# Project root -PROOT = .. - # Edit the vars below to change target settings. TARGET = libssh2 WWWURL = https://www.libssh2.org/ @@ -39,10 +35,7 @@ DESCR = libssh2 $(LIBSSH2_VERSION_STR) #STACK = 64000 # must be equal to DEBUG or NDEBUG -ifndef DB - DB = NDEBUG -# DB = DEBUG -endif +DB ?= NDEBUG # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) OPT = -O2 @@ -86,37 +79,26 @@ CAT = type ECHONL = $(ComSpec) /c echo. endif -ifeq ($(LIBSSH2_RC),) -LIBSSH2_RC := $(CROSSPREFIX)windres -endif -ifeq ($(LIBSSH2_CC),) -LIBSSH2_CC := $(CROSSPREFIX)gcc -endif -ifeq ($(LIBSSH2_AR),) -LIBSSH2_AR := $(CROSSPREFIX)ar -endif -ifeq ($(LIBSSH2_RANLIB),) -LIBSSH2_RANLIB := $(CROSSPREFIX)ranlib -endif -ifeq ($(LIBSSH2_DLL_A_SUFFIX),) -LIBSSH2_DLL_A_SUFFIX := dll -endif +LIBSSH2_RC ?= $(CROSSPREFIX)windres +LIBSSH2_CC ?= $(CROSSPREFIX)gcc +LIBSSH2_AR ?= $(CROSSPREFIX)ar +LIBSSH2_DLL_A_SUFFIX ?= dll libssh2_dll_LIBRARY = $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll CC = $(LIBSSH2_CC) # Set environment var ARCH to your architecture to override autodetection. ifndef ARCH -ifeq ($(findstring gcc,$(CC)),gcc) -ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) -ARCH = w64 -else -ARCH = w32 -endif -else -ARCH = w32 -endif + ifeq ($(findstring gcc,$(CC)),gcc) + ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) + ARCH = w64 + else + ARCH = w32 + endif + else + ARCH = w32 + endif endif # Include the version info retrieved from libssh2.h @@ -132,66 +114,61 @@ RC = $(LIBSSH2_RC) LDFLAGS += -s -shared -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT) AR = $(LIBSSH2_AR) ARFLAGS = cru -RANLIB = $(LIBSSH2_RANLIB) RCFLAGS = -I $(PROOT)/include -O coff CFLAGS += -fno-builtin CFLAGS += -fno-strict-aliasing CFLAGS += -Wall # -pedantic ifeq ($(ARCH),w64) -CFLAGS += -m64 -LDFLAGS += -m64 -RCFLAGS += -F pe-x86-64 -else -ifeq ($(ARCH),w32) -CFLAGS += -m32 -LDFLAGS += -m32 -RCFLAGS += -F pe-i386 -endif + CFLAGS += -m64 + LDFLAGS += -m64 + RCFLAGS += -F pe-x86-64 +else ifeq ($(ARCH),w32) + CFLAGS += -m32 + LDFLAGS += -m32 + RCFLAGS += -F pe-i386 endif INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include ifdef WITH_WINCNG -CFLAGS += -DLIBSSH2_WINCNG -LDLIBS += -lbcrypt -lcrypt32 + CFLAGS += -DLIBSSH2_WINCNG + LDLIBS += -lbcrypt -lcrypt32 +else ifdef MBEDTLS_PATH + CFLAGS += -DLIBSSH2_MBEDTLS + CFLAGS += -I"$(MBEDTLS_PATH)/include" + LIBPATH += -L"$(MBEDTLS_PATH)/libs" + LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto else -ifdef MBEDTLS_PATH -CFLAGS += -DLIBSSH2_MBEDTLS -CFLAGS += -I"$(MBEDTLS_PATH)/include" -LIBPATH += -L"$(MBEDTLS_PATH)/libs" -LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto -else -CFLAGS += -DLIBSSH2_OPENSSL -ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + CFLAGS += -DLIBSSH2_OPENSSL + ifndef OPENSSL_INCLUDE + ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + endif + ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + endif endif - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" + $(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) endif -endif -ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" -$(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) -endif -INCLUDES += -I"$(OPENSSL_INCLUDE)" -ifndef OPENSSL_LIBPATH - OPENSSL_LIBS_STAT = crypto ssl - ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/out - OPENSSL_LIBS_DYN = eay32 ssl32 + INCLUDES += -I"$(OPENSSL_INCLUDE)" + ifndef OPENSSL_LIBPATH + OPENSSL_LIBS_STAT = crypto ssl + ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/out + OPENSSL_LIBS_DYN = eay32 ssl32 + endif + ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib + OPENSSL_LIBS_DYN = crypto.dll ssl.dll + endif endif - ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib - OPENSSL_LIBS_DYN = crypto.dll ssl.dll + ifdef LINK_OPENSSL_STATIC + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 + else + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) endif endif -ifdef LINK_OPENSSL_STATIC - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 -else - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) -endif -endif -endif LDLIBS += -lws2_32 ifdef WITH_ZLIB @@ -209,13 +186,11 @@ CFLAGS += $(INCLUDES) vpath %.c $(PROOT)/src ifdef WITH_WINCNG -include $(PROOT)/Makefile.WinCNG.inc + include $(PROOT)/Makefile.WinCNG.inc +else ifdef MBEDTLS_PATH + include $(PROOT)/Makefile.mbedTLS.inc else -ifdef MBEDTLS_PATH -include $(PROOT)/Makefile.mbedTLS.inc -else -include $(PROOT)/Makefile.OpenSSL.inc -endif + include $(PROOT)/Makefile.OpenSSL.inc endif # include Makefile.inc to get CSOURCES define @@ -305,9 +280,6 @@ $(TARGET).$(LIBEXT): $(OBJS) @echo Creating $@ @$(call DEL, $@) @$(AR) $(ARFLAGS) $@ $^ -ifdef RANLIB - @$(RANLIB) $@ -endif $(libssh2_dll_LIBRARY) $(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT): $(OBJL) @echo Linking $@ diff --git a/win32/test/GNUmakefile b/win32/test/GNUmakefile index 9195b3d029..67fc451fda 100644 --- a/win32/test/GNUmakefile +++ b/win32/test/GNUmakefile @@ -7,34 +7,27 @@ # ######################################################################### +# Project root +PROOT := ../.. + # Edit the path below to point to the base of your Zlib sources. -ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib -endif +ZLIB_PATH ?= $(PROOT)/../zlib # Edit the path below to point to the base of your OpenSSL package. -ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl -endif - -# Project root -PROOT = ../.. +OPENSSL_PATH ?= $(PROOT)/../openssl # Edit the var below to enable static linking of libssh2 and libz -LINK_STATIC = 1 +LINK_STATIC := 1 # Edit the vars below to change target settings. SAMPLES = $(PROOT)/example TARGETS := $(filter-out x11.exe,$(patsubst $(SAMPLES)/%.c,%.exe,$(strip $(wildcard $(SAMPLES)/*.c)))) WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR) +DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR) #STACK = 64000 # must be equal to DEBUG or NDEBUG -ifndef DB - DB = NDEBUG -# DB = DEBUG -endif +DB ?= NDEBUG # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) OPT = -O2 @@ -46,78 +39,81 @@ endif # Here you can find a native Win32 binary of the original awk: # http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk -ZIP = zip -qzr9 +AWK = awk +ZIP = zip -qzr9 # Platform-dependent helper tool macros ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +#COPYR = -cp -afr $1/* $2 +COPYR = -rsync -aC $1/* $2 +TOUCH = touch $1 +CAT = cat +ECHONL = echo "" +DL = ' else ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) +DEL = -del 2>NUL $(subst /,\,$1) +RMDIR = -deltree 2>NUL /y $(subst /,\,$1) endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) +COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) +TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, +CAT = type +ECHONL = $(ComSpec) /c echo. endif -CC = $(CROSSPREFIX)gcc +LIBSSH2_RC ?= $(CROSSPREFIX)windres +LIBSSH2_CC ?= $(CROSSPREFIX)gcc +LIBSSH2_AR ?= $(CROSSPREFIX)ar + +CC = $(LIBSSH2_CC) # Set environment var ARCH to your architecture to override autodetection. ifndef ARCH -ifeq ($(findstring gcc,$(CC)),gcc) -ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) -ARCH = w64 -else -ARCH = w32 -endif -else -ARCH = w32 -endif + ifeq ($(findstring gcc,$(CC)),gcc) + ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) + ARCH = w64 + else + ARCH = w32 + endif + else + ARCH = w32 + endif endif # Include the version info retrieved from libssh2.h -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS = $(OPT) -D$(DB) +CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) +LDFLAGS = $(LIBSSH2_LDFLAG_EXTRAS) -LD = $(CROSSPREFIX)gcc -RC = $(CROSSPREFIX)windres -LDFLAGS = -s -AR = $(CROSSPREFIX)ar -ARFLAGS = -cq LIBEXT = a -#LDLIBS += -lwsock32 -LDLIBS += -lws2_32 +LD = $(LIBSSH2_CC) +RC = $(LIBSSH2_RC) +LDFLAGS += -s +AR = $(LIBSSH2_AR) +ARFLAGS = cru RCFLAGS = -I $(PROOT)/include -O coff CFLAGS += -fno-builtin CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall #-Wno-unused #-pedantic +CFLAGS += -Wall # -pedantic ifeq ($(ARCH),w64) -CFLAGS += -m64 -RCFLAGS += -F pe-x86-64 -else -ifeq ($(ARCH),w32) -CFLAGS += -m32 -RCFLAGS += -F pe-i386 -endif + CFLAGS += -m64 + LDFLAGS += -m64 + RCFLAGS += -F pe-x86-64 +else ifeq ($(ARCH),w32) + CFLAGS += -m32 + LDFLAGS += -m32 + RCFLAGS += -F pe-i386 endif INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include @@ -130,41 +126,44 @@ else endif ifdef WITH_WINCNG -# CFLAGS += -DLIBSSH2_WINCNG -LDLIBS += -lbcrypt -lcrypt32 + LDLIBS += -lbcrypt -lcrypt32 +else ifdef MBEDTLS_PATH + CFLAGS += -I"$(MBEDTLS_PATH)/include" + LIBPATH += -L"$(MBEDTLS_PATH)/libs" + LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto else -# CFLAGS += -DLIBSSH2_OPENSSL -ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + ifndef OPENSSL_INCLUDE + ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + endif + ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + endif endif - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" + $(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) endif -endif -ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" -$(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) -endif -INCLUDES += -I"$(OPENSSL_INCLUDE)" -ifndef OPENSSL_LIBPATH - OPENSSL_LIBS_STAT = crypto ssl - ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/out - OPENSSL_LIBS_DYN = eay32 ssl32 + INCLUDES += -I"$(OPENSSL_INCLUDE)" + ifndef OPENSSL_LIBPATH + OPENSSL_LIBS_STAT = crypto ssl + ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/out + OPENSSL_LIBS_DYN = eay32 ssl32 + endif + ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib + OPENSSL_LIBS_DYN = crypto.dll ssl.dll + endif endif - ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib - OPENSSL_LIBS_DYN = crypto.dll ssl.dll + ifdef LINK_STATIC + ifdef LINK_OPENSSL_STATIC + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 + else + LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) + endif endif endif -ifdef LINK_STATIC -ifdef LINK_OPENSSL_STATIC - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 -else - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) -endif -endif -endif +LDLIBS += -lws2_32 ifdef WITH_ZLIB CFLAGS += -DLIBSSH2_HAVE_ZLIB @@ -172,7 +171,7 @@ ifdef WITH_ZLIB ifdef LINK_ZLIB_STATIC LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) else - LDLIBS += $(ZLIB_PATH)/libzdll.$(LIBEXT) + LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT) endif endif @@ -227,7 +226,7 @@ $(OBJDIR)/%.rc: GNUmakefile $(OBJDIR)/version.inc @echo $(DL) BEGIN$(DL) >> $@ @echo $(DL) BLOCK "040904E4"$(DL) >> $@ @echo $(DL) BEGIN$(DL) >> $@ - @echo $(DL) VALUE "LegalCopyright","\xA9 $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@ + @echo $(DL) VALUE "LegalCopyright","(C) $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@ ifdef COMPANY @echo $(DL) VALUE "CompanyName","$(COMPANY)\0"$(DL) >> $@ endif From 509c84e3c5aa84b6fc2c905a31c3149605f5bebe Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 11 Mar 2023 11:08:42 +0100 Subject: [PATCH 126/424] openssl: fix possible compiler warning in macro condition (#839) Building with wolfSSL or pre-OpenSSL v1.1.1 triggered it. ``` ../src/openssl.h:130:5: warning: 'LIBRESSL_VERSION_NUMBER' is not defined, evaluates to 0 [-Wundef] LIBRESSL_VERSION_NUMBER >= 0x3070000fL ^ ``` Regression from 2e2812dde8c1fc9b48eca592823770ab2e601f7a --- src/openssl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openssl.h b/src/openssl.h index 6d75007abd..a2f168aaa6 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -127,7 +127,8 @@ #if (OPENSSL_VERSION_NUMBER >= 0x10101000L && \ !defined(LIBRESSL_VERSION_NUMBER)) || \ - LIBRESSL_VERSION_NUMBER >= 0x3070000fL + (defined(LIBRESSL_VERSION_NUMBER) && \ + LIBRESSL_VERSION_NUMBER >= 0x3070000fL) # define LIBSSH2_ED25519 1 #else # define LIBSSH2_ED25519 0 From c45ba4d62402038b278b6231effbd9f732a7bc39 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 11 Mar 2023 16:43:13 +0100 Subject: [PATCH 127/424] src: C89-compliant _libssh2_debug() macro (#831) Before this patch, with debug logging disabled, libssh2 code used a variadic macro to catch `_libssh2_debug()` calls, and convert them to no-ops. In certain conditions, it used an empty inline function instead. Variadic macro is a C99 feature. It means that depending on compiler, and build settings, it littered the build log with warnings about this. The new solution uses the trick of passing the variable arg list as a single argument and pass that down to the debug function with a regular macro. When disabled, another regular C89-compatible macro converts it to a no-op. This makes inlining, C99 variadic macros and maintaining the conditions for each unnecessary and also makes the codebase compile more consistently, e.g. with forced C standards and/or picky warnings. TL;DR: It makes this feature C89-compliant. --- src/agent.c | 4 +- src/channel.c | 132 +++++++++++------------ src/comp.c | 12 +-- src/hostkey.c | 20 ++-- src/kex.c | 254 ++++++++++++++++++++++++--------------------- src/libssh2_priv.h | 21 +--- src/misc.c | 7 +- src/openssl.c | 76 +++++++------- src/packet.c | 95 ++++++++--------- src/publickey.c | 32 +++--- src/scp.c | 35 ++++--- src/session.c | 72 ++++++------- src/sftp.c | 133 ++++++++++++------------ src/transport.c | 33 +++--- src/userauth.c | 88 ++++++++-------- 15 files changed, 516 insertions(+), 498 deletions(-) diff --git a/src/agent.c b/src/agent.c index f1a3582566..a8c61cc9e7 100644 --- a/src/agent.c +++ b/src/agent.c @@ -478,10 +478,10 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, /* check to see if we match requested */ if((size_t)method_len != session->userauth_pblc_method_len || memcmp(method_name, session->userauth_pblc_method, method_len)) { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Agent sign method %.*s", - method_len, method_name); + method_len, method_name)); rc = LIBSSH2_ERROR_ALGO_UNSUPPORTED; goto error; diff --git a/src/channel.c b/src/channel.c index e57ddf94f9..74da24495e 100644 --- a/src/channel.c +++ b/src/channel.c @@ -81,8 +81,8 @@ _libssh2_channel_nextid(LIBSSH2_SESSION * session) * told... */ session->next_channel = id + 1; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, "Allocated new channel ID#%lu", - id); + _libssh2_debug((session, LIBSSH2_TRACE_CONN, + "Allocated new channel ID#%lu", id)); return id; } @@ -154,9 +154,9 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, memset(&session->open_packet_requirev_state, 0, sizeof(session->open_packet_requirev_state)); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Opening Channel - win %d pack %d", window_size, - packet_size); + packet_size)); session->open_channel = LIBSSH2_CALLOC(session, sizeof(LIBSSH2_CHANNEL)); if(!session->open_channel) { @@ -262,7 +262,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, _libssh2_ntohu32(session->open_data + 9); session->open_channel->local.packet_size = _libssh2_ntohu32(session->open_data + 13); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Connection Established - ID: %lu/%lu win: %lu/%lu" " pack: %lu/%lu", session->open_channel->local.id, @@ -270,7 +270,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, session->open_channel->local.window_size, session->open_channel->remote.window_size, session->open_channel->local.packet_size, - session->open_channel->remote.packet_size); + session->open_channel->remote.packet_size)); LIBSSH2_FREE(session, session->open_packet); session->open_packet = NULL; LIBSSH2_FREE(session, session->open_data); @@ -390,9 +390,9 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host, session->direct_message_len = session->direct_host_len + session->direct_shost_len + 16; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Requesting direct-tcpip session from %s:%d to %s:%d", - shost, sport, host, port); + shost, sport, host, port)); s = session->direct_message = LIBSSH2_ALLOC(session, session->direct_message_len); @@ -480,9 +480,9 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, memset(&session->fwdLstn_packet_requirev_state, 0, sizeof(session->fwdLstn_packet_requirev_state)); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Requesting tcpip-forward session for %s:%d", host, - port); + port)); s = session->fwdLstn_packet = LIBSSH2_ALLOC(session, session->fwdLstn_packet_len); @@ -567,10 +567,10 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, listener->host[session->fwdLstn_host_len] = 0; if(data_len >= 5 && !port) { listener->port = _libssh2_ntohu32(data + 1); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Dynamic tcpip-forward port " "allocated: %d", - listener->port); + listener->port)); } else listener->port = port; @@ -647,9 +647,9 @@ int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener) int retcode = 0; if(listener->chanFwdCncl_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Cancelling tcpip-forward session for %s:%d", - listener->host, listener->port); + listener->host, listener->port)); s = packet = LIBSSH2_ALLOC(session, packet_len); if(!packet) { @@ -818,10 +818,10 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, memset(&channel->setenv_packet_requirev_state, 0, sizeof(channel->setenv_packet_requirev_state)); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Setting remote environment variable: %s=%s on " "channel %lu/%lu", - varname, value, channel->local.id, channel->remote.id); + varname, value, channel->local.id, channel->remote.id)); s = channel->setenv_packet = LIBSSH2_ALLOC(session, channel->setenv_packet_len); @@ -953,9 +953,9 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, memset(&channel->reqPTY_packet_requirev_state, 0, sizeof(channel->reqPTY_packet_requirev_state)); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Allocating tty on channel %lu/%lu", channel->local.id, - channel->remote.id); + channel->remote.id)); s = channel->reqPTY_packet; @@ -1056,9 +1056,9 @@ static int channel_request_auth_agent(LIBSSH2_CHANNEL *channel, memset(&channel->req_auth_agent_requirev_state, 0, sizeof(channel->req_auth_agent_requirev_state)); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Requesting auth agent on channel %lu/%lu", - channel->local.id, channel->remote.id); + channel->local.id, channel->remote.id)); /* * byte SSH_MSG_CHANNEL_REQUEST @@ -1218,10 +1218,10 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width, memset(&channel->reqPTY_packet_requirev_state, 0, sizeof(channel->reqPTY_packet_requirev_state)); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "changing tty size on channel %lu/%lu", channel->local.id, - channel->remote.id); + channel->remote.id)); s = channel->reqPTY_packet; @@ -1307,13 +1307,13 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, memset(&channel->reqX11_packet_requirev_state, 0, sizeof(channel->reqX11_packet_requirev_state)); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Requesting x11-req for channel %lu/%lu: single=%d " "proto=%s cookie=%s screen=%d", channel->local.id, channel->remote.id, single_connection, auth_proto ? auth_proto : "MIT-MAGIC-COOKIE-1", - auth_cookie ? auth_cookie : "", screen_number); + auth_cookie ? auth_cookie : "", screen_number)); s = channel->reqX11_packet = LIBSSH2_ALLOC(session, channel->reqX11_packet_len); @@ -1465,10 +1465,10 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, if(message) channel->process_packet_len += + 4; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "starting request(%s) on channel %lu/%lu, message=%s", request, channel->local.id, channel->remote.id, - message ? message : ""); + message ? message : "")); s = channel->process_packet = LIBSSH2_ALLOC(session, channel->process_packet_len); if(!channel->process_packet) @@ -1597,8 +1597,8 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid) if(packet->data_len < 1) { packet = next; - _libssh2_debug(channel->session, LIBSSH2_TRACE_ERROR, - "Unexpected packet length"); + _libssh2_debug((channel->session, LIBSSH2_TRACE_ERROR, + "Unexpected packet length")); continue; } @@ -1634,11 +1634,11 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid) size_t bytes_to_flush = packet->data_len - packet->data_head; - _libssh2_debug(channel->session, LIBSSH2_TRACE_CONN, + _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, "Flushing %d bytes of data from stream " "%lu on channel %lu/%lu", bytes_to_flush, packet_stream_id, - channel->local.id, channel->remote.id); + channel->local.id, channel->remote.id)); /* It's one of the streams we wanted to flush */ channel->flush_refund_bytes += packet->data_len - 13; @@ -1797,10 +1797,10 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, if(!force && (adjustment + channel->adjust_queue < LIBSSH2_CHANNEL_MINADJUST)) { - _libssh2_debug(channel->session, LIBSSH2_TRACE_CONN, + _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, "Queueing %lu bytes for receive window adjustment " "for channel %lu/%lu", - adjustment, channel->local.id, channel->remote.id); + adjustment, channel->local.id, channel->remote.id)); channel->adjust_queue += adjustment; return 0; } @@ -1816,10 +1816,10 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, channel->adjust_adjust[0] = SSH_MSG_CHANNEL_WINDOW_ADJUST; _libssh2_htonu32(&channel->adjust_adjust[1], channel->remote.id); _libssh2_htonu32(&channel->adjust_adjust[5], adjustment); - _libssh2_debug(channel->session, LIBSSH2_TRACE_CONN, + _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, "Adjusting window %lu bytes for data on " "channel %lu/%lu", - adjustment, channel->local.id, channel->remote.id); + adjustment, channel->local.id, channel->remote.id)); channel->adjust_state = libssh2_NB_state_created; } @@ -1911,10 +1911,10 @@ int _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode) { if(channel->extData2_state == libssh2_NB_state_idle) { - _libssh2_debug(channel->session, LIBSSH2_TRACE_CONN, + _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, "Setting channel %lu/%lu handle_extended_data" " mode to %d", - channel->local.id, channel->remote.id, ignore_mode); + channel->local.id, channel->remote.id, ignore_mode)); channel->remote.extended_data_ignore_mode = (char)ignore_mode; channel->extData2_state = libssh2_NB_state_created; @@ -1994,11 +1994,11 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, LIBSSH2_PACKET *read_packet; LIBSSH2_PACKET *read_next; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "channel_read() wants %d bytes from channel %lu/%lu " "stream #%d", (int) buflen, channel->local.id, channel->remote.id, - stream_id); + stream_id)); /* expand the receiving window first if it has become too narrow */ if((channel->read_state == libssh2_NB_state_jump1) || @@ -2050,8 +2050,8 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, if(readpkt->data_len != 1 || readpkt->data[0] != SSH_MSG_REQUEST_FAILURE) { - _libssh2_debug(channel->session, LIBSSH2_TRACE_ERROR, - "Unexpected packet length"); + _libssh2_debug((channel->session, LIBSSH2_TRACE_ERROR, + "Unexpected packet length")); } continue; @@ -2091,11 +2091,11 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, unlink_packet = TRUE; } - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "channel_read() got %d of data from %lu/%lu/%d%s", bytes_want, channel->local.id, channel->remote.id, stream_id, - unlink_packet?" [ul]":""); + unlink_packet?" [ul]":"")); /* copy data from this struct to the target buffer */ memcpy(&buf[bytes_read], @@ -2200,8 +2200,8 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id) if(read_packet->data_len < 5) { read_packet = next_packet; - _libssh2_debug(channel->session, LIBSSH2_TRACE_ERROR, - "Unexpected packet length"); + _libssh2_debug((channel->session, LIBSSH2_TRACE_ERROR, + "Unexpected packet length")); continue; } @@ -2269,10 +2269,10 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, if(channel->write_state == libssh2_NB_state_idle) { unsigned char *s = channel->write_packet; - _libssh2_debug(channel->session, LIBSSH2_TRACE_CONN, + _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, "Writing %d bytes on channel %lu/%lu, stream #%d", (int) buflen, channel->local.id, channel->remote.id, - stream_id); + stream_id)); if(channel->local.close) return _libssh2_error(channel->session, @@ -2318,19 +2318,19 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, /* Don't exceed the remote end's limits */ /* REMEMBER local means local as the SOURCE of the data */ if(channel->write_bufwrite > channel->local.window_size) { - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Splitting write block due to %lu byte " "window_size on %lu/%lu/%d", channel->local.window_size, channel->local.id, - channel->remote.id, stream_id); + channel->remote.id, stream_id)); channel->write_bufwrite = channel->local.window_size; } if(channel->write_bufwrite > channel->local.packet_size) { - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Splitting write block due to %lu byte " "packet_size on %lu/%lu/%d", channel->local.packet_size, channel->local.id, - channel->remote.id, stream_id); + channel->remote.id, stream_id)); channel->write_bufwrite = channel->local.packet_size; } /* store the size here only, the buffer is passed in as-is to @@ -2338,10 +2338,10 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, _libssh2_store_u32(&s, channel->write_bufwrite); channel->write_packet_len = s - channel->write_packet; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Sending %d bytes on channel %lu/%lu, stream_id=%d", (int) channel->write_bufwrite, channel->local.id, - channel->remote.id, stream_id); + channel->remote.id, stream_id)); channel->write_state = libssh2_NB_state_created; } @@ -2413,9 +2413,9 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel) unsigned char packet[5]; /* packet_type(1) + channelno(4) */ int rc; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Sending EOF on channel %lu/%lu", - channel->local.id, channel->remote.id); + channel->local.id, channel->remote.id)); packet[0] = SSH_MSG_CHANNEL_EOF; _libssh2_htonu32(packet + 1, channel->remote.id); rc = _libssh2_transport_send(session, packet, 5, NULL, 0); @@ -2474,8 +2474,8 @@ libssh2_channel_eof(LIBSSH2_CHANNEL * channel) if(packet->data_len < 1) { packet = next_packet; - _libssh2_debug(channel->session, LIBSSH2_TRACE_ERROR, - "Unexpected packet length"); + _libssh2_debug((channel->session, LIBSSH2_TRACE_ERROR, + "Unexpected packet length")); continue; } @@ -2503,9 +2503,9 @@ static int channel_wait_eof(LIBSSH2_CHANNEL *channel) int rc; if(channel->wait_eof_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Awaiting EOF for channel %lu/%lu", channel->local.id, - channel->remote.id); + channel->remote.id)); channel->wait_eof_state = libssh2_NB_state_created; } @@ -2585,8 +2585,8 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel) late for us to wait for it. Continue closing! */ if(channel->close_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_CONN, "Closing channel %lu/%lu", - channel->local.id, channel->remote.id); + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Closing channel %lu/%lu", + channel->local.id, channel->remote.id)); channel->close_packet[0] = SSH_MSG_CHANNEL_CLOSE; _libssh2_htonu32(channel->close_packet + 1, channel->remote.id); @@ -2675,9 +2675,9 @@ static int channel_wait_closed(LIBSSH2_CHANNEL *channel) } if(channel->wait_closed_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Awaiting close of channel %lu/%lu", channel->local.id, - channel->remote.id); + channel->remote.id)); channel->wait_closed_state = libssh2_NB_state_created; } @@ -2738,9 +2738,9 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel) assert(session); if(channel->free_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Freeing channel %lu/%lu resources", channel->local.id, - channel->remote.id); + channel->remote.id)); channel->free_state = libssh2_NB_state_created; } @@ -2857,8 +2857,8 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, if(packet->data_len < 1) { packet = next_packet; - _libssh2_debug(channel->session, LIBSSH2_TRACE_ERROR, - "Unexpected packet length"); + _libssh2_debug((channel->session, LIBSSH2_TRACE_ERROR, + "Unexpected packet length")); continue; } diff --git a/src/comp.c b/src/comp.c index 90ab30c89d..96ed2e98fd 100644 --- a/src/comp.c +++ b/src/comp.c @@ -163,8 +163,8 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compr, if(status != Z_OK) { LIBSSH2_FREE(session, strm); - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "unhandled zlib error %d", status); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "unhandled zlib error %d", status)); return LIBSSH2_ERROR_COMPRESS; } *abstract = strm; @@ -204,9 +204,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION *session, return 0; } - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "unhandled zlib compression error %d, avail_out", - status, strm->avail_out); + status, strm->avail_out)); return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compression failure"); } @@ -276,8 +276,8 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session, else { /* error state */ LIBSSH2_FREE(session, out); - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "unhandled zlib error %d", status); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "unhandled zlib error %d", status)); return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, "decompression failure"); } diff --git a/src/hostkey.c b/src/hostkey.c index 23917d8e6c..647c83acb5 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -73,8 +73,8 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, } if(hostkey_data_len < 19) { - _libssh2_debug(session, LIBSSH2_TRACE_ERROR, - "host key length too short"); + _libssh2_debug((session, LIBSSH2_TRACE_ERROR, + "host key length too short")); return -1; } @@ -99,8 +99,8 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, } #endif else { - _libssh2_debug(session, LIBSSH2_TRACE_ERROR, - "unexpected rsa type: %.*s", type_len, type); + _libssh2_debug((session, LIBSSH2_TRACE_ERROR, + "unexpected rsa type: %.*s", type_len, type)); return -1; } @@ -498,8 +498,8 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session, } if(hostkey_data_len < 27) { - _libssh2_debug(session, LIBSSH2_TRACE_ERROR, - "host key length too short"); + _libssh2_debug((session, LIBSSH2_TRACE_ERROR, + "host key length too short")); return -1; } @@ -725,8 +725,8 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session, } if(hostkey_data_len < 39) { - _libssh2_debug(session, LIBSSH2_TRACE_ERROR, - "host key length too short"); + _libssh2_debug((session, LIBSSH2_TRACE_ERROR, + "host key length too short")); return -1; } @@ -1064,8 +1064,8 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session, } if(hostkey_data_len < 19) { - _libssh2_debug(session, LIBSSH2_TRACE_ERROR, - "host key length too short"); + _libssh2_debug((session, LIBSSH2_TRACE_ERROR, + "host key length too short")); return -1; } diff --git a/src/kex.c b/src/kex.c index a1d12b113e..299055fd0c 100644 --- a/src/kex.c +++ b/src/kex.c @@ -296,8 +296,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, exchange_state->e_packet + 6); } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sending KEX packet %d", - (int) packet_type_init); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Sending KEX packet %d", + (int) packet_type_init)); exchange_state->state = libssh2_NB_state_created; } @@ -323,9 +323,9 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, * need to silently ignore it */ int burn_type; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Waiting for badly guessed KEX packet " - "(to be ignored)"); + "(to be ignored)")); burn_type = _libssh2_packet_burn(session, &exchange_state->burn_state); if(burn_type == LIBSSH2_ERROR_EAGAIN) { @@ -338,9 +338,9 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, } session->burn_optimistic_kexinit = 0; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Burnt packet of type: %02x", - (unsigned int) burn_type); + (unsigned int) burn_type)); } exchange_state->state = libssh2_NB_state_sent1; @@ -411,8 +411,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, snprintf(fprint, 4, "%02x:", session->server_hostkey_md5[i]); } *(--fprint) = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server's MD5 Fingerprint: %s", fingerprint); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server's MD5 Fingerprint: %s", fingerprint)); } #endif /* LIBSSH2DEBUG */ #endif /* ! LIBSSH2_MD5 */ @@ -440,8 +440,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); } *(--fprint) = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server's SHA1 Fingerprint: %s", fingerprint); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server's SHA1 Fingerprint: %s", fingerprint)); } #endif /* LIBSSH2DEBUG */ @@ -467,9 +467,9 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, session->server_hostkey_sha256, SHA256_DIGEST_LENGTH, &base64Fingerprint); if(base64Fingerprint != NULL) { - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server's SHA256 Fingerprint: %s", - base64Fingerprint); + base64Fingerprint)); LIBSSH2_FREE(session, base64Fingerprint); } } @@ -633,7 +633,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, goto clean_exit; } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sending NEWKEYS message"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sending NEWKEYS message")); exchange_state->c = SSH_MSG_NEWKEYS; exchange_state->state = libssh2_NB_state_sent2; @@ -668,7 +669,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, /* The first key exchange has been performed, switch to active crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Received NEWKEYS message"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Received NEWKEYS message")); /* This will actually end up being just packet_type(1) for this packet type anyway */ @@ -685,8 +687,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, memcpy(session->session_id, exchange_state->h_sig_comp, digest_len); session->session_id_len = digest_len; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "session_id calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "session_id calculated")); } /* Cleanup any existing cipher */ @@ -739,8 +741,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, secret); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server IV and Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server IV and Key calculated")); if(session->remote.crypt->dtor) { /* Cleanup any existing cipher */ @@ -789,8 +791,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, secret); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client IV and Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client IV and Key calculated")); if(session->local.mac->dtor) { session->local.mac->dtor(session, &session->local.mac_abstract); @@ -816,8 +818,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, key); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server HMAC Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server HMAC Key calculated")); if(session->remote.mac->dtor) { session->remote.mac->dtor(session, &session->remote.mac_abstract); @@ -843,8 +845,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, key); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client HMAC Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client HMAC Key calculated")); /* Initialize compression for each direction */ @@ -861,8 +863,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, goto clean_exit; } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server compression initialized"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server compression initialized")); if(session->remote.comp && session->remote.comp->dtor) { session->remote.comp->dtor(session, 0, @@ -876,8 +878,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, goto clean_exit; } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client compression initialized"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client compression initialized")); } @@ -954,8 +956,8 @@ kex_method_diffie_hellman_group1_sha1_key_exchange(LIBSSH2_SESSION *session, _libssh2_bn_set_word(key_state->g, 2); _libssh2_bn_from_bin(key_state->p, 128, p_value); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group1 Key Exchange"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Initiating Diffie-Hellman Group1 Key Exchange")); key_state->state = libssh2_NB_state_created; } @@ -1047,8 +1049,8 @@ kex_method_diffie_hellman_group14_key_exchange(LIBSSH2_SESSION *session, _libssh2_bn_set_word(key_state->g, 2); _libssh2_bn_from_bin(key_state->p, 256, p_value); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group14 Key Exchange"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Initiating Diffie-Hellman Group14 Key Exchange")); key_state->state = libssh2_NB_state_created; } @@ -1169,8 +1171,8 @@ kex_method_diffie_hellman_group16_sha512_key_exchange(LIBSSH2_SESSION *session, _libssh2_bn_set_word(key_state->g, 2); _libssh2_bn_from_bin(key_state->p, 512, p_value); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group16 Key Exchange"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Initiating Diffie-Hellman Group16 Key Exchange")); key_state->state = libssh2_NB_state_created; } @@ -1302,8 +1304,8 @@ kex_method_diffie_hellman_group18_sha512_key_exchange(LIBSSH2_SESSION *session, _libssh2_bn_set_word(key_state->g, 2); _libssh2_bn_from_bin(key_state->p, 1024, p_value); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group18 Key Exchange"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Initiating Diffie-Hellman Group18 Key Exchange")); key_state->state = libssh2_NB_state_created; } @@ -1346,16 +1348,16 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange _libssh2_htonu32(key_state->request + 5, LIBSSH2_DH_GEX_OPTGROUP); _libssh2_htonu32(key_state->request + 9, LIBSSH2_DH_GEX_MAXGROUP); key_state->request_len = 13; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Initiating Diffie-Hellman Group-Exchange " - "(New Method)"); + "(New Method)")); #else key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST_OLD; _libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_OPTGROUP); key_state->request_len = 5; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Initiating Diffie-Hellman Group-Exchange " - "(Old Method)"); + "(Old Method)")); #endif key_state->state = libssh2_NB_state_created; @@ -1473,16 +1475,16 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange _libssh2_htonu32(key_state->request + 5, LIBSSH2_DH_GEX_OPTGROUP); _libssh2_htonu32(key_state->request + 9, LIBSSH2_DH_GEX_MAXGROUP); key_state->request_len = 13; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Initiating Diffie-Hellman Group-Exchange " - "(New Method SHA256)"); + "(New Method SHA256)")); #else key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST_OLD; _libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_OPTGROUP); key_state->request_len = 5; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Initiating Diffie-Hellman Group-Exchange " - "(Old Method SHA256)"); + "(Old Method SHA256)")); #endif key_state->state = libssh2_NB_state_created; @@ -1794,8 +1796,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, snprintf(fprint, 4, "%02x:", session->server_hostkey_md5[i]); } *(--fprint) = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server's MD5 Fingerprint: %s", fingerprint); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server's MD5 Fingerprint: %s", fingerprint)); } #endif /* LIBSSH2DEBUG */ #endif /* ! LIBSSH2_MD5 */ @@ -1823,8 +1825,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); } *(--fprint) = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server's SHA1 Fingerprint: %s", fingerprint); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server's SHA1 Fingerprint: %s", fingerprint)); } #endif /* LIBSSH2DEBUG */ @@ -1851,9 +1853,9 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, session->server_hostkey_sha256, SHA256_DIGEST_LENGTH, &base64Fingerprint); if(base64Fingerprint != NULL) { - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server's SHA256 Fingerprint: %s", - base64Fingerprint); + base64Fingerprint)); LIBSSH2_FREE(session, base64Fingerprint); } } @@ -1969,7 +1971,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, /* The first key exchange has been performed, switch to active crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Received NEWKEYS message"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Received NEWKEYS message")); /* This will actually end up being just packet_type(1) for this packet type anyway */ @@ -2001,8 +2004,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, memcpy(session->session_id, exchange_state->h_sig_comp, digest_length); session->session_id_len = digest_length; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "session_id calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "session_id calculated")); } /* Cleanup any existing cipher */ @@ -2053,8 +2056,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, LIBSSH2_FREE(session, secret); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server IV and Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server IV and Key calculated")); if(session->remote.crypt->dtor) { /* Cleanup any existing cipher */ @@ -2103,8 +2106,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, LIBSSH2_FREE(session, secret); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client IV and Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client IV and Key calculated")); if(session->local.mac->dtor) { session->local.mac->dtor(session, &session->local.mac_abstract); @@ -2130,8 +2133,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, LIBSSH2_FREE(session, key); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server HMAC Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server HMAC Key calculated")); if(session->remote.mac->dtor) { session->remote.mac->dtor(session, &session->remote.mac_abstract); @@ -2157,8 +2160,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, LIBSSH2_FREE(session, key); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client HMAC Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client HMAC Key calculated")); /* Initialize compression for each direction */ @@ -2175,8 +2178,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, goto clean_exit; } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server compression initialized"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server compression initialized")); if(session->remote.comp && session->remote.comp->dtor) { session->remote.comp->dtor(session, 0, @@ -2190,8 +2193,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, goto clean_exit; } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client compression initialized"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client compression initialized")); } @@ -2256,8 +2259,8 @@ kex_method_ecdh_key_exchange key_state->public_key_oct_len); key_state->request_len = key_state->public_key_oct_len + 5; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Initiating ECDH SHA2 NISTP256"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Initiating ECDH SHA2 NISTP256")); key_state->state = libssh2_NB_state_sent; } @@ -2420,8 +2423,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, snprintf(fprint, 4, "%02x:", session->server_hostkey_md5[i]); } *(--fprint) = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server's MD5 Fingerprint: %s", fingerprint); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server's MD5 Fingerprint: %s", fingerprint)); } #endif /* LIBSSH2DEBUG */ #endif /* ! LIBSSH2_MD5 */ @@ -2449,8 +2452,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); } *(--fprint) = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server's SHA1 Fingerprint: %s", fingerprint); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server's SHA1 Fingerprint: %s", fingerprint)); } #endif /* LIBSSH2DEBUG */ @@ -2477,9 +2480,9 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, session->server_hostkey_sha256, SHA256_DIGEST_LENGTH, &base64Fingerprint); if(base64Fingerprint != NULL) { - _libssh2_debug(session, LIBSSH2_TRACE_KEX, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server's SHA256 Fingerprint: %s", - base64Fingerprint); + base64Fingerprint)); LIBSSH2_FREE(session, base64Fingerprint); } } @@ -2591,7 +2594,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Received NEWKEYS message"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Received NEWKEYS message")); /* This will actually end up being just packet_type(1) for this packet type anyway */ @@ -2610,8 +2614,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, memcpy(session->session_id, exchange_state->h_sig_comp, digest_length); session->session_id_len = digest_length; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "session_id calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "session_id calculated")); } /* Cleanup any existing cipher */ @@ -2662,8 +2666,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, LIBSSH2_FREE(session, secret); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server IV and Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server IV and Key calculated")); if(session->remote.crypt->dtor) { /* Cleanup any existing cipher */ @@ -2712,8 +2716,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, LIBSSH2_FREE(session, secret); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client IV and Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client IV and Key calculated")); if(session->local.mac->dtor) { session->local.mac->dtor(session, &session->local.mac_abstract); @@ -2739,8 +2743,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, LIBSSH2_FREE(session, key); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server HMAC Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server HMAC Key calculated")); if(session->remote.mac->dtor) { session->remote.mac->dtor(session, &session->remote.mac_abstract); @@ -2766,8 +2770,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, LIBSSH2_FREE(session, key); } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client HMAC Key calculated"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client HMAC Key calculated")); /* Initialize compression for each direction */ @@ -2784,8 +2788,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, goto clean_exit; } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Client to Server compression initialized"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Client to Server compression initialized")); if(session->remote.comp && session->remote.comp->dtor) { session->remote.comp->dtor(session, 0, @@ -2799,8 +2803,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, goto clean_exit; } } - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Server to Client compression initialized"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Server to Client compression initialized")); } clean_exit: @@ -2865,8 +2869,8 @@ kex_method_curve25519_key_exchange LIBSSH2_ED25519_KEY_LEN); key_state->request_len = LIBSSH2_ED25519_KEY_LEN + 5; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, - "Initiating curve25519 SHA2"); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Initiating curve25519 SHA2")); key_state->state = libssh2_NB_state_sent; } @@ -3234,25 +3238,35 @@ static int kexinit(LIBSSH2_SESSION * session) /* Funnily enough, they'll all "appear" to be '\0' terminated */ unsigned char *p = data + 21; /* type(1) + cookie(16) + len(4) */ - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent KEX: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent KEX: %s", p)); p += kex_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent HOSTKEY: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent HOSTKEY: %s", p)); p += hostkey_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent CRYPT_CS: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent CRYPT_CS: %s", p)); p += crypt_cs_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent CRYPT_SC: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent CRYPT_SC: %s", p)); p += crypt_sc_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent MAC_CS: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent MAC_CS: %s", p)); p += mac_cs_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent MAC_SC: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent MAC_SC: %s", p)); p += mac_sc_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent COMP_CS: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent COMP_CS: %s", p)); p += comp_cs_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent COMP_SC: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent COMP_SC: %s", p)); p += comp_sc_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent LANG_CS: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent LANG_CS: %s", p)); p += lang_cs_len + 4; - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Sent LANG_SC: %s", p); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Sent LANG_SC: %s", p)); p += lang_sc_len + 4; } #endif /* LIBSSH2DEBUG */ @@ -3768,22 +3782,30 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data, } #endif - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on KEX method: %s", - session->kex->name); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on HOSTKEY method: %s", - session->hostkey->name); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on CRYPT_CS method: %s", - session->local.crypt->name); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on CRYPT_SC method: %s", - session->remote.crypt->name); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on MAC_CS method: %s", - session->local.mac->name); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on MAC_SC method: %s", - session->remote.mac->name); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on COMP_CS method: %s", - session->local.comp->name); - _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on COMP_SC method: %s", - session->remote.comp->name); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on KEX method: %s", + session->kex->name)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on HOSTKEY method: %s", + session->hostkey->name)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on CRYPT_CS method: %s", + session->local.crypt->name)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on CRYPT_SC method: %s", + session->remote.crypt->name)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on MAC_CS method: %s", + session->local.mac->name)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on MAC_SC method: %s", + session->remote.mac->name)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on COMP_CS method: %s", + session->local.comp->name)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, + "Agreed on COMP_SC method: %s", + session->remote.comp->name)); return 0; } diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 358421a0b4..4f77e5f394 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -993,23 +993,12 @@ struct _LIBSSH2_COMP_METHOD }; #ifdef LIBSSH2DEBUG -void _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, - ...); +void +_libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, + ...); +#define _libssh2_debug(x) _libssh2_debug_low x #else -#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ - (defined(__GNUC__) && !defined(__clang__)) -/* C99 supported and also by older GCC */ -#define _libssh2_debug(x,y,...) do {} while (0) -#else -/* no gcc and not C99, do static and hopefully inline */ -static inline void -_libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...) -{ - (void)session; - (void)context; - (void)format; -} -#endif +#define _libssh2_debug(x) do {} while (0) #endif #define LIBSSH2_SOCKET_UNKNOWN 1 diff --git a/src/misc.c b/src/misc.c index 269fccac20..74a6d5a762 100644 --- a/src/misc.c +++ b/src/misc.c @@ -119,8 +119,8 @@ int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode, /* if this is EAGAIN and we're in non-blocking mode, don't generate a debug output for this */ return errcode; - _libssh2_debug(session, LIBSSH2_TRACE_ERROR, "%d - %s", session->err_code, - session->err_msg); + _libssh2_debug((session, LIBSSH2_TRACE_ERROR, "%d - %s", session->err_code, + session->err_msg)); #endif return errcode; @@ -477,7 +477,8 @@ libssh2_trace_sethandler(LIBSSH2_SESSION *session, void *handler_context, } void -_libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...) +_libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, + ...) { char buffer[1536]; int len, msglen, buflen = sizeof(buffer); diff --git a/src/openssl.c b/src/openssl.c index b103644642..131a4231e7 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -898,9 +898,9 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, unsigned char *method_buf = NULL; size_t key_len; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing public key from RSA private key envelope"); + "Computing public key from RSA private key envelope")); rsa = EVP_PKEY_get1_RSA(pk); if(rsa == NULL) { @@ -1025,9 +1025,9 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, unsigned char *n, *e, *d, *p, *q, *coeff, *comment; RSA *rsa = NULL; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing RSA keys from private key data"); + "Computing RSA keys from private key data")); /* public key data */ if(_libssh2_get_bignum_bytes(decrypted, &n, &nlen)) { @@ -1076,9 +1076,9 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, if((rc = _libssh2_rsa_new(&rsa, e, elen, n, nlen, d, dlen, p, plen, q, qlen, NULL, 0, NULL, 0, coeff, coefflen)) != 0) { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Could not create RSA private key"); + "Could not create RSA private key")); goto fail; } @@ -1287,9 +1287,9 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, unsigned char *method_buf = NULL; size_t key_len; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing public key from DSA private key envelope"); + "Computing public key from DSA private key envelope")); dsa = EVP_PKEY_get1_DSA(pk); if(dsa == NULL) { @@ -1342,9 +1342,9 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, unsigned char *p, *q, *g, *pub_key, *priv_key; DSA *dsa = NULL; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing DSA keys from private key data"); + "Computing DSA keys from private key data")); if(_libssh2_get_bignum_bytes(decrypted, &p, &plen)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -1379,9 +1379,9 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, rc = _libssh2_dsa_new(&dsa, p, plen, q, qlen, g, glen, pub_key, pub_len, priv_key, priv_len); if(rc != 0) { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_ERROR_PROTO, - "Could not create DSA private key"); + "Could not create DSA private key")); goto fail; } @@ -1638,8 +1638,8 @@ gen_publickey_from_ed_evp(LIBSSH2_SESSION *session, size_t bufLen = 0; unsigned char *bufPos = NULL; - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Computing public key from ED private key envelope"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Computing public key from ED private key envelope")); methodBuf = LIBSSH2_ALLOC(session, sizeof(methodName) - 1); if(!methodBuf) { @@ -1705,9 +1705,9 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, size_t key_len = 0, tmp_len = 0; unsigned char *p; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing ED25519 keys from private key data"); + "Computing ED25519 keys from private key data")); if(_libssh2_get_string(decrypted, &pub_key, &tmp_len) || tmp_len != LIBSSH2_ED25519_KEY_LEN) { @@ -1744,8 +1744,8 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, memcpy(comment, buf, tmp_len); memcpy(comment + tmp_len, "\0", 1); - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Key comment: %s", - comment); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Key comment: %s", + comment)); LIBSSH2_FREE(session, comment); } @@ -1765,10 +1765,10 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, } if(ret == 0) { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Computing public key from ED25519 " - "private key envelope"); + "private key envelope")); method_buf = LIBSSH2_ALLOC(session, 11); /* ssh-ed25519. */ if(method_buf == NULL) { @@ -1855,9 +1855,9 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, size_t key_len = 0, app_len = 0, tmp_len = 0; unsigned char *p; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing sk-ED25519 keys from private key data"); + "Computing sk-ED25519 keys from private key data")); if(_libssh2_get_string(decrypted, &pub_key, &tmp_len) || tmp_len != LIBSSH2_ED25519_KEY_LEN) { @@ -1900,10 +1900,10 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, LIBSSH2_ED25519_KEY_LEN); if(ret == 0) { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Computing public key from ED25519 " - "private key envelope"); + "private key envelope")); /* sk-ssh-ed25519@openssh.com. */ method_buf = LIBSSH2_ALLOC(session, strlen(key_type)); @@ -2645,9 +2645,9 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, BN_CTX *bn_ctx; libssh2_curve_type type; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing public key from EC private key envelope"); + "Computing public key from EC private key envelope")); bn_ctx = BN_CTX_new(); if(bn_ctx == NULL) @@ -2683,9 +2683,9 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, else if(type == LIBSSH2_EC_CURVE_NISTP521) memcpy(method_buf, "ecdsa-sha2-nistp521", *method_len); else { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_ERROR, - "Unsupported EC private key type"); + "Unsupported EC private key type")); rc = -1; goto clean_exit; } @@ -2779,9 +2779,9 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, EC_KEY *ec_key = NULL; BIGNUM *bn_exponent; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing ECDSA keys from private key data"); + "Computing ECDSA keys from private key data")); if(_libssh2_get_string(decrypted, &curve, &curvelen) || curvelen == 0) { @@ -2865,9 +2865,9 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, unsigned char *curve, *point_buf, *p, *key, *app; EC_KEY *ec_key = NULL; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Extracting ECDSA-SK public key"); + "Extracting ECDSA-SK public key")); if(_libssh2_get_string(decrypted, &curve, &curvelen) || curvelen == 0) { @@ -3574,10 +3574,10 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, int pktype; int rc; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Computing public key from private key file: %s", - privatekey); + privatekey)); bp = BIO_new_file(privatekey, "r"); if(bp == NULL) { @@ -3919,9 +3919,9 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, EVP_PKEY* pk; int pktype; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing public key from private key."); + "Computing public key from private key.")); bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len); if(!bp) @@ -4009,9 +4009,9 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, BIO* bp; EVP_PKEY* pk; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, - "Computing public key from private key."); + "Computing public key from private key.")); bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len); if(!bp) diff --git a/src/packet.c b/src/packet.c index 40bd64c04e..035839550b 100644 --- a/src/packet.c +++ b/src/packet.c @@ -133,10 +133,10 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, "Data too short extracting sport"); } - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Remote received connection from %s:%ld to %s:%ld", listen_state->shost, listen_state->sport, - listen_state->host, listen_state->port); + listen_state->host, listen_state->port)); listen_state->state = libssh2_NB_state_allocated; } @@ -156,8 +156,8 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, (listn->queue_maxsize <= listn->queue_size)) { /* Queue is full */ failure_code = SSH_OPEN_RESOURCE_SHORTAGE; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, - "Listener queue full, ignoring"); + _libssh2_debug((session, LIBSSH2_TRACE_CONN, + "Listener queue full, ignoring")); listen_state->state = libssh2_NB_state_sent; break; } @@ -206,14 +206,14 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, listen_state->initial_window_size; channel->local.packet_size = listen_state->packet_size; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Connection queued: channel %lu/%lu " "win %lu/%lu packet %lu/%lu", channel->local.id, channel->remote.id, channel->local.window_size, channel->remote.window_size, channel->local.packet_size, - channel->remote.packet_size); + channel->remote.packet_size)); p = listen_state->packet; *(p++) = SSH_MSG_CHANNEL_OPEN_CONFIRMATION; @@ -346,10 +346,10 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, goto x11_exit; } - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "X11 Connection Received from %s:%ld on channel %lu", x11open_state->shost, x11open_state->sport, - x11open_state->sender_channel); + x11open_state->sender_channel)); x11open_state->state = libssh2_NB_state_allocated; } @@ -391,14 +391,14 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, channel->local.window_size = x11open_state->initial_window_size; channel->local.packet_size = x11open_state->packet_size; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "X11 Connection established: channel %lu/%lu " "win %lu/%lu packet %lu/%lu", channel->local.id, channel->remote.id, channel->local.window_size, channel->remote.window_size, channel->local.packet_size, - channel->remote.packet_size); + channel->remote.packet_size)); p = x11open_state->packet; *(p++) = SSH_MSG_CHANNEL_OPEN_CONFIRMATION; _libssh2_store_u32(&p, channel->remote.id); @@ -487,9 +487,9 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, switch(session->packAdd_state) { case libssh2_NB_state_idle: - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Packet type %d received, length=%d", - (int) msg, (int) datalen); + (int) msg, (int) datalen)); if((macstate == LIBSSH2_MAC_INVALID) && (!session->macerror || @@ -547,9 +547,9 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, language_len); } - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Disconnect(%d): %s(%s)", reason, - message, language); + message, language)); } LIBSSH2_FREE(session, data); @@ -609,8 +609,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, * _libssh2_debug will actually truncate this for us so * that it's not an inordinate about of data */ - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "Debug Packet: %s", message); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "Debug Packet: %s", message)); LIBSSH2_FREE(session, data); session->packAdd_state = libssh2_NB_state_idle; return 0; @@ -650,10 +650,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, _libssh2_get_string(&buf, &value, &value_len); if(name != NULL && value != NULL) { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server to Client extension %.*s: %.*s", - name_len, name, value_len, value); + name_len, name, value_len, value)); } if(name_len == 15 && @@ -698,10 +698,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, len = _libssh2_ntohu32(data + 1); if((len <= (UINT_MAX - 6)) && (datalen >= (6 + len))) { want_reply = data[5 + len]; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Received global request type %.*s (wr %X)", - len, data + 5, want_reply); + len, data + 5, want_reply)); } @@ -760,12 +760,12 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, if(msg == SSH_MSG_CHANNEL_EXTENDED_DATA) stream_id = _libssh2_ntohu32(data + 5); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "%d bytes packet_add() for %lu/%lu/%lu", (int) (datalen - data_head), channelp->local.id, channelp->remote.id, - stream_id); + stream_id)); } #endif if((channelp->remote.extended_data_ignore_mode == @@ -774,21 +774,21 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, /* Pretend we didn't receive this */ LIBSSH2_FREE(session, data); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Ignoring extended data and refunding %d bytes", - (int) (datalen - 13)); + (int) (datalen - 13))); if(channelp->read_avail + datalen - data_head >= channelp->remote.window_size) datalen = channelp->remote.window_size - channelp->read_avail + data_head; channelp->remote.window_size -= datalen - data_head; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "shrinking window size by %lu bytes to %lu, " "read_avail %lu", datalen - data_head, channelp->remote.window_size, - channelp->read_avail); + channelp->read_avail)); session->packAdd_channelp = channelp; @@ -852,11 +852,11 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, * from an upper layer */ channelp->read_avail += datalen - data_head; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "increasing read_avail by %lu bytes to %lu/%lu", (long)(datalen - data_head), (long)channelp->read_avail, - (long)channelp->remote.window_size); + (long)channelp->remote.window_size)); break; @@ -874,11 +874,11 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, /* We may have freed already, just quietly ignore this... */ ; else { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "EOF received for channel %lu/%lu", channelp->local.id, - channelp->remote.id); + channelp->remote.id)); channelp->remote.eof = 1; } LIBSSH2_FREE(session, data); @@ -902,10 +902,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, if((len + 9) < datalen) want_reply = data[len + 9]; - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Channel %d received request type %.*s (wr %X)", - channel, len, data + 9, want_reply); + channel, len, data + 9, want_reply)); if(len == sizeof("exit-status") - 1 && (sizeof("exit-status") - 1 + 9) <= datalen @@ -920,12 +920,12 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, if(channelp && (sizeof("exit-status") + 13) <= datalen) { channelp->exit_status = _libssh2_ntohu32(data + 9 + sizeof("exit-status")); - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Exit status %lu received for " "channel %lu/%lu", channelp->exit_status, channelp->local.id, - channelp->remote.id); + channelp->remote.id)); } } @@ -959,12 +959,12 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, data + 13 + sizeof("exit-signal"), namelen); channelp->exit_signal[namelen] = '\0'; /* TODO: save error message and language tag */ - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Exit signal %s received for " "channel %lu/%lu", channelp->exit_signal, channelp->local.id, - channelp->remote.id); + channelp->remote.id)); } } } @@ -1001,10 +1001,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, session->packAdd_state = libssh2_NB_state_idle; return 0; } - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Close received for channel %lu/%lu", channelp->local.id, - channelp->remote.id); + channelp->remote.id)); channelp->remote.close = 1; channelp->remote.eof = 1; @@ -1076,13 +1076,13 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, if(channelp) { channelp->local.window_size += bytestoadd; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Window adjust for channel %lu/%lu, " "adding %lu bytes, new window_size=%lu", channelp->local.id, channelp->remote.id, bytestoadd, - channelp->local.window_size); + channelp->local.window_size)); } } LIBSSH2_FREE(session, data); @@ -1099,8 +1099,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, LIBSSH2_PACKET *packetp = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET)); if(!packetp) { - _libssh2_debug(session, LIBSSH2_ERROR_ALLOC, - "memory for packet"); + _libssh2_debug((session, LIBSSH2_ERROR_ALLOC, + "memory for packet")); LIBSSH2_FREE(session, data); session->packAdd_state = libssh2_NB_state_idle; return LIBSSH2_ERROR_ALLOC; @@ -1123,7 +1123,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, * Well, it's already in the brigade, * let's just call back into ourselves */ - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Renegotiating Keys"); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "Renegotiating Keys")); session->packAdd_state = libssh2_NB_state_sent2; } @@ -1168,8 +1169,8 @@ _libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type, { LIBSSH2_PACKET *packet = _libssh2_list_first(&session->packets); - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "Looking for packet of type: %d", (int) packet_type); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "Looking for packet of type: %d", (int) packet_type)); while(packet) { if(packet->data[0] == packet_type @@ -1310,8 +1311,8 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session, return i; } - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "Blocking until packet becomes available to burn"); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "Blocking until packet becomes available to burn")); *state = libssh2_NB_state_created; } diff --git a/src/publickey.c b/src/publickey.c index f26c6327dc..ac6d4ec111 100644 --- a/src/publickey.c +++ b/src/publickey.c @@ -310,8 +310,8 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session) session->pkeyInit_pkey = NULL; session->pkeyInit_channel = NULL; - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, - "Initializing publickey subsystem"); + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, + "Initializing publickey subsystem")); session->pkeyInit_state = libssh2_NB_state_allocated; } @@ -387,9 +387,9 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session) session->pkeyInit_buffer_sent = 0; - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, "Sending publickey advertising version %d support", - (int) LIBSSH2_PUBLICKEY_VERSION); + (int) LIBSSH2_PUBLICKEY_VERSION)); session->pkeyInit_state = libssh2_NB_state_sent2; } @@ -511,16 +511,16 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session) session->pkeyInit_pkey->version = _libssh2_ntohu32(s); if(session->pkeyInit_pkey->version > LIBSSH2_PUBLICKEY_VERSION) { - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, "Truncate remote publickey version " "from %lu", - session->pkeyInit_pkey->version); + session->pkeyInit_pkey->version)); session->pkeyInit_pkey->version = LIBSSH2_PUBLICKEY_VERSION; } - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, "Enabling publickey subsystem version %lu", - session->pkeyInit_pkey->version); + session->pkeyInit_pkey->version)); LIBSSH2_FREE(session, session->pkeyInit_data); session->pkeyInit_data = NULL; session->pkeyInit_state = libssh2_NB_state_idle; @@ -607,8 +607,8 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, if(pkey->add_state == libssh2_NB_state_idle) { pkey->add_packet = NULL; - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, "Adding %s publickey", - name); + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, + "Adding %s publickey", name)); if(pkey->version == 1) { for(i = 0; i < num_attrs; i++) { @@ -689,10 +689,10 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, } } - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, "Sending publickey \"add\" packet: " "type=%s blob_len=%ld num_attrs=%ld", - name, blob_len, num_attrs); + name, blob_len, num_attrs)); pkey->add_state = libssh2_NB_state_created; } @@ -773,10 +773,10 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, memcpy(pkey->remove_s, blob, blob_len); pkey->remove_s += blob_len; - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, "Sending publickey \"remove\" packet: " "type=%s blob_len=%ld", - name, blob_len); + name, blob_len)); pkey->remove_state = libssh2_NB_state_created; } @@ -842,8 +842,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, memcpy(pkey->listFetch_s, "list", sizeof("list") - 1); pkey->listFetch_s += sizeof("list") - 1; - _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, - "Sending publickey \"list\" packet"); + _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, + "Sending publickey \"list\" packet")); pkey->listFetch_state = libssh2_NB_state_created; } diff --git a/src/scp.c b/src/scp.c index 8cb3d65c3b..fd797ab6db 100644 --- a/src/scp.c +++ b/src/scp.c @@ -306,8 +306,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) /* the command to exec should _not_ be NUL-terminated */ session->scpRecv_command_len = cmd_len; - _libssh2_debug(session, LIBSSH2_TRACE_SCP, - "Opening channel for SCP receive"); + _libssh2_debug((session, LIBSSH2_TRACE_SCP, + "Opening channel for SCP receive")); session->scpRecv_state = libssh2_NB_state_created; } @@ -356,7 +356,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) LIBSSH2_FREE(session, session->scpRecv_command); session->scpRecv_command = NULL; - _libssh2_debug(session, LIBSSH2_TRACE_SCP, "Sending initial wakeup"); + _libssh2_debug((session, LIBSSH2_TRACE_SCP, "Sending initial wakeup")); /* SCP ACK */ session->scpRecv_response[0] = '\0'; @@ -435,9 +435,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) /* zero terminate the error */ err_msg[err_len] = 0; - _libssh2_debug(session, LIBSSH2_TRACE_SCP, + _libssh2_debug((session, LIBSSH2_TRACE_SCP, "got %02x %s", session->scpRecv_response[0], - err_msg); + err_msg)); _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Failed to recv file"); @@ -561,9 +561,10 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) goto scp_recv_error; } - _libssh2_debug(session, LIBSSH2_TRACE_SCP, + _libssh2_debug((session, LIBSSH2_TRACE_SCP, "mtime = %ld, atime = %ld", - session->scpRecv_mtime, session->scpRecv_atime); + session->scpRecv_mtime, + session->scpRecv_atime)); /* We *should* check that atime.usec is valid, but why let that stop use? */ @@ -723,9 +724,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) else if(rc != 1) { goto scp_recv_error; } - _libssh2_debug(session, LIBSSH2_TRACE_SCP, + _libssh2_debug((session, LIBSSH2_TRACE_SCP, "mode = 0%lo size = %ld", session->scpRecv_mode, - session->scpRecv_size); + session->scpRecv_size)); /* We *should* check that basename is valid, but why let that stop us? */ @@ -864,8 +865,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, /* the command to exec should _not_ be NUL-terminated */ session->scpSend_command_len = cmd_len; - _libssh2_debug(session, LIBSSH2_TRACE_SCP, - "Opening channel for SCP send"); + _libssh2_debug((session, LIBSSH2_TRACE_SCP, + "Opening channel for SCP send")); /* Allocate a channel */ session->scpSend_state = libssh2_NB_state_created; @@ -947,8 +948,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, snprintf((char *) session->scpSend_response, LIBSSH2_SCP_RESPONSE_BUFLEN, "T%ld 0 %ld 0\n", (long)mtime, (long)atime); - _libssh2_debug(session, LIBSSH2_TRACE_SCP, "Sent %s", - session->scpSend_response); + _libssh2_debug((session, LIBSSH2_TRACE_SCP, "Sent %s", + session->scpSend_response)); } session->scpSend_state = libssh2_NB_state_sent2; @@ -1018,8 +1019,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %" LIBSSH2_INT64_T_FORMAT " %s\n", mode, size, base); - _libssh2_debug(session, LIBSSH2_TRACE_SCP, "Sent %s", - session->scpSend_response); + _libssh2_debug((session, LIBSSH2_TRACE_SCP, "Sent %s", + session->scpSend_response)); session->scpSend_state = libssh2_NB_state_sent5; } @@ -1077,9 +1078,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, err_msg, err_len); if(rc > 0) { err_msg[err_len] = 0; - _libssh2_debug(session, LIBSSH2_TRACE_SCP, + _libssh2_debug((session, LIBSSH2_TRACE_SCP, "got %02x %s", session->scpSend_response[0], - err_msg); + err_msg)); } LIBSSH2_FREE(session, err_msg); _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, diff --git a/src/session.c b/src/session.c index 63a73ec20e..04f58bfe31 100644 --- a/src/session.c +++ b/src/session.c @@ -120,12 +120,12 @@ banner_receive(LIBSSH2_SESSION * session) if(ret < 0) { if(session->api_block_mode || (ret != -EAGAIN)) /* ignore EAGAIN when non-blocking */ - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, - "Error recving %d bytes: %d", 1, -ret); + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Error recving %d bytes: %d", 1, -ret)); } else - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, - "Recved %d bytes banner", ret); + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Recved %d bytes banner", ret)); if(ret < 0) { if(ret == -EAGAIN) { @@ -183,8 +183,8 @@ banner_receive(LIBSSH2_SESSION * session) } memcpy(session->remote.banner, session->banner_TxRx_banner, banner_len); session->remote.banner[banner_len] = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Received Banner: %s", - session->remote.banner); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Received Banner: %s", + session->remote.banner)); return LIBSSH2_ERROR_NONE; } @@ -225,8 +225,8 @@ banner_send(LIBSSH2_SESSION * session) banner_dup[255] = '\0'; } - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Sending Banner: %s", - banner_dup); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Sending Banner: %s", + banner_dup)); #endif session->banner_TxRx_state = libssh2_NB_state_created; @@ -240,14 +240,14 @@ banner_send(LIBSSH2_SESSION * session) banner_len - session->banner_TxRx_total_send, LIBSSH2_SOCKET_SEND_FLAGS(session)); if(ret < 0) - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Error sending %d bytes: %d", - banner_len - session->banner_TxRx_total_send, -ret); + banner_len - session->banner_TxRx_total_send, -ret)); else - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Sent %d/%d bytes at %p+%d", ret, banner_len - session->banner_TxRx_total_send, - banner, session->banner_TxRx_total_send); + banner, session->banner_TxRx_total_send)); if(ret != (banner_len - session->banner_TxRx_total_send)) { if(ret >= 0 || ret == -EAGAIN) { @@ -445,8 +445,8 @@ libssh2_session_banner_set(LIBSSH2_SESSION * session, const char *banner) /* first zero terminate like this so that the debug output is nice */ session->local.banner[banner_len] = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Setting local Banner: %s", - session->local.banner); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Setting local Banner: %s", + session->local.banner)); session->local.banner[banner_len++] = '\r'; session->local.banner[banner_len++] = '\n'; session->local.banner[banner_len] = '\0'; @@ -503,8 +503,8 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), session->abstract = abstract; session->api_timeout = 0; /* timeout-free API by default */ session->api_block_mode = 1; /* blocking API by default */ - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "New session resource allocated"); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "New session resource allocated")); _libssh2_init_if_needed(); } return session; @@ -569,8 +569,8 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session, session->recv = callback; return oldcb; } - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Setting Callback %d", - cbtype); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Setting Callback %d", + cbtype)); return NULL; } @@ -611,8 +611,8 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) dir = libssh2_session_block_directions(session); if(!dir) { - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, - "Nothing to wait for in wait_socket"); + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Nothing to wait for in wait_socket")); /* To avoid that we hang below just because there's nothing set to wait for, we timeout on 1 second to also avoid busy-looping during this condition */ @@ -698,8 +698,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) int rc; if(session->startup_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "session_startup for socket %d", sock); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "session_startup for socket %d", sock)); if(LIBSSH2_INVALID_SOCKET == sock) { /* Did we forget something? */ return _libssh2_error(session, LIBSSH2_ERROR_BAD_SOCKET, @@ -760,8 +760,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) } if(session->startup_state == libssh2_NB_state_sent2) { - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "Requesting userauth service"); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "Requesting userauth service")); /* Request the userauth service */ session->startup_service[0] = SSH_MSG_SERVICE_REQUEST; @@ -877,9 +877,9 @@ session_free(LIBSSH2_SESSION *session) int packets_left = 0; if(session->free_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Freeing session resource", - session->remote.banner); + session->remote.banner)); session->free_state = libssh2_NB_state_created; } @@ -1084,8 +1084,8 @@ session_free(LIBSSH2_SESSION *session) /* Cleanup all remaining packets */ while((pkg = _libssh2_list_first(&session->packets)) != NULL) { packets_left++; - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "packet left with id %d", pkg->data[0]); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "packet left with id %d", pkg->data[0])); /* unlink the node */ _libssh2_list_remove(&pkg->node); @@ -1094,15 +1094,15 @@ session_free(LIBSSH2_SESSION *session) LIBSSH2_FREE(session, pkg); } (void)packets_left; - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "Extra packets left %d", packets_left); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "Extra packets left %d", packets_left)); if(session->socket_prev_blockstate) { /* if the socket was previously blocking, put it back so */ rc = session_nonblock(session->socket_fd, 0); if(rc) { - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "unable to reset socket's blocking state"); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "unable to reset socket's blocking state")); } } @@ -1150,9 +1150,9 @@ session_disconnect(LIBSSH2_SESSION *session, int reason, int rc; if(session->disconnect_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Disconnecting: reason=%d, desc=%s, lang=%s", reason, - description, lang); + description, lang)); if(description) descr_len = strlen(description); @@ -1395,8 +1395,8 @@ int _libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking) { int bl = session->api_block_mode; - _libssh2_debug(session, LIBSSH2_TRACE_CONN, - "Setting blocking mode %s", blocking?"ON":"OFF"); + _libssh2_debug((session, LIBSSH2_TRACE_CONN, + "Setting blocking mode %s", blocking?"ON":"OFF")); session->api_block_mode = blocking; return bl; diff --git a/src/sftp.c b/src/sftp.c index 2df918aaef..707a18d628 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -160,10 +160,10 @@ remove_zombie_request(LIBSSH2_SFTP *sftp, uint32_t request_id) struct sftp_zombie_requests *zombie = find_zombie_request(sftp, request_id); if(zombie) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Removing request ID %ld from the list of " "zombie requests", - request_id); + request_id)); _libssh2_list_remove(&zombie->node); LIBSSH2_FREE(session, zombie); @@ -177,8 +177,8 @@ add_zombie_request(LIBSSH2_SFTP *sftp, uint32_t request_id) struct sftp_zombie_requests *zombie; - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "Marking request ID %ld as a zombie request", request_id); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Marking request ID %ld as a zombie request", request_id)); zombie = LIBSSH2_ALLOC(sftp->channel->session, sizeof(struct sftp_zombie_requests)); @@ -209,9 +209,9 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data, return LIBSSH2_ERROR_OUT_OF_BOUNDARY; } - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Received packet type %d (len %d)", - (int) data[0], data_len); + (int) data[0], data_len)); /* * Experience shows that if we mess up EAGAIN handling somewhere or @@ -256,8 +256,8 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data, request_id = _libssh2_ntohu32(&data[1]); - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Received packet id %d", - request_id); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Received packet id %d", + request_id)); /* Don't add the packet if it answers a request we've given up on. */ if((data[0] == SSH_FXP_STATUS || data[0] == SSH_FXP_DATA) @@ -302,7 +302,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) unsigned long recv_window; int packet_type; - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "recv packet"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "recv packet")); switch(sftp->packet_state) { case libssh2_NB_state_sent: /* EAGAIN from window adjusting */ @@ -316,11 +316,11 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) packet = sftp->partial_packet; - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "partial read cont, len: %lu", sftp->partial_len); - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "partial read cont, len: %lu", sftp->partial_len)); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "partial read cont, already recvd: %lu", - sftp->partial_received); + sftp->partial_received)); /* fall-through */ default: if(!packet) { @@ -359,9 +359,9 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) LIBSSH2_ERROR_ALLOC, "Unable to allocate empty SFTP packet"); - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Data begin - Packet Length: %lu", - sftp->partial_len); + sftp->partial_len)); packet = LIBSSH2_ALLOC(session, sftp->partial_len); if(!packet) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -527,13 +527,13 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, return LIBSSH2_ERROR_BAD_USE; } - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Requiring packet %d id %ld", - (int) packet_type, request_id); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Requiring packet %d id %ld", + (int) packet_type, request_id)); if(sftp_packet_ask(sftp, packet_type, request_id, data, data_len) == 0) { /* The right packet was available in the packet brigade */ - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Got %d", - (int) packet_type); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Got %d", + (int) packet_type)); if (*data_len < required_size) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; @@ -550,8 +550,8 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, /* data was read, check the queue again */ if(!sftp_packet_ask(sftp, packet_type, request_id, data, data_len)) { /* The right packet was available in the packet brigade */ - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Got %d", - (int) packet_type); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Got %d", + (int) packet_type)); if (*data_len < required_size) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; @@ -772,8 +772,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) unsigned char *endp; if(session->sftpInit_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "Initializing SFTP subsystem"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Initializing SFTP subsystem")); /* * The 'sftpInit_sftp' and 'sftpInit_channel' struct fields within the @@ -860,10 +860,10 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) _libssh2_htonu32(session->sftpInit_buffer + 5, LIBSSH2_SFTP_VERSION); session->sftpInit_sent = 0; /* nothing's sent yet */ - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Sending FXP_INIT packet advertising " "version %d support", - (int) LIBSSH2_SFTP_VERSION); + (int) LIBSSH2_SFTP_VERSION)); session->sftpInit_state = libssh2_NB_state_sent2; } @@ -929,14 +929,14 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) } if(sftp_handle->version > LIBSSH2_SFTP_VERSION) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Truncating remote SFTP version from %lu", - sftp_handle->version); + sftp_handle->version)); sftp_handle->version = LIBSSH2_SFTP_VERSION; } - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Enabling SFTP version %lu compatibility", - sftp_handle->version); + sftp_handle->version)); while(buf.dataptr < endp) { unsigned char *extname, *extdata; @@ -1147,8 +1147,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, s += sftp_attr2bin(s, &attrs); } - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Sending %s open request", - open_file? "file" : "directory"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Sending %s open request", + open_file? "file" : "directory")); sftp->open_state = libssh2_NB_state_created; } @@ -1228,8 +1228,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, sftp->last_errno = _libssh2_ntohu32(data + 5); if(LIBSSH2_FX_OK == sftp->last_errno) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "got HANDLE FXOK!"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "got HANDLE FXOK!")); LIBSSH2_FREE(session, data); @@ -1258,9 +1258,9 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, if(badness) { _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, "Failed opening remote file"); - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "got FXP_STATUS %d", - sftp->last_errno); + sftp->last_errno)); LIBSSH2_FREE(session, data); return NULL; } @@ -1304,7 +1304,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, fp->u.file.offset = 0; fp->u.file.offset_sent = 0; - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Open command successful"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Open command successful")); return fp; } return NULL; @@ -1504,9 +1505,9 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, _libssh2_list_add(&handle->packet_list, &chunk->node); count -= MIN(size, count); /* deduct the size we used, as we might * have to create more packets */ - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "read request id %d sent (offset: %d, size: %d)", - request_id, (int)chunk->offset, (int)chunk->len); + request_id, (int)chunk->offset, (int)chunk->len)); } /* FALL-THROUGH */ case libssh2_NB_state_sent: @@ -1857,9 +1858,9 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, LIBSSH2_FREE(session, handle->u.dir.names_packet); end: - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "libssh2_sftp_readdir_ex() return %d", - filename_len); + filename_len)); return (ssize_t)filename_len; } @@ -1881,8 +1882,8 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, } if(sftp->readdir_state == libssh2_NB_state_created) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "Reading entries from directory handle"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Reading entries from directory handle")); retcode = _libssh2_channel_write(channel, 0, sftp->readdir_packet, packet_len); if(retcode == LIBSSH2_ERROR_EAGAIN) { @@ -1938,8 +1939,8 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, sftp->readdir_state = libssh2_NB_state_idle; num_names = _libssh2_ntohu32(data + 5); - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%lu entries returned", - num_names); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "%lu entries returned", + num_names)); if(!num_names) { LIBSSH2_FREE(session, data); return 0; @@ -2251,8 +2252,8 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle) uint32_t retcode; if(sftp->fsync_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "Issuing fsync command"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Issuing fsync command")); s = packet = LIBSSH2_ALLOC(session, packet_len); if(!packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -2360,8 +2361,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, ssize_t rc; if(sftp->fstat_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Issuing %s command", - setstat ? "set-stat" : "stat"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Issuing %s command", + setstat ? "set-stat" : "stat")); s = sftp->fstat_packet = LIBSSH2_ALLOC(session, packet_len); if(!sftp->fstat_packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -2582,7 +2583,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) int rc = 0; if(handle->close_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Closing handle"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Closing handle")); s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len); if(!handle->close_packet) { handle->close_state = libssh2_NB_state_idle; @@ -2713,7 +2714,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, int rc; if(sftp->unlink_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Unlinking %s", filename)); s = sftp->unlink_packet = LIBSSH2_ALLOC(session, packet_len); if(!sftp->unlink_packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -2825,8 +2827,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, } if(sftp->rename_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Renaming %s to %s", - source_filename, dest_filename); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Renaming %s to %s", + source_filename, dest_filename)); sftp->rename_s = sftp->rename_packet = LIBSSH2_ALLOC(session, packet_len); if(!sftp->rename_packet) { @@ -2961,8 +2963,8 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) { SSH_FXP_EXTENDED_REPLY, SSH_FXP_STATUS }; if(sftp->fstatvfs_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "Getting file system statistics"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Getting file system statistics")); s = packet = LIBSSH2_ALLOC(session, packet_len); if(!packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -3097,8 +3099,8 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, { SSH_FXP_EXTENDED_REPLY, SSH_FXP_STATUS }; if(sftp->statvfs_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "Getting file system statistics of %s", path); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Getting file system statistics of %s", path)); s = packet = LIBSSH2_ALLOC(session, packet_len); if(!packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -3241,8 +3243,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, packet_len = path_len + 13 + sftp_attrsize(attrs.flags); if(sftp->mkdir_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "Creating directory %s with mode 0%lo", path, mode); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, + "Creating directory %s with mode 0%lo", path, mode)); s = packet = LIBSSH2_ALLOC(session, packet_len); if(!packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -3305,7 +3307,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_FREE(session, data); if(retcode == LIBSSH2_FX_OK) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "OK!"); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "OK!")); return 0; } else { @@ -3348,8 +3350,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, int rc; if(sftp->rmdir_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Removing directory: %s", - path); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Removing directory: %s", + path)); s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len); if(!sftp->rmdir_packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -3454,10 +3456,10 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, int rc; if(sftp->stat_state == libssh2_NB_state_idle) { - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%s %s", + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "%s %s", (stat_type == LIBSSH2_SFTP_SETSTAT) ? "Set-statting" : (stat_type == - LIBSSH2_SFTP_LSTAT ? "LStatting" : "Statting"), path); + LIBSSH2_SFTP_LSTAT ? "LStatting" : "Statting"), path)); s = sftp->stat_packet = LIBSSH2_ALLOC(session, packet_len); if(!sftp->stat_packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -3603,11 +3605,12 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, "SYMLINK/READLINK/REALPATH packet"); } - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%s %s on %s", + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "%s %s on %s", (link_type == LIBSSH2_SFTP_SYMLINK) ? "Creating" : "Reading", (link_type == - LIBSSH2_SFTP_REALPATH) ? "realpath" : "symlink", path); + LIBSSH2_SFTP_REALPATH) ? "realpath" : "symlink", + path)); _libssh2_store_u32(&s, packet_len - 4); diff --git a/src/transport.c b/src/transport.c index f591ce689f..c0cf749d87 100644 --- a/src/transport.c +++ b/src/transport.c @@ -308,8 +308,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) /* Whoever wants a packet won't get anything until the key re-exchange * is done! */ - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Redirecting into the" - " key re-exchange from _libssh2_transport_read"); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Redirecting into the" + " key re-exchange from _libssh2_transport_read")); rc = _libssh2_kex_exchange(session, 1, &session->startup_key_state); if(rc) return rc; @@ -383,14 +383,14 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) LIBSSH2_SESSION_BLOCK_INBOUND; return LIBSSH2_ERROR_EAGAIN; } - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Error recving %d bytes (got %d)", - PACKETBUFSIZE - remainbuf, -nread); + PACKETBUFSIZE - remainbuf, -nread)); return LIBSSH2_ERROR_SOCKET_RECV; } - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Recved %d/%d bytes to %p+%d", nread, - PACKETBUFSIZE - remainbuf, p->buf, remainbuf); + PACKETBUFSIZE - remainbuf, p->buf, remainbuf)); debugdump(session, "libssh2_transport_read() raw", &p->buf[remainbuf], nread); @@ -659,12 +659,12 @@ send_existing(LIBSSH2_SESSION *session, const unsigned char *data, rc = LIBSSH2_SEND(session, &p->outbuf[p->osent], length, LIBSSH2_SOCKET_SEND_FLAGS(session)); if(rc < 0) - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, - "Error sending %d bytes: %d", length, -rc); + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Error sending %d bytes: %d", length, -rc)); else { - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Sent %d/%d bytes at %p+%d", rc, length, p->outbuf, - p->osent); + p->osent)); debugdump(session, "libssh2_transport_write send()", &p->outbuf[p->osent], rc); } @@ -745,8 +745,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, !(session->state & LIBSSH2_STATE_KEX_ACTIVE)) { /* Don't write any new packets if we're still in the middle of a key * exchange. */ - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Redirecting into the" - " key re-exchange from _libssh2_transport_send"); + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Redirecting into the" + " key re-exchange from _libssh2_transport_send")); rc = _libssh2_kex_exchange(session, 1, &session->startup_key_state); if(rc) return rc; @@ -902,11 +902,12 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, ret = LIBSSH2_SEND(session, p->outbuf, total_length, LIBSSH2_SOCKET_SEND_FLAGS(session)); if(ret < 0) - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, - "Error sending %d bytes: %d", total_length, -ret); + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Error sending %d bytes: %d", total_length, -ret)); else { - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, "Sent %d/%d bytes at %p", - ret, total_length, p->outbuf); + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Sent %d/%d bytes at %p", + ret, total_length, p->outbuf)); debugdump(session, "libssh2_transport_write send()", p->outbuf, ret); } diff --git a/src/userauth.c b/src/userauth.c index bbd22f84ee..1533edc450 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -164,9 +164,9 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, memcpy(session->userauth_banner, session->userauth_list_data + 5, banner_len); session->userauth_banner[banner_len] = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Banner: %s", - session->userauth_banner); + session->userauth_banner)); LIBSSH2_FREE(session, session->userauth_list_data); session->userauth_list_data = NULL; /* SSH_MSG_USERAUTH_BANNER has been handled */ @@ -217,9 +217,9 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, memmove(session->userauth_list_data, session->userauth_list_data + 5, methods_len); session->userauth_list_data[methods_len] = '\0'; - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Permitted auth methods: %s", - session->userauth_list_data); + session->userauth_list_data)); } session->userauth_list_state = libssh2_NB_state_idle; @@ -329,8 +329,8 @@ userauth_password(LIBSSH2_SESSION *session, _libssh2_store_u32(&s, password_len); /* 'password' is sent separately */ - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Attempting to login using password authentication"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Attempting to login using password authentication")); session->userauth_pswd_state = libssh2_NB_state_created; } @@ -384,8 +384,8 @@ userauth_password(LIBSSH2_SESSION *session, } if(session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Password authentication successful"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Password authentication successful")); LIBSSH2_FREE(session, session->userauth_pswd_data); session->userauth_pswd_data = NULL; session->state |= LIBSSH2_STATE_AUTHENTICATED; @@ -394,8 +394,8 @@ userauth_password(LIBSSH2_SESSION *session, } else if(session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_FAILURE) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Password authentication failed"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Password authentication failed")); LIBSSH2_FREE(session, session->userauth_pswd_data); session->userauth_pswd_data = NULL; session->userauth_pswd_state = libssh2_NB_state_idle; @@ -426,8 +426,8 @@ userauth_password(LIBSSH2_SESSION *session, if((session->userauth_pswd_state == libssh2_NB_state_sent1) || (session->userauth_pswd_state == libssh2_NB_state_sent2)) { if(session->userauth_pswd_state == libssh2_NB_state_sent1) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Password change required"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Password change required")); LIBSSH2_FREE(session, session->userauth_pswd_data); session->userauth_pswd_data = NULL; } @@ -653,8 +653,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, size_t pubkey_len = 0, sp_len; unsigned int tmp_len; - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Loading public key file: %s", - pubkeyfile); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Loading public key file: %s", + pubkeyfile)); /* Read Public Key */ fd = fopen(pubkeyfile, FOPEN_READTEXT); if(!fd) { @@ -784,8 +784,8 @@ file_read_privatekey(LIBSSH2_SESSION * session, const LIBSSH2_HOSTKEY_METHOD **hostkey_methods_avail = libssh2_hostkey_methods(); - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Loading private key file: %s", - privkeyfile); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Loading private key file: %s", privkeyfile)); *hostkey_method = NULL; *hostkey_abstract = NULL; while(*hostkey_methods_avail && (*hostkey_methods_avail)->name) { @@ -941,9 +941,9 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, _libssh2_store_u32(&x, *sig_len - 4); } else { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate ecdsa-sk signature."); + "Unable to allocate ecdsa-sk signature.")); rc = LIBSSH2_ERROR_ALLOC; } } @@ -960,9 +960,9 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, sig_info.sig_r_len); } else { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate ed25519-sk signature."); + "Unable to allocate ed25519-sk signature.")); rc = LIBSSH2_ERROR_ALLOC; } } @@ -982,9 +982,9 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, } } else { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_ERROR_DECRYPT, - "sign_callback failed or returned invalid signature."); + "sign_callback failed or returned invalid signature.")); *sig_len = 0; } @@ -1156,8 +1156,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, sig_len); LIBSSH2_FREE(session, sig); - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Attempting hostbased authentication"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Attempting hostbased authentication")); session->userauth_host_state = libssh2_NB_state_created; } @@ -1205,8 +1205,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, } if(session->userauth_host_data[0] == SSH_MSG_USERAUTH_SUCCESS) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Hostbased authentication successful"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Hostbased authentication successful")); /* We are us and we've proved it. */ LIBSSH2_FREE(session, session->userauth_host_data); session->userauth_host_data = NULL; @@ -1485,11 +1485,11 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, if(session->userauth_pblc_method_len && session->userauth_pblc_method) { - _libssh2_debug(session, + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Signing using %.*s", session->userauth_pblc_method_len, - session->userauth_pblc_method); + session->userauth_pblc_method)); } /* @@ -1536,8 +1536,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, session->userauth_pblc_method_len); _libssh2_store_str(&s, (const char *)pubkeydata, pubkeydata_len); - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Attempting publickey authentication"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Attempting publickey authentication")); session->userauth_pblc_state = libssh2_NB_state_created; } @@ -1584,8 +1584,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, } if(session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Pubkey authentication prematurely successful"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Pubkey authentication prematurely successful")); /* * God help any SSH server that allows an UNVERIFIED * public key to validate the user @@ -1730,8 +1730,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, sig); - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Attempting publickey authentication -- phase 2"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Attempting publickey authentication -- phase 2")); session->userauth_pblc_s = s; session->userauth_pblc_state = libssh2_NB_state_sent2; @@ -1777,8 +1777,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, } if(session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Publickey authentication successful"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Publickey authentication successful")); /* We are us and we've proved it. */ LIBSSH2_FREE(session, session->userauth_pblc_data); session->userauth_pblc_data = NULL; @@ -2057,8 +2057,8 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, /* submethods */ _libssh2_store_u32(&s, 0); - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Attempting keyboard-interactive authentication"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Attempting keyboard-interactive authentication")); session->userauth_kybd_state = libssh2_NB_state_created; } @@ -2106,9 +2106,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, } if(session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Keyboard-interactive " - "authentication successful"); + "authentication successful")); LIBSSH2_FREE(session, session->userauth_kybd_data); session->userauth_kybd_data = NULL; session->state |= LIBSSH2_STATE_AUTHENTICATED; @@ -2117,8 +2117,8 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, } if(session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_FAILURE) { - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, - "Keyboard-interactive authentication failed"); + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, + "Keyboard-interactive authentication failed")); LIBSSH2_FREE(session, session->userauth_kybd_data); session->userauth_kybd_data = NULL; session->userauth_kybd_state = libssh2_NB_state_idle; @@ -2144,9 +2144,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, session->userauth_kybd_responses, &session->abstract); - _libssh2_debug(session, LIBSSH2_TRACE_AUTH, + _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Keyboard-interactive response callback function" - " invoked"); + " invoked")); session->userauth_kybd_packet_len = 1 /* byte SSH_MSG_USERAUTH_INFO_RESPONSE */ From 3ac32253f98a66e7e55f5657bfe259d286e33edc Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 13 Mar 2023 12:04:29 +0100 Subject: [PATCH 128/424] wincng: fix memory leak in libssh2_dh_key_pair() (#829) Fixes #722 --- src/wincng.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wincng.c b/src/wincng.c index 6b24bf6f31..e990af1685 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -2516,6 +2516,8 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, } } + _libssh2_wincng_safe_free(blob, key_length_bytes); + return 0; } From b8762c1003d97e109efa587bdc760ff9873949eb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 13 Mar 2023 11:08:19 +0000 Subject: [PATCH 129/424] GNUmakefile: add wolfSSL support + major rework - add wolfSSL support. - reduce size and redundant logic. - fix a bunch of small issues. - rework configuration, now with: `CC`, `AR`, `RC`, `TRIPLET`, `CFLAGS`, `CPPFLAGS`, `LDFLAGS`, `RCFLAGS`, `LIBS`, `LIBSSH2_DLL_SUFFIX`, `LIBSSH2_LDFLAGS_LIB`, `LIBSSH2_LDFLAGS_BIN` (and more). - merge examples build into the main Makefile. - relative dependency paths are now the same for building libssh2 or examples. - drop detection for obsolete OpenSSL versions (can be configure via new `OPENSSL_LIBS`). - merge dev/dist distribution zip options. - build libssh2 with `-DHAVE_STRTOLL`. - tidy-up. - build examples in static mode by default (use `DYN` to build them in shared mode). - drop forced (in non-debug mode) `-O2`. - drop Win9x support. - deprecate `ARCH` in favour of custom options and `TRIPLET`. - drop Windows resources from examples for simplicity - drop `WITH_ZLIB`. Default `ZLIB_PATH` to enable zlib support. - drop `LIBSSH2_DLL_A_SUFFIX`, use standard value `.dll` (as in `libssh2.dll.a`). - always link `bcrypt` (for LibreSSL and OpenSSL) and `crypt32` (for wolfSSL). - unhide executed build commands. - fix mbedTLS `lib` path - drop specific options to force static linking. Custom options seems a better way for this. - based on similar work made for curl: https://github.com/curl/curl/commit/a8861b6ccdd7ca35b6115588a578e36d765c9e38 Closes #842 --- win32/GNUmakefile | 398 +++++++++++++++++------------------------ win32/test/GNUmakefile | 261 --------------------------- 2 files changed, 168 insertions(+), 491 deletions(-) delete mode 100644 win32/test/GNUmakefile diff --git a/win32/GNUmakefile b/win32/GNUmakefile index e7d3849864..1678c4ea09 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -1,270 +1,234 @@ ######################################################################### # -## Makefile for building libssh2 (Win32 version - gnu make) -## Use: make -f GNUmakefile [help|all|clean|dev|devclean|dist|distclean|dll|objclean] -## -## Hacked by: Guenter Knauf +# Makefile for building libssh2 (Windows version - GNU Make) +# Use: make -f GNUmakefile [help|all|clean|dist|distclean|dll|objclean|test|testclean] +# +# Hacked by: Guenter Knauf # ######################################################################### -# Project root PROOT := .. -# Edit the path below to point to the base of your Zlib sources. -ZLIB_PATH ?= $(PROOT)/../zlib +### Common + +HOMEPAGE := https://www.libssh2.org/ + +CFLAGS ?= +CPPFLAGS ?= +RCFLAGS ?= +LDFLAGS ?= +LIBSSH2_LDFLAGS_BIN ?= +LIBSSH2_LDFLAGS_LIB ?= +LIBS ?= -# Edit the path below to point to the base of your OpenSSL package. -OPENSSL_PATH ?= $(PROOT)/../openssl +CROSSPREFIX ?= + +ifeq ($(CC),cc) + CC := gcc +endif +CC := $(CROSSPREFIX)$(CC) +AR := $(CROSSPREFIX)$(AR) +RC ?= $(CROSSPREFIX)windres -# Edit the path below to point to your Distribution folder. -ifndef DISTDIR -DISTDIR = libssh2-$(LIBSSH2_VERSION_STR)-bin-$(ARCH) +# For compatibility +ARCH ?= +ifeq ($(ARCH),w64) + TRIPLET := x86_64-w64-mingw32 + CFLAGS += -m64 + LDFLAGS += -m64 + RCFLAGS += --target=pe-x86-64 +else ifdef ARCH + TRIPLET := i686-w64-mingw32 + CFLAGS += -m32 + LDFLAGS += -m32 + RCFLAGS += --target=pe-i386 +else + TRIPLET ?= $(shell $(CC) -dumpmachine) endif -DISTARC = $(DISTDIR).zip -# Edit the path below to point to your Development folder. -ifndef DEVLDIR -DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-$(ARCH) +CPPFLAGS += -I$(PROOT)/win32 -I$(PROOT)/include +RCFLAGS += -I$(PROOT)/include + +# src + +CPPFLAGS_LIB := -DHAVE_STRTOLL + +# examples, tests + +LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32 +LIBS_BIN := -lssh2 -lws2_32 + +ifdef DYN + libssh2_DEPENDENCIES += $(PROOT)/win32/libssh2.dll.a + LIBSSH2_LDFLAGS_BIN += -shared +else + libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a + LIBSSH2_LDFLAGS_BIN += -static endif -DEVLARC = $(DEVLDIR).zip -# Edit the vars below to change target settings. -TARGET = libssh2 -WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(LIBSSH2_VERSION_STR) -#STACK = 64000 +libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a + +### Optional features # must be equal to DEBUG or NDEBUG DB ?= NDEBUG -# Optimization: -O or debugging: -g +CPPFLAGS += -D$(DB) ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release + OBJDIR := release else - OPT = -g - OPT += -DLIBSSH2DEBUG - OBJDIR = debug + OBJDIR := debug + CFLAGS += -g + CPPFLAGS += -DLIBSSH2DEBUG endif -# Here you can find a native Win32 binary of the original awk: -# http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk -ZIP = zip -qzr9 +# Linker options to exclude for shared mode executables. +_LDFLAGS := +_LIBS := -# Platform-dependent helper tool macros -ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' -else -ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +ifdef WITH_WINCNG + CPPFLAGS += -DLIBSSH2_WINCNG + include $(PROOT)/Makefile.WinCNG.inc +else ifdef MBEDTLS_PATH + CPPFLAGS += -DLIBSSH2_MBEDTLS + CPPFLAGS += -I"$(MBEDTLS_PATH)/include" + _LDFLAGS += -L"$(MBEDTLS_PATH)/lib" + _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto + include $(PROOT)/Makefile.mbedTLS.inc +else ifdef WOLFSSL_PATH + CPPFLAGS += -DLIBSSH2_WOLFSSL + CPPFLAGS += -I"$(WOLFSSL_PATH)/include" + CPPFLAGS += -I"$(WOLFSSL_PATH)/include/wolfssl" + _LDFLAGS += -L"$(WOLFSSL_PATH)/lib" + _LIBS += -lwolfssl + include $(PROOT)/Makefile.wolfSSL.inc else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) -endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. + OPENSSL_PATH ?= $(PROOT)/../openssl + CPPFLAGS += -DLIBSSH2_OPENSSL + OPENSSL_INCLUDE ?= $(OPENSSL_PATH)/include + OPENSSL_LIBPATH ?= $(OPENSSL_PATH)/lib + CPPFLAGS += -I"$(OPENSSL_INCLUDE)" + _LDFLAGS += -L"$(OPENSSL_LIBPATH)" + OPENSSL_LIBS ?= -lssl -lcrypto + _LIBS += $(OPENSSL_LIBS) + include $(PROOT)/Makefile.OpenSSL.inc endif -LIBSSH2_RC ?= $(CROSSPREFIX)windres -LIBSSH2_CC ?= $(CROSSPREFIX)gcc -LIBSSH2_AR ?= $(CROSSPREFIX)ar - -LIBSSH2_DLL_A_SUFFIX ?= dll -libssh2_dll_LIBRARY = $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll - -CC = $(LIBSSH2_CC) - -# Set environment var ARCH to your architecture to override autodetection. -ifndef ARCH - ifeq ($(findstring gcc,$(CC)),gcc) - ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) - ARCH = w64 - else - ARCH = w32 - endif - else - ARCH = w32 - endif +ifdef ZLIB_PATH + CPPFLAGS += -DLIBSSH2_HAVE_ZLIB + CPPFLAGS += -I"$(ZLIB_PATH)/include" + _LDFLAGS += -L"$(ZLIB_PATH)/lib" + _LIBS += -lz endif -# Include the version info retrieved from libssh2.h --include $(OBJDIR)/version.inc +_LIBS += -lws2_32 -lcrypt32 -lbcrypt -# Global flags for all compilers -CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) -LDFLAGS = $(LIBSSH2_LDFLAG_EXTRAS) - -LIBEXT = a -LD = $(LIBSSH2_CC) -RC = $(LIBSSH2_RC) -LDFLAGS += -s -shared -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT) -AR = $(LIBSSH2_AR) -ARFLAGS = cru -RCFLAGS = -I $(PROOT)/include -O coff -CFLAGS += -fno-builtin -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall # -pedantic -ifeq ($(ARCH),w64) - CFLAGS += -m64 - LDFLAGS += -m64 - RCFLAGS += -F pe-x86-64 -else ifeq ($(ARCH),w32) - CFLAGS += -m32 - LDFLAGS += -m32 - RCFLAGS += -F pe-i386 +LIBSSH2_LDFLAGS_LIB += $(_LDFLAGS) +LIBS_LIB += $(_LIBS) + +ifndef DYN + LIBSSH2_LDFLAGS_BIN += $(_LDFLAGS) + LIBS_BIN += $(_LIBS) endif -INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include +### Rules -ifdef WITH_WINCNG - CFLAGS += -DLIBSSH2_WINCNG - LDLIBS += -lbcrypt -lcrypt32 -else ifdef MBEDTLS_PATH - CFLAGS += -DLIBSSH2_MBEDTLS - CFLAGS += -I"$(MBEDTLS_PATH)/include" - LIBPATH += -L"$(MBEDTLS_PATH)/libs" - LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto +# Platform-dependent helper tool macros +ifneq ($(findstring /sh,$(SHELL)),) +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +DL = ' else - CFLAGS += -DLIBSSH2_OPENSSL - ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc - endif - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include - endif - endif - ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" - $(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) - endif - INCLUDES += -I"$(OPENSSL_INCLUDE)" - ifndef OPENSSL_LIBPATH - OPENSSL_LIBS_STAT = crypto ssl - ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/out - OPENSSL_LIBS_DYN = eay32 ssl32 - endif - ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib - OPENSSL_LIBS_DYN = crypto.dll ssl.dll - endif - endif - ifdef LINK_OPENSSL_STATIC - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 - else - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) - endif -endif -LDLIBS += -lws2_32 - -ifdef WITH_ZLIB - CFLAGS += -DLIBSSH2_HAVE_ZLIB - INCLUDES += -I$(ZLIB_PATH) - ifdef LINK_ZLIB_STATIC - LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) - else - LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT) - endif +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) endif +AWK := awk +ZIP := zip -qzr9 -CFLAGS += $(INCLUDES) +# Include the version info retrieved from libssh2.h +-include $(OBJDIR)/version.inc vpath %.c $(PROOT)/src -ifdef WITH_WINCNG - include $(PROOT)/Makefile.WinCNG.inc -else ifdef MBEDTLS_PATH - include $(PROOT)/Makefile.mbedTLS.inc -else - include $(PROOT)/Makefile.OpenSSL.inc -endif - # include Makefile.inc to get CSOURCES define include $(PROOT)/Makefile.inc OBJECTS := $(patsubst %.c,%.o,$(CSOURCES)) OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS)) -OBJL = $(OBJS) $(OBJDIR)/$(TARGET).res +TARGET := libssh2 + +# Override the path below to point to your Distribution folder. +DISTDIR ?= $(TARGET)-$(LIBSSH2_VERSION_STR)-bin-$(word 1,$(subst -, ,$(TRIPLET))) +DISTARC := $(DISTDIR).zip + +LIBSSH2_DLL_SUFFIX ?= +libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll +libssh2_dll_a_LIBRARY := $(TARGET).dll.a + +EXAMPLES := $(PROOT)/example +TARGETS_EXAMPLES := $(filter-out $(EXAMPLES)/x11.exe,$(patsubst %.c,%.exe,$(strip $(wildcard $(EXAMPLES)/*.c)))) all: lib dll dll: prebuild $(libssh2_dll_LIBRARY) -lib: prebuild $(TARGET).$(LIBEXT) +lib: prebuild $(TARGET).a prebuild: $(OBJDIR) $(OBJDIR)/version.inc -# libssh2_config.h -test: all - $(MAKE) -C test -f GNUmakefile +test: $(TARGETS_EXAMPLES) + +%.exe: %.c $(libssh2_DEPENDENCIES) + $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) $< -o $@ $(LIBS) $(LIBS_BIN) $(OBJDIR)/%.o: %.c -# @echo Compiling $< - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(CPPFLAGS_LIB) -c $< -o $@ + +$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS) $(OBJDIR)/$(TARGET).res + @$(call DEL, $@) + $(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_LIB) $^ -o $@ $(LIBS) $(LIBS_LIB) \ + -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(libssh2_dll_a_LIBRARY) + +$(OBJDIR)/%.res: %.rc + $(RC) -O coff $(RCFLAGS) -i $< -o $@ + +$(TARGET).a: $(OBJS) + @$(call DEL, $@) + $(AR) rcs $@ $^ $(OBJDIR)/version.inc: $(PROOT)/get_ver.awk $(PROOT)/include/libssh2.h $(OBJDIR) - @echo Creating $@ - @$(AWK) -f $^ > $@ + $(AWK) -f $^ > $@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call MKDIR, $(DISTDIR)/bin) - @$(call COPY, $(PROOT)/AUTHORS, $(DISTDIR)) + @$(call MKDIR, $(DISTDIR)/include) + @$(call MKDIR, $(DISTDIR)/win32) @$(call COPY, $(PROOT)/COPYING, $(DISTDIR)) - @$(call COPY, $(PROOT)/INSTALL, $(DISTDIR)) @$(call COPY, $(PROOT)/README, $(DISTDIR)) @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) @$(call COPY, $(libssh2_dll_LIBRARY), $(DISTDIR)/bin) - @echo Creating $(DISTARC) + @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) + @$(call COPY, libssh2_config.h, $(DISTDIR)/include) + @$(call COPY, *.a, $(DISTDIR)/win32) + @echo Creating... $(DISTARC) @$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt -dev: all $(DEVLDIR) $(DEVLDIR)/readme.txt - @$(call MKDIR, $(DEVLDIR)/bin) - @$(call MKDIR, $(DEVLDIR)/include) - @$(call MKDIR, $(DEVLDIR)/win32) - @$(call COPY, $(PROOT)/AUTHORS, $(DEVLDIR)) - @$(call COPY, $(PROOT)/COPYING, $(DEVLDIR)) - @$(call COPY, $(PROOT)/INSTALL, $(DEVLDIR)) - @$(call COPY, $(PROOT)/README, $(DEVLDIR)) - @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DEVLDIR)) - @$(call COPY, $(libssh2_dll_LIBRARY), $(DEVLDIR)/bin) - @$(call COPY, $(PROOT)/include/*.h, $(DEVLDIR)/include) - @$(call COPY, libssh2_config.h, $(DEVLDIR)/include) - @$(call COPY, *.$(LIBEXT), $(DEVLDIR)/win32) - @echo Creating $(DEVLARC) - @$(ZIP) $(DEVLARC) $(DEVLDIR)/* < $(DEVLDIR)/readme.txt - distclean vclean: clean $(call RMDIR, $(DISTDIR)) $(call DEL, $(DISTARC)) -devclean: clean - $(call RMDIR, $(DEVLDIR)) - $(call DEL, $(DEVLARC)) - objclean: all $(call RMDIR, $(OBJDIR)) testclean: clean - $(MAKE) -C test -f GNUmakefile clean + $(call DEL, $(TARGETS_EXAMPLES)) clean: -# $(call DEL, libssh2_config.h) - $(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:.dll=.def) $(TARGET).$(LIBEXT) $(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT)) + $(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:.dll=.def) $(TARGET).a $(libssh2_dll_a_LIBRARY)) $(call RMDIR, $(OBJDIR)) $(OBJDIR): @@ -273,55 +237,29 @@ $(OBJDIR): $(DISTDIR): @$(call MKDIR, $@) -$(DEVLDIR): - @$(call MKDIR, $@) - -$(TARGET).$(LIBEXT): $(OBJS) - @echo Creating $@ - @$(call DEL, $@) - @$(AR) $(ARFLAGS) $@ $^ - -$(libssh2_dll_LIBRARY) $(TARGET)$(LIBSSH2_DLL_A_SUFFIX).$(LIBEXT): $(OBJL) - @echo Linking $@ - @$(call DEL, $@) - @$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS) - - -$(OBJDIR)/%.res: %.rc - @echo Creating $@ - @$(RC) $(RCFLAGS) $(LIBSSH2_RCFLAG_EXTRAS) -i $< -o $@ - - $(DISTDIR)/readme.txt: GNUmakefile - @echo Creating $@ - @echo $(DL)This is a binary distribution for Win32 platform.$(DL) > $@ - @echo $(DL)libssh version $(LIBSSH2_VERSION_STR)$(DL) >> $@ - @echo $(DL)Please download the complete libssh package for$(DL) >> $@ - @echo $(DL)any further documentation:$(DL) >> $@ - @echo $(DL)$(WWWURL)$(DL) >> $@ - -$(DEVLDIR)/readme.txt: GNUmakefile - @echo Creating $@ - @echo $(DL)This is a development distribution for Win32 platform.$(DL) > $@ - @echo $(DL)libssh version $(LIBSSH2_VERSION_STR)$(DL) >> $@ - @echo $(DL)Please download the complete libssh package for$(DL) >> $@ + @echo Creating... $@ + @echo $(DL)This is a binary distribution for Windows.$(DL) > $@ + @echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@ + @echo $(DL)Please download the complete libssh2 package for$(DL) >> $@ @echo $(DL)any further documentation:$(DL) >> $@ - @echo $(DL)$(WWWURL)$(DL) >> $@ + @echo $(DL)$(HOMEPAGE)$(DL) >> $@ help: $(OBJDIR)/version.inc @echo $(DL)===========================================================$(DL) @echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL) - @echo $(DL)Zlib path = $(ZLIB_PATH)$(DL) + @echo $(DL)wolfSSL path = $(WOLFSSL_PATH)$(DL) + @echo $(DL)mbedTLS path = $(MBEDTLS_PATH)$(DL) + @echo $(DL)zlib path = $(ZLIB_PATH)$(DL) @echo $(DL)===========================================================$(DL) - @echo $(DL)libssh $(LIBSSH2_VERSION_STR) - available targets are:$(DL) + @echo $(DL)libssh2 $(LIBSSH2_VERSION_STR) - available targets are:$(DL) @echo $(DL)$(MAKE) all$(DL) @echo $(DL)$(MAKE) dll$(DL) @echo $(DL)$(MAKE) lib$(DL) @echo $(DL)$(MAKE) clean$(DL) - @echo $(DL)$(MAKE) dev$(DL) - @echo $(DL)$(MAKE) devclean$(DL) @echo $(DL)$(MAKE) dist$(DL) @echo $(DL)$(MAKE) distclean$(DL) @echo $(DL)$(MAKE) objclean$(DL) @echo $(DL)$(MAKE) test$(DL) + @echo $(DL)$(MAKE) testclean$(DL) @echo $(DL)===========================================================$(DL) diff --git a/win32/test/GNUmakefile b/win32/test/GNUmakefile deleted file mode 100644 index 67fc451fda..0000000000 --- a/win32/test/GNUmakefile +++ /dev/null @@ -1,261 +0,0 @@ -######################################################################### -# -## Makefile for building libssh2 samples (Win32 version - gnu make) -## Use: make -f GNUmakefile [help] -## -## Hacked by: Guenter Knauf -# -######################################################################### - -# Project root -PROOT := ../.. - -# Edit the path below to point to the base of your Zlib sources. -ZLIB_PATH ?= $(PROOT)/../zlib - -# Edit the path below to point to the base of your OpenSSL package. -OPENSSL_PATH ?= $(PROOT)/../openssl - -# Edit the var below to enable static linking of libssh2 and libz -LINK_STATIC := 1 - -# Edit the vars below to change target settings. -SAMPLES = $(PROOT)/example -TARGETS := $(filter-out x11.exe,$(patsubst $(SAMPLES)/%.c,%.exe,$(strip $(wildcard $(SAMPLES)/*.c)))) -WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(subst .rc,,$(notdir $@)) $(LIBSSH2_VERSION_STR) -#STACK = 64000 - -# must be equal to DEBUG or NDEBUG -DB ?= NDEBUG -# Optimization: -O or debugging: -g -ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release -else - OPT = -g - OBJDIR = debug -endif - -# Here you can find a native Win32 binary of the original awk: -# http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk -ZIP = zip -qzr9 - -# Platform-dependent helper tool macros -ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' -else -ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) -else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) -endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. -endif - -LIBSSH2_RC ?= $(CROSSPREFIX)windres -LIBSSH2_CC ?= $(CROSSPREFIX)gcc -LIBSSH2_AR ?= $(CROSSPREFIX)ar - -CC = $(LIBSSH2_CC) - -# Set environment var ARCH to your architecture to override autodetection. -ifndef ARCH - ifeq ($(findstring gcc,$(CC)),gcc) - ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) - ARCH = w64 - else - ARCH = w32 - endif - else - ARCH = w32 - endif -endif - -# Include the version info retrieved from libssh2.h --include $(OBJDIR)/version.inc - -# Global flags for all compilers -CFLAGS = $(LIBSSH2_CFLAG_EXTRAS) $(OPT) -D$(DB) -LDFLAGS = $(LIBSSH2_LDFLAG_EXTRAS) - -LIBEXT = a -LD = $(LIBSSH2_CC) -RC = $(LIBSSH2_RC) -LDFLAGS += -s -AR = $(LIBSSH2_AR) -ARFLAGS = cru -RCFLAGS = -I $(PROOT)/include -O coff -CFLAGS += -fno-builtin -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall # -pedantic -ifeq ($(ARCH),w64) - CFLAGS += -m64 - LDFLAGS += -m64 - RCFLAGS += -F pe-x86-64 -else ifeq ($(ARCH),w32) - CFLAGS += -m32 - LDFLAGS += -m32 - RCFLAGS += -F pe-i386 -endif - -INCLUDES = -I$(PROOT)/win32 -I$(PROOT)/include -LIBPATH += -L$(PROOT)/win32 - -ifdef LINK_STATIC - LDLIBS += -llibssh2 -else - LDLIBS += -llibssh2dll -endif - -ifdef WITH_WINCNG - LDLIBS += -lbcrypt -lcrypt32 -else ifdef MBEDTLS_PATH - CFLAGS += -I"$(MBEDTLS_PATH)/include" - LIBPATH += -L"$(MBEDTLS_PATH)/libs" - LDLIBS += -lmbedtls -lmbedx509 -lmbedcrypto -else - ifndef OPENSSL_INCLUDE - ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc - endif - ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" - OPENSSL_INCLUDE = $(OPENSSL_PATH)/include - endif - endif - ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" - $(error Invalid OPENSSL_PATH: $(OPENSSL_PATH)) - endif - INCLUDES += -I"$(OPENSSL_INCLUDE)" - ifndef OPENSSL_LIBPATH - OPENSSL_LIBS_STAT = crypto ssl - ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/out - OPENSSL_LIBS_DYN = eay32 ssl32 - endif - ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" - OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib - OPENSSL_LIBS_DYN = crypto.dll ssl.dll - endif - endif - ifdef LINK_STATIC - ifdef LINK_OPENSSL_STATIC - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_STAT)) -lgdi32 - else - LDLIBS += $(patsubst %,$(OPENSSL_LIBPATH)/lib%.$(LIBEXT), $(OPENSSL_LIBS_DYN)) - endif - endif -endif -LDLIBS += -lws2_32 - -ifdef WITH_ZLIB - CFLAGS += -DLIBSSH2_HAVE_ZLIB - INCLUDES += -I$(ZLIB_PATH) - ifdef LINK_ZLIB_STATIC - LDLIBS += $(ZLIB_PATH)/libz.$(LIBEXT) - else - LDLIBS += $(ZLIB_PATH)/libz.dll.$(LIBEXT) - endif -endif - -CFLAGS += $(INCLUDES) - -vpath %.c $(PROOT)/example - -.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.rc $(OBJDIR)/%.res - - -all: prebuild $(TARGETS) - -prebuild: $(OBJDIR) $(OBJDIR)/version.inc - -$(OBJDIR)/%.o: %.c -# @echo Compiling $< - $(CC) $(CFLAGS) -c $< -o $@ - -$(OBJDIR)/version.inc: $(PROOT)/include/libssh2.h $(OBJDIR) - @echo Creating $@ - @$(AWK) -f $(PROOT)/get_ver.awk $< > $@ - -objclean: - $(call RMDIR, $(OBJDIR)) - -clean: objclean - $(call DEL, $(TARGETS)) - -$(OBJDIR): - $(call MKDIR, $@) - -%.exe: $(OBJDIR)/%.o $(OBJDIR)/%.res - @echo Linking $@ - @$(call DEL, $@) - $(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS) - -$(OBJDIR)/%.res: $(OBJDIR)/%.rc - @echo Creating $@ - @$(RC) $(RCFLAGS) $(LIBSSH2_RCFLAG_EXTRAS) -i $< -o $@ - -$(OBJDIR)/%.rc: GNUmakefile $(OBJDIR)/version.inc - @echo $(DL)1 VERSIONINFO$(DL) > $@ - @echo $(DL) FILEVERSION $(LIBSSH2_VERSION),0$(DL) >> $@ - @echo $(DL) PRODUCTVERSION $(LIBSSH2_VERSION),0$(DL) >> $@ - @echo $(DL) FILEFLAGSMASK 0x3fL$(DL) >> $@ - @echo $(DL) FILEOS 0x40004L$(DL) >> $@ - @echo $(DL) FILEFLAGS 0x0L$(DL) >> $@ - @echo $(DL) FILETYPE 0x1L$(DL) >> $@ - @echo $(DL) FILESUBTYPE 0x0L$(DL) >> $@ - @echo $(DL)BEGIN$(DL) >> $@ - @echo $(DL) BLOCK "StringFileInfo"$(DL) >> $@ - @echo $(DL) BEGIN$(DL) >> $@ - @echo $(DL) BLOCK "040904E4"$(DL) >> $@ - @echo $(DL) BEGIN$(DL) >> $@ - @echo $(DL) VALUE "LegalCopyright","(C) $(LIBSSH2_COPYRIGHT_STR)\0"$(DL) >> $@ -ifdef COMPANY - @echo $(DL) VALUE "CompanyName","$(COMPANY)\0"$(DL) >> $@ -endif - @echo $(DL) VALUE "ProductName","$(notdir $(@:.rc=.exe))\0"$(DL) >> $@ - @echo $(DL) VALUE "ProductVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@ - @echo $(DL) VALUE "License","Released under GPL.\0"$(DL) >> $@ - @echo $(DL) VALUE "FileDescription","$(DESCR)\0"$(DL) >> $@ - @echo $(DL) VALUE "FileVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@ - @echo $(DL) VALUE "InternalName","$(notdir $(@:.rc=))\0"$(DL) >> $@ - @echo $(DL) VALUE "OriginalFilename","$(notdir $(@:.rc=.exe))\0"$(DL) >> $@ - @echo $(DL) VALUE "WWW","$(WWWURL)\0"$(DL) >> $@ - @echo $(DL) END$(DL) >> $@ - @echo $(DL) END$(DL) >> $@ - @echo $(DL) BLOCK "VarFileInfo"$(DL) >> $@ - @echo $(DL) BEGIN$(DL) >> $@ - @echo $(DL) VALUE "Translation", 0x409, 1252$(DL) >> $@ - @echo $(DL) END$(DL) >> $@ - @echo $(DL)END$(DL) >> $@ -ifdef ICON - @echo $(DL)10 ICON DISCARDABLE "$(ICON)"$(DL) >> $@ -endif - -help: $(OBJDIR)/version.inc - @echo $(DL)===========================================================$(DL) - @echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL) - @echo $(DL)Zlib path = $(ZLIB_PATH)$(DL) - @echo $(DL)===========================================================$(DL) - @echo $(DL)libssh $(LIBSSH2_VERSION_STR) - available targets are:$(DL) - @echo $(DL)$(MAKE) all$(DL) - @echo $(DL)$(MAKE) clean$(DL) - @echo $(DL)$(MAKE) objclean$(DL) - @echo $(DL)===========================================================$(DL) From 0c00d3b9550bc351204b0592b22802259be9c786 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 13 Mar 2023 12:09:46 +0100 Subject: [PATCH 130/424] src: silence unused variable warnings (#843) --- src/libgcrypt.c | 38 ++++++++++++++++++++++++++++++++++++++ src/mbedtls.c | 13 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 2e0a8db4ef..e6e6cabea0 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -157,6 +157,11 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, const char *filedata, size_t filedata_len, unsigned const char *passphrase) { + (void)rsa; + (void)filedata; + (void)filedata_len; + (void)passphrase; + return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, "Unable to extract private key from memory: " "Method unimplemented in libgcrypt backend"); @@ -269,6 +274,11 @@ _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx ** dsa, const char *filedata, size_t filedata_len, unsigned const char *passphrase) { + (void)dsa; + (void)filedata; + (void)filedata_len; + (void)passphrase; + return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, "Unable to extract private key from memory: " "Method unimplemented in libgcrypt backend"); @@ -607,6 +617,14 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, size_t privatekeydata_len, const char *passphrase) { + (void)method; + (void)method_len; + (void)pubkeydata; + (void)pubkeydata_len; + (void)privatekeydata; + (void)privatekeydata_len; + (void)passphrase; + return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, "Unable to extract public key from private " "key in memory: " @@ -622,6 +640,13 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, const char *privatekey, const char *passphrase) { + (void)method; + (void)method_len; + (void)pubkeydata; + (void)pubkeydata_len; + (void)privatekey; + (void)passphrase; + return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public key from private key file: " "Method unimplemented in libgcrypt backend"); @@ -642,6 +667,19 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, size_t privatekeydata_len, const char *passphrase) { + (void)method; + (void)method_len; + (void)pubkeydata; + (void)pubkeydata_len; + (void)algorithm; + (void)flags; + (void)application; + (void)key_handle; + (void)handle_len; + (void)privatekeydata; + (void)privatekeydata_len; + (void)passphrase; + return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public SK key from private key file: " "Method unimplemented in libgcrypt backend"); diff --git a/src/mbedtls.c b/src/mbedtls.c index 50a44373e5..94a0e4ee2b 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -825,6 +825,19 @@ _libssh2_mbedtls_sk_pub_keyfilememory(LIBSSH2_SESSION *session, size_t privatekeydata_len, const char *passphrase) { + (void)method; + (void)method_len; + (void)pubkeydata; + (void)pubkeydata_len; + (void)algorithm; + (void)flags; + (void)application; + (void)key_handle; + (void)handle_len; + (void)privatekeydata; + (void)privatekeydata_len; + (void)passphrase; + return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public SK key from private key file: " "Method unimplemented in mbedTLS backend"); From 2215ee37e961b0660161a63bcb9d5ebfaa7f04e7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 13 Mar 2023 15:27:10 +0100 Subject: [PATCH 131/424] GNUmakefile: move HAVE_STRTOLL to libssh2_config.h [ci skip] (#844) --- win32/GNUmakefile | 6 +----- win32/libssh2_config.h | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 1678c4ea09..bf2cfe22e9 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -49,10 +49,6 @@ endif CPPFLAGS += -I$(PROOT)/win32 -I$(PROOT)/include RCFLAGS += -I$(PROOT)/include -# src - -CPPFLAGS_LIB := -DHAVE_STRTOLL - # examples, tests LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32 @@ -186,7 +182,7 @@ test: $(TARGETS_EXAMPLES) $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) $< -o $@ $(LIBS) $(LIBS_BIN) $(OBJDIR)/%.o: %.c - $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(CPPFLAGS_LIB) -c $< -o $@ + $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@ $(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS) $(OBJDIR)/$(TARGET).res @$(call DEL, $@) diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index a497eab518..ac056b2185 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -20,6 +20,7 @@ # define HAVE_INTTYPES_H # define HAVE_SYS_TIME_H # define HAVE_GETTIMEOFDAY +# define HAVE_STRTOLL #elif defined(_MSC_VER) # if _MSC_VER < 1900 # undef HAVE_SNPRINTF From 664239faa1cca1c00e3236126fb3f04debed1f2d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 13 Mar 2023 20:07:25 +0100 Subject: [PATCH 132/424] win32: set HAVE_STRTOLL with MSVS 2013 and newer (#845) As in curl: https://github.com/curl/curl/blob/7fa6e36583b52dd8f1e639b370c9a2849be81b54/lib/config-win32.h#L221 --- win32/libssh2_config.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index ac056b2185..5308df7c8f 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -22,6 +22,9 @@ # define HAVE_GETTIMEOFDAY # define HAVE_STRTOLL #elif defined(_MSC_VER) +# if _MSC_VER >= 1800 +# define HAVE_STRTOLL +# endif # if _MSC_VER < 1900 # undef HAVE_SNPRINTF # if _MSC_VER < 1500 From e96e96628bba39f868f899b2a49b529caedbc076 Mon Sep 17 00:00:00 2001 From: Jakob Egger Date: Tue, 14 Mar 2023 13:38:28 +0100 Subject: [PATCH 133/424] build: update instructions for autoreconf (#847) The "convenience script" talks about the "buildconf" file, which is no longer recommended. --- docs/INSTALL_AUTOTOOLS | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index a75b51814d..00e0f3925b 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -11,8 +11,7 @@ When Building directly from Master ================================== If you want to build directly from the git repository, you must first -generate the configure script and Makefile using autotools. There is -a convenience script that calls all tools in the correct order. Make +generate the configure script and Makefile using autotools. Make sure that autoconf, automake and libtool are installed on your system, then execute: From f928da9f957f071ed643e215663ae6cbb6e1fbf4 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 14 Mar 2023 20:38:27 +0000 Subject: [PATCH 134/424] appveyor.yml: choco install improvements [ci skip] - avoid outputting 4000 log lines by hiding the progress bar. Reduces log size by 5x. - decrease timeout (from the default 2700 seconds). - omit unnecessary output. Tested as part of #846 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ba82eac204..1c5214ab0a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -88,7 +88,7 @@ install: $env:OPENSSH_SERVER_PORT = Get-Random -Minimum 2000 -Maximum 2300 [System.Environment]::SetEnvironmentVariable("OPENSSH_SERVER_PORT", $env:OPENSSH_SERVER_PORT) - ps: .\ci\appveyor\docker-bridge.ps1 - - appveyor-retry choco install -y docker-cli + - appveyor-retry choco install -y --no-progress --limit-output --timeout 180 docker-cli build_script: - ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" } From 289b4a1c0c939ffa58a6ece22a70559ceea882d1 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 14 Mar 2023 11:18:58 -0700 Subject: [PATCH 135/424] src: check for NULL pointer passed to _libssh2_get_string Callers should be protecting against this, but it's prudent to check here anyway. Fixes #802 Closes #848 --- src/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc.c b/src/misc.c index 74a6d5a762..a262e09dc3 100644 --- a/src/misc.c +++ b/src/misc.c @@ -834,7 +834,7 @@ int _libssh2_get_string(struct string_buf *buf, unsigned char **outbuf, size_t *outlen) { uint32_t data_len; - if(_libssh2_get_u32(buf, &data_len) != 0) { + if(!buf || _libssh2_get_u32(buf, &data_len) != 0) { return -1; } if(!_libssh2_check_length(buf, data_len)) { From d0714c321a326acd394a84797d3ddc805363aa0a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 16 Mar 2023 12:43:38 +0100 Subject: [PATCH 136/424] appveyor.yml: reorder tests to return relevant feedback earlier (#849) - build x64 first x64 is the more interesting target. Most type conversion issues are revealed here. Also more commonly used by now. - test VS 2013 earlier - test WinCNG earlier - delete reference to no longer used VS 2008 After this patch we end up starting with all Shared builds (2015, 2013, OpenSSL, WinCNG), then continue with Static ones. Shared/Static makes a minor if any difference in builds/tests compared to different VS versions of TLS backends. -- CI run times: Preparation + build takes: 8 x VS2015 4.5 mins -> total: 36 8 x VS2013 2 mins -> total: 16 Total: 52 mins with our 30 tests, it increases to: 8 x VS2015 8-10 mins -> total: 72 8 x VS2013 6- 9 mins -> total: 60 Total: 132 mins Without tests: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46475315 With tests: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46480549 --- appveyor.yml | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 1c5214ab0a..238be891f9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,34 +33,34 @@ environment: BUILD_SHARED_LIBS: ON CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2015, OpenSSL, Static" - GENERATOR: "Visual Studio 14 2015" - BUILD_SHARED_LIBS: OFF - CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, Shared" GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: ON CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, Static" - GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: OFF - CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2015, WinCNG, Shared" GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: ON CRYPTO_BACKEND: "WinCNG" - - job_name: "VS2015, WinCNG, Static" + - job_name: "VS2013, WinCNG, Shared" + GENERATOR: "Visual Studio 12 2013" + BUILD_SHARED_LIBS: ON + CRYPTO_BACKEND: "WinCNG" + + - job_name: "VS2015, OpenSSL, Static" GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: OFF - CRYPTO_BACKEND: "WinCNG" + CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, WinCNG, Shared" + - job_name: "VS2013, OpenSSL, Static" GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: ON + BUILD_SHARED_LIBS: OFF + CRYPTO_BACKEND: "OpenSSL" + + - job_name: "VS2015, WinCNG, Static" + GENERATOR: "Visual Studio 14 2015" + BUILD_SHARED_LIBS: OFF CRYPTO_BACKEND: "WinCNG" - job_name: "VS2013, WinCNG, Static" @@ -69,8 +69,8 @@ environment: CRYPTO_BACKEND: "WinCNG" platform: - - x86 - x64 + - x86 configuration: # - Debug @@ -78,9 +78,6 @@ configuration: matrix: fast_finish: true - allow_failures: - - GENERATOR: "Visual Studio 9 2008" - platform: x64 install: # prepare local SSH server for reverse tunneling from GitHub Actions hosting our docker container From ca2e8d5b5ee8d2912be9fb9eeefd3748387e32b6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 17 Mar 2023 00:24:35 +0100 Subject: [PATCH 137/424] ci: update mbedTLS repo URL, delete Travis CI (#850) Last Travis CI session run on 2021-11-18. Ref: https://app.travis-ci.com/github/libssh2/libssh2 Ref: https://travis-ci.org/github/libssh2/libssh2/builds --- .github/workflows/ci.yml | 2 +- .travis.yml | 127 --------------------------------------- 2 files changed, 1 insertion(+), 128 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4c21f8574..e68da1266f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: if: ${{ matrix.crypto_backend == 'mbedTLS' }} run: | MBEDTLSVER=mbedtls-3.2.1 - curl -L https://github.com/ARMmbed/mbedtls/archive/$MBEDTLSVER.tar.gz | tar -xzf - + curl -L https://github.com/Mbed-TLS/mbedtls/archive/$MBEDTLSVER.tar.gz | tar -xzf - cd mbedtls-$MBEDTLSVER cmake $TOOLCHAIN_OPTION -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=../usr . make -j3 install diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bc1a96ffda..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,127 +0,0 @@ -# Copyright (c) 2014 Alexander Lamaison -# -# Redistribution and use in source and binary forms, -# with or without modification, are permitted provided -# that the following conditions are met: -# -# Redistributions of source code must retain the above -# copyright notice, this list of conditions and the -# following disclaimer. -# -# Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# Neither the name of the copyright holder nor the names -# of any other contributors may be used to endorse or -# promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -# OF SUCH DAMAGE. - -sudo: required - -services: - - docker - -language: c - -compiler: - - gcc - - clang - -addons: - chrome: stable -matrix: - include: - - name: "Check style" - script: ./ci/checksrc.sh - -env: - - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=configure - - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=64 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=Libgcrypt BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=ON B=cmake - - ADDRESS_SIZE=32 CRYPTO_BACKEND=mbedTLS BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=ON B=cmake - - B=fuzzer - -before_install: - - if [ $ADDRESS_SIZE = '32' ]; then sudo dpkg --add-architecture i386; fi - - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get update -qq; fi - - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y gcc-multilib; fi - - if [ $ADDRESS_SIZE = '32' ]; then sudo apt-get install -y libssl-dev:i386 libgcrypt20-dev:i386 build-essential gcc-multilib; fi - - if [ $ADDRESS_SIZE = '32' ]; then sudo dpkg --purge --force-depends gcc-multilib && sudo dpkg --purge --force-depends libssl-dev; fi - - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libssl-dev; fi - - if [ $ADDRESS_SIZE = '64' ]; then sudo apt-get install -y libgcrypt11-dev; fi - - if [ $ADDRESS_SIZE = '32' ]; then export TOOLCHAIN_OPTION="-DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Linux-32.cmake"; fi - - if [ $CRYPTO_BACKEND = 'mbedTLS' ]; then - MBEDTLSVER=mbedtls-2.7.0; - curl -L https://github.com/ARMmbed/mbedtls/archive/$MBEDTLSVER.tar.gz | tar -xzf -; - cd mbedtls-$MBEDTLSVER; - cmake $TOOLCHAIN_OPTION -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=../usr .; - make -j3 install; - cd ..; - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/usr/lib; - export TOOLCHAIN_OPTION="$TOOLCHAIN_OPTION -DCMAKE_PREFIX_PATH=$PWD/usr"; - fi - -install: - -script: - - | - if [ "$B" = "configure" ]; then - autoreconf -fi - ./configure --enable-debug --enable-werror - make - make check - fi - - | - if [ "$B" = "cmake" ]; then - mkdir bin - cd bin - export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && ctest -VV --output-on-failure && cmake --build . --target package - fi - - | - if [ "$B" = "fuzzer" ]; then - GIT_REF=$TRAVIS_COMMIT ./ci/ossfuzz.sh - fi - -# whitelist branches to avoid testing feature branches twice (as branch and as pull request) -branches: - only: - - master From c5f2efdf9d6877117e6b2434cbab41bff1b444c3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 17 Mar 2023 09:42:10 +0000 Subject: [PATCH 138/424] ci: set timeout to ctest and GitHub CI jobs - `ctest` shows a the default timeout '10000000' (turns out to be in seconds), cause infinite waits e.g. in case the necessary server worker is not available. CMake CI tests take approx: - GitHub / Linux : 125 seconds - AppVeyor / Windows: 300 seconds New timeouts are: 450 and 900 seconds respectively. - set timeouts for style-check, fuzz, Linux and Windows GitHub CI jobs to avoid hanging forever. Also: - move `choco install` to before_test to make builds start faster in `appveyor.yml`. - fix some yamllint `ON`/`OFF`-confusion issue by quoting these values in `appveyor.yml`. - fix indentation in `appveyor.yml`. - convert to GitHub workflows to LF line-ending. Ref: https://github.com/libssh2/libssh2/pull/655#issuecomment-1472853493 Closes #851 --- .github/workflows/appveyor_status.yml | 120 +++++++++++------------ .github/workflows/ci.yml | 5 +- .github/workflows/cifuzz.yml | 1 + .github/workflows/openssh_server.yml | 132 +++++++++++++------------- appveyor.yml | 24 ++--- 5 files changed, 143 insertions(+), 139 deletions(-) diff --git a/.github/workflows/appveyor_status.yml b/.github/workflows/appveyor_status.yml index cd17a2974c..62f0d7e75d 100644 --- a/.github/workflows/appveyor_status.yml +++ b/.github/workflows/appveyor_status.yml @@ -1,60 +1,60 @@ -# Copyright (c) 2022 Marc Hoersken -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -name: AppVeyor Status Report - -on: - status - -concurrency: - group: ${{ github.workflow }}-${{ github.event.sha }}-${{ github.event.target_url }} - cancel-in-progress: true - -permissions: - statuses: write - -jobs: - split: - runs-on: ubuntu-latest - if: ${{ github.event.sender.login == 'appveyor[bot]' }} - steps: - - name: Create individual AppVeyor build statuses - if: ${{ github.event.sha && github.event.target_url }} - env: - APPVEYOR_COMMIT_SHA: ${{ github.event.sha }} - APPVEYOR_TARGET_URL: ${{ github.event.target_url }} - APPVEYOR_REPOSITORY: ${{ github.event.repository.full_name }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - echo ${APPVEYOR_TARGET_URL} | sed 's/\/project\//\/api\/projects\//' | xargs -t -n1 curl -s | \ - jq -c '.build.jobs[] | {target_url: ($target_url + "/job/" + .jobId), - context: (.name | sub("^(Environment: )?"; "AppVeyor / ")), - state: (.status | sub("queued"; "pending") - | sub("starting"; "pending") - | sub("running"; "pending") - | sub("failed"; "failure") - | sub("cancelled"; "error")), - description: .status}' \ - --arg target_url ${APPVEYOR_TARGET_URL} | tee /dev/stderr | parallel --pipe -j 1 -N 1 \ - gh api --silent --input - repos/${APPVEYOR_REPOSITORY}/statuses/${APPVEYOR_COMMIT_SHA} +# Copyright (c) 2022 Marc Hoersken +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +name: AppVeyor Status Report + +on: + status + +concurrency: + group: ${{ github.workflow }}-${{ github.event.sha }}-${{ github.event.target_url }} + cancel-in-progress: true + +permissions: + statuses: write + +jobs: + split: + runs-on: ubuntu-latest + if: ${{ github.event.sender.login == 'appveyor[bot]' }} + steps: + - name: Create individual AppVeyor build statuses + if: ${{ github.event.sha && github.event.target_url }} + env: + APPVEYOR_COMMIT_SHA: ${{ github.event.sha }} + APPVEYOR_TARGET_URL: ${{ github.event.target_url }} + APPVEYOR_REPOSITORY: ${{ github.event.repository.full_name }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo ${APPVEYOR_TARGET_URL} | sed 's/\/project\//\/api\/projects\//' | xargs -t -n1 curl -s | \ + jq -c '.build.jobs[] | {target_url: ($target_url + "/job/" + .jobId), + context: (.name | sub("^(Environment: )?"; "AppVeyor / ")), + state: (.status | sub("queued"; "pending") + | sub("starting"; "pending") + | sub("running"; "pending") + | sub("failed"; "failure") + | sub("cancelled"; "error")), + description: .status}' \ + --arg target_url ${APPVEYOR_TARGET_URL} | tee /dev/stderr | parallel --pipe -j 1 -N 1 \ + gh api --silent --input - repos/${APPVEYOR_REPOSITORY}/statuses/${APPVEYOR_COMMIT_SHA} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e68da1266f..6ee054b935 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ jobs: check_style: name: style-check runs-on: ubuntu-latest + timeout-minutes: 5 steps: - uses: actions/checkout@v3 - name: Check Style @@ -18,6 +19,7 @@ jobs: build_linux: name: linux runs-on: ubuntu-latest + timeout-minutes: 60 strategy: fail-fast: false matrix: @@ -89,12 +91,13 @@ jobs: cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. cmake --build . export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) - ctest -VV --output-on-failure + ctest -VV --output-on-failure --timeout 450 cmake --build . --target package build_msys2: name: msys2 runs-on: windows-latest + timeout-minutes: 30 strategy: matrix: include: diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index 636b0c5426..500cb63580 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -3,6 +3,7 @@ on: [pull_request] jobs: Fuzzing: runs-on: ubuntu-latest + timeout-minutes: 30 steps: - name: Build Fuzzers id: build diff --git a/.github/workflows/openssh_server.yml b/.github/workflows/openssh_server.yml index ea9529b042..026f333f0d 100644 --- a/.github/workflows/openssh_server.yml +++ b/.github/workflows/openssh_server.yml @@ -1,66 +1,66 @@ -# Copyright (c) 2022 Marc Hoersken -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -name: OpenSSH Server Docker Image - -on: - push: - branches: [ master ] - -jobs: - build-and-push: - runs-on: ubuntu-latest - steps: - - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - uses: actions/checkout@v3 - - - shell: bash - id: hash - run: echo "::set-output name=hash::$(git rev-parse --short=20 HEAD:tests/openssh_server)" - - - shell: bash - id: poll - run: docker manifest inspect ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server:${{ steps.hash.outputs.hash }} - continue-on-error: true - - - uses: docker/metadata-action@v4 - id: meta - with: - images: ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server - tags: | - type=raw,value=${{ steps.hash.outputs.hash }} - if: ${{ steps.poll.outcome == 'failure' }} - - - uses: docker/build-push-action@v3 - with: - context: ./tests/openssh_server - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - if: ${{ steps.poll.outcome == 'failure' }} +# Copyright (c) 2022 Marc Hoersken +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +name: OpenSSH Server Docker Image + +on: + push: + branches: [ master ] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@v3 + + - shell: bash + id: hash + run: echo "::set-output name=hash::$(git rev-parse --short=20 HEAD:tests/openssh_server)" + + - shell: bash + id: poll + run: docker manifest inspect ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server:${{ steps.hash.outputs.hash }} + continue-on-error: true + + - uses: docker/metadata-action@v4 + id: meta + with: + images: ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server + tags: | + type=raw,value=${{ steps.hash.outputs.hash }} + if: ${{ steps.poll.outcome == 'failure' }} + + - uses: docker/build-push-action@v3 + with: + context: ./tests/openssh_server + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + if: ${{ steps.poll.outcome == 'failure' }} diff --git a/appveyor.yml b/appveyor.yml index 238be891f9..07868447c2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,42 +30,42 @@ environment: matrix: - job_name: "VS2015, OpenSSL, Shared" GENERATOR: "Visual Studio 14 2015" - BUILD_SHARED_LIBS: ON + BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - job_name: "VS2013, OpenSSL, Shared" GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: ON + BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - job_name: "VS2015, WinCNG, Shared" GENERATOR: "Visual Studio 14 2015" - BUILD_SHARED_LIBS: ON + BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - job_name: "VS2013, WinCNG, Shared" GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: ON + BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - job_name: "VS2015, OpenSSL, Static" GENERATOR: "Visual Studio 14 2015" - BUILD_SHARED_LIBS: OFF + BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "OpenSSL" - job_name: "VS2013, OpenSSL, Static" GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: OFF + BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "OpenSSL" - job_name: "VS2015, WinCNG, Static" GENERATOR: "Visual Studio 14 2015" - BUILD_SHARED_LIBS: OFF + BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "WinCNG" - job_name: "VS2013, WinCNG, Static" GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: OFF + BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "WinCNG" platform: @@ -85,7 +85,6 @@ install: $env:OPENSSH_SERVER_PORT = Get-Random -Minimum 2000 -Maximum 2300 [System.Environment]::SetEnvironmentVariable("OPENSSH_SERVER_PORT", $env:OPENSSH_SERVER_PORT) - ps: .\ci\appveyor\docker-bridge.ps1 - - appveyor-retry choco install -y --no-progress --limit-output --timeout 180 docker-cli build_script: - ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" } @@ -93,6 +92,7 @@ build_script: - cmake --build _builds --config "%CONFIGURATION%" before_test: + - appveyor-retry choco install -y --no-progress --limit-output --timeout 180 docker-cli - ps: | Write-Host "Waiting for SSH connection from GitHub Actions" -NoNewline while((Get-Process -Name "sshd" -ErrorAction SilentlyContinue).Count -eq 1) { @@ -109,7 +109,7 @@ before_test: test_script: - ps: $env:OPENSSH_SERVER_IMAGE=[string] (& bash -c "echo ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)") - - ps: cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure + - ps: cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure --timeout 900 on_failure: - ps: if(Test-Path _builds/CMakeFiles/CMakeOutput.log) { cat _builds/CMakeFiles/CMakeOutput.log } @@ -123,5 +123,5 @@ on_finish: # whitelist branches to avoid testing feature branches twice (as branch and as pull request) branches: - only: - - master + only: + - master From 2ac44a19aa5cdd404341a3cca66d435e21fdeb0e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 17 Mar 2023 16:55:48 +0100 Subject: [PATCH 139/424] ci: more timeout adjustments (#853) - add timeout to SSH connection wait loop in AppVeyor test prep. (2 minutes) - switch to per-step timeout for GitHub CI cmake/ctest runs. (10 minutes) ctest timeout (of 450 seconds) didn't seem to make any difference. --- .github/workflows/ci.yml | 3 ++- appveyor.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee054b935..6943f1ff7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,7 @@ jobs: make make check - name: Build with CMake + timeout-minutes: 10 if: ${{ matrix.b == 'cmake' }} run: | mkdir bin @@ -91,7 +92,7 @@ jobs: cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. cmake --build . export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) - ctest -VV --output-on-failure --timeout 450 + ctest -VV --output-on-failure cmake --build . --target package build_msys2: diff --git a/appveyor.yml b/appveyor.yml index 07868447c2..14005e8b19 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -95,7 +95,8 @@ before_test: - appveyor-retry choco install -y --no-progress --limit-output --timeout 180 docker-cli - ps: | Write-Host "Waiting for SSH connection from GitHub Actions" -NoNewline - while((Get-Process -Name "sshd" -ErrorAction SilentlyContinue).Count -eq 1) { + $endDate = (Get-Date).AddMinutes(2) + while((Get-Process -Name "sshd" -ErrorAction SilentlyContinue).Count -eq 1 -and (Get-Date) -lt $endDate) { Write-Host "." -NoNewline Start-Sleep -Seconds 1 } From de91e220813fbddf8a9301c85fdcf65ced02fa86 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 19 Mar 2023 15:51:52 +0000 Subject: [PATCH 140/424] build: improve a test build workaround with bcrypt - cmake: extend workaround for linking a test with shared libssh2. One of the tests uses internal libssh2 functions, and with CMake it compiles `src/misc.c` directly for this. `misc.c` references bcrypt / blowfish code. This needs a workaround for build configs where libssh2 doesn't export these. Before this patch, we enabled this workaround for MSVC. In the patch we extend this to all Windows. There is no CI test for this, but gcc and llvm/clang + mingw64 builds also need it. This may well apply to other configurations (it should, as shared libs are not supposed to export internal functions), so also make it easy to enable it at a single point. [ autotools builds force-link this one test against static libssh2. ] - make `misc.c` not depend on bcrypt. By moving out our `bcrypt_pbkdf()` wrapper into `bcrypt_pbkdf.c` itself. This allows to compile `misc.c` into tests without pulling in bcrypt / blowfish functions, and simplify the above workaround. Source code uses `HAVE_BCRYPT_PBKDF`, a leftover from original bcrypt source. We never define this inside libssh2. Defining it breaks the build, and this patch doesn't change that. - make `bcrypt_pbkdf()` static. While here, make the low-level `bcrypt_pbkdf()` function static to avoid namespace pollution. Closes #855 --- src/bcrypt_pbkdf.c | 23 +++++++++++++++++-- src/blf.h | 5 ---- src/misc.c | 21 ----------------- tests/CMakeLists.txt | 2 +- ...t_keyboard_interactive_auth_info_request.c | 19 --------------- 5 files changed, 22 insertions(+), 48 deletions(-) diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 98470c53fd..d1b5b3d7c4 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -15,10 +15,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "libssh2_priv.h" #ifndef HAVE_BCRYPT_PBKDF -#include "libssh2_priv.h" #include #include #ifdef HAVE_SYS_PARAM_H @@ -100,7 +100,7 @@ bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out) _libssh2_explicit_zero(&state, sizeof(state)); } -int +static int bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, size_t saltlen, uint8_t *key, size_t keylen, unsigned int rounds) @@ -181,3 +181,22 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, return 0; } #endif /* HAVE_BCRYPT_PBKDF */ + +/* Wrapper */ + +int _libssh2_bcrypt_pbkdf(const char *pass, + size_t passlen, + const uint8_t *salt, + size_t saltlen, + uint8_t *key, + size_t keylen, + unsigned int rounds) +{ + return bcrypt_pbkdf(pass, + passlen, + salt, + saltlen, + key, + keylen, + rounds); +} diff --git a/src/blf.h b/src/blf.h index cdd089ace4..c694d31f2f 100644 --- a/src/blf.h +++ b/src/blf.h @@ -77,10 +77,5 @@ void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t); /* Converts uint8_t to uint32_t */ uint32_t Blowfish_stream2word(const uint8_t *, uint16_t, uint16_t *); -/* bcrypt with pbkd */ -int bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, - size_t saltlen, - uint8_t *key, size_t keylen, unsigned int rounds); - #endif /* !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H) */ #endif /* __LIBSSH2_BLF_H */ diff --git a/src/misc.c b/src/misc.c index a262e09dc3..a8bebcfcab 100644 --- a/src/misc.c +++ b/src/misc.c @@ -39,7 +39,6 @@ #include "libssh2_priv.h" #include "misc.h" -#include "blf.h" #ifdef HAVE_STDLIB_H #include @@ -927,23 +926,3 @@ int _libssh2_eob(struct string_buf *buf) unsigned char *endp = &buf->data[buf->len]; return buf->dataptr >= endp; } - -/* Wrappers */ - -int _libssh2_bcrypt_pbkdf(const char *pass, - size_t passlen, - const uint8_t *salt, - size_t saltlen, - uint8_t *key, - size_t keylen, - unsigned int rounds) -{ - /* defined in bcrypt_pbkdf.c */ - return bcrypt_pbkdf(pass, - passlen, - salt, - saltlen, - key, - keylen, - rounds); -} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c748e81580..485b6fa875 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -230,7 +230,7 @@ foreach(test ${TESTS}) endforeach() if(WIN32 AND BUILD_SHARED_LIBS) - # Workaround for Visual Studio + # Workaround for platforms not exporting internal functions from libssh2 shared lib add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c ../src/misc.c) else() add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index fc9e3d6aad..96df9556dc 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -315,22 +315,3 @@ int main(void) return 0; } - -/* Workaround for Visual Studio */ -#ifdef _MSC_VER -int -bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, - size_t saltlen, - uint8_t *key, size_t keylen, unsigned int rounds) -{ - (void)pass; - (void)passlen; - (void)salt; - (void)saltlen; - (void)key; - (void)keylen; - (void)rounds; - - return -1; -} -#endif From 4997f921eec39d5226d9eb6657c689f26397c10f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 19 Mar 2023 17:42:12 +0000 Subject: [PATCH 141/424] cmake: fix `ENABLE_WERROR=ON` breaking auto-detections - cmake: fix compiler warnings in `CheckNonblockingSocketSupport`. detection functions. Without this, these detections fail when `ENABLE_WERROR=ON`. - cmake: disable ENABLE_WERROR for MSVC during symbol checks in `src`. CMake's built-in symbol check function `check_symbol_exists()` generate warnings with MSVC. With warnings considered errors, these detections fail permanently. Our workaround is to disable warnings-as-errors while running these checks. ``` CheckSymbolExists.c(8): warning C4054: 'type cast': from function pointer '__int64 (__cdecl *)(const char *,char **,int)' to data pointer 'int *' in `return ((int*)(&strtoll))[argc];` ``` Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46537222/job/4vg4yg333mu2lg9b - example: replace `strcasecmp()` with C89 `strcmp()`. To avoid using CMake symbol checks in `example`. Another option is to duplicate the `check_symbol_exists()` workaround from `src`, but I figure it's not worth the complexity. We use `strcasecmp()` solely to check optional command-line options for example programs, and those are fine as lower-case. Without this, these detections fail when `ENABLE_WERROR=ON`. - also delete `__function__` detection/use in `example`. To avoid the complexity for the sake of using it at a single place in of the example's error branch. Replace that use with a literal name of the function. - cmake: also use `CMakePushCheckState` functions instead of manual save/restore. Closes #857 --- cmake/CheckNonblockingSocketSupport.cmake | 32 +++++++++++------------ example/CMakeLists.txt | 7 ----- example/direct_tcpip.c | 4 +-- example/libssh2_config_cmake.h.in | 24 ----------------- example/sftp.c | 6 ++--- example/sftpdir.c | 6 ++--- example/ssh2.c | 6 ++--- example/subsystem_netconf.c | 8 +++--- example/tcpip-forward.c | 4 +-- nw/GNUmakefile | 4 --- src/CMakeLists.txt | 21 ++++++++++++--- win32/libssh2_config.h | 5 ---- 12 files changed, 50 insertions(+), 77 deletions(-) diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index ba771ed2bd..6affb1cc39 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -47,10 +47,10 @@ macro(check_nonblocking_socket_support) #error \"O_NONBLOCK does not work on this platform\" #endif -int main() +int main(void) { - int socket; - int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK); + int socket = 0; + (void)fcntl(socket, F_SETFL, O_NONBLOCK); }" HAVE_O_NONBLOCK) @@ -59,10 +59,11 @@ int main() #include #include -int main() +int main(void) { - int socket; - int flags = ioctl(socket, FIONBIO, &flags); + int socket = 0; + int flags = 0; + (void)ioctl(socket, FIONBIO, &flags); }" HAVE_FIONBIO) @@ -76,12 +77,11 @@ int main() #include #include -int main() +int main(void) { - SOCKET sd; + SOCKET sd = socket(0, 0, 0); unsigned long flags = 0; - sd = socket(0, 0, 0); - ioctlsocket(sd, FIONBIO, &flags); + (void)ioctlsocket(sd, FIONBIO, &flags); }" HAVE_IOCTLSOCKET) @@ -89,10 +89,10 @@ int main() check_c_source_compiles("/* IoctlSocket test (Amiga?) */ #include -int main() +int main(void) { - int socket; - int flags = IoctlSocket(socket, FIONBIO, (long)1); + int socket = 0; + (void)IoctlSocket(socket, FIONBIO, (long)1); }" HAVE_IOCTLSOCKET_CASE) @@ -100,11 +100,11 @@ int main() check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */ #include -int main() +int main(void) { long b = 1; - int socket; - int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); + int socket = 0; + (void)setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); }" HAVE_SO_NONBLOCK) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 33db9c5349..adf27433b7 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -34,7 +34,6 @@ # OF SUCH DAMAGE. include(CheckIncludeFiles) -include(CheckSymbolExists) include(CopyRuntimeDependencies) set(EXAMPLES @@ -87,12 +86,6 @@ check_include_files(arpa/inet.h HAVE_ARPA_INET_H) check_include_files(netinet/in.h HAVE_NETINET_IN_H) check_include_files(winsock2.h HAVE_WINSOCK2_H) -check_symbol_exists(strcasecmp strings.h HAVE_STRCASECMP) -check_symbol_exists(_stricmp string.h HAVE__STRICMP) - -check_symbol_exists(__func__ "" HAVE___FUNC__) -check_symbol_exists(__FUNCTION__ "" HAVE___FUNCTION__) - configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 9a2af73287..7193ba1fe1 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -170,9 +170,9 @@ int main(int argc, char *argv[]) /* check for options */ if(argc > 8) { - if((auth & AUTH_PASSWORD) && !strcasecmp(argv[8], "-p")) + if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p")) auth = AUTH_PASSWORD; - if((auth & AUTH_PUBLICKEY) && !strcasecmp(argv[8], "-k")) + if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k")) auth = AUTH_PUBLICKEY; } diff --git a/example/libssh2_config_cmake.h.in b/example/libssh2_config_cmake.h.in index bdcbe84969..9985d74fbc 100644 --- a/example/libssh2_config_cmake.h.in +++ b/example/libssh2_config_cmake.h.in @@ -44,27 +44,3 @@ #cmakedefine HAVE_ARPA_INET_H #cmakedefine HAVE_NETINET_IN_H #cmakedefine HAVE_WINSOCK2_H - -/* Functions */ -#cmakedefine HAVE_STRCASECMP -#cmakedefine HAVE__STRICMP - -/* Workaround for platforms without POSIX strcasecmp (e.g. Windows) */ -#ifndef HAVE_STRCASECMP -# ifdef HAVE__STRICMP -# define strcasecmp _stricmp -# define HAVE_STRCASECMP -# endif -#endif - -/* Symbols */ -#cmakedefine HAVE___FUNC__ -#cmakedefine HAVE___FUNCTION__ - -/* Workaround for platforms without C90 __func__ */ -#ifndef HAVE___FUNC__ -# ifdef HAVE___FUNCTION__ -# define __func__ __FUNCTION__ -# define HAVE___FUNC__ -# endif -#endif diff --git a/example/sftp.c b/example/sftp.c index 1f1ddaf3f7..8707a5021f 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -209,13 +209,13 @@ int main(int argc, char *argv[]) /* if we got an 4. argument we set this option if supported */ if(argc > 5) { - if((auth_pw & 1) && !strcasecmp(argv[5], "-p")) { + if((auth_pw & 1) && !strcmp(argv[5], "-p")) { auth_pw = 1; } - if((auth_pw & 2) && !strcasecmp(argv[5], "-i")) { + if((auth_pw & 2) && !strcmp(argv[5], "-i")) { auth_pw = 2; } - if((auth_pw & 4) && !strcasecmp(argv[5], "-k")) { + if((auth_pw & 4) && !strcmp(argv[5], "-k")) { auth_pw = 4; } } diff --git a/example/sftpdir.c b/example/sftpdir.c index 5174d14e1a..2602413d56 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -180,13 +180,13 @@ int main(int argc, char *argv[]) /* if we got an 5. argument we set this option if supported */ if(argc > 5) { - if((auth_pw & 1) && !strcasecmp(argv[5], "-p")) { + if((auth_pw & 1) && !strcmp(argv[5], "-p")) { auth_pw = 1; } - if((auth_pw & 2) && !strcasecmp(argv[5], "-i")) { + if((auth_pw & 2) && !strcmp(argv[5], "-i")) { auth_pw = 2; } - if((auth_pw & 4) && !strcasecmp(argv[5], "-k")) { + if((auth_pw & 4) && !strcmp(argv[5], "-k")) { auth_pw = 4; } } diff --git a/example/ssh2.c b/example/ssh2.c index 9fe7168b6a..9475e98729 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -185,13 +185,13 @@ int main(int argc, char *argv[]) /* if we got an 4. argument we set this option if supported */ if(argc > 4) { - if((auth_pw & 1) && !strcasecmp(argv[4], "-p")) { + if((auth_pw & 1) && !strcmp(argv[4], "-p")) { auth_pw = 1; } - if((auth_pw & 2) && !strcasecmp(argv[4], "-i")) { + if((auth_pw & 2) && !strcmp(argv[4], "-i")) { auth_pw = 2; } - if((auth_pw & 4) && !strcasecmp(argv[4], "-k")) { + if((auth_pw & 4) && !strcmp(argv[4], "-k")) { auth_pw = 4; } } diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index 1b17bf67f8..ccb35ebdfd 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -102,8 +102,8 @@ static int netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag, } while(!specialsequence && rd < buflen); if(!specialsequence) { - fprintf(stderr, "%s: ]]>]]> not found! read buffer too small?\n", - __func__); + fprintf(stderr, "netconf_read_until(): ]]>]]> not found!" + " read buffer too small?\n"); return -1; } @@ -211,9 +211,9 @@ int main(int argc, char *argv[]) /* check for options */ if(argc > 4) { - if((auth & AUTH_PASSWORD) && !strcasecmp(argv[4], "-p")) + if((auth & AUTH_PASSWORD) && !strcmp(argv[4], "-p")) auth = AUTH_PASSWORD; - if((auth & AUTH_PUBLICKEY) && !strcasecmp(argv[4], "-k")) + if((auth & AUTH_PUBLICKEY) && !strcmp(argv[4], "-k")) auth = AUTH_PUBLICKEY; } diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 3f9e6d7ad1..6ed5a92ab8 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -166,9 +166,9 @@ int main(int argc, char *argv[]) /* check for options */ if(argc > 8) { - if((auth & AUTH_PASSWORD) && !strcasecmp(argv[8], "-p")) + if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p")) auth = AUTH_PASSWORD; - if((auth & AUTH_PUBLICKEY) && !strcasecmp(argv[8], "-k")) + if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k")) auth = AUTH_PUBLICKEY; } diff --git a/nw/GNUmakefile b/nw/GNUmakefile index 764ac04b4a..b25248e606 100644 --- a/nw/GNUmakefile +++ b/nw/GNUmakefile @@ -392,11 +392,8 @@ libssh2_config.h: GNUmakefile ifeq ($(LIBARCH),CLIB) @echo $(DL)#define OS "i586-pc-clib-NetWare"$(DL) >> $@ @echo $(DL)#define NETDB_USE_INTERNET 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRICMP 1$(DL) >> $@ @echo $(DL)#define socklen_t int$(DL) >> $@ @echo $(DL)#define sleep(s) delay(1000 * s)$(DL) >> $@ - @echo $(DL)#define strcasecmp stricmp$(DL) >> $@ - @echo $(DL)#define strncasecmp strnicmp$(DL) >> $@ else @echo $(DL)#define OS "i586-pc-libc-NetWare"$(DL) >> $@ @echo $(DL)#define HAVE_DLFCN_H 1$(DL) >> $@ @@ -408,7 +405,6 @@ else @echo $(DL)#define HAVE_LIMITS_H 1$(DL) >> $@ @echo $(DL)#define HAVE_LONGLONG 1$(DL) >> $@ @echo $(DL)#define HAVE_STDINT_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRCASECMP 1$(DL) >> $@ @echo $(DL)#define HAVE_STRLCAT 1$(DL) >> $@ @echo $(DL)#define HAVE_STRLCPY 1$(DL) >> $@ @echo $(DL)#define HAVE_STRTOLL 1$(DL) >> $@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ec9b1dbfe..caba5f82a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ include(CheckIncludeFiles) include(CheckTypeSize) include(CheckSymbolExists) include(CheckNonblockingSocketSupport) +include(CMakePushCheckState) ## Cryptography backend choice @@ -102,14 +103,14 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) endif() # Not all OpenSSL have AES-CTR functions. - set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + cmake_push_check_state() set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}) if(WIN32) # For OpenSSL and LibreSSL set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}" "ws2_32" "bcrypt") endif() check_function_exists(EVP_aes_128_ctr HAVE_EVP_AES_128_CTR) - set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES}) + cmake_pop_check_state() endif() endif() @@ -326,6 +327,14 @@ check_include_files(winsock2.h HAVE_WINSOCK2_H) check_type_size("long long" LONGLONG) +# CMake uses C syntax in check_symbol_exists() that generates a warning with +# MSVC. To not break detection with ENABLE_WERRROR, we disable it for the +# duration of these tests. +if(MSVC AND ENABLE_WERROR) + cmake_push_check_state() + set(CMAKE_REQUIRED_FLAGS "/WX-") +endif() + if(HAVE_SYS_TIME_H) check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY) else() @@ -343,6 +352,10 @@ endif() check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) check_symbol_exists(memset_s string.h HAVE_MEMSET_S) +if(MSVC AND ENABLE_WERROR) + cmake_pop_check_state() +endif() + if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Interix") # poll() does not work on these platforms @@ -371,10 +384,10 @@ endif() # Non-blocking socket support tests. Use a separate, yet unset variable # for the socket libraries to not link against the other configured # dependencies which might not have been built yet. -set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) +cmake_push_check_state() set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES}) check_nonblocking_socket_support() -set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES}) +cmake_pop_check_state() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 5308df7c8f..e6df03cfb1 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -31,12 +31,7 @@ # define vsnprintf _vsnprintf # endif # define strdup _strdup -# define strncasecmp _strnicmp -# define strcasecmp _stricmp # endif -#else -# define strncasecmp strnicmp -# define strcasecmp stricmp #endif /* Enable newer diffie-hellman-group-exchange-sha1 syntax */ From 244a1ae8561644cf863e64a8334dc6cb5c64a9bf Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 19 Mar 2023 20:01:48 +0100 Subject: [PATCH 142/424] nw, os400, watcom: stop setting unused macros [ci skip] (#859) --- nw/GNUmakefile | 68 +----------------------------------------- os400/initscript.sh | 2 +- os400/libssh2_config.h | 33 -------------------- win32/Makefile.Watcom | 4 --- 4 files changed, 2 insertions(+), 105 deletions(-) diff --git a/nw/GNUmakefile b/nw/GNUmakefile index b25248e606..4a4e28c341 100644 --- a/nw/GNUmakefile +++ b/nw/GNUmakefile @@ -396,96 +396,30 @@ ifeq ($(LIBARCH),CLIB) @echo $(DL)#define sleep(s) delay(1000 * s)$(DL) >> $@ else @echo $(DL)#define OS "i586-pc-libc-NetWare"$(DL) >> $@ - @echo $(DL)#define HAVE_DLFCN_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_DLOPEN 1$(DL) >> $@ - @echo $(DL)#define HAVE_FTRUNCATE 1$(DL) >> $@ @echo $(DL)#define HAVE_GETTIMEOFDAY 1$(DL) >> $@ - @echo $(DL)#define HAVE_INET_PTON 1$(DL) >> $@ @echo $(DL)#define HAVE_INTTYPES_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_LIMITS_H 1$(DL) >> $@ @echo $(DL)#define HAVE_LONGLONG 1$(DL) >> $@ @echo $(DL)#define HAVE_STDINT_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRLCAT 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRLCPY 1$(DL) >> $@ @echo $(DL)#define HAVE_STRTOLL 1$(DL) >> $@ @echo $(DL)#define HAVE_SYS_PARAM_H 1$(DL) >> $@ @echo $(DL)#define HAVE_SYS_SELECT_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_TERMIOS_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_AF_INET6 1$(DL) >> $@ - @echo $(DL)#define HAVE_PF_INET6 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRUCT_IN6_ADDR 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRUCT_SOCKADDR_IN6 1$(DL) >> $@ - @echo $(DL)#define SIZEOF_STRUCT_IN6_ADDR 16$(DL) >> $@ -ifdef ENABLE_IPV6 - @echo $(DL)#define ENABLE_IPV6 1$(DL) >> $@ -endif endif @echo $(DL)#define HAVE_SNPRINTF 1$(DL) >> $@ @echo $(DL)#define HAVE_ARPA_INET_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_ASSERT_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_CTYPE_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_ERR_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_ERRNO_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_FCNTL_H 1$(DL) >> $@ @echo $(DL)#define HAVE_FIONBIO 1$(DL) >> $@ - @echo $(DL)#define HAVE_GETHOSTBYADDR 1$(DL) >> $@ - @echo $(DL)#define HAVE_GETHOSTBYNAME 1$(DL) >> $@ - @echo $(DL)#define HAVE_GETPROTOBYNAME 1$(DL) >> $@ - @echo $(DL)#define HAVE_GMTIME_R 1$(DL) >> $@ - @echo $(DL)#define HAVE_INET_NTOA 1$(DL) >> $@ - @echo $(DL)#define HAVE_LL 1$(DL) >> $@ - @echo $(DL)#define HAVE_LOCALTIME_R 1$(DL) >> $@ - @echo $(DL)#define HAVE_MALLOC_H 1$(DL) >> $@ @echo $(DL)#define HAVE_NETINET_IN_H 1$(DL) >> $@ @echo $(DL)#define HAVE_SELECT 1$(DL) >> $@ - @echo $(DL)#define HAVE_SETJMP_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SIGNAL 1$(DL) >> $@ - @echo $(DL)#define HAVE_SIGNAL_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SIG_ATOMIC_T 1$(DL) >> $@ @echo $(DL)#define HAVE_STDLIB_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRDUP 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRFTIME 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRING_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRSTR 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRUCT_ADDRINFO 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRUCT_TIMEVAL 1$(DL) >> $@ @echo $(DL)#define HAVE_SYS_IOCTL_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SYS_STAT_H 1$(DL) >> $@ @echo $(DL)#define HAVE_SYS_TIME_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_TIME_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_UNAME 1$(DL) >> $@ @echo $(DL)#define HAVE_UNISTD_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_UTIME 1$(DL) >> $@ - @echo $(DL)#define HAVE_UTIME_H 1$(DL) >> $@ - @echo $(DL)#define RETSIGTYPE void$(DL) >> $@ - @echo $(DL)#define SIZEOF_STRUCT_IN_ADDR 4$(DL) >> $@ @echo $(DL)#define STDC_HEADERS 1$(DL) >> $@ - @echo $(DL)#define TIME_WITH_SYS_TIME 1$(DL) >> $@ - @echo $(DL)#define USE_SSLEAY 1$(DL) >> $@ - @echo $(DL)#define USE_OPENSSL 1$(DL) >> $@ - @echo $(DL)#define HAVE_OPENSSL_X509_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_OPENSSL_SSL_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_OPENSSL_RSA_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_OPENSSL_PEM_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_OPENSSL_ERR_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_OPENSSL_CRYPTO_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_OPENSSL_ENGINE_H 1$(DL) >> $@ @echo $(DL)#define HAVE_O_NONBLOCK 1$(DL) >> $@ - @echo $(DL)#define HAVE_LIBSSL 1$(DL) >> $@ - @echo $(DL)#define HAVE_LIBCRYPTO 1$(DL) >> $@ - @echo $(DL)#define OPENSSL_NO_KRB5 1$(DL) >> $@ ifdef WITH_ZLIB - @echo $(DL)#define HAVE_ZLIB_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_LIBZ 1$(DL) >> $@ @echo $(DL)#define LIBSSH2_HAVE_ZLIB 1$(DL) >> $@ endif -ifdef NW_WINSOCK - @echo $(DL)#define HAVE_CLOSESOCKET 1$(DL) >> $@ -else - @echo $(DL)#define HAVE_SYS_TYPES_H 1$(DL) >> $@ +ifndef NW_WINSOCK @echo $(DL)#define HAVE_SYS_SOCKET_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SYS_SOCKIO_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_NETDB_H 1$(DL) >> $@ endif ifdef OLD_NOVELLSDK @echo $(DL)#define socklen_t int$(DL) >> $@ diff --git a/os400/initscript.sh b/os400/initscript.sh index a18e24cfeb..9b773d0137 100644 --- a/os400/initscript.sh +++ b/os400/initscript.sh @@ -198,7 +198,7 @@ make_module() DEFINES="${3}" if [ "${WITH_ZLIB}" != "0" ] - then DEFINES="${DEFINES} HAVE_LIBZ LIBSSH2_HAVE_ZLIB" + then DEFINES="${DEFINES} LIBSSH2_HAVE_ZLIB" fi if [ "${DEFINES}" ] diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index c77ac80fa4..2fccfcf425 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -62,18 +62,9 @@ /* disabled non-blocking sockets */ #undef HAVE_DISABLED_NONBLOCKING -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the header file. */ -#define HAVE_ERRNO_H 1 - /* Define to 1 if you have the `EVP_aes_128_ctr' function. */ #undef HAVE_EVP_AES_128_CTR -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - /* use FIONBIO for non-blocking sockets */ #undef HAVE_FIONBIO @@ -89,27 +80,15 @@ /* use Ioctlsocket() for non-blocking sockets */ #undef HAVE_IOCTLSOCKET_CASE -/* Define if you have the bcrypt library. */ -#undef HAVE_LIBBCRYPT - /* Define if you have the crypt32 library. */ #undef HAVE_LIBCRYPT32 /* Define if you have the gcrypt library. */ #undef HAVE_LIBGCRYPT -/* Define if you have the ssl library. */ -#undef HAVE_LIBSSL - -/* Define if you have the z library. */ -/* #undef HAVE_LIBZ */ - /* Define to 1 if the compiler supports the 'long long' data type. */ #define HAVE_LONGLONG 1 -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - /* Define to 1 if you have the header file. */ #define HAVE_NETINET_IN_H 1 @@ -134,12 +113,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - /* Define to 1 if you have the `strtoll' function. */ #define HAVE_STRTOLL 1 @@ -152,15 +125,9 @@ /* Define to 1 if you have the header file. */ #define HAVE_SYS_SOCKET_H 1 -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - /* Define to 1 if you have the header file. */ #define HAVE_SYS_TIME_H 1 -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - /* Define to 1 if you have the header file. */ #define HAVE_SYS_UIO_H 1 diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom index 8b39d51c0a..8ecf95c04c 100644 --- a/win32/Makefile.Watcom +++ b/win32/Makefile.Watcom @@ -54,10 +54,6 @@ CFLAGS += -d3 $(DEBUG) CFLAGS += -d0 !endif -!ifdef %use_ipv6 -CFLAGS += -d_WIN32_WINNT=0x0501 -dENABLE_IPV6 -!endif - # # Change to suite. # From 5a9944e754ff23aa106cd541ce2ae91d15d55f45 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 20 Mar 2023 00:35:15 +0000 Subject: [PATCH 143/424] wincng: fix memory leak in `_libssh2_dh_secret()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch-by: iruis on github Assisted-by: Marc Hörsken Bug #846, commit e3487092ef9553af67633c6747cb9ab2f86465e0. Fixes #856 Closes #858 --- src/wincng.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wincng.c b/src/wincng.c index e990af1685..9a88379ae5 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -2651,6 +2651,9 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, if(agreement) { BCryptDestroySecret(agreement); } + + free(blob); + if(status == STATUS_NOT_SUPPORTED && _libssh2_wincng.hasAlgDHwithKDF == -1) { goto fb; /* fallback to RSA-based implementation */ From ec0a51db1f69eafa14ead6d17e6aca13075c034b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 20 Mar 2023 09:30:40 +0000 Subject: [PATCH 144/424] openssl: require `EVP_aes_128_ctr()` support libssh2 built with OpenSSL and without its `EVP_aes_128_ctr()`, aka `HAVE_EVP_AES_128_CTR`, option are working incorrectly. This option wasn't always auto-detected by autotools up until recently (#811). Non-cmake, non-autotools build methods never enabled it automatically. OpenSSL supports this options since at least v1.0.2, which is already EOLed and considered obsolete. OpenSSL forks (LibreSSL, BoringSSL) supported it all along. In this patch we enable this option unconditionally, now requiring OpenSSL supporting this function, or one of its forks. Also modernize OpenSSL lib references to what 1.0.2 and newer versions have been using. Fixes #739 --- acinclude.m4 | 11 +- os400/libssh2_config.h | 3 - src/CMakeLists.txt | 14 +- src/libssh2_config_cmake.h.in | 3 - src/openssl.c | 233 ---------------------------------- src/openssl.h | 10 -- win32/Makefile.Watcom | 11 +- win32/config.mk | 2 +- win32/msvcproj.head | 4 +- win32/tests.dsp | 4 +- 10 files changed, 13 insertions(+), 282 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index e4806b7356..f645f4a50a 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -419,17 +419,8 @@ m4_case([$1], LIBSSH2_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include ], [ AC_DEFINE(LIBSSH2_OPENSSL, 1, [Use $1]) LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }libssl libcrypto" - - # Not all OpenSSL have AES-CTR functions. - libssh2_save_LIBS="$LIBS" - # Duplicate $LIBS to make binutils ld (known to be fatally - # sensitive to lib order) happy. - LIBS="$LIBS $LIBSSL $LIBS" - AC_CHECK_FUNCS(EVP_aes_128_ctr) - LIBS="$libssh2_save_LIBS" - found_crypto="$1" - found_crypto_str="OpenSSL (AES-CTR: ${ac_cv_func_EVP_aes_128_ctr:-N/A})" + found_crypto_str="OpenSSL" ]) ], diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 2fccfcf425..713eb52884 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -62,9 +62,6 @@ /* disabled non-blocking sockets */ #undef HAVE_DISABLED_NONBLOCKING -/* Define to 1 if you have the `EVP_aes_128_ctr' function. */ -#undef HAVE_EVP_AES_128_CTR - /* use FIONBIO for non-blocking sockets */ #undef HAVE_FIONBIO diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index caba5f82a0..f131db3f79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,7 +76,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) list(APPEND PC_LIBS -lcrypt32 -lbcrypt) find_file(DLL_LIBCRYPTO - NAMES libeay32.dll crypto.dll libcrypto.dll + NAMES crypto.dll libcrypto.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll libcrypto-3.dll libcrypto-3-x64.dll HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} @@ -87,7 +87,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) endif() find_file(DLL_LIBSSL - NAMES ssleay32.dll ssl.dll libssl.dll + NAMES ssl.dll libssl.dll libssl-1_1.dll libssl-1_1-x64.dll libssl-3.dll libssl-3-x64.dll HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} @@ -101,16 +101,6 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBCRYPTO} ${DLL_LIBSSL}) endif() endif() - - # Not all OpenSSL have AES-CTR functions. - cmake_push_check_state() - set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}) - if(WIN32) - # For OpenSSL and LibreSSL - set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}" "ws2_32" "bcrypt") - endif() - check_function_exists(EVP_aes_128_ctr HAVE_EVP_AES_128_CTR) - cmake_pop_check_state() endif() endif() diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index da9e68af53..7bc9d5cf82 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -62,9 +62,6 @@ #cmakedefine HAVE_STRTOI64 #cmakedefine HAVE_SNPRINTF -/* OpenSSL functions */ -#cmakedefine HAVE_EVP_AES_128_CTR - /* Socket non-blocking support */ #cmakedefine HAVE_O_NONBLOCK #cmakedefine HAVE_FIONBIO diff --git a/src/openssl.c b/src/openssl.c index 131a4231e7..0a89b512b6 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -496,215 +496,6 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, return rc; } -#if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR) - -#include -#include - -typedef struct -{ - AES_KEY key; - EVP_CIPHER_CTX *aes_ctx; - unsigned char ctr[AES_BLOCK_SIZE]; -} aes_ctr_ctx; - -static EVP_CIPHER * aes_128_ctr_cipher = NULL; -static EVP_CIPHER * aes_192_ctr_cipher = NULL; -static EVP_CIPHER * aes_256_ctr_cipher = NULL; - -static int -aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) /* init key */ -{ - /* - * variable "c" is leaked from this scope, but is later freed - * in aes_ctr_cleanup - */ - aes_ctr_ctx *c; - const EVP_CIPHER *aes_cipher; - (void) enc; - - switch(EVP_CIPHER_CTX_key_length(ctx)) { - case 16: - aes_cipher = EVP_aes_128_ecb(); - break; - case 24: - aes_cipher = EVP_aes_192_ecb(); - break; - case 32: - aes_cipher = EVP_aes_256_ecb(); - break; - default: - return 0; - } - - c = malloc(sizeof(*c)); - if(c == NULL) - return 0; - -#ifdef HAVE_OPAQUE_STRUCTS - c->aes_ctx = EVP_CIPHER_CTX_new(); -#else - c->aes_ctx = malloc(sizeof(EVP_CIPHER_CTX)); -#endif - if(c->aes_ctx == NULL) { - free(c); - return 0; - } - - if(EVP_EncryptInit(c->aes_ctx, aes_cipher, key, NULL) != 1) { -#ifdef HAVE_OPAQUE_STRUCTS - EVP_CIPHER_CTX_free(c->aes_ctx); -#else - free(c->aes_ctx); -#endif - free(c); - return 0; - } - - EVP_CIPHER_CTX_set_padding(c->aes_ctx, 0); - - memcpy(c->ctr, iv, AES_BLOCK_SIZE); - - EVP_CIPHER_CTX_set_app_data(ctx, c); - - return 1; -} - -static int -aes_ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, - size_t inl) /* encrypt/decrypt data */ -{ - aes_ctr_ctx *c = EVP_CIPHER_CTX_get_app_data(ctx); - unsigned char b1[AES_BLOCK_SIZE]; - int outlen = 0; - - if(inl != 16) /* libssh2 only ever encrypt one block */ - return 0; - - if(c == NULL) { - return 0; - } - -/* - To encrypt a packet P=P1||P2||...||Pn (where P1, P2, ..., Pn are each - blocks of length L), the encryptor first encrypts with - to obtain a block B1. The block B1 is then XORed with P1 to generate - the ciphertext block C1. The counter X is then incremented -*/ - - if(EVP_EncryptUpdate(c->aes_ctx, b1, &outlen, - c->ctr, AES_BLOCK_SIZE) != 1) { - return 0; - } - - _libssh2_xor_data(out, in, b1, AES_BLOCK_SIZE); - _libssh2_aes_ctr_increment(c->ctr, AES_BLOCK_SIZE); - - return 1; -} - -static int -aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) /* cleanup ctx */ -{ - aes_ctr_ctx *c = EVP_CIPHER_CTX_get_app_data(ctx); - - if(c == NULL) { - return 1; - } - - if(c->aes_ctx != NULL) { -#ifdef HAVE_OPAQUE_STRUCTS - EVP_CIPHER_CTX_free(c->aes_ctx); -#else - _libssh2_cipher_dtor(c->aes_ctx); - free(c->aes_ctx); -#endif - } - - free(c); - - return 1; -} - -static const EVP_CIPHER * -make_ctr_evp (size_t keylen, EVP_CIPHER **aes_ctr_cipher, int type) -{ -#ifdef HAVE_OPAQUE_STRUCTS - *aes_ctr_cipher = EVP_CIPHER_meth_new(type, 16, keylen); - if(*aes_ctr_cipher) { - EVP_CIPHER_meth_set_iv_length(*aes_ctr_cipher, 16); - EVP_CIPHER_meth_set_init(*aes_ctr_cipher, aes_ctr_init); - EVP_CIPHER_meth_set_do_cipher(*aes_ctr_cipher, aes_ctr_do_cipher); - EVP_CIPHER_meth_set_cleanup(*aes_ctr_cipher, aes_ctr_cleanup); - } -#else - (*aes_ctr_cipher)->nid = type; - (*aes_ctr_cipher)->block_size = 16; - (*aes_ctr_cipher)->key_len = keylen; - (*aes_ctr_cipher)->iv_len = 16; - (*aes_ctr_cipher)->init = aes_ctr_init; - (*aes_ctr_cipher)->do_cipher = aes_ctr_do_cipher; - (*aes_ctr_cipher)->cleanup = aes_ctr_cleanup; -#endif - - return *aes_ctr_cipher; -} - -const EVP_CIPHER * -_libssh2_EVP_aes_128_ctr(void) -{ -#ifdef HAVE_OPAQUE_STRUCTS - return !aes_128_ctr_cipher ? - make_ctr_evp(16, &aes_128_ctr_cipher, NID_aes_128_ctr) : - aes_128_ctr_cipher; -#else - static EVP_CIPHER aes_ctr_cipher; - if(!aes_128_ctr_cipher) { - aes_128_ctr_cipher = &aes_ctr_cipher; - make_ctr_evp(16, &aes_128_ctr_cipher, 0); - } - return aes_128_ctr_cipher; -#endif -} - -const EVP_CIPHER * -_libssh2_EVP_aes_192_ctr(void) -{ -#ifdef HAVE_OPAQUE_STRUCTS - return !aes_192_ctr_cipher ? - make_ctr_evp(24, &aes_192_ctr_cipher, NID_aes_192_ctr) : - aes_192_ctr_cipher; -#else - static EVP_CIPHER aes_ctr_cipher; - if(!aes_192_ctr_cipher) { - aes_192_ctr_cipher = &aes_ctr_cipher; - make_ctr_evp(24, &aes_192_ctr_cipher, 0); - } - return aes_192_ctr_cipher; -#endif -} - -const EVP_CIPHER * -_libssh2_EVP_aes_256_ctr(void) -{ -#ifdef HAVE_OPAQUE_STRUCTS - return !aes_256_ctr_cipher ? - make_ctr_evp(32, &aes_256_ctr_cipher, NID_aes_256_ctr) : - aes_256_ctr_cipher; -#else - static EVP_CIPHER aes_ctr_cipher; - if(!aes_256_ctr_cipher) { - aes_256_ctr_cipher = &aes_ctr_cipher; - make_ctr_evp(32, &aes_256_ctr_cipher, 0); - } - return aes_256_ctr_cipher; -#endif -} - -#endif /* LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR) */ - void _libssh2_openssl_crypto_init(void) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ @@ -722,34 +513,10 @@ void _libssh2_openssl_crypto_init(void) ENGINE_register_all_complete(); #endif #endif -#if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR) - aes_128_ctr_cipher = (EVP_CIPHER *) _libssh2_EVP_aes_128_ctr(); - aes_192_ctr_cipher = (EVP_CIPHER *) _libssh2_EVP_aes_192_ctr(); - aes_256_ctr_cipher = (EVP_CIPHER *) _libssh2_EVP_aes_256_ctr(); -#endif } void _libssh2_openssl_crypto_exit(void) { -#if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR) -#ifdef HAVE_OPAQUE_STRUCTS - if(aes_128_ctr_cipher) { - EVP_CIPHER_meth_free(aes_128_ctr_cipher); - } - - if(aes_192_ctr_cipher) { - EVP_CIPHER_meth_free(aes_192_ctr_cipher); - } - - if(aes_256_ctr_cipher) { - EVP_CIPHER_meth_free(aes_256_ctr_cipher); - } -#endif - - aes_128_ctr_cipher = NULL; - aes_192_ctr_cipher = NULL; - aes_256_ctr_cipher = NULL; -#endif } /* TODO: Optionally call a passphrase callback specified by the diff --git a/src/openssl.h b/src/openssl.h index a2f168aaa6..b537ae0de7 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -67,10 +67,6 @@ #define OPENSSL_NO_DES #endif -#ifdef EVP_aes_128_ctr -#define HAVE_EVP_AES_128_CTR -#endif - /* wolfSSL doesn't support Blowfish or CAST. */ #define OPENSSL_NO_BF #define OPENSSL_NO_CAST @@ -387,15 +383,9 @@ libssh2_curve_type; #define _libssh2_cipher_aes256 EVP_aes_256_cbc #define _libssh2_cipher_aes192 EVP_aes_192_cbc #define _libssh2_cipher_aes128 EVP_aes_128_cbc -#ifdef HAVE_EVP_AES_128_CTR #define _libssh2_cipher_aes128ctr EVP_aes_128_ctr #define _libssh2_cipher_aes192ctr EVP_aes_192_ctr #define _libssh2_cipher_aes256ctr EVP_aes_256_ctr -#else -#define _libssh2_cipher_aes128ctr _libssh2_EVP_aes_128_ctr -#define _libssh2_cipher_aes192ctr _libssh2_EVP_aes_192_ctr -#define _libssh2_cipher_aes256ctr _libssh2_EVP_aes_256_ctr -#endif #define _libssh2_cipher_blowfish EVP_bf_cbc #define _libssh2_cipher_arcfour EVP_rc4 #define _libssh2_cipher_cast5 EVP_cast5_cbc diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom index 8ecf95c04c..9ca5ae850a 100644 --- a/win32/Makefile.Watcom +++ b/win32/Makefile.Watcom @@ -171,13 +171,12 @@ $(LINK_ARG): $(__MAKEFILES__) !ifdef %use_zlib @%append $^@ library '$(ZLIB_ROOT)\zlib.lib' !endif -!ifdef %use_wincng - @%append $^@ library bcrypt.lib - @%append $^@ library crypt32.lib -!else - @%append $^@ library '$(OPENSSL_ROOT)\out32\libeay32.lib' - @%append $^@ library '$(OPENSSL_ROOT)\out32\ssleay32.lib' +!ifndef %use_wincng + @%append $^@ library '$(OPENSSL_ROOT)\lib\crypt.lib' + @%append $^@ library '$(OPENSSL_ROOT)\lib\ssl.lib' !endif +@%append $^@ library bcrypt.lib +@%append $^@ library crypt32.lib $(LIB_ARG): $(__MAKEFILES__) %create $^@ diff --git a/win32/config.mk b/win32/config.mk index e57f8fe9f8..8f65cabffd 100644 --- a/win32/config.mk +++ b/win32/config.mk @@ -35,7 +35,7 @@ CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_WINCNG # LIBS=bcrypt.lib crypt32.lib !else CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSLINC) -LIBS=$(LIBS) $(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib +LIBS=$(LIBS) $(OPENSSLLIB)\lib\crypto.lib $(OPENSSLLIB)\lib\ssl.lib !endif !if "$(WITH_ZLIB)" == "1" diff --git a/win32/msvcproj.head b/win32/msvcproj.head index b1569a99af..67b5df2dda 100644 --- a/win32/msvcproj.head +++ b/win32/msvcproj.head @@ -62,7 +62,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib libeay32.lib zlib.lib /nologo /dll /map /debug /machine:I386 +# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib crypto.lib zlib.lib /nologo /dll /map /debug /machine:I386 !ELSEIF "$(CFG)" == "libssh2 - Win32 OpenSSL DLL Debug" @@ -89,7 +89,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib libeay32.lib zlib.lib /nologo /dll /incremental:no /map /debug /machine:I386 /pdbtype:sept +# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib crypto.lib zlib.lib /nologo /dll /incremental:no /map /debug /machine:I386 /pdbtype:sept # SUBTRACT LINK32 /nodefaultlib !ELSEIF "$(CFG)" == "libssh2 - Win32 OpenSSL LIB Release" diff --git a/win32/tests.dsp b/win32/tests.dsp index b2a89dcc09..45d13c4d47 100644 --- a/win32/tests.dsp +++ b/win32/tests.dsp @@ -50,7 +50,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2.lib /nologo /subsystem:console /machine:I386 /libpath:"Release" /out:"simple.exe" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib crypto.lib ssl.lib ws2_32.lib zlib.lib libssh2.lib /nologo /subsystem:console /machine:I386 /libpath:"Release" /out:"simple.exe" !ELSEIF "$(CFG)" == "tests - Win32 Debug" @@ -74,7 +74,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libeay32.lib ssleay32.lib ws2_32.lib zlib.lib libssh2d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept /libpath:"Debug" /out:"simple.exe" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib crypto.lib ssl.lib ws2_32.lib zlib.lib libssh2d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept /libpath:"Debug" /out:"simple.exe" !ENDIF From b13936bd6a89993cd3bf4a18317ca5bd84bb08d7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 20 Mar 2023 15:46:12 +0000 Subject: [PATCH 145/424] example, tests: address compiler warnings Fix or silence all C compiler warnings discovered with (or without) `PICKY_COMPILER=ON` (in CMake). This means all warnings showing up in CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and Windows cross-builds using gcc (12) and llvm/clang (14/15). Also fix the expression `nread -= nread` in `sftp_RW_nonblock.c`. Cherry-picked from: #846 Closes #861 --- example/direct_tcpip.c | 25 ++++++----- example/scp.c | 24 +++++++---- example/scp_nonblock.c | 26 ++++++----- example/scp_write.c | 17 ++++---- example/scp_write_nonblock.c | 25 +++++------ example/sftp.c | 18 +++++--- example/sftp_RW_nonblock.c | 38 +++++++++------- example/sftp_append.c | 13 +++--- example/sftp_mkdir.c | 2 +- example/sftp_mkdir_nonblock.c | 2 +- example/sftp_nonblock.c | 28 ++++++------ example/sftp_write.c | 13 +++--- example/sftp_write_nonblock.c | 20 ++++----- example/sftp_write_sliding.c | 22 +++++----- example/sftpdir.c | 9 ++-- example/sftpdir_nonblock.c | 4 +- example/ssh2.c | 9 ++-- example/ssh2_agent.c | 5 ++- example/ssh2_agent_forwarding.c | 28 ++++++------ example/ssh2_echo.c | 30 +++++++------ example/ssh2_exec.c | 27 ++++++------ example/subsystem_netconf.c | 11 ++--- example/tcpip-forward.c | 29 ++++++++----- example/x11.c | 11 ++--- tests/openssh_fixture.c | 43 ++++++++++--------- tests/openssh_fixture.h | 2 +- tests/session_fixture.c | 6 +-- tests/ssh2.c | 5 ++- tests/test_agent_forward_succeeds.c | 5 ++- tests/test_hostkey.c | 8 ++-- ...teractive_auth_fails_with_wrong_response.c | 7 +-- ...tive_auth_succeeds_with_correct_response.c | 7 +-- ..._password_auth_fails_with_wrong_password.c | 9 ++-- ..._password_auth_fails_with_wrong_username.c | 8 ++-- ...d_auth_succeeds_with_correct_credentials.c | 9 ++-- ...est_public_key_auth_fails_with_wrong_key.c | 5 ++- ...c_key_auth_succeeds_with_correct_dsa_key.c | 5 ++- ...key_auth_succeeds_with_correct_ecdsa_key.c | 5 ++- ...y_auth_succeeds_with_correct_ed25519_key.c | 5 ++- ...cceeds_with_correct_ed25519_key_from_mem.c | 3 +- ...ceeds_with_correct_encrypted_ed25519_key.c | 5 ++- ..._succeeds_with_correct_encrypted_rsa_key.c | 5 ++- ...c_key_auth_succeeds_with_correct_rsa_key.c | 5 ++- ...th_succeeds_with_correct_rsa_openssh_key.c | 5 ++- ...h_succeeds_with_correct_signed_ecdsa_key.c | 5 ++- ...uth_succeeds_with_correct_signed_rsa_key.c | 5 ++- tests/test_read.c | 7 +-- 47 files changed, 343 insertions(+), 262 deletions(-) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 7193ba1fe1..162f2fbd70 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -11,6 +11,8 @@ #include #include #include +#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) +#define send(s, b, l, f) send((s), (b), (int)(l), (f)) #else #include #include @@ -161,7 +163,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); fprintf(stderr, "Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "password")) auth |= AUTH_PASSWORD; @@ -261,7 +264,7 @@ int main(int argc, char *argv[]) FD_SET(forwardsock, &fds); tv.tv_sec = 0; tv.tv_usec = 100000; - rc = select(forwardsock + 1, &fds, NULL, NULL, &tv); + rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv); if(-1 == rc) { perror("select"); goto shutdown; @@ -279,15 +282,17 @@ int main(int argc, char *argv[]) } wr = 0; while(wr < len) { - i = libssh2_channel_write(channel, buf + wr, len - wr); - if(LIBSSH2_ERROR_EAGAIN == i) { + ssize_t nwritten = libssh2_channel_write(channel, + buf + wr, len - wr); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { continue; } - if(i < 0) { - fprintf(stderr, "libssh2_channel_write: %d\n", i); + if(nwritten < 0) { + fprintf(stderr, "libssh2_channel_write: %d\n", + (int)nwritten); goto shutdown; } - wr += i; + wr += nwritten; } } for(;;) { @@ -300,12 +305,12 @@ int main(int argc, char *argv[]) } wr = 0; while(wr < len) { - i = send(forwardsock, buf + wr, len - wr, 0); - if(i <= 0) { + ssize_t nsent = send(forwardsock, buf + wr, len - wr, 0); + if(nsent <= 0) { perror("write"); goto shutdown; } - wr += i; + wr += nsent; } if(libssh2_channel_eof(channel)) { fprintf(stderr, "The server at %s:%d disconnected!\n", diff --git a/example/scp.c b/example/scp.c index 2076daa497..c8e0ee3d93 100644 --- a/example/scp.c +++ b/example/scp.c @@ -36,9 +36,13 @@ #include #include +#ifdef WIN32 +#define write(f, b, c) write((f), (b), (unsigned int)(c)) +#endif + int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -159,20 +163,22 @@ int main(int argc, char *argv[]) while(got < fileinfo.st_size) { char mem[1024]; int amount = sizeof(mem); + ssize_t nread; - if((fileinfo.st_size -got) < amount) { - amount = (int)(fileinfo.st_size -got); + if((fileinfo.st_size - got) < amount) { + amount = (int)(fileinfo.st_size - got); } - rc = libssh2_channel_read(channel, mem, amount); - if(rc > 0) { - write(1, mem, rc); + nread = libssh2_channel_read(channel, mem, amount); + if(nread > 0) { + write(1, mem, nread); } - else if(rc < 0) { - fprintf(stderr, "libssh2_channel_read() failed: %d\n", rc); + else if(nread < 0) { + fprintf(stderr, "libssh2_channel_read() failed: %d\n", + (int)nread); break; } - got += rc; + got += nread; } libssh2_channel_free(channel); diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index e2adc652ba..453af82bf2 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -44,6 +44,10 @@ #include #include +#ifdef WIN32 +#define write(f, b, c) write((f), (b), (unsigned int)(c)) +#endif + #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) @@ -78,14 +82,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -238,6 +242,7 @@ int main(int argc, char *argv[]) while(got < fileinfo.st_size) { char mem[1024*24]; + ssize_t nread; do { int amount = sizeof(mem); @@ -247,15 +252,15 @@ int main(int argc, char *argv[]) } /* loop until we block */ - rc = libssh2_channel_read(channel, mem, amount); - if(rc > 0) { - write(1, mem, rc); - got += rc; - total += rc; + nread = libssh2_channel_read(channel, mem, amount); + if(nread > 0) { + write(1, mem, nread); + got += nread; + total += nread; } - } while(rc > 0); + } while(nread > 0); - if((rc == LIBSSH2_ERROR_EAGAIN) && (got < fileinfo.st_size)) { + if((nread == LIBSSH2_ERROR_EAGAIN) && (got < fileinfo.st_size)) { /* this is due to blocking that would occur otherwise so we loop on this condition */ @@ -271,8 +276,7 @@ int main(int argc, char *argv[]) time_ms = tvdiff(end, start); fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", - (long)total, - time_ms, total/(time_ms/1000.0), spin); + (long)total, time_ms, (double)total/(time_ms/1000.0), spin); #else fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin); #endif diff --git a/example/scp_write.c b/example/scp_write.c index 11e3860bc1..a92465b49c 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -171,7 +171,7 @@ int main(int argc, char *argv[]) /* Send a file via scp. The mode parameter must only have permissions! */ channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777, - (unsigned long)fileinfo.st_size); + (size_t)fileinfo.st_size); if(!channel) { char *errmsg; @@ -191,16 +191,17 @@ int main(int argc, char *argv[]) ptr = mem; do { + ssize_t nwritten; /* write the same data over and over, until error or completion */ - rc = libssh2_channel_write(channel, ptr, nread); - if(rc < 0) { - fprintf(stderr, "ERROR %d\n", rc); + nwritten = libssh2_channel_write(channel, ptr, nread); + if(nwritten < 0) { + fprintf(stderr, "ERROR %d\n", (int)nwritten); break; } else { - /* rc indicates how many bytes were written this time */ - ptr += rc; - nread -= rc; + /* nwritten indicates how many bytes were written this time */ + ptr += nwritten; + nread -= nwritten; } } while(nread); diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 6179a0a59c..b8ffa78452 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -65,14 +65,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) char *ptr; struct stat fileinfo; time_t start; - long total = 0; + libssh2_struct_stat_size total = 0; int duration; size_t prev; @@ -210,7 +210,7 @@ int main(int argc, char *argv[]) /* Send a file via scp. The mode parameter must only have permissions! */ do { channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777, - (unsigned long)fileinfo.st_size); + (size_t)fileinfo.st_size); if((!channel) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { @@ -236,22 +236,23 @@ int main(int argc, char *argv[]) prev = 0; do { - while((rc = libssh2_channel_write(channel, ptr, nread)) == + ssize_t nwritten; + while((nwritten = libssh2_channel_write(channel, ptr, nread)) == LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); prev = 0; } - if(rc < 0) { - fprintf(stderr, "ERROR %d total %ld / %d prev %d\n", rc, - total, (int)nread, (int)prev); + if(nwritten < 0) { + fprintf(stderr, "ERROR %d total %ld / %d prev %d\n", + (int)nwritten, (long)total, (int)nread, (int)prev); break; } else { prev = nread; - /* rc indicates how many bytes were written this time */ - nread -= rc; - ptr += rc; + /* nwritten indicates how many bytes were written this time */ + nread -= nwritten; + ptr += nwritten; } } while(nread); } while(!nread); /* only continue if nread was drained */ @@ -259,7 +260,7 @@ int main(int argc, char *argv[]) duration = (int)(time(NULL)-start); fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n", - total, duration, total/(double)duration); + (long)total, duration, (double)total / duration); fprintf(stderr, "Sending EOF\n"); while(libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN); diff --git a/example/sftp.c b/example/sftp.c index 8707a5021f..e902912da6 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -46,6 +46,10 @@ #pragma warning(disable:4127) #endif +#ifdef WIN32 +#define write(f, b, c) write((f), (b), (unsigned int)(c)) +#endif + const char *keyfile1 = "~/.ssh/id_rsa.pub"; const char *keyfile2 = "~/.ssh/id_rsa"; const char *username = "username"; @@ -90,7 +94,7 @@ static void kbd_callback(const char *name, int name_len, buf[n] = 0; responses[i].text = strdup(buf); - responses[i].length = n; + responses[i].length = (unsigned int)n; fprintf(stderr, "Response %d from user is '", i); fwrite(responses[i].text, 1, responses[i].length, stderr); @@ -104,7 +108,7 @@ static void kbd_callback(const char *name, int name_len, int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 0; struct sockaddr_in sin; @@ -195,7 +199,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); fprintf(stderr, "Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "password") != NULL) { auth_pw |= 1; @@ -277,12 +282,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n"); do { char mem[1024]; + ssize_t nread; /* loop until we fail */ fprintf(stderr, "libssh2_sftp_read()!\n"); - rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); - if(rc > 0) { - write(1, mem, rc); + nread = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); + if(nread > 0) { + write(1, mem, nread); } else { break; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 5b8fecec5b..5a6d8fba62 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -43,6 +43,10 @@ #pragma warning(disable:4127) #endif +#ifdef WIN32 +#define write(f, b, c) write((f), (b), (unsigned int)(c)) +#endif + #define STORAGE "/tmp/sftp-storage" /* this is the local file name this example uses to store the downloaded file in */ @@ -72,7 +76,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } @@ -237,21 +241,22 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n"); do { + ssize_t nread; do { /* read in a loop until we block */ - rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); + nread = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); fprintf(stderr, "libssh2_sftp_read returned %d\n", - rc); + (int)nread); - if(rc > 0) { + if(nread > 0) { /* write to stderr */ - write(2, mem, rc); + write(2, mem, nread); /* write to temporary storage area */ - fwrite(mem, rc, 1, tempstorage); + fwrite(mem, nread, 1, tempstorage); } - } while(rc > 0); + } while(nread > 0); - if(rc != LIBSSH2_ERROR_EAGAIN) { + if(nread != LIBSSH2_ERROR_EAGAIN) { /* error or end of file */ break; } @@ -265,7 +270,7 @@ int main(int argc, char *argv[]) FD_SET(sock, &fd2); /* wait for readable or writeable */ - rc = select(sock + 1, &fd, &fd2, NULL, &timeout); + rc = select((int)(sock + 1), &fd, &fd2, NULL, &timeout); if(rc <= 0) { /* negative is error 0 is timeout */ @@ -296,6 +301,7 @@ int main(int argc, char *argv[]) size_t nread; char *ptr; do { + ssize_t nwritten; nread = fread(mem, 1, sizeof(mem), tempstorage); if(nread <= 0) { /* end of file */ @@ -305,13 +311,13 @@ int main(int argc, char *argv[]) do { /* write data in a loop until we block */ - rc = libssh2_sftp_write(sftp_handle, ptr, - nread); - ptr += rc; - nread -= nread; - } while(rc >= 0); + nwritten = libssh2_sftp_write(sftp_handle, ptr, + nread); + ptr += nwritten; + nread -= nwritten; + } while(nwritten >= 0); - if(rc != LIBSSH2_ERROR_EAGAIN) { + if(nwritten != LIBSSH2_ERROR_EAGAIN) { /* error or end of file */ break; } @@ -325,7 +331,7 @@ int main(int argc, char *argv[]) FD_SET(sock, &fd2); /* wait for readable or writeable */ - rc = select(sock + 1, &fd, &fd2, NULL, &timeout); + rc = select((int)(sock + 1), &fd, &fd2, NULL, &timeout); if(rc <= 0) { /* negative is error 0 is timeout */ diff --git a/example/sftp_append.c b/example/sftp_append.c index 7ad7306838..783efb9cfb 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) LIBSSH2_SFTP_ATTRIBUTES attrs; char mem[1024*100]; size_t nread; + ssize_t nwritten; char *ptr; #ifdef WIN32 @@ -213,14 +214,14 @@ int main(int argc, char *argv[]) do { /* write data in a loop until we block */ - rc = libssh2_sftp_write(sftp_handle, ptr, nread); - if(rc < 0) + nwritten = libssh2_sftp_write(sftp_handle, ptr, nread); + if(nwritten < 0) break; - ptr += rc; - nread -= rc; + ptr += nwritten; + nread -= nwritten; } while(nread); - } while(rc > 0); + } while(nwritten > 0); libssh2_sftp_close(sftp_handle); libssh2_sftp_shutdown(sftp_session); diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index ab51a4f330..90084d3107 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index dfbf44c98a..45a36d36b2 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index e12c2a421d..f9f4da2874 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -49,6 +49,10 @@ #pragma warning(disable:4127) #endif +#ifdef WIN32 +#define write(f, b, c) write((f), (b), (unsigned int)(c)) +#endif + #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) @@ -83,14 +87,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -105,7 +109,7 @@ int main(int argc, char *argv[]) long time_ms; #endif int rc; - int total = 0; + libssh2_struct_stat_size total = 0; int spin = 0; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; @@ -258,16 +262,17 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n"); do { char mem[1024*24]; + ssize_t nread; /* loop until we fail */ - while((rc = libssh2_sftp_read(sftp_handle, mem, - sizeof(mem))) == LIBSSH2_ERROR_EAGAIN) { + while((nread = libssh2_sftp_read(sftp_handle, mem, + sizeof(mem))) == LIBSSH2_ERROR_EAGAIN) { spin++; waitsocket(sock, session); /* now we wait */ } - if(rc > 0) { - total += rc; - write(1, mem, rc); + if(nread > 0) { + total += nread; + write(1, mem, nread); } else { break; @@ -277,11 +282,10 @@ int main(int argc, char *argv[]) #ifdef HAVE_GETTIMEOFDAY gettimeofday(&end, NULL); time_ms = tvdiff(end, start); - fprintf(stderr, "Got %d bytes in %ld ms = %.1f bytes/sec spin: %d\n", - total, - time_ms, total/(time_ms/1000.0), spin); + fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", + (long)total, time_ms, (double)total/(time_ms/1000.0), spin); #else - fprintf(stderr, "Got %d bytes spin: %d\n", total, spin); + fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin); #endif libssh2_sftp_close(sftp_handle); diff --git a/example/sftp_write.c b/example/sftp_write.c index 758dc2549e..ce166b9ad7 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -57,6 +57,7 @@ int main(int argc, char *argv[]) LIBSSH2_SFTP_HANDLE *sftp_handle; char mem[1024*100]; size_t nread; + ssize_t nwritten; char *ptr; #ifdef WIN32 @@ -197,14 +198,14 @@ int main(int argc, char *argv[]) do { /* write data in a loop until we block */ - rc = libssh2_sftp_write(sftp_handle, ptr, nread); - if(rc < 0) + nwritten = libssh2_sftp_write(sftp_handle, ptr, nread); + if(nwritten < 0) break; - ptr += rc; - nread -= rc; + ptr += nwritten; + nread -= nwritten; } while(nread); - } while(rc > 0); + } while(nwritten > 0); libssh2_sftp_close(sftp_handle); libssh2_sftp_shutdown(sftp_session); diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 16400c670b..b72daf4ce6 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -71,14 +71,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -94,9 +94,10 @@ int main(int argc, char *argv[]) LIBSSH2_SFTP_HANDLE *sftp_handle; char mem[1024 * 100]; size_t nread; + ssize_t nwritten; char *ptr; time_t start; - long total = 0; + libssh2_struct_stat_size total = 0; int duration; #ifdef WIN32 @@ -254,23 +255,22 @@ int main(int argc, char *argv[]) do { /* write data in a loop until we block */ - while((rc = libssh2_sftp_write(sftp_handle, ptr, nread)) == + while((nwritten = libssh2_sftp_write(sftp_handle, ptr, nread)) == LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } - if(rc < 0) + if(nwritten < 0) break; - ptr += rc; - nread -= rc; + ptr += nwritten; + nread -= nwritten; } while(nread); - } while(rc > 0); + } while(nwritten > 0); duration = (int)(time(NULL)-start); fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n", - total, duration, total/(double)duration); - + (long)total, duration, (double)total / duration); fclose(local); libssh2_sftp_close(sftp_handle); diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 2e9b75b600..acd76cf487 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -71,14 +71,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; @@ -95,8 +95,9 @@ int main(int argc, char *argv[]) char mem[1024 * 1000]; size_t nread; size_t memuse; + ssize_t nwritten; time_t start; - long total = 0; + libssh2_struct_stat_size total = 0; int duration; #ifdef WIN32 @@ -258,29 +259,28 @@ int main(int argc, char *argv[]) total += nread; /* write data in a loop until we block */ - while((rc = libssh2_sftp_write(sftp_handle, mem, memuse)) == + while((nwritten = libssh2_sftp_write(sftp_handle, mem, memuse)) == LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } - if(rc < 0) + if(nwritten < 0) break; - if(memuse - rc) { + if(memuse - nwritten) { /* make room for more data at the end of the buffer */ - memmove(&mem[0], &mem[rc], memuse - rc); - memuse -= rc; + memmove(&mem[0], &mem[nwritten], memuse - nwritten); + memuse -= nwritten; } else /* 'mem' was consumed fully */ memuse = 0; - } while(rc > 0); + } while(nwritten > 0); duration = (int)(time(NULL)-start); fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n", - total, duration, total/(double)duration); - + (long)total, duration, (double)total / duration); fclose(local); libssh2_sftp_close(sftp_handle); diff --git a/example/sftpdir.c b/example/sftpdir.c index 2602413d56..7c5cfe1069 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -46,7 +46,7 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 +#if defined(_MSC_VER) #define __FILESIZE "I64u" #else #define __FILESIZE "llu" @@ -70,7 +70,7 @@ static void kbd_callback(const char *name, int name_len, (void)instruction_len; if(num_prompts == 1) { responses[0].text = strdup(password); - responses[0].length = strlen(password); + responses[0].length = (unsigned int)strlen(password); } (void)prompts; (void)abstract; @@ -78,7 +78,7 @@ static void kbd_callback(const char *name, int name_len, int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int rc, i, auth_pw = 0; struct sockaddr_in sin; @@ -166,7 +166,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); fprintf(stderr, "Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "password") != NULL) { auth_pw |= 1; diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 62de69db4d..746ecd64fc 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -46,7 +46,7 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 +#if defined(_MSC_VER) #define __FILESIZE "I64u" #else #define __FILESIZE "llu" @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 1; struct sockaddr_in sin; diff --git a/example/ssh2.c b/example/ssh2.c index 9475e98729..35785de7a4 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -70,7 +70,7 @@ static void kbd_callback(const char *name, int name_len, (void)instruction_len; if(num_prompts == 1) { responses[0].text = strdup(password); - responses[0].length = strlen(password); + responses[0].length = (unsigned int)strlen(password); } (void)prompts; (void)abstract; @@ -79,7 +79,7 @@ static void kbd_callback(const char *name, int name_len, int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int rc, i, auth_pw = 0; struct sockaddr_in sin; @@ -171,7 +171,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); fprintf(stderr, "Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "password") != NULL) { auth_pw |= 1; @@ -315,7 +316,7 @@ int main(int argc, char *argv[]) char buf[1024]; ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf)); if(err < 0) - fprintf(stderr, "Unable to read response: %zd\n", err); + fprintf(stderr, "Unable to read response: %d\n", (int)err); else { fwrite(buf, 1, err, stdout); } diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index a4cf5e15e6..ffa376c34c 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -46,7 +46,7 @@ const char *username = "username"; int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; int i, rc; struct sockaddr_in sin; @@ -126,7 +126,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); fprintf(stderr, "Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "publickey") == NULL) { fprintf(stderr, "\"publickey\" authentication is not supported\n"); diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 9735f3971c..96b2628884 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -76,7 +76,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) const char *hostname = "127.0.0.1"; const char *commandline = "uptime"; const char *username = NULL; - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; LIBSSH2_SESSION *session; @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) int rc; int exitcode; char *exitsignal = (char *)"none"; - int bytecount = 0; + ssize_t bytecount = 0; #ifdef WIN32 WSADATA wsadata; @@ -230,29 +230,31 @@ int main(int argc, char *argv[]) exit(1); } for(;;) { + ssize_t nread; /* loop until we block */ do { char buffer[0x4000]; - rc = libssh2_channel_read(channel, buffer, sizeof(buffer) ); - if(rc > 0) { - int i; - bytecount += rc; + nread = libssh2_channel_read(channel, buffer, sizeof(buffer) ); + if(nread > 0) { + ssize_t i; + bytecount += nread; fprintf(stderr, "We read:\n"); - for(i = 0; i < rc; ++i) + for(i = 0; i < nread; ++i) fputc(buffer[i], stderr); fprintf(stderr, "\n"); } else { - if(rc != LIBSSH2_ERROR_EAGAIN) + if(nread != LIBSSH2_ERROR_EAGAIN) /* no need to output this for the EAGAIN case */ - fprintf(stderr, "libssh2_channel_read returned %d\n", rc); + fprintf(stderr, "libssh2_channel_read returned %d\n", + (int)nread); } } - while(rc > 0); + while(nread > 0); /* this is due to blocking that would occur otherwise so we loop on this condition */ - if(rc == LIBSSH2_ERROR_EAGAIN) { + if(nread == LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } else @@ -272,7 +274,7 @@ int main(int argc, char *argv[]) printf("\nGot signal: %s\n", exitsignal); } else { - printf("\nEXIT: %d bytecount: %d\n", exitcode, bytecount); + printf("\nEXIT: %d bytecount: %d\n", exitcode, (int)bytecount); } libssh2_channel_free(channel); diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index 1ebd9e971c..ac202f2af0 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -72,7 +72,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) const char *commandline = "cat"; const char *username = "user"; const char *password = "password"; - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; const char *fingerprint; @@ -232,11 +232,11 @@ int main(int argc, char *argv[]) else { LIBSSH2_POLLFD *fds = NULL; int running = 1; - int bufsize = BUFSIZE; + ssize_t bufsize = BUFSIZE; char buffer[BUFSIZE]; - int totsize = 1500000; - int totwritten = 0; - int totread = 0; + ssize_t totsize = 1500000; + ssize_t totwritten = 0; + ssize_t totread = 0; int rereads = 0; int rewrites = 0; int i; @@ -262,7 +262,8 @@ int main(int argc, char *argv[]) continue; if(fds[0].revents & LIBSSH2_POLLFD_POLLIN) { - int n = libssh2_channel_read(channel, buffer, sizeof(buffer)); + ssize_t n = libssh2_channel_read(channel, + buffer, sizeof(buffer)); act++; if(n == LIBSSH2_ERROR_EAGAIN) { @@ -276,7 +277,7 @@ int main(int argc, char *argv[]) else { totread += n; fprintf(stderr, "read %d bytes (%d in total)\n", - n, totread); + (int)n, (int)totread); } } @@ -285,9 +286,10 @@ int main(int argc, char *argv[]) if(totwritten < totsize) { /* we have not written all data yet */ - int left = totsize - totwritten; - int size = (left < bufsize) ? left : bufsize; - int n = libssh2_channel_write_ex(channel, 0, buffer, size); + ssize_t left = totsize - totwritten; + ssize_t size = (left < bufsize) ? left : bufsize; + ssize_t n = libssh2_channel_write_ex(channel, 0, + buffer, size); if(n == LIBSSH2_ERROR_EAGAIN) { rewrites++; @@ -300,7 +302,7 @@ int main(int argc, char *argv[]) else { totwritten += n; fprintf(stderr, "wrote %d bytes (%d in total)", - n, totwritten); + (int)n, (int)totwritten); if(left >= bufsize && n != bufsize) { fprintf(stderr, " PARTIAL"); } @@ -349,11 +351,11 @@ int main(int argc, char *argv[]) channel = NULL; fprintf(stderr, "\nrereads: %d rewrites: %d totwritten %d\n", - rereads, rewrites, totwritten); + rereads, rewrites, (int)totwritten); if(totwritten != totread) { fprintf(stderr, "\n*** FAIL bytes written: %d bytes " - "read: %d ***\n", totwritten, totread); + "read: %d ***\n", (int)totwritten, (int)totread); exit(1); } } diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 2073e85ad7..c205f1a86f 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -74,7 +74,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) writefd = &fd; - rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout); + rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout); return rc; } @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) const char *commandline = "uptime"; const char *username = "user"; const char *password = "password"; - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; const char *fingerprint; @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) int rc; int exitcode; char *exitsignal = (char *)"none"; - int bytecount = 0; + ssize_t bytecount = 0; size_t len; LIBSSH2_KNOWNHOSTS *nh; int type; @@ -259,25 +259,27 @@ int main(int argc, char *argv[]) exit(1); } for(;;) { + ssize_t nread; /* loop until we block */ do { char buffer[0x4000]; - rc = libssh2_channel_read(channel, buffer, sizeof(buffer) ); - if(rc > 0) { - int i; - bytecount += rc; + nread = libssh2_channel_read(channel, buffer, sizeof(buffer)); + if(nread > 0) { + ssize_t i; + bytecount += nread; fprintf(stderr, "We read:\n"); - for(i = 0; i < rc; ++i) + for(i = 0; i < nread; ++i) fputc(buffer[i], stderr); fprintf(stderr, "\n"); } else { - if(rc != LIBSSH2_ERROR_EAGAIN) + if(nread != LIBSSH2_ERROR_EAGAIN) /* no need to output this for the EAGAIN case */ - fprintf(stderr, "libssh2_channel_read returned %d\n", rc); + fprintf(stderr, "libssh2_channel_read returned %d\n", + (int)nread); } } - while(rc > 0); + while(nread > 0); /* this is due to blocking that would occur otherwise so we loop on this condition */ @@ -300,7 +302,8 @@ int main(int argc, char *argv[]) if(exitsignal) fprintf(stderr, "\nGot signal: %s\n", exitsignal); else - fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount); + fprintf(stderr, "\nEXIT: %d bytecount: %d\n", + exitcode, (int)bytecount); libssh2_channel_free(channel); channel = NULL; diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index ccb35ebdfd..beffc8591a 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -56,13 +56,13 @@ enum { static int netconf_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t len) { - int i; + ssize_t i; ssize_t wr = 0; do { i = libssh2_channel_write(channel, buf, len); if(i < 0) { - fprintf(stderr, "libssh2_channel_write: %d\n", i); + fprintf(stderr, "libssh2_channel_write: %d\n", (int)i); return -1; } wr += i; @@ -71,8 +71,8 @@ static int netconf_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t len) return 0; } -static int netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag, - char *buf, size_t buflen) +static ssize_t netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag, + char *buf, size_t buflen) { ssize_t len; size_t rd = 0; @@ -202,7 +202,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); fprintf(stderr, "Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "password")) auth |= AUTH_PASSWORD; diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 6ed5a92ab8..55327ac7e4 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -11,6 +11,8 @@ #include #include #include +#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) +#define send(s, b, l, f) send((s), (b), (int)(l), (f)) #else #include #include @@ -157,7 +159,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); fprintf(stderr, "Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "password")) auth |= AUTH_PASSWORD; @@ -251,12 +254,13 @@ int main(int argc, char *argv[]) FD_SET(forwardsock, &fds); tv.tv_sec = 0; tv.tv_usec = 100000; - rc = select(forwardsock + 1, &fds, NULL, NULL, &tv); + rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv); if(-1 == rc) { perror("select"); goto shutdown; } if(rc && FD_ISSET(forwardsock, &fds)) { + ssize_t nwritten; len = recv(forwardsock, buf, sizeof(buf), 0); if(len < 0) { perror("read"); @@ -269,30 +273,33 @@ int main(int argc, char *argv[]) } wr = 0; do { - i = libssh2_channel_write(channel, buf, len); - if(i < 0) { - fprintf(stderr, "libssh2_channel_write: %d\n", i); + nwritten = libssh2_channel_write(channel, buf, len); + if(nwritten < 0) { + fprintf(stderr, "libssh2_channel_write: %d\n", + (int)nwritten); goto shutdown; } - wr += i; - } while(i > 0 && wr < len); + wr += nwritten; + } while(nwritten > 0 && wr < len); } for(;;) { + ssize_t nsent; len = libssh2_channel_read(channel, buf, sizeof(buf)); if(LIBSSH2_ERROR_EAGAIN == len) break; else if(len < 0) { - fprintf(stderr, "libssh2_channel_read: %d", (int)len); + fprintf(stderr, "libssh2_channel_read: %d", + (int)len); goto shutdown; } wr = 0; while(wr < len) { - i = send(forwardsock, buf + wr, len - wr, 0); - if(i <= 0) { + nsent = send(forwardsock, buf + wr, len - wr, 0); + if(nsent <= 0) { perror("write"); goto shutdown; } - wr += i; + wr += nsent; } if(libssh2_channel_eof(channel)) { fprintf(stderr, "The remote client at %s:%d disconnected!\n", diff --git a/example/x11.c b/example/x11.c index 5406b21e7c..0b8a3934dd 100644 --- a/example/x11.c +++ b/example/x11.c @@ -214,11 +214,12 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) rc = libssh2_poll(fds, nfds, 0); if(rc >0) { - rc = libssh2_channel_read(channel, buf, bufsize); - write(sock, buf, rc); + ssize_t nread; + nread = libssh2_channel_read(channel, buf, bufsize); + write(sock, buf, nread); } - rc = select(sock + 1, &set, NULL, NULL, &timeval_out); + rc = select((int)(sock + 1), &set, NULL, NULL, &timeval_out); if(rc > 0) { memset((void *)buf, 0, bufsize); @@ -247,7 +248,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) int main (int argc, char *argv[]) { - unsigned long hostaddr = 0; + uint32_t hostaddr = 0; int sock = 0; int rc = 0; struct sockaddr_in sin; @@ -448,7 +449,7 @@ main (int argc, char *argv[]) } - rc = select(fileno(stdin) + 1, &set, NULL, NULL, &timeval_out); + rc = select((int)(fileno(stdin) + 1), &set, NULL, NULL, &timeval_out); if(rc > 0) { /* Data in stdin*/ rc = read(fileno(stdin), buf, 1); diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 9c358eaea8..ccae69e553 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -41,8 +41,8 @@ #endif #endif -#include "openssh_fixture.h" #include "session_fixture.h" +#include "openssh_fixture.h" #include "libssh2_config.h" #ifdef HAVE_WINSOCK2_H @@ -66,6 +66,12 @@ #include #include +#if defined(WIN32) && (defined(_M_X64) || defined(__x86_64__)) +#define LIBSSH2_SOCKET_MASK "%lld" +#else +#define LIBSSH2_SOCKET_MASK "%d" +#endif + static int have_docker = 0; static int run_command_varg(char **output, const char *command, va_list args) @@ -113,7 +119,7 @@ static int run_command_varg(char **output, const char *command, va_list args) buf[0] = 0; buf_len = 0; while(buf_len < (sizeof(buf) - 1) && - fgets(&buf[buf_len], sizeof(buf) - buf_len, pipe) != NULL) { + fgets(&buf[buf_len], (int)(sizeof(buf) - buf_len), pipe) != NULL) { buf_len = strlen(buf); } @@ -327,30 +333,30 @@ static int port_from_container(char *container_id, char **port_out) } } -static int open_socket_to_container(char *container_id) +static libssh2_socket_t open_socket_to_container(char *container_id) { char *ip_address = NULL; char *port_string = NULL; - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; int counter = 0; - int ret; + libssh2_socket_t ret = LIBSSH2_INVALID_SOCKET; if(have_docker) { - ret = ip_address_from_container(container_id, &ip_address); - if(ret != 0) { + int res; + res = ip_address_from_container(container_id, &ip_address); + if(res != 0) { fprintf(stderr, "Failed to get IP address for container %s\n", container_id); - ret = -1; goto cleanup; } - ret = port_from_container(container_id, &port_string); - if(ret != 0) { + res = port_from_container(container_id, &port_string); + if(res != 0) { fprintf(stderr, "Failed to get port for container %s\n", container_id); - ret = -1; + goto cleanup; } } else { @@ -365,7 +371,6 @@ static int open_socket_to_container(char *container_id) env = "4711"; } port_string = strdup(env); - ret = 0; } /* 0.0.0.0 is returned by Docker for Windows, because the container @@ -377,16 +382,15 @@ static int open_socket_to_container(char *container_id) } hostaddr = inet_addr(ip_address); - if(hostaddr == (unsigned long)(-1)) { + if(hostaddr == (uint32_t)(-1)) { fprintf(stderr, "Failed to convert %s host address\n", ip_address); - ret = -1; goto cleanup; } sock = socket(AF_INET, SOCK_STREAM, 0); - if(sock <= 0) { - fprintf(stderr, "Failed to open socket (%d)\n", sock); - ret = -1; + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, + "Failed to open socket (" LIBSSH2_SOCKET_MASK ")\n", sock); goto cleanup; } @@ -397,7 +401,6 @@ static int open_socket_to_container(char *container_id) for(counter = 0; counter < 3; ++counter) { if(connect(sock, (struct sockaddr *)(&sin), sizeof(struct sockaddr_in)) != 0) { - ret = -1; fprintf(stderr, "Connection to %s:%s attempt #%d failed: retrying...\n", ip_address, port_string, counter); @@ -408,7 +411,7 @@ static int open_socket_to_container(char *container_id) break; } } - if(ret == -1) { + if(ret == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "Failed to connect to %s:%s\n", ip_address, port_string); goto cleanup; @@ -460,7 +463,7 @@ void stop_openssh_fixture(void) } } -int open_socket_to_openssh_server(void) +libssh2_socket_t open_socket_to_openssh_server(void) { return open_socket_to_container(running_container_id); } diff --git a/tests/openssh_fixture.h b/tests/openssh_fixture.h index f8e3632ceb..055ee4effd 100644 --- a/tests/openssh_fixture.h +++ b/tests/openssh_fixture.h @@ -40,6 +40,6 @@ int start_openssh_fixture(void); void stop_openssh_fixture(void); -int open_socket_to_openssh_server(void); +libssh2_socket_t open_socket_to_openssh_server(void); #endif diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 521e60bff0..1a25feb12f 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -65,13 +65,13 @@ #include LIBSSH2_SESSION *connected_session = NULL; -int connected_socket = -1; +libssh2_socket_t connected_socket = LIBSSH2_INVALID_SOCKET; static int connect_to_server(void) { int rc; connected_socket = open_socket_to_openssh_server(); - if(connected_socket <= 0) { + if(connected_socket == LIBSSH2_INVALID_SOCKET) { return -1; } @@ -91,7 +91,7 @@ static void setup_fixture_workdir(void) #else char wd_buf[MAXPATHLEN]; #endif - char *wd = getenv("FIXTURE_WORKDIR"); + const char *wd = getenv("FIXTURE_WORKDIR"); #ifdef FIXTURE_WORKDIR if(!wd) { wd = FIXTURE_WORKDIR; diff --git a/tests/ssh2.c b/tests/ssh2.c index 983cc05128..d9f1639e00 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { - unsigned long hostaddr; + uint32_t hostaddr; libssh2_socket_t sock; int i, auth_pw = 0; struct sockaddr_in sin; @@ -108,7 +108,8 @@ int main(int argc, char *argv[]) printf("\n"); /* check what authentication methods are available */ - userauthlist = libssh2_userauth_list(session, username, strlen(username)); + userauthlist = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); printf("Authentication methods: %s\n", userauthlist); if(strstr(userauthlist, "password") != NULL) { auth_pw |= 1; diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index 9d203dc9d5..990531dfc7 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) LIBSSH2_CHANNEL *channel; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index 80588b00c7..007b9bfbe6 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -33,13 +33,13 @@ int test(LIBSSH2_SESSION *session) if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) { rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len, - EXPECTED_ECDSA_HOSTKEY, - strlen(EXPECTED_ECDSA_HOSTKEY)); + EXPECTED_ECDSA_HOSTKEY, + (unsigned int)strlen(EXPECTED_ECDSA_HOSTKEY)); } else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) { rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len, - EXPECTED_RSA_HOSTKEY, - strlen(EXPECTED_RSA_HOSTKEY)); + EXPECTED_RSA_HOSTKEY, + (unsigned int)strlen(EXPECTED_RSA_HOSTKEY)); } else { fprintf(stderr, "Unexpected type of hostkey: %i\n", type); diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c index f41d0ce6ac..9927a96cb4 100644 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c @@ -26,7 +26,7 @@ static void kbd_callback(const char *name, int name_len, if(num_prompts == 1) { responses[0].text = strdup(WRONG_PASSWORD); - responses[0].length = strlen(WRONG_PASSWORD); + responses[0].length = (unsigned int)strlen(WRONG_PASSWORD); } } @@ -35,7 +35,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -49,7 +50,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_keyboard_interactive_ex( - session, USERNAME, strlen(USERNAME), kbd_callback); + session, USERNAME, (unsigned int)strlen(USERNAME), kbd_callback); if(rc == 0) { fprintf(stderr, "Keyboard-interactive auth succeeded with wrong response\n"); diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c index 224189ae7f..14746e96ca 100644 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c @@ -28,7 +28,7 @@ static void kbd_callback(const char *name, int name_len, if(num_prompts == 1) { responses[0].text = strdup(PASSWORD); - responses[0].length = strlen(PASSWORD); + responses[0].length = (unsigned int)strlen(PASSWORD); } } @@ -37,7 +37,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -51,7 +52,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_keyboard_interactive_ex( - session, USERNAME, strlen(USERNAME), kbd_callback); + session, USERNAME, (unsigned int)strlen(USERNAME), kbd_callback); if(rc != 0) { print_last_session_error("libssh2_userauth_keyboard_interactive_ex"); return 1; diff --git a/tests/test_password_auth_fails_with_wrong_password.c b/tests/test_password_auth_fails_with_wrong_password.c index d888c78ea0..ec57b3b9ce 100644 --- a/tests/test_password_auth_fails_with_wrong_password.c +++ b/tests/test_password_auth_fails_with_wrong_password.c @@ -13,7 +13,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -25,8 +26,10 @@ int test(LIBSSH2_SESSION *session) return 1; } - rc = libssh2_userauth_password_ex(session, USERNAME, strlen(USERNAME), - WRONG_PASSWORD, strlen(WRONG_PASSWORD), + rc = libssh2_userauth_password_ex(session, USERNAME, + (unsigned int)strlen(USERNAME), + WRONG_PASSWORD, + (unsigned int)strlen(WRONG_PASSWORD), NULL); if(rc == 0) { fprintf(stderr, "Password auth succeeded with wrong password\n"); diff --git a/tests/test_password_auth_fails_with_wrong_username.c b/tests/test_password_auth_fails_with_wrong_username.c index e0630aa2ec..6ada9682e9 100644 --- a/tests/test_password_auth_fails_with_wrong_username.c +++ b/tests/test_password_auth_fails_with_wrong_username.c @@ -14,7 +14,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, WRONG_USERNAME, strlen(WRONG_USERNAME)); + libssh2_userauth_list(session, WRONG_USERNAME, + (unsigned int)strlen(WRONG_USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -27,8 +28,9 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_password_ex(session, WRONG_USERNAME, - strlen(WRONG_USERNAME), PASSWORD, - strlen(PASSWORD), NULL); + (unsigned int)strlen(WRONG_USERNAME), + PASSWORD, + (unsigned int)strlen(PASSWORD), NULL); if(rc == 0) { fprintf(stderr, "Password auth succeeded with wrong username\n"); return 1; diff --git a/tests/test_password_auth_succeeds_with_correct_credentials.c b/tests/test_password_auth_succeeds_with_correct_credentials.c index 48e623734b..7b3fd7d8dd 100644 --- a/tests/test_password_auth_succeeds_with_correct_credentials.c +++ b/tests/test_password_auth_succeeds_with_correct_credentials.c @@ -14,7 +14,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -26,8 +27,10 @@ int test(LIBSSH2_SESSION *session) return 1; } - rc = libssh2_userauth_password_ex(session, USERNAME, strlen(USERNAME), - PASSWORD, strlen(PASSWORD), NULL); + rc = libssh2_userauth_password_ex(session, USERNAME, + (unsigned int)strlen(USERNAME), + PASSWORD, + (unsigned int)strlen(PASSWORD), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_password_ex"); return 1; diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c index 44b459f8fe..83cba13d64 100644 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ b/tests/test_public_key_auth_fails_with_wrong_key.c @@ -14,7 +14,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -27,7 +28,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc == 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c index 01ea06e49d..6d77b3b913 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c index 1a55686dc3..768f417c4f 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = NULL; - userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + userauth_list = libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c index ce15295e8a..31b9bf0ddb 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = NULL; - userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + userauth_list = libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index 0a13edba67..8f7865ff21 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -18,7 +18,8 @@ int test(LIBSSH2_SESSION *session) size_t len = 0; const char *userauth_list = NULL; - userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + userauth_list = libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c index 998fa57233..0095cf4719 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c @@ -16,7 +16,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = NULL; - userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + userauth_list = libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -29,7 +30,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), PASSWORD); if(rc != 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c index d114f95a1d..08acc2be6a 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c @@ -16,7 +16,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -29,7 +30,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), PASSWORD); if(rc != 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c index aa0a79de0c..96792259a7 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c index c6b4cabb7c..cac578a3cd 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c index 1fd7db0557..93d5a31068 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = NULL; - userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + userauth_list = libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c index ef64d2985b..4a9a6dddee 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -15,7 +15,8 @@ int test(LIBSSH2_SESSION *session) int rc; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -28,7 +29,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { diff --git a/tests/test_read.c b/tests/test_read.c index 14d05240bf..b7f9d6af53 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -35,7 +35,8 @@ int test(LIBSSH2_SESSION *session) LIBSSH2_CHANNEL *channel; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); + libssh2_userauth_list(session, USERNAME, + (unsigned int)strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -48,7 +49,7 @@ int test(LIBSSH2_SESSION *session) } rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, strlen(USERNAME), + session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); if(rc != 0) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); @@ -73,7 +74,7 @@ int test(LIBSSH2_SESSION *session) char buf[1024]; ssize_t err = libssh2_channel_read(channel, buf, sizeof(buf)); if(err < 0) - fprintf(stderr, "Unable to read response: %zd\n", err); + fprintf(stderr, "Unable to read response: %d\n", (int)err); else { int i; for(i = 0; i < err; ++i) { From b0cb0b1965cf17b32ba76ed707a58b4e895d3c60 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 20 Mar 2023 20:51:59 +0000 Subject: [PATCH 146/424] include: silence warnings with casts in public `libssh2_sftp.h` Avoid triggering warnings in macros coming from public libssh2 headers. Cherry-picked from: #846 Closes #862 --- include/libssh2_sftp.h | 44 +++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/include/libssh2_sftp.h b/include/libssh2_sftp.h index 476ea87046..d35ff27a3e 100644 --- a/include/libssh2_sftp.h +++ b/include/libssh2_sftp.h @@ -231,10 +231,11 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, unsigned long flags, long mode, int open_type); #define libssh2_sftp_open(sftp, filename, flags, mode) \ - libssh2_sftp_open_ex((sftp), (filename), strlen(filename), (flags), \ - (mode), LIBSSH2_SFTP_OPENFILE) + libssh2_sftp_open_ex((sftp), \ + (filename), (unsigned int)strlen(filename), \ + (flags), (mode), LIBSSH2_SFTP_OPENFILE) #define libssh2_sftp_opendir(sftp, path) \ - libssh2_sftp_open_ex((sftp), (path), strlen(path), 0, 0, \ + libssh2_sftp_open_ex((sftp), (path), (unsigned int)strlen(path), 0, 0, \ LIBSSH2_SFTP_OPENDIR) LIBSSH2_API ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, @@ -281,8 +282,9 @@ LIBSSH2_API int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, unsigned int dest_filename_len, long flags); #define libssh2_sftp_rename(sftp, sourcefile, destfile) \ - libssh2_sftp_rename_ex((sftp), (sourcefile), strlen(sourcefile), \ - (destfile), strlen(destfile), \ + libssh2_sftp_rename_ex((sftp), \ + (sourcefile), (unsigned int)strlen(sourcefile), \ + (destfile), (unsigned int)strlen(destfile), \ LIBSSH2_SFTP_RENAME_OVERWRITE | \ LIBSSH2_SFTP_RENAME_ATOMIC | \ LIBSSH2_SFTP_RENAME_NATIVE) @@ -305,13 +307,13 @@ LIBSSH2_API int libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, long mode); #define libssh2_sftp_mkdir(sftp, path, mode) \ - libssh2_sftp_mkdir_ex((sftp), (path), strlen(path), (mode)) + libssh2_sftp_mkdir_ex((sftp), (path), (unsigned int)strlen(path), (mode)) LIBSSH2_API int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len); #define libssh2_sftp_rmdir(sftp, path) \ - libssh2_sftp_rmdir_ex((sftp), (path), strlen(path)) + libssh2_sftp_rmdir_ex((sftp), (path), (unsigned int)strlen(path)) LIBSSH2_API int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path, @@ -319,14 +321,14 @@ LIBSSH2_API int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, int stat_type, LIBSSH2_SFTP_ATTRIBUTES *attrs); #define libssh2_sftp_stat(sftp, path, attrs) \ - libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_STAT, \ - (attrs)) + libssh2_sftp_stat_ex((sftp), (path), (unsigned int)strlen(path), \ + LIBSSH2_SFTP_STAT, (attrs)) #define libssh2_sftp_lstat(sftp, path, attrs) \ - libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_LSTAT, \ - (attrs)) + libssh2_sftp_stat_ex((sftp), (path), (unsigned int)strlen(path), \ + LIBSSH2_SFTP_LSTAT, (attrs)) #define libssh2_sftp_setstat(sftp, path, attrs) \ - libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_SETSTAT, \ - (attrs)) + libssh2_sftp_stat_ex((sftp), (path), (unsigned int)strlen(path), \ + LIBSSH2_SFTP_SETSTAT, (attrs)) LIBSSH2_API int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path, @@ -335,13 +337,19 @@ LIBSSH2_API int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, unsigned int target_len, int link_type); #define libssh2_sftp_symlink(sftp, orig, linkpath) \ - libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), \ - strlen(linkpath), LIBSSH2_SFTP_SYMLINK) + libssh2_sftp_symlink_ex((sftp), \ + (orig), (unsigned int)strlen(orig), \ + (linkpath), (unsigned int)strlen(linkpath), \ + LIBSSH2_SFTP_SYMLINK) #define libssh2_sftp_readlink(sftp, path, target, maxlen) \ - libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \ - LIBSSH2_SFTP_READLINK) + libssh2_sftp_symlink_ex((sftp), \ + (path), (unsigned int)strlen(path), \ + (target), (maxlen), \ + LIBSSH2_SFTP_READLINK) #define libssh2_sftp_realpath(sftp, path, target, maxlen) \ - libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \ + libssh2_sftp_symlink_ex((sftp), \ + (path), (unsigned int)strlen(path), \ + (target), (maxlen), \ LIBSSH2_SFTP_REALPATH) #ifdef __cplusplus From 4e2580628dd1f8dc51ac65ac747ebcf0e93fa3d1 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 22 Mar 2023 02:47:58 +0000 Subject: [PATCH 147/424] cmake: allow building static + shared libs in a single pass - `BUILD_SHARED_LIBS=ON` no longer disables building static lib. When set, we build the static lib with PIC enabled. For shared lib only, set `BUILD_STATIC_LIBS=OFF`. For static lib without PIC, leave this option disabled. - new setting: `BUILD_STATIC_LIBS`. `ON` by default. Force-enabled when building examples or tests (we build those in static mode always.) - fix to exclude Windows Resource from the static lib. - fix to not overwrite static lib with shared implib on Windows platforms using identical suffix for them (MSVS). By using `libssh2_imp<.ext>` implib filename. - add support for `STATIC_LIB_SUFFIX` setting to set an optional suffix (e.g. `_static`) for the static lib. (experimental, not documented). Overrides the above when set. - fix to set `dllexport` when building shared lib. - set `TrackFileAccess=false` for MSVS. For faster builds, shorter verbose logs. - tests: new test linking against shared libssh2: `test_warmup_shared` - tests: simplify 'runner' lib by merging 3 libs into a single one. - tests: drop hack from `test_keyboard_interactive_auth_info_request` build. We no longer need to compile `src/misc.c` because we always link libssh2 statically. - tests: limit `FIXTURE_WORKDIR=` to the `runner` target. TL;DR: Default behavior unchanged: static (no-PIC), no shared. Enabling shared unchanged, but now also builds a static (PIC) lib by default. Based-on: b60dca8b6450a9729670986d2899cca54ccdbb6d #547 by berney on github Fixes: #547 Fixes: #675 Closes: #863 --- CMakeLists.txt | 15 +++++- docs/INSTALL_CMAKE.md | 10 +++- example/CMakeLists.txt | 2 +- src/CMakeLists.txt | 114 ++++++++++++++++++++++++++++++----------- tests/CMakeLists.txt | 38 ++++++-------- 5 files changed, 123 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc66cf81c8..4afe735ee0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ project(libssh2 C) set(PROJECT_URL "https://www.libssh2.org/") set(PROJECT_DESCRIPTION "The SSH library") +option(BUILD_STATIC_LIBS "Build Static Libraries" ON) option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) # Parse version @@ -77,6 +78,10 @@ install( FILES docs/AUTHORS COPYING docs/HACKING README RELEASE-NOTES NEWS DESTINATION ${CMAKE_INSTALL_DOCDIR}) +if(MSVC) + set(CMAKE_VS_GLOBALS "TrackFileAccess=false") # faster builds +endif() + include(max_warnings) include(FeatureSummary) @@ -107,12 +112,20 @@ if(BUILD_TESTING) add_subdirectory(tests) endif() +if(NOT BUILD_STATIC_LIBS AND (NOT BUILD_SHARED_LIBS OR BUILD_EXAMPLES OR BUILD_TESTING)) + set(BUILD_STATIC_LIBS ON) +endif() + option(LINT "Check style while building" OFF) if(LINT) add_custom_target(lint ALL ./ci/checksrc.sh WORKING_DIRECTORY ${libssh2_SOURCE_DIR}) - add_dependencies(libssh2 lint) + if(BUILD_STATIC_LIBS) + add_dependencies(libssh2_static lint) + else() + add_dependencies(libssh2_shared lint) + endif() endif() add_subdirectory(docs) diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 7aa0708b5f..fe203068cc 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -47,11 +47,17 @@ The following options are available: Enables running the source code linter when building. Can be `ON` or `OFF`. + * `BUILD_STATIC_LIBS=ON` + + Determines whether to build a libssh2 static library. + Can be `ON` or `OFF`. * `BUILD_SHARED_LIBS=OFF` - Determines whether libssh2 is built as a static library or as a - shared library (.dll/.so). Can be `ON` or `OFF`. + Determines whether to build a libssh2 shared library (.dll/.so). + Can be `ON` or `OFF`. + + If enabled, the optional static lib is also built with PIC enabled. * `CRYPTO_BACKEND=` diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index adf27433b7..89d2e3bddc 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -68,7 +68,7 @@ foreach(example ${EXAMPLES}) list(APPEND EXAMPLE_TARGETS example-${example}) # to find generated header target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) - target_link_libraries(example-${example} libssh2 ${LIBRARIES}) + target_link_libraries(example-${example} libssh2_static ${LIBRARIES}) endforeach() add_target_to_copy_dependencies( TARGET copy_example_dependencies diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f131db3f79..7313047260 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -227,22 +227,52 @@ set(SOURCES userauth.h version.c) -if(WIN32 AND BUILD_SHARED_LIBS) - list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) -endif() - -add_library(libssh2 ${SOURCES}) # we want it to be called libssh2 on all platforms -set_target_properties(libssh2 PROPERTIES PREFIX "") -set_target_properties(libssh2 PROPERTIES IMPORT_PREFIX "") - -target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) -target_include_directories(libssh2 +add_library(libssh2_object OBJECT ${SOURCES}) +target_compile_definitions(libssh2_object PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) +target_include_directories(libssh2_object PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${PRIVATE_INCLUDE_DIRECTORIES} PUBLIC $ $/${CMAKE_INSTALL_INCLUDEDIR}>) +if(BUILD_STATIC_LIBS) + list(APPEND libssh2_export libssh2_static) + add_library(libssh2_static STATIC $) + set_target_properties(libssh2_static PROPERTIES PREFIX "" OUTPUT_NAME "libssh2${STATIC_LIB_SUFFIX}") + + target_include_directories(libssh2_static + PRIVATE "${PROJECT_SOURCE_DIR}/include/" + PUBLIC + $ + $/${CMAKE_INSTALL_INCLUDEDIR}>) +endif() +if(BUILD_SHARED_LIBS) + list(APPEND libssh2_export libssh2_shared) + add_library(libssh2_shared SHARED $) + if(WIN32) + add_library(libssh2_winres OBJECT ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) + set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES $) + endif() + set_target_properties(libssh2_shared PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") + if(WIN32 AND BUILD_STATIC_LIBS AND NOT STATIC_LIB_SUFFIX AND + CMAKE_IMPORT_LIBRARY_SUFFIX STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX) + # Extra suffix to avoid filename conflict with the static lib. + set_target_properties(libssh2_shared PROPERTIES IMPORT_SUFFIX "_imp${CMAKE_IMPORT_LIBRARY_SUFFIX}") + endif() + + set_target_properties(libssh2_object PROPERTIES POSITION_INDEPENDENT_CODE ON) + if(WIN32) + target_compile_definitions(libssh2_object PRIVATE libssh2_EXPORTS) + endif() + + target_include_directories(libssh2_shared + PRIVATE "${PROJECT_SOURCE_DIR}/include/" + PUBLIC + $ + $/${CMAKE_INSTALL_INCLUDEDIR}>) +endif() + ## Options option(CLEAR_MEMORY "Enable clearing of memory before being freed" ON) @@ -250,8 +280,11 @@ if(NOT CLEAR_MEMORY) add_definitions(-DLIBSSH2_NO_CLEAR_MEMORY) endif() +add_feature_info("Static library" BUILD_STATIC_LIBS + "creating libssh2 static library") + add_feature_info("Shared library" BUILD_SHARED_LIBS - "creating libssh2 as a shared library (.so/.dll)") + "creating libssh2 shared library (.so/.dll)") option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression") add_feature_info(Compression ENABLE_ZLIB_COMPRESSION @@ -259,24 +292,24 @@ add_feature_info(Compression ENABLE_ZLIB_COMPRESSION if(ENABLE_ZLIB_COMPRESSION) find_package(ZLIB REQUIRED) - target_include_directories(libssh2 PRIVATE ${ZLIB_INCLUDE_DIRS}) + target_include_directories(libssh2_object PRIVATE ${ZLIB_INCLUDE_DIRS}) list(APPEND LIBRARIES ${ZLIB_LIBRARIES}) list(APPEND PC_REQUIRES_PRIVATE zlib) if(ZLIB_FOUND) - target_compile_definitions(libssh2 PRIVATE LIBSSH2_HAVE_ZLIB=1) + target_compile_definitions(libssh2_object PRIVATE LIBSSH2_HAVE_ZLIB=1) endif() endif() option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED") add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "") if(ENABLE_CRYPT_NONE) - target_compile_definitions(libssh2 PRIVATE LIBSSH2_CRYPT_NONE=1) + target_compile_definitions(libssh2_object PRIVATE LIBSSH2_CRYPT_NONE=1) endif() option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED") add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "") if(ENABLE_MAC_NONE) - target_compile_definitions(libssh2 PRIVATE LIBSSH2_MAC_NONE=1) + target_compile_definitions(libssh2_object PRIVATE LIBSSH2_MAC_NONE=1) endif() option(ENABLE_GEX_NEW @@ -284,7 +317,7 @@ option(ENABLE_GEX_NEW add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW "\"new\" diffie-hellman-group-exchange-sha1 method") if(ENABLE_GEX_NEW) - target_compile_definitions(libssh2 PRIVATE LIBSSH2_DH_GEX_NEW=1) + target_compile_definitions(libssh2_object PRIVATE LIBSSH2_DH_GEX_NEW=1) endif() # Enable debugging logging by default if the user configured a debug build @@ -298,7 +331,7 @@ option(ENABLE_DEBUG_LOGGING "log execution with debug trace" add_feature_info(Logging ENABLE_DEBUG_LOGGING "Logging of execution with debug trace") if(ENABLE_DEBUG_LOGGING) - target_compile_definitions(libssh2 PRIVATE LIBSSH2DEBUG) + target_compile_definitions(libssh2_object PRIVATE LIBSSH2DEBUG) endif() ## Platform checks @@ -383,14 +416,19 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) # to find generated header -target_include_directories(libssh2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(libssh2_object PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) if(MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od") set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG") endif() -target_link_libraries(libssh2 PRIVATE ${LIBRARIES}) +if(BUILD_STATIC_LIBS) + target_link_libraries(libssh2_static PRIVATE ${LIBRARIES}) +endif() +if(BUILD_SHARED_LIBS) + target_link_libraries(libssh2_shared PRIVATE ${LIBRARIES}) +endif() ## Installation @@ -400,14 +438,21 @@ install(FILES ${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(TARGETS libssh2 - EXPORT Libssh2Config - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - +if(BUILD_STATIC_LIBS) + install(TARGETS libssh2_static + EXPORT Libssh2Config + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() if(BUILD_SHARED_LIBS) - list(APPEND _RUNTIME_DEPENDENCIES $) + install(TARGETS libssh2_shared + EXPORT Libssh2Config + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + list(APPEND _RUNTIME_DEPENDENCIES $) endif() set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL @@ -422,7 +467,7 @@ install(EXPORT Libssh2Config ## During build, register directly from build tree # create Libssh2Config.cmake -export(TARGETS libssh2 NAMESPACE Libssh2:: FILE Libssh2Config.cmake) +export(TARGETS ${libssh2_export} NAMESPACE Libssh2:: FILE Libssh2Config.cmake) export(PACKAGE Libssh2) # register it ## Export a .pc file for client projects not using CMaek @@ -439,9 +484,18 @@ install( ## Versioning -set_target_properties(libssh2 PROPERTIES - SOVERSION 1 - VERSION 1.0.1) +set(LIBSSH2_SOVERSION 1) +set(LIBSSH2_VERSION 1.0.1) +if(BUILD_STATIC_LIBS) + set_target_properties(libssh2_static PROPERTIES + SOVERSION ${LIBSSH2_SOVERSION} + VERSION ${LIBSSH2_VERSION}) +endif() +if(BUILD_SHARED_LIBS) + set_target_properties(libssh2_shared PROPERTIES + SOVERSION ${LIBSSH2_SOVERSION} + VERSION ${LIBSSH2_VERSION}) +endif() include(CMakePackageConfigHelpers) write_basic_package_version_file( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 485b6fa875..d17c8c61c0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -169,24 +169,23 @@ if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") ) endif() -add_library(openssh_fixture STATIC openssh_fixture.h openssh_fixture.c) -target_link_libraries(openssh_fixture ${LIBRARIES}) -target_include_directories(openssh_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" ../include) - -add_library(session_fixture STATIC session_fixture.h session_fixture.c) -target_link_libraries(session_fixture ${LIBRARIES} openssh_fixture libssh2) -target_include_directories(session_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") - -add_library(runner STATIC runner.h runner.c) -target_link_libraries(runner session_fixture) -target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") +add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) +target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" ../include) +target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") + +# test building against shared libssh2 lib +if(BUILD_SHARED_LIBS) + set(test warmup) # any test will do + add_executable(test_${test}_shared test_${test}.c) + target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + target_link_libraries(test_${test}_shared runner libssh2_shared ${LIBRARIES}) +endif() foreach(test ${TESTS}) add_executable(test_${test} test_${test}.c) - target_link_libraries(test_${test} libssh2 runner ${LIBRARIES}) - target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") list(APPEND TEST_TARGETS test_${test}) - add_definitions(-DFIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") + target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + target_link_libraries(test_${test} runner libssh2_static ${LIBRARIES}) add_test( NAME test_${test} COMMAND $ @@ -229,12 +228,7 @@ foreach(test ${TESTS}) set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") endforeach() -if(WIN32 AND BUILD_SHARED_LIBS) - # Workaround for platforms not exporting internal functions from libssh2 shared lib - add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c ../src/misc.c) -else() - add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) -endif() +add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) target_compile_definitions(test_keyboard_interactive_auth_info_request PRIVATE "${CRYPTO_BACKEND_DEFINE}") target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" "../src/" "${CRYPTO_BACKEND_INCLUDE_DIR}") find_program(GCOV_PATH gcov) @@ -245,9 +239,9 @@ endif() if(CMAKE_COMPILER_IS_GNUCC AND GCOV_PATH) target_compile_options(test_keyboard_interactive_auth_info_request BEFORE PRIVATE ${TGT_OPTIONS}) - target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2 gcov) + target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2_static gcov) else() - target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2) + target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2_static) endif() add_test( NAME test_keyboard_interactive_auth_info_request COMMAND $ From 61a7d45d24c7aef90bec8eb7799bfa5d7cc49c16 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 22 Mar 2023 11:23:57 +0100 Subject: [PATCH 148/424] ci: use static+shared builds to cut number of cmake jobs (#865) With CMake builds supporting static-shared libssh2 builds in a single pass, we no longer need to run static and shared jobs separately. For the same effect it's enough to run builds with both shared and static builds enabled. Halving CI jobs. We add an extra run to test the CMake config-path without shared builds enabled. This allows to add useful jobs, e.g. MSVS 2022 or ZLIB-enabled builds for Windows, valgrind builds or other useful stuff, without stretching CI run times further. Ref: #863 --- .github/workflows/ci.yml | 6 +----- appveyor.yml | 23 ++++------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6943f1ff7b..2e9ed20050 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,27 +26,23 @@ jobs: compiler: [gcc, clang] address_size: [64] crypto_backend: [OpenSSL, Libgcrypt, mbedTLS] - build_shared_libs: [OFF, ON] enable_zlib_compression: [OFF, ON] b: [cmake] include: - compiler: gcc address_size: 64 crypto_backend: OpenSSL - build_shared_libs: OFF enable_zlib_compression: OFF b: configure - compiler: clang address_size: 64 crypto_backend: OpenSSL - build_shared_libs: OFF enable_zlib_compression: OFF b: configure env: CC: ${{ matrix.compiler }} CC_FOR_BUILD: ${{ matrix.compiler }} CRYPTO_BACKEND: ${{ matrix.crypto_backend }} - BUILD_SHARED_LIBS: ${{ matrix.build_shared_libs }} ENABLE_ZLIB_COMPRESSION: ${{ matrix.enable_zlib_compression }} steps: - uses: actions/checkout@v3 @@ -89,7 +85,7 @@ jobs: run: | mkdir bin cd bin - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. + cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. cmake --build . export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) ctest -VV --output-on-failure diff --git a/appveyor.yml b/appveyor.yml index 14005e8b19..8812144a00 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,22 +28,22 @@ os: Visual Studio 2015 environment: matrix: - - job_name: "VS2015, OpenSSL, Shared" + - job_name: "VS2015, OpenSSL" GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, Shared" + - job_name: "VS2013, OpenSSL" GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2015, WinCNG, Shared" + - job_name: "VS2015, WinCNG" GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - - job_name: "VS2013, WinCNG, Shared" + - job_name: "VS2013, WinCNG" GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" @@ -53,21 +53,6 @@ environment: BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, Static" - GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: "OFF" - CRYPTO_BACKEND: "OpenSSL" - - - job_name: "VS2015, WinCNG, Static" - GENERATOR: "Visual Studio 14 2015" - BUILD_SHARED_LIBS: "OFF" - CRYPTO_BACKEND: "WinCNG" - - - job_name: "VS2013, WinCNG, Static" - GENERATOR: "Visual Studio 12 2013" - BUILD_SHARED_LIBS: "OFF" - CRYPTO_BACKEND: "WinCNG" - platform: - x64 - x86 From 3b547417ef63d6416afe33158fb4b31ebef2b312 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 22 Mar 2023 11:25:03 +0100 Subject: [PATCH 149/424] cmake/src: move build options before target definitions (#864) To allow more flexibility when defining targets. --- src/CMakeLists.txt | 191 ++++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 98 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7313047260..c35237c889 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -183,101 +183,11 @@ if(NOT CRYPTO_BACKEND) message(FATAL_ERROR "No suitable cryptography backend found.") endif() -## Library definition - -include(GNUInstallDirs) -set(SOURCES - ${CRYPTO_SOURCES} - agent.c - agent_win.c - blf.h - bcrypt_pbkdf.c - blowfish.c - channel.c - channel.h - comp.c - comp.h - crypt.c - crypto.h - global.c - hostkey.c - keepalive.c - kex.c - knownhost.c - libssh2_priv.h - mac.c - mac.h - misc.c - misc.h - os400qc3.c - packet.c - packet.h - pem.c - publickey.c - scp.c - session.c - session.h - sftp.c - sftp.h - transport.c - transport.h - userauth_kbd_packet.c - userauth_kbd_packet.h - userauth.c - userauth.h - version.c) - -# we want it to be called libssh2 on all platforms -add_library(libssh2_object OBJECT ${SOURCES}) -target_compile_definitions(libssh2_object PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) -target_include_directories(libssh2_object - PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${PRIVATE_INCLUDE_DIRECTORIES} - PUBLIC - $ - $/${CMAKE_INSTALL_INCLUDEDIR}>) - -if(BUILD_STATIC_LIBS) - list(APPEND libssh2_export libssh2_static) - add_library(libssh2_static STATIC $) - set_target_properties(libssh2_static PROPERTIES PREFIX "" OUTPUT_NAME "libssh2${STATIC_LIB_SUFFIX}") - - target_include_directories(libssh2_static - PRIVATE "${PROJECT_SOURCE_DIR}/include/" - PUBLIC - $ - $/${CMAKE_INSTALL_INCLUDEDIR}>) -endif() -if(BUILD_SHARED_LIBS) - list(APPEND libssh2_export libssh2_shared) - add_library(libssh2_shared SHARED $) - if(WIN32) - add_library(libssh2_winres OBJECT ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) - set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES $) - endif() - set_target_properties(libssh2_shared PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") - if(WIN32 AND BUILD_STATIC_LIBS AND NOT STATIC_LIB_SUFFIX AND - CMAKE_IMPORT_LIBRARY_SUFFIX STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX) - # Extra suffix to avoid filename conflict with the static lib. - set_target_properties(libssh2_shared PROPERTIES IMPORT_SUFFIX "_imp${CMAKE_IMPORT_LIBRARY_SUFFIX}") - endif() - - set_target_properties(libssh2_object PROPERTIES POSITION_INDEPENDENT_CODE ON) - if(WIN32) - target_compile_definitions(libssh2_object PRIVATE libssh2_EXPORTS) - endif() - - target_include_directories(libssh2_shared - PRIVATE "${PROJECT_SOURCE_DIR}/include/" - PUBLIC - $ - $/${CMAKE_INSTALL_INCLUDEDIR}>) -endif() - ## Options option(CLEAR_MEMORY "Enable clearing of memory before being freed" ON) if(NOT CLEAR_MEMORY) - add_definitions(-DLIBSSH2_NO_CLEAR_MEMORY) + list(APPEND libssh2_DEFINITIONS LIBSSH2_NO_CLEAR_MEMORY) endif() add_feature_info("Static library" BUILD_STATIC_LIBS @@ -292,24 +202,24 @@ add_feature_info(Compression ENABLE_ZLIB_COMPRESSION if(ENABLE_ZLIB_COMPRESSION) find_package(ZLIB REQUIRED) - target_include_directories(libssh2_object PRIVATE ${ZLIB_INCLUDE_DIRS}) + list(APPEND libssh2_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS}) list(APPEND LIBRARIES ${ZLIB_LIBRARIES}) list(APPEND PC_REQUIRES_PRIVATE zlib) if(ZLIB_FOUND) - target_compile_definitions(libssh2_object PRIVATE LIBSSH2_HAVE_ZLIB=1) + list(APPEND libssh2_DEFINITIONS LIBSSH2_HAVE_ZLIB=1) endif() endif() option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED") add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "") if(ENABLE_CRYPT_NONE) - target_compile_definitions(libssh2_object PRIVATE LIBSSH2_CRYPT_NONE=1) + list(APPEND libssh2_DEFINITIONS LIBSSH2_CRYPT_NONE=1) endif() option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED") add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "") if(ENABLE_MAC_NONE) - target_compile_definitions(libssh2_object PRIVATE LIBSSH2_MAC_NONE=1) + list(APPEND libssh2_DEFINITIONS LIBSSH2_MAC_NONE=1) endif() option(ENABLE_GEX_NEW @@ -317,7 +227,7 @@ option(ENABLE_GEX_NEW add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW "\"new\" diffie-hellman-group-exchange-sha1 method") if(ENABLE_GEX_NEW) - target_compile_definitions(libssh2_object PRIVATE LIBSSH2_DH_GEX_NEW=1) + list(APPEND libssh2_DEFINITIONS LIBSSH2_DH_GEX_NEW=1) endif() # Enable debugging logging by default if the user configured a debug build @@ -331,7 +241,7 @@ option(ENABLE_DEBUG_LOGGING "log execution with debug trace" add_feature_info(Logging ENABLE_DEBUG_LOGGING "Logging of execution with debug trace") if(ENABLE_DEBUG_LOGGING) - target_compile_definitions(libssh2_object PRIVATE LIBSSH2DEBUG) + list(APPEND libssh2_DEFINITIONS LIBSSH2DEBUG) endif() ## Platform checks @@ -416,18 +326,103 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) # to find generated header -target_include_directories(libssh2_object PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +list(APPEND libssh2_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) if(MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od") set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG") endif() +## Library definition + +include(GNUInstallDirs) +set(SOURCES + ${CRYPTO_SOURCES} + agent.c + agent_win.c + blf.h + bcrypt_pbkdf.c + blowfish.c + channel.c + channel.h + comp.c + comp.h + crypt.c + crypto.h + global.c + hostkey.c + keepalive.c + kex.c + knownhost.c + libssh2_priv.h + mac.c + mac.h + misc.c + misc.h + os400qc3.c + packet.c + packet.h + pem.c + publickey.c + scp.c + session.c + session.h + sftp.c + sftp.h + transport.c + transport.h + userauth_kbd_packet.c + userauth_kbd_packet.h + userauth.c + userauth.h + version.c) + +# we want it to be called libssh2 on all platforms +add_library(libssh2_object OBJECT ${SOURCES}) +target_compile_definitions(libssh2_object PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) +target_include_directories(libssh2_object + PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} + PUBLIC + $ + $/${CMAKE_INSTALL_INCLUDEDIR}>) + if(BUILD_STATIC_LIBS) + list(APPEND libssh2_export libssh2_static) + add_library(libssh2_static STATIC $) target_link_libraries(libssh2_static PRIVATE ${LIBRARIES}) + set_target_properties(libssh2_static PROPERTIES PREFIX "" OUTPUT_NAME "libssh2${STATIC_LIB_SUFFIX}") + + target_include_directories(libssh2_static + PRIVATE "${PROJECT_SOURCE_DIR}/include/" + PUBLIC + $ + $/${CMAKE_INSTALL_INCLUDEDIR}>) endif() if(BUILD_SHARED_LIBS) + list(APPEND libssh2_export libssh2_shared) + add_library(libssh2_shared SHARED $) + if(WIN32) + add_library(libssh2_winres OBJECT ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) + set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES $) + endif() target_link_libraries(libssh2_shared PRIVATE ${LIBRARIES}) + set_target_properties(libssh2_shared PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") + if(WIN32 AND BUILD_STATIC_LIBS AND NOT STATIC_LIB_SUFFIX AND + CMAKE_IMPORT_LIBRARY_SUFFIX STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX) + # Extra suffix to avoid filename conflict with the static lib. + set_target_properties(libssh2_shared PROPERTIES IMPORT_SUFFIX "_imp${CMAKE_IMPORT_LIBRARY_SUFFIX}") + endif() + + set_target_properties(libssh2_object PROPERTIES POSITION_INDEPENDENT_CODE ON) + if(WIN32) + target_compile_definitions(libssh2_object PRIVATE libssh2_EXPORTS) + endif() + + target_include_directories(libssh2_shared + PRIVATE "${PROJECT_SOURCE_DIR}/include/" + PUBLIC + $ + $/${CMAKE_INSTALL_INCLUDEDIR}>) endif() ## Installation From 7a039d9a7a2945c10b4622f38eeed21ba6b4ec55 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 22 Mar 2023 13:52:52 +0100 Subject: [PATCH 150/424] ci: parallelize more (#867) --- .github/workflows/ci.yml | 6 +++--- appveyor.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e9ed20050..5fbf6460d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,7 @@ jobs: run: | autoreconf -fi ./configure --enable-debug --enable-werror - make + make -j3 make check - name: Build with CMake timeout-minutes: 10 @@ -86,7 +86,7 @@ jobs: mkdir bin cd bin cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. - cmake --build . + cmake --build . --parallel 2 export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) ctest -VV --output-on-failure cmake --build . --target package @@ -117,5 +117,5 @@ jobs: run: | autoreconf -fi ./configure --enable-debug --enable-static --disable-shared --with-crypto=openssl - make + make -j3 make check diff --git a/appveyor.yml b/appveyor.yml index 8812144a00..fa0d54ea5a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -74,7 +74,7 @@ install: build_script: - ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" } - cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% -H. -B_builds - - cmake --build _builds --config "%CONFIGURATION%" + - cmake --build _builds --config "%CONFIGURATION%" --parallel 2 before_test: - appveyor-retry choco install -y --no-progress --limit-output --timeout 180 docker-cli From 9cc2e5945f0fca60f35a059e7001ad97a093c6d7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 22 Mar 2023 16:55:32 +0100 Subject: [PATCH 151/424] cmake: fix error with static lib off and example/tests on (#869) Regression from 4e2580628dd1f8dc51ac65ac747ebcf0e93fa3d1 --- CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4afe735ee0..0274b7c8c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,23 +99,24 @@ else() endif() endif() +option(BUILD_EXAMPLES "Build libssh2 examples" ON) +option(BUILD_TESTING "Build libssh2 test suite" ON) + +if(NOT BUILD_STATIC_LIBS AND (NOT BUILD_SHARED_LIBS OR BUILD_EXAMPLES OR BUILD_TESTING)) + set(BUILD_STATIC_LIBS ON) +endif() + add_subdirectory(src) -option(BUILD_EXAMPLES "Build libssh2 examples" ON) if(BUILD_EXAMPLES) add_subdirectory(example) endif() -option(BUILD_TESTING "Build libssh2 test suite" ON) if(BUILD_TESTING) enable_testing() add_subdirectory(tests) endif() -if(NOT BUILD_STATIC_LIBS AND (NOT BUILD_SHARED_LIBS OR BUILD_EXAMPLES OR BUILD_TESTING)) - set(BUILD_STATIC_LIBS ON) -endif() - option(LINT "Check style while building" OFF) if(LINT) add_custom_target(lint ALL From 1d32ad1ced69a87395dc0bd75460d5dc7b7ba953 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 22 Mar 2023 19:43:26 +0100 Subject: [PATCH 152/424] ci: speed up static-only build tests on AppVeyor (#868) - limit static-only build to a single platform (x64). - skip running ctest for the static-only build. - use MSVS 2013 for static-only builds. It's faster. - run static-only test before WinCNG ones. Otherwise it's often skipped due to WinCNG failures (#804). --- appveyor.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index fa0d54ea5a..96acde652f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,6 +38,13 @@ environment: BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" + - job_name: "VS2013, OpenSSL, Static" + GENERATOR: "Visual Studio 12 2013" + BUILD_SHARED_LIBS: "OFF" + CRYPTO_BACKEND: "OpenSSL" + SKIP_CTEST: "yes" + SKIP_X86: "yes" + - job_name: "VS2015, WinCNG" GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: "ON" @@ -48,11 +55,6 @@ environment: BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - - job_name: "VS2015, OpenSSL, Static" - GENERATOR: "Visual Studio 14 2015" - BUILD_SHARED_LIBS: "OFF" - CRYPTO_BACKEND: "OpenSSL" - platform: - x64 - x86 @@ -63,6 +65,10 @@ configuration: matrix: fast_finish: true + # Enough to test the build itself on a single platform + exclude: + - platform: x86 + SKIP_X86: "yes" install: # prepare local SSH server for reverse tunneling from GitHub Actions hosting our docker container @@ -94,8 +100,11 @@ before_test: } test_script: - - ps: $env:OPENSSH_SERVER_IMAGE=[string] (& bash -c "echo ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)") - - ps: cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure --timeout 900 + - ps: | + if($env:SKIP_CTEST -ne "yes") { + $env:OPENSSH_SERVER_IMAGE=[string] (& bash -c "echo ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)") + cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure --timeout 900 + } on_failure: - ps: if(Test-Path _builds/CMakeFiles/CMakeOutput.log) { cat _builds/CMakeFiles/CMakeOutput.log } From 0834b9bcc85b90c78afff103f909b5a909b95e45 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 22 Mar 2023 23:09:53 +0100 Subject: [PATCH 153/424] ci: test with OpenSSL v1.1.1 on AppVeyor (#870) Was: v1.0.2. Keep using v1.0.2 with the static-only test. To make sure we don't break support. --- appveyor.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 96acde652f..87596ab709 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -78,8 +78,16 @@ install: - ps: .\ci\appveyor\docker-bridge.ps1 build_script: - - ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" } - - cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% -H. -B_builds + - ps: | + if($env:PLATFORM -eq "x64") { $env:GENERATOR = "$env:GENERATOR Win64" } + if($env:SKIP_CTEST -ne "yes") { + if($env:PLATFORM -eq "x64") { + $env:CMAKE_ARG = "-DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64" + } elseif($env:PLATFORM -eq "x86") { + $env:CMAKE_ARG = "-DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win32" + } + } + - cmake . -B _builds "-G%GENERATOR%" %CMAKE_ARG% -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% - cmake --build _builds --config "%CONFIGURATION%" --parallel 2 before_test: From 52c8a9ba046549efcaccd99e904b47b9688248f9 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 23 Mar 2023 19:43:32 +0100 Subject: [PATCH 154/424] cmake: separate compilation passes for shared/static (#871) Before this patch, cmake did a single compilation pass when we enabled both shared and static lib targets. This saves build time (esp. with MinGW targets and cross-compiling), but has the disadvantage that static libs built this way must have PIC enabled (offering slightly less performance) and `dllexport` enabled also, which means that executables linking the static libssh2 lib export its public symbols. To avoid these downsides, this patch separates the two passes and creates a non-PIC, non-`dllexport` static lib, even when also building the shared lib. --- src/CMakeLists.txt | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c35237c889..77a1b60e9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -378,33 +378,27 @@ set(SOURCES version.c) # we want it to be called libssh2 on all platforms -add_library(libssh2_object OBJECT ${SOURCES}) -target_compile_definitions(libssh2_object PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) -target_include_directories(libssh2_object - PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} - PUBLIC - $ - $/${CMAKE_INSTALL_INCLUDEDIR}>) - if(BUILD_STATIC_LIBS) list(APPEND libssh2_export libssh2_static) - add_library(libssh2_static STATIC $) + add_library(libssh2_static STATIC ${SOURCES}) + target_compile_definitions(libssh2_static PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) target_link_libraries(libssh2_static PRIVATE ${LIBRARIES}) set_target_properties(libssh2_static PROPERTIES PREFIX "" OUTPUT_NAME "libssh2${STATIC_LIB_SUFFIX}") target_include_directories(libssh2_static - PRIVATE "${PROJECT_SOURCE_DIR}/include/" + PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} PUBLIC $ $/${CMAKE_INSTALL_INCLUDEDIR}>) endif() if(BUILD_SHARED_LIBS) list(APPEND libssh2_export libssh2_shared) - add_library(libssh2_shared SHARED $) + add_library(libssh2_shared SHARED ${SOURCES}) if(WIN32) - add_library(libssh2_winres OBJECT ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) - set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES $) + set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) + target_compile_definitions(libssh2_shared PRIVATE libssh2_EXPORTS) endif() + target_compile_definitions(libssh2_shared PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) target_link_libraries(libssh2_shared PRIVATE ${LIBRARIES}) set_target_properties(libssh2_shared PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") if(WIN32 AND BUILD_STATIC_LIBS AND NOT STATIC_LIB_SUFFIX AND @@ -413,13 +407,10 @@ if(BUILD_SHARED_LIBS) set_target_properties(libssh2_shared PROPERTIES IMPORT_SUFFIX "_imp${CMAKE_IMPORT_LIBRARY_SUFFIX}") endif() - set_target_properties(libssh2_object PROPERTIES POSITION_INDEPENDENT_CODE ON) - if(WIN32) - target_compile_definitions(libssh2_object PRIVATE libssh2_EXPORTS) - endif() + set_target_properties(libssh2_shared PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(libssh2_shared - PRIVATE "${PROJECT_SOURCE_DIR}/include/" + PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} PUBLIC $ $/${CMAKE_INSTALL_INCLUDEDIR}>) From dbe5e680b73d10cc64698bbbe318d23760456133 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 23 Mar 2023 23:26:20 +0000 Subject: [PATCH 155/424] dist: delete reference to recently deleted file [ci skip] Follow-up to b8762c1003d97e109efa587bdc760ff9873949eb --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 9198bfaa95..ce20ba5453 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c \ vms/readme.vms vms/libssh2_config.h -WIN32FILES = win32/GNUmakefile win32/test/GNUmakefile \ +WIN32FILES = win32/GNUmakefile \ win32/libssh2_config.h win32/config.mk win32/rules.mk \ win32/Makefile.Watcom win32/libssh2.dsw win32/tests.dsp $(DSP) \ win32/msvcproj.head win32/msvcproj.foot win32/libssh2.rc From c7d48443867e032edbf0f29e576a46fc1dc03804 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 24 Mar 2023 00:34:40 +0100 Subject: [PATCH 156/424] maketgz: add .xz, .bz2, .zip source archive formats (#874) Copied from curl: https://github.com/curl/curl/blob/4528690cd51e5445df74aef8f83470a602683797/maketgz#L174-L222 [ci skip] --- .gitignore | 3 +++ maketgz | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/.gitignore b/.gitignore index f740e52894..4292e8d6f2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,10 @@ libtool ltmain.sh missing ssh2_sample +libssh2-*.tar.bz2 libssh2-*.tar.gz +libssh2-*.tar.xz +libssh2-*.zip install-sh *.o *.lo diff --git a/maketgz b/maketgz index 0a3da5dddf..a53f20d8c7 100755 --- a/maketgz +++ b/maketgz @@ -99,3 +99,52 @@ git log --pretty=fuller --no-color --date=short --decorate=full -1000 | ./git2ne echo "make dist" targz="libssh2-$version.tar.gz" make -s dist VERSION=$version +res=$? + +if test "$res" != 0; then + echo "make dist failed" + exit 2 +fi + +############################################################################ +# +# Now make a bz2 archive from the tar.gz original +# + +bzip2="libssh2-$version.tar.bz2" +echo "Generating $bzip2" +gzip -dc $targz | bzip2 --best > $bzip2 + +############################################################################ +# +# Now make an xz archive from the tar.gz original +# + +xz="libssh2-$version.tar.xz" +echo "Generating $xz" +gzip -dc $targz | xz -6e - > $xz + +############################################################################ +# +# Now make a zip archive from the tar.gz original +# +makezip() { + rm -rf $tempdir + mkdir $tempdir + cd $tempdir + gzip -dc ../$targz | tar -xf - + find . | zip $zip -@ >/dev/null + mv $zip ../ + cd .. + rm -rf $tempdir +} + +zip="libssh2-$version.zip" +echo "Generating $zip" +tempdir=".builddir" +makezip + +echo "------------------" +echo "maketgz report:" +echo "" +ls -l $targz $bzip2 $zip $xz From bd078e12bd79278037d6a805a0d9302b7dce8931 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 24 Mar 2023 03:29:46 +0100 Subject: [PATCH 157/424] cmake: automatic exports macro tidy-up (#875) In a recent CMake update I left the original CMake EXPORTS macro unchanged (`libssh2_EXPORTS`) for compatibility. However, that macro was also recently added [1] and not present in an official release yet, so we might as well just use the new native one instead (`libssh2_shared_EXPORTS`), defined by CMake automatically. This way we don't need to define the old macro manually. CMake forms this macro from the lib's internal name as defined in `add_library()` by appending `_EXPORTS`. That target name changed from `libssh2` to `libssh2_shared` after introducing dual shared + static builds in the recent update. If we're here, add a new, stable, build-tool agnostic macro with the same effect, for non-CMake use: `LIBSSH2_EXPORTS` [1] 1f0fe7443a1ecddd320f2c693607b2afee9bbe2f (2021-10-26) Follow-up to 4e2580628dd1f8dc51ac65ac747ebcf0e93fa3d1 --- include/libssh2.h | 3 ++- src/CMakeLists.txt | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index f7c95cbcfe..98a31a4349 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -100,7 +100,8 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API # ifdef WIN32 -# if defined(_WINDLL) || defined(libssh2_EXPORTS) +# if defined(LIBSSH2_EXPORTS) || \ + defined(_WINDLL) || defined(libssh2_shared_EXPORTS) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) # else diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77a1b60e9a..b98549d4a3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -396,7 +396,6 @@ if(BUILD_SHARED_LIBS) add_library(libssh2_shared SHARED ${SOURCES}) if(WIN32) set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) - target_compile_definitions(libssh2_shared PRIVATE libssh2_EXPORTS) endif() target_compile_definitions(libssh2_shared PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) target_link_libraries(libssh2_shared PRIVATE ${LIBRARIES}) From 02f2700a61157ce5a264319bdb80754c92a40a24 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 26 Mar 2023 09:27:32 +0000 Subject: [PATCH 158/424] src: silence compiler warnings 1 Most of the changes aim to silence warnings by adding casts. An assortment of other issues, mainly compiler warnings, resolved: - unreachable code fixed by using `goto` in `publickey_response_success()` in `publickey.c`. - potentially uninitialized variable in `sftp_open()`. - MSVS-specific bogus warnings with `nid_type` in `kex.c`. - check result of `kex_session_ecdh_curve_type()`. - add missing function declarations. - type changes to fit values without casts: - `cmd_len` in `scp_recv()` and `scp_send()`: `int` -> `size_t` - `Blowfish_expandstate()`, `Blowfish_expand0state()` loop counters: `uint16_t` -> `int` - `RECV_SEND_ALL()`: `int` -> `ssize_t` - `shell_quotearg()` -> `unsigned` -> `size_t` - `sig_len` in `_libssh2_mbedtls_rsa_sha2_sign()`: `unsigned` -> `size_t` - `prefs_len` in `libssh2_session_method_pref()`: `int` -> `size_t` - `firstsec` in `_libssh2_debug_low()`: `int` -> `long` - `method_len` in `libssh2_session_method_pref()`: `int` -> `size_t` - simplify `_libssh2_ntohu64()`. - fix `LIBSSH2_INT64_T_FORMAT` for MinGW. - fix gcc warning by not using a bit field for `burn_optimistic_kexinit`. - fix unused variable warning in `_libssh2_cipher_crypt()` in `libgcrypt.c`. - fix unused variables with `HAVE_DISABLED_NONBLOCKING`. - avoid const stripping with `BIO_new_mem_buf()` and OpenSSL 1.0.2 and newer. - add a missing const in `wincng.h`. - FIXME added for public: - `libssh2_channel_window_read_ex()` `read_avail` argument type. - `libssh2_base64_decode()` `datalen` argument type. - fix possible overflow in `sftp_read()`. Ref: 4552c73cd58fccb1fc49cb0f25f86619133e560f - formatting in `wincng.h`. See warning details in the PR's individual commits. Cherry-picked from #846 Closes #876 --- src/agent.c | 26 ++++++----- src/bcrypt_pbkdf.c | 4 +- src/blowfish.c | 28 ++++++------ src/channel.c | 43 +++++++++-------- src/hostkey.c | 15 ++++-- src/kex.c | 49 ++++++++++++-------- src/knownhost.c | 4 +- src/libgcrypt.c | 3 +- src/libgcrypt.h | 1 + src/libssh2_priv.h | 24 ++++++---- src/mbedtls.c | 16 +++---- src/mbedtls.h | 14 +++--- src/misc.c | 31 +++++++------ src/openssl.c | 112 ++++++++++++++++++++++++++++++--------------- src/openssl.h | 22 ++++----- src/packet.c | 3 +- src/pem.c | 7 +-- src/publickey.c | 30 ++++++------ src/scp.c | 68 ++++++++++++++------------- src/session.c | 21 ++++++--- src/sftp.c | 58 +++++++++++------------ src/transport.c | 2 +- src/userauth.c | 20 ++++---- src/wincng.c | 11 +++-- src/wincng.h | 50 ++++++++++++-------- 25 files changed, 380 insertions(+), 282 deletions(-) diff --git a/src/agent.c b/src/agent.c index a8c61cc9e7..0907e598fd 100644 --- a/src/agent.c +++ b/src/agent.c @@ -131,10 +131,10 @@ agent_connect_unix(LIBSSH2_AGENT *agent) } #define RECV_SEND_ALL(func, socket, buffer, length, flags, abstract) \ - int rc; \ size_t finished = 0; \ \ while(finished < length) { \ + ssize_t rc; \ rc = func(socket, \ (char *)buffer + finished, length - finished, \ flags, abstract); \ @@ -170,9 +170,10 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) /* Send the length of the request */ if(transctx->state == agent_NB_state_request_created) { - _libssh2_htonu32(buf, transctx->request_len); - rc = _send_all(agent->session->send, agent->fd, - buf, sizeof buf, 0, &agent->session->abstract); + _libssh2_htonu32(buf, (uint32_t)transctx->request_len); + rc = (int)_send_all(agent->session->send, agent->fd, + buf, sizeof buf, 0, + &agent->session->abstract); if(rc == -EAGAIN) return LIBSSH2_ERROR_EAGAIN; else if(rc < 0) @@ -183,8 +184,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) /* Send the request body */ if(transctx->state == agent_NB_state_request_length_sent) { - rc = _send_all(agent->session->send, agent->fd, transctx->request, - transctx->request_len, 0, &agent->session->abstract); + rc = (int)_send_all(agent->session->send, agent->fd, + transctx->request, transctx->request_len, 0, + &agent->session->abstract); if(rc == -EAGAIN) return LIBSSH2_ERROR_EAGAIN; else if(rc < 0) @@ -195,8 +197,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) /* Receive the length of a response */ if(transctx->state == agent_NB_state_request_sent) { - rc = _recv_all(agent->session->recv, agent->fd, - buf, sizeof buf, 0, &agent->session->abstract); + rc = (int)_recv_all(agent->session->recv, agent->fd, + buf, sizeof buf, 0, + &agent->session->abstract); if(rc < 0) { if(rc == -EAGAIN) return LIBSSH2_ERROR_EAGAIN; @@ -214,8 +217,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) /* Receive the response body */ if(transctx->state == agent_NB_state_response_length_received) { - rc = _recv_all(agent->session->recv, agent->fd, transctx->response, - transctx->response_len, 0, &agent->session->abstract); + rc = (int)_recv_all(agent->session->recv, agent->fd, + transctx->response, transctx->response_len, 0, + &agent->session->abstract); if(rc < 0) { if(rc == -EAGAIN) return LIBSSH2_ERROR_EAGAIN; @@ -311,7 +315,7 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) transctx->request_len); cds.dwData = PAGEANT_COPYDATA_ID; - cds.cbData = 1 + strlen(mapname); + cds.cbData = (DWORD)(1 + strlen(mapname)); cds.lpData = mapname; id = SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds); diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index d1b5b3d7c4..73a46c7a04 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -88,7 +88,7 @@ bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out) /* copy out */ for(i = 0; i < BCRYPT_BLOCKS; i++) { - out[4 * i + 3] = (cdata[i] >> 24) & 0xff; + out[4 * i + 3] = (uint8_t)((cdata[i] >> 24) & 0xff); out[4 * i + 2] = (cdata[i] >> 16) & 0xff; out[4 * i + 1] = (cdata[i] >> 8) & 0xff; out[4 * i + 0] = cdata[i] & 0xff; @@ -136,7 +136,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, /* generate key, sizeof(out) at a time */ for(count = 1; keylen > 0; count++) { - countsalt[saltlen + 0] = (count >> 24) & 0xff; + countsalt[saltlen + 0] = (uint8_t)((count >> 24) & 0xff); countsalt[saltlen + 1] = (count >> 16) & 0xff; countsalt[saltlen + 2] = (count >> 8) & 0xff; countsalt[saltlen + 3] = count & 0xff; diff --git a/src/blowfish.c b/src/blowfish.c index 2535e9f578..870269ade5 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -422,9 +422,9 @@ Blowfish_stream2word(const uint8_t *data, uint16_t databytes, void Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes) { - uint16_t i; + int i; + int k; uint16_t j; - uint16_t k; uint32_t temp; uint32_t datal; uint32_t datar; @@ -461,9 +461,9 @@ void Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes, const uint8_t *key, uint16_t keybytes) { - uint16_t i; + int i; + int k; uint16_t j; - uint16_t k; uint32_t temp; uint32_t datal; uint32_t datar; @@ -546,11 +546,11 @@ blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len) l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; Blowfish_encipher(c, &l, &r); - data[0] = l >> 24 & 0xff; + data[0] = (uint8_t)(l >> 24 & 0xff); data[1] = l >> 16 & 0xff; data[2] = l >> 8 & 0xff; data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; + data[4] = (uint8_t)(r >> 24 & 0xff); data[5] = r >> 16 & 0xff; data[6] = r >> 8 & 0xff; data[7] = r & 0xff; @@ -568,11 +568,11 @@ blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len) l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; + data[0] = (uint8_t)(l >> 24 & 0xff); data[1] = l >> 16 & 0xff; data[2] = l >> 8 & 0xff; data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; + data[4] = (uint8_t)(r >> 24 & 0xff); data[5] = r >> 16 & 0xff; data[6] = r >> 8 & 0xff; data[7] = r & 0xff; @@ -592,11 +592,11 @@ blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len) l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; Blowfish_encipher(c, &l, &r); - data[0] = l >> 24 & 0xff; + data[0] = (uint8_t)(l >> 24 & 0xff); data[1] = l >> 16 & 0xff; data[2] = l >> 8 & 0xff; data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; + data[4] = (uint8_t)(r >> 24 & 0xff); data[5] = r >> 16 & 0xff; data[6] = r >> 8 & 0xff; data[7] = r & 0xff; @@ -618,11 +618,11 @@ blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len) l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; + data[0] = (uint8_t)(l >> 24 & 0xff); data[1] = l >> 16 & 0xff; data[2] = l >> 8 & 0xff; data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; + data[4] = (uint8_t)(r >> 24 & 0xff); data[5] = r >> 16 & 0xff; data[6] = r >> 8 & 0xff; data[7] = r & 0xff; @@ -634,11 +634,11 @@ blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len) l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; + data[0] = (uint8_t)(l >> 24 & 0xff); data[1] = l >> 16 & 0xff; data[2] = l >> 8 & 0xff; data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; + data[4] = (uint8_t)(r >> 24 & 0xff); data[5] = r >> 16 & 0xff; data[6] = r >> 8 & 0xff; data[7] = r & 0xff; diff --git a/src/channel.c b/src/channel.c index 74da24495e..1e93b27471 100644 --- a/src/channel.c +++ b/src/channel.c @@ -470,11 +470,12 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, host = "0.0.0.0"; if(session->fwdLstn_state == libssh2_NB_state_idle) { - session->fwdLstn_host_len = strlen(host); + session->fwdLstn_host_len = (uint32_t)strlen(host); /* 14 = packet_type(1) + request_len(4) + want_replay(1) + host_len(4) + port(4) */ session->fwdLstn_packet_len = - session->fwdLstn_host_len + (sizeof("tcpip-forward") - 1) + 14; + session->fwdLstn_host_len + + (uint32_t)(sizeof("tcpip-forward") - 1) + 14; /* Zero the whole thing out */ memset(&session->fwdLstn_packet_requirev_state, 0, @@ -1332,7 +1333,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, _libssh2_store_str(&s, auth_proto ? auth_proto : "MIT-MAGIC-COOKIE-1", proto_len); - _libssh2_store_u32(&s, cookie_len); + _libssh2_store_u32(&s, (uint32_t)cookie_len); if(auth_cookie) { memcpy(s, auth_cookie, cookie_len); } @@ -1482,7 +1483,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, *(s++) = 0x01; if(message) - _libssh2_store_u32(&s, message_len); + _libssh2_store_u32(&s, (uint32_t)message_len); channel->process_state = libssh2_NB_state_created; } @@ -1658,20 +1659,20 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid) } channel->read_avail -= channel->flush_flush_bytes; - channel->remote.window_size -= channel->flush_flush_bytes; + channel->remote.window_size -= (uint32_t)channel->flush_flush_bytes; if(channel->flush_refund_bytes) { int rc = _libssh2_channel_receive_window_adjust(channel, - channel->flush_refund_bytes, - 1, NULL); + (uint32_t)channel->flush_refund_bytes, + 1, NULL); if(rc == LIBSSH2_ERROR_EAGAIN) return rc; } channel->flush_state = libssh2_NB_state_idle; - return channel->flush_flush_bytes; + return (int)channel->flush_flush_bytes; } /* @@ -1871,7 +1872,8 @@ libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel, return (unsigned long)LIBSSH2_ERROR_BAD_USE; BLOCK_ADJUST(rc, channel->session, - _libssh2_channel_receive_window_adjust(channel, adj, + _libssh2_channel_receive_window_adjust(channel, + (uint32_t)adj, force, &window)); /* stupid - but this is how it was made to work before and this is just @@ -1902,8 +1904,9 @@ libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel, return LIBSSH2_ERROR_BAD_USE; BLOCK_ADJUST(rc, channel->session, - _libssh2_channel_receive_window_adjust(channel, adj, force, - window)); + _libssh2_channel_receive_window_adjust(channel, + (uint32_t)adj, + force, window)); return rc; } @@ -2005,8 +2008,8 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, (channel->remote.window_size < channel->remote.window_size_initial / 4 * 3 + buflen) ) { - uint32_t adjustment = channel->remote.window_size_initial + buflen - - channel->remote.window_size; + uint32_t adjustment = (uint32_t)(channel->remote.window_size_initial + + buflen - channel->remote.window_size); if(adjustment < LIBSSH2_CHANNEL_MINADJUST) adjustment = LIBSSH2_CHANNEL_MINADJUST; @@ -2134,7 +2137,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, } channel->read_avail -= bytes_read; - channel->remote.window_size -= bytes_read; + channel->remote.window_size -= (uint32_t)bytes_read; return bytes_read; } @@ -2167,8 +2170,8 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, if(buflen > recv_window) { BLOCK_ADJUST(rc, channel->session, - _libssh2_channel_receive_window_adjust(channel, buflen, - 1, NULL)); + _libssh2_channel_receive_window_adjust(channel, + (uint32_t)buflen, 1, NULL)); } BLOCK_ADJUST(rc, channel->session, @@ -2335,7 +2338,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, } /* store the size here only, the buffer is passed in as-is to _libssh2_transport_send() */ - _libssh2_store_u32(&s, channel->write_bufwrite); + _libssh2_store_u32(&s, (uint32_t)channel->write_bufwrite); channel->write_packet_len = s - channel->write_packet; _libssh2_debug((session, LIBSSH2_TRACE_CONN, @@ -2360,7 +2363,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, "Unable to send channel data"); } /* Shrink local window size */ - channel->local.window_size -= channel->write_bufwrite; + channel->local.window_size -= (uint32_t)channel->write_bufwrite; wrote += channel->write_bufwrite; @@ -2835,7 +2838,7 @@ libssh2_channel_free(LIBSSH2_CHANNEL *channel) */ LIBSSH2_API unsigned long libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, - unsigned long *read_avail, + /* FIXME: -> size_t */ unsigned long *read_avail, unsigned long *window_size_initial) { if(!channel) @@ -2875,7 +2878,7 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, packet = next_packet; } - *read_avail = bytes_queued; + *read_avail = (unsigned long)bytes_queued; } return channel->remote.window_size; diff --git a/src/hostkey.c b/src/hostkey.c index 647c83acb5..ea0272250d 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -113,8 +113,11 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, if(!_libssh2_eob(&buf)) return -1; - if(_libssh2_rsa_new(&rsactx, e, e_len, n, n_len, NULL, 0, - NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0)) { + if(_libssh2_rsa_new(&rsactx, + e, (unsigned long)e_len, + n, (unsigned long)n_len, + NULL, 0, NULL, 0, NULL, 0, + NULL, 0, NULL, 0, NULL, 0)) { return -1; } @@ -525,8 +528,12 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session, if(!_libssh2_eob(&buf)) return -1; - if(_libssh2_dsa_new(&dsactx, p, p_len, q, q_len, - g, g_len, y, y_len, NULL, 0)) { + if(_libssh2_dsa_new(&dsactx, + p, (unsigned long)p_len, + q, (unsigned long)q_len, + g, (unsigned long)g_len, + y, (unsigned long)y_len, + NULL, 0)) { return -1; } diff --git a/src/kex.c b/src/kex.c index 299055fd0c..48f8f5cd84 100644 --- a/src/kex.c +++ b/src/kex.c @@ -531,7 +531,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, if(session->local.banner) { _libssh2_htonu32(exchange_state->h_sig_comp, - strlen((char *) session->local.banner) - 2); + (uint32_t)(strlen((char *) session->local.banner) - 2)); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 4); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, @@ -550,7 +550,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, } _libssh2_htonu32(exchange_state->h_sig_comp, - strlen((char *) session->remote.banner)); + (uint32_t)strlen((char *) session->remote.banner)); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 4); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, @@ -558,7 +558,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, strlen((char *) session->remote.banner)); _libssh2_htonu32(exchange_state->h_sig_comp, - session->local.kexinit_len); + (uint32_t)session->local.kexinit_len); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 4); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, @@ -566,7 +566,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, session->local.kexinit_len); _libssh2_htonu32(exchange_state->h_sig_comp, - session->remote.kexinit_len); + (uint32_t)session->remote.kexinit_len); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 4); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, @@ -1428,7 +1428,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange _libssh2_bn_from_bin(key_state->g, g_len, g); ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p, - p_len, 1, + (int)p_len, 1, (void *)&exchange_hash_ctx, SSH_MSG_KEX_DH_GEX_INIT, SSH_MSG_KEX_DH_GEX_REPLY, @@ -1556,7 +1556,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange _libssh2_bn_from_bin(key_state->g, g_len, g); ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p, - p_len, 256, + (int)p_len, 256, (void *)&exchange_hash_ctx, SSH_MSG_KEX_DH_GEX_INIT, SSH_MSG_KEX_DH_GEX_REPLY, @@ -1605,7 +1605,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange (void)libssh2_sha##digest_type##_init(&ctx); \ if(session->local.banner) { \ _libssh2_htonu32(exchange_state->h_sig_comp, \ - strlen((char *) session->local.banner) - 2); \ + (uint32_t)(strlen((char *) session->local.banner) - 2)); \ libssh2_sha##digest_type##_update(ctx, \ exchange_state->h_sig_comp, 4); \ libssh2_sha##digest_type##_update(ctx, \ @@ -1626,7 +1626,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange } \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ - strlen((char *) session->remote.banner)); \ + (uint32_t)strlen((char *) session->remote.banner)); \ libssh2_sha##digest_type##_update(ctx, \ exchange_state->h_sig_comp, 4); \ libssh2_sha##digest_type##_update(ctx, \ @@ -1635,7 +1635,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange session->remote.banner)); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ - session->local.kexinit_len); \ + (uint32_t)session->local.kexinit_len); \ libssh2_sha##digest_type##_update(ctx, \ exchange_state->h_sig_comp, 4); \ libssh2_sha##digest_type##_update(ctx, \ @@ -1643,7 +1643,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange session->local.kexinit_len); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ - session->remote.kexinit_len); \ + (uint32_t)session->remote.kexinit_len); \ libssh2_sha##digest_type##_update(ctx, \ exchange_state->h_sig_comp, 4); \ libssh2_sha##digest_type##_update(ctx, \ @@ -1659,7 +1659,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange session->server_hostkey_len); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ - public_key_len); \ + (uint32_t)public_key_len); \ libssh2_sha##digest_type##_update(ctx, \ exchange_state->h_sig_comp, 4); \ libssh2_sha##digest_type##_update(ctx, \ @@ -1667,7 +1667,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange public_key_len); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ - server_public_key_len); \ + (uint32_t)server_public_key_len); \ libssh2_sha##digest_type##_update(ctx, \ exchange_state->h_sig_comp, 4); \ libssh2_sha##digest_type##_update(ctx, \ @@ -1712,6 +1712,11 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type) else if(strcmp(name, "ecdh-sha2-nistp521") == 0) type = LIBSSH2_EC_CURVE_NISTP521; else { +/* silence: + warning C4701: potentially uninitialized local variable 'type' used */ +#if defined(_MSC_VER) + type = (libssh2_curve_type)0; +#endif ret = -1; } @@ -1907,7 +1912,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, goto clean_exit; } _libssh2_htonu32(exchange_state->k_value, - exchange_state->k_value_len - 4); + (uint32_t)(exchange_state->k_value_len - 4)); if(_libssh2_bn_bits(exchange_state->k) % 8) { _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4); } @@ -2003,7 +2008,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, } memcpy(session->session_id, exchange_state->h_sig_comp, digest_length); - session->session_id_len = digest_length; + session->session_id_len = (uint32_t)digest_length; _libssh2_debug((session, LIBSSH2_TRACE_KEX, "session_id calculated")); } @@ -2298,7 +2303,13 @@ kex_method_ecdh_key_exchange if(key_state->state == libssh2_NB_state_sent2) { - (void)kex_session_ecdh_curve_type(session->kex->name, &type); + rc = kex_session_ecdh_curve_type(session->kex->name, &type); + + if(rc != 0) { + ret = _libssh2_error(session, -1, + "Unknown KEX nistp curve type"); + goto ecdh_clean_exit; + } ret = ecdh_sha2_nistp(session, type, key_state->data, key_state->data_len, @@ -2541,7 +2552,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, goto clean_exit; } _libssh2_htonu32(exchange_state->k_value, - exchange_state->k_value_len - 4); + (uint32_t)(exchange_state->k_value_len - 4)); if(_libssh2_bn_bits(exchange_state->k) % 8) { _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4); } @@ -2613,7 +2624,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, } memcpy(session->session_id, exchange_state->h_sig_comp, digest_length); - session->session_id_len = digest_length; + session->session_id_len = (uint32_t)digest_length; _libssh2_debug((session, LIBSSH2_TRACE_KEX, "session_id calculated")); } @@ -3956,7 +3967,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, const char *prefs) { char **prefvar, *s, *newprefs; - int prefs_len = strlen(prefs); + size_t prefs_len = strlen(prefs); const LIBSSH2_COMMON_METHOD **mlist; switch(method_type) { @@ -4031,7 +4042,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, while(s && *s && mlist) { char *p = strchr(s, ','); - int method_len = p ? (p - s) : (int) strlen(s); + size_t method_len = (p ? (size_t)(p - s) : strlen(s)); if(!kex_get_method_by_name(s, method_len, mlist)) { /* Strip out unsupported method */ diff --git a/src/knownhost.c b/src/knownhost.c index 6b3c0230f9..12edbd646e 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -170,14 +170,14 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, break; case LIBSSH2_KNOWNHOST_TYPE_SHA1: rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen, - host, hostlen); + host, (unsigned int)hostlen); if(rc) goto error; entry->name = ptr; entry->name_len = ptrlen; rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen, - salt, strlen(salt)); + salt, (unsigned int)strlen(salt)); if(rc) goto error; entry->salt = ptr; diff --git a/src/libgcrypt.c b/src/libgcrypt.c index e6e6cabea0..66d64092c0 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -595,9 +595,10 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, _libssh2_cipher_type(algo), int encrypt, unsigned char *block, size_t blklen) { - int cipher = _libssh2_gcry_cipher(algo); int ret; + (void)algo; + if(encrypt) { ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen); } diff --git a/src/libgcrypt.h b/src/libgcrypt.h index 95876b96d1..54f011049a 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -227,6 +227,7 @@ #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ _libssh2_dh_secret(dhctx, secret, f, p) #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) +extern void _libssh2_init_aes_ctr(void); extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx); extern int _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, _libssh2_bn *g, _libssh2_bn *p, diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 4f77e5f394..e4bb01756b 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -164,10 +164,11 @@ struct iovec { #include "crypto.h" #ifdef HAVE_WINSOCK2_H - #include #include - +/* Force parameter type. */ +#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) +#define send(s, b, l, f) send((s), (b), (int)(l), (f)) #endif #ifndef SIZE_MAX @@ -201,20 +202,23 @@ struct iovec { #define LIBSSH2_FREE(session, ptr) \ session->free((ptr), &(session)->abstract) #define LIBSSH2_IGNORE(session, data, datalen) \ - session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract) + session->ssh_msg_ignore((session), (data), (int)(datalen), \ + &(session)->abstract) #define LIBSSH2_DEBUG(session, always_display, message, message_len, \ language, language_len) \ - session->ssh_msg_debug((session), (always_display), (message), \ - (message_len), (language), (language_len), \ + session->ssh_msg_debug((session), (always_display), \ + (message), (int)(message_len), \ + (language), (int)(language_len), \ &(session)->abstract) #define LIBSSH2_DISCONNECT(session, reason, message, message_len, \ language, language_len) \ - session->ssh_msg_disconnect((session), (reason), (message), \ - (message_len), (language), (language_len), \ + session->ssh_msg_disconnect((session), (reason), \ + (message), (int)(message_len), \ + (language), (int)(language_len), \ &(session)->abstract) #define LIBSSH2_MACERROR(session, data, datalen) \ - session->macerror((session), (data), (datalen), &(session)->abstract) + session->macerror((session), (data), (int)(datalen), &(session)->abstract) #define LIBSSH2_X11_OPEN(channel, shost, sport) \ channel->session->x11(((channel)->session), (channel), \ (shost), (sport), (&(channel)->session->abstract)) @@ -633,7 +637,7 @@ struct _LIBSSH2_SESSION /* Agreed Key Exchange Method */ const LIBSSH2_KEX_METHOD *kex; - unsigned int burn_optimistic_kexinit:1; + unsigned int burn_optimistic_kexinit; unsigned char *session_id; uint32_t session_id_len; @@ -1142,7 +1146,7 @@ void _libssh2_init_if_needed(void); #define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0])) /* define to output the libssh2_int64_t type in a *printf() */ -#if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__) +#if defined(__BORLANDC__) || defined(_MSC_VER) #define LIBSSH2_INT64_T_FORMAT "I64d" #else #define LIBSSH2_INT64_T_FORMAT "lld" diff --git a/src/mbedtls.c b/src/mbedtls.c index 94a0e4ee2b..d66fc040d3 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -126,7 +126,7 @@ _libssh2_mbedtls_cipher_init(_libssh2_cipher_ctx *ctx, if(!ret) ret = mbedtls_cipher_setkey(ctx, secret, - mbedtls_cipher_info_get_key_bitlen(cipher_info), + (int)mbedtls_cipher_info_get_key_bitlen(cipher_info), op); if(!ret) @@ -526,11 +526,11 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, #if MBEDTLS_VERSION_NUMBER >= 0x03000000 ret = mbedtls_rsa_pkcs1_verify(rsactx, - md_type, hash_len, + md_type, (unsigned int)hash_len, hash, sig); #else ret = mbedtls_rsa_pkcs1_verify(rsactx, NULL, NULL, MBEDTLS_RSA_PUBLIC, - md_type, hash_len, + md_type, (unsigned int)hash_len, hash, sig); #endif free(hash); @@ -558,7 +558,7 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, { int ret; unsigned char *sig; - unsigned int sig_len; + size_t sig_len; int md_type; (void)hash_len; @@ -587,11 +587,11 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, ret = mbedtls_rsa_pkcs1_sign(rsa, mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg, - md_type, hash_len, + md_type, (unsigned int)hash_len, hash, sig); #else ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, - md_type, hash_len, + md_type, (unsigned int)hash_len, hash, sig); #endif } @@ -634,8 +634,8 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, unsigned char *key; unsigned char *p; - e_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E)); - n_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N)); + e_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E)); + n_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N)); /* Key form is "ssh-rsa" + e + n. */ len = 4 + 7 + 4 + e_bytes + 4 + n_bytes; diff --git a/src/mbedtls.h b/src/mbedtls.h index 27b8c4f556..f1e2e20cb3 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -124,7 +124,7 @@ #define libssh2_hmac_cleanup(pctx) \ mbedtls_md_free(pctx) #define libssh2_hmac_update(ctx, data, datalen) \ - mbedtls_md_hmac_update(&ctx, (unsigned char *) data, datalen) + mbedtls_md_hmac_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_hmac_final(ctx, hash) \ mbedtls_md_hmac_finish(&ctx, hash) @@ -152,7 +152,7 @@ #define libssh2_sha1_init(pctx) \ _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0) #define libssh2_sha1_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha1_final(ctx, hash) \ _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha1(data, datalen, hash) \ @@ -168,7 +168,7 @@ #define libssh2_sha256_init(pctx) \ _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0) #define libssh2_sha256_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha256_final(ctx, hash) \ _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha256(data, datalen, hash) \ @@ -185,7 +185,7 @@ #define libssh2_sha384_init(pctx) \ _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0) #define libssh2_sha384_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha384_final(ctx, hash) \ _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha384(data, datalen, hash) \ @@ -202,7 +202,7 @@ #define libssh2_sha512_init(pctx) \ _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0) #define libssh2_sha512_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha512_final(ctx, hash) \ _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha512(data, datalen, hash) \ @@ -219,7 +219,7 @@ #define libssh2_md5_init(pctx) \ _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0) #define libssh2_md5_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_md5_final(ctx, hash) \ _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_md5(data, datalen, hash) \ @@ -595,6 +595,8 @@ void _libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx); #endif /* LIBSSH2_ECDSA */ +extern void +_libssh2_init_aes_ctr(void); extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx); extern int diff --git a/src/misc.c b/src/misc.c index a8bebcfcab..9fc2d2170f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -79,7 +79,7 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...) va_start(args, fmt); n = vsnprintf(cp, cp_max_len, fmt, args); va_end(args); - return (n < cp_max_len) ? n : (cp_max_len - 1); + return (n < (int)cp_max_len) ? n : (int)(cp_max_len - 1); } #endif @@ -230,14 +230,14 @@ _libssh2_ntohu32(const unsigned char *buf) libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf) { - unsigned long msl, lsl; - - msl = ((libssh2_uint64_t)buf[0] << 24) | ((libssh2_uint64_t)buf[1] << 16) - | ((libssh2_uint64_t)buf[2] << 8) | (libssh2_uint64_t)buf[3]; - lsl = ((libssh2_uint64_t)buf[4] << 24) | ((libssh2_uint64_t)buf[5] << 16) - | ((libssh2_uint64_t)buf[6] << 8) | (libssh2_uint64_t)buf[7]; - - return ((libssh2_uint64_t)msl <<32) | lsl; + return ((libssh2_uint64_t)buf[0] << 56) + | ((libssh2_uint64_t)buf[1] << 48) + | ((libssh2_uint64_t)buf[2] << 40) + | ((libssh2_uint64_t)buf[3] << 32) + | ((libssh2_uint64_t)buf[4] << 24) + | ((libssh2_uint64_t)buf[5] << 16) + | ((libssh2_uint64_t)buf[6] << 8) + | ((libssh2_uint64_t)buf[7]); } /* _libssh2_htonu32 @@ -245,7 +245,7 @@ _libssh2_ntohu64(const unsigned char *buf) void _libssh2_htonu32(unsigned char *buf, uint32_t value) { - buf[0] = (value >> 24) & 0xFF; + buf[0] = (unsigned char)((value >> 24) & 0xFF); buf[1] = (value >> 16) & 0xFF; buf[2] = (value >> 8) & 0xFF; buf[3] = value & 0xFF; @@ -281,7 +281,7 @@ void _libssh2_store_bignum2_bytes(unsigned char **buf, for(p = bytes; len > 0 && *p == 0; --len, ++p) {} extraByte = (len > 0 && (p[0] & 0x80) != 0); - _libssh2_store_u32(buf, len + extraByte); + _libssh2_store_u32(buf, (uint32_t)(len + extraByte)); if(extraByte) { *buf[0] = 0; @@ -319,6 +319,7 @@ static const short base64_reverse_table[256] = { * * Decode a base64 chunk and store it into a newly alloc'd buffer */ +/* FIXME: datalen, src_len -> size_t */ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, unsigned int *datalen, const char *src, @@ -344,15 +345,15 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, d[len] = (unsigned char)(v << 2); break; case 1: - d[len++] |= v >> 4; + d[len++] |= (unsigned char)(v >> 4); d[len] = (unsigned char)(v << 4); break; case 2: - d[len++] |= v >> 2; + d[len++] |= (unsigned char)(v >> 2); d[len] = (unsigned char)(v << 6); break; case 3: - d[len++] |= v; + d[len++] |= (unsigned char)v; break; } i++; @@ -483,7 +484,7 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, int len, msglen, buflen = sizeof(buffer); va_list vargs; struct timeval now; - static int firstsec; + static long firstsec; static const char *const contexts[] = { "Unknown", "Transport", diff --git a/src/openssl.c b/src/openssl.c index 0a89b512b6..9abe8c03af 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -119,29 +119,29 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, BIGNUM * iqmp = 0; e = BN_new(); - BN_bin2bn(edata, elen, e); + BN_bin2bn(edata, (int) elen, e); n = BN_new(); - BN_bin2bn(ndata, nlen, n); + BN_bin2bn(ndata, (int) nlen, n); if(ddata) { d = BN_new(); - BN_bin2bn(ddata, dlen, d); + BN_bin2bn(ddata, (int) dlen, d); p = BN_new(); - BN_bin2bn(pdata, plen, p); + BN_bin2bn(pdata, (int) plen, p); q = BN_new(); - BN_bin2bn(qdata, qlen, q); + BN_bin2bn(qdata, (int) qlen, q); dmp1 = BN_new(); - BN_bin2bn(e1data, e1len, dmp1); + BN_bin2bn(e1data, (int) e1len, dmp1); dmq1 = BN_new(); - BN_bin2bn(e2data, e2len, dmq1); + BN_bin2bn(e2data, (int) e2len, dmq1); iqmp = BN_new(); - BN_bin2bn(coeffdata, coefflen, iqmp); + BN_bin2bn(coeffdata, (int) coefflen, iqmp); } *rsa = RSA_new(); @@ -196,16 +196,23 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, nid_type = NID_sha512; ret = _libssh2_sha512(m, m_len, hash); } - else + else { +/* silence: + warning C4701: potentially uninitialized local variable 'nid_type' used */ +#if defined(_MSC_VER) + nid_type = 0; +#endif ret = -1; /* unsupported digest */ + } if(ret != 0) { free(hash); return -1; /* failure */ } - ret = RSA_verify(nid_type, hash, hash_len, - (unsigned char *) sig, sig_len, rsactx); + ret = RSA_verify(nid_type, hash, (unsigned int) hash_len, + (unsigned char *) sig, + (unsigned int) sig_len, rsactx); free(hash); @@ -242,20 +249,20 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, BIGNUM * priv_key = NULL; p_bn = BN_new(); - BN_bin2bn(p, p_len, p_bn); + BN_bin2bn(p, (int) p_len, p_bn); q_bn = BN_new(); - BN_bin2bn(q, q_len, q_bn); + BN_bin2bn(q, (int) q_len, q_bn); g_bn = BN_new(); - BN_bin2bn(g, g_len, g_bn); + BN_bin2bn(g, (int) g_len, g_bn); pub_key = BN_new(); - BN_bin2bn(y, y_len, pub_key); + BN_bin2bn(y, (int) y_len, pub_key); if(x_len) { priv_key = BN_new(); - BN_bin2bn(x, x_len, priv_key); + BN_bin2bn(x, (int) x_len, priv_key); } *dsactx = DSA_new(); @@ -348,6 +355,11 @@ _libssh2_ecdsa_curve_type_from_name(const char *name, else if(strcmp(name, "ecdsa-sha2-nistp521") == 0) type = LIBSSH2_EC_CURVE_NISTP521; else { +/* silence: + warning C4701: potentially uninitialized local variable 'type' used */ +#if defined(_MSC_VER) + type = (libssh2_curve_type)0; +#endif ret = -1; } @@ -415,17 +427,17 @@ _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx, BIGNUM *pr = BN_new(); BIGNUM *ps = BN_new(); - BN_bin2bn(r, r_len, pr); - BN_bin2bn(s, s_len, ps); + BN_bin2bn(r, (int) r_len, pr); + BN_bin2bn(s, (int) s_len, ps); ECDSA_SIG_set0(ecdsa_sig, pr, ps); #else ECDSA_SIG ecdsa_sig_; ECDSA_SIG *ecdsa_sig = &ecdsa_sig_; ecdsa_sig_.r = BN_new(); - BN_bin2bn(r, r_len, ecdsa_sig_.r); + BN_bin2bn(r, (int) r_len, ecdsa_sig_.r); ecdsa_sig_.s = BN_new(); - BN_bin2bn(s, s_len, ecdsa_sig_.s); + BN_bin2bn(s, (int) s_len, ecdsa_sig_.s); #endif if(type == LIBSSH2_EC_CURVE_NISTP256) { @@ -477,9 +489,9 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, (void) encrypt; #ifdef HAVE_OPAQUE_STRUCTS - ret = EVP_Cipher(*ctx, buf, block, blocksize); + ret = EVP_Cipher(*ctx, buf, block, (unsigned int) blocksize); #else - ret = EVP_Cipher(ctx, buf, block, blocksize); + ret = EVP_Cipher(ctx, buf, block, (unsigned int) blocksize); #endif #if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || \ @@ -525,7 +537,7 @@ void _libssh2_openssl_crypto_exit(void) static int passphrase_cb(char *buf, int size, int rwflag, char *passphrase) { - int passphrase_len = strlen(passphrase); + int passphrase_len = (int) strlen(passphrase); (void) rwflag; if(passphrase_len > (size - 1)) { @@ -551,7 +563,11 @@ read_private_key_from_memory(void **key_ctx, *key_ctx = NULL; - bp = BIO_new_mem_buf((char *)filedata, filedata_len); +#if OPENSSL_VERSION_NUMBER >= 0x1000200fL + bp = BIO_new_mem_buf(filedata, (int)filedata_len); +#else + bp = BIO_new_mem_buf((char *)filedata, (int)filedata_len); +#endif if(!bp) { return -1; } @@ -840,9 +856,14 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } - if((rc = _libssh2_rsa_new(&rsa, e, elen, n, nlen, d, dlen, p, plen, - q, qlen, NULL, 0, NULL, 0, - coeff, coefflen)) != 0) { + if((rc = _libssh2_rsa_new(&rsa, + e, (unsigned long)elen, + n, (unsigned long)nlen, + d, (unsigned long)dlen, + p, (unsigned long)plen, + q, (unsigned long)qlen, + NULL, 0, NULL, 0, + coeff, (unsigned long)coefflen)) != 0) { _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Could not create RSA private key")); @@ -1143,8 +1164,12 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } - rc = _libssh2_dsa_new(&dsa, p, plen, q, qlen, g, glen, pub_key, pub_len, - priv_key, priv_len); + rc = _libssh2_dsa_new(&dsa, + p, (unsigned long)plen, + q, (unsigned long)qlen, + g, (unsigned long)glen, + pub_key, (unsigned long)pub_len, + priv_key, (unsigned long)priv_len); if(rc != 0) { _libssh2_debug((session, LIBSSH2_ERROR_PROTO, @@ -1432,7 +1457,7 @@ gen_publickey_from_ed_evp(LIBSSH2_SESSION *session, } _libssh2_store_str(&bufPos, methodName, sizeof(methodName) - 1); - _libssh2_store_u32(&bufPos, rawKeyLen); + _libssh2_store_u32(&bufPos, (uint32_t) rawKeyLen); if(EVP_PKEY_get_raw_public_key(pk, bufPos, &rawKeyLen) != 1) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -2002,11 +2027,14 @@ _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, } if(hash_len == SHA_DIGEST_LENGTH) - ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx); + ret = RSA_sign(NID_sha1, + hash, (unsigned int) hash_len, sig, &sig_len, rsactx); else if(hash_len == SHA256_DIGEST_LENGTH) - ret = RSA_sign(NID_sha256, hash, hash_len, sig, &sig_len, rsactx); + ret = RSA_sign(NID_sha256, + hash, (unsigned int) hash_len, sig, &sig_len, rsactx); else if(hash_len == SHA512_DIGEST_LENGTH) - ret = RSA_sign(NID_sha512, hash, hash_len, sig, &sig_len, rsactx); + ret = RSA_sign(NID_sha512, + hash, (unsigned int) hash_len, sig, &sig_len, rsactx); else { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unsupported hash digest length"); @@ -2097,7 +2125,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, unsigned char *temp_buffer = NULL; unsigned char *out_buffer = NULL; - ECDSA_SIG *sig = ECDSA_do_sign(hash, hash_len, ec_ctx); + ECDSA_SIG *sig = ECDSA_do_sign(hash, (int) hash_len, ec_ctx); if(sig == NULL) return -1; #ifdef HAVE_OPAQUE_STRUCTS @@ -2585,7 +2613,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } - BN_bin2bn(exponent, exponentlen, bn_exponent); + BN_bin2bn(exponent, (int) exponentlen, bn_exponent); rc = (EC_KEY_set_private_key(ec_key, bn_exponent) != 1); if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) { @@ -3059,7 +3087,7 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key, goto clean_exit; } - BN_bin2bn(secret, secret_len, *k); + BN_bin2bn(secret, (int) secret_len, *k); clean_exit: @@ -3690,7 +3718,11 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, LIBSSH2_TRACE_AUTH, "Computing public key from private key.")); - bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len); +#if OPENSSL_VERSION_NUMBER >= 0x1000200fL + bp = BIO_new_mem_buf(privatekeydata, (int)privatekeydata_len); +#else + bp = BIO_new_mem_buf((char *)privatekeydata, (int)privatekeydata_len); +#endif if(!bp) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory when" @@ -3780,7 +3812,11 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, LIBSSH2_TRACE_AUTH, "Computing public key from private key.")); - bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len); +#if OPENSSL_VERSION_NUMBER >= 0x1000200fL + bp = BIO_new_mem_buf(privatekeydata, (int)privatekeydata_len); +#else + bp = BIO_new_mem_buf((char *)privatekeydata, (int)privatekeydata_len); +#endif if(!bp) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory when" diff --git a/src/openssl.h b/src/openssl.h index b537ae0de7..bc53e35051 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -304,15 +304,15 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define libssh2_hmac_ctx HMAC_CTX * #define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new() #define libssh2_hmac_sha1_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, keylen, EVP_sha1(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha1(), NULL) #define libssh2_hmac_md5_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, keylen, EVP_md5(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_md5(), NULL) #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, keylen, EVP_ripemd160(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_ripemd160(), NULL) #define libssh2_hmac_sha256_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, keylen, EVP_sha256(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha256(), NULL) #define libssh2_hmac_sha512_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, keylen, EVP_sha512(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL) #define libssh2_hmac_update(ctx, data, datalen) \ HMAC_Update(ctx, data, datalen) @@ -323,15 +323,15 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define libssh2_hmac_ctx_init(ctx) \ HMAC_CTX_init(&ctx) #define libssh2_hmac_sha1_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, keylen, EVP_sha1(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha1(), NULL) #define libssh2_hmac_md5_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, keylen, EVP_md5(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_md5(), NULL) #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, keylen, EVP_ripemd160(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_ripemd160(), NULL) #define libssh2_hmac_sha256_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, keylen, EVP_sha256(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha256(), NULL) #define libssh2_hmac_sha512_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, keylen, EVP_sha512(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha512(), NULL) #define libssh2_hmac_update(ctx, data, datalen) \ HMAC_Update(&(ctx), data, datalen) @@ -404,7 +404,7 @@ libssh2_curve_type; #define _libssh2_bn_init() BN_new() #define _libssh2_bn_init_from_bin() _libssh2_bn_init() #define _libssh2_bn_set_word(bn, val) BN_set_word(bn, val) -#define _libssh2_bn_from_bin(bn, len, val) BN_bin2bn(val, len, bn) +#define _libssh2_bn_from_bin(bn, len, val) BN_bin2bn(val, (int)len, bn) #define _libssh2_bn_to_bin(bn, val) BN_bn2bin(bn, val) #define _libssh2_bn_bytes(bn) BN_num_bytes(bn) #define _libssh2_bn_bits(bn) BN_num_bits(bn) diff --git a/src/packet.c b/src/packet.c index 035839550b..403c008591 100644 --- a/src/packet.c +++ b/src/packet.c @@ -782,7 +782,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, datalen = channelp->remote.window_size - channelp->read_avail + data_head; - channelp->remote.window_size -= datalen - data_head; + channelp->remote.window_size -= (uint32_t)(datalen - + data_head); _libssh2_debug((session, LIBSSH2_TRACE_CONN, "shrinking window size by %lu bytes to %lu, " "read_avail %lu", diff --git a/src/pem.c b/src/pem.c index 12405cf67f..c6ec85c836 100644 --- a/src/pem.c +++ b/src/pem.c @@ -100,7 +100,8 @@ static const char *crypt_annotation = "Proc-Type: 4,ENCRYPTED"; static unsigned char hex_decode(char digit) { - return (digit >= 'A') ? 0xA + (digit - 'A') : (digit - '0'); + return (unsigned char) + ((digit >= 'A') ? (0xA + (digit - 'A')) : (digit - '0')); } int @@ -157,7 +158,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, /* Decode IV from hex */ for(i = 0; i < method->iv_len; ++i) { - iv[i] = hex_decode(iv[2*i]) << 4; + iv[i] = (unsigned char)(hex_decode(iv[2*i]) << 4); iv[i] |= hex_decode(iv[2*i + 1]); } @@ -391,7 +392,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, /* decode file */ if(libssh2_base64_decode(session, (char **)&f, &f_len, - b64data, b64datalen)) { + b64data, (unsigned int)b64datalen)) { ret = -1; goto out; } diff --git a/src/publickey.c b/src/publickey.c index ac6d4ec111..05ec84e50d 100644 --- a/src/publickey.c +++ b/src/publickey.c @@ -272,7 +272,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey) return 0; publickey_status_error(pkey, session, status); - return -1; + goto err_exit; } default: LIBSSH2_FREE(session, data); @@ -287,7 +287,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey) data = NULL; } } - /* never reached, but include `return` to silence compiler warnings */ + err_exit: return -1; } @@ -639,25 +639,25 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, } pkey->add_s = pkey->add_packet; - _libssh2_htonu32(pkey->add_s, packet_len - 4); + _libssh2_htonu32(pkey->add_s, (uint32_t)(packet_len - 4)); pkey->add_s += 4; _libssh2_htonu32(pkey->add_s, sizeof("add") - 1); pkey->add_s += 4; memcpy(pkey->add_s, "add", sizeof("add") - 1); pkey->add_s += sizeof("add") - 1; if(pkey->version == 1) { - _libssh2_htonu32(pkey->add_s, comment_len); + _libssh2_htonu32(pkey->add_s, (uint32_t)comment_len); pkey->add_s += 4; if(comment) { memcpy(pkey->add_s, comment, comment_len); pkey->add_s += comment_len; } - _libssh2_htonu32(pkey->add_s, name_len); + _libssh2_htonu32(pkey->add_s, (uint32_t)name_len); pkey->add_s += 4; memcpy(pkey->add_s, name, name_len); pkey->add_s += name_len; - _libssh2_htonu32(pkey->add_s, blob_len); + _libssh2_htonu32(pkey->add_s, (uint32_t)blob_len); pkey->add_s += 4; memcpy(pkey->add_s, blob, blob_len); pkey->add_s += blob_len; @@ -665,23 +665,23 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, else { /* Version == 2 */ - _libssh2_htonu32(pkey->add_s, name_len); + _libssh2_htonu32(pkey->add_s, (uint32_t)name_len); pkey->add_s += 4; memcpy(pkey->add_s, name, name_len); pkey->add_s += name_len; - _libssh2_htonu32(pkey->add_s, blob_len); + _libssh2_htonu32(pkey->add_s, (uint32_t)blob_len); pkey->add_s += 4; memcpy(pkey->add_s, blob, blob_len); pkey->add_s += blob_len; *(pkey->add_s++) = overwrite ? 0x01 : 0; - _libssh2_htonu32(pkey->add_s, num_attrs); + _libssh2_htonu32(pkey->add_s, (uint32_t)num_attrs); pkey->add_s += 4; for(i = 0; i < num_attrs; i++) { - _libssh2_htonu32(pkey->add_s, attrs[i].name_len); + _libssh2_htonu32(pkey->add_s, (uint32_t)attrs[i].name_len); pkey->add_s += 4; memcpy(pkey->add_s, attrs[i].name, attrs[i].name_len); pkey->add_s += attrs[i].name_len; - _libssh2_htonu32(pkey->add_s, attrs[i].value_len); + _libssh2_htonu32(pkey->add_s, (uint32_t)attrs[i].value_len); pkey->add_s += 4; memcpy(pkey->add_s, attrs[i].value, attrs[i].value_len); pkey->add_s += attrs[i].value_len; @@ -758,17 +758,17 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, } pkey->remove_s = pkey->remove_packet; - _libssh2_htonu32(pkey->remove_s, packet_len - 4); + _libssh2_htonu32(pkey->remove_s, (uint32_t)(packet_len - 4)); pkey->remove_s += 4; _libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1); pkey->remove_s += 4; memcpy(pkey->remove_s, "remove", sizeof("remove") - 1); pkey->remove_s += sizeof("remove") - 1; - _libssh2_htonu32(pkey->remove_s, name_len); + _libssh2_htonu32(pkey->remove_s, (uint32_t)name_len); pkey->remove_s += 4; memcpy(pkey->remove_s, name, name_len); pkey->remove_s += name_len; - _libssh2_htonu32(pkey->remove_s, blob_len); + _libssh2_htonu32(pkey->remove_s, (uint32_t)blob_len); pkey->remove_s += 4; memcpy(pkey->remove_s, blob, blob_len); pkey->remove_s += blob_len; @@ -835,7 +835,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, pkey->listFetch_data = NULL; pkey->listFetch_s = pkey->listFetch_buffer; - _libssh2_htonu32(pkey->listFetch_s, buffer_len - 4); + _libssh2_htonu32(pkey->listFetch_s, (uint32_t)(buffer_len - 4)); pkey->listFetch_s += 4; _libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1); pkey->listFetch_s += 4; diff --git a/src/scp.c b/src/scp.c index fd797ab6db..116b328365 100644 --- a/src/scp.c +++ b/src/scp.c @@ -122,9 +122,9 @@ until then it is kept static and in this source file. */ -static unsigned +static size_t shell_quotearg(const char *path, unsigned char *buf, - unsigned bufsize) + size_t bufsize) { const char *src; unsigned char *dst, *endp; @@ -270,7 +270,7 @@ shell_quotearg(const char *path, unsigned char *buf, static LIBSSH2_CHANNEL * scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) { - int cmd_len; + size_t cmd_len; int rc; int tmp_err_code; const char *tmp_err_msg; @@ -364,8 +364,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) } if(session->scpRecv_state == libssh2_NB_state_sent1) { - rc = _libssh2_channel_write(session->scpRecv_channel, 0, - session->scpRecv_response, 1); + rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0, + session->scpRecv_response, 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending initial wakeup"); @@ -388,10 +388,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) unsigned char *s, *p; if(session->scpRecv_state == libssh2_NB_state_sent2) { - rc = _libssh2_channel_read(session->scpRecv_channel, 0, - (char *) session-> - scpRecv_response + - session->scpRecv_response_len, 1); + rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0, + (char *) session-> + scpRecv_response + + session->scpRecv_response_len, + 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for SCP response"); @@ -550,8 +551,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) } if(session->scpRecv_state == libssh2_NB_state_sent3) { - rc = _libssh2_channel_write(session->scpRecv_channel, 0, - session->scpRecv_response, 1); + rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0, + session->scpRecv_response, 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting to send SCP ACK"); @@ -587,10 +588,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) char *s, *p, *e = NULL; if(session->scpRecv_state == libssh2_NB_state_sent5) { - rc = _libssh2_channel_read(session->scpRecv_channel, 0, - (char *) session-> - scpRecv_response + - session->scpRecv_response_len, 1); + rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0, + (char *) session-> + scpRecv_response + + session->scpRecv_response_len, + 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for SCP response"); @@ -714,8 +716,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) } if(session->scpRecv_state == libssh2_NB_state_sent6) { - rc = _libssh2_channel_write(session->scpRecv_channel, 0, - session->scpRecv_response, 1); + rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0, + session->scpRecv_response, 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending SCP ACK"); @@ -833,7 +835,7 @@ static LIBSSH2_CHANNEL * scp_send(LIBSSH2_SESSION * session, const char *path, int mode, libssh2_int64_t size, time_t mtime, time_t atime) { - int cmd_len; + size_t cmd_len; int rc; int tmp_err_code; const char *tmp_err_msg; @@ -923,8 +925,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, if(session->scpSend_state == libssh2_NB_state_sent1) { /* Wait for ACK */ - rc = _libssh2_channel_read(session->scpSend_channel, 0, - (char *) session->scpSend_response, 1); + rc = (int)_libssh2_channel_read(session->scpSend_channel, 0, + (char *) session->scpSend_response, 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response from remote"); @@ -958,9 +960,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, /* Send mtime and atime to be used for file */ if(mtime || atime) { if(session->scpSend_state == libssh2_NB_state_sent2) { - rc = _libssh2_channel_write(session->scpSend_channel, 0, - session->scpSend_response, - session->scpSend_response_len); + rc = (int)_libssh2_channel_write(session->scpSend_channel, 0, + session->scpSend_response, + session->scpSend_response_len); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending time data for SCP file"); @@ -977,8 +979,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, if(session->scpSend_state == libssh2_NB_state_sent3) { /* Wait for ACK */ - rc = _libssh2_channel_read(session->scpSend_channel, 0, - (char *) session->scpSend_response, 1); + rc = (int)_libssh2_channel_read(session->scpSend_channel, 0, + (char *) session->scpSend_response, + 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response"); @@ -1026,9 +1029,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, } if(session->scpSend_state == libssh2_NB_state_sent5) { - rc = _libssh2_channel_write(session->scpSend_channel, 0, - session->scpSend_response, - session->scpSend_response_len); + rc = (int)_libssh2_channel_write(session->scpSend_channel, 0, + session->scpSend_response, + session->scpSend_response_len); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block send core file data for SCP file"); @@ -1045,8 +1048,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, if(session->scpSend_state == libssh2_NB_state_sent6) { /* Wait for ACK */ - rc = _libssh2_channel_read(session->scpSend_channel, 0, - (char *) session->scpSend_response, 1); + rc = (int)_libssh2_channel_read(session->scpSend_channel, 0, + (char *) session->scpSend_response, + 1); if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for response"); @@ -1074,8 +1078,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, } /* Read the remote error message */ - rc = _libssh2_channel_read(session->scpSend_channel, 0, - err_msg, err_len); + rc = (int)_libssh2_channel_read(session->scpSend_channel, 0, + err_msg, err_len); if(rc > 0) { err_msg[err_len] = 0; _libssh2_debug((session, LIBSSH2_TRACE_SCP, diff --git a/src/session.c b/src/session.c index 04f58bfe31..77da310596 100644 --- a/src/session.c +++ b/src/session.c @@ -330,6 +330,8 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ #endif #ifdef HAVE_DISABLED_NONBLOCKING + (void)sockfd; + (void)nonblock; return 0; /* returns success */ #undef SETBLOCK #define SETBLOCK 6 @@ -409,6 +411,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd) #endif #ifdef HAVE_DISABLED_NONBLOCKING + (void)sockfd; return 1; /* returns blocking */ #undef GETBLOCK #define GETBLOCK 7 @@ -651,7 +654,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) sockets[0].events |= POLLOUT; - rc = poll(sockets, 1, has_timeout?ms_to_next: -1); + rc = poll(sockets, 1, has_timeout ? (int)ms_to_next : -1); } #else { @@ -662,7 +665,11 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) struct timeval tv; tv.tv_sec = ms_to_next / 1000; +#ifdef WIN32 + tv.tv_usec = (long)((ms_to_next - tv.tv_sec*1000) * 1000); +#else tv.tv_usec = (ms_to_next - tv.tv_sec*1000) * 1000; +#endif if(dir & LIBSSH2_SESSION_BLOCK_INBOUND) { FD_ZERO(&rfd); @@ -676,7 +683,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) writefd = &wfd; } - rc = select(session->socket_fd + 1, readfd, writefd, NULL, + rc = select((int)(session->socket_fd + 1), readfd, writefd, NULL, has_timeout ? &tv : NULL); } #endif @@ -1538,7 +1545,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) switch(fds[i].type) { case LIBSSH2_POLLFD_SOCKET: sockets[i].fd = fds[i].fd.socket; - sockets[i].events = fds[i].events; + sockets[i].events = (short)fds[i].events; sockets[i].revents = 0; break; @@ -1705,7 +1712,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) struct timeval tv_begin, tv_end; _libssh2_gettimeofday((struct timeval *) &tv_begin, NULL); - sysret = poll(sockets, nfds, timeout_remaining); + sysret = poll(sockets, nfds, (int)timeout_remaining); _libssh2_gettimeofday((struct timeval *) &tv_end, NULL); timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000; timeout_remaining -= (tv_end.tv_usec - tv_begin.tv_usec) / 1000; @@ -1714,7 +1721,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) /* If the platform doesn't support gettimeofday, * then just make the call non-blocking and walk away */ - sysret = poll(sockets, nfds, timeout_remaining); + sysret = poll(sockets, nfds, (int)timeout_remaining); timeout_remaining = 0; #endif /* HAVE_GETTIMEOFDAY */ @@ -1768,7 +1775,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) struct timeval tv_begin, tv_end; _libssh2_gettimeofday((struct timeval *) &tv_begin, NULL); - sysret = select(maxfd + 1, &rfds, &wfds, NULL, &tv); + sysret = select((int)(maxfd + 1), &rfds, &wfds, NULL, &tv); _libssh2_gettimeofday((struct timeval *) &tv_end, NULL); timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000; @@ -1778,7 +1785,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) /* If the platform doesn't support gettimeofday, * then just make the call non-blocking and walk away */ - sysret = select(maxfd + 1, &rfds, &wfds, NULL, &tv); + sysret = select((int)(maxfd + 1), &rfds, &wfds, NULL, &tv); timeout_remaining = 0; #endif diff --git a/src/sftp.c b/src/sftp.c index 707a18d628..af44877ec5 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -649,24 +649,24 @@ sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs) return 4; } - _libssh2_store_u32(&s, attrs->flags & flag_mask); + _libssh2_store_u32(&s, (uint32_t)(attrs->flags & flag_mask)); if(attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) { _libssh2_store_u64(&s, attrs->filesize); } if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) { - _libssh2_store_u32(&s, attrs->uid); - _libssh2_store_u32(&s, attrs->gid); + _libssh2_store_u32(&s, (uint32_t)attrs->uid); + _libssh2_store_u32(&s, (uint32_t)attrs->gid); } if(attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) { - _libssh2_store_u32(&s, attrs->permissions); + _libssh2_store_u32(&s, (uint32_t)attrs->permissions); } if(attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) { - _libssh2_store_u32(&s, attrs->atime); - _libssh2_store_u32(&s, attrs->mtime); + _libssh2_store_u32(&s, (uint32_t)attrs->atime); + _libssh2_store_u32(&s, (uint32_t)attrs->mtime); } return (s - p); @@ -1118,9 +1118,9 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, if(sftp->open_state == libssh2_NB_state_idle) { /* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) + flags(4) */ - sftp->open_packet_len = filename_len + 13 + + sftp->open_packet_len = (uint32_t)(filename_len + 13 + (open_file? (4 + - sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0); + sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0)); /* surprise! this starts out with nothing sent */ sftp->open_packet_sent = 0; @@ -1185,7 +1185,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, } if(sftp->open_state == libssh2_NB_state_sent) { - size_t data_len; + size_t data_len = 0; unsigned char *data; static const unsigned char fopen_responses[2] = { SSH_FXP_HANDLE, SSH_FXP_STATUS }; @@ -1453,8 +1453,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, allows, expand it! */ rc = _libssh2_channel_receive_window_adjust(sftp->channel, - max_read_ahead*8, - 1, NULL); + (uint32_t)(max_read_ahead * 8), + 1, NULL); /* if this returns EAGAIN, we will get back to this function at next call */ assert(rc != LIBSSH2_ERROR_EAGAIN || !filep->data_left); @@ -1469,12 +1469,12 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, /* 25 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) + offset(8) + count(4) */ - uint32_t packet_len = (uint32_t)handle->handle_len + 25; + uint32_t packet_len = (uint32_t)(handle->handle_len + 25); uint32_t request_id; - uint32_t size = count; + uint32_t size = (uint32_t)count; if(size < buffer_size) - size = buffer_size; + size = (uint32_t)buffer_size; if(size > MAX_SFTP_READ_SIZE) size = MAX_SFTP_READ_SIZE; @@ -1668,7 +1668,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, /* getting the full packet would overflow the buffer, so only get the correct amount and keep the remainder */ - rc32 = (uint32_t)buffer_size - bytes_in_buffer; + rc32 = (uint32_t)(buffer_size - bytes_in_buffer); /* store data to keep for next call */ filep->data = data; @@ -1755,7 +1755,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t data_len = 0; uint32_t num_names; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ - uint32_t packet_len = handle->handle_len + 13; + uint32_t packet_len = (uint32_t)(handle->handle_len + 13); unsigned char *s, *data; static const unsigned char read_responses[2] = { SSH_FXP_NAME, SSH_FXP_STATUS }; @@ -2057,12 +2057,12 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, while(count) { /* TODO: Possibly this should have some logic to prevent a very very small fraction to be left but lets ignore that for now */ - uint32_t size = MIN(MAX_SFTP_OUTGOING_SIZE, count); + uint32_t size = (uint32_t)(MIN(MAX_SFTP_OUTGOING_SIZE, count)); uint32_t request_id; /* 25 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) + offset(8) + count(4) */ - packet_len = handle->handle_len + size + 25; + packet_len = (uint32_t)(handle->handle_len + size + 25); chunk = LIBSSH2_ALLOC(session, packet_len + sizeof(struct sftp_pipeline_chunk)); @@ -2245,7 +2245,7 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle) LIBSSH2_SESSION *session = channel->session; /* 34 = packet_len(4) + packet_type(1) + request_id(4) + string_len(4) + strlen("fsync@openssh.com")(17) + handle_len(4) */ - uint32_t packet_len = handle->handle_len + 34; + uint32_t packet_len = (uint32_t)(handle->handle_len + 34); size_t data_len = 0; unsigned char *packet, *s, *data = NULL; ssize_t rc; @@ -2353,8 +2353,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SESSION *session = channel->session; size_t data_len = 0; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ - uint32_t packet_len = - handle->handle_len + 13 + (setstat ? sftp_attrsize(attrs->flags) : 0); + uint32_t packet_len = (uint32_t)(handle->handle_len + 13 + + (setstat ? sftp_attrsize(attrs->flags) : 0)); unsigned char *s, *data = NULL; static const unsigned char fstat_responses[2] = { SSH_FXP_ATTRS, SSH_FXP_STATUS }; @@ -2578,7 +2578,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) LIBSSH2_SESSION *session = channel->session; size_t data_len = 0; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ - uint32_t packet_len = handle->handle_len + 13; + uint32_t packet_len = (uint32_t)(handle->handle_len + 13); unsigned char *s, *data = NULL; int rc = 0; @@ -2709,7 +2709,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, size_t data_len = 0; int retcode; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) */ - uint32_t packet_len = filename_len + 13; + uint32_t packet_len = (uint32_t)(filename_len + 13); unsigned char *s, *data = NULL; int rc; @@ -2846,7 +2846,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, _libssh2_store_str(&sftp->rename_s, dest_filename, dest_filename_len); if(sftp->version >= 5) - _libssh2_store_u32(&sftp->rename_s, flags); + _libssh2_store_u32(&sftp->rename_s, (uint32_t)flags); sftp->rename_state = libssh2_NB_state_created; } @@ -2955,7 +2955,7 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) /* 17 = packet_len(4) + packet_type(1) + request_id(4) + ext_len(4) + handle_len (4) */ /* 20 = strlen ("fstatvfs@openssh.com") */ - uint32_t packet_len = handle->handle_len + 20 + 17; + uint32_t packet_len = (uint32_t)(handle->handle_len + 20 + 17); unsigned char *packet, *s, *data = NULL; ssize_t rc; unsigned int flag; @@ -3252,7 +3252,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, "packet"); } - _libssh2_store_u32(&s, packet_len - 4); + _libssh2_store_u32(&s, (uint32_t)(packet_len - 4)); *(s++) = SSH_FXP_MKDIR; sftp->mkdir_request_id = sftp->request_id++; _libssh2_store_u32(&s, sftp->mkdir_request_id); @@ -3359,7 +3359,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, "packet"); } - _libssh2_store_u32(&s, packet_len - 4); + _libssh2_store_u32(&s, (uint32_t)(packet_len - 4)); *(s++) = SSH_FXP_RMDIR; sftp->rmdir_request_id = sftp->request_id++; _libssh2_store_u32(&s, sftp->rmdir_request_id); @@ -3467,7 +3467,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, "packet"); } - _libssh2_store_u32(&s, packet_len - 4); + _libssh2_store_u32(&s, (uint32_t)(packet_len - 4)); switch(stat_type) { case LIBSSH2_SFTP_SETSTAT: @@ -3612,7 +3612,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_SFTP_REALPATH) ? "realpath" : "symlink", path)); - _libssh2_store_u32(&s, packet_len - 4); + _libssh2_store_u32(&s, (uint32_t)(packet_len - 4)); switch(link_type) { case LIBSSH2_SFTP_REALPATH: diff --git a/src/transport.c b/src/transport.c index c0cf749d87..83a48371a3 100644 --- a/src/transport.c +++ b/src/transport.c @@ -864,7 +864,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, /* store packet_length, which is the size of the whole packet except the MAC and the packet_length field itself */ - _libssh2_htonu32(p->outbuf, packet_length - 4); + _libssh2_htonu32(p->outbuf, (uint32_t)(packet_length - 4)); /* store padding_length */ p->outbuf[4] = (unsigned char)padding_length; diff --git a/src/userauth.c b/src/userauth.c index 1533edc450..4201113476 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -611,7 +611,8 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, } if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, - (char *) sp1, sp2 - sp1)) { + (const char *) sp1, + (unsigned int)(sp2 - sp1))) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid key data, not base64 encoded"); @@ -715,7 +716,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, } if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, - (char *) sp1, sp2 - sp1)) { + (const char *) sp1, + (unsigned int)(sp2 - sp1))) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid key data, not base64 encoded"); @@ -938,7 +940,7 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, *sig_len = p - *sig; - _libssh2_store_u32(&x, *sig_len - 4); + _libssh2_store_u32(&x, (uint32_t)(*sig_len - 4)); } else { _libssh2_debug((session, @@ -1144,8 +1146,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, session->userauth_host_packet + session->userauth_host_packet_len; _libssh2_store_u32(&session->userauth_host_s, - 4 + session->userauth_host_method_len + - 4 + sig_len); + (uint32_t)(4 + session->userauth_host_method_len + + 4 + sig_len)); _libssh2_store_str(&session->userauth_host_s, (const char *)session->userauth_host_method, session->userauth_host_method_len); @@ -1709,8 +1711,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, "sk-ssh-ed25519@openssh.com", session->userauth_pblc_method_len) == 0) { _libssh2_store_u32(&s, - 4 + session->userauth_pblc_method_len + - sig_len); + (uint32_t)(4 + session->userauth_pblc_method_len + + sig_len)); _libssh2_store_str(&s, (const char *)session->userauth_pblc_method, session->userauth_pblc_method_len); memcpy(s, sig, sig_len); @@ -1718,8 +1720,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, } else { _libssh2_store_u32(&s, - 4 + session->userauth_pblc_method_len + 4 + - sig_len); + (uint32_t)(4 + session->userauth_pblc_method_len + + 4 + sig_len)); _libssh2_store_str(&s, (const char *)session->userauth_pblc_method, session->userauth_pblc_method_len); _libssh2_store_str(&s, (const char *)sig, sig_len); diff --git a/src/wincng.c b/src/wincng.c index 9a88379ae5..9b97652aa4 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -668,7 +668,7 @@ _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, memcpy(data, sig, datalen); ret = BCryptVerifySignature(ctx->hKey, pPaddingInfo, - hash, hashlen, data, datalen, flags); + hash, (ULONG)hashlen, data, datalen, flags); _libssh2_wincng_safe_free(hash, hashlen); _libssh2_wincng_safe_free(data, datalen); @@ -2120,13 +2120,13 @@ _libssh2_wincng_bignum_rand(_libssh2_bn *rnd, int bits, int top, int bottom) bits = 8; /* fill most significant byte with zero padding */ - bignum[0] &= ((1 << bits) - 1); + bignum[0] &= (unsigned char)((1 << bits) - 1); /* set most significant bits in most significant byte */ if(top == 0) - bignum[0] |= (1 << (bits - 1)); + bignum[0] |= (unsigned char)(1 << (bits - 1)); else if(top == 1) - bignum[0] |= (3 << (bits - 2)); + bignum[0] |= (unsigned char)(3 << (bits - 2)); /* make odd by setting first bit in least significant byte */ if(bottom) @@ -2551,7 +2551,8 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, unsigned char *start, *end; BCRYPT_DH_KEY_BLOB *public_blob = NULL; DWORD key_length_bytes = max(f->length, dhctx->dh_params->cbKeyLength); - DWORD public_blob_len = sizeof(*public_blob) + 3 * key_length_bytes; + DWORD public_blob_len = (DWORD)(sizeof(*public_blob) + + 3 * key_length_bytes); { /* Populate a BCRYPT_DH_KEY_BLOB; after the header follows the diff --git a/src/wincng.h b/src/wincng.h index f9791650f4..aa0e655f23 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -148,10 +148,11 @@ typedef struct __libssh2_wincng_hash_ctx { #define libssh2_sha1_ctx _libssh2_wincng_hash_ctx #define libssh2_sha1_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \ + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \ SHA_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha1_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) + _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha1_final(ctx, hash) \ _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha1(data, datalen, hash) \ @@ -160,32 +161,37 @@ typedef struct __libssh2_wincng_hash_ctx { #define libssh2_sha256_ctx _libssh2_wincng_hash_ctx #define libssh2_sha256_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \ + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \ SHA256_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha256_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) + _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha256_final(ctx, hash) \ _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha256(data, datalen, hash) \ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA256, \ hash, SHA256_DIGEST_LENGTH) + #define libssh2_sha384_ctx _libssh2_wincng_hash_ctx #define libssh2_sha384_init(ctx) \ (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA384, \ - SHA384_DIGEST_LENGTH, NULL, 0) == 0) + SHA384_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha384_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) + _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha384_final(ctx, hash) \ - _libssh2_wincng_hash_final(&ctx, hash) + _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha384(data, datalen, hash) \ -_libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \ - hash, SHA384_DIGEST_LENGTH) + _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \ + hash, SHA384_DIGEST_LENGTH) + #define libssh2_sha512_ctx _libssh2_wincng_hash_ctx #define libssh2_sha512_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA512, \ + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA512, \ SHA512_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha512_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) + _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha512_final(ctx, hash) \ _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha512(data, datalen, hash) \ @@ -194,10 +200,11 @@ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \ #define libssh2_md5_ctx _libssh2_wincng_hash_ctx #define libssh2_md5_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \ + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \ MD5_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_md5_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) + _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_md5_final(ctx, hash) \ _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_md5(data, datalen, hash) \ @@ -212,20 +219,25 @@ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \ #define libssh2_hmac_ctx_init(ctx) #define libssh2_hmac_sha1_init(ctx, key, keylen) \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA1, \ - SHA_DIGEST_LENGTH, key, keylen) + SHA_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_md5_init(ctx, key, keylen) \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacMD5, \ - MD5_DIGEST_LENGTH, key, keylen) + MD5_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_ripemd160_init(ctx, key, keylen) /* not implemented */ #define libssh2_hmac_sha256_init(ctx, key, keylen) \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA256, \ - SHA256_DIGEST_LENGTH, key, keylen) + SHA256_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_sha512_init(ctx, key, keylen) \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA512, \ - SHA512_DIGEST_LENGTH, key, keylen) + SHA512_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) + _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_hmac_final(ctx, hash) \ _libssh2_wincng_hmac_final(&ctx, hash) #define libssh2_hmac_cleanup(ctx) \ @@ -396,7 +408,7 @@ _libssh2_bn *_libssh2_wincng_bignum_init(void); #define _libssh2_bn_set_word(bn, word) \ _libssh2_wincng_bignum_set_word(bn, word) #define _libssh2_bn_from_bin(bn, len, bin) \ - _libssh2_wincng_bignum_from_bin(bn, len, bin) + _libssh2_wincng_bignum_from_bin(bn, (unsigned long) len, bin) #define _libssh2_bn_to_bin(bn, bin) \ _libssh2_wincng_bignum_to_bin(bn, bin) #define _libssh2_bn_bytes(bn) bn->length From 463449fb9ee7dbe5fbe71a28494579a9a6890d6d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 26 Mar 2023 09:36:13 +0000 Subject: [PATCH 159/424] src: silence compiler warnings 2 (ZLIB interface) Silence warnings in the ZLIB interface by adding casts and changing types. See PR for individual commits. Cherry-picked from #846 Closes #878 --- src/comp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/comp.c b/src/comp.c index 96ed2e98fd..88445272f6 100644 --- a/src/comp.c +++ b/src/comp.c @@ -189,11 +189,11 @@ comp_method_zlib_comp(LIBSSH2_SESSION *session, void **abstract) { z_stream *strm = *abstract; - int out_maxlen = *dest_len; + uInt out_maxlen = (uInt)*dest_len; int status; strm->next_in = (unsigned char *) src; - strm->avail_in = src_len; + strm->avail_in = (uInt)src_len; strm->next_out = dest; strm->avail_out = out_maxlen; @@ -227,10 +227,10 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session, /* A short-term alloc of a full data chunk is better than a series of reallocs */ char *out; - size_t out_maxlen = src_len; + size_t out_maxlen; if(src_len <= SIZE_MAX / 4) - out_maxlen = src_len * 4; + out_maxlen = (uInt)src_len * 4; else out_maxlen = payload_limit; @@ -247,10 +247,11 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session, out_maxlen = payload_limit; strm->next_in = (unsigned char *) src; - strm->avail_in = src_len; - strm->next_out = (unsigned char *) LIBSSH2_ALLOC(session, out_maxlen); + strm->avail_in = (uInt)src_len; + strm->next_out = (unsigned char *) LIBSSH2_ALLOC(session, + (uInt)out_maxlen); out = (char *) strm->next_out; - strm->avail_out = out_maxlen; + strm->avail_out = (uInt)out_maxlen; if(!strm->next_out) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate decompression buffer"); @@ -299,7 +300,7 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session, } out = newout; strm->next_out = (unsigned char *) out + out_ofs; - strm->avail_out = out_maxlen - out_ofs; + strm->avail_out = (uInt)(out_maxlen - out_ofs); } *dest = (unsigned char *) out; From 5a96f494ee0b00282afb2db2e091246fc5e1774a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 26 Mar 2023 22:42:04 +0000 Subject: [PATCH 160/424] src: silence compiler warnings 3 (change types) Apply type changes to avoid casts and warnings. In most cases this means changing to a larger type, usually `size_t` or `ssize_t`. Change signedness in a few places. Also introduce new variables to avoid reusing them for multiple purposes, to avoid casts and warnings. - add FIXME for public `libssh2_sftp_readdir_ex()` return type. - fix `_libssh2_mbedtls_rsa_sha2_verify()` to verify if `sig_len` is large enough. - fix `_libssh2_dh_key_pair()` in `wincng.c` to return error if `group_order` input is negative. Maybe we should also reject zero? - bump `_libssh2_random()` size type `int` -> `size_t`. Add checks for WinCNG and OpenSSL to return error if requested more than they support (`ULONG_MAX`, `INT_MAX` respectively). - change `_libssh2_ntohu32()` return value `unsigned int` -> `uint32_t`. - fix `_libssh2_mbedtls_bignum_random()` to check for a negative `top` input. - size down `_libssh2_wincng_key_sha_verify()` `hashlen` to match Windows'. - fix `session_disconnect()` to limit length of `lang_len` (to 256 bytes). - fix bad syntax in an `assert()`. - add a few `const` to casts. - `while(1)` -> `for(;;)`. - add casts that didn't fit into #876. - update `docs/HACKING-CRYPTO` with new sizes. May need review for OS400QC3: /cc @monnerat @jonrumsey See warning details in the PR's individual commits. Cherry-picked from #846 Closes #879 --- docs/HACKING-CRYPTO | 24 ++++---- src/channel.c | 2 +- src/crypto.h | 12 ++-- src/kex.c | 55 +++++++++--------- src/libgcrypt.c | 10 ++-- src/libssh2_priv.h | 8 +-- src/mac.c | 32 +++++----- src/mac.h | 4 +- src/mbedtls.c | 47 ++++++++------- src/mbedtls.h | 2 +- src/misc.c | 10 ++-- src/misc.h | 2 +- src/openssl.c | 34 +++++++---- src/openssl.h | 15 +++-- src/os400qc3.c | 10 ++-- src/os400qc3.h | 2 +- src/packet.c | 16 ++--- src/pem.c | 14 ++--- src/publickey.c | 70 +++++++++++----------- src/session.c | 31 +++++----- src/sftp.c | 138 +++++++++++++++++++++++--------------------- src/transport.c | 25 ++++---- src/userauth.c | 28 ++++----- src/userauth.h | 4 +- src/wincng.c | 56 +++++++++++------- src/wincng.h | 10 ++-- 26 files changed, 356 insertions(+), 305 deletions(-) diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index c0fe3711a7..e330a7e7ed 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -152,7 +152,7 @@ Note: if the ctx parameter is modified by the underlying code, this procedure must be implemented as a macro to map ctx --> &ctx. int libssh2_sha256(const unsigned char *message, - unsigned long len, + size_t len, unsigned char output[SHA256_DIGEST_LENGTH]); Computes the SHA-256 signature over the given message of length len and store the result into the output buffer. @@ -197,7 +197,7 @@ Note: if the ctx parameter is modified by the underlying code, this procedure must be implemented as a macro to map ctx --> &ctx. int libssh2_sha384(const unsigned char *message, - unsigned long len, + size_t len, unsigned char output[SHA384_DIGEST_LENGTH]); Computes the SHA-384 signature over the given message of length len and store the result into the output buffer. @@ -231,7 +231,7 @@ Note: if the ctx parameter is modified by the underlying code, this procedure must be implemented as a macro to map ctx --> &ctx. int libssh2_sha512(const unsigned char *message, - unsigned long len, + size_t len, unsigned char output[SHA512_DIGEST_LENGTH]); Computes the SHA-512 signature over the given message of length len and store the result into the output buffer. @@ -599,7 +599,7 @@ This procedure is already prototyped in crypto.h. int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, LIBSSH2_SESSION *session, const char *data, - size_t data_len, + size_t data_len, unsigned const char *passphrase); Gets an RSA private key from data into a new RSA context. Must call _libssh2_init_if_needed(). @@ -608,8 +608,8 @@ This procedure is already prototyped in crypto.h. int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa, const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len); + size_t sig_len, + const unsigned char *m, size_t m_len); Verify (sig, sig_len) signature of (m, m_len) using an SHA-1 hash and the RSA context. Return 0 if OK, else -1. @@ -661,8 +661,8 @@ Note: this procedure is not used if macro _libssh2_rsa_sha1_signv() is defined. int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsa, size_t hash_len, const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len); + size_t sig_len, + const unsigned char *m, size_t m_len); Verify (sig, sig_len) signature of (m, m_len) using an SHA-2 hash based on hash length and the RSA context. Return 0 if OK, else -1. @@ -717,7 +717,7 @@ This procedure is already prototyped in crypto.h. int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx, const unsigned char *sig, - const unsigned char *m, unsigned long m_len); + const unsigned char *m, size_t m_len); Verify (sig, siglen) signature of (m, m_len) using an SHA-1 hash and the DSA context. Returns 0 if OK, else -1. @@ -725,7 +725,7 @@ This procedure is already prototyped in crypto.h. int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx, const unsigned char *hash, - unsigned long hash_len, unsigned char *sig); + size_t hash_len, unsigned char *sig); DSA signs the (hash, hash_len) data using SHA-1 and store the signature at sig. Returns 0 if OK, else -1. This procedure is already prototyped in crypto.h. @@ -874,7 +874,7 @@ This procedure is already prototyped in crypto.h. int _libssh2_ed25519_new_public(libssh2_ed25519_ctx **ed_ctx, LIBSSH2_SESSION *session, const unsigned char *raw_pub_key, - const uint8_t key_len); + const size_t key_len); Stores at ed_ctx a new ED25519 key context for raw public key (raw_pub_key, key_len). Return 0 if OK, else -1. @@ -927,7 +927,7 @@ In example, this is needed to preset unused structure slacks on platforms requiring it. If this is not needed, it should be defined as an empty macro. -int _libssh2_random(unsigned char *buf, int len); +int _libssh2_random(unsigned char *buf, size_t len); Store len random bytes at buf. Returns 0 if OK, else -1. diff --git a/src/channel.c b/src/channel.c index 1e93b27471..832d69dbbb 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2160,7 +2160,7 @@ LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, size_t buflen) { - int rc; + ssize_t rc; unsigned long recv_window; if(!channel) diff --git a/src/crypto.h b/src/crypto.h index 0abbd5b881..6fa0a85185 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -85,8 +85,8 @@ int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, unsigned const char *passphrase); int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len); + size_t sig_len, + const unsigned char *m, size_t m_len); int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, libssh2_rsa_ctx * rsactx, const unsigned char *hash, @@ -103,8 +103,8 @@ int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsa, size_t hash_len, const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len); + size_t sig_len, + const unsigned char *m, size_t m_len); #endif int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, LIBSSH2_SESSION * session, @@ -130,7 +130,7 @@ int _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, unsigned const char *passphrase); int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, const unsigned char *sig, - const unsigned char *m, unsigned long m_len); + const unsigned char *m, size_t m_len); int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, const unsigned char *hash, unsigned long hash_len, unsigned char *sig); @@ -246,7 +246,7 @@ int _libssh2_ed25519_new_public(libssh2_ed25519_ctx **ed_ctx, LIBSSH2_SESSION *session, const unsigned char *raw_pub_key, - const uint8_t key_len); + const size_t key_len); int _libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session, diff --git a/src/kex.c b/src/kex.c index 48f8f5cd84..bd7e83de3c 100644 --- a/src/kex.c +++ b/src/kex.c @@ -71,13 +71,13 @@ reqlen, version) \ { \ libssh2_sha##digest_type##_ctx hash; \ - unsigned long len = 0; \ + size_t len = 0; \ if(!(value)) { \ value = LIBSSH2_ALLOC(session, \ reqlen + SHA##digest_type##_DIGEST_LENGTH); \ } \ if(value) \ - while(len < (unsigned long)reqlen) { \ + while(len < (size_t)reqlen) { \ (void)libssh2_sha##digest_type##_init(&hash); \ libssh2_sha##digest_type##_update(hash, \ exchange_state->k_value, \ @@ -217,7 +217,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, unsigned char packet_type_init, unsigned char packet_type_reply, unsigned char *midhash, - unsigned long midhash_len, + size_t midhash_len, kmdhgGPshakex_state_t *exchange_state) { int ret = 0; @@ -285,7 +285,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, } exchange_state->e_packet[0] = packet_type_init; _libssh2_htonu32(exchange_state->e_packet + 1, - exchange_state->e_packet_len - 5); + (uint32_t)(exchange_state->e_packet_len - 5)); if(_libssh2_bn_bits(exchange_state->e) % 8) { _libssh2_bn_to_bin(exchange_state->e, exchange_state->e_packet + 5); @@ -517,7 +517,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, goto clean_exit; } _libssh2_htonu32(exchange_state->k_value, - exchange_state->k_value_len - 4); + (uint32_t)(exchange_state->k_value_len - 4)); if(_libssh2_bn_bits(exchange_state->k) % 8) { _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4); } @@ -610,7 +610,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, exchange_state->e_packet_len - 1); _libssh2_htonu32(exchange_state->h_sig_comp, - exchange_state->f_value_len); + (uint32_t)exchange_state->f_value_len); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 4); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, @@ -992,7 +992,7 @@ typedef int (*diffie_hellman_hash_func_t)(LIBSSH2_SESSION *, unsigned char, unsigned char, unsigned char *, - unsigned long, + size_t, kmdhgGPshakex_state_t *); static int kex_method_diffie_hellman_group14_key_exchange(LIBSSH2_SESSION *session, @@ -3106,8 +3106,8 @@ kex_method_strlen(LIBSSH2_COMMON_METHOD ** method) /* kex_method_list * Generate formatted preference list in buf */ -static size_t -kex_method_list(unsigned char *buf, size_t list_strlen, +static uint32_t +kex_method_list(unsigned char *buf, uint32_t list_strlen, LIBSSH2_COMMON_METHOD ** method) { _libssh2_htonu32(buf, list_strlen); @@ -3118,7 +3118,7 @@ kex_method_list(unsigned char *buf, size_t list_strlen, } while(*method && (*method)->name) { - int mlen = strlen((*method)->name); + uint32_t mlen = (uint32_t)strlen((*method)->name); memcpy(buf, (*method)->name, mlen); buf += mlen; *(buf++) = ','; @@ -3131,7 +3131,7 @@ kex_method_list(unsigned char *buf, size_t list_strlen, #define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) \ - ((prefvar) ? strlen(prefvar) : \ + (uint32_t)((prefvar) ? strlen(prefvar) : \ kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar))) #define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \ @@ -3154,15 +3154,16 @@ static int kexinit(LIBSSH2_SESSION * session) /* 62 = packet_type(1) + cookie(16) + first_packet_follows(1) + reserved(4) + length longs(40) */ size_t data_len = 62; - size_t kex_len, hostkey_len = 0; - size_t crypt_cs_len, crypt_sc_len; - size_t comp_cs_len, comp_sc_len; - size_t mac_cs_len, mac_sc_len; - size_t lang_cs_len, lang_sc_len; unsigned char *data, *s; int rc; if(session->kexinit_state == libssh2_NB_state_idle) { + uint32_t kex_len, hostkey_len; + uint32_t crypt_cs_len, crypt_sc_len; + uint32_t comp_cs_len, comp_sc_len; + uint32_t mac_cs_len, mac_sc_len; + uint32_t lang_cs_len, lang_sc_len; + kex_len = LIBSSH2_METHOD_PREFS_LEN(session->kex_prefs, libssh2_kex_methods); hostkey_len = @@ -3323,12 +3324,12 @@ static int kexinit(LIBSSH2_SESSION * session) * Needle must be precede by BOL or ',', and followed by ',' or EOL */ static unsigned char * -kex_agree_instr(unsigned char *haystack, unsigned long haystack_len, - const unsigned char *needle, unsigned long needle_len) +kex_agree_instr(unsigned char *haystack, size_t haystack_len, + const unsigned char *needle, size_t needle_len) { unsigned char *s; unsigned char *end_haystack; - unsigned long left; + size_t left; if(haystack == NULL || needle == NULL) { return NULL; @@ -3396,8 +3397,8 @@ kex_get_method_by_name(const char *name, size_t name_len, * Agree on a Hostkey which works with this kex */ static int kex_agree_hostkey(LIBSSH2_SESSION * session, - unsigned long kex_flags, - unsigned char *hostkey, unsigned long hostkey_len) + size_t kex_flags, + unsigned char *hostkey, size_t hostkey_len) { const LIBSSH2_HOSTKEY_METHOD **hostkeyp = libssh2_hostkey_methods(); unsigned char *s; @@ -3473,8 +3474,8 @@ static int kex_agree_hostkey(LIBSSH2_SESSION * session, * Agree on a Key Exchange method and a hostkey encoding type */ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex, - unsigned long kex_len, unsigned char *hostkey, - unsigned long hostkey_len) + size_t kex_len, unsigned char *hostkey, + size_t hostkey_len) { const LIBSSH2_KEX_METHOD **kexp = libssh2_kex_methods; unsigned char *s; @@ -3551,7 +3552,7 @@ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex, static int kex_agree_crypt(LIBSSH2_SESSION * session, libssh2_endpoint_data *endpoint, unsigned char *crypt, - unsigned long crypt_len) + size_t crypt_len) { const LIBSSH2_CRYPT_METHOD **cryptp = libssh2_crypt_methods(); unsigned char *s; @@ -3607,7 +3608,7 @@ static int kex_agree_crypt(LIBSSH2_SESSION * session, */ static int kex_agree_mac(LIBSSH2_SESSION * session, libssh2_endpoint_data * endpoint, unsigned char *mac, - unsigned long mac_len) + size_t mac_len) { const LIBSSH2_MAC_METHOD **macp = _libssh2_mac_methods(); unsigned char *s; @@ -3660,7 +3661,7 @@ static int kex_agree_mac(LIBSSH2_SESSION * session, */ static int kex_agree_comp(LIBSSH2_SESSION *session, libssh2_endpoint_data *endpoint, unsigned char *comp, - unsigned long comp_len) + size_t comp_len) { const LIBSSH2_COMP_METHOD **compp = _libssh2_comp_methods(session); unsigned char *s; @@ -3716,7 +3717,7 @@ static int kex_agree_comp(LIBSSH2_SESSION *session, * Decide which specific method to use of the methods offered by each party */ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data, - unsigned data_len) + size_t data_len) { unsigned char *kex, *hostkey, *crypt_cs, *crypt_sc, *comp_cs, *comp_sc, *mac_cs, *mac_sc; diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 66d64092c0..6d7092ee6b 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -88,8 +88,8 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len) + size_t sig_len, + const unsigned char *m, size_t m_len) { unsigned char hash[SHA_DIGEST_LENGTH]; gcry_sexp_t s_sig, s_hash; @@ -525,7 +525,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, const unsigned char *sig, - const unsigned char *m, unsigned long m_len) + const unsigned char *m, size_t m_len) { unsigned char hash[SHA_DIGEST_LENGTH + 1]; gcry_sexp_t s_sig, s_hash; @@ -560,7 +560,7 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, int ret; int cipher = _libssh2_gcry_cipher(algo); int mode = _libssh2_gcry_mode(algo); - int keylen = gcry_cipher_get_algo_keylen(cipher); + size_t keylen = gcry_cipher_get_algo_keylen(cipher); (void) encrypt; @@ -576,7 +576,7 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, } if(mode != GCRY_CIPHER_MODE_STREAM) { - int blklen = gcry_cipher_get_algo_blklen(cipher); + size_t blklen = gcry_cipher_get_algo_blklen(cipher); if(mode == GCRY_CIPHER_MODE_CTR) ret = gcry_cipher_setctr(*h, iv, blklen); else diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index e4bb01756b..b0a44bc7f0 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -410,7 +410,7 @@ struct _LIBSSH2_CHANNEL /* Amount of bytes to be refunded to receive window (but not yet sent) */ uint32_t adjust_queue; /* Data immediately available for reading */ - uint32_t read_avail; + size_t read_avail; LIBSSH2_SESSION *session; @@ -567,7 +567,7 @@ struct transportpacket /* ------------- for outgoing data --------------- */ unsigned char outbuf[MAX_SSH_PACKET_LEN]; /* area for the outgoing data */ - int ototal_num; /* size of outbuf in number of bytes */ + ssize_t ototal_num; /* size of outbuf in number of bytes */ const unsigned char *odata; /* original pointer to the data */ size_t olen; /* original size of the data we stored in outbuf */ @@ -850,8 +850,8 @@ struct _LIBSSH2_SESSION LIBSSH2_CHANNEL *sftpInit_channel; unsigned char sftpInit_buffer[9]; /* sftp_header(5){excludes request_id} + version_id(4) */ - int sftpInit_sent; /* number of bytes from the buffer that have been - sent */ + size_t sftpInit_sent; /* number of bytes from the buffer that have been + sent */ /* State variables used in libssh2_scp_recv() / libssh_scp_recv2() */ libssh2_nonblocking_states scpRecv_state; diff --git a/src/mac.c b/src/mac.c index 5ac71df4ce..146671efe5 100644 --- a/src/mac.c +++ b/src/mac.c @@ -45,8 +45,8 @@ static int mac_none_MAC(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract) + size_t packet_len, const unsigned char *addtl, + size_t addtl_len, void **abstract) { return 0; } @@ -104,9 +104,9 @@ static int mac_method_hmac_sha2_512_hash(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, + size_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract) + size_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; @@ -149,9 +149,9 @@ static int mac_method_hmac_sha2_256_hash(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, + size_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract) + size_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; @@ -194,9 +194,9 @@ static int mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, + size_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract) + size_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; @@ -235,9 +235,9 @@ static int mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, + size_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract) + size_t addtl_len, void **abstract) { unsigned char temp[SHA_DIGEST_LENGTH]; @@ -267,9 +267,9 @@ static int mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, + size_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract) + size_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; @@ -308,9 +308,9 @@ static int mac_method_hmac_md5_96_hash(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, + size_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract) + size_t addtl_len, void **abstract) { unsigned char temp[MD5_DIGEST_LENGTH]; mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len, @@ -339,9 +339,9 @@ static int mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, + size_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, + size_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; diff --git a/src/mac.h b/src/mac.h index 46fce54248..c6e48bba71 100644 --- a/src/mac.h +++ b/src/mac.h @@ -54,8 +54,8 @@ struct _LIBSSH2_MAC_METHOD void **abstract); int (*hash) (LIBSSH2_SESSION * session, unsigned char *buf, uint32_t seqno, const unsigned char *packet, - uint32_t packet_len, const unsigned char *addtl, - uint32_t addtl_len, void **abstract); + size_t packet_len, const unsigned char *addtl, + size_t addtl_len, void **abstract); int (*dtor) (LIBSSH2_SESSION * session, void **abstract); }; diff --git a/src/mbedtls.c b/src/mbedtls.c index d66fc040d3..16abf2f2c5 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -83,7 +83,7 @@ _libssh2_mbedtls_free(void) } int -_libssh2_mbedtls_random(unsigned char *buf, int len) +_libssh2_mbedtls_random(unsigned char *buf, size_t len) { int ret; ret = mbedtls_ctr_drbg_random(&_libssh2_mbedtls_ctr_drbg, buf, len); @@ -91,7 +91,7 @@ _libssh2_mbedtls_random(unsigned char *buf, int len) } static void -_libssh2_mbedtls_safe_free(void *buf, int len) +_libssh2_mbedtls_safe_free(void *buf, size_t len) { if(!buf) return; @@ -267,7 +267,7 @@ _libssh2_mbedtls_bignum_random(_libssh2_bn *bn, int bits, int top, int bottom) { size_t len; int err; - int i; + size_t i; if(!bn || bits <= 0) return -1; @@ -279,7 +279,7 @@ _libssh2_mbedtls_bignum_random(_libssh2_bn *bn, int bits, int top, int bottom) return -1; /* Zero unused bits above the most significant bit*/ - for(i = len*8 - 1; bits <= i; --i) { + for(i = len*8 - 1; (size_t)bits <= i; --i) { err = mbedtls_mpi_set_bit(bn, i, 0); if(err) return -1; @@ -291,10 +291,12 @@ _libssh2_mbedtls_bignum_random(_libssh2_bn *bn, int bits, int top, int bottom) will be set to 1, so that the product of two such random numbers will always have 2*bits length. */ - for(i = 0; i <= top; ++i) { - err = mbedtls_mpi_set_bit(bn, bits-i-1, 1); - if(err) - return -1; + if(top >= 0) { + for(i = 0; i <= (size_t)top; ++i) { + err = mbedtls_mpi_set_bit(bn, bits-i-1, 1); + if(err) + return -1; + } } /* make odd by setting first bit in least significant byte */ @@ -500,7 +502,12 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, { int ret; int md_type; - unsigned char *hash = malloc(hash_len); + unsigned char *hash; + + if(sig_len < mbedtls_rsa_get_len(rsactx)) + return -1; + + hash = malloc(hash_len); if(hash == NULL) return -1; @@ -560,7 +567,6 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, unsigned char *sig; size_t sig_len; int md_type; - (void)hash_len; sig_len = mbedtls_rsa_get_len(rsa); sig = LIBSSH2_ALLOC(session, sig_len); @@ -629,13 +635,13 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, mbedtls_rsa_context *rsa, size_t *keylen) { - int e_bytes, n_bytes; - unsigned long len; + uint32_t e_bytes, n_bytes; + uint32_t len; unsigned char *key; unsigned char *p; - e_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E)); - n_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N)); + e_bytes = (uint32_t)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E)); + n_bytes = (uint32_t)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N)); /* Key form is "ssh-rsa" + e + n. */ len = 4 + 7 + 4 + e_bytes + 4 + n_bytes; @@ -1289,6 +1295,7 @@ _libssh2_mbedtls_mpi_write_binary(unsigned char *buf, size_t bytes) { unsigned char *p = buf; + uint32_t size = (uint32_t)bytes; if(sizeof(&p) / sizeof(p[0]) < 4) { goto done; @@ -1297,19 +1304,19 @@ _libssh2_mbedtls_mpi_write_binary(unsigned char *buf, p += 4; *p = 0; - if(bytes > 0) { - mbedtls_mpi_write_binary(mpi, p + 1, bytes - 1); + if(size > 0) { + mbedtls_mpi_write_binary(mpi, p + 1, size - 1); } - if(bytes > 0 && !(*(p + 1) & 0x80)) { - memmove(p, p + 1, --bytes); + if(size > 0 && !(*(p + 1) & 0x80)) { + memmove(p, p + 1, --size); } - _libssh2_htonu32(p - 4, bytes); + _libssh2_htonu32(p - 4, size); done: - return p + bytes; + return p + size; } /* _libssh2_ecdsa_sign diff --git a/src/mbedtls.h b/src/mbedtls.h index f1e2e20cb3..4db9ee405c 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -448,7 +448,7 @@ void _libssh2_mbedtls_free(void); int -_libssh2_mbedtls_random(unsigned char *buf, int len); +_libssh2_mbedtls_random(unsigned char *buf, size_t len); int _libssh2_mbedtls_cipher_init(_libssh2_cipher_ctx *ctx, diff --git a/src/misc.c b/src/misc.c index 9fc2d2170f..465d7b00e9 100644 --- a/src/misc.c +++ b/src/misc.c @@ -215,13 +215,13 @@ _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length, /* libssh2_ntohu32 */ -unsigned int +uint32_t _libssh2_ntohu32(const unsigned char *buf) { - return (((unsigned int)buf[0] << 24) - | ((unsigned int)buf[1] << 16) - | ((unsigned int)buf[2] << 8) - | ((unsigned int)buf[3])); + return ((uint32_t)buf[0] << 24) + | ((uint32_t)buf[1] << 16) + | ((uint32_t)buf[2] << 8) + | ((uint32_t)buf[3]); } diff --git a/src/misc.h b/src/misc.h index 60c99de721..1e996e21e6 100644 --- a/src/misc.h +++ b/src/misc.h @@ -97,7 +97,7 @@ void _libssh2_list_remove(struct list_node *entry); size_t _libssh2_base64_encode(LIBSSH2_SESSION *session, const char *inp, size_t insize, char **outptr); -unsigned int _libssh2_ntohu32(const unsigned char *buf); +uint32_t _libssh2_ntohu32(const unsigned char *buf); libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf); void _libssh2_htonu32(unsigned char *buf, uint32_t val); void _libssh2_store_u32(unsigned char **buf, uint32_t value); diff --git a/src/openssl.c b/src/openssl.c index 9abe8c03af..8b362af79b 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -91,6 +91,16 @@ write_bn(unsigned char *buf, const BIGNUM *bn, int bn_bytes) return p + bn_bytes; } +int +_libssh2_openssl_random(void *buf, size_t len) +{ + if(len > INT_MAX) { + return -1; + } + + return RAND_bytes(buf, (int)len) == 1 ? 0 : -1; +} + int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, const unsigned char *edata, @@ -174,8 +184,8 @@ int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, size_t hash_len, const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len) + size_t sig_len, + const unsigned char *m, size_t m_len) { int ret; int nid_type; @@ -222,8 +232,8 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len) + size_t sig_len, + const unsigned char *m, size_t m_len) { return _libssh2_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, sig, sig_len, m, m_len); @@ -287,7 +297,7 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, const unsigned char *sig, - const unsigned char *m, unsigned long m_len) + const unsigned char *m, size_t m_len) { unsigned char hash[SHA_DIGEST_LENGTH]; DSA_SIG * dsasig; @@ -1985,7 +1995,7 @@ int _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, LIBSSH2_SESSION * session, const unsigned char *raw_pub_key, - const uint8_t key_len) + const size_t key_len) { libssh2_ed25519_ctx *ctx = NULL; @@ -2196,7 +2206,7 @@ _libssh2_sha1_init(libssh2_sha1_ctx *ctx) } int -_libssh2_sha1(const unsigned char *message, unsigned long len, +_libssh2_sha1(const unsigned char *message, size_t len, unsigned char *out) { #ifdef HAVE_OPAQUE_STRUCTS @@ -2248,7 +2258,7 @@ _libssh2_sha256_init(libssh2_sha256_ctx *ctx) } int -_libssh2_sha256(const unsigned char *message, unsigned long len, +_libssh2_sha256(const unsigned char *message, size_t len, unsigned char *out) { #ifdef HAVE_OPAQUE_STRUCTS @@ -2300,8 +2310,8 @@ _libssh2_sha384_init(libssh2_sha384_ctx *ctx) } int -_libssh2_sha384(const unsigned char *message, unsigned long len, - unsigned char *out) +_libssh2_sha384(const unsigned char *message, size_t len, + unsigned char *out) { #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); @@ -2352,8 +2362,8 @@ _libssh2_sha512_init(libssh2_sha512_ctx *ctx) } int -_libssh2_sha512(const unsigned char *message, unsigned long len, - unsigned char *out) +_libssh2_sha512(const unsigned char *message, size_t len, + unsigned char *out) { #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); diff --git a/src/openssl.h b/src/openssl.h index bc53e35051..733366d6e3 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -181,7 +181,8 @@ #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) -#define _libssh2_random(buf, len) (RAND_bytes((buf), (len)) == 1 ? 0 : -1) +#define _libssh2_random(buf, len) \ + _libssh2_openssl_random((buf), (len)) #define libssh2_prepare_iovec(vec, len) /* Empty. */ @@ -204,7 +205,7 @@ int _libssh2_sha1_init(libssh2_sha1_ctx *ctx); #define libssh2_sha1_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len) #define libssh2_sha1_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) #endif -int _libssh2_sha1(const unsigned char *message, unsigned long len, +int _libssh2_sha1(const unsigned char *message, size_t len, unsigned char *out); #define libssh2_sha1(x,y,z) _libssh2_sha1(x,y,z) @@ -228,8 +229,8 @@ int _libssh2_sha256_init(libssh2_sha256_ctx *ctx); EVP_DigestUpdate(&(ctx), data, len) #define libssh2_sha256_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) #endif -int _libssh2_sha256(const unsigned char *message, unsigned long len, - unsigned char *out); +int _libssh2_sha256(const unsigned char *message, size_t len, + unsigned char *out); #define libssh2_sha256(x,y,z) _libssh2_sha256(x,y,z) #ifdef HAVE_OPAQUE_STRUCTS @@ -252,7 +253,7 @@ int _libssh2_sha384_init(libssh2_sha384_ctx *ctx); EVP_DigestUpdate(&(ctx), data, len) #define libssh2_sha384_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) #endif -int _libssh2_sha384(const unsigned char *message, unsigned long len, +int _libssh2_sha384(const unsigned char *message, size_t len, unsigned char *out); #define libssh2_sha384(x,y,z) _libssh2_sha384(x,y,z) @@ -276,7 +277,7 @@ int _libssh2_sha512_init(libssh2_sha512_ctx *ctx); EVP_DigestUpdate(&(ctx), data, len) #define libssh2_sha512_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) #endif -int _libssh2_sha512(const unsigned char *message, unsigned long len, +int _libssh2_sha512(const unsigned char *message, size_t len, unsigned char *out); #define libssh2_sha512(x,y,z) _libssh2_sha512(x,y,z) @@ -427,6 +428,8 @@ extern int _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, _libssh2_bn_ctx *bnctx); extern void _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx); +extern int _libssh2_openssl_random(void *buf, size_t len); + const EVP_CIPHER *_libssh2_EVP_aes_128_ctr(void); const EVP_CIPHER *_libssh2_EVP_aes_192_ctr(void); const EVP_CIPHER *_libssh2_EVP_aes_256_ctr(void); diff --git a/src/os400qc3.c b/src/os400qc3.c index 6e3137b2fe..3ce9d542f3 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -883,7 +883,7 @@ _libssh2_bn_from_bn(_libssh2_bn *to, _libssh2_bn *from) } int -_libssh2_random(unsigned char *buf, int len) +_libssh2_random(unsigned char *buf, size_t len) { Qc3GenPRNs(buf, len, Qc3PRN_TYPE_NORMAL, Qc3PRN_NO_PARITY, (char *) &ecnull); @@ -2379,12 +2379,12 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa, - const unsigned char *sig, unsigned long sig_len, - const unsigned char *m, unsigned long m_len) + const unsigned char *sig, size_t sig_len, + const unsigned char *m, size_t m_len) { Qus_EC_t errcode; - int slen = sig_len; - int mlen = m_len; + int slen = (int)sig_len; + int mlen = (int)m_len; set_EC_length(errcode, sizeof errcode); Qc3VerifySignature((char *) sig, &slen, (char *) m, &mlen, Qc3_Data, diff --git a/src/os400qc3.h b/src/os400qc3.h index 7bcef23364..23148dbe50 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -361,7 +361,7 @@ extern int _libssh2_bn_from_bin(_libssh2_bn *bn, int len, const unsigned char *v); extern int _libssh2_bn_set_word(_libssh2_bn *bn, unsigned long val); extern int _libssh2_bn_to_bin(_libssh2_bn *bn, unsigned char *val); -extern int _libssh2_random(unsigned char *buf, int len); +extern int _libssh2_random(unsigned char *buf, size_t len); extern void _libssh2_os400qc3_crypto_dtor(_libssh2_os400qc3_crypto_ctx *x); extern int libssh2_os400qc3_hash_init(Qc3_Format_ALGD0100_T *x, unsigned int algo); diff --git a/src/packet.c b/src/packet.c index 403c008591..43b92f7b6c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -72,21 +72,21 @@ */ static inline int packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, - unsigned long datalen, + size_t datalen, packet_queue_listener_state_t *listen_state) { /* * Look for a matching listener */ /* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */ - unsigned long packet_len = 17 + (sizeof(FwdNotReq) - 1); + size_t packet_len = 17 + (sizeof(FwdNotReq) - 1); unsigned char *p; LIBSSH2_LISTENER *listn = _libssh2_list_first(&session->listeners); char failure_code = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED; int rc; if(listen_state->state == libssh2_NB_state_idle) { - unsigned long offset = (sizeof("forwarded-tcpip") - 1) + 5; + size_t offset = (sizeof("forwarded-tcpip") - 1) + 5; size_t temp_len = 0; struct string_buf buf; buf.data = data; @@ -285,19 +285,19 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, */ static inline int packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, - unsigned long datalen, + size_t datalen, packet_x11_open_state_t *x11open_state) { int failure_code = SSH_OPEN_CONNECT_FAILED; /* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */ - unsigned long packet_len = 17 + (sizeof(X11FwdUnAvil) - 1); + size_t packet_len = 17 + (sizeof(X11FwdUnAvil) - 1); unsigned char *p; LIBSSH2_CHANNEL *channel = x11open_state->channel; int rc; if(x11open_state->state == libssh2_NB_state_idle) { - unsigned long offset = (sizeof("x11") - 1) + 5; + size_t offset = (sizeof("x11") - 1) + 5; size_t temp_len = 0; struct string_buf buf; buf.data = data; @@ -798,7 +798,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, session->packAdd_state = libssh2_NB_state_jump1; rc = _libssh2_channel_receive_window_adjust(session-> packAdd_channelp, - datalen - 13, + (uint32_t)(datalen - 13), 1, NULL); if(rc == LIBSSH2_ERROR_EAGAIN) return rc; @@ -1208,7 +1208,7 @@ _libssh2_packet_askv(LIBSSH2_SESSION * session, const unsigned char *match_buf, size_t match_len) { - int i, packet_types_len = strlen((char *) packet_types); + size_t i, packet_types_len = strlen((const char *) packet_types); for(i = 0; i < packet_types_len; i++) { if(0 == _libssh2_packet_ask(session, packet_types[i], data, diff --git a/src/pem.c b/src/pem.c index c6ec85c836..e4dc1f742a 100644 --- a/src/pem.c +++ b/src/pem.c @@ -114,7 +114,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, char line[LINE_SIZE]; unsigned char iv[LINE_SIZE]; char *b64data = NULL; - unsigned int b64datalen = 0; + size_t b64datalen = 0; int ret; const LIBSSH2_CRYPT_METHOD *method = NULL; @@ -200,7 +200,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, } if(libssh2_base64_decode(session, (char **) data, datalen, - b64data, b64datalen)) { + b64data, (unsigned int)b64datalen)) { ret = -1; goto out; } @@ -299,7 +299,7 @@ _libssh2_pem_parse_memory(LIBSSH2_SESSION * session, { char line[LINE_SIZE]; char *b64data = NULL; - unsigned int b64datalen = 0; + size_t b64datalen = 0; size_t off = 0; int ret; @@ -345,7 +345,7 @@ _libssh2_pem_parse_memory(LIBSSH2_SESSION * session, } if(libssh2_base64_decode(session, (char **) data, datalen, - b64data, b64datalen)) { + b64data, (unsigned int)b64datalen)) { ret = -1; goto out; } @@ -669,7 +669,7 @@ _libssh2_openssh_pem_parse(LIBSSH2_SESSION * session, { char line[LINE_SIZE]; char *b64data = NULL; - unsigned int b64datalen = 0; + size_t b64datalen = 0; int ret = 0; /* read file */ @@ -720,7 +720,7 @@ _libssh2_openssh_pem_parse(LIBSSH2_SESSION * session, ret = _libssh2_openssh_pem_parse_data(session, passphrase, (const char *)b64data, - (size_t)b64datalen, + b64datalen, decrypted_buf); if(b64data) { @@ -741,7 +741,7 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session, { char line[LINE_SIZE]; char *b64data = NULL; - unsigned int b64datalen = 0; + size_t b64datalen = 0; size_t off = 0; int ret; diff --git a/src/publickey.c b/src/publickey.c index 05ec84e50d..36bfd3ca60 100644 --- a/src/publickey.c +++ b/src/publickey.c @@ -105,7 +105,7 @@ static const LIBSSH2_PUBLICKEY_CODE_LIST publickey_status_codes[] = { */ static void publickey_status_error(const LIBSSH2_PUBLICKEY *pkey, - LIBSSH2_SESSION *session, int status) + LIBSSH2_SESSION *session, unsigned long status) { const char *msg; @@ -114,7 +114,7 @@ publickey_status_error(const LIBSSH2_PUBLICKEY *pkey, status = 7; } - if(status < 0 || status > LIBSSH2_PUBLICKEY_STATUS_CODE_MAX) { + if(status > LIBSSH2_PUBLICKEY_STATUS_CODE_MAX) { msg = "unknown"; } else { @@ -136,14 +136,14 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey, LIBSSH2_CHANNEL *channel = pkey->channel; LIBSSH2_SESSION *session = channel->session; unsigned char buffer[4]; - int rc; + ssize_t rc; *data = NULL; /* default to nothing returned */ *data_len = 0; if(pkey->receive_state == libssh2_NB_state_idle) { rc = _libssh2_channel_read(channel, 0, (char *) buffer, 4); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } else if(rc != 4) { return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, @@ -166,9 +166,9 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey, rc = _libssh2_channel_read(channel, 0, (char *) pkey->receive_packet, pkey->receive_packet_len); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } - else if(rc != (int)pkey->receive_packet_len) { + else if(rc != (ssize_t)pkey->receive_packet_len) { LIBSSH2_FREE(session, pkey->receive_packet); pkey->receive_packet = NULL; pkey->receive_state = libssh2_NB_state_idle; @@ -234,7 +234,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey) size_t data_len; int response; - while(1) { + for(;;) { int rc = publickey_packet_receive(pkey, &data, &data_len); if(rc == LIBSSH2_ERROR_EAGAIN) { return rc; @@ -395,20 +395,21 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session) } if(session->pkeyInit_state == libssh2_NB_state_sent2) { - rc = _libssh2_channel_write(session->pkeyInit_channel, 0, - session->pkeyInit_buffer, - 19 - session->pkeyInit_buffer_sent); - if(rc == LIBSSH2_ERROR_EAGAIN) { + ssize_t nwritten; + nwritten = _libssh2_channel_write(session->pkeyInit_channel, 0, + session->pkeyInit_buffer, + 19 - session->pkeyInit_buffer_sent); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending publickey version packet"); return NULL; } - else if(rc < 0) { - _libssh2_error(session, rc, + else if(nwritten < 0) { + _libssh2_error(session, (int)nwritten, "Unable to send publickey version packet"); goto err_exit; } - session->pkeyInit_buffer_sent += rc; + session->pkeyInit_buffer_sent += nwritten; if(session->pkeyInit_buffer_sent < 19) { _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Need to be called again to complete this"); @@ -419,7 +420,7 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session) } if(session->pkeyInit_state == libssh2_NB_state_sent3) { - while(1) { + for(;;) { unsigned char *s; rc = publickey_packet_receive(session->pkeyInit_pkey, &session->pkeyInit_data, @@ -698,12 +699,13 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, } if(pkey->add_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, pkey->add_packet, - (pkey->add_s - pkey->add_packet)); - if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, pkey->add_packet, + (pkey->add_s - pkey->add_packet)); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { + return (int)nwritten; } - else if((pkey->add_s - pkey->add_packet) != rc) { + else if((pkey->add_s - pkey->add_packet) != nwritten) { LIBSSH2_FREE(session, pkey->add_packet); pkey->add_packet = NULL; return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, @@ -782,12 +784,13 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, } if(pkey->remove_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, pkey->remove_packet, - (pkey->remove_s - pkey->remove_packet)); - if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, pkey->remove_packet, + (pkey->remove_s - pkey->remove_packet)); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { + return (int)nwritten; } - else if((pkey->remove_s - pkey->remove_packet) != rc) { + else if((pkey->remove_s - pkey->remove_packet) != nwritten) { LIBSSH2_FREE(session, pkey->remove_packet); pkey->remove_packet = NULL; pkey->remove_state = libssh2_NB_state_idle; @@ -849,14 +852,15 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, } if(pkey->listFetch_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, - pkey->listFetch_buffer, - (pkey->listFetch_s - - pkey->listFetch_buffer)); - if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, + pkey->listFetch_buffer, + (pkey->listFetch_s - + pkey->listFetch_buffer)); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { + return (int)nwritten; } - else if((pkey->listFetch_s - pkey->listFetch_buffer) != rc) { + else if((pkey->listFetch_s - pkey->listFetch_buffer) != nwritten) { pkey->listFetch_state = libssh2_NB_state_idle; return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey list packet"); @@ -865,7 +869,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, pkey->listFetch_state = libssh2_NB_state_sent; } - while(1) { + for(;;) { rc = publickey_packet_receive(pkey, &pkey->listFetch_data, &pkey->listFetch_data_len); if(rc == LIBSSH2_ERROR_EAGAIN) { diff --git a/src/session.c b/src/session.c index 77da310596..7420c15178 100644 --- a/src/session.c +++ b/src/session.c @@ -95,8 +95,8 @@ LIBSSH2_REALLOC_FUNC(libssh2_default_realloc) static int banner_receive(LIBSSH2_SESSION * session) { - int ret; - int banner_len; + ssize_t ret; + size_t banner_len; if(session->banner_TxRx_state == libssh2_NB_state_idle) { banner_len = 0; @@ -107,7 +107,7 @@ banner_receive(LIBSSH2_SESSION * session) banner_len = session->banner_TxRx_total_send; } - while((banner_len < (int) sizeof(session->banner_TxRx_banner)) && + while((banner_len < sizeof(session->banner_TxRx_banner)) && ((banner_len == 0) || (session->banner_TxRx_banner[banner_len - 1] != '\n'))) { char c = '\0'; @@ -121,11 +121,11 @@ banner_receive(LIBSSH2_SESSION * session) if(session->api_block_mode || (ret != -EAGAIN)) /* ignore EAGAIN when non-blocking */ _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error recving %d bytes: %d", 1, -ret)); + "Error recving %d bytes: %d", 1, (int)-ret)); } else _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Recved %d bytes banner", ret)); + "Recved %d bytes banner", (int)ret)); if(ret < 0) { if(ret == -EAGAIN) { @@ -202,7 +202,7 @@ static int banner_send(LIBSSH2_SESSION * session) { char *banner = (char *) LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF; - int banner_len = sizeof(LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF) - 1; + size_t banner_len = sizeof(LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF) - 1; ssize_t ret; #ifdef LIBSSH2DEBUG char banner_dup[256]; @@ -249,7 +249,7 @@ banner_send(LIBSSH2_SESSION * session) banner_len - session->banner_TxRx_total_send, banner, session->banner_TxRx_total_send)); - if(ret != (banner_len - session->banner_TxRx_total_send)) { + if(ret != (ssize_t)(banner_len - session->banner_TxRx_total_send)) { if(ret >= 0 || ret == -EAGAIN) { /* the whole packet could not be sent, save the what was */ session->socket_block_directions = @@ -750,7 +750,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) else if(rc) return _libssh2_error(session, rc, "Failed getting banner"); - } while(strncmp("SSH-", (char *)session->remote.banner, 4)); + } while(strncmp("SSH-", (const char *)session->remote.banner, 4)); session->startup_state = libssh2_NB_state_sent1; } @@ -814,7 +814,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) if((session->startup_service_length != (sizeof("ssh-userauth") - 1)) - || strncmp("ssh-userauth", (char *) session->startup_data + 5, + || strncmp("ssh-userauth", + (const char *) session->startup_data + 5, session->startup_service_length)) { LIBSSH2_FREE(session, session->startup_data); session->startup_data = NULL; @@ -1153,7 +1154,7 @@ session_disconnect(LIBSSH2_SESSION *session, int reason, const char *lang) { unsigned char *s; - unsigned long descr_len = 0, lang_len = 0; + size_t descr_len = 0, lang_len = 0; int rc; if(session->disconnect_state == libssh2_NB_state_idle) { @@ -1170,6 +1171,10 @@ session_disconnect(LIBSSH2_SESSION *session, int reason, return _libssh2_error(session, LIBSSH2_ERROR_INVAL, "too long description"); + if(lang_len > 256) + return _libssh2_error(session, LIBSSH2_ERROR_INVAL, + "too long language string"); + /* 13 = packet_type(1) + reason code(4) + descr_len(4) + lang_len(4) */ session->disconnect_data_len = descr_len + lang_len + 13; @@ -1179,14 +1184,14 @@ session_disconnect(LIBSSH2_SESSION *session, int reason, _libssh2_store_u32(&s, reason); _libssh2_store_str(&s, description, descr_len); /* store length only, lang is sent separately */ - _libssh2_store_u32(&s, lang_len); + _libssh2_store_u32(&s, (uint32_t)lang_len); session->disconnect_state = libssh2_NB_state_created; } rc = _libssh2_transport_send(session, session->disconnect_data, session->disconnect_data_len, - (unsigned char *)lang, lang_len); + (const unsigned char *)lang, lang_len); if(rc == LIBSSH2_ERROR_EAGAIN) return rc; @@ -1335,7 +1340,7 @@ libssh2_session_last_error(LIBSSH2_SESSION * session, char **errmsg, } if(errmsg_len) { - *errmsg_len = msglen; + *errmsg_len = (int)msglen; } return session->err_code; diff --git a/src/sftp.c b/src/sftp.c index af44877ec5..0065f1b981 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -333,9 +333,9 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) sftp->partial_size_len], 4 - sftp->partial_size_len); if(rc == LIBSSH2_ERROR_EAGAIN) - return rc; + return (int)rc; else if(rc < 0) - return _libssh2_error(session, rc, "channel read"); + return _libssh2_error(session, (int)rc, "channel read"); sftp->partial_size_len += rc; @@ -387,7 +387,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) libssh2_NB_state_idle; if(rc == LIBSSH2_ERROR_EAGAIN) - return rc; + return (int)rc; } } @@ -405,12 +405,12 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) * knows how to continue on the next invoke. */ sftp->packet_state = libssh2_NB_state_sent1; - return rc; + return (int)rc; } else if(rc < 0) { LIBSSH2_FREE(session, packet); sftp->partial_packet = NULL; - return _libssh2_error(session, rc, + return _libssh2_error(session, (int)rc, "Error waiting for SFTP packet"); } sftp->partial_received += rc; @@ -424,7 +424,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) rc = sftp_packet_add(sftp, packet, sftp->partial_len); if(rc) { LIBSSH2_FREE(session, packet); - return rc; + return (int)rc; } else { return packet_type; @@ -674,7 +674,7 @@ sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs) /* sftp_bin2attr */ -static int +static ssize_t sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p, size_t data_len) { @@ -912,7 +912,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) goto sftp_init_error; } else if(rc) { - _libssh2_error(session, rc, + _libssh2_error(session, (int)rc, "Timeout waiting for response from SFTP subsystem"); goto sftp_init_error; } @@ -1165,7 +1165,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, return NULL; } else if(rc < 0) { - _libssh2_error(session, rc, "Unable to send FXP_OPEN*"); + _libssh2_error(session, (int)rc, "Unable to send FXP_OPEN*"); LIBSSH2_FREE(session, sftp->open_packet); sftp->open_packet = NULL; sftp->open_state = libssh2_NB_state_idle; @@ -1207,7 +1207,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, } sftp->open_state = libssh2_NB_state_idle; if(rc) { - _libssh2_error(session, rc, "Timeout waiting for status message"); + _libssh2_error(session, (int)rc, + "Timeout waiting for status message"); return NULL; } @@ -1324,8 +1325,8 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename, return NULL; BLOCK_ADJUST_ERRNO(hnd, sftp->channel->session, - sftp_open(sftp, filename, filename_len, flags, mode, - open_type)); + sftp_open(sftp, filename, filename_len, (uint32_t)flags, + mode, open_type)); return hnd; } @@ -1718,7 +1719,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, break; default: - assert(!"State machine error; unrecognised read state"); + assert(0); /* State machine error; unrecognised read state */ } /* we should never reach this point */ @@ -1773,7 +1774,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t filename_len; size_t longentry_len; size_t names_packet_len = handle->u.dir.names_packet_len; - int attr_len = 0; + ssize_t attr_len = 0; if(names_packet_len >= 4) { s = (unsigned char *) handle->u.dir.next_name; @@ -1917,19 +1918,20 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, } else if(retcode) { sftp->readdir_state = libssh2_NB_state_idle; - return _libssh2_error(session, retcode, + return _libssh2_error(session, (int)retcode, "Timeout waiting for status message"); } if(data[0] == SSH_FXP_STATUS) { - retcode = _libssh2_ntohu32(data + 5); + unsigned int rerrno; + rerrno = _libssh2_ntohu32(data + 5); LIBSSH2_FREE(session, data); - if(retcode == LIBSSH2_FX_EOF) { + if(rerrno == LIBSSH2_FX_EOF) { sftp->readdir_state = libssh2_NB_state_idle; return 0; } else { - sftp->last_errno = retcode; + sftp->last_errno = rerrno; sftp->readdir_state = libssh2_NB_state_idle; return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, "SFTP Protocol Error"); @@ -1965,13 +1967,13 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *hnd, char *buffer, size_t longentry_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs) { - int rc; + ssize_t rc; if(!hnd) return LIBSSH2_ERROR_BAD_USE; BLOCK_ADJUST(rc, hnd->sftp->channel->session, sftp_readdir(hnd, buffer, buffer_maxlen, longentry, longentry_maxlen, attrs)); - return rc; + return (int)rc; /* FIXME: -> ssize_t */ } /* @@ -2296,7 +2298,7 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle) rc = sftp_packet_require(sftp, SSH_FXP_STATUS, sftp->fsync_request_id, &data, &data_len, 9); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) { if(data_len > 0) { @@ -2307,7 +2309,7 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle) } else if(rc) { sftp->fsync_state = libssh2_NB_state_idle; - return _libssh2_error(session, rc, + return _libssh2_error(session, (int)rc, "Error waiting for FXP EXTENDED REPLY"); } @@ -2387,7 +2389,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, rc = _libssh2_channel_write(channel, 0, sftp->fstat_packet, packet_len); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } else if((ssize_t)packet_len != rc) { LIBSSH2_FREE(session, sftp->fstat_packet); @@ -2407,7 +2409,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, sftp->fstat_request_id, &data, &data_len, 9); if(rc == LIBSSH2_ERROR_EAGAIN) - return rc; + return (int)rc; else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) { if(data_len > 0) { LIBSSH2_FREE(session, data); @@ -2417,7 +2419,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, } else if(rc) { sftp->fstat_state = libssh2_NB_state_idle; - return _libssh2_error(session, rc, + return _libssh2_error(session, (int)rc, "Timeout waiting for status message"); } @@ -2603,12 +2605,13 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) } if(handle->close_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, handle->close_packet, - packet_len); - if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, handle->close_packet, + packet_len); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { + return (int)nwritten; } - else if((ssize_t)packet_len != rc) { + else if((ssize_t)packet_len != nwritten) { handle->close_state = libssh2_NB_state_idle; rc = _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send FXP_CLOSE command"); @@ -2650,7 +2653,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) } else { - int retcode = _libssh2_ntohu32(data + 5); + uint32_t retcode = _libssh2_ntohu32(data + 5); LIBSSH2_FREE(session, data); if(retcode != LIBSSH2_FX_OK) { @@ -2707,7 +2710,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; size_t data_len = 0; - int retcode; + uint32_t retcode; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) */ uint32_t packet_len = (uint32_t)(filename_len + 13); unsigned char *s, *data = NULL; @@ -2732,12 +2735,13 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, } if(sftp->unlink_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, sftp->unlink_packet, - packet_len); - if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, sftp->unlink_packet, + packet_len); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { + return (int)nwritten; } - else if((ssize_t)packet_len != rc) { + else if((ssize_t)packet_len != nwritten) { LIBSSH2_FREE(session, sftp->unlink_packet); sftp->unlink_packet = NULL; sftp->unlink_state = libssh2_NB_state_idle; @@ -2855,7 +2859,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, rc = _libssh2_channel_write(channel, 0, sftp->rename_packet, sftp->rename_s - sftp->rename_packet); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } else if((ssize_t)packet_len != rc) { LIBSSH2_FREE(session, sftp->rename_packet); @@ -2874,7 +2878,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, sftp->rename_request_id, &data, &data_len, 9); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) { if(data_len > 0) { @@ -2885,7 +2889,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, } else if(rc) { sftp->rename_state = libssh2_NB_state_idle; - return _libssh2_error(session, rc, + return _libssh2_error(session, (int)rc, "Error waiting for FXP STATUS"); } @@ -3008,7 +3012,7 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) &data, &data_len, 9); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) { if(data_len > 0) { @@ -3019,12 +3023,12 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) } else if(rc) { sftp->fstatvfs_state = libssh2_NB_state_idle; - return _libssh2_error(session, rc, + return _libssh2_error(session, (int)rc, "Error waiting for FXP EXTENDED REPLY"); } if(data[0] == SSH_FXP_STATUS) { - int retcode = _libssh2_ntohu32(data + 5); + uint32_t retcode = _libssh2_ntohu32(data + 5); sftp->fstatvfs_state = libssh2_NB_state_idle; LIBSSH2_FREE(session, data); sftp->last_errno = retcode; @@ -3143,7 +3147,7 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, rc = sftp_packet_requirev(sftp, 2, responses, sftp->statvfs_request_id, &data, &data_len, 9); if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + return (int)rc; } else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) { if(data_len > 0) { @@ -3154,12 +3158,12 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, } else if(rc) { sftp->statvfs_state = libssh2_NB_state_idle; - return _libssh2_error(session, rc, + return _libssh2_error(session, (int)rc, "Error waiting for FXP EXTENDED REPLY"); } if(data[0] == SSH_FXP_STATUS) { - int retcode = _libssh2_ntohu32(data + 5); + uint32_t retcode = _libssh2_ntohu32(data + 5); sftp->statvfs_state = libssh2_NB_state_idle; LIBSSH2_FREE(session, data); sftp->last_errno = retcode; @@ -3208,8 +3212,8 @@ libssh2_sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, int rc; if(!sftp || !st) return LIBSSH2_ERROR_BAD_USE; - BLOCK_ADJUST(rc, sftp->channel->session, sftp_statvfs(sftp, path, path_len, - st)); + BLOCK_ADJUST(rc, sftp->channel->session, + sftp_statvfs(sftp, path, (unsigned int)path_len, st)); return rc; } @@ -3228,7 +3232,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, 0, 0, 0, 0, 0, 0, 0 }; size_t data_len = 0; - int retcode; + uint32_t retcode; ssize_t packet_len; unsigned char *packet, *s, *data = NULL; int rc; @@ -3267,12 +3271,13 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, } if(sftp->mkdir_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, packet, packet_len); - if(rc == LIBSSH2_ERROR_EAGAIN) { + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, packet, packet_len); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { sftp->mkdir_packet = packet; - return rc; + return (int)nwritten; } - if(packet_len != rc) { + if(packet_len != nwritten) { LIBSSH2_FREE(session, packet); sftp->mkdir_state = libssh2_NB_state_idle; return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, @@ -3343,7 +3348,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; size_t data_len = 0; - int retcode; + uint32_t retcode; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */ ssize_t packet_len = path_len + 13; unsigned char *s, *data = NULL; @@ -3369,12 +3374,13 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, } if(sftp->rmdir_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, sftp->rmdir_packet, - packet_len); - if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, sftp->rmdir_packet, + packet_len); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { + return (int)nwritten; } - else if(packet_len != rc) { + else if(packet_len != nwritten) { LIBSSH2_FREE(session, sftp->rmdir_packet); sftp->rmdir_packet = NULL; sftp->rmdir_state = libssh2_NB_state_idle; @@ -3493,11 +3499,13 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, } if(sftp->stat_state == libssh2_NB_state_created) { - rc = _libssh2_channel_write(channel, 0, sftp->stat_packet, packet_len); - if(rc == LIBSSH2_ERROR_EAGAIN) { - return rc; + ssize_t nwritten; + nwritten = _libssh2_channel_write(channel, 0, + sftp->stat_packet, packet_len); + if(nwritten == LIBSSH2_ERROR_EAGAIN) { + return (int)nwritten; } - else if(packet_len != rc) { + else if(packet_len != nwritten) { LIBSSH2_FREE(session, sftp->stat_packet); sftp->stat_packet = NULL; sftp->stat_state = libssh2_NB_state_idle; @@ -3530,7 +3538,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, sftp->stat_state = libssh2_NB_state_idle; if(data[0] == SSH_FXP_STATUS) { - int retcode; + uint32_t retcode; retcode = _libssh2_ntohu32(data + 5); LIBSSH2_FREE(session, data); @@ -3641,7 +3649,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, ssize_t rc = _libssh2_channel_write(channel, 0, sftp->symlink_packet, packet_len); if(rc == LIBSSH2_ERROR_EAGAIN) - return rc; + return (int)rc; else if(packet_len != rc) { LIBSSH2_FREE(session, sftp->symlink_packet); sftp->symlink_packet = NULL; diff --git a/src/transport.c b/src/transport.c index 83a48371a3..e4ffc1a635 100644 --- a/src/transport.c +++ b/src/transport.c @@ -130,7 +130,7 @@ debugdump(LIBSSH2_SESSION * session, static int decrypt(LIBSSH2_SESSION * session, unsigned char *source, - unsigned char *dest, int len) + unsigned char *dest, ssize_t len) { struct transportpacket *p = &session->packet; int blocksize = session->remote.crypt->blocksize; @@ -275,13 +275,14 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) { int rc; struct transportpacket *p = &session->packet; - int remainpack; /* how much there is left to add to the current payload - package */ - int remainbuf; /* how much data there is remaining in the buffer to deal - with before we should read more from the network */ - int numbytes; /* how much data to deal with from the buffer on this - iteration through the loop */ - int numdecrypt; /* number of bytes to decrypt this iteration */ + ssize_t remainpack; /* how much there is left to add to the current payload + package */ + ssize_t remainbuf; /* how much data there is remaining in the buffer to + deal with before we should read more from the + network */ + ssize_t numbytes; /* how much data to deal with from the buffer on this + iteration through the loop */ + ssize_t numdecrypt; /* number of bytes to decrypt this iteration */ unsigned char block[MAX_BLOCKSIZE]; /* working block buffer */ int blocksize; /* minimum number of bytes we need before we can use them */ @@ -533,7 +534,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) numdecrypt = (p->total_num - skip) - p->data_num; } else { - int frac; + ssize_t frac; numdecrypt = numbytes; frac = numdecrypt % blocksize; if(frac) { @@ -575,7 +576,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) copy them as-is to the target buffer */ if(numbytes > 0) { - if(numbytes <= (int)(p->total_num - (p->wptr - p->payload))) { + if((size_t)numbytes <= (p->total_num - (p->wptr - p->payload))) { memcpy(p->wptr, &p->buf[p->readidx], numbytes); } else { @@ -719,9 +720,9 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, int blocksize = (session->state & LIBSSH2_STATE_NEWKEYS) ? session->local.crypt->blocksize : 8; - int padding_length; + ssize_t padding_length; size_t packet_length; - int total_length; + ssize_t total_length; #ifdef RANDOM_PADDING int rand_max; int seed = data[0]; /* FIXME: make this random */ diff --git a/src/userauth.c b/src/userauth.c index 4201113476..ab58da2656 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -739,7 +739,7 @@ static int memory_read_privatekey(LIBSSH2_SESSION * session, const LIBSSH2_HOSTKEY_METHOD ** hostkey_method, void **hostkey_abstract, - const unsigned char *method, int method_len, + const unsigned char *method, size_t method_len, const char *privkeyfiledata, size_t privkeyfiledata_len, const char *passphrase) { @@ -780,7 +780,7 @@ static int file_read_privatekey(LIBSSH2_SESSION * session, const LIBSSH2_HOSTKEY_METHOD ** hostkey_method, void **hostkey_abstract, - const unsigned char *method, int method_len, + const unsigned char *method, size_t method_len, const char *privkeyfile, const char *passphrase) { const LIBSSH2_HOSTKEY_METHOD **hostkey_methods_avail = @@ -1249,7 +1249,7 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, return rc; } -static int plain_method_len(const char *method, size_t method_len) +static size_t plain_method_len(const char *method, size_t method_len) { if(!strncmp("ssh-rsa-cert-v01@openssh.com", method, @@ -1294,10 +1294,10 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, const char *p = NULL; const char *f = NULL; char *i = NULL; - int p_len = 0; - int f_len = 0; + size_t p_len = 0; + size_t f_len = 0; int rc = 0; - int match_len = 0; + size_t match_len = 0; char *filtered_algs = NULL; const char *supported_algs = @@ -1325,12 +1325,12 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, while(s && *s) { p = strchr(s, ','); - p_len = p ? (p - s) : (int) strlen(s); + p_len = (p ? (size_t)(p - s) : strlen(s)); a = supported_algs; while(a && *a) { f = strchr(a, ','); - f_len = f ? (f - a) : (int) strlen(a); + f_len = (f ? (size_t)(f - a) : strlen(a)); if(f_len == p_len && memcmp(a, s, p_len) == 0) { @@ -1363,12 +1363,12 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, while(s && *s && !match) { p = strchr(s, ','); - p_len = p ? (p - s) : (int) strlen(s); + p_len = (p ? (size_t)(p - s) : strlen(s)); a = filtered_algs; while(a && *a && !match) { f = strchr(a, ','); - f_len = f ? (f - a) : (int) strlen(a); + f_len = (f ? (size_t)(f - a) : strlen(a)); if(f_len == p_len && memcmp(a, s, p_len) == 0) { /* found a match, upgrade key method */ @@ -1413,9 +1413,9 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, int _libssh2_userauth_publickey(LIBSSH2_SESSION *session, const char *username, - unsigned int username_len, + size_t username_len, const unsigned char *pubkeydata, - unsigned long pubkeydata_len, + size_t pubkeydata_len, LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC ((*sign_callback)), void *abstract) @@ -2137,10 +2137,10 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, } response_callback((const char *)session->userauth_kybd_auth_name, - session->userauth_kybd_auth_name_len, + (int)session->userauth_kybd_auth_name_len, (const char *) session->userauth_kybd_auth_instruction, - session->userauth_kybd_auth_instruction_len, + (int)session->userauth_kybd_auth_instruction_len, session->userauth_kybd_num_prompts, session->userauth_kybd_prompts, session->userauth_kybd_responses, diff --git a/src/userauth.h b/src/userauth.h index 6b402ddbf9..cbb7af974e 100644 --- a/src/userauth.h +++ b/src/userauth.h @@ -41,9 +41,9 @@ int _libssh2_userauth_publickey(LIBSSH2_SESSION *session, const char *username, - unsigned int username_len, + size_t username_len, const unsigned char *pubkeydata, - unsigned long pubkeydata_len, + size_t pubkeydata_len, LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC ((*sign_callback)), void *abstract); diff --git a/src/wincng.c b/src/wincng.c index 9b97652aa4..d268c8fb93 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -419,17 +419,21 @@ _libssh2_wincng_free(void) } int -_libssh2_wincng_random(void *buf, int len) +_libssh2_wincng_random(void *buf, size_t len) { int ret; - ret = BCryptGenRandom(_libssh2_wincng.hAlgRNG, buf, len, 0); + if(len > ULONG_MAX) { + return -1; + } + + ret = BCryptGenRandom(_libssh2_wincng.hAlgRNG, buf, (ULONG)len, 0); return BCRYPT_SUCCESS(ret) ? 0 : -1; } static void -_libssh2_wincng_safe_free(void *buf, int len) +_libssh2_wincng_safe_free(void *buf, size_t len) { if(!buf) return; @@ -453,12 +457,6 @@ memcpy_with_be_padding(unsigned char *dest, unsigned long dest_len, memcpy((dest + dest_len) - src_len, src, src_len); } -static int -round_down(int number, int multiple) -{ - return (number / multiple) * multiple; -} - /*******************************************************************/ /* * Windows CNG backend: Hash functions @@ -595,7 +593,7 @@ _libssh2_wincng_hmac_cleanup(_libssh2_wincng_hash_ctx *ctx) int _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, - size_t hashlen, + unsigned long hashlen, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, @@ -668,7 +666,7 @@ _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, memcpy(data, sig, datalen); ret = BCryptVerifySignature(ctx->hKey, pPaddingInfo, - hash, (ULONG)hashlen, data, datalen, flags); + hash, hashlen, data, datalen, flags); _libssh2_wincng_safe_free(hash, hashlen); _libssh2_wincng_safe_free(data, datalen); @@ -1221,24 +1219,28 @@ _libssh2_wincng_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, int _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, const unsigned char *sig, - unsigned long sig_len, + size_t sig_len, const unsigned char *m, - unsigned long m_len) + size_t m_len) { - return _libssh2_wincng_key_sha_verify(rsa, SHA_DIGEST_LENGTH, sig, sig_len, - m, m_len, BCRYPT_PAD_PKCS1); + return _libssh2_wincng_key_sha_verify(rsa, SHA_DIGEST_LENGTH, + sig, (unsigned long)sig_len, + m, (unsigned long)m_len, + BCRYPT_PAD_PKCS1); } int _libssh2_wincng_rsa_sha2_verify(libssh2_rsa_ctx* rsa, size_t hash_len, const unsigned char *sig, - unsigned long sig_len, + size_t sig_len, const unsigned char *m, - unsigned long m_len) + size_t m_len) { - return _libssh2_wincng_key_sha_verify(rsa, hash_len, sig, sig_len, m, - m_len, BCRYPT_PAD_PKCS1); + return _libssh2_wincng_key_sha_verify(rsa, (unsigned long)hash_len, + sig, (unsigned long)sig_len, + m, (unsigned long)m_len, + BCRYPT_PAD_PKCS1); } int @@ -1541,10 +1543,10 @@ int _libssh2_wincng_dsa_sha1_verify(libssh2_dsa_ctx *dsa, const unsigned char *sig_fixed, const unsigned char *m, - unsigned long m_len) + size_t m_len) { return _libssh2_wincng_key_sha_verify(dsa, SHA_DIGEST_LENGTH, sig_fixed, - 40, m, m_len, 0); + 40, m, (unsigned long)m_len, 0); } int @@ -2347,6 +2349,12 @@ _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx) } } +static int +round_down(int number, int multiple) +{ + return (number / multiple) * multiple; +} + /* Generates a Diffie-Hellman key pair using base `g', prime `p' and the given * `group_order'. Can use the given big number context `bnctx' if needed. The * private key is stored as opaque in the Diffie-Hellman context `*dhctx' and @@ -2357,6 +2365,10 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, _libssh2_bn *g, _libssh2_bn *p, int group_order) { const int hasAlgDHwithKDF = _libssh2_wincng.hasAlgDHwithKDF; + + if(group_order < 0) + return -1; + while(_libssh2_wincng.hAlgDH && hasAlgDHwithKDF != -1) { BCRYPT_DH_PARAMETER_HEADER *dh_params = NULL; unsigned long dh_params_len; @@ -2366,7 +2378,7 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, * in length. At the time of writing a practical observed group_order * value is 257, so we need to round down to 8 bytes of length (64/8) * in order for kex to succeed */ - DWORD key_length_bytes = max(round_down(group_order, 8), + DWORD key_length_bytes = max((unsigned long)round_down(group_order, 8), max(g->length, p->length)); BCRYPT_DH_KEY_BLOB *dh_key_blob; LPCWSTR key_type; diff --git a/src/wincng.h b/src/wincng.h index aa0e655f23..e5c77ef416 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -445,7 +445,7 @@ typedef struct { */ void _libssh2_wincng_init(void); void _libssh2_wincng_free(void); -int _libssh2_wincng_random(void *buf, int len); +int _libssh2_wincng_random(void *buf, size_t len); int _libssh2_wincng_hash_init(_libssh2_wincng_hash_ctx *ctx, @@ -470,7 +470,7 @@ _libssh2_wincng_hmac_cleanup(_libssh2_wincng_hash_ctx *ctx); int _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, - size_t hashlen, + unsigned long hashlen, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, @@ -509,9 +509,9 @@ _libssh2_wincng_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, int _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, const unsigned char *sig, - unsigned long sig_len, + size_t sig_len, const unsigned char *m, - unsigned long m_len); + size_t m_len); int _libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session, libssh2_rsa_ctx *rsa, @@ -550,7 +550,7 @@ int _libssh2_wincng_dsa_sha1_verify(libssh2_dsa_ctx *dsa, const unsigned char *sig_fixed, const unsigned char *m, - unsigned long m_len); + size_t m_len); int _libssh2_wincng_dsa_sha1_sign(libssh2_dsa_ctx *dsa, const unsigned char *hash, From 29347905721d2e7fbb97dabfb0071bee51db3013 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 26 Mar 2023 22:50:14 +0000 Subject: [PATCH 161/424] src: silence compiler warnings 4 (alignment in WinCNG) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Silence alignment warnings in WinCNG, by reworking the code. Also add two unrelated casts to avoid gcc compiler warnings in surrounding code. `increases required alignment from 1 to 4 [-Wcast-align]` `increases required alignment from 1 to 8 [-Wcast-align]` See warning details in the PR's individual commits. Reviewed-by: Marc Hörsken in Cherry-picked from #846 Closes #880 --- src/wincng.c | 219 +++++++++++++++++++++++++++------------------------ src/wincng.h | 2 +- 2 files changed, 118 insertions(+), 103 deletions(-) diff --git a/src/wincng.c b/src/wincng.c index d268c8fb93..ca72990099 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -855,16 +855,17 @@ _libssh2_wincng_asn_decode_bn(unsigned char *pbEncoded, unsigned char **ppbDecoded, unsigned long *pcbDecoded) { - unsigned char *pbDecoded = NULL, *pbInteger; + unsigned char *pbDecoded = NULL; + PCRYPT_DATA_BLOB pbInteger; unsigned long cbDecoded = 0, cbInteger; int ret; ret = _libssh2_wincng_asn_decode(pbEncoded, cbEncoded, X509_MULTI_BYTE_UINT, - &pbInteger, &cbInteger); + (void *)&pbInteger, &cbInteger); if(!ret) { - ret = _libssh2_wincng_bn_ltob(((PCRYPT_DATA_BLOB)pbInteger)->pbData, - ((PCRYPT_DATA_BLOB)pbInteger)->cbData, + ret = _libssh2_wincng_bn_ltob(pbInteger->pbData, + pbInteger->cbData, &pbDecoded, &cbDecoded); if(!ret) { *ppbDecoded = pbDecoded; @@ -884,23 +885,23 @@ _libssh2_wincng_asn_decode_bns(unsigned char *pbEncoded, unsigned long *pcbCount) { PCRYPT_DER_BLOB pBlob; - unsigned char *pbDecoded, **rpbDecoded; + unsigned char **rpbDecoded; + PCRYPT_SEQUENCE_OF_ANY pbDecoded; unsigned long cbDecoded, *rcbDecoded, index, length; int ret; ret = _libssh2_wincng_asn_decode(pbEncoded, cbEncoded, X509_SEQUENCE_OF_ANY, - &pbDecoded, &cbDecoded); + (void *)&pbDecoded, &cbDecoded); if(!ret) { - length = ((PCRYPT_DATA_BLOB)pbDecoded)->cbData; + length = pbDecoded->cValue; rpbDecoded = malloc(sizeof(PBYTE) * length); if(rpbDecoded) { rcbDecoded = malloc(sizeof(DWORD) * length); if(rcbDecoded) { for(index = 0; index < length; index++) { - pBlob = &((PCRYPT_DER_BLOB) - ((PCRYPT_DATA_BLOB)pbDecoded)->pbData)[index]; + pBlob = &pbDecoded->rgValue[index]; ret = _libssh2_wincng_asn_decode_bn(pBlob->pbData, pBlob->cbData, &rpbDecoded[index], @@ -989,7 +990,6 @@ _libssh2_wincng_rsa_new(libssh2_rsa_ctx **rsa, BCRYPT_KEY_HANDLE hKey; BCRYPT_RSAKEY_BLOB *rsakey; LPCWSTR lpszBlobType; - unsigned char *key; unsigned long keylen, offset, mlen, p1len = 0, p2len = 0; int ret; @@ -1005,65 +1005,76 @@ _libssh2_wincng_rsa_new(libssh2_rsa_ctx **rsa, keylen += p1len * 3 + p2len * 2 + mlen; } - key = malloc(keylen); - if(!key) { + rsakey = (BCRYPT_RSAKEY_BLOB *)malloc(keylen); + if(!rsakey) { return -1; } - memset(key, 0, keylen); + memset(rsakey, 0, keylen); /* https://msdn.microsoft.com/library/windows/desktop/aa375531.aspx */ - rsakey = (BCRYPT_RSAKEY_BLOB *)key; rsakey->BitLength = mlen * 8; rsakey->cbPublicExp = elen; rsakey->cbModulus = mlen; - memcpy(key + offset, edata, elen); + memcpy((unsigned char *)rsakey + offset, edata, elen); offset += elen; if(nlen < mlen) - memcpy(key + offset + mlen - nlen, ndata, nlen); + memcpy((unsigned char *)rsakey + offset + mlen - nlen, ndata, nlen); else - memcpy(key + offset, ndata + nlen - mlen, mlen); + memcpy((unsigned char *)rsakey + offset, ndata + nlen - mlen, mlen); if(ddata && dlen > 0) { offset += mlen; if(plen < p1len) - memcpy(key + offset + p1len - plen, pdata, plen); + memcpy((unsigned char *)rsakey + offset + p1len - plen, + pdata, plen); else - memcpy(key + offset, pdata + plen - p1len, p1len); + memcpy((unsigned char *)rsakey + offset, + pdata + plen - p1len, p1len); offset += p1len; if(qlen < p2len) - memcpy(key + offset + p2len - qlen, qdata, qlen); + memcpy((unsigned char *)rsakey + offset + p2len - qlen, + qdata, qlen); else - memcpy(key + offset, qdata + qlen - p2len, p2len); + memcpy((unsigned char *)rsakey + offset, + qdata + qlen - p2len, p2len); offset += p2len; if(e1len < p1len) - memcpy(key + offset + p1len - e1len, e1data, e1len); + memcpy((unsigned char *)rsakey + offset + p1len - e1len, + e1data, e1len); else - memcpy(key + offset, e1data + e1len - p1len, p1len); + memcpy((unsigned char *)rsakey + offset, + e1data + e1len - p1len, p1len); offset += p1len; if(e2len < p2len) - memcpy(key + offset + p2len - e2len, e2data, e2len); + memcpy((unsigned char *)rsakey + offset + p2len - e2len, + e2data, e2len); else - memcpy(key + offset, e2data + e2len - p2len, p2len); + memcpy((unsigned char *)rsakey + offset, + e2data + e2len - p2len, p2len); offset += p2len; if(coefflen < p1len) - memcpy(key + offset + p1len - coefflen, coeffdata, coefflen); + memcpy((unsigned char *)rsakey + offset + p1len - coefflen, + coeffdata, coefflen); else - memcpy(key + offset, coeffdata + coefflen - p1len, p1len); + memcpy((unsigned char *)rsakey + offset, + coeffdata + coefflen - p1len, p1len); offset += p1len; if(dlen < mlen) - memcpy(key + offset + mlen - dlen, ddata, dlen); + memcpy((unsigned char *)rsakey + offset + mlen - dlen, + ddata, dlen); else - memcpy(key + offset, ddata + dlen - mlen, mlen); + memcpy((unsigned char *)rsakey + offset, + ddata + dlen - mlen, mlen); lpszBlobType = BCRYPT_RSAFULLPRIVATE_BLOB; rsakey->Magic = BCRYPT_RSAFULLPRIVATE_MAGIC; @@ -1079,9 +1090,9 @@ _libssh2_wincng_rsa_new(libssh2_rsa_ctx **rsa, ret = BCryptImportKeyPair(_libssh2_wincng.hAlgRSA, NULL, lpszBlobType, - &hKey, key, keylen, 0); + &hKey, (PUCHAR)rsakey, keylen, 0); if(!BCRYPT_SUCCESS(ret)) { - _libssh2_wincng_safe_free(key, keylen); + _libssh2_wincng_safe_free(rsakey, keylen); return -1; } @@ -1089,12 +1100,12 @@ _libssh2_wincng_rsa_new(libssh2_rsa_ctx **rsa, *rsa = malloc(sizeof(libssh2_rsa_ctx)); if(!(*rsa)) { BCryptDestroyKey(hKey); - _libssh2_wincng_safe_free(key, keylen); + _libssh2_wincng_safe_free(rsakey, keylen); return -1; } (*rsa)->hKey = hKey; - (*rsa)->pbKeyObject = key; + (*rsa)->pbKeyObject = rsakey; (*rsa)->cbKeyObject = keylen; return 0; @@ -1340,7 +1351,6 @@ _libssh2_wincng_dsa_new(libssh2_dsa_ctx **dsa, BCRYPT_KEY_HANDLE hKey; BCRYPT_DSA_KEY_BLOB *dsakey; LPCWSTR lpszBlobType; - unsigned char *key; unsigned long keylen, offset, length; int ret; @@ -1352,16 +1362,15 @@ _libssh2_wincng_dsa_new(libssh2_dsa_ctx **dsa, if(xdata && xlen > 0) keylen += 20; - key = malloc(keylen); - if(!key) { + dsakey = (BCRYPT_DSA_KEY_BLOB *)malloc(keylen); + if(!dsakey) { return -1; } - memset(key, 0, keylen); + memset(dsakey, 0, keylen); /* https://msdn.microsoft.com/library/windows/desktop/aa833126.aspx */ - dsakey = (BCRYPT_DSA_KEY_BLOB *)key; dsakey->cbKey = length; memset(dsakey->Count, -1, sizeof(dsakey->Count)); @@ -1373,29 +1382,35 @@ _libssh2_wincng_dsa_new(libssh2_dsa_ctx **dsa, memcpy(dsakey->q, qdata + qlen - 20, 20); if(plen < length) - memcpy(key + offset + length - plen, pdata, plen); + memcpy((unsigned char *)dsakey + offset + length - plen, + pdata, plen); else - memcpy(key + offset, pdata + plen - length, length); + memcpy((unsigned char *)dsakey + offset, + pdata + plen - length, length); offset += length; if(glen < length) - memcpy(key + offset + length - glen, gdata, glen); + memcpy((unsigned char *)dsakey + offset + length - glen, + gdata, glen); else - memcpy(key + offset, gdata + glen - length, length); + memcpy((unsigned char *)dsakey + offset, + gdata + glen - length, length); offset += length; if(ylen < length) - memcpy(key + offset + length - ylen, ydata, ylen); + memcpy((unsigned char *)dsakey + offset + length - ylen, + ydata, ylen); else - memcpy(key + offset, ydata + ylen - length, length); + memcpy((unsigned char *)dsakey + offset, + ydata + ylen - length, length); if(xdata && xlen > 0) { offset += length; if(xlen < 20) - memcpy(key + offset + 20 - xlen, xdata, xlen); + memcpy((unsigned char *)dsakey + offset + 20 - xlen, xdata, xlen); else - memcpy(key + offset, xdata + xlen - 20, 20); + memcpy((unsigned char *)dsakey + offset, xdata + xlen - 20, 20); lpszBlobType = BCRYPT_DSA_PRIVATE_BLOB; dsakey->dwMagic = BCRYPT_DSA_PRIVATE_MAGIC; @@ -1407,9 +1422,9 @@ _libssh2_wincng_dsa_new(libssh2_dsa_ctx **dsa, ret = BCryptImportKeyPair(_libssh2_wincng.hAlgDSA, NULL, lpszBlobType, - &hKey, key, keylen, 0); + &hKey, (PUCHAR)dsakey, keylen, 0); if(!BCRYPT_SUCCESS(ret)) { - _libssh2_wincng_safe_free(key, keylen); + _libssh2_wincng_safe_free(dsakey, keylen); return -1; } @@ -1417,12 +1432,12 @@ _libssh2_wincng_dsa_new(libssh2_dsa_ctx **dsa, *dsa = malloc(sizeof(libssh2_dsa_ctx)); if(!(*dsa)) { BCryptDestroyKey(hKey); - _libssh2_wincng_safe_free(key, keylen); + _libssh2_wincng_safe_free(dsakey, keylen); return -1; } (*dsa)->hKey = hKey; - (*dsa)->pbKeyObject = key; + (*dsa)->pbKeyObject = dsakey; (*dsa)->cbKeyObject = keylen; return 0; @@ -1881,7 +1896,7 @@ _libssh2_wincng_cipher_init(_libssh2_cipher_ctx *ctx, { BCRYPT_KEY_HANDLE hKey; BCRYPT_KEY_DATA_BLOB_HEADER *header; - unsigned char *pbKeyObject, *pbIV, *key, *pbCtr, *pbIVCopy; + unsigned char *pbKeyObject, *pbIV, *pbCtr, *pbIVCopy; unsigned long dwKeyObject, dwIV, dwCtrLength, dwBlockLength, cbData, keylen; int ret; @@ -1910,26 +1925,27 @@ _libssh2_wincng_cipher_init(_libssh2_cipher_ctx *ctx, } - keylen = sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + type.dwKeyLength; - key = malloc(keylen); - if(!key) { + keylen = (unsigned long)sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + + type.dwKeyLength; + header = (BCRYPT_KEY_DATA_BLOB_HEADER *)malloc(keylen); + if(!header) { free(pbKeyObject); return -1; } - header = (BCRYPT_KEY_DATA_BLOB_HEADER *)key; header->dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC; header->dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1; header->cbKeyData = type.dwKeyLength; - memcpy(key + sizeof(BCRYPT_KEY_DATA_BLOB_HEADER), + memcpy((unsigned char *)header + sizeof(BCRYPT_KEY_DATA_BLOB_HEADER), secret, type.dwKeyLength); ret = BCryptImportKey(*type.phAlg, NULL, BCRYPT_KEY_DATA_BLOB, &hKey, - pbKeyObject, dwKeyObject, key, keylen, 0); + pbKeyObject, dwKeyObject, + (PUCHAR)header, keylen, 0); - _libssh2_wincng_safe_free(key, keylen); + _libssh2_wincng_safe_free(header, keylen); if(!BCRYPT_SUCCESS(ret)) { _libssh2_wincng_safe_free(pbKeyObject, dwKeyObject); @@ -2145,7 +2161,7 @@ _libssh2_wincng_bignum_mod_exp(_libssh2_bn *r, { BCRYPT_KEY_HANDLE hKey; BCRYPT_RSAKEY_BLOB *rsakey; - unsigned char *key, *bignum; + unsigned char *bignum; unsigned long keylen, offset, length; int ret; @@ -2155,13 +2171,12 @@ _libssh2_wincng_bignum_mod_exp(_libssh2_bn *r, offset = sizeof(BCRYPT_RSAKEY_BLOB); keylen = offset + p->length + m->length; - key = malloc(keylen); - if(!key) + rsakey = (BCRYPT_RSAKEY_BLOB *)malloc(keylen); + if(!rsakey) return -1; /* https://msdn.microsoft.com/library/windows/desktop/aa375531.aspx */ - rsakey = (BCRYPT_RSAKEY_BLOB *)key; rsakey->Magic = BCRYPT_RSAPUBLIC_MAGIC; rsakey->BitLength = m->length * 8; rsakey->cbPublicExp = p->length; @@ -2169,14 +2184,15 @@ _libssh2_wincng_bignum_mod_exp(_libssh2_bn *r, rsakey->cbPrime1 = 0; rsakey->cbPrime2 = 0; - memcpy(key + offset, p->bignum, p->length); + memcpy((unsigned char *)rsakey + offset, p->bignum, p->length); offset += p->length; - memcpy(key + offset, m->bignum, m->length); + memcpy((unsigned char *)rsakey + offset, m->bignum, m->length); offset = 0; ret = BCryptImportKeyPair(_libssh2_wincng.hAlgRSA, NULL, - BCRYPT_RSAPUBLIC_BLOB, &hKey, key, keylen, 0); + BCRYPT_RSAPUBLIC_BLOB, &hKey, + (PUCHAR)rsakey, keylen, 0); if(BCRYPT_SUCCESS(ret)) { ret = BCryptEncrypt(hKey, a->bignum, a->length, NULL, NULL, 0, NULL, 0, &length, BCRYPT_PAD_NONE); @@ -2208,7 +2224,7 @@ _libssh2_wincng_bignum_mod_exp(_libssh2_bn *r, BCryptDestroyKey(hKey); } - _libssh2_wincng_safe_free(key, keylen); + _libssh2_wincng_safe_free(rsakey, keylen); return BCRYPT_SUCCESS(ret) ? 0 : -1; } @@ -2370,9 +2386,8 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, return -1; while(_libssh2_wincng.hAlgDH && hasAlgDHwithKDF != -1) { - BCRYPT_DH_PARAMETER_HEADER *dh_params = NULL; + BCRYPT_DH_PARAMETER_HEADER *dh_params; unsigned long dh_params_len; - unsigned char *blob = NULL; int status; /* Note that the DH provider requires that keys be multiples of 64 bits * in length. At the time of writing a practical observed group_order @@ -2392,28 +2407,30 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, return -1; } - dh_params_len = sizeof(*dh_params) + 2 * key_length_bytes; - blob = malloc(dh_params_len); - if(!blob) { + dh_params_len = (unsigned long)sizeof(*dh_params) + + 2 * key_length_bytes; + dh_params = (BCRYPT_DH_PARAMETER_HEADER *)malloc(dh_params_len); + if(!dh_params) { return -1; } /* Populate DH parameters blob; after the header follows the `p` * value and the `g` value. */ - dh_params = (BCRYPT_DH_PARAMETER_HEADER*)blob; dh_params->cbLength = dh_params_len; dh_params->dwMagic = BCRYPT_DH_PARAMETERS_MAGIC; dh_params->cbKeyLength = key_length_bytes; - memcpy_with_be_padding(blob + sizeof(*dh_params), key_length_bytes, - p->bignum, p->length); - memcpy_with_be_padding(blob + sizeof(*dh_params) + key_length_bytes, + memcpy_with_be_padding((unsigned char *)dh_params + + sizeof(*dh_params), + key_length_bytes, p->bignum, p->length); + memcpy_with_be_padding((unsigned char *)dh_params + + sizeof(*dh_params) + key_length_bytes, key_length_bytes, g->bignum, g->length); status = BCryptSetProperty(dhctx->dh_handle, BCRYPT_DH_PARAMETERS, - blob, dh_params_len, 0); + (PUCHAR)dh_params, dh_params_len, 0); if(hasAlgDHwithKDF == -1) { /* We know that the raw KDF is not supported, so discard this. */ - free(blob); + free(dh_params); } else { /* Pass ownership to dhctx; these parameters will be freed when @@ -2423,7 +2440,6 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, dhctx->dh_params = dh_params; } dh_params = NULL; - blob = NULL; if(!BCRYPT_SUCCESS(status)) { return -1; @@ -2453,21 +2469,21 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, return -1; } - blob = malloc(key_length_bytes); - if(!blob) { + dh_key_blob = (BCRYPT_DH_KEY_BLOB *)malloc(key_length_bytes); + if(!dh_key_blob) { return -1; } status = BCryptExportKey(dhctx->dh_handle, NULL, key_type, - blob, key_length_bytes, + (PUCHAR)dh_key_blob, key_length_bytes, &key_length_bytes, 0); if(!BCRYPT_SUCCESS(status)) { if(hasAlgDHwithKDF == 1) { /* We have no private data, because raw KDF is supported */ - free(blob); + free(dh_key_blob); } else { /* we may have potentially private data, use secure free */ - _libssh2_wincng_safe_free(blob, key_length_bytes); + _libssh2_wincng_safe_free(dh_key_blob, key_length_bytes); } return -1; } @@ -2481,46 +2497,47 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, /* BCRYPT_DH_PUBLIC_BLOB corresponds to a BCRYPT_DH_KEY_BLOB header * followed by the Modulus, Generator and Public data. Those components * each have equal size, specified by dh_key_blob->cbKey. */ - dh_key_blob = (BCRYPT_DH_KEY_BLOB*)blob; if(_libssh2_wincng_bignum_resize(public, dh_key_blob->cbKey)) { if(hasAlgDHwithKDF == 1) { /* We have no private data, because raw KDF is supported */ - free(blob); + free(dh_key_blob); } else { /* we may have potentially private data, use secure free */ - _libssh2_wincng_safe_free(blob, key_length_bytes); + _libssh2_wincng_safe_free(dh_key_blob, key_length_bytes); } return -1; } /* Copy the public key data into the public bignum data buffer */ - memcpy(public->bignum, - blob + sizeof(*dh_key_blob) + 2 * dh_key_blob->cbKey, + memcpy(public->bignum, (unsigned char *)dh_key_blob + + sizeof(*dh_key_blob) + + 2 * dh_key_blob->cbKey, dh_key_blob->cbKey); if(dh_key_blob->dwMagic == BCRYPT_DH_PRIVATE_MAGIC) { /* BCRYPT_DH_PRIVATE_BLOB additionally contains the Private data */ dhctx->dh_privbn = _libssh2_wincng_bignum_init(); if(!dhctx->dh_privbn) { - _libssh2_wincng_safe_free(blob, key_length_bytes); + _libssh2_wincng_safe_free(dh_key_blob, key_length_bytes); return -1; } if(_libssh2_wincng_bignum_resize(dhctx->dh_privbn, dh_key_blob->cbKey)) { - _libssh2_wincng_safe_free(blob, key_length_bytes); + _libssh2_wincng_safe_free(dh_key_blob, key_length_bytes); return -1; } /* Copy the private key data into the dhctx bignum data buffer */ - memcpy(dhctx->dh_privbn->bignum, - blob + sizeof(*dh_key_blob) + 3 * dh_key_blob->cbKey, + memcpy(dhctx->dh_privbn->bignum, (unsigned char *)dh_key_blob + + sizeof(*dh_key_blob) + + 3 * dh_key_blob->cbKey, dh_key_blob->cbKey); /* Make sure the private key is an odd number, because only * odd primes can be used with the RSA-based fallback while * DH itself does not seem to care about it being odd or not. */ if(!(dhctx->dh_privbn->bignum[dhctx->dh_privbn->length-1] % 2)) { - _libssh2_wincng_safe_free(blob, key_length_bytes); + _libssh2_wincng_safe_free(dh_key_blob, key_length_bytes); /* discard everything first, then try again */ _libssh2_dh_dtor(dhctx); _libssh2_dh_init(dhctx); @@ -2528,7 +2545,7 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, } } - _libssh2_wincng_safe_free(blob, key_length_bytes); + _libssh2_wincng_safe_free(dh_key_blob, key_length_bytes); return 0; } @@ -2558,10 +2575,9 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, BCRYPT_KEY_HANDLE peer_public = NULL; BCRYPT_SECRET_HANDLE agreement = NULL; ULONG secret_len_bytes = 0; - unsigned char *blob; int status; unsigned char *start, *end; - BCRYPT_DH_KEY_BLOB *public_blob = NULL; + BCRYPT_DH_KEY_BLOB *public_blob; DWORD key_length_bytes = max(f->length, dhctx->dh_params->cbKeyLength); DWORD public_blob_len = (DWORD)(sizeof(*public_blob) + 3 * key_length_bytes); @@ -2573,11 +2589,10 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, unsigned char *dest; unsigned char *src; - blob = malloc(public_blob_len); - if(!blob) { + public_blob = (BCRYPT_DH_KEY_BLOB *)malloc(public_blob_len); + if(!public_blob) { return -1; } - public_blob = (BCRYPT_DH_KEY_BLOB*)blob; public_blob->dwMagic = BCRYPT_DH_PUBLIC_MAGIC; public_blob->cbKey = key_length_bytes; @@ -2598,8 +2613,8 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, /* Import the peer public key information */ status = BCryptImportKeyPair(_libssh2_wincng.hAlgDH, NULL, - BCRYPT_DH_PUBLIC_BLOB, &peer_public, blob, - public_blob_len, 0); + BCRYPT_DH_PUBLIC_BLOB, &peer_public, + (PUCHAR)public_blob, public_blob_len, 0); if(!BCRYPT_SUCCESS(status)) { goto out; } @@ -2665,7 +2680,7 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, BCryptDestroySecret(agreement); } - free(blob); + free(public_blob); if(status == STATUS_NOT_SUPPORTED && _libssh2_wincng.hasAlgDHwithKDF == -1) { diff --git a/src/wincng.h b/src/wincng.h index e5c77ef416..2b91afd1d8 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -251,7 +251,7 @@ typedef struct __libssh2_wincng_hash_ctx { typedef struct __libssh2_wincng_key_ctx { BCRYPT_KEY_HANDLE hKey; - unsigned char *pbKeyObject; + void *pbKeyObject; unsigned long cbKeyObject; } _libssh2_wincng_key_ctx; From 71cae949d577fdd632a271da0bec89f977dc5dd2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 01:23:55 +0200 Subject: [PATCH 162/424] ci: cmake `ENABLE_WERROR` -> `ON` (#877) Consider warnings as errors for CMake jobs in CI. --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fbf6460d9..fc08868bb2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: run: | mkdir bin cd bin - cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. + cmake $TOOLCHAIN_OPTION -DENABLE_WERROR=ON -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. cmake --build . --parallel 2 export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) ctest -VV --output-on-failure diff --git a/appveyor.yml b/appveyor.yml index 87596ab709..36d66b6f0c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -87,7 +87,7 @@ build_script: $env:CMAKE_ARG = "-DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win32" } } - - cmake . -B _builds "-G%GENERATOR%" %CMAKE_ARG% -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% + - cmake . -B _builds "-G%GENERATOR%" %CMAKE_ARG% -DENABLE_WERROR=ON -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% - cmake --build _builds --config "%CONFIGURATION%" --parallel 2 before_test: From a3d42f41d002c72c19fd39d9437e99607e1b3e2a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 11:27:05 +0200 Subject: [PATCH 163/424] ci: fix cmake warning with AppVeyor WinCNG builds (#883) ``` CMake Warning: Manually-specified variables were not used by the project: OPENSSL_ROOT_DIR ``` Follow-up to 0834b9bcc85b90c78afff103f909b5a909b95e45 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 36d66b6f0c..ce703f856f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -80,7 +80,7 @@ install: build_script: - ps: | if($env:PLATFORM -eq "x64") { $env:GENERATOR = "$env:GENERATOR Win64" } - if($env:SKIP_CTEST -ne "yes") { + if($env:SKIP_CTEST -ne "yes" -and $env:CRYPTO_BACKEND -eq "OpenSSL") { if($env:PLATFORM -eq "x64") { $env:CMAKE_ARG = "-DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64" } elseif($env:PLATFORM -eq "x86") { From 4f28eec947d9901605592def35de617134fa053f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 11:27:59 +0200 Subject: [PATCH 164/424] src: more tolerant snprintf() local override (#881) `#undef snprintf` before redefining it, when `HAVE_SNPRINTF` is not defined, even though `snprintf` is available and it should have been. Possibly with 3rd party builds. Downside is that cases of missing `HAVE_SNPRINTF` are less trivially detected at compile-time. --- src/libssh2_priv.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index b0a44bc7f0..3e02cf1834 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -135,6 +135,7 @@ /* Use local implementation when not available */ #if !defined(HAVE_SNPRINTF) #define LIBSSH2_SNPRINTF +#undef snprintf #define snprintf _libssh2_snprintf int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...); #endif From 38177f18dd4fe484e4044186217cdc287cd04076 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 11:28:51 +0200 Subject: [PATCH 165/424] delete old gex (SSH2_MSG_KEX_DH_GEX_REQUEST_OLD) build option (#872) libssh2 supports an "old" style KEX message `SSH2_MSG_KEX_DH_GEX_REQUEST_OLD`, as an off-by-default build option. OpenSSH deprecated/disabled this feature in v6.9 (2015-07-01): https://www.openssh.com/releasenotes.html#6.9 This patch deletes this obsolete feature from libssh2, with no option to enable it. Added to libssh2 in: cf8ca63ea0c9388c8ae9079961d7e6a91b72b5c8 (2004-12-31) RFC: https://datatracker.ietf.org/doc/html/rfc4419 (2006-03) --- configure.ac | 7 ------- docs/INSTALL_AUTOTOOLS | 14 -------------- docs/INSTALL_CMAKE.md | 12 ------------ nw/GNUmakefile | 1 - os400/libssh2_config.h | 3 --- src/CMakeLists.txt | 8 -------- src/kex.c | 31 ++----------------------------- vms/libssh2_config.h | 4 ---- win32/libssh2_config.h | 3 --- 9 files changed, 2 insertions(+), 81 deletions(-) diff --git a/configure.ac b/configure.ac index 61fa13aa2a..1bebee5f5e 100644 --- a/configure.ac +++ b/configure.ac @@ -165,13 +165,6 @@ AC_ARG_ENABLE(mac-none, AC_HELP_STRING([--enable-mac-none],[Permit "none" MAC -- NOT RECOMMENDED]), [AC_DEFINE(LIBSSH2_MAC_NONE, 1, [Enable "none" MAC -- NOT RECOMMENDED])]) -AC_ARG_ENABLE(gex-new, - AC_HELP_STRING([--disable-gex-new],[Disable "new" diffie-hellman-group-exchange-sha1 method]), - [GEX_NEW=$enableval]) -if test "$GEX_NEW" != "no"; then - AC_DEFINE(LIBSSH2_DH_GEX_NEW, 1, [Enable newer diffie-hellman-group-exchange-sha1 syntax]) -fi - AC_ARG_ENABLE(clear-memory, AC_HELP_STRING([--disable-clear-memory],[Disable clearing of memory before being freed]), [CLEAR_MEMORY=$enableval]) diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index 00e0f3925b..5577886d20 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -280,20 +280,6 @@ Some ./configure options deserve additional comments: method be advertized by the remote end and that no more-preferable methods are available. - * --disable-gex-new - - The diffie-hellman-group-exchange-sha1 (dh-gex) key - exchange method originally defined an exchange - negotiation using packet type 30 to request a - generation pair based on a single target value. Later - refinement of dh-gex provided for range and target - values. By default libssh2 will use the newer range - method. - - If you experience trouble connecting to an old SSH - server using dh-gex, try this option to fallback on - the older more reliable method. - * --with-libgcrypt * --without-libgcrypt * --with-libgcrypt-prefix=DIR diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index fe203068cc..779238e760 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -96,18 +96,6 @@ The following options are available: however it still requires that the method be advertized by the remote end and that no more-preferable methods are available. - * `ENABLE_GEX_NEW=ON` - - The diffie-hellman-group-exchange-sha1 (dh-gex) key exchange - method originally defined an exchange negotiation using packet - type 30 to request a generation pair based on a single target - value. Later refinement of dh-gex provided for range and target - values. By default libssh2 will use the newer range method. - - If you experience trouble connecting to an old SSH server using - dh-gex, try this option to fallback on the older more reliable - method. - * `ENABLE_DEBUG_LOGGING=ON` in Debug, `=OFF` in Release Will enable the libssh2_trace() function for showing debug traces. diff --git a/nw/GNUmakefile b/nw/GNUmakefile index 4a4e28c341..291f59241c 100644 --- a/nw/GNUmakefile +++ b/nw/GNUmakefile @@ -424,7 +424,6 @@ endif ifdef OLD_NOVELLSDK @echo $(DL)#define socklen_t int$(DL) >> $@ endif - @echo $(DL)#define LIBSSH2_DH_GEX_NEW 1$(DL) >> $@ ifeq ($(DB),DEBUG) @echo $(DL)#define LIBSSH2_DEBUG_CONNECTION 1$(DL) >> $@ @echo $(DL)#define LIBSSH2_DEBUG_ERRORS 1$(DL) >> $@ diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 713eb52884..d1b6b7bb82 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -146,9 +146,6 @@ /* Enable "none" cipher -- NOT RECOMMENDED */ #undef LIBSSH2_CRYPT_NONE -/* Enable newer diffie-hellman-group-exchange-sha1 syntax */ -#define LIBSSH2_DH_GEX_NEW 1 - /* Compile in zlib support */ /* #undef LIBSSH2_HAVE_ZLIB */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b98549d4a3..30a20d9e68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -222,14 +222,6 @@ if(ENABLE_MAC_NONE) list(APPEND libssh2_DEFINITIONS LIBSSH2_MAC_NONE=1) endif() -option(ENABLE_GEX_NEW - "Enable diffie-hellman-group-exchange-sha1 method" ON) -add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW - "\"new\" diffie-hellman-group-exchange-sha1 method") -if(ENABLE_GEX_NEW) - list(APPEND libssh2_DEFINITIONS LIBSSH2_DH_GEX_NEW=1) -endif() - # Enable debugging logging by default if the user configured a debug build if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(DEBUG_LOGGING_DEFAULT ON) diff --git a/src/kex.c b/src/kex.c index bd7e83de3c..b3f7d2ce7c 100644 --- a/src/kex.c +++ b/src/kex.c @@ -583,7 +583,6 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, if(packet_type_init == SSH_MSG_KEX_DH_GEX_INIT) { /* diffie-hellman-group-exchange hashes additional fields */ -#ifdef LIBSSH2_DH_GEX_NEW _libssh2_htonu32(exchange_state->h_sig_comp, LIBSSH2_DH_GEX_MINGROUP); _libssh2_htonu32(exchange_state->h_sig_comp + 4, @@ -592,12 +591,6 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, LIBSSH2_DH_GEX_MAXGROUP); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 12); -#else - _libssh2_htonu32(exchange_state->h_sig_comp, - LIBSSH2_DH_GEX_OPTGROUP); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); -#endif } if(midhash) { @@ -1342,23 +1335,13 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange key_state->p = _libssh2_bn_init_from_bin(); key_state->g = _libssh2_bn_init_from_bin(); /* Ask for a P and G pair */ -#ifdef LIBSSH2_DH_GEX_NEW key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST; _libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_MINGROUP); _libssh2_htonu32(key_state->request + 5, LIBSSH2_DH_GEX_OPTGROUP); _libssh2_htonu32(key_state->request + 9, LIBSSH2_DH_GEX_MAXGROUP); key_state->request_len = 13; _libssh2_debug((session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group-Exchange " - "(New Method)")); -#else - key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST_OLD; - _libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_OPTGROUP); - key_state->request_len = 5; - _libssh2_debug((session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group-Exchange " - "(Old Method)")); -#endif + "Initiating Diffie-Hellman Group-Exchange SHA1")); key_state->state = libssh2_NB_state_created; } @@ -1469,23 +1452,13 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange key_state->p = _libssh2_bn_init(); key_state->g = _libssh2_bn_init(); /* Ask for a P and G pair */ -#ifdef LIBSSH2_DH_GEX_NEW key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST; _libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_MINGROUP); _libssh2_htonu32(key_state->request + 5, LIBSSH2_DH_GEX_OPTGROUP); _libssh2_htonu32(key_state->request + 9, LIBSSH2_DH_GEX_MAXGROUP); key_state->request_len = 13; _libssh2_debug((session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group-Exchange " - "(New Method SHA256)")); -#else - key_state->request[0] = SSH_MSG_KEX_DH_GEX_REQUEST_OLD; - _libssh2_htonu32(key_state->request + 1, LIBSSH2_DH_GEX_OPTGROUP); - key_state->request_len = 5; - _libssh2_debug((session, LIBSSH2_TRACE_KEX, - "Initiating Diffie-Hellman Group-Exchange " - "(Old Method SHA256)")); -#endif + "Initiating Diffie-Hellman Group-Exchange SHA256")); key_state->state = libssh2_NB_state_created; } diff --git a/vms/libssh2_config.h b/vms/libssh2_config.h index 45a49b5ac7..8cbee62dcf 100644 --- a/vms/libssh2_config.h +++ b/vms/libssh2_config.h @@ -81,9 +81,5 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ #define LIBSSH2_HAVE_ZLIB -/* Enable newer diffie-hellman-group-exchange-sha1 syntax */ - -#define LIBSSH2_DH_GEX_NEW 1 - #endif /* __VMS */ #endif /* LIBSSH2_CONFIG_H */ diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index e6df03cfb1..352209108a 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -34,7 +34,4 @@ # endif #endif -/* Enable newer diffie-hellman-group-exchange-sha1 syntax */ -#define LIBSSH2_DH_GEX_NEW 1 - #endif /* LIBSSH2_CONFIG_H */ From 50c9bf868e833258d23c5f55ed546d1fcd5687d0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 11:34:54 +0200 Subject: [PATCH 166/424] rework how to enable insecure null-cipher/null-MAC (#873) Null-cipher and null-MAC are security footguns we want to avoid. Existing option names to toggle these were ambiguous and gave room for misinterpretation. Some projects may have had these options enabled by accident. This patch aims to make it more difficult to enable them, and making sure that existing methods require an update to stay enabled. - delete CMake/autotools settings to enable the "none" cipher and MAC. - rename existing C macros that can enable them. To use them, pass them as custom `CPPFLAGS` to the build. - enable them only if `LIBSSH2DEBUG` is also enabled. Best would be to delete them, though they may have some use while developing libssh2 itself, or debugging. --- configure.ac | 8 -------- os400/libssh2_config.h | 6 ------ src/CMakeLists.txt | 12 ------------ src/crypt.c | 8 ++++---- src/mac.c | 10 +++++----- 5 files changed, 9 insertions(+), 35 deletions(-) diff --git a/configure.ac b/configure.ac index 1bebee5f5e..624944fd60 100644 --- a/configure.ac +++ b/configure.ac @@ -157,14 +157,6 @@ AC_SUBST(LIBSREQUIRED) # # Optional Settings # -AC_ARG_ENABLE(crypt-none, - AC_HELP_STRING([--enable-crypt-none],[Permit "none" cipher -- NOT RECOMMENDED]), - [AC_DEFINE(LIBSSH2_CRYPT_NONE, 1, [Enable "none" cipher -- NOT RECOMMENDED])]) - -AC_ARG_ENABLE(mac-none, - AC_HELP_STRING([--enable-mac-none],[Permit "none" MAC -- NOT RECOMMENDED]), - [AC_DEFINE(LIBSSH2_MAC_NONE, 1, [Enable "none" MAC -- NOT RECOMMENDED])]) - AC_ARG_ENABLE(clear-memory, AC_HELP_STRING([--disable-clear-memory],[Disable clearing of memory before being freed]), [CLEAR_MEMORY=$enableval]) diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index d1b6b7bb82..9e1174197f 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -143,18 +143,12 @@ /* to make a symbol visible */ #undef LIBSSH2_API -/* Enable "none" cipher -- NOT RECOMMENDED */ -#undef LIBSSH2_CRYPT_NONE - /* Compile in zlib support */ /* #undef LIBSSH2_HAVE_ZLIB */ /* Use libgcrypt */ #undef LIBSSH2_LIBGCRYPT -/* Enable "none" MAC -- NOT RECOMMENDED */ -#undef LIBSSH2_MAC_NONE - /* Use OpenSSL */ #undef LIBSSH2_OPENSSL diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30a20d9e68..6795825a44 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -210,18 +210,6 @@ if(ENABLE_ZLIB_COMPRESSION) endif() endif() -option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED") -add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "") -if(ENABLE_CRYPT_NONE) - list(APPEND libssh2_DEFINITIONS LIBSSH2_CRYPT_NONE=1) -endif() - -option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED") -add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "") -if(ENABLE_MAC_NONE) - list(APPEND libssh2_DEFINITIONS LIBSSH2_MAC_NONE=1) -endif() - # Enable debugging logging by default if the user configured a debug build if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(DEBUG_LOGGING_DEFAULT ON) diff --git a/src/crypt.c b/src/crypt.c index b7d9e6c65b..0674e925b9 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -38,10 +38,10 @@ #include "libssh2_priv.h" -#ifdef LIBSSH2_CRYPT_NONE +#if defined(LIBSSH2DEBUG) && defined(LIBSSH2_CRYPT_NONE_INSECURE) /* crypt_none_crypt - * Minimalist cipher: VERY secure *wink* + * Minimalist cipher: no encryption. DO NOT USE. */ static int crypt_none_crypt(LIBSSH2_SESSION * session, unsigned char *buf, @@ -62,7 +62,7 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = { crypt_none_crypt, NULL }; -#endif /* LIBSSH2_CRYPT_NONE */ +#endif /* defined(LIBSSH2DEBUG) && defined(LIBSSH2_CRYPT_NONE_INSECURE) */ struct crypt_ctx { @@ -337,7 +337,7 @@ static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = { #if LIBSSH2_3DES &libssh2_crypt_method_3des_cbc, #endif /* LIBSSH2_DES */ -#ifdef LIBSSH2_CRYPT_NONE +#if defined(LIBSSH2DEBUG) && defined(LIBSSH2_CRYPT_NONE_INSECURE) &libssh2_crypt_method_none, #endif NULL diff --git a/src/mac.c b/src/mac.c index 146671efe5..ffdc209bf1 100644 --- a/src/mac.c +++ b/src/mac.c @@ -38,9 +38,9 @@ #include "libssh2_priv.h" #include "mac.h" -#ifdef LIBSSH2_MAC_NONE +#if defined(LIBSSH2DEBUG) && defined(LIBSSH2_MAC_NONE_INSECURE) /* mac_none_MAC - * Minimalist MAC: No MAC + * Minimalist MAC: No MAC. DO NOT USE. */ static int mac_none_MAC(LIBSSH2_SESSION * session, unsigned char *buf, @@ -62,7 +62,7 @@ static LIBSSH2_MAC_METHOD mac_method_none = { mac_none_MAC, NULL }; -#endif /* LIBSSH2_MAC_NONE */ +#endif /* defined(LIBSSH2DEBUG) && defined(LIBSSH2_MAC_NONE_INSECURE) */ /* mac_method_common_init * Initialize simple mac methods @@ -401,9 +401,9 @@ static const LIBSSH2_MAC_METHOD *mac_methods[] = { &mac_method_hmac_ripemd160, &mac_method_hmac_ripemd160_openssh_com, #endif /* LIBSSH2_HMAC_RIPEMD */ -#ifdef LIBSSH2_MAC_NONE +#if defined(LIBSSH2DEBUG) && defined(LIBSSH2_MAC_NONE_INSECURE) &mac_method_none, -#endif /* LIBSSH2_MAC_NONE */ +#endif NULL }; From 0d08974633cfc02641e6593db8d569ddb3644255 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 16:29:00 +0200 Subject: [PATCH 167/424] ci: drop cmake --parallel (#884) `--parallel 2` did not seem to make builds faster. Neither did 4 or 6. Delete this option from both GHA and AppVeyor jobs. On AppVeyor, with VS, it uses MSBuild under the hood where apparently `--parallel` doesn't do much [1]. The suggested MSBuild-specific option `/p:CL_MPcount=2` did not improve build times either. CMake spends significant time (comparable to building the project itself) on feature detection, it'd be nice to execute those in parallel, but I found not such CMake option. [1] https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964 Partial revert of 7a039d9a7a2945c10b4622f38eeed21ba6b4ec55 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc08868bb2..0f9c736128 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: mkdir bin cd bin cmake $TOOLCHAIN_OPTION -DENABLE_WERROR=ON -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. - cmake --build . --parallel 2 + cmake --build . export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) ctest -VV --output-on-failure cmake --build . --target package diff --git a/appveyor.yml b/appveyor.yml index ce703f856f..c6ff8c43fd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -88,7 +88,7 @@ build_script: } } - cmake . -B _builds "-G%GENERATOR%" %CMAKE_ARG% -DENABLE_WERROR=ON -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% - - cmake --build _builds --config "%CONFIGURATION%" --parallel 2 + - cmake --build _builds --config "%CONFIGURATION%" before_test: - appveyor-retry choco install -y --no-progress --limit-output --timeout 180 docker-cli From 2f16d8105c9491beb2a02b3081f4f1c2a224fa62 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 18:28:27 +0200 Subject: [PATCH 168/424] tidy-up: replace tabs and other whitespace (#885) There are a few non-whitespace changes, see them here: https://github.com/libssh2/libssh2/pull/885/files?w=1 --- .gitignore | 2 +- Makefile.am | 93 +++-- Makefile.inc | 12 +- NMakefile | 2 +- docs/INSTALL_AUTOTOOLS | 76 ++-- docs/Makefile.am | 352 +++++++++--------- docs/libssh2_agent_connect.3 | 1 - docs/libssh2_agent_get_identity_path.3 | 1 - docs/libssh2_agent_list_identities.3 | 1 - docs/libssh2_agent_set_identity_path.3 | 1 - docs/libssh2_agent_userauth.3 | 4 +- docs/libssh2_banner_set.3 | 8 +- docs/libssh2_channel_close.3 | 12 +- docs/libssh2_channel_direct_tcpip_ex.3 | 12 +- docs/libssh2_channel_eof.3 | 2 +- docs/libssh2_channel_flush_ex.3 | 10 +- docs/libssh2_channel_forward_cancel.3 | 4 +- docs/libssh2_channel_forward_listen_ex.3 | 6 +- docs/libssh2_channel_free.3 | 8 +- docs/libssh2_channel_get_exit_signal.3 | 8 +- docs/libssh2_channel_get_exit_status.3 | 6 +- docs/libssh2_channel_handle_extended_data.3 | 6 +- docs/libssh2_channel_handle_extended_data2.3 | 14 +- docs/libssh2_channel_open_ex.3 | 18 +- docs/libssh2_channel_process_startup.3 | 6 +- docs/libssh2_channel_read_ex.3 | 4 +- docs/libssh2_channel_request_pty_ex.3 | 12 +- docs/libssh2_channel_send_eof.3 | 4 +- docs/libssh2_channel_set_blocking.3 | 4 +- docs/libssh2_channel_setenv_ex.3 | 6 +- docs/libssh2_channel_wait_closed.3 | 2 +- docs/libssh2_channel_wait_eof.3 | 2 +- docs/libssh2_channel_write_ex.3 | 8 +- docs/libssh2_channel_x11_req_ex.3 | 6 +- docs/libssh2_hostkey_hash.3 | 8 +- docs/libssh2_keepalive_config.3 | 1 - docs/libssh2_knownhost_writefile.3 | 1 - docs/libssh2_knownhost_writeline.3 | 1 - docs/libssh2_publickey_add.3 | 2 +- docs/libssh2_publickey_remove.3 | 4 +- docs/libssh2_scp_recv.3 | 5 +- docs/libssh2_scp_recv2.3 | 5 +- docs/libssh2_scp_send64.3 | 6 +- docs/libssh2_scp_send_ex.3 | 8 +- docs/libssh2_session_abstract.3 | 2 +- docs/libssh2_session_banner_set.3 | 4 +- docs/libssh2_session_callback_set.3 | 4 +- docs/libssh2_session_disconnect_ex.3 | 12 +- docs/libssh2_session_free.3 | 2 +- docs/libssh2_session_init_ex.3 | 18 +- docs/libssh2_session_last_errno.3 | 2 +- docs/libssh2_session_last_error.3 | 12 +- docs/libssh2_session_method_pref.3 | 12 +- docs/libssh2_session_set_blocking.3 | 4 +- docs/libssh2_session_startup.3 | 12 +- docs/libssh2_sftp_close_handle.3 | 12 +- docs/libssh2_sftp_fstat_ex.3 | 14 +- docs/libssh2_sftp_init.3 | 8 +- docs/libssh2_sftp_last_error.3 | 4 +- docs/libssh2_sftp_mkdir_ex.3 | 14 +- docs/libssh2_sftp_open_ex.3 | 11 +- docs/libssh2_sftp_read.3 | 12 +- docs/libssh2_sftp_readdir_ex.3 | 16 +- docs/libssh2_sftp_rename_ex.3 | 30 +- docs/libssh2_sftp_rmdir_ex.3 | 8 +- docs/libssh2_sftp_seek.3 | 10 +- docs/libssh2_sftp_seek64.3 | 2 +- docs/libssh2_sftp_shutdown.3 | 6 +- docs/libssh2_sftp_stat_ex.3 | 16 +- docs/libssh2_sftp_statvfs.3 | 2 +- docs/libssh2_sftp_symlink_ex.3 | 14 +- docs/libssh2_sftp_tell.3 | 2 +- docs/libssh2_sftp_unlink_ex.3 | 14 +- docs/libssh2_sftp_write.3 | 6 +- docs/libssh2_sign_sk.3 | 32 +- docs/libssh2_userauth_authenticated.3 | 4 +- docs/libssh2_userauth_list.3 | 2 +- docs/libssh2_userauth_password_ex.3 | 16 +- docs/libssh2_userauth_publickey_fromfile_ex.3 | 2 +- docs/libssh2_userauth_publickey_frommemory.3 | 2 +- docs/libssh2_userauth_publickey_sk.3 | 38 +- docs/template.3 | 2 +- example/Makefile.am | 31 +- git2news.pl | 2 +- libssh2-style.el | 22 +- m4/autobuild.m4 | 44 +-- m4/lib-ld.m4 | 6 +- maketgz | 38 +- nw/GNUmakefile | 204 +++++----- nw/keepscreen.c | 10 +- nw/nwlib.c | 2 - nw/test/GNUmakefile | 192 +++++----- os400/ccsid.c | 2 +- os400/libssh2_config.h | 6 +- os400/macros.h | 4 +- src/Makefile.am | 4 +- tests/Makefile.am | 125 ++++--- tests/ossfuzz/Makefile.am | 4 +- vms/libssh2_config.h | 38 +- vms/libssh2_make_example.dcl | 70 ++-- vms/libssh2_make_kit.dcl | 35 +- vms/libssh2_make_lib.dcl | 74 ++-- vms/man2help.c | 64 ++-- vms/readme.vms | 107 +++--- 104 files changed, 1109 insertions(+), 1112 deletions(-) diff --git a/.gitignore b/.gitignore index 4292e8d6f2..460bb772ad 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,4 @@ libssh2.pc TAGS *~ .DS_Store -build \ No newline at end of file +build diff --git a/Makefile.am b/Makefile.am index ce20ba5453..e0489bdb52 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,45 +11,45 @@ endif pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libssh2.pc -include_HEADERS = \ - include/libssh2.h \ - include/libssh2_publickey.h \ - include/libssh2_sftp.h +include_HEADERS = \ + include/libssh2.h \ + include/libssh2_publickey.h \ + include/libssh2_sftp.h NETWAREFILES = nw/keepscreen.c \ - nw/nwlib.c \ - nw/GNUmakefile \ - nw/test/GNUmakefile + nw/nwlib.c \ + nw/GNUmakefile \ + nw/test/GNUmakefile DSP = win32/libssh2.dsp VCPROJ = win32/libssh2.vcproj DISTCLEANFILES = $(DSP) -VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ -vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c \ -vms/readme.vms vms/libssh2_config.h - -WIN32FILES = win32/GNUmakefile \ -win32/libssh2_config.h win32/config.mk win32/rules.mk \ -win32/Makefile.Watcom win32/libssh2.dsw win32/tests.dsp $(DSP) \ -win32/msvcproj.head win32/msvcproj.foot win32/libssh2.rc - -OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ -os400/make-src.sh os400/make-rpg.sh os400/make-include.sh \ -os400/os400sys.c os400/ccsid.c \ -os400/libssh2_config.h os400/macros.h os400/libssh2_ccsid.h \ -os400/include/alloca.h os400/include/sys/socket.h os400/include/stdio.h \ -os400/libssh2rpg/libssh2.rpgle.in \ -os400/libssh2rpg/libssh2_ccsid.rpgle.in \ -os400/libssh2rpg/libssh2_publickey.rpgle \ -os400/libssh2rpg/libssh2_sftp.rpgle \ -Makefile.os400qc3.inc +VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ + vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c \ + vms/readme.vms vms/libssh2_config.h + +WIN32FILES = win32/GNUmakefile \ + win32/libssh2_config.h win32/config.mk win32/rules.mk \ + win32/Makefile.Watcom win32/libssh2.dsw win32/tests.dsp $(DSP) \ + win32/msvcproj.head win32/msvcproj.foot win32/libssh2.rc + +OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ + os400/make-src.sh os400/make-rpg.sh os400/make-include.sh \ + os400/os400sys.c os400/ccsid.c \ + os400/libssh2_config.h os400/macros.h os400/libssh2_ccsid.h \ + os400/include/alloca.h os400/include/sys/socket.h os400/include/stdio.h \ + os400/libssh2rpg/libssh2.rpgle.in \ + os400/libssh2rpg/libssh2_ccsid.rpgle.in \ + os400/libssh2rpg/libssh2_publickey.rpgle \ + os400/libssh2rpg/libssh2_sftp.rpgle \ + Makefile.os400qc3.inc EXTRA_DIST = $(WIN32FILES) $(NETWAREFILES) get_ver.awk \ - maketgz NMakefile RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ - CMakeLists.txt cmake git2news.pl libssh2-style.el README.md $(OS400FILES) \ - buildconf + maketgz NMakefile RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ + CMakeLists.txt cmake git2news.pl libssh2-style.el README.md $(OS400FILES) \ + buildconf ACLOCAL_AMFLAGS = -I m4 @@ -110,10 +110,10 @@ $(DSP): win32/msvcproj.head win32/msvcproj.foot Makefile.am win32_srcs='$(WIN32SOURCES)'; \ sorted_srcs=`for file in $$win32_srcs; do echo $$file; done | sort`; \ for file in $$sorted_srcs; do \ - echo "# Begin Source File"; \ - echo ""; \ - echo "SOURCE=..\\src\\"$$file; \ - echo "# End Source File"; \ + echo "# Begin Source File"; \ + echo ""; \ + echo "SOURCE=..\\src\\"$$file; \ + echo "# End Source File"; \ done; \ echo "# End Group"; \ echo "# Begin Group \"Header Files\""; \ @@ -122,15 +122,14 @@ $(DSP): win32/msvcproj.head win32/msvcproj.foot Makefile.am win32_hdrs='$(WIN32HEADERS)'; \ sorted_hdrs=`for file in $$win32_hdrs; do echo $$file; done | sort`; \ for file in $$sorted_hdrs; do \ - echo "# Begin Source File"; \ - echo ""; \ - if [ "$$file" = "libssh2_config.h" ]; \ - then \ - echo "SOURCE=.\\"$$file; \ - else \ - echo "SOURCE=..\\src\\"$$file; \ - fi; \ - echo "# End Source File"; \ + echo "# Begin Source File"; \ + echo ""; \ + if [ "$$file" = "libssh2_config.h" ]; then \ + echo "SOURCE=.\\"$$file; \ + else \ + echo "SOURCE=..\\src\\"$$file; \ + fi; \ + echo "# End Source File"; \ done; \ echo "# End Group"; \ cat $(srcdir)/win32/msvcproj.foot) | \ @@ -142,18 +141,18 @@ $(VCPROJ): win32/vc8proj.head win32/vc8proj.foot Makefile.am win32_srcs='$(WIN32SOURCES)'; \ sorted_srcs=`for file in $$win32_srcs; do echo $$file; done | sort`; \ for file in $$sorted_srcs; do \ - echo ""; \ + echo ""; \ done; \ - echo ""; \ + echo ""; \ win32_hdrs='$(WIN32HEADERS)'; \ sorted_hdrs=`for file in $$win32_hdrs; do echo $$file; done | sort`; \ for file in $$sorted_hdrs; do \ - echo ""; \ + echo ""; \ done; \ cat $(srcdir)/vc8proj.foot) | \ awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ ) checksrc: perl src/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT \ - -AFOPENMODE -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \ - tests/*.[ch] + -AFOPENMODE -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \ + tests/*.[ch] diff --git a/Makefile.inc b/Makefile.inc index 29273f4aaf..a6524cdeb4 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -1,9 +1,9 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ - packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ - userauth_kbd_packet.c \ - version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ - blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c + packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ + userauth_kbd_packet.c \ + version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ + blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c HHEADERS = libssh2_priv.h $(CRYPTO_HHEADERS) transport.h channel.h comp.h \ - mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h blf.h agent.h \ - userauth_kbd_packet.h os400qc3.h + mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h blf.h agent.h \ + userauth_kbd_packet.h os400qc3.h diff --git a/NMakefile b/NMakefile index 07bc2ddad1..f0867089db 100644 --- a/NMakefile +++ b/NMakefile @@ -15,7 +15,7 @@ SUBDIRS=src all-sub: win32\objects.mk -for %D in ($(SUBDIRS)) do $(MAKE) /nologo /f %D/NMakefile BUILD=$(BUILD) SUBDIR=%D all-sub -clean: +clean: -rmdir 2>NUL /s/q $(TARGET) -del 2>NUL win32\objects.mk diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index 5577886d20..a98441df9b 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -256,57 +256,57 @@ Some ./configure options deserve additional comments: * --enable-crypt-none - The SSH2 Transport allows for unencrypted data - transmission using the "none" cipher. Because this is - such a huge security hole, it is typically disabled on - SSH2 implementations and is disabled in libssh2 by - default as well. + The SSH2 Transport allows for unencrypted data + transmission using the "none" cipher. Because this is + such a huge security hole, it is typically disabled on + SSH2 implementations and is disabled in libssh2 by + default as well. - Enabling this option will allow for "none" as a - negotiable method, however it still requires that the - method be advertized by the remote end and that no - more-preferable methods are available. + Enabling this option will allow for "none" as a + negotiable method, however it still requires that the + method be advertized by the remote end and that no + more-preferable methods are available. * --enable-mac-none - The SSH2 Transport also allows implementations to - forego a message authentication code. While this is - less of a security risk than using a "none" cipher, it - is still not recommended as disabling MAC hashes - removes a layer of security. + The SSH2 Transport also allows implementations to + forego a message authentication code. While this is + less of a security risk than using a "none" cipher, it + is still not recommended as disabling MAC hashes + removes a layer of security. - Enabling this option will allow for "none" as a - negotiable method, however it still requires that the - method be advertized by the remote end and that no - more-preferable methods are available. + Enabling this option will allow for "none" as a + negotiable method, however it still requires that the + method be advertized by the remote end and that no + more-preferable methods are available. * --with-libgcrypt * --without-libgcrypt * --with-libgcrypt-prefix=DIR - libssh2 can use the Libgcrypt library - (https://www.gnupg.org/) for cryptographic operations. + libssh2 can use the Libgcrypt library + (https://www.gnupg.org/) for cryptographic operations. One of the cryptographic libraries is required. - Configure will attempt to locate Libgcrypt - automatically. + Configure will attempt to locate Libgcrypt + automatically. - If your installation of Libgcrypt is in another - location, specify it using --with-libgcrypt-prefix. + If your installation of Libgcrypt is in another + location, specify it using --with-libgcrypt-prefix. * --with-openssl * --without-openssl * --with-libssl-prefix=[DIR] - libssh2 can use the OpenSSL library - (https://www.openssl.org) for cryptographic operations. + libssh2 can use the OpenSSL library + (https://www.openssl.org) for cryptographic operations. One of the cryptographic libraries is required. - Configure will attempt to locate OpenSSL in the - default location. + Configure will attempt to locate OpenSSL in the + default location. - If your installation of OpenSSL is in another - location, specify it using --with-libssl-prefix. + If your installation of OpenSSL is in another + location, specify it using --with-libssl-prefix. * --with-mbedtls * --without-mbedtls @@ -326,15 +326,15 @@ Some ./configure options deserve additional comments: * --without-libz * --with-libz-prefix=[DIR] - If present, libssh2 will attempt to use the zlib - (http://www.zlib.org) for payload compression, however - zlib is not required. + If present, libssh2 will attempt to use the zlib + (http://www.zlib.org) for payload compression, however + zlib is not required. - If your installation of Libz is in another location, - specify it using --with-libz-prefix. + If your installation of Libz is in another location, + specify it using --with-libz-prefix. * --enable-debug - Will make the build use more pedantic and strict compiler - options as well as enable the libssh2_trace() function (for - showing debug traces). + Will make the build use more pedantic and strict compiler + options as well as enable the libssh2_trace() function (for + showing debug traces). diff --git a/docs/Makefile.am b/docs/Makefile.am index 30d6ef0b6b..6b938ba71b 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -4,179 +4,179 @@ EXTRA_DIST = template.3 BINDINGS INSTALL_AUTOTOOLS INSTALL_CMAKE.md HACKING TODO AUTHORS CMakeLists.txt HACKING-CRYPTO SECURITY.md dist_man_MANS = \ - libssh2_agent_connect.3 \ - libssh2_agent_disconnect.3 \ - libssh2_agent_free.3 \ - libssh2_agent_get_identity.3 \ - libssh2_agent_get_identity_path.3 \ - libssh2_agent_init.3 \ - libssh2_agent_list_identities.3 \ - libssh2_agent_set_identity_path.3 \ - libssh2_agent_userauth.3 \ - libssh2_banner_set.3 \ - libssh2_base64_decode.3 \ - libssh2_channel_close.3 \ - libssh2_channel_direct_tcpip.3 \ - libssh2_channel_direct_tcpip_ex.3 \ - libssh2_channel_eof.3 \ - libssh2_channel_exec.3 \ - libssh2_channel_flush.3 \ - libssh2_channel_flush_ex.3 \ - libssh2_channel_flush_stderr.3 \ - libssh2_channel_forward_accept.3 \ - libssh2_channel_forward_cancel.3 \ - libssh2_channel_forward_listen.3 \ - libssh2_channel_forward_listen_ex.3 \ - libssh2_channel_free.3 \ - libssh2_channel_get_exit_signal.3 \ - libssh2_channel_get_exit_status.3 \ - libssh2_channel_handle_extended_data.3 \ - libssh2_channel_handle_extended_data2.3 \ - libssh2_channel_ignore_extended_data.3 \ - libssh2_channel_open_ex.3 \ - libssh2_channel_open_session.3 \ - libssh2_channel_process_startup.3 \ - libssh2_channel_read.3 \ - libssh2_channel_read_ex.3 \ - libssh2_channel_read_stderr.3 \ - libssh2_channel_receive_window_adjust.3 \ - libssh2_channel_receive_window_adjust2.3 \ - libssh2_channel_request_auth_agent.3 \ - libssh2_channel_request_pty.3 \ - libssh2_channel_request_pty_ex.3 \ - libssh2_channel_request_pty_size.3 \ - libssh2_channel_request_pty_size_ex.3 \ - libssh2_channel_send_eof.3 \ - libssh2_channel_set_blocking.3 \ - libssh2_channel_setenv.3 \ - libssh2_channel_setenv_ex.3 \ - libssh2_channel_shell.3 \ - libssh2_channel_subsystem.3 \ - libssh2_channel_wait_closed.3 \ - libssh2_channel_wait_eof.3 \ - libssh2_channel_window_read.3 \ - libssh2_channel_window_read_ex.3 \ - libssh2_channel_window_write.3 \ - libssh2_channel_window_write_ex.3 \ - libssh2_channel_write.3 \ - libssh2_channel_write_ex.3 \ - libssh2_channel_write_stderr.3 \ - libssh2_channel_x11_req.3 \ - libssh2_channel_x11_req_ex.3 \ - libssh2_crypto_engine.3 \ - libssh2_exit.3 \ - libssh2_free.3 \ - libssh2_hostkey_hash.3 \ - libssh2_init.3 \ - libssh2_keepalive_config.3 \ - libssh2_keepalive_send.3 \ - libssh2_knownhost_add.3 \ - libssh2_knownhost_addc.3 \ - libssh2_knownhost_check.3 \ - libssh2_knownhost_checkp.3 \ - libssh2_knownhost_del.3 \ - libssh2_knownhost_free.3 \ - libssh2_knownhost_get.3 \ - libssh2_knownhost_init.3 \ - libssh2_knownhost_readfile.3 \ - libssh2_knownhost_readline.3 \ - libssh2_knownhost_writefile.3 \ - libssh2_knownhost_writeline.3 \ - libssh2_poll.3 \ - libssh2_poll_channel_read.3 \ - libssh2_publickey_add.3 \ - libssh2_publickey_add_ex.3 \ - libssh2_publickey_init.3 \ - libssh2_publickey_list_fetch.3 \ - libssh2_publickey_list_free.3 \ - libssh2_publickey_remove.3 \ - libssh2_publickey_remove_ex.3 \ - libssh2_publickey_shutdown.3 \ - libssh2_scp_recv.3 \ - libssh2_scp_recv2.3 \ - libssh2_scp_send.3 \ - libssh2_scp_send64.3 \ - libssh2_scp_send_ex.3 \ - libssh2_session_abstract.3 \ - libssh2_session_banner_get.3 \ - libssh2_session_banner_set.3 \ - libssh2_session_block_directions.3 \ - libssh2_session_callback_set.3 \ - libssh2_session_disconnect.3 \ - libssh2_session_disconnect_ex.3 \ - libssh2_session_flag.3 \ - libssh2_session_free.3 \ - libssh2_session_get_blocking.3 \ - libssh2_session_get_timeout.3 \ - libssh2_session_handshake.3 \ - libssh2_session_hostkey.3 \ - libssh2_session_init.3 \ - libssh2_session_init_ex.3 \ - libssh2_session_last_errno.3 \ - libssh2_session_last_error.3 \ - libssh2_session_set_last_error.3 \ - libssh2_session_method_pref.3 \ - libssh2_session_methods.3 \ - libssh2_session_set_blocking.3 \ - libssh2_session_set_timeout.3 \ - libssh2_session_startup.3 \ - libssh2_session_supported_algs.3 \ - libssh2_sftp_close.3 \ - libssh2_sftp_close_handle.3 \ - libssh2_sftp_closedir.3 \ - libssh2_sftp_fsetstat.3 \ - libssh2_sftp_fstat.3 \ - libssh2_sftp_fstat_ex.3 \ - libssh2_sftp_fstatvfs.3 \ - libssh2_sftp_fsync.3 \ - libssh2_sftp_get_channel.3 \ - libssh2_sftp_init.3 \ - libssh2_sftp_last_error.3 \ - libssh2_sftp_lstat.3 \ - libssh2_sftp_mkdir.3 \ - libssh2_sftp_mkdir_ex.3 \ - libssh2_sftp_open.3 \ - libssh2_sftp_open_ex.3 \ - libssh2_sftp_opendir.3 \ - libssh2_sftp_read.3 \ - libssh2_sftp_readdir.3 \ - libssh2_sftp_readdir_ex.3 \ - libssh2_sftp_readlink.3 \ - libssh2_sftp_realpath.3 \ - libssh2_sftp_rename.3 \ - libssh2_sftp_rename_ex.3 \ - libssh2_sftp_rewind.3 \ - libssh2_sftp_rmdir.3 \ - libssh2_sftp_rmdir_ex.3 \ - libssh2_sftp_seek.3 \ - libssh2_sftp_seek64.3 \ - libssh2_sftp_setstat.3 \ - libssh2_sftp_shutdown.3 \ - libssh2_sftp_stat.3 \ - libssh2_sftp_stat_ex.3 \ - libssh2_sftp_statvfs.3 \ - libssh2_sftp_symlink.3 \ - libssh2_sftp_symlink_ex.3 \ - libssh2_sftp_tell.3 \ - libssh2_sftp_tell64.3 \ - libssh2_sftp_unlink.3 \ - libssh2_sftp_unlink_ex.3 \ - libssh2_sftp_write.3 \ - libssh2_sign_sk.3 \ - libssh2_trace.3 \ - libssh2_trace_sethandler.3 \ - libssh2_userauth_authenticated.3 \ - libssh2_userauth_banner.3 \ - libssh2_userauth_hostbased_fromfile.3 \ - libssh2_userauth_hostbased_fromfile_ex.3 \ - libssh2_userauth_keyboard_interactive.3 \ - libssh2_userauth_keyboard_interactive_ex.3 \ - libssh2_userauth_list.3 \ - libssh2_userauth_password.3 \ - libssh2_userauth_password_ex.3 \ - libssh2_userauth_publickey.3 \ - libssh2_userauth_publickey_fromfile.3 \ - libssh2_userauth_publickey_fromfile_ex.3 \ - libssh2_userauth_publickey_frommemory.3 \ - libssh2_userauth_publickey_sk.3 \ - libssh2_version.3 + libssh2_agent_connect.3 \ + libssh2_agent_disconnect.3 \ + libssh2_agent_free.3 \ + libssh2_agent_get_identity.3 \ + libssh2_agent_get_identity_path.3 \ + libssh2_agent_init.3 \ + libssh2_agent_list_identities.3 \ + libssh2_agent_set_identity_path.3 \ + libssh2_agent_userauth.3 \ + libssh2_banner_set.3 \ + libssh2_base64_decode.3 \ + libssh2_channel_close.3 \ + libssh2_channel_direct_tcpip.3 \ + libssh2_channel_direct_tcpip_ex.3 \ + libssh2_channel_eof.3 \ + libssh2_channel_exec.3 \ + libssh2_channel_flush.3 \ + libssh2_channel_flush_ex.3 \ + libssh2_channel_flush_stderr.3 \ + libssh2_channel_forward_accept.3 \ + libssh2_channel_forward_cancel.3 \ + libssh2_channel_forward_listen.3 \ + libssh2_channel_forward_listen_ex.3 \ + libssh2_channel_free.3 \ + libssh2_channel_get_exit_signal.3 \ + libssh2_channel_get_exit_status.3 \ + libssh2_channel_handle_extended_data.3 \ + libssh2_channel_handle_extended_data2.3 \ + libssh2_channel_ignore_extended_data.3 \ + libssh2_channel_open_ex.3 \ + libssh2_channel_open_session.3 \ + libssh2_channel_process_startup.3 \ + libssh2_channel_read.3 \ + libssh2_channel_read_ex.3 \ + libssh2_channel_read_stderr.3 \ + libssh2_channel_receive_window_adjust.3 \ + libssh2_channel_receive_window_adjust2.3 \ + libssh2_channel_request_auth_agent.3 \ + libssh2_channel_request_pty.3 \ + libssh2_channel_request_pty_ex.3 \ + libssh2_channel_request_pty_size.3 \ + libssh2_channel_request_pty_size_ex.3 \ + libssh2_channel_send_eof.3 \ + libssh2_channel_set_blocking.3 \ + libssh2_channel_setenv.3 \ + libssh2_channel_setenv_ex.3 \ + libssh2_channel_shell.3 \ + libssh2_channel_subsystem.3 \ + libssh2_channel_wait_closed.3 \ + libssh2_channel_wait_eof.3 \ + libssh2_channel_window_read.3 \ + libssh2_channel_window_read_ex.3 \ + libssh2_channel_window_write.3 \ + libssh2_channel_window_write_ex.3 \ + libssh2_channel_write.3 \ + libssh2_channel_write_ex.3 \ + libssh2_channel_write_stderr.3 \ + libssh2_channel_x11_req.3 \ + libssh2_channel_x11_req_ex.3 \ + libssh2_crypto_engine.3 \ + libssh2_exit.3 \ + libssh2_free.3 \ + libssh2_hostkey_hash.3 \ + libssh2_init.3 \ + libssh2_keepalive_config.3 \ + libssh2_keepalive_send.3 \ + libssh2_knownhost_add.3 \ + libssh2_knownhost_addc.3 \ + libssh2_knownhost_check.3 \ + libssh2_knownhost_checkp.3 \ + libssh2_knownhost_del.3 \ + libssh2_knownhost_free.3 \ + libssh2_knownhost_get.3 \ + libssh2_knownhost_init.3 \ + libssh2_knownhost_readfile.3 \ + libssh2_knownhost_readline.3 \ + libssh2_knownhost_writefile.3 \ + libssh2_knownhost_writeline.3 \ + libssh2_poll.3 \ + libssh2_poll_channel_read.3 \ + libssh2_publickey_add.3 \ + libssh2_publickey_add_ex.3 \ + libssh2_publickey_init.3 \ + libssh2_publickey_list_fetch.3 \ + libssh2_publickey_list_free.3 \ + libssh2_publickey_remove.3 \ + libssh2_publickey_remove_ex.3 \ + libssh2_publickey_shutdown.3 \ + libssh2_scp_recv.3 \ + libssh2_scp_recv2.3 \ + libssh2_scp_send.3 \ + libssh2_scp_send64.3 \ + libssh2_scp_send_ex.3 \ + libssh2_session_abstract.3 \ + libssh2_session_banner_get.3 \ + libssh2_session_banner_set.3 \ + libssh2_session_block_directions.3 \ + libssh2_session_callback_set.3 \ + libssh2_session_disconnect.3 \ + libssh2_session_disconnect_ex.3 \ + libssh2_session_flag.3 \ + libssh2_session_free.3 \ + libssh2_session_get_blocking.3 \ + libssh2_session_get_timeout.3 \ + libssh2_session_handshake.3 \ + libssh2_session_hostkey.3 \ + libssh2_session_init.3 \ + libssh2_session_init_ex.3 \ + libssh2_session_last_errno.3 \ + libssh2_session_last_error.3 \ + libssh2_session_set_last_error.3 \ + libssh2_session_method_pref.3 \ + libssh2_session_methods.3 \ + libssh2_session_set_blocking.3 \ + libssh2_session_set_timeout.3 \ + libssh2_session_startup.3 \ + libssh2_session_supported_algs.3 \ + libssh2_sftp_close.3 \ + libssh2_sftp_close_handle.3 \ + libssh2_sftp_closedir.3 \ + libssh2_sftp_fsetstat.3 \ + libssh2_sftp_fstat.3 \ + libssh2_sftp_fstat_ex.3 \ + libssh2_sftp_fstatvfs.3 \ + libssh2_sftp_fsync.3 \ + libssh2_sftp_get_channel.3 \ + libssh2_sftp_init.3 \ + libssh2_sftp_last_error.3 \ + libssh2_sftp_lstat.3 \ + libssh2_sftp_mkdir.3 \ + libssh2_sftp_mkdir_ex.3 \ + libssh2_sftp_open.3 \ + libssh2_sftp_open_ex.3 \ + libssh2_sftp_opendir.3 \ + libssh2_sftp_read.3 \ + libssh2_sftp_readdir.3 \ + libssh2_sftp_readdir_ex.3 \ + libssh2_sftp_readlink.3 \ + libssh2_sftp_realpath.3 \ + libssh2_sftp_rename.3 \ + libssh2_sftp_rename_ex.3 \ + libssh2_sftp_rewind.3 \ + libssh2_sftp_rmdir.3 \ + libssh2_sftp_rmdir_ex.3 \ + libssh2_sftp_seek.3 \ + libssh2_sftp_seek64.3 \ + libssh2_sftp_setstat.3 \ + libssh2_sftp_shutdown.3 \ + libssh2_sftp_stat.3 \ + libssh2_sftp_stat_ex.3 \ + libssh2_sftp_statvfs.3 \ + libssh2_sftp_symlink.3 \ + libssh2_sftp_symlink_ex.3 \ + libssh2_sftp_tell.3 \ + libssh2_sftp_tell64.3 \ + libssh2_sftp_unlink.3 \ + libssh2_sftp_unlink_ex.3 \ + libssh2_sftp_write.3 \ + libssh2_sign_sk.3 \ + libssh2_trace.3 \ + libssh2_trace_sethandler.3 \ + libssh2_userauth_authenticated.3 \ + libssh2_userauth_banner.3 \ + libssh2_userauth_hostbased_fromfile.3 \ + libssh2_userauth_hostbased_fromfile_ex.3 \ + libssh2_userauth_keyboard_interactive.3 \ + libssh2_userauth_keyboard_interactive_ex.3 \ + libssh2_userauth_list.3 \ + libssh2_userauth_password.3 \ + libssh2_userauth_password_ex.3 \ + libssh2_userauth_publickey.3 \ + libssh2_userauth_publickey_fromfile.3 \ + libssh2_userauth_publickey_fromfile_ex.3 \ + libssh2_userauth_publickey_frommemory.3 \ + libssh2_userauth_publickey_sk.3 \ + libssh2_version.3 diff --git a/docs/libssh2_agent_connect.3 b/docs/libssh2_agent_connect.3 index 1c6ff6d960..6482c66fde 100644 --- a/docs/libssh2_agent_connect.3 +++ b/docs/libssh2_agent_connect.3 @@ -20,4 +20,3 @@ Added in libssh2 1.2 .SH SEE ALSO .BR libssh2_agent_init(3) .BR libssh2_agent_disconnect(3) - diff --git a/docs/libssh2_agent_get_identity_path.3 b/docs/libssh2_agent_get_identity_path.3 index 58d6dd569a..1cbdf7aed4 100644 --- a/docs/libssh2_agent_get_identity_path.3 +++ b/docs/libssh2_agent_get_identity_path.3 @@ -19,4 +19,3 @@ Added in libssh2 1.9 .SH SEE ALSO .BR libssh2_agent_init(3) .BR libssh2_agent_set_identity_path(3) - diff --git a/docs/libssh2_agent_list_identities.3 b/docs/libssh2_agent_list_identities.3 index e1e4b545f4..48a1d6c1fe 100644 --- a/docs/libssh2_agent_list_identities.3 +++ b/docs/libssh2_agent_list_identities.3 @@ -21,4 +21,3 @@ Added in libssh2 1.2 .SH SEE ALSO .BR libssh2_agent_connect(3) .BR libssh2_agent_get_identity(3) - diff --git a/docs/libssh2_agent_set_identity_path.3 b/docs/libssh2_agent_set_identity_path.3 index 73e1266d1e..2d75b7916c 100644 --- a/docs/libssh2_agent_set_identity_path.3 +++ b/docs/libssh2_agent_set_identity_path.3 @@ -19,4 +19,3 @@ Added in libssh2 1.9 .SH SEE ALSO .BR libssh2_agent_init(3) .BR libssh2_agent_get_identity_path(3) - diff --git a/docs/libssh2_agent_userauth.3 b/docs/libssh2_agent_userauth.3 index 3c956fec01..8524884a2c 100644 --- a/docs/libssh2_agent_userauth.3 +++ b/docs/libssh2_agent_userauth.3 @@ -11,12 +11,12 @@ int libssh2_agent_userauth(LIBSSH2_AGENT *agent, const char *username, struct libssh2_agent_publickey *identity); .SH DESCRIPTION -\fIagent\fP - ssh-agent handle as returned by +\fIagent\fP - ssh-agent handle as returned by .BR libssh2_agent_init(3) \fIusername\fP - Remote user name to authenticate as. -\fIidentity\fP - Public key to authenticate with, as returned by +\fIidentity\fP - Public key to authenticate with, as returned by .BR libssh2_agent_get_identity(3) Attempt public key authentication with the help of ssh-agent. diff --git a/docs/libssh2_banner_set.3 b/docs/libssh2_banner_set.3 index 2baa121e30..04f6ef58c4 100644 --- a/docs/libssh2_banner_set.3 +++ b/docs/libssh2_banner_set.3 @@ -4,20 +4,20 @@ libssh2_banner_set - set the SSH protocol banner for the local client .SH SYNOPSIS #include -int +int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner); .SH DESCRIPTION This function is \fBDEPRECATED\fP. Use \fIlibssh2_session_banner_set(3)\fP instead! -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIbanner\fP - A pointer to a user defined banner -Set the banner that will be sent to the remote host when the SSH session is -started with +Set the banner that will be sent to the remote host when the SSH session is +started with .BR libssh2_session_handshake(3) This is optional; a banner corresponding to the protocol and libssh2 version will be sent by default. .SH RETURN VALUE diff --git a/docs/libssh2_channel_close.3 b/docs/libssh2_channel_close.3 index 2fe0a0d4bd..b493395a2f 100644 --- a/docs/libssh2_channel_close.3 +++ b/docs/libssh2_channel_close.3 @@ -4,17 +4,17 @@ libssh2_channel_close - close a channel .SH SYNOPSIS #include -int +int libssh2_channel_close(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION \fIchannel\fP - active channel stream to set closed status on. -Close an active data channel. In practice this means sending an SSH_MSG_CLOSE -packet to the remote host which serves as instruction that no further data -will be sent to it. The remote host may still send data back until it sends -its own close message in response. To wait for the remote end to close its -connection as well, follow this command with +Close an active data channel. In practice this means sending an SSH_MSG_CLOSE +packet to the remote host which serves as instruction that no further data +will be sent to it. The remote host may still send data back until it sends +its own close message in response. To wait for the remote end to close its +connection as well, follow this command with .BR libssh2_channel_wait_closed(3) .SH RETURN VALUE diff --git a/docs/libssh2_channel_direct_tcpip_ex.3 b/docs/libssh2_channel_direct_tcpip_ex.3 index 481c55cece..5959bc9398 100644 --- a/docs/libssh2_channel_direct_tcpip_ex.3 +++ b/docs/libssh2_channel_direct_tcpip_ex.3 @@ -4,14 +4,14 @@ libssh2_channel_direct_tcpip_ex - Tunnel a TCP connection through an SSH session .SH SYNOPSIS #include -LIBSSH2_CHANNEL * +LIBSSH2_CHANNEL * libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, int port, const char *shost, int sport); -LIBSSH2_CHANNEL * +LIBSSH2_CHANNEL * libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session, const char *host, int port); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIhost\fP - Third party host to connect to using the SSH host as a proxy. @@ -22,9 +22,9 @@ libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session, const char *host, int por \fIsport\fP - Port to tell the SSH server the connection originated from. -Tunnel a TCP/IP connection through the SSH transport via the remote host to -a third party. Communication from the client to the SSH server remains -encrypted, communication from the server to the 3rd party host travels +Tunnel a TCP/IP connection through the SSH transport via the remote host to +a third party. Communication from the client to the SSH server remains +encrypted, communication from the server to the 3rd party host travels in cleartext. .SH RETURN VALUE diff --git a/docs/libssh2_channel_eof.3 b/docs/libssh2_channel_eof.3 index ed4a074b74..9ddc108117 100644 --- a/docs/libssh2_channel_eof.3 +++ b/docs/libssh2_channel_eof.3 @@ -4,7 +4,7 @@ libssh2_channel_eof - check a channel's EOF status .SH SYNOPSIS #include -int +int libssh2_channel_eof(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION \fIchannel\fP - active channel stream to set closed status on. diff --git a/docs/libssh2_channel_flush_ex.3 b/docs/libssh2_channel_flush_ex.3 index 6cd39b2c6c..61b351ab40 100644 --- a/docs/libssh2_channel_flush_ex.3 +++ b/docs/libssh2_channel_flush_ex.3 @@ -4,26 +4,26 @@ libssh2_channel_flush_ex - flush a channel .SH SYNOPSIS #include -int +int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int streamid); -int +int libssh2_channel_flush(LIBSSH2_CHANNEL *channel); -int +int libssh2_channel_flush_stderr(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION \fIchannel\fP - Active channel stream to flush. -\fIstreamid\fP - Specific substream number to flush. Groups of substreams may +\fIstreamid\fP - Specific substream number to flush. Groups of substreams may be flushed by passing on of the following Constants. .br \fBLIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA\fP: Flush all extended data substreams .br \fBLIBSSH2_CHANNEL_FLUSH_ALL\fP: Flush all substreams -Flush the read buffer for a given channel instance. Individual substreams may +Flush the read buffer for a given channel instance. Individual substreams may be flushed by number or using one of the provided macros. .SH RETURN VALUE diff --git a/docs/libssh2_channel_forward_cancel.3 b/docs/libssh2_channel_forward_cancel.3 index 16f826fb61..1bb4c03741 100644 --- a/docs/libssh2_channel_forward_cancel.3 +++ b/docs/libssh2_channel_forward_cancel.3 @@ -4,11 +4,11 @@ libssh2_channel_forward_cancel - cancel a forwarded TCP port .SH SYNOPSIS #include -int +int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener); .SH DESCRIPTION -\fIlistener\fP - Forwarding listener instance as returned by +\fIlistener\fP - Forwarding listener instance as returned by .BR libssh2_channel_forward_listen_ex(3) Instruct the remote host to stop listening for new connections on a previously requested host/port. diff --git a/docs/libssh2_channel_forward_listen_ex.3 b/docs/libssh2_channel_forward_listen_ex.3 index a358f6cea8..22154996f8 100644 --- a/docs/libssh2_channel_forward_listen_ex.3 +++ b/docs/libssh2_channel_forward_listen_ex.3 @@ -4,10 +4,10 @@ libssh2_channel_forward_listen_ex - listen to inbound connections .SH SYNOPSIS #include -LIBSSH2_LISTENER * +LIBSSH2_LISTENER * libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, char *host, int port, int *bound_port, int queue_maxsize); -LIBSSH2_LISTENER * +LIBSSH2_LISTENER * libssh2_channel_forward_listen(LIBSSH2_SESSION *session, int port); .SH DESCRIPTION @@ -15,7 +15,7 @@ Instruct the remote SSH server to begin listening for inbound TCP/IP connections. New connections will be queued by the library until accepted by \fIlibssh2_channel_forward_accept(3)\fP. -\fIsession\fP - instance as returned by libssh2_session_init(). +\fIsession\fP - instance as returned by libssh2_session_init(). \fIhost\fP - specific address to bind to on the remote host. Binding to 0.0.0.0 (default when NULL is passed) will bind to all available addresses. diff --git a/docs/libssh2_channel_free.3 b/docs/libssh2_channel_free.3 index fc76f5a852..9013a4a2f9 100644 --- a/docs/libssh2_channel_free.3 +++ b/docs/libssh2_channel_free.3 @@ -4,16 +4,16 @@ libssh2_channel_free - free all resources associated with a channel .SH SYNOPSIS #include -int +int libssh2_channel_free(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION \fIchannel\fP - Channel stream to free. -Release all resources associated with a channel stream. If the channel has -not yet been closed with +Release all resources associated with a channel stream. If the channel has +not yet been closed with .BR libssh2_channel_close(3) -, it will be called automatically so that the remote end may know that it +, it will be called automatically so that the remote end may know that it can safely free its own resources. .SH RETURN VALUE diff --git a/docs/libssh2_channel_get_exit_signal.3 b/docs/libssh2_channel_get_exit_signal.3 index 138e7c7201..1dc83f8e37 100644 --- a/docs/libssh2_channel_get_exit_signal.3 +++ b/docs/libssh2_channel_get_exit_signal.3 @@ -4,7 +4,7 @@ libssh2_channel_get_exit_signal - get the remote exit signal .SH SYNOPSIS #include -int +int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel, char **exitsignal, size_t *exitsignal_len, char **errmsg, size_t *errmsg_len, char **langtag, size_t *langtag_len); .SH DESCRIPTION @@ -13,10 +13,10 @@ libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel, char **exitsignal, siz \fIexitsignal\fP - If not NULL, is populated by reference with the exit signal (without leading "SIG"). Note that the string is stored in a newly allocated buffer. If the remote program exited cleanly, the referenced string pointer -will be set to NULL. +will be set to NULL. \fIexitsignal_len\fP - If not NULL, is populated by reference with the length -of exitsignal. +of exitsignal. \fIerrmsg\fP - If not NULL, is populated by reference with the error message (if provided by remote server, if not it will be set to NULL). Note that the @@ -24,7 +24,7 @@ string is stored in a newly allocated buffer. \fIerrmsg_len\fP - If not NULL, is populated by reference with the length of errmsg. -\fIlangtag\fP - If not NULL, is populated by reference with the language tag +\fIlangtag\fP - If not NULL, is populated by reference with the language tag (if provided by remote server, if not it will be set to NULL). Note that the string is stored in a newly allocated buffer. diff --git a/docs/libssh2_channel_get_exit_status.3 b/docs/libssh2_channel_get_exit_status.3 index 4a8c9e2fcd..24ceb3bd71 100644 --- a/docs/libssh2_channel_get_exit_status.3 +++ b/docs/libssh2_channel_get_exit_status.3 @@ -4,14 +4,14 @@ libssh2_channel_get_exit_status - get the remote exit code .SH SYNOPSIS #include -int +int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel) .SH DESCRIPTION \fIchannel\fP - Closed channel stream to retrieve exit status from. -Returns the exit code raised by the process running on the remote host at -the other end of the named channel. Note that the exit status may not be +Returns the exit code raised by the process running on the remote host at +the other end of the named channel. Note that the exit status may not be available if the remote end has not yet set its status to closed. .SH RETURN VALUE diff --git a/docs/libssh2_channel_handle_extended_data.3 b/docs/libssh2_channel_handle_extended_data.3 index 8ab248835b..d996477651 100644 --- a/docs/libssh2_channel_handle_extended_data.3 +++ b/docs/libssh2_channel_handle_extended_data.3 @@ -4,7 +4,7 @@ libssh2_channel_handle_extended_data - set extended data handling mode .SH SYNOPSIS #include -void +void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode); .SH DESCRIPTION @@ -15,7 +15,7 @@ This function is deprecated. Use the \fIignore_mode\fP - One of the three LIBSSH2_CHANNEL_EXTENDED_DATA_* Constants. .br -\fBLIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL\fP: Queue extended data for eventual +\fBLIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL\fP: Queue extended data for eventual reading .br \fBLIBSSH2_CHANNEL_EXTENDED_DATA_MERGE\fP: Treat extended data and ordinary @@ -23,7 +23,7 @@ data the same. Merge all substreams such that calls to \fIlibssh2_channel_read(3)\fP will pull from all substreams on a first-in/first-out basis. .br -\fBLIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE\fP: Discard all extended data as it +\fBLIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE\fP: Discard all extended data as it arrives. Change how a channel deals with extended data packets. By default all extended diff --git a/docs/libssh2_channel_handle_extended_data2.3 b/docs/libssh2_channel_handle_extended_data2.3 index 8910d8ce65..a090e435b6 100644 --- a/docs/libssh2_channel_handle_extended_data2.3 +++ b/docs/libssh2_channel_handle_extended_data2.3 @@ -4,7 +4,7 @@ libssh2_channel_handle_extended_data2 - set extended data handling mode .SH SYNOPSIS #include -int +int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, int ignore_mode); .SH DESCRIPTION @@ -12,19 +12,19 @@ libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, int ignore_mode) \fIignore_mode\fP - One of the three LIBSSH2_CHANNEL_EXTENDED_DATA_* Constants. .br -\fBLIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL\fP: Queue extended data for eventual +\fBLIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL\fP: Queue extended data for eventual reading .br -\fBLIBSSH2_CHANNEL_EXTENDED_DATA_MERGE\fP: Treat extended data and ordinary -data the same. Merge all substreams such that calls to +\fBLIBSSH2_CHANNEL_EXTENDED_DATA_MERGE\fP: Treat extended data and ordinary +data the same. Merge all substreams such that calls to .BR libssh2_channel_read(3) will pull from all substreams on a first-in/first-out basis. .br -\fBLIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE\fP: Discard all extended data as it +\fBLIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE\fP: Discard all extended data as it arrives. -Change how a channel deals with extended data packets. By default all -extended data is queued until read by +Change how a channel deals with extended data packets. By default all +extended data is queued until read by .BR libssh2_channel_read_ex(3) .SH RETURN VALUE diff --git a/docs/libssh2_channel_open_ex.3 b/docs/libssh2_channel_open_ex.3 index 7dec29455a..aeacb1afde 100644 --- a/docs/libssh2_channel_open_ex.3 +++ b/docs/libssh2_channel_open_ex.3 @@ -11,29 +11,29 @@ LIBSSH2_CHANNEL * libssh2_channel_open_session(session); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) -\fIchannel_type\fP - Channel type to open. Typically one of session, -direct-tcpip, or tcpip-forward. The SSH2 protocol allowed for additional +\fIchannel_type\fP - Channel type to open. Typically one of session, +direct-tcpip, or tcpip-forward. The SSH2 protocol allowed for additional types including local, custom channel types. \fIchannel_type_len\fP - Length of channel_type -\fIwindow_size\fP - Maximum amount of unacknowledged data remote host is +\fIwindow_size\fP - Maximum amount of unacknowledged data remote host is allowed to send before receiving an SSH_MSG_CHANNEL_WINDOW_ADJUST packet. -\fIpacket_size\fP - Maximum number of bytes remote host is allowed to send +\fIpacket_size\fP - Maximum number of bytes remote host is allowed to send in a single SSH_MSG_CHANNEL_DATA or SSG_MSG_CHANNEL_EXTENDED_DATA packet. \fImessage\fP - Additional data as required by the selected channel_type. \fImessage_len\fP - Length of message parameter. -Allocate a new channel for exchanging data with the server. This method is -typically called through its macroized form: +Allocate a new channel for exchanging data with the server. This method is +typically called through its macroized form: .BR libssh2_channel_open_session(3) -or via +or via .BR libssh2_channel_direct_tcpip(3) or .BR libssh2_channel_forward_listen(3) @@ -46,7 +46,7 @@ Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_CHANNEL_FAILURE\fP - +\fILIBSSH2_ERROR_CHANNEL_FAILURE\fP - \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. diff --git a/docs/libssh2_channel_process_startup.3 b/docs/libssh2_channel_process_startup.3 index 7c2798204b..b215e2fa56 100644 --- a/docs/libssh2_channel_process_startup.3 +++ b/docs/libssh2_channel_process_startup.3 @@ -13,7 +13,7 @@ int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, .SH DESCRIPTION \fIchannel\fP - Active session channel instance. -\fIrequest\fP - Type of process to startup. The SSH2 protocol currently +\fIrequest\fP - Type of process to startup. The SSH2 protocol currently defines shell, exec, and subsystem as standard process services. \fIrequest_len\fP - Length of request parameter. @@ -22,7 +22,7 @@ defines shell, exec, and subsystem as standard process services. \fImessage_len\fP - Length of message parameter. -Initiate a request on a session type channel such as returned by +Initiate a request on a session type channel such as returned by .BR libssh2_channel_open_ex(3) .SH RETURN VALUE Return 0 on success or negative on failure. It returns @@ -33,6 +33,6 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - +\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - .SH SEE ALSO .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_channel_read_ex.3 b/docs/libssh2_channel_read_ex.3 index 83d7c3e054..bc021a45ad 100644 --- a/docs/libssh2_channel_read_ex.3 +++ b/docs/libssh2_channel_read_ex.3 @@ -19,9 +19,9 @@ one standard I/O substream (stream_id == 0), and may have up to 2^32 extended data streams as identified by the selected \fIstream_id\fP. The SSH2 protocol currently defines a stream ID of 1 to be the stderr substream. -\fIchannel\fP - active channel stream to read from. +\fIchannel\fP - active channel stream to read from. -\fIstream_id\fP - substream ID number (e.g. 0 or SSH_EXTENDED_DATA_STDERR) +\fIstream_id\fP - substream ID number (e.g. 0 or SSH_EXTENDED_DATA_STDERR) \fIbuf\fP - pointer to storage buffer to read data into diff --git a/docs/libssh2_channel_request_pty_ex.3 b/docs/libssh2_channel_request_pty_ex.3 index 35b5840a74..11dda5bb5e 100644 --- a/docs/libssh2_channel_request_pty_ex.3 +++ b/docs/libssh2_channel_request_pty_ex.3 @@ -4,14 +4,14 @@ libssh2_channel_request_pty_ex - short function description .SH SYNOPSIS #include -int +int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel, const char *term, unsigned int term_len, const char *modes, unsigned int modes_len, int width, int height, int width_px, int height_px); -int +int libssh2_channel_request_pty(LIBSSH2_CHANNEL *channel, char *term); .SH DESCRIPTION -\fIchannel\fP - Previously opened channel instance such as returned by +\fIchannel\fP - Previously opened channel instance such as returned by .BR libssh2_channel_open_ex(3) \fIterm\fP - Terminal emulation (e.g. vt102, ansi, etc...) @@ -30,8 +30,8 @@ libssh2_channel_request_pty(LIBSSH2_CHANNEL *channel, char *term); \fIheight_px\fP - Height of pty in pixels -Request a PTY on an established channel. Note that this does not make sense -for all channel types and may be ignored by the server despite returning +Request a PTY on an established channel. Note that this does not make sense +for all channel types and may be ignored by the server despite returning success. .SH RETURN VALUE Return 0 on success or negative on failure. It returns @@ -42,6 +42,6 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - +\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - .SH SEE ALSO .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_channel_send_eof.3 b/docs/libssh2_channel_send_eof.3 index 0e5975acbd..025ef73261 100644 --- a/docs/libssh2_channel_send_eof.3 +++ b/docs/libssh2_channel_send_eof.3 @@ -4,11 +4,11 @@ libssh2_channel_send_eof - send EOF to remote server .SH SYNOPSIS #include -int +int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION -Tell the remote host that no further data will be sent on the specified +Tell the remote host that no further data will be sent on the specified channel. Processes typically interpret this as a closed stdin descriptor. .SH RETURN VALUE diff --git a/docs/libssh2_channel_set_blocking.3 b/docs/libssh2_channel_set_blocking.3 index 55ee4ff04a..9ebb7a6ba3 100644 --- a/docs/libssh2_channel_set_blocking.3 +++ b/docs/libssh2_channel_set_blocking.3 @@ -4,7 +4,7 @@ libssh2_channel_set_blocking - set or clear blocking mode on channel .SH SYNOPSIS #include -void +void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking); .SH DESCRIPTION \fIchannel\fP - channel stream to set or clean blocking status on. @@ -12,7 +12,7 @@ libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking); \fIblocking\fP - Set to a non-zero value to make the channel block, or zero to make it non-blocking. -Currently this is just a short cut call to +Currently this is just a short cut call to .BR libssh2_session_set_blocking(3) and therefore will affect the session and all channels. .SH RETURN VALUE diff --git a/docs/libssh2_channel_setenv_ex.3 b/docs/libssh2_channel_setenv_ex.3 index 4a5fd3e995..b16dd01fb0 100644 --- a/docs/libssh2_channel_setenv_ex.3 +++ b/docs/libssh2_channel_setenv_ex.3 @@ -11,10 +11,10 @@ int libssh2_channel_setenv(LIBSSH2_CHANNEL *channel, char *varname, const char *value); .SH DESCRIPTION -\fIchannel\fP - Previously opened channel instance such as returned by +\fIchannel\fP - Previously opened channel instance such as returned by .BR libssh2_channel_open_ex(3) -\fIvarname\fP - Name of environment variable to set on the remote +\fIvarname\fP - Name of environment variable to set on the remote channel instance. \fIvarname_len\fP - Length of passed varname parameter. @@ -36,6 +36,6 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - +\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - .SH SEE ALSO .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_channel_wait_closed.3 b/docs/libssh2_channel_wait_closed.3 index 44717368ca..8cf0911a28 100644 --- a/docs/libssh2_channel_wait_closed.3 +++ b/docs/libssh2_channel_wait_closed.3 @@ -4,7 +4,7 @@ libssh2_channel_wait_closed - wait for the remote to close the channel .SH SYNOPSIS #include -int +int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION diff --git a/docs/libssh2_channel_wait_eof.3 b/docs/libssh2_channel_wait_eof.3 index 8a3dc47570..ef4d8b70f7 100644 --- a/docs/libssh2_channel_wait_eof.3 +++ b/docs/libssh2_channel_wait_eof.3 @@ -4,7 +4,7 @@ libssh2_channel_wait_eof - wait for the remote to reply to an EOF request .SH SYNOPSIS #include -int +int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION diff --git a/docs/libssh2_channel_write_ex.3 b/docs/libssh2_channel_write_ex.3 index cb73648d83..1ede81e6e2 100644 --- a/docs/libssh2_channel_write_ex.3 +++ b/docs/libssh2_channel_write_ex.3 @@ -14,9 +14,9 @@ substream (stream_id == 0), and may have up to 2^32 extended data streams as identified by the selected \fIstream_id\fP. The SSH2 protocol currently defines a stream ID of 1 to be the stderr substream. -\fIchannel\fP - active channel stream to write to. +\fIchannel\fP - active channel stream to write to. -\fIstream_id\fP - substream ID number (e.g. 0 or SSH_EXTENDED_DATA_STDERR) +\fIstream_id\fP - substream ID number (e.g. 0 or SSH_EXTENDED_DATA_STDERR) \fIbuf\fP - pointer to buffer to write @@ -43,8 +43,8 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_CHANNEL_EOF_SENT\fP - The channel has been requested to be \fILIBSSH2_ERROR_BAD_USE\fP - This can be returned if you ignored a previous -return for LIBSSH2_ERROR_EAGAIN and rather than sending the original buffer with -the original size, you sent a new buffer with a different size. +return for LIBSSH2_ERROR_EAGAIN and rather than sending the original buffer with +the original size, you sent a new buffer with a different size. closed. .SH SEE ALSO diff --git a/docs/libssh2_channel_x11_req_ex.3 b/docs/libssh2_channel_x11_req_ex.3 index e0121bd169..33c3c76c47 100644 --- a/docs/libssh2_channel_x11_req_ex.3 +++ b/docs/libssh2_channel_x11_req_ex.3 @@ -11,7 +11,7 @@ int libssh2_channel_x11_req(LIBSSH2_CHANNEL *channel, int screen_number); .SH DESCRIPTION -\fIchannel\fP - Previously opened channel instance such as returned by +\fIchannel\fP - Previously opened channel instance such as returned by .BR libssh2_channel_open_ex(3) \fIsingle_connection\fP - non-zero to only forward a single connection. @@ -22,7 +22,7 @@ libssh2_channel_x11_req(LIBSSH2_CHANNEL *channel, int screen_number); \fIscreen_number\fP - the XLL screen to forward -Request an X11 forwarding on \fIchannel\fP. To use X11 forwarding, +Request an X11 forwarding on \fIchannel\fP. To use X11 forwarding, .BR libssh2_session_callback_set(3) must first be called to set \fBLIBSSH2_CALLBACK_X11\fP. This callback will be invoked when the remote host accepts the X11 forwarding. @@ -37,7 +37,7 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - +\fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - .SH SEE ALSO .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_hostkey_hash.3 b/docs/libssh2_hostkey_hash.3 index d57fc0dd5f..12f3726105 100644 --- a/docs/libssh2_hostkey_hash.3 +++ b/docs/libssh2_hostkey_hash.3 @@ -8,14 +8,14 @@ const char * libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) -\fIhash_type\fP - One of: \fBLIBSSH2_HOSTKEY_HASH_MD5\fP, +\fIhash_type\fP - One of: \fBLIBSSH2_HOSTKEY_HASH_MD5\fP, \fBLIBSSH2_HOSTKEY_HASH_SHA1\fP or \fBLIBSSH2_HOSTKEY_HASH_SHA256\fP. -Returns the computed digest of the remote system's hostkey. The length of -the returned string is hash_type specific (e.g. 16 bytes for MD5, +Returns the computed digest of the remote system's hostkey. The length of +the returned string is hash_type specific (e.g. 16 bytes for MD5, 20 bytes for SHA1, 32 bytes for SHA256). .SH RETURN VALUE Computed hostkey hash value, or NULL if the information is not available diff --git a/docs/libssh2_keepalive_config.3 b/docs/libssh2_keepalive_config.3 index 15e3ab96f2..62867cf129 100644 --- a/docs/libssh2_keepalive_config.3 +++ b/docs/libssh2_keepalive_config.3 @@ -24,4 +24,3 @@ Nothing Added in libssh2 1.2.5 .SH SEE ALSO .BR libssh2_keepalive_send(3) - diff --git a/docs/libssh2_knownhost_writefile.3 b/docs/libssh2_knownhost_writefile.3 index 48335a01b6..9ecc4a8df8 100644 --- a/docs/libssh2_knownhost_writefile.3 +++ b/docs/libssh2_knownhost_writefile.3 @@ -26,4 +26,3 @@ Added in libssh2 1.2 .SH SEE ALSO .BR libssh2_knownhost_readfile(3) .BR libssh2_knownhost_add(3) - diff --git a/docs/libssh2_knownhost_writeline.3 b/docs/libssh2_knownhost_writeline.3 index c014a6a39d..e4c113ec27 100644 --- a/docs/libssh2_knownhost_writeline.3 +++ b/docs/libssh2_knownhost_writeline.3 @@ -43,4 +43,3 @@ Added in libssh2 1.2 .BR libssh2_knownhost_get(3) .BR libssh2_knownhost_readline(3) .BR libssh2_knownhost_writefile(3) - diff --git a/docs/libssh2_publickey_add.3 b/docs/libssh2_publickey_add.3 index 666cd942bc..7fc3eb107f 100644 --- a/docs/libssh2_publickey_add.3 +++ b/docs/libssh2_publickey_add.3 @@ -5,7 +5,7 @@ libssh2_publickey_add - convenience macro for \fIlibssh2_publickey_add_ex(3)\fP #include int libssh2_publickey_add(LIBSSH2_PUBLICKEY *pkey, - const unsigned char *name, + const unsigned char *name, const unsigned char *blob, unsigned long blob_len, char overwrite, unsigned long num_attrs, const libssh2_publickey_attribute attrs[]); diff --git a/docs/libssh2_publickey_remove.3 b/docs/libssh2_publickey_remove.3 index 874fdbed1a..1d4cdeb6c1 100644 --- a/docs/libssh2_publickey_remove.3 +++ b/docs/libssh2_publickey_remove.3 @@ -5,8 +5,8 @@ libssh2_publickey_remove - convenience macro for \fIlibssh2_publickey_remove_ex( #include int libssh2_publickey_remove(LIBSSH2_PUBLICKEY *pkey, - const unsigned char *name, unsigned long name_len, - const unsigned char *blob, unsigned long blob_len); + const unsigned char *name, unsigned long name_len, + const unsigned char *blob, unsigned long blob_len); .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the diff --git a/docs/libssh2_scp_recv.3 b/docs/libssh2_scp_recv.3 index 2edcdd4890..2da4fa2cc2 100644 --- a/docs/libssh2_scp_recv.3 +++ b/docs/libssh2_scp_recv.3 @@ -11,7 +11,7 @@ libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb); This function is \fBDEPRECATED\fP. Use \fIlibssh2_scp_recv2(3)\fP instead! -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIpath\fP - Full path and filename of file to transfer. That is the remote @@ -25,11 +25,10 @@ Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. -\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - +\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. .SH SEE ALSO .BR libssh2_session_init_ex(3) .BR libssh2_channel_open_ex(3) - diff --git a/docs/libssh2_scp_recv2.3 b/docs/libssh2_scp_recv2.3 index 6b48fd14f1..b7e2ebebef 100644 --- a/docs/libssh2_scp_recv2.3 +++ b/docs/libssh2_scp_recv2.3 @@ -8,7 +8,7 @@ LIBSSH2_CHANNEL * libssh2_scp_recv2(LIBSSH2_SESSION *session, const char *path, struct_stat *sb); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIpath\fP - Full path and filename of file to transfer. That is the remote @@ -22,11 +22,10 @@ Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. -\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - +\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. .SH SEE ALSO .BR libssh2_session_init_ex(3) .BR libssh2_channel_open_ex(3) - diff --git a/docs/libssh2_scp_send64.3 b/docs/libssh2_scp_send64.3 index 98d7e74fa1..42a90d9d3e 100644 --- a/docs/libssh2_scp_send64.3 +++ b/docs/libssh2_scp_send64.3 @@ -9,7 +9,7 @@ LIBSSH2_CHANNEL * libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode, libssh2_uint64_t size, time_t mtime, time_t atime); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIpath\fP - Full path and filename of file to transfer to. That is the remote @@ -24,7 +24,7 @@ compilers. \fImtime\fP - mtime to assign to file being created -\fIatime\fP - atime to assign to file being created (Set this and +\fIatime\fP - atime to assign to file being created (Set this and mtime to zero to instruct remote host to use current time). Send a file to the remote host via SCP. @@ -36,7 +36,7 @@ Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - +\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. diff --git a/docs/libssh2_scp_send_ex.3 b/docs/libssh2_scp_send_ex.3 index 8de7083d11..c271705732 100644 --- a/docs/libssh2_scp_send_ex.3 +++ b/docs/libssh2_scp_send_ex.3 @@ -12,7 +12,7 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, This function has been deemed deprecated since libssh2 1.2.6. See \fIlibssh2_scp_send64(3)\fP. -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIpath\fP - Full path and filename of file to transfer to. That is the remote @@ -20,12 +20,12 @@ file name. \fImode\fP - File access mode to create file with -\fIsize\fP - Size of file being transmitted (Must be known +\fIsize\fP - Size of file being transmitted (Must be known ahead of time precisely) \fImtime\fP - mtime to assign to file being created -\fIatime\fP - atime to assign to file being created (Set this and +\fIatime\fP - atime to assign to file being created (Set this and mtime to zero to instruct remote host to use current time). Send a file to the remote host via SCP. @@ -37,7 +37,7 @@ Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - +\fILIBSSH2_ERROR_SCP_PROTOCOL\fP - \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. diff --git a/docs/libssh2_session_abstract.3 b/docs/libssh2_session_abstract.3 index d880b09b56..1fba1f25dd 100644 --- a/docs/libssh2_session_abstract.3 +++ b/docs/libssh2_session_abstract.3 @@ -8,7 +8,7 @@ void ** libssh2_session_abstract(LIBSSH2_SESSION *session); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) Return a pointer to where the abstract pointer provided to diff --git a/docs/libssh2_session_banner_set.3 b/docs/libssh2_session_banner_set.3 index 5e4161eab1..1b6f4c9a07 100644 --- a/docs/libssh2_session_banner_set.3 +++ b/docs/libssh2_session_banner_set.3 @@ -4,11 +4,11 @@ libssh2_session_banner_set - set the SSH protocol banner for the local client .SH SYNOPSIS #include -int +int libssh2_session_banner_set(LIBSSH2_SESSION *session, const char *banner); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIbanner\fP - A pointer to a zero-terminated string holding the user defined diff --git a/docs/libssh2_session_callback_set.3 b/docs/libssh2_session_callback_set.3 index 6a075cbfb8..5dd2243c24 100644 --- a/docs/libssh2_session_callback_set.3 +++ b/docs/libssh2_session_callback_set.3 @@ -12,12 +12,12 @@ Sets a custom callback handler for a previously initialized session object. Callbacks are triggered by the receipt of special packets at the Transport layer. To disable a callback, set it to NULL. -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIcbtype\fP - Callback type. One of the types listed in Callback Types. -\fIcallback\fP - Pointer to custom callback function. The prototype for +\fIcallback\fP - Pointer to custom callback function. The prototype for this function must match the associated callback declaration macro. .SH CALLBACK TYPES .IP LIBSSH2_CALLBACK_IGNORE diff --git a/docs/libssh2_session_disconnect_ex.3 b/docs/libssh2_session_disconnect_ex.3 index 82174f9b63..f047bb6962 100644 --- a/docs/libssh2_session_disconnect_ex.3 +++ b/docs/libssh2_session_disconnect_ex.3 @@ -4,14 +4,14 @@ libssh2_session_disconnect_ex - terminate transport layer .SH SYNOPSIS #include -int +int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang); -int +int libssh2_session_disconnect(LIBSSH2_SESSION *session, const char *description); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIreason\fP - One of the Disconnect Reason constants. @@ -20,14 +20,14 @@ libssh2_session_disconnect(LIBSSH2_SESSION *session, const char *description); \fIlang\fP - Localization string describing the language/encoding of the description provided. -Send a disconnect message to the remote host associated with \fIsession\fP, +Send a disconnect message to the remote host associated with \fIsession\fP, along with a \fIreason\fP symbol and a verbose \fIdescription\fP. -As a convenience, the macro +As a convenience, the macro .BR libssh2_session_disconnect(3) is provided. It calls .BR libssh2_session_disconnect_ex(3) -with \fIreason\fP set to SSH_DISCONNECT_BY_APPLICATION +with \fIreason\fP set to SSH_DISCONNECT_BY_APPLICATION and \fIlang\fP set to an empty string. .SH RETURN VALUE diff --git a/docs/libssh2_session_free.3 b/docs/libssh2_session_free.3 index 96eff0cb55..f2dbfeb5d9 100644 --- a/docs/libssh2_session_free.3 +++ b/docs/libssh2_session_free.3 @@ -4,7 +4,7 @@ libssh2_session_free - frees resources associated with a session instance .SH SYNOPSIS #include -int +int libssh2_session_free(LIBSSH2_SESSION *session); .SH DESCRIPTION Frees all resources associated with a session instance. Typically called after diff --git a/docs/libssh2_session_init_ex.3 b/docs/libssh2_session_init_ex.3 index 5e4ef06c4e..5f06183157 100644 --- a/docs/libssh2_session_init_ex.3 +++ b/docs/libssh2_session_init_ex.3 @@ -4,27 +4,27 @@ libssh2_session_init_ex - initializes an SSH session object .SH SYNOPSIS #include -LIBSSH2_SESSION * +LIBSSH2_SESSION * libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*myalloc)), LIBSSH2_FREE_FUNC((*myfree)), LIBSSH2_REALLOC_FUNC((*myrealloc)), void *abstract); LIBSSH2_SESSION * libssh2_session_init(void); .SH DESCRIPTION -\fImyalloc\fP - Custom allocator function. Refer to the section on Callbacks -for implementing an allocator callback. Pass a value of NULL to use the +\fImyalloc\fP - Custom allocator function. Refer to the section on Callbacks +for implementing an allocator callback. Pass a value of NULL to use the default system allocator. -\fImyfree\fP - Custom de-allocator function. Refer to the section on Callbacks -for implementing a deallocator callback. Pass a value of NULL to use the +\fImyfree\fP - Custom de-allocator function. Refer to the section on Callbacks +for implementing a deallocator callback. Pass a value of NULL to use the default system deallocator. -\fImyrealloc\fP - Custom re-allocator function. Refer to the section on -Callbacks for implementing a reallocator callback. Pass a value of NULL to +\fImyrealloc\fP - Custom re-allocator function. Refer to the section on +Callbacks for implementing a reallocator callback. Pass a value of NULL to use the default system reallocator. -\fIabstract\fP - Arbitrary pointer to application specific callback data. -This value will be passed to any callback function associated with the named +\fIabstract\fP - Arbitrary pointer to application specific callback data. +This value will be passed to any callback function associated with the named session instance. Initializes an SSH session object. By default system memory allocators diff --git a/docs/libssh2_session_last_errno.3 b/docs/libssh2_session_last_errno.3 index f9172cbc4f..e23233bc6c 100644 --- a/docs/libssh2_session_last_errno.3 +++ b/docs/libssh2_session_last_errno.3 @@ -8,7 +8,7 @@ int libssh2_session_last_errno(LIBSSH2_SESSION *session); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) Determine the most recent error condition. diff --git a/docs/libssh2_session_last_error.3 b/docs/libssh2_session_last_error.3 index 2a64dbb7d8..6bbdbd0302 100644 --- a/docs/libssh2_session_last_error.3 +++ b/docs/libssh2_session_last_error.3 @@ -8,18 +8,18 @@ int libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_len, int want_buf); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) -\fIerrmsg\fP - If not NULL, is populated by reference with the human +\fIerrmsg\fP - If not NULL, is populated by reference with the human readable form of the most recent error message. -\fIerrmsg_len\fP - If not NULL, is populated by reference with the length -of errmsg. (The string is NUL-terminated, so the length is only useful as +\fIerrmsg_len\fP - If not NULL, is populated by reference with the length +of errmsg. (The string is NUL-terminated, so the length is only useful as an optimization, to avoid calling strlen.) -\fIwant_buf\fP - If set to a non-zero value, "ownership" of the errmsg -buffer will be given to the calling scope. If necessary, the errmsg buffer +\fIwant_buf\fP - If set to a non-zero value, "ownership" of the errmsg +buffer will be given to the calling scope. If necessary, the errmsg buffer will be duplicated. Determine the most recent error condition and its cause. diff --git a/docs/libssh2_session_method_pref.3 b/docs/libssh2_session_method_pref.3 index dcf77f6dcb..0af2d855c1 100644 --- a/docs/libssh2_session_method_pref.3 +++ b/docs/libssh2_session_method_pref.3 @@ -4,21 +4,21 @@ libssh2_session_method_pref - set preferred key exchange method .SH SYNOPSIS #include -int +int libssh2_session_method_pref(LIBSSH2_SESSION *session, int method_type, const char *prefs); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fImethod_type\fP - One of the Method Type constants. -\fIprefs\fP - Coma delimited list of preferred methods to use with -the most preferred listed first and the least preferred listed last. -If a method is listed which is not supported by libssh2 it will be +\fIprefs\fP - Coma delimited list of preferred methods to use with +the most preferred listed first and the least preferred listed last. +If a method is listed which is not supported by libssh2 it will be ignored and not sent to the remote host during protocol negotiation. -Set preferred methods to be negotiated. These +Set preferred methods to be negotiated. These preferences must be set prior to calling .BR libssh2_session_handshake(3) as they are used during the protocol initiation phase. diff --git a/docs/libssh2_session_set_blocking.3 b/docs/libssh2_session_set_blocking.3 index b16e009178..a7e9dcd17c 100644 --- a/docs/libssh2_session_set_blocking.3 +++ b/docs/libssh2_session_set_blocking.3 @@ -4,11 +4,11 @@ libssh2_session_set_blocking - set or clear blocking mode on session .SH SYNOPSIS #include -void +void libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking); .SH DESCRIPTION -\fIsession\fP - session instance as returned by +\fIsession\fP - session instance as returned by .BR libssh2_session_init_ex(3) \fIblocking\fP - Set to a non-zero value to make the channel block, or zero to diff --git a/docs/libssh2_session_startup.3 b/docs/libssh2_session_startup.3 index b59056f7d5..8e06014058 100644 --- a/docs/libssh2_session_startup.3 +++ b/docs/libssh2_session_startup.3 @@ -4,17 +4,17 @@ libssh2_session_startup - begin transport layer .SH SYNOPSIS #include -int +int libssh2_session_startup(LIBSSH2_SESSION *session, int socket); .SH DESCRIPTION Starting in libssh2 version 1.2.8 this function is considered deprecated. Use \fIlibssh2_session_handshake(3)\fP instead. -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) -\fIsocket\fP - Connected socket descriptor. Typically a TCP connection -though the protocol allows for any reliable transport and the library will +\fIsocket\fP - Connected socket descriptor. Typically a TCP connection +though the protocol allows for any reliable transport and the library will attempt to use any berkeley socket. Begin transport layer protocol negotiation with the connected host. @@ -25,14 +25,14 @@ Returns 0 on success, negative on failure. \fILIBSSH2_ERROR_BANNER_SEND\fP - Unable to send banner to remote host. -\fILIBSSH2_ERROR_KEX_FAILURE\fP - >Encryption key exchange with the remote +\fILIBSSH2_ERROR_KEX_FAILURE\fP - >Encryption key exchange with the remote host failed. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. \fILIBSSH2_ERROR_SOCKET_DISCONNECT\fP - The socket was disconnected. -\fILIBSSH2_ERROR_PROTO\fP - An invalid SSH protocol response was received on +\fILIBSSH2_ERROR_PROTO\fP - An invalid SSH protocol response was received on the socket. \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. diff --git a/docs/libssh2_sftp_close_handle.3 b/docs/libssh2_sftp_close_handle.3 index 30e299cfcb..432e50d3ef 100644 --- a/docs/libssh2_sftp_close_handle.3 +++ b/docs/libssh2_sftp_close_handle.3 @@ -5,13 +5,13 @@ libssh2_sftp_close_handle - close filehandle #include #include -int +int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle); -int +int libssh2_sftp_close(LIBSSH2_SFTP_HANDLE *handle); -int +int libssh2_sftp_closedir(LIBSSH2_SFTP_HANDLE *handle); .SH DESCRIPTION @@ -33,10 +33,10 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO diff --git a/docs/libssh2_sftp_fstat_ex.3 b/docs/libssh2_sftp_fstat_ex.3 index 107594cf0a..3c6967b41f 100644 --- a/docs/libssh2_sftp_fstat_ex.3 +++ b/docs/libssh2_sftp_fstat_ex.3 @@ -6,7 +6,7 @@ libssh2_sftp_fstat_ex - get or set attributes on an SFTP file handle #include #include -int +int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat) @@ -16,14 +16,14 @@ libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle, libssh2_sftp_fstat_ex((handle), (attrs), 1) .fi .SH DESCRIPTION -\fIhandle\fP - SFTP File Handle as returned by +\fIhandle\fP - SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) \fIattrs\fP - Pointer to an LIBSSH2_SFTP_ATTRIBUTES structure to set file metadata from or into depending on the value of setstat. -\fIsetstat\fP - When non-zero, the file's metadata will be updated -with the data found in attrs according to the values of attrs->flags +\fIsetstat\fP - When non-zero, the file's metadata will be updated +with the data found in attrs according to the values of attrs->flags and other relevant member attributes. Get or Set statbuf type data for a given LIBSSH2_SFTP_HANDLE instance. @@ -91,10 +91,10 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH AVAILABILITY This function has been around since forever, but most of the diff --git a/docs/libssh2_sftp_init.3 b/docs/libssh2_sftp_init.3 index a59d030048..d1ac40120a 100644 --- a/docs/libssh2_sftp_init.3 +++ b/docs/libssh2_sftp_init.3 @@ -9,7 +9,7 @@ LIBSSH2_SFTP * libssh2_sftp_init(LIBSSH2_SESSION *session); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) Open a channel and initialize the SFTP subsystem. Although the SFTP subsystem @@ -26,10 +26,10 @@ A pointer to the newly allocated SFTP instance or NULL on failure. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to be +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would diff --git a/docs/libssh2_sftp_last_error.3 b/docs/libssh2_sftp_last_error.3 index aadbd5d10d..2aee4c62fa 100644 --- a/docs/libssh2_sftp_last_error.3 +++ b/docs/libssh2_sftp_last_error.3 @@ -5,11 +5,11 @@ libssh2_sftp_last_error - return the last SFTP-specific error code #include #include -unsigned long +unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp); .SH DESCRIPTION -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) Returns the last error code produced by the SFTP layer. Note that this only diff --git a/docs/libssh2_sftp_mkdir_ex.3 b/docs/libssh2_sftp_mkdir_ex.3 index 20df03c394..ad65dcef82 100644 --- a/docs/libssh2_sftp_mkdir_ex.3 +++ b/docs/libssh2_sftp_mkdir_ex.3 @@ -5,16 +5,16 @@ libssh2_sftp_mkdir_ex - create a directory on the remote file system #include #include -int +int libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, long mode); -int +int libssh2_sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, long mode); .SH DESCRIPTION -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) -\fIpath\fP - full path of the new directory to create. Note that the new +\fIpath\fP - full path of the new directory to create. Note that the new directory's parents must all exist prior to making this call. \fIpath_len\fP - length of the full path of the new directory to create. @@ -31,10 +31,10 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to be +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO .BR libssh2_sftp_open_ex(3) diff --git a/docs/libssh2_sftp_open_ex.3 b/docs/libssh2_sftp_open_ex.3 index 32cc23fbc4..af341f14f4 100644 --- a/docs/libssh2_sftp_open_ex.3 +++ b/docs/libssh2_sftp_open_ex.3 @@ -13,9 +13,9 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename, .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by \fIlibssh2_sftp_init(3)\fP -\fIfilename\fP - Remote file/directory resource to open +\fIfilename\fP - Remote file/directory resource to open -\fIfilename_len\fP - Length of filename +\fIfilename_len\fP - Length of filename \fIflags\fP - Any reasonable combination of the LIBSSH2_FXF_* constants: .RS @@ -52,14 +52,13 @@ failure. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to be +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. .SH SEE ALSO .BR libssh2_sftp_close_handle(3) - diff --git a/docs/libssh2_sftp_read.3 b/docs/libssh2_sftp_read.3 index 36bc9794c6..6420121811 100644 --- a/docs/libssh2_sftp_read.3 +++ b/docs/libssh2_sftp_read.3 @@ -5,11 +5,11 @@ libssh2_sftp_read - read data from an SFTP handle #include #include -ssize_t +ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen); .SH DESCRIPTION -\fIhandle\fP is the SFTP File Handle as returned by +\fIhandle\fP is the SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) \fIbuffer\fP is a pointer to a pre-allocated buffer of at least @@ -17,15 +17,15 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxle \fIbuffer_maxlen\fP bytes to read data into. Reads a block of data from an LIBSSH2_SFTP_HANDLE. This method is modelled -after the POSIX +after the POSIX .BR read(2) -function and uses the same calling semantics. +function and uses the same calling semantics. .BR libssh2_sftp_read(3) will attempt to read as much as possible however it may not fill all of buffer if the file pointer reaches the end or if further reads would cause the socket to block. .SH RETURN VALUE -Number of bytes actually populated into buffer, or negative on failure. +Number of bytes actually populated into buffer, or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. .SH ERRORS @@ -33,7 +33,7 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - \fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be diff --git a/docs/libssh2_sftp_readdir_ex.3 b/docs/libssh2_sftp_readdir_ex.3 index a40e4df8fb..eb9dd2f7a9 100644 --- a/docs/libssh2_sftp_readdir_ex.3 +++ b/docs/libssh2_sftp_readdir_ex.3 @@ -6,7 +6,7 @@ libssh2_sftp_readdir_ex - read directory data from an SFTP handle #include #include -int +int libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen, char *longentry, size_t longentry_maxlen, @@ -15,14 +15,14 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *handle, Reads a block of data from a LIBSSH2_SFTP_HANDLE and returns file entry information for the next entry, if any. -\fIhandle\fP - is the SFTP File Handle as returned by +\fIhandle\fP - is the SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) \fIbuffer\fP - is a pointer to a pre-allocated buffer of at least \fIbuffer_maxlen\fP bytes to read data into. -\fIbuffer_maxlen\fP - is the length of buffer in bytes. If the length of the -filename is longer than the space provided by buffer_maxlen it will be +\fIbuffer_maxlen\fP - is the length of buffer in bytes. If the length of the +filename is longer than the space provided by buffer_maxlen it will be truncated to fit. \fIlongentry\fP - is a pointer to a pre-allocated buffer of at least @@ -35,7 +35,7 @@ a directory listing command is to simply display this data). the full directory entry is longer than the space provided by \fIlongentry_maxlen\fP it will be truncated to fit. -\fIattrs\fP - is a pointer to LIBSSH2_SFTP_ATTRIBUTES storage to populate +\fIattrs\fP - is a pointer to LIBSSH2_SFTP_ATTRIBUTES storage to populate statbuf style data into. .SH RETURN VALUE Number of bytes actually populated into buffer (not counting the terminating @@ -51,10 +51,10 @@ and it is not possible for the application to tell when it happens! \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to be +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. From 1.2.8, LIBSSH2_ERROR_BUFFER_TOO_SMALL is returned if any of the diff --git a/docs/libssh2_sftp_rename_ex.3 b/docs/libssh2_sftp_rename_ex.3 index 20a3b9db45..1a13ffd33c 100644 --- a/docs/libssh2_sftp_rename_ex.3 +++ b/docs/libssh2_sftp_rename_ex.3 @@ -5,35 +5,35 @@ libssh2_sftp_rename_ex - rename an SFTP file #include #include -int +int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename, unsigned int source_filename_len, const char *dest_filename, unsigned int dest_filename_len, long flags); -int +int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename, const char *dest_filename); .SH DESCRIPTION -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) \fIsourcefile\fP - Path and name of the existing filesystem entry -\fIsourcefile_len\fP - Length of the path and name of the existing +\fIsourcefile_len\fP - Length of the path and name of the existing filesystem entry \fIdestfile\fP - Path and name of the target filesystem entry -\fIdestfile_len\fP - Length of the path and name of the target +\fIdestfile_len\fP - Length of the path and name of the target filesystem entry -\fIflags\fP - +\fIflags\fP - Bitmask flags made up of LIBSSH2_SFTP_RENAME_* constants. -Rename a filesystem object on the remote filesystem. The semantics of -this command typically include the ability to move a filesystem object -between folders and/or filesystem mounts. If the LIBSSH2_SFTP_RENAME_OVERWRITE -flag is not set and the destfile entry already exists, the operation -will fail. Use of the other two flags indicate a preference (but not a -requirement) for the remote end to perform an atomic rename operation +Rename a filesystem object on the remote filesystem. The semantics of +this command typically include the ability to move a filesystem object +between folders and/or filesystem mounts. If the LIBSSH2_SFTP_RENAME_OVERWRITE +flag is not set and the destfile entry already exists, the operation +will fail. Use of the other two flags indicate a preference (but not a +requirement) for the remote end to perform an atomic rename operation and/or using native system calls when possible. .SH RETURN VALUE @@ -46,10 +46,10 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO diff --git a/docs/libssh2_sftp_rmdir_ex.3 b/docs/libssh2_sftp_rmdir_ex.3 index daa85cf055..117cf94ce1 100644 --- a/docs/libssh2_sftp_rmdir_ex.3 +++ b/docs/libssh2_sftp_rmdir_ex.3 @@ -11,7 +11,7 @@ int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path, .SH DESCRIPTION Remove a directory from the remote file system. -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) \fIsourcefile\fP - Full path of the existing directory to remove. @@ -27,10 +27,10 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_seek.3 b/docs/libssh2_sftp_seek.3 index ccf5e10694..13d4e78f55 100644 --- a/docs/libssh2_sftp_seek.3 +++ b/docs/libssh2_sftp_seek.3 @@ -10,15 +10,15 @@ void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset); .SH DESCRIPTION Deprecated function. Use \fIlibssh2_sftp_seek64(3)\fP instead! -\fIhandle\fP - SFTP File Handle as returned by +\fIhandle\fP - SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) \fIoffset\fP - Number of bytes from the beginning of file to seek to. -Move the file handle's internal pointer to an arbitrary location. -Note that libssh2 implements file pointers as a localized concept to make -file access appear more POSIX like. No packets are exchanged with the server -during a seek operation. The localized file pointer is simply used as a +Move the file handle's internal pointer to an arbitrary location. +Note that libssh2 implements file pointers as a localized concept to make +file access appear more POSIX like. No packets are exchanged with the server +during a seek operation. The localized file pointer is simply used as a convenience offset during read/write operations. .SH SEE ALSO .BR libssh2_sftp_open_ex(3), diff --git a/docs/libssh2_sftp_seek64.3 b/docs/libssh2_sftp_seek64.3 index 57c9a48586..847a545117 100644 --- a/docs/libssh2_sftp_seek64.3 +++ b/docs/libssh2_sftp_seek64.3 @@ -9,7 +9,7 @@ libssh2_sftp_seek64 - set the read/write position within a file void libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset); .SH DESCRIPTION -\fIhandle\fP - SFTP File Handle as returned by +\fIhandle\fP - SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) \fIoffset\fP - Number of bytes from the beginning of file to seek to. diff --git a/docs/libssh2_sftp_shutdown.3 b/docs/libssh2_sftp_shutdown.3 index 42cc1c4911..e1e8a96f28 100644 --- a/docs/libssh2_sftp_shutdown.3 +++ b/docs/libssh2_sftp_shutdown.3 @@ -5,14 +5,14 @@ libssh2_sftp_shutdown - shut down an SFTP session #include #include -int +int libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp); .SH DESCRIPTION -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) -Destroys a previously initialized SFTP session and frees all resources +Destroys a previously initialized SFTP session and frees all resources associated with it. .SH RETURN VALUE diff --git a/docs/libssh2_sftp_stat_ex.3 b/docs/libssh2_sftp_stat_ex.3 index 2fd9507fc5..4e6f681062 100644 --- a/docs/libssh2_sftp_stat_ex.3 +++ b/docs/libssh2_sftp_stat_ex.3 @@ -10,15 +10,15 @@ int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, int stat_type, LIBSSH2_SFTP_ATTRIBUTES *attrs); .SH DESCRIPTION -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) \fIpath\fP - Remote filesystem object to stat/lstat/setstat. -\fIpath_len\fP - Length of the name of the remote filesystem object +\fIpath_len\fP - Length of the name of the remote filesystem object to stat/lstat/setstat. -\fIstat_type\fP - One of the three constants specifying the type of +\fIstat_type\fP - One of the three constants specifying the type of stat operation to perform: .br @@ -34,9 +34,9 @@ metadata from or into depending on the value of stat_type. Get or Set statbuf type data on a remote filesystem object. When getting statbuf data, .BR libssh2_sftp_stat(3) -will follow all symlinks, while +will follow all symlinks, while .BR libssh2_sftp_lstat(3) -will return data about the object encountered, even if that object +will return data about the object encountered, even if that object happens to be a symlink. The LIBSSH2_SFTP_ATTRIBUTES struct looks like this: @@ -65,10 +65,10 @@ number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_statvfs.3 b/docs/libssh2_sftp_statvfs.3 index 6327030ae9..1b5feb1d0b 100644 --- a/docs/libssh2_sftp_statvfs.3 +++ b/docs/libssh2_sftp_statvfs.3 @@ -68,7 +68,7 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - \fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned diff --git a/docs/libssh2_sftp_symlink_ex.3 b/docs/libssh2_sftp_symlink_ex.3 index fc0bc936b7..6aacaa55ab 100644 --- a/docs/libssh2_sftp_symlink_ex.3 +++ b/docs/libssh2_sftp_symlink_ex.3 @@ -6,19 +6,19 @@ libssh2_sftp_symlink_ex - read or set a symbolic link #include #include -int +int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, char *target, unsigned int target_len, int link_type); .SH DESCRIPTION Create a symlink or read out symlink information from the remote side. -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) \fIpath\fP - Remote filesystem object to create a symlink from or resolve. -\fIpath_len\fP - Length of the name of the remote filesystem object to +\fIpath_len\fP - Length of the name of the remote filesystem object to create a symlink from or resolve. \fItarget\fP - a pointer to a buffer. The buffer has different uses depending @@ -34,7 +34,7 @@ into. \fItarget_len\fP - Length of the name of the remote filesystem target object. -\fIlink_type\fP - One of the three previously mentioned constants which +\fIlink_type\fP - One of the three previously mentioned constants which determines the resulting behavior of this function. These are convenience macros: @@ -69,10 +69,10 @@ for the application to tell when it happens! \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO diff --git a/docs/libssh2_sftp_tell.3 b/docs/libssh2_sftp_tell.3 index 2ff1fbad88..574a883563 100644 --- a/docs/libssh2_sftp_tell.3 +++ b/docs/libssh2_sftp_tell.3 @@ -5,7 +5,7 @@ libssh2_sftp_tell - get the current read/write position indicator for a file #include #include -size_t +size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle); .SH DESCRIPTION diff --git a/docs/libssh2_sftp_unlink_ex.3 b/docs/libssh2_sftp_unlink_ex.3 index 6672a8c343..9d05006aa2 100644 --- a/docs/libssh2_sftp_unlink_ex.3 +++ b/docs/libssh2_sftp_unlink_ex.3 @@ -5,19 +5,19 @@ libssh2_sftp_unlink_ex - unlink an SFTP file #include #include -int +int libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp, const char *filename, unsigned int filename_len); -int +int libssh2_sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename); .SH DESCRIPTION -\fIsftp\fP - SFTP instance as returned by +\fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) \fIfilename\fP - Path and name of the existing filesystem entry -\fIfilename_len\fP - Length of the path and name of the existing +\fIfilename_len\fP - Length of the path and name of the existing filesystem entry Unlink (delete) a file from the remote filesystem. @@ -32,10 +32,10 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO diff --git a/docs/libssh2_sftp_write.3 b/docs/libssh2_sftp_write.3 index 8d819129a0..eca2cbc7e2 100644 --- a/docs/libssh2_sftp_write.3 +++ b/docs/libssh2_sftp_write.3 @@ -62,10 +62,10 @@ end. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - -\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was -received on the socket, or an SFTP operation caused an errorcode to +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be returned by the server. .SH SEE ALSO .BR libssh2_sftp_open_ex(3) diff --git a/docs/libssh2_sign_sk.3 b/docs/libssh2_sign_sk.3 index 7aa503d671..79e529633c 100644 --- a/docs/libssh2_sign_sk.3 +++ b/docs/libssh2_sign_sk.3 @@ -22,10 +22,10 @@ typedef struct _LIBSSH2_PRIVKEY_SK { } LIBSSH2_PRIVKEY_SK; .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) -\fIsig\fP - A pointer to a buffer in which to place the signature. The caller +\fIsig\fP - A pointer to a buffer in which to place the signature. The caller is responsible for freeing the signature with LIBSSH2_FREE. \fIsig_len\fP - A pointer to the length of the sig parameter. @@ -34,48 +34,48 @@ is responsible for freeing the signature with LIBSSH2_FREE. \fIdata_len\fP - The length of the data parameter. -\fIabstract\fP - A pointer to a pointer to a LIBSSH2_PRIVKEY_SK. See +\fIabstract\fP - A pointer to a pointer to a LIBSSH2_PRIVKEY_SK. See description below. -Create a signature from a FIDO2 authenticator, using either the -sk-ssh-ed25519@openssh.com or sk-ecdsa-sha2-nistp256@openssh.com key +Create a signature from a FIDO2 authenticator, using either the +sk-ssh-ed25519@openssh.com or sk-ecdsa-sha2-nistp256@openssh.com key exchange algorithms. -The abstract parameter is a pointer to a pointer due to the internal workings -of libssh2. The LIBSSH2_PRIVKEY_SK must be completely filled out, and the +The abstract parameter is a pointer to a pointer due to the internal workings +of libssh2. The LIBSSH2_PRIVKEY_SK must be completely filled out, and the caller is responsible for all memory management of its fields. -\fIalgorithm\fP - The signing algorithm to use. Possible values are +\fIalgorithm\fP - The signing algorithm to use. Possible values are LIBSSH2_HOSTKEY_TYPE_ED25519 and LIBSSH2_HOSTKEY_TYPE_ECDSA_256. -\fIflags\fP - A bitmask specifying options for the authenticator. When +\fIflags\fP - A bitmask specifying options for the authenticator. When LIBSSH2_SK_PRESENCE_REQUIRED is set, the authenticator requires a touch. When -LIBSSH2_SK_VERIFICATION_REQUIRED is set, the authenticator requires a PIN. -Many servers and authenticators do not work properly when +LIBSSH2_SK_VERIFICATION_REQUIRED is set, the authenticator requires a PIN. +Many servers and authenticators do not work properly when LIBSSH2_SK_PRESENCE_REQUIRED is not set. -\fIapplication\fP - A user-defined string to use as the RP name for the +\fIapplication\fP - A user-defined string to use as the RP name for the authenticator. Usually "ssh:". \fIkey_handle\fP - The key handle to use for the authenticator's allow list. \fIhandle_len\fP - The length of the key_handle parameter. -\fIabstract\fP - User-defined data. When a PIN is required, use this to pass in +\fIabstract\fP - User-defined data. When a PIN is required, use this to pass in the PIN, or a function pointer to retrieve the PIN. \fIkey_handle\fP The decoded key handle from the private key file. \fIhandle_len\fP The length of the key_handle parameter. -\fIsign_callback\fP - Responsible for communicating with the hardware +\fIsign_callback\fP - Responsible for communicating with the hardware authenticator to generate a signature. On success, the signature information -must be placed in the `\fIsig_info\fP sig_info parameter and the callback must +must be placed in the `\fIsig_info\fP sig_info parameter and the callback must return 0. On failure, it should return a negative number. See .BR libssh2_userauth_publickey_sk(3) for more information. -\fIorig_abstract\fP - User-defined data. When a PIN is required, use this to +\fIorig_abstract\fP - User-defined data. When a PIN is required, use this to pass in the PIN, or a function pointer to retrieve the PIN. .SH RETURN VALUE diff --git a/docs/libssh2_userauth_authenticated.3 b/docs/libssh2_userauth_authenticated.3 index 786e0f0e5b..3019562918 100644 --- a/docs/libssh2_userauth_authenticated.3 +++ b/docs/libssh2_userauth_authenticated.3 @@ -4,11 +4,11 @@ libssh2_userauth_authenticated - return authentication status .SH SYNOPSIS #include -int +int libssh2_userauth_authenticated(LIBSSH2_SESSION *session); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) Indicates whether or not the named session has been successfully authenticated. diff --git a/docs/libssh2_userauth_list.3 b/docs/libssh2_userauth_list.3 index de349f105a..c8c2d35207 100644 --- a/docs/libssh2_userauth_list.3 +++ b/docs/libssh2_userauth_list.3 @@ -9,7 +9,7 @@ char * libssh2_userauth_list(LIBSSH2_SESSION *session, const char *username, unsigned int username_len); .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIusername\fP - Username which will be used while authenticating. Note that diff --git a/docs/libssh2_userauth_password_ex.3 b/docs/libssh2_userauth_password_ex.3 index 03b90a11d1..d1b6c86f93 100644 --- a/docs/libssh2_userauth_password_ex.3 +++ b/docs/libssh2_userauth_password_ex.3 @@ -16,7 +16,7 @@ int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, strlen(username), \\ (password), strlen(password), NULL) .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIusername\fP - Name of user to attempt plain password authentication for. @@ -27,14 +27,14 @@ int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, \fIpassword_len\fP - Length of password parameter. -\fIpasswd_change_cb\fP - If the host accepts authentication but -requests that the password be changed, this callback will be issued. -If no callback is defined, but server required password change, +\fIpasswd_change_cb\fP - If the host accepts authentication but +requests that the password be changed, this callback will be issued. +If no callback is defined, but server required password change, authentication will fail. -Attempt basic password authentication. Note that many SSH servers -which appear to support ordinary password authentication actually have -it disabled and use Keyboard Interactive authentication (routed via +Attempt basic password authentication. Note that many SSH servers +which appear to support ordinary password authentication actually have +it disabled and use Keyboard Interactive authentication (routed via PAM or another authentication backed) instead. .SH RETURN VALUE @@ -49,7 +49,7 @@ Some of the errors this function may return include: \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_PASSWORD_EXPIRED\fP - +\fILIBSSH2_ERROR_PASSWORD_EXPIRED\fP - \fILIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - failed, invalid username/password or public/private key. diff --git a/docs/libssh2_userauth_publickey_fromfile_ex.3 b/docs/libssh2_userauth_publickey_fromfile_ex.3 index 0d77c9a30f..f5ffc3670d 100644 --- a/docs/libssh2_userauth_publickey_fromfile_ex.3 +++ b/docs/libssh2_userauth_publickey_fromfile_ex.3 @@ -40,7 +40,7 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - \fILIBSSH2_ERROR_PUBLICKEY_UNVERIFIED\fP - The username/public key combination was invalid. diff --git a/docs/libssh2_userauth_publickey_frommemory.3 b/docs/libssh2_userauth_publickey_frommemory.3 index 685bd59108..bd58fde51f 100644 --- a/docs/libssh2_userauth_publickey_frommemory.3 +++ b/docs/libssh2_userauth_publickey_frommemory.3 @@ -43,7 +43,7 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. -\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - \fILIBSSH2_ERROR_PUBLICKEY_UNVERIFIED\fP - The username/public key combination was invalid. diff --git a/docs/libssh2_userauth_publickey_sk.3 b/docs/libssh2_userauth_publickey_sk.3 index 4ed54c906f..f24650f671 100644 --- a/docs/libssh2_userauth_publickey_sk.3 +++ b/docs/libssh2_userauth_publickey_sk.3 @@ -28,15 +28,15 @@ typedef struct _LIBSSH2_SK_SIG_INFO { size_t sig_s_len; } LIBSSH2_SK_SIG_INFO; -int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, +int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, const unsigned char *data, size_t data_len, int algorithm, uint8_t flags, const char *application, - const unsigned char *key_handle, size_t handle_len, + const unsigned char *key_handle, size_t handle_len, void **abstract); .fi .SH DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) \fIusername\fP - Name of user to attempt authentication for. @@ -53,49 +53,49 @@ int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, \fIabstract\fP - User-provided data to pass to callback. -Attempt FIDO2 authentication. using either the sk-ssh-ed25519@openssh.com or +Attempt FIDO2 authentication. using either the sk-ssh-ed25519@openssh.com or sk-ecdsa-sha2-nistp256@openssh.com key exchange algorithms. This function is only supported when libssh2 is backed by OpenSSL. .SH CALLBACK DESCRIPTION -\fIsession\fP - Session instance as returned by +\fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) -\fIsig_info\fP - Filled in by the callback with the signature and accompanying +\fIsig_info\fP - Filled in by the callback with the signature and accompanying information from the authenticator. \fIdata\fP - The data to sign. \fIdata_len\fP - The length of the data parameter. -\fIalgorithm\fP - The signing algorithm to use. Possible values are +\fIalgorithm\fP - The signing algorithm to use. Possible values are LIBSSH2_HOSTKEY_TYPE_ED25519 and LIBSSH2_HOSTKEY_TYPE_ECDSA_256. -\fIflags\fP - A bitmask specifying options for the authenticator. When +\fIflags\fP - A bitmask specifying options for the authenticator. When LIBSSH2_SK_PRESENCE_REQUIRED is set, the authenticator requires a touch. When -LIBSSH2_SK_VERIFICATION_REQUIRED is set, the authenticator requires a PIN. -Many servers and authenticators do not work properly when +LIBSSH2_SK_VERIFICATION_REQUIRED is set, the authenticator requires a PIN. +Many servers and authenticators do not work properly when LIBSSH2_SK_PRESENCE_REQUIRED is not set. -\fIapplication\fP - A user-defined string to use as the RP name for the +\fIapplication\fP - A user-defined string to use as the RP name for the authenticator. Usually "ssh:". \fIkey_handle\fP - The key handle to use for the authenticator's allow list. \fIhandle_len\fP - The length of the key_handle parameter. -\fIabstract\fP - User-defined data. When a PIN is required, use this to pass in +\fIabstract\fP - User-defined data. When a PIN is required, use this to pass in the PIN, or a function pointer to retrieve the PIN. -The \fIsign_callback\fP is responsible for communicating with the hardware +The \fIsign_callback\fP is responsible for communicating with the hardware authenticator to generate a signature. On success, the signature information -must be placed in the `\fIsig_info\fP sig_info parameter and the callback must +must be placed in the `\fIsig_info\fP sig_info parameter and the callback must return 0. On failure, it should return a negative number. The fields of the LIBSSH2_SK_SIG_INFO are as follows. -\fIflags\fP - A bitmask specifying options for the authenticator. This should +\fIflags\fP - A bitmask specifying options for the authenticator. This should be read from the authenticator and not merely copied from the flags parameter to the callback. @@ -103,15 +103,15 @@ to the callback. \fIsig_r\fP - For Ed25519 signatures, this contains the entire signature, as returned directly from the authenticator. For ECDSA signatures, this contains -the r component of the signature in a big-endian binary representation. For +the r component of the signature in a big-endian binary representation. For both algorithms, use LIBSSH2_ALLOC to allocate memory. It will be freed by the caller. \fIsig_r_len\fP - The length of the sig_r parameter. -\fIsig_s\fP - For ECDSA signatures, this contains the s component of the -signature in a big-endian binary representation. Use LIBSSH2_ALLOC to allocate -memory. It will be freed by the caller. For Ed25519 signatures, set this to +\fIsig_s\fP - For ECDSA signatures, this contains the s component of the +signature in a big-endian binary representation. Use LIBSSH2_ALLOC to allocate +memory. It will be freed by the caller. For Ed25519 signatures, set this to NULL. \fIsig_s_len\fP - The length of the sig_s parameter. diff --git a/docs/template.3 b/docs/template.3 index d5b4473c8d..c3a229628a 100644 --- a/docs/template.3 +++ b/docs/template.3 @@ -4,7 +4,7 @@ libssh2_template - short function description .SH SYNOPSIS #include -void +void libssh2_template(void); .SH DESCRIPTION diff --git a/example/Makefile.am b/example/Makefile.am index 2f91eb2b93..2bd08c7c53 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -2,12 +2,31 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = libssh2_config_cmake.h.in CMakeLists.txt -# samples -noinst_PROGRAMS = direct_tcpip ssh2 scp scp_nonblock scp_write \ - scp_write_nonblock sftp sftp_nonblock sftp_write sftp_write_nonblock \ - sftp_mkdir sftp_mkdir_nonblock sftp_RW_nonblock sftp_write_sliding \ - sftpdir sftpdir_nonblock ssh2_exec ssh2_agent ssh2_agent_forwarding \ - ssh2_echo sftp_append subsystem_netconf tcpip-forward +# examples +noinst_PROGRAMS = \ + direct_tcpip \ + scp \ + scp_nonblock \ + scp_write \ + scp_write_nonblock \ + sftp \ + sftp_RW_nonblock \ + sftp_append \ + sftp_mkdir \ + sftp_mkdir_nonblock \ + sftp_nonblock \ + sftp_write \ + sftp_write_nonblock \ + sftp_write_sliding \ + sftpdir \ + sftpdir_nonblock \ + ssh2 \ + ssh2_agent \ + ssh2_agent_forwarding \ + ssh2_echo \ + ssh2_exec \ + subsystem_netconf \ + tcpip-forward if HAVE_SYS_UN_H noinst_PROGRAMS += x11 diff --git a/git2news.pl b/git2news.pl index 7da4709d21..5544663cf4 100755 --- a/git2news.pl +++ b/git2news.pl @@ -14,7 +14,7 @@ sub nicedate { return $date; } -print +print ' Changelog for the libssh2 project. Generated with git2news.pl '; diff --git a/libssh2-style.el b/libssh2-style.el index 20a24e8a97..7b622b45da 100644 --- a/libssh2-style.el +++ b/libssh2-style.el @@ -10,13 +10,13 @@ (c-comment-only-line-offset . 0) (c-hanging-braces-alist . ((substatement-open before after))) (c-offsets-alist . ((topmost-intro . 0) - (topmost-intro-cont . 0) - (substatement . +) - (substatement-open . 0) - (statement-case-intro . +) - (statement-case-open . 0) - (case-label . 0) - )) + (topmost-intro-cont . 0) + (substatement . +) + (substatement-open . 0) + (statement-case-intro . +) + (statement-case-open . 0) + (case-label . 0) + )) ) "Libssh2 C Programming Style") @@ -33,10 +33,10 @@ ;; add libssh2 style and set it for the current buffer (c-add-style "libssh2" libssh2-c-style t) (setq tab-width 8 - indent-tabs-mode nil ; Use spaces, not tabs. - comment-column 40 - c-font-lock-extra-types (append '("libssh2_int64_t" "LIBSSH2_USERAUTH_KBDINT_PROMPT" "LIBSSH2_SESSION" "LIBSSH2_CHANNEL" "ssize_t" "size_t" "uint32_t" "LIBSSH2_LISTENER" "LIBSSH2_POLLFD")) - ) + indent-tabs-mode nil ; Use spaces, not tabs. + comment-column 40 + c-font-lock-extra-types (append '("libssh2_int64_t" "LIBSSH2_USERAUTH_KBDINT_PROMPT" "LIBSSH2_SESSION" "LIBSSH2_CHANNEL" "ssize_t" "size_t" "uint32_t" "LIBSSH2_LISTENER" "LIBSSH2_POLLFD")) + ) ;; keybindings for C, C++, and Objective-C. We can put these in ;; c-mode-base-map because of inheritance ... (define-key c-mode-base-map "\M-q" 'c-fill-paragraph) diff --git a/m4/autobuild.m4 b/m4/autobuild.m4 index 2f94844e98..78b216774f 100644 --- a/m4/autobuild.m4 +++ b/m4/autobuild.m4 @@ -14,31 +14,31 @@ # Usage: AB_INIT([MODE]). AC_DEFUN([AB_INIT], [ - AC_REQUIRE([AC_CANONICAL_BUILD]) - AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AC_CANONICAL_BUILD]) + AC_REQUIRE([AC_CANONICAL_HOST]) - if test -z "$AB_PACKAGE"; then - AB_PACKAGE=${PACKAGE_NAME:-$PACKAGE} - fi - AC_MSG_NOTICE([autobuild project... $AB_PACKAGE]) + if test -z "$AB_PACKAGE"; then + AB_PACKAGE=${PACKAGE_NAME:-$PACKAGE} + fi + AC_MSG_NOTICE([autobuild project... $AB_PACKAGE]) - if test -z "$AB_VERSION"; then - AB_VERSION=${PACKAGE_VERSION:-$VERSION} - fi - AC_MSG_NOTICE([autobuild revision... $AB_VERSION]) + if test -z "$AB_VERSION"; then + AB_VERSION=${PACKAGE_VERSION:-$VERSION} + fi + AC_MSG_NOTICE([autobuild revision... $AB_VERSION]) - hostname=`hostname` - if test "$hostname"; then - AC_MSG_NOTICE([autobuild hostname... $hostname]) - fi + hostname=`hostname` + if test "$hostname"; then + AC_MSG_NOTICE([autobuild hostname... $hostname]) + fi - ifelse([$1],[],,[AC_MSG_NOTICE([autobuild mode... $1])]) + ifelse([$1],[],,[AC_MSG_NOTICE([autobuild mode... $1])]) - date=`date +%Y%m%d-%H%M%S` - if test "$?" != 0; then - date=`date` - fi - if test "$date"; then - AC_MSG_NOTICE([autobuild timestamp... $date]) - fi + date=`date +%Y%m%d-%H%M%S` + if test "$?" != 0; then + date=`date` + fi + if test "$date"; then + AC_MSG_NOTICE([autobuild timestamp... $date]) + fi ]) diff --git a/m4/lib-ld.m4 b/m4/lib-ld.m4 index 96c4e2c339..db76f6bcf0 100644 --- a/m4/lib-ld.m4 +++ b/m4/lib-ld.m4 @@ -59,7 +59,7 @@ if test "$GCC" = yes; then # Canonicalize the path of ld ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do - ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` + ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; @@ -89,9 +89,9 @@ AC_CACHE_VAL(acl_cv_path_LD, # Break only if it was the GNU/non-GNU ld that we prefer. case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in *GNU* | *'with BFD'*) - test "$with_gnu_ld" != no && break ;; + test "$with_gnu_ld" != no && break ;; *) - test "$with_gnu_ld" != yes && break ;; + test "$with_gnu_ld" != yes && break ;; esac fi done diff --git a/maketgz b/maketgz index a53f20d8c7..ed03db7346 100755 --- a/maketgz +++ b/maketgz @@ -10,8 +10,8 @@ if [ -z "$version" ]; then fi if [ "xonly" = "x$2" ]; then - echo "Setup version number only!" - only=1 + echo "Setup version number only!" + only=1 fi libversion="$version" @@ -25,25 +25,26 @@ numeric=`perl -e 'printf("%02x%02x%02x\n", '"$major, $minor, $patch);"` HEADER=include/libssh2.h if test -z "$only"; then - ext=".dist" - # when not setting up version numbers locally - for a in $HEADER; do - cp $a "$a$ext" - done - HEADER="$HEADER$ext" + ext=".dist" + # when not setting up version numbers locally + for a in $HEADER; do + cp $a "$a$ext" + done + HEADER="$HEADER$ext" fi # requires a date command that knows -u for UTC time zone datestamp=`LC_TIME=C date -u` # Replace in-place version number in header file: -sed -i.bak -e 's/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION "'$libversion'"/g' \ - -e 's/^#define LIBSSH2_VERSION_NUM .*/#define LIBSSH2_VERSION_NUM 0x'$numeric'/g' \ - -e 's/^#define LIBSSH2_VERSION_MAJOR .*/#define LIBSSH2_VERSION_MAJOR '$major'/g' \ - -e 's/^#define LIBSSH2_VERSION_MINOR .*/#define LIBSSH2_VERSION_MINOR '$minor'/g' \ - -e 's/^#define LIBSSH2_VERSION_PATCH .*/#define LIBSSH2_VERSION_PATCH '$patch'/g' \ - -e "s/^#define LIBSSH2_TIMESTAMP .*/#define LIBSSH2_TIMESTAMP \"$datestamp\"/g" \ - $HEADER +sed -i.bak \ + -e 's/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION "'$libversion'"/g' \ + -e 's/^#define LIBSSH2_VERSION_NUM .*/#define LIBSSH2_VERSION_NUM 0x'$numeric'/g' \ + -e 's/^#define LIBSSH2_VERSION_MAJOR .*/#define LIBSSH2_VERSION_MAJOR '$major'/g' \ + -e 's/^#define LIBSSH2_VERSION_MINOR .*/#define LIBSSH2_VERSION_MINOR '$minor'/g' \ + -e 's/^#define LIBSSH2_VERSION_PATCH .*/#define LIBSSH2_VERSION_PATCH '$patch'/g' \ + -e "s/^#define LIBSSH2_TIMESTAMP .*/#define LIBSSH2_TIMESTAMP \"$datestamp\"/g" \ + $HEADER rm -f "$HEADER.bak" @@ -52,12 +53,11 @@ echo "libssh2 numerical $numeric" echo "datestamp $datestamp" if test -n "$only"; then - # done! - exit; + # done! + exit fi -findprog() -{ +findprog() { file="$1" for part in `echo $PATH| tr ':' ' '`; do path="$part/$file" diff --git a/nw/GNUmakefile b/nw/GNUmakefile index 291f59241c..8519118646 100644 --- a/nw/GNUmakefile +++ b/nw/GNUmakefile @@ -9,7 +9,7 @@ # Edit the path below to point to the base of your Novell NDK. ifndef NDKBASE -NDKBASE = c:/novell +NDKBASE = c:/novell endif # Edit the path below to point to the base of your Zlib sources. @@ -24,26 +24,26 @@ endif # Edit the path below to point to your Distribution folder. ifndef DISTDIR -DISTDIR = libssh2-$(LIBSSH2_VERSION_STR)-bin-nw +DISTDIR = libssh2-$(LIBSSH2_VERSION_STR)-bin-nw endif -DISTARC = $(DISTDIR).zip +DISTARC = $(DISTDIR).zip # Edit the path below to point to your Development folder. ifndef DEVLDIR -DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-nw +DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-nw endif -DEVLARC = $(DEVLDIR).zip +DEVLARC = $(DEVLDIR).zip # Edit the vars below to change NLM target settings. -TARGET = libssh2 -VERSION = $(LIBSSH2_VERSION) -CPRIGHT = Copyright (c) $(LIBSSH2_COPYRIGHT_STR) -WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) -MTSAFE = YES -STACK = 64000 -SCREEN = none -EXPORTS = @$(TARGET).imp +TARGET = libssh2 +VERSION = $(LIBSSH2_VERSION) +CPRIGHT = Copyright (c) $(LIBSSH2_COPYRIGHT_STR) +WWWURL = https://www.libssh2.org/ +DESCR = libssh2 $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) +MTSAFE = YES +STACK = 64000 +SCREEN = none +EXPORTS = @$(TARGET).imp # Edit the var below to point to your lib architecture. ifndef LIBARCH @@ -52,66 +52,66 @@ endif # must be equal to DEBUG or NDEBUG ifndef DB - DB = NDEBUG - # DB = DEBUG + DB = NDEBUG +# DB = DEBUG endif # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release + OPT = -O2 + OBJDIR = release else - OPT = -g - OPT += -DLIBSSH2DEBUG - OBJDIR = debug + OPT = -g + OPT += -DLIBSSH2DEBUG + OBJDIR = debug endif # The following lines defines your compiler. ifdef CWFolder - METROWERKS = $(CWFolder) + METROWERKS = $(CWFolder) endif ifdef METROWERKS - # MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support - MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support - CC = mwccnlm +# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support + MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support + CC = mwccnlm else - CC = $(CROSSPREFIX)gcc + CC = $(CROSSPREFIX)gcc endif # Here you can find a native Win32 binary of the original awk: # http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk +AWK = awk # If you want to mark the target as MTSAFE you will need a tool for # generating the xdc data for the linker; here's a minimal tool: # http://www.gknw.net/development/prgtools/mkxdc.zip -MPKXDC = mkxdc -ZIP = zip -qzr9 +MPKXDC = mkxdc +ZIP = zip -qzr9 # Platform-dependent helper tool macros ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +#COPYR = -cp -afr $1/* $2 +COPYR = -rsync -aC $1/* $2 +TOUCH = touch $1 +CAT = cat +ECHONL = echo "" +DL = ' else ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) -endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. +DEL = -del 2>NUL $(subst /,\,$1) +RMDIR = -deltree 2>NUL /y $(subst /,\,$1) +endif +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) +COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) +TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, +CAT = type +ECHONL = $(ComSpec) /c echo. endif # LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH)) @@ -121,52 +121,52 @@ LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH)) -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS += $(OPT) -D$(DB) -DNETWARE -nostdinc -#CFLAGS += -DHAVE_CONFIG_H +CFLAGS += $(OPT) -D$(DB) -DNETWARE -nostdinc +#CFLAGS += -DHAVE_CONFIG_H ifeq ($(CC),mwccnlm) -LD = mwldnlm -LDFLAGS = -nostdlib $(PRELUDE) $(OBJL) -o $@ -commandfile -AR = mwldnlm -ARFLAGS = -nostdlib -type library -o -LIBEXT = lib -CFLAGS += -msgstyle gcc -gccinc -inline on -opt nointrinsics -proc 586 -CFLAGS += -relax_pointers -#CFLAGS += -w on +LD = mwldnlm +LDFLAGS = -nostdlib $(PRELUDE) $(OBJL) -o $@ -commandfile +AR = mwldnlm +ARFLAGS = -nostdlib -type library -o +LIBEXT = lib +CFLAGS += -msgstyle gcc -gccinc -inline on -opt nointrinsics -proc 586 +CFLAGS += -relax_pointers +#CFLAGS += -w on ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.o - CFLAGS += -align 4 + PRELUDE = $(SDK_LIBC)/imports/libcpre.o + CFLAGS += -align 4 else - # PRELUDE = $(SDK_CLIB)/imports/clibpre.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" - # CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" - CFLAGS += -align 1 +# PRELUDE = $(SDK_CLIB)/imports/clibpre.o + # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK + PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" +# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" + CFLAGS += -align 1 endif else -LD = $(CROSSPREFIX)nlmconv -LDFLAGS = -UT -AR = $(CROSSPREFIX)ar -ARFLAGS = -cq -LIBEXT = a -RANLIB = $(CROSSPREFIX)ranlib -CFLAGS += -m32 -CFLAGS += -fno-builtin -fpcc-struct-return -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall # -pedantic -#CFLAGS += -Wno-pointer-sign +LD = $(CROSSPREFIX)nlmconv +LDFLAGS = -UT +AR = $(CROSSPREFIX)ar +ARFLAGS = -cq +LIBEXT = a +RANLIB = $(CROSSPREFIX)ranlib +CFLAGS += -m32 +CFLAGS += -fno-builtin -fpcc-struct-return +CFLAGS += -fno-strict-aliasing +CFLAGS += -Wall # -pedantic +#CFLAGS += -Wno-pointer-sign ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o + PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o else - # PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - # http://www.gknw.net/development/mk_nlm/gcc_pre.zip - PRELUDE = $(NDK_ROOT)/pre/prelude.o - CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h +# PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o + # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK + # http://www.gknw.net/development/mk_nlm/gcc_pre.zip + PRELUDE = $(NDK_ROOT)/pre/prelude.o + CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h endif endif -LDLIBS = +LDLIBS = NDK_ROOT = $(NDKBASE)/ndk SDK_CLIB = $(NDK_ROOT)/nwsdk @@ -176,12 +176,12 @@ SNPRINTF = $(NDKBASE)/snprintf INCLUDES = -I. -I../include ifdef WITH_ZLIB - INCLUDES += -I$(ZLIB_PATH) + INCLUDES += -I$(ZLIB_PATH) ifdef LINK_STATIC - LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) + LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) else - MODULES += libz.nlm - IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp + MODULES += libz.nlm + IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp endif endif INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) @@ -190,25 +190,25 @@ LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) IMPORTS += GetProcessSwitchCount RunningProcess ifeq ($(LIBARCH),LIBC) - INCLUDES += -I$(SDK_LIBC)/include - # INCLUDES += -I$(SDK_LIBC)/include/nks - # INCLUDES += -I$(SDK_LIBC)/include/winsock - CFLAGS += -D_POSIX_SOURCE + INCLUDES += -I$(SDK_LIBC)/include +# INCLUDES += -I$(SDK_LIBC)/include/nks +# INCLUDES += -I$(SDK_LIBC)/include/winsock + CFLAGS += -D_POSIX_SOURCE else - INCLUDES += -I$(SDK_CLIB)/include/nlm - # INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete - # INCLUDES += -I$(SDK_CLIB)/include + INCLUDES += -I$(SDK_CLIB)/include/nlm +# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete +# INCLUDES += -I$(SDK_CLIB)/include endif -CFLAGS += $(INCLUDES) +CFLAGS += $(INCLUDES) ifeq ($(MTSAFE),YES) - XDCOPT = -n + XDCOPT = -n endif ifeq ($(MTSAFE),NO) - XDCOPT = -u + XDCOPT = -u endif ifdef XDCOPT - XDCDATA = $(OBJDIR)/$(TARGET).xdc + XDCDATA = $(OBJDIR)/$(TARGET).xdc endif vpath %.c . ../src @@ -228,8 +228,8 @@ OBJECTS += snprintf.o vpath %.c $(SNPRINTF) endif -OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS)) -OBJL = $(OBJS) $(OBJDIR)/nwlib.o $(LDLIBS) +OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS)) +OBJL = $(OBJS) $(OBJDIR)/nwlib.o $(LDLIBS) all: lib nlm diff --git a/nw/keepscreen.c b/nw/keepscreen.c index c3471b3e00..ae53dc5fee 100644 --- a/nw/keepscreen.c +++ b/nw/keepscreen.c @@ -1,25 +1,23 @@ -/* Simple _NonAppStop() implementation which can be linked to your +/* Simple _NonAppStop() implementation which can be linked to your * NLM in order to keep the screen open when the NLM terminates * (the good old clib behaviour). * You dont have to call it, its done automatically from LibC. * - * 2004-Aug-11 by Guenter Knauf + * 2004-Aug-11 by Guenter Knauf * * URL: http://www.gknw.net/development/mk_nlm/ */ - + #include #include void _NonAppStop() { uint16_t row, col; - + GetScreenSize(&row, &col); gotorowcol(row-1, 0); /* pressanykey(); */ printf(" "); getcharacter(); } - - diff --git a/nw/nwlib.c b/nw/nwlib.c index 43018e59a2..fe8377b31d 100644 --- a/nw/nwlib.c +++ b/nw/nwlib.c @@ -300,5 +300,3 @@ int main ( void ) #endif /* __NOVELL_LIBC__ */ #endif /* NETWARE */ - - diff --git a/nw/test/GNUmakefile b/nw/test/GNUmakefile index 5749a377d9..9bbd9c0968 100644 --- a/nw/test/GNUmakefile +++ b/nw/test/GNUmakefile @@ -8,7 +8,7 @@ # Edit the path below to point to the base of your Novell NDK. ifndef NDKBASE -NDKBASE = c:/novell +NDKBASE = c:/novell endif # Edit the path below to point to the base of your Zlib sources. @@ -25,18 +25,18 @@ endif LINK_STATIC = 1 # Edit the vars below to change NLM target settings. -SAMPLES = ../../example +SAMPLES = ../../example TARGETS := $(filter-out x11.nlm,$(patsubst $(SAMPLES)/%.c,%.nlm,$(strip $(wildcard $(SAMPLES)/*.c)))) -VERSION = $(LIBSSH2_VERSION) +VERSION = $(LIBSSH2_VERSION) COPYR = Copyright (c) $(LIBSSH2_COPYRIGHT_STR) -WWWURL = http://www.libssh2.org/ -DESCR = libssh2 $(notdir $(@:.def=)) $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) -MTSAFE = YES -STACK = 64000 -SCREEN = NONE -#SCREEN = libssh2 $(notdir $(@:.def=)) +WWWURL = http://www.libssh2.org/ +DESCR = libssh2 $(notdir $(@:.def=)) $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) +MTSAFE = YES +STACK = 64000 +SCREEN = NONE +#SCREEN = libssh2 $(notdir $(@:.def=)) # Comment the line below if you dont want to load protected automatically. -#LDRING = 3 +#LDRING = 3 # Edit the var below to point to your lib architecture. ifndef LIBARCH @@ -45,65 +45,65 @@ endif # must be equal to DEBUG or NDEBUG ifndef DB - DB = NDEBUG - # DB = DEBUG + DB = NDEBUG +# DB = DEBUG endif # Optimization: -O or debugging: -g ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release + OPT = -O2 + OBJDIR = release else - OPT = -g - OPT += -DLIBSSH2DEBUG - OBJDIR = debug + OPT = -g + OPT += -DLIBSSH2DEBUG + OBJDIR = debug endif # The following lines defines your compiler. ifdef CWFolder - METROWERKS = $(CWFolder) + METROWERKS = $(CWFolder) endif ifdef METROWERKS - # MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support - MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support - CC = mwccnlm +# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support + MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support + CC = mwccnlm else - CC = $(CROSSPREFIX)gcc + CC = $(CROSSPREFIX)gcc endif # Here you can find a native Win32 binary of the original awk: # http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk +AWK = awk # If you want to mark the target as MTSAFE you will need a tool for # generating the xdc data for the linker; here's a minimal tool: # http://www.gknw.net/development/prgtools/mkxdc.zip -MPKXDC = mkxdc +MPKXDC = mkxdc # Platform-dependent helper tool macros ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +#COPYR = -cp -afr $1/* $2 +COPYR = -rsync -aC $1/* $2 +TOUCH = touch $1 +CAT = cat +ECHONL = echo "" +DL = ' else ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) -endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. +DEL = -del 2>NUL $(subst /,\,$1) +RMDIR = -deltree 2>NUL /y $(subst /,\,$1) +endif +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) +COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) +TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, +CAT = type +ECHONL = $(ComSpec) /c echo. endif # LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH)) @@ -113,45 +113,45 @@ LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH)) -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS += $(OPT) -D$(DB) -DNETWARE -nostdinc +CFLAGS += $(OPT) -D$(DB) -DNETWARE -nostdinc ifeq ($(CC),mwccnlm) -LD = mwldnlm -LDFLAGS = -nostdlib $(<:.def=.o) $(PRELUDE) $(LDLIBS) -o $@ -commandfile -AR = mwldnlm -ARFLAGS = -type library -w nocmdline $(OBJS) -o -LIBEXT = lib -CFLAGS += -msgstyle gcc -gccinc -inline off -opt nointrinsics -proc 586 -CFLAGS += -relax_pointers -#CFLAGS += -w on +LD = mwldnlm +LDFLAGS = -nostdlib $(<:.def=.o) $(PRELUDE) $(LDLIBS) -o $@ -commandfile +AR = mwldnlm +ARFLAGS = -type library -w nocmdline $(OBJS) -o +LIBEXT = lib +CFLAGS += -msgstyle gcc -gccinc -inline off -opt nointrinsics -proc 586 +CFLAGS += -relax_pointers +#CFLAGS += -w on ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.o - CFLAGS += -align 4 + PRELUDE = $(SDK_LIBC)/imports/libcpre.o + CFLAGS += -align 4 else - # PRELUDE = $(SDK_CLIB)/imports/clibpre.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" - # CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" - CFLAGS += -align 1 +# PRELUDE = $(SDK_CLIB)/imports/clibpre.o + # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK + PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" +# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" + CFLAGS += -align 1 endif else -LD = nlmconv -LDFLAGS = -UT -AR = ar -ARFLAGS = -cq -LIBEXT = a -CFLAGS += -m32 -CFLAGS += -fno-builtin -fpcc-struct-return -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall # -pedantic +LD = nlmconv +LDFLAGS = -UT +AR = ar +ARFLAGS = -cq +LIBEXT = a +CFLAGS += -m32 +CFLAGS += -fno-builtin -fpcc-struct-return +CFLAGS += -fno-strict-aliasing +CFLAGS += -Wall # -pedantic ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o + PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o else - # PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - # http://www.gknw.net/development/mk_nlm/gcc_pre.zip - PRELUDE = $(NDK_ROOT)/pre/prelude.o - CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h +# PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o + # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK + # http://www.gknw.net/development/mk_nlm/gcc_pre.zip + PRELUDE = $(NDK_ROOT)/pre/prelude.o + CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h endif endif @@ -163,12 +163,12 @@ SNPRINTF = $(NDKBASE)/snprintf INCLUDES = -I.. -I../../include LDLIBS = - + ifdef LINK_STATIC - LDLIBS += ../libssh2.$(LIBEXT) + LDLIBS += ../libssh2.$(LIBEXT) else - IMPORTS += @../libssh2.imp - MODULES += libssh2.nlm + IMPORTS += @../libssh2.imp + MODULES += libssh2.nlm endif INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) @@ -177,33 +177,33 @@ LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) IMPORTS += GetProcessSwitchCount RunningProcess ifdef WITH_ZLIB - INCLUDES += -I$(ZLIB_PATH) + INCLUDES += -I$(ZLIB_PATH) ifdef LINK_STATIC - LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) + LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) else - MODULES += libz.nlm - IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp + MODULES += libz.nlm + IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp endif endif ifeq ($(LIBARCH),LIBC) - INCLUDES += -I$(SDK_LIBC)/include - # INCLUDES += -I$(SDK_LIBC)/include/nks - # INCLUDES += -I$(SDK_LIBC)/include/winsock - CFLAGS += -D_POSIX_SOURCE + INCLUDES += -I$(SDK_LIBC)/include +# INCLUDES += -I$(SDK_LIBC)/include/nks +# INCLUDES += -I$(SDK_LIBC)/include/winsock + CFLAGS += -D_POSIX_SOURCE else - INCLUDES += -I$(SDK_CLIB)/include/nlm - # INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete - # INCLUDES += -I$(SDK_CLIB)/include - # CFLAGS += -DNETDB_USE_INTERNET + INCLUDES += -I$(SDK_CLIB)/include/nlm +# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete +# INCLUDES += -I$(SDK_CLIB)/include +# CFLAGS += -DNETDB_USE_INTERNET endif -CFLAGS += $(INCLUDES) +CFLAGS += $(INCLUDES) ifeq ($(MTSAFE),YES) - XDCOPT = -n + XDCOPT = -n endif ifeq ($(MTSAFE),NO) - XDCOPT = -u + XDCOPT = -u endif vpath %.c $(SAMPLES) @@ -211,7 +211,7 @@ vpath %.c $(SAMPLES) .PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.def $(OBJDIR)/%.xdc -all: prebuild $(TARGETS) +all: prebuild $(TARGETS) prebuild: $(OBJDIR) $(OBJDIR)/version.inc diff --git a/os400/ccsid.c b/os400/ccsid.c index ef02f1d304..fdad8a6522 100644 --- a/os400/ccsid.c +++ b/os400/ccsid.c @@ -138,7 +138,7 @@ convert_ccsid(LIBSSH2_SESSION *session, libssh2_string_cache **cache, termsize = terminator_size(outccsid); if (termsize < 0) return NULL; - + /* Prepare conversion parameters. */ memset((void *) &incode, 0, sizeof incode); memset((void *) &outcode, 0, sizeof outcode); diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 9e1174197f..5de01fdb74 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -193,9 +193,9 @@ /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at runtime. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION /* Define to 1 if you have the ANSI C header files. */ diff --git a/os400/macros.h b/os400/macros.h index 408b98d010..1e809e17c9 100644 --- a/os400/macros.h +++ b/os400/macros.h @@ -116,9 +116,9 @@ libssh2_scp_send(LIBSSH2_SESSION *session, LIBSSH2_API int libssh2_publickey_add(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, - const unsigned char *blob, unsigned long blob_len, + const unsigned char *blob, unsigned long blob_len, char overwrite, unsigned long num_attrs, - const libssh2_publickey_attribute attrs[]); + const libssh2_publickey_attribute attrs[]); LIBSSH2_API int libssh2_publickey_remove(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, const unsigned char *blob, unsigned long blob_len); diff --git a/src/Makefile.am b/src/Makefile.am index 46cb88cf22..1352ab7b2b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -64,5 +64,5 @@ VERSION=-version-info 1:1:0 # libssh2_la_LDFLAGS = $(VERSION) -no-undefined \ - -export-symbols-regex '^libssh2_.*' \ - $(CRYPTO_LTLIBS) $(LTLIBZ) + -export-symbols-regex '^libssh2_.*' \ + $(CRYPTO_LTLIBS) $(LTLIBZ) diff --git a/tests/Makefile.am b/tests/Makefile.am index e321dfc82f..b27fb27990 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,9 +39,10 @@ INTEGRATION_TESTS = \ # Enable this once the tests are working #TESTS += $(INTEGRATION_TESTS) check_PROGRAMS += $(INTEGRATION_TESTS) -librunner_la_SOURCES = runner.c runner.h \ - session_fixture.c session_fixture.h \ - openssh_fixture.c openssh_fixture.h +librunner_la_SOURCES = \ + runner.c runner.h \ + session_fixture.c session_fixture.h \ + openssh_fixture.c openssh_fixture.h LDADD = librunner.la check_LTLIBRARIES = librunner.la @@ -55,62 +56,62 @@ LDADD += ../src/libssh2.la TESTS_ENVIRONMENT = SSHD=$(SSHD) EXEEXT=$(EXEEXT) TESTS_ENVIRONMENT += srcdir=$(top_srcdir)/tests builddir=$(top_builddir)/tests -EXTRA_DIST = \ - CMakeLists.txt \ - etc/host \ - etc/host.pub \ - etc/sshd_config \ - etc/user \ - etc/user.pub \ - key_dsa \ - key_dsa.pub \ - key_dsa_wrong \ - key_dsa_wrong.pub \ - key_ecdsa \ - key_ecdsa.pub \ - signed_key_ecdsa \ - signed_key_ecdsa.pub \ - signed_key_ecdsa-cert.pub \ - signed_key_rsa \ - signed_key_rsa-cert.pub \ - signed_key_rsa.pub \ - key_ed25519 \ - key_ed25519.pub \ - key_ed25519_encrypted \ - key_ed25519_encrypted.pub \ - key_rsa \ - key_rsa.pub \ - key_rsa_encrypted \ - key_rsa_encrypted.pub \ - key_rsa_openssh \ - key_rsa_openssh.pub \ - libssh2_config_cmake.h.in \ - mansyntax.sh \ - openssh_server/Dockerfile \ - openssh_server/authorized_keys \ - openssh_server/ca_rsa \ - openssh_server/ca_rsa.pub \ - openssh_server/ca_ecdsa \ - openssh_server/ca_ecdsa.pub \ - openssh_server/ssh_host_ecdsa_key \ - openssh_server/ssh_host_ed25519_key \ - openssh_server/ssh_host_rsa_key \ - simple.c \ - sshdwrap \ - ssh2.c \ - ssh2.sh \ - sshd_fixture.sh.in \ - test_read_3des-cbc \ - test_read_aes128-cbc \ - test_read_aes128-ctr \ - test_read_aes192-cbc \ - test_read_aes192-ctr \ - test_read_aes256-cbc \ - test_read_aes256-ctr \ - test_read_hmac-md5 \ - test_read_hmac-md5-96 \ - test_read_hmac-sha1 \ - test_read_hmac-sha1-96 \ - test_read_hmac-sha2-256 \ - test_read_hmac-sha2-512 \ - test_read_rijndael-cbc +EXTRA_DIST = \ + CMakeLists.txt \ + etc/host \ + etc/host.pub \ + etc/sshd_config \ + etc/user \ + etc/user.pub \ + key_dsa \ + key_dsa.pub \ + key_dsa_wrong \ + key_dsa_wrong.pub \ + key_ecdsa \ + key_ecdsa.pub \ + signed_key_ecdsa \ + signed_key_ecdsa.pub \ + signed_key_ecdsa-cert.pub \ + signed_key_rsa \ + signed_key_rsa-cert.pub \ + signed_key_rsa.pub \ + key_ed25519 \ + key_ed25519.pub \ + key_ed25519_encrypted \ + key_ed25519_encrypted.pub \ + key_rsa \ + key_rsa.pub \ + key_rsa_encrypted \ + key_rsa_encrypted.pub \ + key_rsa_openssh \ + key_rsa_openssh.pub \ + libssh2_config_cmake.h.in \ + mansyntax.sh \ + openssh_server/Dockerfile \ + openssh_server/authorized_keys \ + openssh_server/ca_rsa \ + openssh_server/ca_rsa.pub \ + openssh_server/ca_ecdsa \ + openssh_server/ca_ecdsa.pub \ + openssh_server/ssh_host_ecdsa_key \ + openssh_server/ssh_host_ed25519_key \ + openssh_server/ssh_host_rsa_key \ + simple.c \ + sshdwrap \ + ssh2.c \ + ssh2.sh \ + sshd_fixture.sh.in \ + test_read_3des-cbc \ + test_read_aes128-cbc \ + test_read_aes128-ctr \ + test_read_aes192-cbc \ + test_read_aes192-ctr \ + test_read_aes256-cbc \ + test_read_aes256-ctr \ + test_read_hmac-md5 \ + test_read_hmac-md5-96 \ + test_read_hmac-sha1 \ + test_read_hmac-sha1-96 \ + test_read_hmac-sha2-256 \ + test_read_hmac-sha2-512 \ + test_read_rijndael-cbc diff --git a/tests/ossfuzz/Makefile.am b/tests/ossfuzz/Makefile.am index 9b621be84e..b58c84cf06 100644 --- a/tests/ossfuzz/Makefile.am +++ b/tests/ossfuzz/Makefile.am @@ -18,10 +18,10 @@ noinst_LIBRARIES = if USE_OSSFUZZERS noinst_PROGRAMS += \ - ssh2_client_fuzzer + ssh2_client_fuzzer noinst_LIBRARIES += \ - libstandaloneengine.a + libstandaloneengine.a endif ssh2_client_fuzzer_SOURCES = ssh2_client_fuzzer.cc testinput.h diff --git a/vms/libssh2_config.h b/vms/libssh2_config.h index 8cbee62dcf..94c81e0171 100644 --- a/vms/libssh2_config.h +++ b/vms/libssh2_config.h @@ -8,7 +8,7 @@ #define ssize_t SSIZE_T -typedef unsigned int uint32_t ; +typedef unsigned int uint32_t; typedef unsigned int socklen_t; /* missing in headers on VMS */ /* Have's */ @@ -30,7 +30,7 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ #define POSIX_C_SOURCE /* Enable the possibility of using tracing */ - + #define LIBSSH2DEBUG 1 /* For selection of proper block/unblock function in session.c */ @@ -39,23 +39,23 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ #include -/* In VMS TCP/IP Services and some BSD variants SO_STATE retrieves - * a bitmask revealing amongst others the blocking state of the +/* In VMS TCP/IP Services and some BSD variants SO_STATE retrieves + * a bitmask revealing amongst others the blocking state of the * socket. On VMS the bits are undocumented, but SS_NBIO - * works, I did not test the other bits. Below bitdefs are - * from Berkely source socketvar.h at + * works, I did not test the other bits. Below bitdefs are + * from Berkely source socketvar.h at * http://ftp.fibranet.cat/UnixArchive/PDP-11/Trees/2.11BSD/sys/h/socketvar.h * Socket state bits. - * #define SS_NOFDREF 0x001 no file table ref any more - * #define SS_ISCONNECTED 0x002 socket connected to a peer - * #define SS_ISCONNECTING 0x004 in process of connecting to peer - * #define SS_ISDISCONNECTING 0x008 in process of disconnecting - * #define SS_CANTSENDMORE 0x010 can't send more data to peer - * #define SS_CANTRCVMORE 0x020 can't receive more data from peer - * #define SS_RCVATMARK 0x040 at mark on input - * #define SS_PRIV 0x080 privileged for broadcast, raw... - * #define SS_NBIO 0x100 non-blocking ops - * #define SS_ASYNC 0x200 async i/o notify + * #define SS_NOFDREF 0x001 no file table ref any more + * #define SS_ISCONNECTED 0x002 socket connected to a peer + * #define SS_ISCONNECTING 0x004 in process of connecting to peer + * #define SS_ISDISCONNECTING 0x008 in process of disconnecting + * #define SS_CANTSENDMORE 0x010 can't send more data to peer + * #define SS_CANTRCVMORE 0x020 can't receive more data from peer + * #define SS_RCVATMARK 0x040 at mark on input + * #define SS_PRIV 0x080 privileged for broadcast, raw... + * #define SS_NBIO 0x100 non-blocking ops + * #define SS_ASYNC 0x200 async i/o notify * */ @@ -65,10 +65,10 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ * When running on Multinet, SO_STATE renders a protocol * not started error. Functionally this has no impact, * apart from libssh2 not being able to restore the socket - * to the proper blocking/non-blocking state. + * to the proper blocking/non-blocking state. */ -#define SS_NBIO 0x100 +#define SS_NBIO 0x100 #endif @@ -82,4 +82,4 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ #define LIBSSH2_HAVE_ZLIB #endif /* __VMS */ -#endif /* LIBSSH2_CONFIG_H */ +#endif /* LIBSSH2_CONFIG_H */ diff --git a/vms/libssh2_make_example.dcl b/vms/libssh2_make_example.dcl index af4116dd56..17e7196201 100644 --- a/vms/libssh2_make_example.dcl +++ b/vms/libssh2_make_example.dcl @@ -8,9 +8,9 @@ $ if .not. init_status then goto YExit $! $ if what .eqs. "ALL" $ then -$ call MakeAll +$ call MakeAll $ else -$ call Make +$ call Make $endif $! $YExit: @@ -19,7 +19,7 @@ $! deassign exadir $! deassign objdir $ delete 'link_opts';* $ set default 'olddir' -$exit +$exit $MakeAll: subroutine $! @@ -45,14 +45,14 @@ $ set noon $! $ cc 'cc_include' 'cc_flags'/object=objdir:'what' exadir:'what' $ sev = $severity -$ if sev .and. 2 +$ if sev .and. 2 $ then -$ say "Error compiling ''what', not linked." +$ say "Error compiling ''what', not linked." $ else -$ if .not. (sev .and. 1) -$ then -$ say "Compile warnings in ''what'" -$ endif +$ if .not. (sev .and. 1) +$ then +$ say "Compile warnings in ''what'" +$ endif $ link/exe='what'.exe objdir:'what'.obj, 'link_opts'/opt $ endif $! @@ -60,15 +60,15 @@ $! $End: $ delete objdir:'what'.obj;* $exit -$endsubroutine +$endsubroutine -$Init: +$Init: $! $! $ init_status = 1 $ thisid = f$integer( %x'f$getjpi(0,"pid")') + "''f$cvtime(,,"second")'" -$ mdir = f$environment("procedure") +$ mdir = f$environment("procedure") $ mdir = mdir - f$parse(mdir,,,"name") - f$parse(mdir,,,"type") - f$parse(mdir,,,"version") $ set default 'mdir' $! @@ -78,7 +78,7 @@ $! $ objdirfile = objdir - "[." - "]" + ".dir" $ if f$search( objdirfile ) .eqs. "" $ then -$ create/directory 'objdir' +$ create/directory 'objdir' $ endif $! $ define objdir 'objdir' @@ -89,17 +89,17 @@ $ cc_flags = "/name=shortened/show=all/define=(_USE_STD_STAT=1)" $ link_opts = "objdir:libssh2_''thisid'.opt" $! $! -$ what = "''p1'" -$ if what .eqs. "" .or. f$edit(p1,"trim,collapse,upcase") .eqs. "ALL" -$ then -$ what = "ALL" +$ what = "''p1'" +$ if what .eqs. "" .or. f$edit(p1,"trim,collapse,upcase") .eqs. "ALL" +$ then +$ what = "ALL" $ else -$ what = f$parse(what,,,"name") -$ if f$search("exadir:''what'.c") .eqs. "" -$ then -$ write sys$output "Can't make ''what'" -$ init_status = 0 -$ endif +$ what = f$parse(what,,,"name") +$ if f$search("exadir:''what'.c") .eqs. "" +$ then +$ write sys$output "Can't make ''what'" +$ init_status = 0 +$ endif $ endif $! $ currentlib = f$search("libssh2*.exe") @@ -107,19 +107,19 @@ $! $ define libssh2 'currentlib' $! $ how = "''p2'" -$ if how .eqs. "" .or. f$edit(p2,"trim,collapse,upcase") .eqs. "STATIC" +$ if how .eqs. "" .or. f$edit(p2,"trim,collapse,upcase") .eqs. "STATIC" $ then -$ open/write lout 'link_opts' -$ write lout "libssh2.olb/lib" -$ write lout "sys$share:ssl$libcrypto_shr32.exe/share" -$ write lout "sys$share:ssl$libssl_shr32.exe/share" -$ write lout "gnv$libzshr/share" -$ close lout +$ open/write lout 'link_opts' +$ write lout "libssh2.olb/lib" +$ write lout "sys$share:ssl$libcrypto_shr32.exe/share" +$ write lout "sys$share:ssl$libssl_shr32.exe/share" +$ write lout "gnv$libzshr/share" +$ close lout $ else -$ how = "SHARED" -$ open/write lout 'link_opts' -$ write lout "libssh2/share" -$ close lout -$ endif +$ how = "SHARED" +$ open/write lout 'link_opts' +$ write lout "libssh2/share" +$ close lout +$ endif $! $return diff --git a/vms/libssh2_make_kit.dcl b/vms/libssh2_make_kit.dcl index 6a14958806..738187e1b3 100644 --- a/vms/libssh2_make_kit.dcl +++ b/vms/libssh2_make_kit.dcl @@ -22,24 +22,24 @@ $! $ set default [-] $! $ defdir = f$environment( "default" ) -$ thisdev = f$parse(defdir,,,"device","no_conceal") +$ thisdev = f$parse(defdir,,,"device","no_conceal") $ thisdir = f$parse(defdir,,,"directory","no_conceal") - "][" - "][" - "][" - "][" $! -$ libssh2_kf = thisdev + thisdir +$ libssh2_kf = thisdev + thisdir $ libssh2_kf = libssh2_kf - "]" + ".]" $! $ set default 'mdir' $! $ define/translation_attributes=concealed libssh2_kf 'libssh2_kf' $! -$ product package libssh2 - - /base='arch' - +$ product package libssh2 - + /base='arch' - /producer=jcb - - /source=[] - ! where to find PDF and PTF - /destination=[] - ! where to put .PCSI file - /material=libssh2_kf:[000000...] - ! where to find product material + /source=[] - ! where to find PDF and PTF + /destination=[] - ! where to put .PCSI file + /material=libssh2_kf:[000000...] - ! where to find product material /version="''vms_majorv'.''minorv'-''patchv'''datename'" - - /format=sequential + /format=sequential $! $End: $! @@ -52,7 +52,7 @@ $! $ if f$trnlnm("libssh2_kf") .nes. "" then deassign libssh2_kf $ set default 'olddir' $! -$exit +$exit $! $!-------------------------------------------------------------------------------- $! @@ -61,20 +61,20 @@ $ set process/parse=extended $! $ say = "write sys$output" $! -$ mdir = f$environment("procedure") +$ mdir = f$environment("procedure") $ mdir = mdir - f$parse(mdir,,,"name") - f$parse(mdir,,,"type") - f$parse(mdir,,,"version") $! $ set default 'mdir' $! -$ pipe search [-.include]*.h libssh2_version_major/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - +$ pipe search [-.include]*.h libssh2_version_major/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - define/job majorv &l ) -$ pipe search [-.include]*.h libssh2_version_minor/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - +$ pipe search [-.include]*.h libssh2_version_minor/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - define/job minorv &l ) -$ pipe search [-.include]*.h libssh2_version_patch/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - +$ pipe search [-.include]*.h libssh2_version_patch/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - define/job patchv &l ) $! $ majorv = f$trnlnm("majorv") -$ minorv = f$integer(f$trnlnm("minorv")) +$ minorv = f$integer(f$trnlnm("minorv")) $ patchv = f$integer( f$trnlnm("patchv")) $! $ deassign/job majorv @@ -106,10 +106,10 @@ $ then $ daily = "FALSE" $ datename = "Final" $ else -$ datename = "D" + f$extract(seconddash+1,8,restdir) +$ datename = "D" + f$extract(seconddash+1,8,restdir) $ endif $! -$ if daily +$ if daily $ then $ productname = "JCB ''arch' LIBSSH2 V''vms_majorv'.''minorv'-''patchv'''datename'" $ else @@ -176,7 +176,7 @@ $ write pd " file ""[gnv.usr.share.doc.libssh2]libssh2-''versionname'.release $ write pd " file ""[gnv.usr.lib]gnv$libssh2_''versionname'.exe"" source ""[vms]libssh2_''versionname'.exe"";" $ write pd "end product ;" $ close pd -$exit +$exit $endsubroutine $! $!-------------------------------------------------------------------------------- @@ -219,4 +219,3 @@ $ write pt "[gnv.common_src]libssh2_''versionname'''datename'_src.bck" $close pt $exit $ endsubroutine - diff --git a/vms/libssh2_make_lib.dcl b/vms/libssh2_make_lib.dcl index 56d168f21c..a763445e5b 100644 --- a/vms/libssh2_make_lib.dcl +++ b/vms/libssh2_make_lib.dcl @@ -21,16 +21,16 @@ $ deassign objdir $ delete library_objects.dir;* $! $ set default 'olddir' -$exit +$exit $! $!--------------------------------------------------------------------- $! -$Init: +$Init: $! $! $ init_status = 1 -$ thisid = f$integer( %x'f$getjpi(0,"pid")') -$ mdir = f$environment("procedure") +$ thisid = f$integer( %x'f$getjpi(0,"pid")') +$ mdir = f$environment("procedure") $ mdir = mdir - f$parse(mdir,,,"name") - f$parse(mdir,,,"type") - f$parse(mdir,,,"version") $ set default 'mdir' $! @@ -50,15 +50,15 @@ $ cc_include = "/include=([],[-.include],""/gnv$zlib_include"")" $ cc_define = "/DEFINE=(_USE_STD_STAT=1)" $ link_opts = "objdir:libssh2_''thisid'.opt" $! -$ pipe search [-.include]libssh2.h libssh2_version_major/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - +$ pipe search [-.include]libssh2.h libssh2_version_major/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - define/job majorv &l ) -$ pipe search [-.include]libssh2.h libssh2_version_minor/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - +$ pipe search [-.include]libssh2.h libssh2_version_minor/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - define/job minorv &l ) -$ pipe search [-.include]libssh2.h libssh2_version_patch/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - +$ pipe search [-.include]libssh2.h libssh2_version_patch/nohead | (read sys$input l ; l = f$element(2," ",f$edit(l,"trim,compress")) ; - define/job patchv &l ) $! $ majorv = f$trnlnm("majorv") -$ minorv = f$integer(f$trnlnm("minorv")) +$ minorv = f$integer(f$trnlnm("minorv")) $ patchv = f$integer( f$trnlnm("patchv")) $! $ OLBONLY = "FALSE" @@ -81,7 +81,7 @@ $ set noon $ purge *.opt $ purge *.olb $ purge *.exe -$! +$! $exit 1 $endsubroutine $! @@ -103,7 +103,7 @@ $ write uitv "sys$share:ssl$libcrypto_shr32.exe/share" $ write uitv "sys$share:ssl$libssl_shr32.exe/share" $ write uitv "gnv$libzshr/share" $ close uitv -$! +$! $ link/shared/exe=libssh2_'majorv'_'minorv'_'patchv'.exe - libssh2.olb/lib, - link_libssh2_version_'majorv'_'minorv'_'patchv'.opt/opt, - @@ -118,12 +118,12 @@ $CompileAll: subroutine $! $ set noon $! -$ if f$search("objdir:*.obj;*") .nes "" -$ then +$ if f$search("objdir:*.obj;*") .nes "" +$ then $ delete objdir:*.obj;* $ endif -$ if f$search("[.cxx_repository]cxx$demangler_db.;") .nes "" -$ then +$ if f$search("[.cxx_repository]cxx$demangler_db.;") .nes "" +$ then $ delete [.cxx_repository]cxx$demangler_db.;* $ endif $! @@ -136,16 +136,16 @@ $ case = 0 $ if OLBONLY then case = 1 $CaseLoop: $! -$ if case .eq. 0 -$ then!camel case names +$ if case .eq. 0 +$ then!camel case names $ cc_flags = "/names=(shortened,as_is)''cc_define'" $ objlib = "libssh2_asis.olb" $ endif $! -$ if case .eq. 1 -$ then!uppercase names -$ if f$search("[.cxx_repository]cxx$demangler_db.;") .nes "" -$ then +$ if case .eq. 1 +$ then!uppercase names +$ if f$search("[.cxx_repository]cxx$demangler_db.;") .nes "" +$ then $ rename [.cxx_repository]cxx$demangler_db.; *.lowercase $ purge [.cxx_repository]cxx$demangler_db.lowercase $ endif @@ -172,8 +172,8 @@ $ delete objdir:*.obj;* $ if case .lt 2 then goto CaseLoop $! $ rename libssh2_up.olb libssh2.olb -$ if f$search("[.cxx_repository]cxx$demangler_db.;") .nes "" -$ then +$ if f$search("[.cxx_repository]cxx$demangler_db.;") .nes "" +$ then $ rename [.cxx_repository]cxx$demangler_db.; *.uppercase $ purge [.cxx_repository]cxx$demangler_db.uppercase $ endif @@ -182,10 +182,10 @@ $ if OLBONLY then exit 4 $! $! For each function that is too long, create a global symbol $! low$'shortened-uppercase-name' with as value lowercase shortened -$! name in it, so we can add the proper lower or mixed case -$! shortened name later when building the transfer vectors +$! name in it, so we can add the proper lower or mixed case +$! shortened name later when building the transfer vectors $! for the shared image. -$! This is to prevent two very long similar function names +$! This is to prevent two very long similar function names $! that are shortened getting mixed up when sorted alphabetically. $! $ inputfile = "[.cxx_repository]cxx$demangler_db.lowercase" @@ -211,7 +211,7 @@ $ symvalue = "" $! $ if shortname .eqs. f$edit(shortname,"upcase") $ then -$! this is an uppercase shortname, add it +$! this is an uppercase shortname, add it $ symname = "u$''longname'" $ symvalue = "''shortname'" $ low$'shortname' == l$'longname' @@ -246,7 +246,7 @@ $ library/insert 'objlib' objdir:'what'.obj $! $End: $exit -$endsubroutine +$endsubroutine $! $!--------------------------------------------------------------------- $! @@ -254,7 +254,7 @@ $BuildTransferVectors: subroutine $! $! Do a balanced read of the uppercase library names $! and the mixed case library names, and build the -$! transfer vectors with uppercase entry points +$! transfer vectors with uppercase entry points $! with an alternative in mixed case. $! For shortened names, use the low$* symbols $! to avoid being fooled by the sort. @@ -267,9 +267,9 @@ $! case blind sort of all modules in both the uppercase $! as the case sensitive object library. $! $ sort libu.'thisid' lib.'thisid'/spec=sys$input -/COLLATING_SEQUENCE=(SEQUENCE= ("A" - "Z","0"-"9","_"), FOLD) +/COLLATING_SEQUENCE=(SEQUENCE= ("A" - "Z","0"-"9","_"), FOLD) $ sort lib_asisu.'thisid' lib_asis.'thisid'/spec=sys$input -/COLLATING_SEQUENCE=(SEQUENCE= ("A" - "Z","0"-"9","_"), FOLD) +/COLLATING_SEQUENCE=(SEQUENCE= ("A" - "Z","0"-"9","_"), FOLD) $! $ open/read in lib.'thisid' $ open/read inasis lib_asis.'thisid' @@ -300,12 +300,12 @@ $ endif $! $ if uitregel .nes. "" .and. mode .eq. 1 $ then -$ write uit "''uitregel'=PROCEDURE, -" -$ write uit "''uitasis'/''uitregel'=PROCEDURE, -" +$ write uit "''uitregel'=PROCEDURE, -" +$ write uit "''uitasis'/''uitregel'=PROCEDURE, -" $! $ uitregel = "" $ uitasis = "" -$ endif +$ endif $! $ uitregel = regel $ if f$type( low$'uitregel' ) .nes. "" @@ -320,14 +320,14 @@ $ mode = 1 $! $ goto ReadLoop $EndreadLoop: -$! +$! $! To get the closing brace after the last procedure $! keyword. $! $ if uitregel .nes. "" -$ then -$ write uit "''uitregel'=PROCEDURE, -" -$ write uit "''uitasis'/''uitregel'=PROCEDURE)" +$ then +$ write uit "''uitregel'=PROCEDURE, -" +$ write uit "''uitasis'/''uitregel'=PROCEDURE)" $ endif $! $ write uit "CASE_SENSITIVE=NO" diff --git a/vms/man2help.c b/vms/man2help.c index 92e5f2b941..71f125849b 100644 --- a/vms/man2help.c +++ b/vms/man2help.c @@ -14,12 +14,12 @@ typedef struct manl{ struct manl *next; char *filename; }man, *manPtr; - + typedef struct pf_fabnam{ struct FAB dfab; struct RAB drab; struct namldef dnam; - char expanded_filename[NAM$C_MAXRSS + 1]; + char expanded_filename[NAM$C_MAXRSS + 1]; } pfn, *pfnPtr; /*----------------------------------------------------------*/ @@ -37,13 +37,13 @@ if ( len ){ }else{ output[0] = 0; } -} +} /*----------------------------------------------------------*/ /* give part of ilename in partname. See code for proper value of i ( 0 = node, 1 = dev, 2 = dir,3 = name etc. -*/ +*/ int fnamepart( char *inputfile, char *part, int whatpart ) { @@ -59,8 +59,8 @@ pf->dnam = cc$rms_naml; pf->dfab.fab$l_naml = &pf->dnam; -pf->dfab.fab$l_fna = (char *) -1; -pf->dfab.fab$l_dna = (char *) -1; +pf->dfab.fab$l_fna = (char *) -1; +pf->dfab.fab$l_dna = (char *) -1; pf->dfab.fab$b_fns = 0; pf->dfab.fab$w_ifi = 0; @@ -85,7 +85,7 @@ fpcopy ( ipart[0], pf->dnam.naml$l_long_node , pf->dnam.naml$l_long_node_size); fpcopy ( ipart[1], pf->dnam.naml$l_long_dev , pf->dnam.naml$l_long_dev_size); fpcopy ( ipart[2], pf->dnam.naml$l_long_dir , pf->dnam.naml$l_long_dir_size); fpcopy ( ipart[3], pf->dnam.naml$l_long_name , pf->dnam.naml$l_long_name_size); -fpcopy ( ipart[4], pf->dnam.naml$l_long_type , pf->dnam.naml$l_long_type_size); +fpcopy ( ipart[4], pf->dnam.naml$l_long_type , pf->dnam.naml$l_long_type_size); fpcopy ( ipart[5], pf->dnam.naml$l_long_ver , pf->dnam.naml$l_long_ver_size); for( i = ipart[ whatpart ], p = part; *i; ++i, ++p){ @@ -93,7 +93,7 @@ for( i = ipart[ whatpart ], p = part; *i; ++i, ++p){ *p = toupper( *i ); }else{ *p = tolower( *i ); - } + } } *p = 0; @@ -111,16 +111,16 @@ char gevonden_file[NAM$C_MAXRSS + 1]; filespec.dsc$w_length = strlen(filename); filespec.dsc$b_dtype = DSC$K_DTYPE_T; -filespec.dsc$b_class = DSC$K_CLASS_S; +filespec.dsc$b_class = DSC$K_CLASS_S; filespec.dsc$a_pointer = filename; gevondend.dsc$w_length = NAM$C_MAXRSS; gevondend.dsc$b_dtype = DSC$K_DTYPE_T; -gevondend.dsc$b_class = DSC$K_CLASS_S; +gevondend.dsc$b_class = DSC$K_CLASS_S; gevondend.dsc$a_pointer = gevonden_file; status=lib$find_file(&filespec,&gevondend,findex,0,0,0,0); - + if ( (status & 1) == 1 ){ strcpy(gevonden,strtok(gevonden_file," ")); }else{ @@ -143,7 +143,7 @@ if ( !m ) return( NULL ); m->filename = strdup( filename ); if ( *manroot == NULL ){ - *manroot = m; + *manroot = m; }else{ for( f = *manroot; f->next ; f = f->next ); f->next = m; @@ -259,10 +259,10 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ mode = 0; break; case 'B': - ++m; + ++m; *h = ' ';++h; mode = 0; - break; + break; case 'I': /* remove preceding eol */ if ( *(m+1) != 'P' ){ @@ -272,7 +272,7 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ } /* skip .Ix */ - for(;*m != ' ' && *m != '\n' && *m != '\r'; ++m); + for(;*m != ' ' && *m != '\n' && *m != '\r'; ++m); /* copy line up to EOL */ @@ -281,7 +281,7 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ /* if line ends in ., this is an EOL */ if ( *(h-1) == '.'){ - --h; + --h; --m; }else{ /* if line does not end in ., skip EOL in source */ @@ -293,7 +293,7 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ case 'S': if ( *(m+1) == 'H' ){ *h = '\n';++h; - if ( strncmp( m+3 ,"NAME",4) == 0 || + if ( strncmp( m+3 ,"NAME",4) == 0 || strncmp( m+3 ,"SYNOPSIS",8) == 0 || strncmp( m+3 ,"DESCRIPTION",11) == 0 ){ while( *m != '\n' && *m != '\r')++m; @@ -306,7 +306,7 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ *h = '0' + base_level + 1;++h; return_status |= 2; - *h = ' ';++h; + *h = ' ';++h; /* skip H (or whatever after S) and blank */ ++m;++m; @@ -318,11 +318,11 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ if ( *m != '\"' ){ *h = tolower( *m ); - if (*h == ' ') *h = '_'; + if (*h == ' ') *h = '_'; }else{ --h; - } - } + } + } /* Add a linefeed or two */ @@ -330,7 +330,7 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ *h = *m;++h; mode = 0; - } + } } break; case 'T': @@ -341,10 +341,10 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ for ( m = m + 3; *m != ' ' && *m ; ++m, ++h ){ *h = *m; } - if ( add_parentheses ){ - *h = '(';++h; - *h = ')';++h; - } + if ( add_parentheses ){ + *h = '(';++h; + *h = ')';++h; + } while( *m != '\n' && *m != '\r' && *m )++m; mode = 0; } @@ -355,7 +355,7 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ break; } break; - case 2: /* after \ skip two characters or print the backslash */ + case 2: /* after \ skip two characters or print the backslash */ switch(*m){ case '\\': *h = *m; @@ -367,7 +367,7 @@ for ( mode = 0, bol = 1 ; *m; ++m ){ mode = 0; break; } - break; + break; } /*end switch mode */ bol = 0; @@ -401,8 +401,8 @@ if ( (return_status&2) ){ len, filespec, strlen(uit), return_status ); */ -free( m ); -free( h ); +free( m ); +free( h ); return ( 1); } @@ -474,7 +474,7 @@ for ( i = 1; i < argc; ++i){ case 'a': append = 1; break; - case 'b': + case 'b': if ( (i+1) < argc ){ base_level = atoi( argv[ i + 1 ] ); basechange = 1; @@ -512,5 +512,3 @@ free( helpfile ); return( status ); } - - diff --git a/vms/readme.vms b/vms/readme.vms index 978da1974f..e38af16374 100644 --- a/vms/readme.vms +++ b/vms/readme.vms @@ -1,13 +1,13 @@ *These are the porting notes to OpenVMS, as of 7 April 2010 -by Jose Baars. This file will be installed as +by Jose Baars. This file will be installed as libssh2*.release_notes by the product install kit. -LIBSSH2 +LIBSSH2 ------- -LIBSSH2 is a client-side library written in C that aims to -implement the SSH2 protocol. It is an open source project, +LIBSSH2 is a client-side library written in C that aims to +implement the SSH2 protocol. It is an open source project, to be found at https://libssh2.org. GNV @@ -19,44 +19,44 @@ of the GNV project, John Malmberg. Installing the PCSI kit ======================= -Prerequisites +Prerequisites ------------- -- VMS version 8.3 minimal. +- VMS version 8.3 minimal. See the remarks at prerequisites for building the kit -- TCP/IP stack, both TCP/IP services and Multinet should work. +- TCP/IP stack, both TCP/IP services and Multinet should work. See the remarks at prerequisites for building the kit -- HP OPENSSL V1.3 minimal. +- HP OPENSSL V1.3 minimal. See the remarks at prerequisites for building the kit -- JEM ZLIB V1.2-3E1 minimal. +- JEM ZLIB V1.2-3E1 minimal. See the remarks at prerequisites for building the kit - -The first three dependencies are tested at installation time, and + +The first three dependencies are tested at installation time, and installation will fail if any these products are not installed. The ZLIB dependency is not tested by the product installation -procedure, as libssh2 will probably be installed as part of +procedure, as libssh2 will probably be installed as part of multiple libraries including zlib. Install ------- -The kit will install gnv$libssh2.exe in a directory tree that might -already be available on your system if you have installed other gnv* -libraries or utilities. +The kit will install gnv$libssh2.exe in a directory tree that might +already be available on your system if you have installed other gnv* +libraries or utilities. The directory tree for gnv$libssh2.exe will be like this: [gnv] -- [usr] -- [include] -- [libssh2] include files for libssh2 [lib] gnv$libssh2_x_y_z.exe - [share] -- [doc] -- [libssh2] libssh2.hlb, - release notes (this file), - libssh2 release notes + [share] -- [doc] -- [libssh2] libssh2.hlb, + release notes (this file), + libssh2 release notes optional: - [example] libssh2_examples-x_y_z.bck + [example] libssh2_examples-x_y_z.bck [common_src] libssh2-x_y_z_src.bck -By default, it will install the shared image and include files to +By default, it will install the shared image and include files to SYS$COMMON:[GNV...]. You can override this destination by specifying the destination @@ -71,9 +71,9 @@ Please ignore the following warnings, as the kit is not signed : Optionally, you can install a backup saveset with some programming examples, or a backupo saveset with the complete libssh2 source tree. - -you will need to answer 'NO' to the question -'Do you want the default for all options'. + +you will need to answer 'NO' to the question +'Do you want the default for all options'. and 'YES' to either or both the following questions: @@ -99,34 +99,34 @@ Optionally, you can install the executbale like so: $ mc sysgen install dev:[dir..]gnv$libssh2_x_y_z.exe/open/share/header -Link your programs against gnv$libssh2, and when upgrading libssh2 +Link your programs against gnv$libssh2, and when upgrading libssh2 test thoroughly. If you want to be extra cautious define a system logical like this: $ define/system/executive gnv$libssh2_x_y_z dev:[dir..]gnv$libssh2_x_y_z.exe -Link programs against gnv$libssh2_x_y_z, and when upgrading libssh2 -link against new versions. +Link programs against gnv$libssh2_x_y_z, and when upgrading libssh2 +link against new versions. -It is probably more convenient in the last case to link against the object +It is probably more convenient in the last case to link against the object library provided in the source backup saveset. Both an uppercase and a -mixed case object library, called libssh2.olb and libssh2_asis.olb +mixed case object library, called libssh2.olb and libssh2_asis.olb are provided. Compiling and linking against libssh2 ------------------------------------- -The shared image library has a vector table with both uppercase and -mixed case entry points, allowing to link directly against the shared +The shared image library has a vector table with both uppercase and +mixed case entry points, allowing to link directly against the shared image wether you need the /NAMES=AS_IS or not. To link successfully, you MUST use /NAMES=shortened, as some function names in libssh2 are longer than the VMS maximum of 32 characters. If you chose to install the examples, you can unpack the backup -saveset by +saveset by backup/sel=*.c device:[gnv.usr.share.doc.libssh2.examples]libssh2_examples-x_y_z.bck - [] @@ -147,7 +147,7 @@ Building gnv$libssh2 You can build gnv$libssh2 yourself, which may have advantages, as the library is in full development, very regularly new features are added. -For production use, it is probably advisable to use a stable version, and +For production use, it is probably advisable to use a stable version, and link against that. To check out new features, statically linking against the object library is probably more practical, to avoid compatibility issues. @@ -161,21 +161,21 @@ You will need to have the following available: - An Alpha or Itanium VMS system. Due to dependencies on zlib, ssl and ODS-5, support on VAXen would be cumbersome at least. -- VMS version 8.3 minimal. This is a requirement of gnv$zlibshr.exe against +- VMS version 8.3 minimal. This is a requirement of gnv$zlibshr.exe against which shared image library libssh2 is linked. If you use another zlib to link against, you can make it work under lower versions of VMS. I have made it work on VMS 7.3-2 with not a lot of difficulty. Also, if you are not interested in compression, you can choose not - to link against zlib at all; in that case comment out the + to link against zlib at all; in that case comment out the #define LIBSSH2_HAVE_ZLIB in libssh2_config.h. - TCP/IP services or Multinet for OpenVMS. TCPWare has not been tested. -- The HP OpenSSL product. Of course, with tweaking, you can probably link +- The HP OpenSSL product. Of course, with tweaking, you can probably link it against the OpenSSL library, but that is not what I have used. - -- A C compiler. I don't know any other working C compilers than + +- A C compiler. I don't know any other working C compilers than the DEC/Compac/HP-C compiler on VMS. - An ODS-5 disk. With tweaking you'll get it to work on an ODS-2 @@ -199,7 +199,7 @@ Downloading libssh2 ------------------- At the website of libssh2, you can find stable and daily gzipped -tarballs. if you have a computer connected to internet you can +tarballs. if you have a computer connected to internet you can download a daily build yourself by a procedure that looks a lot like this ( fill out your own proxy user/password, set up right symbols to gunzip, vmstar and curl and set up the libssh2 build version): @@ -212,8 +212,8 @@ $ currentday = f$cvtime(,,"date") - "-" - "-" $! $ set def mydev:[mydir.libssh2] $! -$ if f$search("libssh2-''libssh2_version'-''currentday'.tar.gz") .nes. "" -$ then +$ if f$search("libssh2-''libssh2_version'-''currentday'.tar.gz") .nes. "" +$ then $ delete libssh2-'libssh2_version'-'currentday'.tar.gz;* $ endif $! @@ -221,15 +221,15 @@ $ curl 'proxy_line' "https://libssh2.org/snapshots/libssh2-''libssh2_version'-'' -o libssh2-'libssh2_version'-'currentday'.tar.gz $! $! -$ if f$search("libssh2-''libssh2_version'-''currentday'.tar.;") .nes. "" -$ then +$ if f$search("libssh2-''libssh2_version'-''currentday'.tar.;") .nes. "" +$ then $ delete libssh2-'libssh2_version'-'currentday'.tar.;* $ endif $! $ gunzip libssh2-'libssh2_version'-'currentday'.tar.gz $! $ tarfile = f$search("libssh2-''libssh2_version'-''currentday'.tar.;") -$ vmstar xf 'tarfile' +$ vmstar xf 'tarfile' Downloading a stable build will need you to get rid of the currentday. @@ -241,8 +241,8 @@ Getting the libssh2 sources from the source backup in the binary kit -------------------------------------------------------------------- During installation of the binary kit, you are given the option -of installing the sources. If chosen, a backup saveset with -the complete libssh2 directory is made available in +of installing the sources. If chosen, a backup saveset with +the complete libssh2 directory is made available in [gnv.common_src]. By restoring this backup saveset, you end up with the same @@ -262,7 +262,7 @@ command: @libssh2_make_lib.dcl This should produce libssh2_x_y_z.exe in this same vms directory. - + Building the examples @@ -274,16 +274,16 @@ produced when building the shared image, or against the shared image produced in the step before. You can compile only one of the examples by giving only the -name part of the filename of the example as p1 to the +name part of the filename of the example as p1 to the build procedure: -@libssh2_make_example.dcl +@libssh2_make_example.dcl or for instance -@libssh2_make_example.dcl sftp +@libssh2_make_example.dcl sftp -By default, libssh2_make_example.dcl links to the object libraries +By default, libssh2_make_example.dcl links to the object libraries produced by the libssh2_make_lib.dcl procedure. If you want to link against the shared image library made in the same procedure, invoke the procedure like so: @@ -291,7 +291,7 @@ the procedure like so: @libssh2_make_example.dcl sftp "SHARED" The procdure defines a process logical gnv$libssh2 pointing to the shared -image library in the directory, which obviously will not survive a logout. +image library in the directory, which obviously will not survive a logout. Building the help library @@ -312,8 +312,3 @@ When you have built the shared library and the help library, you can build a PCSI kit by issueing this command: @libssh2_make_kit.dcl - - - - - From 1d9af006095d5865a5cd37daba28ab32d15ad6ca Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 19:26:58 +0200 Subject: [PATCH 169/424] tidy-up: fix typos (#886) detected by codespell 2.2.4. --- RELEASE-NOTES | 2 +- acinclude.m4 | 8 ++++---- buildconf | 2 +- ci/checksrc.pl | 2 +- configure.ac | 2 +- docs/HACKING-CRYPTO | 4 ++-- docs/INSTALL_AUTOTOOLS | 4 ++-- docs/INSTALL_CMAKE.md | 4 ++-- docs/TODO | 4 ++-- example/direct_tcpip.c | 2 +- example/scp.c | 2 +- example/scp_nonblock.c | 2 +- example/scp_write.c | 2 +- example/scp_write_nonblock.c | 2 +- example/sftp.c | 2 +- example/sftp_RW_nonblock.c | 2 +- example/sftp_append.c | 2 +- example/sftp_mkdir.c | 2 +- example/sftp_mkdir_nonblock.c | 2 +- example/sftp_nonblock.c | 14 +++++++------- example/sftp_write.c | 2 +- example/sftp_write_nonblock.c | 6 +++--- example/sftp_write_sliding.c | 6 +++--- example/sftpdir.c | 2 +- example/sftpdir_nonblock.c | 2 +- example/ssh2.c | 2 +- example/ssh2_agent.c | 2 +- example/subsystem_netconf.c | 2 +- example/tcpip-forward.c | 2 +- example/x11.c | 2 +- include/libssh2.h | 2 +- os400/README400 | 6 +++--- os400/libssh2rpg/libssh2.rpgle.in | 10 +++++----- src/agent_win.c | 2 +- src/crypto.h | 2 +- src/kex.c | 2 +- vms/readme.vms | 6 +++--- 37 files changed, 62 insertions(+), 62 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 62064a9fe6..f2e5c737cf 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -20,7 +20,7 @@ This release includes the following enhancements and bugfixes: o improves portiablity of the make file o improves timeout behavior with 2FA keyboard auth o various improvements to the Wincng backend - o fixes reading parital packet replies when using an agent + o fixes reading partial packet replies when using an agent o fixes Diffie Hellman key exchange on Windows 1903+ builds o fixes building tests with older versions of OpenSSL o fixes possible multiple definition warnings diff --git a/acinclude.m4 b/acinclude.m4 index f645f4a50a..8a09e2570f 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -28,7 +28,7 @@ AC_DEFUN([CURL_DETECT_ICC], ]) dnl We create a function for detecting which compiler we use and then set as -dnl pendantic compiler options as possible for that particular compiler. The +dnl pedantic compiler options as possible for that particular compiler. The dnl options are only used for debug-builds. AC_DEFUN([CURL_CC_DEBUG_OPTS], @@ -237,7 +237,7 @@ dnl ioctlsocket test was good nonblock="ioctlsocket" AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets]) ],[ -dnl ioctlsocket didnt compile!, go to test 4 +dnl ioctlsocket did not compile!, go to test 4 AC_TRY_LINK([ /* headers for IoctlSocket test (Amiga?) */ @@ -251,7 +251,7 @@ dnl ioctlsocket test was good nonblock="IoctlSocket" AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets]) ],[ -dnl Ioctlsocket didnt compile, do test 5! +dnl Ioctlsocket did not compile, do test 5! AC_TRY_COMPILE([ /* headers for SO_NONBLOCK test (BeOS) */ #include @@ -265,7 +265,7 @@ dnl the SO_NONBLOCK test was good nonblock="SO_NONBLOCK" AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets]) ],[ -dnl test 5 didnt compile! +dnl test 5 did not compile! nonblock="nada" AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets]) ]) diff --git a/buildconf b/buildconf index 8097193097..ebdd3972b6 100755 --- a/buildconf +++ b/buildconf @@ -2,7 +2,7 @@ echo "***" >&2 echo "*** Do not use buildconf. Instead, just use: autoreconf -fi" >&2 -echo "*** Doing it for you now, but buildconf may disapear in the future." >&2 +echo "*** Doing it for you now, but buildconf may disappear in the future." >&2 echo "***" >&2 exec ${AUTORECONF:-autoreconf} -fi "${@}" diff --git a/ci/checksrc.pl b/ci/checksrc.pl index 965f0bab1d..f8c2caffef 100755 --- a/ci/checksrc.pl +++ b/ci/checksrc.pl @@ -712,7 +712,7 @@ sub scanfile { # A rather more interesting, and correct, check would be to not test # only locally committed files but inspect all files wrt the year of # their last commit. Removing the `git rev-list origin/master..HEAD` - # condition below will enfore copyright year checks against the year + # condition below will enforce copyright year checks against the year # the file was last committed (and thus edited to some degree). my $commityear = undef; @copyright = sort {$$b{year} cmp $$a{year}} @copyright; diff --git a/configure.ac b/configure.ac index 624944fd60..1658c99916 100644 --- a/configure.ac +++ b/configure.ac @@ -112,7 +112,7 @@ esac if test "$found_crypto" = "none"; then crypto_errors="${crypto_errors} -Specify --with-crypto=\$backend and/or the neccessary library search prefix. +Specify --with-crypto=\$backend and/or the necessary library search prefix. Known crypto backends: auto, m4_set_contents([crypto_backends], [, ])" AS_MESSAGE([ERROR: ${crypto_errors}]) diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index e330a7e7ed..c41495240c 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -392,7 +392,7 @@ _libssh2_cipher_cast5 CAST5-CBC algorithm identifier initializer. #define with constant value of type _libssh2_cipher_type(). -4.5) Tripple DES in CBC block mode. +4.5) Triple DES in CBC block mode. LIBSSH2_3DES #define as 1 if the crypto library supports TripleDES in CBC mode, else 0. If defined as 0, the rest of this section can be omitted. @@ -939,5 +939,5 @@ This function is for implementing key hash upgrading as defined in RFC 8332. Based on the incoming key_method value, this function will return a list of supported algorithms that can upgrade the original key method algorithm -as a comma seperated list, if there is no upgrade option this function should +as a comma separated list, if there is no upgrade option this function should return NULL. diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index a98441df9b..f9d157fbfa 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -264,7 +264,7 @@ Some ./configure options deserve additional comments: Enabling this option will allow for "none" as a negotiable method, however it still requires that the - method be advertized by the remote end and that no + method be advertised by the remote end and that no more-preferable methods are available. * --enable-mac-none @@ -277,7 +277,7 @@ Some ./configure options deserve additional comments: Enabling this option will allow for "none" as a negotiable method, however it still requires that the - method be advertized by the remote end and that no + method be advertised by the remote end and that no more-preferable methods are available. * --with-libgcrypt diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 779238e760..ddd471704f 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -82,7 +82,7 @@ The following options are available: libssh2 by default as well. Enabling this option will allow for "none" as a negotiable method, - however it still requires that the method be advertized by the + however it still requires that the method be advertised by the remote end and that no more-preferable methods are available. * `ENABLE_MAC_NONE=OFF` @@ -93,7 +93,7 @@ The following options are available: MAC hashes removes a layer of security. Enabling this option will allow for "none" as a negotiable method, - however it still requires that the method be advertized by the + however it still requires that the method be advertised by the remote end and that no more-preferable methods are available. * `ENABLE_DEBUG_LOGGING=ON` in Debug, `=OFF` in Release diff --git a/docs/TODO b/docs/TODO index cae1afa78c..a83af7cf64 100644 --- a/docs/TODO +++ b/docs/TODO @@ -41,7 +41,7 @@ At next SONAME bump libssh2_poll() libssh2_poll_channel_read() libssh2_session_startup() (libssh2_session_handshake() is the replacement) - libssh2_banner_set() (libssh2_session_banner_set() is the repacement) + libssh2_banner_set() (libssh2_session_banner_set() is the replacement) * Rename a few function: @@ -60,7 +60,7 @@ At next SONAME bump * remove the existing libssh2_scp_send_ex() function and rename libssh2_scp_send64 to become the new libssh2_scp_send instead. -* remove the existing libssh2_knownhost_check() functin and rename +* remove the existing libssh2_knownhost_check() function and rename libssh2_knownhost_checkp() to become the new libssh2_knownhost_check instead Buffering Improvements diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 162f2fbd70..f61b9bb76a 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/scp.c b/example/scp.c index c8e0ee3d93..6b2788ee4f 100644 --- a/example/scp.c +++ b/example/scp.c @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 453af82bf2..56ecfe2d21 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -179,7 +179,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/scp_write.c b/example/scp_write.c index a92465b49c..1f85a185b3 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index b8ffa78452..f41e44fd0a 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftp.c b/example/sftp.c index e902912da6..d11007774b 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 5a6d8fba62..1830ec33e5 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) libssh2_session_set_blocking(session, 0); - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftp_append.c b/example/sftp_append.c index 783efb9cfb..37e2212699 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 90084d3107..2888d3edc7 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index 45a36d36b2..cba29daf68 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index f9f4da2874..8b33986714 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -176,8 +176,8 @@ int main(int argc, char *argv[]) #endif /* ... start it up. This will trade welcome banners, exchange keys, - * and setup crypto, compression, and MAC layers - */ + * and setup crypto, compression, and MAC layers + */ while((rc = libssh2_session_handshake(session, sock)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -185,11 +185,11 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do - * is check the hostkey's fingerprint against our known hosts Your app - * may have it hard coded, may go to a file, may present it to the - * user, that's your call - */ + /* At this point we have not yet authenticated. The first thing to do + * is check the hostkey's fingerprint against our known hosts Your app + * may have it hard coded, may go to a file, may present it to the + * user, that's your call + */ fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); fprintf(stderr, "Fingerprint: "); for(i = 0; i < 20; i++) { diff --git a/example/sftp_write.c b/example/sftp_write.c index ce166b9ad7..804b69bd29 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index b72daf4ce6..35997c0eb0 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -168,8 +168,8 @@ int main(int argc, char *argv[]) libssh2_session_set_blocking(session, 0); /* ... start it up. This will trade welcome banners, exchange keys, - * and setup crypto, compression, and MAC layers - */ + * and setup crypto, compression, and MAC layers + */ while((rc = libssh2_session_handshake(session, sock)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do is + /* At this point we have not yet authenticated. The first thing to do is * check the hostkey's fingerprint against our known hosts Your app may * have it hard coded, may go to a file, may present it to the user, * that's your call diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index acd76cf487..e87cbe8605 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -168,8 +168,8 @@ int main(int argc, char *argv[]) libssh2_session_set_blocking(session, 0); /* ... start it up. This will trade welcome banners, exchange keys, - * and setup crypto, compression, and MAC layers - */ + * and setup crypto, compression, and MAC layers + */ while((rc = libssh2_session_handshake(session, sock)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do is + /* At this point we have not yet authenticated. The first thing to do is * check the hostkey's fingerprint against our known hosts Your app may * have it hard coded, may go to a file, may present it to the user, * that's your call diff --git a/example/sftpdir.c b/example/sftpdir.c index 7c5cfe1069..6f5079ffb2 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -153,7 +153,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 746ecd64fc..9228766b33 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/ssh2.c b/example/ssh2.c index 35785de7a4..5934fa624f 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't authenticated. The first thing to do is check + /* At this point we have not authenticated. The first thing to do is check * the hostkey's fingerprint against our known hosts Your app may have it * hard coded, may go to a file, may present it to the user, that's your * call diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index ffa376c34c..1eeaff14d4 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) return 1; } - /* At this point we havn't authenticated. The first thing to do is check + /* At this point we have not authenticated. The first thing to do is check * the hostkey's fingerprint against our known hosts Your app may have it * hard coded, may go to a file, may present it to the user, that's your * call diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index beffc8591a..4a400593b9 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -190,7 +190,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 55327ac7e4..c42a6f1405 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -147,7 +147,7 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we havn't yet authenticated. The first thing to do + /* At this point we have not yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call diff --git a/example/x11.c b/example/x11.c index 0b8a3934dd..c4956130e3 100644 --- a/example/x11.c +++ b/example/x11.c @@ -148,7 +148,7 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, rc = connect(sock, (struct sockaddr *) &addr, sizeof(addr)); if(rc != -1) { - /* Connection Successfull */ + /* Connection Successful */ if(gp_x11_chan == NULL) { /* Calloc ensure that gp_X11_chan is full of 0 */ gp_x11_chan = (struct chan_X11_list *) diff --git a/include/libssh2.h b/include/libssh2.h index 98a31a4349..9695763496 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -55,7 +55,7 @@ #define LIBSSH2_VERSION_PATCH 1 /* This is the numeric version of the libssh2 version number, meant for easier - parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will + parsing and comparisons by programs. The LIBSSH2_VERSION_NUM define will always follow this syntax: 0xXXYYZZ diff --git a/os400/README400 b/os400/README400 index fdac7da5b2..870c3634bf 100644 --- a/os400/README400 +++ b/os400/README400 @@ -96,9 +96,9 @@ String transcoding support: values from/to the libssh2 API, three non-standard additional procedures are provided. They use a session pointer and a "string cache" pointer. Each time a string is transcoded, it is cached in the given cache. It is -the responsibility of the caller to release the cache when its associted strings -are no longer needed. These procedures and the string cache type are defined -in a new libssh2_ccsid.h header file. +the responsibility of the caller to release the cache when its associated +strings are no longer needed. These procedures and the string cache type are +defined in a new libssh2_ccsid.h header file. To create a string cache, use: #include diff --git a/os400/libssh2rpg/libssh2.rpgle.in b/os400/libssh2rpg/libssh2.rpgle.in index 7b7fdd9466..ea1db892db 100644 --- a/os400/libssh2rpg/libssh2.rpgle.in +++ b/os400/libssh2rpg/libssh2.rpgle.in @@ -58,7 +58,7 @@ d c @LIBSSH2_VERSION_PATCH@ * This is the numeric version of the libssh2 version number, meant for - * easier parsing and comparions by programs. The LIBSSH2_VERSION_NUM + * easier parsing and comparisons by programs. The LIBSSH2_VERSION_NUM * define will always follow this syntax: * * X'XXYYZZ' @@ -511,7 +511,7 @@ * * Fills algs with a list of supported cryptographic algorithms. Returns a * non-negative number (number of supported algorithms) on success or a - * negative number (an eror code) on failure. + * negative number (an error code) on failure. * * NOTE: on success, algs must be deallocated (by calling libssh2_free) * when not needed anymore @@ -772,7 +772,7 @@ * response_callback is provided with filled by library prompts array, * but client must allocate and fill individual responses. Responses * array is already allocated. Responses data will be freed by libssh2 - * after callback return, but before subsequent callback invokation. + * after callback return, but before subsequent callback invocation. d libssh2_userauth_keyboard_interactive_ex... d pr extproc('libssh2_userauth_keyboard_i- @@ -1519,7 +1519,7 @@ * libssh2_knownhost_get() * * Traverse the internal list of known hosts. Pass NULL to 'prev' to get - * the first one. Or pass a poiner to the previously returned one to + * the first one. Or pass a pointer to the previously returned one to * get the next. * * Returns: @@ -1580,7 +1580,7 @@ * libssh2_agent_get_identity() * * Traverse the internal list of public keys. Pass NULL to 'prev' to get - * the first one. Or pass a poiner to the previously returned one to + * the first one. Or pass a pointer to the previously returned one to * get the next. * * Returns: diff --git a/src/agent_win.c b/src/agent_win.c index a84d4794d0..be6be4b741 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -59,7 +59,7 @@ * Portable OpenSSH by the PowerShell team. Commit * 8ab565c53f3619d6a1f5ac229e212cad8a52852c of * https://github.com/PowerShell/openssh-portable.git was used as the base, - * specificaly the following files: + * specifically the following files: * * - contrib\win32\win32compat\fileio.c * - Structure of agent_connect_openssh from ssh_get_authentication_socket diff --git a/src/crypto.h b/src/crypto.h index 6fa0a85185..8462e8b87d 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -324,7 +324,7 @@ int _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, * @related _libssh2_key_sign_algorithm() * @param key_method current key method, usually the default key sig method * @param key_method_len length of the key method buffer - * @result comma seperated list of supported upgrade options per RFC 8332, if + * @result comma separated list of supported upgrade options per RFC 8332, if * there is no upgrade option return NULL */ diff --git a/src/kex.c b/src/kex.c index b3f7d2ce7c..7c6760d881 100644 --- a/src/kex.c +++ b/src/kex.c @@ -2193,7 +2193,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, /* kex_method_ecdh_key_exchange * * Elliptic Curve Diffie Hellman Key Exchange - * supports SHA256/384/512 hashes based on negotated ecdh method + * supports SHA256/384/512 hashes based on negotiated ecdh method * */ diff --git a/vms/readme.vms b/vms/readme.vms index e38af16374..c3d10d2a23 100644 --- a/vms/readme.vms +++ b/vms/readme.vms @@ -95,7 +95,7 @@ define this logical in your systartup like so: $ define/system/executive gnv$libssh2 dev:[dir..]gnv$libssh2_x_y_z.exe -Optionally, you can install the executbale like so: +Optionally, you can install the executable like so: $ mc sysgen install dev:[dir..]gnv$libssh2_x_y_z.exe/open/share/header @@ -120,7 +120,7 @@ Compiling and linking against libssh2 The shared image library has a vector table with both uppercase and mixed case entry points, allowing to link directly against the shared -image wether you need the /NAMES=AS_IS or not. +image whether you need the /NAMES=AS_IS or not. To link successfully, you MUST use /NAMES=shortened, as some function names in libssh2 are longer than the VMS maximum of 32 characters. @@ -309,6 +309,6 @@ Building a PCSI kit ------------------- When you have built the shared library and the help library, -you can build a PCSI kit by issueing this command: +you can build a PCSI kit by issuing this command: @libssh2_make_kit.dcl From 480965e2d90f0b429cc3bdb4c6c86d246ac0ac95 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Mar 2023 19:48:41 +0200 Subject: [PATCH 170/424] tidy-up: fix/update URLs (#887) --- docs/INSTALL_AUTOTOOLS | 2 +- docs/INSTALL_CMAKE.md | 2 +- docs/SECURITY.md | 2 +- nw/test/GNUmakefile | 2 +- src/scp.c | 2 +- win32/Makefile.Watcom | 3 ++- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index f9d157fbfa..b2a0c61086 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -327,7 +327,7 @@ Some ./configure options deserve additional comments: * --with-libz-prefix=[DIR] If present, libssh2 will attempt to use the zlib - (http://www.zlib.org) for payload compression, however + (https://zlib.net/) for payload compression, however zlib is not required. If your installation of Libz is in another location, diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index ddd471704f..835bd573b1 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -71,7 +71,7 @@ The following options are available: * `ENABLE_ZLIB_COMPRESSION=OFF` - Will use zlib (http://www.zlib.org) for payload compression. Can + Will use zlib (https://zlib.net/) for payload compression. Can be `ON` or `OFF`. * `ENABLE_CRYPT_NONE=OFF` diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 6f442eb634..4dfcf80698 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -61,7 +61,7 @@ announcement. contributors properly. - Request a CVE number from - [distros@openwall](http://oss-security.openwall.org/wiki/mailing-lists/distros) + [distros@openwall](https://oss-security.openwall.org/wiki/mailing-lists/distros) when also informing and preparing them for the upcoming public security vulnerability announcement - attach the advisory draft for information. Note that 'distros' won't accept an embargo longer than 14 days. diff --git a/nw/test/GNUmakefile b/nw/test/GNUmakefile index 9bbd9c0968..b00936b86b 100644 --- a/nw/test/GNUmakefile +++ b/nw/test/GNUmakefile @@ -29,7 +29,7 @@ SAMPLES = ../../example TARGETS := $(filter-out x11.nlm,$(patsubst $(SAMPLES)/%.c,%.nlm,$(strip $(wildcard $(SAMPLES)/*.c)))) VERSION = $(LIBSSH2_VERSION) COPYR = Copyright (c) $(LIBSSH2_COPYRIGHT_STR) -WWWURL = http://www.libssh2.org/ +WWWURL = https://www.libssh2.org/ DESCR = libssh2 $(notdir $(@:.def=)) $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) MTSAFE = YES STACK = 64000 diff --git a/src/scp.c b/src/scp.c index 116b328365..879e26a715 100644 --- a/src/scp.c +++ b/src/scp.c @@ -112,7 +112,7 @@ References: o csh-compatible quotation (special handling for '!' etc.), see - http://www.grymoire.com/Unix/Csh.html#toc-uh-10 + https://www.grymoire.com/Unix/Csh.html#toc-uh-10 Return value: Length of the resulting string (not counting the terminating '\0'), diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom index 9ca5ae850a..9b613eaacd 100644 --- a/win32/Makefile.Watcom +++ b/win32/Makefile.Watcom @@ -1,7 +1,8 @@ # # Watcom / OpenWatcom Win32 makefile for libssh2. # -# Comments to: Guenter Knauf http://www.gknw.net/phpbb +# Comments to: Guenter Knauf +# https://web.archive.org/web/20100126042636/www.gknw.net/phpbb/ # !ifndef %watcom From 4b800182c510e2c33602d65ed4b777d79fd567f7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 09:37:46 +0200 Subject: [PATCH 171/424] checksrc: update and fix warnings (#890) Update from: https://github.com/curl/curl/blob/5fec927374e4d9553205d861f2dcb39ec78002cc/scripts/checksrc.pl - suppress these new checks: - EQUALSNULL: 320 warnings - NOTEQUALSZERO: 142 warnings - TYPEDEFSTRUCT: 16 warnings We can enabled them in the future. - fix all other new ones. - also fix whitespace in two `NMakefile` files. --- NMakefile | 1 - ci/checksrc.pl | 286 ++++++++++++++---- ci/checksrc.sh | 10 +- example/ssh2.c | 18 +- example/x11.c | 4 +- src/NMakefile | 1 - src/hostkey.c | 2 +- src/kex.c | 6 +- src/mbedtls.c | 2 +- src/misc.c | 4 +- src/misc.h | 2 +- src/openssl.c | 12 +- src/os400qc3.c | 1 - src/scp.c | 4 +- src/session.c | 10 +- ...t_keyboard_interactive_auth_info_request.c | 2 +- 16 files changed, 270 insertions(+), 95 deletions(-) diff --git a/NMakefile b/NMakefile index f0867089db..30b20de7d7 100644 --- a/NMakefile +++ b/NMakefile @@ -30,4 +30,3 @@ win32\objects.mk: Makefile.inc @echo OBJECTS = \>$@ @for %O in ($(OBJECTS)) do @echo $$(INTDIR)\%O \>>$@ @echo $$(EOL)>>$@ - diff --git a/ci/checksrc.pl b/ci/checksrc.pl index f8c2caffef..2aab0ad8fb 100755 --- a/ci/checksrc.pl +++ b/ci/checksrc.pl @@ -6,11 +6,11 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 2011 - 2018, Daniel Stenberg, , et al. +# Copyright (C) Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms -# are also available at https://curl.haxx.se/docs/copyright.html. +# are also available at https://curl.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,8 @@ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # +# SPDX-License-Identifier: curl +# ########################################################################### use strict; @@ -31,14 +33,14 @@ my $swarnings = 0; my $errors = 0; my $serrors = 0; -my $suppressed; # whitelisted problems +my $suppressed; # skipped problems my $file; my $dir="."; my $wlist=""; my @alist; -my $windows_os = $^O eq 'MSWin32' || $^O eq 'msys' || $^O eq 'cygwin'; +my $windows_os = $^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys'; my $verbose; -my %whitelist; +my %skiplist; my %ignore; my %ignore_set; @@ -47,47 +49,59 @@ my %warnings_extended = ( 'COPYRIGHTYEAR' => 'copyright year incorrect', + 'STRERROR', => 'strerror() detected', ); my %warnings = ( - 'LONGLINE' => "Line longer than $max_column", - 'TABS' => 'TAB characters not allowed', - 'TRAILINGSPACE' => 'Trailing white space on the line', - 'CPPCOMMENTS' => '// comment detected', - 'SPACEBEFOREPAREN' => 'space before an open parenthesis', - 'SPACEAFTERPAREN' => 'space after open parenthesis', - 'SPACEBEFORECLOSE' => 'space before a close parenthesis', - 'SPACEBEFORECOMMA' => 'space before a comma', - 'RETURNNOSPACE' => 'return without space', - 'COMMANOSPACE' => 'comma without following space', - 'BRACEELSE' => '} else on the same line', - 'PARENBRACE' => '){ without sufficient space', - 'SPACESEMICOLON' => 'space before semicolon', + 'ASSIGNWITHINCONDITION' => 'assignment within conditional expression', + 'ASTERISKNOSPACE' => 'pointer declared without space before asterisk', + 'ASTERISKSPACE' => 'pointer declared with space after asterisk', + 'BADCOMMAND' => 'bad !checksrc! instruction', 'BANNEDFUNC' => 'a banned function was used', - 'FOPENMODE' => 'fopen needs a macro for the mode string', + 'BRACEELSE' => '} else on the same line', 'BRACEPOS' => 'wrong position for an open brace', - 'INDENTATION' => 'wrong start column for code', + 'BRACEWHILE' => 'A single space between open brace and while', + 'COMMANOSPACE' => 'comma without following space', + 'COMMENTNOSPACEEND' => 'no space before */', + 'COMMENTNOSPACESTART' => 'no space following /*', 'COPYRIGHT' => 'file missing a copyright statement', - 'BADCOMMAND' => 'bad !checksrc! instruction', - 'UNUSEDIGNORE' => 'a warning ignore was not used', - 'OPENCOMMENT' => 'file ended with a /* comment still "open"', - 'ASTERISKSPACE' => 'pointer declared with space after asterisk', - 'ASTERISKNOSPACE' => 'pointer declared without space before asterisk', - 'ASSIGNWITHINCONDITION' => 'assignment within conditional expression', + 'CPPCOMMENTS' => '// comment detected', + 'DOBRACE' => 'A single space between do and open brace', + 'EMPTYLINEBRACE' => 'Empty line before the open brace', 'EQUALSNOSPACE' => 'equals sign without following space', + 'EQUALSNULL' => 'if/while comparison with == NULL', + 'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression', + 'FOPENMODE' => 'fopen needs a macro for the mode string', + 'INCLUDEDUP', => 'same file is included again', + 'INDENTATION' => 'wrong start column for code', + 'LONGLINE' => "Line longer than $max_column", + 'MULTISPACE' => 'multiple spaces used when not suitable', 'NOSPACEEQUALS' => 'equals sign without preceding space', + 'NOTEQUALSZERO', => 'if/while comparison with != 0', + 'ONELINECONDITION' => 'conditional block on the same line as the if()', + 'OPENCOMMENT' => 'file ended with a /* comment still "open"', + 'PARENBRACE' => '){ without sufficient space', + 'RETURNNOSPACE' => 'return without space', 'SEMINOSPACE' => 'semicolon without following space', - 'MULTISPACE' => 'multiple spaces used when not suitable', 'SIZEOFNOPAREN' => 'use of sizeof without parentheses', 'SNPRINTF' => 'use of snprintf', + 'SPACEAFTERPAREN' => 'space after open parenthesis', + 'SPACEBEFORECLOSE' => 'space before a close parenthesis', + 'SPACEBEFORECOMMA' => 'space before a comma', + 'SPACEBEFOREPAREN' => 'space before an open parenthesis', + 'SPACESEMICOLON' => 'space before semicolon', + 'TABS' => 'TAB characters not allowed', + 'TRAILINGSPACE' => 'Trailing whitespace on the line', + 'TYPEDEFSTRUCT' => 'typedefed struct', + 'UNUSEDIGNORE' => 'a warning ignore was not used', ); -sub readwhitelist { - open(W, "<$dir/checksrc.whitelist") or return; +sub readskiplist { + open(W, "<$dir/checksrc.skip") or return; my @all=; for(@all) { $windows_os ? $_ =~ s/\r?\n$// : chomp; - $whitelist{$_}=1; + $skiplist{$_}=1; } close(W); } @@ -115,10 +129,19 @@ sub readlocalfile { } $warnings{$1} = $warnings_extended{$1}; } + elsif (/^\s*disable ([A-Z]+)$/) { + if(!defined($warnings{$1})) { + print STDERR "invalid warning specified in .checksrc: \"$1\"\n"; + next; + } + # Accept-list + push @alist, $1; + } else { die "Invalid format in $dir/.checksrc on line $i\n"; } } + close($rcfile); } sub checkwarn { @@ -131,8 +154,8 @@ sub checkwarn { # print STDERR "Dev! there's no description for $name!\n"; #} - # checksrc.whitelist - if($whitelist{$line}) { + # checksrc.skip + if($skiplist{$line}) { $nowarn = 1; } # !checksrc! controlled @@ -176,7 +199,7 @@ sub checkwarn { $file = shift @ARGV; -while(1) { +while(defined $file) { if($file =~ /-D(.*)/) { $dir = $1; @@ -217,17 +240,25 @@ sub checkwarn { print " -A[rule] Accept this violation, can be used multiple times\n"; print " -D[DIR] Directory to prepend file names\n"; print " -h Show help output\n"; - print " -W[file] Whitelist the given file - ignore all its flaws\n"; + print " -W[file] Skip the given file - ignore all its flaws\n"; print " -i Indent spaces. Default: 2\n"; print " -m Maximum line length. Default: 79\n"; print "\nDetects and warns for these problems:\n"; - for(sort keys %warnings) { - printf (" %-18s: %s\n", $_, $warnings{$_}); + my @allw = keys %warnings; + push @allw, keys %warnings_extended; + for my $w (sort @allw) { + if($warnings{$w}) { + printf (" %-18s: %s\n", $w, $warnings{$w}); + } + else { + printf (" %-18s: %s[*]\n", $w, $warnings_extended{$w}); + } } + print " [*] = disabled by default\n"; exit; } -readwhitelist(); +readskiplist(); readlocalfile(); do { @@ -344,11 +375,15 @@ sub scanfile { my $line = 1; my $prevl=""; - my $l; + my $prevpl=""; + my $l = ""; + my $prep = 0; + my $prevp = 0; open(R, "<$file") || die "failed to open $file"; my $incomment=0; my @copyright=(); + my %includes; checksrc_clear(); # for file based ignores accept_violations(); @@ -365,7 +400,8 @@ sub scanfile { } # check for a copyright statement and save the years - if($l =~ /\* +copyright .* \d\d\d\d/i) { + if($l =~ /\* +copyright .* (\d\d\d\d|)/i) { + my $count = 0; while($l =~ /([\d]{4})/g) { push @copyright, { year => $1, @@ -373,6 +409,16 @@ sub scanfile { col => index($l, $1), code => $l }; + $count++; + } + if(!$count) { + # year-less + push @copyright, { + year => -1, + line => $line, + col => index($l, $1), + code => $l + }; } } @@ -386,12 +432,24 @@ sub scanfile { checkwarn("TABS", $line, length($1), $file, $l, "Contains TAB character", 1); } - # detect trailing white space + # detect trailing whitespace if($l =~ /^(.*)[ \t]+\z/) { checkwarn("TRAILINGSPACE", $line, length($1), $file, $l, "Trailing whitespace"); } + # no space after comment start + if($l =~ /^(.*)\/\*\w/) { + checkwarn("COMMENTNOSPACESTART", + $line, length($1) + 2, $file, $l, + "Missing space after comment start"); + } + # no space at comment end + if($l =~ /^(.*)\w\*\//) { + checkwarn("COMMENTNOSPACEEND", + $line, length($1) + 1, $file, $l, + "Missing space end comment end"); + } # ------------------------------------------------------------ # Above this marker, the checks were done on lines *including* # comments @@ -426,13 +484,37 @@ sub scanfile { # comments # ------------------------------------------------------------ + # prev line was a preprocessor **and** ended with a backslash + if($prep && ($prevpl =~ /\\ *\z/)) { + # this is still a preprocessor line + $prep = 1; + goto preproc; + } + $prep = 0; + # crude attempt to detect // comments without too many false # positives - if($l =~ /^([^"\*]*)[^:"]\/\//) { + if($l =~ /^(([^"\*]*)[^:"]|)\/\//) { checkwarn("CPPCOMMENTS", $line, length($1), $file, $l, "\/\/ comment"); } + if($l =~ /^(\#\s*include\s+)([\">].*[>}"])/) { + my ($pre, $path) = ($1, $2); + if($includes{$path}) { + checkwarn("INCLUDEDUP", + $line, length($1), $file, $l, "duplicated include"); + } + $includes{$path} = $l; + } + + # detect and strip preprocessor directives + if($l =~ /^[ \t]*\#/) { + # preprocessor line + $prep = 1; + goto preproc; + } + my $nostr = nostrings($l); # check spaces after for/if/while/function call if($nostr =~ /^(.*)(for|if|while| ([a-zA-Z0-9_]+)) \((.)/) { @@ -456,14 +538,57 @@ sub scanfile { "$2 with space"); } } + # check for '== NULL' in if/while conditions but not if the thing on + # the left of it is a function call + if($nostr =~ /^(.*)(if|while)(\(.*?)([!=]= NULL|NULL [!=]=)/) { + checkwarn("EQUALSNULL", $line, + length($1) + length($2) + length($3), + $file, $l, "we prefer !variable instead of \"== NULL\" comparisons"); + } - if($nostr =~ /^((.*)(if) *\()(.*)\)/) { + # check for '!= 0' in if/while conditions but not if the thing on + # the left of it is a function call + if($nostr =~ /^(.*)(if|while)(\(.*[^)]) != 0[^x]/) { + checkwarn("NOTEQUALSZERO", $line, + length($1) + length($2) + length($3), + $file, $l, "we prefer if(rc) instead of \"rc != 0\" comparisons"); + } + + # check spaces in 'do {' + if($nostr =~ /^( *)do( *)\{/ && length($2) != 1) { + checkwarn("DOBRACE", $line, length($1) + 2, $file, $l, "one space after do before brace"); + } + # check spaces in 'do {' + elsif($nostr =~ /^( *)\}( *)while/ && length($2) != 1) { + checkwarn("BRACEWHILE", $line, length($1) + 2, $file, $l, "one space between brace and while"); + } + if($nostr =~ /^((.*\s)(if) *\()(.*)\)(.*)/) { my $pos = length($1); - if($4 =~ / = /) { + my $postparen = $5; + my $cond = $4; + if($cond =~ / = /) { checkwarn("ASSIGNWITHINCONDITION", $line, $pos+1, $file, $l, "assignment within conditional expression"); } + my $temp = $cond; + $temp =~ s/\(//g; # remove open parens + my $openc = length($cond) - length($temp); + + $temp = $cond; + $temp =~ s/\)//g; # remove close parens + my $closec = length($cond) - length($temp); + my $even = $openc == $closec; + + if($l =~ / *\#/) { + # this is a #if, treat it differently + } + elsif($even && $postparen && + ($postparen !~ /^ *$/) && ($postparen !~ /^ *[,{&|\\]+/)) { + checkwarn("ONELINECONDITION", + $line, length($l)-length($postparen), $file, $l, + "conditional block on the same line"); + } } # check spaces after open parentheses if($l =~ /^(.*[a-z])\( /i) { @@ -551,16 +676,22 @@ sub scanfile { checkwarn("PARENBRACE", $line, length($1)+1, $file, $l, "missing space after close paren"); } + # check for "^{" with an empty line before it + if(($l =~ /^\{/) && ($prevl =~ /^[ \t]*\z/)) { + checkwarn("EMPTYLINEBRACE", + $line, 0, $file, $l, "empty line before open brace"); + } # check for space before the semicolon last in a line if($l =~ /^(.*[^ ].*) ;$/) { checkwarn("SPACESEMICOLON", - $line, length($1), $file, $ol, "space before last semicolon"); + $line, length($1), $file, $ol, "no space before semicolon"); } # scan for use of banned functions if($l =~ /^(.*\W) - (gets| + (gmtime|localtime| + gets| strtok| v?sprintf| (str|_mbs|_tcs|_wcs)n?cat| @@ -571,7 +702,18 @@ sub scanfile { $line, length($1), $file, $ol, "use of $2 is banned"); } - + if($warnings{"STRERROR"}) { + # scan for use of banned strerror. This is not a BANNEDFUNC to + # allow for individual enable/disable of this warning. + if($l =~ /^(.*\W)(strerror)\s*\(/x) { + if($1 !~ /^ *\#/) { + # skip preprocessor lines + checkwarn("STRERROR", + $line, length($1), $file, $ol, + "use of $2 is banned"); + } + } + } # scan for use of snprintf for curl-internals reasons if($l =~ /^(.*\W)(v?snprintf)\s*\(/x) { checkwarn("SNPRINTF", @@ -589,10 +731,9 @@ sub scanfile { } } - # check for open brace first on line but not first column - # only alert if previous line ended with a close paren and wasn't a cpp - # line - if((($prevl =~ /\)\z/) && ($prevl !~ /^ *#/)) && ($l =~ /^( +)\{/)) { + # check for open brace first on line but not first column only alert + # if previous line ended with a close paren and it wasn't a cpp line + if(($prevl =~ /\)\z/) && ($l =~ /^( +)\{/) && !$prevp) { checkwarn("BRACEPOS", $line, length($1), $file, $ol, "badly placed open brace"); } @@ -600,11 +741,10 @@ sub scanfile { # if the previous line starts with if/while/for AND ends with an open # brace, or an else statement, check that this line is indented $indent # more steps, if not a cpp line - if($prevl =~ /^( *)((if|while|for)\(.*\{|else)\z/) { + if(!$prevp && ($prevl =~ /^( *)((if|while|for)\(.*\{|else)\z/)) { my $first = length($1); - # this line has some character besides spaces - if(($l !~ /^ *#/) && ($l =~ /^( *)[^ ]/)) { + if($l =~ /^( *)[^ ]/) { my $second = length($1); my $expect = $first+$indent; if($expect != $second) { @@ -617,10 +757,10 @@ sub scanfile { } # check for 'char * name' - if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost) *(\*+)) (\w+)/) && ($4 ne "const")) { - checkwarn("ASTERISKNOSPACE", + if(($l =~ /(^.*(char|int|long|void|CURL|CURLM|CURLMsg|[cC]url_[A-Za-z_]+|struct [a-zA-Z_]+) *(\*+)) (\w+)/) && ($4 !~ /^(const|volatile)$/)) { + checkwarn("ASTERISKSPACE", $line, length($1), $file, $ol, - "no space after declarative asterisk"); + "space after declarative asterisk"); } # check for 'char*' if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost|sockaddr_in|FILE)\*)/)) { @@ -675,6 +815,19 @@ sub scanfile { "no space after semicolon"); } + # typedef struct ... { + if($nostr =~ /^(.*)typedef struct.*{/) { + checkwarn("TYPEDEFSTRUCT", + $line, length($1)+1, $file, $ol, + "typedef'ed struct"); + } + + if($nostr =~ /(.*)! +(\w|\()/) { + checkwarn("EXCLAMATIONSPACE", + $line, length($1)+1, $file, $ol, + "space after exclamation mark"); + } + # check for more than one consecutive space before open brace or # question mark. Skip lines containing strings since they make it hard # due to artificially getting multiple spaces @@ -682,13 +835,13 @@ sub scanfile { $nostr =~ /^(.*(\S)) + [{?]/i) { checkwarn("MULTISPACE", $line, length($1)+1, $file, $ol, - "multiple space"); - print STDERR "L: $l\n"; - print STDERR "nostr: $nostr\n"; + "multiple spaces"); } - + preproc: $line++; - $prevl = $ol; + $prevp = $prep; + $prevl = $ol if(!$prep); + $prevpl = $ol if($prep); } if(!scalar(@copyright)) { @@ -717,12 +870,17 @@ sub scanfile { my $commityear = undef; @copyright = sort {$$b{year} cmp $$a{year}} @copyright; + # if the file is modified, assume commit year this year if(`git status -s -- $file` =~ /^ [MARCU]/) { $commityear = (localtime(time))[5] + 1900; } - elsif (`git rev-list --count origin/master..HEAD -- $file` !~ /^0/) { - my $grl = `git rev-list --max-count=1 --timestamp HEAD -- $file`; - $commityear = (localtime((split(/ /, $grl))[0]))[5] + 1900; + else { + # min-parents=1 to ignore wrong initial commit in truncated repos + my $grl = `git rev-list --max-count=1 --min-parents=1 --timestamp HEAD -- $file`; + if($grl) { + chomp $grl; + $commityear = (localtime((split(/ /, $grl))[0]))[5] + 1900; + } } if(defined($commityear) && scalar(@copyright) && diff --git a/ci/checksrc.sh b/ci/checksrc.sh index 3890815b4d..aff58909ec 100755 --- a/ci/checksrc.sh +++ b/ci/checksrc.sh @@ -5,4 +5,12 @@ set -e FILES="src/*.[ch] include/*.h example/*.c tests/*.[ch]" WHITELIST="-Wsrc/libssh2_config.h" -perl ./ci/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT -AFOPENMODE $WHITELIST $FILES +perl ./ci/checksrc.pl -i4 -m79 \ + -ASIZEOFNOPAREN \ + -ASNPRINTF \ + -ACOPYRIGHT \ + -AFOPENMODE \ + -AEQUALSNULL \ + -ANOTEQUALSZERO \ + -ATYPEDEFSTRUCT \ + $WHITELIST $FILES diff --git a/example/ssh2.c b/example/ssh2.c index 5934fa624f..f689c39d0b 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -275,9 +275,11 @@ int main(int argc, char *argv[]) * See /etc/termcap for more options. This is useful when opening * an interactive shell. */ -// if(libssh2_channel_request_pty(channel, "vanilla")) { -// fprintf(stderr, "Failed requesting pty\n"); -// } + #if 0 + if(libssh2_channel_request_pty(channel, "vanilla")) { + fprintf(stderr, "Failed requesting pty\n"); + } + #endif if(argc > 5) { if(libssh2_channel_exec(channel, argv[5])) { @@ -287,10 +289,12 @@ int main(int argc, char *argv[]) /* Instead of just running a single command with libssh2_channel_exec, * a shell can be opened on the channel instead, for interactive use. * You usually want a pty allocated first in that case (see above). */ -// if(libssh2_channel_shell(channel)) { -// fprintf(stderr, "Unable to request shell on allocated pty\n"); -// goto shutdown; -// } + #if 0 + if(libssh2_channel_shell(channel)) { + fprintf(stderr, "Unable to request shell on allocated pty\n"); + goto shutdown; + } + #endif /* At this point the shell can be interacted with using * libssh2_channel_read() diff --git a/example/x11.c b/example/x11.c index c4956130e3..e66da6888a 100644 --- a/example/x11.c +++ b/example/x11.c @@ -223,7 +223,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) if(rc > 0) { memset((void *)buf, 0, bufsize); - /* Data in sock*/ + /* Data in sock */ rc = read(sock, buf, bufsize); if(rc > 0) { libssh2_channel_write(channel, buf, rc); @@ -451,7 +451,7 @@ main (int argc, char *argv[]) rc = select((int)(fileno(stdin) + 1), &set, NULL, NULL, &timeval_out); if(rc > 0) { - /* Data in stdin*/ + /* Data in stdin */ rc = read(fileno(stdin), buf, 1); if(rc > 0) libssh2_channel_write(channel, buf, sizeof(buf)); diff --git a/src/NMakefile b/src/NMakefile index 0c4853f1df..46430bbd22 100644 --- a/src/NMakefile +++ b/src/NMakefile @@ -27,4 +27,3 @@ $(RESOURCE): win32\libssh2.rc $(RC) $(RCFLAGS) /Fo"$@" $? !include "win32/rules.mk" - diff --git a/src/hostkey.c b/src/hostkey.c index ea0272250d..92447e7499 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -1247,7 +1247,7 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_ed25519 = { hostkey_method_ssh_ed25519_dtor, }; -#endif /*LIBSSH2_ED25519*/ +#endif /* LIBSSH2_ED25519 */ static const LIBSSH2_HOSTKEY_METHOD *hostkey_methods[] = { diff --git a/src/kex.c b/src/kex.c index 7c6760d881..83b522cbbe 100644 --- a/src/kex.c +++ b/src/kex.c @@ -1104,7 +1104,6 @@ static int kex_method_diffie_hellman_group16_sha512_key_exchange(LIBSSH2_SESSION *session, key_exchange_state_low_t * key_state) - { static const unsigned char p_value[512] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, @@ -1194,7 +1193,6 @@ static int kex_method_diffie_hellman_group18_sha512_key_exchange(LIBSSH2_SESSION *session, key_exchange_state_low_t * key_state) - { static const unsigned char p_value[1024] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, @@ -2315,7 +2313,7 @@ kex_method_ecdh_key_exchange return ret; } -#endif /*LIBSSH2_ECDSA*/ +#endif /* LIBSSH2_ECDSA */ #if LIBSSH2_ED25519 @@ -2926,7 +2924,7 @@ kex_method_curve25519_key_exchange } -#endif /*LIBSSH2_ED25519*/ +#endif /* LIBSSH2_ED25519 */ #define LIBSSH2_KEX_METHOD_FLAG_REQ_ENC_HOSTKEY 0x0001 diff --git a/src/mbedtls.c b/src/mbedtls.c index 16abf2f2c5..6c7f7f8c50 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -278,7 +278,7 @@ _libssh2_mbedtls_bignum_random(_libssh2_bn *bn, int bits, int top, int bottom) if(err) return -1; - /* Zero unused bits above the most significant bit*/ + /* Zero unused bits above the most significant bit */ for(i = len*8 - 1; (size_t)bits <= i; --i) { err = mbedtls_mpi_set_bit(bn, i, 0); if(err) diff --git a/src/misc.c b/src/misc.c index 465d7b00e9..5e07d33c18 100644 --- a/src/misc.c +++ b/src/misc.c @@ -683,7 +683,7 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */ int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp) { union { - unsigned __int64 ns100; /*time since 1 Jan 1601 in 100ns units */ + unsigned __int64 ns100; /* time since 1 Jan 1601 in 100ns units */ FILETIME ft; } _now; (void)tzp; @@ -751,7 +751,7 @@ void _libssh2_memzero(void *buf, size_t size) /* String buffer */ -struct string_buf* _libssh2_string_buf_new(LIBSSH2_SESSION *session) +struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session) { struct string_buf *ret; diff --git a/src/misc.h b/src/misc.h index 1e996e21e6..f7175b248c 100644 --- a/src/misc.h +++ b/src/misc.h @@ -107,7 +107,7 @@ void _libssh2_store_bignum2_bytes(unsigned char **buf, size_t len); void *_libssh2_calloc(LIBSSH2_SESSION *session, size_t size); -struct string_buf* _libssh2_string_buf_new(LIBSSH2_SESSION *session); +struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session); void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf); int _libssh2_get_boolean(struct string_buf *buf, unsigned char *out); diff --git a/src/openssl.c b/src/openssl.c index 8b362af79b..1dd6b17f25 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -3199,13 +3199,19 @@ _libssh2_curve25519_gen_k(_libssh2_bn **k, } rc = EVP_PKEY_derive_init(server_key_ctx); - if(rc <= 0) goto cleanExit; + if(rc <= 0) { + goto cleanExit; + } rc = EVP_PKEY_derive_set_peer(server_key_ctx, peer_key); - if(rc <= 0) goto cleanExit; + if(rc <= 0) { + goto cleanExit; + } rc = EVP_PKEY_derive(server_key_ctx, NULL, &out_len); - if(rc <= 0) goto cleanExit; + if(rc <= 0) { + goto cleanExit; + } if(out_len != LIBSSH2_ED25519_KEY_LEN) { rc = -1; diff --git a/src/os400qc3.c b/src/os400qc3.c index 3ce9d542f3..89f440ee82 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -2142,7 +2142,6 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, unsigned char **method, size_t *method_len, unsigned char **pubkeydata, size_t *pubkeydata_len, const char *privatekey, const char *passphrase) - { loadpubkeydata p; int ret; diff --git a/src/scp.c b/src/scp.c index 879e26a715..524d3e5776 100644 --- a/src/scp.c +++ b/src/scp.c @@ -599,7 +599,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) return NULL; } else if(rc < 0) { - /* error, bail out*/ + /* error, bail out */ _libssh2_error(session, rc, "Failed reading SCP response"); goto scp_recv_error; } @@ -783,7 +783,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) * */ LIBSSH2_API LIBSSH2_CHANNEL * -libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat * sb) +libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb) { LIBSSH2_CHANNEL *ptr; diff --git a/src/session.c b/src/session.c index 7420c15178..da6332bda8 100644 --- a/src/session.c +++ b/src/session.c @@ -295,7 +295,7 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ #endif #if defined(HAVE_FIONBIO) && (SETBLOCK == 0) - /* older unix versions and VMS*/ + /* older unix versions and VMS */ int flags; flags = nonblock; @@ -402,8 +402,12 @@ get_socket_nonblocking(libssh2_socket_t sockfd) callstat = getsockopt(sockfd, SOL_SOCKET, SO_STATE, (char *)&sockstat, &size); - if(callstat == -1) return 0; - if((sockstat&SS_NBIO) != 0) return 1; + if(callstat == -1) { + return 0; + } + if((sockstat&SS_NBIO) != 0) { + return 1; + } return 0; #undef GETBLOCK diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index 96df9556dc..989681f9c4 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -164,7 +164,7 @@ struct test_case test_cases[TEST_CASES_LEN] = { "\0\0\0\x0aResponse: " "\x01" , 89, {PASS, 0, ""}}, - /* three prompts, 3rd missing*/ + /* three prompts, 3rd missing */ { "<" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x03" From b35381e4464d35ec7441fb0610572debf6abf7fd Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 09:40:51 +0200 Subject: [PATCH 172/424] build: delete native Watcom wmake support with Win32 (#889) CMake supports generating Watcom wmake files: https://cmake.org/cmake/help/v3.1/generator/Watcom%20WMake.html --- Makefile.am | 2 +- win32/Makefile.Watcom | 184 ------------------------------------------ 2 files changed, 1 insertion(+), 185 deletions(-) delete mode 100644 win32/Makefile.Watcom diff --git a/Makefile.am b/Makefile.am index e0489bdb52..f407ef7292 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,7 +32,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ WIN32FILES = win32/GNUmakefile \ win32/libssh2_config.h win32/config.mk win32/rules.mk \ - win32/Makefile.Watcom win32/libssh2.dsw win32/tests.dsp $(DSP) \ + win32/libssh2.dsw win32/tests.dsp $(DSP) \ win32/msvcproj.head win32/msvcproj.foot win32/libssh2.rc OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ diff --git a/win32/Makefile.Watcom b/win32/Makefile.Watcom deleted file mode 100644 index 9b613eaacd..0000000000 --- a/win32/Makefile.Watcom +++ /dev/null @@ -1,184 +0,0 @@ -# -# Watcom / OpenWatcom Win32 makefile for libssh2. -# -# Comments to: Guenter Knauf -# https://web.archive.org/web/20100126042636/www.gknw.net/phpbb/ -# - -!ifndef %watcom -!error WATCOM environment variable not set! -!else -SYS_INCL = -I$(%watcom)\h\nt -I$(%watcom)\h -SYS_LIBS = $(%watcom)\lib386\nt;$(%watcom)\lib386 -!endif - -!ifdef %libname -LIBNAME = $(%libname) -!else -LIBNAME = libssh2 -!endif -TARGETS = $(LIBNAME).dll $(LIBNAME)_imp.lib $(LIBNAME).lib - -CC = wcc386 -LD = wlink -AR = wlib -RC = wrc - -!ifdef __LOADDLL__ -! loaddll wcc386 wccd386 -! loaddll wpp386 wppd386 -! loaddll wlib wlibd -! if $(__VERSION__) > 1270 -! loaddll wlink wlinkd -! else -! loaddll wlink wlink -! endif -!endif - -!if $(__VERSION__) < 1250 -RM = del /q /f 2>NUL -!else -RM = rm -f -!endif -MD = mkdir -RD = rmdir /q /s 2>NUL -CP = copy - -CFLAGS = -3r -mf -hc -zff -zgf -zq -zm -zc -s -fr=nul -w2 -fpi -oilrtfm & - -wcd=201 -bt=nt -d+ -dWIN32 & - -I. -I..\include $(SYS_INCL) - -!ifdef %debug -DEBUG = -dDEBUG=1 -dDEBUGBUILD -CFLAGS += -d3 $(DEBUG) -!else -CFLAGS += -d0 -!endif - -# -# Change to suite. -# -!ifdef %zlib_root -ZLIB_ROOT = $(%zlib_root) -!else -ZLIB_ROOT = ..\..\zlib -!endif - -!ifdef %openssl_root -OPENSSL_ROOT = $(%openssl_root) -!else -OPENSSL_ROOT = ..\..\openssl -!endif - -!ifdef %use_zlib -CFLAGS += -DLIBSSH2_HAVE_ZLIB -I$(ZLIB_ROOT) -!endif - -!ifdef %use_wincng -CFLAGS += -DLIBSSH2_WINCNG -!else -CFLAGS += -wcd=138 -dLIBSSH2_OPENSSL -I$(OPENSSL_ROOT)\inc32 -!endif - -!ifdef %use_watt32 -CFLAGS += -dUSE_WATT32 -I$(%watt_root)\inc -!endif - -OBJ_BASE = WC_Win32.obj -LINK_ARG = $(OBJ_BASE)\dyn\wlink.arg -LIB_ARG = $(OBJ_BASE)\stat\wlib.arg - -# In order to process Makefile.inc wmake must be called with -u switch! -!ifndef %MAKEFLAGS -!error You MUST call wmake with the -u switch! -!else -!ifdef %use_wincng -!include ..\Makefile.WinCNG.inc -!else -!include ..\Makefile.OpenSSL.inc -!endif -!include ..\Makefile.inc -!endif - -OBJS = $(CSOURCES:.c=.obj) -OBJS = $OBJ_DIR\$(OBJS: = $OBJ_DIR\) - -# -# Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN). -# -OBJ_DIR = $(OBJ_BASE)\stat -OBJS_STAT = $+ $(OBJS) $- - -OBJ_DIR = $(OBJ_BASE)\dyn -OBJS_DYN = $+ $(OBJS) $- - -RESOURCE = $(OBJ_BASE)\dyn\libssh2.res - -.c: ..\src - - -all: $(OBJ_BASE) $(TARGETS) .SYMBOLIC - @echo Welcome to libssh2 - -clean: .SYMBOLIC - -$(RM) $(OBJS_STAT) - -$(RM) $(OBJS_DYN) - -$(RM) $(RESOURCE) $(LINK_ARG) $(LIB_ARG) - -vclean realclean: clean .SYMBOLIC - -$(RM) $(TARGETS) $(LIBNAME).map $(LIBNAME).sym - -$(RD) $(OBJ_BASE)\stat - -$(RD) $(OBJ_BASE)\dyn - -$(RD) $(OBJ_BASE) - -$(OBJ_BASE): - -$(MD) $^@ - -$(MD) $^@\stat - -$(MD) $^@\dyn - -$(LIBNAME).dll: $(OBJS_DYN) $(RESOURCE) $(LINK_ARG) - $(LD) name $^@ @$]@ - -$(LIBNAME).lib: $(OBJS_STAT) $(LIB_ARG) - $(AR) -q -b -c $^@ @$]@ - -.ERASE -$(RESOURCE): libssh2.rc - $(RC) $(DEBUG) -q -r -zm -I..\include $(SYS_INCL) $[@ -fo=$^@ - -.ERASE -.c{$(OBJ_BASE)\dyn}.obj: - $(CC) $(CFLAGS) -bd -br $[@ -fo=$^@ - -.ERASE -.c{$(OBJ_BASE)\stat}.obj: - $(CC) $(CFLAGS) $[@ -fo=$^@ - -$(LINK_ARG): $(__MAKEFILES__) - %create $^@ - @%append $^@ system nt dll - @%append $^@ file { $(OBJS_DYN) } -!ifdef %debug - @%append $^@ debug all - @%append $^@ option symfile -!endif - @%append $^@ option quiet, map, caseexact, eliminate, implib=$(LIBNAME)_imp.lib, - @%append $^@ res=$(RESOURCE) libpath $(SYS_LIBS) -!ifdef %use_watt32 - @%append $^@ library $(%watt_root)\lib\wattcpw_imp.lib -!else - @%append $^@ library ws2_32.lib -!endif -!ifdef %use_zlib - @%append $^@ library '$(ZLIB_ROOT)\zlib.lib' -!endif -!ifndef %use_wincng - @%append $^@ library '$(OPENSSL_ROOT)\lib\crypt.lib' - @%append $^@ library '$(OPENSSL_ROOT)\lib\ssl.lib' -!endif -@%append $^@ library bcrypt.lib -@%append $^@ library crypt32.lib - -$(LIB_ARG): $(__MAKEFILES__) - %create $^@ - @for %f in ($(OBJS_STAT)) do @%append $^@ +- %f From 4e0f0ceeb3b5c54df58345bde48f976b12a11a63 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 07:59:24 +0000 Subject: [PATCH 173/424] checksrc: fix reference in Makefile.am, update options [ci skip] --- Makefile.am | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index f407ef7292..2ee78602ab 100644 --- a/Makefile.am +++ b/Makefile.am @@ -153,6 +153,13 @@ $(VCPROJ): win32/vc8proj.head win32/vc8proj.foot Makefile.am awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ ) checksrc: - perl src/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT \ - -AFOPENMODE -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \ + perl ci/checksrc.pl -i4 -m79 \ + -ASIZEOFNOPAREN \ + -ASNPRINTF \ + -ACOPYRIGHT \ + -AFOPENMODE \ + -AEQUALSNULL \ + -ANOTEQUALSZERO \ + -ATYPEDEFSTRUCT \ + -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \ tests/*.[ch] From 243e7a82f772c64858a7b4fa4816d76e2936d1eb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 14:58:07 +0200 Subject: [PATCH 174/424] build: delete MS Dev Studio build files (#891) Last updated in 2007. Also delete `VCPROJ` target remains (necessary files seem to have been missing from the repo all along) for Visual Studio 2008. --- .gitattribute | 2 - Makefile.am | 70 +----------- win32/.gitignore | 1 - win32/libssh2.dsw | 41 ------- win32/msvcproj.foot | 3 - win32/msvcproj.head | 256 -------------------------------------------- win32/tests.dsp | 102 ------------------ 7 files changed, 2 insertions(+), 473 deletions(-) delete mode 100644 .gitattribute delete mode 100644 win32/libssh2.dsw delete mode 100644 win32/msvcproj.foot delete mode 100644 win32/msvcproj.head delete mode 100644 win32/tests.dsp diff --git a/.gitattribute b/.gitattribute deleted file mode 100644 index bc501446c4..0000000000 --- a/.gitattribute +++ /dev/null @@ -1,2 +0,0 @@ -win32/msvcproj.head -crlf -win32/msvcproj.foot -crlf diff --git a/Makefile.am b/Makefile.am index 2ee78602ab..51b23ce3a7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,10 +21,7 @@ NETWAREFILES = nw/keepscreen.c \ nw/GNUmakefile \ nw/test/GNUmakefile -DSP = win32/libssh2.dsp -VCPROJ = win32/libssh2.vcproj - -DISTCLEANFILES = $(DSP) +DISTCLEANFILES = VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c \ @@ -32,8 +29,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ WIN32FILES = win32/GNUmakefile \ win32/libssh2_config.h win32/config.mk win32/rules.mk \ - win32/libssh2.dsw win32/tests.dsp $(DSP) \ - win32/msvcproj.head win32/msvcproj.foot win32/libssh2.rc + win32/libssh2.rc OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ os400/make-src.sh os400/make-rpg.sh os400/make-include.sh \ @@ -90,68 +86,6 @@ gen-coverage: coverage: init-coverage build-coverage gen-coverage -# DSP/VCPROJ generation adapted from libcurl -# only OpenSSL and WinCNG are supported with this build system -CRYPTO_CSOURCES = openssl.c wincng.c mbedtls.c -CRYPTO_HHEADERS = openssl.h wincng.h mbedtls.h -# Makefile.inc provides the CSOURCES and HHEADERS defines -include Makefile.inc - -WIN32SOURCES = $(CSOURCES) -WIN32HEADERS = $(HHEADERS) libssh2_config.h - -$(DSP): win32/msvcproj.head win32/msvcproj.foot Makefile.am - echo "creating $(DSP)" - -$(MKDIR_P) "`echo "$@" | sed 's@[/\\][^/\\]*$$@@'`" - @( (cat $(srcdir)/win32/msvcproj.head; \ - echo "# Begin Group \"Source Files\""; \ - echo ""; \ - echo "# PROP Default_Filter \"cpp;c;cxx\""; \ - win32_srcs='$(WIN32SOURCES)'; \ - sorted_srcs=`for file in $$win32_srcs; do echo $$file; done | sort`; \ - for file in $$sorted_srcs; do \ - echo "# Begin Source File"; \ - echo ""; \ - echo "SOURCE=..\\src\\"$$file; \ - echo "# End Source File"; \ - done; \ - echo "# End Group"; \ - echo "# Begin Group \"Header Files\""; \ - echo ""; \ - echo "# PROP Default_Filter \"h;hpp;hxx\""; \ - win32_hdrs='$(WIN32HEADERS)'; \ - sorted_hdrs=`for file in $$win32_hdrs; do echo $$file; done | sort`; \ - for file in $$sorted_hdrs; do \ - echo "# Begin Source File"; \ - echo ""; \ - if [ "$$file" = "libssh2_config.h" ]; then \ - echo "SOURCE=.\\"$$file; \ - else \ - echo "SOURCE=..\\src\\"$$file; \ - fi; \ - echo "# End Source File"; \ - done; \ - echo "# End Group"; \ - cat $(srcdir)/win32/msvcproj.foot) | \ - awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ ) - -$(VCPROJ): win32/vc8proj.head win32/vc8proj.foot Makefile.am - echo "creating $(VCPROJ)" - @( (cat $(srcdir)/vc8proj.head; \ - win32_srcs='$(WIN32SOURCES)'; \ - sorted_srcs=`for file in $$win32_srcs; do echo $$file; done | sort`; \ - for file in $$sorted_srcs; do \ - echo ""; \ - done; \ - echo ""; \ - win32_hdrs='$(WIN32HEADERS)'; \ - sorted_hdrs=`for file in $$win32_hdrs; do echo $$file; done | sort`; \ - for file in $$sorted_hdrs; do \ - echo ""; \ - done; \ - cat $(srcdir)/vc8proj.foot) | \ - awk '{printf("%s\r\n", gensub("\r", "", "g"))}' > $@ ) - checksrc: perl ci/checksrc.pl -i4 -m79 \ -ASIZEOFNOPAREN \ diff --git a/win32/.gitignore b/win32/.gitignore index 0afd7fd943..cfad4cf94b 100644 --- a/win32/.gitignore +++ b/win32/.gitignore @@ -10,5 +10,4 @@ Release *.ncb *.opt *.plg -libssh2.dsp objects.mk diff --git a/win32/libssh2.dsw b/win32/libssh2.dsw deleted file mode 100644 index 36ad8fc0f5..0000000000 --- a/win32/libssh2.dsw +++ /dev/null @@ -1,41 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "libssh2"=".\libssh2.dsp" - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "tests"=".\tests.dsp" - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/win32/msvcproj.foot b/win32/msvcproj.foot deleted file mode 100644 index 07defa465d..0000000000 --- a/win32/msvcproj.foot +++ /dev/null @@ -1,3 +0,0 @@ -# End Target -# End Project - diff --git a/win32/msvcproj.head b/win32/msvcproj.head deleted file mode 100644 index 67b5df2dda..0000000000 --- a/win32/msvcproj.head +++ /dev/null @@ -1,256 +0,0 @@ -# Microsoft Developer Studio Project File - Name="libssh2" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** -# only OpenSSL and WinCNG are supported with this build system - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=libssh2 - Win32 OpenSSL Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "libssh2.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "libssh2.mak" CFG="libssh2 - Win32 DLL Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "libssh2 - Win32 OpenSSL DLL Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "libssh2 - Win32 OpenSSL DLL Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "libssh2 - Win32 OpenSSL LIB Release" (based on "Win32 (x86) Static Library") -!MESSAGE "libssh2 - Win32 OpenSSL LIB Debug" (based on "Win32 (x86) Static Library") -!MESSAGE "libssh2 - Win32 WinCNG DLL Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "libssh2 - Win32 WinCNG DLL Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "libssh2 - Win32 WinCNG LIB Release" (based on "Win32 (x86) Static Library") -!MESSAGE "libssh2 - Win32 WinCNG LIB Debug" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "libssh2 - Win32 OpenSSL DLL Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release_dll" -# PROP BASE Intermediate_Dir "Release_dll" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_dll" -# PROP Intermediate_Dir "Release_dll" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib crypto.lib zlib.lib /nologo /dll /map /debug /machine:I386 - -!ELSEIF "$(CFG)" == "libssh2 - Win32 OpenSSL DLL Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug_dll" -# PROP BASE Intermediate_Dir "Debug_dll" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug_dll" -# PROP Intermediate_Dir "Debug_dll" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c -# SUBTRACT CPP /WX /YX -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib crypto.lib zlib.lib /nologo /dll /incremental:no /map /debug /machine:I386 /pdbtype:sept -# SUBTRACT LINK32 /nodefaultlib - -!ELSEIF "$(CFG)" == "libssh2 - Win32 OpenSSL LIB Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release_lib" -# PROP BASE Intermediate_Dir "Release_lib" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_lib" -# PROP Intermediate_Dir "Release_lib" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo -# ADD LIB32 /nologo /out:"Release_lib\libssh2.lib" - -!ELSEIF "$(CFG)" == "libssh2 - Win32 OpenSSL LIB Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug_lib" -# PROP BASE Intermediate_Dir "Debug_lib" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug_lib" -# PROP Intermediate_Dir "Debug_lib" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_OPENSSL" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"Debug_lib\libssh2d.lib" - -!ELSEIF "$(CFG)" == "libssh2 - Win32 WinCNG LIB Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release_dll" -# PROP BASE Intermediate_Dir "Release_dll" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_dll" -# PROP Intermediate_Dir "Release_dll" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib crypt32.lib bcrypt.lib /nologo /dll /map /debug /machine:I386 - -!ELSEIF "$(CFG)" == "libssh2 - Win32 WinCNG DLL Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug_dll" -# PROP BASE Intermediate_Dir "Debug_dll" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug_dll" -# PROP Intermediate_Dir "Debug_dll" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c -# SUBTRACT CPP /WX /YX -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 gdi32.lib advapi32.lib user32.lib kernel32.lib ws2_32.lib crypt32.lib bcrypt.lib /nologo /dll /incremental:no /map /debug /machine:I386 /pdbtype:sept -# SUBTRACT LINK32 /nodefaultlib - -!ELSEIF "$(CFG)" == "libssh2 - Win32 WinCNG LIB Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release_lib" -# PROP BASE Intermediate_Dir "Release_lib" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_lib" -# PROP Intermediate_Dir "Release_lib" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\win32" /I "..\include" /D "WIN32" /D "NDEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo -# ADD LIB32 /nologo /out:"Release_lib\libssh2.lib" - -!ELSEIF "$(CFG)" == "libssh2 - Win32 WinCNG LIB Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug_lib" -# PROP BASE Intermediate_Dir "Debug_lib" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug_lib" -# PROP Intermediate_Dir "Debug_lib" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\include" /D "WIN32" /D "_DEBUG" /D "LIBSSH2_WINCNG" /D "_MBCS" /D "_LIB" /D "LIBSSH2DEBUG" /YX /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"Debug_lib\libssh2d.lib" - -!ENDIF - -# Begin Target - -# Name "libssh2 - Win32 OpenSSL DLL Release" -# Name "libssh2 - Win32 OpenSSL DLL Debug" -# Name "libssh2 - Win32 OpenSSL LIB Release" -# Name "libssh2 - Win32 OpenSSL LIB Debug" -# Name "libssh2 - Win32 WinCNG DLL Release" -# Name "libssh2 - Win32 WinCNG DLL Debug" -# Name "libssh2 - Win32 WinCNG LIB Release" -# Name "libssh2 - Win32 WinCNG LIB Debug" - diff --git a/win32/tests.dsp b/win32/tests.dsp deleted file mode 100644 index 45d13c4d47..0000000000 --- a/win32/tests.dsp +++ /dev/null @@ -1,102 +0,0 @@ -# Microsoft Developer Studio Project File - Name="tests" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=tests - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "tests.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "tests.mak" CFG="tests - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "tests - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "tests - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "tests - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "tests___Win32_Release" -# PROP BASE Intermediate_Dir "tests___Win32_Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib crypto.lib ssl.lib ws2_32.lib zlib.lib libssh2.lib /nologo /subsystem:console /machine:I386 /libpath:"Release" /out:"simple.exe" - -!ELSEIF "$(CFG)" == "tests - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "tests___Win32_Debug" -# PROP BASE Intermediate_Dir "tests___Win32_Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\win32" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib crypto.lib ssl.lib ws2_32.lib zlib.lib libssh2d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept /libpath:"Debug" /out:"simple.exe" - -!ENDIF - -# Begin Target - -# Name "tests - Win32 Release" -# Name "tests - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\tests\simple.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project From 9cfb5816df4eeea6c109e223477e7aede18bbae7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 17:22:40 +0200 Subject: [PATCH 175/424] GNUmakefile: minor fix for DYN mode [ci skip] (#893) Follow-up to b8762c1003d97e109efa587bdc760ff9873949eb --- win32/GNUmakefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index bf2cfe22e9..7bf0ad35d9 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -55,15 +55,13 @@ LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32 LIBS_BIN := -lssh2 -lws2_32 ifdef DYN - libssh2_DEPENDENCIES += $(PROOT)/win32/libssh2.dll.a + libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a LIBSSH2_LDFLAGS_BIN += -shared else libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a LIBSSH2_LDFLAGS_BIN += -static endif -libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a - ### Optional features # must be equal to DEBUG or NDEBUG From 9e99a80ebf5159ac19a819cecf1cf1aa86c8e25b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 17:47:34 +0200 Subject: [PATCH 176/424] ci: bump mbedtls (#894) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f9c736128..8b8dd424d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: - name: Install mbedTLS Dependencies if: ${{ matrix.crypto_backend == 'mbedTLS' }} run: | - MBEDTLSVER=mbedtls-3.2.1 + MBEDTLSVER=mbedtls-3.4.0 curl -L https://github.com/Mbed-TLS/mbedtls/archive/$MBEDTLSVER.tar.gz | tar -xzf - cd mbedtls-$MBEDTLSVER cmake $TOOLCHAIN_OPTION -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=../usr . From 00005682f7b9a1aa42be50e269056ea873637047 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 17:49:38 +0200 Subject: [PATCH 177/424] detect and use explicit_bzero() and explicit_memset() (#895) Also skip detecting these and `memset_s()` for Windows targets in CMake, to save detection time. On Windows we always use `SecureZeroMemory()`. --- configure.ac | 2 +- src/CMakeLists.txt | 6 +++++- src/misc.h | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 1658c99916..c7f477676c 100644 --- a/configure.ac +++ b/configure.ac @@ -311,7 +311,7 @@ case $host in ;; esac -AC_CHECK_FUNCS(gettimeofday select strtoll memset_s snprintf) +AC_CHECK_FUNCS(gettimeofday select strtoll explicit_bzero explicit_memset memset_s snprintf) dnl Check for select() into ws2_32 for Msys/Mingw if test "$ac_cv_func_select" != "yes"; then diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6795825a44..b31194a9f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -263,7 +263,11 @@ if (NOT HAVE_STRTOLL) check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64) endif() check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) -check_symbol_exists(memset_s string.h HAVE_MEMSET_S) +if(NOT WIN32) + check_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO) + check_symbol_exists(explicit_memset string.h HAVE_EXPLICIT_MEMSET) + check_symbol_exists(memset_s string.h HAVE_MEMSET_S) +endif() if(MSVC AND ENABLE_WERROR) cmake_pop_check_state() diff --git a/src/misc.h b/src/misc.h index f7175b248c..1ec4f20b71 100644 --- a/src/misc.h +++ b/src/misc.h @@ -46,6 +46,10 @@ #else #ifdef WIN32 #define _libssh2_explicit_zero(buf, size) SecureZeroMemory(buf, size) +#elif defined(HAVE_EXPLICIT_BZERO) +#define _libssh2_explicit_zero(buf, size) explicit_bzero(buf, size) +#elif defined(HAVE_EXPLICIT_MEMSET) +#define _libssh2_explicit_zero(buf, size) (void)explicit_memset(buf, 0, size) #elif defined(HAVE_MEMSET_S) #define _libssh2_explicit_zero(buf, size) (void)memset_s(buf, size, 0, size) #else From 5a4d532ce5a9da227e600f764eb146658b117864 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 19:13:28 +0200 Subject: [PATCH 178/424] cmake: introduce variables for lib target names (#896) Make our CMake config more self-documenting by introducing variables for the shared and static lib target names. Without this, it might be non-trivial to find out which line is referring to a target name vs libname, export name or other occurrences of `libssh2`. This allows to rename back the shared lib target name to the value used before 4e2580628dd1f8dc51ac65ac747ebcf0e93fa3d1: `libssh2_shared` -> `libssh2`, if necessary for compatibility. Notice: before that patch, `libssh2` name referred to either the static or shared lib, depending on build settings. --- CMakeLists.txt | 7 +++++-- example/CMakeLists.txt | 2 +- src/CMakeLists.txt | 40 ++++++++++++++++++++-------------------- tests/CMakeLists.txt | 8 ++++---- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0274b7c8c2..e4670f7b87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,9 @@ if(NOT BUILD_STATIC_LIBS AND (NOT BUILD_SHARED_LIBS OR BUILD_EXAMPLES OR BUILD_T set(BUILD_STATIC_LIBS ON) endif() +set(LIB_STATIC "libssh2_static") +set(LIB_SHARED "libssh2_shared") # Must match libssh2_shared_EXPORTS macro in include/libssh2.h + add_subdirectory(src) if(BUILD_EXAMPLES) @@ -123,9 +126,9 @@ if(LINT) ./ci/checksrc.sh WORKING_DIRECTORY ${libssh2_SOURCE_DIR}) if(BUILD_STATIC_LIBS) - add_dependencies(libssh2_static lint) + add_dependencies(${LIB_STATIC} lint) else() - add_dependencies(libssh2_shared lint) + add_dependencies(${LIB_SHARED} lint) endif() endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 89d2e3bddc..41dfa51134 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -68,7 +68,7 @@ foreach(example ${EXAMPLES}) list(APPEND EXAMPLE_TARGETS example-${example}) # to find generated header target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) - target_link_libraries(example-${example} libssh2_static ${LIBRARIES}) + target_link_libraries(example-${example} ${LIB_STATIC} ${LIBRARIES}) endforeach() add_target_to_copy_dependencies( TARGET copy_example_dependencies diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b31194a9f2..128e4604ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -363,36 +363,36 @@ set(SOURCES # we want it to be called libssh2 on all platforms if(BUILD_STATIC_LIBS) - list(APPEND libssh2_export libssh2_static) - add_library(libssh2_static STATIC ${SOURCES}) - target_compile_definitions(libssh2_static PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) - target_link_libraries(libssh2_static PRIVATE ${LIBRARIES}) - set_target_properties(libssh2_static PROPERTIES PREFIX "" OUTPUT_NAME "libssh2${STATIC_LIB_SUFFIX}") + list(APPEND libssh2_export ${LIB_STATIC}) + add_library(${LIB_STATIC} STATIC ${SOURCES}) + target_compile_definitions(${LIB_STATIC} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) + target_link_libraries(${LIB_STATIC} PRIVATE ${LIBRARIES}) + set_target_properties(${LIB_STATIC} PROPERTIES PREFIX "" OUTPUT_NAME "libssh2${STATIC_LIB_SUFFIX}") - target_include_directories(libssh2_static + target_include_directories(${LIB_STATIC} PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} PUBLIC $ $/${CMAKE_INSTALL_INCLUDEDIR}>) endif() if(BUILD_SHARED_LIBS) - list(APPEND libssh2_export libssh2_shared) - add_library(libssh2_shared SHARED ${SOURCES}) + list(APPEND libssh2_export ${LIB_SHARED}) + add_library(${LIB_SHARED} SHARED ${SOURCES}) if(WIN32) - set_property(TARGET libssh2_shared APPEND PROPERTY SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) + set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) endif() - target_compile_definitions(libssh2_shared PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) - target_link_libraries(libssh2_shared PRIVATE ${LIBRARIES}) - set_target_properties(libssh2_shared PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") + target_compile_definitions(${LIB_SHARED} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) + target_link_libraries(${LIB_SHARED} PRIVATE ${LIBRARIES}) + set_target_properties(${LIB_SHARED} PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") if(WIN32 AND BUILD_STATIC_LIBS AND NOT STATIC_LIB_SUFFIX AND CMAKE_IMPORT_LIBRARY_SUFFIX STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX) # Extra suffix to avoid filename conflict with the static lib. - set_target_properties(libssh2_shared PROPERTIES IMPORT_SUFFIX "_imp${CMAKE_IMPORT_LIBRARY_SUFFIX}") + set_target_properties(${LIB_SHARED} PROPERTIES IMPORT_SUFFIX "_imp${CMAKE_IMPORT_LIBRARY_SUFFIX}") endif() - set_target_properties(libssh2_shared PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(${LIB_SHARED} PROPERTIES POSITION_INDEPENDENT_CODE ON) - target_include_directories(libssh2_shared + target_include_directories(${LIB_SHARED} PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} PUBLIC $ @@ -408,20 +408,20 @@ install(FILES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) if(BUILD_STATIC_LIBS) - install(TARGETS libssh2_static + install(TARGETS ${LIB_STATIC} EXPORT Libssh2Config RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() if(BUILD_SHARED_LIBS) - install(TARGETS libssh2_shared + install(TARGETS ${LIB_SHARED} EXPORT Libssh2Config RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - list(APPEND _RUNTIME_DEPENDENCIES $) + list(APPEND _RUNTIME_DEPENDENCIES $) endif() set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL @@ -456,12 +456,12 @@ install( set(LIBSSH2_SOVERSION 1) set(LIBSSH2_VERSION 1.0.1) if(BUILD_STATIC_LIBS) - set_target_properties(libssh2_static PROPERTIES + set_target_properties(${LIB_STATIC} PROPERTIES SOVERSION ${LIBSSH2_SOVERSION} VERSION ${LIBSSH2_VERSION}) endif() if(BUILD_SHARED_LIBS) - set_target_properties(libssh2_shared PROPERTIES + set_target_properties(${LIB_SHARED} PROPERTIES SOVERSION ${LIBSSH2_SOVERSION} VERSION ${LIBSSH2_VERSION}) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d17c8c61c0..128ea06c03 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -178,14 +178,14 @@ if(BUILD_SHARED_LIBS) set(test warmup) # any test will do add_executable(test_${test}_shared test_${test}.c) target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") - target_link_libraries(test_${test}_shared runner libssh2_shared ${LIBRARIES}) + target_link_libraries(test_${test}_shared runner ${LIB_SHARED} ${LIBRARIES}) endif() foreach(test ${TESTS}) add_executable(test_${test} test_${test}.c) list(APPEND TEST_TARGETS test_${test}) target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") - target_link_libraries(test_${test} runner libssh2_static ${LIBRARIES}) + target_link_libraries(test_${test} runner ${LIB_STATIC} ${LIBRARIES}) add_test( NAME test_${test} COMMAND $ @@ -239,9 +239,9 @@ endif() if(CMAKE_COMPILER_IS_GNUCC AND GCOV_PATH) target_compile_options(test_keyboard_interactive_auth_info_request BEFORE PRIVATE ${TGT_OPTIONS}) - target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2_static gcov) + target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} ${LIB_STATIC} gcov) else() - target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} libssh2_static) + target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} ${LIB_STATIC}) endif() add_test( NAME test_keyboard_interactive_auth_info_request COMMAND $ From da0584534f52960c53c7a2bf2b11da4550cf9432 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 28 Mar 2023 23:46:58 +0200 Subject: [PATCH 179/424] wolfssl: add workaround for HMAC_Update() len arg difference (#897) It's `int` in wolfSSL. `size_t` in OpenSSL/quictls/LibreSSL/BoringSSL. Ref: https://github.com/wolfSSL/wolfssl/blob/ba47562d182e10e59813da012e0ab8ef20892231/wolfssl/openssl/hmac.h#L60-L61 /cc @wolfSSL --- src/openssl.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/openssl.h b/src/openssl.h index 733366d6e3..c3d98f9ddd 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -315,8 +315,14 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define libssh2_hmac_sha512_init(ctx, key, keylen) \ HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL) +#ifdef LIBSSH2_WOLFSSL +/* FIXME: upstream bug as of v5.6.0: datalen is int instead of size_t */ +#define libssh2_hmac_update(ctx, data, datalen) \ + HMAC_Update(ctx, data, (int)datalen) +#else #define libssh2_hmac_update(ctx, data, datalen) \ HMAC_Update(ctx, data, datalen) +#endif /* LIBSSH2_WOLFSSL */ #define libssh2_hmac_final(ctx, data) HMAC_Final(ctx, data, NULL) #define libssh2_hmac_cleanup(ctx) HMAC_CTX_free(*(ctx)) #else From 84f5cb9f232a925e452229cae60950e0d5232200 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 29 Mar 2023 02:09:30 +0200 Subject: [PATCH 180/424] netware: delete support (#888) Last related commit happened 15 years ago. NetWare had it last release in 2009. All links referenced from the make file are inaccessible. --- Makefile.am | 7 +- include/libssh2.h | 10 - nw/GNUmakefile | 556 -------------------------------------------- nw/keepscreen.c | 23 -- nw/nwlib.c | 302 ------------------------ nw/test/GNUmakefile | 310 ------------------------ 6 files changed, 1 insertion(+), 1207 deletions(-) delete mode 100644 nw/GNUmakefile delete mode 100644 nw/keepscreen.c delete mode 100644 nw/nwlib.c delete mode 100644 nw/test/GNUmakefile diff --git a/Makefile.am b/Makefile.am index 51b23ce3a7..5fe3299033 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,11 +16,6 @@ include_HEADERS = \ include/libssh2_publickey.h \ include/libssh2_sftp.h -NETWAREFILES = nw/keepscreen.c \ - nw/nwlib.c \ - nw/GNUmakefile \ - nw/test/GNUmakefile - DISTCLEANFILES = VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ @@ -42,7 +37,7 @@ OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ os400/libssh2rpg/libssh2_sftp.rpgle \ Makefile.os400qc3.inc -EXTRA_DIST = $(WIN32FILES) $(NETWAREFILES) get_ver.awk \ +EXTRA_DIST = $(WIN32FILES) get_ver.awk \ maketgz NMakefile RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ CMakeLists.txt cmake git2news.pl libssh2-style.el README.md $(OS400FILES) \ buildconf diff --git a/include/libssh2.h b/include/libssh2.h index 9695763496..abc9f3b522 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -119,16 +119,6 @@ extern "C" { # include #endif -#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) -# include -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef int int32_t; -typedef unsigned long long uint64_t; -typedef long long int64_t; -#endif - #ifdef _MSC_VER typedef unsigned char uint8_t; typedef unsigned short int uint16_t; diff --git a/nw/GNUmakefile b/nw/GNUmakefile deleted file mode 100644 index 8519118646..0000000000 --- a/nw/GNUmakefile +++ /dev/null @@ -1,556 +0,0 @@ -######################################################################### -# -## Makefile for building libssh2 (NetWare version - gnu make) -## Use: make [help|all|clean|dev|devclean|dist|distclean|lib|nlm|objclean] -## -## Hacked by: Guenter Knauf -# -######################################################################### - -# Edit the path below to point to the base of your Novell NDK. -ifndef NDKBASE -NDKBASE = c:/novell -endif - -# Edit the path below to point to the base of your Zlib sources. -ifndef ZLIB_PATH -ZLIB_PATH = ../../zlib -endif - -# Edit the path below to point to the base of your OpenSSL package. -ifndef OPENSSL_PATH -OPENSSL_PATH = ../../openssl -endif - -# Edit the path below to point to your Distribution folder. -ifndef DISTDIR -DISTDIR = libssh2-$(LIBSSH2_VERSION_STR)-bin-nw -endif -DISTARC = $(DISTDIR).zip - -# Edit the path below to point to your Development folder. -ifndef DEVLDIR -DEVLDIR = libssh2-$(LIBSSH2_VERSION_STR)-dev-nw -endif -DEVLARC = $(DEVLDIR).zip - -# Edit the vars below to change NLM target settings. -TARGET = libssh2 -VERSION = $(LIBSSH2_VERSION) -CPRIGHT = Copyright (c) $(LIBSSH2_COPYRIGHT_STR) -WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) -MTSAFE = YES -STACK = 64000 -SCREEN = none -EXPORTS = @$(TARGET).imp - -# Edit the var below to point to your lib architecture. -ifndef LIBARCH -LIBARCH = LIBC -endif - -# must be equal to DEBUG or NDEBUG -ifndef DB - DB = NDEBUG -# DB = DEBUG -endif -# Optimization: -O or debugging: -g -ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release -else - OPT = -g - OPT += -DLIBSSH2DEBUG - OBJDIR = debug -endif - -# The following lines defines your compiler. -ifdef CWFolder - METROWERKS = $(CWFolder) -endif -ifdef METROWERKS -# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support - MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support - CC = mwccnlm -else - CC = $(CROSSPREFIX)gcc -endif - -# Here you can find a native Win32 binary of the original awk: -# http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk -# If you want to mark the target as MTSAFE you will need a tool for -# generating the xdc data for the linker; here's a minimal tool: -# http://www.gknw.net/development/prgtools/mkxdc.zip -MPKXDC = mkxdc -ZIP = zip -qzr9 - -# Platform-dependent helper tool macros -ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' -else -ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) -else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) -endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. -endif - -# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH)) -LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH)) - -# Include the version info retrieved from libssh2.h --include $(OBJDIR)/version.inc - -# Global flags for all compilers -CFLAGS += $(OPT) -D$(DB) -DNETWARE -nostdinc -#CFLAGS += -DHAVE_CONFIG_H - -ifeq ($(CC),mwccnlm) -LD = mwldnlm -LDFLAGS = -nostdlib $(PRELUDE) $(OBJL) -o $@ -commandfile -AR = mwldnlm -ARFLAGS = -nostdlib -type library -o -LIBEXT = lib -CFLAGS += -msgstyle gcc -gccinc -inline on -opt nointrinsics -proc 586 -CFLAGS += -relax_pointers -#CFLAGS += -w on -ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.o - CFLAGS += -align 4 -else -# PRELUDE = $(SDK_CLIB)/imports/clibpre.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" -# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" - CFLAGS += -align 1 -endif -else -LD = $(CROSSPREFIX)nlmconv -LDFLAGS = -UT -AR = $(CROSSPREFIX)ar -ARFLAGS = -cq -LIBEXT = a -RANLIB = $(CROSSPREFIX)ranlib -CFLAGS += -m32 -CFLAGS += -fno-builtin -fpcc-struct-return -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall # -pedantic -#CFLAGS += -Wno-pointer-sign -ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o -else -# PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - # http://www.gknw.net/development/mk_nlm/gcc_pre.zip - PRELUDE = $(NDK_ROOT)/pre/prelude.o - CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h -endif -endif - -LDLIBS = - -NDK_ROOT = $(NDKBASE)/ndk -SDK_CLIB = $(NDK_ROOT)/nwsdk -SDK_LIBC = $(NDK_ROOT)/libc -SNPRINTF = $(NDKBASE)/snprintf - -INCLUDES = -I. -I../include - -ifdef WITH_ZLIB - INCLUDES += -I$(ZLIB_PATH) -ifdef LINK_STATIC - LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) -else - MODULES += libz.nlm - IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp -endif -endif -INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) -LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT) -LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) -IMPORTS += GetProcessSwitchCount RunningProcess - -ifeq ($(LIBARCH),LIBC) - INCLUDES += -I$(SDK_LIBC)/include -# INCLUDES += -I$(SDK_LIBC)/include/nks -# INCLUDES += -I$(SDK_LIBC)/include/winsock - CFLAGS += -D_POSIX_SOURCE -else - INCLUDES += -I$(SDK_CLIB)/include/nlm -# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete -# INCLUDES += -I$(SDK_CLIB)/include -endif -CFLAGS += $(INCLUDES) - -ifeq ($(MTSAFE),YES) - XDCOPT = -n -endif -ifeq ($(MTSAFE),NO) - XDCOPT = -u -endif -ifdef XDCOPT - XDCDATA = $(OBJDIR)/$(TARGET).xdc -endif - -vpath %.c . ../src - -# only OpenSSL is supported with this build system -CFLAGS += -DLIBSSH2_OPENSSL -include ../Makefile.OpenSSL.inc - -# include Makefile.inc to get CSOURCES define -include ../Makefile.inc - -OBJECTS := $(patsubst %.c,%.o,$(CSOURCES)) -ifeq ($(LIBARCH),CLIB) -# CLIB lacks of snprint() function - here's a replacement: -# https://www.ijs.si/software/snprintf/ -OBJECTS += snprintf.o -vpath %.c $(SNPRINTF) -endif - -OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS)) -OBJL = $(OBJS) $(OBJDIR)/nwlib.o $(LDLIBS) - -all: lib nlm - -nlm: prebuild $(TARGET).nlm - -lib: prebuild $(TARGET).$(LIBEXT) - -prebuild: $(OBJDIR) $(OBJDIR)/version.inc libssh2_config.h - -test: all - $(MAKE) -C test - -$(OBJDIR)/%.o: %.c -# @echo Compiling $< - $(CC) $(CFLAGS) -c $< -o $@ - -$(OBJDIR)/version.inc: ../get_ver.awk ../include/libssh2.h $(OBJDIR) - @echo Creating $@ - @$(AWK) -f $^ > $@ - -dist: all $(DISTDIR) $(DISTDIR)/readme.txt - @$(call MKDIR, $(DISTDIR)/bin) - @$(call COPY, ../AUTHORS, $(DISTDIR)) - @$(call COPY, ../COPYING, $(DISTDIR)) - @$(call COPY, ../INSTALL, $(DISTDIR)) - @$(call COPY, ../README, $(DISTDIR)) - @$(call COPY, ../RELEASE-NOTES, $(DISTDIR)) - @$(call COPY, $(TARGET).nlm, $(DISTDIR)/bin) - @echo Creating $(DISTARC) - @$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt - -dev: all $(DEVLDIR) $(DEVLDIR)/readme.txt - @$(call MKDIR, $(DEVLDIR)/bin) - @$(call MKDIR, $(DEVLDIR)/include) - @$(call MKDIR, $(DEVLDIR)/nw) - @$(call COPY, ../AUTHORS, $(DEVLDIR)) - @$(call COPY, ../COPYING, $(DEVLDIR)) - @$(call COPY, ../INSTALL, $(DEVLDIR)) - @$(call COPY, ../README, $(DEVLDIR)) - @$(call COPY, ../RELEASE-NOTES, $(DEVLDIR)) - @$(call COPY, ../include/*.h, $(DEVLDIR)/include) - @$(call COPY, libssh2_config.h, $(DEVLDIR)/include) - @$(call COPY, $(TARGET).nlm, $(DEVLDIR)/bin) - @$(call COPY, $(TARGET).imp, $(DEVLDIR)/nw) - @$(call COPY, $(TARGET).$(LIBEXT), $(DEVLDIR)/nw) - @echo Creating $(DEVLARC) - @$(ZIP) $(DEVLARC) $(DEVLDIR)/* < $(DEVLDIR)/readme.txt - -distclean: clean - $(call RMDIR, $(DISTDIR)) - $(call DEL, $(DISTARC)) - -devclean: clean - $(call RMDIR, $(DEVLDIR)) - $(call DEL, $(DEVLARC)) - -objclean: - $(call RMDIR, $(OBJDIR)) - -testclean: clean - $(MAKE) -C test clean - -clean: objclean - $(call DEL, libssh2_config.h) - $(call DEL, $(TARGET).*) - -$(OBJDIR): - @$(call MKDIR, $@) - -$(DISTDIR): - @$(call MKDIR, $@) - -$(DEVLDIR): - @$(call MKDIR, $@) - -$(TARGET).$(LIBEXT): $(OBJS) - @echo Creating $@ - @$(call DEL, $@) - @$(AR) $(ARFLAGS) $@ $^ -ifdef RANLIB - @$(RANLIB) $@ -endif - -$(TARGET).nlm: $(OBJDIR)/$(TARGET).def $(TARGET).imp $(OBJL) $(XDCDATA) - @echo Linking $@ - @$(call DEL, $@) - @$(LD) $(LDFLAGS) $< - -$(OBJDIR)/%.xdc: GNUmakefile - @echo Creating $@ - @$(MPKXDC) $(XDCOPT) $@ - -$(OBJDIR)/%.def: GNUmakefile - @echo $(DL)# DEF file for linking with $(LD)$(DL) > $@ - @echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@ - @echo $(DL)# All your changes will be lost!!$(DL) >> $@ - @echo $(DL)#$(DL) >> $@ - @echo $(DL)copyright "$(CPRIGHT)"$(DL) >> $@ - @echo $(DL)description "$(DESCR)"$(DL) >> $@ - @echo $(DL)version $(VERSION)$(DL) >> $@ -ifdef NLMTYPE - @echo $(DL)type $(NLMTYPE)$(DL) >> $@ -endif -ifdef STACK - @echo $(DL)stack $(STACK)$(DL) >> $@ -endif -ifdef SCREEN - @echo $(DL)screenname "$(SCREEN)"$(DL) >> $@ -else - @echo $(DL)screenname "DEFAULT"$(DL) >> $@ -endif -ifeq ($(DB),DEBUG) - @echo $(DL)debug$(DL) >> $@ -endif - @echo $(DL)threadname "$(TARGET)"$(DL) >> $@ -ifdef XDCDATA - @echo $(DL)xdcdata $(XDCDATA)$(DL) >> $@ -endif - @echo $(DL)flag_on 64$(DL) >> $@ -ifeq ($(LIBARCH),CLIB) - @echo $(DL)start _Prelude$(DL) >> $@ - @echo $(DL)exit _Stop$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/clib.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/threads.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/nlmlib.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/socklib.imp$(DL) >> $@ - @echo $(DL)module clib$(DL) >> $@ -else - @echo $(DL)pseudopreemption$(DL) >> $@ - @echo $(DL)start _LibCPrelude$(DL) >> $@ - @echo $(DL)exit _LibCPostlude$(DL) >> $@ - @echo $(DL)check _LibCCheckUnload$(DL) >> $@ - @echo $(DL)import @$(SDK_LIBC)/imports/libc.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_LIBC)/imports/netware.imp$(DL) >> $@ - @echo $(DL)module libc$(DL) >> $@ -endif -ifdef MODULES - @echo $(DL)module $(MODULES)$(DL) >> $@ -endif -ifdef EXPORTS - @echo $(DL)export $(EXPORTS)$(DL) >> $@ -endif -ifdef IMPORTS - @echo $(DL)import $(IMPORTS)$(DL) >> $@ -endif -ifeq ($(LD),nlmconv) - @echo $(DL)input $(OBJL)$(DL) >> $@ - @echo $(DL)input $(PRELUDE)$(DL) >> $@ - @echo $(DL)output $(TARGET).nlm$(DL) >> $@ -endif - -libssh2_config.h: GNUmakefile - @echo Creating $@ - @echo $(DL)/* $@ for NetWare target.$(DL) > $@ - @echo $(DL)** Do not edit this file - it is created by make!$(DL) >> $@ - @echo $(DL)** All your changes will be lost!!$(DL) >> $@ - @echo $(DL)*/$(DL) >> $@ - @echo $(DL)#define VERSION "$(LIBSSH2_VERSION_STR)"$(DL) >> $@ - @echo $(DL)#define PACKAGE_BUGREPORT "https://github.com/libssh2/libssh2/issues"$(DL) >> $@ -ifeq ($(LIBARCH),CLIB) - @echo $(DL)#define OS "i586-pc-clib-NetWare"$(DL) >> $@ - @echo $(DL)#define NETDB_USE_INTERNET 1$(DL) >> $@ - @echo $(DL)#define socklen_t int$(DL) >> $@ - @echo $(DL)#define sleep(s) delay(1000 * s)$(DL) >> $@ -else - @echo $(DL)#define OS "i586-pc-libc-NetWare"$(DL) >> $@ - @echo $(DL)#define HAVE_GETTIMEOFDAY 1$(DL) >> $@ - @echo $(DL)#define HAVE_INTTYPES_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_LONGLONG 1$(DL) >> $@ - @echo $(DL)#define HAVE_STDINT_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_STRTOLL 1$(DL) >> $@ - @echo $(DL)#define HAVE_SYS_PARAM_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SYS_SELECT_H 1$(DL) >> $@ -endif - @echo $(DL)#define HAVE_SNPRINTF 1$(DL) >> $@ - @echo $(DL)#define HAVE_ARPA_INET_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_FIONBIO 1$(DL) >> $@ - @echo $(DL)#define HAVE_NETINET_IN_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SELECT 1$(DL) >> $@ - @echo $(DL)#define HAVE_STDLIB_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SYS_IOCTL_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_SYS_TIME_H 1$(DL) >> $@ - @echo $(DL)#define HAVE_UNISTD_H 1$(DL) >> $@ - @echo $(DL)#define STDC_HEADERS 1$(DL) >> $@ - @echo $(DL)#define HAVE_O_NONBLOCK 1$(DL) >> $@ -ifdef WITH_ZLIB - @echo $(DL)#define LIBSSH2_HAVE_ZLIB 1$(DL) >> $@ -endif -ifndef NW_WINSOCK - @echo $(DL)#define HAVE_SYS_SOCKET_H 1$(DL) >> $@ -endif -ifdef OLD_NOVELLSDK - @echo $(DL)#define socklen_t int$(DL) >> $@ -endif -ifeq ($(DB),DEBUG) - @echo $(DL)#define LIBSSH2_DEBUG_CONNECTION 1$(DL) >> $@ - @echo $(DL)#define LIBSSH2_DEBUG_ERRORS 1$(DL) >> $@ - @echo $(DL)#define LIBSSH2_DEBUG_KEX 1$(DL) >> $@ - @echo $(DL)#define LIBSSH2_DEBUG_PUBLICKEY 1$(DL) >> $@ - @echo $(DL)#define LIBSSH2_DEBUG_SCP 1$(DL) >> $@ - @echo $(DL)#define LIBSSH2_DEBUG_SFTP 1$(DL) >> $@ - @echo $(DL)#define LIBSSH2_DEBUG_TRANSPORT 1$(DL) >> $@ - @echo $(DL)#define LIBSSH2_DEBUG_USERAUTH 1$(DL) >> $@ -endif - -libssh2.imp: GNUmakefile - @echo Creating $@ - @echo $(DL)# $@ for NetWare target.$(DL) > $@ - @echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@ - @echo $(DL)# All your changes will be lost!!$(DL) >> $@ -ifeq ($(LIBARCH),CLIB) - @echo $(DL) (CLIB_LIBSSH2)$(DL) >> $@ -else - @echo $(DL) (LIBC_LIBSSH2)$(DL) >> $@ -endif - @echo $(DL) libssh2_banner_set,$(DL) >> $@ - @echo $(DL) libssh2_channel_close,$(DL) >> $@ - @echo $(DL) libssh2_channel_direct_tcpip_ex,$(DL) >> $@ - @echo $(DL) libssh2_channel_eof,$(DL) >> $@ - @echo $(DL) libssh2_channel_flush_ex,$(DL) >> $@ - @echo $(DL) libssh2_channel_free,$(DL) >> $@ - @echo $(DL) libssh2_channel_get_exit_status,$(DL) >> $@ - @echo $(DL) libssh2_channel_open_ex,$(DL) >> $@ - @echo $(DL) libssh2_channel_process_startup,$(DL) >> $@ - @echo $(DL) libssh2_channel_read_ex,$(DL) >> $@ - @echo $(DL) libssh2_channel_request_pty_ex,$(DL) >> $@ - @echo $(DL) libssh2_channel_send_eof,$(DL) >> $@ - @echo $(DL) libssh2_channel_set_blocking,$(DL) >> $@ - @echo $(DL) libssh2_channel_setenv_ex,$(DL) >> $@ - @echo $(DL) libssh2_channel_wait_closed,$(DL) >> $@ - @echo $(DL) libssh2_channel_wait_eof,$(DL) >> $@ - @echo $(DL) libssh2_channel_write_ex,$(DL) >> $@ - @echo $(DL) libssh2_exit,$(DL) >> $@ - @echo $(DL) libssh2_hostkey_hash,$(DL) >> $@ - @echo $(DL) libssh2_init,$(DL) >> $@ - @echo $(DL) libssh2_knownhost_add,$(DL) >> $@ - @echo $(DL) libssh2_knownhost_check,$(DL) >> $@ - @echo $(DL) libssh2_knownhost_checkp,$(DL) >> $@ - @echo $(DL) libssh2_knownhost_free,$(DL) >> $@ - @echo $(DL) libssh2_knownhost_init,$(DL) >> $@ - @echo $(DL) libssh2_knownhost_readfile,$(DL) >> $@ - @echo $(DL) libssh2_knownhost_writefile,$(DL) >> $@ - @echo $(DL) libssh2_scp_recv,$(DL) >> $@ - @echo $(DL) libssh2_scp_recv2,$(DL) >> $@ - @echo $(DL) libssh2_scp_send64,$(DL) >> $@ - @echo $(DL) libssh2_scp_send_ex,$(DL) >> $@ - @echo $(DL) libssh2_session_abstract,$(DL) >> $@ - @echo $(DL) libssh2_session_block_directions,$(DL) >> $@ - @echo $(DL) libssh2_session_callback_set,$(DL) >> $@ - @echo $(DL) libssh2_session_disconnect_ex,$(DL) >> $@ - @echo $(DL) libssh2_session_free,$(DL) >> $@ - @echo $(DL) libssh2_session_handshake,$(DL) >> $@ - @echo $(DL) libssh2_session_hostkey,$(DL) >> $@ - @echo $(DL) libssh2_session_init_ex,$(DL) >> $@ - @echo $(DL) libssh2_session_last_errno,$(DL) >> $@ - @echo $(DL) libssh2_session_last_error,$(DL) >> $@ - @echo $(DL) libssh2_session_method_pref,$(DL) >> $@ - @echo $(DL) libssh2_session_methods,$(DL) >> $@ - @echo $(DL) libssh2_session_set_blocking,$(DL) >> $@ - @echo $(DL) libssh2_session_startup,$(DL) >> $@ - @echo $(DL) libssh2_sftp_close_handle,$(DL) >> $@ - @echo $(DL) libssh2_sftp_fstat_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_init,$(DL) >> $@ - @echo $(DL) libssh2_sftp_last_error,$(DL) >> $@ - @echo $(DL) libssh2_sftp_mkdir_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_open_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_read,$(DL) >> $@ - @echo $(DL) libssh2_sftp_readdir_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_rename_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_rmdir_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_seek,$(DL) >> $@ - @echo $(DL) libssh2_sftp_seek64,$(DL) >> $@ - @echo $(DL) libssh2_sftp_shutdown,$(DL) >> $@ - @echo $(DL) libssh2_sftp_stat_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_symlink_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_tell,$(DL) >> $@ - @echo $(DL) libssh2_sftp_unlink_ex,$(DL) >> $@ - @echo $(DL) libssh2_sftp_write,$(DL) >> $@ - @echo $(DL) libssh2_trace,$(DL) >> $@ - @echo $(DL) libssh2_userauth_authenticated,$(DL) >> $@ - @echo $(DL) libssh2_userauth_keyboard_interactive_ex,$(DL) >> $@ - @echo $(DL) libssh2_userauth_list,$(DL) >> $@ - @echo $(DL) libssh2_userauth_password_ex,$(DL) >> $@ - @echo $(DL) libssh2_userauth_publickey_fromfile_ex,$(DL) >> $@ - @echo $(DL) libssh2_version$(DL) >> $@ - -$(DISTDIR)/readme.txt: GNUmakefile - @echo Creating $@ - @echo $(DL)This is a binary distribution for NetWare platform.$(DL) > $@ - @echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@ - @echo $(DL)Please download the complete libssh package for$(DL) >> $@ - @echo $(DL)any further documentation:$(DL) >> $@ - @echo $(DL)$(WWWURL)$(DL) >> $@ - -$(DEVLDIR)/readme.txt: GNUmakefile - @echo Creating $@ - @echo $(DL)This is a development distribution for NetWare platform.$(DL) > $@ - @echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@ - @echo $(DL)Please download the complete libssh2 package for$(DL) >> $@ - @echo $(DL)any further documentation:$(DL) >> $@ - @echo $(DL)$(WWWURL)$(DL) >> $@ - -help: $(OBJDIR)/version.inc - @echo $(DL)===========================================================$(DL) -ifeq ($(LIBARCH),LIBC) - @echo $(DL)Novell LibC NDK = $(SDK_LIBC)$(DL) -else - @echo $(DL)Novell CLib NDK = $(SDK_CLIB)$(DL) -endif - @echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL) - @echo $(DL)Zlib path = $(ZLIB_PATH)$(DL) - @echo $(DL)===========================================================$(DL) - @echo $(DL)libssh $(LIBSSH2_VERSION_STR) - available targets are:$(DL) - @echo $(DL)$(MAKE) all$(DL) - @echo $(DL)$(MAKE) nlm$(DL) - @echo $(DL)$(MAKE) lib$(DL) - @echo $(DL)$(MAKE) clean$(DL) - @echo $(DL)$(MAKE) dev$(DL) - @echo $(DL)$(MAKE) devclean$(DL) - @echo $(DL)$(MAKE) dist$(DL) - @echo $(DL)$(MAKE) distclean$(DL) - @echo $(DL)$(MAKE) objclean$(DL) - @echo $(DL)$(MAKE) test$(DL) - @echo $(DL)===========================================================$(DL) diff --git a/nw/keepscreen.c b/nw/keepscreen.c deleted file mode 100644 index ae53dc5fee..0000000000 --- a/nw/keepscreen.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Simple _NonAppStop() implementation which can be linked to your - * NLM in order to keep the screen open when the NLM terminates - * (the good old clib behaviour). - * You dont have to call it, its done automatically from LibC. - * - * 2004-Aug-11 by Guenter Knauf - * - * URL: http://www.gknw.net/development/mk_nlm/ - */ - -#include -#include - -void _NonAppStop() -{ - uint16_t row, col; - - GetScreenSize(&row, &col); - gotorowcol(row-1, 0); - /* pressanykey(); */ - printf(" "); - getcharacter(); -} diff --git a/nw/nwlib.c b/nw/nwlib.c deleted file mode 100644 index fe8377b31d..0000000000 --- a/nw/nwlib.c +++ /dev/null @@ -1,302 +0,0 @@ -/********************************************************************* - * Universal NetWare library stub. * - * written by Ulrich Neuman and given to OpenSource copyright-free. * - * Extended for CLIB support by Guenter Knauf. * - *********************************************************************/ - -#ifdef NETWARE /* Novell NetWare */ - -#include - -#ifdef __NOVELL_LIBC__ -/* For native LibC-based NLM we need to register as a real lib. */ -#include -#include -#include -#include -#include -#include -#include - -typedef struct -{ - int _errno; - void *twentybytes; -} libthreaddata_t; - -typedef struct -{ - int x; - int y; - int z; - void *tenbytes; - NXKey_t perthreadkey; /* if -1, no key obtained... */ - NXMutex_t *lock; -} libdata_t; - -int gLibId = -1; -void *gLibHandle = (void *) NULL; -rtag_t gAllocTag = (rtag_t) NULL; -NXMutex_t *gLibLock = (NXMutex_t *) NULL; - -/* internal library function prototypes... */ -int DisposeLibraryData ( void * ); -void DisposeThreadData ( void * ); -int GetOrSetUpData ( int id, libdata_t **data, libthreaddata_t **threaddata ); - - -int _NonAppStart( void *NLMHandle, - void *errorScreen, - const char *cmdLine, - const char *loadDirPath, - size_t uninitializedDataLength, - void *NLMFileHandle, - int (*readRoutineP)( int conn, - void *fileHandle, size_t offset, - size_t nbytes, - size_t *bytesRead, - void *buffer ), - size_t customDataOffset, - size_t customDataSize, - int messageCount, - const char **messages ) -{ - NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0); - -#ifndef __GNUC__ -#pragma unused(cmdLine) -#pragma unused(loadDirPath) -#pragma unused(uninitializedDataLength) -#pragma unused(NLMFileHandle) -#pragma unused(readRoutineP) -#pragma unused(customDataOffset) -#pragma unused(customDataSize) -#pragma unused(messageCount) -#pragma unused(messages) -#endif - -/* -** Here we process our command line, post errors (to the error screen), -** perform initializations and anything else we need to do before being able -** to accept calls into us. If we succeed, we return non-zero and the NetWare -** Loader will leave us up, otherwise we fail to load and get dumped. -*/ - gAllocTag = AllocateResourceTag(NLMHandle, - " memory allocations", AllocSignature); - - if (!gAllocTag) { - OutputToScreen(errorScreen, "Unable to allocate resource tag for " - "library memory allocations.\n"); - return -1; - } - - gLibId = register_library(DisposeLibraryData); - - if (gLibId < -1) { - OutputToScreen(errorScreen, "Unable to register library with kernel.\n"); - return -1; - } - - gLibHandle = NLMHandle; - - gLibLock = NXMutexAlloc(0, 0, &liblock); - - if (!gLibLock) { - OutputToScreen(errorScreen, "Unable to allocate library data lock.\n"); - return -1; - } - - return 0; -} - -/* -** Here we clean up any resources we allocated. Resource tags is a big part -** of what we created, but NetWare doesn't ask us to free those. -*/ -void _NonAppStop( void ) -{ - (void) unregister_library(gLibId); - NXMutexFree(gLibLock); -} - -/* -** This function cannot be the first in the file for if the file is linked -** first, then the check-unload function's offset will be nlmname.nlm+0 -** which is how to tell that there isn't one. When the check function is -** first in the linked objects, it is ambiguous. For this reason, we will -** put it inside this file after the stop function. -** -** Here we check to see if it's alright to ourselves to be unloaded. If not, -** we return a non-zero value. Right now, there isn't any reason not to allow -** it. -*/ -int _NonAppCheckUnload( void ) -{ - return 0; -} - -int GetOrSetUpData(int id, libdata_t **appData, libthreaddata_t **threadData) -{ - int err; - libdata_t *app_data; - libthreaddata_t *thread_data; - NXKey_t key; - NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0); - - err = 0; - thread_data = (libthreaddata_t *) NULL; - -/* -** Attempt to get our data for the application calling us. This is where we -** store whatever application-specific information we need to carry in support -** of calling applications. -*/ - app_data = (libdata_t *) get_app_data(id); - - if (!app_data) { -/* -** This application hasn't called us before; set up application AND per-thread -** data. Of course, just in case a thread from this same application is calling -** us simultaneously, we better lock our application data-creation mutex. We -** also need to recheck for data after we acquire the lock because WE might be -** that other thread that was too late to create the data and the first thread -** in will have created it. -*/ - NXLock(gLibLock); - - if (!(app_data = (libdata_t *) get_app_data(id))) { - app_data = (libdata_t *) malloc(sizeof(libdata_t)); - - if (app_data) { - memset(app_data, 0, sizeof(libdata_t)); - - app_data->tenbytes = malloc(10); - app_data->lock = NXMutexAlloc(0, 0, &liblock); - - if (!app_data->tenbytes || !app_data->lock) { - if (app_data->lock) - NXMutexFree(app_data->lock); - - free(app_data); - app_data = (libdata_t *) NULL; - err = ENOMEM; - } - - if (app_data) { -/* -** Here we burn in the application data that we were trying to get by calling -** get_app_data(). Next time we call the first function, we'll get this data -** we're just now setting. We also go on here to establish the per-thread data -** for the calling thread, something we'll have to do on each application -** thread the first time it calls us. -*/ - err = set_app_data(gLibId, app_data); - - if (err) { - free(app_data); - app_data = (libdata_t *) NULL; - err = ENOMEM; - } - else { - /* create key for thread-specific data... */ - err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); - - if (err) /* (no more keys left?) */ - key = -1; - - app_data->perthreadkey = key; - } - } - } - } - - NXUnlock(gLibLock); - } - - if (app_data) { - key = app_data->perthreadkey; - - if (key != -1 /* couldn't create a key? no thread data */ - && !(err = NXKeyGetValue(key, (void **) &thread_data)) - && !thread_data) { -/* -** Allocate the per-thread data for the calling thread. Regardless of whether -** there was already application data or not, this may be the first call by a -** a new thread. The fact that we allocation 20 bytes on a pointer is not very -** important, this just helps to demonstrate that we can have arbitrarily -** complex per-thread data. -*/ - thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t)); - - if (thread_data) { - thread_data->_errno = 0; - thread_data->twentybytes = malloc(20); - - if (!thread_data->twentybytes) { - free(thread_data); - thread_data = (libthreaddata_t *) NULL; - err = ENOMEM; - } - - if ((err = NXKeySetValue(key, thread_data))) { - free(thread_data->twentybytes); - free(thread_data); - thread_data = (libthreaddata_t *) NULL; - } - } - } - } - - if (appData) - *appData = app_data; - - if (threadData) - *threadData = thread_data; - - return err; -} - -int DisposeLibraryData( void *data ) -{ - if (data) { - void *tenbytes = ((libdata_t *) data)->tenbytes; - - if (tenbytes) - free(tenbytes); - - free(data); - } - - return 0; -} - -void DisposeThreadData( void *data ) -{ - if (data) { - void *twentybytes = ((libthreaddata_t *) data)->twentybytes; - - if (twentybytes) - free(twentybytes); - - free(data); - } -} - -#else /* __NOVELL_LIBC__ */ -/* For native CLib-based NLM seems we can do a bit more simple. */ -#include - -int main ( void ) -{ - /* initialize any globals here... */ - - /* do this if any global initializing was done - SynchronizeStart(); - */ - ExitThread (TSR_THREAD, 0); - return 0; -} - -#endif /* __NOVELL_LIBC__ */ - -#endif /* NETWARE */ diff --git a/nw/test/GNUmakefile b/nw/test/GNUmakefile deleted file mode 100644 index b00936b86b..0000000000 --- a/nw/test/GNUmakefile +++ /dev/null @@ -1,310 +0,0 @@ -######################################################################### -# -## Makefile for building libssh2 (NetWare version - gnu make) -## -## Hacked by: Guenter Knauf -# -######################################################################### - -# Edit the path below to point to the base of your Novell NDK. -ifndef NDKBASE -NDKBASE = c:/novell -endif - -# Edit the path below to point to the base of your Zlib sources. -ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib -endif - -# Edit the path below to point to the base of your OpenSSL package. -ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl -endif - -# Edit the var below to enable static linking of libssh2 and libz -LINK_STATIC = 1 - -# Edit the vars below to change NLM target settings. -SAMPLES = ../../example -TARGETS := $(filter-out x11.nlm,$(patsubst $(SAMPLES)/%.c,%.nlm,$(strip $(wildcard $(SAMPLES)/*.c)))) -VERSION = $(LIBSSH2_VERSION) -COPYR = Copyright (c) $(LIBSSH2_COPYRIGHT_STR) -WWWURL = https://www.libssh2.org/ -DESCR = libssh2 $(notdir $(@:.def=)) $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) -MTSAFE = YES -STACK = 64000 -SCREEN = NONE -#SCREEN = libssh2 $(notdir $(@:.def=)) -# Comment the line below if you dont want to load protected automatically. -#LDRING = 3 - -# Edit the var below to point to your lib architecture. -ifndef LIBARCH -LIBARCH = LIBC -endif - -# must be equal to DEBUG or NDEBUG -ifndef DB - DB = NDEBUG -# DB = DEBUG -endif -# Optimization: -O or debugging: -g -ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release -else - OPT = -g - OPT += -DLIBSSH2DEBUG - OBJDIR = debug -endif - -# The following lines defines your compiler. -ifdef CWFolder - METROWERKS = $(CWFolder) -endif -ifdef METROWERKS -# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support - MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support - CC = mwccnlm -else - CC = $(CROSSPREFIX)gcc -endif - -# Here you can find a native Win32 binary of the original awk: -# http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk -# If you want to mark the target as MTSAFE you will need a tool for -# generating the xdc data for the linker; here's a minimal tool: -# http://www.gknw.net/development/prgtools/mkxdc.zip -MPKXDC = mkxdc - -# Platform-dependent helper tool macros -ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' -else -ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) -else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) -endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. -endif - -# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH)) -LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH)) - -# Include the version info retrieved from libssh2.h --include $(OBJDIR)/version.inc - -# Global flags for all compilers -CFLAGS += $(OPT) -D$(DB) -DNETWARE -nostdinc - -ifeq ($(CC),mwccnlm) -LD = mwldnlm -LDFLAGS = -nostdlib $(<:.def=.o) $(PRELUDE) $(LDLIBS) -o $@ -commandfile -AR = mwldnlm -ARFLAGS = -type library -w nocmdline $(OBJS) -o -LIBEXT = lib -CFLAGS += -msgstyle gcc -gccinc -inline off -opt nointrinsics -proc 586 -CFLAGS += -relax_pointers -#CFLAGS += -w on -ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.o - CFLAGS += -align 4 -else -# PRELUDE = $(SDK_CLIB)/imports/clibpre.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" -# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" - CFLAGS += -align 1 -endif -else -LD = nlmconv -LDFLAGS = -UT -AR = ar -ARFLAGS = -cq -LIBEXT = a -CFLAGS += -m32 -CFLAGS += -fno-builtin -fpcc-struct-return -CFLAGS += -fno-strict-aliasing -CFLAGS += -Wall # -pedantic -ifeq ($(LIBARCH),LIBC) - PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o -else -# PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o - # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK - # http://www.gknw.net/development/mk_nlm/gcc_pre.zip - PRELUDE = $(NDK_ROOT)/pre/prelude.o - CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h -endif -endif - -NDK_ROOT = $(NDKBASE)/ndk -SDK_CLIB = $(NDK_ROOT)/nwsdk -SDK_LIBC = $(NDK_ROOT)/libc -SNPRINTF = $(NDKBASE)/snprintf - -INCLUDES = -I.. -I../../include - -LDLIBS = - -ifdef LINK_STATIC - LDLIBS += ../libssh2.$(LIBEXT) -else - IMPORTS += @../libssh2.imp - MODULES += libssh2.nlm -endif - -INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) -LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT) -LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) -IMPORTS += GetProcessSwitchCount RunningProcess - -ifdef WITH_ZLIB - INCLUDES += -I$(ZLIB_PATH) -ifdef LINK_STATIC - LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) -else - MODULES += libz.nlm - IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp -endif -endif - -ifeq ($(LIBARCH),LIBC) - INCLUDES += -I$(SDK_LIBC)/include -# INCLUDES += -I$(SDK_LIBC)/include/nks -# INCLUDES += -I$(SDK_LIBC)/include/winsock - CFLAGS += -D_POSIX_SOURCE -else - INCLUDES += -I$(SDK_CLIB)/include/nlm -# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete -# INCLUDES += -I$(SDK_CLIB)/include -# CFLAGS += -DNETDB_USE_INTERNET -endif -CFLAGS += $(INCLUDES) - -ifeq ($(MTSAFE),YES) - XDCOPT = -n -endif -ifeq ($(MTSAFE),NO) - XDCOPT = -u -endif - -vpath %.c $(SAMPLES) - -.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.def $(OBJDIR)/%.xdc - - -all: prebuild $(TARGETS) - -prebuild: $(OBJDIR) $(OBJDIR)/version.inc - -$(OBJDIR)/%.o: %.c -# @echo Compiling $< - $(CC) $(CFLAGS) -c $< -o $@ - -$(OBJDIR)/version.inc: ../../get_ver.awk ../../include/libssh2.h $(OBJDIR) - @echo Creating $@ - @$(AWK) -f $^ > $@ - -objclean: - $(call RMDIR, $(OBJDIR)) - -clean: objclean - $(foreach f, $(TARGETS), $(call DEL, $(f))) - -$(OBJDIR): - @$(call MKDIR, $@) - -%.nlm: $(OBJDIR)/%.def $(OBJDIR)/%.o $(OBJDIR)/%.xdc - @echo Linking $@ - @$(call DEL, $@) - @$(LD) $(LDFLAGS) $< - -$(OBJDIR)/%.xdc: GNUmakefile - @echo Creating $@ - @$(MPKXDC) $(XDCOPT) $@ - -$(OBJDIR)/%.def: GNUmakefile - @echo $(DL)# DEF file for linking with $(LD)$(DL) > $@ - @echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@ - @echo $(DL)# All your changes will be lost!!$(DL) >> $@ - @echo $(DL)#$(DL) >> $@ - @echo $(DL)copyright "$(COPYR)"$(DL) >> $@ - @echo $(DL)description "$(DESCR)"$(DL) >> $@ - @echo $(DL)version $(VERSION)$(DL) >> $@ -ifdef NLMTYPE - @echo $(DL)type $(NLMTYPE)$(DL) >> $@ -endif -ifdef STACK - @echo $(DL)stack $(STACK)$(DL) >> $@ -endif -ifdef SCREEN - @echo $(DL)screenname "$(SCREEN)"$(DL) >> $@ -else - @echo $(DL)screenname "DEFAULT"$(DL) >> $@ -endif -ifeq ($(DB),DEBUG) - @echo $(DL)debug$(DL) >> $@ -endif - @echo $(DL)threadname "$(notdir $(@:.def=))"$(DL) >> $@ -ifdef XDCOPT - @echo $(DL)xdcdata $(@:.def=.xdc)$(DL) >> $@ -endif -ifeq ($(LDRING),0) - @echo $(DL)flag_on 16$(DL) >> $@ -endif -ifeq ($(LDRING),3) - @echo $(DL)flag_on 512$(DL) >> $@ -endif -ifeq ($(LIBARCH),CLIB) - @echo $(DL)start _Prelude$(DL) >> $@ - @echo $(DL)exit _Stop$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/clib.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/threads.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/nlmlib.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_CLIB)/imports/socklib.imp$(DL) >> $@ - @echo $(DL)module clib$(DL) >> $@ -else - @echo $(DL)flag_on 64$(DL) >> $@ - @echo $(DL)pseudopreemption$(DL) >> $@ - @echo $(DL)start _LibCPrelude$(DL) >> $@ - @echo $(DL)exit _LibCPostlude$(DL) >> $@ - @echo $(DL)check _LibCCheckUnload$(DL) >> $@ - @echo $(DL)import @$(SDK_LIBC)/imports/libc.imp$(DL) >> $@ - @echo $(DL)import @$(SDK_LIBC)/imports/netware.imp$(DL) >> $@ - @echo $(DL)module libc$(DL) >> $@ -endif -ifdef MODULES - @echo $(DL)module $(MODULES)$(DL) >> $@ -endif -ifdef EXPORTS - @echo $(DL)export $(EXPORTS)$(DL) >> $@ -endif -ifdef IMPORTS - @echo $(DL)import $(IMPORTS)$(DL) >> $@ -endif -ifeq ($(LD),nlmconv) - @echo $(DL)input $(@:.def=.o)$(DL) >> $@ - @echo $(DL)input $(PRELUDE)$(DL) >> $@ -ifdef LDLIBS - @echo $(DL)input $(LDLIBS)$(DL) >> $@ -endif - @echo $(DL)output $(notdir $(@:.def=.nlm))$(DL) >> $@ -endif From 0b61317e6f5dc172da26d908295dca2fdc886250 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 29 Mar 2023 00:35:35 +0000 Subject: [PATCH 181/424] tidy-up: tabs to spaces in Makefile.am [ci skip] Follow-up to 2f16d8105c9491beb2a02b3081f4f1c2a224fa62 --- Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5fe3299033..10d03a6180 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,13 +71,13 @@ build-coverage: make CFLAGS=$(COVERAGE_CCOPTS) check mkdir -p $(COVERAGE_OUT) lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \ - --capture + --capture gen-coverage: genhtml --output-directory $(COVERAGE_OUT) \ - $(COVERAGE_OUT)/$(PACKAGE).info \ - --highlight --frames --legend \ - --title "$(PACKAGE_NAME)" + $(COVERAGE_OUT)/$(PACKAGE).info \ + --highlight --frames --legend \ + --title "$(PACKAGE_NAME)" coverage: init-coverage build-coverage gen-coverage From 08354e0abbe86d4cc5088d210d53531be6d8981a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 29 Mar 2023 10:07:57 +0200 Subject: [PATCH 182/424] src: fix compiler warning on Darwin (#898) ``` src/session.c:675:52: warning: implicit conversion loses integer precision: 'long' to '__darwin_suseconds_t' (aka 'int') [-Wshorten-64-to-32] tv.tv_usec = (ms_to_next - tv.tv_sec*1000) * 1000; ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~ ``` --- src/session.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/session.c b/src/session.c index da6332bda8..817bc17939 100644 --- a/src/session.c +++ b/src/session.c @@ -57,6 +57,14 @@ #include "channel.h" #include "mac.h" +#if defined(WIN32) +#define libssh2_usec_t long +#elif defined(__APPLE__) +#define libssh2_usec_t suseconds_t +#else +#undef libssh2_usec_t +#endif + /* libssh2_default_alloc */ static @@ -669,8 +677,8 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) struct timeval tv; tv.tv_sec = ms_to_next / 1000; -#ifdef WIN32 - tv.tv_usec = (long)((ms_to_next - tv.tv_sec*1000) * 1000); +#ifdef libssh2_usec_t + tv.tv_usec = (libssh2_usec_t)((ms_to_next - tv.tv_sec*1000) * 1000); #else tv.tv_usec = (ms_to_next - tv.tv_sec*1000) * 1000; #endif From 97417ad37f117a3f7a2e2c949412f1bb3a563431 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 29 Mar 2023 20:23:25 +0200 Subject: [PATCH 183/424] ci: add VS2022 builds (incl. ARM64) to AppVeyor (#899) - add MSVS 2022 WinCNG builds for x64 and ARM64, replacing MSVS 2013 WinCNG builds for x64 and x86. - add MSVS 2022 OpenSSL builds for x64. - fix a compiler warning uncovered by the new ARM64 build: ``` tests\openssh_fixture.c(393,17): warning C4477: 'fprintf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'libssh2_socket_t' tests\openssh_fixture.c(393,17): message : consider using '%lld' in the format string tests\openssh_fixture.c(393,17): message : consider using '%Id' in the format string tests\openssh_fixture.c(393,17): message : consider using '%I64d' in the format string ``` - echo the actual CMake command-line. - cmake: echo the DLL filenames found by the OpenSSL DLL-finder heuristics. - cmake: delete `libcrypto.dll` and `libssl.dll` names from the above logic. I've added these in 19884e5055b6c65f0df93d7cc776a01c518a2f06. That resulted in CMake picking up a rogue `libcrypto.dll` (with no `libssl.dll` pair) from `C:\Windows\System32\` on the `Visual Studio 2022` image, breaking tests. Turns out, OpenSSL v1.0.2 uses the "EAY" names, but let's not re-add those either, because CMake mis-picks those up from `C:/OpenSSL-Win64/bin/`, even while pointing `OPENSSL_ROOT_DIR` to a v1.1.1 installation. - cmake: set `NO_DEFAULT_PATH` for OpenSSL DLL lookup to avoid picking up all kinds of wrong DLLs. CMake considers not the first, but the _last_ hit the valid one. This happened to be `C:/Program Files/Meson/lib*-1_1.dll` when using the `Visual Studio 2022` image. Ref: https://cmake.org/cmake/help/latest/command/find_file.html - cmake: leave two commented debug lines that will be useful next time the DLL detection lookup goes wrong. Ref: https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_DEBUG_MODE.html - on error, also dump `CMakeFiles/CMakeConfigureLog.yaml` if it exists (requires CMake 3.26 and newer) --- appveyor.yml | 49 ++++++++++++++++++++++++++++++++--------- src/CMakeLists.txt | 20 ++++++++++++----- tests/openssh_fixture.c | 2 +- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c6ff8c43fd..4fdd028b4d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,39 +24,49 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -os: Visual Studio 2015 - environment: matrix: + - job_name: "VS2022, OpenSSL" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" + GENERATOR: "Visual Studio 17 2022" + BUILD_SHARED_LIBS: "ON" + CRYPTO_BACKEND: "OpenSSL" + - job_name: "VS2015, OpenSSL" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - job_name: "VS2013, OpenSSL" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - job_name: "VS2013, OpenSSL, Static" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "OpenSSL" SKIP_CTEST: "yes" SKIP_X86: "yes" - - job_name: "VS2015, WinCNG" - GENERATOR: "Visual Studio 14 2015" + - job_name: "VS2022, WinCNG" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" + GENERATOR: "Visual Studio 17 2022" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - - job_name: "VS2013, WinCNG" - GENERATOR: "Visual Studio 12 2013" + - job_name: "VS2015, WinCNG" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + GENERATOR: "Visual Studio 14 2015" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" platform: - x64 + - ARM64 - x86 configuration: @@ -67,6 +77,15 @@ matrix: fast_finish: true # Enough to test the build itself on a single platform exclude: + # Supported via '-A Win32', but skip this in favour of ARM64 builds + - platform: x86 + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" + # No ARM64 support before Visual Studio 2022 + - platform: ARM64 + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + # No ARM64 binaries provided by the image + - platform: ARM64 + CRYPTO_BACKEND: "OpenSSL" - platform: x86 SKIP_X86: "yes" @@ -79,14 +98,23 @@ install: build_script: - ps: | - if($env:PLATFORM -eq "x64") { $env:GENERATOR = "$env:GENERATOR Win64" } + if($env:GENERATOR -eq "Visual Studio 17 2022") { + if($env:PLATFORM -eq "x86") { + $env:CMAKE_ARG = "-A Win32" + } else { + $env:CMAKE_ARG = "-A $env:PLATFORM" + } + } elseif($env:PLATFORM -eq "x64") { + $env:GENERATOR += " Win64" + } if($env:SKIP_CTEST -ne "yes" -and $env:CRYPTO_BACKEND -eq "OpenSSL") { if($env:PLATFORM -eq "x64") { - $env:CMAKE_ARG = "-DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64" + $env:CMAKE_ARG += " -DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64" } elseif($env:PLATFORM -eq "x86") { - $env:CMAKE_ARG = "-DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win32" + $env:CMAKE_ARG += " -DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win32" } } + - echo cmake "-G%GENERATOR%" %CMAKE_ARG% -DENABLE_WERROR=ON -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% - cmake . -B _builds "-G%GENERATOR%" %CMAKE_ARG% -DENABLE_WERROR=ON -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% - cmake --build _builds --config "%CONFIGURATION%" @@ -109,12 +137,13 @@ before_test: test_script: - ps: | - if($env:SKIP_CTEST -ne "yes") { + if($env:SKIP_CTEST -ne "yes" -and $env:PLATFORM -ne "ARM64") { $env:OPENSSH_SERVER_IMAGE=[string] (& bash -c "echo ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)") cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure --timeout 900 } on_failure: + - ps: if(Test-Path _builds/CMakeFiles/CMakeConfigureLog.yaml) { cat _builds/CMakeFiles/CMakeConfigureLog.yaml } - ps: if(Test-Path _builds/CMakeFiles/CMakeOutput.log) { cat _builds/CMakeFiles/CMakeOutput.log } - ps: if(Test-Path _builds/CMakeFiles/CMakeError.log) { cat _builds/CMakeFiles/CMakeError.log } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 128e4604ac..020526f703 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -75,28 +75,36 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) list(APPEND LIBRARIES crypt32 bcrypt) list(APPEND PC_LIBS -lcrypt32 -lbcrypt) + #set(CMAKE_FIND_DEBUG_MODE TRUE) + find_file(DLL_LIBCRYPTO - NAMES crypto.dll libcrypto.dll + NAMES crypto.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll libcrypto-3.dll libcrypto-3-x64.dll HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} - PATH_SUFFIXES bin) - if(NOT DLL_LIBCRYPTO) + PATH_SUFFIXES bin NO_DEFAULT_PATH) + if(DLL_LIBCRYPTO) + message(STATUS "Found libcrypto DLL: ${DLL_LIBCRYPTO}") + else() message(WARNING "Unable to find OpenSSL libcrypto DLL, executables may not run") endif() find_file(DLL_LIBSSL - NAMES ssl.dll libssl.dll + NAMES ssl.dll libssl-1_1.dll libssl-1_1-x64.dll libssl-3.dll libssl-3-x64.dll HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} - PATH_SUFFIXES bin) - if(NOT DLL_LIBSSL) + PATH_SUFFIXES bin NO_DEFAULT_PATH) + if(DLL_LIBSSL) + message(STATUS "Found libssl DLL: ${DLL_LIBSSL}") + else() message(WARNING "Unable to find OpenSSL libssl DLL, executables may not run") endif() + #set(CMAKE_FIND_DEBUG_MODE FALSE) + if(DLL_LIBCRYPTO AND DLL_LIBSSL) list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBCRYPTO} ${DLL_LIBSSL}) endif() diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index ccae69e553..1b169ff171 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -66,7 +66,7 @@ #include #include -#if defined(WIN32) && (defined(_M_X64) || defined(__x86_64__)) +#if defined(WIN32) && defined(_WIN64) #define LIBSSH2_SOCKET_MASK "%lld" #else #define LIBSSH2_SOCKET_MASK "%d" From d23133b5a389ab5ac2b9cf05fc0cfc201e9309b7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 29 Mar 2023 22:53:59 +0200 Subject: [PATCH 184/424] ci: flatten AppVeyor jobs, add debug builds (#900) This results in better job names (now including CPU), avoiding the complex exception rules, and fine-tuning the order and variation of these tests. Enable `LIBSSH2DEBUG` for two of the existing jobs. --- appveyor.yml | 77 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4fdd028b4d..9ad4d8d819 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,68 +26,89 @@ environment: matrix: - - job_name: "VS2022, OpenSSL" + - job_name: "VS2022, OpenSSL, x64" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" + PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" + CONFIGURATION: "Release" - - job_name: "VS2015, OpenSSL" + - job_name: "VS2015, OpenSSL, x86" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" + PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" + CONFIGURATION: "Release" - - job_name: "VS2013, OpenSSL" + - job_name: "VS2015, OpenSSL, x64, Logging" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + GENERATOR: "Visual Studio 14 2015" + PLATFORM: "x64" + BUILD_SHARED_LIBS: "ON" + CRYPTO_BACKEND: "OpenSSL" + CONFIGURATION: "Debug" + + - job_name: "VS2013, OpenSSL, x64" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + GENERATOR: "Visual Studio 12 2013" + PLATFORM: "x64" + BUILD_SHARED_LIBS: "ON" + CRYPTO_BACKEND: "OpenSSL" + CONFIGURATION: "Release" + + - job_name: "VS2013, OpenSSL, x86" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" + PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" + CONFIGURATION: "Release" - - job_name: "VS2013, OpenSSL, Static" + - job_name: "VS2013, OpenSSL, x64, Static-only" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" + PLATFORM: "x64" BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "OpenSSL" SKIP_CTEST: "yes" - SKIP_X86: "yes" + CONFIGURATION: "Release" - - job_name: "VS2022, WinCNG" + - job_name: "VS2022, WinCNG, x64, Logging" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" + PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" + CONFIGURATION: "Debug" - - job_name: "VS2015, WinCNG" + - job_name: "VS2022, WinCNG, ARM64" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" + GENERATOR: "Visual Studio 17 2022" + PLATFORM: "ARM64" + BUILD_SHARED_LIBS: "ON" + CRYPTO_BACKEND: "WinCNG" + CONFIGURATION: "Release" + + - job_name: "VS2015, WinCNG, x86" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" + PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" + CONFIGURATION: "Release" -platform: - - x64 - - ARM64 - - x86 - -configuration: -# - Debug - - Release + - job_name: "VS2015, WinCNG, x64" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + GENERATOR: "Visual Studio 14 2015" + PLATFORM: "x64" + BUILD_SHARED_LIBS: "ON" + CRYPTO_BACKEND: "WinCNG" + CONFIGURATION: "Release" matrix: fast_finish: true - # Enough to test the build itself on a single platform - exclude: - # Supported via '-A Win32', but skip this in favour of ARM64 builds - - platform: x86 - APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" - # No ARM64 support before Visual Studio 2022 - - platform: ARM64 - APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" - # No ARM64 binaries provided by the image - - platform: ARM64 - CRYPTO_BACKEND: "OpenSSL" - - platform: x86 - SKIP_X86: "yes" install: # prepare local SSH server for reverse tunneling from GitHub Actions hosting our docker container From 50124428509ffc2f5d08d8d3c152fa36546c9a75 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 30 Mar 2023 20:59:47 +0200 Subject: [PATCH 185/424] maketgz: tidy-up [ci skip] (#901) - fix shellcheck warnings: - use quotes - use `$()` - use `printf` (instead of calling perl). - indent. - copy/adapt header comment from curl to `maketgz`. --- git2news.pl | 2 +- maketgz | 59 ++++++++++++++++++++-------------------- tests/mansyntax.sh | 12 ++++---- tests/ossfuzz/ossfuzz.sh | 11 +++++--- tests/ssh2.sh | 41 ++++++++++++++-------------- tests/sshd_fixture.sh.in | 38 ++++++++++++-------------- tests/sshdwrap | 16 +++++------ 7 files changed, 90 insertions(+), 89 deletions(-) diff --git a/git2news.pl b/git2news.pl index 5544663cf4..63dd382676 100755 --- a/git2news.pl +++ b/git2news.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # git log --pretty=fuller --no-color --date=short --decorate=full diff --git a/maketgz b/maketgz index ed03db7346..2fae14b9e2 100755 --- a/maketgz +++ b/maketgz @@ -1,26 +1,27 @@ -#! /bin/sh -# Script to build release-archives with +#!/bin/sh +# Script to build release-archives with. Note that this requires a checkout +# from git and you should first run 'autoreconf -fi' and './configure'. # -version=$1 +version="$1" if [ -z "$version" ]; then echo "Specify a version number!" exit fi -if [ "xonly" = "x$2" ]; then +if [ "only" = "$2" ]; then echo "Setup version number only!" only=1 fi libversion="$version" -major=`echo $libversion |cut -d. -f1 | sed -e "s/[^0-9]//g"` -minor=`echo $libversion |cut -d. -f2 | sed -e "s/[^0-9]//g"` -patch=`echo $libversion |cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g"` +major="$(echo "$libversion" | cut -d. -f1 | sed -e "s/[^0-9]//g")" +minor="$(echo "$libversion" | cut -d. -f2 | sed -e "s/[^0-9]//g")" +patch="$(echo "$libversion" | cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g")" -numeric=`perl -e 'printf("%02x%02x%02x\n", '"$major, $minor, $patch);"` +numeric="$(printf "%02x%02x%02x\n" "$major" "$minor" "$patch")" HEADER=include/libssh2.h @@ -28,23 +29,23 @@ if test -z "$only"; then ext=".dist" # when not setting up version numbers locally for a in $HEADER; do - cp $a "$a$ext" + cp "$a" "$a$ext" done HEADER="$HEADER$ext" fi # requires a date command that knows -u for UTC time zone -datestamp=`LC_TIME=C date -u` +datestamp="$(LC_TIME=C date -u)" # Replace in-place version number in header file: sed -i.bak \ - -e 's/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION "'$libversion'"/g' \ - -e 's/^#define LIBSSH2_VERSION_NUM .*/#define LIBSSH2_VERSION_NUM 0x'$numeric'/g' \ - -e 's/^#define LIBSSH2_VERSION_MAJOR .*/#define LIBSSH2_VERSION_MAJOR '$major'/g' \ - -e 's/^#define LIBSSH2_VERSION_MINOR .*/#define LIBSSH2_VERSION_MINOR '$minor'/g' \ - -e 's/^#define LIBSSH2_VERSION_PATCH .*/#define LIBSSH2_VERSION_PATCH '$patch'/g' \ + -e "s/^#define LIBSSH2_VERSION .*/#define LIBSSH2_VERSION \"$libversion\"/g" \ + -e "s/^#define LIBSSH2_VERSION_NUM .*/#define LIBSSH2_VERSION_NUM 0x$numeric/g" \ + -e "s/^#define LIBSSH2_VERSION_MAJOR .*/#define LIBSSH2_VERSION_MAJOR $major/g" \ + -e "s/^#define LIBSSH2_VERSION_MINOR .*/#define LIBSSH2_VERSION_MINOR $minor/g" \ + -e "s/^#define LIBSSH2_VERSION_PATCH .*/#define LIBSSH2_VERSION_PATCH $patch/g" \ -e "s/^#define LIBSSH2_TIMESTAMP .*/#define LIBSSH2_TIMESTAMP \"$datestamp\"/g" \ - $HEADER + "$HEADER" rm -f "$HEADER.bak" @@ -59,7 +60,7 @@ fi findprog() { file="$1" - for part in `echo $PATH| tr ':' ' '`; do + for part in $(echo "$PATH" | tr ':' ' '); do path="$part/$file" if [ -x "$path" ]; then # there it is! @@ -98,7 +99,7 @@ git log --pretty=fuller --no-color --date=short --decorate=full -1000 | ./git2ne echo "make dist" targz="libssh2-$version.tar.gz" -make -s dist VERSION=$version +make -s dist "VERSION=$version" res=$? if test "$res" != 0; then @@ -113,7 +114,7 @@ fi bzip2="libssh2-$version.tar.bz2" echo "Generating $bzip2" -gzip -dc $targz | bzip2 --best > $bzip2 +gzip -dc "$targz" | bzip2 --best > "$bzip2" ############################################################################ # @@ -122,21 +123,21 @@ gzip -dc $targz | bzip2 --best > $bzip2 xz="libssh2-$version.tar.xz" echo "Generating $xz" -gzip -dc $targz | xz -6e - > $xz +gzip -dc "$targz" | xz -6e - > "$xz" ############################################################################ # # Now make a zip archive from the tar.gz original # makezip() { - rm -rf $tempdir - mkdir $tempdir - cd $tempdir - gzip -dc ../$targz | tar -xf - - find . | zip $zip -@ >/dev/null - mv $zip ../ - cd .. - rm -rf $tempdir + rm -rf "$tempdir" + mkdir "$tempdir" + cd "$tempdir" || exit 1 + gzip -dc "../$targz" | tar -xf - + find . | zip "$zip" -@ >/dev/null + mv "$zip" ../ + cd .. || exit 1 + rm -rf "$tempdir" } zip="libssh2-$version.zip" @@ -147,4 +148,4 @@ makezip echo "------------------" echo "maketgz report:" echo "" -ls -l $targz $bzip2 $zip $xz +ls -l "$targz" "$bzip2" "$zip" "$xz" diff --git a/tests/mansyntax.sh b/tests/mansyntax.sh index dd4aa773ff..8c98fdf7cc 100755 --- a/tests/mansyntax.sh +++ b/tests/mansyntax.sh @@ -6,9 +6,9 @@ set -e # Run syntax checks for all manpages in the documentation tree. # -srcdir=${srcdir:-$PWD} -dstdir=${builddir:-$PWD} -mandir=${srcdir}/../docs +srcdir="${srcdir:-$PWD}" +dstdir="${builddir:-$PWD}" +mandir="${srcdir}/../docs" # # Only test if suitable man is available @@ -20,11 +20,11 @@ fi ec=0 -trap "rm -f $dstdir/man3" EXIT +trap 'rm -f "$dstdir/man3"' EXIT ln -sf "$mandir" "$dstdir/man3" -for manpage in $mandir/libssh2_*.*; do +for manpage in "$mandir"/libssh2_*.*; do echo "$manpage" warnings=$(LANG=en_US.UTF-8 MANWIDTH=80 man -M "$dstdir" --warnings \ -E UTF-8 -l "$manpage" 2>&1 >/dev/null) @@ -34,4 +34,4 @@ for manpage in $mandir/libssh2_*.*; do fi done -exit $ec +exit "$ec" diff --git a/tests/ossfuzz/ossfuzz.sh b/tests/ossfuzz/ossfuzz.sh index 36c1f78729..7925fb792c 100755 --- a/tests/ossfuzz/ossfuzz.sh +++ b/tests/ossfuzz/ossfuzz.sh @@ -1,10 +1,12 @@ -#!/bin/bash -eu +#!/usr/bin/env bash + +set -eu # This script is called by the oss-fuzz main project when compiling the fuzz # targets. This script is regression tested by ci/ossfuzz.sh. # Save off the current folder as the build root. -export BUILD_ROOT=$PWD +export BUILD_ROOT="$PWD" echo "CC: $CC" echo "CXX: $CXX" @@ -13,7 +15,8 @@ echo "CFLAGS: $CFLAGS" echo "CXXFLAGS: $CXXFLAGS" echo "OUT: $OUT" -export MAKEFLAGS+="-j$(nproc)" +MAKEFLAGS+="-j$(nproc)" +export MAKEFLAGS # Install dependencies apt-get -y install automake libtool libssl-dev zlib1g-dev @@ -27,4 +30,4 @@ apt-get -y install automake libtool libssl-dev zlib1g-dev make V=1 # Copy the fuzzer to the output directory. -cp -v tests/ossfuzz/ssh2_client_fuzzer $OUT/ +cp -v tests/ossfuzz/ssh2_client_fuzzer "$OUT/" diff --git a/tests/ssh2.sh b/tests/ssh2.sh index 07795bb7f2..3c99486920 100755 --- a/tests/ssh2.sh +++ b/tests/ssh2.sh @@ -5,44 +5,43 @@ # Start sshd, invoke parameters, saving exit code, kill sshd, and # return exit code. -srcdir=${srcdir:-$PWD} -SSHD=${SSHD:-/usr/sbin/sshd} +srcdir="${srcdir:-$PWD}" +SSHD="${SSHD:-/usr/sbin/sshd}" cmd="./ssh2${EXEEXT}" -srcdir=`cd "$srcdir"; pwd` +srcdir="$(cd "$srcdir" || exit; pwd)" -PRIVKEY=$srcdir/etc/user -export PRIVKEY -PUBKEY=$srcdir/etc/user.pub -export PUBKEY +export PRIVKEY="$srcdir/etc/user" +export PUBKEY="$srcdir/etc/user.pub" if test -n "$DEBUG"; then - libssh2_sshd_params="-d -d" + libssh2_sshd_params="-d -d" fi chmod go-rwx "$srcdir"/etc/host* -$SSHD -f /dev/null -h "$srcdir"/etc/host \ - -o 'Port 4711' \ - -o 'Protocol 2' \ - -o "AuthorizedKeysFile $srcdir/etc/user.pub" \ - -o 'UsePrivilegeSeparation no' \ - -o 'StrictModes no' \ - -D \ - $libssh2_sshd_params & +# shellcheck disable=SC2086 +"$SSHD" -f /dev/null -h "$srcdir/etc/host" \ + -o 'Port 4711' \ + -o 'Protocol 2' \ + -o "AuthorizedKeysFile \"$srcdir/etc/user.pub\"" \ + -o 'UsePrivilegeSeparation no' \ + -o 'StrictModes no' \ + -D \ + $libssh2_sshd_params & sshdpid=$! -trap "kill ${sshdpid}; echo signal killing sshd; exit 1;" EXIT +trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT : "started sshd (${sshdpid})" sleep 3 -: Invoking $cmd... -eval $cmd +: "Invoking $cmd..." +eval "$cmd" ec=$? -: Self-test exit code $ec +: "Self-test exit code $ec" : "killing sshd (${sshdpid})" kill "${sshdpid}" > /dev/null 2>&1 trap "" EXIT -exit $ec +exit "$ec" diff --git a/tests/sshd_fixture.sh.in b/tests/sshd_fixture.sh.in index a76f4338ae..086cdb2678 100644 --- a/tests/sshd_fixture.sh.in +++ b/tests/sshd_fixture.sh.in @@ -10,44 +10,42 @@ SSHD="@SSHD_EXECUTABLE@" cmd="\"$1\"" -PRIVKEY=$srcdir/etc/user -export PRIVKEY -PUBKEY=$srcdir/etc/user.pub -export PUBKEY +export PRIVKEY="$srcdir/etc/user" +export PUBKEY="$srcdir/etc/user.pub" if test -n "$DEBUG"; then - libssh2_sshd_params="-d -d" + libssh2_sshd_params="-d -d" fi chmod go-rwx "$srcdir"/etc/host* +# shellcheck disable=SC2086 "$SSHD" -f /dev/null -h "$srcdir/etc/host" \ - -o 'Port 4711' \ - -o 'Protocol 2' \ - -o "AuthorizedKeysFile \"$srcdir/etc/user.pub\"" \ - -o 'UsePrivilegeSeparation no' \ - -o 'StrictModes no' \ - -D \ - $libssh2_sshd_params & + -o 'Port 4711' \ + -o 'Protocol 2' \ + -o "AuthorizedKeysFile \"$srcdir/etc/user.pub\"" \ + -o 'UsePrivilegeSeparation no' \ + -o 'StrictModes no' \ + -D \ + $libssh2_sshd_params & sshdpid=$! -trap "kill ${sshdpid}; echo signal killing sshd; exit 1;" EXIT +trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT : "started sshd (${sshdpid})" sleep 3 -if ! kill -0 ${sshdpid} -then - echo "SSHD exited before test started" - exit 1 +if ! kill -0 "${sshdpid}"; then + echo "SSHD exited before test started" + exit 1 fi -: Invoking $cmd... +: "Invoking $cmd..." eval "$cmd" ec=$? -: Self-test exit code $ec +: "Self-test exit code $ec" : "killing sshd (${sshdpid})" kill "${sshdpid}" > /dev/null 2>&1 trap "" EXIT -exit $ec +exit "$ec" diff --git a/tests/sshdwrap b/tests/sshdwrap index b479c955fe..496056ddc8 100755 --- a/tests/sshdwrap +++ b/tests/sshdwrap @@ -5,24 +5,24 @@ # Start sshd, invoke parameters, saving exit code, kill sshd, and # return exit code. -cmd="$@" -SSHD=${SSHD:-/usr/sbin/sshd} +cmd="$*" +SSHD="${SSHD:-/usr/sbin/sshd}" -$SSHD -f etc/sshd_config -h $PWD/etc/host -D & +"$SSHD" -f etc/sshd_config -h "$PWD/etc/host" -D & sshdpid=$! -trap "kill ${sshdpid}; echo signal killing sshd; exit 1;" EXIT +trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT : "started sshd (${sshdpid})" sleep 1 -: Invoking $cmd... -eval $cmd +: "Invoking $cmd..." +eval "$cmd" ec=$? -: Self-test exit code $ec +: "Self-test exit code $ec" : "killing sshd (${sshdpid})" kill "${sshdpid}" > /dev/null 2>&1 trap "" EXIT -exit $ec +exit "$ec" From 057522bb0f15c10c33159e12899ecc60e40aa6ef Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 30 Mar 2023 21:01:01 +0200 Subject: [PATCH 186/424] NMakefile: merge them into a single file [ci skip] (#902) Also: - allow to override `AR` and `ARFLAGS`. - The extra `src` subdir in the target directory is no longer, to simplify things. - gone the dynamically generated `objects.mk`. Now replaced with some tricky logic to do that inline. - add necessary `LIBS` for WinCNG. (untested) Lightly tested via clang-cl. --- NMakefile | 107 ++++++++++++++++++++++++++++++++++++++++++----- src/NMakefile | 29 ------------- win32/.gitignore | 9 ---- win32/config.mk | 51 ---------------------- win32/rules.mk | 12 ------ 5 files changed, 96 insertions(+), 112 deletions(-) delete mode 100644 src/NMakefile delete mode 100644 win32/config.mk delete mode 100644 win32/rules.mk diff --git a/NMakefile b/NMakefile index 30b20de7d7..73fce5efd2 100644 --- a/NMakefile +++ b/NMakefile @@ -1,4 +1,56 @@ -!include "win32/config.mk" +# Tweak these for your system +!if "$(OPENSSLINC)" == "" +OPENSSLINC=..\openssl\include +!endif + +!if "$(OPENSSLLIB)" == "" +OPENSSLLIB=..\openssl\lib +!endif + +!if "$(ZLIBINC)" == "" +ZLIBINC=..\zlib +!endif + +!if "$(ZLIBLIB)" == "" +ZLIBLIB=..\zlib +!endif + +!if "$(TARGET)" == "" +TARGET=Release +!endif + +!if "$(TARGET)" == "Debug" +SUFFIX=_debug +CPPFLAGS=/Od /MDd +DLLFLAGS=/DEBUG /LDd +!else +CPPFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG +DLLFLAGS=/DEBUG /LD +!endif + +CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude + +!if "$(WITH_WINCNG)" == "1" +CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_WINCNG +LIBS=ws2_32.lib crypt32.lib bcrypt.lib +!else +CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSLINC) +LIBS=$(LIBS) $(OPENSSLLIB)\lib\crypto.lib $(OPENSSLLIB)\lib\ssl.lib +!endif + +!if "$(WITH_ZLIB)" == "1" +CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_HAVE_ZLIB /I$(ZLIBINC) +LIBS=$(LIBS) $(ZLIBLIB)\zlib.lib +!endif + +CFLAGS=$(CPPFLAGS) +RCFLAGS=/Iinclude +DLLFLAGS=$(CFLAGS) $(DLLFLAGS) +LIBS=$(LIBS) ws2_32.lib user32.lib advapi32.lib gdi32.lib + +INTDIR=$(TARGET) + +SUBDIR=src !if "$(WITH_WINCNG)" == "1" !include "Makefile.WinCNG.inc" @@ -9,15 +61,53 @@ OBJECTS=$(CSOURCES:.c=.obj) -# SUBDIRS=src example -SUBDIRS=src +!if "$(TARGET)" == "Debug" +OBJECTS=Debug/$(OBJECTS: = Debug/) +OBJECTS=$(OBJECTS: Debug/ = ) +!else +TARGET=Release +OBJECTS=Release/$(OBJECTS: = Release/) +OBJECTS=$(OBJECTS: Release/ = ) +!endif + +CFLAGS=$(CFLAGS) + +!if "$(AR)" == "" +AR=lib +ARFLAGS=-nologo /LTCG +!endif -all-sub: win32\objects.mk - -for %D in ($(SUBDIRS)) do $(MAKE) /nologo /f %D/NMakefile BUILD=$(BUILD) SUBDIR=%D all-sub +RESOURCE=$(INTDIR)\libssh2.res +DLL=libssh2$(SUFFIX).dll +STATICLIB=$(INTDIR)\libssh2.lib + +!if "$(BUILD_STATIC_LIB)" == "" +all: $(INTDIR) $(DLL) +!else +all: $(INTDIR) $(STATICLIB) +!endif + +$(INTDIR): + @if not exist $(INTDIR) mkdir $(INTDIR) + +$(DLL): $(OBJECTS) $(RESOURCE) + $(CC) -o $(DLL) $(DLLFLAGS) $(OBJECTS) $(RESOURCE) $(LIBS) + +$(STATICLIB): $(OBJECTS) + $(AR) $(ARFLAGS) -out:$@ $(OBJECTS) + +$(RESOURCE): win32\libssh2.rc + $(RC) $(RCFLAGS) /Fo"$@" $? + +all-sub: $(INTDIR) all + +clean-sub: clean + +{$(SUBDIR)}.c{$(INTDIR)}.obj:: + $(CC) -c $(CFLAGS) /Fo"$(INTDIR)\\" $< clean: -rmdir 2>NUL /s/q $(TARGET) - -del 2>NUL win32\objects.mk real-clean vclean: clean -del 2>NUL libssh2.dll @@ -25,8 +115,3 @@ real-clean vclean: clean -del 2>NUL libssh2.ilk -del 2>NUL libssh2.lib -del 2>NUL *.pdb - -win32\objects.mk: Makefile.inc - @echo OBJECTS = \>$@ - @for %O in ($(OBJECTS)) do @echo $$(INTDIR)\%O \>>$@ - @echo $$(EOL)>>$@ diff --git a/src/NMakefile b/src/NMakefile deleted file mode 100644 index 46430bbd22..0000000000 --- a/src/NMakefile +++ /dev/null @@ -1,29 +0,0 @@ -!include "win32/config.mk" - -!include "win32/objects.mk" - -CFLAGS=$(CFLAGS) - -AR = lib -ARFLAGS = -nologo /LTCG - -RESOURCE=$(INTDIR)\libssh2.res -DLL=libssh2$(SUFFIX).dll -STATICLIB=$(INTDIR)\libssh2.lib - -!if "$(BUILD_STATIC_LIB)" == "" -all: $(DLL) -!else -all: $(STATICLIB) -!endif - -$(DLL): $(OBJECTS) $(RESOURCE) - $(CC) -o $(DLL) $(DLLFLAGS) $(OBJECTS) $(RESOURCE) $(LIBS) - -$(STATICLIB): $(OBJECTS) - $(AR) $(ARFLAGS) -out:$@ $(OBJECTS) - -$(RESOURCE): win32\libssh2.rc - $(RC) $(RCFLAGS) /Fo"$@" $? - -!include "win32/rules.mk" diff --git a/win32/.gitignore b/win32/.gitignore index cfad4cf94b..b8117e4a2f 100644 --- a/win32/.gitignore +++ b/win32/.gitignore @@ -1,13 +1,4 @@ -*.lib -*.pdb *.dll *.exe -*.obj -.*.swp Debug Release -*.exp -*.ncb -*.opt -*.plg -objects.mk diff --git a/win32/config.mk b/win32/config.mk deleted file mode 100644 index 8f65cabffd..0000000000 --- a/win32/config.mk +++ /dev/null @@ -1,51 +0,0 @@ -# Tweak these for your system -!if "$(OPENSSLINC)" == "" -OPENSSLINC=..\openssl\include -!endif - -!if "$(OPENSSLLIB)" == "" -OPENSSLLIB=..\openssl\lib -!endif - -!if "$(ZLIBINC)" == "" -ZLIBINC=..\zlib -!endif - -!if "$(ZLIBLIB)" == "" -ZLIBLIB=..\zlib -!endif - -!if "$(TARGET)" == "" -TARGET=Release -!endif - -!if "$(TARGET)" == "Debug" -SUFFIX=_debug -CPPFLAGS=/Od /MDd -DLLFLAGS=/DEBUG /LDd -!else -CPPFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG -DLLFLAGS=/DEBUG /LD -!endif - -CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude - -!if "$(WITH_WINCNG)" == "1" -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_WINCNG -# LIBS=bcrypt.lib crypt32.lib -!else -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSLINC) -LIBS=$(LIBS) $(OPENSSLLIB)\lib\crypto.lib $(OPENSSLLIB)\lib\ssl.lib -!endif - -!if "$(WITH_ZLIB)" == "1" -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_HAVE_ZLIB /I$(ZLIBINC) -LIBS=$(LIBS) $(ZLIBLIB)\zlib.lib -!endif - -CFLAGS=$(CPPFLAGS) -RCFLAGS=/Iinclude -DLLFLAGS=$(CFLAGS) $(DLLFLAGS) -LIBS=$(LIBS) ws2_32.lib user32.lib advapi32.lib gdi32.lib - -INTDIR=$(TARGET)\$(SUBDIR) diff --git a/win32/rules.mk b/win32/rules.mk deleted file mode 100644 index e5bd1a9467..0000000000 --- a/win32/rules.mk +++ /dev/null @@ -1,12 +0,0 @@ -all-sub: $(INTDIR) all - -clean-sub: clean - -$(INTDIR): -!if "$(SRCDIR)" == "" - @if not exist $(TARGET) mkdir $(TARGET) -!endif - @if not exist $(INTDIR) mkdir $(INTDIR) - -{$(SUBDIR)}.c{$(INTDIR)}.obj:: - $(CC) -c $(CFLAGS) /Fo"$(INTDIR)\\" $< From 46f233fd7dd6cd2520273466b93dd88d3ec6a02c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 30 Mar 2023 19:03:35 +0000 Subject: [PATCH 187/424] build: delete references to deleted NMake files [ci skip] Follow-up to 057522bb0f15c10c33159e12899ecc60e40aa6ef --- Makefile.am | 2 +- src/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 10d03a6180..e44b8e935c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/readme.vms vms/libssh2_config.h WIN32FILES = win32/GNUmakefile \ - win32/libssh2_config.h win32/config.mk win32/rules.mk \ + win32/libssh2_config.h \ win32/libssh2.rc OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ diff --git a/src/Makefile.am b/src/Makefile.am index 1352ab7b2b..d63b477a0d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,7 @@ include ../Makefile.inc libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS) EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in libssh2.pc.in -EXTRA_DIST += CMakeLists.txt NMakefile +EXTRA_DIST += CMakeLists.txt lib_LTLIBRARIES = libssh2.la From e195aeeff390bc695db949af4d93db0aeace6410 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 30 Mar 2023 19:08:27 +0000 Subject: [PATCH 188/424] GNUmakefile: adjust win32/.gitignore [ci skip] --- win32/.gitignore | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/win32/.gitignore b/win32/.gitignore index b8117e4a2f..0f142bac2d 100644 --- a/win32/.gitignore +++ b/win32/.gitignore @@ -1,4 +1,6 @@ +*.a *.dll +*.def *.exe -Debug -Release +debug +release From bcb5eda096802fd45c435d2354eb83b313fd2fbb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 31 Mar 2023 00:17:46 +0200 Subject: [PATCH 189/424] tidy-up: NMakefile (#903) --- Makefile.am | 4 ++-- NMakefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index e44b8e935c..964336e347 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c \ vms/readme.vms vms/libssh2_config.h -WIN32FILES = win32/GNUmakefile \ +WIN32FILES = win32/GNUmakefile NMakefile \ win32/libssh2_config.h \ win32/libssh2.rc @@ -38,7 +38,7 @@ OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ Makefile.os400qc3.inc EXTRA_DIST = $(WIN32FILES) get_ver.awk \ - maketgz NMakefile RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ + maketgz RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ CMakeLists.txt cmake git2news.pl libssh2-style.el README.md $(OS400FILES) \ buildconf diff --git a/NMakefile b/NMakefile index 73fce5efd2..9479ff54e5 100644 --- a/NMakefile +++ b/NMakefile @@ -32,7 +32,7 @@ CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude !if "$(WITH_WINCNG)" == "1" CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_WINCNG -LIBS=ws2_32.lib crypt32.lib bcrypt.lib +LIBS=crypt32.lib bcrypt.lib !else CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSLINC) LIBS=$(LIBS) $(OPENSSLLIB)\lib\crypto.lib $(OPENSSLLIB)\lib\ssl.lib From 3da46f17adcdee2ba91288aa488ce649a4598371 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 31 Mar 2023 01:05:07 +0000 Subject: [PATCH 190/424] cmake: add missing #cmakedefines to src - `HAVE_MEMSET_S` missing since 03092292597ac601c3f9f0c267ecb145dda75e4e (2018-08-02) - `HAVE_EXPLICIT_BZERO` and `HAVE_EXPLICIT_MEMSET` missing since 00005682f7b9a1aa42be50e269056ea873637047 (2023-03-28) --- src/libssh2_config_cmake.h.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 7bc9d5cf82..f8f3baa222 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -61,6 +61,9 @@ #cmakedefine HAVE_STRTOLL #cmakedefine HAVE_STRTOI64 #cmakedefine HAVE_SNPRINTF +#cmakedefine HAVE_EXPLICIT_BZERO +#cmakedefine HAVE_EXPLICIT_MEMSET +#cmakedefine HAVE_MEMSET_S /* Socket non-blocking support */ #cmakedefine HAVE_O_NONBLOCK From 67ac735ad09e48bb5c92e765c72a6564d5873c27 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 31 Mar 2023 13:39:11 +0000 Subject: [PATCH 191/424] cmake: dedupe crypto-backend detection Before this patch CMake did crypto-backend detection in both `src/CMakefiles.txt` and `tests/CMakefiles.txt`. Merge them and move it to the root `CMakefiles.txt`. While here, also add zlib for OpenSSL. Necessary when using OpenSSL builds with zlib enabled. Closes #905 --- CMakeLists.txt | 167 +++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 149 +------------------------------------- tests/CMakeLists.txt | 78 -------------------- 3 files changed, 170 insertions(+), 224 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4670f7b87..a23d2efbec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,8 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. +include(CheckIncludeFiles) + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") include(CheckFunctionExistsMayNeedLibrary) @@ -109,6 +111,171 @@ endif() set(LIB_STATIC "libssh2_static") set(LIB_SHARED "libssh2_shared") # Must match libssh2_shared_EXPORTS macro in include/libssh2.h +## Cryptography backend choice + +set(CRYPTO_BACKEND + "" + CACHE + STRING + "The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt, +WinCNG, mbedTLS, or empty to try any available") + +# If the crypto backend was given, rather than searching for the first +# we are able to find, the find_package commands must abort configuration +# and report to the user. +if(CRYPTO_BACKEND) + set(SPECIFIC_CRYPTO_REQUIREMENT REQUIRED) +endif() + +if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) + + find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT}) + + if(OPENSSL_FOUND) + set(CRYPTO_BACKEND "OpenSSL") + set(CRYPTO_SOURCES openssl.c openssl.h) + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL") + set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) + list(APPEND LIBRARIES ${OPENSSL_LIBRARIES}) + list(APPEND PC_REQUIRES_PRIVATE libssl libcrypto) + + if (WIN32) + # Statically linking to OpenSSL requires crypt32 for some Windows APIs. + # This should really be handled by FindOpenSSL.cmake. + list(APPEND LIBRARIES crypt32 bcrypt) + list(APPEND PC_LIBS -lcrypt32 -lbcrypt) + + #set(CMAKE_FIND_DEBUG_MODE TRUE) + + find_file(DLL_LIBCRYPTO + NAMES crypto.dll + libcrypto-1_1.dll libcrypto-1_1-x64.dll + libcrypto-3.dll libcrypto-3-x64.dll + HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} + PATH_SUFFIXES bin NO_DEFAULT_PATH) + if(DLL_LIBCRYPTO) + message(STATUS "Found libcrypto DLL: ${DLL_LIBCRYPTO}") + else() + message(WARNING + "Unable to find OpenSSL libcrypto DLL, executables may not run") + endif() + + find_file(DLL_LIBSSL + NAMES ssl.dll + libssl-1_1.dll libssl-1_1-x64.dll + libssl-3.dll libssl-3-x64.dll + HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} + PATH_SUFFIXES bin NO_DEFAULT_PATH) + if(DLL_LIBSSL) + message(STATUS "Found libssl DLL: ${DLL_LIBSSL}") + else() + message(WARNING + "Unable to find OpenSSL libssl DLL, executables may not run") + endif() + + #set(CMAKE_FIND_DEBUG_MODE FALSE) + + if(DLL_LIBCRYPTO AND DLL_LIBSSL) + list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBCRYPTO} ${DLL_LIBSSL}) + endif() + endif() + + find_package(ZLIB) + + if(ZLIB_FOUND) + list(APPEND LIBRARIES ${ZLIB_LIBRARIES}) + list(APPEND PC_REQUIRES_PRIVATE zlib) + endif() + endif() +endif() + +if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) + + find_package(wolfssl ${SPECIFIC_CRYPTO_REQUIREMENT}) + + if(WOLFSSL_FOUND) + set(CRYPTO_BACKEND "wolfSSL") + set(CRYPTO_SOURCES openssl.c openssl.h) + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WOLFSSL") + set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl) + list(APPEND LIBRARIES ${WOLFSSL_LIBRARIES}) + list(APPEND PC_LIBS -lwolfssl) + + if (WIN32) + list(APPEND LIBRARIES crypt32) + list(APPEND PC_LIBS -lcrypt32) + endif() + + find_package(ZLIB) + + if(ZLIB_FOUND) + list(PREPEND CRYPTO_BACKEND_INCLUDE_DIR ${ZLIB_INCLUDE_DIR}) + + list(APPEND LIBRARIES ${ZLIB_LIBRARIES}) # Public wolfSSL headers require zlib headers + list(APPEND PC_REQUIRES_PRIVATE zlib) + endif() + endif() +endif() + +if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) + + find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT}) + + if(LIBGCRYPT_FOUND) + set(CRYPTO_BACKEND "Libgcrypt") + set(CRYPTO_SOURCES libgcrypt.c libgcrypt.h) + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT") + set(CRYPTO_BACKEND_INCLUDE_DIR ${LIBGCRYPT_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES}) + list(APPEND PC_LIBS -lgcrypt) + endif() +endif() + +if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) + + # The check actually compiles the header. This requires windows.h. + check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) + + if(HAVE_BCRYPT_H) + set(CRYPTO_BACKEND "WinCNG") + set(CRYPTO_SOURCES wincng.c wincng.h) + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG") + set(CRYPTO_BACKEND_INCLUDE_DIR "") + + set(HAVE_LIBCRYPT32 TRUE) + list(APPEND LIBRARIES bcrypt) + list(APPEND PC_LIBS -lbcrypt) + + # Reading keys from files is optional and depends on Wincrypt + check_include_files("windows.h;wincrypt.h" HAVE_WINCRYPT_H) + + if(HAVE_WINCRYPT_H) + list(APPEND LIBRARIES crypt32) + list(APPEND PC_LIBS -lcrypt32) + endif() + + elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL ${REQUIRED}) + message(FATAL_ERROR "WinCNG not available") + endif() +endif() + +if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) + + find_package(mbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT}) + + if(MBEDTLS_FOUND) + set(CRYPTO_BACKEND "mbedTLS") + set(CRYPTO_SOURCES mbedtls.c mbedtls.h) + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS") + set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR}) + list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES}) + list(APPEND PC_LIBS -lmbedcrypto) + link_directories(${MBEDTLS_LIBRARY_DIR}) + endif() +endif() + +# + add_subdirectory(src) if(BUILD_EXAMPLES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 020526f703..44e03d7ac5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,153 +41,10 @@ include(CheckSymbolExists) include(CheckNonblockingSocketSupport) include(CMakePushCheckState) -## Cryptography backend choice - -set(CRYPTO_BACKEND - "" - CACHE - STRING - "The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt, -WinCNG, mbedTLS, or empty to try any available") - -# If the crypto backend was given, rather than searching for the first -# we are able to find, the find_package commands must abort configuration -# and report to the user. if(CRYPTO_BACKEND) - set(SPECIFIC_CRYPTO_REQUIREMENT REQUIRED) -endif() - -if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) - - find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(OPENSSL_FOUND) - set(CRYPTO_BACKEND "OpenSSL") - set(CRYPTO_SOURCES openssl.c openssl.h) - list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_OPENSSL) - list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR}) - list(APPEND LIBRARIES ${OPENSSL_LIBRARIES}) - list(APPEND PC_REQUIRES_PRIVATE libssl libcrypto) - - if (WIN32) - # Statically linking to OpenSSL requires crypt32 for some Windows APIs. - # This should really be handled by FindOpenSSL.cmake. - list(APPEND LIBRARIES crypt32 bcrypt) - list(APPEND PC_LIBS -lcrypt32 -lbcrypt) - - #set(CMAKE_FIND_DEBUG_MODE TRUE) - - find_file(DLL_LIBCRYPTO - NAMES crypto.dll - libcrypto-1_1.dll libcrypto-1_1-x64.dll - libcrypto-3.dll libcrypto-3-x64.dll - HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} - PATH_SUFFIXES bin NO_DEFAULT_PATH) - if(DLL_LIBCRYPTO) - message(STATUS "Found libcrypto DLL: ${DLL_LIBCRYPTO}") - else() - message(WARNING - "Unable to find OpenSSL libcrypto DLL, executables may not run") - endif() - - find_file(DLL_LIBSSL - NAMES ssl.dll - libssl-1_1.dll libssl-1_1-x64.dll - libssl-3.dll libssl-3-x64.dll - HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS} - PATH_SUFFIXES bin NO_DEFAULT_PATH) - if(DLL_LIBSSL) - message(STATUS "Found libssl DLL: ${DLL_LIBSSL}") - else() - message(WARNING - "Unable to find OpenSSL libssl DLL, executables may not run") - endif() - - #set(CMAKE_FIND_DEBUG_MODE FALSE) - - if(DLL_LIBCRYPTO AND DLL_LIBSSL) - list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBCRYPTO} ${DLL_LIBSSL}) - endif() - endif() - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) - - find_package(wolfssl ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(WOLFSSL_FOUND) - set(CRYPTO_BACKEND "wolfSSL") - set(CRYPTO_SOURCES openssl.c openssl.h) - list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_WOLFSSL) - list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl) - list(APPEND LIBRARIES ${WOLFSSL_LIBRARIES}) - list(APPEND PC_LIBS -lwolfssl) - - if (WIN32) - list(APPEND LIBRARIES crypt32) - list(APPEND PC_LIBS -lcrypt32) - endif() - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) - - find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(LIBGCRYPT_FOUND) - set(CRYPTO_BACKEND "Libgcrypt") - set(CRYPTO_SOURCES libgcrypt.c libgcrypt.h) - list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_LIBGCRYPT) - list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${LIBGCRYPT_INCLUDE_DIRS}) - list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES}) - list(APPEND PC_LIBS -lgcrypt) - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) - - # The check actually compiles the header. This requires windows.h. - check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) - - if(HAVE_BCRYPT_H) - set(CRYPTO_BACKEND "WinCNG") - set(CRYPTO_SOURCES wincng.c wincng.h) - list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_WINCNG) - - set(HAVE_LIBCRYPT32 TRUE) - list(APPEND LIBRARIES bcrypt) - list(APPEND PC_LIBS -lbcrypt) - - # Reading keys from files is optional and depends on Wincrypt - check_include_files("windows.h;wincrypt.h" HAVE_WINCRYPT_H) - - if(HAVE_WINCRYPT_H) - list(APPEND LIBRARIES crypt32) - list(APPEND PC_LIBS -lcrypt32) - endif() - - elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL ${REQUIRED}) - message(FATAL_ERROR "WinCNG not available") - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) - - find_package(mbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(MBEDTLS_FOUND) - set(CRYPTO_BACKEND "mbedTLS") - set(CRYPTO_SOURCES mbedtls.c mbedtls.h) - list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_MBEDTLS) - list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${MBEDTLS_INCLUDE_DIR}) - list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES}) - list(APPEND PC_LIBS -lmbedcrypto) - link_directories(${MBEDTLS_LIBRARY_DIR}) - endif() -endif() - -if(NOT CRYPTO_BACKEND) + list(APPEND PRIVATE_COMPILE_DEFINITIONS ${CRYPTO_BACKEND_DEFINE}) + list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${CRYPTO_BACKEND_INCLUDE_DIR}) +else() message(FATAL_ERROR "No suitable cryptography backend found.") endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 128ea06c03..3bba01e695 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,84 +53,6 @@ configure_file( list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) -## Cryptography backend choice - -set(CRYPTO_BACKEND - "" - CACHE - STRING - "The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt, -WinCNG, mbedTLS, or empty to try any available") - -# If the crypto backend was given, rather than searching for the first -# we are able to find, the find_package commands must abort configuration -# and report to the user. -if(CRYPTO_BACKEND) - set(SPECIFIC_CRYPTO_REQUIREMENT REQUIRED) -endif() - -if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) - - find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(OPENSSL_FOUND) - set(CRYPTO_BACKEND "OpenSSL") - set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL") - set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) - - find_package(wolfssl ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(WOLFSSL_FOUND) - set(CRYPTO_BACKEND "wolfSSL") - set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WOLFSSL") - set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl) - - find_package(ZLIB) - - if(ZLIB_FOUND) - set(CRYPTO_BACKEND_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} ${CRYPTO_BACKEND_INCLUDE_DIR}) - endif() - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) - - find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(LIBGCRYPT_FOUND) - set(CRYPTO_BACKEND "Libgcrypt") - set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT") - set(CRYPTO_BACKEND_INCLUDE_DIR ${LIBGCRYPT_INCLUDE_DIRS}) - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) - - # The check actually compiles the header. This requires windows.h. - check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) - - if(HAVE_BCRYPT_H) - set(CRYPTO_BACKEND "WinCNG") - set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG") - set(CRYPTO_BACKEND_INCLUDE_DIR "") - endif() -endif() - -if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) - - find_package(mbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(MBEDTLS_FOUND) - set(CRYPTO_BACKEND "mbedTLS") - set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS") - set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR}) - endif() -endif() - set(TESTS warmup hostkey From ce26743b4ef81c9b839553bd7a98619700aafc72 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 31 Mar 2023 18:11:27 +0000 Subject: [PATCH 192/424] cmake: dedupe and merge config detection Before this patch CMake did feature detections in three files: `src/CMakefiles.txt`, `examples/CMakefiles.txt` and `tests/CMakefiles.txt`. Merge and move them to the root `CMakefiles.txt`. After this patch we end up with a single `src/libssh2_config.h`. This brings CMake in sync with autotools builds, which already worked with a single config header. This also prevents mistakes where feature detection went out of sync between `src` & `tests` (see ae90a35d15d97154ac0c8554bce99ebfb18ee825). `tests` do compile sources from `src` directly, so these should always be in sync. It also allows to better integrate hand-crafted, platform-specific config headers into the builds, like the one currently residing in the `win32` directory (and also in `vms` and `os400`). Subject to an upcoming PR. Also fix a warning revealed after this patch made CMake correctly enable `HAVE_GETTIMEOFDAY` for `example` programs. Closes #906 --- CMakeLists.txt | 88 +++++++++++++++++++++++++++++++ example/CMakeLists.txt | 24 ++------- example/Makefile.am | 2 +- example/libssh2_config_cmake.h.in | 46 ---------------- example/scp_nonblock.c | 3 +- example/sftp_nonblock.c | 3 +- src/CMakeLists.txt | 87 ++---------------------------- src/libssh2_config_cmake.h.in | 5 ++ tests/CMakeLists.txt | 26 +++------ tests/Makefile.am | 1 - tests/libssh2_config_cmake.h.in | 47 ----------------- 11 files changed, 112 insertions(+), 220 deletions(-) delete mode 100644 example/libssh2_config_cmake.h.in delete mode 100644 tests/libssh2_config_cmake.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a23d2efbec..40b7563bdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,10 +33,16 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. +include(CheckFunctionExists) +include(CheckSymbolExists) include(CheckIncludeFiles) +include(CheckTypeSize) +include(CheckSymbolExists) +include(CMakePushCheckState) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") include(CheckFunctionExistsMayNeedLibrary) +include(CheckNonblockingSocketSupport) cmake_minimum_required(VERSION 3.1) @@ -111,6 +117,88 @@ endif() set(LIB_STATIC "libssh2_static") set(LIB_SHARED "libssh2_shared") # Must match libssh2_shared_EXPORTS macro in include/libssh2.h +# Auto-detection + +## Platform checks +check_include_files(unistd.h HAVE_UNISTD_H) +check_include_files(inttypes.h HAVE_INTTYPES_H) +check_include_files(stdlib.h HAVE_STDLIB_H) +check_include_files(sys/select.h HAVE_SYS_SELECT_H) + +check_include_files(sys/uio.h HAVE_SYS_UIO_H) +check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) +check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) +check_include_files(sys/time.h HAVE_SYS_TIME_H) +check_include_files(sys/un.h HAVE_SYS_UN_H) +check_include_files(ws2tcpip.h HAVE_WS2TCPIP_H) +check_include_files(winsock2.h HAVE_WINSOCK2_H) + +# for example and tests +check_include_files(sys/param.h HAVE_SYS_PARAM_H) +check_include_files(arpa/inet.h HAVE_ARPA_INET_H) +check_include_files(netinet/in.h HAVE_NETINET_IN_H) + +check_type_size("long long" LONGLONG) + +# CMake uses C syntax in check_symbol_exists() that generates a warning with +# MSVC. To not break detection with ENABLE_WERRROR, we disable it for the +# duration of these tests. +if(MSVC AND ENABLE_WERROR) + cmake_push_check_state() + set(CMAKE_REQUIRED_FLAGS "/WX-") +endif() + +if(HAVE_SYS_TIME_H) + check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY) +else() + check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) +endif() +if(HAVE_STDLIB_H) + check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) +else() + check_function_exists(strtoll HAVE_STRTOLL) +endif() +if (NOT HAVE_STRTOLL) + # Try _strtoi64 if strtoll isn't available + check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64) +endif() +check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) +if(NOT WIN32) + check_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO) + check_symbol_exists(explicit_memset string.h HAVE_EXPLICIT_MEMSET) + check_symbol_exists(memset_s string.h HAVE_MEMSET_S) +endif() + +if(MSVC AND ENABLE_WERROR) + cmake_pop_check_state() +endif() + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR + ${CMAKE_SYSTEM_NAME} STREQUAL "Interix") + # poll() does not work on these platforms + # + # Interix: "does provide poll(), but the implementing developer must + # have been in a bad mood, because poll() only works on the /proc + # filesystem here" + # + # Mac OS X's poll has funny behaviors, like: + # not being able to do poll on no filedescriptors (10.3?) + # not being able to poll on some files (like anything in /dev) + # not having reliable timeout support + # inconsistent return of POLLHUP where other implementations give POLLIN + message("poll use is disabled on this platform") +else() + check_function_exists(poll HAVE_POLL) +endif() + +# Non-blocking socket support tests. Use a separate, yet unset variable +# for the socket libraries to not link against the other configured +# dependencies which might not have been built yet. +cmake_push_check_state() +set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES}) +check_nonblocking_socket_support() +cmake_pop_check_state() + ## Cryptography backend choice set(CRYPTO_BACKEND diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 41dfa51134..c20d37ce07 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -33,9 +33,12 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -include(CheckIncludeFiles) include(CopyRuntimeDependencies) +list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) + +add_definitions(-DHAVE_CONFIG_H) + set(EXAMPLES direct_tcpip ssh2 @@ -61,31 +64,14 @@ set(EXAMPLES subsystem_netconf tcpip-forward) -list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) - foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) list(APPEND EXAMPLE_TARGETS example-${example}) # to find generated header - target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src) target_link_libraries(example-${example} ${LIB_STATIC} ${LIBRARIES}) endforeach() add_target_to_copy_dependencies( TARGET copy_example_dependencies DEPENDENCIES ${RUNTIME_DEPENDENCIES} BEFORE_TARGETS ${EXAMPLE_TARGETS}) - -## Platform checks -check_include_files(inttypes.h HAVE_INTTYPES_H) -check_include_files(unistd.h HAVE_UNISTD_H) -check_include_files(stdlib.h HAVE_STDLIB_H) -check_include_files(sys/select.h HAVE_SYS_SELECT_H) -check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) -check_include_files(sys/time.h HAVE_SYS_TIME_H) -check_include_files(arpa/inet.h HAVE_ARPA_INET_H) -check_include_files(netinet/in.h HAVE_NETINET_IN_H) -check_include_files(winsock2.h HAVE_WINSOCK2_H) - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in - ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) diff --git a/example/Makefile.am b/example/Makefile.am index 2bd08c7c53..1fa4c25744 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign nostdinc -EXTRA_DIST = libssh2_config_cmake.h.in CMakeLists.txt +EXTRA_DIST = CMakeLists.txt # examples noinst_PROGRAMS = \ diff --git a/example/libssh2_config_cmake.h.in b/example/libssh2_config_cmake.h.in deleted file mode 100644 index 9985d74fbc..0000000000 --- a/example/libssh2_config_cmake.h.in +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2014 Alexander Lamaison - * - * Redistribution and use in source and binary forms, - * with or without modification, are permitted provided - * that the following conditions are met: - * - * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * Neither the name of the copyright holder nor the names - * of any other contributors may be used to endorse or - * promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -/* Headers */ -#cmakedefine HAVE_UNISTD_H -#cmakedefine HAVE_INTTYPES_H -#cmakedefine HAVE_STDLIB_H -#cmakedefine HAVE_SYS_SELECT_H -#cmakedefine HAVE_SYS_SOCKET_H -#cmakedefine HAVE_SYS_TIME_H -#cmakedefine HAVE_ARPA_INET_H -#cmakedefine HAVE_NETINET_IN_H -#cmakedefine HAVE_WINSOCK2_H diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 56ecfe2d21..0b4a8ec8aa 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -276,7 +276,8 @@ int main(int argc, char *argv[]) time_ms = tvdiff(end, start); fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", - (long)total, time_ms, (double)total/(time_ms/1000.0), spin); + (long)total, time_ms, + (double)total/((double)time_ms/1000.0), spin); #else fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin); #endif diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 8b33986714..279cc8e42c 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -283,7 +283,8 @@ int main(int argc, char *argv[]) gettimeofday(&end, NULL); time_ms = tvdiff(end, start); fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", - (long)total, time_ms, (double)total/(time_ms/1000.0), spin); + (long)total, time_ms, + (double)total/((double)time_ms/1000.0), spin); #else fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin); #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 44e03d7ac5..b1f6c7e342 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,14 +33,6 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -include(CheckFunctionExists) -include(CheckSymbolExists) -include(CheckIncludeFiles) -include(CheckTypeSize) -include(CheckSymbolExists) -include(CheckNonblockingSocketSupport) -include(CMakePushCheckState) - if(CRYPTO_BACKEND) list(APPEND PRIVATE_COMPILE_DEFINITIONS ${CRYPTO_BACKEND_DEFINE}) list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${CRYPTO_BACKEND_INCLUDE_DIR}) @@ -89,73 +81,6 @@ if(ENABLE_DEBUG_LOGGING) list(APPEND libssh2_DEFINITIONS LIBSSH2DEBUG) endif() -## Platform checks -check_include_files(unistd.h HAVE_UNISTD_H) -check_include_files(inttypes.h HAVE_INTTYPES_H) -check_include_files(stdlib.h HAVE_STDLIB_H) -check_include_files(sys/select.h HAVE_SYS_SELECT_H) - -check_include_files(sys/uio.h HAVE_SYS_UIO_H) -check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) -check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) -check_include_files(sys/time.h HAVE_SYS_TIME_H) -check_include_files(sys/un.h HAVE_SYS_UN_H) -check_include_files(ws2tcpip.h HAVE_WS2TCPIP_H) -check_include_files(winsock2.h HAVE_WINSOCK2_H) - -check_type_size("long long" LONGLONG) - -# CMake uses C syntax in check_symbol_exists() that generates a warning with -# MSVC. To not break detection with ENABLE_WERRROR, we disable it for the -# duration of these tests. -if(MSVC AND ENABLE_WERROR) - cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "/WX-") -endif() - -if(HAVE_SYS_TIME_H) - check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY) -else() - check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) -endif() -if(HAVE_STDLIB_H) - check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) -else() - check_function_exists(strtoll HAVE_STRTOLL) -endif() -if (NOT HAVE_STRTOLL) - # Try _strtoi64 if strtoll isn't available - check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64) -endif() -check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) -if(NOT WIN32) - check_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO) - check_symbol_exists(explicit_memset string.h HAVE_EXPLICIT_MEMSET) - check_symbol_exists(memset_s string.h HAVE_MEMSET_S) -endif() - -if(MSVC AND ENABLE_WERROR) - cmake_pop_check_state() -endif() - -if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR - ${CMAKE_SYSTEM_NAME} STREQUAL "Interix") - # poll() does not work on these platforms - # - # Interix: "does provide poll(), but the implementing developer must - # have been in a bad mood, because poll() only works on the /proc - # filesystem here" - # - # Mac OS X's poll has funny behaviors, like: - # not being able to do poll on no filedescriptors (10.3?) - # not being able to poll on some files (like anything in /dev) - # not having reliable timeout support - # inconsistent return of POLLHUP where other implementations give POLLIN - message("poll use is disabled on this platform") -else() - check_function_exists(poll HAVE_POLL) -endif() - list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) if(WIN32) @@ -163,17 +88,11 @@ if(WIN32) list(APPEND PC_LIBS -lws2_32) endif() -# Non-blocking socket support tests. Use a separate, yet unset variable -# for the socket libraries to not link against the other configured -# dependencies which might not have been built yet. -cmake_push_check_state() -set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES}) -check_nonblocking_socket_support() -cmake_pop_check_state() +add_definitions(-DHAVE_CONFIG_H) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in +configure_file(libssh2_config_cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) + # to find generated header list(APPEND libssh2_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index f8f3baa222..712e869d47 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -48,6 +48,11 @@ #cmakedefine HAVE_WS2TCPIP_H #cmakedefine HAVE_WINSOCK2_H +/* for example and tests */ +#cmakedefine HAVE_SYS_PARAM_H +#cmakedefine HAVE_ARPA_INET_H +#cmakedefine HAVE_NETINET_IN_H + /* Libraries */ #cmakedefine HAVE_LIBCRYPT32 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3bba01e695..53f6fa618f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,26 +33,12 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -include(CheckIncludeFiles) -include(CheckFunctionExists) -include(CheckSymbolExists) include(CopyRuntimeDependencies) -## Platform checks -check_include_files(inttypes.h HAVE_INTTYPES_H) -check_include_files(unistd.h HAVE_UNISTD_H) -check_include_files(sys/param.h HAVE_SYS_PARAM_H) -check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) -check_include_files(arpa/inet.h HAVE_ARPA_INET_H) -check_include_files(winsock2.h HAVE_WINSOCK2_H) -check_include_files(netinet/in.h HAVE_NETINET_IN_H) -check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h") - list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) +add_definitions(-DHAVE_CONFIG_H) + set(TESTS warmup hostkey @@ -92,21 +78,21 @@ if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") endif() add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) -target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" ../include) +target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../include) target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") # test building against shared libssh2 lib if(BUILD_SHARED_LIBS) set(test warmup) # any test will do add_executable(test_${test}_shared test_${test}.c) - target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src") target_link_libraries(test_${test}_shared runner ${LIB_SHARED} ${LIBRARIES}) endif() foreach(test ${TESTS}) add_executable(test_${test} test_${test}.c) list(APPEND TEST_TARGETS test_${test}) - target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src") target_link_libraries(test_${test} runner ${LIB_STATIC} ${LIBRARIES}) add_test( @@ -152,7 +138,7 @@ endforeach() add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) target_compile_definitions(test_keyboard_interactive_auth_info_request PRIVATE "${CRYPTO_BACKEND_DEFINE}") -target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" "../src/" "${CRYPTO_BACKEND_INCLUDE_DIR}") +target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src/" "${CRYPTO_BACKEND_INCLUDE_DIR}") find_program(GCOV_PATH gcov) set(TGT_OPTIONS -g --coverage -fprofile-abs-path) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) diff --git a/tests/Makefile.am b/tests/Makefile.am index b27fb27990..f0ada7d337 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -85,7 +85,6 @@ EXTRA_DIST = \ key_rsa_encrypted.pub \ key_rsa_openssh \ key_rsa_openssh.pub \ - libssh2_config_cmake.h.in \ mansyntax.sh \ openssh_server/Dockerfile \ openssh_server/authorized_keys \ diff --git a/tests/libssh2_config_cmake.h.in b/tests/libssh2_config_cmake.h.in deleted file mode 100644 index 4cf1d09934..0000000000 --- a/tests/libssh2_config_cmake.h.in +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (c) 2014 Alexander Lamaison - * - * Redistribution and use in source and binary forms, - * with or without modification, are permitted provided - * that the following conditions are met: - * - * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * Neither the name of the copyright holder nor the names - * of any other contributors may be used to endorse or - * promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -/* Headers */ -#cmakedefine HAVE_UNISTD_H -#cmakedefine HAVE_INTTYPES_H -#cmakedefine HAVE_SYS_PARAM_H -#cmakedefine HAVE_SYS_SOCKET_H -#cmakedefine HAVE_ARPA_INET_H -#cmakedefine HAVE_NETINET_IN_H -#cmakedefine HAVE_WINSOCK2_H - -/* Functions */ -#cmakedefine HAVE_SNPRINTF From ccfeac87da57b8ca2b29c2694c1ff97d83ed02bb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 31 Mar 2023 19:03:21 +0000 Subject: [PATCH 193/424] cmake: add missing man pages --- docs/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index a95b44c2d5..4a0504738e 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -71,6 +71,7 @@ set(MAN_PAGES libssh2_channel_read_stderr.3 libssh2_channel_receive_window_adjust.3 libssh2_channel_receive_window_adjust2.3 + libssh2_channel_request_auth_agent.3 libssh2_channel_request_pty.3 libssh2_channel_request_pty_ex.3 libssh2_channel_request_pty_size.3 @@ -191,6 +192,7 @@ set(MAN_PAGES libssh2_sftp_unlink.3 libssh2_sftp_unlink_ex.3 libssh2_sftp_write.3 + libssh2_sign_sk.3 libssh2_trace.3 libssh2_trace_sethandler.3 libssh2_userauth_authenticated.3 @@ -206,6 +208,7 @@ set(MAN_PAGES libssh2_userauth_publickey_fromfile.3 libssh2_userauth_publickey_fromfile_ex.3 libssh2_userauth_publickey_frommemory.3 + libssh2_userauth_publickey_sk.3 libssh2_version.3) include(GNUInstallDirs) From 9aa1964dfbeec338c38abba171dc658412432719 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 31 Mar 2023 18:14:38 +0000 Subject: [PATCH 194/424] tidy-up: whitespace, sorting, comment and naming fixups --- docs/CMakeLists.txt | 2 +- docs/Makefile.am | 2 +- example/CMakeLists.txt | 13 +++++++------ example/x11.c | 3 +-- src/channel.h | 1 - src/libssh2.pc.in | 2 +- src/libssh2_config_cmake.h.in | 5 +++-- src/libssh2_priv.h | 2 +- src/packet.c | 1 - src/session.c | 2 +- win32/GNUmakefile | 26 +++++++++++++------------- 11 files changed, 29 insertions(+), 30 deletions(-) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 4a0504738e..d8b9296af9 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -144,10 +144,10 @@ set(MAN_PAGES libssh2_session_init_ex.3 libssh2_session_last_errno.3 libssh2_session_last_error.3 - libssh2_session_set_last_error.3 libssh2_session_method_pref.3 libssh2_session_methods.3 libssh2_session_set_blocking.3 + libssh2_session_set_last_error.3 libssh2_session_set_timeout.3 libssh2_session_startup.3 libssh2_session_supported_algs.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index 6b938ba71b..cc0e52446d 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -114,10 +114,10 @@ dist_man_MANS = \ libssh2_session_init_ex.3 \ libssh2_session_last_errno.3 \ libssh2_session_last_error.3 \ - libssh2_session_set_last_error.3 \ libssh2_session_method_pref.3 \ libssh2_session_methods.3 \ libssh2_session_set_blocking.3 \ + libssh2_session_set_last_error.3 \ libssh2_session_set_timeout.3 \ libssh2_session_startup.3 \ libssh2_session_supported_algs.3 \ diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index c20d37ce07..1badba3ec0 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -41,26 +41,26 @@ add_definitions(-DHAVE_CONFIG_H) set(EXAMPLES direct_tcpip - ssh2 scp scp_nonblock scp_write scp_write_nonblock sftp + sftp_RW_nonblock + sftp_append + sftp_mkdir + sftp_mkdir_nonblock sftp_nonblock sftp_write sftp_write_nonblock - sftp_mkdir - sftp_mkdir_nonblock - sftp_RW_nonblock sftp_write_sliding sftpdir sftpdir_nonblock - ssh2_exec + ssh2 ssh2_agent ssh2_agent_forwarding ssh2_echo - sftp_append + ssh2_exec subsystem_netconf tcpip-forward) @@ -71,6 +71,7 @@ foreach(example ${EXAMPLES}) target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src) target_link_libraries(example-${example} ${LIB_STATIC} ${LIBRARIES}) endforeach() + add_target_to_copy_dependencies( TARGET copy_example_dependencies DEPENDENCIES ${RUNTIME_DEPENDENCIES} diff --git a/example/x11.c b/example/x11.c index e66da6888a..80d4f46584 100644 --- a/example/x11.c +++ b/example/x11.c @@ -1,8 +1,7 @@ /* - * * Sample showing how to makes SSH2 with X11 Forwarding works. * - * Usage : + * Usage: * "ssh2 host user password [DEBUG]" */ diff --git a/src/channel.h b/src/channel.h index dc0ee3764f..4466c4fc7f 100644 --- a/src/channel.h +++ b/src/channel.h @@ -138,4 +138,3 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel); int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener); #endif /* __LIBSSH2_CHANNEL_H */ - diff --git a/src/libssh2.pc.in b/src/libssh2.pc.in index c070988b93..282a39b5fa 100644 --- a/src/libssh2.pc.in +++ b/src/libssh2.pc.in @@ -14,4 +14,4 @@ Version: @LIBSSH2_VERSION@ Requires.private: @PC_REQUIRES_PRIVATE@ Libs: -L${libdir} -lssh2 @PC_LIBS@ Libs.private: @PC_LIBS@ -Cflags: -I${includedir} \ No newline at end of file +Cflags: -I${includedir} diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 712e869d47..8ee6389bbe 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -61,8 +61,6 @@ /* Functions */ #cmakedefine HAVE_GETTIMEOFDAY -#cmakedefine HAVE_POLL -#cmakedefine HAVE_SELECT #cmakedefine HAVE_STRTOLL #cmakedefine HAVE_STRTOI64 #cmakedefine HAVE_SNPRINTF @@ -70,6 +68,9 @@ #cmakedefine HAVE_EXPLICIT_MEMSET #cmakedefine HAVE_MEMSET_S +#cmakedefine HAVE_POLL +#cmakedefine HAVE_SELECT + /* Socket non-blocking support */ #cmakedefine HAVE_O_NONBLOCK #cmakedefine HAVE_FIONBIO diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 3e02cf1834..adb0dca9d1 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -76,7 +76,7 @@ # define LIBSSH2_WINDOWS_APP # endif # endif -#endif +#endif /* WIN32 */ #ifdef HAVE_WS2TCPIP_H #include diff --git a/src/packet.c b/src/packet.c index 43b92f7b6c..f507770a22 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1406,4 +1406,3 @@ _libssh2_packet_requirev(LIBSSH2_SESSION *session, state->start = 0; return LIBSSH2_ERROR_SOCKET_DISCONNECT; } - diff --git a/src/session.c b/src/session.c index 817bc17939..65946e1e8d 100644 --- a/src/session.c +++ b/src/session.c @@ -1740,7 +1740,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) */ sysret = poll(sockets, nfds, (int)timeout_remaining); timeout_remaining = 0; -#endif /* HAVE_GETTIMEOFDAY */ +#endif /* HAVE_LIBSSH2_GETTIMEOFDAY */ if(sysret > 0) { for(i = 0; i < nfds; i++) { diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 7bf0ad35d9..2c91eaef62 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -68,9 +68,9 @@ endif DB ?= NDEBUG CPPFLAGS += -D$(DB) ifeq ($(DB),NDEBUG) - OBJDIR := release + OBJ_DIR := release else - OBJDIR := debug + OBJ_DIR := debug CFLAGS += -g CPPFLAGS += -DLIBSSH2DEBUG endif @@ -143,7 +143,7 @@ AWK := awk ZIP := zip -qzr9 # Include the version info retrieved from libssh2.h --include $(OBJDIR)/version.inc +-include $(OBJ_DIR)/version.inc vpath %.c $(PROOT)/src @@ -151,7 +151,7 @@ vpath %.c $(PROOT)/src include $(PROOT)/Makefile.inc OBJECTS := $(patsubst %.c,%.o,$(CSOURCES)) -OBJS := $(addprefix $(OBJDIR)/,$(OBJECTS)) +OBJS := $(addprefix $(OBJ_DIR)/,$(OBJECTS)) TARGET := libssh2 @@ -172,29 +172,29 @@ dll: prebuild $(libssh2_dll_LIBRARY) lib: prebuild $(TARGET).a -prebuild: $(OBJDIR) $(OBJDIR)/version.inc +prebuild: $(OBJ_DIR) $(OBJ_DIR)/version.inc test: $(TARGETS_EXAMPLES) %.exe: %.c $(libssh2_DEPENDENCIES) $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) $< -o $@ $(LIBS) $(LIBS_BIN) -$(OBJDIR)/%.o: %.c +$(OBJ_DIR)/%.o: %.c $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@ -$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS) $(OBJDIR)/$(TARGET).res +$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS) $(OBJ_DIR)/$(TARGET).res @$(call DEL, $@) $(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_LIB) $^ -o $@ $(LIBS) $(LIBS_LIB) \ -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(libssh2_dll_a_LIBRARY) -$(OBJDIR)/%.res: %.rc +$(OBJ_DIR)/%.res: %.rc $(RC) -O coff $(RCFLAGS) -i $< -o $@ $(TARGET).a: $(OBJS) @$(call DEL, $@) $(AR) rcs $@ $^ -$(OBJDIR)/version.inc: $(PROOT)/get_ver.awk $(PROOT)/include/libssh2.h $(OBJDIR) +$(OBJ_DIR)/version.inc: $(PROOT)/get_ver.awk $(PROOT)/include/libssh2.h $(OBJ_DIR) $(AWK) -f $^ > $@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @@ -216,16 +216,16 @@ distclean vclean: clean $(call DEL, $(DISTARC)) objclean: all - $(call RMDIR, $(OBJDIR)) + $(call RMDIR, $(OBJ_DIR)) testclean: clean $(call DEL, $(TARGETS_EXAMPLES)) clean: $(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:.dll=.def) $(TARGET).a $(libssh2_dll_a_LIBRARY)) - $(call RMDIR, $(OBJDIR)) + $(call RMDIR, $(OBJ_DIR)) -$(OBJDIR): +$(OBJ_DIR): @$(call MKDIR, $@) $(DISTDIR): @@ -239,7 +239,7 @@ $(DISTDIR)/readme.txt: GNUmakefile @echo $(DL)any further documentation:$(DL) >> $@ @echo $(DL)$(HOMEPAGE)$(DL) >> $@ -help: $(OBJDIR)/version.inc +help: $(OBJ_DIR)/version.inc @echo $(DL)===========================================================$(DL) @echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL) @echo $(DL)wolfSSL path = $(WOLFSSL_PATH)$(DL) From 91af53851d735170926f69505379545ac8a172d3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 31 Mar 2023 23:45:36 +0000 Subject: [PATCH 195/424] .gitignore updates [ci skip] --- example/.gitignore | 25 ++++++++++--------------- src/.gitignore | 2 ++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/example/.gitignore b/example/.gitignore index a1549e2f3a..4d26823d30 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,36 +1,31 @@ +.deps +.libs Makefile Makefile.in *.gcno *.gcda +stamp-h2 direct_tcpip scp scp_nonblock scp_write scp_write_nonblock sftp -sftp_nonblock -sftpdir -sftpdir_nonblock -ssh2 sftp_RW_nonblock +sftp_append sftp_mkdir sftp_mkdir_nonblock +sftp_nonblock sftp_write sftp_write_nonblock -config.h.in -ssh2_exec +sftp_write_sliding +sftpdir +sftpdir_nonblock +ssh2 ssh2_agent ssh2_agent_forwarding -stamp-h2 -sftp_append -sftp_write_sliding ssh2_echo +ssh2_exec subsystem_netconf -test-scp -test-sftp_append -test-sftp_nonblock -test-sftp_write -test-sftp_write_nonblock -test-ssh2_echo tcpip-forward x11 diff --git a/src/.gitignore b/src/.gitignore index 0dd1abc0c4..2c86ec73df 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,5 @@ +.deps +.libs libssh2_config.h libssh2_config.h.in stamp-h1 From d245c66cc0029e480674394c23e8be1c9410f7ad Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 01:36:54 +0000 Subject: [PATCH 196/424] example: make `x11` exclusion build-tool-agnostic Whether to build the `x11` example or not was decided by each build tool. CMake didn't build it even on supported platforms. GNUMakefile used a specific blocklist for it, while autotools enabled it based on feature-detection. Migrate the enabler logic to an #ifdef in source and build `x11` unconditionally with all build tools. On unsupported platforms (=Windows) this program now displays a short message stating that fact. Also: - fix `x11.c` warnings uncovered after CMake started building it. - use `libssh2_socket_t` type for portability in `x11.c` too. - use detected header guards in `x11.c`. - delete a duplicate reference to `-lws2_32` from `win32/GNUmakefile` while there. Closes #909 --- example/CMakeLists.txt | 3 +- example/Makefile.am | 7 ++--- example/x11.c | 64 +++++++++++++++++++++++++++++++++--------- win32/GNUmakefile | 4 +-- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 1badba3ec0..66e5debaea 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -62,7 +62,8 @@ set(EXAMPLES ssh2_echo ssh2_exec subsystem_netconf - tcpip-forward) + tcpip-forward + x11) foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) diff --git a/example/Makefile.am b/example/Makefile.am index 1fa4c25744..495f93eb59 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -26,11 +26,8 @@ noinst_PROGRAMS = \ ssh2_echo \ ssh2_exec \ subsystem_netconf \ - tcpip-forward - -if HAVE_SYS_UN_H -noinst_PROGRAMS += x11 -endif + tcpip-forward \ + x11 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/example -I../src LDADD = $(top_builddir)/src/libssh2.la diff --git a/example/x11.c b/example/x11.c index 80d4f46584..ecce88716a 100644 --- a/example/x11.c +++ b/example/x11.c @@ -5,23 +5,44 @@ * "ssh2 host user password [DEBUG]" */ +#include +#include "libssh2_config.h" + +#include + +#ifdef HAVE_SYS_UN_H + #include +#ifdef HAVE_SYS_IOCTL_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_SYS_SELECT_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_UNISTD_H #include +#endif #include +#ifdef HAVE_SYS_UN_H #include +#endif #include #include -#include #include +#ifdef HAVE_STDLIB_H #include -#include +#endif -#include +#include #define _PATH_UNIX_X "/tmp/.X11-unix/X%d" @@ -67,7 +88,7 @@ static void remove_node(struct chan_X11_list *elem) static void session_shutdown(LIBSSH2_SESSION *session) { libssh2_session_disconnect(session, - "Session Shutdown, Thank you for playing"); + "Session Shutdown, Thank you for playing"); libssh2_session_free(session); } @@ -109,8 +130,8 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, char *ptr = NULL; char *temp_buff = NULL; int display_port = 0; - int sock = 0; int rc = 0; + libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; struct sockaddr_un addr; struct chan_X11_list *new; struct chan_X11_list *chan_iter; @@ -138,7 +159,7 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, free(temp_buff); sock = socket(AF_UNIX, SOCK_STREAM, 0); - if(sock < 0) + if(sock == LIBSSH2_INVALID_SOCKET) return; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; @@ -212,7 +233,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) fds[0].revents = LIBSSH2_POLLFD_POLLIN; rc = libssh2_poll(fds, nfds, 0); - if(rc >0) { + if(rc > 0) { ssize_t nread; nread = libssh2_channel_read(channel, buf, bufsize); write(sock, buf, nread); @@ -220,12 +241,14 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) rc = select((int)(sock + 1), &set, NULL, NULL, &timeval_out); if(rc > 0) { + ssize_t nread; + memset((void *)buf, 0, bufsize); /* Data in sock */ - rc = read(sock, buf, bufsize); - if(rc > 0) { - libssh2_channel_write(channel, buf, rc); + nread = read(sock, buf, bufsize); + if(nread > 0) { + libssh2_channel_write(channel, buf, nread); } else { free(buf); @@ -248,8 +271,8 @@ int main (int argc, char *argv[]) { uint32_t hostaddr = 0; - int sock = 0; int rc = 0; + libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; struct sockaddr_in sin; LIBSSH2_SESSION *session; LIBSSH2_CHANNEL *channel; @@ -298,7 +321,7 @@ main (int argc, char *argv[]) } sock = socket(AF_INET, SOCK_STREAM, 0); - if(sock == -1) { + if(sock == LIBSSH2_INVALID_SOCKET) { perror("socket"); return -1; } @@ -450,9 +473,11 @@ main (int argc, char *argv[]) rc = select((int)(fileno(stdin) + 1), &set, NULL, NULL, &timeval_out); if(rc > 0) { + ssize_t nread; + /* Data in stdin */ - rc = read(fileno(stdin), buf, 1); - if(rc > 0) + nread = read(fileno(stdin), buf, 1); + if(nread > 0) libssh2_channel_write(channel, buf, sizeof(buf)); } @@ -474,3 +499,14 @@ main (int argc, char *argv[]) return 0; } + +#else + +int +main (void) +{ + printf("Sorry, this platform is not supported."); + return 1; +} + +#endif /* HAVE_SYS_UN_H */ diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 2c91eaef62..4996627620 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -52,7 +52,7 @@ RCFLAGS += -I$(PROOT)/include # examples, tests LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32 -LIBS_BIN := -lssh2 -lws2_32 +LIBS_BIN := -lssh2 ifdef DYN libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a @@ -164,7 +164,7 @@ libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll libssh2_dll_a_LIBRARY := $(TARGET).dll.a EXAMPLES := $(PROOT)/example -TARGETS_EXAMPLES := $(filter-out $(EXAMPLES)/x11.exe,$(patsubst %.c,%.exe,$(strip $(wildcard $(EXAMPLES)/*.c)))) +TARGETS_EXAMPLES := $(patsubst %.c,%.exe,$(strip $(wildcard $(EXAMPLES)/*.c))) all: lib dll From 0d1ef8a7cb12acf987ab32a9d752cd8275daf94d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 01:47:08 +0000 Subject: [PATCH 197/424] win32/libssh2_config.h: set `HAVE_LONGLONG` & `HAVE_STDLIB_H` [ci skip] - enable `HAVE_LONGLONG` for MinGW and MSVC versions supporting it. Necessary for `GNUmakefile`/`NMakefile` builds to create the same binaries as CMake/autotools ones do. - enable `HAVE_STDLIB_H`. It has been universally available on Windows for a long time. Fixes these clang-cl warnings: ``` src\wincng.c(444,5) : warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration] free(buf); ^ src\wincng.c(491,20) : warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long long)' [-Wimplicit-function-declaration] pbHashObject = malloc(dwHashObject); ^ src\wincng.c(491,20) : note: include the header or explicitly provide a declaration for 'malloc' src\wincng.c(2106,14) : warning: implicitly declaring library function 'realloc' with type 'void *(void *, unsigned long long)' [-Wimplicit-function-declaration] bignum = realloc(bn->bignum, length); ^ src\wincng.c(2106,14) : note: include the header or explicitly provide a declaration for 'realloc' 3 warnings generated. ``` --- win32/libssh2_config.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 352209108a..493826c4a0 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -11,6 +11,7 @@ #define HAVE_LIBCRYPT32 #define HAVE_WINSOCK2_H +#define HAVE_STDLIB_H #define HAVE_IOCTLSOCKET #define HAVE_SELECT #define HAVE_SNPRINTF @@ -20,8 +21,12 @@ # define HAVE_INTTYPES_H # define HAVE_SYS_TIME_H # define HAVE_GETTIMEOFDAY +# define HAVE_LONGLONG # define HAVE_STRTOLL #elif defined(_MSC_VER) +# if _MSC_VER >= 1310 +# define HAVE_LONGLONG +# endif # if _MSC_VER >= 1800 # define HAVE_STRTOLL # endif From b66d7317ca6c882afbe52fe426f68c119c40d348 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 01:02:06 +0000 Subject: [PATCH 198/424] delete redundant `HAVE_WS2TCPIP_H` It was used once in `src/libssh2_priv.h`, but without any effect. The header included `ws2tcpip.h` twice, once guarded by `HAVE_WS2TCPIP_H` and another time by `HAVE_WINSOCK2_H`. Dedupe these to not use `HAVE_WS2TCPIP_H`. Then delete detection of this feature from all build methods. TODO: Replace `HAVE_WINSOCK2_H` with `_WIN32`/`WIN32`. --- CMakeLists.txt | 1 - configure.ac | 2 +- os400/libssh2_config.h | 3 --- src/libssh2_config_cmake.h.in | 1 - src/libssh2_priv.h | 14 +++++--------- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40b7563bdf..301718f78f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,6 @@ check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files(sys/un.h HAVE_SYS_UN_H) -check_include_files(ws2tcpip.h HAVE_WS2TCPIP_H) check_include_files(winsock2.h HAVE_WINSOCK2_H) # for example and tests diff --git a/configure.ac b/configure.ac index c7f477676c..6c51288f04 100644 --- a/configure.ac +++ b/configure.ac @@ -289,7 +289,7 @@ case $host in # These are POSIX-like systems using BSD-like sockets API. ;; *) - AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h]) + AC_CHECK_HEADERS([windows.h winsock2.h]) ;; esac diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 5de01fdb74..df3c381d70 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -137,9 +137,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WINSOCK2_H -/* Define to 1 if you have the header file. */ -#undef HAVE_WS2TCPIP_H - /* to make a symbol visible */ #undef LIBSSH2_API diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 8ee6389bbe..e0ccdade3f 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -45,7 +45,6 @@ #cmakedefine HAVE_SYS_IOCTL_H #cmakedefine HAVE_SYS_TIME_H #cmakedefine HAVE_SYS_UN_H -#cmakedefine HAVE_WS2TCPIP_H #cmakedefine HAVE_WINSOCK2_H /* for example and tests */ diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index adb0dca9d1..87c7d4db85 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -78,8 +78,12 @@ # endif #endif /* WIN32 */ -#ifdef HAVE_WS2TCPIP_H +#ifdef HAVE_WINSOCK2_H +#include #include +/* Force parameter type. */ +#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) +#define send(s, b, l, f) send((s), (b), (int)(l), (f)) #endif #include @@ -164,14 +168,6 @@ struct iovec { #include "crypto.h" -#ifdef HAVE_WINSOCK2_H -#include -#include -/* Force parameter type. */ -#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) -#define send(s, b, l, f) send((s), (b), (int)(l), (f)) -#endif - #ifndef SIZE_MAX #if _WIN64 #define SIZE_MAX 0xFFFFFFFFFFFFFFFF From 618c0e68ac91b056799139e4fa7bab4b6ec76c2f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 11:52:53 +0000 Subject: [PATCH 199/424] win32/GNUmakefile: fixups to previous commit [ci skip] - `-lws2_32` is necessary when building examples. - drop a temporary variable. Follow-up to d245c66cc0029e480674394c23e8be1c9410f7ad --- win32/GNUmakefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 4996627620..5eb97b1b0b 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -52,7 +52,7 @@ RCFLAGS += -I$(PROOT)/include # examples, tests LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32 -LIBS_BIN := -lssh2 +LIBS_BIN := -lssh2 -lws2_32 ifdef DYN libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a @@ -163,8 +163,7 @@ LIBSSH2_DLL_SUFFIX ?= libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll libssh2_dll_a_LIBRARY := $(TARGET).dll.a -EXAMPLES := $(PROOT)/example -TARGETS_EXAMPLES := $(patsubst %.c,%.exe,$(strip $(wildcard $(EXAMPLES)/*.c))) +TARGETS_EXAMPLES := $(patsubst %.c,%.exe,$(strip $(wildcard $(PROOT)/example/*.c))) all: lib dll From 82644b649ae101e4a4a915daed1868a5121c2977 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 15:24:37 +0000 Subject: [PATCH 200/424] win32/GNUmakefile: default to WinCNG [ci skip] Also check for wolfSSL before mbedTLS to match CMake. --- win32/GNUmakefile | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 5eb97b1b0b..2f5e15884b 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -79,24 +79,7 @@ endif _LDFLAGS := _LIBS := -ifdef WITH_WINCNG - CPPFLAGS += -DLIBSSH2_WINCNG - include $(PROOT)/Makefile.WinCNG.inc -else ifdef MBEDTLS_PATH - CPPFLAGS += -DLIBSSH2_MBEDTLS - CPPFLAGS += -I"$(MBEDTLS_PATH)/include" - _LDFLAGS += -L"$(MBEDTLS_PATH)/lib" - _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto - include $(PROOT)/Makefile.mbedTLS.inc -else ifdef WOLFSSL_PATH - CPPFLAGS += -DLIBSSH2_WOLFSSL - CPPFLAGS += -I"$(WOLFSSL_PATH)/include" - CPPFLAGS += -I"$(WOLFSSL_PATH)/include/wolfssl" - _LDFLAGS += -L"$(WOLFSSL_PATH)/lib" - _LIBS += -lwolfssl - include $(PROOT)/Makefile.wolfSSL.inc -else - OPENSSL_PATH ?= $(PROOT)/../openssl +ifdef OPENSSL_PATH CPPFLAGS += -DLIBSSH2_OPENSSL OPENSSL_INCLUDE ?= $(OPENSSL_PATH)/include OPENSSL_LIBPATH ?= $(OPENSSL_PATH)/lib @@ -105,6 +88,22 @@ else OPENSSL_LIBS ?= -lssl -lcrypto _LIBS += $(OPENSSL_LIBS) include $(PROOT)/Makefile.OpenSSL.inc +else ifdef WOLFSSL_PATH + CPPFLAGS += -DLIBSSH2_WOLFSSL + CPPFLAGS += -I"$(WOLFSSL_PATH)/include" + CPPFLAGS += -I"$(WOLFSSL_PATH)/include/wolfssl" + _LDFLAGS += -L"$(WOLFSSL_PATH)/lib" + _LIBS += -lwolfssl + include $(PROOT)/Makefile.wolfSSL.inc +else ifdef MBEDTLS_PATH + CPPFLAGS += -DLIBSSH2_MBEDTLS + CPPFLAGS += -I"$(MBEDTLS_PATH)/include" + _LDFLAGS += -L"$(MBEDTLS_PATH)/lib" + _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto + include $(PROOT)/Makefile.mbedTLS.inc +else + CPPFLAGS += -DLIBSSH2_WINCNG + include $(PROOT)/Makefile.WinCNG.inc endif ifdef ZLIB_PATH From 68fd02fba002c8c6af3ba51a2780de46b47b3787 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 15:35:14 +0000 Subject: [PATCH 201/424] win32/GNUmakefile: make it support non-Windows builds [ci skip] With 20-ish extra lines, make this Makefile support all GCC-like toolchains. The temporary directory becomes `-{release|debug}` from the former `{release|debug}`. Also change the lib directory name in the `dist` package from `win32` to `lib`, to match other packages and build tools. --- win32/GNUmakefile | 59 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 2f5e15884b..cb9f4f5fa2 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -1,6 +1,6 @@ ######################################################################### # -# Makefile for building libssh2 (Windows version - GNU Make) +# Makefile for building libssh2 with GCC-like toolchains. # Use: make -f GNUmakefile [help|all|clean|dist|distclean|dll|objclean|test|testclean] # # Hacked by: Guenter Knauf @@ -46,16 +46,31 @@ else TRIPLET ?= $(shell $(CC) -dumpmachine) endif +ifneq ($(findstring -w,$(TRIPLET)),) + WIN32 := 1 + BIN_EXT := .exe + DYN_EXT := .dll +endif + CPPFLAGS += -I$(PROOT)/win32 -I$(PROOT)/include RCFLAGS += -I$(PROOT)/include +OBJ_DIR := $(TRIPLET) + # examples, tests LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32 -LIBS_BIN := -lssh2 -lws2_32 +LIBS_BIN := -lssh2 +ifdef WIN32 + LIBS_BIN += -lws2_32 +endif ifdef DYN - libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a + ifdef WIN32 + libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a + else + libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2$(DYN_EXT) + endif LIBSSH2_LDFLAGS_BIN += -shared else libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a @@ -68,9 +83,9 @@ endif DB ?= NDEBUG CPPFLAGS += -D$(DB) ifeq ($(DB),NDEBUG) - OBJ_DIR := release + OBJ_DIR := $(OBJ_DIR)-release else - OBJ_DIR := debug + OBJ_DIR := $(OBJ_DIR)-debug CFLAGS += -g CPPFLAGS += -DLIBSSH2DEBUG endif @@ -101,7 +116,7 @@ else ifdef MBEDTLS_PATH _LDFLAGS += -L"$(MBEDTLS_PATH)/lib" _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto include $(PROOT)/Makefile.mbedTLS.inc -else +else ifdef WIN32 CPPFLAGS += -DLIBSSH2_WINCNG include $(PROOT)/Makefile.WinCNG.inc endif @@ -113,7 +128,9 @@ ifdef ZLIB_PATH _LIBS += -lz endif -_LIBS += -lws2_32 -lcrypt32 -lbcrypt +ifdef WIN32 + _LIBS += -lws2_32 -lcrypt32 -lbcrypt +endif LIBSSH2_LDFLAGS_LIB += $(_LDFLAGS) LIBS_LIB += $(_LIBS) @@ -159,10 +176,15 @@ DISTDIR ?= $(TARGET)-$(LIBSSH2_VERSION_STR)-bin-$(word 1,$(subst -, ,$(TRIPLET)) DISTARC := $(DISTDIR).zip LIBSSH2_DLL_SUFFIX ?= -libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX).dll -libssh2_dll_a_LIBRARY := $(TARGET).dll.a +libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX)$(DYN_EXT) +OBJS_dll := $(OBJS) +ifdef WIN32 + libssh2_dll_a_LIBRARY := $(TARGET).dll.a + OBJS_dll += $(OBJ_DIR)/$(TARGET).res + LIBSSH2_LDFLAGS_LIB += -Wl,--output-def,$(libssh2_dll_LIBRARY:$(DYN_EXT)=.def),--out-implib,$(libssh2_dll_a_LIBRARY) +endif -TARGETS_EXAMPLES := $(patsubst %.c,%.exe,$(strip $(wildcard $(PROOT)/example/*.c))) +TARGETS_EXAMPLES := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard $(PROOT)/example/*.c))) all: lib dll @@ -174,19 +196,20 @@ prebuild: $(OBJ_DIR) $(OBJ_DIR)/version.inc test: $(TARGETS_EXAMPLES) -%.exe: %.c $(libssh2_DEPENDENCIES) +%$(BIN_EXT): %.c $(libssh2_DEPENDENCIES) $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) $< -o $@ $(LIBS) $(LIBS_BIN) $(OBJ_DIR)/%.o: %.c $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@ -$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS) $(OBJ_DIR)/$(TARGET).res +$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS_dll) @$(call DEL, $@) - $(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_LIB) $^ -o $@ $(LIBS) $(LIBS_LIB) \ - -Wl,--output-def,$(libssh2_dll_LIBRARY:.dll=.def),--out-implib,$(libssh2_dll_a_LIBRARY) + $(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_LIB) $^ -o $@ $(LIBS) $(LIBS_LIB) +ifdef WIN32 $(OBJ_DIR)/%.res: %.rc $(RC) -O coff $(RCFLAGS) -i $< -o $@ +endif $(TARGET).a: $(OBJS) @$(call DEL, $@) @@ -198,14 +221,14 @@ $(OBJ_DIR)/version.inc: $(PROOT)/get_ver.awk $(PROOT)/include/libssh2.h $(OBJ_DI dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call MKDIR, $(DISTDIR)/bin) @$(call MKDIR, $(DISTDIR)/include) - @$(call MKDIR, $(DISTDIR)/win32) + @$(call MKDIR, $(DISTDIR)/lib) @$(call COPY, $(PROOT)/COPYING, $(DISTDIR)) @$(call COPY, $(PROOT)/README, $(DISTDIR)) @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) @$(call COPY, $(libssh2_dll_LIBRARY), $(DISTDIR)/bin) @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) @$(call COPY, libssh2_config.h, $(DISTDIR)/include) - @$(call COPY, *.a, $(DISTDIR)/win32) + @$(call COPY, *.a, $(DISTDIR)/lib) @echo Creating... $(DISTARC) @$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt @@ -220,7 +243,7 @@ testclean: clean $(call DEL, $(TARGETS_EXAMPLES)) clean: - $(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:.dll=.def) $(TARGET).a $(libssh2_dll_a_LIBRARY)) + $(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:$(DYN_EXT)=.def) $(TARGET).a $(libssh2_dll_a_LIBRARY)) $(call RMDIR, $(OBJ_DIR)) $(OBJ_DIR): @@ -231,7 +254,7 @@ $(DISTDIR): $(DISTDIR)/readme.txt: GNUmakefile @echo Creating... $@ - @echo $(DL)This is a binary distribution for Windows.$(DL) > $@ + @echo $(DL)This is a binary distribution for $(TRIPLET).$(DL) > $@ @echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@ @echo $(DL)Please download the complete libssh2 package for$(DL) >> $@ @echo $(DL)any further documentation:$(DL) >> $@ From 969487113aae856e43d3d905c3f2260246d44f9b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 15:50:15 +0000 Subject: [PATCH 202/424] libssh2-gnumake.sh: make variable names platform-agnostic [ci skip] Also more consistent. Refer to DLL/SO/shared as 'dyn'. Also add comment on how to find customizable environment variables. --- win32/GNUmakefile | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index cb9f4f5fa2..56a6d40d8b 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -1,10 +1,12 @@ ######################################################################### # # Makefile for building libssh2 with GCC-like toolchains. -# Use: make -f GNUmakefile [help|all|clean|dist|distclean|dll|objclean|test|testclean] +# Use: make -f GNUmakefile [help|all|clean|dist|distclean|dyn|objclean|test|testclean] # # Hacked by: Guenter Knauf # +# Look for ' ?=' to find accepted customization variables. +# ######################################################################### PROOT := .. @@ -18,7 +20,7 @@ CPPFLAGS ?= RCFLAGS ?= LDFLAGS ?= LIBSSH2_LDFLAGS_BIN ?= -LIBSSH2_LDFLAGS_LIB ?= +LIBSSH2_LDFLAGS_DYN ?= LIBS ?= CROSSPREFIX ?= @@ -132,8 +134,8 @@ ifdef WIN32 _LIBS += -lws2_32 -lcrypt32 -lbcrypt endif -LIBSSH2_LDFLAGS_LIB += $(_LDFLAGS) -LIBS_LIB += $(_LIBS) +LIBSSH2_LDFLAGS_DYN += $(_LDFLAGS) +LIBS_DYN += $(_LIBS) ifndef DYN LIBSSH2_LDFLAGS_BIN += $(_LDFLAGS) @@ -175,20 +177,23 @@ TARGET := libssh2 DISTDIR ?= $(TARGET)-$(LIBSSH2_VERSION_STR)-bin-$(word 1,$(subst -, ,$(TRIPLET))) DISTARC := $(DISTDIR).zip -LIBSSH2_DLL_SUFFIX ?= -libssh2_dll_LIBRARY := $(TARGET)$(LIBSSH2_DLL_SUFFIX)$(DYN_EXT) -OBJS_dll := $(OBJS) +LIBSSH2_DYN_SUFFIX ?= +libssh2_dyn_LIBRARY := $(TARGET)$(LIBSSH2_DYN_SUFFIX)$(DYN_EXT) +OBJS_dyn := $(OBJS) ifdef WIN32 - libssh2_dll_a_LIBRARY := $(TARGET).dll.a - OBJS_dll += $(OBJ_DIR)/$(TARGET).res - LIBSSH2_LDFLAGS_LIB += -Wl,--output-def,$(libssh2_dll_LIBRARY:$(DYN_EXT)=.def),--out-implib,$(libssh2_dll_a_LIBRARY) + libssh2_dyn_a_LIBRARY := $(TARGET).dll.a + OBJS_dyn += $(OBJ_DIR)/$(TARGET).res + LIBSSH2_LDFLAGS_DYN += -Wl,--output-def,$(libssh2_dyn_LIBRARY:$(DYN_EXT)=.def),--out-implib,$(libssh2_dyn_a_LIBRARY) endif TARGETS_EXAMPLES := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard $(PROOT)/example/*.c))) -all: lib dll +all: lib dyn + +# For compatibility +dll: dyn -dll: prebuild $(libssh2_dll_LIBRARY) +dyn: prebuild $(libssh2_dyn_LIBRARY) lib: prebuild $(TARGET).a @@ -202,9 +207,9 @@ test: $(TARGETS_EXAMPLES) $(OBJ_DIR)/%.o: %.c $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@ -$(libssh2_dll_LIBRARY) $(libssh2_dll_a_LIBRARY): $(OBJS_dll) +$(libssh2_dyn_LIBRARY) $(libssh2_dyn_a_LIBRARY): $(OBJS_dyn) @$(call DEL, $@) - $(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_LIB) $^ -o $@ $(LIBS) $(LIBS_LIB) + $(CC) $(LDFLAGS) -shared $(LIBSSH2_LDFLAGS_DYN) $^ -o $@ $(LIBS) $(LIBS_DYN) ifdef WIN32 $(OBJ_DIR)/%.res: %.rc @@ -225,7 +230,7 @@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call COPY, $(PROOT)/COPYING, $(DISTDIR)) @$(call COPY, $(PROOT)/README, $(DISTDIR)) @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) - @$(call COPY, $(libssh2_dll_LIBRARY), $(DISTDIR)/bin) + @$(call COPY, $(libssh2_dyn_LIBRARY), $(DISTDIR)/bin) @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) @$(call COPY, libssh2_config.h, $(DISTDIR)/include) @$(call COPY, *.a, $(DISTDIR)/lib) @@ -243,7 +248,7 @@ testclean: clean $(call DEL, $(TARGETS_EXAMPLES)) clean: - $(call DEL, $(libssh2_dll_LIBRARY) $(libssh2_dll_LIBRARY:$(DYN_EXT)=.def) $(TARGET).a $(libssh2_dll_a_LIBRARY)) + $(call DEL, $(libssh2_dyn_LIBRARY) $(libssh2_dyn_LIBRARY:$(DYN_EXT)=.def) $(TARGET).a $(libssh2_dyn_a_LIBRARY)) $(call RMDIR, $(OBJ_DIR)) $(OBJ_DIR): @@ -269,7 +274,7 @@ help: $(OBJ_DIR)/version.inc @echo $(DL)===========================================================$(DL) @echo $(DL)libssh2 $(LIBSSH2_VERSION_STR) - available targets are:$(DL) @echo $(DL)$(MAKE) all$(DL) - @echo $(DL)$(MAKE) dll$(DL) + @echo $(DL)$(MAKE) dyn$(DL) @echo $(DL)$(MAKE) lib$(DL) @echo $(DL)$(MAKE) clean$(DL) @echo $(DL)$(MAKE) dist$(DL) From 5bcd25c4c980e9765c00a2f20ac5348635063aad Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 16:20:13 +0000 Subject: [PATCH 203/424] win32/GNUmakefile: add libgcrypt support [ci skip] In the previous commit 969487113aae856e43d3d905c3f2260246d44f9b, the commit message should read `win32/GNUmakefile: ` instead of `libssh2-gnumake.sh: `. Sorry for the mixup. --- win32/GNUmakefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 56a6d40d8b..f8ac05b14f 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -112,6 +112,12 @@ else ifdef WOLFSSL_PATH _LDFLAGS += -L"$(WOLFSSL_PATH)/lib" _LIBS += -lwolfssl include $(PROOT)/Makefile.wolfSSL.inc +else ifdef LIBGCRYPT_PATH + CPPFLAGS += -DLIBSSH2_LIBGCRYPT + CPPFLAGS += -I"$(LIBGCRYPT_PATH)/include" + _LDFLAGS += -L"$(LIBGCRYPT_PATH)/lib" + _LIBS += -lgcrypt + include $(PROOT)/Makefile.libgcrypt.inc else ifdef MBEDTLS_PATH CPPFLAGS += -DLIBSSH2_MBEDTLS CPPFLAGS += -I"$(MBEDTLS_PATH)/include" From f058f7eacc7fb24bc5cf3811f77e517b33feaa7e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 16:38:24 +0000 Subject: [PATCH 204/424] win32/GNUmakefile: rename object dir and update .gitignore [ci skip] From `-{release|debug}` to `{release|debug}-`. Follow-up to 68fd02fba002c8c6af3ba51a2780de46b47b3787 --- win32/.gitignore | 5 +++-- win32/GNUmakefile | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/win32/.gitignore b/win32/.gitignore index 0f142bac2d..5f852e423c 100644 --- a/win32/.gitignore +++ b/win32/.gitignore @@ -2,5 +2,6 @@ *.dll *.def *.exe -debug -release +debug-* +release-* +libssh2-*.zip diff --git a/win32/GNUmakefile b/win32/GNUmakefile index f8ac05b14f..f43c57cd02 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -85,9 +85,9 @@ endif DB ?= NDEBUG CPPFLAGS += -D$(DB) ifeq ($(DB),NDEBUG) - OBJ_DIR := $(OBJ_DIR)-release + OBJ_DIR := release-$(OBJ_DIR) else - OBJ_DIR := $(OBJ_DIR)-debug + OBJ_DIR := debug-$(OBJ_DIR) CFLAGS += -g CPPFLAGS += -DLIBSSH2DEBUG endif From 62235989e83126d289dac24a2b25de9b77158ecf Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 16:57:08 +0000 Subject: [PATCH 205/424] NMakefile: rename config variables, default to WinCNG [ci skip] - replace `OPENSSLINC` and `OPENSSLLIB` with `OPENSSL_PATH`. Assume `include` and `lib` subdirs for headers and libs. - replace `WITH_ZLIB`, `ZLIBINC` and `ZLIBLIB` with `ZLIB_PATH`. Assume `include` and `lib` subdirs for header and lib. - make WinCNG the default if `WITH_OPENSSL` is not set. --- NMakefile | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/NMakefile b/NMakefile index 9479ff54e5..0ced50784d 100644 --- a/NMakefile +++ b/NMakefile @@ -1,20 +1,3 @@ -# Tweak these for your system -!if "$(OPENSSLINC)" == "" -OPENSSLINC=..\openssl\include -!endif - -!if "$(OPENSSLLIB)" == "" -OPENSSLLIB=..\openssl\lib -!endif - -!if "$(ZLIBINC)" == "" -ZLIBINC=..\zlib -!endif - -!if "$(ZLIBLIB)" == "" -ZLIBLIB=..\zlib -!endif - !if "$(TARGET)" == "" TARGET=Release !endif @@ -30,17 +13,19 @@ DLLFLAGS=/DEBUG /LD CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude -!if "$(WITH_WINCNG)" == "1" +!if "$(OPENSSL_PATH)" != "" +CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSL_PATH)\include +LIBS=$(LIBS) $(OPENSSL_PATH)\lib\crypto.lib $(OPENSSL_PATH)\lib\ssl.lib +!include "Makefile.OpenSSL.inc" +!else CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_WINCNG LIBS=crypt32.lib bcrypt.lib -!else -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSLINC) -LIBS=$(LIBS) $(OPENSSLLIB)\lib\crypto.lib $(OPENSSLLIB)\lib\ssl.lib +!include "Makefile.WinCNG.inc" !endif -!if "$(WITH_ZLIB)" == "1" -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_HAVE_ZLIB /I$(ZLIBINC) -LIBS=$(LIBS) $(ZLIBLIB)\zlib.lib +!if "$(ZLIB_PATH)" != "" +CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_HAVE_ZLIB /I$(ZLIB_PATH)\include +LIBS=$(LIBS) $(ZLIB_PATH)\lib\zlib.lib !endif CFLAGS=$(CPPFLAGS) @@ -52,11 +37,6 @@ INTDIR=$(TARGET) SUBDIR=src -!if "$(WITH_WINCNG)" == "1" -!include "Makefile.WinCNG.inc" -!else -!include "Makefile.OpenSSL.inc" -!endif !include "Makefile.inc" OBJECTS=$(CSOURCES:.c=.obj) From ba53142e0ecd7b3c33f662e0b4ea7a36fbee6ba3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 16:03:21 +0000 Subject: [PATCH 206/424] cmake: detect WinCNG last This gives a chance to auto-detect mbedTLS on Windows with CMake. --- CMakeLists.txt | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 301718f78f..9e736cef37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -318,6 +318,23 @@ if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) endif() endif() +if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) + + find_package(mbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT}) + + if(MBEDTLS_FOUND) + set(CRYPTO_BACKEND "mbedTLS") + set(CRYPTO_SOURCES mbedtls.c mbedtls.h) + set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS") + set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR}) + list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES}) + list(APPEND PC_LIBS -lmbedcrypto) + link_directories(${MBEDTLS_LIBRARY_DIR}) + endif() +endif() + +# Detect platform-specific crypto-backends last: + if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) # The check actually compiles the header. This requires windows.h. @@ -346,21 +363,6 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) endif() endif() -if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) - - find_package(mbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT}) - - if(MBEDTLS_FOUND) - set(CRYPTO_BACKEND "mbedTLS") - set(CRYPTO_SOURCES mbedtls.c mbedtls.h) - set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS") - set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR}) - list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES}) - list(APPEND PC_LIBS -lmbedcrypto) - link_directories(${MBEDTLS_LIBRARY_DIR}) - endif() -endif() - # add_subdirectory(src) From eb236329c469ec906a9c8be65e8128b1abd6d414 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 12:31:16 +0000 Subject: [PATCH 207/424] delete redundant `HAVE_WINSOCK2_H` `libssh2.h` required `winsock2.h` for `_WIN32` since 81d53de4dc5ee39bd6215958c7dce3b12731195e (2011-06-04). Apply that to the whole codebase. This makes it unnecessary to detect `HAVE_WINSOCK2_H` and allows to drop all its uses. Completes TODO from b66d7317ca6c882afbe52fe426f68c119c40d348 TODO: Straighten out the use a mixture of `HAVE_WINDOWS_H`, `WIN32`, `_WIN32` to detect Windows. --- CMakeLists.txt | 1 - acinclude.m4 | 6 ------ configure.ac | 4 ++-- example/scp.c | 7 ++----- example/scp_nonblock.c | 7 ++----- example/scp_write.c | 2 +- example/scp_write_nonblock.c | 2 +- example/sftp.c | 7 ++----- example/sftp_RW_nonblock.c | 7 ++----- example/sftp_append.c | 2 +- example/sftp_mkdir.c | 2 +- example/sftp_mkdir_nonblock.c | 2 +- example/sftp_nonblock.c | 7 ++----- example/sftp_write.c | 2 +- example/sftp_write_nonblock.c | 2 +- example/sftp_write_sliding.c | 2 +- example/sftpdir.c | 2 +- example/sftpdir_nonblock.c | 2 +- example/ssh2.c | 2 -- example/ssh2_agent.c | 2 -- example/ssh2_agent_forwarding.c | 2 +- example/ssh2_echo.c | 2 +- example/ssh2_exec.c | 2 +- os400/libssh2_config.h | 3 --- src/libssh2_config_cmake.h.in | 1 - src/libssh2_priv.h | 2 -- tests/openssh_fixture.c | 4 ++-- tests/session_fixture.c | 5 ++--- tests/ssh2.c | 2 -- win32/libssh2_config.h | 1 - 30 files changed, 29 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e736cef37..19dbfaa7c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,6 @@ check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files(sys/un.h HAVE_SYS_UN_H) -check_include_files(winsock2.h HAVE_WINSOCK2_H) # for example and tests check_include_files(sys/param.h HAVE_SYS_PARAM_H) diff --git a/acinclude.m4 b/acinclude.m4 index 8a09e2570f..130ac8bbd8 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -218,13 +218,7 @@ dnl the code was bad, try a different program now, test 3 #define WIN32_LEAN_AND_MEAN #endif #include -#ifdef HAVE_WINSOCK2_H #include -#else -#ifdef HAVE_WINSOCK_H -#include -#endif -#endif #endif ],[ /* ioctlsocket source code */ diff --git a/configure.ac b/configure.ac index 6c51288f04..076eee6f0b 100644 --- a/configure.ac +++ b/configure.ac @@ -289,7 +289,7 @@ case $host in # These are POSIX-like systems using BSD-like sockets API. ;; *) - AC_CHECK_HEADERS([windows.h winsock2.h]) + AC_CHECK_HEADERS([windows.h]) ;; esac @@ -317,7 +317,7 @@ dnl Check for select() into ws2_32 for Msys/Mingw if test "$ac_cv_func_select" != "yes"; then AC_MSG_CHECKING([for select in ws2_32]) AC_TRY_LINK([ -#ifdef HAVE_WINSOCK2_H +#ifdef HAVE_WINDOWS_H #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif diff --git a/example/scp.c b/example/scp.c index 6b2788ee4f..f02944f9bb 100644 --- a/example/scp.c +++ b/example/scp.c @@ -11,8 +11,9 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -36,10 +37,6 @@ #include #include -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - int main(int argc, char *argv[]) { uint32_t hostaddr; diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 0b4a8ec8aa..0858b84337 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -16,8 +16,9 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -44,10 +45,6 @@ #include #include -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/scp_write.c b/example/scp_write.c index 1f85a185b3..833b60189d 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -11,7 +11,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index f41e44fd0a..f469abab9d 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -11,7 +11,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp.c b/example/sftp.c index d11007774b..96fdea708c 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -17,8 +17,9 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -46,10 +47,6 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - const char *keyfile1 = "~/.ssh/id_rsa.pub"; const char *keyfile2 = "~/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 1830ec33e5..76dc525e01 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -11,8 +11,9 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -43,10 +44,6 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - #define STORAGE "/tmp/sftp-storage" /* this is the local file name this example uses to store the downloaded file in */ diff --git a/example/sftp_append.c b/example/sftp_append.c index 37e2212699..012af2f265 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 2888d3edc7..9c9dc526f6 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index cba29daf68..a24a174520 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 279cc8e42c..5932ad0524 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -17,8 +17,9 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -49,10 +50,6 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/sftp_write.c b/example/sftp_write.c index 804b69bd29..5c6e5a80fd 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 35997c0eb0..584aab5576 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index e87cbe8605..a842271fc7 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftpdir.c b/example/sftpdir.c index 6f5079ffb2..e137a8a6eb 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 9228766b33..fb229b9958 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2.c b/example/ssh2.c index f689c39d0b..7d87b2b976 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -23,8 +23,6 @@ #ifdef WIN32 # include -#endif -#ifdef HAVE_WINSOCK2_H # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 1eeaff14d4..33d41be443 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -18,8 +18,6 @@ #ifdef WIN32 # include -#endif -#ifdef HAVE_WINSOCK2_H # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 96b2628884..3546d042a0 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -22,7 +22,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index ac202f2af0..ae62a7cc18 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -17,7 +17,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index c205f1a86f..fb250e63e4 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -19,7 +19,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index df3c381d70..ac14da6a84 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -134,9 +134,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 -/* Define to 1 if you have the header file. */ -#undef HAVE_WINSOCK2_H - /* to make a symbol visible */ #undef LIBSSH2_API diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index e0ccdade3f..0be020e119 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -45,7 +45,6 @@ #cmakedefine HAVE_SYS_IOCTL_H #cmakedefine HAVE_SYS_TIME_H #cmakedefine HAVE_SYS_UN_H -#cmakedefine HAVE_WINSOCK2_H /* for example and tests */ #cmakedefine HAVE_SYS_PARAM_H diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 87c7d4db85..3fc636676c 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -76,9 +76,7 @@ # define LIBSSH2_WINDOWS_APP # endif # endif -#endif /* WIN32 */ -#ifdef HAVE_WINSOCK2_H #include #include /* Force parameter type. */ diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 1b169ff171..a34e4b9b68 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -45,7 +45,7 @@ #include "openssh_fixture.h" #include "libssh2_config.h" -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 #include #endif #ifdef HAVE_SYS_SOCKET_H @@ -429,7 +429,7 @@ static char *running_container_id = NULL; int start_openssh_fixture(void) { int ret; -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 WSADATA wsadata; ret = WSAStartup(MAKEWORD(2, 0), &wsadata); diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 1a25feb12f..7087c3599f 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -47,15 +47,14 @@ #ifdef WIN32 #include +#include #ifdef _MSC_VER #include #define getcwd _getcwd #define chdir _chdir #endif #endif -#ifdef HAVE_WINSOCK2_H -#include -#endif + #ifdef HAVE_SYS_SOCKET_H #include #endif diff --git a/tests/ssh2.c b/tests/ssh2.c index d9f1639e00..b338c92210 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -6,8 +6,6 @@ #ifdef WIN32 # include -#endif -#ifdef HAVE_WINSOCK2_H # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 493826c4a0..bc2ab68135 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -10,7 +10,6 @@ #endif #define HAVE_LIBCRYPT32 -#define HAVE_WINSOCK2_H #define HAVE_STDLIB_H #define HAVE_IOCTLSOCKET #define HAVE_SELECT From 5f790d24ef817e009b024bd31909305bd73a43e0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 19:45:53 +0000 Subject: [PATCH 208/424] NMakefile: drop redundant variable and assignments [ci skip] --- NMakefile | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/NMakefile b/NMakefile index 0ced50784d..570a147afc 100644 --- a/NMakefile +++ b/NMakefile @@ -4,31 +4,30 @@ TARGET=Release !if "$(TARGET)" == "Debug" SUFFIX=_debug -CPPFLAGS=/Od /MDd +CFLAGS=/Od /MDd DLLFLAGS=/DEBUG /LDd !else -CPPFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG +CFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG DLLFLAGS=/DEBUG /LD !endif -CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude +CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iwin32 /Iinclude !if "$(OPENSSL_PATH)" != "" -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSL_PATH)\include +CFLAGS=$(CFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSL_PATH)\include LIBS=$(LIBS) $(OPENSSL_PATH)\lib\crypto.lib $(OPENSSL_PATH)\lib\ssl.lib !include "Makefile.OpenSSL.inc" !else -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_WINCNG +CFLAGS=$(CFLAGS) /DLIBSSH2_WINCNG LIBS=crypt32.lib bcrypt.lib !include "Makefile.WinCNG.inc" !endif !if "$(ZLIB_PATH)" != "" -CPPFLAGS=$(CPPFLAGS) /DLIBSSH2_HAVE_ZLIB /I$(ZLIB_PATH)\include +CFLAGS=$(CFLAGS) /DLIBSSH2_HAVE_ZLIB /I$(ZLIB_PATH)\include LIBS=$(LIBS) $(ZLIB_PATH)\lib\zlib.lib !endif -CFLAGS=$(CPPFLAGS) RCFLAGS=/Iinclude DLLFLAGS=$(CFLAGS) $(DLLFLAGS) LIBS=$(LIBS) ws2_32.lib user32.lib advapi32.lib gdi32.lib @@ -50,8 +49,6 @@ OBJECTS=Release/$(OBJECTS: = Release/) OBJECTS=$(OBJECTS: Release/ = ) !endif -CFLAGS=$(CFLAGS) - !if "$(AR)" == "" AR=lib ARFLAGS=-nologo /LTCG From cab599120c3ae507838e44b34d23427d3add8f6e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 23:41:07 +0000 Subject: [PATCH 209/424] delete redundant `HAVE_STDLIB_H` libssh2 used this standard C89 header unconditionally before this patch. Delete the feature checks and all unnecessary header guards. Closes #913 --- CMakeLists.txt | 7 +------ configure.ac | 2 +- example/direct_tcpip.c | 2 -- example/ssh2_echo.c | 2 -- example/ssh2_exec.c | 2 -- example/subsystem_netconf.c | 2 -- example/tcpip-forward.c | 2 -- example/x11.c | 2 -- os400/libssh2_config.h | 3 --- src/libssh2_config_cmake.h.in | 1 - src/misc.c | 2 -- src/os400qc3.c | 2 -- src/wincng.c | 3 +-- vms/libssh2_config.h | 1 - win32/libssh2_config.h | 1 - 15 files changed, 3 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19dbfaa7c3..8795d80118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,6 @@ set(LIB_SHARED "libssh2_shared") # Must match libssh2_shared_EXPORTS macro in i ## Platform checks check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(inttypes.h HAVE_INTTYPES_H) -check_include_files(stdlib.h HAVE_STDLIB_H) check_include_files(sys/select.h HAVE_SYS_SELECT_H) check_include_files(sys/uio.h HAVE_SYS_UIO_H) @@ -151,11 +150,7 @@ if(HAVE_SYS_TIME_H) else() check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) endif() -if(HAVE_STDLIB_H) - check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) -else() - check_function_exists(strtoll HAVE_STRTOLL) -endif() +check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) if (NOT HAVE_STRTOLL) # Try _strtoi64 if strtoll isn't available check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64) diff --git a/configure.ac b/configure.ac index 076eee6f0b..2f6d7238bd 100644 --- a/configure.ac +++ b/configure.ac @@ -278,7 +278,7 @@ AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"]) # Checks for header files. # AC_HEADER_STDC -AC_CHECK_HEADERS([errno.h fcntl.h stdio.h stdlib.h unistd.h sys/param.h sys/uio.h]) +AC_CHECK_HEADERS([errno.h fcntl.h stdio.h unistd.h sys/param.h sys/uio.h]) AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) AC_CHECK_HEADERS([sys/un.h], [have_sys_un_h=yes], [have_sys_un_h=no]) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index f61b9bb76a..7572562367 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -23,9 +23,7 @@ #include #include #include -#ifdef HAVE_STDLIB_H #include -#endif #ifdef HAVE_UNISTD_H #include #endif diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index ae62a7cc18..d884532cec 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -39,9 +39,7 @@ #include #endif #include -#ifdef HAVE_STDLIB_H #include -#endif #include #include #include diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index fb250e63e4..834dcdf88b 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -41,9 +41,7 @@ #include #endif #include -#ifdef HAVE_STDLIB_H #include -#endif #include #include #include diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index 4a400593b9..7903411684 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -22,9 +22,7 @@ #include #include #include -#ifdef HAVE_STDLIB_H #include -#endif #ifdef HAVE_UNISTD_H #include #endif diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index c42a6f1405..7ec4692c13 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -23,9 +23,7 @@ #include #include #include -#ifdef HAVE_STDLIB_H #include -#endif #ifdef HAVE_UNISTD_H #include #endif diff --git a/example/x11.c b/example/x11.c index ecce88716a..a58ee075da 100644 --- a/example/x11.c +++ b/example/x11.c @@ -38,9 +38,7 @@ #include #include #include -#ifdef HAVE_STDLIB_H #include -#endif #include diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index ac14da6a84..1c07d1f2a3 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -107,9 +107,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_STDIO_H 1 -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - /* Define to 1 if you have the `strtoll' function. */ #define HAVE_STRTOLL 1 diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 0be020e119..2bca1e4a7d 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -38,7 +38,6 @@ /* Headers */ #cmakedefine HAVE_UNISTD_H #cmakedefine HAVE_INTTYPES_H -#cmakedefine HAVE_STDLIB_H #cmakedefine HAVE_SYS_SELECT_H #cmakedefine HAVE_SYS_UIO_H #cmakedefine HAVE_SYS_SOCKET_H diff --git a/src/misc.c b/src/misc.c index 5e07d33c18..8699002946 100644 --- a/src/misc.c +++ b/src/misc.c @@ -40,9 +40,7 @@ #include "libssh2_priv.h" #include "misc.h" -#ifdef HAVE_STDLIB_H #include -#endif #ifdef HAVE_UNISTD_H #include diff --git a/src/os400qc3.c b/src/os400qc3.c index 89f440ee82..420cfad26e 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -41,9 +41,7 @@ #ifdef LIBSSH2_OS400QC3 /* compile only if we build with OS/400 QC3 library */ -#ifdef HAVE_STDLIB_H #include -#endif #include #include diff --git a/src/wincng.c b/src/wincng.c index ca72990099..e17ae45410 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -60,9 +60,8 @@ #include #include -#ifdef HAVE_STDLIB_H #include -#endif + #ifdef HAVE_LIBCRYPT32 #include #endif diff --git a/vms/libssh2_config.h b/vms/libssh2_config.h index 94c81e0171..9eac4d71e8 100644 --- a/vms/libssh2_config.h +++ b/vms/libssh2_config.h @@ -14,7 +14,6 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ /* Have's */ #define HAVE_UNISTD_H -#define HAVE_STDLIB_H #define HAVE_INTTYPES_H #define HAVE_SYS_TIME_H #define HAVE_SELECT diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index bc2ab68135..da4af839b3 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -10,7 +10,6 @@ #endif #define HAVE_LIBCRYPT32 -#define HAVE_STDLIB_H #define HAVE_IOCTLSOCKET #define HAVE_SELECT #define HAVE_SNPRINTF From 06f281921907fa077884c7020917661ca805b9d3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 23:41:42 +0000 Subject: [PATCH 210/424] cmake: re-use existing `libssh2.pc` template Instead of maintaining a second copy of `libssh2.pc.in` in `src` just for CMake, teach CMake to use the existing template in the root dir, that we already use with autotools. Closes #914 --- CMakeLists.txt | 2 -- src/CMakeLists.txt | 9 ++++++++- src/libssh2.pc.in | 17 ----------------- 3 files changed, 8 insertions(+), 20 deletions(-) delete mode 100644 src/libssh2.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 8795d80118..6f0d5c8d34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,8 +49,6 @@ cmake_minimum_required(VERSION 3.1) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) project(libssh2 C) -set(PROJECT_URL "https://www.libssh2.org/") -set(PROJECT_DESCRIPTION "The SSH library") option(BUILD_STATIC_LIBS "Build Static Libraries" ON) option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1f6c7e342..e6c5925814 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -230,7 +230,14 @@ endif() if(PC_LIBS) string(REPLACE ";" " " PC_LIBS "${PC_LIBS}") endif() -configure_file(libssh2.pc.in libssh2.pc @ONLY) +set(LIBSSH2VER ${LIBSSH2_VERSION}) +set(LIBSREQUIRED ${PC_REQUIRES_PRIVATE}) +set(LIBS ${PC_LIBS}) +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix "\${prefix}") +set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") +set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") +configure_file(${CMAKE_SOURCE_DIR}/libssh2.pc.in libssh2.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/libssh2.pc.in b/src/libssh2.pc.in deleted file mode 100644 index 282a39b5fa..0000000000 --- a/src/libssh2.pc.in +++ /dev/null @@ -1,17 +0,0 @@ -########################################################################### -# libssh2 installation details -########################################################################### - -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix} -libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ - -Name: @PROJECT_NAME@ -URL: @PROJECT_URL@ -Description: @PROJECT_DESCRIPTION@ -Version: @LIBSSH2_VERSION@ -Requires.private: @PC_REQUIRES_PRIVATE@ -Libs: -L${libdir} -lssh2 @PC_LIBS@ -Libs.private: @PC_LIBS@ -Cflags: -I${includedir} From 1b59e907054296eaa2fe20d1df85dfc0a7dd097e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 23:41:57 +0000 Subject: [PATCH 211/424] tidy-up: null-mac/cipher documentation Move documentation for these deleted build-level options from autotools/cmake docs to the source code itself. Follow-up to 50c9bf868e833258d23c5f55ed546d1fcd5687d0 Closes #915 --- docs/INSTALL_AUTOTOOLS | 26 -------------------------- docs/INSTALL_CMAKE.md | 22 ---------------------- src/crypt.c | 11 ++++++++++- src/mac.c | 10 ++++++++++ 4 files changed, 20 insertions(+), 49 deletions(-) diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index b2a0c61086..b4a0cf194f 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -254,32 +254,6 @@ More configure options Some ./configure options deserve additional comments: - * --enable-crypt-none - - The SSH2 Transport allows for unencrypted data - transmission using the "none" cipher. Because this is - such a huge security hole, it is typically disabled on - SSH2 implementations and is disabled in libssh2 by - default as well. - - Enabling this option will allow for "none" as a - negotiable method, however it still requires that the - method be advertised by the remote end and that no - more-preferable methods are available. - - * --enable-mac-none - - The SSH2 Transport also allows implementations to - forego a message authentication code. While this is - less of a security risk than using a "none" cipher, it - is still not recommended as disabling MAC hashes - removes a layer of security. - - Enabling this option will allow for "none" as a - negotiable method, however it still requires that the - method be advertised by the remote end and that no - more-preferable methods are available. - * --with-libgcrypt * --without-libgcrypt * --with-libgcrypt-prefix=DIR diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 835bd573b1..23a8ce9b50 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -74,28 +74,6 @@ The following options are available: Will use zlib (https://zlib.net/) for payload compression. Can be `ON` or `OFF`. - * `ENABLE_CRYPT_NONE=OFF` - - The SSH2 Transport allows for unencrypted data transmission using - the "none" cipher. Because this is such a huge security hole, it - is typically disabled on SSH2 implementations and is disabled in - libssh2 by default as well. - - Enabling this option will allow for "none" as a negotiable method, - however it still requires that the method be advertised by the - remote end and that no more-preferable methods are available. - - * `ENABLE_MAC_NONE=OFF` - - The SSH2 Transport also allows implementations to forego a message - authentication code. While this is less of a security risk than - using a "none" cipher, it is still not recommended as disabling - MAC hashes removes a layer of security. - - Enabling this option will allow for "none" as a negotiable method, - however it still requires that the method be advertised by the - remote end and that no more-preferable methods are available. - * `ENABLE_DEBUG_LOGGING=ON` in Debug, `=OFF` in Release Will enable the libssh2_trace() function for showing debug traces. diff --git a/src/crypt.c b/src/crypt.c index 0674e925b9..aefada0846 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -39,9 +39,18 @@ #include "libssh2_priv.h" #if defined(LIBSSH2DEBUG) && defined(LIBSSH2_CRYPT_NONE_INSECURE) - /* crypt_none_crypt * Minimalist cipher: no encryption. DO NOT USE. + * + * The SSH2 Transport allows for unencrypted data transmission using + * the "none" cipher. Because this is such a huge security hole, it is + * typically disabled on SSH2 implementations and is disabled in libssh2 + * by default as well. + * + * Enabling this option will allow for "none" as a negotiable method, + * however it still requires that the method be advertised by the remote + * end and that no more-preferable methods are available. + * */ static int crypt_none_crypt(LIBSSH2_SESSION * session, unsigned char *buf, diff --git a/src/mac.c b/src/mac.c index ffdc209bf1..e2c6759439 100644 --- a/src/mac.c +++ b/src/mac.c @@ -41,6 +41,16 @@ #if defined(LIBSSH2DEBUG) && defined(LIBSSH2_MAC_NONE_INSECURE) /* mac_none_MAC * Minimalist MAC: No MAC. DO NOT USE. + * + * The SSH2 Transport allows implementations to forego a message + * authentication code. While this is less of a security risk than using + * a "none" cipher, it is still not recommended as disabling MAC hashes + * removes a layer of security. + * + * Enabling this option will allow for "none" as a negotiable method, + * however it still requires that the method be advertised by the remote + * end and that no more-preferable methods are available. + * */ static int mac_none_MAC(LIBSSH2_SESSION * session, unsigned char *buf, From a07ba9ee71a08b791700fdf040833b6d3832ec60 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 2 Apr 2023 00:27:56 +0000 Subject: [PATCH 212/424] autotools: delete `src/libssh2.pc.in` reference [ci skip] Follow-up to 06f281921907fa077884c7020917661ca805b9d3 --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index d63b477a0d..84e210197a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,7 @@ include ../Makefile.inc libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS) -EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in libssh2.pc.in +EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in EXTRA_DIST += CMakeLists.txt lib_LTLIBRARIES = libssh2.la From 185292a06b369115e573ba18f6b067e54bfc5313 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 2 Apr 2023 03:24:16 +0000 Subject: [PATCH 213/424] build: make `HAVE_LIBCRYPT32` local to `wincng.c` libssh2 uses `wincrypt.h` aka the `crypt32` Windows system library for the function `CryptDecodeObjectEx()` [1]. This function has been available for Win32 (and UWP/WinRT apps) for a long while. Even old MinGW supports it, and also Watcom 1.9, of the rare/old compilers I checked. CMake had it permanently enabled, while it also did an extra check for the header to add the lib to the lib list. Autotools did the detection proper. Other builds had it permanently enabled. It seems safe to assume this function/header/lib is available in all environments we support. In this patch we simplify by deleting these detections and feature flags from all build tools. Keep the feature flag internal to `wincng.h`, and for extra safety add the new macro `LIBSSH2_WINCNG_DISABLE_WINCRYPT` do disable it via custom `CPPFLAGS`. WinCNG's other requirement is `bcrypt`. That also has been universally available for a long time. Here the only known outlier is old/legacy MinGW, which is missing support. [1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptdecodeobjectex Closes #916 --- CMakeLists.txt | 14 ++------------ Makefile.WinCNG.inc | 2 +- acinclude.m4 | 7 ++----- os400/libssh2_config.h | 3 --- src/libssh2_config_cmake.h.in | 3 --- src/wincng.c | 6 +++++- win32/libssh2_config.h | 1 - 7 files changed, 10 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f0d5c8d34..cfe63b185f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,18 +338,8 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG") set(CRYPTO_BACKEND_INCLUDE_DIR "") - set(HAVE_LIBCRYPT32 TRUE) - list(APPEND LIBRARIES bcrypt) - list(APPEND PC_LIBS -lbcrypt) - - # Reading keys from files is optional and depends on Wincrypt - check_include_files("windows.h;wincrypt.h" HAVE_WINCRYPT_H) - - if(HAVE_WINCRYPT_H) - list(APPEND LIBRARIES crypt32) - list(APPEND PC_LIBS -lcrypt32) - endif() - + list(APPEND LIBRARIES crypt32 bcrypt) + list(APPEND PC_LIBS -lcrypt32 -lbcrypt) elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL ${REQUIRED}) message(FATAL_ERROR "WinCNG not available") endif() diff --git a/Makefile.WinCNG.inc b/Makefile.WinCNG.inc index bbcb82bfde..09e410964f 100644 --- a/Makefile.WinCNG.inc +++ b/Makefile.WinCNG.inc @@ -1,3 +1,3 @@ CRYPTO_CSOURCES = wincng.c CRYPTO_HHEADERS = wincng.h -CRYPTO_LTLIBS = $(LTLIBBCRYPT) $(LTLIBCRYPT32) +CRYPTO_LTLIBS = $(LTLIBBCRYPT) diff --git a/acinclude.m4 b/acinclude.m4 index 130ac8bbd8..85de8c1408 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -449,10 +449,8 @@ m4_case([$1], [wincng], [ # Look for Windows Cryptography API: Next Generation - LIBSSH2_LIB_HAVE_LINKFLAGS([crypt32], [], [ - #include - #include - ]) + LIBS="$LIBS -lcrypt32" + LIBSSH2_LIB_HAVE_LINKFLAGS([bcrypt], [], [ #include #include @@ -504,4 +502,3 @@ AC_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]), CFLAGS="$CFLAGS -Werror" fi ]) - diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 1c07d1f2a3..f3bf725dbf 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -77,9 +77,6 @@ /* use Ioctlsocket() for non-blocking sockets */ #undef HAVE_IOCTLSOCKET_CASE -/* Define if you have the crypt32 library. */ -#undef HAVE_LIBCRYPT32 - /* Define if you have the gcrypt library. */ #undef HAVE_LIBGCRYPT diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 2bca1e4a7d..ccace6564b 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -50,9 +50,6 @@ #cmakedefine HAVE_ARPA_INET_H #cmakedefine HAVE_NETINET_IN_H -/* Libraries */ -#cmakedefine HAVE_LIBCRYPT32 - /* Types */ #cmakedefine HAVE_LONGLONG diff --git a/src/wincng.c b/src/wincng.c index e17ae45410..46a29d853e 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -48,6 +48,10 @@ #define _WIN32_WINNT 0x0600 #endif +#if !defined(LIBSSH2_WINCNG_DISABLE_WINCRYPT) && !defined(HAVE_LIBCRYPT32) +#define HAVE_LIBCRYPT32 +#endif + /* specify the required libraries for dependencies using MSVC */ #ifdef _MSC_VER #pragma comment(lib, "bcrypt.lib") @@ -63,7 +67,7 @@ #include #ifdef HAVE_LIBCRYPT32 -#include +#include /* for CryptDecodeObjectEx() */ #endif #define PEM_RSA_HEADER "-----BEGIN RSA PRIVATE KEY-----" diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index da4af839b3..371ae634f9 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -9,7 +9,6 @@ #define _CRT_SECURE_NO_DEPRECATE 1 #endif -#define HAVE_LIBCRYPT32 #define HAVE_IOCTLSOCKET #define HAVE_SELECT #define HAVE_SNPRINTF From fb1195cf88268a11e2709b9912ab9dca8c23739c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 2 Apr 2023 03:24:39 +0000 Subject: [PATCH 214/424] build: respect autotools `DLL_EXPORT` in `libssh2.h` The `DLL_EXPORT` macro is automatically set by autotools when building the libssh2 DLL. Certain toolchains might require this to correctly export symbols, so make sure to respect it in `libssh2.h` to enable `declspec(dllexport)`. With this patch we have a manual macro for that (`LIBSSH2_EXPORT`), this autotools one, the CMake one, and `_WINDLL` (added in c355d31ff94a1622526c4988b9d09074f7f7605d), possibly defined by Visual Studio. Closes #917 --- include/libssh2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libssh2.h b/include/libssh2.h index abc9f3b522..7d9b33976f 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -100,7 +100,7 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API # ifdef WIN32 -# if defined(LIBSSH2_EXPORTS) || \ +# if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || \ defined(_WINDLL) || defined(libssh2_shared_EXPORTS) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) From cffcae4e0daaaf7640d6785145f8b7601fa7ef48 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 2 Apr 2023 09:59:53 +0000 Subject: [PATCH 215/424] win32/GNUmakefile: update help & exit without crypto backend [ci skip] Follow-up to: 5bcd25c4c980e9765c00a2f20ac5348635063aad Follow-up to: 68fd02fba002c8c6af3ba51a2780de46b47b3787 --- win32/GNUmakefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index f43c57cd02..134e5c3215 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -127,6 +127,8 @@ else ifdef MBEDTLS_PATH else ifdef WIN32 CPPFLAGS += -DLIBSSH2_WINCNG include $(PROOT)/Makefile.WinCNG.inc +else + $(error No suitable cryptography backend found) endif ifdef ZLIB_PATH @@ -275,6 +277,7 @@ help: $(OBJ_DIR)/version.inc @echo $(DL)===========================================================$(DL) @echo $(DL)OpenSSL path = $(OPENSSL_PATH)$(DL) @echo $(DL)wolfSSL path = $(WOLFSSL_PATH)$(DL) + @echo $(DL)libgcrypt path = $(LIBGCRYPT_PATH)$(DL) @echo $(DL)mbedTLS path = $(MBEDTLS_PATH)$(DL) @echo $(DL)zlib path = $(ZLIB_PATH)$(DL) @echo $(DL)===========================================================$(DL) From a7a2fcdab6c8ad8c008119ab226c8baf9b46e62d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 2 Apr 2023 01:21:00 +0000 Subject: [PATCH 216/424] autotools: delete unused conditional `HAVE_SYS_UN_H` No longer necessary after moving the disabling/enabling logic from build tool to `example/x11.c`. Reverts 4774d500e724bc4e548f743a0cb644ab05599474 Follow-up to d245c66cc0029e480674394c23e8be1c9410f7ad --- configure.ac | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 2f6d7238bd..f5ae8571ec 100644 --- a/configure.ac +++ b/configure.ac @@ -281,8 +281,7 @@ AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"]) AC_CHECK_HEADERS([errno.h fcntl.h stdio.h unistd.h sys/param.h sys/uio.h]) AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) -AC_CHECK_HEADERS([sys/un.h], [have_sys_un_h=yes], [have_sys_un_h=no]) -AM_CONDITIONAL([HAVE_SYS_UN_H], test "x$have_sys_un_h" = xyes) +AC_CHECK_HEADERS([sys/un.h]) case $host in *-*-cygwin* | *-*-cegcc*) From 194cfc0f84192809c87f846140e5bf06b7a864af Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 12:07:13 +0000 Subject: [PATCH 217/424] windows: move `libssh2.rc` to the `src` directory Closes #918 --- Makefile.am | 2 +- NMakefile | 2 +- src/CMakeLists.txt | 2 +- win32/GNUmakefile | 3 +++ win32/libssh2.rc | 45 --------------------------------------------- 5 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 win32/libssh2.rc diff --git a/Makefile.am b/Makefile.am index 964336e347..91cdaff8da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,7 +24,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ WIN32FILES = win32/GNUmakefile NMakefile \ win32/libssh2_config.h \ - win32/libssh2.rc + src/libssh2.rc OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ os400/make-src.sh os400/make-rpg.sh os400/make-include.sh \ diff --git a/NMakefile b/NMakefile index 570a147afc..5f445a3f82 100644 --- a/NMakefile +++ b/NMakefile @@ -73,7 +73,7 @@ $(DLL): $(OBJECTS) $(RESOURCE) $(STATICLIB): $(OBJECTS) $(AR) $(ARFLAGS) -out:$@ $(OBJECTS) -$(RESOURCE): win32\libssh2.rc +$(RESOURCE): src\libssh2.rc $(RC) $(RCFLAGS) /Fo"$@" $? all-sub: $(INTDIR) all diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e6c5925814..44d650c2d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -163,7 +163,7 @@ if(BUILD_SHARED_LIBS) list(APPEND libssh2_export ${LIB_SHARED}) add_library(${LIB_SHARED} SHARED ${SOURCES}) if(WIN32) - set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc) + set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES libssh2.rc) endif() target_compile_definitions(${LIB_SHARED} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) target_link_libraries(${LIB_SHARED} PRIVATE ${LIBRARIES}) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index 134e5c3215..a9f4b232c7 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -172,6 +172,9 @@ ZIP := zip -qzr9 -include $(OBJ_DIR)/version.inc vpath %.c $(PROOT)/src +ifdef WIN32 +vpath %.rc $(PROOT)/src +endif # include Makefile.inc to get CSOURCES define include $(PROOT)/Makefile.inc diff --git a/win32/libssh2.rc b/win32/libssh2.rc deleted file mode 100644 index 04a30a405e..0000000000 --- a/win32/libssh2.rc +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** -* libssh2 Win32 resource file * -***************************************************************************/ -#include -#include "../include/libssh2.h" - -LANGUAGE 0x09,0x01 - -#define RC_VERSION LIBSSH2_VERSION_MAJOR, LIBSSH2_VERSION_MINOR, LIBSSH2_VERSION_PATCH, 0 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION RC_VERSION - PRODUCTVERSION RC_VERSION - FILEFLAGSMASK 0x3fL -#if defined(DEBUGBUILD) || defined(_DEBUG) - FILEFLAGS 1 -#else - FILEFLAGS 0 -#endif - FILEOS VOS__WINDOWS32 - FILETYPE VFT_DLL - FILESUBTYPE 0x0L - -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "CompanyName", "The libssh2 library, https://www.libssh2.org/\0" - VALUE "FileDescription", "libssh2 Shared Library\0" - VALUE "FileVersion", LIBSSH2_VERSION "\0" - VALUE "InternalName", "libssh2\0" - VALUE "OriginalFilename", "libssh2.dll\0" - VALUE "ProductName", "The libssh2 library\0" - VALUE "ProductVersion", LIBSSH2_VERSION "\0" - VALUE "LegalCopyright", "Copyright (C) " LIBSSH2_COPYRIGHT "\0" - VALUE "License", "https://www.libssh2.org/license.html\0" - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END From d1b36efe417f4c8730ea75a0fc00bd07189a0a22 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 12:07:49 +0000 Subject: [PATCH 218/424] transport: rename local `RANDOM_PADDING` macro Rename `RANDOM_PADDING` macro used internally to enable some code. Committed in the initial version of `transport.c` in 9d55db6501aa4e21f0858cf36cdc2ddc11b96e83 (2007-02-02). libssh2 code never defined it. The name happens to collide with a Windows macro in `wincrypt.h`. `transport.c` doesn't include this header, but it includes `winsock2.h`, and it turns out it can also define this macro in some cases, e.g. when `WIN32_LEAN_AND_MEAN` is not set. To be on the safe side, prefix the name with `LIBSSH2_` to avoid enabling it by accident. Q: Maybe it'd be best to delete it with the guarded code? Reported-by: Markus-Schmidt on github Fixes #921 Closes #924 --- src/transport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transport.c b/src/transport.c index e4ffc1a635..19671054a0 100644 --- a/src/transport.c +++ b/src/transport.c @@ -723,7 +723,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, ssize_t padding_length; size_t packet_length; ssize_t total_length; -#ifdef RANDOM_PADDING +#ifdef LIBSSH2_RANDOM_PADDING int rand_max; int seed = data[0]; /* FIXME: make this random */ #endif @@ -846,7 +846,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, if(padding_length < 4) { padding_length += blocksize; } -#ifdef RANDOM_PADDING +#ifdef LIBSSH2_RANDOM_PADDING /* FIXME: we can add padding here, but that also makes the packets bigger etc */ From 2e3e0be816b2e71f59a6f56a0d38898ceeb5c82f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 12:08:50 +0000 Subject: [PATCH 219/424] ci: add MSVS 2008/2010 build tests and fix warnings Also: - fix newly surfaced (bogus) warnings in examples with MSVS 2010: ``` ..\..\example\direct_tcpip.c(262): warning C4127: conditional expression is constant ``` Happens for every `FD_SET()` macro reference. Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46677835/job/ni4hs97bh18c14ap - silence MSVS 2010 predefined Windows macro warnings: ``` ..\..\src\wincng.c(867): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size ..\..\src\wincng.c(897): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size ..\..\src\wincng.c(1132): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size ``` Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46678071/job/08t5ktvkcgdghp7r Closes #925 --- appveyor.yml | 24 +++++++++++++++++++++--- example/direct_tcpip.c | 4 ++++ example/scp_nonblock.c | 4 ++++ example/scp_write_nonblock.c | 4 ++++ example/sftp_write_nonblock.c | 4 ++++ example/sftp_write_sliding.c | 4 ++++ example/ssh2_agent_forwarding.c | 4 ++++ example/ssh2_echo.c | 4 ++++ example/ssh2_exec.c | 4 ++++ example/tcpip-forward.c | 4 ++++ example/x11.c | 4 ++++ src/wincng.c | 10 ++++++++++ 12 files changed, 71 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 9ad4d8d819..a55f55c37b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -66,14 +66,32 @@ environment: CRYPTO_BACKEND: "OpenSSL" CONFIGURATION: "Release" - - job_name: "VS2013, OpenSSL, x64, Static-only" + - job_name: "VS2013, OpenSSL, x64, Static-only, Build-only" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" PLATFORM: "x64" BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "OpenSSL" + CONFIGURATION: "Release" + SKIP_CTEST: "yes" + + - job_name: "VS2010, WinCNG, x64, Build-only" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + GENERATOR: "Visual Studio 10 2010" + PLATFORM: "x64" + BUILD_SHARED_LIBS: "ON" + CRYPTO_BACKEND: "WinCNG" + CONFIGURATION: "Release" SKIP_CTEST: "yes" + + - job_name: "VS2008, WinCNG, x86, Build-only" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + GENERATOR: "Visual Studio 9 2008" + PLATFORM: "x86" + BUILD_SHARED_LIBS: "ON" + CRYPTO_BACKEND: "WinCNG" CONFIGURATION: "Release" + SKIP_CTEST: "yes" - job_name: "VS2022, WinCNG, x64, Logging" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" @@ -83,7 +101,7 @@ environment: CRYPTO_BACKEND: "WinCNG" CONFIGURATION: "Debug" - - job_name: "VS2022, WinCNG, ARM64" + - job_name: "VS2022, WinCNG, ARM64, Build-only" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" PLATFORM: "ARM64" @@ -174,7 +192,7 @@ on_finish: Start-Sleep -Seconds 3 Get-Process -Name "sshd" -ErrorAction SilentlyContinue | Stop-Process -# whitelist branches to avoid testing feature branches twice (as branch and as pull request) +# Limit branches to avoid testing feature branches twice (as branch and as pull request) branches: only: - master diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 7572562367..5cbccf508e 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -36,6 +36,10 @@ #define INADDR_NONE (in_addr_t)-1 #endif +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; const char *keyfile2 = "/home/username/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 0858b84337..fd8ab99dd1 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -45,6 +45,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index f469abab9d..0e6a1bebb5 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -40,6 +40,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 584aab5576..ef90210e6a 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -46,6 +46,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index a842271fc7..3c3d911303 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -46,6 +46,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 3546d042a0..0d8135024d 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -51,6 +51,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index d884532cec..d5fa7635ab 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -45,6 +45,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 834dcdf88b..ae4d57ef05 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -47,6 +47,10 @@ #include #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 7ec4692c13..c7affdc64b 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -36,6 +36,10 @@ #define INADDR_NONE (in_addr_t)-1 #endif +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; const char *keyfile2 = "/home/username/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/x11.c b/example/x11.c index a58ee075da..3e801d4d49 100644 --- a/example/x11.c +++ b/example/x11.c @@ -42,6 +42,10 @@ #include +#if defined(_MSC_VER) && _MSC_VER < 1700 +#pragma warning(disable:4127) +#endif + #define _PATH_UNIX_X "/tmp/.X11-unix/X%d" /* diff --git a/src/wincng.c b/src/wincng.c index 46a29d853e..72f8bfed3a 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -223,6 +223,16 @@ #define PKCS_RSA_PRIVATE_KEY (LPCSTR)43 #endif +#if defined(_MSC_VER) && _MSC_VER < 1700 +/* Workaround for warning C4306: + 'type cast' : conversion from 'int' to 'LPCSTR' of greater size */ +#undef X509_SEQUENCE_OF_ANY +#undef X509_MULTI_BYTE_UINT +#undef PKCS_RSA_PRIVATE_KEY +#define X509_SEQUENCE_OF_ANY ((LPCSTR)(size_t)34) +#define X509_MULTI_BYTE_UINT ((LPCSTR)(size_t)38) +#define PKCS_RSA_PRIVATE_KEY ((LPCSTR)(size_t)43) +#endif /*******************************************************************/ /* From ad6aae302aaec84afbfacf0c1dfdc446d46eaf21 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 12:09:48 +0000 Subject: [PATCH 220/424] hostkey: fix `hash_len` field constants Replace incorrect `MD5_DIGEST_LENGTH` with `SHA_DIGEST_LENGTH` for these hostkey algos: - `ssh-rsa` and `ssh-dss` Ref: 7a5ffc8cee259bbde82ab92515cd8fea2166854b (2004-12-07 Initial) - `ssh-rsa-cert-v01@openssh.com` Ref: 4b21e49d9d2db74579b18804ed1f5eeb16578b2f (2022-07-28) Ref: #710 Also delete local fall-back definition of `MD5_DIGEST_LENGTH` (added in 9af7eb48dc3854ce8ee0589f7e2beb944e064847). Macro is no longer used. Reported-by: Markus-Schmidt on github Fixes #919 Closes #926 --- src/hostkey.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/hostkey.c b/src/hostkey.c index 92447e7499..0639d787ec 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -413,13 +413,9 @@ hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract) return 0; } -#ifdef OPENSSL_NO_MD5 -#define MD5_DIGEST_LENGTH 16 -#endif - static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = { "ssh-rsa", - MD5_DIGEST_LENGTH, + SHA_DIGEST_LENGTH, hostkey_method_ssh_rsa_init, hostkey_method_ssh_rsa_initPEM, hostkey_method_ssh_rsa_initPEMFromMemory, @@ -459,7 +455,7 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_512 = { static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_cert = { "ssh-rsa-cert-v01@openssh.com", - MD5_DIGEST_LENGTH, + SHA_DIGEST_LENGTH, NULL, hostkey_method_ssh_rsa_initPEM, hostkey_method_ssh_rsa_initPEMFromMemory, @@ -688,7 +684,7 @@ hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, void **abstract) static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_dss = { "ssh-dss", - MD5_DIGEST_LENGTH, + SHA_DIGEST_LENGTH, hostkey_method_ssh_dss_init, hostkey_method_ssh_dss_initPEM, hostkey_method_ssh_dss_initPEMFromMemory, From be31457f3071686b555a0f0b19e5dcf63d67fc27 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 12:10:47 +0000 Subject: [PATCH 221/424] crypto: add `LIBSSH2_NO_MD5` to disable MD5 support Closes #927 --- src/crypto.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/crypto.h b/src/crypto.h index 8462e8b87d..890f209bdc 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -58,6 +58,10 @@ #include "mbedtls.h" #endif +#ifdef LIBSSH2_NO_MD5 +#undef LIBSSH2_MD5 +#endif + #define LIBSSH2_ED25519_KEY_LEN 32 #define LIBSSH2_ED25519_PRIVATE_KEY_LEN 64 #define LIBSSH2_ED25519_SIG_LEN 64 From e387311bd6631059bda2460a57766d470504a3cb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 12:27:02 +0000 Subject: [PATCH 222/424] windows: re-add `libssh2.rc` Lost while moving it from the win32 directory Follow-up to 194cfc0f84192809c87f846140e5bf06b7a864af --- src/libssh2.rc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/libssh2.rc diff --git a/src/libssh2.rc b/src/libssh2.rc new file mode 100644 index 0000000000..5358942f84 --- /dev/null +++ b/src/libssh2.rc @@ -0,0 +1,45 @@ +/*************************************************************************** +* libssh2 Windows resource file * +***************************************************************************/ +#include +#include "libssh2.h" + +LANGUAGE 0x09,0x01 + +#define RC_VERSION LIBSSH2_VERSION_MAJOR, LIBSSH2_VERSION_MINOR, LIBSSH2_VERSION_PATCH, 0 + +VS_VERSION_INFO VERSIONINFO + FILEVERSION RC_VERSION + PRODUCTVERSION RC_VERSION + FILEFLAGSMASK 0x3fL +#if defined(DEBUGBUILD) || defined(_DEBUG) + FILEFLAGS 1 +#else + FILEFLAGS 0 +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0x0L + +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "The libssh2 library, https://www.libssh2.org/\0" + VALUE "FileDescription", "libssh2 Shared Library\0" + VALUE "FileVersion", LIBSSH2_VERSION "\0" + VALUE "InternalName", "libssh2\0" + VALUE "OriginalFilename", "libssh2.dll\0" + VALUE "ProductName", "The libssh2 library\0" + VALUE "ProductVersion", LIBSSH2_VERSION "\0" + VALUE "LegalCopyright", "Copyright (C) " LIBSSH2_COPYRIGHT "\0" + VALUE "License", "https://www.libssh2.org/license.html\0" + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END From 1cd1aaefa67db8dc0f9799475458ab53f40021cd Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 15:16:51 +0000 Subject: [PATCH 223/424] win32/GNUmakefile: drop an unnecessary variable [ci skip] --- win32/GNUmakefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index a9f4b232c7..e6ee2892b2 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -13,8 +13,6 @@ PROOT := .. ### Common -HOMEPAGE := https://www.libssh2.org/ - CFLAGS ?= CPPFLAGS ?= RCFLAGS ?= @@ -274,7 +272,7 @@ $(DISTDIR)/readme.txt: GNUmakefile @echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@ @echo $(DL)Please download the complete libssh2 package for$(DL) >> $@ @echo $(DL)any further documentation:$(DL) >> $@ - @echo $(DL)$(HOMEPAGE)$(DL) >> $@ + @echo $(DL)https://www.libssh2.org/$(DL) >> $@ help: $(OBJ_DIR)/version.inc @echo $(DL)===========================================================$(DL) From 8c24a3f59994b4e470548a1f9a94a22ca39ac4a0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 3 Apr 2023 23:23:21 +0000 Subject: [PATCH 224/424] win32/GNUmakefile: make it movable [ci skip] - add `BLD_DIR` to customize the output directory (where libs, .zip, obj subdir will go). This directory must exist. It remains `./win32` for Windows builds. - add `CONFIG_H_DIR` option to customize `libssh2_config.h` location. It remains `./win32` for Windows builds. - include `.def` in distro zip for Windows. - ready to move to the root directory. --- win32/GNUmakefile | 48 ++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/win32/GNUmakefile b/win32/GNUmakefile index e6ee2892b2..1cbd7babd7 100644 --- a/win32/GNUmakefile +++ b/win32/GNUmakefile @@ -50,16 +50,19 @@ ifneq ($(findstring -w,$(TRIPLET)),) WIN32 := 1 BIN_EXT := .exe DYN_EXT := .dll + BLD_DIR ?= $(PROOT)/win32 + CONFIG_H_DIR ?= $(PROOT)/win32 +else + BLD_DIR ?= $(PROOT) + CONFIG_H_DIR ?= $(PROOT) endif -CPPFLAGS += -I$(PROOT)/win32 -I$(PROOT)/include +CPPFLAGS += -I$(CONFIG_H_DIR) -I$(PROOT)/include RCFLAGS += -I$(PROOT)/include -OBJ_DIR := $(TRIPLET) - # examples, tests -LIBSSH2_LDFLAGS_BIN += -L$(PROOT)/win32 +LIBSSH2_LDFLAGS_BIN += -L$(BLD_DIR) LIBS_BIN := -lssh2 ifdef WIN32 LIBS_BIN += -lws2_32 @@ -67,13 +70,13 @@ endif ifdef DYN ifdef WIN32 - libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.dll.a + libssh2_DEPENDENCIES := $(BLD_DIR)/libssh2.dll.a else - libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2$(DYN_EXT) + libssh2_DEPENDENCIES := $(BLD_DIR)/libssh2$(DYN_EXT) endif LIBSSH2_LDFLAGS_BIN += -shared else - libssh2_DEPENDENCIES := $(PROOT)/win32/libssh2.a + libssh2_DEPENDENCIES := $(BLD_DIR)/libssh2.a LIBSSH2_LDFLAGS_BIN += -static endif @@ -83,13 +86,15 @@ endif DB ?= NDEBUG CPPFLAGS += -D$(DB) ifeq ($(DB),NDEBUG) - OBJ_DIR := release-$(OBJ_DIR) + OBJ_DIR := release-$(TRIPLET) else - OBJ_DIR := debug-$(OBJ_DIR) + OBJ_DIR := debug-$(TRIPLET) CFLAGS += -g CPPFLAGS += -DLIBSSH2DEBUG endif +OBJ_DIR := $(BLD_DIR)/$(OBJ_DIR) + # Linker options to exclude for shared mode executables. _LDFLAGS := _LIBS := @@ -177,22 +182,23 @@ endif # include Makefile.inc to get CSOURCES define include $(PROOT)/Makefile.inc -OBJECTS := $(patsubst %.c,%.o,$(CSOURCES)) -OBJS := $(addprefix $(OBJ_DIR)/,$(OBJECTS)) +OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(CSOURCES))) -TARGET := libssh2 +TARGET := $(BLD_DIR)/libssh2 # Override the path below to point to your Distribution folder. -DISTDIR ?= $(TARGET)-$(LIBSSH2_VERSION_STR)-bin-$(word 1,$(subst -, ,$(TRIPLET))) +DISTNAM ?= libssh2-$(LIBSSH2_VERSION_STR)-bin-$(word 1,$(subst -, ,$(TRIPLET))) +DISTDIR := $(BLD_DIR)/$(DISTNAM) DISTARC := $(DISTDIR).zip LIBSSH2_DYN_SUFFIX ?= libssh2_dyn_LIBRARY := $(TARGET)$(LIBSSH2_DYN_SUFFIX)$(DYN_EXT) OBJS_dyn := $(OBJS) ifdef WIN32 + libssh2_def_LIBRARY := $(libssh2_dyn_LIBRARY:$(DYN_EXT)=.def) libssh2_dyn_a_LIBRARY := $(TARGET).dll.a - OBJS_dyn += $(OBJ_DIR)/$(TARGET).res - LIBSSH2_LDFLAGS_DYN += -Wl,--output-def,$(libssh2_dyn_LIBRARY:$(DYN_EXT)=.def),--out-implib,$(libssh2_dyn_a_LIBRARY) + OBJS_dyn += $(OBJ_DIR)/libssh2.res + LIBSSH2_LDFLAGS_DYN += -Wl,--output-def,$(libssh2_def_LIBRARY),--out-implib,$(libssh2_dyn_a_LIBRARY) endif TARGETS_EXAMPLES := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard $(PROOT)/example/*.c))) @@ -241,10 +247,14 @@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) @$(call COPY, $(libssh2_dyn_LIBRARY), $(DISTDIR)/bin) @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) - @$(call COPY, libssh2_config.h, $(DISTDIR)/include) - @$(call COPY, *.a, $(DISTDIR)/lib) + @$(call COPY, $(CONFIG_H_DIR)/libssh2_config.h, $(DISTDIR)/include) + @$(call COPY, $(TARGET).a, $(DISTDIR)/lib) +ifdef WIN32 + @$(call COPY, $(libssh2_dyn_a_LIBRARY), $(DISTDIR)/lib) + @$(call COPY, $(libssh2_def_LIBRARY), $(DISTDIR)/bin) +endif @echo Creating... $(DISTARC) - @$(ZIP) $(DISTARC) $(DISTDIR)/* < $(DISTDIR)/readme.txt + (cd $(DISTDIR)/.. && $(ZIP) $(abspath $(DISTARC)) $(DISTNAM)/* < $(abspath $(DISTDIR)/readme.txt)) distclean vclean: clean $(call RMDIR, $(DISTDIR)) @@ -257,7 +267,7 @@ testclean: clean $(call DEL, $(TARGETS_EXAMPLES)) clean: - $(call DEL, $(libssh2_dyn_LIBRARY) $(libssh2_dyn_LIBRARY:$(DYN_EXT)=.def) $(TARGET).a $(libssh2_dyn_a_LIBRARY)) + $(call DEL, $(TARGET).a $(libssh2_dyn_LIBRARY) $(libssh2_def_LIBRARY) $(libssh2_dyn_a_LIBRARY)) $(call RMDIR, $(OBJ_DIR)) $(OBJ_DIR): From 202a4f3f7a3396039bc8f8bad8c1646194f80f9d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 4 Apr 2023 00:03:33 +0000 Subject: [PATCH 225/424] build: MSVS warning suppression option tidy-up - in `win32/libssh2_config.h` replace `_CRT_SECURE_NO_DEPRECATE` with `_CRT_SECURE_NO_WARNINGS`, to use the official macro for this, like in CMake. Also, it's now safe to move it back under `_MSC_VER`. Suppressing: `warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.` `warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead.` - move `_CRT_NONSTDC_NO_DEPRECATE` to `example` and `tests`. Not needed for `src`. Suppressing: `warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup.` `warning C4996: 'write': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _write.` - move `_WINSOCK_DEPRECATED_NO_WARNINGS` from source files to CMake files, in `example` and `tests`. Also limit this to MSVC. Suppressing: `warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead` TODO: try fixing these instead of suppressing. Closes #929 --- cmake/max_warnings.cmake | 3 +-- example/CMakeLists.txt | 5 +++++ example/direct_tcpip.c | 6 ------ example/scp.c | 6 ------ example/scp_nonblock.c | 6 ------ example/scp_write.c | 6 ------ example/scp_write_nonblock.c | 6 ------ example/sftp.c | 6 ------ example/sftp_append.c | 6 ------ example/sftp_mkdir.c | 6 ------ example/sftp_mkdir_nonblock.c | 6 ------ example/sftp_nonblock.c | 6 ------ example/sftp_write.c | 6 ------ example/sftp_write_nonblock.c | 6 ------ example/sftp_write_sliding.c | 6 ------ example/sftpdir.c | 6 ------ example/sftpdir_nonblock.c | 6 ------ example/ssh2.c | 6 ------ example/ssh2_agent.c | 6 ------ example/ssh2_agent_forwarding.c | 6 ------ example/ssh2_echo.c | 6 ------ example/ssh2_exec.c | 6 ------ example/subsystem_netconf.c | 6 ------ example/tcpip-forward.c | 6 ------ tests/CMakeLists.txt | 5 +++++ tests/openssh_fixture.c | 6 ------ win32/libssh2_config.h | 7 +++---- 27 files changed, 14 insertions(+), 144 deletions(-) diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index 182738b72b..e14c67a802 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -28,8 +28,7 @@ if(MSVC) endif() endif() - # Disable broken warnings - add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang") if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 66e5debaea..f062634f41 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -39,6 +39,11 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) +if(MSVC) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) +endif() + set(EXAMPLES direct_tcpip scp diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 5cbccf508e..f724373c80 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -1,9 +1,3 @@ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp.c b/example/scp.c index f02944f9bb..ead7a84b4d 100644 --- a/example/scp.c +++ b/example/scp.c @@ -2,12 +2,6 @@ * Sample showing how to do a simple SCP transfer. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index fd8ab99dd1..d7b97bed3d 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -7,12 +7,6 @@ * "scp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp_write.c b/example/scp_write.c index 833b60189d..0962a89d95 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -2,12 +2,6 @@ * Sample showing how to do an SCP upload. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 0e6a1bebb5..f9f12b1d63 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -2,12 +2,6 @@ * Sample showing how to do an SCP non-blocking upload transfer. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/sftp.c b/example/sftp.c index 96fdea708c..78a4e4cbaa 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_append.c b/example/sftp_append.c index 012af2f265..0278009c82 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -7,12 +7,6 @@ * sftp_append 192.168.0.1 user password localfile /tmp/remotefile */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 9c9dc526f6..30231ee949 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password /tmp/sftp_mkdir" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index a24a174520..be5f7afee1 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 5932ad0524..ea16f23852 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -7,12 +7,6 @@ * "sftp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_write.c b/example/sftp_write.c index 5c6e5a80fd..e3725d1bbf 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index ef90210e6a..b907109cfe 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password thisfile /tmp/storehere" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 3c3d911303..2622314006 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password file /tmp/storehere" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftpdir.c b/example/sftpdir.c index e137a8a6eb..8d6dad5875 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -7,12 +7,6 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index fb229b9958..457ed7e055 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -7,12 +7,6 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/ssh2.c b/example/ssh2.c index 7d87b2b976..afd1d64764 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -11,12 +11,6 @@ * command executes on the remote machine */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 33d41be443..1815c10da6 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -6,12 +6,6 @@ * "ssh2_agent host user" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 0d8135024d..2110d6fa8b 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -13,12 +13,6 @@ * */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index d5fa7635ab..c08b4bef04 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -8,12 +8,6 @@ * */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index ae4d57ef05..7d0db115bc 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -10,12 +10,6 @@ * */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index 7903411684..b3198770fb 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -1,9 +1,3 @@ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index c7affdc64b..c90865fdbf 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -1,9 +1,3 @@ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 53f6fa618f..91ce4f66f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,6 +39,11 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) +if(MSVC) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) +endif() + set(TESTS warmup hostkey diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index a34e4b9b68..3e453d935f 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -35,12 +35,6 @@ * OF SUCH DAMAGE. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "session_fixture.h" #include "openssh_fixture.h" #include "libssh2_config.h" diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 371ae634f9..60c1467642 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -5,10 +5,6 @@ #define WIN32 #endif -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE 1 -#endif - #define HAVE_IOCTLSOCKET #define HAVE_SELECT #define HAVE_SNPRINTF @@ -21,6 +17,9 @@ # define HAVE_LONGLONG # define HAVE_STRTOLL #elif defined(_MSC_VER) +# ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS +# endif # if _MSC_VER >= 1310 # define HAVE_LONGLONG # endif From d58b71368770d2bbaab8b6facb6cc3b2c5199140 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 4 Apr 2023 00:03:52 +0000 Subject: [PATCH 226/424] src: include `limits.h` for `*_MAX` macros Follow-up to 5a96f494ee0b00282afb2db2e091246fc5e1774a Reported-by: OldWorldOrdr on github Fixes #928 Closes #930 --- src/libssh2_priv.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 3fc636676c..0307ec0958 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -86,6 +86,7 @@ #include #include +#include /* The following CPP block should really only be in session.c and packet.c. However, AIX have #define's for 'events' and 'revents' and we are using From 901bf00d0224d81d13875683cecc5c0725ca24b0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 4 Apr 2023 00:12:00 +0000 Subject: [PATCH 227/424] Makefile.mk: move portable GNU Make file to the root Move the GNU Make file formerly known as `win32/GNUmakefile` to the root directory from `win32`. It now supports any platform with a GCC-like toolchain, while also keeping support for win32. For non-Windows platforms it's necessary to provide a hand-crafted `libssh2_config.h` header for now. Usage: `make -f Makefile.mk` --- .gitignore | 4 ++++ Makefile.am | 4 ++-- win32/GNUmakefile => Makefile.mk | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) rename win32/GNUmakefile => Makefile.mk (98%) diff --git a/.gitignore b/.gitignore index 460bb772ad..64c776c3f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,17 @@ .deps .libs +*.a *.lib *.pdb *.dll +*.def *.exe *.obj .*.swp Debug Release +debug-* +release-* *.exp Makefile Makefile.in diff --git a/Makefile.am b/Makefile.am index 91cdaff8da..3f6f7907c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c \ vms/readme.vms vms/libssh2_config.h -WIN32FILES = win32/GNUmakefile NMakefile \ +WIN32FILES = NMakefile \ win32/libssh2_config.h \ src/libssh2.rc @@ -40,7 +40,7 @@ OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ EXTRA_DIST = $(WIN32FILES) get_ver.awk \ maketgz RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ CMakeLists.txt cmake git2news.pl libssh2-style.el README.md $(OS400FILES) \ - buildconf + buildconf Makefile.mk ACLOCAL_AMFLAGS = -I m4 diff --git a/win32/GNUmakefile b/Makefile.mk similarity index 98% rename from win32/GNUmakefile rename to Makefile.mk index 1cbd7babd7..387c85ae7c 100644 --- a/win32/GNUmakefile +++ b/Makefile.mk @@ -1,7 +1,7 @@ ######################################################################### # # Makefile for building libssh2 with GCC-like toolchains. -# Use: make -f GNUmakefile [help|all|clean|dist|distclean|dyn|objclean|test|testclean] +# Use: make -f Makefile.mk [help|all|clean|dist|distclean|dyn|objclean|test|testclean] # # Hacked by: Guenter Knauf # @@ -9,7 +9,7 @@ # ######################################################################### -PROOT := .. +PROOT := . ### Common @@ -276,7 +276,7 @@ $(OBJ_DIR): $(DISTDIR): @$(call MKDIR, $@) -$(DISTDIR)/readme.txt: GNUmakefile +$(DISTDIR)/readme.txt: Makefile.mk @echo Creating... $@ @echo $(DL)This is a binary distribution for $(TRIPLET).$(DL) > $@ @echo $(DL)libssh2 version $(LIBSSH2_VERSION_STR)$(DL) >> $@ From d709e3f9d0823115bb3e832a4da433a4279741a1 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 4 Apr 2023 17:52:10 +0000 Subject: [PATCH 228/424] libssh2.h: bump LIBSSH2_COPYRIGHT year [ci skip] --- include/libssh2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libssh2.h b/include/libssh2.h index 7d9b33976f..c932d76336 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -40,7 +40,7 @@ #ifndef LIBSSH2_H #define LIBSSH2_H 1 -#define LIBSSH2_COPYRIGHT "2004-2021 The libssh2 project and its contributors." +#define LIBSSH2_COPYRIGHT "2004-2023 The libssh2 project and its contributors." /* We use underscore instead of dash when appending DEV in dev versions just to make the BANNER define (used by src/session.c) be a valid SSH From a7d60c62ab77feb340bb6a33a6796182bfd5f524 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 4 Apr 2023 17:54:17 +0000 Subject: [PATCH 229/424] cmake: whitespace fixes [ci skip] --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfe63b185f..f0c393021e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,7 +149,7 @@ else() check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) endif() check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) -if (NOT HAVE_STRTOLL) +if(NOT HAVE_STRTOLL) # Try _strtoi64 if strtoll isn't available check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64) endif() @@ -218,7 +218,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) list(APPEND LIBRARIES ${OPENSSL_LIBRARIES}) list(APPEND PC_REQUIRES_PRIVATE libssl libcrypto) - if (WIN32) + if(WIN32) # Statically linking to OpenSSL requires crypt32 for some Windows APIs. # This should really be handled by FindOpenSSL.cmake. list(APPEND LIBRARIES crypt32 bcrypt) @@ -280,7 +280,7 @@ if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) list(APPEND LIBRARIES ${WOLFSSL_LIBRARIES}) list(APPEND PC_LIBS -lwolfssl) - if (WIN32) + if(WIN32) list(APPEND LIBRARIES crypt32) list(APPEND PC_LIBS -lcrypt32) endif() From c20c81ab105cdf27f5a4e2604bd13085f46e21de Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Wed, 5 Apr 2023 14:53:53 +0100 Subject: [PATCH 230/424] Configurable session read timeout (#892) This set of changes provides a mechanism to runtime-configure the previously #define'd timeout for reading packets from a session. The intention here is to also extend libcurl to be able to use this interface so that when fetching from sftp servers which are very slow to return directory listings, connections do not time-out so much. * Add new field to session to hold configurable read timeout * Updated `_libssh2_packet_require()`, `_libssh2_packet_requirev()`, and `sftp_packet_requirev()` to use new field in session structure * Updated docs for API functions to set/get read timeout field in session structure * Updated `libssh2.h` to declare the get/set read timeout functions Co-authored-by: Jon Axtell Credit: Daniel Silverstone --- docs/libssh2_session_get_read_timeout.3 | 19 +++++++++++++++++++ docs/libssh2_session_set_read_timeout.3 | 20 ++++++++++++++++++++ include/libssh2.h | 4 ++++ src/libssh2_priv.h | 7 +++++-- src/packet.c | 6 +++--- src/session.c | 25 +++++++++++++++++++++++++ src/sftp.c | 2 +- 7 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 docs/libssh2_session_get_read_timeout.3 create mode 100644 docs/libssh2_session_set_read_timeout.3 diff --git a/docs/libssh2_session_get_read_timeout.3 b/docs/libssh2_session_get_read_timeout.3 new file mode 100644 index 0000000000..4f47af39de --- /dev/null +++ b/docs/libssh2_session_get_read_timeout.3 @@ -0,0 +1,19 @@ +.TH libssh2_session_get_read_timeout 3 "13 Jan 2023" "libssh2 1.10.1" "libssh2 manual" +.SH NAME +libssh2_session_get_read_timeout - get the timeout for packet read functions +.SH SYNOPSIS +#include +.nf +long libssh2_session_get_read_timeout(LIBSSH2_SESSION *session); +.SH DESCRIPTION +Returns the \fBtimeout\fP (in seconds) for how long the ssh2 packet receive +function calls may wait until they consider the situation an error and +return LIBSSH2_ERROR_TIMEOUT. + +By default the timeout is 60 seconds. +.SH RETURN VALUE +The value of the timeout setting. +.SH AVAILABILITY +Added in 1.10.1 +.SH SEE ALSO +.BR libssh2_session_set_read_timeout(3) diff --git a/docs/libssh2_session_set_read_timeout.3 b/docs/libssh2_session_set_read_timeout.3 new file mode 100644 index 0000000000..63acd0001f --- /dev/null +++ b/docs/libssh2_session_set_read_timeout.3 @@ -0,0 +1,20 @@ +.TH libssh2_session_set_read_timeout 3 "13 Jan 2023" "libssh2 1.10.1" "libssh2 manual" +.SH NAME +libssh2_session_set_read_timeout - set timeout for packet read functions +.SH SYNOPSIS +#include +.nf +void libssh2_session_set_read_timeout(LIBSSH2_SESSION *session, long timeout); +.SH DESCRIPTION +Set the \fBtimeout\fP in seconds for how long libssh2 packet read +function calls may wait until they consider the situation an error and return +LIBSSH2_ERROR_TIMEOUT. + +By default or if you set the timeout to zero, the timeout will be set to +60 seconds. +.SH RETURN VALUE +Nothing +.SH AVAILABILITY +Added in 1.10.1 +.SH SEE ALSO +.BR libssh2_session_get_read_timeout(3) diff --git a/include/libssh2.h b/include/libssh2.h index c932d76336..0c82911a15 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -916,6 +916,10 @@ LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session, long timeout); LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session); +LIBSSH2_API void libssh2_session_set_read_timeout(LIBSSH2_SESSION* session, + long timeout); +LIBSSH2_API long libssh2_session_get_read_timeout(LIBSSH2_SESSION* session); + /* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */ LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode); diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 0307ec0958..67c4da54db 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -883,6 +883,9 @@ struct _LIBSSH2_SESSION int keepalive_interval; int keepalive_want_reply; time_t keepalive_last_sent; + + /* Configurable timeout for packets. Replaces LIBSSH2_READ_TIMEOUT */ + long packet_read_timeout; }; /* session.state bits */ @@ -1089,8 +1092,8 @@ ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer, ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length, int flags, void **abstract); -#define LIBSSH2_READ_TIMEOUT 60 /* generic timeout in seconds used when - waiting for more data to arrive */ +#define LIBSSH2_DEFAULT_READ_TIMEOUT 60 /* generic timeout in seconds used when + waiting for more data to arrive */ int _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, diff --git a/src/packet.c b/src/packet.c index f507770a22..fa221e832c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1267,8 +1267,8 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type, } else if(ret == 0) { /* nothing available, wait until data arrives or we time out */ - long left = LIBSSH2_READ_TIMEOUT - (long)(time(NULL) - - state->start); + long left = session->packet_read_timeout - (long)(time(NULL) - + state->start); if(left <= 0) { state->start = 0; @@ -1380,7 +1380,7 @@ _libssh2_packet_requirev(LIBSSH2_SESSION *session, return ret; } if(ret <= 0) { - long left = LIBSSH2_READ_TIMEOUT - + long left = session->packet_read_timeout - (long)(time(NULL) - state->start); if(left <= 0) { diff --git a/src/session.c b/src/session.c index 65946e1e8d..96a2167bbf 100644 --- a/src/session.c +++ b/src/session.c @@ -518,6 +518,7 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), session->abstract = abstract; session->api_timeout = 0; /* timeout-free API by default */ session->api_block_mode = 1; /* blocking API by default */ + session->packet_read_timeout = LIBSSH2_DEFAULT_READ_TIMEOUT; _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "New session resource allocated")); _libssh2_init_if_needed(); @@ -1469,6 +1470,30 @@ libssh2_session_get_timeout(LIBSSH2_SESSION * session) return session->api_timeout; } +/* libssh2_session_set_read_timeout + * + * Set a session's timeout (in sec) when reading packets, + * or 0 to use default of 60 seconds. + */ +LIBSSH2_API void +libssh2_session_set_read_timeout(LIBSSH2_SESSION * session, long timeout) +{ + if(timeout <= 0) { + timeout = LIBSSH2_DEFAULT_READ_TIMEOUT; + } + session->packet_read_timeout = timeout; +} + +/* libssh2_session_get_read_timeout + * + * Returns a session's timeout. Default is 60 seconds. + */ +LIBSSH2_API long +libssh2_session_get_read_timeout(LIBSSH2_SESSION * session) +{ + return session->packet_read_timeout; +} + /* * libssh2_poll_channel_read * diff --git a/src/sftp.c b/src/sftp.c index 0065f1b981..1e890b791d 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -611,7 +611,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses, else if(rc <= 0) { /* prevent busy-looping */ long left = - LIBSSH2_READ_TIMEOUT - + sftp->channel->session->packet_read_timeout - (long)(time(NULL) - sftp->requirev_start); if(left <= 0) { From bdad217440c173c613ff6e70504437d128f107ae Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 5 Apr 2023 13:58:21 +0000 Subject: [PATCH 231/424] build: add new man pages Follow-up to c20c81ab105cdf27f5a4e2604bd13085f46e21de --- docs/CMakeLists.txt | 2 ++ docs/Makefile.am | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index d8b9296af9..cb11db6c95 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -137,6 +137,7 @@ set(MAN_PAGES libssh2_session_flag.3 libssh2_session_free.3 libssh2_session_get_blocking.3 + libssh2_session_get_read_timeout.3 libssh2_session_get_timeout.3 libssh2_session_handshake.3 libssh2_session_hostkey.3 @@ -148,6 +149,7 @@ set(MAN_PAGES libssh2_session_methods.3 libssh2_session_set_blocking.3 libssh2_session_set_last_error.3 + libssh2_session_set_read_timeout.3 libssh2_session_set_timeout.3 libssh2_session_startup.3 libssh2_session_supported_algs.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index cc0e52446d..5efd370e6e 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -107,6 +107,7 @@ dist_man_MANS = \ libssh2_session_flag.3 \ libssh2_session_free.3 \ libssh2_session_get_blocking.3 \ + libssh2_session_get_read_timeout.3 \ libssh2_session_get_timeout.3 \ libssh2_session_handshake.3 \ libssh2_session_hostkey.3 \ @@ -118,6 +119,7 @@ dist_man_MANS = \ libssh2_session_methods.3 \ libssh2_session_set_blocking.3 \ libssh2_session_set_last_error.3 \ + libssh2_session_set_read_timeout.3 \ libssh2_session_set_timeout.3 \ libssh2_session_startup.3 \ libssh2_session_supported_algs.3 \ From 85582df111af7bc5633397c4be709fb7549766a0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 5 Apr 2023 13:59:49 +0000 Subject: [PATCH 232/424] crypto: fix `LIBSSH2_NO_MD5` compiler warnings Follow-up to be31457f3071686b555a0f0b19e5dcf63d67fc27 Closes #933 --- src/crypto.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/crypto.h b/src/crypto.h index 890f209bdc..503a825b43 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -60,6 +60,7 @@ #ifdef LIBSSH2_NO_MD5 #undef LIBSSH2_MD5 +#define LIBSSH2_MD5 0 #endif #define LIBSSH2_ED25519_KEY_LEN 32 From 4048d0ba26c2212534783206370e464a3b806433 Mon Sep 17 00:00:00 2001 From: ihsinme Date: Wed, 5 Apr 2023 17:23:54 +0300 Subject: [PATCH 233/424] example/x11: Add null-termination (#749) --- example/x11.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/x11.c b/example/x11.c index 3e801d4d49..70f400929e 100644 --- a/example/x11.c +++ b/example/x11.c @@ -151,7 +151,7 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, display[0] == ':') { /* Connect to the local unix domain */ ptr = strrchr(display, ':'); - temp_buff = (char *) calloc(strlen(ptr + 1), sizeof(char)); + temp_buff = (char *) calloc(strlen(ptr + 1) + 1, sizeof(char)); if(!temp_buff) { perror("calloc"); return; From 2082db93b23344b1df5457c085e70129ffea2230 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 6 Apr 2023 10:53:03 +0000 Subject: [PATCH 234/424] TODO: update item about compiler warnings [ci skip] Follow-up to 08354e0abbe86d4cc5088d210d53531be6d8981a Follow-up to 29347905721d2e7fbb97dabfb0071bee51db3013 Follow-up to 5a96f494ee0b00282afb2db2e091246fc5e1774a Follow-up to 463449fb9ee7dbe5fbe71a28494579a9a6890d6d Follow-up to 02f2700a61157ce5a264319bdb80754c92a40a24 --- docs/TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/TODO b/docs/TODO index a83af7cf64..a097c4f0c5 100644 --- a/docs/TODO +++ b/docs/TODO @@ -16,7 +16,7 @@ Things TODO * Extend the test suite to actually test lots of aspects of libssh2 -* Fix all compiler warnings (some can't be done without API changes) +* Update public API to drop casts added to fix compiler warnings * Expose error messages sent by the server From dfbd28308e068ecfed94b9098ac4ba4e0b9be602 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 14:15:11 +0000 Subject: [PATCH 235/424] Makefile.mk: merge two rules [ci skip] --- Makefile.mk | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile.mk b/Makefile.mk index 387c85ae7c..810d094964 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -270,10 +270,7 @@ clean: $(call DEL, $(TARGET).a $(libssh2_dyn_LIBRARY) $(libssh2_def_LIBRARY) $(libssh2_dyn_a_LIBRARY)) $(call RMDIR, $(OBJ_DIR)) -$(OBJ_DIR): - @$(call MKDIR, $@) - -$(DISTDIR): +$(OBJ_DIR) $(DISTDIR): @$(call MKDIR, $@) $(DISTDIR)/readme.txt: Makefile.mk From 17a419ba625e362ac99e13099b1bef8f4d12bf55 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 14:16:26 +0000 Subject: [PATCH 236/424] NMakefile: simplify [ci skip] --- NMakefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/NMakefile b/NMakefile index 5f445a3f82..3e368573c9 100644 --- a/NMakefile +++ b/NMakefile @@ -28,8 +28,6 @@ CFLAGS=$(CFLAGS) /DLIBSSH2_HAVE_ZLIB /I$(ZLIB_PATH)\include LIBS=$(LIBS) $(ZLIB_PATH)\lib\zlib.lib !endif -RCFLAGS=/Iinclude -DLLFLAGS=$(CFLAGS) $(DLLFLAGS) LIBS=$(LIBS) ws2_32.lib user32.lib advapi32.lib gdi32.lib INTDIR=$(TARGET) @@ -68,13 +66,13 @@ $(INTDIR): @if not exist $(INTDIR) mkdir $(INTDIR) $(DLL): $(OBJECTS) $(RESOURCE) - $(CC) -o $(DLL) $(DLLFLAGS) $(OBJECTS) $(RESOURCE) $(LIBS) + $(CC) -o $(DLL) $(CFLAGS) $(DLLFLAGS) $(OBJECTS) $(RESOURCE) $(LIBS) $(STATICLIB): $(OBJECTS) $(AR) $(ARFLAGS) -out:$@ $(OBJECTS) $(RESOURCE): src\libssh2.rc - $(RC) $(RCFLAGS) /Fo"$@" $? + $(RC) /Iinclude /Fo"$@" $? all-sub: $(INTDIR) all From ed72926640643512effa5361462f1a888fc674a7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 14:17:26 +0000 Subject: [PATCH 237/424] NMakefile: drop `/DEBUG` linker option in release mode [ci skip] --- NMakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NMakefile b/NMakefile index 3e368573c9..8cf64bace3 100644 --- a/NMakefile +++ b/NMakefile @@ -5,10 +5,10 @@ TARGET=Release !if "$(TARGET)" == "Debug" SUFFIX=_debug CFLAGS=/Od /MDd -DLLFLAGS=/DEBUG /LDd +DLLFLAGS=/LDd /DEBUG !else CFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG -DLLFLAGS=/DEBUG /LD +DLLFLAGS=/LD !endif CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iwin32 /Iinclude From 72cd241239c9f1115c618bb7ed8c88241a9696df Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 15:43:26 +0000 Subject: [PATCH 238/424] test_warmup: re-implement as `test()` Instead of overriding `main()`. To align with the other tests. Overriding `main()` can cause duplicate symbols without using a lib for the `runner` code. Follow-up to 40ac6b230a309d35c57aa65a8f6d7ab6654aa3d8 Closes #934 --- tests/test_warmup.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/test_warmup.c b/tests/test_warmup.c index dfbf6fa3ae..c8f2c21c30 100644 --- a/tests/test_warmup.c +++ b/tests/test_warmup.c @@ -1,4 +1,4 @@ -/* Warm-up test. Always return 0. +/* Warm-up test. Always return success. Workaround for CI/docker/etc flakiness on the first run. */ #include "session_fixture.h" @@ -8,20 +8,17 @@ #include -int main(void) +int test(LIBSSH2_SESSION *session) { - LIBSSH2_SESSION *session = start_session_fixture(); - if(session != NULL) { - size_t len = 0; - int type = 0; - const char *hostkey = libssh2_session_hostkey(session, &len, &type); + size_t len = 0; + int type = 0; + const char *hostkey = libssh2_session_hostkey(session, &len, &type); - (void)hostkey; + (void)hostkey; - fprintf(stdout, - "libssh2_session_hostkey returned len, type: %d, %d\n", - (int)len, type); - } - stop_session_fixture(); - return 0; + fprintf(stdout, + "libssh2_session_hostkey returned len, type: %d, %d\n", + (int)len, type); + + return 0; /* always return success */ } From 8774f4973ff34d19310ca0165aa182ab0efbece1 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 23:01:46 +0000 Subject: [PATCH 239/424] Makefile.mk: build tests and other improvements [ci skip] - use `example` target for building examples (was: `test`). - add support for building tests via the `test` target. - accept lib-only options in a new `LIBSSH2_CPPFLAGS_LIB` variable. Useful to pass `-DLIBSSH2_EXPORTS` for correct `dllexport` in `libssh2.dll`. - fix to put dynamic library in lib directory for non-Windows builds - fix to not delete lib objects on `testclean` --- Makefile.mk | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Makefile.mk b/Makefile.mk index 810d094964..0c7a1feb79 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -1,7 +1,7 @@ ######################################################################### # # Makefile for building libssh2 with GCC-like toolchains. -# Use: make -f Makefile.mk [help|all|clean|dist|distclean|dyn|objclean|test|testclean] +# Use: make -f Makefile.mk [help|all|clean|dist|distclean|dyn|objclean|example|exampleclean|test|testclean] # # Hacked by: Guenter Knauf # @@ -15,6 +15,7 @@ PROOT := . CFLAGS ?= CPPFLAGS ?= +LIBSSH2_CPPFLAGS_LIB ?= RCFLAGS ?= LDFLAGS ?= LIBSSH2_LDFLAGS_BIN ?= @@ -214,13 +215,30 @@ lib: prebuild $(TARGET).a prebuild: $(OBJ_DIR) $(OBJ_DIR)/version.inc -test: $(TARGETS_EXAMPLES) +example: $(TARGETS_EXAMPLES) + +TARGETS_RUNNER := $(TARGET)-runner.a +TARGETS_RUNNER_OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,runner.c session_fixture.c openssh_fixture.c)) +TARGETS_TESTS := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard $(PROOT)/tests/test_*.c))) + +test: $(TARGETS_RUNNER) $(TARGETS_TESTS) + +$(TARGETS_RUNNER_OBJS): + $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $(patsubst $(OBJ_DIR)/%.o,$(PROOT)/tests/%.c,$@) -o $@ + +$(TARGETS_RUNNER): $(TARGETS_RUNNER_OBJS) + @$(call DEL, $@) + $(AR) rcs $@ $^ + +test_%$(BIN_EXT): $(libssh2_DEPENDENCIES) + $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) \ + $(patsubst %$(BIN_EXT),%.c,$@) -o $@ $(TARGETS_RUNNER) $(LIBS) $(LIBS_BIN) %$(BIN_EXT): %.c $(libssh2_DEPENDENCIES) $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBSSH2_LDFLAGS_BIN) $< -o $@ $(LIBS) $(LIBS_BIN) $(OBJ_DIR)/%.o: %.c - $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) $(LIBSSH2_CPPFLAGS_LIB) -c $< -o $@ $(libssh2_dyn_LIBRARY) $(libssh2_dyn_a_LIBRARY): $(OBJS_dyn) @$(call DEL, $@) @@ -245,13 +263,15 @@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call COPY, $(PROOT)/COPYING, $(DISTDIR)) @$(call COPY, $(PROOT)/README, $(DISTDIR)) @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) - @$(call COPY, $(libssh2_dyn_LIBRARY), $(DISTDIR)/bin) @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) @$(call COPY, $(CONFIG_H_DIR)/libssh2_config.h, $(DISTDIR)/include) @$(call COPY, $(TARGET).a, $(DISTDIR)/lib) ifdef WIN32 - @$(call COPY, $(libssh2_dyn_a_LIBRARY), $(DISTDIR)/lib) @$(call COPY, $(libssh2_def_LIBRARY), $(DISTDIR)/bin) + @$(call COPY, $(libssh2_dyn_LIBRARY), $(DISTDIR)/bin) + @$(call COPY, $(libssh2_dyn_a_LIBRARY), $(DISTDIR)/lib) +else + @$(call COPY, $(libssh2_dyn_LIBRARY), $(DISTDIR)/lib) endif @echo Creating... $(DISTARC) (cd $(DISTDIR)/.. && $(ZIP) $(abspath $(DISTARC)) $(DISTNAM)/* < $(abspath $(DISTDIR)/readme.txt)) @@ -263,9 +283,12 @@ distclean vclean: clean objclean: all $(call RMDIR, $(OBJ_DIR)) -testclean: clean +exampleclean: $(call DEL, $(TARGETS_EXAMPLES)) +testclean: + $(call DEL, $(TARGETS_RUNNER_OBJS) $(TARGETS_RUNNER) $(TARGETS_TESTS)) + clean: $(call DEL, $(TARGET).a $(libssh2_dyn_LIBRARY) $(libssh2_def_LIBRARY) $(libssh2_dyn_a_LIBRARY)) $(call RMDIR, $(OBJ_DIR)) @@ -297,6 +320,8 @@ help: $(OBJ_DIR)/version.inc @echo $(DL)$(MAKE) dist$(DL) @echo $(DL)$(MAKE) distclean$(DL) @echo $(DL)$(MAKE) objclean$(DL) + @echo $(DL)$(MAKE) example$(DL) + @echo $(DL)$(MAKE) exampleclean$(DL) @echo $(DL)$(MAKE) test$(DL) @echo $(DL)$(MAKE) testclean$(DL) @echo $(DL)===========================================================$(DL) From 59666e03f04927e5fe3e8d8772d40729f63c570e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 23:32:42 +0000 Subject: [PATCH 240/424] build: hand-crafted config rework & header tidy-up - introduce the concept of a project level setup header `src/libssh2_setup.h`, that is used by `src`, `example` and `tests` alike. Move there all common platform/compiler configuration from `src/libssh2_priv.h`, individual sources and `CMakeFiles.txt` files. Also move there our hand-crafted (= not auto-generated by CMake or autotools) configuration `win32/libssh2-config.h`. - `win32` directory is empty now, delete it. - `Makefile.mk`: adapt to the above. Build-directory is the target triplet, or any custom name set via `BLD_DIR`. - sync header path order between build systems: build/src -> source/src -> source/include - delete redundant references to `windows.h`, `winsock2.h`, `ws2tcpip.h`. - delete unnecessary #includes, update order (`libssh2_setup.h` first, `winsock2.h` first), simplify where possible. This makes the code warning-free without `WIN32_LEAN_AND_MEAN`. At the same time this patch applies this macro globally, to avoid header bloat. - example: add missing *nix header guards. - example: fix misindented `HAVE_UNISTD_H` `#ifdef`s. - set `WIN32` with all build-tools. - set `HAVE_SYS_PARAM_H` in the hand-crafted config for MinGW. To match auto-detection. - move a source-specific macro to `misc.c` from `libssh2_priv.h`. See the PR's individual commits for step-by-step updates. Closes #932 --- .gitignore | 3 +- CMakeLists.txt | 3 +- Makefile.am | 1 - Makefile.inc | 6 +- Makefile.mk | 14 ++- NMakefile | 2 +- acinclude.m4 | 2 +- cmake/CheckNonblockingSocketSupport.cmake | 1 - cmake/max_warnings.cmake | 2 - example/CMakeLists.txt | 7 +- example/Makefile.am | 2 +- example/direct_tcpip.c | 20 +++-- example/scp.c | 7 +- example/scp_nonblock.c | 11 +-- example/scp_write.c | 13 +-- example/scp_write_nonblock.c | 13 +-- example/sftp.c | 11 +-- example/sftp_RW_nonblock.c | 11 +-- example/sftp_append.c | 9 +- example/sftp_mkdir.c | 9 +- example/sftp_mkdir_nonblock.c | 9 +- example/sftp_nonblock.c | 11 +-- example/sftp_write.c | 9 +- example/sftp_write_nonblock.c | 13 +-- example/sftp_write_sliding.c | 13 +-- example/sftpdir.c | 9 +- example/sftpdir_nonblock.c | 13 +-- example/ssh2.c | 10 +-- example/ssh2_agent.c | 10 +-- example/ssh2_agent_forwarding.c | 13 +-- example/ssh2_echo.c | 13 +-- example/ssh2_exec.c | 13 +-- example/subsystem_netconf.c | 14 +-- example/tcpip-forward.c | 20 +++-- example/x11.c | 6 +- include/libssh2.h | 21 +++-- include/libssh2_sftp.h | 2 +- src/Makefile.am | 2 +- src/agent.c | 3 - src/agent.h | 3 - src/agent_win.c | 16 +--- src/libssh2_priv.h | 57 ++++-------- src/libssh2_setup.h | 90 +++++++++++++++++++ src/misc.c | 4 +- src/session.c | 5 ++ tests/CMakeLists.txt | 13 +-- tests/Makefile.am | 2 +- tests/openssh_fixture.c | 4 - tests/runner.c | 1 - tests/runner.h | 4 + tests/session_fixture.c | 5 -- tests/session_fixture.h | 1 + tests/ssh2.c | 6 +- tests/test_agent_forward_succeeds.c | 5 -- tests/test_hostkey.c | 5 -- tests/test_hostkey_hash.c | 6 -- ...teractive_auth_fails_with_wrong_response.c | 5 -- ...t_keyboard_interactive_auth_info_request.c | 4 +- ...tive_auth_succeeds_with_correct_response.c | 5 -- ..._password_auth_fails_with_wrong_password.c | 5 -- ..._password_auth_fails_with_wrong_username.c | 5 -- ...d_auth_succeeds_with_correct_credentials.c | 5 -- ...est_public_key_auth_fails_with_wrong_key.c | 5 -- ...c_key_auth_succeeds_with_correct_dsa_key.c | 5 -- ...key_auth_succeeds_with_correct_ecdsa_key.c | 5 -- ...y_auth_succeeds_with_correct_ed25519_key.c | 5 -- ...cceeds_with_correct_ed25519_key_from_mem.c | 4 - ...ceeds_with_correct_encrypted_ed25519_key.c | 5 -- ..._succeeds_with_correct_encrypted_rsa_key.c | 5 -- ...c_key_auth_succeeds_with_correct_rsa_key.c | 5 -- ...th_succeeds_with_correct_rsa_openssh_key.c | 5 -- ...h_succeeds_with_correct_signed_ecdsa_key.c | 5 -- ...uth_succeeds_with_correct_signed_rsa_key.c | 5 -- tests/test_read.c | 5 -- tests/test_warmup.c | 5 -- win32/.gitignore | 7 -- win32/libssh2_config.h | 38 -------- 77 files changed, 250 insertions(+), 466 deletions(-) create mode 100644 src/libssh2_setup.h delete mode 100644 win32/.gitignore delete mode 100644 win32/libssh2_config.h diff --git a/.gitignore b/.gitignore index 64c776c3f1..3eda965d92 100644 --- a/.gitignore +++ b/.gitignore @@ -8,10 +8,9 @@ *.exe *.obj .*.swp +*-*-* Debug Release -debug-* -release-* *.exp Makefile Makefile.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c393021e..bd51aa89e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,9 +127,9 @@ check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files(sys/un.h HAVE_SYS_UN_H) +check_include_files(sys/param.h HAVE_SYS_PARAM_H) # for example and tests -check_include_files(sys/param.h HAVE_SYS_PARAM_H) check_include_files(arpa/inet.h HAVE_ARPA_INET_H) check_include_files(netinet/in.h HAVE_NETINET_IN_H) @@ -330,6 +330,7 @@ endif() if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) # The check actually compiles the header. This requires windows.h. + # Check necessary for old-MinGW check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) if(HAVE_BCRYPT_H) diff --git a/Makefile.am b/Makefile.am index 3f6f7907c3..5caa05538b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,6 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/readme.vms vms/libssh2_config.h WIN32FILES = NMakefile \ - win32/libssh2_config.h \ src/libssh2.rc OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ diff --git a/Makefile.inc b/Makefile.inc index a6524cdeb4..e3c1f0cc52 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -4,6 +4,6 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c -HHEADERS = libssh2_priv.h $(CRYPTO_HHEADERS) transport.h channel.h comp.h \ - mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h blf.h agent.h \ - userauth_kbd_packet.h os400qc3.h +HHEADERS = libssh2_priv.h libssh2_setup.h $(CRYPTO_HHEADERS) transport.h \ + channel.h comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h \ + blf.h agent.h userauth_kbd_packet.h os400qc3.h diff --git a/Makefile.mk b/Makefile.mk index 0c7a1feb79..337d23b92a 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -47,18 +47,17 @@ else TRIPLET ?= $(shell $(CC) -dumpmachine) endif +BLD_DIR ?= $(PROOT)/$(TRIPLET) + ifneq ($(findstring -w,$(TRIPLET)),) WIN32 := 1 BIN_EXT := .exe DYN_EXT := .dll - BLD_DIR ?= $(PROOT)/win32 - CONFIG_H_DIR ?= $(PROOT)/win32 else - BLD_DIR ?= $(PROOT) - CONFIG_H_DIR ?= $(PROOT) + CPPFLAGS += -I$(BLD_DIR) -DHAVE_CONFIG_H endif -CPPFLAGS += -I$(CONFIG_H_DIR) -I$(PROOT)/include +CPPFLAGS += -I$(PROOT)/src -I$(PROOT)/include RCFLAGS += -I$(PROOT)/include # examples, tests @@ -87,9 +86,9 @@ endif DB ?= NDEBUG CPPFLAGS += -D$(DB) ifeq ($(DB),NDEBUG) - OBJ_DIR := release-$(TRIPLET) + OBJ_DIR := release else - OBJ_DIR := debug-$(TRIPLET) + OBJ_DIR := debug CFLAGS += -g CPPFLAGS += -DLIBSSH2DEBUG endif @@ -264,7 +263,6 @@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call COPY, $(PROOT)/README, $(DISTDIR)) @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) - @$(call COPY, $(CONFIG_H_DIR)/libssh2_config.h, $(DISTDIR)/include) @$(call COPY, $(TARGET).a, $(DISTDIR)/lib) ifdef WIN32 @$(call COPY, $(libssh2_def_LIBRARY), $(DISTDIR)/bin) diff --git a/NMakefile b/NMakefile index 8cf64bace3..19756816f1 100644 --- a/NMakefile +++ b/NMakefile @@ -11,7 +11,7 @@ CFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG DLLFLAGS=/LD !endif -CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iwin32 /Iinclude +CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iinclude !if "$(OPENSSL_PATH)" != "" CFLAGS=$(CFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSL_PATH)\include diff --git a/acinclude.m4 b/acinclude.m4 index 85de8c1408..9c497944b5 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -217,7 +217,6 @@ dnl the code was bad, try a different program now, test 3 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#include #include #endif ],[ @@ -451,6 +450,7 @@ m4_case([$1], LIBS="$LIBS -lcrypt32" + # Check necessary for old-MinGW LIBSSH2_LIB_HAVE_LINKFLAGS([bcrypt], [], [ #include #include diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index 6affb1cc39..b34b8b9864 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -74,7 +74,6 @@ int main(void) #define WIN32_LEAN_AND_MEAN #endif -#include #include int main(void) diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index e14c67a802..6d20334445 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -27,8 +27,6 @@ if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") endif() endif() - - add_definitions(-D_CRT_SECURE_NO_WARNINGS) elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang") if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f062634f41..72ca94895e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -39,11 +39,6 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) -if(MSVC) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) -endif() - set(EXAMPLES direct_tcpip scp @@ -74,7 +69,7 @@ foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) list(APPEND EXAMPLE_TARGETS example-${example}) # to find generated header - target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src) + target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ../src) target_link_libraries(example-${example} ${LIB_STATIC} ${LIBRARIES}) endforeach() diff --git a/example/Makefile.am b/example/Makefile.am index 495f93eb59..0d9594b50a 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -29,5 +29,5 @@ noinst_PROGRAMS = \ tcpip-forward \ x11 -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/example -I../src +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/include LDADD = $(top_builddir)/src/libssh2.la diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index f724373c80..cf19fed396 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -1,16 +1,22 @@ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -#include -#include -#include +#include /* for socklen_t */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) #define send(s, b, l, f) send((s), (b), (int)(l), (f)) -#else +#endif + +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include #endif @@ -30,10 +36,6 @@ #define INADDR_NONE (in_addr_t)-1 #endif -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; const char *keyfile2 = "/home/username/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/scp.c b/example/scp.c index ead7a84b4d..999a960edd 100644 --- a/example/scp.c +++ b/example/scp.c @@ -2,11 +2,10 @@ * Sample showing how to do a simple SCP transfer. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -15,8 +14,8 @@ #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index d7b97bed3d..1160150e03 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -7,11 +7,10 @@ * "scp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -23,8 +22,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -39,10 +38,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/scp_write.c b/example/scp_write.c index 0962a89d95..581db95ad5 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -2,20 +2,17 @@ * Sample showing how to do an SCP upload. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -30,10 +27,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - int main(int argc, char *argv[]) { uint32_t hostaddr; diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index f9f12b1d63..742896bb42 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -2,12 +2,9 @@ * Sample showing how to do an SCP non-blocking upload transfer. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -17,8 +14,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -34,10 +31,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftp.c b/example/sftp.c index 78a4e4cbaa..12073b70f5 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -7,12 +7,11 @@ * "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -21,8 +20,8 @@ #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -37,10 +36,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - const char *keyfile1 = "~/.ssh/id_rsa.pub"; const char *keyfile2 = "~/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 76dc525e01..6d30ae7f4f 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -7,12 +7,11 @@ * Using the SFTP server running on 127.0.0.1 */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -24,8 +23,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +39,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #define STORAGE "/tmp/sftp-storage" /* this is the local file name this example uses to store the downloaded file in */ diff --git a/example/sftp_append.c b/example/sftp_append.c index 0278009c82..a24d053239 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -7,21 +7,18 @@ * sftp_append 192.168.0.1 user password localfile /tmp/remotefile */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 30231ee949..4838c1ef44 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -7,21 +7,18 @@ * "sftp 192.168.0.1 user password /tmp/sftp_mkdir" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index be5f7afee1..4563a153ac 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -7,21 +7,18 @@ * "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index ea16f23852..760b78ba8f 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -7,12 +7,11 @@ * "sftp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -24,8 +23,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +39,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/sftp_write.c b/example/sftp_write.c index e3725d1bbf..a241a42445 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -7,21 +7,18 @@ * "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index b907109cfe..db57fd5f5b 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -7,13 +7,10 @@ * "sftp 192.168.0.1 user password thisfile /tmp/storehere" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -23,8 +20,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +37,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 2622314006..2be99d29cf 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -7,13 +7,10 @@ * "sftp 192.168.0.1 user password file /tmp/storehere" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -23,8 +20,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +37,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftpdir.c b/example/sftpdir.c index 8d6dad5875..976ae818c4 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -7,13 +7,10 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -36,10 +33,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #if defined(_MSC_VER) #define __FILESIZE "I64u" #else diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 457ed7e055..779dd3d4af 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -7,21 +7,18 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -36,10 +33,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #if defined(_MSC_VER) #define __FILESIZE "I64u" #else diff --git a/example/ssh2.c b/example/ssh2.c index afd1d64764..b1e026f572 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -11,22 +11,18 @@ * command executes on the remote machine */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif # ifdef HAVE_ARPA_INET_H #include diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 1815c10da6..2056ba6d93 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -6,22 +6,18 @@ * "ssh2_agent host user" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif # ifdef HAVE_ARPA_INET_H #include diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 2110d6fa8b..2e7f104a6a 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -13,12 +13,9 @@ * */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -28,8 +25,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -45,10 +42,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index c08b4bef04..36651d7f59 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -8,12 +8,9 @@ * */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -23,8 +20,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -39,10 +36,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 7d0db115bc..9fc3dbce3b 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -10,12 +10,9 @@ * */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -25,8 +22,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -41,10 +38,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index b3198770fb..2101cedc97 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -1,14 +1,16 @@ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -#include -#include -#include -#else +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include #endif diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index c90865fdbf..8dea412f1c 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -1,16 +1,22 @@ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -#include -#include -#include +#include /* for socklen_t */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) #define send(s, b, l, f) send((s), (b), (int)(l), (f)) -#else +#endif + +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include #endif @@ -30,10 +36,6 @@ #define INADDR_NONE (in_addr_t)-1 #endif -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; const char *keyfile2 = "/home/username/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/x11.c b/example/x11.c index 70f400929e..c8971252eb 100644 --- a/example/x11.c +++ b/example/x11.c @@ -5,8 +5,8 @@ * "ssh2 host user password [DEBUG]" */ +#include "libssh2_setup.h" #include -#include "libssh2_config.h" #include @@ -42,10 +42,6 @@ #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - #define _PATH_UNIX_X "/tmp/.X11-unix/X%d" /* diff --git a/include/libssh2.h b/include/libssh2.h index 0c82911a15..2a859cb975 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -87,7 +87,12 @@ #ifdef __cplusplus extern "C" { #endif -#ifdef _WIN32 + +#if defined(_WIN32) || defined(WIN32) +#define _LIBSSH2_WIN32 +#endif + +#ifdef _LIBSSH2_WIN32 # include # include #endif @@ -99,7 +104,7 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API -# ifdef WIN32 +# ifdef _LIBSSH2_WIN32 # if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || \ defined(_WINDLL) || defined(libssh2_shared_EXPORTS) # ifdef LIBSSH2_LIBRARY @@ -110,9 +115,9 @@ extern "C" { # else # define LIBSSH2_API # endif -# else /* !WIN32 */ +# else /* !_LIBSSH2_WIN32 */ # define LIBSSH2_API -# endif /* WIN32 */ +# endif /* _LIBSSH2_WIN32 */ #endif /* LIBSSH2_API */ #ifdef HAVE_SYS_UIO_H @@ -138,13 +143,13 @@ typedef unsigned long long libssh2_uint64_t; typedef long long libssh2_int64_t; #endif -#ifdef WIN32 +#ifdef _LIBSSH2_WIN32 typedef SOCKET libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET INVALID_SOCKET -#else /* !WIN32 */ +#else /* !_LIBSSH2_WIN32 */ typedef int libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET -1 -#endif /* WIN32 */ +#endif /* _LIBSSH2_WIN32 */ /* * Determine whether there is small or large file support on windows. @@ -170,7 +175,7 @@ typedef int libssh2_socket_t; # undef LIBSSH2_USE_WIN32_LARGE_FILES #endif -#if defined(_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ +#if defined(_LIBSSH2_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ !defined(LIBSSH2_USE_WIN32_SMALL_FILES) # define LIBSSH2_USE_WIN32_SMALL_FILES #endif diff --git a/include/libssh2_sftp.h b/include/libssh2_sftp.h index d35ff27a3e..5c152d7522 100644 --- a/include/libssh2_sftp.h +++ b/include/libssh2_sftp.h @@ -40,7 +40,7 @@ #include "libssh2.h" -#ifndef WIN32 +#ifndef _LIBSSH2_WIN32 #include #endif diff --git a/src/Makefile.am b/src/Makefile.am index 84e210197a..240bed1413 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,7 +31,7 @@ lib_LTLIBRARIES = libssh2.la # srcdir/include for the shipped headers # builddir/src for the generated config header when building out of the source # tree -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/src +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/include VERSION=-version-info 1:1:0 diff --git a/src/agent.c b/src/agent.c index 0907e598fd..a7b5de7e06 100644 --- a/src/agent.c +++ b/src/agent.c @@ -50,9 +50,6 @@ #endif #include "userauth.h" #include "session.h" -#ifdef WIN32 -#include -#endif /* Requests from client to agent for protocol 1 key operations */ #define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1 diff --git a/src/agent.h b/src/agent.h index 64bbfe0154..605ba05d1c 100644 --- a/src/agent.h +++ b/src/agent.h @@ -41,9 +41,6 @@ #include "libssh2_priv.h" #include "session.h" -#ifdef WIN32 -#include -#endif /* non-blocking mode on agent connection is not yet implemented, but for future use. */ diff --git a/src/agent_win.c b/src/agent_win.c index be6be4b741..95e2b8cd47 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -40,21 +40,11 @@ #include "libssh2_priv.h" #include "agent.h" #include -#ifdef HAVE_SYS_UN_H -#include -#else -/* Use the existence of sys/un.h as a test if Unix domain socket is - supported. winsock*.h define PF_UNIX/AF_UNIX but do not actually - support them. */ -#undef PF_UNIX -#endif -#include "userauth.h" -#include "session.h" -#ifdef WIN32 -#include -#endif #if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) + +#include /* for getenv() */ + /* Code to talk to OpenSSH was taken and modified from the Win32 port of * Portable OpenSSH by the PowerShell team. Commit * 8ab565c53f3619d6a1f5ac229e212cad8a52852c of diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 67c4da54db..6b048df2f5 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -39,50 +39,12 @@ * OF SUCH DAMAGE. */ -/* Disable warnings: C4127: conditional expression is constant */ -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - -/* Define mingw-w64 version macros, eg __MINGW{32,64}_{MINOR,MAJOR}_VERSION */ -#ifdef __MINGW32__ -#include <_mingw.h> -#endif +/* Header used by 'src' */ #define LIBSSH2_LIBRARY -#include "libssh2_config.h" -/* Number of bits in a file offset, on hosts where this is settable. */ -#if defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR) -# ifndef _FILE_OFFSET_BITS -# define _FILE_OFFSET_BITS 64 -# endif -#endif - -#ifdef WIN32 -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#undef WIN32_LEAN_AND_MEAN - -/* Detect Windows App environment which has a restricted access - to the Win32 APIs. */ -# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ - defined(WINAPI_FAMILY) -# include -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ - !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define LIBSSH2_WINDOWS_APP -# endif -# endif - -#include -#include -/* Force parameter type. */ -#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) -#define send(s, b, l, f) send((s), (b), (int)(l), (f)) -#endif +/* platform/compiler-specific setup */ +#include "libssh2_setup.h" #include #include @@ -128,6 +90,19 @@ #include "libssh2_sftp.h" #include "misc.h" +#ifdef WIN32 +/* Detect Windows App environment which has a restricted access + to the Win32 APIs. */ +# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ + defined(WINAPI_FAMILY) +# include +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define LIBSSH2_WINDOWS_APP +# endif +# endif +#endif + #ifndef FALSE #define FALSE 0 #endif diff --git a/src/libssh2_setup.h b/src/libssh2_setup.h new file mode 100644 index 0000000000..ac769233fd --- /dev/null +++ b/src/libssh2_setup.h @@ -0,0 +1,90 @@ +#ifndef LIBSSH2_SETUP_H +#define LIBSSH2_SETUP_H + +/* Header for platform/compiler-specific initialization. + Used by 'src', 'example', 'tests' */ + +#if defined(_WIN32) && !defined(WIN32) +#define WIN32 +#endif + +/* Define mingw-w64 version macros, eg __MINGW{32,64}_{MINOR,MAJOR}_VERSION */ +#ifdef __MINGW32__ +#include <_mingw.h> +#endif + +/* Configuration provided by build tools (autotools and CMake), + and via platform-specific directories for os400 and vms */ +#if defined(HAVE_CONFIG_H) || defined(__OS400__) || defined(__VMS) + +#include "libssh2_config.h" + +/* Hand-crafted configuration for platforms which lack config tool. */ +#elif defined(WIN32) + +#define HAVE_IOCTLSOCKET +#define HAVE_SELECT +#define HAVE_SNPRINTF + +#ifdef __MINGW32__ +# define HAVE_UNISTD_H +# define HAVE_INTTYPES_H +# define HAVE_SYS_TIME_H +# define HAVE_SYS_PARAM_H +# define HAVE_GETTIMEOFDAY +# define HAVE_LONGLONG +# define HAVE_STRTOLL +#elif defined(_MSC_VER) +# if _MSC_VER >= 1310 +# define HAVE_LONGLONG +# endif +# if _MSC_VER >= 1800 +# define HAVE_STRTOLL +# endif +# if _MSC_VER < 1900 +# undef HAVE_SNPRINTF +# endif +#endif + +#endif /* defined(HAVE_CONFIG_H) */ + +/* Below applies to both auto-detected and hand-crafted configs */ + +#ifdef WIN32 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __MINGW32__ +# ifdef __MINGW64_VERSION_MAJOR +/* Number of bits in a file offset, on hosts where this is settable. */ +# ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +# endif +# endif +#elif defined(_MSC_VER) +# ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS /* for fopen(), getenv() */ +# endif +# ifndef LIBSSH2_LIBRARY /* apply to examples and tests only */ +# ifndef _CRT_NONSTDC_NO_DEPRECATE +# define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write() */ +# endif +# ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +# define _WINSOCK_DEPRECATED_NO_WARNINGS /* for inet_addr() */ +# endif +# endif +# if _MSC_VER < 1500 +# define vsnprintf _vsnprintf +# endif +# if _MSC_VER < 1900 +# define strdup _strdup +/* Silence bogus warning C4127: conditional expression is constant */ +# pragma warning(disable:4127) +# endif +#endif + +#endif /* WIN32 */ + +#endif /* LIBSSH2_SETUP_H */ diff --git a/src/misc.c b/src/misc.c index 8699002946..654877bda3 100644 --- a/src/misc.c +++ b/src/misc.c @@ -51,7 +51,9 @@ #endif #ifdef WIN32 -#include +/* Force parameter type. */ +#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) +#define send(s, b, l, f) send((s), (b), (int)(l), (f)) #endif #include diff --git a/src/session.c b/src/session.c index 96a2167bbf..5d2b023bc2 100644 --- a/src/session.c +++ b/src/session.c @@ -38,6 +38,11 @@ */ #include "libssh2_priv.h" + +#ifdef WIN32 +#include /* for socklen_t */ +#endif + #include #ifdef HAVE_UNISTD_H #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 91ce4f66f1..e792523336 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,11 +39,6 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) -if(MSVC) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) -endif() - set(TESTS warmup hostkey @@ -83,21 +78,21 @@ if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") endif() add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) -target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../include) +target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include) target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") # test building against shared libssh2 lib if(BUILD_SHARED_LIBS) set(test warmup) # any test will do add_executable(test_${test}_shared test_${test}.c) - target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src") + target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) target_link_libraries(test_${test}_shared runner ${LIB_SHARED} ${LIBRARIES}) endif() foreach(test ${TESTS}) add_executable(test_${test} test_${test}.c) list(APPEND TEST_TARGETS test_${test}) - target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src") + target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) target_link_libraries(test_${test} runner ${LIB_STATIC} ${LIBRARIES}) add_test( @@ -143,7 +138,7 @@ endforeach() add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) target_compile_definitions(test_keyboard_interactive_auth_info_request PRIVATE "${CRYPTO_BACKEND_DEFINE}") -target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src/" "${CRYPTO_BACKEND_INCLUDE_DIR}") +target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") find_program(GCOV_PATH gcov) set(TGT_OPTIONS -g --coverage -fprofile-abs-path) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) diff --git a/tests/Makefile.am b/tests/Makefile.am index f0ada7d337..d9f73165c0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = ossfuzz -AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include -I$(top_builddir)/src +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/include ctests = simple$(EXEEXT) TESTS = $(ctests) mansyntax.sh diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 3e453d935f..75a40ab1d2 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -37,11 +37,7 @@ #include "session_fixture.h" #include "openssh_fixture.h" -#include "libssh2_config.h" -#ifdef WIN32 -#include -#endif #ifdef HAVE_SYS_SOCKET_H #include #endif diff --git a/tests/runner.c b/tests/runner.c index f3522bba5a..aff8cae5bc 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -35,7 +35,6 @@ * OF SUCH DAMAGE. */ -#include "session_fixture.h" #include "runner.h" int main(void) diff --git a/tests/runner.h b/tests/runner.h index f32a7af258..6cd549340f 100644 --- a/tests/runner.h +++ b/tests/runner.h @@ -38,6 +38,10 @@ #ifndef LIBSSH2_TESTS_RUNNER_H #define LIBSSH2_TESTS_RUNNER_H +/* Most tests need these */ +#include "session_fixture.h" +#include + int test(LIBSSH2_SESSION *session); #endif diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 7087c3599f..232c049871 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -36,7 +36,6 @@ */ #include "session_fixture.h" -#include "libssh2_config.h" #include "openssh_fixture.h" #include @@ -45,15 +44,11 @@ #include #endif -#ifdef WIN32 -#include -#include #ifdef _MSC_VER #include #define getcwd _getcwd #define chdir _chdir #endif -#endif #ifdef HAVE_SYS_SOCKET_H #include diff --git a/tests/session_fixture.h b/tests/session_fixture.h index 3820a5a94c..5314fa5789 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -38,6 +38,7 @@ #ifndef LIBSSH2_TESTS_SESSION_FIXTURE_H #define LIBSSH2_TESTS_SESSION_FIXTURE_H +#include "libssh2_setup.h" #include #if defined(_MSC_VER) && _MSC_VER < 1900 diff --git a/tests/ssh2.c b/tests/ssh2.c index b338c92210..f912065135 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -1,13 +1,9 @@ /* Self test, based on examples/ssh2.c. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index 990531dfc7..7d835feb83 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - const char *USERNAME = "libssh2"; /* set in Dockerfile */ const char *KEY_FILE_PRIVATE = "key_rsa"; const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */ diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index 007b9bfbe6..3ab01ab010 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *EXPECTED_RSA_HOSTKEY = "AAAAB3NzaC1yc2EAAAABIwAAAQEArrr/JuJmaZligyfS8vcNur+mWR2ddDQtVdhHzdKU" "UoR6/Om6cvxpe61H1YZO1xCpLUBXmkki4HoNtYOpPB2W4V+8U4BDeVBD5crypEOE1+7B" diff --git a/tests/test_hostkey_hash.c b/tests/test_hostkey_hash.c index 6f22d68fe0..41f1e44d7c 100644 --- a/tests/test_hostkey_hash.c +++ b/tests/test_hostkey_hash.c @@ -1,10 +1,4 @@ -#include "session_fixture.h" #include "runner.h" -#include "libssh2_config.h" - -#include - -#include static const char *EXPECTED_RSA_HOSTKEY = "AAAAB3NzaC1yc2EAAAABIwAAAQEArrr/JuJmaZligyfS8vcNur+mWR2ddDQtVdhHzdKU" diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c index 9927a96cb4..9a37afb425 100644 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *USERNAME = "libssh2"; /* set in Dockerfile */ static const char *WRONG_PASSWORD = "i'm not the password"; diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index 989681f9c4..d30c0cfcab 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -35,11 +35,11 @@ * OF SUCH DAMAGE. */ -#include - #include "libssh2_priv.h" #include "userauth_kbd_packet.h" +#include + #define PASS 0 #define FAIL -1 diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c index 14746e96ca..f15ab7dcc9 100644 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "my test password"; diff --git a/tests/test_password_auth_fails_with_wrong_password.c b/tests/test_password_auth_fails_with_wrong_password.c index ec57b3b9ce..e72c7ff863 100644 --- a/tests/test_password_auth_fails_with_wrong_password.c +++ b/tests/test_password_auth_fails_with_wrong_password.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *USERNAME = "libssh2"; /* set in Dockerfile */ static const char *WRONG_PASSWORD = "i'm not the password"; diff --git a/tests/test_password_auth_fails_with_wrong_username.c b/tests/test_password_auth_fails_with_wrong_username.c index 6ada9682e9..12516c883a 100644 --- a/tests/test_password_auth_fails_with_wrong_username.c +++ b/tests/test_password_auth_fails_with_wrong_username.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *PASSWORD = "my test password"; static const char *WRONG_USERNAME = "i dont exist"; diff --git a/tests/test_password_auth_succeeds_with_correct_credentials.c b/tests/test_password_auth_succeeds_with_correct_credentials.c index 7b3fd7d8dd..01be0c5932 100644 --- a/tests/test_password_auth_succeeds_with_correct_credentials.c +++ b/tests/test_password_auth_succeeds_with_correct_credentials.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "my test password"; diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c index 83cba13d64..c371c21c2f 100644 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ b/tests/test_public_key_auth_fails_with_wrong_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *USERNAME = "libssh2"; /* set in Dockerfile */ static const char *KEY_FILE_PRIVATE = "key_dsa_wrong"; static const char *KEY_FILE_PUBLIC = "key_dsa_wrong.pub"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c index 6d77b3b913..bc5319c6cf 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_dsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c index 768f417c4f..2d1650c8d4 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_ecdsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c index 31b9bf0ddb..e0380f69dc 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_ed25519"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index 8f7865ff21..b9d9385f06 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -1,9 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include #include static const char *USERNAME = "libssh2"; /* set in Dockerfile */ diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c index 0095cf4719..7a305cef34 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "libssh2"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c index 08acc2be6a..15803afef2 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "libssh2"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c index 96792259a7..6b905e6e9f 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c index cac578a3cd..4440f124ba 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa_openssh"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c index 93d5a31068..f5c51f98d8 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "signed_key_ecdsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c index 4a9a6dddee..65c5597bf7 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "signed_key_rsa"; diff --git a/tests/test_read.c b/tests/test_read.c index b7f9d6af53..03ab99dc39 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -1,12 +1,7 @@ /* libssh2 test receiving large amounts of data through a channel */ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa"; diff --git a/tests/test_warmup.c b/tests/test_warmup.c index c8f2c21c30..4eb19514b6 100644 --- a/tests/test_warmup.c +++ b/tests/test_warmup.c @@ -1,13 +1,8 @@ /* Warm-up test. Always return success. Workaround for CI/docker/etc flakiness on the first run. */ -#include "session_fixture.h" #include "runner.h" -#include - -#include - int test(LIBSSH2_SESSION *session) { size_t len = 0; diff --git a/win32/.gitignore b/win32/.gitignore deleted file mode 100644 index 5f852e423c..0000000000 --- a/win32/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -*.a -*.dll -*.def -*.exe -debug-* -release-* -libssh2-*.zip diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h deleted file mode 100644 index 60c1467642..0000000000 --- a/win32/libssh2_config.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef LIBSSH2_CONFIG_H -#define LIBSSH2_CONFIG_H - -#ifndef WIN32 -#define WIN32 -#endif - -#define HAVE_IOCTLSOCKET -#define HAVE_SELECT -#define HAVE_SNPRINTF - -#ifdef __MINGW32__ -# define HAVE_UNISTD_H -# define HAVE_INTTYPES_H -# define HAVE_SYS_TIME_H -# define HAVE_GETTIMEOFDAY -# define HAVE_LONGLONG -# define HAVE_STRTOLL -#elif defined(_MSC_VER) -# ifndef _CRT_SECURE_NO_WARNINGS -# define _CRT_SECURE_NO_WARNINGS -# endif -# if _MSC_VER >= 1310 -# define HAVE_LONGLONG -# endif -# if _MSC_VER >= 1800 -# define HAVE_STRTOLL -# endif -# if _MSC_VER < 1900 -# undef HAVE_SNPRINTF -# if _MSC_VER < 1500 -# define vsnprintf _vsnprintf -# endif -# define strdup _strdup -# endif -#endif - -#endif /* LIBSSH2_CONFIG_H */ From bc0cd58e8770e9382c7051d58e521f5c0668bbfb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 23:50:57 +0000 Subject: [PATCH 241/424] Makefile.mk: drop `PROOT` variable [ci skip] --- Makefile.mk | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Makefile.mk b/Makefile.mk index 337d23b92a..2cfd0a8df8 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -9,8 +9,6 @@ # ######################################################################### -PROOT := . - ### Common CFLAGS ?= @@ -47,7 +45,7 @@ else TRIPLET ?= $(shell $(CC) -dumpmachine) endif -BLD_DIR ?= $(PROOT)/$(TRIPLET) +BLD_DIR ?= $(TRIPLET) ifneq ($(findstring -w,$(TRIPLET)),) WIN32 := 1 @@ -57,8 +55,8 @@ else CPPFLAGS += -I$(BLD_DIR) -DHAVE_CONFIG_H endif -CPPFLAGS += -I$(PROOT)/src -I$(PROOT)/include -RCFLAGS += -I$(PROOT)/include +CPPFLAGS += -Isrc -Iinclude +RCFLAGS += -Iinclude # examples, tests @@ -107,29 +105,29 @@ ifdef OPENSSL_PATH _LDFLAGS += -L"$(OPENSSL_LIBPATH)" OPENSSL_LIBS ?= -lssl -lcrypto _LIBS += $(OPENSSL_LIBS) - include $(PROOT)/Makefile.OpenSSL.inc + include Makefile.OpenSSL.inc else ifdef WOLFSSL_PATH CPPFLAGS += -DLIBSSH2_WOLFSSL CPPFLAGS += -I"$(WOLFSSL_PATH)/include" CPPFLAGS += -I"$(WOLFSSL_PATH)/include/wolfssl" _LDFLAGS += -L"$(WOLFSSL_PATH)/lib" _LIBS += -lwolfssl - include $(PROOT)/Makefile.wolfSSL.inc + include Makefile.wolfSSL.inc else ifdef LIBGCRYPT_PATH CPPFLAGS += -DLIBSSH2_LIBGCRYPT CPPFLAGS += -I"$(LIBGCRYPT_PATH)/include" _LDFLAGS += -L"$(LIBGCRYPT_PATH)/lib" _LIBS += -lgcrypt - include $(PROOT)/Makefile.libgcrypt.inc + include Makefile.libgcrypt.inc else ifdef MBEDTLS_PATH CPPFLAGS += -DLIBSSH2_MBEDTLS CPPFLAGS += -I"$(MBEDTLS_PATH)/include" _LDFLAGS += -L"$(MBEDTLS_PATH)/lib" _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto - include $(PROOT)/Makefile.mbedTLS.inc + include Makefile.mbedTLS.inc else ifdef WIN32 CPPFLAGS += -DLIBSSH2_WINCNG - include $(PROOT)/Makefile.WinCNG.inc + include Makefile.WinCNG.inc else $(error No suitable cryptography backend found) endif @@ -174,13 +172,13 @@ ZIP := zip -qzr9 # Include the version info retrieved from libssh2.h -include $(OBJ_DIR)/version.inc -vpath %.c $(PROOT)/src +vpath %.c src ifdef WIN32 -vpath %.rc $(PROOT)/src +vpath %.rc src endif # include Makefile.inc to get CSOURCES define -include $(PROOT)/Makefile.inc +include Makefile.inc OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(CSOURCES))) @@ -201,7 +199,7 @@ ifdef WIN32 LIBSSH2_LDFLAGS_DYN += -Wl,--output-def,$(libssh2_def_LIBRARY),--out-implib,$(libssh2_dyn_a_LIBRARY) endif -TARGETS_EXAMPLES := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard $(PROOT)/example/*.c))) +TARGETS_EXAMPLES := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard example/*.c))) all: lib dyn @@ -218,12 +216,12 @@ example: $(TARGETS_EXAMPLES) TARGETS_RUNNER := $(TARGET)-runner.a TARGETS_RUNNER_OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,runner.c session_fixture.c openssh_fixture.c)) -TARGETS_TESTS := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard $(PROOT)/tests/test_*.c))) +TARGETS_TESTS := $(patsubst %.c,%$(BIN_EXT),$(strip $(wildcard tests/test_*.c))) test: $(TARGETS_RUNNER) $(TARGETS_TESTS) $(TARGETS_RUNNER_OBJS): - $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $(patsubst $(OBJ_DIR)/%.o,$(PROOT)/tests/%.c,$@) -o $@ + $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $(patsubst $(OBJ_DIR)/%.o,tests/%.c,$@) -o $@ $(TARGETS_RUNNER): $(TARGETS_RUNNER_OBJS) @$(call DEL, $@) @@ -252,17 +250,17 @@ $(TARGET).a: $(OBJS) @$(call DEL, $@) $(AR) rcs $@ $^ -$(OBJ_DIR)/version.inc: $(PROOT)/get_ver.awk $(PROOT)/include/libssh2.h $(OBJ_DIR) +$(OBJ_DIR)/version.inc: get_ver.awk include/libssh2.h $(OBJ_DIR) $(AWK) -f $^ > $@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call MKDIR, $(DISTDIR)/bin) @$(call MKDIR, $(DISTDIR)/include) @$(call MKDIR, $(DISTDIR)/lib) - @$(call COPY, $(PROOT)/COPYING, $(DISTDIR)) - @$(call COPY, $(PROOT)/README, $(DISTDIR)) - @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) - @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) + @$(call COPY, COPYING, $(DISTDIR)) + @$(call COPY, README, $(DISTDIR)) + @$(call COPY, RELEASE-NOTES, $(DISTDIR)) + @$(call COPY, include/*.h, $(DISTDIR)/include) @$(call COPY, $(TARGET).a, $(DISTDIR)/lib) ifdef WIN32 @$(call COPY, $(libssh2_def_LIBRARY), $(DISTDIR)/bin) From dfb086bfe240fe2e7d93128e4de6b23fe160048a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 8 Apr 2023 10:55:23 +0000 Subject: [PATCH 242/424] tidy-up: indentation in guarded #includes [ci skip] --- example/scp.c | 10 +++++----- example/scp_nonblock.c | 12 ++++++------ example/scp_write.c | 10 +++++----- example/scp_write_nonblock.c | 12 ++++++------ example/sftp.c | 10 +++++----- example/sftp_RW_nonblock.c | 12 ++++++------ example/sftp_append.c | 8 ++++---- example/sftp_mkdir.c | 8 ++++---- example/sftp_mkdir_nonblock.c | 8 ++++---- example/sftp_nonblock.c | 12 ++++++------ example/sftp_write.c | 8 ++++---- example/sftp_write_nonblock.c | 12 ++++++------ example/sftp_write_sliding.c | 12 ++++++------ example/sftpdir.c | 10 +++++----- example/sftpdir_nonblock.c | 10 +++++----- example/ssh2.c | 8 ++++---- example/ssh2_agent.c | 8 ++++---- example/ssh2_agent_forwarding.c | 12 ++++++------ example/ssh2_echo.c | 10 +++++----- example/ssh2_exec.c | 10 +++++----- src/libssh2_priv.h | 10 +++++----- tests/ssh2.c | 8 ++++---- 22 files changed, 110 insertions(+), 110 deletions(-) diff --git a/example/scp.c b/example/scp.c index 999a960edd..6dec695a5f 100644 --- a/example/scp.c +++ b/example/scp.c @@ -9,19 +9,19 @@ # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 1160150e03..9ee48529c6 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -14,22 +14,22 @@ # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/scp_write.c b/example/scp_write.c index 581db95ad5..76bbabd39b 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -6,19 +6,19 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 742896bb42..50f9de5a73 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -6,22 +6,22 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/sftp.c b/example/sftp.c index 12073b70f5..2d2394fc35 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -15,19 +15,19 @@ # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 6d30ae7f4f..f6728b09ce 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -15,22 +15,22 @@ # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/sftp_append.c b/example/sftp_append.c index a24d053239..63d9e31d3f 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -12,16 +12,16 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #include diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 4838c1ef44..0ce3307b53 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -12,16 +12,16 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #include diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index 4563a153ac..68a46d9cf9 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -12,16 +12,16 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #include diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 760b78ba8f..658243b7f5 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -15,22 +15,22 @@ # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/sftp_write.c b/example/sftp_write.c index a241a42445..85823a2d67 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -12,16 +12,16 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #include diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index db57fd5f5b..b5219b597e 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -12,22 +12,22 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 2be99d29cf..8950979e73 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -12,22 +12,22 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include diff --git a/example/sftpdir.c b/example/sftpdir.c index 976ae818c4..5e2993f710 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -12,19 +12,19 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_INTTYPES_H -# include +#include #endif #include diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 779dd3d4af..1bb9eb4685 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -12,19 +12,19 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_INTTYPES_H -# include +#include #endif #include diff --git a/example/ssh2.c b/example/ssh2.c index b1e026f572..9accc3ec10 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -16,15 +16,15 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif -# ifdef HAVE_ARPA_INET_H +#ifdef HAVE_ARPA_INET_H #include #endif diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 2056ba6d93..5d7802da7c 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -11,15 +11,15 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif -# ifdef HAVE_ARPA_INET_H +#ifdef HAVE_ARPA_INET_H #include #endif diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 2e7f104a6a..5a482efdea 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -17,23 +17,23 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H -# include +#include #endif #include #include diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index 36651d7f59..f2b3085e24 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -12,19 +12,19 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H #include diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 9fc3dbce3b..e6a23307b5 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -14,19 +14,19 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_SYS_SELECT_H -# include +#include #endif #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #ifdef HAVE_SYS_TIME_H #include diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 6b048df2f5..22731ff1aa 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -62,10 +62,10 @@ #else # if defined(HAVE_SELECT) && !defined(WIN32) # ifdef HAVE_SYS_SELECT_H -# include +# include # else -# include -# include +# include +# include # endif # endif #endif @@ -76,10 +76,10 @@ #endif #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_SYS_IOCTL_H -# include +#include #endif #ifdef HAVE_INTTYPES_H #include diff --git a/tests/ssh2.c b/tests/ssh2.c index f912065135..098230df03 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -5,15 +5,15 @@ #include #ifdef HAVE_SYS_SOCKET_H -# include +#include #endif #ifdef HAVE_NETINET_IN_H -# include +#include #endif -# ifdef HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif -# ifdef HAVE_ARPA_INET_H +#ifdef HAVE_ARPA_INET_H #include #endif From 7e4855926ef0309212da01167980f3776d748bf2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 8 Apr 2023 22:25:46 +0000 Subject: [PATCH 243/424] tests/mansyntax.sh: avoid `if !` for portability Ref: https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Builtins.html#Limitations-of-Builtins Fixes #704 Closes #935 --- tests/mansyntax.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/mansyntax.sh b/tests/mansyntax.sh index 8c98fdf7cc..180140961b 100755 --- a/tests/mansyntax.sh +++ b/tests/mansyntax.sh @@ -10,28 +10,28 @@ srcdir="${srcdir:-$PWD}" dstdir="${builddir:-$PWD}" mandir="${srcdir}/../docs" +ec=0 + # # Only test if suitable man is available # -if ! man --help | grep -q warnings; then +if man --help | grep -q warnings; then + + trap 'rm -f "$dstdir/man3"' EXIT + + ln -sf "$mandir" "$dstdir/man3" + + for manpage in "$mandir"/libssh2_*.*; do + echo "$manpage" + warnings=$(LANG=en_US.UTF-8 MANWIDTH=80 man -M "$dstdir" --warnings \ + -E UTF-8 -l "$manpage" 2>&1 >/dev/null) + if [ -n "$warnings" ]; then + echo "$warnings" + ec=1 + fi + done +else echo "man version not suitable, skipping tests" - exit 0 fi -ec=0 - -trap 'rm -f "$dstdir/man3"' EXIT - -ln -sf "$mandir" "$dstdir/man3" - -for manpage in "$mandir"/libssh2_*.*; do - echo "$manpage" - warnings=$(LANG=en_US.UTF-8 MANWIDTH=80 man -M "$dstdir" --warnings \ - -E UTF-8 -l "$manpage" 2>&1 >/dev/null) - if [ -n "$warnings" ]; then - echo "$warnings" - ec=1 - fi -done - exit "$ec" From fb9f8883086ddf7249733d6ad8a2c31e07d912a5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 8 Apr 2023 22:26:10 +0000 Subject: [PATCH 244/424] tidy-up: example, tests - drop unnecessary `WIN32`-specific branches. - add `static`. - sync header inclusion order. - sync some common code between examples/tests. - fix formatting/indentation. - fix some `checksrc` errors not caught by `checksrc`. Closes #936 --- example/direct_tcpip.c | 58 ++++++-------- example/scp.c | 23 +++--- example/scp_nonblock.c | 23 +++--- example/scp_write.c | 17 ++-- example/scp_write_nonblock.c | 22 +++--- example/sftp.c | 32 ++++---- example/sftp_RW_nonblock.c | 21 +++-- example/sftp_append.c | 19 ++--- example/sftp_mkdir.c | 19 +++-- example/sftp_mkdir_nonblock.c | 19 +++-- example/sftp_nonblock.c | 25 +++--- example/sftp_write.c | 17 ++-- example/sftp_write_nonblock.c | 16 ++-- example/sftp_write_sliding.c | 27 +++---- example/sftpdir.c | 28 +++---- example/sftpdir_nonblock.c | 16 ++-- example/ssh2.c | 77 +++++++++---------- example/ssh2_agent.c | 30 ++++---- example/ssh2_agent_forwarding.c | 16 ++-- example/ssh2_echo.c | 26 +++---- example/ssh2_exec.c | 41 +++++----- example/subsystem_netconf.c | 42 +++++----- example/tcpip-forward.c | 52 ++++++------- example/x11.c | 36 ++++----- tests/openssh_fixture.c | 4 +- tests/simple.c | 4 +- tests/ssh2.c | 30 ++++---- ...t_keyboard_interactive_auth_info_request.c | 12 +-- 28 files changed, 343 insertions(+), 409 deletions(-) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index cf19fed396..baa55a72d0 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -10,6 +10,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_NETINET_IN_H #include #endif @@ -20,34 +26,28 @@ #include #endif +#include #include #include #include #include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifndef INADDR_NONE -#define INADDR_NONE (in_addr_t)-1 +#define INADDR_NONE (in_addr_t)~0 #endif -const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; -const char *keyfile2 = "/home/username/.ssh/id_rsa"; -const char *username = "username"; -const char *password = ""; +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = ""; -const char *server_ip = "127.0.0.1"; +static const char *server_ip = "127.0.0.1"; -const char *local_listenip = "127.0.0.1"; -unsigned int local_listenport = 2222; +static const char *local_listenip = "127.0.0.1"; +static unsigned int local_listenport = 2222; -const char *remote_desthost = "localhost"; /* resolved by the server */ -unsigned int remote_destport = 22; +static const char *remote_desthost = "localhost"; /* resolved by the server */ +static unsigned int remote_destport = 22; enum { AUTH_NONE = 0, @@ -112,24 +112,19 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock == LIBSSH2_INVALID_SOCKET) { -#ifdef WIN32 fprintf(stderr, "failed to open socket!\n"); -#else - perror("socket"); -#endif return -1; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); if(INADDR_NONE == sin.sin_addr.s_addr) { - perror("inet_addr"); + fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip); return -1; } sin.sin_port = htons(22); - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { - fprintf(stderr, "failed to connect!\n"); + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { + fprintf(stderr, "Failed to connect to %s!\n", inet_ntoa(sin.sin_addr)); return -1; } @@ -184,8 +179,9 @@ int main(int argc, char *argv[]) } } else if(auth & AUTH_PUBLICKEY) { - if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, - keyfile2, password)) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { fprintf(stderr, "\tAuthentication by public key failed!\n"); goto shutdown; } @@ -198,11 +194,7 @@ int main(int argc, char *argv[]) listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(listensock == LIBSSH2_INVALID_SOCKET) { -#ifdef WIN32 fprintf(stderr, "failed to open listen socket!\n"); -#else - perror("socket"); -#endif return -1; } @@ -231,11 +223,7 @@ int main(int argc, char *argv[]) forwardsock = accept(listensock, (struct sockaddr *)&sin, &sinlen); if(forwardsock == LIBSSH2_INVALID_SOCKET) { -#ifdef WIN32 fprintf(stderr, "failed to accept forward socket!\n"); -#else - perror("accept"); -#endif goto shutdown; } diff --git a/example/scp.c b/example/scp.c index 6dec695a5f..7a917ba862 100644 --- a/example/scp.c +++ b/example/scp.c @@ -6,17 +6,18 @@ #include #ifdef WIN32 -# define write(f, b, c) write((f), (b), (unsigned int)(c)) +#define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif + #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -39,6 +40,8 @@ int main(int argc, char *argv[]) const char *fingerprint; LIBSSH2_SESSION *session; LIBSSH2_CHANNEL *channel; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *scppath = "/tmp/TEST"; @@ -88,8 +91,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -130,10 +132,8 @@ int main(int argc, char *argv[]) } else { /* Or by public key */ -#define HOME_DIR "/home/username/" if(libssh2_userauth_publickey_fromfile(session, username, - HOME_DIR ".ssh/id_rsa.pub", - HOME_DIR ".ssh/id_rsa", + pubkey, privkey, password)) { fprintf(stderr, "\tAuthentication by public key failed\n"); goto shutdown; @@ -174,10 +174,9 @@ int main(int argc, char *argv[]) libssh2_channel_free(channel); channel = NULL; - shutdown: +shutdown: - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 9ee48529c6..ea07f32083 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -11,20 +11,21 @@ #include #ifdef WIN32 -# define write(f, b, c) write((f), (b), (unsigned int)(c)) +#define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif + #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -42,8 +43,8 @@ /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) { - return (newer.tv_sec-older.tv_sec)*1000+ - (newer.tv_usec-older.tv_usec)/1000; + return (newer.tv_sec-older.tv_sec)*1000+ + (newer.tv_usec-older.tv_usec)/1000; } #endif @@ -86,6 +87,8 @@ int main(int argc, char *argv[]) const char *fingerprint; LIBSSH2_SESSION *session; LIBSSH2_CHANNEL *channel; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *scppath = "/tmp/TEST"; @@ -193,10 +196,7 @@ int main(int argc, char *argv[]) else { /* Or by public key */ while((rc = libssh2_userauth_publickey_fromfile(session, username, - "/home/username/" - ".ssh/id_rsa.pub", - "/home/username/" - ".ssh/id_rsa", + pubkey, privkey, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -277,8 +277,7 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/scp_write.c b/example/scp_write.c index 76bbabd39b..e95c0bb666 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -8,12 +8,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -36,6 +36,8 @@ int main(int argc, char *argv[]) const char *fingerprint; LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *loclfile = "scp_write.c"; @@ -104,8 +106,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -146,10 +147,8 @@ int main(int argc, char *argv[]) } else { /* Or by public key */ -#define HOME "/home/username/" if(libssh2_userauth_publickey_fromfile(session, username, - HOME ".ssh/id_rsa.pub", - HOME ".ssh/id_rsa", + pubkey, privkey, password)) { fprintf(stderr, "\tAuthentication by public key failed\n"); goto shutdown; @@ -206,7 +205,7 @@ int main(int argc, char *argv[]) libssh2_channel_free(channel); channel = NULL; - shutdown: +shutdown: if(session) { libssh2_session_disconnect(session, "Normal Shutdown"); diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 50f9de5a73..372e461f36 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -8,15 +8,15 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -70,6 +70,8 @@ int main(int argc, char *argv[]) const char *fingerprint; LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *loclfile = "scp_write.c"; @@ -138,8 +140,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -186,10 +187,8 @@ int main(int argc, char *argv[]) } else { /* Or by public key */ -#define HOME "/home/username/" while((rc = libssh2_userauth_publickey_fromfile(session, username, - HOME ".ssh/id_rsa.pub", - HOME ".ssh/id_rsa", + pubkey, privkey, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -265,11 +264,10 @@ int main(int argc, char *argv[]) libssh2_channel_free(channel); channel = NULL; - shutdown: +shutdown: - while(libssh2_session_disconnect(session, - "Normal Shutdown,") == - LIBSSH2_ERROR_EAGAIN); + while(libssh2_session_disconnect(session, "Normal Shutdown") + == LIBSSH2_ERROR_EAGAIN); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/sftp.c b/example/sftp.c index 2d2394fc35..c3bf835fca 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -12,17 +12,18 @@ #include #ifdef WIN32 -# define write(f, b, c) write((f), (b), (unsigned int)(c)) +#define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif + #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -36,12 +37,11 @@ #include #include -const char *keyfile1 = "~/.ssh/id_rsa.pub"; -const char *keyfile2 = "~/.ssh/id_rsa"; -const char *username = "username"; -const char *password = "password"; -const char *sftppath = "/tmp/TEST"; - +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *sftppath = "/tmp/TEST"; static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, @@ -91,7 +91,6 @@ static void kbd_callback(const char *name, int name_len, "Done. Sending keyboard-interactive responses to server now.\n"); } - int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -122,7 +121,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -148,8 +146,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -233,8 +230,9 @@ int main(int argc, char *argv[]) } else if(auth_pw & 4) { /* Or by public key */ - if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, - keyfile2, password)) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { fprintf(stderr, "\tAuthentication by public key failed!\n"); goto shutdown; } @@ -284,7 +282,7 @@ int main(int argc, char *argv[]) libssh2_sftp_close(sftp_handle); libssh2_sftp_shutdown(sftp_session); - shutdown: +shutdown: libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index f6728b09ce..829145481d 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -12,20 +12,21 @@ #include #ifdef WIN32 -# define write(f, b, c) write((f), (b), (unsigned int)(c)) +#define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif + #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -80,6 +81,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *sftppath = "/tmp/TEST"; /* source path */ @@ -119,8 +122,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = htonl(0x7F000001); - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -186,10 +188,7 @@ int main(int argc, char *argv[]) /* Or by public key */ while((rc = libssh2_userauth_publickey_fromfile(session, username, - "/home/username/" - ".ssh/id_rsa.pub", - "/home/username/" - ".ssh/id_rsa", + pubkey, privkey, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -341,7 +340,7 @@ int main(int argc, char *argv[]) libssh2_sftp_shutdown(sftp_session); - shutdown: +shutdown: libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); diff --git a/example/sftp_append.c b/example/sftp_append.c index 63d9e31d3f..0684ce8950 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -14,12 +14,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -38,6 +38,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *loclfile = "sftp_write.c"; @@ -69,7 +71,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -104,8 +105,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -149,10 +149,8 @@ int main(int argc, char *argv[]) } else { /* Or by public key */ -#define HOME "/home/username/" if(libssh2_userauth_publickey_fromfile(session, username, - HOME ".ssh/id_rsa.pub", - HOME ".ssh/id_rsa", + pubkey, privkey, password)) { fprintf(stderr, "\tAuthentication by public key failed\n"); goto shutdown; @@ -218,8 +216,7 @@ int main(int argc, char *argv[]) libssh2_sftp_shutdown(sftp_session); shutdown: - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 0ce3307b53..ab3a56c6ed 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -14,12 +14,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -38,6 +38,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *sftppath = "/tmp/sftp_mkdir"; @@ -61,7 +63,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -87,8 +88,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -130,9 +130,8 @@ int main(int argc, char *argv[]) else { /* Or by public key */ if(libssh2_userauth_publickey_fromfile(session, username, - "/home/username/.ssh/id_rsa.pub", - "/home/username/.ssh/id_rsa", - password)) { + pubkey, privkey, + password)) { fprintf(stderr, "\tAuthentication by public key failed\n"); goto shutdown; } @@ -159,7 +158,7 @@ int main(int argc, char *argv[]) libssh2_sftp_shutdown(sftp_session); - shutdown: +shutdown: libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index 68a46d9cf9..6d636cb07e 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -14,12 +14,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -38,6 +38,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *sftppath = "/tmp/sftp_mkdir_nonblock"; @@ -61,7 +63,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -87,8 +88,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -130,9 +130,8 @@ int main(int argc, char *argv[]) else { /* Or by public key */ if(libssh2_userauth_publickey_fromfile(session, username, - "/home/username/.ssh/id_rsa.pub", - "/home/username/.ssh/id_rsa", - password)) { + pubkey, privkey, + password)) { fprintf(stderr, "\tAuthentication by public key failed\n"); goto shutdown; } @@ -159,7 +158,7 @@ int main(int argc, char *argv[]) libssh2_sftp_shutdown(sftp_session); - shutdown: +shutdown: libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 658243b7f5..4fcdaa18f7 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -12,20 +12,21 @@ #include #ifdef WIN32 -# define write(f, b, c) write((f), (b), (unsigned int)(c)) +#define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif + #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -86,6 +87,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *sftppath = "/tmp/TEST"; @@ -117,7 +120,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -143,8 +145,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -196,10 +197,7 @@ int main(int argc, char *argv[]) /* Or by public key */ while((rc = libssh2_userauth_publickey_fromfile(session, username, - "/home/username/" - ".ssh/id_rsa.pub", - "/home/username/" - ".ssh/id_rsa", + pubkey, privkey, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -281,9 +279,8 @@ int main(int argc, char *argv[]) shutdown: fprintf(stderr, "libssh2_session_disconnect\n"); - while(libssh2_session_disconnect(session, - "Normal Shutdown, Thank you") == - LIBSSH2_ERROR_EAGAIN); + while(libssh2_session_disconnect(session, "Normal Shutdown") + == LIBSSH2_ERROR_EAGAIN); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/sftp_write.c b/example/sftp_write.c index 85823a2d67..dba15e658a 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -14,12 +14,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -38,6 +38,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *loclfile = "sftp_write.c"; @@ -68,7 +70,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -103,8 +104,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -148,8 +148,6 @@ int main(int argc, char *argv[]) } else { /* Or by public key */ - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa.pub"; if(libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { @@ -202,8 +200,7 @@ int main(int argc, char *argv[]) libssh2_sftp_shutdown(sftp_session); shutdown: - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index b5219b597e..793434369f 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -14,15 +14,15 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -75,6 +75,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *loclfile = "sftp_write_nonblock.c"; @@ -108,7 +110,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -143,8 +144,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -191,8 +191,6 @@ int main(int argc, char *argv[]) } else { /* Or by public key */ - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; while((rc = libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) == @@ -270,7 +268,7 @@ int main(int argc, char *argv[]) shutdown: while(libssh2_session_disconnect(session, "Normal Shutdown") - == LIBSSH2_ERROR_EAGAIN); + == LIBSSH2_ERROR_EAGAIN); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 8950979e73..1e8ffbefaf 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -14,15 +14,15 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -75,6 +75,8 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *loclfile = "sftp_write_nonblock.c"; @@ -108,7 +110,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -143,14 +144,13 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } /* Create a session instance - */ + */ session = libssh2_session_init(); if(!session) return -1; @@ -168,10 +168,10 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we have not yet authenticated. The first thing to do is - * check the hostkey's fingerprint against our known hosts Your app may - * have it hard coded, may go to a file, may present it to the user, - * that's your call + /* At this point we have not yet authenticated. The first thing to do + * is check the hostkey's fingerprint against our known hosts Your app + * may have it hard coded, may go to a file, may present it to the + * user, that's your call */ fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); fprintf(stderr, "Fingerprint: "); @@ -191,10 +191,8 @@ int main(int argc, char *argv[]) } else { /* Or by public key */ -#define PUBKEY "/home/username/.ssh/id_rsa.pub" -#define PRIVKEY "/home/username/.ssh/id_rsa" while((rc = libssh2_userauth_publickey_fromfile(session, username, - PUBKEY, PRIVKEY, + pubkey, privkey, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { @@ -223,7 +221,6 @@ int main(int argc, char *argv[]) LIBSSH2_FXF_TRUNC, LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); - if(!sftp_handle && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { fprintf(stderr, "Unable to open file with SFTP\n"); diff --git a/example/sftpdir.c b/example/sftpdir.c index 5e2993f710..94190cdf6e 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -14,12 +14,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -39,10 +39,10 @@ #define __FILESIZE "llu" #endif -const char *keyfile1 = "~/.ssh/id_rsa.pub"; -const char *keyfile2 = "~/.ssh/id_rsa"; -const char *username = "username"; -const char *password = "password"; +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, @@ -93,7 +93,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -119,8 +118,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -204,8 +202,9 @@ int main(int argc, char *argv[]) } else if(auth_pw & 4) { /* Or by public key */ - if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, - keyfile2, password)) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { fprintf(stderr, "\tAuthentication by public key failed!\n"); goto shutdown; } @@ -277,15 +276,16 @@ int main(int argc, char *argv[]) printf("%s\n", mem); } } - else + else { break; + } } while(1); libssh2_sftp_closedir(sftp_handle); libssh2_sftp_shutdown(sftp_session); - shutdown: +shutdown: libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 1bb9eb4685..cc8d888b57 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -14,12 +14,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -47,11 +47,11 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; LIBSSH2_SESSION *session; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; const char *username = "username"; const char *password = "password"; const char *sftppath = "/tmp/secretdir"; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; int rc; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; @@ -73,7 +73,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -99,8 +98,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -229,7 +227,7 @@ int main(int argc, char *argv[]) libssh2_sftp_closedir(sftp_handle); libssh2_sftp_shutdown(sftp_session); - shutdown: +shutdown: libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); diff --git a/example/ssh2.c b/example/ssh2.c index 9accc3ec10..a762d7056e 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -18,32 +18,31 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif -#include #include #include #include #include +#include #include #if defined(_MSC_VER) && _MSC_VER < 1900 #define snprintf _snprintf #endif -const char *keyfile1 = ".ssh/id_rsa.pub"; -const char *keyfile2 = ".ssh/id_rsa"; -const char *username = "username"; -const char *password = "password"; - +static const char *pubkey = ".ssh/id_rsa.pub"; +static const char *privkey = ".ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, @@ -62,8 +61,7 @@ static void kbd_callback(const char *name, int name_len, } (void)prompts; (void)abstract; -} /* kbd_callback */ - +} int main(int argc, char *argv[]) { @@ -92,7 +90,6 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } @@ -118,8 +115,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Connecting to %s:%d as user %s\n", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), username); - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -146,10 +142,10 @@ int main(int argc, char *argv[]) return -1; } - /* At this point we have not authenticated. The first thing to do is check - * the hostkey's fingerprint against our known hosts Your app may have it - * hard coded, may go to a file, may present it to the user, that's your - * call + /* At this point we have not yet authenticated. The first thing to do + * is check the hostkey's fingerprint against our known hosts Your app + * may have it hard coded, may go to a file, may present it to the + * user, that's your call */ fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); fprintf(stderr, "Fingerprint: "); @@ -215,8 +211,8 @@ int main(int argc, char *argv[]) char const *h = getenv("HOME"); if(!h || !*h) h = "."; - fn1sz = strlen(h) + strlen(keyfile1) + 2; - fn2sz = strlen(h) + strlen(keyfile2) + 2; + fn1sz = strlen(h) + strlen(pubkey) + 2; + fn2sz = strlen(h) + strlen(privkey) + 2; fn1 = malloc(fn1sz); fn2 = malloc(fn2sz); if(!fn1 || !fn2) { @@ -226,11 +222,12 @@ int main(int argc, char *argv[]) goto shutdown; } /* Using asprintf() here would be much cleaner, but less portable */ - snprintf(fn1, fn1sz, "%s/%s", h, keyfile1); - snprintf(fn2, fn2sz, "%s/%s", h, keyfile2); + snprintf(fn1, fn1sz, "%s/%s", h, pubkey); + snprintf(fn2, fn2sz, "%s/%s", h, privkey); - if(libssh2_userauth_publickey_fromfile(session, username, fn1, - fn2, password)) { + if(libssh2_userauth_publickey_fromfile(session, username, + fn1, fn2, + password)) { fprintf(stderr, "\tAuthentication by public key failed!\n"); free(fn2); free(fn1); @@ -284,18 +281,19 @@ int main(int argc, char *argv[]) } #endif -/* At this point the shell can be interacted with using - * libssh2_channel_read() - * libssh2_channel_read_stderr() - * libssh2_channel_write() - * libssh2_channel_write_stderr() - * - * Blocking mode may be (en|dis)abled with: libssh2_channel_set_blocking() - * If the server send EOF, libssh2_channel_eof() will return non-0 - * To send EOF to the server use: libssh2_channel_send_eof() - * A channel can be closed with: libssh2_channel_close() - * A channel can be freed with: libssh2_channel_free() - */ + /* At this point the shell can be interacted with using + * libssh2_channel_read() + * libssh2_channel_read_stderr() + * libssh2_channel_write() + * libssh2_channel_write_stderr() + * + * Blocking mode may be (en|dis)abled with: + * libssh2_channel_set_blocking() + * If the server send EOF, libssh2_channel_eof() will return non-0 + * To send EOF to the server use: libssh2_channel_send_eof() + * A channel can be closed with: libssh2_channel_close() + * A channel can be freed with: libssh2_channel_free() + */ /* Read and display all the data received on stdout (ignoring stderr) * until the channel closes. This will eventually block if the command @@ -331,10 +329,9 @@ int main(int argc, char *argv[]) * libssh2_channel_direct_tcpip() */ - shutdown: +shutdown: - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 @@ -342,7 +339,7 @@ int main(int argc, char *argv[]) #else close(sock); #endif - fprintf(stderr, "all done!\n"); + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 5d7802da7c..5e3a82f3cf 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -13,12 +13,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -27,10 +27,10 @@ #include #include #include -#include #include +#include -const char *username = "username"; +static const char *username = "username"; int main(int argc, char *argv[]) { @@ -86,8 +86,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); goto shutdown; } @@ -101,10 +100,10 @@ int main(int argc, char *argv[]) return 1; } - /* At this point we have not authenticated. The first thing to do is check - * the hostkey's fingerprint against our known hosts Your app may have it - * hard coded, may go to a file, may present it to the user, that's your - * call + /* At this point we have not yet authenticated. The first thing to do + * is check the hostkey's fingerprint against our known hosts Your app + * may have it hard coded, may go to a file, may present it to the + * user, that's your call */ fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); fprintf(stderr, "Fingerprint: "); @@ -208,7 +207,7 @@ int main(int argc, char *argv[]) * A channel can be freed with: libssh2_channel_free() */ - skip_shell: +skip_shell: if(channel) { libssh2_channel_free(channel); channel = NULL; @@ -220,7 +219,7 @@ int main(int argc, char *argv[]) * libssh2_channel_direct_tcpip() */ - shutdown: +shutdown: if(agent) { libssh2_agent_disconnect(agent); @@ -228,8 +227,7 @@ int main(int argc, char *argv[]) } if(session) { - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); } @@ -241,7 +239,7 @@ int main(int argc, char *argv[]) #endif } - fprintf(stderr, "all done!\n"); + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 5a482efdea..0a03113df2 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -19,27 +19,27 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif - #ifdef HAVE_SYS_TIME_H #include #endif + #include -#include #include #include #include +#include #include static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) @@ -122,8 +122,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -273,8 +272,7 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index f2b3085e24..e4972b8d01 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -14,26 +14,27 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif #ifdef HAVE_SYS_TIME_H #include #endif + #include -#include #include #include #include +#include #include static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) @@ -98,10 +99,9 @@ int main(int argc, char *argv[]) } #endif - if(argc > 1) - /* must be ip address only */ - hostname = argv[1]; - + if(argc > 1) { + hostname = argv[1]; /* must be ip address only */ + } if(argc > 2) { username = argv[2]; } @@ -126,8 +126,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -144,7 +143,7 @@ int main(int argc, char *argv[]) * and setup crypto, compression, and MAC layers */ while((rc = libssh2_session_handshake(session, sock)) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); return -1; @@ -233,7 +232,7 @@ int main(int argc, char *argv[]) for(i = 0; i < BUFSIZE; i++) buffer[i] = 'A'; - fds = malloc(sizeof (LIBSSH2_POLLFD)); + fds = malloc(sizeof(LIBSSH2_POLLFD)); if(!fds) { fprintf(stderr, "malloc failed\n"); exit(1); @@ -349,8 +348,7 @@ int main(int argc, char *argv[]) } } - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index e6a23307b5..1c4ea4b783 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -16,26 +16,27 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_SYS_SELECT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif #ifdef HAVE_SYS_TIME_H #include #endif + #include -#include #include #include #include +#include #include static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) @@ -72,8 +73,10 @@ int main(int argc, char *argv[]) { const char *hostname = "127.0.0.1"; const char *commandline = "uptime"; - const char *username = "user"; - const char *password = "password"; + const char *pubkey = "/home/username/.ssh/id_rsa.pub"; + const char *privkey = "/home/username/.ssh/id_rsa"; + const char *username = "user"; + const char *password = "password"; uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; @@ -99,10 +102,9 @@ int main(int argc, char *argv[]) } #endif - if(argc > 1) - /* must be ip address only */ - hostname = argv[1]; - + if(argc > 1) { + hostname = argv[1]; /* must be ip address only */ + } if(argc > 2) { username = argv[2]; } @@ -130,8 +132,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return -1; } @@ -148,7 +149,7 @@ int main(int argc, char *argv[]) * and setup crypto, compression, and MAC layers */ while((rc = libssh2_session_handshake(session, sock)) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); return -1; @@ -213,11 +214,8 @@ int main(int argc, char *argv[]) else { /* Or by public key */ while((rc = libssh2_userauth_publickey_fromfile(session, username, - "/home/user/" - ".ssh/id_rsa.pub", - "/home/user/" - ".ssh/id_rsa", - password)) == + pubkey, privkey, + password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "\tAuthentication by public key failed\n"); @@ -240,11 +238,11 @@ int main(int argc, char *argv[]) exit(1); } while((rc = libssh2_channel_exec(channel, commandline)) == - LIBSSH2_ERROR_EAGAIN) { + LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } if(rc != 0) { - fprintf(stderr, "Error\n"); + fprintf(stderr, "exec error\n"); exit(1); } for(;;) { @@ -299,8 +297,7 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, - "Normal Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); #ifdef WIN32 diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index 2101cedc97..fef9f926e7 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -4,6 +4,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_NETINET_IN_H #include #endif @@ -14,18 +20,12 @@ #include #endif +#include #include #include #include -#include #include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_SYS_SELECT_H -#include -#endif +#include #ifndef INADDR_NONE #define INADDR_NONE (in_addr_t)~0 @@ -35,12 +35,12 @@ #define snprintf _snprintf #endif -const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; -const char *keyfile2 = "/home/username/.ssh/id_rsa"; -const char *username = "username"; -const char *password = ""; +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = ""; -const char *server_ip = "127.0.0.1"; +static const char *server_ip = "127.0.0.1"; enum { AUTH_NONE = 0, @@ -147,11 +147,7 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock == LIBSSH2_INVALID_SOCKET) { -#ifdef WIN32 fprintf(stderr, "failed to open socket!\n"); -#else - perror("socket"); -#endif return -1; } @@ -162,8 +158,7 @@ int main(int argc, char *argv[]) return -1; } sin.sin_port = htons(830); - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "Failed to connect to %s!\n", inet_ntoa(sin.sin_addr)); return -1; } @@ -219,12 +214,13 @@ int main(int argc, char *argv[]) } } else if(auth & AUTH_PUBLICKEY) { - if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, - keyfile2, password)) { - fprintf(stderr, "Authentication by public key failed!\n"); + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { + fprintf(stderr, "\tAuthentication by public key failed!\n"); goto shutdown; } - fprintf(stderr, "Authentication by public key succeeded.\n"); + fprintf(stderr, "\tAuthentication by public key succeeded.\n"); } else { fprintf(stderr, "No supported authentication methods found!\n"); diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 8dea412f1c..d802c58efd 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -10,6 +10,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_NETINET_IN_H #include #endif @@ -20,34 +26,30 @@ #include #endif +#include #include #include #include #include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifndef INADDR_NONE -#define INADDR_NONE (in_addr_t)-1 +#define INADDR_NONE (in_addr_t)~0 #endif -const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; -const char *keyfile2 = "/home/username/.ssh/id_rsa"; -const char *username = "username"; -const char *password = ""; +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = ""; -const char *server_ip = "127.0.0.1"; +static const char *server_ip = "127.0.0.1"; + +/* resolved by the server */ +static const char *remote_listenhost = "localhost"; -const char *remote_listenhost = "localhost"; /* resolved by the server */ int remote_wantport = 2222; int remote_listenport; -const char *local_destip = "127.0.0.1"; +static const char *local_destip = "127.0.0.1"; int local_destport = 22; enum { @@ -108,24 +110,19 @@ int main(int argc, char *argv[]) /* Connect to SSH server */ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock == LIBSSH2_INVALID_SOCKET) { -#ifdef WIN32 fprintf(stderr, "failed to open socket!\n"); -#else - perror("socket"); -#endif return -1; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); if(INADDR_NONE == sin.sin_addr.s_addr) { - perror("inet_addr"); + fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip); return -1; } sin.sin_port = htons(22); - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { - fprintf(stderr, "failed to connect!\n"); + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { + fprintf(stderr, "Failed to connect to %s!\n", inet_ntoa(sin.sin_addr)); return -1; } @@ -180,8 +177,9 @@ int main(int argc, char *argv[]) } } else if(auth & AUTH_PUBLICKEY) { - if(libssh2_userauth_publickey_fromfile(session, username, keyfile1, - keyfile2, password)) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { fprintf(stderr, "\tAuthentication by public key failed!\n"); goto shutdown; } @@ -221,11 +219,7 @@ int main(int argc, char *argv[]) local_destip, local_destport); forwardsock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(forwardsock == LIBSSH2_INVALID_SOCKET) { -#ifdef WIN32 fprintf(stderr, "failed to open forward socket!\n"); -#else - perror("socket"); -#endif goto shutdown; } diff --git a/example/x11.c b/example/x11.c index c8971252eb..e5c6815c76 100644 --- a/example/x11.c +++ b/example/x11.c @@ -12,7 +12,6 @@ #ifdef HAVE_SYS_UN_H -#include #ifdef HAVE_SYS_IOCTL_H #include #endif @@ -25,20 +24,22 @@ #ifdef HAVE_SYS_SELECT_H #include #endif -#ifdef HAVE_ARPA_INET_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif -#include +#ifdef HAVE_ARPA_INET_H +#include +#endif #ifdef HAVE_SYS_UN_H #include #endif + +#include #include #include -#include #include +#include +#include #include @@ -85,8 +86,7 @@ static void remove_node(struct chan_X11_list *elem) static void session_shutdown(LIBSSH2_SESSION *session) { - libssh2_session_disconnect(session, - "Session Shutdown, Thank you for playing"); + libssh2_session_disconnect(session, "Session Shutdown"); libssh2_session_free(session); } @@ -205,13 +205,12 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) int bufsize = 8192; int rc = 0; int nfds = 1; - LIBSSH2_POLLFD *fds = NULL; + LIBSSH2_POLLFD *fds = NULL; fd_set set; struct timeval timeval_out; timeval_out.tv_sec = 0; timeval_out.tv_usec = 0; - FD_ZERO(&set); FD_SET(sock, &set); @@ -219,7 +218,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) if(!buf) return 0; - fds = malloc(sizeof (LIBSSH2_POLLFD)); + fds = malloc(sizeof(LIBSSH2_POLLFD)); if(!fds) { free(buf); return 0; @@ -266,7 +265,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) * Main, more than inspired by ssh2.c by Bagder */ int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { uint32_t hostaddr = 0; int rc = 0; @@ -295,7 +294,6 @@ main (int argc, char *argv[]) timeval_out.tv_sec = 0; timeval_out.tv_usec = 10; - if(argc > 3) { hostaddr = inet_addr(argv[1]); username = argv[2]; @@ -328,9 +326,7 @@ main (int argc, char *argv[]) sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; - rc = connect(sock, (struct sockaddr *) &sin, - sizeof(struct sockaddr_in)); - if(rc != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "Failed to established connection!\n"); return -1; } @@ -371,7 +367,6 @@ main (int argc, char *argv[]) return -1; } - /* Request a PTY */ rc = libssh2_channel_request_pty(channel, "xterm"); if(rc != 0) { @@ -430,7 +425,7 @@ main (int argc, char *argv[]) if(buf == NULL) break; - fds = malloc(sizeof (LIBSSH2_POLLFD)); + fds = malloc(sizeof(LIBSSH2_POLLFD)); if(fds == NULL) { free(buf); break; @@ -468,7 +463,6 @@ main (int argc, char *argv[]) current_node = next_node; } - rc = select((int)(fileno(stdin) + 1), &set, NULL, NULL, &timeval_out); if(rc > 0) { ssize_t nread; @@ -482,7 +476,7 @@ main (int argc, char *argv[]) free(fds); free(buf); - if(libssh2_channel_eof (channel) == 1) { + if(libssh2_channel_eof(channel) == 1) { break; } } @@ -501,7 +495,7 @@ main (int argc, char *argv[]) #else int -main (void) +main(void) { printf("Sorry, this platform is not supported."); return 1; diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 75a40ab1d2..afbbdaa479 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -389,8 +389,8 @@ static libssh2_socket_t open_socket_to_container(char *container_id) sin.sin_addr.s_addr = hostaddr; for(counter = 0; counter < 3; ++counter) { - if(connect(sock, (struct sockaddr *)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), + sizeof(struct sockaddr_in))) { fprintf(stderr, "Connection to %s:%s attempt #%d failed: retrying...\n", ip_address, port_string, counter); diff --git a/tests/simple.c b/tests/simple.c index e97f7d3398..450fd56886 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -36,11 +36,11 @@ * OF SUCH DAMAGE. */ +#include + #include #include -#include "libssh2.h" - static int test_libssh2_base64_decode(LIBSSH2_SESSION *session) { char *data; diff --git a/tests/ssh2.c b/tests/ssh2.c index 098230df03..84b95ca739 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -1,4 +1,4 @@ -/* Self test, based on examples/ssh2.c. */ +/* Self test, based on example/ssh2.c. */ #include "libssh2_setup.h" #include @@ -7,12 +7,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_NETINET_IN_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETINET_IN_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif @@ -34,8 +34,8 @@ int main(int argc, char *argv[]) char *userauthlist; LIBSSH2_SESSION *session; LIBSSH2_CHANNEL *channel; - const char *pubkeyfile = "etc/user.pub"; - const char *privkeyfile = "etc/user"; + const char *pubkey = "etc/user.pub"; + const char *privkey = "etc/user"; const char *username = "username"; const char *password = "password"; int ec = 1; @@ -57,11 +57,11 @@ int main(int argc, char *argv[]) if(getenv("USER")) username = getenv("USER"); - if(getenv ("PRIVKEY")) - privkeyfile = getenv("PRIVKEY"); + if(getenv("PRIVKEY")) + privkey = getenv("PRIVKEY"); if(getenv("PUBKEY")) - pubkeyfile = getenv("PUBKEY"); + pubkey = getenv("PUBKEY"); hostaddr = htonl(0x7F000001); @@ -72,8 +72,7 @@ int main(int argc, char *argv[]) sin.sin_family = AF_INET; sin.sin_port = htons(4711); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), - sizeof(struct sockaddr_in)) != 0) { + if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); return 1; } @@ -117,8 +116,9 @@ int main(int argc, char *argv[]) if(auth_pw & 4) { /* Authenticate by public key */ - if(libssh2_userauth_publickey_fromfile(session, username, pubkeyfile, - privkeyfile, password)) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { printf("\tAuthentication by public key failed!\n"); goto shutdown; } @@ -159,13 +159,13 @@ int main(int argc, char *argv[]) ec = 0; - skip_shell: +skip_shell: if(channel) { libssh2_channel_free(channel); channel = NULL; } - shutdown: +shutdown: libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index d30c0cfcab..8fbdc2f23d 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -221,7 +221,7 @@ LIBSSH2_ALLOC_FUNC(test_alloc) { int *threshold_int_ptr = *abstract; alloc_count++; - if (*abstract != NULL && *threshold_int_ptr == alloc_count) { + if(*abstract != NULL && *threshold_int_ptr == alloc_count) { return NULL; } @@ -233,7 +233,7 @@ LIBSSH2_ALLOC_FUNC(test_alloc) static LIBSSH2_FREE_FUNC(test_free) { - (void) abstract; + (void)abstract; free_count++; free(ptr); } @@ -307,10 +307,10 @@ int main(void) int tc = i + TEST_CASES_LEN + 1; int malloc_call_num = 5 + i; test_case(tc, - failed_malloc_test_cases[i].data, - failed_malloc_test_cases[i].data_len, - &malloc_call_num, - failed_malloc_test_cases[i].expected); + failed_malloc_test_cases[i].data, + failed_malloc_test_cases[i].data_len, + &malloc_call_num, + failed_malloc_test_cases[i].expected); } return 0; From 279dd47247cbc1d8120cf8fd3e3d738f7338f962 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 8 Apr 2023 22:26:25 +0000 Subject: [PATCH 245/424] libssh2.rc: fix debug flag, other cleanups - fix to use `LIBSSH2DEBUG` macro to set the debug flag. (was `DEBUGBUILD`, a curl-specific macro) - use manifest constants instead of literals - change language to neutral Closes #937 --- src/libssh2.rc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libssh2.rc b/src/libssh2.rc index 5358942f84..0843c0144d 100644 --- a/src/libssh2.rc +++ b/src/libssh2.rc @@ -4,22 +4,22 @@ #include #include "libssh2.h" -LANGUAGE 0x09,0x01 +LANGUAGE 0, 0 #define RC_VERSION LIBSSH2_VERSION_MAJOR, LIBSSH2_VERSION_MINOR, LIBSSH2_VERSION_PATCH, 0 VS_VERSION_INFO VERSIONINFO FILEVERSION RC_VERSION PRODUCTVERSION RC_VERSION - FILEFLAGSMASK 0x3fL -#if defined(DEBUGBUILD) || defined(_DEBUG) - FILEFLAGS 1 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#if defined(LIBSSH2DEBUG) || defined(_DEBUG) + FILEFLAGS VS_FF_DEBUG #else FILEFLAGS 0 #endif FILEOS VOS__WINDOWS32 FILETYPE VFT_DLL - FILESUBTYPE 0x0L + FILESUBTYPE 0 BEGIN BLOCK "StringFileInfo" From ff3c774e03585252b70a9ee0fcf254de7b14a767 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 8 Apr 2023 22:26:47 +0000 Subject: [PATCH 246/424] blowfish: build improvements - include `blowfish.c` into `bcrypt_pbkdf.c`, instead of compiling it as a distinct object. - make low-level blowfish functions static. This prevents this symbols to pollute the public namespace of libssh2. It also allows the compiler to inline these functions. - integrate `blf.h` header into `bcrypt_pbkdf.c` as well. - use `_DEBUG_BLOWFISH` instead of `#if 0`. - fix `_DEBUG_BLOWFISH` compiler warnings and other nits. - `#undef` `inline` before redefining it in `libssh2_priv.h`. (copied from `blowfish.c`) - delete unused `inline` redefinitions from `blowfish.c`. - disable unused low-level blowfish functions. - formatting, header order. Closes #938 --- Makefile.inc | 4 +- src/CMakeLists.txt | 2 - src/bcrypt_pbkdf.c | 2 +- src/blf.h | 81 ----------------------------- src/blowfish.c | 127 +++++++++++++++++++++++++++++++-------------- src/libssh2_priv.h | 2 + 6 files changed, 93 insertions(+), 125 deletions(-) delete mode 100644 src/blf.h diff --git a/Makefile.inc b/Makefile.inc index e3c1f0cc52..1f23e66f9e 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -2,8 +2,8 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ userauth_kbd_packet.c \ version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ - blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c + bcrypt_pbkdf.c agent_win.c os400qc3.c HHEADERS = libssh2_priv.h libssh2_setup.h $(CRYPTO_HHEADERS) transport.h \ channel.h comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h \ - blf.h agent.h userauth_kbd_packet.h os400qc3.h + agent.h userauth_kbd_packet.h os400qc3.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 44d650c2d5..c59e9c76c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,9 +108,7 @@ set(SOURCES ${CRYPTO_SOURCES} agent.c agent_win.c - blf.h bcrypt_pbkdf.c - blowfish.c channel.c channel.h comp.c diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 73a46c7a04..bfbc69e420 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -25,7 +25,7 @@ #include #endif -#include "blf.h" +#include "blowfish.c" #define MINIMUM(a,b) (((a) < (b)) ? (a) : (b)) diff --git a/src/blf.h b/src/blf.h deleted file mode 100644 index c694d31f2f..0000000000 --- a/src/blf.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef __LIBSSH2_BLF_H -#define __LIBSSH2_BLF_H -/* $OpenBSD: blf.h,v 1.7 2007/03/14 17:59:41 grunk Exp $ */ -/* - * Blowfish - a fast block cipher designed by Bruce Schneier - * - * Copyright 1997 Niels Provos - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H) - -/* Schneier specifies a maximum key length of 56 bytes. - * This ensures that every key bit affects every cipher - * bit. However, the subkeys can hold up to 72 bytes. - * Warning: For normal blowfish encryption only 56 bytes - * of the key affect all cipherbits. - */ - -#define BLF_N 16 /* Number of Subkeys */ -#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */ -#define BLF_MAXUTILIZED ((BLF_N + 2)*4) /* 576 bits */ - -/* Blowfish context */ -typedef struct BlowfishContext { - uint32_t S[4][256]; /* S-Boxes */ - uint32_t P[BLF_N + 2]; /* Subkeys */ -} blf_ctx; - -/* Raw access to customized Blowfish - * blf_key is just: - * Blowfish_initstate( state ) - * Blowfish_expand0state( state, key, keylen ) - */ - -void Blowfish_encipher(blf_ctx *, uint32_t *, uint32_t *); -void Blowfish_decipher(blf_ctx *, uint32_t *, uint32_t *); -void Blowfish_initstate(blf_ctx *); -void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t); -void Blowfish_expandstate -(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t); - -/* Standard Blowfish */ - -void blf_key(blf_ctx *, const uint8_t *, uint16_t); -void blf_enc(blf_ctx *, uint32_t *, uint16_t); -void blf_dec(blf_ctx *, uint32_t *, uint16_t); - -void blf_ecb_encrypt(blf_ctx *, uint8_t *, uint32_t); -void blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t); - -void blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t); -void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t); - -/* Converts uint8_t to uint32_t */ -uint32_t Blowfish_stream2word(const uint8_t *, uint16_t, uint16_t *); - -#endif /* !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H) */ -#endif /* __LIBSSH2_BLF_H */ diff --git a/src/blowfish.c b/src/blowfish.c index 870269ade5..12eaed0132 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -1,6 +1,7 @@ /* $OpenBSD: blowfish.c,v 1.18 2004/11/02 17:23:26 hshoexer Exp $ */ /* - * Blowfish block cipher for OpenBSD + * Blowfish for OpenBSD - a fast block cipher designed by Bruce Schneier + * * Copyright 1997 Niels Provos * All rights reserved. * @@ -36,40 +37,79 @@ * Bruce Schneier. */ - #if !defined(HAVE_BCRYPT_PBKDF) && (!defined(HAVE_BLOWFISH_INITSTATE) || \ !defined(HAVE_BLOWFISH_EXPAND0STATE) || \ !defined(HAVE_BLF_ENC)) -#if 0 -#include /* used for debugging */ +#ifdef _DEBUG_BLOWFISH +#include #include +#include #endif -#include +/* Schneier specifies a maximum key length of 56 bytes. + * This ensures that every key bit affects every cipher + * bit. However, the subkeys can hold up to 72 bytes. + * Warning: For normal blowfish encryption only 56 bytes + * of the key affect all cipherbits. + */ + +#define BLF_N 16 /* Number of Subkeys */ +#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */ +#define BLF_MAXUTILIZED ((BLF_N + 2)*4) /* 576 bits */ + +/* Blowfish context */ +typedef struct BlowfishContext { + uint32_t S[4][256]; /* S-Boxes */ + uint32_t P[BLF_N + 2]; /* Subkeys */ +} blf_ctx; + +/* Raw access to customized Blowfish + * blf_key is just: + * Blowfish_initstate( state ) + * Blowfish_expand0state( state, key, keylen ) + */ + +static void Blowfish_encipher(blf_ctx *, uint32_t *, uint32_t *); +#ifdef _DEBUG_BLOWFISH +static void Blowfish_decipher(blf_ctx *, uint32_t *, uint32_t *); +#endif +static void Blowfish_initstate(blf_ctx *); +static void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t); +static void Blowfish_expandstate +(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t); -#include "libssh2.h" -#include "blf.h" +/* Standard Blowfish */ -#undef inline -#ifdef __GNUC__ -#define inline __inline__ -#elif defined(_MSC_VER) -#define inline __inline -#else -#define inline +#ifdef _DEBUG_BLOWFISH +static void blf_key(blf_ctx *, const uint8_t *, uint16_t); +#endif +static void blf_enc(blf_ctx *, uint32_t *, uint16_t); +#ifdef _DEBUG_BLOWFISH +static void blf_dec(blf_ctx *, uint32_t *, uint16_t); #endif +#if 0 +static void blf_ecb_encrypt(blf_ctx *, uint8_t *, uint32_t); +static void blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t); + +static void blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t); +static void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t); +#endif + +/* Converts uint8_t to uint32_t */ +static uint32_t Blowfish_stream2word(const uint8_t *, uint16_t, uint16_t *); + /* Function for Feistel Networks */ -#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \ - + (s)[0x100 + (((x)>>16)&0xFF)]) \ - ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \ +#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \ + + (s)[0x100 + (((x)>>16)&0xFF)]) \ + ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \ + (s)[0x300 + ( (x) &0xFF)]) #define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n]) -void +static void Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr) { uint32_t Xl; @@ -94,7 +134,8 @@ Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr) *xr = Xl; } -void +#ifdef _DEBUG_BLOWFISH +static void Blowfish_decipher(blf_ctx *c, uint32_t *xl, uint32_t *xr) { uint32_t Xl; @@ -118,8 +159,9 @@ Blowfish_decipher(blf_ctx *c, uint32_t *xl, uint32_t *xr) *xl = Xr ^ p[0]; *xr = Xl; } +#endif -void +static void Blowfish_initstate(blf_ctx *c) { /* P-box and S-box tables initialized with digits of Pi */ @@ -398,7 +440,7 @@ Blowfish_initstate(blf_ctx *c) *c = initstate; } -uint32_t +static uint32_t Blowfish_stream2word(const uint8_t *data, uint16_t databytes, uint16_t *current) { @@ -419,7 +461,7 @@ Blowfish_stream2word(const uint8_t *data, uint16_t databytes, return temp; } -void +static void Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes) { int i; @@ -456,8 +498,7 @@ Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes) } } - -void +static void Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes, const uint8_t *key, uint16_t keybytes) { @@ -500,7 +541,8 @@ Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes, } -void +#ifdef _DEBUG_BLOWFISH +static void blf_key(blf_ctx *c, const uint8_t *k, uint16_t len) { /* Initialize S-boxes and subkeys with Pi */ @@ -509,8 +551,9 @@ blf_key(blf_ctx *c, const uint8_t *k, uint16_t len) /* Transform S-boxes and subkeys with key */ Blowfish_expand0state(c, k, len); } +#endif -void +static void blf_enc(blf_ctx *c, uint32_t *data, uint16_t blocks) { uint32_t *d; @@ -523,7 +566,8 @@ blf_enc(blf_ctx *c, uint32_t *data, uint16_t blocks) } } -void +#ifdef _DEBUG_BLOWFISH +static void blf_dec(blf_ctx *c, uint32_t *data, uint16_t blocks) { uint32_t *d; @@ -535,8 +579,10 @@ blf_dec(blf_ctx *c, uint32_t *data, uint16_t blocks) d += 2; } } +#endif -void +#if 0 +static void blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len) { uint32_t l, r; @@ -558,7 +604,7 @@ blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len) } } -void +static void blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len) { uint32_t l, r; @@ -580,7 +626,7 @@ blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len) } } -void +static void blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len) { uint32_t l, r; @@ -605,7 +651,7 @@ blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len) } } -void +static void blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len) { uint32_t l, r; @@ -645,20 +691,20 @@ blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len) for(j = 0; j < 8; j++) data[j] ^= iva[j]; } +#endif -#if 0 -void +#ifdef _DEBUG_BLOWFISH +static void report(uint32_t data[], uint16_t len) { - uint16_t i; + int i; for(i = 0; i < len; i += 2) - printf("Block %0hd: %08lx %08lx.\n", - i / 2, data[i], data[i + 1]); + printf("Block %d: 0x%08lx 0x%08lx.\n", + i / 2, (unsigned long)data[i], (unsigned long)data[i + 1]); } -void +int main(void) { - blf_ctx c; char key[] = "AAAAA"; char key2[] = "abcdefghijklmnopqrstuvwxyz"; @@ -681,12 +727,15 @@ main(void) report(data, 10); /* Second test */ - blf_key(&c, (uint8_t *) key2, strlen(key2)); + blf_key(&c, (uint8_t *) key2, (uint16_t)strlen(key2)); blf_enc(&c, data2, 1); printf("\nShould read as: 0x324ed0fe 0xf413a203.\n"); report(data2, 2); blf_dec(&c, data2, 1); + printf("\nShould read as: 0x424c4f57 0x46495348.\n"); report(data2, 2); + + return 0; } #endif diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 22731ff1aa..318167620e 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -120,8 +120,10 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...); /* "inline" keyword is valid only with C++ engine! */ #ifdef __GNUC__ +#undef inline #define inline __inline__ #elif defined(_MSC_VER) +#undef inline #define inline __inline #endif From c1ed4e99dfea636bdc22d90a09381c56f54c4dbb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 9 Apr 2023 10:13:09 +0000 Subject: [PATCH 247/424] build: make `windows.h` even leaner Disable GDI and NLS features in `windows.h`. libssh2 doesn't use these. Closes #940 --- src/libssh2_setup.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libssh2_setup.h b/src/libssh2_setup.h index ac769233fd..638e6c4aa2 100644 --- a/src/libssh2_setup.h +++ b/src/libssh2_setup.h @@ -55,6 +55,12 @@ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif +#ifndef NOGDI +#define NOGDI +#endif +#ifndef NONLS +#define NONLS +#endif #ifdef __MINGW32__ # ifdef __MINGW64_VERSION_MAJOR From 80175921638fa0a345237d23206a2ad1644cdd9b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 9 Apr 2023 10:13:43 +0000 Subject: [PATCH 248/424] cmake: add `HIDE_SYMBOLS` option & do symbol hiding on *nix - implement symbol hiding on non-Windows platforms. The essence of the detection logic was copied from: https://github.com/curl/curl/blob/dfabe8bca218d2524af052bd551aa87e13b8a10b/CMake/CurlSymbolHiding.cmake Then simplified and shortened. This method doesn't require a recent CMake version, nor an external, auto-generated C header. Move `configure_file()` after `set(LIBSSH2_API ...)`, for the config file to pick up `LIBSSH2_API`s value. Closes #602 - add CMake option `HIDE_SYMBOLS`. This setting means to hide non-public functions from the libssh2 dynamic library when set to `ON`. The default. When set to `OFF`, make all non-static/internal functions visible in the dynamic library. This setting requires `BUILD_SHARED_LIBS=ON`. - honor this setting on Windows. By setting the `LIBSSH2_EXPORTS` manual macro again, and stop recognizing the automatic CMake macro for this purpose: `libssh2_shared_EXPORT`. Closes #939 --- include/libssh2.h | 3 +-- src/CMakeLists.txt | 31 ++++++++++++++++++++++++++----- src/libssh2_config_cmake.h.in | 5 +++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index 2a859cb975..325631ed20 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -105,8 +105,7 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API # ifdef _LIBSSH2_WIN32 -# if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || \ - defined(_WINDLL) || defined(libssh2_shared_EXPORTS) +# if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || defined(_WINDLL) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) # else diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c59e9c76c1..ec556fc2fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,11 +88,6 @@ if(WIN32) list(APPEND PC_LIBS -lws2_32) endif() -add_definitions(-DHAVE_CONFIG_H) - -configure_file(libssh2_config_cmake.h.in - ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) - # to find generated header list(APPEND libssh2_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) @@ -179,8 +174,34 @@ if(BUILD_SHARED_LIBS) PUBLIC $ $/${CMAKE_INSTALL_INCLUDEDIR}>) + + # Symbol hiding + + option(HIDE_SYMBOLS "Set to ON to hide all libssh2 symbols that aren't officially external." ON) + mark_as_advanced(HIDE_SYMBOLS) + + if(HIDE_SYMBOLS) + target_compile_definitions(${LIB_SHARED} PRIVATE LIBSSH2_EXPORTS) + if(WIN32) + elseif((CMAKE_C_COMPILER_ID MATCHES "Clang") OR + (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0) OR + (CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)) + target_compile_options(${LIB_SHARED} PRIVATE -fvisibility=hidden) + set(LIBSSH2_API "__attribute__ ((__visibility__ (\"default\")))") + elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0) + target_compile_options(${LIB_SHARED} PRIVATE -xldscope=hidden) + set(LIBSSH2_API "__global") + endif() + endif() endif() +# Config file + +add_definitions(-DHAVE_CONFIG_H) + +configure_file(libssh2_config_cmake.h.in + ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) + ## Installation install(FILES diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index ccace6564b..89784b4ff0 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -72,3 +72,8 @@ #cmakedefine HAVE_IOCTLSOCKET_CASE #cmakedefine HAVE_SO_NONBLOCK #cmakedefine HAVE_DISABLED_NONBLOCKING + +/* attribute to export symbol */ +#if defined(LIBSSH2_EXPORTS) && defined(LIBSSH2_LIBRARY) +#cmakedefine LIBSSH2_API ${LIBSSH2_API} +#endif From e1e78e367023704060ada53256bcf57fd57f7a63 Mon Sep 17 00:00:00 2001 From: Zenju Date: Sun, 9 Apr 2023 12:15:44 +0200 Subject: [PATCH 249/424] sftp: always clear protocol error (#787) --- src/sftp.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index 1e890b791d..dd8ef7ec0c 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -250,6 +250,7 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data, case SSH_FXP_EXTENDED_REPLY: break; default: + sftp->last_errno = LIBSSH2_FX_OK; return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, "Out of sync with the world"); } @@ -1116,6 +1117,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, int open_file = (open_type == LIBSSH2_SFTP_OPENFILE)?1:0; if(sftp->open_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + /* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) + flags(4) */ sftp->open_packet_len = (uint32_t)(filename_len + 13 + @@ -1384,6 +1387,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, switch(sftp->read_state) { case libssh2_NB_state_idle: + sftp->last_errno = LIBSSH2_FX_OK; /* Some data may already have been read from the server in the previous call but didn't fit in the buffer at the time. If so, we @@ -1763,6 +1767,8 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, ssize_t retcode; if(sftp->readdir_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + if(handle->u.dir.names_left) { /* * A prior request returned more than one directory entry, @@ -2034,6 +2040,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, switch(sftp->write_state) { default: case libssh2_NB_state_idle: + sftp->last_errno = LIBSSH2_FX_OK; /* Number of bytes sent off that haven't been acked and therefore we will get passed in here again. @@ -2254,6 +2261,8 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle) uint32_t retcode; if(sftp->fsync_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Issuing fsync command")); s = packet = LIBSSH2_ALLOC(session, packet_len); @@ -2363,6 +2372,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, ssize_t rc; if(sftp->fstat_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Issuing %s command", setstat ? "set-stat" : "stat")); s = sftp->fstat_packet = LIBSSH2_ALLOC(session, packet_len); @@ -2585,6 +2596,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) int rc = 0; if(handle->close_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Closing handle")); s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len); if(!handle->close_packet) { @@ -2717,6 +2730,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, int rc; if(sftp->unlink_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename)); s = sftp->unlink_packet = LIBSSH2_ALLOC(session, packet_len); @@ -2825,12 +2840,14 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, unsigned char *data = NULL; ssize_t rc; - if(sftp->version < 2) { - return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Server does not support RENAME"); - } - if(sftp->rename_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + + if(sftp->version < 2) { + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Server does not support RENAME"); + } + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Renaming %s to %s", source_filename, dest_filename)); sftp->rename_s = sftp->rename_packet = @@ -2967,6 +2984,8 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) { SSH_FXP_EXTENDED_REPLY, SSH_FXP_STATUS }; if(sftp->fstatvfs_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Getting file system statistics")); s = packet = LIBSSH2_ALLOC(session, packet_len); @@ -3103,6 +3122,8 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, { SSH_FXP_EXTENDED_REPLY, SSH_FXP_STATUS }; if(sftp->statvfs_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Getting file system statistics of %s", path)); s = packet = LIBSSH2_ALLOC(session, packet_len); @@ -3247,6 +3268,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, packet_len = path_len + 13 + sftp_attrsize(attrs.flags); if(sftp->mkdir_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Creating directory %s with mode 0%lo", path, mode)); s = packet = LIBSSH2_ALLOC(session, packet_len); @@ -3355,6 +3378,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, int rc; if(sftp->rmdir_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Removing directory: %s", path)); s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len); @@ -3462,6 +3487,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, int rc; if(sftp->stat_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "%s %s", (stat_type == LIBSSH2_SFTP_SETSTAT) ? "Set-statting" : (stat_type == @@ -3600,12 +3627,15 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, { SSH_FXP_NAME, SSH_FXP_STATUS }; int retcode; - if((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) { - return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Server does not support SYMLINK or READLINK"); - } - if(sftp->symlink_state == libssh2_NB_state_idle) { + sftp->last_errno = LIBSSH2_FX_OK; + + if((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) { + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Server does not support SYMLINK or" + " READLINK"); + } + s = sftp->symlink_packet = LIBSSH2_ALLOC(session, packet_len); if(!sftp->symlink_packet) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, From 4f0f4bff5a92dce6a6cd7a5600a8ee5660402c3f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Apr 2023 09:20:13 +0000 Subject: [PATCH 250/424] build: unify source lists - introduce `src/crypto.c` as an umbrella source that does nothing else than include the selected crypto backend source. Moving this job from the built-tool to the C preprocessor. - this allows dropping the various techniques to pick the correct crypto backend sources in autotools, CMake and other build method. Including the per-backend `Makefile..inc` makefiles. - copy a trick from curl and instead of maintaining duplicate source lists for CMake, convert the GNU Makefile kept for autotools automatically. Do this in `docs`, `examples` and `src`. Ref: https://github.com/curl/curl/blob/dfabe8bca218d2524af052bd551aa87e13b8a10b/CMakeLists.txt#L1399-L1413 Also fixes missing `libssh2_setup.h` from `src/CMakeFiles.txt` after 59666e03f04927e5fe3e8d8772d40729f63c570e. - move `Makefile.inc` from root to `src`. - reformat `src/Makefile.inc` to list each source in separate lines, re-align the continuation character and sort the lists alphabetically. - update `docs/HACKING-CRYPTO` accordingly. - autotools: update the way we add crypto-backends to `LIBS`. - delete old CSV headers, indent, and merge two lines in `docs/Makefile.am` and `src/Makefile.am`. - add `libssh2.pc` to `.gitignore`, while there. Closes #941 --- CMakeLists.txt | 18 ++-- Makefile.OpenSSL.inc | 3 - Makefile.WinCNG.inc | 3 - Makefile.am | 3 +- Makefile.inc | 9 -- Makefile.libgcrypt.inc | 3 - Makefile.mbedTLS.inc | 3 - Makefile.mk | 9 +- Makefile.os400qc3.inc | 2 - Makefile.wolfSSL.inc | 3 - NMakefile | 4 +- configure.ac | 14 +++- docs/.gitignore | 1 + docs/CMakeLists.txt | 184 +---------------------------------------- docs/HACKING-CRYPTO | 20 +++-- docs/Makefile.am | 4 +- example/.gitignore | 1 + example/CMakeLists.txt | 29 +------ os400/make-src.sh | 4 +- src/.gitignore | 2 + src/CMakeLists.txt | 46 ++--------- src/Makefile.am | 27 +----- src/Makefile.inc | 46 +++++++++++ src/crypto.c | 13 +++ 24 files changed, 124 insertions(+), 327 deletions(-) delete mode 100644 Makefile.OpenSSL.inc delete mode 100644 Makefile.WinCNG.inc delete mode 100644 Makefile.inc delete mode 100644 Makefile.libgcrypt.inc delete mode 100644 Makefile.mbedTLS.inc delete mode 100644 Makefile.os400qc3.inc delete mode 100644 Makefile.wolfSSL.inc create mode 100644 src/Makefile.inc create mode 100644 src/crypto.c diff --git a/CMakeLists.txt b/CMakeLists.txt index bd51aa89e3..ad2dcf8fc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,7 +212,6 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) if(OPENSSL_FOUND) set(CRYPTO_BACKEND "OpenSSL") - set(CRYPTO_SOURCES openssl.c openssl.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL") set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) list(APPEND LIBRARIES ${OPENSSL_LIBRARIES}) @@ -274,7 +273,6 @@ if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND) if(WOLFSSL_FOUND) set(CRYPTO_BACKEND "wolfSSL") - set(CRYPTO_SOURCES openssl.c openssl.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WOLFSSL") set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl) list(APPEND LIBRARIES ${WOLFSSL_LIBRARIES}) @@ -302,7 +300,6 @@ if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND) if(LIBGCRYPT_FOUND) set(CRYPTO_BACKEND "Libgcrypt") - set(CRYPTO_SOURCES libgcrypt.c libgcrypt.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT") set(CRYPTO_BACKEND_INCLUDE_DIR ${LIBGCRYPT_INCLUDE_DIRS}) list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES}) @@ -316,7 +313,6 @@ if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND) if(MBEDTLS_FOUND) set(CRYPTO_BACKEND "mbedTLS") - set(CRYPTO_SOURCES mbedtls.c mbedtls.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS") set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR}) list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES}) @@ -335,7 +331,6 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) if(HAVE_BCRYPT_H) set(CRYPTO_BACKEND "WinCNG") - set(CRYPTO_SOURCES wincng.c wincng.h) set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG") set(CRYPTO_BACKEND_INCLUDE_DIR "") @@ -346,6 +341,19 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) endif() endif() +# Global functions + +# Convert GNU Make assignments into CMake ones. +function(transform_makefile_inc INPUT_FILE OUTPUT_FILE) + file(READ ${INPUT_FILE} MAKEFILE_INC_CMAKE) + + string(REGEX REPLACE "\\\\\n" "" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE}) + string(REGEX REPLACE "([A-Za-z_]+) *= *([^\n]*)" "set(\\1 \\2)" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE}) + + file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_CMAKE}) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}") +endfunction() + # add_subdirectory(src) diff --git a/Makefile.OpenSSL.inc b/Makefile.OpenSSL.inc deleted file mode 100644 index 1e4e8f0bbb..0000000000 --- a/Makefile.OpenSSL.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = openssl.c -CRYPTO_HHEADERS = openssl.h -CRYPTO_LTLIBS = $(LTLIBSSL) diff --git a/Makefile.WinCNG.inc b/Makefile.WinCNG.inc deleted file mode 100644 index 09e410964f..0000000000 --- a/Makefile.WinCNG.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = wincng.c -CRYPTO_HHEADERS = wincng.h -CRYPTO_LTLIBS = $(LTLIBBCRYPT) diff --git a/Makefile.am b/Makefile.am index 5caa05538b..abbefd5c66 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,8 +33,7 @@ OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ os400/libssh2rpg/libssh2.rpgle.in \ os400/libssh2rpg/libssh2_ccsid.rpgle.in \ os400/libssh2rpg/libssh2_publickey.rpgle \ - os400/libssh2rpg/libssh2_sftp.rpgle \ - Makefile.os400qc3.inc + os400/libssh2rpg/libssh2_sftp.rpgle EXTRA_DIST = $(WIN32FILES) get_ver.awk \ maketgz RELEASE-NOTES libssh2.pc.in $(VMSFILES) config.rpath \ diff --git a/Makefile.inc b/Makefile.inc deleted file mode 100644 index 1f23e66f9e..0000000000 --- a/Makefile.inc +++ /dev/null @@ -1,9 +0,0 @@ -CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ - packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ - userauth_kbd_packet.c \ - version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ - bcrypt_pbkdf.c agent_win.c os400qc3.c - -HHEADERS = libssh2_priv.h libssh2_setup.h $(CRYPTO_HHEADERS) transport.h \ - channel.h comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h \ - agent.h userauth_kbd_packet.h os400qc3.h diff --git a/Makefile.libgcrypt.inc b/Makefile.libgcrypt.inc deleted file mode 100644 index 0a3aae9aad..0000000000 --- a/Makefile.libgcrypt.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = libgcrypt.c -CRYPTO_HHEADERS = libgcrypt.h -CRYPTO_LTLIBS = $(LTLIBGCRYPT) diff --git a/Makefile.mbedTLS.inc b/Makefile.mbedTLS.inc deleted file mode 100644 index b9f19fce1a..0000000000 --- a/Makefile.mbedTLS.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = mbedtls.c -CRYPTO_HHEADERS = mbedtls.h -CRYPTO_LTLIBS = $(LTLIBMBEDCRYPTO) diff --git a/Makefile.mk b/Makefile.mk index 2cfd0a8df8..3ce5059ed0 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -105,29 +105,24 @@ ifdef OPENSSL_PATH _LDFLAGS += -L"$(OPENSSL_LIBPATH)" OPENSSL_LIBS ?= -lssl -lcrypto _LIBS += $(OPENSSL_LIBS) - include Makefile.OpenSSL.inc else ifdef WOLFSSL_PATH CPPFLAGS += -DLIBSSH2_WOLFSSL CPPFLAGS += -I"$(WOLFSSL_PATH)/include" CPPFLAGS += -I"$(WOLFSSL_PATH)/include/wolfssl" _LDFLAGS += -L"$(WOLFSSL_PATH)/lib" _LIBS += -lwolfssl - include Makefile.wolfSSL.inc else ifdef LIBGCRYPT_PATH CPPFLAGS += -DLIBSSH2_LIBGCRYPT CPPFLAGS += -I"$(LIBGCRYPT_PATH)/include" _LDFLAGS += -L"$(LIBGCRYPT_PATH)/lib" _LIBS += -lgcrypt - include Makefile.libgcrypt.inc else ifdef MBEDTLS_PATH CPPFLAGS += -DLIBSSH2_MBEDTLS CPPFLAGS += -I"$(MBEDTLS_PATH)/include" _LDFLAGS += -L"$(MBEDTLS_PATH)/lib" _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto - include Makefile.mbedTLS.inc else ifdef WIN32 CPPFLAGS += -DLIBSSH2_WINCNG - include Makefile.WinCNG.inc else $(error No suitable cryptography backend found) endif @@ -177,8 +172,8 @@ ifdef WIN32 vpath %.rc src endif -# include Makefile.inc to get CSOURCES define -include Makefile.inc +# Get CSOURCES define +include src/Makefile.inc OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(CSOURCES))) diff --git a/Makefile.os400qc3.inc b/Makefile.os400qc3.inc deleted file mode 100644 index e55094d9bd..0000000000 --- a/Makefile.os400qc3.inc +++ /dev/null @@ -1,2 +0,0 @@ -CRYPTO_CSOURCES = os400qc3.c -CRYPTO_HHEADERS = os400qc3.h diff --git a/Makefile.wolfSSL.inc b/Makefile.wolfSSL.inc deleted file mode 100644 index 24fed511f8..0000000000 --- a/Makefile.wolfSSL.inc +++ /dev/null @@ -1,3 +0,0 @@ -CRYPTO_CSOURCES = openssl.c -CRYPTO_HHEADERS = openssl.h -CRYPTO_LTLIBS = -lwolfssl diff --git a/NMakefile b/NMakefile index 19756816f1..a7be7c11a3 100644 --- a/NMakefile +++ b/NMakefile @@ -16,11 +16,9 @@ CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iinclude !if "$(OPENSSL_PATH)" != "" CFLAGS=$(CFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSL_PATH)\include LIBS=$(LIBS) $(OPENSSL_PATH)\lib\crypto.lib $(OPENSSL_PATH)\lib\ssl.lib -!include "Makefile.OpenSSL.inc" !else CFLAGS=$(CFLAGS) /DLIBSSH2_WINCNG LIBS=crypt32.lib bcrypt.lib -!include "Makefile.WinCNG.inc" !endif !if "$(ZLIB_PATH)" != "" @@ -34,7 +32,7 @@ INTDIR=$(TARGET) SUBDIR=src -!include "Makefile.inc" +!include "src/Makefile.inc" OBJECTS=$(CSOURCES:.c=.obj) diff --git a/configure.ac b/configure.ac index f5ae8571ec..742c9b0fe4 100644 --- a/configure.ac +++ b/configure.ac @@ -120,9 +120,17 @@ else test "$found_crypto_str" = "" && found_crypto_str="$found_crypto" fi -m4_set_foreach([crypto_backends], [backend], - [AM_CONDITIONAL(m4_toupper(backend), test "$found_crypto" = "backend")] -) +if test "$found_crypto" = "openssl"; then + LIBS="${LIBS} ${LTLIBSSL}" +elif test "$found_crypto" = "wolfssl"; then + LIBS="${LIBS} ${LTLIBWOLFSSL}" +elif test "$found_crypto" = "libgcrypt"; then + LIBS="${LIBS} ${LTLIBGCRYPT}" +elif test "$found_crypto" = "wincng"; then + LIBS="${LIBS} ${LTLIBBCRYPT}" +elif test "$found_crypto" = "mbedtls"; then + LIBS="${LIBS} ${LTLIBMBEDCRYPTO}" +fi # libz diff --git a/docs/.gitignore b/docs/.gitignore index 3aed763290..6fc54d7cf0 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,3 +1,4 @@ Makefile Makefile.in +Makefile.am.cmake coverage diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index cb11db6c95..d64dfe0651 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -33,185 +33,9 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -set(MAN_PAGES - libssh2_agent_connect.3 - libssh2_agent_disconnect.3 - libssh2_agent_free.3 - libssh2_agent_get_identity.3 - libssh2_agent_get_identity_path.3 - libssh2_agent_init.3 - libssh2_agent_list_identities.3 - libssh2_agent_set_identity_path.3 - libssh2_agent_userauth.3 - libssh2_banner_set.3 - libssh2_base64_decode.3 - libssh2_channel_close.3 - libssh2_channel_direct_tcpip.3 - libssh2_channel_direct_tcpip_ex.3 - libssh2_channel_eof.3 - libssh2_channel_exec.3 - libssh2_channel_flush.3 - libssh2_channel_flush_ex.3 - libssh2_channel_flush_stderr.3 - libssh2_channel_forward_accept.3 - libssh2_channel_forward_cancel.3 - libssh2_channel_forward_listen.3 - libssh2_channel_forward_listen_ex.3 - libssh2_channel_free.3 - libssh2_channel_get_exit_signal.3 - libssh2_channel_get_exit_status.3 - libssh2_channel_handle_extended_data.3 - libssh2_channel_handle_extended_data2.3 - libssh2_channel_ignore_extended_data.3 - libssh2_channel_open_ex.3 - libssh2_channel_open_session.3 - libssh2_channel_process_startup.3 - libssh2_channel_read.3 - libssh2_channel_read_ex.3 - libssh2_channel_read_stderr.3 - libssh2_channel_receive_window_adjust.3 - libssh2_channel_receive_window_adjust2.3 - libssh2_channel_request_auth_agent.3 - libssh2_channel_request_pty.3 - libssh2_channel_request_pty_ex.3 - libssh2_channel_request_pty_size.3 - libssh2_channel_request_pty_size_ex.3 - libssh2_channel_send_eof.3 - libssh2_channel_set_blocking.3 - libssh2_channel_setenv.3 - libssh2_channel_setenv_ex.3 - libssh2_channel_shell.3 - libssh2_channel_subsystem.3 - libssh2_channel_wait_closed.3 - libssh2_channel_wait_eof.3 - libssh2_channel_window_read.3 - libssh2_channel_window_read_ex.3 - libssh2_channel_window_write.3 - libssh2_channel_window_write_ex.3 - libssh2_channel_write.3 - libssh2_channel_write_ex.3 - libssh2_channel_write_stderr.3 - libssh2_channel_x11_req.3 - libssh2_channel_x11_req_ex.3 - libssh2_crypto_engine.3 - libssh2_exit.3 - libssh2_free.3 - libssh2_hostkey_hash.3 - libssh2_init.3 - libssh2_keepalive_config.3 - libssh2_keepalive_send.3 - libssh2_knownhost_add.3 - libssh2_knownhost_addc.3 - libssh2_knownhost_check.3 - libssh2_knownhost_checkp.3 - libssh2_knownhost_del.3 - libssh2_knownhost_free.3 - libssh2_knownhost_get.3 - libssh2_knownhost_init.3 - libssh2_knownhost_readfile.3 - libssh2_knownhost_readline.3 - libssh2_knownhost_writefile.3 - libssh2_knownhost_writeline.3 - libssh2_poll.3 - libssh2_poll_channel_read.3 - libssh2_publickey_add.3 - libssh2_publickey_add_ex.3 - libssh2_publickey_init.3 - libssh2_publickey_list_fetch.3 - libssh2_publickey_list_free.3 - libssh2_publickey_remove.3 - libssh2_publickey_remove_ex.3 - libssh2_publickey_shutdown.3 - libssh2_scp_recv.3 - libssh2_scp_recv2.3 - libssh2_scp_send.3 - libssh2_scp_send64.3 - libssh2_scp_send_ex.3 - libssh2_session_abstract.3 - libssh2_session_banner_get.3 - libssh2_session_banner_set.3 - libssh2_session_block_directions.3 - libssh2_session_callback_set.3 - libssh2_session_disconnect.3 - libssh2_session_disconnect_ex.3 - libssh2_session_flag.3 - libssh2_session_free.3 - libssh2_session_get_blocking.3 - libssh2_session_get_read_timeout.3 - libssh2_session_get_timeout.3 - libssh2_session_handshake.3 - libssh2_session_hostkey.3 - libssh2_session_init.3 - libssh2_session_init_ex.3 - libssh2_session_last_errno.3 - libssh2_session_last_error.3 - libssh2_session_method_pref.3 - libssh2_session_methods.3 - libssh2_session_set_blocking.3 - libssh2_session_set_last_error.3 - libssh2_session_set_read_timeout.3 - libssh2_session_set_timeout.3 - libssh2_session_startup.3 - libssh2_session_supported_algs.3 - libssh2_sftp_close.3 - libssh2_sftp_close_handle.3 - libssh2_sftp_closedir.3 - libssh2_sftp_fsetstat.3 - libssh2_sftp_fstat.3 - libssh2_sftp_fstat_ex.3 - libssh2_sftp_fstatvfs.3 - libssh2_sftp_fsync.3 - libssh2_sftp_get_channel.3 - libssh2_sftp_init.3 - libssh2_sftp_last_error.3 - libssh2_sftp_lstat.3 - libssh2_sftp_mkdir.3 - libssh2_sftp_mkdir_ex.3 - libssh2_sftp_open.3 - libssh2_sftp_open_ex.3 - libssh2_sftp_opendir.3 - libssh2_sftp_read.3 - libssh2_sftp_readdir.3 - libssh2_sftp_readdir_ex.3 - libssh2_sftp_readlink.3 - libssh2_sftp_realpath.3 - libssh2_sftp_rename.3 - libssh2_sftp_rename_ex.3 - libssh2_sftp_rewind.3 - libssh2_sftp_rmdir.3 - libssh2_sftp_rmdir_ex.3 - libssh2_sftp_seek.3 - libssh2_sftp_seek64.3 - libssh2_sftp_setstat.3 - libssh2_sftp_shutdown.3 - libssh2_sftp_stat.3 - libssh2_sftp_stat_ex.3 - libssh2_sftp_statvfs.3 - libssh2_sftp_symlink.3 - libssh2_sftp_symlink_ex.3 - libssh2_sftp_tell.3 - libssh2_sftp_tell64.3 - libssh2_sftp_unlink.3 - libssh2_sftp_unlink_ex.3 - libssh2_sftp_write.3 - libssh2_sign_sk.3 - libssh2_trace.3 - libssh2_trace_sethandler.3 - libssh2_userauth_authenticated.3 - libssh2_userauth_banner.3 - libssh2_userauth_hostbased_fromfile.3 - libssh2_userauth_hostbased_fromfile_ex.3 - libssh2_userauth_keyboard_interactive.3 - libssh2_userauth_keyboard_interactive_ex.3 - libssh2_userauth_list.3 - libssh2_userauth_password.3 - libssh2_userauth_password_ex.3 - libssh2_userauth_publickey.3 - libssh2_userauth_publickey_fromfile.3 - libssh2_userauth_publickey_fromfile_ex.3 - libssh2_userauth_publickey_frommemory.3 - libssh2_userauth_publickey_sk.3 - libssh2_version.3) +transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake") +# Get 'dist_man_MANS' variable +include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) include(GNUInstallDirs) -install(FILES ${MAN_PAGES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) +install(FILES ${dist_man_MANS} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index c41495240c..233cb32543 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -31,18 +31,20 @@ LIBSSH2_LIB_HAVE_LINKFLAGS from LIBSSH2_CRYPTO_CHECK, which automatically creates and handles a --with-$newname-prefix option and sets an LTLIBNEWNAME variable on success. -0.3) Create Makefile.newname.inc in the top-level directory +0.3) Add new header to src/Makefile.inc -This must set CRYPTO_CSOURCES, CRYPTO_HHEADERS and CRYPTO_LTLIBS. -Set CRYPTO_CSOURCES and CRYPTO_HHEADERS to the new backend source files -and set CRYPTO_LTLIBS to the required library linking parameters, e.g. -$(LTLIBNEWNAME) as generated by by LIBSSH2_LIB_HAVE_LINKFLAGS. +0.4) Include new source in src/crypto.c -0.4) Add a new block in src/Makefile.am +0.5) Add a new block in configure.ac -if NEWNAME -include ../Makefile.newname.inc -endif +``` +elif test "$found_crypto" = "newname"; then + LIBS="${LIBS} ${LTLIBNEWNAME}" +``` + +0.6) Add CMake detection logic to CMakeLists.txt + +0.7) Add manual config logic to Makefile.mk 1) Crypto library initialization/termination. diff --git a/docs/Makefile.am b/docs/Makefile.am index 5efd370e6e..b2f2e5c9b9 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,7 +1,5 @@ -# $Id: Makefile.am,v 1.37 2009/03/26 15:41:15 bagder Exp $ - EXTRA_DIST = template.3 BINDINGS INSTALL_AUTOTOOLS INSTALL_CMAKE.md HACKING TODO \ - AUTHORS CMakeLists.txt HACKING-CRYPTO SECURITY.md + AUTHORS CMakeLists.txt HACKING-CRYPTO SECURITY.md dist_man_MANS = \ libssh2_agent_connect.3 \ diff --git a/example/.gitignore b/example/.gitignore index 4d26823d30..f9603da0eb 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -2,6 +2,7 @@ .libs Makefile Makefile.in +Makefile.am.cmake *.gcno *.gcda stamp-h2 diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 72ca94895e..a8661e93c9 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -39,31 +39,10 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) -set(EXAMPLES - direct_tcpip - scp - scp_nonblock - scp_write - scp_write_nonblock - sftp - sftp_RW_nonblock - sftp_append - sftp_mkdir - sftp_mkdir_nonblock - sftp_nonblock - sftp_write - sftp_write_nonblock - sftp_write_sliding - sftpdir - sftpdir_nonblock - ssh2 - ssh2_agent - ssh2_agent_forwarding - ssh2_echo - ssh2_exec - subsystem_netconf - tcpip-forward - x11) +transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake") +# Get 'noinst_PROGRAMS' variable +include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) +set(EXAMPLES ${noinst_PROGRAMS}) foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) diff --git a/os400/make-src.sh b/os400/make-src.sh index 2e9a3c4309..3d352cbe95 100644 --- a/os400/make-src.sh +++ b/os400/make-src.sh @@ -78,7 +78,7 @@ fi # Get source list. -cat ../Makefile.inc ../Makefile.os400qc3.inc | +cat Makefile.inc | sed -e ':begin' \ -e '/\\$/{' \ -e 's/\\$/ /' \ @@ -98,7 +98,7 @@ cat ../Makefile.inc ../Makefile.os400qc3.inc | INCLUDES="'`pwd`'" for SRC in "${TOPDIR}/os400/os400sys.c" "${TOPDIR}/os400/ccsid.c" \ - ${CSOURCES} ${CRYPTO_CSOURCES} macros.c + ${CSOURCES} macros.c do MODULE=`db2_name "${SRC}"` make_module "${MODULE}" "${SRC}" done diff --git a/src/.gitignore b/src/.gitignore index 2c86ec73df..91aa7f0be0 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,5 +1,7 @@ .deps .libs +Makefile.inc.cmake +libssh2.pc libssh2_config.h libssh2_config.h.in stamp-h1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec556fc2fd..60176c453b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -96,47 +96,15 @@ if(MSVC) set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG") endif() -## Library definition +## Sources include(GNUInstallDirs) -set(SOURCES - ${CRYPTO_SOURCES} - agent.c - agent_win.c - bcrypt_pbkdf.c - channel.c - channel.h - comp.c - comp.h - crypt.c - crypto.h - global.c - hostkey.c - keepalive.c - kex.c - knownhost.c - libssh2_priv.h - mac.c - mac.h - misc.c - misc.h - os400qc3.c - packet.c - packet.h - pem.c - publickey.c - scp.c - session.c - session.h - sftp.c - sftp.h - transport.c - transport.h - userauth_kbd_packet.c - userauth_kbd_packet.h - userauth.c - userauth.h - version.c) +transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") +# Get 'CSOURCES' and 'HHEADERS' variables +include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake) +set(SOURCES ${CSOURCES} ${HHEADERS}) + +## Library definition # we want it to be called libssh2 on all platforms if(BUILD_STATIC_LIBS) diff --git a/src/Makefile.am b/src/Makefile.am index 240bed1413..1bb8a7d8b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,30 +1,11 @@ -# $Id: Makefile.am,v 1.21 2009/05/07 17:21:56 bagder Exp $ AUTOMAKE_OPTIONS = foreign nostdinc -# Get the CRYPTO_CSOURCES, CRYPTO_HHEADERS and CRYPTO_LTLIBS defines -if OPENSSL -include ../Makefile.OpenSSL.inc -endif -if WOLFSSL -include ../Makefile.wolfSSL.inc -endif -if LIBGCRYPT -include ../Makefile.libgcrypt.inc -endif -if WINCNG -include ../Makefile.WinCNG.inc -endif -if MBEDTLS -include ../Makefile.mbedTLS.inc -endif - -# Makefile.inc provides the CSOURCES and HHEADERS defines -include ../Makefile.inc +# Get the CSOURCES and HHEADERS defines +include Makefile.inc libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS) -EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in -EXTRA_DIST += CMakeLists.txt +EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt lib_LTLIBRARIES = libssh2.la @@ -65,4 +46,4 @@ VERSION=-version-info 1:1:0 libssh2_la_LDFLAGS = $(VERSION) -no-undefined \ -export-symbols-regex '^libssh2_.*' \ - $(CRYPTO_LTLIBS) $(LTLIBZ) + $(LTLIBZ) diff --git a/src/Makefile.inc b/src/Makefile.inc new file mode 100644 index 0000000000..1614271ea6 --- /dev/null +++ b/src/Makefile.inc @@ -0,0 +1,46 @@ +CSOURCES = \ + agent.c \ + agent_win.c \ + bcrypt_pbkdf.c \ + channel.c \ + comp.c \ + crypt.c \ + crypto.c \ + global.c \ + hostkey.c \ + keepalive.c \ + kex.c \ + knownhost.c \ + mac.c \ + misc.c \ + packet.c \ + pem.c \ + publickey.c \ + scp.c \ + session.c \ + sftp.c \ + transport.c \ + userauth.c \ + userauth_kbd_packet.c \ + version.c + +HHEADERS = \ + agent.h \ + channel.h \ + comp.h \ + crypto.h \ + libgcrypt.h \ + libssh2_priv.h \ + libssh2_setup.h \ + mac.h \ + mbedtls.h \ + misc.h \ + openssl.h \ + os400qc3.h \ + packet.h \ + session.h \ + sftp.h \ + transport.h \ + userauth.h \ + userauth_kbd_packet.h \ + wincng.h diff --git a/src/crypto.c b/src/crypto.c new file mode 100644 index 0000000000..789fcc4191 --- /dev/null +++ b/src/crypto.c @@ -0,0 +1,13 @@ +#include "libssh2_priv.h" + +#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) +#include "openssl.c" +#elif defined(LIBSSH2_LIBGCRYPT) +#include "libgcrypt.c" +#elif defined(LIBSSH2_MBEDTLS) +#include "mbedtls.c" +#elif defined(LIBSSH2_OS400QC3) +#include "os400qc3.c" +#elif defined(LIBSSH2_WINCNG) +#include "wincng.c" +#endif From 38015f4e46d8dbeea522dc7ee664522d4f47fc75 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Apr 2023 09:21:30 +0000 Subject: [PATCH 251/424] crypto: add `LIBSSH2_NO_DSA` to disable DSA support See also: be31457f3071686b555a0f0b19e5dcf63d67fc27 Closes #942 --- src/crypto.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/crypto.h b/src/crypto.h index 503a825b43..b5d6e0e62d 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -63,6 +63,11 @@ #define LIBSSH2_MD5 0 #endif +#ifdef LIBSSH2_NO_DSA +#undef LIBSSH2_DSA +#define LIBSSH2_DSA 0 +#endif + #define LIBSSH2_ED25519_KEY_LEN 32 #define LIBSSH2_ED25519_PRIVATE_KEY_LEN 64 #define LIBSSH2_ED25519_SIG_LEN 64 From c76b96cbe68453cb1c9a8240a80ce27d20ed4346 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Apr 2023 09:24:31 +0000 Subject: [PATCH 252/424] build: support `libssh2.rc` with autotools Caveat: When building `--enable-static` and `--enable-shared` at the same time, the compiled Windows resource is also included in the static library. This appears to be an autotools limitation, with no way to have different input lists (or different custom options) for shared and static libraries, even though it builds them separately. The workaround is to build static libraries in a separate `./configure` + `make` pass. Closes #944 --- configure.ac | 7 ++++++- src/Makefile.am | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 742c9b0fe4..d3685e8758 100644 --- a/configure.ac +++ b/configure.ac @@ -76,6 +76,8 @@ AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL AC_C_BIGENDIAN +LT_LANG([Windows Resource]) + dnl check for how to do large files AC_SYS_LARGEFILE @@ -296,7 +298,7 @@ case $host in # These are POSIX-like systems using BSD-like sockets API. ;; *) - AC_CHECK_HEADERS([windows.h]) + AC_CHECK_HEADERS([windows.h], [have_windows_h=yes], [have_windows_h=no]) ;; esac @@ -366,6 +368,9 @@ if test $missing_required_deps = 1; then AC_MSG_ERROR([Required dependencies are missing!]) fi +AM_CONDITIONAL([HAVE_WINDRES], + [test "x$have_windows_h" = "xyes" && test "x${enable_shared}" = "xyes" && test -n "${RC}"]) + # Configure parameters LIBSSH2_CHECK_OPTION_WERROR diff --git a/src/Makefile.am b/src/Makefile.am index 1bb8a7d8b3..ed6cfa2eac 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,6 +4,9 @@ AUTOMAKE_OPTIONS = foreign nostdinc include Makefile.inc libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS) +if HAVE_WINDRES +libssh2_la_SOURCES += libssh2.rc +endif EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt @@ -47,3 +50,8 @@ VERSION=-version-info 1:1:0 libssh2_la_LDFLAGS = $(VERSION) -no-undefined \ -export-symbols-regex '^libssh2_.*' \ $(LTLIBZ) + +if HAVE_WINDRES +.rc.lo: + $(LIBTOOL) --tag=RC --mode=compile $(RC) -I$(top_srcdir)/include $(RCFLAGS) -i $< -o $@ +endif From fe706697ed1094aaa7ad41ba5b6f865bab40d5f9 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Apr 2023 14:23:17 +0200 Subject: [PATCH 253/424] Support for direct-streamlocal@openssh.com UNIX socket connection (#945) This patch allow to use direct-streamlocal service from OpenSSH 6.7, that allows UNIX socket connections. Mods: - delete unrelated condition: Ref: https://github.com/libssh2/libssh2/pull/216#discussion_r374748111 - rebase on master, whitespace updates. Patch-by: @gjalves Gustavo Junior Alves Closes #216 Closes #632 Closes #945 --- docs/Makefile.am | 1 + docs/libssh2_channel_direct_streamlocal_ex.3 | 33 ++++++++ include/libssh2.h | 5 ++ src/channel.c | 79 ++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 docs/libssh2_channel_direct_streamlocal_ex.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index b2f2e5c9b9..1e41bac21c 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -14,6 +14,7 @@ dist_man_MANS = \ libssh2_banner_set.3 \ libssh2_base64_decode.3 \ libssh2_channel_close.3 \ + libssh2_channel_direct_streamlocal_ex.3 \ libssh2_channel_direct_tcpip.3 \ libssh2_channel_direct_tcpip_ex.3 \ libssh2_channel_eof.3 \ diff --git a/docs/libssh2_channel_direct_streamlocal_ex.3 b/docs/libssh2_channel_direct_streamlocal_ex.3 new file mode 100644 index 0000000000..c39b039b66 --- /dev/null +++ b/docs/libssh2_channel_direct_streamlocal_ex.3 @@ -0,0 +1,33 @@ +.TH libssh2_channel_direct_streamlocal_ex 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.SH NAME +libssh2_channel_direct_streamlocal_ex - Tunnel a UNIX socket connection through an SSH session +.SH SYNOPSIS +#include + +LIBSSH2_CHANNEL * +libssh2_channel_direct_streamlocal_ex(LIBSSH2_SESSION *session, const char *socket_path, const char *shost, int sport); + +LIBSSH2_CHANNEL * +libssh2_channel_direct_streamlocal(LIBSSH2_SESSION *session, const char *socket_path, const char *shost, int sport); + +.SH DESCRIPTION +\fIsession\fP - Session instance as returned by +.BR libssh2_session_init_ex(3) + +\fIsocket_path\fP - UNIX socket to connect to using the SSH host as a proxy. + +\fIshost\fP - Host to tell the SSH server the connection originated on. + +\fIsport\fP - Port to tell the SSH server the connection originated from. + +Tunnel a UNIX socket connection through the SSH transport via the remote host to +a third party. Communication from the client to the SSH server remains +encrypted, communication from the server to the 3rd party host travels +in cleartext. + +.SH RETURN VALUE +Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. +.SH ERRORS +\fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. +.SH SEE ALSO +.BR libssh2_session_init_ex(3) diff --git a/include/libssh2.h b/include/libssh2.h index 325631ed20..2848192d90 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -791,6 +791,11 @@ libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, #define libssh2_channel_direct_tcpip(session, host, port) \ libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22) +LIBSSH2_API LIBSSH2_CHANNEL * +libssh2_channel_direct_streamlocal_ex(LIBSSH2_SESSION * session, + const char *socket_path, + const char *shost, int sport); + LIBSSH2_API LIBSSH2_LISTENER * libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host, int port, int *bound_port, diff --git a/src/channel.c b/src/channel.c index 832d69dbbb..f1db4d7229 100644 --- a/src/channel.c +++ b/src/channel.c @@ -452,6 +452,85 @@ libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, return ptr; } +/* + * libssh2_channel_direct_streamlocal_ex + * + * Tunnel TCP/IP connect through the SSH session to direct UNIX socket + */ +static LIBSSH2_CHANNEL * +channel_direct_streamlocal(LIBSSH2_SESSION * session, const char *socket_path, + const char *shost, int sport) +{ + LIBSSH2_CHANNEL *channel; + unsigned char *s; + + if(session->direct_state == libssh2_NB_state_idle) { + session->direct_host_len = strlen(socket_path); + session->direct_shost_len = strlen(shost); + session->direct_message_len = + session->direct_host_len + session->direct_shost_len + 12; + + _libssh2_debug((session, LIBSSH2_TRACE_CONN, + "Requesting direct-streamlocal session to %s", + socket_path)); + + s = session->direct_message = + LIBSSH2_ALLOC(session, session->direct_message_len); + if(!session->direct_message) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for direct-streamlocal connection"); + return NULL; + } + _libssh2_store_str(&s, socket_path, session->direct_host_len); + _libssh2_store_str(&s, shost, session->direct_shost_len); + _libssh2_store_u32(&s, sport); + } + + channel = + _libssh2_channel_open(session, "direct-streamlocal@openssh.com", + sizeof("direct-streamlocal@openssh.com") - 1, + LIBSSH2_CHANNEL_WINDOW_DEFAULT, + LIBSSH2_CHANNEL_PACKET_DEFAULT, + session->direct_message, + session->direct_message_len); + + if(!channel && + libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { + /* The error code is still set to LIBSSH2_ERROR_EAGAIN, set our state + to created to avoid re-creating the package on next invoke */ + session->direct_state = libssh2_NB_state_created; + return NULL; + } + /* by default we set (keep?) idle state... */ + session->direct_state = libssh2_NB_state_idle; + + LIBSSH2_FREE(session, session->direct_message); + session->direct_message = NULL; + + return channel; +} + +/* + * libssh2_channel_direct_streamlocal_ex + * + * Tunnel TCP/IP connect through the SSH session to direct UNIX socket + */ +LIBSSH2_API LIBSSH2_CHANNEL * +libssh2_channel_direct_streamlocal_ex(LIBSSH2_SESSION * session, + const char *socket_path, + const char *shost, int sport) +{ + LIBSSH2_CHANNEL *ptr; + + if(!session) + return NULL; + + BLOCK_ADJUST_ERRNO(ptr, session, + channel_direct_streamlocal(session, + socket_path, shost, sport)); + return ptr; +} + /* * channel_forward_listen * From 0924632fa09c4827d9fad0ea7b656b42ae864a9f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Apr 2023 23:03:43 +0000 Subject: [PATCH 254/424] tidy-up: misc & minor cmake MSVS fix - `libssh2.rc`: document language/codepage codes. Ref: https://learn.microsoft.com/windows/win32/intl/code-page-identifiers - convert to Markdown: `docs/BINDINGS`, `docs/HACKING` Blind update for `vms/libssh2_make_help.dcl`. Please double-check. - cmake: fix to recognize dash-style warning options (`-Wn`) with MSVC. - `NMakefile`: sync `rd` command with `Makefile.mk`. - delete a CVS header. - cmake: simplify a `LIBSSH2_HAVE_ZLIB` macro. - few other nits and whitespace mods. Closes #943 --- CMakeLists.txt | 4 +++- COPYING | 1 - Makefile.am | 3 +-- NMakefile | 2 +- cmake/max_warnings.cmake | 10 +++++----- docs/BINDINGS | 29 ----------------------------- docs/BINDINGS.md | 25 +++++++++++++++++++++++++ docs/HACKING | 13 ------------- docs/HACKING.md | 14 ++++++++++++++ docs/Makefile.am | 4 ++-- libssh2-style.el | 1 - os400/make.sh | 2 +- src/CMakeLists.txt | 2 +- src/libssh2.rc | 4 ++-- src/sftp.c | 4 ++-- vms/libssh2_make_help.dcl | 4 ++-- 16 files changed, 59 insertions(+), 63 deletions(-) delete mode 100644 docs/BINDINGS create mode 100644 docs/BINDINGS.md delete mode 100644 docs/HACKING create mode 100644 docs/HACKING.md diff --git a/CMakeLists.txt b/CMakeLists.txt index ad2dcf8fc7..408d265147 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,9 @@ endif() include(GNUInstallDirs) install( - FILES docs/AUTHORS COPYING docs/HACKING README RELEASE-NOTES NEWS + FILES + COPYING NEWS README RELEASE-NOTES + docs/AUTHORS docs/BINDINGS.md docs/HACKING.md DESTINATION ${CMAKE_INSTALL_DOCDIR}) if(MSVC) diff --git a/COPYING b/COPYING index 937ed32e3a..fac8532725 100644 --- a/COPYING +++ b/COPYING @@ -41,4 +41,3 @@ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ - diff --git a/Makefile.am b/Makefile.am index abbefd5c66..d64e2ca632 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,8 +22,7 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/libssh2_make_kit.dcl vms/libssh2_make_lib.dcl vms/man2help.c \ vms/readme.vms vms/libssh2_config.h -WIN32FILES = NMakefile \ - src/libssh2.rc +WIN32FILES = src/libssh2.rc NMakefile OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ os400/make-src.sh os400/make-rpg.sh os400/make-include.sh \ diff --git a/NMakefile b/NMakefile index a7be7c11a3..9e3f36e378 100644 --- a/NMakefile +++ b/NMakefile @@ -80,7 +80,7 @@ clean-sub: clean $(CC) -c $(CFLAGS) /Fo"$(INTDIR)\\" $< clean: - -rmdir 2>NUL /s/q $(TARGET) + -rd 2>NUL /q /s $(TARGET) real-clean vclean: clean -del 2>NUL libssh2.dll diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index 6d20334445..1f42b03cf0 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -14,15 +14,15 @@ if(ENABLE_WERROR) endif() if(MSVC) - # Use the highest warning level for visual studio. + # Use the highest warning level for Visual Studio. if(PICKY_COMPILER) - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + if(CMAKE_CXX_FLAGS MATCHES "[/-]W[0-4]") + string(REGEX REPLACE "[/-]W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") endif() - if(CMAKE_C_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + if(CMAKE_C_FLAGS MATCHES "[/-]W[0-4]") + string(REGEX REPLACE "[/-]W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") endif() diff --git a/docs/BINDINGS b/docs/BINDINGS deleted file mode 100644 index 471f9be8c9..0000000000 --- a/docs/BINDINGS +++ /dev/null @@ -1,29 +0,0 @@ - -Creative people have written bindings or interfaces for various environments -and programming languages. Using one of these bindings allows you to take -advantage of libssh2 directly from within your favourite language. - -The bindings listed below are not part of the libssh2 distribution archives, -but must be downloaded and installed separately. - -Cocoa/Objective-C - https://github.com/karelia/libssh2_sftp-Cocoa-wrapper - -Haskell - FFI bindings - https://hackage.haskell.org/package/libssh2 - -Perl - Net::SSH2 - https://metacpan.org/pod/Net::SSH2 - -PHP - ssh2 - https://pecl.php.net/package/ssh2 - -Python - pylibssh2 - https://pypi.python.org/pypi/pylibssh2 - -Python-ctypes - - PySsh2 - https://github.com/gellule/PySsh2 - -Ruby - libssh2-ruby - https://github.com/mitchellh/libssh2-ruby diff --git a/docs/BINDINGS.md b/docs/BINDINGS.md new file mode 100644 index 0000000000..63ad1b0d34 --- /dev/null +++ b/docs/BINDINGS.md @@ -0,0 +1,25 @@ +libssh2 bindings +================ + +Creative people have written bindings or interfaces for various environments +and programming languages. Using one of these bindings allows you to take +advantage of libssh2 directly from within your favourite language. + +The bindings listed below are not part of the libssh2 distribution archives, +but must be downloaded and installed separately. + + + +[Cocoa/Objective-C](https://github.com/karelia/libssh2_sftp-Cocoa-wrapper) + +[Haskell FFI bindings](https://hackage.haskell.org/package/libssh2) + +[Perl Net::SSH2](https://metacpan.org/pod/Net::SSH2) + +[PHP ssh2](https://pecl.php.net/package/ssh2) + +[Python pylibssh2](https://pypi.python.org/pypi/pylibssh2) + +[Python-ctypes PySsh2](https://github.com/gellule/PySsh2) + +[Ruby libssh2-ruby](https://github.com/mitchellh/libssh2-ruby) diff --git a/docs/HACKING b/docs/HACKING deleted file mode 100644 index 5da8e66c23..0000000000 --- a/docs/HACKING +++ /dev/null @@ -1,13 +0,0 @@ - -libssh2 source code style guide: - - - 4 level indent - - spaces-only (no tabs) - - open braces on the if/for line: - - if (banana) { - go_nuts(); - } - - - keep source lines shorter than 80 columns - - See libssh2-style.el for how to achieve this within Emacs diff --git a/docs/HACKING.md b/docs/HACKING.md new file mode 100644 index 0000000000..11ddbd305d --- /dev/null +++ b/docs/HACKING.md @@ -0,0 +1,14 @@ +# libssh2 source code style guide + +- 4 level indent +- spaces-only (no tabs) +- open braces on the if/for line: + + ``` + if (banana) { + go_nuts(); + } + ``` + +- keep source lines shorter than 80 columns +- See `libssh2-style.el` for how to achieve this within Emacs diff --git a/docs/Makefile.am b/docs/Makefile.am index 1e41bac21c..235e77c573 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,5 +1,5 @@ -EXTRA_DIST = template.3 BINDINGS INSTALL_AUTOTOOLS INSTALL_CMAKE.md HACKING TODO \ - AUTHORS CMakeLists.txt HACKING-CRYPTO SECURITY.md +EXTRA_DIST = template.3 AUTHORS BINDINGS.md HACKING.md HACKING-CRYPTO \ + INSTALL_AUTOTOOLS INSTALL_CMAKE.md SECURITY.md TODO CMakeLists.txt dist_man_MANS = \ libssh2_agent_connect.3 \ diff --git a/libssh2-style.el b/libssh2-style.el index 7b622b45da..4437f88ac7 100644 --- a/libssh2-style.el +++ b/libssh2-style.el @@ -1,5 +1,4 @@ ;;;; Emacs Lisp help for writing libssh2 code. ;;;; -;;;; $Id: libssh2-style.el,v 1.1 2008/12/20 12:36:50 bagder Exp $ ;;; The libssh2 hacker's C conventions. ;;; See the sample.emacs file on how this file can be made to take diff --git a/os400/make.sh b/os400/make.sh index 0c9e3decde..0cfa7ec61a 100644 --- a/os400/make.sh +++ b/os400/make.sh @@ -31,7 +31,7 @@ fi for TEXT in "${TOPDIR}/COPYING" "${SCRIPTDIR}/README400" \ "${TOPDIR}/NEWS" "${TOPDIR}/README" "${TOPDIR}/docs/AUTHORS" \ - "${TOPDIR}/docs/BINDINGS" + "${TOPDIR}/docs/BINDINGS.md" do MEMBER="${LIBIFSNAME}/DOCS.FILE/`db2_name \"${TEXT}\"`.MBR" if action_needed "${MEMBER}" "${TEXT}" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 60176c453b..cd284e5aff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,7 +63,7 @@ if(ENABLE_ZLIB_COMPRESSION) list(APPEND LIBRARIES ${ZLIB_LIBRARIES}) list(APPEND PC_REQUIRES_PRIVATE zlib) if(ZLIB_FOUND) - list(APPEND libssh2_DEFINITIONS LIBSSH2_HAVE_ZLIB=1) + list(APPEND libssh2_DEFINITIONS LIBSSH2_HAVE_ZLIB) endif() endif() diff --git a/src/libssh2.rc b/src/libssh2.rc index 0843c0144d..c154951d9b 100644 --- a/src/libssh2.rc +++ b/src/libssh2.rc @@ -24,7 +24,7 @@ VS_VERSION_INFO VERSIONINFO BEGIN BLOCK "StringFileInfo" BEGIN - BLOCK "040904b0" + BLOCK "040904b0" /* 0x0409: en-US, 1200/0x04b0: UTF-16LE */ BEGIN VALUE "CompanyName", "The libssh2 library, https://www.libssh2.org/\0" VALUE "FileDescription", "libssh2 Shared Library\0" @@ -40,6 +40,6 @@ BEGIN BLOCK "VarFileInfo" BEGIN - VALUE "Translation", 0x409, 1200 + VALUE "Translation", 0x0409, 0x04b0 /* 0x0409: en-US, 1200/0x04b0: UTF-16LE */ END END diff --git a/src/sftp.c b/src/sftp.c index dd8ef7ec0c..d1dc1ad604 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -120,12 +120,12 @@ static void _libssh2_store_u64(unsigned char **ptr, libssh2_uint64_t value) buf[0] = (unsigned char)((msl >> 24) & 0xFF); buf[1] = (unsigned char)((msl >> 16) & 0xFF); - buf[2] = (unsigned char)((msl >> 8) & 0xFF); + buf[2] = (unsigned char)((msl >> 8) & 0xFF); buf[3] = (unsigned char)( msl & 0xFF); buf[4] = (unsigned char)((value >> 24) & 0xFF); buf[5] = (unsigned char)((value >> 16) & 0xFF); - buf[6] = (unsigned char)((value >> 8) & 0xFF); + buf[6] = (unsigned char)((value >> 8) & 0xFF); buf[7] = (unsigned char)( value & 0xFF); *ptr += 8; diff --git a/vms/libssh2_make_help.dcl b/vms/libssh2_make_help.dcl index 652671da3d..34bbb0522f 100644 --- a/vms/libssh2_make_help.dcl +++ b/vms/libssh2_make_help.dcl @@ -26,8 +26,8 @@ $ man2help -a [-]COPYING.; libssh2.hlp -b 2 $ man2help -a [-]NEWS.; libssh2.hlp -b 2 $ man2help -a [-]RELEASE-NOTES.; libssh2.hlp -b 2 $ man2help -a [-.docs]AUTHORS.; libssh2.hlp -b 2 -$ man2help -a [-.docs]BINDINGS.; libssh2.hlp -b 2 -$ man2help -a [-.docs]HACKING.; libssh2.hlp -b 2 +$ copy [-.docs]BINDINGS.md; []BINDINGS.md +$ copy [-.docs]HACKING.md; []HACKING.md $ if f$search("[]HACKING_CRYPTO.") .nes. "" then delete []HACKING_CRYPTO.;* $ copy [-.docs]HACKING-CRYPTO; []HACKING_CRYPTO. $ man2help -a []HACKING_CRYPTO.; libssh2.hlp -b 2 From 504026262d0a3aa2bfaa16613176644d1a56293e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Apr 2023 23:08:22 +0000 Subject: [PATCH 255/424] include: indentation fixes --- include/libssh2.h | 217 +++++++++++++++++++----------------- include/libssh2_publickey.h | 20 ++-- include/libssh2_sftp.h | 23 ++-- 3 files changed, 136 insertions(+), 124 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index 2848192d90..1490897649 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -289,22 +289,24 @@ typedef struct _LIBSSH2_SK_SIG_INFO { /* 'publickey' authentication callback */ #define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \ - int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \ - const unsigned char *data, size_t data_len, void **abstract) + int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \ + const unsigned char *data, size_t data_len, void **abstract) /* 'keyboard-interactive' authentication callback */ #define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \ - void name_(const char *name, int name_len, const char *instruction, \ - int instruction_len, int num_prompts, \ - const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, \ - LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract) + void name_(const char *name, int name_len, const char *instruction, \ + int instruction_len, int num_prompts, \ + const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, \ + LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract) /* SK authentication callback */ #define LIBSSH2_USERAUTH_SK_SIGN_FUNC(name) \ -int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, \ -const unsigned char *data, size_t data_len, int algorithm, uint8_t flags, \ -const char *application, const unsigned char *key_handle, size_t handle_len, \ -void **abstract) + int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, \ + const unsigned char *data, size_t data_len, \ + int algorithm, uint8_t flags, \ + const char *application, const unsigned char *key_handle, \ + size_t handle_len, \ + void **abstract) /* Flags for SK authentication */ #define LIBSSH2_SK_PRESENCE_REQUIRED 0x01 @@ -312,34 +314,36 @@ void **abstract) /* Callbacks for special SSH packets */ #define LIBSSH2_IGNORE_FUNC(name) \ - void name(LIBSSH2_SESSION *session, const char *message, int message_len, \ - void **abstract) + void name(LIBSSH2_SESSION *session, const char *message, int message_len, \ + void **abstract) #define LIBSSH2_DEBUG_FUNC(name) \ - void name(LIBSSH2_SESSION *session, int always_display, const char *message, \ - int message_len, const char *language, int language_len, \ - void **abstract) + void name(LIBSSH2_SESSION *session, int always_display, \ + const char *message, int message_len, \ + const char *language, int language_len, \ + void **abstract) #define LIBSSH2_DISCONNECT_FUNC(name) \ - void name(LIBSSH2_SESSION *session, int reason, const char *message, \ - int message_len, const char *language, int language_len, \ - void **abstract) + void name(LIBSSH2_SESSION *session, int reason, \ + const char *message, int message_len, \ + const char *language, int language_len, \ + void **abstract) #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \ - void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \ - void **abstract) + void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \ + void **abstract) #define LIBSSH2_MACERROR_FUNC(name) \ - int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \ - void **abstract) + int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \ + void **abstract) #define LIBSSH2_X11_OPEN_FUNC(name) \ - void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \ - const char *shost, int sport, void **abstract) + void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \ + const char *shost, int sport, void **abstract) #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \ - void name(LIBSSH2_SESSION *session, void **session_abstract, \ - LIBSSH2_CHANNEL *channel, void **channel_abstract) + void name(LIBSSH2_SESSION *session, void **session_abstract, \ + LIBSSH2_CHANNEL *channel, void **channel_abstract) /* I/O callbacks */ #define LIBSSH2_RECV_FUNC(name) \ @@ -618,8 +622,8 @@ LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, const char *description, const char *lang); #define libssh2_session_disconnect(session, description) \ - libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \ - (description), "") + libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \ + (description), "") LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session); @@ -662,12 +666,13 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION *session, const char *password, unsigned int password_len, LIBSSH2_PASSWD_CHANGEREQ_FUNC - ((*passwd_change_cb))); + ((*passwd_change_cb))); #define libssh2_userauth_password(session, username, password) \ - libssh2_userauth_password_ex((session), (username), \ - (unsigned int)strlen(username), \ - (password), (unsigned int)strlen(password), NULL) + libssh2_userauth_password_ex((session), (username), \ + (unsigned int)strlen(username), \ + (password), (unsigned int)strlen(password), \ + NULL) LIBSSH2_API int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, @@ -677,11 +682,11 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, const char *privatekey, const char *passphrase); -#define libssh2_userauth_publickey_fromfile(session, username, publickey, \ - privatekey, passphrase) \ - libssh2_userauth_publickey_fromfile_ex((session), (username), \ +#define libssh2_userauth_publickey_fromfile(session, username, publickey, \ + privatekey, passphrase) \ + libssh2_userauth_publickey_fromfile_ex((session), (username), \ (unsigned int)strlen(username), \ - (publickey), \ + (publickey), \ (privatekey), (passphrase)) LIBSSH2_API int @@ -690,7 +695,7 @@ libssh2_userauth_publickey(LIBSSH2_SESSION *session, const unsigned char *pubkeydata, size_t pubkeydata_len, LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC - ((*sign_callback)), + ((*sign_callback)), void **abstract); LIBSSH2_API int @@ -705,16 +710,16 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, const char *local_username, unsigned int local_username_len); -#define libssh2_userauth_hostbased_fromfile(session, username, publickey, \ +#define libssh2_userauth_hostbased_fromfile(session, username, publickey, \ privatekey, passphrase, hostname) \ - libssh2_userauth_hostbased_fromfile_ex((session), (username), \ - (unsigned int)strlen(username), \ - (publickey), \ - (privatekey), (passphrase), \ - (hostname), \ - (unsigned int)strlen(hostname), \ - (username), \ - (unsigned int)strlen(username)) + libssh2_userauth_hostbased_fromfile_ex((session), (username), \ + (unsigned int)strlen(username), \ + (publickey), \ + (privatekey), (passphrase), \ + (hostname), \ + (unsigned int)strlen(hostname), \ + (username), \ + (unsigned int)strlen(username)) LIBSSH2_API int libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session, @@ -736,12 +741,12 @@ LIBSSH2_API int libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session, const char *username, unsigned int username_len, - LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC( - (*response_callback))); + LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC + ((*response_callback))); -#define libssh2_userauth_keyboard_interactive(session, username, \ - response_callback) \ - libssh2_userauth_keyboard_interactive_ex((session), (username), \ +#define libssh2_userauth_keyboard_interactive(session, username, \ + response_callback) \ + libssh2_userauth_keyboard_interactive_ex((session), (username), \ (unsigned int)strlen(username), \ (response_callback)) @@ -753,7 +758,7 @@ libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, size_t privatekeydata_len, const char *passphrase, LIBSSH2_USERAUTH_SK_SIGN_FUNC - ((*sign_callback)), + ((*sign_callback)), void **abstract); LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, @@ -781,15 +786,15 @@ libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type, const char *message, unsigned int message_len); #define libssh2_channel_open_session(session) \ - libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \ - LIBSSH2_CHANNEL_WINDOW_DEFAULT, \ - LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0) + libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \ + LIBSSH2_CHANNEL_WINDOW_DEFAULT, \ + LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0) LIBSSH2_API LIBSSH2_CHANNEL * libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, int port, const char *shost, int sport); #define libssh2_channel_direct_tcpip(session, host, port) \ - libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22) + libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22) LIBSSH2_API LIBSSH2_CHANNEL * libssh2_channel_direct_streamlocal_ex(LIBSSH2_SESSION * session, @@ -801,7 +806,7 @@ libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host, int port, int *bound_port, int queue_maxsize); #define libssh2_channel_forward_listen(session, port) \ - libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16) + libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16) LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener); @@ -842,7 +847,7 @@ LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel, int width_px, int height_px); #define libssh2_channel_request_pty_size(channel, width, height) \ - libssh2_channel_request_pty_size_ex((channel), (width), (height), 0, 0) + libssh2_channel_request_pty_size_ex((channel), (width), (height), 0, 0) LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection, @@ -850,7 +855,7 @@ LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, const char *auth_cookie, int screen_number); #define libssh2_channel_x11_req(channel, screen_number) \ - libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number)) + libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number)) LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, const char *request, @@ -858,23 +863,25 @@ LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, const char *message, unsigned int message_len); #define libssh2_channel_shell(channel) \ - libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \ - NULL, 0) + libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \ + NULL, 0) #define libssh2_channel_exec(channel, command) \ - libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \ - (command), (unsigned int)strlen(command)) + libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \ + (command), (unsigned int)strlen(command)) #define libssh2_channel_subsystem(channel, subsystem) \ - libssh2_channel_process_startup((channel), "subsystem", \ - sizeof("subsystem") - 1, (subsystem), \ - (unsigned int)strlen(subsystem)) + libssh2_channel_process_startup((channel), "subsystem", \ + sizeof("subsystem") - 1, (subsystem), \ + (unsigned int)strlen(subsystem)) LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, size_t buflen); #define libssh2_channel_read(channel, buf, buflen) \ - libssh2_channel_read_ex((channel), 0, (buf), (buflen)) + libssh2_channel_read_ex((channel), 0, \ + (buf), (buflen)) #define libssh2_channel_read_stderr(channel, buf, buflen) \ - libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen)) + libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, \ + (buf), (buflen)) LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended); @@ -884,9 +891,9 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, unsigned long *read_avail, unsigned long *window_size_initial); #define libssh2_channel_window_read(channel) \ - libssh2_channel_window_read_ex((channel), NULL, NULL) + libssh2_channel_window_read_ex((channel), NULL, NULL) -/* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */ +/* libssh2_channel_receive_window_adjust() is DEPRECATED, do not use! */ LIBSSH2_API unsigned long libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel, unsigned long adjustment, @@ -903,16 +910,17 @@ LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, size_t buflen); #define libssh2_channel_write(channel, buf, buflen) \ - libssh2_channel_write_ex((channel), 0, (buf), (buflen)) -#define libssh2_channel_write_stderr(channel, buf, buflen) \ - libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, \ + libssh2_channel_write_ex((channel), 0, \ + (buf), (buflen)) +#define libssh2_channel_write_stderr(channel, buf, buflen) \ + libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, \ (buf), (buflen)) LIBSSH2_API unsigned long libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel, unsigned long *window_size_initial); #define libssh2_channel_window_write(channel) \ - libssh2_channel_window_write_ex((channel), NULL) + libssh2_channel_window_write_ex((channel), NULL) LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session, int blocking); @@ -929,7 +937,7 @@ LIBSSH2_API void libssh2_session_set_read_timeout(LIBSSH2_SESSION* session, long timeout); LIBSSH2_API long libssh2_session_get_read_timeout(LIBSSH2_SESSION* session); -/* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */ +/* libssh2_channel_handle_extended_data() is DEPRECATED, do not use! */ LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode); LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, @@ -943,9 +951,8 @@ LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, * (FIFO) from the standard data channel */ /* DEPRECATED */ -#define libssh2_channel_ignore_extended_data(channel, ignore) \ - libssh2_channel_handle_extended_data((channel), \ - (ignore) ? \ +#define libssh2_channel_ignore_extended_data(channel, ignore) \ + libssh2_channel_handle_extended_data((channel), (ignore) ? \ LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \ LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL) @@ -955,7 +962,7 @@ LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int streamid); #define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0) #define libssh2_channel_flush_stderr(channel) \ - libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR) + libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR) LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel); LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel, @@ -976,7 +983,7 @@ LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel); LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb); -/* Use libssh2_scp_recv2 for large (> 2GB) file support on windows */ +/* Use libssh2_scp_recv2() for large (> 2GB) file support on windows */ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv2(LIBSSH2_SESSION *session, const char *path, libssh2_struct_stat *sb); @@ -989,7 +996,7 @@ libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode, libssh2_int64_t size, time_t mtime, time_t atime); #define libssh2_scp_send(session, path, mode, size) \ - libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0) + libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0) LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, unsigned int *dest_len, @@ -1023,7 +1030,7 @@ struct libssh2_knownhost { }; /* - * libssh2_knownhost_init + * libssh2_knownhost_init() * * Init a collection of known hosts. Returns the pointer to a collection. * @@ -1032,7 +1039,7 @@ LIBSSH2_API LIBSSH2_KNOWNHOSTS * libssh2_knownhost_init(LIBSSH2_SESSION *session); /* - * libssh2_knownhost_add + * libssh2_knownhost_add() * * Add a host and its associated key to the collection of known hosts. * @@ -1084,7 +1091,7 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, struct libssh2_knownhost **store); /* - * libssh2_knownhost_addc + * libssh2_knownhost_addc() * * Add a host and its associated key to the collection of known hosts. * @@ -1102,8 +1109,8 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, * If 'sha1' is selected as type, the salt must be provided to the salt * argument. This too base64 encoded. * - * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If - * a custom type is used, salt is ignored and you must provide the host + * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. + * If a custom type is used, salt is ignored and you must provide the host * pre-hashed when checking for it in the libssh2_knownhost_check() function. * * The keylen parameter may be omitted (zero) if the key is provided as a @@ -1119,7 +1126,7 @@ libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts, struct libssh2_knownhost **store); /* - * libssh2_knownhost_check + * libssh2_knownhost_check() * * Check a host and its associated key against the collection of known hosts. * @@ -1158,7 +1165,7 @@ libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts, struct libssh2_knownhost **knownhost); /* - * libssh2_knownhost_del + * libssh2_knownhost_del() * * Remove a host from the collection of known hosts. The 'entry' struct is * retrieved by a call to libssh2_knownhost_check(). @@ -1169,7 +1176,7 @@ libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts, struct libssh2_knownhost *entry); /* - * libssh2_knownhost_free + * libssh2_knownhost_free() * * Free an entire collection of known hosts. * @@ -1190,7 +1197,7 @@ libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts, const char *line, size_t len, int type); /* - * libssh2_knownhost_readfile + * libssh2_knownhost_readfile() * * Add hosts+key pairs from a given file. * @@ -1226,7 +1233,7 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, int type); /* - * libssh2_knownhost_writefile + * libssh2_knownhost_writefile() * * Write hosts+key pairs to a given file. * @@ -1266,7 +1273,7 @@ struct libssh2_agent_publickey { }; /* - * libssh2_agent_init + * libssh2_agent_init() * * Init an ssh-agent handle. Returns the pointer to the handle. * @@ -1308,8 +1315,8 @@ libssh2_agent_list_identities(LIBSSH2_AGENT *agent); */ LIBSSH2_API int libssh2_agent_get_identity(LIBSSH2_AGENT *agent, - struct libssh2_agent_publickey **store, - struct libssh2_agent_publickey *prev); + struct libssh2_agent_publickey **store, + struct libssh2_agent_publickey *prev); /* * libssh2_agent_userauth() @@ -1320,8 +1327,8 @@ libssh2_agent_get_identity(LIBSSH2_AGENT *agent, */ LIBSSH2_API int libssh2_agent_userauth(LIBSSH2_AGENT *agent, - const char *username, - struct libssh2_agent_publickey *identity); + const char *username, + struct libssh2_agent_publickey *identity); /* * libssh2_agent_disconnect() @@ -1394,15 +1401,15 @@ LIBSSH2_API int libssh2_keepalive_send(LIBSSH2_SESSION *session, enabled */ LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask); -#define LIBSSH2_TRACE_TRANS (1<<1) -#define LIBSSH2_TRACE_KEX (1<<2) -#define LIBSSH2_TRACE_AUTH (1<<3) -#define LIBSSH2_TRACE_CONN (1<<4) -#define LIBSSH2_TRACE_SCP (1<<5) -#define LIBSSH2_TRACE_SFTP (1<<6) -#define LIBSSH2_TRACE_ERROR (1<<7) -#define LIBSSH2_TRACE_PUBLICKEY (1<<8) -#define LIBSSH2_TRACE_SOCKET (1<<9) +#define LIBSSH2_TRACE_TRANS (1<<1) +#define LIBSSH2_TRACE_KEX (1<<2) +#define LIBSSH2_TRACE_AUTH (1<<3) +#define LIBSSH2_TRACE_CONN (1<<4) +#define LIBSSH2_TRACE_SCP (1<<5) +#define LIBSSH2_TRACE_SFTP (1<<6) +#define LIBSSH2_TRACE_ERROR (1<<7) +#define LIBSSH2_TRACE_PUBLICKEY (1<<8) +#define LIBSSH2_TRACE_SOCKET (1<<9) typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*, void *, diff --git a/include/libssh2_publickey.h b/include/libssh2_publickey.h index 5dbdcf9253..00ea5ffdcf 100644 --- a/include/libssh2_publickey.h +++ b/include/libssh2_publickey.h @@ -72,9 +72,9 @@ typedef struct _libssh2_publickey_list { /* Generally use the first macro here, but if both name and value are string literals, you can use _fast() to take advantage of preprocessing */ #define libssh2_publickey_attribute(name, value, mandatory) \ - { (name), strlen(name), (value), strlen(value), (mandatory) }, + { (name), strlen(name), (value), strlen(value), (mandatory) }, #define libssh2_publickey_attribute_fast(name, value, mandatory) \ - { (name), sizeof(name) - 1, (value), sizeof(value) - 1, (mandatory) }, + { (name), sizeof(name) - 1, (value), sizeof(value) - 1, (mandatory) }, #ifdef __cplusplus extern "C" { @@ -92,10 +92,12 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, unsigned long blob_len, char overwrite, unsigned long num_attrs, const libssh2_publickey_attribute attrs[]); -#define libssh2_publickey_add(pkey, name, blob, blob_len, overwrite, \ - num_attrs, attrs) \ - libssh2_publickey_add_ex((pkey), (name), strlen(name), (blob), (blob_len), \ - (overwrite), (num_attrs), (attrs)) +#define libssh2_publickey_add(pkey, name, blob, blob_len, overwrite, \ + num_attrs, attrs) \ + libssh2_publickey_add_ex((pkey), \ + (name), strlen(name), \ + (blob), (blob_len), \ + (overwrite), (num_attrs), (attrs)) LIBSSH2_API int libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, @@ -103,7 +105,9 @@ LIBSSH2_API int libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *blob, unsigned long blob_len); #define libssh2_publickey_remove(pkey, name, blob, blob_len) \ - libssh2_publickey_remove_ex((pkey), (name), strlen(name), (blob), (blob_len)) + libssh2_publickey_remove_ex((pkey), \ + (name), strlen(name), \ + (blob), (blob_len)) LIBSSH2_API int libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, @@ -119,4 +123,4 @@ LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey); } /* extern "C" */ #endif -#endif /* ifndef: LIBSSH2_PUBLICKEY_H */ +#endif /* LIBSSH2_PUBLICKEY_H */ diff --git a/include/libssh2_sftp.h b/include/libssh2_sftp.h index 5c152d7522..0e848f5205 100644 --- a/include/libssh2_sftp.h +++ b/include/libssh2_sftp.h @@ -165,19 +165,19 @@ struct _LIBSSH2_SFTP_STATVFS { /* macros to check for specific file types, added in 1.2.5 */ #define LIBSSH2_SFTP_S_ISLNK(m) \ - (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFLNK) + (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFLNK) #define LIBSSH2_SFTP_S_ISREG(m) \ - (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFREG) + (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFREG) #define LIBSSH2_SFTP_S_ISDIR(m) \ - (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFDIR) + (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFDIR) #define LIBSSH2_SFTP_S_ISCHR(m) \ - (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFCHR) + (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFCHR) #define LIBSSH2_SFTP_S_ISBLK(m) \ - (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFBLK) + (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFBLK) #define LIBSSH2_SFTP_S_ISFIFO(m) \ - (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFIFO) + (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFIFO) #define LIBSSH2_SFTP_S_ISSOCK(m) \ - (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFSOCK) + (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFSOCK) /* SFTP File Transfer Flags -- (e.g. flags parameter to sftp_open()) * Danger will robinson... APPEND doesn't have any effect on OpenSSH servers */ @@ -230,13 +230,14 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, unsigned int filename_len, unsigned long flags, long mode, int open_type); -#define libssh2_sftp_open(sftp, filename, flags, mode) \ +#define libssh2_sftp_open(sftp, filename, flags, mode) \ libssh2_sftp_open_ex((sftp), \ (filename), (unsigned int)strlen(filename), \ (flags), (mode), LIBSSH2_SFTP_OPENFILE) #define libssh2_sftp_opendir(sftp, path) \ - libssh2_sftp_open_ex((sftp), (path), (unsigned int)strlen(path), 0, 0, \ - LIBSSH2_SFTP_OPENDIR) + libssh2_sftp_open_ex((sftp), \ + (path), (unsigned int)strlen(path), \ + 0, 0, LIBSSH2_SFTP_OPENDIR) LIBSSH2_API ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen); @@ -246,7 +247,7 @@ LIBSSH2_API int libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *handle, \ char *longentry, size_t longentry_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs); -#define libssh2_sftp_readdir(handle, buffer, buffer_maxlen, attrs) \ +#define libssh2_sftp_readdir(handle, buffer, buffer_maxlen, attrs) \ libssh2_sftp_readdir_ex((handle), (buffer), (buffer_maxlen), NULL, 0, \ (attrs)) From e590450dccc4703f2cab8aa6bc21a50df40bf5d2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 11 Apr 2023 00:38:35 +0000 Subject: [PATCH 256/424] man: fixups - add missing `.fi` tags. - fix misplaced `.nf` tags. - add `.nf`/`.fi` tags `SYNOPSIS` where missing. - fix missing/wrong function name from `SH NAME`. - fix wrong function name in `TH`. - keep return values in a separate line. - indent. - fold long lines. - deleted `libssh2_channel_direct_streamlocal()`, there is no such function. - add missing types. - add missing headers. Closes #949 --- docs/libssh2_agent_connect.3 | 5 +++- docs/libssh2_agent_disconnect.3 | 5 +++- docs/libssh2_agent_free.3 | 5 +++- docs/libssh2_agent_get_identity.3 | 9 +++++--- docs/libssh2_agent_get_identity_path.3 | 2 ++ docs/libssh2_agent_init.3 | 5 +++- docs/libssh2_agent_list_identities.3 | 5 +++- docs/libssh2_agent_set_identity_path.3 | 2 ++ docs/libssh2_agent_userauth.3 | 9 +++++--- docs/libssh2_banner_set.3 | 3 ++- docs/libssh2_base64_decode.3 | 9 +++++--- docs/libssh2_channel_close.3 | 3 ++- docs/libssh2_channel_direct_streamlocal_ex.3 | 10 ++++---- docs/libssh2_channel_direct_tcpip.3 | 6 +++-- docs/libssh2_channel_direct_tcpip_ex.3 | 10 +++++--- docs/libssh2_channel_eof.3 | 2 ++ docs/libssh2_channel_exec.3 | 6 +++-- docs/libssh2_channel_flush.3 | 6 +++-- docs/libssh2_channel_flush_ex.3 | 3 ++- docs/libssh2_channel_flush_stderr.3 | 6 +++-- docs/libssh2_channel_forward_accept.3 | 3 ++- docs/libssh2_channel_forward_cancel.3 | 3 ++- docs/libssh2_channel_forward_listen.3 | 6 +++-- docs/libssh2_channel_forward_listen_ex.3 | 7 ++++-- docs/libssh2_channel_free.3 | 3 ++- docs/libssh2_channel_get_exit_signal.3 | 8 +++++-- docs/libssh2_channel_get_exit_status.3 | 3 ++- docs/libssh2_channel_handle_extended_data.3 | 6 +++-- docs/libssh2_channel_handle_extended_data2.3 | 6 +++-- docs/libssh2_channel_ignore_extended_data.3 | 7 ++++-- docs/libssh2_channel_open_ex.3 | 9 ++++++-- docs/libssh2_channel_open_session.3 | 3 ++- docs/libssh2_channel_process_startup.3 | 12 ++++++---- docs/libssh2_channel_read.3 | 7 ++++-- docs/libssh2_channel_read_ex.3 | 12 ++++++---- docs/libssh2_channel_read_stderr.3 | 7 ++++-- docs/libssh2_channel_receive_window_adjust.3 | 3 ++- docs/libssh2_channel_receive_window_adjust2.3 | 3 ++- docs/libssh2_channel_request_auth_agent.3 | 3 ++- docs/libssh2_channel_request_pty.3 | 6 +++-- docs/libssh2_channel_request_pty_ex.3 | 11 ++++++--- docs/libssh2_channel_request_pty_size.3 | 7 ++++-- docs/libssh2_channel_request_pty_size_ex.3 | 3 ++- docs/libssh2_channel_send_eof.3 | 3 ++- docs/libssh2_channel_set_blocking.3 | 2 ++ docs/libssh2_channel_setenv.3 | 7 ++++-- docs/libssh2_channel_setenv_ex.3 | 10 +++++--- docs/libssh2_channel_shell.3 | 6 +++-- docs/libssh2_channel_subsystem.3 | 6 +++-- docs/libssh2_channel_wait_closed.3 | 3 ++- docs/libssh2_channel_wait_eof.3 | 3 ++- docs/libssh2_channel_window_read.3 | 6 +++-- docs/libssh2_channel_window_read_ex.3 | 2 ++ docs/libssh2_channel_window_write.3 | 6 +++-- docs/libssh2_channel_window_write_ex.3 | 2 ++ docs/libssh2_channel_write.3 | 6 +++-- docs/libssh2_channel_write_ex.3 | 8 ++++--- docs/libssh2_channel_write_stderr.3 | 6 +++-- docs/libssh2_channel_x11_req.3 | 6 +++-- docs/libssh2_channel_x11_req_ex.3 | 10 +++++--- docs/libssh2_crypto_engine.3 | 6 +++-- docs/libssh2_exit.3 | 2 ++ docs/libssh2_free.3 | 4 +++- docs/libssh2_hostkey_hash.3 | 3 ++- docs/libssh2_init.3 | 2 ++ docs/libssh2_keepalive_config.3 | 9 ++++---- docs/libssh2_keepalive_send.3 | 8 ++++--- docs/libssh2_knownhost_add.3 | 14 ++++++----- docs/libssh2_knownhost_addc.3 | 21 +++++++++-------- docs/libssh2_knownhost_check.3 | 13 +++++++---- docs/libssh2_knownhost_checkp.3 | 15 +++++++----- docs/libssh2_knownhost_del.3 | 7 ++++-- docs/libssh2_knownhost_free.3 | 5 +++- docs/libssh2_knownhost_get.3 | 9 +++++--- docs/libssh2_knownhost_init.3 | 5 +++- docs/libssh2_knownhost_readfile.3 | 7 ++++-- docs/libssh2_knownhost_readline.3 | 7 ++++-- docs/libssh2_knownhost_writefile.3 | 7 ++++-- docs/libssh2_knownhost_writeline.3 | 3 +++ docs/libssh2_poll.3 | 5 +++- docs/libssh2_poll_channel_read.3 | 5 +++- docs/libssh2_publickey_add.3 | 13 +++++++---- docs/libssh2_publickey_add_ex.3 | 11 +++++---- docs/libssh2_publickey_init.3 | 3 ++- docs/libssh2_publickey_list_fetch.3 | 3 ++- docs/libssh2_publickey_list_free.3 | 3 ++- docs/libssh2_publickey_remove.3 | 10 ++++---- docs/libssh2_publickey_remove_ex.3 | 3 ++- docs/libssh2_publickey_shutdown.3 | 3 ++- docs/libssh2_scp_recv.3 | 3 ++- docs/libssh2_scp_recv2.3 | 3 ++- docs/libssh2_scp_send.3 | 6 +++-- docs/libssh2_scp_send64.3 | 1 + docs/libssh2_scp_send_ex.3 | 1 + docs/libssh2_session_abstract.3 | 3 ++- docs/libssh2_session_banner_get.3 | 5 +++- docs/libssh2_session_banner_set.3 | 3 ++- docs/libssh2_session_block_directions.3 | 2 ++ docs/libssh2_session_callback_set.3 | 6 +++-- docs/libssh2_session_disconnect.3 | 6 +++-- docs/libssh2_session_disconnect_ex.3 | 10 +++++--- docs/libssh2_session_flag.3 | 4 ++++ docs/libssh2_session_free.3 | 2 ++ docs/libssh2_session_get_blocking.3 | 7 +++++- docs/libssh2_session_get_read_timeout.3 | 7 ++++-- docs/libssh2_session_get_timeout.3 | 7 ++++-- docs/libssh2_session_handshake.3 | 2 ++ docs/libssh2_session_hostkey.3 | 7 ++++-- docs/libssh2_session_init.3 | 3 ++- docs/libssh2_session_init_ex.3 | 8 +++++-- docs/libssh2_session_last_errno.3 | 3 ++- docs/libssh2_session_last_error.3 | 6 +++-- docs/libssh2_session_method_pref.3 | 6 +++-- docs/libssh2_session_methods.3 | 3 ++- docs/libssh2_session_set_blocking.3 | 3 ++- docs/libssh2_session_set_last_error.3 | 6 +++-- docs/libssh2_session_set_read_timeout.3 | 7 ++++-- docs/libssh2_session_set_timeout.3 | 7 ++++-- docs/libssh2_session_startup.3 | 2 ++ docs/libssh2_session_supported_algs.3 | 13 +++++++---- docs/libssh2_sftp_close.3 | 7 ++++-- docs/libssh2_sftp_close_handle.3 | 3 ++- docs/libssh2_sftp_closedir.3 | 7 ++++-- docs/libssh2_sftp_fsetstat.3 | 8 +++++-- docs/libssh2_sftp_fstat.3 | 8 +++++-- docs/libssh2_sftp_get_channel.3 | 3 ++- docs/libssh2_sftp_init.3 | 3 ++- docs/libssh2_sftp_last_error.3 | 3 ++- docs/libssh2_sftp_lstat.3 | 8 +++++-- docs/libssh2_sftp_mkdir.3 | 8 +++++-- docs/libssh2_sftp_mkdir_ex.3 | 10 ++++++-- docs/libssh2_sftp_open.3 | 8 +++++-- docs/libssh2_sftp_open_ex.3 | 9 +++++--- docs/libssh2_sftp_opendir.3 | 4 +++- docs/libssh2_sftp_read.3 | 6 +++-- docs/libssh2_sftp_readdir.3 | 9 ++++++-- docs/libssh2_sftp_readdir_ex.3 | 1 + docs/libssh2_sftp_readlink.3 | 7 ++++-- docs/libssh2_sftp_realpath.3 | 8 +++++-- docs/libssh2_sftp_rename.3 | 9 ++++++-- docs/libssh2_sftp_rename_ex.3 | 14 ++++++++--- docs/libssh2_sftp_rewind.3 | 7 ++++-- docs/libssh2_sftp_rmdir.3 | 2 ++ docs/libssh2_sftp_rmdir_ex.3 | 6 +++-- docs/libssh2_sftp_seek.3 | 5 +++- docs/libssh2_sftp_seek64.3 | 6 +++-- docs/libssh2_sftp_setstat.3 | 8 +++++-- docs/libssh2_sftp_shutdown.3 | 3 ++- docs/libssh2_sftp_stat.3 | 8 +++++-- docs/libssh2_sftp_stat_ex.3 | 8 ++++--- docs/libssh2_sftp_symlink.3 | 2 ++ docs/libssh2_sftp_symlink_ex.3 | 1 + docs/libssh2_sftp_tell.3 | 3 ++- docs/libssh2_sftp_tell64.3 | 3 ++- docs/libssh2_sftp_unlink.3 | 7 ++++-- docs/libssh2_sftp_unlink_ex.3 | 3 ++- docs/libssh2_sftp_write.3 | 8 ++++--- docs/libssh2_sign_sk.3 | 18 ++++++++------- docs/libssh2_trace.3 | 6 +++-- docs/libssh2_trace_sethandler.3 | 8 ++++--- docs/libssh2_userauth_authenticated.3 | 3 ++- docs/libssh2_userauth_banner.3 | 1 + docs/libssh2_userauth_hostbased_fromfile.3 | 11 +++++++-- docs/libssh2_userauth_hostbased_fromfile_ex.3 | 3 ++- docs/libssh2_userauth_keyboard_interactive.3 | 5 ++-- ...libssh2_userauth_keyboard_interactive_ex.3 | 17 +++++++------- docs/libssh2_userauth_list.3 | 4 +++- docs/libssh2_userauth_password.3 | 10 ++++---- docs/libssh2_userauth_password_ex.3 | 23 +++++++++++-------- docs/libssh2_userauth_publickey.3 | 16 +++++++------ docs/libssh2_userauth_publickey_fromfile.3 | 3 ++- docs/libssh2_userauth_publickey_fromfile_ex.3 | 20 ++++++++-------- docs/libssh2_userauth_publickey_frommemory.3 | 20 ++++++++-------- docs/libssh2_userauth_publickey_sk.3 | 22 +++++++++--------- docs/libssh2_version.3 | 2 ++ docs/template.3 | 5 ++-- 176 files changed, 761 insertions(+), 358 deletions(-) diff --git a/docs/libssh2_agent_connect.3 b/docs/libssh2_agent_connect.3 index 6482c66fde..491ca06d5b 100644 --- a/docs/libssh2_agent_connect.3 +++ b/docs/libssh2_agent_connect.3 @@ -5,9 +5,12 @@ .SH NAME libssh2_agent_connect - connect to an ssh-agent .SH SYNOPSIS +.nf #include -int libssh2_agent_connect(LIBSSH2_AGENT *agent); +int +libssh2_agent_connect(LIBSSH2_AGENT *agent); +.fi .SH DESCRIPTION Connect to an ssh-agent running on the system. diff --git a/docs/libssh2_agent_disconnect.3 b/docs/libssh2_agent_disconnect.3 index f9f9ef0749..41eb1d40ab 100644 --- a/docs/libssh2_agent_disconnect.3 +++ b/docs/libssh2_agent_disconnect.3 @@ -5,9 +5,12 @@ .SH NAME libssh2_agent_disconnect - close a connection to an ssh-agent .SH SYNOPSIS +.nf #include -int libssh2_agent_disconnect(LIBSSH2_AGENT *agent); +int +libssh2_agent_disconnect(LIBSSH2_AGENT *agent); +.fi .SH DESCRIPTION Close a connection to an ssh-agent. diff --git a/docs/libssh2_agent_free.3 b/docs/libssh2_agent_free.3 index 197f87eb9e..2f18cc8d7b 100644 --- a/docs/libssh2_agent_free.3 +++ b/docs/libssh2_agent_free.3 @@ -5,9 +5,12 @@ .SH NAME libssh2_agent_free - free an ssh-agent handle .SH SYNOPSIS +.nf #include -void libssh2_agent_free(LIBSSH2_AGENT *agent); +void +libssh2_agent_free(LIBSSH2_AGENT *agent); +.fi .SH DESCRIPTION Free an ssh-agent handle. This function also frees the internal collection of public keys. diff --git a/docs/libssh2_agent_get_identity.3 b/docs/libssh2_agent_get_identity.3 index a94416566f..c4a33fa9c5 100644 --- a/docs/libssh2_agent_get_identity.3 +++ b/docs/libssh2_agent_get_identity.3 @@ -5,11 +5,14 @@ .SH NAME libssh2_agent_get_identity - get a public key off the collection of public keys managed by ssh-agent .SH SYNOPSIS +.nf #include -int libssh2_agent_get_identity(LIBSSH2_AGENT *agent, - struct libssh2_agent_publickey **store, - struct libssh2_agent_publickey *prev); +int +libssh2_agent_get_identity(LIBSSH2_AGENT *agent, + struct libssh2_agent_publickey **store, + struct libssh2_agent_publickey *prev); +.fi .SH DESCRIPTION \fIlibssh2_agent_get_identity(3)\fP allows an application to iterate over all public keys in the collection managed by ssh-agent. diff --git a/docs/libssh2_agent_get_identity_path.3 b/docs/libssh2_agent_get_identity_path.3 index 1cbdf7aed4..748995da9e 100644 --- a/docs/libssh2_agent_get_identity_path.3 +++ b/docs/libssh2_agent_get_identity_path.3 @@ -5,10 +5,12 @@ .SH NAME libssh2_agent_get_identity_path - gets the custom ssh-agent socket path .SH SYNOPSIS +.nf #include const char * libssh2_agent_get_identity_path(LIBSSH2_AGENT *agent); +.fi .SH DESCRIPTION Returns the custom agent identity socket path if set using libssh2_agent_set_identity_path() diff --git a/docs/libssh2_agent_init.3 b/docs/libssh2_agent_init.3 index 26e891e42b..4b25508f35 100644 --- a/docs/libssh2_agent_init.3 +++ b/docs/libssh2_agent_init.3 @@ -5,9 +5,12 @@ .SH NAME libssh2_agent_init - init an ssh-agent handle .SH SYNOPSIS +.nf #include -LIBSSH2_AGENT *libssh2_agent_init(LIBSSH2_SESSION *session); +LIBSSH2_AGENT * +libssh2_agent_init(LIBSSH2_SESSION *session); +.fi .SH DESCRIPTION Init an ssh-agent handle. Returns the handle to an internal representation of an ssh-agent connection. After the successful diff --git a/docs/libssh2_agent_list_identities.3 b/docs/libssh2_agent_list_identities.3 index 48a1d6c1fe..e1d7c40dcd 100644 --- a/docs/libssh2_agent_list_identities.3 +++ b/docs/libssh2_agent_list_identities.3 @@ -5,9 +5,12 @@ .SH NAME libssh2_agent_list_identities - request an ssh-agent to list of public keys. .SH SYNOPSIS +.nf #include -int libssh2_agent_list_identities(LIBSSH2_AGENT *agent); +int +libssh2_agent_list_identities(LIBSSH2_AGENT *agent); +.fi .SH DESCRIPTION Request an ssh-agent to list of public keys, and stores them in the internal collection of the handle. Call diff --git a/docs/libssh2_agent_set_identity_path.3 b/docs/libssh2_agent_set_identity_path.3 index 2d75b7916c..6ee425999a 100644 --- a/docs/libssh2_agent_set_identity_path.3 +++ b/docs/libssh2_agent_set_identity_path.3 @@ -5,10 +5,12 @@ .SH NAME libssh2_agent_set_identity_path - set an ssh-agent socket path on disk .SH SYNOPSIS +.nf #include void libssh2_agent_set_identity_path(LIBSSH2_AGENT *agent, const char *path); +.fi .SH DESCRIPTION Allows a custom agent identity socket path instead of the default SSH_AUTH_SOCK env value diff --git a/docs/libssh2_agent_userauth.3 b/docs/libssh2_agent_userauth.3 index 8524884a2c..8513e6513f 100644 --- a/docs/libssh2_agent_userauth.3 +++ b/docs/libssh2_agent_userauth.3 @@ -5,11 +5,14 @@ .SH NAME libssh2_agent_userauth - authenticate a session with a public key, with the help of ssh-agent .SH SYNOPSIS +.nf #include -int libssh2_agent_userauth(LIBSSH2_AGENT *agent, - const char *username, - struct libssh2_agent_publickey *identity); +int +libssh2_agent_userauth(LIBSSH2_AGENT *agent, + const char *username, + struct libssh2_agent_publickey *identity); +.fi .SH DESCRIPTION \fIagent\fP - ssh-agent handle as returned by .BR libssh2_agent_init(3) diff --git a/docs/libssh2_banner_set.3 b/docs/libssh2_banner_set.3 index 04f6ef58c4..c6e874de73 100644 --- a/docs/libssh2_banner_set.3 +++ b/docs/libssh2_banner_set.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_banner_set - set the SSH protocol banner for the local client .SH SYNOPSIS +.nf #include int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner); - +.fi .SH DESCRIPTION This function is \fBDEPRECATED\fP. Use \fIlibssh2_session_banner_set(3)\fP instead! diff --git a/docs/libssh2_base64_decode.3 b/docs/libssh2_base64_decode.3 index 932f03a8b9..c05fbec357 100644 --- a/docs/libssh2_base64_decode.3 +++ b/docs/libssh2_base64_decode.3 @@ -2,11 +2,14 @@ .SH NAME libssh2_base64_decode - decode a base64 encoded string .SH SYNOPSIS +.nf #include -int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, - unsigned int *dest_len, const char *src, - unsigned int src_len); +int +libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, + unsigned int *dest_len, const char *src, + unsigned int src_len); +.fi .SH DESCRIPTION This function is deemed DEPRECATED and will be removed from libssh2 in a future version. Don't use it! diff --git a/docs/libssh2_channel_close.3 b/docs/libssh2_channel_close.3 index b493395a2f..1c6ef6f90b 100644 --- a/docs/libssh2_channel_close.3 +++ b/docs/libssh2_channel_close.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_close - close a channel .SH SYNOPSIS +.nf #include int libssh2_channel_close(LIBSSH2_CHANNEL *channel); - +.fi .SH DESCRIPTION \fIchannel\fP - active channel stream to set closed status on. diff --git a/docs/libssh2_channel_direct_streamlocal_ex.3 b/docs/libssh2_channel_direct_streamlocal_ex.3 index c39b039b66..c28f68d7a9 100644 --- a/docs/libssh2_channel_direct_streamlocal_ex.3 +++ b/docs/libssh2_channel_direct_streamlocal_ex.3 @@ -2,14 +2,14 @@ .SH NAME libssh2_channel_direct_streamlocal_ex - Tunnel a UNIX socket connection through an SSH session .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * -libssh2_channel_direct_streamlocal_ex(LIBSSH2_SESSION *session, const char *socket_path, const char *shost, int sport); - -LIBSSH2_CHANNEL * -libssh2_channel_direct_streamlocal(LIBSSH2_SESSION *session, const char *socket_path, const char *shost, int sport); - +libssh2_channel_direct_streamlocal_ex(LIBSSH2_SESSION *session, + const char *socket_path, + const char *shost, int sport); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_channel_direct_tcpip.3 b/docs/libssh2_channel_direct_tcpip.3 index 742769df3b..81c495df62 100644 --- a/docs/libssh2_channel_direct_tcpip.3 +++ b/docs/libssh2_channel_direct_tcpip.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_channel_direct_tcpip - convenience macro for \fIlibssh2_channel_direct_tcpip_ex(3)\fP calls .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * -libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session, const char *host, int port); - +libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session, + const char *host, int port); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_direct_tcpip_ex(3)\fP. diff --git a/docs/libssh2_channel_direct_tcpip_ex.3 b/docs/libssh2_channel_direct_tcpip_ex.3 index 5959bc9398..229635991e 100644 --- a/docs/libssh2_channel_direct_tcpip_ex.3 +++ b/docs/libssh2_channel_direct_tcpip_ex.3 @@ -2,14 +2,18 @@ .SH NAME libssh2_channel_direct_tcpip_ex - Tunnel a TCP connection through an SSH session .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * -libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, int port, const char *shost, int sport); +libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, + const char *host, int port, + const char *shost, int sport); LIBSSH2_CHANNEL * -libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session, const char *host, int port); - +libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session, + const char *host, int port); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_channel_eof.3 b/docs/libssh2_channel_eof.3 index 9ddc108117..d948eece17 100644 --- a/docs/libssh2_channel_eof.3 +++ b/docs/libssh2_channel_eof.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_eof - check a channel's EOF status .SH SYNOPSIS +.nf #include int libssh2_channel_eof(LIBSSH2_CHANNEL *channel); +.fi .SH DESCRIPTION \fIchannel\fP - active channel stream to set closed status on. diff --git a/docs/libssh2_channel_exec.3 b/docs/libssh2_channel_exec.3 index 3ab069d78c..312372cd62 100644 --- a/docs/libssh2_channel_exec.3 +++ b/docs/libssh2_channel_exec.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_exec - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_exec(LIBSSH2_CHANNEL *channel, const char *command); - +int +libssh2_channel_exec(LIBSSH2_CHANNEL *channel, const char *command); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_process_startup(3)\fP. diff --git a/docs/libssh2_channel_flush.3 b/docs/libssh2_channel_flush.3 index b449945b87..3e9c4fd0cd 100644 --- a/docs/libssh2_channel_flush.3 +++ b/docs/libssh2_channel_flush.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_flush - convenience macro for \fIlibssh2_channel_flush_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_flush(LIBSSH2_CHANNEL *channel); - +int +libssh2_channel_flush(LIBSSH2_CHANNEL *channel); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_flush_ex(3)\fP. diff --git a/docs/libssh2_channel_flush_ex.3 b/docs/libssh2_channel_flush_ex.3 index 61b351ab40..af5c48d3a5 100644 --- a/docs/libssh2_channel_flush_ex.3 +++ b/docs/libssh2_channel_flush_ex.3 @@ -2,6 +2,7 @@ .SH NAME libssh2_channel_flush_ex - flush a channel .SH SYNOPSIS +.nf #include int @@ -12,7 +13,7 @@ libssh2_channel_flush(LIBSSH2_CHANNEL *channel); int libssh2_channel_flush_stderr(LIBSSH2_CHANNEL *channel); - +.fi .SH DESCRIPTION \fIchannel\fP - Active channel stream to flush. diff --git a/docs/libssh2_channel_flush_stderr.3 b/docs/libssh2_channel_flush_stderr.3 index 156bb06f2c..b211c1b133 100644 --- a/docs/libssh2_channel_flush_stderr.3 +++ b/docs/libssh2_channel_flush_stderr.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_flush_stderr - convenience macro for \fIlibssh2_channel_flush_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_flush_stderr(LIBSSH2_CHANNEL *channel); - +int +libssh2_channel_flush_stderr(LIBSSH2_CHANNEL *channel); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_flush_ex(3)\fP. diff --git a/docs/libssh2_channel_forward_accept.3 b/docs/libssh2_channel_forward_accept.3 index 176ac1cddc..fdf82a85e8 100644 --- a/docs/libssh2_channel_forward_accept.3 +++ b/docs/libssh2_channel_forward_accept.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_forward_accept - accept a queued connection .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener); - +.fi .SH DESCRIPTION \fIlistener\fP is a forwarding listener instance as returned by \fBlibssh2_channel_forward_listen_ex(3)\fP. diff --git a/docs/libssh2_channel_forward_cancel.3 b/docs/libssh2_channel_forward_cancel.3 index 1bb4c03741..5663c0ab7c 100644 --- a/docs/libssh2_channel_forward_cancel.3 +++ b/docs/libssh2_channel_forward_cancel.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_forward_cancel - cancel a forwarded TCP port .SH SYNOPSIS +.nf #include int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener); - +.fi .SH DESCRIPTION \fIlistener\fP - Forwarding listener instance as returned by .BR libssh2_channel_forward_listen_ex(3) diff --git a/docs/libssh2_channel_forward_listen.3 b/docs/libssh2_channel_forward_listen.3 index 6cb54e73b3..a5494a6d9d 100644 --- a/docs/libssh2_channel_forward_listen.3 +++ b/docs/libssh2_channel_forward_listen.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_forward_listen - convenience macro for \fIlibssh2_channel_forward_listen_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_forward_listen(LIBSSH2_SESSION *session, int port); - +int +libssh2_channel_forward_listen(LIBSSH2_SESSION *session, int port); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_forward_listen_ex(3)\fP. diff --git a/docs/libssh2_channel_forward_listen_ex.3 b/docs/libssh2_channel_forward_listen_ex.3 index 22154996f8..14f598af7a 100644 --- a/docs/libssh2_channel_forward_listen_ex.3 +++ b/docs/libssh2_channel_forward_listen_ex.3 @@ -2,14 +2,17 @@ .SH NAME libssh2_channel_forward_listen_ex - listen to inbound connections .SH SYNOPSIS +.nf #include LIBSSH2_LISTENER * -libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, char *host, int port, int *bound_port, int queue_maxsize); +libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, + char *host, int port, + int *bound_port, int queue_maxsize); LIBSSH2_LISTENER * libssh2_channel_forward_listen(LIBSSH2_SESSION *session, int port); - +.fi .SH DESCRIPTION Instruct the remote SSH server to begin listening for inbound TCP/IP connections. New connections will be queued by the library until accepted by diff --git a/docs/libssh2_channel_free.3 b/docs/libssh2_channel_free.3 index 9013a4a2f9..d0ded79856 100644 --- a/docs/libssh2_channel_free.3 +++ b/docs/libssh2_channel_free.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_free - free all resources associated with a channel .SH SYNOPSIS +.nf #include int libssh2_channel_free(LIBSSH2_CHANNEL *channel); - +.fi .SH DESCRIPTION \fIchannel\fP - Channel stream to free. diff --git a/docs/libssh2_channel_get_exit_signal.3 b/docs/libssh2_channel_get_exit_signal.3 index 1dc83f8e37..d2b46c7193 100644 --- a/docs/libssh2_channel_get_exit_signal.3 +++ b/docs/libssh2_channel_get_exit_signal.3 @@ -2,11 +2,15 @@ .SH NAME libssh2_channel_get_exit_signal - get the remote exit signal .SH SYNOPSIS +.nf #include int -libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel, char **exitsignal, size_t *exitsignal_len, char **errmsg, size_t *errmsg_len, char **langtag, size_t *langtag_len); - +libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel, + char **exitsignal, size_t *exitsignal_len, + char **errmsg, size_t *errmsg_len, + char **langtag, size_t *langtag_len); +.fi .SH DESCRIPTION \fIchannel\fP - Closed channel stream to retrieve exit signal from. diff --git a/docs/libssh2_channel_get_exit_status.3 b/docs/libssh2_channel_get_exit_status.3 index 24ceb3bd71..e619bc8b96 100644 --- a/docs/libssh2_channel_get_exit_status.3 +++ b/docs/libssh2_channel_get_exit_status.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_get_exit_status - get the remote exit code .SH SYNOPSIS +.nf #include int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel) - +.fi .SH DESCRIPTION \fIchannel\fP - Closed channel stream to retrieve exit status from. diff --git a/docs/libssh2_channel_handle_extended_data.3 b/docs/libssh2_channel_handle_extended_data.3 index d996477651..8adc6cb923 100644 --- a/docs/libssh2_channel_handle_extended_data.3 +++ b/docs/libssh2_channel_handle_extended_data.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_channel_handle_extended_data - set extended data handling mode .SH SYNOPSIS +.nf #include void -libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode); - +libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, + int ignore_mode); +.fi .SH DESCRIPTION This function is deprecated. Use the \fIlibssh2_channel_handle_extended_data2(3)\fP function instead! diff --git a/docs/libssh2_channel_handle_extended_data2.3 b/docs/libssh2_channel_handle_extended_data2.3 index a090e435b6..0988873b3f 100644 --- a/docs/libssh2_channel_handle_extended_data2.3 +++ b/docs/libssh2_channel_handle_extended_data2.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_channel_handle_extended_data2 - set extended data handling mode .SH SYNOPSIS +.nf #include int -libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, int ignore_mode); - +libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, + int ignore_mode); +.fi .SH DESCRIPTION \fIchannel\fP - Active channel stream to change extended data handling on. diff --git a/docs/libssh2_channel_ignore_extended_data.3 b/docs/libssh2_channel_ignore_extended_data.3 index 342c620836..5f49abbaf6 100644 --- a/docs/libssh2_channel_ignore_extended_data.3 +++ b/docs/libssh2_channel_ignore_extended_data.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_channel_ignore_extended_data - convenience macro for \fIlibssh2_channel_handle_extended_data(3)\fP calls .SH SYNOPSIS +.nf #include -libssh2_channel_ignore_extended_data(arguments) - +void +libssh2_channel_ignore_extended_data(LIBSSH2_CHANNEL *channel, + int ignore_mode); +.fi .SH DESCRIPTION This function is deprecated. Use the \fIlibssh2_channel_handle_extended_data2(3)\fP function instead! diff --git a/docs/libssh2_channel_open_ex.3 b/docs/libssh2_channel_open_ex.3 index aeacb1afde..f978675e50 100644 --- a/docs/libssh2_channel_open_ex.3 +++ b/docs/libssh2_channel_open_ex.3 @@ -2,14 +2,19 @@ .SH NAME libssh2_channel_open_ex - establish a generic session channel .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * -libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type, unsigned int channel_type_len, unsigned int window_size, unsigned int packet_size, const char *message, unsigned int message_len); +libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type, + unsigned int channel_type_len, + unsigned int window_size, + unsigned int packet_size, + const char *message, unsigned int message_len); LIBSSH2_CHANNEL * libssh2_channel_open_session(session); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_channel_open_session.3 b/docs/libssh2_channel_open_session.3 index 4306f4ccd7..83e5e6205e 100644 --- a/docs/libssh2_channel_open_session.3 +++ b/docs/libssh2_channel_open_session.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_open_session - convenience macro for \fIlibssh2_channel_open_ex(3)\fP calls .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * libssh2_channel_open_session(LIBSSH2_SESSION *session); - +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_open_ex(3)\fP. diff --git a/docs/libssh2_channel_process_startup.3 b/docs/libssh2_channel_process_startup.3 index b215e2fa56..e1cf436ca2 100644 --- a/docs/libssh2_channel_process_startup.3 +++ b/docs/libssh2_channel_process_startup.3 @@ -5,11 +5,13 @@ libssh2_channel_process_startup - request a shell on a channel .nf #include -int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, - const char *request, - unsigned int request_len, - const char *message, - unsigned int message_len); +int +libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, + const char *request, + unsigned int request_len, + const char *message, + unsigned int message_len); +.fi .SH DESCRIPTION \fIchannel\fP - Active session channel instance. diff --git a/docs/libssh2_channel_read.3 b/docs/libssh2_channel_read.3 index f185716751..80966e2881 100644 --- a/docs/libssh2_channel_read.3 +++ b/docs/libssh2_channel_read.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_channel_read - convenience macro for \fIlibssh2_channel_read_ex(3)\fP calls .SH SYNOPSIS +.nf #include -ssize_t libssh2_channel_read(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen); - +ssize_t +libssh2_channel_read(LIBSSH2_CHANNEL *channel, + char *buf, size_t buflen); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_read_ex(3)\fP. diff --git a/docs/libssh2_channel_read_ex.3 b/docs/libssh2_channel_read_ex.3 index bc021a45ad..7f895999ee 100644 --- a/docs/libssh2_channel_read_ex.3 +++ b/docs/libssh2_channel_read_ex.3 @@ -2,17 +2,21 @@ .SH NAME libssh2_channel_read_ex - read data from a channel stream .SH SYNOPSIS +.nf #include ssize_t -libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, size_t buflen); +libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, + char *buf, size_t buflen); ssize_t -libssh2_channel_read(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen); +libssh2_channel_read(LIBSSH2_CHANNEL *channel, + char *buf, size_t buflen); ssize_t -libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen); - +libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel, + char *buf, size_t buflen); +.fi .SH DESCRIPTION Attempt to read data from an active channel stream. All channel streams have one standard I/O substream (stream_id == 0), and may have up to 2^32 extended diff --git a/docs/libssh2_channel_read_stderr.3 b/docs/libssh2_channel_read_stderr.3 index 9324410b43..e23e47b406 100644 --- a/docs/libssh2_channel_read_stderr.3 +++ b/docs/libssh2_channel_read_stderr.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_channel_read_stderr - convenience macro for \fIlibssh2_channel_read_ex(3)\fP calls .SH SYNOPSIS +.nf #include -ssize_t libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen); - +ssize_t +libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel, + char *buf, size_t buflen); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_read_ex(3)\fP. diff --git a/docs/libssh2_channel_receive_window_adjust.3 b/docs/libssh2_channel_receive_window_adjust.3 index a7288118f4..731558fc2e 100644 --- a/docs/libssh2_channel_receive_window_adjust.3 +++ b/docs/libssh2_channel_receive_window_adjust.3 @@ -2,13 +2,14 @@ .SH NAME libssh2_channel_receive_window_adjust - adjust the channel window .SH SYNOPSIS +.nf #include unsigned long libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, unsigned long adjustment, unsigned char force); - +.fi .SH DESCRIPTION This function is deprecated in 1.1. Use \fIlibssh2_channel_receive_window_adjust2(3)\fP! diff --git a/docs/libssh2_channel_receive_window_adjust2.3 b/docs/libssh2_channel_receive_window_adjust2.3 index dd2fcc1e94..e4681f78ee 100644 --- a/docs/libssh2_channel_receive_window_adjust2.3 +++ b/docs/libssh2_channel_receive_window_adjust2.3 @@ -2,6 +2,7 @@ .SH NAME libssh2_channel_receive_window_adjust2 - adjust the channel window .SH SYNOPSIS +.nf #include int @@ -9,7 +10,7 @@ libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL * channel, unsigned long adjustment, unsigned char force, unsigned int *window); - +.fi .SH DESCRIPTION Adjust the receive window for a channel by adjustment bytes. If the amount to be adjusted is less than LIBSSH2_CHANNEL_MINADJUST and force is 0 the diff --git a/docs/libssh2_channel_request_auth_agent.3 b/docs/libssh2_channel_request_auth_agent.3 index ea76a48bce..22f988d697 100644 --- a/docs/libssh2_channel_request_auth_agent.3 +++ b/docs/libssh2_channel_request_auth_agent.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_request_auth_agent - request agent forwarding for a session .SH SYNOPSIS +.nf #include int libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel); - +.fi .SH DESCRIPTION Request that agent forwarding be enabled for this SSH session. This sends the request over this specific channel, which causes the agent listener to be diff --git a/docs/libssh2_channel_request_pty.3 b/docs/libssh2_channel_request_pty.3 index f57352b28b..4adb846a4b 100644 --- a/docs/libssh2_channel_request_pty.3 +++ b/docs/libssh2_channel_request_pty.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_request_pty - convenience macro for \fIlibssh2_channel_request_pty_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_request_pty(LIBSSH2_SESSION *session, const char *term); - +int +libssh2_channel_request_pty(LIBSSH2_SESSION *session, const char *term); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_request_pty_ex(3)\fP. diff --git a/docs/libssh2_channel_request_pty_ex.3 b/docs/libssh2_channel_request_pty_ex.3 index 11dda5bb5e..933cdf2f1e 100644 --- a/docs/libssh2_channel_request_pty_ex.3 +++ b/docs/libssh2_channel_request_pty_ex.3 @@ -2,14 +2,19 @@ .SH NAME libssh2_channel_request_pty_ex - short function description .SH SYNOPSIS +.nf #include int -libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel, const char *term, unsigned int term_len, const char *modes, unsigned int modes_len, int width, int height, int width_px, int height_px); +libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel, const char *term, + unsigned int term_len, + const char *modes, unsigned int modes_len, + int width, int height, + int width_px, int height_px); int -libssh2_channel_request_pty(LIBSSH2_CHANNEL *channel, char *term); - +libssh2_channel_request_pty(LIBSSH2_CHANNEL *channel, const char *term); +.fi .SH DESCRIPTION \fIchannel\fP - Previously opened channel instance such as returned by .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_channel_request_pty_size.3 b/docs/libssh2_channel_request_pty_size.3 index 4b0c12df40..fd58bd3636 100644 --- a/docs/libssh2_channel_request_pty_size.3 +++ b/docs/libssh2_channel_request_pty_size.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_channel_request_pty_size - convenience macro for \fIlibssh2_channel_request_pty_size_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_request_pty_size(LIBSSH2_CHANNEL *channel, int width, int height); - +int +libssh2_channel_request_pty_size(LIBSSH2_CHANNEL *channel, + int width, int height); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_request_pty_size_ex(3)\fP. diff --git a/docs/libssh2_channel_request_pty_size_ex.3 b/docs/libssh2_channel_request_pty_size_ex.3 index b3cd6197ff..ca172a148a 100644 --- a/docs/libssh2_channel_request_pty_size_ex.3 +++ b/docs/libssh2_channel_request_pty_size_ex.3 @@ -2,7 +2,8 @@ .SH NAME libssh2_channel_request_pty_size_ex - TODO .SH SYNOPSIS - +.nf +.fi .SH DESCRIPTION .SH RETURN VALUE diff --git a/docs/libssh2_channel_send_eof.3 b/docs/libssh2_channel_send_eof.3 index 025ef73261..6dc0286018 100644 --- a/docs/libssh2_channel_send_eof.3 +++ b/docs/libssh2_channel_send_eof.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_send_eof - send EOF to remote server .SH SYNOPSIS +.nf #include int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel); - +.fi .SH DESCRIPTION Tell the remote host that no further data will be sent on the specified channel. Processes typically interpret this as a closed stdin descriptor. diff --git a/docs/libssh2_channel_set_blocking.3 b/docs/libssh2_channel_set_blocking.3 index 9ebb7a6ba3..4c61b14a83 100644 --- a/docs/libssh2_channel_set_blocking.3 +++ b/docs/libssh2_channel_set_blocking.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_set_blocking - set or clear blocking mode on channel .SH SYNOPSIS +.nf #include void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking); +.fi .SH DESCRIPTION \fIchannel\fP - channel stream to set or clean blocking status on. diff --git a/docs/libssh2_channel_setenv.3 b/docs/libssh2_channel_setenv.3 index b30d471019..e9d553b7e7 100644 --- a/docs/libssh2_channel_setenv.3 +++ b/docs/libssh2_channel_setenv.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_channel_setenv - convenience macro for \fIlibssh2_channel_setenv_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_setenv(LIBSSH2_CHANNEL *channel, const char *varname, const char *value); - +int +libssh2_channel_setenv(LIBSSH2_CHANNEL *channel, + const char *varname, const char *value); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_setenv_ex(3)\fP. diff --git a/docs/libssh2_channel_setenv_ex.3 b/docs/libssh2_channel_setenv_ex.3 index b16dd01fb0..c01b94b059 100644 --- a/docs/libssh2_channel_setenv_ex.3 +++ b/docs/libssh2_channel_setenv_ex.3 @@ -2,14 +2,18 @@ .SH NAME libssh2_channel_setenv_ex - set an environment variable on the channel .SH SYNOPSIS +.nf #include int -libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel, char *varname, unsigned int varname_len, const char *value, unsigned int value_len); +libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel, + char *varname, unsigned int varname_len, + const char *value, unsigned int value_len); int -libssh2_channel_setenv(LIBSSH2_CHANNEL *channel, char *varname, const char *value); - +libssh2_channel_setenv(LIBSSH2_CHANNEL *channel, + char *varname, const char *value); +.fi .SH DESCRIPTION \fIchannel\fP - Previously opened channel instance such as returned by .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_channel_shell.3 b/docs/libssh2_channel_shell.3 index 4ba6e69d7a..bbff5b6963 100644 --- a/docs/libssh2_channel_shell.3 +++ b/docs/libssh2_channel_shell.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_shell - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_shell(LIBSSH2_CHANNEL *channel); - +int +libssh2_channel_shell(LIBSSH2_CHANNEL *channel); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_process_startup(3)\fP. diff --git a/docs/libssh2_channel_subsystem.3 b/docs/libssh2_channel_subsystem.3 index dd29f2c977..6f3b8bcd28 100644 --- a/docs/libssh2_channel_subsystem.3 +++ b/docs/libssh2_channel_subsystem.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_subsystem - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_subsystem(LIBSSH2_CHANNEL *channel, const char *subsystem); - +int +libssh2_channel_subsystem(LIBSSH2_CHANNEL *channel, const char *subsystem); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_process_startup(3)\fP. diff --git a/docs/libssh2_channel_wait_closed.3 b/docs/libssh2_channel_wait_closed.3 index 8cf0911a28..cbd242f994 100644 --- a/docs/libssh2_channel_wait_closed.3 +++ b/docs/libssh2_channel_wait_closed.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_wait_closed - wait for the remote to close the channel .SH SYNOPSIS +.nf #include int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel); - +.fi .SH DESCRIPTION Enter a temporary blocking state until the remote host closes the named channel. Typically sent after \fIlibssh2_channel_close(3)\fP in order to diff --git a/docs/libssh2_channel_wait_eof.3 b/docs/libssh2_channel_wait_eof.3 index ef4d8b70f7..777f9f55dd 100644 --- a/docs/libssh2_channel_wait_eof.3 +++ b/docs/libssh2_channel_wait_eof.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_channel_wait_eof - wait for the remote to reply to an EOF request .SH SYNOPSIS +.nf #include int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel); - +.fi .SH DESCRIPTION Wait for the remote end to send EOF. diff --git a/docs/libssh2_channel_window_read.3 b/docs/libssh2_channel_window_read.3 index 70938d3040..41efb4c8cd 100644 --- a/docs/libssh2_channel_window_read.3 +++ b/docs/libssh2_channel_window_read.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_window_read - convenience macro for \fIlibssh2_channel_window_read_ex(3)\fP calls .SH SYNOPSIS +.nf #include -unsigned long libssh2_channel_window_read(LIBSSH2_CHANNEL *channel); - +unsigned long +libssh2_channel_window_read(LIBSSH2_CHANNEL *channel); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_window_read_ex(3)\fP. diff --git a/docs/libssh2_channel_window_read_ex.3 b/docs/libssh2_channel_window_read_ex.3 index b52809603a..f5cdab35f2 100644 --- a/docs/libssh2_channel_window_read_ex.3 +++ b/docs/libssh2_channel_window_read_ex.3 @@ -2,12 +2,14 @@ .SH NAME libssh2_channel_window_read_ex - Check the status of the read window .SH SYNOPSIS +.nf #include unsigned long libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, unsigned long *read_avail, unsigned long *window_size_initial) +.fi .SH DESCRIPTION Check the status of the read window. Returns the number of bytes which the remote end may send without overflowing the window limit read_avail (if diff --git a/docs/libssh2_channel_window_write.3 b/docs/libssh2_channel_window_write.3 index d8c39930d4..61815eb0aa 100644 --- a/docs/libssh2_channel_window_write.3 +++ b/docs/libssh2_channel_window_write.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_window_write - convenience macro for \fIlibssh2_channel_window_write_ex(3)\fP calls .SH SYNOPSIS +.nf #include -unsigned long libssh2_channel_window_write(LIBSSH2_CHANNEL *channel); - +unsigned long +libssh2_channel_window_write(LIBSSH2_CHANNEL *channel); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_window_write_ex(3)\fP. diff --git a/docs/libssh2_channel_window_write_ex.3 b/docs/libssh2_channel_window_write_ex.3 index d34cd4082c..2803d5b890 100644 --- a/docs/libssh2_channel_window_write_ex.3 +++ b/docs/libssh2_channel_window_write_ex.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_channel_window_write_ex - Check the status of the write window .SH SYNOPSIS +.nf #include unsigned long libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel, unsigned long *window_size_initial) +.fi .SH DESCRIPTION Check the status of the write window Returns the number of bytes which may be safely written on the channel without blocking. 'window_size_initial' (if diff --git a/docs/libssh2_channel_write.3 b/docs/libssh2_channel_write.3 index b9de747fd4..dd463be2dd 100644 --- a/docs/libssh2_channel_write.3 +++ b/docs/libssh2_channel_write.3 @@ -5,8 +5,10 @@ libssh2_channel_write - convenience macro for \fIlibssh2_channel_write_ex(3)\fP .nf #include -ssize_t libssh2_channel_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t buflen); - +ssize_t +libssh2_channel_write(LIBSSH2_CHANNEL *channel, + const char *buf, size_t buflen); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_write_ex(3)\fP. diff --git a/docs/libssh2_channel_write_ex.3 b/docs/libssh2_channel_write_ex.3 index 1ede81e6e2..0abf3c1283 100644 --- a/docs/libssh2_channel_write_ex.3 +++ b/docs/libssh2_channel_write_ex.3 @@ -5,9 +5,11 @@ libssh2_channel_write_ex - write data to a channel stream blocking .nf #include -ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, - int stream_id, char *buf, - size_t buflen); +ssize_t +libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, + int stream_id, char *buf, + size_t buflen); +.fi .SH DESCRIPTION Write data to a channel stream. All channel streams have one standard I/O substream (stream_id == 0), and may have up to 2^32 extended data streams as diff --git a/docs/libssh2_channel_write_stderr.3 b/docs/libssh2_channel_write_stderr.3 index ac4d3874d7..89a6088375 100644 --- a/docs/libssh2_channel_write_stderr.3 +++ b/docs/libssh2_channel_write_stderr.3 @@ -5,8 +5,10 @@ libssh2_channel_write_stderr - convenience macro for \fIlibssh2_channel_write_ex .nf #include -ssize_t libssh2_channel_write_stderr(LIBSSH2_CHANNEL *channel, const char *buf, size_t buflen); - +ssize_t +libssh2_channel_write_stderr(LIBSSH2_CHANNEL *channel, + const char *buf, size_t buflen); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_write_ex(3)\fP. diff --git a/docs/libssh2_channel_x11_req.3 b/docs/libssh2_channel_x11_req.3 index c558e4088d..dfd71aac71 100644 --- a/docs/libssh2_channel_x11_req.3 +++ b/docs/libssh2_channel_x11_req.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_channel_x11_req - convenience macro for \fIlibssh2_channel_x11_req_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_channel_x11_req(LIBSSH2_CHANNEL *channel, int screen_number); - +int +libssh2_channel_x11_req(LIBSSH2_CHANNEL *channel, int screen_number); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_channel_x11_req_ex(3)\fP. diff --git a/docs/libssh2_channel_x11_req_ex.3 b/docs/libssh2_channel_x11_req_ex.3 index 33c3c76c47..32121e18ba 100644 --- a/docs/libssh2_channel_x11_req_ex.3 +++ b/docs/libssh2_channel_x11_req_ex.3 @@ -2,14 +2,18 @@ .SH NAME libssh2_channel_x11_req_ex - request an X11 forwarding channel .SH SYNOPSIS +.nf #include int -libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection, const char *auth_proto, const char *auth_cookie, int screen_number); +libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection, + const char *auth_proto, const char *auth_cookie, + int screen_number); int -libssh2_channel_x11_req(LIBSSH2_CHANNEL *channel, int screen_number); - +libssh2_channel_x11_req(LIBSSH2_CHANNEL *channel, + int screen_number); +.fi .SH DESCRIPTION \fIchannel\fP - Previously opened channel instance such as returned by .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_crypto_engine.3 b/docs/libssh2_crypto_engine.3 index 268ac0e517..c1d95eafd0 100644 --- a/docs/libssh2_crypto_engine.3 +++ b/docs/libssh2_crypto_engine.3 @@ -1,11 +1,13 @@ .TH libssh2_crypto_engine 3 "22 Nov 2021" "libssh2 1.11" "libssh2 manual" .SH NAME - - retrieve used crypto engine +libssh2_crypto_engine - retrieve used crypto engine .SH SYNOPSIS +.nf #include libssh2_crypto_engine_t -libssh2_crypto_engine(); +libssh2_crypto_engine(void); +.fi .SH DESCRIPTION Returns currently used crypto engine, as en enum value. .SH AVAILABILITY diff --git a/docs/libssh2_exit.3 b/docs/libssh2_exit.3 index 2e7afd7386..cfab6518c0 100644 --- a/docs/libssh2_exit.3 +++ b/docs/libssh2_exit.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_exit - global library deinitialization .SH SYNOPSIS +.nf #include void libssh2_exit(void); +.fi .SH DESCRIPTION Exit the libssh2 functions and free's all memory used internal. .SH AVAILABILITY diff --git a/docs/libssh2_free.3 b/docs/libssh2_free.3 index 30176d5843..db494e7df1 100644 --- a/docs/libssh2_free.3 +++ b/docs/libssh2_free.3 @@ -1,11 +1,13 @@ -.TH libssh2_exit 3 "13 Oct 2010" "libssh2 1.2.8" "libssh2 manual" +.TH libssh2_free 3 "13 Oct 2010" "libssh2 1.2.8" "libssh2 manual" .SH NAME libssh2_free - deallocate libssh2 memory .SH SYNOPSIS +.nf #include void libssh2_free(LIBSSH2_SESSION *session, void *ptr); +.fi .SH DESCRIPTION Deallocate memory allocated by earlier call to libssh2 functions. It uses the memory allocation callbacks provided by the application, if diff --git a/docs/libssh2_hostkey_hash.3 b/docs/libssh2_hostkey_hash.3 index 12f3726105..663a00f835 100644 --- a/docs/libssh2_hostkey_hash.3 +++ b/docs/libssh2_hostkey_hash.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_hostkey_hash - return a hash of the remote host's key .SH SYNOPSIS +.nf #include const char * libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_init.3 b/docs/libssh2_init.3 index 416a78937c..0adff7ba00 100644 --- a/docs/libssh2_init.3 +++ b/docs/libssh2_init.3 @@ -2,12 +2,14 @@ .SH NAME libssh2_init - global library initialization .SH SYNOPSIS +.nf #include #define LIBSSH2_INIT_NO_CRYPTO 0x0001 int libssh2_init(int flags); +.fi .SH DESCRIPTION Initialize the libssh2 functions. This typically initialize the crypto library. It uses a global state, and is not thread safe -- you diff --git a/docs/libssh2_keepalive_config.3 b/docs/libssh2_keepalive_config.3 index 62867cf129..698befa721 100644 --- a/docs/libssh2_keepalive_config.3 +++ b/docs/libssh2_keepalive_config.3 @@ -2,12 +2,13 @@ .SH NAME libssh2_keepalive_config - short function description .SH SYNOPSIS -#include .nf +#include -void libssh2_keepalive_config(LIBSSH2_SESSION *session, - int want_reply, - unsigned interval); +void +libssh2_keepalive_config(LIBSSH2_SESSION *session, + int want_reply, + unsigned interval); .fi .SH DESCRIPTION Set how often keepalive messages should be sent. \fBwant_reply\fP indicates diff --git a/docs/libssh2_keepalive_send.3 b/docs/libssh2_keepalive_send.3 index f4f19d1a02..78221efe17 100644 --- a/docs/libssh2_keepalive_send.3 +++ b/docs/libssh2_keepalive_send.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_keepalive_send - short function description .SH SYNOPSIS -#include .nf +#include -int libssh2_keepalive_send(LIBSSH2_SESSION *session, - int *seconds_to_next); +int +libssh2_keepalive_send(LIBSSH2_SESSION *session, + int *seconds_to_next); +.fi .SH DESCRIPTION Send a keepalive message if needed. \fBseconds_to_next\fP indicates how many seconds you can sleep after this call before you need to call it again. diff --git a/docs/libssh2_knownhost_add.3 b/docs/libssh2_knownhost_add.3 index 00a69e0d43..79ea8b78a5 100644 --- a/docs/libssh2_knownhost_add.3 +++ b/docs/libssh2_knownhost_add.3 @@ -1,4 +1,4 @@ - +.\" .\" Copyright (c) 2009, 2010 by Daniel Stenberg .\" .TH libssh2_knownhost_add 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" @@ -8,11 +8,13 @@ libssh2_knownhost_add - add a known host .nf #include -int libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, - char *host, char *salt, - char *key, size_t keylen, - int typemask, - struct libssh2_knownhost **store); +int +libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, + char *host, char *salt, + char *key, size_t keylen, + int typemask, + struct libssh2_knownhost **store); +.fi .SH DESCRIPTION We discourage use of this function as of libssh2 1.2.5. Instead we strongly urge users to use \fIlibssh2_knownhost_addc(3)\fP instead, which as a more diff --git a/docs/libssh2_knownhost_addc.3 b/docs/libssh2_knownhost_addc.3 index 73e262a498..e1575e6b0d 100644 --- a/docs/libssh2_knownhost_addc.3 +++ b/docs/libssh2_knownhost_addc.3 @@ -1,18 +1,21 @@ - +.\" .\" Copyright (c) 2009, 2010 by Daniel Stenberg .\" -.TH libssh2_knownhost_add 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_addc 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" .SH NAME -libssh2_knownhost_add - add a known host +libssh2_knownhost_addc - add a known host .SH SYNOPSIS +.nf #include -int libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts, - char *host, char *salt, - char *key, size_t keylen, - const char *comment, size_t commentlen, - int typemask, - struct libssh2_knownhost **store); +int +libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts, + char *host, char *salt, + char *key, size_t keylen, + const char *comment, size_t commentlen, + int typemask, + struct libssh2_knownhost **store); +.fi .SH DESCRIPTION Adds a known host to the collection of known hosts identified by the 'hosts' handle. diff --git a/docs/libssh2_knownhost_check.3 b/docs/libssh2_knownhost_check.3 index 889392cb5a..3649645984 100644 --- a/docs/libssh2_knownhost_check.3 +++ b/docs/libssh2_knownhost_check.3 @@ -5,13 +5,16 @@ .SH NAME libssh2_knownhost_check - check a host+key against the list of known hosts .SH SYNOPSIS +.nf #include -int libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts, - const char *host, - const char *key, size_t keylen, - int typemask, - struct libssh2_knownhost **knownhost); +int +libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts, + const char *host, + const char *key, size_t keylen, + int typemask, + struct libssh2_knownhost **knownhost); +.fi .SH DESCRIPTION Checks a host and its associated key against the collection of known hosts, and returns info back about the (partially) matched entry. diff --git a/docs/libssh2_knownhost_checkp.3 b/docs/libssh2_knownhost_checkp.3 index 434ed7b335..92e1403fa4 100644 --- a/docs/libssh2_knownhost_checkp.3 +++ b/docs/libssh2_knownhost_checkp.3 @@ -1,17 +1,20 @@ .\" .\" Copyright (c) 2009-2010 by Daniel Stenberg .\" -.TH libssh2_knownhost_check 3 "1 May 2010" "libssh2 1.2.6" "libssh2 manual" +.TH libssh2_knownhost_checkp 3 "1 May 2010" "libssh2 1.2.6" "libssh2 manual" .SH NAME libssh2_knownhost_checkp - check a host+key against the list of known hosts .SH SYNOPSIS +.nf #include -int libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts, - const char *host, int port, - const char *key, size_t keylen, - int typemask, - struct libssh2_knownhost **knownhost); +int +libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts, + const char *host, int port, + const char *key, size_t keylen, + int typemask, + struct libssh2_knownhost **knownhost); +.fi .SH DESCRIPTION Checks a host and its associated key against the collection of known hosts, and returns info back about the (partially) matched entry. diff --git a/docs/libssh2_knownhost_del.3 b/docs/libssh2_knownhost_del.3 index 75a8eaf506..d7cbeff9f1 100644 --- a/docs/libssh2_knownhost_del.3 +++ b/docs/libssh2_knownhost_del.3 @@ -5,10 +5,13 @@ .SH NAME libssh2_knownhost_del - delete a known host entry .SH SYNOPSIS +.nf #include -int libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts, - struct libssh2_knownhost *entry); +int +libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts, + struct libssh2_knownhost *entry); +.fi .SH DESCRIPTION Delete a known host entry from the collection of known hosts. diff --git a/docs/libssh2_knownhost_free.3 b/docs/libssh2_knownhost_free.3 index 8d8bcc2985..01ea209ab1 100644 --- a/docs/libssh2_knownhost_free.3 +++ b/docs/libssh2_knownhost_free.3 @@ -5,9 +5,12 @@ .SH NAME libssh2_knownhost_free - free a collection of known hosts .SH SYNOPSIS +.nf #include -void libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts); +void +libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts); +.fi .SH DESCRIPTION Free a collection of known hosts. .SH RETURN VALUE diff --git a/docs/libssh2_knownhost_get.3 b/docs/libssh2_knownhost_get.3 index d725f8dc26..8a20b4295e 100644 --- a/docs/libssh2_knownhost_get.3 +++ b/docs/libssh2_knownhost_get.3 @@ -5,11 +5,14 @@ .SH NAME libssh2_knownhost_get - get a known host off the collection of known hosts .SH SYNOPSIS +.nf #include -int libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts, - struct libssh2_knownhost **store, - struct libssh2_knownhost *prev): +int +libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts, + struct libssh2_knownhost **store, + struct libssh2_knownhost *prev): +.fi .SH DESCRIPTION \fIlibssh2_knownhost_get(3)\fP allows an application to iterate over all known hosts in the collection. diff --git a/docs/libssh2_knownhost_init.3 b/docs/libssh2_knownhost_init.3 index 145f10ca86..159c7aac37 100644 --- a/docs/libssh2_knownhost_init.3 +++ b/docs/libssh2_knownhost_init.3 @@ -5,9 +5,12 @@ .SH NAME libssh2_knownhost_init - init a collection of known hosts .SH SYNOPSIS +.nf #include -LIBSSH2_KNOWNHOSTS *libssh2_knownhost_init(LIBSSH2_SESSION *session); +LIBSSH2_KNOWNHOSTS * +libssh2_knownhost_init(LIBSSH2_SESSION *session); +.fi .SH DESCRIPTION Init a collection of known hosts for this session. Returns the handle to an internal representation of a known host collection. diff --git a/docs/libssh2_knownhost_readfile.3 b/docs/libssh2_knownhost_readfile.3 index 68aa9402e3..3bc678e55a 100644 --- a/docs/libssh2_knownhost_readfile.3 +++ b/docs/libssh2_knownhost_readfile.3 @@ -5,10 +5,13 @@ .SH NAME libssh2_knownhost_readfile - parse a file of known hosts .SH SYNOPSIS +.nf #include -int libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts, - const char *filename, int type); +int +libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts, + const char *filename, int type); +.fi .SH DESCRIPTION Reads a collection of known hosts from a specified file and adds them to the collection of known hosts. diff --git a/docs/libssh2_knownhost_readline.3 b/docs/libssh2_knownhost_readline.3 index a5881c44d2..eb43c79fad 100644 --- a/docs/libssh2_knownhost_readline.3 +++ b/docs/libssh2_knownhost_readline.3 @@ -5,10 +5,13 @@ .SH NAME libssh2_knownhost_readline - read a known host line .SH SYNOPSIS +.nf #include -int libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts, - const char *line, size_t len, int type): +int +libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts, + const char *line, size_t len, int type): +.fi .SH DESCRIPTION Tell libssh2 to read a buffer as it if is a line from a known hosts file. diff --git a/docs/libssh2_knownhost_writefile.3 b/docs/libssh2_knownhost_writefile.3 index 9ecc4a8df8..0457ecefd0 100644 --- a/docs/libssh2_knownhost_writefile.3 +++ b/docs/libssh2_knownhost_writefile.3 @@ -5,10 +5,13 @@ .SH NAME libssh2_knownhost_writefile - write a collection of known hosts to a file .SH SYNOPSIS +.nf #include -int libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts, - const char *filename, int type); +int +libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts, + const char *filename, int type); +.fi .SH DESCRIPTION Writes all the known hosts to the specified file using the specified file format. diff --git a/docs/libssh2_knownhost_writeline.3 b/docs/libssh2_knownhost_writeline.3 index e4c113ec27..4a0cbfc35f 100644 --- a/docs/libssh2_knownhost_writeline.3 +++ b/docs/libssh2_knownhost_writeline.3 @@ -5,13 +5,16 @@ .SH NAME libssh2_knownhost_writeline - convert a known host to a line for storage .SH SYNOPSIS +.nf #include +int libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, struct libssh2_knownhost *known, char *buffer, size_t buflen, size_t *outlen, int type); +.fi .SH DESCRIPTION Converts a single known host to a single line of output for storage, using the 'type' output format. diff --git a/docs/libssh2_poll.3 b/docs/libssh2_poll.3 index 6656945c72..34cef03726 100644 --- a/docs/libssh2_poll.3 +++ b/docs/libssh2_poll.3 @@ -2,9 +2,12 @@ .SH NAME libssh2_poll - poll for activity on a socket, channel or listener .SH SYNOPSIS +.nf #include -int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeout); +int +libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeout); +.fi .SH DESCRIPTION This function is deprecated. Do note use. We encourage users to instead use the \fIpoll(3)\fP or \fIselect(3)\fP functions to check for socket activity or diff --git a/docs/libssh2_poll_channel_read.3 b/docs/libssh2_poll_channel_read.3 index 207275b526..45d5702da7 100644 --- a/docs/libssh2_poll_channel_read.3 +++ b/docs/libssh2_poll_channel_read.3 @@ -2,9 +2,12 @@ .SH NAME libssh2_poll_channel_read - check if data is available .SH SYNOPSIS +.nf #include -int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended); +int +libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended); +.fi .SH DESCRIPTION This function is deprecated. Do note use. diff --git a/docs/libssh2_publickey_add.3 b/docs/libssh2_publickey_add.3 index 7fc3eb107f..d967a71512 100644 --- a/docs/libssh2_publickey_add.3 +++ b/docs/libssh2_publickey_add.3 @@ -2,13 +2,16 @@ .SH NAME libssh2_publickey_add - convenience macro for \fIlibssh2_publickey_add_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_publickey_add(LIBSSH2_PUBLICKEY *pkey, - const unsigned char *name, - const unsigned char *blob, unsigned long blob_len, char overwrite, - unsigned long num_attrs, const libssh2_publickey_attribute attrs[]); - +int +libssh2_publickey_add(LIBSSH2_PUBLICKEY *pkey, + const unsigned char *name, + const unsigned char *blob, unsigned long blob_len, + char overwrite, unsigned long num_attrs, + const libssh2_publickey_attribute attrs[]); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_publickey_add_ex(3)\fP. diff --git a/docs/libssh2_publickey_add_ex.3 b/docs/libssh2_publickey_add_ex.3 index 5c01d2345d..5499b11ab0 100644 --- a/docs/libssh2_publickey_add_ex.3 +++ b/docs/libssh2_publickey_add_ex.3 @@ -2,15 +2,16 @@ .SH NAME libssh2_publickey_add_ex - Add a public key entry .SH SYNOPSIS +.nf #include int -libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, - unsigned long name_len, const unsigned char *blob, - unsigned long blob_len, char overwrite, - unsigned long num_attrs, +libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, + const unsigned char *name, unsigned long name_len, + const unsigned char *blob, unsigned long blob_len, + char overwrite, unsigned long num_attrs, const libssh2_publickey_attribute attrs[]) - +.fi .SH DESCRIPTION TBD .SH RETURN VALUE diff --git a/docs/libssh2_publickey_init.3 b/docs/libssh2_publickey_init.3 index 448eb714ee..2bf3d0625b 100644 --- a/docs/libssh2_publickey_init.3 +++ b/docs/libssh2_publickey_init.3 @@ -2,7 +2,8 @@ .SH NAME libssh2_publickey_init - TODO .SH SYNOPSIS - +.nf +.fi .SH DESCRIPTION .SH RETURN VALUE diff --git a/docs/libssh2_publickey_list_fetch.3 b/docs/libssh2_publickey_list_fetch.3 index 07a7024b97..f38d494f4d 100644 --- a/docs/libssh2_publickey_list_fetch.3 +++ b/docs/libssh2_publickey_list_fetch.3 @@ -2,7 +2,8 @@ .SH NAME libssh2_publickey_list_fetch - TODO .SH SYNOPSIS - +.nf +.fi .SH DESCRIPTION .SH RETURN VALUE diff --git a/docs/libssh2_publickey_list_free.3 b/docs/libssh2_publickey_list_free.3 index d50e935d20..3761c12872 100644 --- a/docs/libssh2_publickey_list_free.3 +++ b/docs/libssh2_publickey_list_free.3 @@ -2,7 +2,8 @@ .SH NAME libssh2_publickey_list_free - TODO .SH SYNOPSIS - +.nf +.fi .SH DESCRIPTION .SH RETURN VALUE diff --git a/docs/libssh2_publickey_remove.3 b/docs/libssh2_publickey_remove.3 index 1d4cdeb6c1..9295806da6 100644 --- a/docs/libssh2_publickey_remove.3 +++ b/docs/libssh2_publickey_remove.3 @@ -2,12 +2,14 @@ .SH NAME libssh2_publickey_remove - convenience macro for \fIlibssh2_publickey_remove_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_publickey_remove(LIBSSH2_PUBLICKEY *pkey, - const unsigned char *name, unsigned long name_len, - const unsigned char *blob, unsigned long blob_len); - +int +libssh2_publickey_remove(LIBSSH2_PUBLICKEY *pkey, + const unsigned char *name, unsigned long name_len, + const unsigned char *blob, unsigned long blob_len); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_publickey_remove_ex(3)\fP. diff --git a/docs/libssh2_publickey_remove_ex.3 b/docs/libssh2_publickey_remove_ex.3 index a6cba50c7d..a83ee2d05c 100644 --- a/docs/libssh2_publickey_remove_ex.3 +++ b/docs/libssh2_publickey_remove_ex.3 @@ -2,7 +2,8 @@ .SH NAME libssh2_publickey_list_remove_ex - TODO .SH SYNOPSIS - +.nf +.fi .SH DESCRIPTION .SH RETURN VALUE diff --git a/docs/libssh2_publickey_shutdown.3 b/docs/libssh2_publickey_shutdown.3 index fe67a7636d..8eabf63386 100644 --- a/docs/libssh2_publickey_shutdown.3 +++ b/docs/libssh2_publickey_shutdown.3 @@ -2,7 +2,8 @@ .SH NAME libssh2_publickey_shutdown - TODO .SH SYNOPSIS - +.nf +.fi .SH DESCRIPTION .SH RETURN VALUE diff --git a/docs/libssh2_scp_recv.3 b/docs/libssh2_scp_recv.3 index 2da4fa2cc2..607d49ae95 100644 --- a/docs/libssh2_scp_recv.3 +++ b/docs/libssh2_scp_recv.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_scp_recv - request a remote file via SCP .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb); - +.fi .SH DESCRIPTION This function is \fBDEPRECATED\fP. Use \fIlibssh2_scp_recv2(3)\fP instead! diff --git a/docs/libssh2_scp_recv2.3 b/docs/libssh2_scp_recv2.3 index b7e2ebebef..06c88d6bfe 100644 --- a/docs/libssh2_scp_recv2.3 +++ b/docs/libssh2_scp_recv2.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_scp_recv2 - request a remote file via SCP .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * libssh2_scp_recv2(LIBSSH2_SESSION *session, const char *path, struct_stat *sb); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_scp_send.3 b/docs/libssh2_scp_send.3 index 5e29347b86..65477c464f 100644 --- a/docs/libssh2_scp_send.3 +++ b/docs/libssh2_scp_send.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_scp_send - convenience macro for \fIlibssh2_scp_send_ex(3)\fP calls .SH SYNOPSIS +.nf #include LIBSSH2_CHANNEL * -libssh2_scp_send(LIBSSH2_SESSION *session, const char *path, int mode, size_t size); - +libssh2_scp_send(LIBSSH2_SESSION *session, const char *path, + int mode, size_t size); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_scp_send_ex(3)\fP. diff --git a/docs/libssh2_scp_send64.3 b/docs/libssh2_scp_send64.3 index 42a90d9d3e..53b6d5c44c 100644 --- a/docs/libssh2_scp_send64.3 +++ b/docs/libssh2_scp_send64.3 @@ -8,6 +8,7 @@ libssh2_scp_send64 - Send a file via SCP LIBSSH2_CHANNEL * libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode, libssh2_uint64_t size, time_t mtime, time_t atime); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_scp_send_ex.3 b/docs/libssh2_scp_send_ex.3 index c271705732..cb4d362e05 100644 --- a/docs/libssh2_scp_send_ex.3 +++ b/docs/libssh2_scp_send_ex.3 @@ -8,6 +8,7 @@ libssh2_scp_send_ex - Send a file via SCP LIBSSH2_CHANNEL * libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t size, long mtime, long atime); +.fi .SH DESCRIPTION This function has been deemed deprecated since libssh2 1.2.6. See \fIlibssh2_scp_send64(3)\fP. diff --git a/docs/libssh2_session_abstract.3 b/docs/libssh2_session_abstract.3 index 1fba1f25dd..a28bff64b1 100644 --- a/docs/libssh2_session_abstract.3 +++ b/docs/libssh2_session_abstract.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_session_abstract - return a pointer to a session's abstract pointer .SH SYNOPSIS +.nf #include void ** libssh2_session_abstract(LIBSSH2_SESSION *session); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_banner_get.3 b/docs/libssh2_session_banner_get.3 index e253aa13d2..f1097b3ce0 100644 --- a/docs/libssh2_session_banner_get.3 +++ b/docs/libssh2_session_banner_get.3 @@ -2,9 +2,12 @@ .SH NAME libssh2_session_banner_get - get the remote banner .SH SYNOPSIS +.nf #include -const char *libssh2_session_banner_get(oLIBSSH2_SESSION *session); +const char * +libssh2_session_banner_get(oLIBSSH2_SESSION *session); +.fi .SH DESCRIPTION Once the session has been setup and \fIlibssh2_session_handshake(3)\fP has completed successfully, this function can be used to get the server id from diff --git a/docs/libssh2_session_banner_set.3 b/docs/libssh2_session_banner_set.3 index 1b6f4c9a07..bcb7923572 100644 --- a/docs/libssh2_session_banner_set.3 +++ b/docs/libssh2_session_banner_set.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_session_banner_set - set the SSH protocol banner for the local client .SH SYNOPSIS +.nf #include int libssh2_session_banner_set(LIBSSH2_SESSION *session, const char *banner); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_block_directions.3 b/docs/libssh2_session_block_directions.3 index 48ffca3d63..0c40eaf195 100644 --- a/docs/libssh2_session_block_directions.3 +++ b/docs/libssh2_session_block_directions.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_session_block_directions - get directions to wait for .SH SYNOPSIS +.nf #include int libssh2_session_block_directions(LIBSSH2_SESSION *session); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by \fBlibssh2_session_init_ex(3)\fP diff --git a/docs/libssh2_session_callback_set.3 b/docs/libssh2_session_callback_set.3 index 5dd2243c24..9a94c00f50 100644 --- a/docs/libssh2_session_callback_set.3 +++ b/docs/libssh2_session_callback_set.3 @@ -5,8 +5,10 @@ libssh2_session_callback_set - set a callback function .nf #include -void *libssh2_session_callback_set(LIBSSH2_SESSION *session, - int cbtype, void *callback); +void * +libssh2_session_callback_set(LIBSSH2_SESSION *session, + int cbtype, void *callback); +.fi .SH DESCRIPTION Sets a custom callback handler for a previously initialized session object. Callbacks are triggered by the receipt of special packets at the diff --git a/docs/libssh2_session_disconnect.3 b/docs/libssh2_session_disconnect.3 index 32d5e8787f..63b087258b 100644 --- a/docs/libssh2_session_disconnect.3 +++ b/docs/libssh2_session_disconnect.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_session_disconnect - convenience macro for \fIlibssh2_session_disconnect_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_session_disconnect(LIBSSH2_SESSION *session, const char *description); - +int +libssh2_session_disconnect(LIBSSH2_SESSION *session, const char *description); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_session_disconnect_ex(3)\fP. diff --git a/docs/libssh2_session_disconnect_ex.3 b/docs/libssh2_session_disconnect_ex.3 index f047bb6962..35eb8d7818 100644 --- a/docs/libssh2_session_disconnect_ex.3 +++ b/docs/libssh2_session_disconnect_ex.3 @@ -2,14 +2,18 @@ .SH NAME libssh2_session_disconnect_ex - terminate transport layer .SH SYNOPSIS +.nf #include int -libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang); +libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, + const char *description, + const char *lang); int -libssh2_session_disconnect(LIBSSH2_SESSION *session, const char *description); - +libssh2_session_disconnect(LIBSSH2_SESSION *session, + const char *description); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_flag.3 b/docs/libssh2_session_flag.3 index 3a9e5e559a..71d82e4c38 100644 --- a/docs/libssh2_session_flag.3 +++ b/docs/libssh2_session_flag.3 @@ -2,8 +2,12 @@ .SH NAME libssh2_session_flag - TODO .SH SYNOPSIS +.nf +#include + int libssh2_session_flag(LIBSSH2_SESSION *session, int flag, int value); +.fi .SH DESCRIPTION Set options for the created session. \fIflag\fP is the option to set, while \fIvalue\fP is typically set to 1 or 0 to enable or disable the option. diff --git a/docs/libssh2_session_free.3 b/docs/libssh2_session_free.3 index f2dbfeb5d9..50d2cb28a9 100644 --- a/docs/libssh2_session_free.3 +++ b/docs/libssh2_session_free.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_session_free - frees resources associated with a session instance .SH SYNOPSIS +.nf #include int libssh2_session_free(LIBSSH2_SESSION *session); +.fi .SH DESCRIPTION Frees all resources associated with a session instance. Typically called after .BR libssh2_session_disconnect_ex(3) diff --git a/docs/libssh2_session_get_blocking.3 b/docs/libssh2_session_get_blocking.3 index 8d98fa3317..9bd12134dd 100644 --- a/docs/libssh2_session_get_blocking.3 +++ b/docs/libssh2_session_get_blocking.3 @@ -2,7 +2,12 @@ .SH NAME libssh2_session_get_blocking - TODO .SH SYNOPSIS -int libssh2_session_get_blocking(LIBSSH2_SESSION *session); +.nf +#include + +int +libssh2_session_get_blocking(LIBSSH2_SESSION *session); +.fi .SH DESCRIPTION Returns 0 if the state of the session has previously be set to non-blocking and it returns 1 if the state was set to blocking. diff --git a/docs/libssh2_session_get_read_timeout.3 b/docs/libssh2_session_get_read_timeout.3 index 4f47af39de..a39e7aee56 100644 --- a/docs/libssh2_session_get_read_timeout.3 +++ b/docs/libssh2_session_get_read_timeout.3 @@ -2,9 +2,12 @@ .SH NAME libssh2_session_get_read_timeout - get the timeout for packet read functions .SH SYNOPSIS -#include .nf -long libssh2_session_get_read_timeout(LIBSSH2_SESSION *session); +#include + +long +libssh2_session_get_read_timeout(LIBSSH2_SESSION *session); +.fi .SH DESCRIPTION Returns the \fBtimeout\fP (in seconds) for how long the ssh2 packet receive function calls may wait until they consider the situation an error and diff --git a/docs/libssh2_session_get_timeout.3 b/docs/libssh2_session_get_timeout.3 index 94aacd6536..488918d2c7 100644 --- a/docs/libssh2_session_get_timeout.3 +++ b/docs/libssh2_session_get_timeout.3 @@ -2,9 +2,12 @@ .SH NAME libssh2_session_get_timeout - get the timeout for blocking functions .SH SYNOPSIS -#include .nf -long libssh2_session_get_timeout(LIBSSH2_SESSION *session); +#include + +long +libssh2_session_get_timeout(LIBSSH2_SESSION *session); +.fi .SH DESCRIPTION Returns the \fBtimeout\fP (in milliseconds) for how long a blocking the libssh2 function calls may wait until they consider the situation an error and diff --git a/docs/libssh2_session_handshake.3 b/docs/libssh2_session_handshake.3 index 33908c64ab..b22e2c5a39 100644 --- a/docs/libssh2_session_handshake.3 +++ b/docs/libssh2_session_handshake.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_session_handshake - perform the SSH handshake .SH SYNOPSIS +.nf #include int libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t socket); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_hostkey.3 b/docs/libssh2_session_hostkey.3 index 5d044407c9..8d45b53bce 100644 --- a/docs/libssh2_session_hostkey.3 +++ b/docs/libssh2_session_hostkey.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_session_hostkey - get the remote key .SH SYNOPSIS +.nf #include -const char *libssh2_session_hostkey(LIBSSH2_SESSION *session, - size_t *len, int *type); +const char * +libssh2_session_hostkey(LIBSSH2_SESSION *session, + size_t *len, int *type); +.fi .SH DESCRIPTION Returns a pointer to the current host key, the value \fIlen\fP points to will get the length of the key. diff --git a/docs/libssh2_session_init.3 b/docs/libssh2_session_init.3 index 476a3b4237..a9d524c483 100644 --- a/docs/libssh2_session_init.3 +++ b/docs/libssh2_session_init.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_session_init - convenience macro for \fIlibssh2_session_init_ex(3)\fP calls .SH SYNOPSIS +.nf #include LIBSSH2_SESSION * libssh2_session_init(void); - +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_session_init_ex(3)\fP. diff --git a/docs/libssh2_session_init_ex.3 b/docs/libssh2_session_init_ex.3 index 5f06183157..e54ff7ff0a 100644 --- a/docs/libssh2_session_init_ex.3 +++ b/docs/libssh2_session_init_ex.3 @@ -2,14 +2,18 @@ .SH NAME libssh2_session_init_ex - initializes an SSH session object .SH SYNOPSIS +.nf #include LIBSSH2_SESSION * -libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*myalloc)), LIBSSH2_FREE_FUNC((*myfree)), LIBSSH2_REALLOC_FUNC((*myrealloc)), void *abstract); +libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*myalloc)), + LIBSSH2_FREE_FUNC((*myfree)), + LIBSSH2_REALLOC_FUNC((*myrealloc)), + void *abstract); LIBSSH2_SESSION * libssh2_session_init(void); - +.fi .SH DESCRIPTION \fImyalloc\fP - Custom allocator function. Refer to the section on Callbacks for implementing an allocator callback. Pass a value of NULL to use the diff --git a/docs/libssh2_session_last_errno.3 b/docs/libssh2_session_last_errno.3 index e23233bc6c..e6076dc190 100644 --- a/docs/libssh2_session_last_errno.3 +++ b/docs/libssh2_session_last_errno.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_session_last_errno - get the most recent error number .SH SYNOPSIS +.nf #include int libssh2_session_last_errno(LIBSSH2_SESSION *session); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_last_error.3 b/docs/libssh2_session_last_error.3 index 6bbdbd0302..fa7285cc45 100644 --- a/docs/libssh2_session_last_error.3 +++ b/docs/libssh2_session_last_error.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_session_last_error - get the most recent error .SH SYNOPSIS +.nf #include int -libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_len, int want_buf); - +libssh2_session_last_error(LIBSSH2_SESSION *session, + char **errmsg, int *errmsg_len, int want_buf); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_method_pref.3 b/docs/libssh2_session_method_pref.3 index 0af2d855c1..cb6f33d600 100644 --- a/docs/libssh2_session_method_pref.3 +++ b/docs/libssh2_session_method_pref.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_session_method_pref - set preferred key exchange method .SH SYNOPSIS +.nf #include int -libssh2_session_method_pref(LIBSSH2_SESSION *session, int method_type, const char *prefs); - +libssh2_session_method_pref(LIBSSH2_SESSION *session, + int method_type, const char *prefs); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_methods.3 b/docs/libssh2_session_methods.3 index 0e7f79fa96..089f7a13e2 100644 --- a/docs/libssh2_session_methods.3 +++ b/docs/libssh2_session_methods.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_session_methods - return the currently active algorithms .SH SYNOPSIS +.nf #include const char * libssh2_session_methods(LIBSSH2_SESSION *session, int method_type); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_set_blocking.3 b/docs/libssh2_session_set_blocking.3 index a7e9dcd17c..7cde73aacd 100644 --- a/docs/libssh2_session_set_blocking.3 +++ b/docs/libssh2_session_set_blocking.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_session_set_blocking - set or clear blocking mode on session .SH SYNOPSIS +.nf #include void libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking); - +.fi .SH DESCRIPTION \fIsession\fP - session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_set_last_error.3 b/docs/libssh2_session_set_last_error.3 index fca6d1dff1..e00cbd2284 100644 --- a/docs/libssh2_session_set_last_error.3 +++ b/docs/libssh2_session_set_last_error.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_session_set_last_error - sets the internal error state .SH SYNOPSIS +.nf #include int -libssh2_session_set_last_error(LIBSSH2_SESSION *session, int errcode, const char *errmsg) - +libssh2_session_set_last_error(LIBSSH2_SESSION *session, + int errcode, const char *errmsg) +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_set_read_timeout.3 b/docs/libssh2_session_set_read_timeout.3 index 63acd0001f..c97e7ae6a7 100644 --- a/docs/libssh2_session_set_read_timeout.3 +++ b/docs/libssh2_session_set_read_timeout.3 @@ -2,9 +2,12 @@ .SH NAME libssh2_session_set_read_timeout - set timeout for packet read functions .SH SYNOPSIS -#include .nf -void libssh2_session_set_read_timeout(LIBSSH2_SESSION *session, long timeout); +#include + +void +libssh2_session_set_read_timeout(LIBSSH2_SESSION *session, long timeout); +.fi .SH DESCRIPTION Set the \fBtimeout\fP in seconds for how long libssh2 packet read function calls may wait until they consider the situation an error and return diff --git a/docs/libssh2_session_set_timeout.3 b/docs/libssh2_session_set_timeout.3 index 2d4f10f131..b151d11c98 100644 --- a/docs/libssh2_session_set_timeout.3 +++ b/docs/libssh2_session_set_timeout.3 @@ -2,9 +2,12 @@ .SH NAME libssh2_session_set_timeout - set timeout for blocking functions .SH SYNOPSIS -#include .nf -void libssh2_session_set_timeout(LIBSSH2_SESSION *session, long timeout); +#include + +void +libssh2_session_set_timeout(LIBSSH2_SESSION *session, long timeout); +.fi .SH DESCRIPTION Set the \fBtimeout\fP in milliseconds for how long a blocking the libssh2 function calls may wait until they consider the situation an error and return diff --git a/docs/libssh2_session_startup.3 b/docs/libssh2_session_startup.3 index 8e06014058..af66243df5 100644 --- a/docs/libssh2_session_startup.3 +++ b/docs/libssh2_session_startup.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_session_startup - begin transport layer .SH SYNOPSIS +.nf #include int libssh2_session_startup(LIBSSH2_SESSION *session, int socket); +.fi .SH DESCRIPTION Starting in libssh2 version 1.2.8 this function is considered deprecated. Use \fIlibssh2_session_handshake(3)\fP instead. diff --git a/docs/libssh2_session_supported_algs.3 b/docs/libssh2_session_supported_algs.3 index 6e414a90c2..89de417e34 100644 --- a/docs/libssh2_session_supported_algs.3 +++ b/docs/libssh2_session_supported_algs.3 @@ -5,9 +5,11 @@ libssh2_session_supported_algs - get list of supported algorithms .nf #include -int libssh2_session_supported_algs(LIBSSH2_SESSION* session, - int method_type, - const char*** algs); +int +libssh2_session_supported_algs(LIBSSH2_SESSION* session, + int method_type, + const char*** algs); +.fi .SH DESCRIPTION \fIsession\fP - An instance of initialized LIBSSH2_SESSION (the function will use its pointer to the memory allocation function). \fImethod_type\fP - @@ -41,11 +43,11 @@ session = libssh2_session_init(); rc = libssh2_session_supported_algs(session, LIBSSH2_METHOD_CRYPT_CS, &algorithms); -if (rc>0) { +if(rc > 0) { /* the call succeeded, do sth. with the list of algorithms (e.g. list them)... */ printf("Supported symmetric algorithms:\\n"); - for ( i=0; i0) { else { /* call failed, error handling */ } +.fi .SH RETURN VALUE On success, a number of returned algorithms (i.e a positive number will be returned). In case of a failure, an error code (a negative number, see below) diff --git a/docs/libssh2_sftp_close.3 b/docs/libssh2_sftp_close.3 index b169b1ba38..f4155191bf 100644 --- a/docs/libssh2_sftp_close.3 +++ b/docs/libssh2_sftp_close.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_sftp_close - convenience macro for \fIlibssh2_sftp_close_handle(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_close(LIBSSH2_SFTP_HANDLE *handle); - +int +libssh2_sftp_close(LIBSSH2_SFTP_HANDLE *handle); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_close_handle(3)\fP. diff --git a/docs/libssh2_sftp_close_handle.3 b/docs/libssh2_sftp_close_handle.3 index 432e50d3ef..1f5d0ef1f4 100644 --- a/docs/libssh2_sftp_close_handle.3 +++ b/docs/libssh2_sftp_close_handle.3 @@ -2,6 +2,7 @@ .SH NAME libssh2_sftp_close_handle - close filehandle .SH SYNOPSIS +.nf #include #include @@ -13,7 +14,7 @@ libssh2_sftp_close(LIBSSH2_SFTP_HANDLE *handle); int libssh2_sftp_closedir(LIBSSH2_SFTP_HANDLE *handle); - +.fi .SH DESCRIPTION \fIhandle\fP - SFTP File Handle as returned by \fBlibssh2_sftp_open_ex(3)\fP or \fBlibssh2_sftp_opendir(3)\fP (which is a macro). diff --git a/docs/libssh2_sftp_closedir.3 b/docs/libssh2_sftp_closedir.3 index 3e032a77bd..f4b4452e2b 100644 --- a/docs/libssh2_sftp_closedir.3 +++ b/docs/libssh2_sftp_closedir.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_sftp_closedir - convenience macro for \fIlibssh2_sftp_close_handle(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_closedir(LIBSSH2_SFTP_HANDLE *handle) - +int +libssh2_sftp_closedir(LIBSSH2_SFTP_HANDLE *handle) +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_close_handle(3)\fP. diff --git a/docs/libssh2_sftp_fsetstat.3 b/docs/libssh2_sftp_fsetstat.3 index e77dd2149c..2f45f4f3a9 100644 --- a/docs/libssh2_sftp_fsetstat.3 +++ b/docs/libssh2_sftp_fsetstat.3 @@ -2,10 +2,14 @@ .SH NAME libssh2_sftp_fsetstat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_fsetstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs); - +int +libssh2_sftp_fsetstat(LIBSSH2_SFTP_HANDLE *handle, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_fstat_ex(3)\fP. diff --git a/docs/libssh2_sftp_fstat.3 b/docs/libssh2_sftp_fstat.3 index 66116a391e..809b531158 100644 --- a/docs/libssh2_sftp_fstat.3 +++ b/docs/libssh2_sftp_fstat.3 @@ -2,10 +2,14 @@ .SH NAME libssh2_sftp_fstat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs); - +int +libssh2_sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_fstat_ex(3)\fP. diff --git a/docs/libssh2_sftp_get_channel.3 b/docs/libssh2_sftp_get_channel.3 index d1d82bc76e..1e24f10ebe 100644 --- a/docs/libssh2_sftp_get_channel.3 +++ b/docs/libssh2_sftp_get_channel.3 @@ -6,8 +6,9 @@ libssh2_sftp_get_channel - return the channel of sftp #include #include +LIBSSH2_CHANNEL * +libssh2_sftp_get_channel(LIBSSH2_SFTP *sftp); .fi -LIBSSH2_CHANNEL *libssh2_sftp_get_channel(LIBSSH2_SFTP *sftp); .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_init.3 b/docs/libssh2_sftp_init.3 index d1ac40120a..ea602d82d3 100644 --- a/docs/libssh2_sftp_init.3 +++ b/docs/libssh2_sftp_init.3 @@ -2,12 +2,13 @@ .SH NAME libssh2_sftp_init - open SFTP channel for the given SSH session. .SH SYNOPSIS +.nf #include #include LIBSSH2_SFTP * libssh2_sftp_init(LIBSSH2_SESSION *session); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_sftp_last_error.3 b/docs/libssh2_sftp_last_error.3 index 2aee4c62fa..91dd6fdfa2 100644 --- a/docs/libssh2_sftp_last_error.3 +++ b/docs/libssh2_sftp_last_error.3 @@ -2,12 +2,13 @@ .SH NAME libssh2_sftp_last_error - return the last SFTP-specific error code .SH SYNOPSIS +.nf #include #include unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp); - +.fi .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_lstat.3 b/docs/libssh2_sftp_lstat.3 index 78c90577f9..fc0ecd4ebb 100644 --- a/docs/libssh2_sftp_lstat.3 +++ b/docs/libssh2_sftp_lstat.3 @@ -2,10 +2,14 @@ .SH NAME libssh2_sftp_lstat - convenience macro for \fIlibssh2_sftp_stat_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_lstat(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_SFTP_ATTRIBUTES *attrs); - +int +libssh2_sftp_lstat(LIBSSH2_SFTP *sftp, const char *path, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_stat_ex(3)\fP. diff --git a/docs/libssh2_sftp_mkdir.3 b/docs/libssh2_sftp_mkdir.3 index 999bd016e2..63e4c3b477 100644 --- a/docs/libssh2_sftp_mkdir.3 +++ b/docs/libssh2_sftp_mkdir.3 @@ -2,10 +2,14 @@ .SH NAME libssh2_sftp_mkdir - convenience macro for \fIlibssh2_sftp_mkdir_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, long mode); - +int +libssh2_sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, + long mode); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_mkdir_ex(3)\fP. diff --git a/docs/libssh2_sftp_mkdir_ex.3 b/docs/libssh2_sftp_mkdir_ex.3 index ad65dcef82..4bf73b84af 100644 --- a/docs/libssh2_sftp_mkdir_ex.3 +++ b/docs/libssh2_sftp_mkdir_ex.3 @@ -2,14 +2,20 @@ .SH NAME libssh2_sftp_mkdir_ex - create a directory on the remote file system .SH SYNOPSIS +.nf #include #include int -libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, long mode); +libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp, + const char *path, unsigned int path_len, + long mode); int -libssh2_sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, long mode); +libssh2_sftp_mkdir(LIBSSH2_SFTP *sftp, + const char *path, + long mode); +.fi .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_open.3 b/docs/libssh2_sftp_open.3 index 9096986006..85d54f67fc 100644 --- a/docs/libssh2_sftp_open.3 +++ b/docs/libssh2_sftp_open.3 @@ -2,11 +2,15 @@ .SH NAME libssh2_sftp_open - convenience macro for \fIlibssh2_sftp_open_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include LIBSSH2_SFTP_HANDLE * -libssh2_sftp_open(LIBSSH2_SFTP *sftp, const char *path, unsigned long flags, long mode); - +libssh2_sftp_open(LIBSSH2_SFTP *sftp, const char *filename, + unsigned long flags, + long mode); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_open_ex(3)\fP. diff --git a/docs/libssh2_sftp_open_ex.3 b/docs/libssh2_sftp_open_ex.3 index af341f14f4..c23108c8b3 100644 --- a/docs/libssh2_sftp_open_ex.3 +++ b/docs/libssh2_sftp_open_ex.3 @@ -1,6 +1,6 @@ .TH libssh2_sftp_open_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" .SH NAME -libssh2_sftp_open - open filehandle for file on SFTP. +libssh2_sftp_open_ex - open filehandle for file on SFTP. .SH SYNOPSIS .nf #include @@ -8,8 +8,11 @@ libssh2_sftp_open - open filehandle for file on SFTP. LIBSSH2_SFTP_HANDLE * libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename, - unsigned int filename_len, unsigned long flags, - long mode, int open_type); + unsigned int filename_len, + unsigned long flags, + long mode, + int open_type); +.fi .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by \fIlibssh2_sftp_init(3)\fP diff --git a/docs/libssh2_sftp_opendir.3 b/docs/libssh2_sftp_opendir.3 index d34510314c..ad78cea2e6 100644 --- a/docs/libssh2_sftp_opendir.3 +++ b/docs/libssh2_sftp_opendir.3 @@ -2,11 +2,13 @@ .SH NAME libssh2_sftp_opendir - convenience macro for \fIlibssh2_sftp_open_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include LIBSSH2_SFTP_HANDLE * libssh2_sftp_opendir(LIBSSH2_SFTP *sftp, const char *path); - +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_open_ex(3)\fP. diff --git a/docs/libssh2_sftp_read.3 b/docs/libssh2_sftp_read.3 index 6420121811..c998e2c913 100644 --- a/docs/libssh2_sftp_read.3 +++ b/docs/libssh2_sftp_read.3 @@ -2,12 +2,14 @@ .SH NAME libssh2_sftp_read - read data from an SFTP handle .SH SYNOPSIS +.nf #include #include ssize_t -libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen); - +libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, + char *buffer, size_t buffer_maxlen); +.fi .SH DESCRIPTION \fIhandle\fP is the SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) diff --git a/docs/libssh2_sftp_readdir.3 b/docs/libssh2_sftp_readdir.3 index adecbcbe13..f0fc9561d1 100644 --- a/docs/libssh2_sftp_readdir.3 +++ b/docs/libssh2_sftp_readdir.3 @@ -2,10 +2,15 @@ .SH NAME libssh2_sftp_readdir - convenience macro for \fIlibssh2_sftp_readdir_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs); - +int +libssh2_sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, + char *buffer, size_t buffer_maxlen, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_readdir_ex(3)\fP. diff --git a/docs/libssh2_sftp_readdir_ex.3 b/docs/libssh2_sftp_readdir_ex.3 index eb9dd2f7a9..6ea3e0488f 100644 --- a/docs/libssh2_sftp_readdir_ex.3 +++ b/docs/libssh2_sftp_readdir_ex.3 @@ -11,6 +11,7 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen, char *longentry, size_t longentry_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi .SH DESCRIPTION Reads a block of data from a LIBSSH2_SFTP_HANDLE and returns file entry information for the next entry, if any. diff --git a/docs/libssh2_sftp_readlink.3 b/docs/libssh2_sftp_readlink.3 index 7425074ecc..e6d79be777 100644 --- a/docs/libssh2_sftp_readlink.3 +++ b/docs/libssh2_sftp_readlink.3 @@ -4,10 +4,13 @@ libssh2_sftp_readlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP .SH SYNOPSIS .nf #include +#include #define libssh2_sftp_readlink(sftp, path, target, maxlen) \\ - libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \\ - LIBSSH2_SFTP_READLINK) + libssh2_sftp_symlink_ex((sftp), (path), strlen(path), \\ + (target), (maxlen), \\ + LIBSSH2_SFTP_READLINK) +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_symlink_ex(3)\fP. diff --git a/docs/libssh2_sftp_realpath.3 b/docs/libssh2_sftp_realpath.3 index 33f0fa828f..c0221c29f4 100644 --- a/docs/libssh2_sftp_realpath.3 +++ b/docs/libssh2_sftp_realpath.3 @@ -4,10 +4,14 @@ libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP .SH SYNOPSIS .nf #include +#include #define libssh2_sftp_realpath(sftp, path, target, maxlen) \\ - libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \\ - LIBSSH2_SFTP_REALPATH) + libssh2_sftp_symlink_ex((sftp), \\ + (path), strlen(path), \\ + (target), (maxlen), \\ + LIBSSH2_SFTP_REALPATH) +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_symlink_ex(3)\fP. diff --git a/docs/libssh2_sftp_rename.3 b/docs/libssh2_sftp_rename.3 index 4939e3c179..fd0e1185ea 100644 --- a/docs/libssh2_sftp_rename.3 +++ b/docs/libssh2_sftp_rename.3 @@ -2,10 +2,15 @@ .SH NAME libssh2_sftp_rename - convenience macro for \fIlibssh2_sftp_rename_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, const char *destination_filename); - +int +libssh2_sftp_rename(LIBSSH2_SFTP *sftp, + const char *source_filename, + const char *destination_filename); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_rename_ex(3)\fP. diff --git a/docs/libssh2_sftp_rename_ex.3 b/docs/libssh2_sftp_rename_ex.3 index 1a13ffd33c..d29b42aaad 100644 --- a/docs/libssh2_sftp_rename_ex.3 +++ b/docs/libssh2_sftp_rename_ex.3 @@ -2,15 +2,23 @@ .SH NAME libssh2_sftp_rename_ex - rename an SFTP file .SH SYNOPSIS +.nf #include #include int -libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename, unsigned int source_filename_len, const char *dest_filename, unsigned int dest_filename_len, long flags); +libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, + const char *source_filename, + unsigned int source_filename_len, + const char *dest_filename, + unsigned int dest_filename_len, + long flags); int -libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename, const char *dest_filename); - +libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, + const char *source_filename, + const char *dest_filename); +.fi .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_rewind.3 b/docs/libssh2_sftp_rewind.3 index 92d99e2b7a..867bfd8b57 100644 --- a/docs/libssh2_sftp_rewind.3 +++ b/docs/libssh2_sftp_rewind.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_sftp_rewind - convenience macro for \fIlibssh2_sftp_seek64(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_rewind(LIBSSH2_SFTP_HANDLE *handle); - +int +libssh2_sftp_rewind(LIBSSH2_SFTP_HANDLE *handle); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_seek64(3)\fP. diff --git a/docs/libssh2_sftp_rmdir.3 b/docs/libssh2_sftp_rmdir.3 index 0d4b67f298..fb797c2332 100644 --- a/docs/libssh2_sftp_rmdir.3 +++ b/docs/libssh2_sftp_rmdir.3 @@ -4,9 +4,11 @@ libssh2_sftp_rmdir - convenience macro for \fIlibssh2_sftp_rmdir_ex(3)\fP .SH SYNOPSIS .nf #include +#include #define libssh2_sftp_rmdir(sftp, path) \\ libssh2_sftp_rmdir_ex((sftp), (path), strlen(path)) +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_rmdir_ex(3)\fP. diff --git a/docs/libssh2_sftp_rmdir_ex.3 b/docs/libssh2_sftp_rmdir_ex.3 index 117cf94ce1..1b1bb08144 100644 --- a/docs/libssh2_sftp_rmdir_ex.3 +++ b/docs/libssh2_sftp_rmdir_ex.3 @@ -6,8 +6,10 @@ libssh2_sftp_rmdir_ex - remove an SFTP directory #include #include -int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path, - unsigned int path_len); +int +libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path, + unsigned int path_len); +.fi .SH DESCRIPTION Remove a directory from the remote file system. diff --git a/docs/libssh2_sftp_seek.3 b/docs/libssh2_sftp_seek.3 index 13d4e78f55..ce3aeeb14a 100644 --- a/docs/libssh2_sftp_seek.3 +++ b/docs/libssh2_sftp_seek.3 @@ -6,7 +6,10 @@ libssh2_sftp_seek - set the read/write position indicator within a file #include #include -void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset); +void +libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, + size_t offset); +.fi .SH DESCRIPTION Deprecated function. Use \fIlibssh2_sftp_seek64(3)\fP instead! diff --git a/docs/libssh2_sftp_seek64.3 b/docs/libssh2_sftp_seek64.3 index 847a545117..c7fd62a592 100644 --- a/docs/libssh2_sftp_seek64.3 +++ b/docs/libssh2_sftp_seek64.3 @@ -6,8 +6,10 @@ libssh2_sftp_seek64 - set the read/write position within a file #include #include -void libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, - libssh2_uint64_t offset); +void +libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, + libssh2_uint64_t offset); +.fi .SH DESCRIPTION \fIhandle\fP - SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) diff --git a/docs/libssh2_sftp_setstat.3 b/docs/libssh2_sftp_setstat.3 index 198703e0f0..07284d8931 100644 --- a/docs/libssh2_sftp_setstat.3 +++ b/docs/libssh2_sftp_setstat.3 @@ -2,10 +2,14 @@ .SH NAME libssh2_sftp_setstat - convenience macro for \fIlibssh2_sftp_stat_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_setstat(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_SFTP_ATTRIBUTES *attr); - +int +libssh2_sftp_setstat(LIBSSH2_SFTP *sftp, const char *path, + LIBSSH2_SFTP_ATTRIBUTES *attr); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_stat_ex(3)\fP. diff --git a/docs/libssh2_sftp_shutdown.3 b/docs/libssh2_sftp_shutdown.3 index e1e8a96f28..d73a7af9d8 100644 --- a/docs/libssh2_sftp_shutdown.3 +++ b/docs/libssh2_sftp_shutdown.3 @@ -2,12 +2,13 @@ .SH NAME libssh2_sftp_shutdown - shut down an SFTP session .SH SYNOPSIS +.nf #include #include int libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp); - +.fi .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_stat.3 b/docs/libssh2_sftp_stat.3 index 96cb2a5a7d..59abb59ead 100644 --- a/docs/libssh2_sftp_stat.3 +++ b/docs/libssh2_sftp_stat.3 @@ -2,10 +2,14 @@ .SH NAME libssh2_sftp_stat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_stat(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_SFTP_ATTRIBUTES *attrs); - +int +libssh2_sftp_stat(LIBSSH2_SFTP *sftp, const char *path, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_fstat_ex(3)\fP. diff --git a/docs/libssh2_sftp_stat_ex.3 b/docs/libssh2_sftp_stat_ex.3 index 4e6f681062..6b03539594 100644 --- a/docs/libssh2_sftp_stat_ex.3 +++ b/docs/libssh2_sftp_stat_ex.3 @@ -6,9 +6,11 @@ libssh2_sftp_stat_ex - get status about an SFTP file #include #include -int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path, - unsigned int path_len, int stat_type, - LIBSSH2_SFTP_ATTRIBUTES *attrs); +int +libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path, + unsigned int path_len, int stat_type, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_symlink.3 b/docs/libssh2_sftp_symlink.3 index 3de7b29093..60c8550b08 100644 --- a/docs/libssh2_sftp_symlink.3 +++ b/docs/libssh2_sftp_symlink.3 @@ -4,10 +4,12 @@ libssh2_sftp_symlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP .SH SYNOPSIS .nf #include +#include #define libssh2_sftp_symlink(sftp, orig, linkpath) \\ libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), \\ strlen(linkpath), LIBSSH2_SFTP_SYMLINK) +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_symlink_ex(3)\fP. diff --git a/docs/libssh2_sftp_symlink_ex.3 b/docs/libssh2_sftp_symlink_ex.3 index 6aacaa55ab..8ef4a1f625 100644 --- a/docs/libssh2_sftp_symlink_ex.3 +++ b/docs/libssh2_sftp_symlink_ex.3 @@ -10,6 +10,7 @@ int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, char *target, unsigned int target_len, int link_type); +.fi .SH DESCRIPTION Create a symlink or read out symlink information from the remote side. diff --git a/docs/libssh2_sftp_tell.3 b/docs/libssh2_sftp_tell.3 index 574a883563..4e99bd0391 100644 --- a/docs/libssh2_sftp_tell.3 +++ b/docs/libssh2_sftp_tell.3 @@ -2,12 +2,13 @@ .SH NAME libssh2_sftp_tell - get the current read/write position indicator for a file .SH SYNOPSIS +.nf #include #include size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle); - +.fi .SH DESCRIPTION \fIhandle\fP - SFTP File Handle as returned by \fBlibssh2_sftp_open_ex(3)\fP. diff --git a/docs/libssh2_sftp_tell64.3 b/docs/libssh2_sftp_tell64.3 index 827601f15b..d0c037775f 100644 --- a/docs/libssh2_sftp_tell64.3 +++ b/docs/libssh2_sftp_tell64.3 @@ -2,12 +2,13 @@ .SH NAME libssh2_sftp_tell64 - get the current read/write position indicator for a file .SH SYNOPSIS +.nf #include #include libssh2_uint64_t libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle); - +.fi .SH DESCRIPTION \fIhandle\fP - SFTP File Handle as returned by \fBlibssh2_sftp_open_ex(3)\fP diff --git a/docs/libssh2_sftp_unlink.3 b/docs/libssh2_sftp_unlink.3 index 32bbbf9616..f83fd7e95b 100644 --- a/docs/libssh2_sftp_unlink.3 +++ b/docs/libssh2_sftp_unlink.3 @@ -2,10 +2,13 @@ .SH NAME libssh2_sftp_unlink - convenience macro for \fIlibssh2_sftp_unlink_ex(3)\fP calls .SH SYNOPSIS +.nf #include +#include -int libssh2_sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename); - +int +libssh2_sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_sftp_unlink_ex(3)\fP. diff --git a/docs/libssh2_sftp_unlink_ex.3 b/docs/libssh2_sftp_unlink_ex.3 index 9d05006aa2..9589305052 100644 --- a/docs/libssh2_sftp_unlink_ex.3 +++ b/docs/libssh2_sftp_unlink_ex.3 @@ -2,6 +2,7 @@ .SH NAME libssh2_sftp_unlink_ex - unlink an SFTP file .SH SYNOPSIS +.nf #include #include @@ -10,7 +11,7 @@ libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp, const char *filename, unsigned int fi int libssh2_sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename); - +.fi .SH DESCRIPTION \fIsftp\fP - SFTP instance as returned by .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_write.3 b/docs/libssh2_sftp_write.3 index eca2cbc7e2..8518eea014 100644 --- a/docs/libssh2_sftp_write.3 +++ b/docs/libssh2_sftp_write.3 @@ -6,9 +6,11 @@ libssh2_sftp_write - write SFTP data #include #include -ssize_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle, - const char *buffer, - size_t count); +ssize_t +libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle, + const char *buffer, + size_t count); +.fi .SH DESCRIPTION \fBlibssh2_sftp_write(3)\fP writes a block of data to the SFTP server. This method is modeled after the POSIX write() function and uses the same calling diff --git a/docs/libssh2_sign_sk.3 b/docs/libssh2_sign_sk.3 index 79e529633c..a1dcbc2a47 100644 --- a/docs/libssh2_sign_sk.3 +++ b/docs/libssh2_sign_sk.3 @@ -2,14 +2,16 @@ .SH NAME libssh2_sign_sk - Create a signature from a FIDO2 authenticator. .SH SYNOPSIS -#include .nf -int libssh2_sign_sk(LIBSSH2_SESSION *session, - unsigned char **sig, - size_t *sig_len, - const unsigned char *data, - size_t data_len, - void **abstract); +#include + +int +libssh2_sign_sk(LIBSSH2_SESSION *session, + unsigned char **sig, + size_t *sig_len, + const unsigned char *data, + size_t data_len, + void **abstract); typedef struct _LIBSSH2_PRIVKEY_SK { int algorithm; @@ -20,7 +22,7 @@ typedef struct _LIBSSH2_PRIVKEY_SK { LIBSSH2_USERAUTH_SK_SIGN_FUNC((*sign_callback)); void **orig_abstract; } LIBSSH2_PRIVKEY_SK; - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_trace.3 b/docs/libssh2_trace.3 index 4d01bf7edc..94e6d634fb 100644 --- a/docs/libssh2_trace.3 +++ b/docs/libssh2_trace.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_trace - enable debug info from inside libssh2 .SH SYNOPSIS +.nf #include -void libssh2_trace(LIBSSH2_SESSION *session, int bitmask); - +void +libssh2_trace(LIBSSH2_SESSION *session, int bitmask); +.fi .SH DESCRIPTION This is a function present in the library that can be used to get debug info from within libssh2 when it is running. Helpful when trying to trace or debug diff --git a/docs/libssh2_trace_sethandler.3 b/docs/libssh2_trace_sethandler.3 index 57d84ba982..badf23321f 100644 --- a/docs/libssh2_trace_sethandler.3 +++ b/docs/libssh2_trace_sethandler.3 @@ -10,9 +10,11 @@ typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION *session, const char *data, size_t length); -int libssh2_trace_sethandler(LIBSSH2_SESSION *session, - void* context, - libssh2_trace_handler_func callback); +int +libssh2_trace_sethandler(LIBSSH2_SESSION *session, + void* context, + libssh2_trace_handler_func callback); +.fi .SH DESCRIPTION libssh2_trace_sethandler installs a trace output handler for your application. By default, when tracing has been switched on via a call to libssh2_trace(), diff --git a/docs/libssh2_userauth_authenticated.3 b/docs/libssh2_userauth_authenticated.3 index 3019562918..ea2cb4dabd 100644 --- a/docs/libssh2_userauth_authenticated.3 +++ b/docs/libssh2_userauth_authenticated.3 @@ -2,11 +2,12 @@ .SH NAME libssh2_userauth_authenticated - return authentication status .SH SYNOPSIS +.nf #include int libssh2_userauth_authenticated(LIBSSH2_SESSION *session); - +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_userauth_banner.3 b/docs/libssh2_userauth_banner.3 index 1003b65add..f463bcf879 100644 --- a/docs/libssh2_userauth_banner.3 +++ b/docs/libssh2_userauth_banner.3 @@ -7,6 +7,7 @@ libssh2_userauth_banner - get the server's userauth banner message int libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_userauth_hostbased_fromfile.3 b/docs/libssh2_userauth_hostbased_fromfile.3 index 21153561b1..2d0c47594a 100644 --- a/docs/libssh2_userauth_hostbased_fromfile.3 +++ b/docs/libssh2_userauth_hostbased_fromfile.3 @@ -2,10 +2,17 @@ .SH NAME libssh2_userauth_hostbased_fromfile - convenience macro for \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_userauth_hostbased_fromfile(LIBSSH2_SESSION *session, const char *username, const char *publickey, const char *privatekey, const char *passphrase, const char *hostname); - +int +libssh2_userauth_hostbased_fromfile(LIBSSH2_SESSION *session, + const char *username, + const char *publickey, + const char *privatekey, + const char *passphrase, + const char *hostname); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP. diff --git a/docs/libssh2_userauth_hostbased_fromfile_ex.3 b/docs/libssh2_userauth_hostbased_fromfile_ex.3 index a65f8029e4..f1baa41a94 100644 --- a/docs/libssh2_userauth_hostbased_fromfile_ex.3 +++ b/docs/libssh2_userauth_hostbased_fromfile_ex.3 @@ -2,7 +2,8 @@ .SH NAME libssh2_userauth_hostbased_fromfile_ex - TODO .SH SYNOPSIS - +.nf +.fi .SH DESCRIPTION .SH RETURN VALUE diff --git a/docs/libssh2_userauth_keyboard_interactive.3 b/docs/libssh2_userauth_keyboard_interactive.3 index a85de3212c..492ed50af6 100644 --- a/docs/libssh2_userauth_keyboard_interactive.3 +++ b/docs/libssh2_userauth_keyboard_interactive.3 @@ -2,13 +2,14 @@ .SH NAME libssh2_userauth_keyboard_interactive - convenience macro for \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP calls .SH SYNOPSIS -#include .nf +#include int libssh2_userauth_keyboard_interactive(LIBSSH2_SESSION* session, const char *username, - LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback))); + LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback))); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP. diff --git a/docs/libssh2_userauth_keyboard_interactive_ex.3 b/docs/libssh2_userauth_keyboard_interactive_ex.3 index 222b2ba8c2..6137c5ba25 100644 --- a/docs/libssh2_userauth_keyboard_interactive_ex.3 +++ b/docs/libssh2_userauth_keyboard_interactive_ex.3 @@ -10,7 +10,8 @@ int libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len, - LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(*response_callback)); + LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(*response_callback)); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by \fIlibssh2_session_init_ex(3)\fP. @@ -28,13 +29,13 @@ control. Responses will be sent to the host. String values will be free(3)ed by the library. The callback prototype must match this: .nf - void response(const char *name, - int name_len, const char *instruction, - int instruction_len, - int num_prompts, - const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, - LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, - void **abstract); +void response(const char *name, + int name_len, const char *instruction, + int instruction_len, + int num_prompts, + const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, + LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, + void **abstract); .fi Attempts keyboard-interactive (challenge/response) authentication. diff --git a/docs/libssh2_userauth_list.3 b/docs/libssh2_userauth_list.3 index c8c2d35207..aa77298b83 100644 --- a/docs/libssh2_userauth_list.3 +++ b/docs/libssh2_userauth_list.3 @@ -6,8 +6,10 @@ libssh2_userauth_list - list supported authentication methods #include char * -libssh2_userauth_list(LIBSSH2_SESSION *session, const char *username, +libssh2_userauth_list(LIBSSH2_SESSION *session, + const char *username, unsigned int username_len); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_userauth_password.3 b/docs/libssh2_userauth_password.3 index 15e551181b..f067196ce0 100644 --- a/docs/libssh2_userauth_password.3 +++ b/docs/libssh2_userauth_password.3 @@ -2,12 +2,14 @@ .SH NAME libssh2_userauth_password - convenience macro for \fIlibssh2_userauth_password_ex(3)\fP calls .SH SYNOPSIS +.nf #include -int libssh2_userauth_password(LIBSSH2_SESSION *session, - const char *username, - const char *password); - +int +libssh2_userauth_password(LIBSSH2_SESSION *session, + const char *username, + const char *password); +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_userauth_password_ex(3)\fP. diff --git a/docs/libssh2_userauth_password_ex.3 b/docs/libssh2_userauth_password_ex.3 index d1b6c86f93..784ef802fc 100644 --- a/docs/libssh2_userauth_password_ex.3 +++ b/docs/libssh2_userauth_password_ex.3 @@ -2,19 +2,22 @@ .SH NAME libssh2_userauth_password_ex - authenticate a session with username and password .SH SYNOPSIS -#include .nf -int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, - const char *username, - unsigned int username_len, - const char *password, - unsigned int password_len, - LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb))); +#include + +int +libssh2_userauth_password_ex(LIBSSH2_SESSION *session, + const char *username, + unsigned int username_len, + const char *password, + unsigned int password_len, + LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb))); #define libssh2_userauth_password(session, username, password) \\ - libssh2_userauth_password_ex((session), (username), \\ - strlen(username), \\ - (password), strlen(password), NULL) + libssh2_userauth_password_ex((session), (username), \\ + strlen(username), \\ + (password), strlen(password), NULL) +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_userauth_publickey.3 b/docs/libssh2_userauth_publickey.3 index 0081a2489c..5712f4cec3 100644 --- a/docs/libssh2_userauth_publickey.3 +++ b/docs/libssh2_userauth_publickey.3 @@ -2,15 +2,17 @@ .SH NAME libssh2_userauth_publickey - authenticate using a callback function .SH SYNOPSIS +.nf #include -.nf -int libssh2_userauth_publickey(LIBSSH2_SESSION *session, - const char *user, - const unsigned char *pubkeydata, - size_t pubkeydata_len, - sign_callback, - void **abstract); +int +libssh2_userauth_publickey(LIBSSH2_SESSION *session, + const char *user, + const unsigned char *pubkeydata, + size_t pubkeydata_len, + sign_callback, + void **abstract); +.fi .SH DESCRIPTION Authenticate with the \fIsign_callback\fP callback that matches the prototype below diff --git a/docs/libssh2_userauth_publickey_fromfile.3 b/docs/libssh2_userauth_publickey_fromfile.3 index f4799a1c53..7be047d246 100644 --- a/docs/libssh2_userauth_publickey_fromfile.3 +++ b/docs/libssh2_userauth_publickey_fromfile.3 @@ -2,6 +2,7 @@ .SH NAME libssh2_userauth_publickey_fromfile - convenience macro for \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP calls .SH SYNOPSIS +.nf #include int @@ -10,7 +11,7 @@ libssh2_userauth_publickey_fromfile(LIBSSH2_SESSION *session, const char *publickey, const char *privatekey, const char *passphrase); - +.fi .SH DESCRIPTION This is a macro defined in a public libssh2 header file that is using the underlying function \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP. diff --git a/docs/libssh2_userauth_publickey_fromfile_ex.3 b/docs/libssh2_userauth_publickey_fromfile_ex.3 index f5ffc3670d..51091d7c29 100644 --- a/docs/libssh2_userauth_publickey_fromfile_ex.3 +++ b/docs/libssh2_userauth_publickey_fromfile_ex.3 @@ -1,16 +1,18 @@ -.TH libssh2_userauth_publickey_fromfile 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_userauth_publickey_fromfile_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" .SH NAME -libssh2_userauth_publickey_fromfile - authenticate a session with a public key, read from a file +libssh2_userauth_publickey_fromfile_ex - authenticate a session with a public key, read from a file .SH SYNOPSIS +.nf #include -.nf -int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, - const char *username, - unsigned int ousername_len, - const char *publickey, - const char *privatekey, - const char *passphrase); +int +libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, + const char *username, + unsigned int ousername_len, + const char *publickey, + const char *privatekey, + const char *passphrase); +.fi .SH DESCRIPTION \fIsession\fP - Session instance as returned by \fBlibssh2_session_init_ex(3)\fP diff --git a/docs/libssh2_userauth_publickey_frommemory.3 b/docs/libssh2_userauth_publickey_frommemory.3 index bd58fde51f..0509f1a785 100644 --- a/docs/libssh2_userauth_publickey_frommemory.3 +++ b/docs/libssh2_userauth_publickey_frommemory.3 @@ -2,17 +2,19 @@ .SH NAME libssh2_userauth_publickey_frommemory - authenticate a session with a public key, read from memory .SH SYNOPSIS +.nf #include -.nf -int libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session, - const char *username, - size_t username_len, - const char *publickeydata, - size_t publickeydata_len, - const char *privatekeydata, - size_t privatekeydata_len, - const char *passphrase); +int +libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session, + const char *username, + size_t username_len, + const char *publickeydata, + size_t publickeydata_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase); +.fi .SH DESCRIPTION This function allows to authenticate a session with a public key read from memory. It's only supported when libssh2 is backed by OpenSSL. diff --git a/docs/libssh2_userauth_publickey_sk.3 b/docs/libssh2_userauth_publickey_sk.3 index f24650f671..663acd5eb8 100644 --- a/docs/libssh2_userauth_publickey_sk.3 +++ b/docs/libssh2_userauth_publickey_sk.3 @@ -2,18 +2,19 @@ .SH NAME libssh2_userauth_publickey_sk - authenticate a session with a FIDO2 authenticator .SH SYNOPSIS -#include .nf -int libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, - const char *username, - size_t username_len, - const char *privatekeydata, - size_t privatekeydata_len, - const char *passphrase, - LIBSSH2_USERAUTH_SK_SIGN_FUNC - ((*sign_callback)), - void **abstract); +#include +int +libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, + const char *username, + size_t username_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase, + LIBSSH2_USERAUTH_SK_SIGN_FUNC((*sign_callback)), + void **abstract); +.fi .SH CALLBACK .nf #define LIBSSH2_SK_PRESENCE_REQUIRED 0x01 @@ -34,7 +35,6 @@ int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, const unsigned char *key_handle, size_t handle_len, void **abstract); .fi - .SH DESCRIPTION \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_version.3 b/docs/libssh2_version.3 index f98ca967c7..932c0af005 100644 --- a/docs/libssh2_version.3 +++ b/docs/libssh2_version.3 @@ -2,10 +2,12 @@ .SH NAME libssh2_version - return the libssh2 version number .SH SYNOPSIS +.nf #include const char * libssh2_version(int required_version); +.fi .SH DESCRIPTION If \fIrequired_version\fP is lower than or equal to the version number of the libssh2 in use, the version number of libssh2 is returned as a pointer to a diff --git a/docs/template.3 b/docs/template.3 index c3a229628a..e6b0ac020c 100644 --- a/docs/template.3 +++ b/docs/template.3 @@ -1,12 +1,13 @@ -.TH libssh2_template 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_template 3 "1 Jun 2022" "libssh2 1.10.0" "libssh2 manual" .SH NAME libssh2_template - short function description .SH SYNOPSIS +.nf #include void libssh2_template(void); - +.fi .SH DESCRIPTION Long text describing the function and its input arguments. From fe02bd2b2d75413dfcda14cb3f1004d677593941 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 11 Apr 2023 00:45:41 +0000 Subject: [PATCH 257/424] sftp: calculate attr size based on attr content in `sftp_open()` Improve robustness by replacing constant argument of `sftp_attrsize()` in `sftp_open()` with the actual `flag` value read from the `attr` we plan to transfer. Restores state of this before 37624b61e3ec4aa65a608800613d00b55ced56d7. Prerequisite for #947, #506. Also improve readability a bit and link to SFTP specs. Delete comment about version 6: The latest spec no longer features the mentioned "DO NOT IMPLEMENT" notice. Closes #946 --- src/sftp.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index d1dc1ad604..8eea6c88c3 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -45,11 +45,12 @@ #include "session.h" #include "sftp.h" -/* Note: Version 6 was documented at the time of writing - * However it was marked as "DO NOT IMPLEMENT" due to pending changes - * - * This release of libssh2 implements Version 5 with automatic downgrade +/* This release of libssh2 implements Version 5 with automatic downgrade * based on server's declaration + * https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-05.txt + * + * Version 6: + * https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-13.txt */ /* SFTP packet types */ @@ -98,19 +99,6 @@ static int sftp_packet_ask(LIBSSH2_SFTP *sftp, unsigned char packet_type, size_t *data_len); static void sftp_packet_flush(LIBSSH2_SFTP *sftp); -/* sftp_attrsize - * Size that attr with this flagset will occupy when turned into a bin struct - */ -static int sftp_attrsize(unsigned long flags) -{ - return (4 + /* flags(4) */ - ((flags & LIBSSH2_SFTP_ATTR_SIZE) ? 8 : 0) + - ((flags & LIBSSH2_SFTP_ATTR_UIDGID) ? 8 : 0) + - ((flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) ? 4 : 0) + - ((flags & LIBSSH2_SFTP_ATTR_ACMODTIME) ? 8 : 0)); - /* atime + mtime as u32 */ -} - /* _libssh2_store_u64 */ static void _libssh2_store_u64(unsigned char **ptr, libssh2_uint64_t value) @@ -631,6 +619,19 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses, return LIBSSH2_ERROR_SOCKET_DISCONNECT; } +/* sftp_attrsize + * Size that attr with this flagset will occupy when turned into a bin struct + */ +static int sftp_attrsize(unsigned long flags) +{ + return (4 + /* flags(4) */ + ((flags & LIBSSH2_SFTP_ATTR_SIZE) ? 8 : 0) + + ((flags & LIBSSH2_SFTP_ATTR_UIDGID) ? 8 : 0) + + ((flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) ? 4 : 0) + + ((flags & LIBSSH2_SFTP_ATTR_ACMODTIME) ? 8 : 0)); + /* atime + mtime as u32 */ +} + /* sftp_attr2bin * Populate attributes into an SFTP block */ @@ -639,8 +640,10 @@ sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs) { unsigned char *s = p; uint32_t flag_mask = - LIBSSH2_SFTP_ATTR_SIZE | LIBSSH2_SFTP_ATTR_UIDGID | - LIBSSH2_SFTP_ATTR_PERMISSIONS | LIBSSH2_SFTP_ATTR_ACMODTIME; + LIBSSH2_SFTP_ATTR_SIZE | + LIBSSH2_SFTP_ATTR_UIDGID | + LIBSSH2_SFTP_ATTR_PERMISSIONS | + LIBSSH2_SFTP_ATTR_ACMODTIME; /* TODO: When we add SFTP4+ functionality flag_mask can get additional bits */ @@ -1122,8 +1125,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, /* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) + flags(4) */ sftp->open_packet_len = (uint32_t)(filename_len + 13 + - (open_file? (4 + - sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0)); + (open_file? (4 + sftp_attrsize(attrs.flags)) : 0)); /* surprise! this starts out with nothing sent */ sftp->open_packet_sent = 0; From 73d95a055c8b7bd71323f82c46bd8a0255fa975c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 12 Apr 2023 09:17:10 +0000 Subject: [PATCH 258/424] build: be friendly with 3rd-party build tools After recent build changes, 3rd party build that took the list of C source to compile them as-is, stopped working as expected, due to `blowfish.c` and crypto-backend C sources no longer expected to compile separately but via `bcrypt_pbkdf.c` and `crypto.c`, respectively. This patch ensures that compiling these files directly result in an empty object instead of redundant code and duplicated symbols. Also: - add a compile-time error if none of the supported crypto backends are enabled. - fix `libssh2_crypto_engine()` for wolfSSL and os400qc3. Rearrange code to avoid a hard-to-find copy of crypto-backend selection guards. Follow-up to 4f0f4bff5a92dce6a6cd7a5600a8ee5660402c3f Follow-up to ff3c774e03585252b70a9ee0fcf254de7b14a767 Closes #951 --- include/libssh2.h | 3 ++- src/bcrypt_pbkdf.c | 1 + src/blowfish.c | 4 ++++ src/crypto.c | 2 ++ src/crypto.h | 22 ++++++++-------------- src/libgcrypt.c | 6 ++---- src/libgcrypt.h | 2 ++ src/mbedtls.c | 6 ++---- src/mbedtls.h | 2 ++ src/openssl.c | 7 ++----- src/openssl.h | 2 ++ src/os400qc3.c | 6 ++---- src/os400qc3.h | 2 ++ src/version.c | 12 +----------- src/wincng.c | 6 ++---- src/wincng.h | 2 ++ 16 files changed, 38 insertions(+), 47 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index 1490897649..f9e45e1f40 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -1010,7 +1010,8 @@ typedef enum { libssh2_openssl, libssh2_gcrypt, libssh2_mbedtls, - libssh2_wincng + libssh2_wincng, + libssh2_os400qc3 } libssh2_crypto_engine_t; LIBSSH2_API diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index bfbc69e420..2b84c70759 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -25,6 +25,7 @@ #include #endif +#define LIBSSH2_BCRYPT_PBKDF_C #include "blowfish.c" #define MINIMUM(a,b) (((a) < (b)) ? (a) : (b)) diff --git a/src/blowfish.c b/src/blowfish.c index 12eaed0132..40134ef38b 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -37,6 +37,8 @@ * Bruce Schneier. */ +#if defined(LIBSSH2_BCRYPT_PBKDF_C) || defined(_DEBUG_BLOWFISH) + #if !defined(HAVE_BCRYPT_PBKDF) && (!defined(HAVE_BLOWFISH_INITSTATE) || \ !defined(HAVE_BLOWFISH_EXPAND0STATE) || \ !defined(HAVE_BLF_ENC)) @@ -743,3 +745,5 @@ main(void) (!defined(HAVE_BLOWFISH_INITSTATE) || \ !defined(HAVE_BLOWFISH_EXPAND0STATE) || \ '!defined(HAVE_BLF_ENC)) */ + +#endif /* defined(LIBSSH2_BCRYPT_PBKDF_C) || defined(_DEBUG_BLOWFISH) */ diff --git a/src/crypto.c b/src/crypto.c index 789fcc4191..68db0f2ae6 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -1,3 +1,5 @@ +#define LIBSSH2_CRYPTO_C + #include "libssh2_priv.h" #if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) diff --git a/src/crypto.h b/src/crypto.h index b5d6e0e62d..168a8d3f65 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -40,22 +40,16 @@ #if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) #include "openssl.h" -#endif - -#ifdef LIBSSH2_LIBGCRYPT +#elif defined(LIBSSH2_LIBGCRYPT) #include "libgcrypt.h" -#endif - -#ifdef LIBSSH2_WINCNG -#include "wincng.h" -#endif - -#ifdef LIBSSH2_OS400QC3 -#include "os400qc3.h" -#endif - -#ifdef LIBSSH2_MBEDTLS +#elif defined(LIBSSH2_MBEDTLS) #include "mbedtls.h" +#elif defined(LIBSSH2_OS400QC3) +#include "os400qc3.h" +#elif defined(LIBSSH2_WINCNG) +#include "wincng.h" +#else +#error "no cryptography backend selected" #endif #ifdef LIBSSH2_NO_MD5 diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 6d7092ee6b..699f05fdf3 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -36,9 +36,7 @@ * OF SUCH DAMAGE. */ -#include "libssh2_priv.h" - -#ifdef LIBSSH2_LIBGCRYPT /* compile only if we build with libgcrypt */ +#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ #include @@ -741,4 +739,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, return NULL; } -#endif /* LIBSSH2_LIBGCRYPT */ +#endif /* LIBSSH2_CRYPTO_C */ diff --git a/src/libgcrypt.h b/src/libgcrypt.h index 54f011049a..58a375579a 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -39,6 +39,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_gcrypt + #include #define LIBSSH2_MD5 1 diff --git a/src/mbedtls.c b/src/mbedtls.c index 6c7f7f8c50..366f7c2212 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -35,9 +35,7 @@ * OF SUCH DAMAGE. */ -#include "libssh2_priv.h" - -#ifdef LIBSSH2_MBEDTLS /* compile only if we build with mbedtls */ +#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ #if MBEDTLS_VERSION_NUMBER < 0x03000000 #define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) @@ -1456,4 +1454,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, } #endif /* LIBSSH2_ECDSA */ -#endif /* LIBSSH2_MBEDTLS */ +#endif /* LIBSSH2_CRYPTO_C */ diff --git a/src/mbedtls.h b/src/mbedtls.h index 4db9ee405c..3fd7a8b1dc 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -37,6 +37,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls + #include #include diff --git a/src/openssl.c b/src/openssl.c index 1dd6b17f25..dd00b22aba 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -38,10 +38,7 @@ * OF SUCH DAMAGE. */ -#include "libssh2_priv.h" - -/* compile only if we build with openssl or wolfSSL */ -#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) +#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ #include @@ -3918,4 +3915,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, return NULL; } -#endif /* LIBSSH2_OPENSSL */ +#endif /* LIBSSH2_CRYPTO_C */ diff --git a/src/openssl.h b/src/openssl.h index c3d98f9ddd..2f347c36ca 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -39,6 +39,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_openssl + /* disable deprecated warnings in OpenSSL 3 */ #define OPENSSL_SUPPRESS_DEPRECATED diff --git a/src/os400qc3.c b/src/os400qc3.c index 420cfad26e..b7fc7487ab 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -37,9 +37,7 @@ * OF SUCH DAMAGE. */ -#include "libssh2_priv.h" - -#ifdef LIBSSH2_OS400QC3 /* compile only if we build with OS/400 QC3 library */ +#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ #include @@ -2442,6 +2440,6 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, return NULL; } -#endif /* LIBSSH2_OS400QC3 */ +#endif /* LIBSSH2_CRYPTO_C */ /* vim: set expandtab ts=4 sw=4: */ diff --git a/src/os400qc3.h b/src/os400qc3.h index 23148dbe50..8d26dfbf11 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -39,6 +39,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_os400qc3 + #include #include diff --git a/src/version.c b/src/version.c index c54d57cd23..2d5f46f95d 100644 --- a/src/version.c +++ b/src/version.c @@ -56,15 +56,5 @@ const char *libssh2_version(int req_version_num) LIBSSH2_API libssh2_crypto_engine_t libssh2_crypto_engine(void) { -#if defined LIBSSH2_OPENSSL - return libssh2_openssl; -#elif defined LIBSSH2_LIBGCRYPT - return libssh2_gcrypt; -#elif defined LIBSSH2_MBEDTLS - return libssh2_mbedtls; -#elif defined LIBSSH2_WINCNG - return libssh2_wincng; -#else - return libssh2_no_crypto; -#endif + return LIBSSH2_CRYPTO_ENGINE; } diff --git a/src/wincng.c b/src/wincng.c index 72f8bfed3a..eb5107f9e3 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -36,9 +36,7 @@ * OF SUCH DAMAGE. */ -#include "libssh2_priv.h" - -#ifdef LIBSSH2_WINCNG /* compile only if we build with wincng */ +#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ /* required for cross-compilation against the w64 mingw-runtime package */ #if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) @@ -2730,4 +2728,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, return NULL; } -#endif /* LIBSSH2_WINCNG */ +#endif /* LIBSSH2_CRYPTO_C */ diff --git a/src/wincng.h b/src/wincng.h index 2b91afd1d8..32410d1e42 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -38,6 +38,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_wincng + /* required for cross-compilation against the w64 mingw-runtime package */ #if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) #undef _WIN32_WINNT From 1ccae7d5482b362b6685916858dfac726f09fd4b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 12 Apr 2023 09:17:54 +0000 Subject: [PATCH 259/424] ci: use OpenSSL 3 on AppVeyor VS2022 images Closes #954 --- appveyor.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a55f55c37b..dc99c1858a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,7 +26,7 @@ environment: matrix: - - job_name: "VS2022, OpenSSL, x64" + - job_name: "VS2022, OpenSSL3, x64" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" PLATFORM: "x64" @@ -147,10 +147,16 @@ build_script: $env:GENERATOR += " Win64" } if($env:SKIP_CTEST -ne "yes" -and $env:CRYPTO_BACKEND -eq "OpenSSL") { - if($env:PLATFORM -eq "x64") { - $env:CMAKE_ARG += " -DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64" - } elseif($env:PLATFORM -eq "x86") { - $env:CMAKE_ARG += " -DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win32" + if($env:APPVEYOR_BUILD_WORKER_IMAGE -eq "Visual Studio 2022") { + if($env:PLATFORM -eq "x64") { + $env:CMAKE_ARG += " -DOPENSSL_ROOT_DIR=C:/OpenSSL-v30-Win64" + } + } else { + if($env:PLATFORM -eq "x64") { + $env:CMAKE_ARG += " -DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64" + } elseif($env:PLATFORM -eq "x86") { + $env:CMAKE_ARG += " -DOPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win32" + } } } - echo cmake "-G%GENERATOR%" %CMAKE_ARG% -DENABLE_WERROR=ON -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% From 224fffb178995a320c3cea3d4629ff49141b7351 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 13 Apr 2023 11:09:35 +0000 Subject: [PATCH 260/424] include: delete leading underscore from macro name It can cause compiler warnings in 3rd-party code. Follow-up to 59666e03f04927e5fe3e8d8772d40729f63c570e Closes #957 --- include/libssh2.h | 18 +++++++++--------- include/libssh2_sftp.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index f9e45e1f40..657e12bc31 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -89,10 +89,10 @@ extern "C" { #endif #if defined(_WIN32) || defined(WIN32) -#define _LIBSSH2_WIN32 +#define LIBSSH2_WIN32 #endif -#ifdef _LIBSSH2_WIN32 +#ifdef LIBSSH2_WIN32 # include # include #endif @@ -104,7 +104,7 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API -# ifdef _LIBSSH2_WIN32 +# ifdef LIBSSH2_WIN32 # if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || defined(_WINDLL) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) @@ -114,9 +114,9 @@ extern "C" { # else # define LIBSSH2_API # endif -# else /* !_LIBSSH2_WIN32 */ +# else /* !LIBSSH2_WIN32 */ # define LIBSSH2_API -# endif /* _LIBSSH2_WIN32 */ +# endif /* LIBSSH2_WIN32 */ #endif /* LIBSSH2_API */ #ifdef HAVE_SYS_UIO_H @@ -142,13 +142,13 @@ typedef unsigned long long libssh2_uint64_t; typedef long long libssh2_int64_t; #endif -#ifdef _LIBSSH2_WIN32 +#ifdef LIBSSH2_WIN32 typedef SOCKET libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET INVALID_SOCKET -#else /* !_LIBSSH2_WIN32 */ +#else /* !LIBSSH2_WIN32 */ typedef int libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET -1 -#endif /* _LIBSSH2_WIN32 */ +#endif /* LIBSSH2_WIN32 */ /* * Determine whether there is small or large file support on windows. @@ -174,7 +174,7 @@ typedef int libssh2_socket_t; # undef LIBSSH2_USE_WIN32_LARGE_FILES #endif -#if defined(_LIBSSH2_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ +#if defined(LIBSSH2_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ !defined(LIBSSH2_USE_WIN32_SMALL_FILES) # define LIBSSH2_USE_WIN32_SMALL_FILES #endif diff --git a/include/libssh2_sftp.h b/include/libssh2_sftp.h index 0e848f5205..e406127f76 100644 --- a/include/libssh2_sftp.h +++ b/include/libssh2_sftp.h @@ -40,7 +40,7 @@ #include "libssh2.h" -#ifndef _LIBSSH2_WIN32 +#ifndef LIBSSH2_WIN32 #include #endif From ec0feae7920d695ce234a5aba13014bf29824c09 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 13 Apr 2023 11:12:22 +0000 Subject: [PATCH 261/424] build: speed up and extend picky compiler options Implement picky warnings with clang in autotools. Extend picky gcc warnings, sync them between build tools and compilers and greatly speed up detection in CMake. - autotools: enable clang compiler warnings with `--enable-debug`. - autotools: enable more gcc compiler warnings with `--enable-debug`. - autotools/cmake: sync compiler warning options between gcc and clang. - sync compiler warning options between autotools and cmake. - cmake: reduce option-checks to speed up the detection phase. Bring them down to 3 (from 35). Leaving some checks to keep the CMake logic alive and for an easy way to add new options. clang 3.0 (2011-11-29) and gcc 2.95 (1999-07-31) now required. - autotools logic copied from curl, with these differences: - delete `-Wimplicit-fallthrough=4` due to a false positive. - reduce `-Wformat-truncation=2` to `1` due to a false positive. - simplify MinGW detection for `-Wno-pedantic-ms-format`. - cmake: show enabled picky compiler options (like autotools). - cmake: do compile `tests/simple.c` and `tests/ssh2.c`. - fix new compiler warnings. - `tests/CMakeLists.txt`: fix indentation. Original source of autotools logic: - https://github.com/curl/curl/blob/a8fbdb461cecbfe1ac6ecc5d8f6cf181e1507da8/acinclude.m4 - https://github.com/curl/curl/blob/a8fbdb461cecbfe1ac6ecc5d8f6cf181e1507da8/m4/curl-compilers.m4 Notice that the autotools implementation considers Apple clang as legacy clang 3.7. CMake detection works more accurately, at the same time more error-prone and difficult to update due to the sparsely documented nature of Apple clang option evolution. Closes #952 --- acinclude.m4 | 398 +++++++++++++++++- cmake/max_warnings.cmake | 170 +++++++- example/sftpdir_nonblock.c | 4 +- example/tcpip-forward.c | 6 +- example/x11.c | 4 +- src/agent.c | 28 +- src/agent.h | 6 +- src/comp.c | 2 +- src/hostkey.c | 4 +- src/kex.c | 211 +++++----- src/libgcrypt.h | 2 +- src/mbedtls.c | 21 +- src/openssl.c | 15 +- tests/CMakeLists.txt | 33 +- tests/openssh_fixture.c | 3 +- tests/session_fixture.c | 4 +- tests/simple.c | 4 +- tests/ssh2.c | 2 +- tests/test_agent_forward_succeeds.c | 6 +- ...t_keyboard_interactive_auth_info_request.c | 9 +- ...cceeds_with_correct_ed25519_key_from_mem.c | 4 +- 21 files changed, 740 insertions(+), 196 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 9c497944b5..9f60b9c1ca 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,3 +1,145 @@ +dnl CURL_CPP_P +dnl +dnl Check if $cpp -P should be used for extract define values due to gcc 5 +dnl splitting up strings and defines between line outputs. gcc by default +dnl (without -P) will show TEST EINVAL TEST as +dnl +dnl # 13 "conftest.c" +dnl TEST +dnl # 13 "conftest.c" 3 4 +dnl 22 +dnl # 13 "conftest.c" +dnl TEST + +AC_DEFUN([CURL_CPP_P], [ + AC_MSG_CHECKING([if cpp -P is needed]) + AC_EGREP_CPP([TEST.*TEST], [ + #include +TEST EINVAL TEST + ], [cpp=no], [cpp=yes]) + AC_MSG_RESULT([$cpp]) + + dnl we need cpp -P so check if it works then + if test "x$cpp" = "xyes"; then + AC_MSG_CHECKING([if cpp -P works]) + OLDCPPFLAGS=$CPPFLAGS + CPPFLAGS="$CPPFLAGS -P" + AC_EGREP_CPP([TEST.*TEST], [ + #include +TEST EINVAL TEST + ], [cpp_p=yes], [cpp_p=no]) + AC_MSG_RESULT([$cpp_p]) + + if test "x$cpp_p" = "xno"; then + AC_MSG_WARN([failed to figure out cpp -P alternative]) + # without -P + CPPPFLAG="" + else + # with -P + CPPPFLAG="-P" + fi + dnl restore CPPFLAGS + CPPFLAGS=$OLDCPPFLAGS + else + # without -P + CPPPFLAG="" + fi +]) + +dnl CURL_CHECK_DEF (SYMBOL, [INCLUDES], [SILENT]) +dnl ------------------------------------------------- +dnl Use the C preprocessor to find out if the given object-style symbol +dnl is defined and get its expansion. This macro will not use default +dnl includes even if no INCLUDES argument is given. This macro will run +dnl silently when invoked with three arguments. If the expansion would +dnl result in a set of double-quoted strings the returned expansion will +dnl actually be a single double-quoted string concatenating all them. + +AC_DEFUN([CURL_CHECK_DEF], [ + AC_REQUIRE([CURL_CPP_P])dnl + OLDCPPFLAGS=$CPPFLAGS + # CPPPFLAG comes from CURL_CPP_P + CPPFLAGS="$CPPFLAGS $CPPPFLAG" + AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl + AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl + if test -z "$SED"; then + AC_MSG_ERROR([SED not set. Cannot continue without SED being set.]) + fi + if test -z "$GREP"; then + AC_MSG_ERROR([GREP not set. Cannot continue without GREP being set.]) + fi + ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])]) + tmp_exp="" + AC_PREPROC_IFELSE([ + AC_LANG_SOURCE( +ifelse($2,,,[$2])[[ +#ifdef $1 +CURL_DEF_TOKEN $1 +#endif + ]]) + ],[ + tmp_exp=`eval "$ac_cpp conftest.$ac_ext" 2>/dev/null | \ + "$GREP" CURL_DEF_TOKEN 2>/dev/null | \ + "$SED" 's/.*CURL_DEF_TOKEN[[ ]][[ ]]*//' 2>/dev/null | \ + "$SED" 's/[["]][[ ]]*[["]]//g' 2>/dev/null` + if test -z "$tmp_exp" || test "$tmp_exp" = "$1"; then + tmp_exp="" + fi + ]) + if test -z "$tmp_exp"; then + AS_VAR_SET(ac_HaveDef, no) + ifelse($3,,[AC_MSG_RESULT([no])]) + else + AS_VAR_SET(ac_HaveDef, yes) + AS_VAR_SET(ac_Def, $tmp_exp) + ifelse($3,,[AC_MSG_RESULT([$tmp_exp])]) + fi + AS_VAR_POPDEF([ac_Def])dnl + AS_VAR_POPDEF([ac_HaveDef])dnl + CPPFLAGS=$OLDCPPFLAGS +]) + +dnl CURL_CHECK_COMPILER_CLANG +dnl ------------------------------------------------- +dnl Verify if compiler being used is clang. + +AC_DEFUN([CURL_CHECK_COMPILER_CLANG], [ + AC_BEFORE([$0],[CURL_CHECK_COMPILER_GNU_C])dnl + AC_MSG_CHECKING([if compiler is clang]) + CURL_CHECK_DEF([__clang__], [], [silent]) + if test "$curl_cv_have_def___clang__" = "yes"; then + AC_MSG_RESULT([yes]) + AC_MSG_CHECKING([if compiler is xlclang]) + CURL_CHECK_DEF([__ibmxl__], [], [silent]) + if test "$curl_cv_have_def___ibmxl__" = "yes" ; then + dnl IBM's almost-compatible clang version + AC_MSG_RESULT([yes]) + compiler_id="XLCLANG" + else + AC_MSG_RESULT([no]) + compiler_id="CLANG" + fi + fullclangver=`$CC -v 2>&1 | grep version` + clangver=`echo $fullclangver | grep "based on LLVM " | "$SED" 's/.*(based on LLVM \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*)/\1/'` + if test -z "$clangver"; then + if echo $fullclangver | grep "Apple LLVM version " >/dev/null; then + dnl Starting with XCode 7 / clang 3.7, Apple clang won't tell its upstream version + clangver="3.7" + else + clangver=`echo $fullclangver | "$SED" 's/.*version \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*/\1/'` + fi + fi + clangvhi=`echo $clangver | cut -d . -f1` + clangvlo=`echo $clangver | cut -d . -f2` + compiler_num=`(expr $clangvhi "*" 100 + $clangvlo) 2>/dev/null` + flags_dbg_yes="-g" + flags_opt_all="-O -O0 -O1 -O2 -Os -O3 -O4" + flags_opt_yes="-O2" + flags_opt_off="-O0" + else + AC_MSG_RESULT([no]) + fi +]) dnl ********************************************************************** dnl CURL_DETECT_ICC ([ACTION-IF-YES]) @@ -33,11 +175,123 @@ dnl options are only used for debug-builds. AC_DEFUN([CURL_CC_DEBUG_OPTS], [ + if test "z$CLANG" = "z"; then + CURL_CHECK_COMPILER_CLANG + if test "z$compiler_id" = "zCLANG"; then + CLANG="yes" + else + CLANG="no" + fi + fi if test "z$ICC" = "z"; then CURL_DETECT_ICC fi - if test "$GCC" = "yes"; then + if test "$CLANG" = "yes"; then + + dnl figure out clang version! + AC_MSG_CHECKING([clang version]) + fullclangver=`$CC -v 2>&1 | grep version` + clangver=`echo $fullclangver | grep "based on LLVM " | "$SED" 's/.*(based on LLVM \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*)/\1/'` + if test -z "$clangver"; then + if echo $fullclangver | grep "Apple LLVM version " >/dev/null; then + dnl Starting with Xcode 7 / clang 3.7, Apple clang won't tell its upstream version + clangver="3.7" + else + clangver=`echo $fullclangver | "$SED" 's/.*version \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*/\1/'` + fi + fi + clangvhi=`echo $clangver | cut -d . -f1` + clangvlo=`echo $clangver | cut -d . -f2` + compiler_num=`(expr $clangvhi "*" 100 + $clangvlo) 2>/dev/null` + AC_MSG_RESULT($compiler_num) + + WARN="-pedantic" + CURL_ADD_COMPILER_WARNINGS([WARN], [all extra]) + CURL_ADD_COMPILER_WARNINGS([WARN], [pointer-arith write-strings]) + CURL_ADD_COMPILER_WARNINGS([WARN], [shadow]) + CURL_ADD_COMPILER_WARNINGS([WARN], [inline nested-externs]) + CURL_ADD_COMPILER_WARNINGS([WARN], [missing-declarations]) + CURL_ADD_COMPILER_WARNINGS([WARN], [missing-prototypes]) + WARN="$WARN -Wno-long-long" + CURL_ADD_COMPILER_WARNINGS([WARN], [float-equal]) + CURL_ADD_COMPILER_WARNINGS([WARN], [no-multichar sign-compare]) + CURL_ADD_COMPILER_WARNINGS([WARN], [undef]) + WARN="$WARN -Wno-format-nonliteral" + CURL_ADD_COMPILER_WARNINGS([WARN], [endif-labels strict-prototypes]) + CURL_ADD_COMPILER_WARNINGS([WARN], [declaration-after-statement]) + CURL_ADD_COMPILER_WARNINGS([WARN], [cast-align]) + WARN="$WARN -Wno-system-headers" + CURL_ADD_COMPILER_WARNINGS([WARN], [shorten-64-to-32]) + # + dnl Only clang 1.1 or later + if test "$compiler_num" -ge "101"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [unused]) + fi + # + dnl Only clang 2.8 or later + if test "$compiler_num" -ge "208"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [vla]) + fi + # + dnl Only clang 2.9 or later + if test "$compiler_num" -ge "209"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [shift-sign-overflow]) + fi + # + dnl Only clang 3.0 or later (possibly earlier) + if test "$compiler_num" -ge "300"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [conversion]) + CURL_ADD_COMPILER_WARNINGS([WARN], [empty-body]) + CURL_ADD_COMPILER_WARNINGS([WARN], [ignored-qualifiers]) + CURL_ADD_COMPILER_WARNINGS([WARN], [type-limits]) + CURL_ADD_COMPILER_WARNINGS([WARN], [no-sign-conversion]) + fi + # + dnl Only clang 3.2 or later + if test "$compiler_num" -ge "302"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [enum-conversion]) + case $host_os in + cygwin* | mingw*) + dnl skip missing-variable-declarations warnings for cygwin and + dnl mingw because the libtool wrapper executable causes them + ;; + *) + CURL_ADD_COMPILER_WARNINGS([WARN], [missing-variable-declarations]) + ;; + esac + fi + # + dnl Only clang 3.4 or later + if test "$compiler_num" -ge "304"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [unused-const-variable]) + fi + # + dnl Only clang 3.6 or later + if test "$compiler_num" -ge "306"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [double-promotion]) + fi + # + dnl Only clang 3.9 or later + if test "$compiler_num" -ge "309"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [comma]) + # avoid the varargs warning, fixed in 4.0 + # https://bugs.llvm.org/show_bug.cgi?id=29140 + if test "$compiler_num" -lt "400"; then + WARN="$WARN -Wno-varargs" + fi + fi + dnl clang 7 or later + if test "$compiler_num" -ge "700"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [assign-enum]) + CURL_ADD_COMPILER_WARNINGS([WARN], [extra-semi-stmt]) + fi + + CFLAGS="$CFLAGS $WARN" + + AC_MSG_NOTICE([Added this set of compiler options: $WARN]) + + elif test "$GCC" = "yes"; then dnl figure out gcc version! AC_MSG_CHECKING([gcc version]) @@ -69,8 +323,6 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], dnl this is a set of options we believe *ALL* gcc versions support: WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes" - dnl -Wcast-align is a bit too annoying on all gcc versions ;-) - if test "$gccnum" -ge "207"; then dnl gcc 2.7 or later WARN="$WARN -Wmissing-declarations" @@ -80,7 +332,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], dnl only if the compiler is newer than 2.95 since we got lots of dnl "`_POSIX_C_SOURCE' is not defined" in system headers with dnl gcc 2.95.4 on FreeBSD 4.9! - WARN="$WARN -Wundef -Wno-long-long -Wsign-compare" + WARN="$WARN -Wundef -Wno-long-long -Wno-multichar -Wshadow -Wsign-compare -Wunused" fi if test "$gccnum" -ge "296"; then @@ -108,6 +360,83 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], WARN="$WARN -Wdeclaration-after-statement" fi + dnl Only gcc 4.0 or later + if test "$gccnum" -ge "400"; then + WARN="$WARN -Wstrict-aliasing=3" + fi + # + dnl Only gcc 4.1 or later (possibly earlier) + if test "$gccnum" -ge "401"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [no-system-headers]) + fi + # + dnl Only gcc 4.2 or later + if test "$gccnum" -ge "402"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [cast-align]) + fi + # + dnl Only gcc 4.3 or later + if test "$gccnum" -ge "403"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [type-limits old-style-declaration]) + CURL_ADD_COMPILER_WARNINGS([WARN], [missing-parameter-type empty-body]) + CURL_ADD_COMPILER_WARNINGS([WARN], [ignored-qualifiers]) + CURL_ADD_COMPILER_WARNINGS([WARN], [conversion]) + WARN="$WARN -Wno-sign-conversion" + CURL_ADD_COMPILER_WARNINGS([WARN], [vla]) + dnl required for -Warray-bounds, included in -Wall + WARN="$WARN -ftree-vrp" + fi + # + dnl Only gcc 4.5 or later + if test "$gccnum" -ge "405"; then + dnl Only windows targets + case $host_os in + mingw*) + WARN="$WARN -Wno-pedantic-ms-format" + ;; + esac + fi + # + dnl Only gcc 4.6 or later + if test "$gccnum" -ge "406"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [double-promotion]) + fi + # + dnl only gcc 4.8 or later + if test "$gccnum" -ge "408"; then + WARN="$WARN -Wformat=2" + fi + # + dnl Only gcc 5 or later + if test "$gccnum" -ge "500"; then + WARN="$WARN -Warray-bounds=2" + fi + # + dnl Only gcc 6 or later + if test "$gccnum" -ge "600"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [shift-negative-value]) + WARN="$WARN -Wshift-overflow=2" + CURL_ADD_COMPILER_WARNINGS([WARN], [null-dereference]) + WARN="$WARN -fdelete-null-pointer-checks" + CURL_ADD_COMPILER_WARNINGS([WARN], [duplicated-cond]) + CURL_ADD_COMPILER_WARNINGS([WARN], [unused-const-variable]) + fi + # + dnl Only gcc 7 or later + if test "$gccnum" -ge "700"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [duplicated-branches]) + CURL_ADD_COMPILER_WARNINGS([WARN], [restrict]) + CURL_ADD_COMPILER_WARNINGS([WARN], [alloc-zero]) + WARN="$WARN -Wformat-overflow=2" + WARN="$WARN -Wformat-truncation=1" + fi + # + dnl Only gcc 10 or later + if test "$gccnum" -ge "1000"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [arith-conversion]) + CURL_ADD_COMPILER_WARNINGS([WARN], [enum-conversion]) + fi + for flag in $CPPFLAGS; do case "$flag" in -I*) @@ -148,6 +477,67 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], ]) dnl end of AC_DEFUN() +dnl CURL_ADD_COMPILER_WARNINGS (WARNING-LIST, NEW-WARNINGS) +dnl ------------------------------------------------------- +dnl Contents of variable WARNING-LIST and NEW-WARNINGS are +dnl handled as whitespace separated lists of words. +dnl Add each compiler warning from NEW-WARNINGS that has not +dnl been disabled via CFLAGS to WARNING-LIST. + +AC_DEFUN([CURL_ADD_COMPILER_WARNINGS], [ + AC_REQUIRE([CURL_SHFUNC_SQUEEZE])dnl + ac_var_added_warnings="" + for warning in [$2]; do + CURL_VAR_MATCH(CFLAGS, [-Wno-$warning -W$warning]) + if test "$ac_var_match_word" = "no"; then + ac_var_added_warnings="$ac_var_added_warnings -W$warning" + fi + done + dnl squeeze whitespace out of result + [$1]="$[$1] $ac_var_added_warnings" + squeeze [$1] +]) + +dnl CURL_SHFUNC_SQUEEZE +dnl ------------------------------------------------- +dnl Declares a shell function squeeze() which removes +dnl redundant whitespace out of a shell variable. + +AC_DEFUN([CURL_SHFUNC_SQUEEZE], [ +squeeze() { + _sqz_result="" + eval _sqz_input=\[$][$]1 + for _sqz_token in $_sqz_input; do + if test -z "$_sqz_result"; then + _sqz_result="$_sqz_token" + else + _sqz_result="$_sqz_result $_sqz_token" + fi + done + eval [$]1=\$_sqz_result + return 0 +} +]) + +dnl CURL_VAR_MATCH (VARNAME, VALUE) +dnl ------------------------------------------------- +dnl Verifies if shell variable VARNAME contains VALUE. +dnl Contents of variable VARNAME and VALUE are handled +dnl as whitespace separated lists of words. If at least +dnl one word of VALUE is present in VARNAME the match +dnl is considered positive, otherwise false. + +AC_DEFUN([CURL_VAR_MATCH], [ + ac_var_match_word="no" + for word1 in $[$1]; do + for word2 in [$2]; do + if test "$word1" = "$word2"; then + ac_var_match_word="yes" + fi + done + done +]) + dnl CURL_CHECK_NONBLOCKING_SOCKET dnl ------------------------------------------------- dnl Check for how to set a socket to non-blocking state. There seems to exist diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index 1f42b03cf0..dfa614eafa 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -28,6 +28,10 @@ if(MSVC) endif() endif() elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang") + + # https://clang.llvm.org/docs/DiagnosticsReference.html + # https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") endif() @@ -36,23 +40,169 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I endif() if(PICKY_COMPILER) - foreach(_CCOPT -pedantic -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wfloat-equal -Wsign-compare -Wundef -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wvla -Wdouble-promotion -Wenum-conversion -Warith-conversion) + + # WPICKY_ENABLE = Options we want to enable as-is. + # WPICKY_DETECT = Options we want to test first and enable if available. + + # Prefer the -Wextra alias with clang. + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + set(WPICKY_ENABLE "-Wextra") + else() + set(WPICKY_ENABLE "-W") + endif() + + list(APPEND WPICKY_ENABLE + -pedantic + ) + + # ---------------------------------- + # Add new options here, if in doubt: + # ---------------------------------- + set(WPICKY_DETECT + ) + + # Assume these options always exist with both clang and gcc. + # Require clang 3.0 / gcc 2.95 or later. + list(APPEND WPICKY_ENABLE + -Wconversion # clang 3.0 gcc 2.95 + -Winline # clang 1.0 gcc 1.0 + -Wmissing-declarations # clang 1.0 gcc 2.7 + -Wmissing-prototypes # clang 1.0 gcc 1.0 + -Wnested-externs # clang 1.0 gcc 1.0 + -Wno-long-long # clang 1.0 gcc 2.95 + -Wno-multichar # clang 1.0 gcc 2.95 + -Wpointer-arith # clang 1.0 gcc 1.0 + -Wshadow # clang 1.0 gcc 2.95 + -Wsign-compare # clang 1.0 gcc 2.95 + -Wundef # clang 1.0 gcc 2.95 + -Wunused # clang 1.1 gcc 2.95 + -Wwrite-strings # clang 1.0 gcc 1.0 + ) + + # Always enable with clang, version dependent with gcc + set(WPICKY_COMMON_OLD + -Wcast-align # clang 1.0 gcc 4.2 + -Wdeclaration-after-statement # clang 1.0 gcc 3.4 + -Wempty-body # clang 3.0 gcc 4.3 + -Wendif-labels # clang 1.0 gcc 3.3 + -Wfloat-equal # clang 1.0 gcc 2.96 (3.0) + -Wignored-qualifiers # clang 3.0 gcc 4.3 + -Wno-format-nonliteral # clang 1.0 gcc 2.96 (3.0) + -Wno-sign-conversion # clang 3.0 gcc 4.3 + -Wno-system-headers # clang 1.0 gcc 3.0 + -Wstrict-prototypes # clang 1.0 gcc 3.3 + -Wtype-limits # clang 3.0 gcc 4.3 + -Wvla # clang 2.8 gcc 4.3 + ) + + set(WPICKY_COMMON + -Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3 + -Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0 + -Wunused-const-variable # clang 3.4 gcc 6.0 appleclang 5.1 + ) + + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + list(APPEND WPICKY_ENABLE + ${WPICKY_COMMON_OLD} + -Wshift-sign-overflow # clang 2.9 + -Wshorten-64-to-32 # clang 1.0 + ) + # Enable based on compiler version + if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR + (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3)) + list(APPEND WPICKY_ENABLE + ${WPICKY_COMMON} + ) + endif() + if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9) OR + (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.3)) + list(APPEND WPICKY_ENABLE + -Wcomma # clang 3.9 appleclang 8.3 + -Wmissing-variable-declarations # clang 3.2 appleclang 4.6 + ) + endif() + if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) OR + (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.3)) + list(APPEND WPICKY_ENABLE + -Wassign-enum # clang 7.0 appleclang 10.3 + -Wextra-semi-stmt # clang 7.0 appleclang 10.3 + ) + endif() + else() # gcc + list(APPEND WPICKY_DETECT + ${WPICKY_COMMON} + ) + # Enable based on compiler version + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3) + list(APPEND WPICKY_ENABLE + ${WPICKY_COMMON_OLD} + -Wmissing-parameter-type # gcc 4.3 + -Wold-style-declaration # gcc 4.3 + -Wstrict-aliasing=3 # gcc 4.0 + ) + endif() + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND MINGW) + list(APPEND WPICKY_ENABLE + -Wno-pedantic-ms-format # gcc 4.5 (mingw-only) + ) + endif() + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8) + list(APPEND WPICKY_ENABLE + -Wformat=2 # clang 3.0 gcc 4.8 (clang part-default, enabling it fully causes -Wformat-nonliteral warnings) + ) + endif() + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0) + list(APPEND WPICKY_ENABLE + -Warray-bounds=2 -ftree-vrp # clang 3.0 gcc 5.0 (clang default: -Warray-bounds) + ) + endif() + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0) + list(APPEND WPICKY_ENABLE + -Wduplicated-cond # gcc 6.0 + -Wnull-dereference # clang 3.0 gcc 6.0 (clang default) + -fdelete-null-pointer-checks + -Wshift-negative-value # clang 3.7 gcc 6.0 (clang default) + -Wshift-overflow=2 # clang 3.0 gcc 6.0 (clang default: -Wshift-overflow) + ) + endif() + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) + list(APPEND WPICKY_ENABLE + -Walloc-zero # gcc 7.0 + -Wduplicated-branches # gcc 7.0 + -Wformat-overflow=2 # gcc 7.0 + -Wformat-truncation=1 # gcc 7.0 + -Wrestrict # gcc 7.0 + ) + endif() + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) + list(APPEND WPICKY_ENABLE + -Warith-conversion # gcc 10.0 + ) + endif() + endif() + + # + + unset(WPICKY) + + foreach(_CCOPT ${WPICKY_ENABLE}) + set(WPICKY "${WPICKY} ${_CCOPT}") + endforeach() + + foreach(_CCOPT ${WPICKY_DETECT}) # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new # test result in. string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname) - check_c_compiler_flag(${_CCOPT} ${_optvarname}) - if(${_optvarname}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}") - endif() - endforeach() - foreach(_CCOPT long-long multichar format-nonliteral sign-conversion system-headers pedantic-ms-format) # GCC only warns about unknown -Wno- options if there are also other diagnostic messages, # so test for the positive form instead - string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname) - check_c_compiler_flag("-W${_CCOPT}" ${_optvarname}) + string(REPLACE "-Wno-" "-W" _CCOPT_ON "${_CCOPT}") + check_c_compiler_flag(${_CCOPT_ON} ${_optvarname}) if(${_optvarname}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-${_CCOPT}") + set(WPICKY "${WPICKY} ${_CCOPT}") endif() endforeach() + + message(STATUS "Picky compiler options:${WPICKY}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WPICKY}") endif() endif() diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index cc8d888b57..976dea47c5 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -185,9 +185,7 @@ int main(int argc, char *argv[]) /* loop until we fail */ while((rc = libssh2_sftp_readdir(sftp_handle, mem, sizeof(mem), - &attrs)) == LIBSSH2_ERROR_EAGAIN) { - ; - } + &attrs)) == LIBSSH2_ERROR_EAGAIN); if(rc > 0) { /* rc is the length of the file name in the mem buffer */ diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index d802c58efd..7925a02ba9 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -46,11 +46,11 @@ static const char *server_ip = "127.0.0.1"; /* resolved by the server */ static const char *remote_listenhost = "localhost"; -int remote_wantport = 2222; -int remote_listenport; +static int remote_wantport = 2222; +static int remote_listenport; static const char *local_destip = "127.0.0.1"; -int local_destport = 22; +static int local_destport = 22; enum { AUTH_NONE = 0, diff --git a/example/x11.c b/example/x11.c index e5c6815c76..4c0a1d4ced 100644 --- a/example/x11.c +++ b/example/x11.c @@ -55,8 +55,8 @@ struct chan_X11_list { struct chan_X11_list *next; }; -struct chan_X11_list * gp_x11_chan = NULL; -struct termios _saved_tio; +static struct chan_X11_list * gp_x11_chan = NULL; +static struct termios _saved_tio; /* * Utility function to remove a Node of the chained list diff --git a/src/agent.c b/src/agent.c index a7b5de7e06..9ac83bb2b9 100644 --- a/src/agent.c +++ b/src/agent.c @@ -128,20 +128,22 @@ agent_connect_unix(LIBSSH2_AGENT *agent) } #define RECV_SEND_ALL(func, socket, buffer, length, flags, abstract) \ - size_t finished = 0; \ + do { \ + size_t finished = 0; \ \ - while(finished < length) { \ - ssize_t rc; \ - rc = func(socket, \ - (char *)buffer + finished, length - finished, \ - flags, abstract); \ - if(rc < 0) \ - return rc; \ + while(finished < length) { \ + ssize_t rc; \ + rc = func(socket, \ + (char *)buffer + finished, length - finished, \ + flags, abstract); \ + if(rc < 0) \ + return rc; \ \ - finished += rc; \ - } \ + finished += rc; \ + } \ \ - return finished; + return finished; \ + } while(0) static ssize_t _send_all(LIBSSH2_SEND_FUNC(func), libssh2_socket_t socket, const void *buffer, size_t length, @@ -242,7 +244,7 @@ agent_disconnect_unix(LIBSSH2_AGENT *agent) return LIBSSH2_ERROR_NONE; } -struct agent_ops agent_ops_unix = { +static struct agent_ops agent_ops_unix = { agent_connect_unix, agent_transact_unix, agent_disconnect_unix @@ -347,7 +349,7 @@ agent_disconnect_pageant(LIBSSH2_AGENT *agent) return 0; } -struct agent_ops agent_ops_pageant = { +static struct agent_ops agent_ops_pageant = { agent_connect_pageant, agent_transact_pageant, agent_disconnect_pageant diff --git a/src/agent.h b/src/agent.h index 605ba05d1c..5c334e8a27 100644 --- a/src/agent.h +++ b/src/agent.h @@ -75,9 +75,9 @@ struct agent_publickey { }; struct agent_ops { - agent_connect_func connect; - agent_transact_func transact; - agent_disconnect_func disconnect; + const agent_connect_func connect; + const agent_transact_func transact; + const agent_disconnect_func disconnect; }; struct _LIBSSH2_AGENT diff --git a/src/comp.c b/src/comp.c index 88445272f6..81ca89bf3b 100644 --- a/src/comp.c +++ b/src/comp.c @@ -237,7 +237,7 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session, /* If strm is null, then we have not yet been initialized. */ if(strm == NULL) return _libssh2_error(session, LIBSSH2_ERROR_COMPRESS, - "decompression uninitialized");; + "decompression uninitialized"); /* In practice they never come smaller than this */ if(out_maxlen < 25) diff --git a/src/hostkey.c b/src/hostkey.c index 0639d787ec..6553ab6f71 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -894,7 +894,7 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session, #define LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(digest_type) \ - { \ + do { \ unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ libssh2_sha##digest_type##_ctx ctx; \ int i; \ @@ -907,7 +907,7 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session, ret = _libssh2_ecdsa_sign(session, ec_ctx, hash, \ SHA##digest_type##_DIGEST_LENGTH, \ signature, signature_len); \ - } + } while(0) /* diff --git a/src/kex.c b/src/kex.c index 83b522cbbe..b7a2764507 100644 --- a/src/kex.c +++ b/src/kex.c @@ -54,7 +54,7 @@ kex_method_diffie_hellman_group1_sha1_key_exchange */ #define LIBSSH2_KEX_METHOD_EC_SHA_VALUE_HASH(value, reqlen, version) \ - { \ + do { \ if(type == LIBSSH2_EC_CURVE_NISTP256) { \ LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(256, value, reqlen, version); \ } \ @@ -64,12 +64,11 @@ else if(type == LIBSSH2_EC_CURVE_NISTP521) { \ LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(512, value, reqlen, version); \ } \ - } \ - + } while(0) #define LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(digest_type, value, \ reqlen, version) \ -{ \ +do { \ libssh2_sha##digest_type##_ctx hash; \ size_t len = 0; \ if(!(value)) { \ @@ -96,7 +95,7 @@ libssh2_sha##digest_type##_final(hash, (value) + len); \ len += SHA##digest_type##_DIGEST_LENGTH; \ } \ -} +} while(0) /*! * @note The following are wrapper functions used by diffie_hellman_sha_algo(). @@ -1569,96 +1568,96 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange * */ -#define LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(digest_type) \ -{ \ - libssh2_sha##digest_type##_ctx ctx; \ - exchange_state->exchange_hash = (void *)&ctx; \ - (void)libssh2_sha##digest_type##_init(&ctx); \ - if(session->local.banner) { \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - (uint32_t)(strlen((char *) session->local.banner) - 2)); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - (char *) session->local.banner, \ - strlen((char *) \ - session->local.banner) \ - - 2); \ - } \ - else { \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - LIBSSH2_SSH_DEFAULT_BANNER, \ +#define LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(digest_type) \ +do { \ + libssh2_sha##digest_type##_ctx ctx; \ + exchange_state->exchange_hash = (void *)&ctx; \ + (void)libssh2_sha##digest_type##_init(&ctx); \ + if(session->local.banner) { \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + (uint32_t)(strlen((char *) session->local.banner) - 2)); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + (char *) session->local.banner, \ + strlen((char *) \ + session->local.banner) \ + - 2); \ + } \ + else { \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + LIBSSH2_SSH_DEFAULT_BANNER, \ sizeof(LIBSSH2_SSH_DEFAULT_BANNER) \ - - 1); \ - } \ - \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - (uint32_t)strlen((char *) session->remote.banner)); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->remote.banner, \ - strlen((char *) \ - session->remote.banner)); \ - \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - (uint32_t)session->local.kexinit_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->local.kexinit, \ - session->local.kexinit_len); \ - \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - (uint32_t)session->remote.kexinit_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->remote.kexinit, \ - session->remote.kexinit_len); \ - \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - session->server_hostkey_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->server_hostkey, \ - session->server_hostkey_len); \ - \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - (uint32_t)public_key_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - public_key, \ - public_key_len); \ - \ - _libssh2_htonu32(exchange_state->h_sig_comp, \ - (uint32_t)server_public_key_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - server_public_key, \ - server_public_key_len); \ - \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->k_value, \ - exchange_state->k_value_len); \ - \ - libssh2_sha##digest_type##_final(ctx, exchange_state->h_sig_comp); \ - \ - if(session->hostkey-> \ - sig_verify(session, exchange_state->h_sig, \ - exchange_state->h_sig_len, exchange_state->h_sig_comp, \ - SHA##digest_type##_DIGEST_LENGTH, \ - &session->server_hostkey_abstract)) { \ - rc = -1; \ - } \ -} \ + - 1); \ + } \ + \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + (uint32_t)strlen((char *) session->remote.banner)); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + session->remote.banner, \ + strlen((char *) \ + session->remote.banner)); \ + \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + (uint32_t)session->local.kexinit_len); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + session->local.kexinit, \ + session->local.kexinit_len); \ + \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + (uint32_t)session->remote.kexinit_len); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + session->remote.kexinit, \ + session->remote.kexinit_len); \ + \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + session->server_hostkey_len); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + session->server_hostkey, \ + session->server_hostkey_len); \ + \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + (uint32_t)public_key_len); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + public_key, \ + public_key_len); \ + \ + _libssh2_htonu32(exchange_state->h_sig_comp, \ + (uint32_t)server_public_key_len); \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + libssh2_sha##digest_type##_update(ctx, \ + server_public_key, \ + server_public_key_len); \ + \ + libssh2_sha##digest_type##_update(ctx, \ + exchange_state->k_value, \ + exchange_state->k_value_len); \ + \ + libssh2_sha##digest_type##_final(ctx, exchange_state->h_sig_comp); \ + \ + if(session->hostkey-> \ + sig_verify(session, exchange_state->h_sig, \ + exchange_state->h_sig_len, exchange_state->h_sig_comp, \ + SHA##digest_type##_DIGEST_LENGTH, \ + &session->server_hostkey_abstract)) { \ + rc = -1; \ + } \ +} while(0) #if LIBSSH2_ECDSA @@ -3105,17 +3104,19 @@ kex_method_list(unsigned char *buf, uint32_t list_strlen, (uint32_t)((prefvar) ? strlen(prefvar) : \ kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar))) -#define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \ - if(prefvar) { \ - _libssh2_htonu32((buf), (prefvarlen)); \ - buf += 4; \ - memcpy((buf), (prefvar), (prefvarlen)); \ - buf += (prefvarlen); \ - } \ - else { \ - buf += kex_method_list((buf), (prefvarlen), \ - (LIBSSH2_COMMON_METHOD**)(defaultvar)); \ - } +#define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \ + do { \ + if(prefvar) { \ + _libssh2_htonu32((buf), (prefvarlen)); \ + buf += 4; \ + memcpy((buf), (prefvar), (prefvarlen)); \ + buf += (prefvarlen); \ + } \ + else { \ + buf += kex_method_list((buf), (prefvarlen), \ + (LIBSSH2_COMMON_METHOD**)(defaultvar)); \ + } \ + } while(0) /* kexinit * Send SSH_MSG_KEXINIT packet diff --git a/src/libgcrypt.h b/src/libgcrypt.h index 58a375579a..d1c09b5a5b 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -155,7 +155,7 @@ #define libssh2_hmac_final(ctx, data) \ memcpy(data, gcry_md_read(ctx, 0), \ gcry_md_get_algo_dlen(gcry_md_get_algo(ctx))) -#define libssh2_hmac_cleanup(ctx) gcry_md_close (*ctx); +#define libssh2_hmac_cleanup(ctx) gcry_md_close(*ctx) #define libssh2_crypto_init() gcry_control (GCRYCTL_DISABLE_SECMEM) #define libssh2_crypto_exit() diff --git a/src/mbedtls.c b/src/mbedtls.c index 366f7c2212..90c8ce095a 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -1033,17 +1033,16 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, return rc; } -#define LIBSSH2_MBEDTLS_ECDSA_VERIFY(digest_type) \ -{ \ - unsigned char hsh[SHA##digest_type##_DIGEST_LENGTH]; \ - \ - if(libssh2_sha##digest_type(m, m_len, hsh) == 0) { \ - rc = mbedtls_ecdsa_verify(&ctx->MBEDTLS_PRIVATE(grp), hsh, \ - SHA##digest_type##_DIGEST_LENGTH, \ - &ctx->MBEDTLS_PRIVATE(Q), &pr, &ps); \ - } \ - \ -} +#define LIBSSH2_MBEDTLS_ECDSA_VERIFY(digest_type) \ + do { \ + unsigned char hsh[SHA##digest_type##_DIGEST_LENGTH]; \ + \ + if(libssh2_sha##digest_type(m, m_len, hsh) == 0) { \ + rc = mbedtls_ecdsa_verify(&ctx->MBEDTLS_PRIVATE(grp), hsh, \ + SHA##digest_type##_DIGEST_LENGTH, \ + &ctx->MBEDTLS_PRIVATE(Q), &pr, &ps); \ + } \ + } while(0) /* _libssh2_ecdsa_sign * diff --git a/src/openssl.c b/src/openssl.c index dd00b22aba..baff5194d6 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -410,14 +410,13 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx, return (ret == 1) ? 0 : -1; } -#define LIBSSH2_ECDSA_VERIFY(digest_type) \ -{ \ - unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ - libssh2_sha##digest_type(m, m_len, hash); \ - ret = ECDSA_do_verify(hash, SHA##digest_type##_DIGEST_LENGTH, \ - ecdsa_sig, ec_key); \ - \ -} +#define LIBSSH2_ECDSA_VERIFY(digest_type) \ + do { \ + unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ + libssh2_sha##digest_type(m, m_len, hash); \ + ret = ECDSA_do_verify(hash, SHA##digest_type##_DIGEST_LENGTH, \ + ecdsa_sig, ec_key); \ + } while(0) int _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e792523336..f92bf631e7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,19 +56,19 @@ set(TESTS ) if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR CRYPTO_BACKEND STREQUAL "wolfSSL") + list(APPEND TESTS + public_key_auth_succeeds_with_correct_rsa_openssh_key + ) + if(OPENSSL_VERSION VERSION_GREATER "1.1.0" OR CRYPTO_BACKEND STREQUAL "wolfSSL") list(APPEND TESTS - public_key_auth_succeeds_with_correct_rsa_openssh_key + public_key_auth_succeeds_with_correct_ed25519_key + public_key_auth_succeeds_with_correct_encrypted_ed25519_key + public_key_auth_succeeds_with_correct_ed25519_key_from_mem + public_key_auth_succeeds_with_correct_ecdsa_key + public_key_auth_succeeds_with_correct_signed_ecdsa_key + public_key_auth_succeeds_with_correct_signed_rsa_key ) - if(OPENSSL_VERSION VERSION_GREATER "1.1.0" OR CRYPTO_BACKEND STREQUAL "wolfSSL") - list(APPEND TESTS - public_key_auth_succeeds_with_correct_ed25519_key - public_key_auth_succeeds_with_correct_encrypted_ed25519_key - public_key_auth_succeeds_with_correct_ed25519_key_from_mem - public_key_auth_succeeds_with_correct_ecdsa_key - public_key_auth_succeeds_with_correct_signed_ecdsa_key - public_key_auth_succeeds_with_correct_signed_rsa_key - ) - endif() + endif() endif() if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") @@ -83,10 +83,11 @@ target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURC # test building against shared libssh2 lib if(BUILD_SHARED_LIBS) - set(test warmup) # any test will do - add_executable(test_${test}_shared test_${test}.c) - target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) - target_link_libraries(test_${test}_shared runner ${LIB_SHARED} ${LIBRARIES}) + foreach(test simple ssh2) + add_executable(test_${test}_shared ${test}.c) + target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) + target_link_libraries(test_${test}_shared ${LIB_SHARED} ${LIBRARIES}) + endforeach() endif() foreach(test ${TESTS}) @@ -142,7 +143,7 @@ target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE " find_program(GCOV_PATH gcov) set(TGT_OPTIONS -g --coverage -fprofile-abs-path) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) - set(TGT_OPTIONS -g --coverage) + set(TGT_OPTIONS -g --coverage) endif() if(CMAKE_COMPILER_IS_GNUCC AND GCOV_PATH) target_compile_options(test_keyboard_interactive_auth_info_request BEFORE PRIVATE diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index afbbdaa479..b318573900 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -66,8 +66,9 @@ static int have_docker = 0; static int run_command_varg(char **output, const char *command, va_list args) { + static const char redirect_stderr[] = "%s 2>&1"; + FILE *pipe; - char redirect_stderr[] = "%s 2>&1"; char command_buf[BUFSIZ]; char buf[BUFSIZ]; int ret; diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 232c049871..24a6aa1e74 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -58,8 +58,8 @@ #endif #include -LIBSSH2_SESSION *connected_session = NULL; -libssh2_socket_t connected_socket = LIBSSH2_INVALID_SOCKET; +static LIBSSH2_SESSION *connected_session = NULL; +static libssh2_socket_t connected_socket = LIBSSH2_INVALID_SOCKET; static int connect_to_server(void) { diff --git a/tests/simple.c b/tests/simple.c index 450fd56886..33e26f259b 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -46,11 +46,11 @@ static int test_libssh2_base64_decode(LIBSSH2_SESSION *session) char *data; unsigned int datalen; const char *src = "Zm5vcmQ="; - unsigned int src_len = strlen(src); + size_t src_len = strlen(src); int ret; ret = libssh2_base64_decode(session, &data, &datalen, - src, src_len); + src, (unsigned int)src_len); if(ret) return ret; diff --git a/tests/ssh2.c b/tests/ssh2.c index 84b95ca739..4d9bbc5710 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) * and setup crypto, compression, and MAC layers */ session = libssh2_session_init(); - if(libssh2_session_startup(session, sock)) { + if(libssh2_session_handshake(session, sock)) { fprintf(stderr, "Failure establishing SSH session\n"); return 1; } diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index 7d835feb83..361c4c21c2 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -1,8 +1,8 @@ #include "runner.h" -const char *USERNAME = "libssh2"; /* set in Dockerfile */ -const char *KEY_FILE_PRIVATE = "key_rsa"; -const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */ +static const char *USERNAME = "libssh2"; /* set in Dockerfile */ +static const char *KEY_FILE_PRIVATE = "key_rsa"; +static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */ int test(LIBSSH2_SESSION *session) { diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index 8fbdc2f23d..8683f9fe8e 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -55,7 +55,8 @@ struct test_case { }; #define TEST_CASES_LEN 16 -struct test_case test_cases[TEST_CASES_LEN] = { +static const struct test_case + test_cases[TEST_CASES_LEN] = { /* too small */ { NULL, 0, @@ -191,7 +192,8 @@ struct test_case test_cases[TEST_CASES_LEN] = { }; #define FAILED_MALLOC_TEST_CASES_LEN 2 -struct test_case failed_malloc_test_cases[FAILED_MALLOC_TEST_CASES_LEN] = { +static const struct test_case + failed_malloc_test_cases[FAILED_MALLOC_TEST_CASES_LEN] = { /* malloc fail */ { "<" @@ -298,7 +300,8 @@ int main(void) for(i = 0; i < TEST_CASES_LEN; i++) { test_case(i + 1, - test_cases[i].data, test_cases[i].data_len, + test_cases[i].data, + test_cases[i].data_len, NULL, test_cases[i].expected); } diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index b9d9385f06..04ae61b684 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -5,7 +5,7 @@ static const char *USERNAME = "libssh2"; /* set in Dockerfile */ static const char *KEY_FILE_ED25519_PRIVATE = "key_ed25519"; -int read_file(const char *path, char **buf, size_t *len); +static int read_file(const char *path, char **buf, size_t *len); int test(LIBSSH2_SESSION *session) { @@ -48,7 +48,7 @@ int test(LIBSSH2_SESSION *session) return 0; } -int read_file(const char *path, char **out_buffer, size_t *out_len) +static int read_file(const char *path, char **out_buffer, size_t *out_len) { FILE *fp = NULL; char *buffer = NULL; From bf85faaa923bf24ec21a5233db859c5e6bc929c4 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 13 Apr 2023 11:34:11 +0000 Subject: [PATCH 262/424] sftp: add open functions with custom attribute support Before this patch, libssh2 sent hardcoded `LIBSSH2_SFTP_ATTRIBUTES` struct on handle open. This can be problematic on some special OS, where the file size should be known on new file creation. I added two new functions to resolve this issue. Patch-by: @vajdaakos on github via #506 Changes compared to #506: - drop attr size fixup in favour of #946. - move `memcpy()` under the state where we need it. - bump filename length type to `size_t`. - fix filenames in documentation and other nits. Closes #506 Closes #947 --- docs/Makefile.am | 2 + docs/libssh2_sftp_open_ex_r.3 | 73 +++++++++++++++++++++++++++++++++++ docs/libssh2_sftp_open_r.3 | 23 +++++++++++ include/libssh2_sftp.h | 11 ++++++ src/sftp.c | 26 ++++++++++++- 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 docs/libssh2_sftp_open_ex_r.3 create mode 100644 docs/libssh2_sftp_open_r.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index 235e77c573..8e998638fd 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -138,6 +138,8 @@ dist_man_MANS = \ libssh2_sftp_mkdir_ex.3 \ libssh2_sftp_open.3 \ libssh2_sftp_open_ex.3 \ + libssh2_sftp_open_ex_r.3 \ + libssh2_sftp_open_r.3 \ libssh2_sftp_opendir.3 \ libssh2_sftp_read.3 \ libssh2_sftp_readdir.3 \ diff --git a/docs/libssh2_sftp_open_ex_r.3 b/docs/libssh2_sftp_open_ex_r.3 new file mode 100644 index 0000000000..a7326718de --- /dev/null +++ b/docs/libssh2_sftp_open_ex_r.3 @@ -0,0 +1,73 @@ +.TH libssh2_sftp_open_ex_r 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.SH NAME +libssh2_sftp_open_ex_r - open filehandle for file on SFTP. +.SH SYNOPSIS +.nf +#include +#include + +LIBSSH2_SFTP_HANDLE * +libssh2_sftp_open_ex_r(LIBSSH2_SFTP *sftp, const char *filename, + size_t filename_len, + unsigned long flags, + long mode, + int open_type, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi +.SH DESCRIPTION +\fIsftp\fP - SFTP instance as returned by \fIlibssh2_sftp_init(3)\fP + +\fIfilename\fP - Remote file/directory resource to open + +\fIfilename_len\fP - Length of filename + +\fIflags\fP - Any reasonable combination of the LIBSSH2_FXF_* constants: +.RS +.IP LIBSSH2_FXF_READ +Open the file for reading. +.IP LIBSSH2_FXF_WRITE +Open the file for writing. If both this and LIBSSH2_FXF_READ are specified, +the file is opened for both reading and writing. +.IP LIBSSH2_FXF_APPEND +Force all writes to append data at the end of the file. +.IP LIBSSH2_FXF_CREAT, +If this flag is specified, then a new file will be created if one does not +already exist (if LIBSSH2_FXF_TRUNC is specified, the new file will be +truncated to zero length if it previously exists) +.IP LIBSSH2_FXF_TRUNC +Forces an existing file with the same name to be truncated to zero length when +creating a file by specifying LIBSSH2_FXF_CREAT. LIBSSH2_FXF_CREAT MUST also +be specified if this flag is used. +.IP LIBSSH2_FXF_EXCL +Causes the request to fail if the named file already exists. +LIBSSH2_FXF_CREAT MUST also be specified if this flag is used. + +.RE +\fImode\fP - POSIX file permissions to assign if the file is being newly +created. See the LIBSSH2_SFTP_S_* convenience defines in + +\fIopen_type\fP - Either of LIBSSH2_SFTP_OPENFILE (to open a file) or +LIBSSH2_SFTP_OPENDIR (to open a directory). + +\fIattrs\fP - Pointer to LIBSSH2_SFTP_ATTRIBUTES struct. See +libssh2_sftp_fstat_ex for detailed usage. + +.SH RETURN VALUE +A pointer to the newly created LIBSSH2_SFTP_HANDLE instance or NULL on +failure. +.SH ERRORS +\fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. + +\fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. + +\fILIBSSH2_ERROR_SOCKET_TIMEOUT\fP - + +\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was +received on the socket, or an SFTP operation caused an errorcode to be +returned by the server. + +\fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would +block. +.SH SEE ALSO +.BR libssh2_sftp_close_handle(3) +.BR libssh2_sftp_fstat_ex(3) diff --git a/docs/libssh2_sftp_open_r.3 b/docs/libssh2_sftp_open_r.3 new file mode 100644 index 0000000000..bccc0df38e --- /dev/null +++ b/docs/libssh2_sftp_open_r.3 @@ -0,0 +1,23 @@ +.TH libssh2_sftp_open_r 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.SH NAME +libssh2_sftp_open_r - convenience macro for \fIlibssh2_sftp_open_ex_r(3)\fP calls +.SH SYNOPSIS +.nf +#include +#include + +LIBSSH2_SFTP_HANDLE * +libssh2_sftp_open_r(LIBSSH2_SFTP *sftp, const char *filename, + unsigned long flags, + long mode, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +.fi +.SH DESCRIPTION +This is a macro defined in a public libssh2 header file that is using the +underlying function \fIlibssh2_sftp_open_ex_r(3)\fP. +.SH RETURN VALUE +See \fIlibssh2_sftp_open_ex_r(3)\fP +.SH ERRORS +See \fIlibssh2_sftp_open_ex_r(3)\fP +.SH SEE ALSO +.BR libssh2_sftp_open_ex_r(3) diff --git a/include/libssh2_sftp.h b/include/libssh2_sftp.h index e406127f76..74f619fccd 100644 --- a/include/libssh2_sftp.h +++ b/include/libssh2_sftp.h @@ -238,6 +238,17 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, libssh2_sftp_open_ex((sftp), \ (path), (unsigned int)strlen(path), \ 0, 0, LIBSSH2_SFTP_OPENDIR) +LIBSSH2_API LIBSSH2_SFTP_HANDLE * +libssh2_sftp_open_ex_r(LIBSSH2_SFTP *sftp, + const char *filename, + size_t filename_len, + unsigned long flags, + long mode, int open_type, + LIBSSH2_SFTP_ATTRIBUTES *attrs); +#define libssh2_sftp_open_r(sftp, filename, flags, mode, attrs) \ + libssh2_sftp_open_ex_r((sftp), (filename), strlen(filename), \ + (flags), (mode), LIBSSH2_SFTP_OPENFILE, \ + (attrs)) LIBSSH2_API ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle, char *buffer, size_t buffer_maxlen); diff --git a/src/sftp.c b/src/sftp.c index 8eea6c88c3..a3862a7387 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1107,7 +1107,7 @@ libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp) static LIBSSH2_SFTP_HANDLE * sftp_open(LIBSSH2_SFTP *sftp, const char *filename, size_t filename_len, uint32_t flags, long mode, - int open_type) + int open_type, LIBSSH2_SFTP_ATTRIBUTES *attrs_in) { LIBSSH2_CHANNEL *channel = sftp->channel; LIBSSH2_SESSION *session = channel->session; @@ -1122,6 +1122,10 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, if(sftp->open_state == libssh2_NB_state_idle) { sftp->last_errno = LIBSSH2_FX_OK; + if(attrs_in) { + memcpy(&attrs, attrs_in, sizeof(LIBSSH2_SFTP_ATTRIBUTES)); + } + /* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) + flags(4) */ sftp->open_packet_len = (uint32_t)(filename_len + 13 + @@ -1331,7 +1335,25 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename, BLOCK_ADJUST_ERRNO(hnd, sftp->channel->session, sftp_open(sftp, filename, filename_len, (uint32_t)flags, - mode, open_type)); + mode, open_type, NULL)); + return hnd; +} + +/* libssh2_sftp_open_ex_r + */ +LIBSSH2_API LIBSSH2_SFTP_HANDLE * +libssh2_sftp_open_ex_r(LIBSSH2_SFTP *sftp, const char *filename, + size_t filename_len, unsigned long flags, long mode, + int open_type, LIBSSH2_SFTP_ATTRIBUTES *attrs) +{ + LIBSSH2_SFTP_HANDLE *hnd; + + if(!sftp) + return NULL; + + BLOCK_ADJUST_ERRNO(hnd, sftp->channel->session, + sftp_open(sftp, filename, filename_len, (uint32_t)flags, + mode, open_type, attrs)); return hnd; } From 6dc42e9d625deb816a051d312d09e68926959e78 Mon Sep 17 00:00:00 2001 From: monnerat Date: Thu, 13 Apr 2023 14:08:12 +0200 Subject: [PATCH 263/424] Make OS/400 implementation work again (#953) * os400: support QADRT development files in a non-standard directory This enables the possibility to compile libssh2 even if the ascii runtime development files are not installed system-wide. * userauth_kbd_packet: fix a pointer target type mismatch. A temporary variable matching the parameter type is used before copying to the real target and checking for overflow (that should not occur!). * os400qc3: move and fix big number procedures A bug added by a previous code style cleaning is fixed. _libssh2_random() now checks and return the success status. * os400qc3: fix cipher definition block lengths They were wrongly set to the key size. * Diffie-Hellman min/max modulus sizes are dependent of crypto-backend In particular, os400qc3 limits the maximum group size to 2048-bits. Move definitions of these parameters to crypto backend header files. * kex: return an error if Diffie-Hellman key pair generation fails * os400: add an ascii assert.h header file * os400qc3: implement RSA SHA2 256/512 --- docs/HACKING-CRYPTO | 38 +++- include/libssh2.h | 8 - os400/README400 | 3 +- os400/include/assert.h | 58 +++++ os400/initscript.sh | 5 +- src/kex.c | 5 +- src/libgcrypt.h | 8 + src/mbedtls.h | 8 + src/openssl.h | 8 + src/os400qc3.c | 437 +++++++++++++++++++------------------- src/os400qc3.h | 44 ++-- src/userauth_kbd_packet.c | 4 +- src/wincng.h | 8 + 13 files changed, 383 insertions(+), 251 deletions(-) create mode 100644 os400/include/assert.h diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index 233cb32543..e23ac2288e 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -406,6 +406,21 @@ TripleDES-CBC algorithm identifier initializer. 5) Diffie-Hellman support. +LIBSSH2_DH_GEX_MINGROUP +The minimum Diffie-Hellman group length in bits supported by the backend. +Usually defined as 2048. + +LIBSSH2_DH_GEX_OPTGROUP +The preferred Diffie-Hellman group length in bits. Usually defined as 4096. + +LIBSSH2_DH_GEX_MAXGROUP +The maximum Diffie-Hellman group length in bits supported by the backend. +Usually defined as 8192. + +LIBSSH2_DH_MAX_MODULUS_BITS +The maximum Diffie-Hellman modulus bit count accepted from the server. This +value must be supported by the backend. Usually 16384. + 5.1) Diffie-Hellman context. _libssh2_dh_ctx Type of a Diffie-Hellman computation context. @@ -658,7 +673,28 @@ the allocated signature at (signature, signature_len). Signature buffer must be allocated from the given session. Returns 0 if OK, else -1. This procedure is already prototyped in crypto.h. -Note: this procedure is not used if macro _libssh2_rsa_sha1_signv() is defined. +Note: this procedure is not used if both macros _libssh2_rsa_sha2_256_signv() +and _libssh2_rsa_sha2_512_signv are defined. + +int _libssh2_rsa_sha2_256_signv(LIBSSH2_SESSION *session, + unsigned char **sig, size_t *siglen, + int count, const struct iovec vector[], + libssh2_rsa_ctx *ctx); +RSA signs the SHA-256 hash computed over the count data chunks in vector. +Signature is stored at (sig, siglen). +Signature buffer must be allocated from the given session. +Returns 0 if OK, else -1. +Note: this procedure is optional: if provided, it MUST be defined as a macro. + +int _libssh2_rsa_sha2_512_signv(LIBSSH2_SESSION *session, + unsigned char **sig, size_t *siglen, + int count, const struct iovec vector[], + libssh2_rsa_ctx *ctx); +RSA signs the SHA-512 hash computed over the count data chunks in vector. +Signature is stored at (sig, siglen). +Signature buffer must be allocated from the given session. +Returns 0 if OK, else -1. +Note: this procedure is optional: if provided, it MUST be defined as a macro. int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsa, size_t hash_len, diff --git a/include/libssh2.h b/include/libssh2.h index 657e12bc31..6bce4e2647 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -228,14 +228,6 @@ typedef off_t libssh2_struct_stat_size; #define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER #define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n" -/* Default generate and safe prime sizes for - diffie-hellman-group-exchange-sha1 */ -#define LIBSSH2_DH_GEX_MINGROUP 2048 -#define LIBSSH2_DH_GEX_OPTGROUP 4096 -#define LIBSSH2_DH_GEX_MAXGROUP 8192 - -#define LIBSSH2_DH_MAX_MODULUS_BITS 16384 - /* Defaults for pty requests */ #define LIBSSH2_TERM_WIDTH 80 #define LIBSSH2_TERM_HEIGHT 24 diff --git a/os400/README400 b/os400/README400 index 870c3634bf..e14bcf3648 100644 --- a/os400/README400 +++ b/os400/README400 @@ -38,7 +38,8 @@ familiar with. _ As a prerequisite, QADRT development environment must be installed. _ Install the libssh2 sources directory in IFS. -_ Enter shell (QSH) +_ Enter shell (QSH). You may need to change the LANG environment variable + to be in phase with the libssh2 source files CCSID. _ Change current directory to the libssh2 sources installation directory _ Change current directory to os400 _ Edit file iniscript.sh. You may want to change tunable configuration diff --git a/os400/include/assert.h b/os400/include/assert.h new file mode 100644 index 0000000000..33ea34776d --- /dev/null +++ b/os400/include/assert.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 Patrick Monnerat + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the copyright holder nor the names + * of any other contributors may be used to endorse or + * promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#ifndef LIBSSH2_ASSERT_H +#define LIBSSH2_ASSERT_H + +#include +#include + +/* Ascii assert() macro. */ + +#ifndef NDEBUG +#pragma convert(819) + +#define assert(expr) ((expr)? ((void) 0): (fprintf(stderr, \ + "Assertion failed: %s in file %s line %u. Aborting\n", \ + #expr, __FILE__, __LINE__), abort())) +#else +#define assert(expr) ((void) 0) +#endif +#endif + +/* vim: set expandtab ts=4 sw=4: */ diff --git a/os400/initscript.sh b/os400/initscript.sh index 9b773d0137..931c8cd887 100644 --- a/os400/initscript.sh +++ b/os400/initscript.sh @@ -49,8 +49,9 @@ setenv TGTCCSID '500' # Target CCSID of objects. setenv DEBUG '*ALL' # Debug level. setenv OPTIMIZE '10' # Optimisation level setenv OUTPUT '*NONE' # Compilation output option. -setenv TGTRLS 'V6R1M0' # Target OS release. +setenv TGTRLS 'V7R3M0' # Target OS release. setenv IFSDIR '/libssh2' # Installation IFS directory. +setenv QADRTDIR '/QIBM/ProdData/qadrt' # QADRT IFS directory. # Define ZLIB availability and locations. @@ -182,7 +183,7 @@ make_module() CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)" CMD="${CMD} LOCALETYPE(*LOCALE) FLAG(10)" CMD="${CMD} INCDIR('${TOPDIR}/os400/include'" - CMD="${CMD} '/QIBM/ProdData/qadrt/include' '${TOPDIR}/include'" + CMD="${CMD} '${QADRTDIR}/include' '${TOPDIR}/include'" CMD="${CMD} '${TOPDIR}/os400' '${SRCDIR}'" if [ "${WITH_ZLIB}" != "0" ] diff --git a/src/kex.c b/src/kex.c index b7a2764507..66ca6350ed 100644 --- a/src/kex.c +++ b/src/kex.c @@ -263,8 +263,11 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, rc = libssh2_dh_key_pair(&exchange_state->x, exchange_state->e, g, p, group_order, exchange_state->ctx); - if(rc) + if(rc) { + ret = _libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE, + "dh key pair generation failed"); goto clean_exit; + } /* Send KEX init */ /* packet_type(1) + String Length(4) + leading 0(1) */ diff --git a/src/libgcrypt.h b/src/libgcrypt.h index d1c09b5a5b..7f87ba8209 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -222,6 +222,14 @@ #define _libssh2_bn_bits(bn) gcry_mpi_get_nbits (bn) #define _libssh2_bn_free(bn) gcry_mpi_release(bn) +/* Default generate and safe prime sizes for + diffie-hellman-group-exchange-sha1 */ +#define LIBSSH2_DH_GEX_MINGROUP 2048 +#define LIBSSH2_DH_GEX_OPTGROUP 4096 +#define LIBSSH2_DH_GEX_MAXGROUP 8192 + +#define LIBSSH2_DH_MAX_MODULUS_BITS 16384 + #define _libssh2_dh_ctx struct gcry_mpi * #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ diff --git a/src/mbedtls.h b/src/mbedtls.h index 3fd7a8b1dc..f379e6cf87 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -429,6 +429,14 @@ typedef enum { * mbedTLS backend: Diffie-Hellman support. */ +/* Default generate and safe prime sizes for + diffie-hellman-group-exchange-sha1 */ +#define LIBSSH2_DH_GEX_MINGROUP 2048 +#define LIBSSH2_DH_GEX_OPTGROUP 4096 +#define LIBSSH2_DH_GEX_MAXGROUP 8192 + +#define LIBSSH2_DH_MAX_MODULUS_BITS 16384 + #define _libssh2_dh_ctx mbedtls_mpi * #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ diff --git a/src/openssl.h b/src/openssl.h index 2f347c36ca..cf623c1420 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -419,6 +419,14 @@ libssh2_curve_type; #define _libssh2_bn_bits(bn) BN_num_bits(bn) #define _libssh2_bn_free(bn) BN_clear_free(bn) +/* Default generate and safe prime sizes for + diffie-hellman-group-exchange-sha1 */ +#define LIBSSH2_DH_GEX_MINGROUP 2048 +#define LIBSSH2_DH_GEX_OPTGROUP 4096 +#define LIBSSH2_DH_GEX_MAXGROUP 8192 + +#define LIBSSH2_DH_MAX_MODULUS_BITS 16384 + #define _libssh2_dh_ctx BIGNUM * #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ diff --git a/src/os400qc3.c b/src/os400qc3.c index b7fc7487ab..f531bbd191 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2015-2016 Patrick Monnerat, D+H - * Copyright (C) 2020 Patrick Monnerat . + * Copyright (C) 2020-2023 Patrick Monnerat . * All rights reserved. * * Redistribution and use in source and binary forms, @@ -348,6 +348,169 @@ static asn1Element lastbytebitcount = { }; +/******************************************************************* + * + * OS/400 QC3 crypto-library backend: big numbers support. + * + *******************************************************************/ + +int +_libssh2_random(unsigned char *buf, size_t len) +{ + Qus_EC_t errcode; + + set_EC_length(errcode, sizeof errcode); + Qc3GenPRNs(buf, len, + Qc3PRN_TYPE_NORMAL, Qc3PRN_NO_PARITY, (char *) &errcode); + return errcode.Bytes_Available? -1: 0; +} + +_libssh2_bn * +_libssh2_bn_init(void) +{ + _libssh2_bn *bignum; + + bignum = (_libssh2_bn *) malloc(sizeof *bignum); + if(bignum) { + bignum->bignum = NULL; + bignum->length = 0; + } + + return bignum; +} + +void +_libssh2_bn_free(_libssh2_bn *bn) +{ + if(bn) { + if(bn->bignum) { + if(bn->length) + _libssh2_explicit_zero(bn->bignum, bn->length); + + free(bn->bignum); + } + + free((char *) bn); + } +} + +static int +_libssh2_bn_resize(_libssh2_bn *bn, size_t newlen) +{ + unsigned char *bignum; + + if(!bn) + return -1; + if(newlen == bn->length) + return 0; + + if(!bn->bignum) + bignum = (unsigned char *) malloc(newlen); + else { + if(newlen < bn->length) + _libssh2_explicit_zero(bn->bignum + newlen, bn->length - newlen); + + if(!newlen) { + free((char *) bn->bignum); + bn->bignum = NULL; + bn->length = 0; + return 0; + } + bignum = (unsigned char *) realloc((char *) bn->bignum, newlen); + } + + if(!bignum) + return -1; + + if(newlen > bn->length) + memset((char *) bignum + bn->length, 0, newlen - bn->length); + + bn->bignum = bignum; + bn->length = newlen; + return 0; +} + +unsigned long +_libssh2_bn_bits(_libssh2_bn *bn) +{ + unsigned int i; + unsigned char b; + + if(bn && bn->bignum) { + for(i = bn->length; i--;) { + b = bn->bignum[i]; + if(b) { + i *= 8; + do { + i++; + } while(b >>= 1); + return i; + } + } + } + + return 0; +} + +int +_libssh2_bn_from_bin(_libssh2_bn *bn, int len, const unsigned char *val) +{ + int i; + + if(!bn || (len && !val)) + return -1; + + for(; len && !*val; len--) + val++; + + if(_libssh2_bn_resize(bn, len)) + return -1; + + for(i = len; i--;) + bn->bignum[i] = *val++; + + return 0; +} + +int +_libssh2_bn_set_word(_libssh2_bn *bn, unsigned long val) +{ + val = htonl(val); + return _libssh2_bn_from_bin(bn, sizeof val, (unsigned char *) &val); +} + +int +_libssh2_bn_to_bin(_libssh2_bn *bn, unsigned char *val) +{ + int i; + + if(!bn || !val) + return -1; + + for(i = bn->length; i--;) + *val++ = bn->bignum[i]; + + return 0; +} + +static int +_libssh2_bn_from_bn(_libssh2_bn *to, _libssh2_bn *from) +{ + int i; + + if(!to || !from) + return -1; + + if(_libssh2_bn_resize(to, from->length)) + return -1; + + for(i = to->length; i--;) + to->bignum[i] = from->bignum[i]; + + return 0; +} + + /******************************************************************* * * OS/400 QC3 crypto-library backend: ASN.1 support. @@ -727,167 +890,6 @@ rsaprivatekeyinfo(asn1Element *privkey) return privkeyinfo; } -/******************************************************************* - * - * OS/400 QC3 crypto-library backend: big numbers support. - * - *******************************************************************/ - - -_libssh2_bn * -_libssh2_bn_init(void) -{ - _libssh2_bn *bignum; - - bignum = (_libssh2_bn *) malloc(sizeof *bignum); - if(bignum) { - bignum->bignum = NULL; - bignum->length = 0; - } - - return bignum; -} - -void -_libssh2_bn_free(_libssh2_bn *bn) -{ - if(bn) { - if(bn->bignum) { - if(bn->length) - _libssh2_explicit_zero(bn->bignum, bn->length); - - free(bn->bignum); - } - - free((char *) bn); - } -} - -static int -_libssh2_bn_resize(_libssh2_bn *bn, size_t newlen) -{ - unsigned char *bignum; - - if(!bn) - return -1; - if(newlen == bn->length) - return 0; - - if(!bn->bignum) - bignum = (unsigned char *) malloc(newlen); - else { - if(newlen < bn->length) - _libssh2_explicit_zero(bn->bignum + newlen, bn->length - newlen); - - if(!newlen) { - free((char *) bn->bignum); - bn->bignum = NULL; - bn->length = 0; - return 0; - } - bignum = (unsigned char *) realloc((char *) bn->bignum, newlen); - } - - if(!bignum) - return -1; - - if(newlen > bn->length) - memset((char *) bignum + bn->length, 0, newlen - bn->length); - - bn->bignum = bignum; - bn->length = newlen; - return 0; -} - -unsigned long -_libssh2_bn_bits(_libssh2_bn *bn) -{ - unsigned int i; - unsigned char b; - - if(bn && bn->bignum) { - for(i = bn->length; i--;) - b = bn->bignum[i]; - if(b) { - i *= 8; - do { - i++; - } while(b >>= 1); - return i; - } - } - - return 0; -} - -int -_libssh2_bn_from_bin(_libssh2_bn *bn, int len, const unsigned char *val) -{ - int i; - - if(!bn || (len && !val)) - return -1; - - for(; len && !*val; len--) - val++; - - if(_libssh2_bn_resize(bn, len)) - return -1; - - for(i = len; i--;) - bn->bignum[i] = *val++; - - return 0; -} - -int -_libssh2_bn_set_word(_libssh2_bn *bn, unsigned long val) -{ - val = htonl(val); - return _libssh2_bn_from_bin(bn, sizeof val, (unsigned char *) &val); -} - -int -_libssh2_bn_to_bin(_libssh2_bn *bn, unsigned char *val) -{ - int i; - - if(!bn || !val) - return -1; - - for(i = bn->length; i--;) - *val++ = bn->bignum[i]; - - return 0; -} - -static int -_libssh2_bn_from_bn(_libssh2_bn *to, _libssh2_bn *from) -{ - int i; - - if(!to || !from) - return -1; - - if(_libssh2_bn_resize(to, from->length)) - return -1; - - for(i = to->length; i--;) - to->bignum[i] = from->bignum[i]; - - return 0; -} - -int -_libssh2_random(unsigned char *buf, size_t len) -{ - Qc3GenPRNs(buf, len, - Qc3PRN_TYPE_NORMAL, Qc3PRN_NO_PARITY, (char *) &ecnull); - /* FIXME: any error is silently discarded! But Qc3GenPRNs could fail, - including if "The system seed digest is not ready" dixit IBM doc. */ - return 0; -} - /******************************************************************* * @@ -1145,8 +1147,6 @@ _libssh2_rsa_new(libssh2_rsa_ctx **rsa, _libssh2_bn *coeff = NULL; asn1Element *key = NULL; asn1Element *structkey = NULL; - Qc3_Format_ALGD0400_T algd; - Qus_EC_t errcode; int keytype; int ret = 0; int i; @@ -1192,23 +1192,11 @@ _libssh2_rsa_new(libssh2_rsa_ctx **rsa, if(!key || !structkey) ret = -1; - set_EC_length(errcode, sizeof errcode); - - if(!ret) { - /* Create the algorithm context. */ - algd.Public_Key_Alg = Qc3_RSA; - algd.PKA_Block_Format = Qc3_PKCS1_01; - memset(algd.Reserved, 0, sizeof algd.Reserved); - algd.Signing_Hash_Alg = Qc3_SHA1; - Qc3CreateAlgorithmContext((char *) &algd, Qc3_Alg_Public_Key, - ctx->hash.Alg_Context_Token, &errcode); - if(errcode.Bytes_Available) - ret = -1; - ctx->hash.Final_Op_Flag = Qc3_Continue; - } - /* Create the key context. */ if(!ret) { + Qus_EC_t errcode; + + set_EC_length(errcode, sizeof errcode); i = structkey->end - structkey->header; Qc3CreateKeyContext(structkey->header, &i, berstring, &keytype, qc3clear, NULL, NULL, ctx->key.Key_Context_Token, @@ -2105,26 +2093,12 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx **rsa, LIBSSH2_SESSION *session, { libssh2_rsa_ctx *ctx = libssh2_init_crypto_ctx(NULL); int ret; - Qc3_Format_ALGD0400_T algd; - Qus_EC_t errcode; if(!ctx) return -1; ret = load_rsa_private_file(session, filename, passphrase, rsapkcs1privkey, rsapkcs8privkey, (void *) ctx); - if(!ret) { - /* Create the algorithm context. */ - algd.Public_Key_Alg = Qc3_RSA; - algd.PKA_Block_Format = Qc3_PKCS1_01; - memset(algd.Reserved, 0, sizeof algd.Reserved); - algd.Signing_Hash_Alg = Qc3_SHA1; - set_EC_length(errcode, sizeof errcode); - Qc3CreateAlgorithmContext((char *) &algd, Qc3_Alg_Public_Key, - ctx->hash.Alg_Context_Token, &errcode); - if(errcode.Bytes_Available) - ret = -1; - } if(ret) { _libssh2_os400qc3_crypto_dtor(ctx); ctx = NULL; @@ -2185,8 +2159,6 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, unsigned char *data = NULL; unsigned int datalen = 0; int ret; - Qc3_Format_ALGD0400_T algd; - Qus_EC_t errcode; if(!ctx) return -1; @@ -2238,19 +2210,6 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, if(data) LIBSSH2_FREE(session, data); - if(!ret) { - /* Create the algorithm context. */ - algd.Public_Key_Alg = Qc3_RSA; - algd.PKA_Block_Format = Qc3_PKCS1_01; - memset(algd.Reserved, 0, sizeof algd.Reserved); - algd.Signing_Hash_Alg = Qc3_SHA1; - set_EC_length(errcode, sizeof errcode); - Qc3CreateAlgorithmContext((char *) &algd, Qc3_Alg_Public_Key, - ctx->hash.Alg_Context_Token, &errcode); - if(errcode.Bytes_Available) - ret = -1; - } - if(ret) { _libssh2_os400qc3_crypto_dtor(ctx); ctx = NULL; @@ -2373,44 +2332,75 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, } int -_libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa, +_libssh2_rsa_sha2_verify(libssh2_rsa_ctx *rsa, size_t hash_len, const unsigned char *sig, size_t sig_len, const unsigned char *m, size_t m_len) { Qus_EC_t errcode; + Qc3_Format_ALGD0400_T algd; int slen = (int)sig_len; int mlen = (int)m_len; + memset(&algd, 0, sizeof algd); + algd.Public_Key_Alg = Qc3_RSA; + algd.PKA_Block_Format = Qc3_PKCS1_01; + switch(hash_len) { + case SHA_DIGEST_LENGTH: + algd.Signing_Hash_Alg = Qc3_SHA1; + break; + case SHA256_DIGEST_LENGTH: + algd.Signing_Hash_Alg = Qc3_SHA256; + break; + case SHA512_DIGEST_LENGTH: + algd.Signing_Hash_Alg = Qc3_SHA512; + break; + default: + return -1; + } + set_EC_length(errcode, sizeof errcode); Qc3VerifySignature((char *) sig, &slen, (char *) m, &mlen, Qc3_Data, - rsa->hash.Alg_Context_Token, Qc3_Alg_Token, - rsa->key.Key_Context_Token, Qc3_Key_Token, anycsp, + (char *) &algd, Qc3_Alg_Public_Key, + (char *) &rsa->key, Qc3_Key_Token, anycsp, NULL, (char *) &errcode); return errcode.Bytes_Available? -1: 0; } int -_libssh2_os400qc3_rsa_sha1_signv(LIBSSH2_SESSION *session, - unsigned char **signature, - size_t *signature_len, - int veccount, - const struct iovec vector[], - libssh2_rsa_ctx *ctx) +_libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa, + const unsigned char *sig, size_t sig_len, + const unsigned char *m, size_t m_len) +{ + return _libssh2_rsa_sha2_verify(rsa, SHA_DIGEST_LENGTH, + sig, sig_len, m, m_len); +} + +int +_libssh2_os400qc3_rsa_signv(LIBSSH2_SESSION *session, + int algo, + unsigned char **signature, + size_t *signature_len, + int veccount, + const struct iovec vector[], + libssh2_rsa_ctx *ctx) { Qus_EC_t errcode; + Qc3_Format_ALGD0400_T algd; int siglen; unsigned char *sig; char sigbuf[8192]; int sigbufsize = sizeof sigbuf; - ctx->hash.Final_Op_Flag = Qc3_Final; + algd.Public_Key_Alg = Qc3_RSA; + algd.PKA_Block_Format = Qc3_PKCS1_01; + memset(algd.Reserved, 0, sizeof algd.Reserved); + algd.Signing_Hash_Alg = algo; set_EC_length(errcode, sizeof errcode); Qc3CalculateSignature((char *) vector, &veccount, Qc3_Array, - (char *) &ctx->hash, Qc3_Alg_Token, + (char *) &algd, Qc3_Alg_Public_Key, (char *) &ctx->key, Qc3_Key_Token, anycsp, NULL, sigbuf, &sigbufsize, &siglen, (char *) &errcode); - ctx->hash.Final_Op_Flag = Qc3_Continue; if(errcode.Bytes_Available) return -1; sig = LIBSSH2_ALLOC(session, siglen); @@ -2434,8 +2424,11 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, size_t key_method_len) { (void)session; - (void)key_method; - (void)key_method_len; + + if(key_method_len == 7 && + memcmp(key_method, "ssh-rsa", key_method_len) == 0) { + return "rsa-sha2-512,rsa-sha2-256,ssh-rsa"; + } return NULL; } diff --git a/src/os400qc3.h b/src/os400qc3.h index 8d26dfbf11..68ef0b9844 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -2,7 +2,7 @@ #define __LIBSSH2_OS400QC3_H /* * Copyright (C) 2015-2016 Patrick Monnerat, D+H - * Copyright (C) 2020 Patrick Monnerat . + * Copyright (C) 2020-2023 Patrick Monnerat . * All rights reserved. * * Redistribution and use in source and binary forms, @@ -177,7 +177,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 -#define LIBSSH2_RSA_SHA2 0 +#define LIBSSH2_RSA_SHA2 1 #define LIBSSH2_DSA 0 #define LIBSSH2_ECDSA 0 #define LIBSSH2_ED25519 0 @@ -316,19 +316,19 @@ typedef struct { /* Diffie-Hellman context. */ #define _libssh2_cipher_type(name) _libssh2_os400qc3_cipher_t name #define _libssh2_cipher_aes128 {Qc3_Alg_Block_Cipher, Qc3_AES, 16, \ Qc3_CBC, 16} -#define _libssh2_cipher_aes192 {Qc3_Alg_Block_Cipher, Qc3_AES, 24, \ +#define _libssh2_cipher_aes192 {Qc3_Alg_Block_Cipher, Qc3_AES, 16, \ Qc3_CBC, 24} -#define _libssh2_cipher_aes256 {Qc3_Alg_Block_Cipher, Qc3_AES, 32, \ +#define _libssh2_cipher_aes256 {Qc3_Alg_Block_Cipher, Qc3_AES, 16, \ Qc3_CBC, 32} #define _libssh2_cipher_aes128ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 16, \ Qc3_CTR, 16} -#define _libssh2_cipher_aes192ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 24, \ +#define _libssh2_cipher_aes192ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 16, \ Qc3_CTR, 24} -#define _libssh2_cipher_aes256ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 32, \ +#define _libssh2_cipher_aes256ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 16, \ Qc3_CTR, 32} -#define _libssh2_cipher_3des {Qc3_Alg_Block_Cipher, Qc3_TDES, 0, \ +#define _libssh2_cipher_3des {Qc3_Alg_Block_Cipher, Qc3_TDES, 8, \ Qc3_CBC, 24} -#define _libssh2_cipher_arcfour {Qc3_Alg_Stream_Cipher, Qc3_RC4, 0, 0, 16} +#define _libssh2_cipher_arcfour {Qc3_Alg_Stream_Cipher, Qc3_RC4, 8, 0, 16} #define _libssh2_cipher_dtor(ctx) _libssh2_os400qc3_crypto_dtor(ctx) @@ -338,8 +338,22 @@ typedef struct { /* Diffie-Hellman context. */ #define libssh2_prepare_iovec(vec, len) memset((char *) (vec), 0, \ (len) * sizeof(struct iovec)) #define _libssh2_rsa_sha1_signv(session, sig, siglen, count, vector, ctx) \ - _libssh2_os400qc3_rsa_sha1_signv(session, sig, siglen, \ + _libssh2_os400qc3_rsa_signv(session, Qc3_SHA1, sig, siglen, \ count, vector, ctx) +#define _libssh2_rsa_sha2_256_signv(session, sig, siglen, cnt, vector, ctx) \ + _libssh2_os400qc3_rsa_signv(session, Qc3_SHA256, sig, siglen, \ + cnt, vector, ctx) +#define _libssh2_rsa_sha2_512_signv(session, sig, siglen, cnt, vector, ctx) \ + _libssh2_os400qc3_rsa_signv(session, Qc3_SHA512, sig, siglen, \ + cnt, vector, ctx) + +/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 + Qc3 is limited to a maximum 2048-bit modulus/key size. */ +#define LIBSSH2_DH_GEX_MINGROUP 1024 +#define LIBSSH2_DH_GEX_OPTGROUP 1536 +#define LIBSSH2_DH_GEX_MAXGROUP 2048 + +#define LIBSSH2_DH_MAX_MODULUS_BITS 2048 #define _libssh2_dh_ctx _libssh2_os400qc3_dh_ctx #define libssh2_dh_init(dhctx) _libssh2_os400qc3_dh_init(dhctx) @@ -383,12 +397,12 @@ extern void libssh2_os400qc3_hmac_update(_libssh2_os400qc3_crypto_ctx *ctx, int len); extern void libssh2_os400qc3_hmac_final(_libssh2_os400qc3_crypto_ctx *ctx, unsigned char *out); -extern int _libssh2_os400qc3_rsa_sha1_signv(LIBSSH2_SESSION *session, - unsigned char **signature, - size_t *signature_len, - int veccount, - const struct iovec vector[], - libssh2_rsa_ctx *ctx); +extern int _libssh2_os400qc3_rsa_signv(LIBSSH2_SESSION *session, int algo, + unsigned char **signature, + size_t *signature_len, + int veccount, + const struct iovec vector[], + libssh2_rsa_ctx *ctx); extern void _libssh2_os400qc3_dh_init(_libssh2_dh_ctx *dhctx); extern int _libssh2_os400qc3_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, diff --git a/src/userauth_kbd_packet.c b/src/userauth_kbd_packet.c index 56cd0efef3..298683879a 100644 --- a/src/userauth_kbd_packet.c +++ b/src/userauth_kbd_packet.c @@ -44,6 +44,7 @@ int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *session) size_t language_tag_len; unsigned int i; unsigned char packet_type; + uint32_t tmp_u32; struct string_buf decoded; @@ -95,7 +96,8 @@ int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *session) } /* int num-prompts */ - if(_libssh2_get_u32(&decoded, &session->userauth_kybd_num_prompts) == -1) { + if(_libssh2_get_u32(&decoded, &tmp_u32) == -1 || + (session->userauth_kybd_num_prompts = tmp_u32) != tmp_u32) { _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, "Unable to decode " "keyboard-interactive number of keyboard prompts"); diff --git a/src/wincng.h b/src/wincng.h index 32410d1e42..94aeef75f7 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -423,6 +423,14 @@ _libssh2_bn *_libssh2_wincng_bignum_init(void); * Windows CNG backend: Diffie-Hellman support */ +/* Default generate and safe prime sizes for + diffie-hellman-group-exchange-sha1 */ +#define LIBSSH2_DH_GEX_MINGROUP 2048 +#define LIBSSH2_DH_GEX_OPTGROUP 4096 +#define LIBSSH2_DH_GEX_MAXGROUP 8192 + +#define LIBSSH2_DH_MAX_MODULUS_BITS 16384 + typedef struct { /* holds our private and public key components */ BCRYPT_KEY_HANDLE dh_handle; From f4f5841dd52c7efbe9aed3a3c2d5678d11105d73 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 13 Apr 2023 11:23:13 +0000 Subject: [PATCH 264/424] example/ssh2_exec: drop conditional code for deprecated API --- example/ssh2_exec.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 1c4ea4b783..f672322dfd 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -172,21 +172,11 @@ int main(int argc, char *argv[]) fingerprint = libssh2_session_hostkey(session, &len, &type); if(fingerprint) { struct libssh2_knownhost *host; -#if LIBSSH2_VERSION_NUM >= 0x010206 - /* introduced in 1.2.6 */ int check = libssh2_knownhost_checkp(nh, hostname, 22, fingerprint, len, LIBSSH2_KNOWNHOST_TYPE_PLAIN| LIBSSH2_KNOWNHOST_KEYENC_RAW, &host); -#else - /* 1.2.5 or older */ - int check = libssh2_knownhost_check(nh, hostname, - fingerprint, len, - LIBSSH2_KNOWNHOST_TYPE_PLAIN| - LIBSSH2_KNOWNHOST_KEYENC_RAW, - &host); -#endif fprintf(stderr, "Host check: %d, key: %s\n", check, (check <= LIBSSH2_KNOWNHOST_CHECK_MISMATCH)? host->key:""); From d5438f4ba9036e8028f35258dd1ab97cc2edb37c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 13 Apr 2023 23:39:01 +0000 Subject: [PATCH 265/424] src: fix indentation of macro definitions And some comment cleanup. Closes #958 --- src/agent.c | 18 +-- src/channel.c | 7 +- src/hostkey.c | 2 +- src/kex.c | 6 +- src/knownhost.c | 14 +-- src/libgcrypt.h | 106 +++++++++--------- src/libssh2_priv.h | 2 +- src/mac.c | 1 + src/mbedtls.h | 266 ++++++++++++++++++++++----------------------- src/misc.c | 4 +- src/openssl.h | 34 +++--- src/packet.c | 2 +- src/scp.c | 2 +- src/session.c | 12 +- src/sftp.c | 58 +++------- src/transport.c | 2 +- src/transport.h | 1 - src/userauth.c | 16 +-- src/userauth.h | 2 +- src/version.c | 6 +- src/wincng.c | 2 +- src/wincng.h | 221 +++++++++++++++++++------------------ 22 files changed, 383 insertions(+), 401 deletions(-) diff --git a/src/agent.c b/src/agent.c index 9ac83bb2b9..35613c5bf7 100644 --- a/src/agent.c +++ b/src/agent.c @@ -679,7 +679,7 @@ agent_free_identities(LIBSSH2_AGENT *agent) #define AGENT_PUBLICKEY_MAGIC 0x3bdefed2 /* - * agent_publickey_to_external() + * agent_publickey_to_external * * Copies data from the internal to the external representation struct. * @@ -727,7 +727,7 @@ libssh2_agent_init(LIBSSH2_SESSION *session) } /* - * libssh2_agent_connect() + * libssh2_agent_connect * * Connect to an ssh-agent. * @@ -747,7 +747,7 @@ libssh2_agent_connect(LIBSSH2_AGENT *agent) } /* - * libssh2_agent_list_identities() + * libssh2_agent_list_identities * * Request ssh-agent to list identities. * @@ -763,7 +763,7 @@ libssh2_agent_list_identities(LIBSSH2_AGENT *agent) } /* - * libssh2_agent_get_identity() + * libssh2_agent_get_identity * * Traverse the internal list of public keys. Pass NULL to 'prev' to get * the first one. Or pass a pointer to the previously returned one to get the @@ -800,7 +800,7 @@ libssh2_agent_get_identity(LIBSSH2_AGENT *agent, } /* - * libssh2_agent_userauth() + * libssh2_agent_userauth * * Do publickey user authentication with the help of ssh-agent. * @@ -830,7 +830,7 @@ libssh2_agent_userauth(LIBSSH2_AGENT *agent, } /* - * libssh2_agent_disconnect() + * libssh2_agent_disconnect * * Close a connection to an ssh-agent. * @@ -845,7 +845,7 @@ libssh2_agent_disconnect(LIBSSH2_AGENT *agent) } /* - * libssh2_agent_free() + * libssh2_agent_free * * Free an ssh-agent handle. This function also frees the internal * collection of public keys. @@ -866,7 +866,7 @@ libssh2_agent_free(LIBSSH2_AGENT *agent) } /* - * libssh2_agent_set_identity_path() + * libssh2_agent_set_identity_path * * Allows a custom agent socket path beyond SSH_AUTH_SOCK env * @@ -891,7 +891,7 @@ libssh2_agent_set_identity_path(LIBSSH2_AGENT *agent, const char *path) } /* - * libssh2_agent_get_identity_path() + * libssh2_agent_get_identity_path * * Returns the custom agent socket path if set * diff --git a/src/channel.c b/src/channel.c index f1db4d7229..ff5c17e5a9 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1207,13 +1207,14 @@ static int channel_request_auth_agent(LIBSSH2_CHANNEL *channel, "Unable to complete request for auth-agent"); } -/** +/* * libssh2_channel_request_auth_agent + * * Requests that agent forwarding be enabled for the session. The * request must be sent over a specific channel, which starts the agent * listener on the remote side. Once the channel is closed, the agent * listener continues to exist. - * */ + */ LIBSSH2_API int libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel) { @@ -2017,7 +2018,7 @@ _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode) } /* - * libssh2_channel_handle_extended_data2() + * libssh2_channel_handle_extended_data2 * */ LIBSSH2_API int diff --git a/src/hostkey.c b/src/hostkey.c index 6553ab6f71..5e973cabb7 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -1367,7 +1367,7 @@ static int hostkey_type(const unsigned char *hostkey, size_t len) } /* - * libssh2_session_hostkey() + * libssh2_session_hostkey * * Returns the server key and length. * diff --git a/src/kex.c b/src/kex.c index 66ca6350ed..4965388c71 100644 --- a/src/kex.c +++ b/src/kex.c @@ -2196,7 +2196,6 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, * supports SHA256/384/512 hashes based on negotiated ecdh method * */ - static int kex_method_ecdh_key_exchange (LIBSSH2_SESSION * session, key_exchange_state_low_t * key_state) @@ -3052,6 +3051,7 @@ typedef struct _LIBSSH2_COMMON_METHOD } LIBSSH2_COMMON_METHOD; /* kex_method_strlen + * * Calculate the length of a particular method list's resulting string * Includes SUM(strlen() of each individual method plus 1 (for coma)) - 1 * (because the last coma isn't used) @@ -3296,7 +3296,7 @@ static int kexinit(LIBSSH2_SESSION * session) /* kex_agree_instr * Kex specific variant of strstr() - * Needle must be precede by BOL or ',', and followed by ',' or EOL + * Needle must be preceded by BOL or ',', and followed by ',' or EOL */ static unsigned char * kex_agree_instr(unsigned char *haystack, size_t haystack_len, @@ -4055,7 +4055,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, } /* - * libssh2_session_supported_algs() + * libssh2_session_supported_algs * returns a number of returned algorithms (a positive number) on success, * a negative number on failure */ diff --git a/src/knownhost.c b/src/knownhost.c index 12edbd646e..c43762f8cd 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -110,7 +110,7 @@ libssh2_knownhost_init(LIBSSH2_SESSION *session) #define KNOWNHOST_MAGIC 0xdeadcafe /* - * knownhost_to_external() + * knownhost_to_external * * Copies data from the internal to the external representation struct. * @@ -726,7 +726,7 @@ static int hashed_hostline(LIBSSH2_KNOWNHOSTS *hosts, } /* - * hostline() + * hostline * * Parse a single known_host line pre-split into host and key. * @@ -840,7 +840,7 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts, } /* - * libssh2_knownhost_readline() + * libssh2_knownhost_readline * * Pass in a line of a file of 'type'. * @@ -982,7 +982,7 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts, } /* - * knownhost_writeline() + * knownhost_writeline * * Ask libssh2 to convert a known host to an output line for storage. * @@ -1156,7 +1156,7 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, } /* - * libssh2_knownhost_writeline() + * libssh2_knownhost_writeline * * Ask libssh2 to convert a known host to an output line for storage. * @@ -1182,7 +1182,7 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, } /* - * libssh2_knownhost_writefile() + * libssh2_knownhost_writefile * * Write hosts+key pairs to the given file. */ @@ -1233,7 +1233,7 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts, /* - * libssh2_knownhost_get() + * libssh2_knownhost_get * * Traverse the internal list of known hosts. Pass NULL to 'prev' to get * the first one. diff --git a/src/libgcrypt.h b/src/libgcrypt.h index 7f87ba8209..0e2d9bc81a 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -70,8 +70,8 @@ #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) -#define _libssh2_random(buf, len) \ - (gcry_randomize ((buf), (len), GCRY_STRONG_RANDOM), 0) +#define _libssh2_random(buf, len) \ + (gcry_randomize((buf), (len), GCRY_STRONG_RANDOM), 0) #define libssh2_prepare_iovec(vec, len) /* Empty. */ @@ -79,94 +79,94 @@ /* returns 0 in case of failure */ #define libssh2_sha1_init(ctx) \ - (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA1, 0)) + (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA1, 0)) #define libssh2_sha1_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + gcry_md_write(ctx, (unsigned char *) data, len) #define libssh2_sha1_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA_DIGEST_LENGTH), gcry_md_close(ctx) + memcpy(out, gcry_md_read(ctx, 0), SHA_DIGEST_LENGTH), gcry_md_close(ctx) #define libssh2_sha1(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA1, out, message, len) + gcry_md_hash_buffer(GCRY_MD_SHA1, out, message, len) #define libssh2_sha256_ctx gcry_md_hd_t #define libssh2_sha256_init(ctx) \ - (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA256, 0)) + (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA256, 0)) #define libssh2_sha256_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + gcry_md_write(ctx, (unsigned char *) data, len) #define libssh2_sha256_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA256_DIGEST_LENGTH), gcry_md_close(ctx) + memcpy(out, gcry_md_read(ctx, 0), SHA256_DIGEST_LENGTH), gcry_md_close(ctx) #define libssh2_sha256(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA256, out, message, len) + gcry_md_hash_buffer(GCRY_MD_SHA256, out, message, len) #define libssh2_sha384_ctx gcry_md_hd_t #define libssh2_sha384_init(ctx) \ - (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA384, 0)) + (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA384, 0)) #define libssh2_sha384_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + gcry_md_write(ctx, (unsigned char *) data, len) #define libssh2_sha384_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA384_DIGEST_LENGTH), gcry_md_close(ctx) + memcpy(out, gcry_md_read(ctx, 0), SHA384_DIGEST_LENGTH), gcry_md_close(ctx) #define libssh2_sha384(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA384, out, message, len) + gcry_md_hash_buffer(GCRY_MD_SHA384, out, message, len) #define libssh2_sha512_ctx gcry_md_hd_t #define libssh2_sha512_init(ctx) \ - (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA512, 0)) + (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA512, 0)) #define libssh2_sha512_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + gcry_md_write(ctx, (unsigned char *) data, len) #define libssh2_sha512_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA512_DIGEST_LENGTH), gcry_md_close(ctx) + memcpy(out, gcry_md_read(ctx, 0), SHA512_DIGEST_LENGTH), gcry_md_close(ctx) #define libssh2_sha512(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA512, out, message, len) + gcry_md_hash_buffer(GCRY_MD_SHA512, out, message, len) #define libssh2_md5_ctx gcry_md_hd_t /* returns 0 in case of failure */ #define libssh2_md5_init(ctx) \ - (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_MD5, 0)) + (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_MD5, 0)) #define libssh2_md5_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + gcry_md_write(ctx, (unsigned char *) data, len) #define libssh2_md5_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), MD5_DIGEST_LENGTH), gcry_md_close(ctx) + memcpy(out, gcry_md_read(ctx, 0), MD5_DIGEST_LENGTH), gcry_md_close(ctx) #define libssh2_md5(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_MD5, out, message, len) + gcry_md_hash_buffer(GCRY_MD_MD5, out, message, len) #define libssh2_hmac_ctx gcry_md_hd_t #define libssh2_hmac_ctx_init(ctx) #define libssh2_hmac_sha1_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC), \ + gcry_md_open(ctx, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC), \ gcry_md_setkey(*ctx, key, keylen) #define libssh2_hmac_md5_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC), \ + gcry_md_open(ctx, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC), \ gcry_md_setkey(*ctx, key, keylen) #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_RMD160, GCRY_MD_FLAG_HMAC), \ + gcry_md_open(ctx, GCRY_MD_RMD160, GCRY_MD_FLAG_HMAC), \ gcry_md_setkey(*ctx, key, keylen) #define libssh2_hmac_sha256_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC), \ + gcry_md_open(ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC), \ gcry_md_setkey(*ctx, key, keylen) #define libssh2_hmac_sha512_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC), \ + gcry_md_open(ctx, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC), \ gcry_md_setkey(*ctx, key, keylen) #define libssh2_hmac_update(ctx, data, datalen) \ - gcry_md_write(ctx, (unsigned char *) data, datalen) + gcry_md_write(ctx, (unsigned char *) data, datalen) #define libssh2_hmac_final(ctx, data) \ - memcpy(data, gcry_md_read(ctx, 0), \ - gcry_md_get_algo_dlen(gcry_md_get_algo(ctx))) + memcpy(data, gcry_md_read(ctx, 0), \ + gcry_md_get_algo_dlen(gcry_md_get_algo(ctx))) #define libssh2_hmac_cleanup(ctx) gcry_md_close(*ctx) -#define libssh2_crypto_init() gcry_control (GCRYCTL_DISABLE_SECMEM) +#define libssh2_crypto_init() gcry_control(GCRYCTL_DISABLE_SECMEM) #define libssh2_crypto_exit() #define libssh2_rsa_ctx struct gcry_sexp -#define _libssh2_rsa_free(rsactx) gcry_sexp_release (rsactx) +#define _libssh2_rsa_free(rsactx) gcry_sexp_release(rsactx) #define libssh2_dsa_ctx struct gcry_sexp -#define _libssh2_dsa_free(dsactx) gcry_sexp_release (dsactx) +#define _libssh2_dsa_free(dsactx) gcry_sexp_release(dsactx) #if LIBSSH2_ECDSA #else @@ -181,25 +181,25 @@ #define _libssh2_gcry_mode(m) (m & 0xFF) #define _libssh2_cipher_aes256ctr \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CTR) + _libssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CTR) #define _libssh2_cipher_aes192ctr \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CTR) + _libssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CTR) #define _libssh2_cipher_aes128ctr \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR) + _libssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR) #define _libssh2_cipher_aes256 \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC) + _libssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC) #define _libssh2_cipher_aes192 \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC) + _libssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC) #define _libssh2_cipher_aes128 \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC) + _libssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC) #define _libssh2_cipher_blowfish \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_CBC) + _libssh2_gcry_ciphermode(GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_CBC) #define _libssh2_cipher_arcfour \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM) + _libssh2_gcry_ciphermode(GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM) #define _libssh2_cipher_cast5 \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC) + _libssh2_gcry_ciphermode(GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC) #define _libssh2_cipher_3des \ - _libssh2_gcry_ciphermode(GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC) + _libssh2_gcry_ciphermode(GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC) #define _libssh2_cipher_dtor(ctx) gcry_cipher_close(*(ctx)) @@ -209,17 +209,17 @@ #define _libssh2_bn_ctx_new() 0 #define _libssh2_bn_ctx_free(bnctx) ((void)0) #define _libssh2_bn_init() gcry_mpi_new(0) -#define _libssh2_bn_init_from_bin() NULL /* because gcry_mpi_scan() creates a - new bignum */ +#define _libssh2_bn_init_from_bin() NULL /* because gcry_mpi_scan() creates a + new bignum */ #define _libssh2_bn_set_word(bn, val) gcry_mpi_set_ui(bn, val) -#define _libssh2_bn_from_bin(bn, len, val) \ +#define _libssh2_bn_from_bin(bn, len, val) \ gcry_mpi_scan(&((bn)), GCRYMPI_FMT_USG, val, len, NULL) -#define _libssh2_bn_to_bin(bn, val) \ +#define _libssh2_bn_to_bin(bn, val) \ gcry_mpi_print(GCRYMPI_FMT_USG, val, _libssh2_bn_bytes(bn), NULL, bn) -#define _libssh2_bn_bytes(bn) \ - (gcry_mpi_get_nbits (bn) / 8 + \ - ((gcry_mpi_get_nbits (bn) % 8 == 0) ? 0 : 1)) -#define _libssh2_bn_bits(bn) gcry_mpi_get_nbits (bn) +#define _libssh2_bn_bytes(bn) \ + (gcry_mpi_get_nbits(bn) / 8 + \ + ((gcry_mpi_get_nbits(bn) % 8 == 0) ? 0 : 1)) +#define _libssh2_bn_bits(bn) gcry_mpi_get_nbits(bn) #define _libssh2_bn_free(bn) gcry_mpi_release(bn) /* Default generate and safe prime sizes for @@ -233,9 +233,9 @@ #define _libssh2_dh_ctx struct gcry_mpi * #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ - _libssh2_dh_key_pair(dhctx, public, g, p, group_order) + _libssh2_dh_key_pair(dhctx, public, g, p, group_order) #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ - _libssh2_dh_secret(dhctx, secret, f, p) + _libssh2_dh_secret(dhctx, secret, f, p) #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) extern void _libssh2_init_aes_ctr(void); extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx); diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 318167620e..012897273b 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -978,7 +978,7 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, ...); #define _libssh2_debug(x) _libssh2_debug_low x #else -#define _libssh2_debug(x) do {} while (0) +#define _libssh2_debug(x) do {} while(0) #endif #define LIBSSH2_SOCKET_UNKNOWN 1 diff --git a/src/mac.c b/src/mac.c index e2c6759439..f0ce99336d 100644 --- a/src/mac.c +++ b/src/mac.c @@ -40,6 +40,7 @@ #if defined(LIBSSH2DEBUG) && defined(LIBSSH2_MAC_NONE_INSECURE) /* mac_none_MAC + * * Minimalist MAC: No MAC. DO NOT USE. * * The SSH2 Transport allows implementations to forego a message diff --git a/src/mbedtls.h b/src/mbedtls.h index f379e6cf87..66290f232f 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -105,12 +105,12 @@ */ #define libssh2_crypto_init() \ - _libssh2_mbedtls_init() + _libssh2_mbedtls_init() #define libssh2_crypto_exit() \ - _libssh2_mbedtls_free() + _libssh2_mbedtls_free() #define _libssh2_random(buf, len) \ - _libssh2_mbedtls_random(buf, len) + _libssh2_mbedtls_random(buf, len) #define libssh2_prepare_iovec(vec, len) /* Empty. */ @@ -124,24 +124,24 @@ #define libssh2_hmac_ctx_init(ctx) #define libssh2_hmac_cleanup(pctx) \ - mbedtls_md_free(pctx) + mbedtls_md_free(pctx) #define libssh2_hmac_update(ctx, data, datalen) \ - mbedtls_md_hmac_update(&ctx, (const unsigned char *) data, datalen) + mbedtls_md_hmac_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_hmac_final(ctx, hash) \ - mbedtls_md_hmac_finish(&ctx, hash) + mbedtls_md_hmac_finish(&ctx, hash) #define libssh2_hmac_sha1_init(pctx, key, keylen) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, key, keylen) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, key, keylen) #define libssh2_hmac_md5_init(pctx, key, keylen) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, key, keylen) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, key, keylen) #define libssh2_hmac_ripemd160_init(pctx, key, keylen) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_RIPEMD160, key, keylen) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_RIPEMD160, key, keylen) #define libssh2_hmac_sha256_init(pctx, key, keylen) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, key, keylen) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, key, keylen) #define libssh2_hmac_sha384_init(pctx, key, keylen) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, key, keylen) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, key, keylen) #define libssh2_hmac_sha512_init(pctx, key, keylen) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, key, keylen) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, key, keylen) /*******************************************************************/ @@ -152,13 +152,13 @@ #define libssh2_sha1_ctx mbedtls_md_context_t #define libssh2_sha1_init(pctx) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0) #define libssh2_sha1_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha1_final(ctx, hash) \ - _libssh2_mbedtls_hash_final(&ctx, hash) + _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha1(data, datalen, hash) \ - _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA1, hash) + _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA1, hash) /*******************************************************************/ /* @@ -168,13 +168,13 @@ #define libssh2_sha256_ctx mbedtls_md_context_t #define libssh2_sha256_init(pctx) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0) #define libssh2_sha256_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha256_final(ctx, hash) \ - _libssh2_mbedtls_hash_final(&ctx, hash) + _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha256(data, datalen, hash) \ - _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA256, hash) + _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA256, hash) /*******************************************************************/ @@ -185,13 +185,13 @@ #define libssh2_sha384_ctx mbedtls_md_context_t #define libssh2_sha384_init(pctx) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0) #define libssh2_sha384_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha384_final(ctx, hash) \ - _libssh2_mbedtls_hash_final(&ctx, hash) + _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha384(data, datalen, hash) \ - _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA384, hash) + _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA384, hash) /*******************************************************************/ @@ -202,13 +202,13 @@ #define libssh2_sha512_ctx mbedtls_md_context_t #define libssh2_sha512_init(pctx) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0) #define libssh2_sha512_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_sha512_final(ctx, hash) \ - _libssh2_mbedtls_hash_final(&ctx, hash) + _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_sha512(data, datalen, hash) \ - _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA512, hash) + _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA512, hash) /*******************************************************************/ @@ -219,13 +219,13 @@ #define libssh2_md5_ctx mbedtls_md_context_t #define libssh2_md5_init(pctx) \ - _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0) + _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0) #define libssh2_md5_update(ctx, data, datalen) \ - mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) + mbedtls_md_update(&ctx, (const unsigned char *) data, datalen) #define libssh2_md5_final(ctx, hash) \ - _libssh2_mbedtls_hash_final(&ctx, hash) + _libssh2_mbedtls_hash_final(&ctx, hash) #define libssh2_md5(data, datalen, hash) \ - _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_MD5, hash) + _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_MD5, hash) /*******************************************************************/ @@ -238,33 +238,33 @@ #define _libssh2_rsa_new(rsactx, e, e_len, n, n_len, \ d, d_len, p, p_len, q, q_len, \ e1, e1_len, e2, e2_len, c, c_len) \ - _libssh2_mbedtls_rsa_new(rsactx, e, e_len, n, n_len, \ - d, d_len, p, p_len, q, q_len, \ - e1, e1_len, e2, e2_len, c, c_len) + _libssh2_mbedtls_rsa_new(rsactx, e, e_len, n, n_len, \ + d, d_len, p, p_len, q, q_len, \ + e1, e1_len, e2, e2_len, c, c_len) #define _libssh2_rsa_new_private(rsactx, s, filename, passphrase) \ - _libssh2_mbedtls_rsa_new_private(rsactx, s, filename, passphrase) + _libssh2_mbedtls_rsa_new_private(rsactx, s, filename, passphrase) #define _libssh2_rsa_new_private_frommemory(rsactx, s, filedata, \ filedata_len, passphrase) \ - _libssh2_mbedtls_rsa_new_private_frommemory(rsactx, s, filedata, \ - filedata_len, passphrase) + _libssh2_mbedtls_rsa_new_private_frommemory(rsactx, s, filedata, \ + filedata_len, passphrase) #define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \ - _libssh2_mbedtls_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) + _libssh2_mbedtls_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) #define _libssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \ - _libssh2_mbedtls_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) + _libssh2_mbedtls_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) #define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \ - _libssh2_mbedtls_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) + _libssh2_mbedtls_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) #define _libssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \ - _libssh2_mbedtls_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) + _libssh2_mbedtls_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) #define _libssh2_rsa_free(rsactx) \ - _libssh2_mbedtls_rsa_free(rsactx) + _libssh2_mbedtls_rsa_free(rsactx) /*******************************************************************/ @@ -309,34 +309,34 @@ typedef enum { #define _libssh2_ecdsa_create_key(session, privkey, pubkey_octal, \ pubkey_octal_len, curve) \ - _libssh2_mbedtls_ecdsa_create_key(session, privkey, pubkey_octal, \ - pubkey_octal_len, curve) + _libssh2_mbedtls_ecdsa_create_key(session, privkey, pubkey_octal, \ + pubkey_octal_len, curve) #define _libssh2_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) \ - _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) + _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) #define _libssh2_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) \ - _libssh2_mbedtls_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) + _libssh2_mbedtls_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) #define _libssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) \ - _libssh2_mbedtls_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) + _libssh2_mbedtls_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) #define _libssh2_ecdsa_new_private(ctx, session, filename, passphrase) \ - _libssh2_mbedtls_ecdsa_new_private(ctx, session, filename, passphrase) + _libssh2_mbedtls_ecdsa_new_private(ctx, session, filename, passphrase) #define _libssh2_ecdsa_new_private_frommemory(ctx, session, filedata, \ filedata_len, passphrase) \ - _libssh2_mbedtls_ecdsa_new_private_frommemory(ctx, session, filedata, \ - filedata_len, passphrase) + _libssh2_mbedtls_ecdsa_new_private_frommemory(ctx, session, filedata, \ + filedata_len, passphrase) #define _libssh2_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) \ - _libssh2_mbedtls_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) + _libssh2_mbedtls_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) #define _libssh2_ecdsa_get_curve_type(ctx) \ - _libssh2_mbedtls_ecdsa_get_curve_type(ctx) + _libssh2_mbedtls_ecdsa_get_curve_type(ctx) #define _libssh2_ecdsa_free(ctx) \ - _libssh2_mbedtls_ecdsa_free(ctx) + _libssh2_mbedtls_ecdsa_free(ctx) #endif /* LIBSSH2_ECDSA */ @@ -347,15 +347,15 @@ typedef enum { */ #define _libssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \ - _libssh2_mbedtls_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) + _libssh2_mbedtls_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) #define _libssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ - pk, pk_len, pw) \ - _libssh2_mbedtls_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ - pk, pk_len, pw) + pk, pk_len, pw) \ + _libssh2_mbedtls_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ + pk, pk_len, pw) #define _libssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ f, kh, kh_len, pk, pk_len, pw) \ - _libssh2_mbedtls_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ - f, kh, kh_len, pk, pk_len, pw) + _libssh2_mbedtls_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ + f, kh, kh_len, pk, pk_len, pw) /*******************************************************************/ @@ -388,11 +388,11 @@ typedef enum { */ #define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \ - _libssh2_mbedtls_cipher_init(ctx, type, iv, secret, encrypt) + _libssh2_mbedtls_cipher_init(ctx, type, iv, secret, encrypt) #define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen) \ - _libssh2_mbedtls_cipher_crypt(ctx, type, encrypt, block, blocklen) + _libssh2_mbedtls_cipher_crypt(ctx, type, encrypt, block, blocklen) #define _libssh2_cipher_dtor(ctx) \ - _libssh2_mbedtls_cipher_dtor(ctx) + _libssh2_mbedtls_cipher_dtor(ctx) /*******************************************************************/ @@ -407,21 +407,21 @@ typedef enum { #define _libssh2_bn mbedtls_mpi #define _libssh2_bn_init() \ - _libssh2_mbedtls_bignum_init() + _libssh2_mbedtls_bignum_init() #define _libssh2_bn_init_from_bin() \ - _libssh2_mbedtls_bignum_init() + _libssh2_mbedtls_bignum_init() #define _libssh2_bn_set_word(bn, word) \ - mbedtls_mpi_lset(bn, word) + mbedtls_mpi_lset(bn, word) #define _libssh2_bn_from_bin(bn, len, bin) \ - mbedtls_mpi_read_binary(bn, bin, len) + mbedtls_mpi_read_binary(bn, bin, len) #define _libssh2_bn_to_bin(bn, bin) \ - mbedtls_mpi_write_binary(bn, bin, mbedtls_mpi_size(bn)) + mbedtls_mpi_write_binary(bn, bin, mbedtls_mpi_size(bn)) #define _libssh2_bn_bytes(bn) \ - mbedtls_mpi_size(bn) + mbedtls_mpi_size(bn) #define _libssh2_bn_bits(bn) \ - mbedtls_mpi_bitlen(bn) + mbedtls_mpi_bitlen(bn) #define _libssh2_bn_free(bn) \ - _libssh2_mbedtls_bignum_free(bn) + _libssh2_mbedtls_bignum_free(bn) /*******************************************************************/ @@ -440,9 +440,9 @@ typedef enum { #define _libssh2_dh_ctx mbedtls_mpi * #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ - _libssh2_dh_key_pair(dhctx, public, g, p, group_order) + _libssh2_dh_key_pair(dhctx, public, g, p, group_order) #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ - _libssh2_dh_secret(dhctx, secret, f, p) + _libssh2_dh_secret(dhctx, secret, f, p) #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) @@ -462,23 +462,23 @@ _libssh2_mbedtls_random(unsigned char *buf, size_t len); int _libssh2_mbedtls_cipher_init(_libssh2_cipher_ctx *ctx, - _libssh2_cipher_type(type), - unsigned char *iv, - unsigned char *secret, - int encrypt); + _libssh2_cipher_type(type), + unsigned char *iv, + unsigned char *secret, + int encrypt); int _libssh2_mbedtls_cipher_crypt(_libssh2_cipher_ctx *ctx, - _libssh2_cipher_type(type), - int encrypt, - unsigned char *block, - size_t blocklen); + _libssh2_cipher_type(type), + int encrypt, + unsigned char *block, + size_t blocklen); void _libssh2_mbedtls_cipher_dtor(_libssh2_cipher_ctx *ctx); int _libssh2_mbedtls_hash_init(mbedtls_md_context_t *ctx, - mbedtls_md_type_t mdtype, - const unsigned char *key, unsigned long keylen); + mbedtls_md_type_t mdtype, + const unsigned char *key, unsigned long keylen); int _libssh2_mbedtls_hash_final(mbedtls_md_context_t *ctx, unsigned char *hash); @@ -494,68 +494,68 @@ _libssh2_mbedtls_bignum_free(_libssh2_bn *bn); int _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, - const unsigned char *edata, - unsigned long elen, - const unsigned char *ndata, - unsigned long nlen, - const unsigned char *ddata, - unsigned long dlen, - const unsigned char *pdata, - unsigned long plen, - const unsigned char *qdata, - unsigned long qlen, - const unsigned char *e1data, - unsigned long e1len, - const unsigned char *e2data, - unsigned long e2len, - const unsigned char *coeffdata, - unsigned long coefflen); + const unsigned char *edata, + unsigned long elen, + const unsigned char *ndata, + unsigned long nlen, + const unsigned char *ddata, + unsigned long dlen, + const unsigned char *pdata, + unsigned long plen, + const unsigned char *qdata, + unsigned long qlen, + const unsigned char *e1data, + unsigned long e1len, + const unsigned char *e2data, + unsigned long e2len, + const unsigned char *coeffdata, + unsigned long coefflen); int _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa, - LIBSSH2_SESSION *session, - const char *filename, - const unsigned char *passphrase); + LIBSSH2_SESSION *session, + const char *filename, + const unsigned char *passphrase); int _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, - LIBSSH2_SESSION *session, - const char *filedata, - size_t filedata_len, - unsigned const char *passphrase); + LIBSSH2_SESSION *session, + const char *filedata, + size_t filedata_len, + unsigned const char *passphrase); int _libssh2_mbedtls_rsa_sha1_verify(libssh2_rsa_ctx *rsa, - const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, - unsigned long m_len); + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, + unsigned long m_len); int _libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION *session, - libssh2_rsa_ctx *rsa, - const unsigned char *hash, - size_t hash_len, - unsigned char **signature, - size_t *signature_len); + libssh2_rsa_ctx *rsa, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, + size_t *signature_len); void _libssh2_mbedtls_rsa_free(libssh2_rsa_ctx *rsa); int _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session, - unsigned char **method, - size_t *method_len, - unsigned char **pubkeydata, - size_t *pubkeydata_len, - const char *privatekey, - const char *passphrase); + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + const char *privatekey, + const char *passphrase); int _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, - unsigned char **method, - size_t *method_len, - unsigned char **pubkeydata, - size_t *pubkeydata_len, - const char *privatekeydata, - size_t privatekeydata_len, - const char *passphrase); + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase); #if LIBSSH2_ECDSA int _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session, @@ -580,9 +580,9 @@ _libssh2_mbedtls_ecdsa_verify(libssh2_ecdsa_ctx *ctx, const unsigned char *m, size_t m_len); int _libssh2_mbedtls_ecdsa_new_private(libssh2_ecdsa_ctx **ctx, - LIBSSH2_SESSION *session, - const char *filename, - const unsigned char *passphrase); + LIBSSH2_SESSION *session, + const char *filename, + const unsigned char *passphrase); int _libssh2_mbedtls_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx **ctx, LIBSSH2_SESSION *session, @@ -611,10 +611,10 @@ extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx); extern int _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, - _libssh2_bn *g, _libssh2_bn *p, int group_order); + _libssh2_bn *g, _libssh2_bn *p, int group_order); extern int _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, - _libssh2_bn *f, _libssh2_bn *p); + _libssh2_bn *f, _libssh2_bn *p); extern void _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx); diff --git a/src/misc.c b/src/misc.c index 654877bda3..d0c7aeeefa 100644 --- a/src/misc.c +++ b/src/misc.c @@ -375,7 +375,7 @@ static const char table64[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* - * _libssh2_base64_encode() + * _libssh2_base64_encode * * Returns the length of the newly created base64 string. The third argument * is a pointer to an allocated area holding the base64 data. If something @@ -656,7 +656,7 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */ /* this define is defined in misc.h for the correct platforms */ #ifdef LIBSSH2_GETTIMEOFDAY_WIN32 /* - * gettimeofday + * _libssh2_gettimeofday * Implementation according to: * The Open Group Base Specifications Issue 6 * IEEE Std 1003.1, 2004 Edition diff --git a/src/openssl.h b/src/openssl.h index cf623c1420..34de8cafc2 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -184,7 +184,7 @@ #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) #define _libssh2_random(buf, len) \ - _libssh2_openssl_random((buf), (len)) + _libssh2_openssl_random((buf), (len)) #define libssh2_prepare_iovec(vec, len) /* Empty. */ @@ -307,43 +307,43 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); #define libssh2_hmac_ctx HMAC_CTX * #define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new() #define libssh2_hmac_sha1_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha1(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha1(), NULL) #define libssh2_hmac_md5_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_md5(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_md5(), NULL) #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_ripemd160(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_ripemd160(), NULL) #define libssh2_hmac_sha256_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha256(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha256(), NULL) #define libssh2_hmac_sha512_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL) + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL) #ifdef LIBSSH2_WOLFSSL /* FIXME: upstream bug as of v5.6.0: datalen is int instead of size_t */ #define libssh2_hmac_update(ctx, data, datalen) \ - HMAC_Update(ctx, data, (int)datalen) + HMAC_Update(ctx, data, (int)datalen) #else #define libssh2_hmac_update(ctx, data, datalen) \ - HMAC_Update(ctx, data, datalen) + HMAC_Update(ctx, data, datalen) #endif /* LIBSSH2_WOLFSSL */ #define libssh2_hmac_final(ctx, data) HMAC_Final(ctx, data, NULL) #define libssh2_hmac_cleanup(ctx) HMAC_CTX_free(*(ctx)) #else #define libssh2_hmac_ctx HMAC_CTX #define libssh2_hmac_ctx_init(ctx) \ - HMAC_CTX_init(&ctx) + HMAC_CTX_init(&ctx) #define libssh2_hmac_sha1_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha1(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha1(), NULL) #define libssh2_hmac_md5_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_md5(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_md5(), NULL) #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_ripemd160(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_ripemd160(), NULL) #define libssh2_hmac_sha256_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha256(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha256(), NULL) #define libssh2_hmac_sha512_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha512(), NULL) + HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha512(), NULL) #define libssh2_hmac_update(ctx, data, datalen) \ - HMAC_Update(&(ctx), data, datalen) + HMAC_Update(&(ctx), data, datalen) #define libssh2_hmac_final(ctx, data) HMAC_Final(&(ctx), data, NULL) #define libssh2_hmac_cleanup(ctx) HMAC_cleanup(ctx) #endif @@ -430,9 +430,9 @@ libssh2_curve_type; #define _libssh2_dh_ctx BIGNUM * #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ - _libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) + _libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ - _libssh2_dh_secret(dhctx, secret, f, p, bnctx) + _libssh2_dh_secret(dhctx, secret, f, p, bnctx) #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx); extern int _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, diff --git a/src/packet.c b/src/packet.c index fa221e832c..c682fc7f1e 100644 --- a/src/packet.c +++ b/src/packet.c @@ -606,7 +606,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, } /* - * _libssh2_debug will actually truncate this for us so + * _libssh2_debug() will actually truncate this for us so * that it's not an inordinate about of data */ _libssh2_debug((session, LIBSSH2_TRACE_TRANS, diff --git a/src/scp.c b/src/scp.c index 524d3e5776..530679abe8 100644 --- a/src/scp.c +++ b/src/scp.c @@ -826,7 +826,7 @@ libssh2_scp_recv2(LIBSSH2_SESSION *session, const char *path, } /* - * scp_send() + * scp_send * * Send a file using SCP * diff --git a/src/session.c b/src/session.c index 5d2b023bc2..a37eccef84 100644 --- a/src/session.c +++ b/src/session.c @@ -356,7 +356,7 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ } /* - * get_socket_nonblocking() + * get_socket_nonblocking * * gets the given blocking or non-blocking state of the socket. */ @@ -602,7 +602,7 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session, #endif /* - * _libssh2_wait_socket() + * _libssh2_wait_socket * * Utility function that waits for action on the socket. Returns 0 when ready * to run again or error on timeout. @@ -853,7 +853,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) } /* - * libssh2_session_handshake() + * libssh2_session_handshake * * session: LIBSSH2_SESSION struct allocated and owned by the calling program * sock: *must* be populated with an opened and connected socket. @@ -871,7 +871,7 @@ libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t sock) } /* - * libssh2_session_startup() + * libssh2_session_startup * * DEPRECATED. Use libssh2_session_handshake() instead! This function is not * portable enough. @@ -888,7 +888,7 @@ libssh2_session_startup(LIBSSH2_SESSION *session, int sock) } /* - * libssh2_session_free + * session_free * * Frees the memory allocated to the session * Also closes and frees any channels attached to this session @@ -1164,7 +1164,7 @@ libssh2_session_free(LIBSSH2_SESSION * session) } /* - * libssh2_session_disconnect_ex + * session_disconnect */ static int session_disconnect(LIBSSH2_SESSION *session, int reason, diff --git a/src/sftp.c b/src/sftp.c index a3862a7387..76e62c08ef 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -180,9 +180,7 @@ add_zombie_request(LIBSSH2_SFTP *sftp, uint32_t request_id) } } -/* - * sftp_packet_add - * +/* sftp_packet_add * Add a packet to the SFTP packet brigade */ static int @@ -276,9 +274,7 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data, return LIBSSH2_ERROR_NONE; } -/* - * sftp_packet_read - * +/* sftp_packet_read * Frame an SFTP packet off the channel */ static int @@ -421,8 +417,8 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) } /* WON'T REACH */ } -/* - * sftp_packetlist_flush + +/* sftp_packetlist_flush * * Remove all pending packets in the packet_list and the corresponding one(s) * in the SFTP packet brigade. @@ -463,7 +459,7 @@ static void sftp_packetlist_flush(LIBSSH2_SFTP_HANDLE *handle) /* - * sftp_packet_ask() + * sftp_packet_ask * * Checks if there's a matching SFTP packet available. */ @@ -761,9 +757,7 @@ LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor) LIBSSH2_FREE(session, sftp); } -/* - * sftp_init - * +/* sftp_init * Startup an SFTP session */ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) @@ -987,9 +981,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) return NULL; } -/* - * libssh2_sftp_init - * +/* libssh2_sftp_init * Startup an SFTP session */ LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session) @@ -1009,9 +1001,7 @@ LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session) return ptr; } -/* - * sftp_shutdown - * +/* sftp_shutdown * Shuts down the SFTP subsystem */ static int @@ -1357,11 +1347,8 @@ libssh2_sftp_open_ex_r(LIBSSH2_SFTP *sftp, const char *filename, return hnd; } -/* - * sftp_read - * +/* sftp_read * Read from an SFTP file handle - * */ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, size_t buffer_size) @@ -2006,8 +1993,7 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *hnd, char *buffer, return (int)rc; /* FIXME: -> ssize_t */ } -/* - * sftp_write +/* sftp_write * * Write data to an SFTP handle. Returns the number of bytes written, or * a negative error code. @@ -2375,9 +2361,7 @@ libssh2_sftp_fsync(LIBSSH2_SFTP_HANDLE *hnd) } -/* - * sftp_fstat - * +/* sftp_fstat * Get or Set stat on a file */ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, @@ -2842,9 +2826,7 @@ libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp, const char *filename, return rc; } -/* - * sftp_rename - * +/* sftp_rename * Rename a file on the remote server */ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, @@ -2986,9 +2968,7 @@ libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename, return rc; } -/* - * sftp_fstatvfs - * +/* sftp_fstatvfs * Get file system statistics */ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) @@ -3124,9 +3104,7 @@ libssh2_sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) return rc; } -/* - * sftp_statvfs - * +/* sftp_statvfs * Get file system statistics */ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, @@ -3263,9 +3241,7 @@ libssh2_sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path, } -/* - * sftp_mkdir - * +/* sftp_mkdir * Create an SFTP directory */ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, @@ -3369,9 +3345,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, } } -/* - * libssh2_sftp_mkdir_ex - * +/* libssh2_sftp_mkdir_ex * Create an SFTP directory */ LIBSSH2_API int diff --git a/src/transport.c b/src/transport.c index 19671054a0..14d511e565 100644 --- a/src/transport.c +++ b/src/transport.c @@ -605,7 +605,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) if(session->packAdd_state != libssh2_NB_state_idle) { /* fullpacket only returns LIBSSH2_ERROR_EAGAIN if - * libssh2_packet_add returns LIBSSH2_ERROR_EAGAIN. If + * libssh2_packet_add() returns LIBSSH2_ERROR_EAGAIN. If * that returns LIBSSH2_ERROR_EAGAIN but the packAdd_state * is idle, then the packet has been added to the brigade, * but some immediate action that was taken based on the diff --git a/src/transport.h b/src/transport.h index 7d395d0e78..7128bda7ac 100644 --- a/src/transport.h +++ b/src/transport.h @@ -43,7 +43,6 @@ #include "libssh2_priv.h" #include "packet.h" - /* * libssh2_transport_send * diff --git a/src/userauth.c b/src/userauth.c index ab58da2656..80fffb0783 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -54,7 +54,7 @@ #include "userauth.h" #include "userauth_kbd_packet.h" -/* libssh2_userauth_list +/* userauth_list * * List authentication methods * Will yield successful login if "none" happens to be allowable for this user @@ -1037,7 +1037,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, &pubkeydata, &pubkeydata_len, privatekey, passphrase); if(rc) - /* libssh2_pub_priv_keyfile calls _libssh2_error() */ + /* libssh2_pub_priv_keyfile() calls _libssh2_error() */ return rc; } @@ -1798,10 +1798,10 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, "username/public key combination"); } - /* - * userauth_publickey_frommemory - * Authenticate using a keypair from memory - */ +/* + * userauth_publickey_frommemory + * Authenticate using a keypair from memory + */ static int userauth_publickey_frommemory(LIBSSH2_SESSION *session, const char *username, @@ -2282,7 +2282,9 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION *session, return rc; } -/* libssh2_userauth_publickey_sk +/* + * libssh2_userauth_publickey_sk + * * Authenticate using an external callback function */ LIBSSH2_API int diff --git a/src/userauth.h b/src/userauth.h index cbb7af974e..10ec5a0f05 100644 --- a/src/userauth.h +++ b/src/userauth.h @@ -45,7 +45,7 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, const unsigned char *pubkeydata, size_t pubkeydata_len, LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC - ((*sign_callback)), + ((*sign_callback)), void *abstract); #endif /* __LIBSSH2_USERAUTH_H */ diff --git a/src/version.c b/src/version.c index 2d5f46f95d..e573f73a17 100644 --- a/src/version.c +++ b/src/version.c @@ -40,9 +40,9 @@ /* libssh2_version() can be used like this: - if (!libssh2_version(LIBSSH2_VERSION_NUM)) { - fprintf (stderr, "Runtime libssh2 version too old!\n"); - exit(1); + if(!libssh2_version(LIBSSH2_VERSION_NUM)) { + fprintf(stderr, "Runtime libssh2 version too old!\n"); + exit(1); } */ LIBSSH2_API diff --git a/src/wincng.c b/src/wincng.c index eb5107f9e3..e35de1130c 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -2447,7 +2447,7 @@ _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, /* Pass ownership to dhctx; these parameters will be freed when * the context is destroyed. We need to keep the parameters more * easily available so that we have access to the `g` value when - * _libssh2_dh_secret is called later. */ + * _libssh2_dh_secret() is called later. */ dhctx->dh_params = dh_params; } dh_params = NULL; diff --git a/src/wincng.h b/src/wincng.h index 94aeef75f7..40aa5fb444 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -122,12 +122,12 @@ void _libssh2_wincng_init(void); void _libssh2_wincng_free(void); #define libssh2_crypto_init() \ - _libssh2_wincng_init() + _libssh2_wincng_init() #define libssh2_crypto_exit() \ - _libssh2_wincng_free() + _libssh2_wincng_free() #define _libssh2_random(buf, len) \ - _libssh2_wincng_random(buf, len) + _libssh2_wincng_random(buf, len) #define libssh2_prepare_iovec(vec, len) /* Empty. */ @@ -150,68 +150,73 @@ typedef struct __libssh2_wincng_hash_ctx { #define libssh2_sha1_ctx _libssh2_wincng_hash_ctx #define libssh2_sha1_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \ - SHA_DIGEST_LENGTH, NULL, 0) == 0) + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \ + SHA_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha1_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ - (unsigned long) datalen) + _libssh2_wincng_hash_update(&ctx, \ + (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha1_final(ctx, hash) \ - _libssh2_wincng_hash_final(&ctx, hash) + _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha1(data, datalen, hash) \ - _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA1, \ - hash, SHA_DIGEST_LENGTH) + _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA1, \ + hash, SHA_DIGEST_LENGTH) #define libssh2_sha256_ctx _libssh2_wincng_hash_ctx #define libssh2_sha256_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \ - SHA256_DIGEST_LENGTH, NULL, 0) == 0) + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \ + SHA256_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha256_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ - (unsigned long) datalen) + _libssh2_wincng_hash_update(&ctx, \ + (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha256_final(ctx, hash) \ - _libssh2_wincng_hash_final(&ctx, hash) + _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha256(data, datalen, hash) \ - _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA256, \ - hash, SHA256_DIGEST_LENGTH) + _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA256, \ + hash, SHA256_DIGEST_LENGTH) #define libssh2_sha384_ctx _libssh2_wincng_hash_ctx #define libssh2_sha384_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA384, \ - SHA384_DIGEST_LENGTH, NULL, 0) == 0) + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA384, \ + SHA384_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha384_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ - (unsigned long) datalen) + _libssh2_wincng_hash_update(&ctx, \ + (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha384_final(ctx, hash) \ - _libssh2_wincng_hash_final(&ctx, hash) + _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha384(data, datalen, hash) \ - _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \ - hash, SHA384_DIGEST_LENGTH) + _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \ + hash, SHA384_DIGEST_LENGTH) #define libssh2_sha512_ctx _libssh2_wincng_hash_ctx #define libssh2_sha512_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA512, \ - SHA512_DIGEST_LENGTH, NULL, 0) == 0) + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA512, \ + SHA512_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_sha512_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ - (unsigned long) datalen) + _libssh2_wincng_hash_update(&ctx, \ + (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_sha512_final(ctx, hash) \ - _libssh2_wincng_hash_final(&ctx, hash) + _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_sha512(data, datalen, hash) \ - _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA512, \ - hash, SHA512_DIGEST_LENGTH) + _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA512, \ + hash, SHA512_DIGEST_LENGTH) #define libssh2_md5_ctx _libssh2_wincng_hash_ctx #define libssh2_md5_init(ctx) \ - (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \ - MD5_DIGEST_LENGTH, NULL, 0) == 0) + (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \ + MD5_DIGEST_LENGTH, NULL, 0) == 0) #define libssh2_md5_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ - (unsigned long) datalen) + _libssh2_wincng_hash_update(&ctx, \ + (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_md5_final(ctx, hash) \ - _libssh2_wincng_hash_final(&ctx, hash) + _libssh2_wincng_hash_final(&ctx, hash) #define libssh2_md5(data, datalen, hash) \ - _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashMD5, \ - hash, MD5_DIGEST_LENGTH) + _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashMD5, \ + hash, MD5_DIGEST_LENGTH) /* * Windows CNG backend: HMAC functions @@ -220,30 +225,30 @@ typedef struct __libssh2_wincng_hash_ctx { #define libssh2_hmac_ctx _libssh2_wincng_hash_ctx #define libssh2_hmac_ctx_init(ctx) #define libssh2_hmac_sha1_init(ctx, key, keylen) \ - _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA1, \ - SHA_DIGEST_LENGTH, \ - key, (unsigned long) keylen) + _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA1, \ + SHA_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_md5_init(ctx, key, keylen) \ - _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacMD5, \ - MD5_DIGEST_LENGTH, \ - key, (unsigned long) keylen) + _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacMD5, \ + MD5_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_ripemd160_init(ctx, key, keylen) - /* not implemented */ + /* not implemented */ #define libssh2_hmac_sha256_init(ctx, key, keylen) \ - _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA256, \ - SHA256_DIGEST_LENGTH, \ - key, (unsigned long) keylen) + _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA256, \ + SHA256_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_sha512_init(ctx, key, keylen) \ - _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA512, \ - SHA512_DIGEST_LENGTH, \ - key, (unsigned long) keylen) + _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA512, \ + SHA512_DIGEST_LENGTH, \ + key, (unsigned long) keylen) #define libssh2_hmac_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ - (unsigned long) datalen) + _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_hmac_final(ctx, hash) \ - _libssh2_wincng_hmac_final(&ctx, hash) + _libssh2_wincng_hmac_final(&ctx, hash) #define libssh2_hmac_cleanup(ctx) \ - _libssh2_wincng_hmac_cleanup(ctx) + _libssh2_wincng_hmac_cleanup(ctx) /*******************************************************************/ @@ -266,25 +271,25 @@ typedef struct __libssh2_wincng_key_ctx { #define _libssh2_rsa_new(rsactx, e, e_len, n, n_len, \ d, d_len, p, p_len, q, q_len, \ e1, e1_len, e2, e2_len, c, c_len) \ - _libssh2_wincng_rsa_new(rsactx, e, e_len, n, n_len, \ - d, d_len, p, p_len, q, q_len, \ - e1, e1_len, e2, e2_len, c, c_len) + _libssh2_wincng_rsa_new(rsactx, e, e_len, n, n_len, \ + d, d_len, p, p_len, q, q_len, \ + e1, e1_len, e2, e2_len, c, c_len) #define _libssh2_rsa_new_private(rsactx, s, filename, passphrase) \ - _libssh2_wincng_rsa_new_private(rsactx, s, filename, passphrase) + _libssh2_wincng_rsa_new_private(rsactx, s, filename, passphrase) #define _libssh2_rsa_new_private_frommemory(rsactx, s, filedata, \ filedata_len, passphrase) \ - _libssh2_wincng_rsa_new_private_frommemory(rsactx, s, filedata, \ - filedata_len, passphrase) + _libssh2_wincng_rsa_new_private_frommemory(rsactx, s, filedata, \ + filedata_len, passphrase) #define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \ - _libssh2_wincng_rsa_sha_sign(s, rsactx, hash, hash_len, sig, sig_len) + _libssh2_wincng_rsa_sha_sign(s, rsactx, hash, hash_len, sig, sig_len) #define _libssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \ - _libssh2_wincng_rsa_sha_sign(s, rsactx, hash, hash_len, sig, sig_len) + _libssh2_wincng_rsa_sha_sign(s, rsactx, hash, hash_len, sig, sig_len) #define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \ - _libssh2_wincng_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) + _libssh2_wincng_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) #define _libssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \ - _libssh2_wincng_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) + _libssh2_wincng_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) #define _libssh2_rsa_free(rsactx) \ - _libssh2_wincng_rsa_free(rsactx) + _libssh2_wincng_rsa_free(rsactx) /* * Windows CNG backend: DSA functions @@ -293,35 +298,35 @@ typedef struct __libssh2_wincng_key_ctx { #define libssh2_dsa_ctx _libssh2_wincng_key_ctx #define _libssh2_dsa_new(dsactx, p, p_len, q, q_len, \ g, g_len, y, y_len, x, x_len) \ - _libssh2_wincng_dsa_new(dsactx, p, p_len, q, q_len, \ - g, g_len, y, y_len, x, x_len) + _libssh2_wincng_dsa_new(dsactx, p, p_len, q, q_len, \ + g, g_len, y, y_len, x, x_len) #define _libssh2_dsa_new_private(dsactx, s, filename, passphrase) \ - _libssh2_wincng_dsa_new_private(dsactx, s, filename, passphrase) + _libssh2_wincng_dsa_new_private(dsactx, s, filename, passphrase) #define _libssh2_dsa_new_private_frommemory(dsactx, s, filedata, \ filedata_len, passphrase) \ - _libssh2_wincng_dsa_new_private_frommemory(dsactx, s, filedata, \ - filedata_len, passphrase) + _libssh2_wincng_dsa_new_private_frommemory(dsactx, s, filedata, \ + filedata_len, passphrase) #define _libssh2_dsa_sha1_sign(dsactx, hash, hash_len, sig) \ - _libssh2_wincng_dsa_sha1_sign(dsactx, hash, hash_len, sig) + _libssh2_wincng_dsa_sha1_sign(dsactx, hash, hash_len, sig) #define _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len) \ - _libssh2_wincng_dsa_sha1_verify(dsactx, sig, m, m_len) + _libssh2_wincng_dsa_sha1_verify(dsactx, sig, m, m_len) #define _libssh2_dsa_free(dsactx) \ - _libssh2_wincng_dsa_free(dsactx) + _libssh2_wincng_dsa_free(dsactx) /* * Windows CNG backend: Key functions */ #define _libssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \ - _libssh2_wincng_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) + _libssh2_wincng_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) #define _libssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ - pk, pk_len, pw) \ - _libssh2_wincng_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ - pk, pk_len, pw) + pk, pk_len, pw) \ + _libssh2_wincng_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ + pk, pk_len, pw) #define _libssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ f, kh, kh_len, pk, pk_len, pw) \ - _libssh2_wincng_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ - f, kh, kh_len, pk, pk_len, pw) + _libssh2_wincng_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \ + f, kh, kh_len, pk, pk_len, pw) /*******************************************************************/ /* @@ -358,22 +363,22 @@ struct _libssh2_wincng_cipher_type { #define _libssh2_cipher_aes256ctr { &_libssh2_wincng.hAlgAES_ECB, 32, 0, 1 } #define _libssh2_cipher_aes192ctr { &_libssh2_wincng.hAlgAES_ECB, 24, 0, 1 } #define _libssh2_cipher_aes128ctr { &_libssh2_wincng.hAlgAES_ECB, 16, 0, 1 } -#define _libssh2_cipher_aes256 { &_libssh2_wincng.hAlgAES_CBC, 32, 1, 0 } -#define _libssh2_cipher_aes192 { &_libssh2_wincng.hAlgAES_CBC, 24, 1, 0 } -#define _libssh2_cipher_aes128 { &_libssh2_wincng.hAlgAES_CBC, 16, 1, 0 } -#define _libssh2_cipher_arcfour { &_libssh2_wincng.hAlgRC4_NA, 16, 0, 0 } -#define _libssh2_cipher_3des { &_libssh2_wincng.hAlg3DES_CBC, 24, 1, 0 } +#define _libssh2_cipher_aes256 { &_libssh2_wincng.hAlgAES_CBC, 32, 1, 0 } +#define _libssh2_cipher_aes192 { &_libssh2_wincng.hAlgAES_CBC, 24, 1, 0 } +#define _libssh2_cipher_aes128 { &_libssh2_wincng.hAlgAES_CBC, 16, 1, 0 } +#define _libssh2_cipher_arcfour { &_libssh2_wincng.hAlgRC4_NA, 16, 0, 0 } +#define _libssh2_cipher_3des { &_libssh2_wincng.hAlg3DES_CBC, 24, 1, 0 } /* * Windows CNG backend: Cipher functions */ #define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \ - _libssh2_wincng_cipher_init(ctx, type, iv, secret, encrypt) + _libssh2_wincng_cipher_init(ctx, type, iv, secret, encrypt) #define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen) \ - _libssh2_wincng_cipher_crypt(ctx, type, encrypt, block, blocklen) + _libssh2_wincng_cipher_crypt(ctx, type, encrypt, block, blocklen) #define _libssh2_cipher_dtor(ctx) \ - _libssh2_wincng_cipher_dtor(ctx) + _libssh2_wincng_cipher_dtor(ctx) /*******************************************************************/ /* @@ -404,20 +409,20 @@ struct _libssh2_wincng_bignum { _libssh2_bn *_libssh2_wincng_bignum_init(void); #define _libssh2_bn_init() \ - _libssh2_wincng_bignum_init() + _libssh2_wincng_bignum_init() #define _libssh2_bn_init_from_bin() \ - _libssh2_bn_init() + _libssh2_bn_init() #define _libssh2_bn_set_word(bn, word) \ - _libssh2_wincng_bignum_set_word(bn, word) + _libssh2_wincng_bignum_set_word(bn, word) #define _libssh2_bn_from_bin(bn, len, bin) \ - _libssh2_wincng_bignum_from_bin(bn, (unsigned long) len, bin) + _libssh2_wincng_bignum_from_bin(bn, (unsigned long) len, bin) #define _libssh2_bn_to_bin(bn, bin) \ - _libssh2_wincng_bignum_to_bin(bn, bin) + _libssh2_wincng_bignum_to_bin(bn, bin) #define _libssh2_bn_bytes(bn) bn->length #define _libssh2_bn_bits(bn) \ - _libssh2_wincng_bignum_bits(bn) + _libssh2_wincng_bignum_bits(bn) #define _libssh2_bn_free(bn) \ - _libssh2_wincng_bignum_free(bn) + _libssh2_wincng_bignum_free(bn) /* * Windows CNG backend: Diffie-Hellman support @@ -444,9 +449,9 @@ typedef struct { #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ - _libssh2_dh_key_pair(dhctx, public, g, p, group_order) + _libssh2_dh_key_pair(dhctx, public, g, p, group_order) #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ - _libssh2_dh_secret(dhctx, secret, f, p) + _libssh2_dh_secret(dhctx, secret, f, p) #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) /*******************************************************************/ @@ -480,12 +485,12 @@ _libssh2_wincng_hmac_cleanup(_libssh2_wincng_hash_ctx *ctx); int _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, - unsigned long hashlen, - const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, - unsigned long m_len, - unsigned long flags); + unsigned long hashlen, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, + unsigned long m_len, + unsigned long flags); int _libssh2_wincng_rsa_new(libssh2_rsa_ctx **rsa, @@ -524,11 +529,11 @@ _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, size_t m_len); int _libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session, - libssh2_rsa_ctx *rsa, - const unsigned char *hash, - size_t hash_len, - unsigned char **signature, - size_t *signature_len); + libssh2_rsa_ctx *rsa, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, + size_t *signature_len); void _libssh2_wincng_rsa_free(libssh2_rsa_ctx *rsa); From 0162d1649ca018fc704365580ed46dd23fa3a92a Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 13 Apr 2023 23:44:17 +0000 Subject: [PATCH 266/424] src: fix indentation of macro definitions (follow-up) Follow-up to d5438f4ba9036e8028f35258dd1ab97cc2edb37c --- src/wincng.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wincng.h b/src/wincng.h index 40aa5fb444..0f967a0b17 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -243,8 +243,9 @@ typedef struct __libssh2_wincng_hash_ctx { SHA512_DIGEST_LENGTH, \ key, (unsigned long) keylen) #define libssh2_hmac_update(ctx, data, datalen) \ - _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \ - (unsigned long) datalen) + _libssh2_wincng_hash_update(&ctx, \ + (const unsigned char *) data, \ + (unsigned long) datalen) #define libssh2_hmac_final(ctx, hash) \ _libssh2_wincng_hmac_final(&ctx, hash) #define libssh2_hmac_cleanup(ctx) \ From 2efdb6747af788384a672c7c63a4821ed15ba32d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 14 Apr 2023 11:05:21 +0000 Subject: [PATCH 267/424] tidy-up: example, tests continued - fix skip auth if `userauthlist` is NULL. Closes #836 (Reported-by: @sudipm-mukherjee on github) - fix most silenced `checksrc` warnings. - sync examples/tests code between each other. (output messages, error handling, declaration order, comments) - stop including unnecessary headers. - always deinitialize in case of error. - drop some redundant variables. - add error handling where missing. - show more error codes. - switch `perror()` to `fprintf()`. - fix some `printf()`s to be `fprintf()`. - formatting. Closes #960 --- example/direct_tcpip.c | 137 +++++++----- example/scp.c | 65 +++--- example/scp_nonblock.c | 82 ++++--- example/scp_write.c | 63 +++--- example/scp_write_nonblock.c | 81 ++++--- example/sftp.c | 154 +++++++------ example/sftp_RW_nonblock.c | 124 ++++++----- example/sftp_append.c | 87 +++++--- example/sftp_mkdir.c | 67 +++--- example/sftp_mkdir_nonblock.c | 70 +++--- example/sftp_nonblock.c | 96 ++++---- example/sftp_write.c | 87 +++++--- example/sftp_write_nonblock.c | 108 ++++----- example/sftp_write_sliding.c | 105 +++++---- example/sftpdir.c | 156 ++++++------- example/sftpdir_nonblock.c | 69 +++--- example/ssh2.c | 208 +++++++++--------- example/ssh2_agent.c | 126 ++++++----- example/ssh2_agent_forwarding.c | 93 ++++---- example/ssh2_echo.c | 91 ++++---- example/ssh2_exec.c | 90 ++++---- example/subsystem_netconf.c | 118 +++++----- example/tcpip-forward.c | 130 ++++++----- example/x11.c | 80 +++---- tests/openssh_fixture.c | 22 +- tests/ossfuzz/ssh2_client_fuzzer.cc | 24 +- tests/runner.c | 2 +- tests/session_fixture.c | 10 +- tests/simple.c | 2 +- tests/ssh2.c | 150 +++++++------ tests/test_agent_forward_succeeds.c | 8 +- tests/test_hostkey.c | 4 +- tests/test_hostkey_hash.c | 14 +- ...teractive_auth_fails_with_wrong_response.c | 4 +- ...t_keyboard_interactive_auth_info_request.c | 4 +- ...tive_auth_succeeds_with_correct_response.c | 6 +- ..._password_auth_fails_with_wrong_password.c | 4 +- ..._password_auth_fails_with_wrong_username.c | 4 +- ...d_auth_succeeds_with_correct_credentials.c | 6 +- ...est_public_key_auth_fails_with_wrong_key.c | 4 +- ...c_key_auth_succeeds_with_correct_dsa_key.c | 6 +- ...key_auth_succeeds_with_correct_ecdsa_key.c | 6 +- ...y_auth_succeeds_with_correct_ed25519_key.c | 6 +- ...cceeds_with_correct_ed25519_key_from_mem.c | 8 +- ...ceeds_with_correct_encrypted_ed25519_key.c | 6 +- ..._succeeds_with_correct_encrypted_rsa_key.c | 6 +- ...c_key_auth_succeeds_with_correct_rsa_key.c | 6 +- ...th_succeeds_with_correct_rsa_openssh_key.c | 6 +- ...h_succeeds_with_correct_signed_ecdsa_key.c | 6 +- ...uth_succeeds_with_correct_signed_rsa_key.c | 6 +- tests/test_read.c | 6 +- 51 files changed, 1542 insertions(+), 1281 deletions(-) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index baa55a72d0..503aa9fcef 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -51,18 +51,19 @@ static unsigned int remote_destport = 22; enum { AUTH_NONE = 0, - AUTH_PASSWORD, - AUTH_PUBLICKEY + AUTH_PASSWORD = 1, + AUTH_PUBLICKEY = 2 }; int main(int argc, char *argv[]) { - int rc, i, auth = AUTH_NONE; + int i, auth = AUTH_NONE; struct sockaddr_in sin; socklen_t sinlen; const char *fingerprint; char *userauthlist; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel = NULL; const char *shost; unsigned int sport; @@ -70,18 +71,17 @@ int main(int argc, char *argv[]) struct timeval tv; ssize_t len, wr; char buf[16384]; - libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; + libssh2_socket_t sock; libssh2_socket_t listensock = LIBSSH2_INVALID_SOCKET; libssh2_socket_t forwardsock = LIBSSH2_INVALID_SOCKET; #ifdef WIN32 char sockopt; WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #else @@ -113,26 +113,26 @@ int main(int argc, char *argv[]) sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "failed to open socket!\n"); - return -1; + goto shutdown; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); if(INADDR_NONE == sin.sin_addr.s_addr) { fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip); - return -1; + goto shutdown; } sin.sin_port = htons(22); if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "Failed to connect to %s!\n", inet_ntoa(sin.sin_addr)); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); if(!session) { fprintf(stderr, "Could not initialize SSH session!\n"); - return -1; + goto shutdown; } /* ... start it up. This will trade welcome banners, exchange keys, @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Error when starting up SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -158,51 +158,55 @@ int main(int argc, char *argv[]) /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - fprintf(stderr, "Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "password")) - auth |= AUTH_PASSWORD; - if(strstr(userauthlist, "publickey")) - auth |= AUTH_PUBLICKEY; - - /* check for options */ - if(argc > 8) { - if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p")) - auth = AUTH_PASSWORD; - if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k")) - auth = AUTH_PUBLICKEY; - } + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(strstr(userauthlist, "password")) + auth |= AUTH_PASSWORD; + if(strstr(userauthlist, "publickey")) + auth |= AUTH_PUBLICKEY; + + /* check for options */ + if(argc > 8) { + if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p")) + auth = AUTH_PASSWORD; + if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k")) + auth = AUTH_PUBLICKEY; + } - if(auth & AUTH_PASSWORD) { - if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); - goto shutdown; + if(auth & AUTH_PASSWORD) { + if(libssh2_userauth_password(session, username, password)) { + fprintf(stderr, "Authentication by password failed!\n"); + goto shutdown; + } } - } - else if(auth & AUTH_PUBLICKEY) { - if(libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) { - fprintf(stderr, "\tAuthentication by public key failed!\n"); + else if(auth & AUTH_PUBLICKEY) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { + fprintf(stderr, "Authentication by public key failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by public key succeeded.\n"); + } + } + else { + fprintf(stderr, "No supported authentication methods found!\n"); goto shutdown; } - fprintf(stderr, "\tAuthentication by public key succeeded.\n"); - } - else { - fprintf(stderr, "No supported authentication methods found!\n"); - goto shutdown; } listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(listensock == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "failed to open listen socket!\n"); - return -1; + goto shutdown; } sin.sin_family = AF_INET; sin.sin_port = htons((unsigned short)local_listenport); sin.sin_addr.s_addr = inet_addr(local_listenip); if(INADDR_NONE == sin.sin_addr.s_addr) { - perror("inet_addr"); + fprintf(stderr, "failed in inet_addr()!\n"); goto shutdown; } sockopt = 1; @@ -210,11 +214,11 @@ int main(int argc, char *argv[]) sizeof(sockopt)); sinlen = sizeof(sin); if(-1 == bind(listensock, (struct sockaddr *)&sin, sinlen)) { - perror("bind"); + fprintf(stderr, "failed to bind()!\n"); goto shutdown; } if(-1 == listen(listensock, 2)) { - perror("listen"); + fprintf(stderr, "failed to listen()!\n"); goto shutdown; } @@ -237,8 +241,8 @@ int main(int argc, char *argv[]) remote_destport, shost, sport); if(!channel) { fprintf(stderr, "Could not open the direct-tcpip channel!\n" - "(Note that this can be a problem at the server!" - " Please review the server logs.)\n"); + "(Note that this can be a problem at the server!" + " Please review the server logs.)\n"); goto shutdown; } @@ -252,13 +256,13 @@ int main(int argc, char *argv[]) tv.tv_usec = 100000; rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv); if(-1 == rc) { - perror("select"); + fprintf(stderr, "failed to select()!\n"); goto shutdown; } if(rc && FD_ISSET(forwardsock, &fds)) { len = recv(forwardsock, buf, sizeof(buf), 0); if(len < 0) { - perror("read"); + fprintf(stderr, "failed to recv()!\n"); goto shutdown; } else if(0 == len) { @@ -293,7 +297,7 @@ int main(int argc, char *argv[]) while(wr < len) { ssize_t nsent = send(forwardsock, buf + wr, len - wr, 0); if(nsent <= 0) { - perror("write"); + fprintf(stderr, "failed to send()!\n"); goto shutdown; } wr += nsent; @@ -307,23 +311,38 @@ int main(int argc, char *argv[]) } shutdown: + + if(forwardsock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(forwardsock); - closesocket(listensock); + closesocket(forwardsock); #else - close(forwardsock); - close(listensock); + close(forwardsock); #endif + } + + if(listensock != LIBSSH2_INVALID_SOCKET) { +#ifdef WIN32 + closesocket(listensock); +#else + close(listensock); +#endif + } + if(channel) libssh2_channel_free(channel); - libssh2_session_disconnect(session, "Client disconnecting normally"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } libssh2_exit(); diff --git a/example/scp.c b/example/scp.c index 7a917ba862..2c0e0af68a 100644 --- a/example/scp.c +++ b/example/scp.c @@ -21,9 +21,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include @@ -31,6 +28,12 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *scppath = "/tmp/TEST"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -38,24 +41,18 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *scppath = "/tmp/TEST"; libssh2_struct_stat fileinfo; - int rc; libssh2_struct_stat_size got = 0; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -82,25 +79,29 @@ int main(int argc, char *argv[]) return 1; } - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers @@ -108,7 +109,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -126,7 +127,7 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -135,7 +136,7 @@ int main(int argc, char *argv[]) if(libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -149,7 +150,6 @@ int main(int argc, char *argv[]) goto shutdown; } - while(got < fileinfo.st_size) { char mem[1024]; int amount = sizeof(mem); @@ -176,14 +176,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index ea07f32083..615b4ea570 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "scp_nonblock 192.168.0.1 user password /tmp/secrets" + * $ ./scp_nonblock 192.168.0.1 user password /tmp/secrets */ #include "libssh2_setup.h" @@ -39,12 +39,18 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *scppath = "/tmp/TEST"; + #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) { - return (newer.tv_sec-older.tv_sec)*1000+ - (newer.tv_usec-older.tv_usec)/1000; + return (newer.tv_sec - older.tv_sec) * 1000 + + (newer.tv_usec - older.tv_usec) / 1000; } #endif @@ -85,31 +91,25 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *scppath = "/tmp/TEST"; libssh2_struct_stat fileinfo; #ifdef HAVE_GETTIMEOFDAY struct timeval start; struct timeval end; long time_ms; #endif - int rc; int spin = 0; libssh2_struct_stat_size got = 0; libssh2_struct_stat_size total = 0; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -131,29 +131,34 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are non-blocking */ libssh2_session_set_blocking(session, 0); @@ -169,14 +174,14 @@ int main(int argc, char *argv[]) LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do - * is check the hostkey's fingerprint against our known hosts Your app - * may have it hard coded, may go to a file, may present it to the - * user, that's your call - */ + * is check the hostkey's fingerprint against our known hosts Your app + * may have it hard coded, may go to a file, may present it to the + * user, that's your call + */ fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); fprintf(stderr, "Fingerprint: "); for(i = 0; i < 20; i++) { @@ -189,7 +194,7 @@ int main(int argc, char *argv[]) while((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -200,7 +205,7 @@ int main(int argc, char *argv[]) password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -231,13 +236,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_scp_recv() is done, now receive data!\n"); while(got < fileinfo.st_size) { - char mem[1024*24]; + char mem[1024 * 24]; ssize_t nread; do { int amount = sizeof(mem); - if((fileinfo.st_size -got) < amount) { + if((fileinfo.st_size - got) < amount) { amount = (int)(fileinfo.st_size - got); } @@ -250,7 +255,7 @@ int main(int argc, char *argv[]) } } while(nread > 0); - if((nread == LIBSSH2_ERROR_EAGAIN) && (got < fileinfo.st_size)) { + if(nread == LIBSSH2_ERROR_EAGAIN && got < fileinfo.st_size) { /* this is due to blocking that would occur otherwise so we loop on this condition */ @@ -267,7 +272,7 @@ int main(int argc, char *argv[]) time_ms = tvdiff(end, start); fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", (long)total, time_ms, - (double)total/((double)time_ms/1000.0), spin); + (double)total / ((double)time_ms / 1000.0), spin); #else fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin); #endif @@ -277,14 +282,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/scp_write.c b/example/scp_write.c index e95c0bb666..ac66c0f138 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -17,9 +17,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include @@ -27,6 +24,13 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *loclfile = "scp_write.c"; +static const char *scppath = "/tmp/TEST"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -34,28 +38,21 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; + int rc; LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *loclfile = "scp_write.c"; - const char *scppath = "/tmp/TEST"; FILE *local; - int rc; char mem[1024]; size_t nread; char *ptr; struct stat fileinfo; - int err; #ifdef WIN32 WSADATA wsadata; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -80,7 +77,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -88,19 +85,18 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { fprintf(stderr, "Can't open local file %s\n", loclfile); - return -1; + return 1; } stat(loclfile, &fileinfo); - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); if(sock == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "failed to create socket!\n"); - return -1; + goto shutdown; } sin.sin_family = AF_INET; @@ -108,14 +104,15 @@ int main(int argc, char *argv[]) sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers @@ -123,7 +120,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -141,7 +138,7 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -150,7 +147,7 @@ int main(int argc, char *argv[]) if(libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -162,6 +159,7 @@ int main(int argc, char *argv[]) if(!channel) { char *errmsg; int errlen; + int err; err = libssh2_session_last_error(session, &errmsg, &errlen, 0); fprintf(stderr, "Unable to open a session: (%d) %s\n", err, errmsg); goto shutdown; @@ -211,13 +209,18 @@ int main(int argc, char *argv[]) libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); } + + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + if(local) fclose(local); + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 372e461f36..7a2754eedb 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -31,6 +31,13 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *loclfile = "scp_write.c"; +static const char *scppath = "/tmp/TEST"; + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; @@ -68,17 +75,11 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; + int rc; LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *loclfile = "scp_write.c"; - const char *scppath = "/tmp/TEST"; FILE *local; - int rc; - char mem[1024*100]; + char mem[1024 * 100]; size_t nread; char *ptr; struct stat fileinfo; @@ -89,11 +90,10 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -118,38 +118,42 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } local = fopen(loclfile, "rb"); if(!local) { - fprintf(stderr, "Can't local file %s\n", loclfile); - return -1; + fprintf(stderr, "Can't open local file %s\n", loclfile); + return 1; } stat(loclfile, &fileinfo); - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are non-blocking */ libssh2_session_set_blocking(session, 0); @@ -157,11 +161,11 @@ int main(int argc, char *argv[]) /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers */ - while((rc = libssh2_session_handshake(session, sock)) - == LIBSSH2_ERROR_EAGAIN); + while((rc = libssh2_session_handshake(session, sock)) == + LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -181,7 +185,7 @@ int main(int argc, char *argv[]) while((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -192,7 +196,7 @@ int main(int argc, char *argv[]) password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -202,8 +206,8 @@ int main(int argc, char *argv[]) channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777, (size_t)fileinfo.st_size); - if((!channel) && (libssh2_session_last_errno(session) != - LIBSSH2_ERROR_EAGAIN)) { + if(!channel && + libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { char *err_msg; libssh2_session_last_error(session, &err_msg, NULL, 0); @@ -247,7 +251,7 @@ int main(int argc, char *argv[]) } while(nread); } while(!nread); /* only continue if nread was drained */ - duration = (int)(time(NULL)-start); + duration = (int)(time(NULL) - start); fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n", (long)total, duration, (double)total / duration); @@ -266,15 +270,20 @@ int main(int argc, char *argv[]) shutdown: - while(libssh2_session_disconnect(session, "Normal Shutdown") - == LIBSSH2_ERROR_EAGAIN); - libssh2_session_free(session); + if(session) { + while(libssh2_session_disconnect(session, "Normal Shutdown") == + LIBSSH2_ERROR_EAGAIN); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp.c b/example/sftp.c index c3bf835fca..3a3c5866f3 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k" + * $ ./sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k */ #include "libssh2_setup.h" @@ -27,9 +27,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include @@ -76,7 +73,7 @@ static void kbd_callback(const char *name, int name_len, fgets(buf, sizeof(buf), stdin); n = strlen(buf); while(n > 0 && strchr("\r\n", buf[n - 1])) - n--; + n--; buf[n] = 0; responses[i].text = strdup(buf); @@ -99,18 +96,17 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; char *userauthlist; - LIBSSH2_SESSION *session; int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -132,7 +128,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -142,20 +138,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are blocking */ libssh2_session_set_blocking(session, 1); @@ -166,7 +167,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -184,66 +185,68 @@ int main(int argc, char *argv[]) /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - fprintf(stderr, "Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "password") != NULL) { - auth_pw |= 1; - } - if(strstr(userauthlist, "keyboard-interactive") != NULL) { - auth_pw |= 2; - } - if(strstr(userauthlist, "publickey") != NULL) { - auth_pw |= 4; - } - - /* if we got an 4. argument we set this option if supported */ - if(argc > 5) { - if((auth_pw & 1) && !strcmp(argv[5], "-p")) { - auth_pw = 1; + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(strstr(userauthlist, "password")) { + auth_pw |= 1; } - if((auth_pw & 2) && !strcmp(argv[5], "-i")) { - auth_pw = 2; + if(strstr(userauthlist, "keyboard-interactive")) { + auth_pw |= 2; } - if((auth_pw & 4) && !strcmp(argv[5], "-k")) { - auth_pw = 4; + if(strstr(userauthlist, "publickey")) { + auth_pw |= 4; } - } - if(auth_pw & 1) { - /* We could authenticate via password */ - if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); - goto shutdown; + /* check for options */ + if(argc > 5) { + if((auth_pw & 1) && !strcmp(argv[5], "-p")) { + auth_pw = 1; + } + if((auth_pw & 2) && !strcmp(argv[5], "-i")) { + auth_pw = 2; + } + if((auth_pw & 4) && !strcmp(argv[5], "-k")) { + auth_pw = 4; + } } - } - else if(auth_pw & 2) { - /* Or via keyboard-interactive */ - if(libssh2_userauth_keyboard_interactive(session, username, - &kbd_callback) ) { - fprintf(stderr, - "\tAuthentication by keyboard-interactive failed!\n"); - goto shutdown; + + if(auth_pw & 1) { + /* We could authenticate via password */ + if(libssh2_userauth_password(session, username, password)) { + fprintf(stderr, "Authentication by password failed!\n"); + goto shutdown; + } } - else { - fprintf(stderr, - "\tAuthentication by keyboard-interactive succeeded.\n"); + else if(auth_pw & 2) { + /* Or via keyboard-interactive */ + if(libssh2_userauth_keyboard_interactive(session, username, + &kbd_callback) ) { + fprintf(stderr, + "Authentication by keyboard-interactive failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, + "Authentication by keyboard-interactive succeeded.\n"); + } } - } - else if(auth_pw & 4) { - /* Or by public key */ - if(libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) { - fprintf(stderr, "\tAuthentication by public key failed!\n"); - goto shutdown; + else if(auth_pw & 4) { + /* Or by public key */ + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { + fprintf(stderr, "Authentication by public key failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by public key succeeded.\n"); + } } else { - fprintf(stderr, "\tAuthentication by public key succeeded.\n"); + fprintf(stderr, "No supported authentication methods found!\n"); + goto shutdown; } } - else { - fprintf(stderr, "No supported authentication methods found!\n"); - goto shutdown; - } fprintf(stderr, "libssh2_sftp_init()!\n"); sftp_session = libssh2_sftp_init(session); @@ -255,14 +258,14 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open()!\n"); /* Request a file via SFTP */ - sftp_handle = - libssh2_sftp_open(sftp_session, sftppath, LIBSSH2_FXF_READ, 0); - + sftp_handle = libssh2_sftp_open(sftp_session, sftppath, + LIBSSH2_FXF_READ, 0); if(!sftp_handle) { fprintf(stderr, "Unable to open file with SFTP: %ld\n", libssh2_sftp_last_error(sftp_session)); goto shutdown; } + fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n"); do { char mem[1024]; @@ -284,14 +287,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 829145481d..9696e86abe 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -27,9 +27,6 @@ #ifdef HAVE_NETINET_IN_H #include #endif -#ifdef HAVE_ARPA_INET_H -#include -#endif #ifdef HAVE_SYS_TIME_H #include #endif @@ -44,6 +41,13 @@ example uses to store the downloaded file in */ +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *sftppath = "/tmp/TEST"; /* source path */ +static const char *dest = "/tmp/TEST2"; /* destination path */ + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; @@ -80,17 +84,11 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *sftppath = "/tmp/TEST"; /* source path */ - const char *dest = "/tmp/TEST2"; /* destination path */ int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; - FILE *tempstorage; + FILE *tempstorage = NULL; char mem[1000]; struct timeval timeout; fd_set fd; @@ -98,40 +96,56 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif + if(argc > 1) { + username = argv[1]; + } + if(argc > 2) { + password = argv[2]; + } + if(argc > 3) { + sftppath = argv[3]; + } + if(argc > 4) { + dest = argv[4]; + } + rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } - /* Ultra basic "connect to port 22 on localhost" - * The application is responsible for creating the socket establishing - * the connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = htonl(0x7F000001); if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers @@ -139,7 +153,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } libssh2_session_set_blocking(session, 0); @@ -156,19 +170,6 @@ int main(int argc, char *argv[]) } fprintf(stderr, "\n"); - if(argc > 1) { - username = argv[1]; - } - if(argc > 2) { - password = argv[2]; - } - if(argc > 3) { - sftppath = argv[3]; - } - if(argc > 4) { - dest = argv[4]; - } - tempstorage = fopen(STORAGE, "wb"); if(!tempstorage) { fprintf(stderr, "Can't open temp storage file %s\n", STORAGE); @@ -177,22 +178,22 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ - while((rc = libssh2_userauth_password(session, username, password)) - == LIBSSH2_ERROR_EAGAIN); + while((rc = libssh2_userauth_password(session, username, password)) == + LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } else { /* Or by public key */ while((rc = - libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) == + libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -201,8 +202,7 @@ int main(int argc, char *argv[]) sftp_session = libssh2_sftp_init(session); if(!sftp_session) { - if(libssh2_session_last_errno(session) == - LIBSSH2_ERROR_EAGAIN) { + if(libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { fprintf(stderr, "non-blocking init\n"); waitsocket(sock, session); /* now we wait */ } @@ -217,10 +217,10 @@ int main(int argc, char *argv[]) do { sftp_handle = libssh2_sftp_open(sftp_session, sftppath, LIBSSH2_FXF_READ, 0); - if(!sftp_handle) { if(libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { - fprintf(stderr, "Unable to open file with SFTP\n"); + fprintf(stderr, "Unable to open file with SFTP: %ld\n", + libssh2_sftp_last_error(sftp_session)); goto shutdown; } else { @@ -283,11 +283,13 @@ int main(int argc, char *argv[]) /* we're done downloading, now reverse the process and upload the temporarily stored data to the destination path */ - sftp_handle = - libssh2_sftp_open(sftp_session, dest, - LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT, - LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| - LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); + sftp_handle = libssh2_sftp_open(sftp_session, dest, + LIBSSH2_FXF_WRITE | + LIBSSH2_FXF_CREAT, + LIBSSH2_SFTP_S_IRUSR | + LIBSSH2_SFTP_S_IWUSR | + LIBSSH2_SFTP_S_IRGRP | + LIBSSH2_SFTP_S_IROTH); if(sftp_handle) { size_t nread; char *ptr; @@ -342,16 +344,22 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + if(tempstorage) fclose(tempstorage); + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_append.c b/example/sftp_append.c index 0684ce8950..db80e10611 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * sftp_append 192.168.0.1 user password localfile /tmp/remotefile + * $ ./sftp_append 192.168.0.1 user password localfile /tmp/remotefile */ #include "libssh2_setup.h" @@ -30,6 +30,13 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *loclfile = "sftp_write.c"; +static const char *sftppath = "/tmp/TEST"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -37,30 +44,23 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *loclfile = "sftp_write.c"; - const char *sftppath = "/tmp/TEST"; int rc; - FILE *local; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; LIBSSH2_SFTP_ATTRIBUTES attrs; - char mem[1024*100]; + char mem[1024 * 100]; + FILE *local; size_t nread; ssize_t nwritten; char *ptr; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { fprintf(stderr, "Can't open local file %s\n", loclfile); - return -1; + return 1; } /* @@ -101,20 +101,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are blocking */ libssh2_session_set_blocking(session, 1); @@ -125,7 +130,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -143,7 +148,7 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -152,7 +157,7 @@ int main(int argc, char *argv[]) if(libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -167,14 +172,16 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open() for READ and WRITE!\n"); /* Request a file via SFTP */ - - sftp_handle = - libssh2_sftp_open(sftp_session, sftppath, - LIBSSH2_FXF_WRITE|LIBSSH2_FXF_READ, - LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| - LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); + sftp_handle = libssh2_sftp_open(sftp_session, sftppath, + LIBSSH2_FXF_WRITE | + LIBSSH2_FXF_READ, + LIBSSH2_SFTP_S_IRUSR | + LIBSSH2_SFTP_S_IWUSR | + LIBSSH2_SFTP_S_IRGRP | + LIBSSH2_SFTP_S_IROTH); if(!sftp_handle) { - fprintf(stderr, "Unable to open file with SFTP\n"); + fprintf(stderr, "Unable to open file with SFTP: %ld\n", + libssh2_sftp_last_error(sftp_session)); goto shutdown; } @@ -187,11 +194,12 @@ int main(int argc, char *argv[]) fprintf(stderr, "Did a seek to position %ld\n", (long) attrs.filesize); fprintf(stderr, "libssh2_sftp_open() a handle for APPEND\n"); - if(!sftp_handle) { - fprintf(stderr, "Unable to open file with SFTP\n"); + fprintf(stderr, "Unable to open file with SFTP: %ld\n", + libssh2_sftp_last_error(sftp_session)); goto shutdown; } + fprintf(stderr, "libssh2_sftp_open() is done, now send data!\n"); do { nread = fread(mem, 1, sizeof(mem), local); @@ -216,16 +224,23 @@ int main(int argc, char *argv[]) libssh2_sftp_shutdown(sftp_session); shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + if(local) fclose(local); + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index ab3a56c6ed..3937d5bed6 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "sftp 192.168.0.1 user password /tmp/sftp_mkdir" + * $ ./sftp_mkdir 192.168.0.1 user password /tmp/sftp_mkdir */ #include "libssh2_setup.h" @@ -30,6 +30,12 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *sftppath = "/tmp/sftp_mkdir"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -37,22 +43,16 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *sftppath = "/tmp/sftp_mkdir"; int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -84,20 +84,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers @@ -105,7 +110,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -123,7 +128,7 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -132,7 +137,7 @@ int main(int argc, char *argv[]) if(libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -149,10 +154,11 @@ int main(int argc, char *argv[]) /* Make a directory via SFTP */ rc = libssh2_sftp_mkdir(sftp_session, sftppath, - LIBSSH2_SFTP_S_IRWXU| - LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IXGRP| - LIBSSH2_SFTP_S_IROTH|LIBSSH2_SFTP_S_IXOTH); - + LIBSSH2_SFTP_S_IRWXU | + LIBSSH2_SFTP_S_IRGRP | + LIBSSH2_SFTP_S_IXGRP | + LIBSSH2_SFTP_S_IROTH | + LIBSSH2_SFTP_S_IXOTH); if(rc) fprintf(stderr, "libssh2_sftp_mkdir failed: %d\n", rc); @@ -160,14 +166,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index 6d636cb07e..acbec2b44d 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c" + * $ ./sftp_mkdir_nonblock 192.168.0.1 user password /tmp/sftp_write_nonblock.c */ #include "libssh2_setup.h" @@ -30,6 +30,12 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *sftppath = "/tmp/sftp_mkdir_nonblock"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -37,22 +43,16 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *sftppath = "/tmp/sftp_mkdir_nonblock"; int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -84,20 +84,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers @@ -105,7 +110,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -123,7 +128,7 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -132,12 +137,11 @@ int main(int argc, char *argv[]) if(libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } - fprintf(stderr, "libssh2_sftp_init()!\n"); sftp_session = libssh2_sftp_init(session); if(!sftp_session) { @@ -148,26 +152,32 @@ int main(int argc, char *argv[]) /* Since we have set non-blocking, tell libssh2 we are non-blocking */ libssh2_session_set_blocking(session, 0); - fprintf(stderr, "libssh2_sftp_mkdirnb()!\n"); /* Make a directory via SFTP */ while(libssh2_sftp_mkdir(sftp_session, sftppath, - LIBSSH2_SFTP_S_IRWXU| - LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IXGRP| - LIBSSH2_SFTP_S_IROTH|LIBSSH2_SFTP_S_IXOTH) - == LIBSSH2_ERROR_EAGAIN); + LIBSSH2_SFTP_S_IRWXU | + LIBSSH2_SFTP_S_IRGRP | + LIBSSH2_SFTP_S_IXGRP | + LIBSSH2_SFTP_S_IROTH | + LIBSSH2_SFTP_S_IXOTH) == + LIBSSH2_ERROR_EAGAIN); libssh2_sftp_shutdown(sftp_session); shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 4fcdaa18f7..741eeff1f0 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "sftp_nonblock 192.168.0.1 user password /tmp/secrets" + * $ ./sftp_nonblock 192.168.0.1 user password /tmp/secrets */ #include "libssh2_setup.h" @@ -40,12 +40,18 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *sftppath = "/tmp/TEST"; + #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) { - return (newer.tv_sec-older.tv_sec)*1000+ - (newer.tv_usec-older.tv_usec)/1000; + return (newer.tv_sec - older.tv_sec) * 1000 + + (newer.tv_usec - older.tv_usec) / 1000; } #endif @@ -86,30 +92,24 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *sftppath = "/tmp/TEST"; + int rc; + LIBSSH2_SESSION *session = NULL; + LIBSSH2_SFTP *sftp_session; + LIBSSH2_SFTP_HANDLE *sftp_handle; #ifdef HAVE_GETTIMEOFDAY struct timeval start; struct timeval end; long time_ms; #endif - int rc; libssh2_struct_stat_size total = 0; int spin = 0; - LIBSSH2_SFTP *sftp_session; - LIBSSH2_SFTP_HANDLE *sftp_handle; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -141,19 +141,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are non-blocking */ libssh2_session_set_blocking(session, 0); @@ -166,10 +172,10 @@ int main(int argc, char *argv[]) * and setup crypto, compression, and MAC layers */ while((rc = libssh2_session_handshake(session, sock)) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -186,22 +192,22 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ - while((rc = libssh2_userauth_password(session, username, password)) - == LIBSSH2_ERROR_EAGAIN); + while((rc = libssh2_userauth_password(session, username, password)) == + LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } else { /* Or by public key */ while((rc = - libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) == + libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -213,8 +219,7 @@ int main(int argc, char *argv[]) sftp_session = libssh2_sftp_init(session); if(!sftp_session) { - if(libssh2_session_last_errno(session) == - LIBSSH2_ERROR_EAGAIN) { + if(libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { fprintf(stderr, "non-blocking init\n"); waitsocket(sock, session); /* now we wait */ } @@ -230,10 +235,10 @@ int main(int argc, char *argv[]) do { sftp_handle = libssh2_sftp_open(sftp_session, sftppath, LIBSSH2_FXF_READ, 0); - if(!sftp_handle) { if(libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { - fprintf(stderr, "Unable to open file with SFTP\n"); + fprintf(stderr, "Unable to open file with SFTP: %ld\n", + libssh2_sftp_last_error(sftp_session)); goto shutdown; } else { @@ -245,12 +250,12 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open() is done, now receive data!\n"); do { - char mem[1024*24]; + char mem[1024 * 24]; ssize_t nread; /* loop until we fail */ - while((nread = libssh2_sftp_read(sftp_handle, mem, - sizeof(mem))) == LIBSSH2_ERROR_EAGAIN) { + while((nread = libssh2_sftp_read(sftp_handle, mem, sizeof(mem))) == + LIBSSH2_ERROR_EAGAIN) { spin++; waitsocket(sock, session); /* now we wait */ } @@ -268,7 +273,7 @@ int main(int argc, char *argv[]) time_ms = tvdiff(end, start); fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", (long)total, time_ms, - (double)total/((double)time_ms/1000.0), spin); + (double)total / ((double)time_ms / 1000.0), spin); #else fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin); #endif @@ -278,16 +283,21 @@ int main(int argc, char *argv[]) shutdown: - fprintf(stderr, "libssh2_session_disconnect\n"); - while(libssh2_session_disconnect(session, "Normal Shutdown") - == LIBSSH2_ERROR_EAGAIN); - libssh2_session_free(session); + if(session) { + fprintf(stderr, "libssh2_session_disconnect\n"); + while(libssh2_session_disconnect(session, "Normal Shutdown") == + LIBSSH2_ERROR_EAGAIN); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_write.c b/example/sftp_write.c index dba15e658a..62b0ee0f23 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets" + * $ ./sftp_write 192.168.0.1 user password sftp_write.c /tmp/secrets */ #include "libssh2_setup.h" @@ -30,6 +30,13 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *loclfile = "sftp_write.c"; +static const char *sftppath = "/tmp/TEST"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -37,29 +44,22 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *loclfile = "sftp_write.c"; - const char *sftppath = "/tmp/TEST"; int rc; - FILE *local; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; - char mem[1024*100]; + FILE *local; + char mem[1024 * 100]; size_t nread; ssize_t nwritten; char *ptr; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { fprintf(stderr, "Can't open local file %s\n", loclfile); - return -1; + return 1; } /* @@ -100,20 +100,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are blocking */ libssh2_session_set_blocking(session, 1); @@ -124,7 +129,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -142,7 +147,7 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -151,7 +156,7 @@ int main(int argc, char *argv[]) if(libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -166,16 +171,20 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open()!\n"); /* Request a file via SFTP */ - sftp_handle = - libssh2_sftp_open(sftp_session, sftppath, - LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, - LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| - LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); - + sftp_handle = libssh2_sftp_open(sftp_session, sftppath, + LIBSSH2_FXF_WRITE | + LIBSSH2_FXF_CREAT | + LIBSSH2_FXF_TRUNC, + LIBSSH2_SFTP_S_IRUSR | + LIBSSH2_SFTP_S_IWUSR | + LIBSSH2_SFTP_S_IRGRP | + LIBSSH2_SFTP_S_IROTH); if(!sftp_handle) { - fprintf(stderr, "Unable to open file with SFTP\n"); + fprintf(stderr, "Unable to open file with SFTP: %ld\n", + libssh2_sftp_last_error(sftp_session)); goto shutdown; } + fprintf(stderr, "libssh2_sftp_open() is done, now send data!\n"); do { nread = fread(mem, 1, sizeof(mem), local); @@ -193,23 +202,29 @@ int main(int argc, char *argv[]) ptr += nwritten; nread -= nwritten; } while(nread); - } while(nwritten > 0); libssh2_sftp_close(sftp_handle); libssh2_sftp_shutdown(sftp_session); shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + if(local) fclose(local); + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 793434369f..5c662f8303 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "sftp 192.168.0.1 user password thisfile /tmp/storehere" + * $ ./sftp_write_nonblock 192.168.0.1 user password thisfile /tmp/storehere */ #include "libssh2_setup.h" @@ -37,6 +37,13 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *loclfile = "sftp_write_nonblock.c"; +static const char *sftppath = "/tmp/sftp_write_nonblock.c"; + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; @@ -74,17 +81,11 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *loclfile = "sftp_write_nonblock.c"; - const char *sftppath = "/tmp/sftp_write_nonblock.c"; int rc; - FILE *local; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; + FILE *local; char mem[1024 * 100]; size_t nread; ssize_t nwritten; @@ -95,11 +96,10 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { fprintf(stderr, "Can't open local file %s\n", loclfile); - return -1; + return 1; } /* @@ -140,20 +140,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are non-blocking */ libssh2_session_set_blocking(session, 0); @@ -161,17 +166,17 @@ int main(int argc, char *argv[]) /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers */ - while((rc = libssh2_session_handshake(session, sock)) - == LIBSSH2_ERROR_EAGAIN); + while((rc = libssh2_session_handshake(session, sock)) == + LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } - /* At this point we have not yet authenticated. The first thing to do is - * check the hostkey's fingerprint against our known hosts Your app may - * have it hard coded, may go to a file, may present it to the user, - * that's your call + /* At this point we have not yet authenticated. The first thing to do + * is check the hostkey's fingerprint against our known hosts Your app + * may have it hard coded, may go to a file, may present it to the + * user, that's your call */ fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); fprintf(stderr, "Fingerprint: "); @@ -183,9 +188,9 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ while((rc = libssh2_userauth_password(session, username, password)) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -196,7 +201,7 @@ int main(int argc, char *argv[]) password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -206,7 +211,7 @@ int main(int argc, char *argv[]) sftp_session = libssh2_sftp_init(session); if(!sftp_session && - (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { + libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { fprintf(stderr, "Unable to init SFTP session\n"); goto shutdown; } @@ -215,23 +220,24 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open()!\n"); /* Request a file via SFTP */ do { - sftp_handle = - libssh2_sftp_open(sftp_session, sftppath, - LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT| - LIBSSH2_FXF_TRUNC, - LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| - LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); + sftp_handle = libssh2_sftp_open(sftp_session, sftppath, + LIBSSH2_FXF_WRITE | + LIBSSH2_FXF_CREAT | + LIBSSH2_FXF_TRUNC, + LIBSSH2_SFTP_S_IRUSR | + LIBSSH2_SFTP_S_IWUSR | + LIBSSH2_SFTP_S_IRGRP | + LIBSSH2_SFTP_S_IROTH); if(!sftp_handle && - (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { - fprintf(stderr, "Unable to open file with SFTP\n"); + libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { + fprintf(stderr, "Unable to open file with SFTP: %ld\n", + libssh2_sftp_last_error(sftp_session)); goto shutdown; } } while(!sftp_handle); fprintf(stderr, "libssh2_sftp_open() is done, now send data!\n"); - start = time(NULL); - do { nread = fread(mem, 1, sizeof(mem), local); if(nread <= 0) { @@ -245,18 +251,17 @@ int main(int argc, char *argv[]) do { /* write data in a loop until we block */ while((nwritten = libssh2_sftp_write(sftp_handle, ptr, nread)) == - LIBSSH2_ERROR_EAGAIN) { + LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } if(nwritten < 0) break; ptr += nwritten; nread -= nwritten; - } while(nread); } while(nwritten > 0); - duration = (int)(time(NULL)-start); + duration = (int)(time(NULL) - start); fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n", (long)total, duration, (double)total / duration); @@ -267,15 +272,20 @@ int main(int argc, char *argv[]) shutdown: - while(libssh2_session_disconnect(session, "Normal Shutdown") - == LIBSSH2_ERROR_EAGAIN); - libssh2_session_free(session); + if(session) { + while(libssh2_session_disconnect(session, "Normal Shutdown") == + LIBSSH2_ERROR_EAGAIN); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 1e8ffbefaf..15cca39c72 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * "sftp 192.168.0.1 user password file /tmp/storehere" + * $ ./sftp_write_sliding 192.168.0.1 user password thisfile /tmp/storehere */ #include "libssh2_setup.h" @@ -37,6 +37,13 @@ #include #include +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *loclfile = "sftp_write_nonblock.c"; +static const char *sftppath = "/tmp/sftp_write_nonblock.c"; + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; @@ -74,32 +81,25 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *loclfile = "sftp_write_nonblock.c"; - const char *sftppath = "/tmp/sftp_write_nonblock.c"; int rc; - FILE *local; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; + FILE *local; char mem[1024 * 1000]; size_t nread; - size_t memuse; ssize_t nwritten; + size_t memuse; time_t start; libssh2_struct_stat_size total = 0; int duration; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { fprintf(stderr, "Can't open local file %s\n", loclfile); - return -1; + return 1; } /* @@ -140,20 +140,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are non-blocking */ libssh2_session_set_blocking(session, 0); @@ -161,11 +166,11 @@ int main(int argc, char *argv[]) /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers */ - while((rc = libssh2_session_handshake(session, sock)) - == LIBSSH2_ERROR_EAGAIN); + while((rc = libssh2_session_handshake(session, sock)) == + LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -183,9 +188,9 @@ int main(int argc, char *argv[]) if(auth_pw) { /* We could authenticate via password */ while((rc = libssh2_userauth_password(session, username, password)) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -196,7 +201,7 @@ int main(int argc, char *argv[]) password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -206,7 +211,7 @@ int main(int argc, char *argv[]) sftp_session = libssh2_sftp_init(session); if(!sftp_session && - (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { + libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { fprintf(stderr, "Unable to init SFTP session\n"); goto shutdown; } @@ -215,26 +220,27 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_open()!\n"); /* Request a file via SFTP */ do { - sftp_handle = - libssh2_sftp_open(sftp_session, sftppath, - LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT| - LIBSSH2_FXF_TRUNC, - LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| - LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); + sftp_handle = libssh2_sftp_open(sftp_session, sftppath, + LIBSSH2_FXF_WRITE | + LIBSSH2_FXF_CREAT | + LIBSSH2_FXF_TRUNC, + LIBSSH2_SFTP_S_IRUSR | + LIBSSH2_SFTP_S_IWUSR | + LIBSSH2_SFTP_S_IRGRP | + LIBSSH2_SFTP_S_IROTH); if(!sftp_handle && - (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { - fprintf(stderr, "Unable to open file with SFTP\n"); + libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { + fprintf(stderr, "Unable to open file with SFTP: %ld\n", + libssh2_sftp_last_error(sftp_session)); goto shutdown; } } while(!sftp_handle); fprintf(stderr, "libssh2_sftp_open() is done, now send data!\n"); - start = time(NULL); - - memuse = 0; /* it starts blank */ + memuse = 0; /* it starts blank */ do { - nread = fread(&mem[memuse], 1, sizeof(mem)-memuse, local); + nread = fread(&mem[memuse], 1, sizeof(mem) - memuse, local); if(nread <= 0) { /* end of file */ if(memuse > 0) @@ -248,7 +254,7 @@ int main(int argc, char *argv[]) /* write data in a loop until we block */ while((nwritten = libssh2_sftp_write(sftp_handle, mem, memuse)) == - LIBSSH2_ERROR_EAGAIN) { + LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } if(nwritten < 0) @@ -265,7 +271,7 @@ int main(int argc, char *argv[]) } while(nwritten > 0); - duration = (int)(time(NULL)-start); + duration = (int)(time(NULL) - start); fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n", (long)total, duration, (double)total / duration); @@ -276,15 +282,20 @@ int main(int argc, char *argv[]) shutdown: - while(libssh2_session_disconnect(session, "Normal Shutdown") - == LIBSSH2_ERROR_EAGAIN); - libssh2_session_free(session); + if(session) { + while(libssh2_session_disconnect(session, "Normal Shutdown") == + LIBSSH2_ERROR_EAGAIN); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftpdir.c b/example/sftpdir.c index 94190cdf6e..655db52588 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password and * path, but you can specify them on the command line like: * - * "sftpdir 192.168.0.1 user password /tmp/secretdir" + * $ ./sftpdir 192.168.0.1 user password /tmp/secretdir */ #include "libssh2_setup.h" @@ -23,9 +23,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_INTTYPES_H -#include -#endif #include #include @@ -43,6 +40,7 @@ static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; static const char *username = "username"; static const char *password = "password"; +static const char *sftppath = "/tmp/secretdir"; static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, @@ -67,22 +65,21 @@ int main(int argc, char *argv[]) { uint32_t hostaddr; libssh2_socket_t sock; - int rc, i, auth_pw = 0; + int i, auth_pw = 0; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; - LIBSSH2_SESSION *session; - const char *sftppath = "/tmp/secretdir"; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -104,7 +101,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -114,20 +111,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers @@ -135,7 +137,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -153,69 +155,68 @@ int main(int argc, char *argv[]) /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - fprintf(stderr, "Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "password") != NULL) { - auth_pw |= 1; - } - if(strstr(userauthlist, "keyboard-interactive") != NULL) { - auth_pw |= 2; - } - if(strstr(userauthlist, "publickey") != NULL) { - auth_pw |= 4; - } - - /* if we got an 5. argument we set this option if supported */ - if(argc > 5) { - if((auth_pw & 1) && !strcmp(argv[5], "-p")) { - auth_pw = 1; + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(strstr(userauthlist, "password")) { + auth_pw |= 1; } - if((auth_pw & 2) && !strcmp(argv[5], "-i")) { - auth_pw = 2; + if(strstr(userauthlist, "keyboard-interactive")) { + auth_pw |= 2; } - if((auth_pw & 4) && !strcmp(argv[5], "-k")) { - auth_pw = 4; + if(strstr(userauthlist, "publickey")) { + auth_pw |= 4; } - } - if(auth_pw & 1) { - /* We could authenticate via password */ - if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "\tAuthentication by password failed!\n"); - goto shutdown; - } - else { - fprintf(stderr, "\tAuthentication by password succeeded.\n"); + /* check for options */ + if(argc > 5) { + if((auth_pw & 1) && !strcmp(argv[5], "-p")) { + auth_pw = 1; + } + if((auth_pw & 2) && !strcmp(argv[5], "-i")) { + auth_pw = 2; + } + if((auth_pw & 4) && !strcmp(argv[5], "-k")) { + auth_pw = 4; + } } - } - else if(auth_pw & 2) { - /* Or via keyboard-interactive */ - if(libssh2_userauth_keyboard_interactive(session, username, - &kbd_callback) ) { - fprintf(stderr, - "\tAuthentication by keyboard-interactive failed!\n"); - goto shutdown; + + if(auth_pw & 1) { + /* We could authenticate via password */ + if(libssh2_userauth_password(session, username, password)) { + fprintf(stderr, "Authentication by password failed!\n"); + goto shutdown; + } } - else { - fprintf(stderr, - "\tAuthentication by keyboard-interactive succeeded.\n"); + else if(auth_pw & 2) { + /* Or via keyboard-interactive */ + if(libssh2_userauth_keyboard_interactive(session, username, + &kbd_callback) ) { + fprintf(stderr, + "Authentication by keyboard-interactive failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, + "Authentication by keyboard-interactive succeeded.\n"); + } } - } - else if(auth_pw & 4) { - /* Or by public key */ - if(libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) { - fprintf(stderr, "\tAuthentication by public key failed!\n"); - goto shutdown; + else if(auth_pw & 4) { + /* Or by public key */ + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { + fprintf(stderr, "Authentication by public key failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by public key succeeded.\n"); + } } else { - fprintf(stderr, "\tAuthentication by public key succeeded.\n"); + fprintf(stderr, "No supported authentication methods found!\n"); + goto shutdown; } } - else { - fprintf(stderr, "No supported authentication methods found!\n"); - goto shutdown; - } fprintf(stderr, "libssh2_sftp_init()!\n"); sftp_session = libssh2_sftp_init(session); @@ -231,11 +232,11 @@ int main(int argc, char *argv[]) fprintf(stderr, "libssh2_sftp_opendir()!\n"); /* Request a dir listing via SFTP */ sftp_handle = libssh2_sftp_opendir(sftp_session, sftppath); - if(!sftp_handle) { fprintf(stderr, "Unable to open dir with SFTP\n"); goto shutdown; } + fprintf(stderr, "libssh2_sftp_opendir() is done, now receive listing!\n"); do { char mem[512]; @@ -287,14 +288,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 976dea47c5..8237f6a7a5 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -4,7 +4,7 @@ * The sample code has default values for host name, user name, password and * path, but you can specify them on the command line like: * - * "sftpdir 192.168.0.1 user password /tmp/secretdir" + * $ ./sftpdir_nonblock 192.168.0.1 user password /tmp/secretdir */ #include "libssh2_setup.h" @@ -23,9 +23,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_INTTYPES_H -#include -#endif #include #include @@ -39,6 +36,12 @@ #define __FILESIZE "llu" #endif +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "username"; +static const char *password = "password"; +static const char *sftppath = "/tmp/secretdir"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -46,23 +49,17 @@ int main(int argc, char *argv[]) int i, auth_pw = 1; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "username"; - const char *password = "password"; - const char *sftppath = "/tmp/secretdir"; int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -84,7 +81,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -94,20 +91,25 @@ int main(int argc, char *argv[]) * and establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } - /* Create a session instance - */ + /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* Since we have set non-blocking, tell libssh2 we are non-blocking */ libssh2_session_set_blocking(session, 0); @@ -119,7 +121,7 @@ int main(int argc, char *argv[]) LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -139,7 +141,7 @@ int main(int argc, char *argv[]) while((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -150,7 +152,7 @@ int main(int argc, char *argv[]) password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -159,8 +161,8 @@ int main(int argc, char *argv[]) do { sftp_session = libssh2_sftp_init(session); - if((!sftp_session) && (libssh2_session_last_errno(session) != - LIBSSH2_ERROR_EAGAIN)) { + if(!sftp_session && + libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { fprintf(stderr, "Unable to init SFTP session\n"); goto shutdown; } @@ -171,8 +173,8 @@ int main(int argc, char *argv[]) do { sftp_handle = libssh2_sftp_opendir(sftp_session, sftppath); - if((!sftp_handle) && (libssh2_session_last_errno(session) != - LIBSSH2_ERROR_EAGAIN)) { + if(!sftp_handle && + libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { fprintf(stderr, "Unable to open dir with SFTP\n"); goto shutdown; } @@ -227,14 +229,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/ssh2.c b/example/ssh2.c index a762d7056e..52444b7b86 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -4,7 +4,8 @@ * The sample code has default values for host name, user name, password * and path to copy, but you can specify them on the command line like: * - * Usage: ssh2 hostip user password [[-p|-i|-k] [command]] + * $ ./ssh2 hostip user password [[-p|-i|-k] [command]] + * * -p authenticate using password * -i authenticate using keyboard-interactive * -k authenticate using public key (password argument decrypts keyfile) @@ -13,7 +14,6 @@ #include "libssh2_setup.h" #include -#include #ifdef HAVE_SYS_SOCKET_H #include @@ -67,18 +67,19 @@ int main(int argc, char *argv[]) { uint32_t hostaddr; libssh2_socket_t sock; - int rc, i, auth_pw = 0; + int i, auth_pw = 0; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; #ifdef WIN32 WSADATA wsadata; rc = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(rc != 0) { + if(rc) { fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } @@ -98,7 +99,7 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -107,6 +108,11 @@ int main(int argc, char *argv[]) * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + rc = 1; + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); @@ -117,29 +123,25 @@ int main(int argc, char *argv[]) if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } /* Create a session instance and start it up. This will trade welcome * banners, exchange keys, and setup crypto, compression, and MAC layers */ session = libssh2_session_init(); + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } + /* Enable all debugging when libssh2 was built with debugging enabled */ - libssh2_trace(session, - LIBSSH2_TRACE_TRANS | - LIBSSH2_TRACE_KEX | - LIBSSH2_TRACE_AUTH | - LIBSSH2_TRACE_CONN | - LIBSSH2_TRACE_SCP | - LIBSSH2_TRACE_SFTP | - LIBSSH2_TRACE_ERROR | - LIBSSH2_TRACE_PUBLICKEY | - LIBSSH2_TRACE_SOCKET - ); - - if(libssh2_session_handshake(session, sock)) { - fprintf(stderr, "Failure establishing SSH session\n"); - return -1; + libssh2_trace(session, ~0); + + rc = libssh2_session_handshake(session, sock); + if(rc) { + fprintf(stderr, "Failure establishing SSH session: %d\n", rc); + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -157,91 +159,94 @@ int main(int argc, char *argv[]) /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - fprintf(stderr, "Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "password") != NULL) { - auth_pw |= 1; - } - if(strstr(userauthlist, "keyboard-interactive") != NULL) { - auth_pw |= 2; - } - if(strstr(userauthlist, "publickey") != NULL) { - auth_pw |= 4; - } - - /* if we got an 4. argument we set this option if supported */ - if(argc > 4) { - if((auth_pw & 1) && !strcmp(argv[4], "-p")) { - auth_pw = 1; + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(strstr(userauthlist, "password")) { + auth_pw |= 1; } - if((auth_pw & 2) && !strcmp(argv[4], "-i")) { - auth_pw = 2; + if(strstr(userauthlist, "keyboard-interactive")) { + auth_pw |= 2; } - if((auth_pw & 4) && !strcmp(argv[4], "-k")) { - auth_pw = 4; + if(strstr(userauthlist, "publickey")) { + auth_pw |= 4; } - } - if(auth_pw & 1) { - /* We could authenticate via password */ - if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "\tAuthentication by password failed!\n"); - goto shutdown; - } - else { - fprintf(stderr, "\tAuthentication by password succeeded.\n"); - } - } - else if(auth_pw & 2) { - /* Or via keyboard-interactive */ - if(libssh2_userauth_keyboard_interactive(session, username, - &kbd_callback) ) { - fprintf(stderr, - "\tAuthentication by keyboard-interactive failed!\n"); - goto shutdown; + /* check for options */ + if(argc > 4) { + if((auth_pw & 1) && !strcmp(argv[4], "-p")) { + auth_pw = 1; + } + if((auth_pw & 2) && !strcmp(argv[4], "-i")) { + auth_pw = 2; + } + if((auth_pw & 4) && !strcmp(argv[4], "-k")) { + auth_pw = 4; + } } - else { - fprintf(stderr, - "\tAuthentication by keyboard-interactive succeeded.\n"); + + if(auth_pw & 1) { + /* We could authenticate via password */ + if(libssh2_userauth_password(session, username, password)) { + fprintf(stderr, "Authentication by password failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by password succeeded.\n"); + } } - } - else if(auth_pw & 4) { - /* Or by public key */ - size_t fn1sz, fn2sz; - char *fn1, *fn2; - char const *h = getenv("HOME"); - if(!h || !*h) - h = "."; - fn1sz = strlen(h) + strlen(pubkey) + 2; - fn2sz = strlen(h) + strlen(privkey) + 2; - fn1 = malloc(fn1sz); - fn2 = malloc(fn2sz); - if(!fn1 || !fn2) { - free(fn2); - free(fn1); - fprintf(stderr, "out of memory\n"); - goto shutdown; + else if(auth_pw & 2) { + /* Or via keyboard-interactive */ + if(libssh2_userauth_keyboard_interactive(session, username, + &kbd_callback) ) { + fprintf(stderr, + "Authentication by keyboard-interactive failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, + "Authentication by keyboard-interactive succeeded.\n"); + } } - /* Using asprintf() here would be much cleaner, but less portable */ - snprintf(fn1, fn1sz, "%s/%s", h, pubkey); - snprintf(fn2, fn2sz, "%s/%s", h, privkey); - - if(libssh2_userauth_publickey_fromfile(session, username, - fn1, fn2, - password)) { - fprintf(stderr, "\tAuthentication by public key failed!\n"); + else if(auth_pw & 4) { + /* Or by public key */ + size_t fn1sz, fn2sz; + char *fn1, *fn2; + char const *h = getenv("HOME"); + if(!h || !*h) + h = "."; + fn1sz = strlen(h) + strlen(pubkey) + 2; + fn2sz = strlen(h) + strlen(privkey) + 2; + fn1 = malloc(fn1sz); + fn2 = malloc(fn2sz); + if(!fn1 || !fn2) { + free(fn2); + free(fn1); + fprintf(stderr, "out of memory\n"); + goto shutdown; + } + /* Using asprintf() here would be much cleaner, + but less portable */ + snprintf(fn1, fn1sz, "%s/%s", h, pubkey); + snprintf(fn2, fn2sz, "%s/%s", h, privkey); + + if(libssh2_userauth_publickey_fromfile(session, username, + fn1, fn2, + password)) { + fprintf(stderr, "Authentication by public key failed!\n"); + free(fn2); + free(fn1); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by public key succeeded.\n"); + } free(fn2); free(fn1); - goto shutdown; } else { - fprintf(stderr, "\tAuthentication by public key succeeded.\n"); + fprintf(stderr, "No supported authentication methods found!\n"); + goto shutdown; } - free(fn2); - free(fn1); - } - else { - fprintf(stderr, "No supported authentication methods found!\n"); - goto shutdown; } /* Request a session channel on which to run a shell */ @@ -331,14 +336,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 5e3a82f3cf..3bf66e479e 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -3,12 +3,11 @@ * * The sample code has default values for host name, user name: * - * "ssh2_agent host user" + * $ ./ssh2_agent host user */ #include "libssh2_setup.h" #include -#include #ifdef HAVE_SYS_SOCKET_H #include @@ -35,11 +34,12 @@ static const char *username = "username"; int main(int argc, char *argv[]) { uint32_t hostaddr; - libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; - int i, rc; + libssh2_socket_t sock; + int i; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; + int rc; LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; LIBSSH2_AGENT *agent = NULL; @@ -47,11 +47,10 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -62,13 +61,12 @@ int main(int argc, char *argv[]) else { hostaddr = htonl(0x7F000001); } - if(argc > 2) { username = argv[2]; } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -91,13 +89,17 @@ int main(int argc, char *argv[]) goto shutdown; } - /* Create a session instance and start it up. This will trade welcome - * banners, exchange keys, and setup crypto, compression, and MAC layers - */ + /* Create a session instance */ session = libssh2_session_init(); - if(libssh2_session_handshake(session, sock)) { - fprintf(stderr, "Failure establishing SSH session\n"); - return 1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } + + rc = libssh2_session_handshake(session, sock); + if(rc) { + fprintf(stderr, "Failure establishing SSH session: %d\n", rc); + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -115,55 +117,57 @@ int main(int argc, char *argv[]) /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - fprintf(stderr, "Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "publickey") == NULL) { - fprintf(stderr, "\"publickey\" authentication is not supported\n"); - goto shutdown; - } + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(!strstr(userauthlist, "publickey")) { + fprintf(stderr, "\"publickey\" authentication is not supported\n"); + goto shutdown; + } - /* Connect to the ssh-agent */ - agent = libssh2_agent_init(session); - if(!agent) { - fprintf(stderr, "Failure initializing ssh-agent support\n"); - rc = 1; - goto shutdown; - } - if(libssh2_agent_connect(agent)) { - fprintf(stderr, "Failure connecting to ssh-agent\n"); - rc = 1; - goto shutdown; - } - if(libssh2_agent_list_identities(agent)) { - fprintf(stderr, "Failure requesting identities to ssh-agent\n"); - rc = 1; - goto shutdown; - } - for(;;) { - rc = libssh2_agent_get_identity(agent, &identity, prev_identity); - if(rc == 1) - break; - if(rc < 0) { - fprintf(stderr, - "Failure obtaining identity from ssh-agent support\n"); + /* Connect to the ssh-agent */ + agent = libssh2_agent_init(session); + if(!agent) { + fprintf(stderr, "Failure initializing ssh-agent support\n"); rc = 1; goto shutdown; } - if(libssh2_agent_userauth(agent, username, identity)) { - fprintf(stderr, "\tAuthentication with username %s and " - "public key %s failed!\n", - username, identity->comment); + if(libssh2_agent_connect(agent)) { + fprintf(stderr, "Failure connecting to ssh-agent\n"); + rc = 1; + goto shutdown; } - else { - fprintf(stderr, "\tAuthentication with username %s and " - "public key %s succeeded!\n", - username, identity->comment); - break; + if(libssh2_agent_list_identities(agent)) { + fprintf(stderr, "Failure requesting identities to ssh-agent\n"); + rc = 1; + goto shutdown; + } + for(;;) { + rc = libssh2_agent_get_identity(agent, &identity, prev_identity); + if(rc == 1) + break; + if(rc < 0) { + fprintf(stderr, + "Failure obtaining identity from ssh-agent support\n"); + rc = 1; + goto shutdown; + } + if(libssh2_agent_userauth(agent, username, identity)) { + fprintf(stderr, "Authentication with username %s and " + "public key %s failed!\n", + username, identity->comment); + } + else { + fprintf(stderr, "Authentication with username %s and " + "public key %s succeeded.\n", + username, identity->comment); + break; + } + prev_identity = identity; + } + if(rc) { + fprintf(stderr, "Couldn't continue authentication\n"); + goto shutdown; } - prev_identity = identity; - } - if(rc) { - fprintf(stderr, "Couldn't continue authentication\n"); - goto shutdown; } /* We're authenticated now. */ @@ -181,7 +185,8 @@ int main(int argc, char *argv[]) libssh2_channel_setenv(channel, "FOO", "bar"); /* Request a terminal with 'vanilla' terminal emulation - * See /etc/termcap for more options + * See /etc/termcap for more options. This is useful when opening + * an interactive shell. */ if(libssh2_channel_request_pty(channel, "vanilla")) { fprintf(stderr, "Failed requesting pty\n"); @@ -208,6 +213,7 @@ int main(int argc, char *argv[]) */ skip_shell: + if(channel) { libssh2_channel_free(channel); channel = NULL; diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 0a03113df2..3583daaa5f 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -7,8 +7,6 @@ * The example uses agent authentication to ensure an agent to forward * is running. * - * Run it like this: - * * $ ./ssh2_agent_forwarding 127.0.0.1 user "uptime" * */ @@ -42,6 +40,10 @@ #include #include +static const char *hostname = "127.0.0.1"; +static const char *commandline = "uptime"; +static const char *username; + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; @@ -74,25 +76,28 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { - const char *hostname = "127.0.0.1"; - const char *commandline = "uptime"; - const char *username = NULL; uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; LIBSSH2_AGENT *agent = NULL; struct libssh2_agent_publickey *identity, *prev_identity = NULL; - int rc; int exitcode; char *exitsignal = (char *)"none"; ssize_t bytecount = 0; #ifdef WIN32 WSADATA wsadata; - WSAStartup(MAKEWORD(2, 0), &wsadata); + + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); + return 1; + } #endif + if(argc < 2) { fprintf(stderr, "At least IP and username arguments are required.\n"); return 1; @@ -106,35 +111,40 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } hostaddr = inet_addr(hostname); - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } if(libssh2_session_handshake(session, sock) != 0) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } /* Connect to the ssh-agent */ @@ -165,14 +175,14 @@ int main(int argc, char *argv[]) goto shutdown; } if(libssh2_agent_userauth(agent, username, identity)) { - fprintf(stderr, "\tAuthentication with username %s and " - "public key %s failed!\n", - username, identity->comment); + fprintf(stderr, "Authentication with username %s and " + "public key %s failed!\n", + username, identity->comment); } else { - fprintf(stderr, "\tAuthentication with username %s and " - "public key %s succeeded!\n", - username, identity->comment); + fprintf(stderr, "Authentication with username %s and " + "public key %s succeeded.\n", + username, identity->comment); break; } prev_identity = identity; @@ -189,13 +199,16 @@ int main(int argc, char *argv[]) /* Set session to non-blocking */ libssh2_session_set_blocking(session, 0); - /* Exec non-blocking on the remove host */ - while((channel = libssh2_channel_open_session(session)) == NULL && - libssh2_session_last_error(session, NULL, NULL, 0) == - LIBSSH2_ERROR_EAGAIN) { + /* Exec non-blocking on the remote host */ + do { + channel = libssh2_channel_open_session(session); + if(channel || + libssh2_session_last_error(session, NULL, NULL, 0) != + LIBSSH2_ERROR_EAGAIN) + break; waitsocket(sock, session); - } - if(channel == NULL) { + } while(1); + if(!channel) { fprintf(stderr, "Error\n"); exit(1); } @@ -203,19 +216,19 @@ int main(int argc, char *argv[]) LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } - if(rc != 0) { + if(rc) { fprintf(stderr, "Error, couldn't request auth agent, error code %d.\n", rc); exit(1); } else { - fprintf(stdout, "\tAgent forwarding request succeeded!\n"); + fprintf(stdout, "Agent forwarding request succeeded!\n"); } while((rc = libssh2_channel_exec(channel, commandline)) == LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } - if(rc != 0) { + if(rc) { fprintf(stderr, "Error\n"); exit(1); } @@ -261,10 +274,11 @@ int main(int argc, char *argv[]) } if(exitsignal) { - printf("\nGot signal: %s\n", exitsignal); + fprintf(stderr, "\nGot signal: %s\n", exitsignal); } else { - printf("\nEXIT: %d bytecount: %d\n", exitcode, (int)bytecount); + fprintf(stderr, "\nEXIT: %d bytecount: %d\n", + exitcode, (int)bytecount); } libssh2_channel_free(channel); @@ -272,14 +286,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index e4972b8d01..f918a1cc80 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -1,11 +1,9 @@ /* - * Run it like this: - * - * $ ./ssh2_echo 127.0.0.1 user password - * * The code sends a 'cat' command, and then writes a lot of data to it only to * check that reading the returned data sums up to the same amount. * + * $ ./ssh2_echo 127.0.0.1 user password + * */ #include "libssh2_setup.h" @@ -37,6 +35,11 @@ #include #include +static const char *hostname = "127.0.0.1"; +static const char *commandline = "cat"; +static const char *username = "user"; +static const char *password = "password"; + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; @@ -71,17 +74,13 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { - const char *hostname = "127.0.0.1"; - const char *commandline = "cat"; - const char *username = "user"; - const char *password = "password"; uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - LIBSSH2_CHANNEL *channel; int rc; + LIBSSH2_SESSION *session = NULL; + LIBSSH2_CHANNEL *channel; int exitcode = 0; char *exitsignal = (char *)"none"; size_t len; @@ -90,11 +89,10 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -110,31 +108,36 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } hostaddr = inet_addr(hostname); - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* tell libssh2 we want it all done non-blocking */ libssh2_session_set_blocking(session, 0); @@ -146,7 +149,7 @@ int main(int argc, char *argv[]) LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } nh = libssh2_knownhost_init(session); @@ -173,8 +176,8 @@ int main(int argc, char *argv[]) &host); fprintf(stderr, "Host check: %d, key: %s\n", check, - (check <= LIBSSH2_KNOWNHOST_CHECK_MISMATCH)? - host->key:""); + (check <= LIBSSH2_KNOWNHOST_CHECK_MISMATCH) ? + host->key : ""); /***** * At this point, we could verify that 'check' tells us the key is @@ -192,28 +195,31 @@ int main(int argc, char *argv[]) while((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); exit(1); } } libssh2_trace(session, LIBSSH2_TRACE_SOCKET); - /* Exec non-blocking on the remove host */ - while((channel = libssh2_channel_open_session(session)) == NULL && - libssh2_session_last_error(session, NULL, NULL, 0) == - LIBSSH2_ERROR_EAGAIN) { + /* Exec non-blocking on the remote host */ + do { + channel = libssh2_channel_open_session(session); + if(channel || + libssh2_session_last_error(session, NULL, NULL, 0) != + LIBSSH2_ERROR_EAGAIN) + break; waitsocket(sock, session); - } - if(channel == NULL) { + } while(1); + if(!channel) { fprintf(stderr, "Error\n"); exit(1); } while((rc = libssh2_channel_exec(channel, commandline)) == - LIBSSH2_ERROR_EAGAIN) + LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); - - if(rc != 0) { + } + if(rc) { fprintf(stderr, "exec error\n"); exit(1); } @@ -244,7 +250,7 @@ int main(int argc, char *argv[]) do { int act = 0; - rc = (libssh2_poll(fds, 1, 10)); + rc = libssh2_poll(fds, 1, 10); if(rc < 1) continue; @@ -348,14 +354,21 @@ int main(int argc, char *argv[]) } } - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); +shutdown: + + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index f672322dfd..4c368bf3a0 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -4,8 +4,6 @@ * The sample code has fixed values for host name, user name, password * and command to run. * - * Run it like this: - * * $ ./ssh2_exec 127.0.0.1 user password "uptime" * */ @@ -39,6 +37,13 @@ #include #include +static const char *hostname = "127.0.0.1"; +static const char *commandline = "uptime"; +static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; +static const char *privkey = "/home/username/.ssh/id_rsa"; +static const char *username = "user"; +static const char *password = "password"; + static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; @@ -71,19 +76,13 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) int main(int argc, char *argv[]) { - const char *hostname = "127.0.0.1"; - const char *commandline = "uptime"; - const char *pubkey = "/home/username/.ssh/id_rsa.pub"; - const char *privkey = "/home/username/.ssh/id_rsa"; - const char *username = "user"; - const char *password = "password"; uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; const char *fingerprint; - LIBSSH2_SESSION *session; - LIBSSH2_CHANNEL *channel; int rc; + LIBSSH2_SESSION *session = NULL; + LIBSSH2_CHANNEL *channel; int exitcode; char *exitsignal = (char *)"none"; ssize_t bytecount = 0; @@ -93,11 +92,10 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -116,31 +114,36 @@ int main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } hostaddr = inet_addr(hostname); - /* Ultra basic "connect to port 22 on localhost" - * Your code is responsible for creating the socket establishing the - * connection + /* Ultra basic "connect to port 22 on localhost". Your code is + * responsible for creating the socket establishing the connection */ sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } sin.sin_family = AF_INET; sin.sin_port = htons(22); sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); - if(!session) - return -1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } /* tell libssh2 we want it all done non-blocking */ libssh2_session_set_blocking(session, 0); @@ -152,7 +155,7 @@ int main(int argc, char *argv[]) LIBSSH2_ERROR_EAGAIN); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); - return -1; + goto shutdown; } nh = libssh2_knownhost_init(session); @@ -177,9 +180,10 @@ int main(int argc, char *argv[]) LIBSSH2_KNOWNHOST_TYPE_PLAIN| LIBSSH2_KNOWNHOST_KEYENC_RAW, &host); + fprintf(stderr, "Host check: %d, key: %s\n", check, - (check <= LIBSSH2_KNOWNHOST_CHECK_MISMATCH)? - host->key:""); + (check <= LIBSSH2_KNOWNHOST_CHECK_MISMATCH) ? + host->key : ""); /***** * At this point, we could verify that 'check' tells us the key is @@ -195,9 +199,9 @@ int main(int argc, char *argv[]) if(strlen(password) != 0) { /* We could authenticate via password */ while((rc = libssh2_userauth_password(session, username, password)) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "Authentication by password failed.\n"); + fprintf(stderr, "Authentication by password failed!\n"); goto shutdown; } } @@ -206,9 +210,9 @@ int main(int argc, char *argv[]) while((rc = libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); if(rc) { - fprintf(stderr, "\tAuthentication by public key failed\n"); + fprintf(stderr, "Authentication by public key failed!\n"); goto shutdown; } } @@ -217,13 +221,16 @@ int main(int argc, char *argv[]) libssh2_trace(session, ~0); #endif - /* Exec non-blocking on the remove host */ - while((channel = libssh2_channel_open_session(session)) == NULL && - libssh2_session_last_error(session, NULL, NULL, 0) == - LIBSSH2_ERROR_EAGAIN) { + /* Exec non-blocking on the remote host */ + do { + channel = libssh2_channel_open_session(session); + if(channel || + libssh2_session_last_error(session, NULL, NULL, 0) != + LIBSSH2_ERROR_EAGAIN) + break; waitsocket(sock, session); - } - if(channel == NULL) { + } while(1); + if(!channel) { fprintf(stderr, "Error\n"); exit(1); } @@ -231,7 +238,7 @@ int main(int argc, char *argv[]) LIBSSH2_ERROR_EAGAIN) { waitsocket(sock, session); } - if(rc != 0) { + if(rc) { fprintf(stderr, "exec error\n"); exit(1); } @@ -287,14 +294,19 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } + fprintf(stderr, "all done\n"); libssh2_exit(); diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index fef9f926e7..fd24039fea 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -4,9 +4,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -16,9 +13,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include @@ -44,8 +38,8 @@ static const char *server_ip = "127.0.0.1"; enum { AUTH_NONE = 0, - AUTH_PASSWORD, - AUTH_PUBLICKEY + AUTH_PASSWORD = 1, + AUTH_PUBLICKEY = 2 }; static int netconf_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t len) @@ -110,23 +104,23 @@ static ssize_t netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag, int main(int argc, char *argv[]) { - int rc, i, auth = AUTH_NONE; + int i, auth = AUTH_NONE; struct sockaddr_in sin; const char *fingerprint; char *userauthlist; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel = NULL; char buf[1048576]; /* avoid any buffer reallocation for simplicity */ ssize_t len; - libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; + libssh2_socket_t sock; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -139,7 +133,7 @@ int main(int argc, char *argv[]) password = argv[3]; rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -148,26 +142,26 @@ int main(int argc, char *argv[]) sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "failed to open socket!\n"); - return -1; + goto shutdown; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); if(INADDR_NONE == sin.sin_addr.s_addr) { fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip); - return -1; + goto shutdown; } sin.sin_port = htons(830); if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "Failed to connect to %s!\n", inet_ntoa(sin.sin_addr)); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); if(!session) { fprintf(stderr, "Could not initialize SSH session!\n"); - return -1; + goto shutdown; } /* ... start it up. This will trade welcome banners, exchange keys, @@ -176,7 +170,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Error when starting up SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -193,54 +187,58 @@ int main(int argc, char *argv[]) /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - fprintf(stderr, "Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "password")) - auth |= AUTH_PASSWORD; - if(strstr(userauthlist, "publickey")) - auth |= AUTH_PUBLICKEY; - - /* check for options */ - if(argc > 4) { - if((auth & AUTH_PASSWORD) && !strcmp(argv[4], "-p")) - auth = AUTH_PASSWORD; - if((auth & AUTH_PUBLICKEY) && !strcmp(argv[4], "-k")) - auth = AUTH_PUBLICKEY; - } + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(strstr(userauthlist, "password")) + auth |= AUTH_PASSWORD; + if(strstr(userauthlist, "publickey")) + auth |= AUTH_PUBLICKEY; + + /* check for options */ + if(argc > 4) { + if((auth & AUTH_PASSWORD) && !strcmp(argv[4], "-p")) + auth = AUTH_PASSWORD; + if((auth & AUTH_PUBLICKEY) && !strcmp(argv[4], "-k")) + auth = AUTH_PUBLICKEY; + } - if(auth & AUTH_PASSWORD) { - if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); - goto shutdown; + if(auth & AUTH_PASSWORD) { + if(libssh2_userauth_password(session, username, password)) { + fprintf(stderr, "Authentication by password failed!\n"); + goto shutdown; + } } - } - else if(auth & AUTH_PUBLICKEY) { - if(libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) { - fprintf(stderr, "\tAuthentication by public key failed!\n"); + else if(auth & AUTH_PUBLICKEY) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { + fprintf(stderr, "Authentication by public key failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by public key succeeded.\n"); + } + } + else { + fprintf(stderr, "No supported authentication methods found!\n"); goto shutdown; } - fprintf(stderr, "\tAuthentication by public key succeeded.\n"); - } - else { - fprintf(stderr, "No supported authentication methods found!\n"); - goto shutdown; } /* open a channel */ channel = libssh2_channel_open_session(session); if(!channel) { fprintf(stderr, "Could not open the channel!\n" - "(Note that this can be a problem at the server!" - " Please review the server logs.)\n"); + "(Note that this can be a problem at the server!" + " Please review the server logs.)\n"); goto shutdown; } /* execute the subsystem on our channel */ if(libssh2_channel_subsystem(channel, "netconf")) { fprintf(stderr, "Could not execute the \"netconf\" subsystem!\n" - "(Note that this can be a problem at the server!" - " Please review the server logs.)\n"); + "(Note that this can be a problem at the server!" + " Please review the server logs.)\n"); goto shutdown; } @@ -285,16 +283,22 @@ int main(int argc, char *argv[]) (int)len, buf); shutdown: + if(channel) libssh2_channel_free(channel); - libssh2_session_disconnect(session, "Client disconnecting normally"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } libssh2_exit(); diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 7925a02ba9..0fd7ca8f99 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -54,34 +54,34 @@ static int local_destport = 22; enum { AUTH_NONE = 0, - AUTH_PASSWORD, - AUTH_PUBLICKEY + AUTH_PASSWORD = 1, + AUTH_PUBLICKEY = 2 }; int main(int argc, char *argv[]) { - int rc, i, auth = AUTH_NONE; + int i, auth = AUTH_NONE; struct sockaddr_in sin; socklen_t sinlen = sizeof(sin); const char *fingerprint; char *userauthlist; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_LISTENER *listener = NULL; LIBSSH2_CHANNEL *channel = NULL; fd_set fds; struct timeval tv; ssize_t len, wr; char buf[16384]; - libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; + libssh2_socket_t sock; libssh2_socket_t forwardsock = LIBSSH2_INVALID_SOCKET; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); return 1; } #endif @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) local_destport = atoi(argv[7]); rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } @@ -111,26 +111,26 @@ int main(int argc, char *argv[]) sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock == LIBSSH2_INVALID_SOCKET) { fprintf(stderr, "failed to open socket!\n"); - return -1; + goto shutdown; } sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ip); if(INADDR_NONE == sin.sin_addr.s_addr) { fprintf(stderr, "inet_addr: Invalid IP address \"%s\"\n", server_ip); - return -1; + goto shutdown; } sin.sin_port = htons(22); if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "Failed to connect to %s!\n", inet_ntoa(sin.sin_addr)); - return -1; + goto shutdown; } /* Create a session instance */ session = libssh2_session_init(); if(!session) { fprintf(stderr, "Could not initialize SSH session!\n"); - return -1; + goto shutdown; } /* ... start it up. This will trade welcome banners, exchange keys, @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Error when starting up SSH session: %d\n", rc); - return -1; + goto shutdown; } /* At this point we have not yet authenticated. The first thing to do @@ -156,38 +156,42 @@ int main(int argc, char *argv[]) /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - fprintf(stderr, "Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "password")) - auth |= AUTH_PASSWORD; - if(strstr(userauthlist, "publickey")) - auth |= AUTH_PUBLICKEY; - - /* check for options */ - if(argc > 8) { - if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p")) - auth = AUTH_PASSWORD; - if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k")) - auth = AUTH_PUBLICKEY; - } + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(strstr(userauthlist, "password")) + auth |= AUTH_PASSWORD; + if(strstr(userauthlist, "publickey")) + auth |= AUTH_PUBLICKEY; + + /* check for options */ + if(argc > 8) { + if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p")) + auth = AUTH_PASSWORD; + if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k")) + auth = AUTH_PUBLICKEY; + } - if(auth & AUTH_PASSWORD) { - if(libssh2_userauth_password(session, username, password)) { - fprintf(stderr, "Authentication by password failed.\n"); - goto shutdown; + if(auth & AUTH_PASSWORD) { + if(libssh2_userauth_password(session, username, password)) { + fprintf(stderr, "Authentication by password failed!\n"); + goto shutdown; + } } - } - else if(auth & AUTH_PUBLICKEY) { - if(libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) { - fprintf(stderr, "\tAuthentication by public key failed!\n"); + else if(auth & AUTH_PUBLICKEY) { + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { + fprintf(stderr, "Authentication by public key failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by public key succeeded.\n"); + } + } + else { + fprintf(stderr, "No supported authentication methods found!\n"); goto shutdown; } - fprintf(stderr, "\tAuthentication by public key succeeded.\n"); - } - else { - fprintf(stderr, "No supported authentication methods found!\n"); - goto shutdown; } fprintf(stderr, "Asking server to listen on remote %s:%d\n", @@ -197,8 +201,8 @@ int main(int argc, char *argv[]) remote_wantport, &remote_listenport, 1); if(!listener) { fprintf(stderr, "Could not start the tcpip-forward listener!\n" - "(Note that this can be a problem at the server!" - " Please review the server logs.)\n"); + "(Note that this can be a problem at the server!" + " Please review the server logs.)\n"); goto shutdown; } @@ -209,8 +213,8 @@ int main(int argc, char *argv[]) channel = libssh2_channel_forward_accept(listener); if(!channel) { fprintf(stderr, "Could not accept connection!\n" - "(Note that this can be a problem at the server!" - " Please review the server logs.)\n"); + "(Note that this can be a problem at the server!" + " Please review the server logs.)\n"); goto shutdown; } @@ -227,11 +231,11 @@ int main(int argc, char *argv[]) sin.sin_port = htons((unsigned short)local_destport); sin.sin_addr.s_addr = inet_addr(local_destip); if(INADDR_NONE == sin.sin_addr.s_addr) { - perror("inet_addr"); + fprintf(stderr, "failed in inet_addr()!\n"); goto shutdown; } if(-1 == connect(forwardsock, (struct sockaddr *)&sin, sinlen)) { - perror("connect"); + fprintf(stderr, "failed to connect()!\n"); goto shutdown; } @@ -248,14 +252,14 @@ int main(int argc, char *argv[]) tv.tv_usec = 100000; rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv); if(-1 == rc) { - perror("select"); + fprintf(stderr, "failed to select()!\n"); goto shutdown; } if(rc && FD_ISSET(forwardsock, &fds)) { ssize_t nwritten; len = recv(forwardsock, buf, sizeof(buf), 0); if(len < 0) { - perror("read"); + fprintf(stderr, "failed to recv()!\n"); goto shutdown; } else if(0 == len) { @@ -288,7 +292,7 @@ int main(int argc, char *argv[]) while(wr < len) { nsent = send(forwardsock, buf + wr, len - wr, 0); if(nsent <= 0) { - perror("write"); + fprintf(stderr, "failed to send()!\n"); goto shutdown; } wr += nsent; @@ -302,23 +306,33 @@ int main(int argc, char *argv[]) } shutdown: + + if(forwardsock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(forwardsock); + closesocket(forwardsock); #else - close(forwardsock); + close(forwardsock); #endif + } + if(channel) libssh2_channel_free(channel); + if(listener) libssh2_channel_forward_cancel(listener); - libssh2_session_disconnect(session, "Client disconnecting normally"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - closesocket(sock); + closesocket(sock); #else - close(sock); + close(sock); #endif + } libssh2_exit(); diff --git a/example/x11.c b/example/x11.c index 4c0a1d4ced..87d1aa3b73 100644 --- a/example/x11.c +++ b/example/x11.c @@ -1,8 +1,7 @@ /* * Sample showing how to makes SSH2 with X11 Forwarding works. * - * Usage: - * "ssh2 host user password [DEBUG]" + * $ ./x11 host user password [DEBUG] */ #include "libssh2_setup.h" @@ -30,6 +29,9 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_SYS_TIME_H +#include +#endif #ifdef HAVE_SYS_UN_H #include #endif @@ -73,7 +75,7 @@ static void remove_node(struct chan_X11_list *elem) return; } - while(current_node->next != NULL) { + while(current_node->next) { if(current_node->next == elem) { current_node->next = current_node->next->next; current_node = current_node->next; @@ -86,7 +88,7 @@ static void remove_node(struct chan_X11_list *elem) static void session_shutdown(LIBSSH2_SESSION *session) { - libssh2_session_disconnect(session, "Session Shutdown"); + libssh2_session_disconnect(session, "Normal Shutdown"); libssh2_session_free(session); } @@ -124,11 +126,11 @@ static int _normal_mode(void) static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, char *shost, int sport, void **abstract) { - const char *display = NULL; - char *ptr = NULL; - char *temp_buff = NULL; - int display_port = 0; - int rc = 0; + const char *display; + char *ptr; + char *temp_buff; + int display_port; + int rc; libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; struct sockaddr_un addr; struct chan_X11_list *new; @@ -142,14 +144,14 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, * Inspired by x11_connect_display in openssh */ display = getenv("DISPLAY"); - if(display != NULL) { + if(display) { if(strncmp(display, "unix:", 5) == 0 || display[0] == ':') { /* Connect to the local unix domain */ ptr = strrchr(display, ':'); - temp_buff = (char *) calloc(strlen(ptr + 1) + 1, sizeof(char)); + temp_buff = (char *)calloc(strlen(ptr + 1) + 1, sizeof(char)); if(!temp_buff) { - perror("calloc"); + fprintf(stderr, "failed to calloc()!\n"); return; } memcpy(temp_buff, ptr + 1, strlen(ptr + 1)); @@ -167,7 +169,7 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, if(rc != -1) { /* Connection Successful */ - if(gp_x11_chan == NULL) { + if(!gp_x11_chan) { /* Calloc ensure that gp_X11_chan is full of 0 */ gp_x11_chan = (struct chan_X11_list *) calloc(1, sizeof(struct chan_X11_list)); @@ -177,7 +179,7 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, } else { chan_iter = gp_x11_chan; - while(chan_iter->next != NULL) + while(chan_iter->next) chan_iter = chan_iter->next; /* Create the new Node */ new = (struct chan_X11_list *) @@ -201,10 +203,10 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, */ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) { - char *buf = NULL; - int bufsize = 8192; - int rc = 0; - int nfds = 1; + char *buf; + int bufsize = 8192; + int rc; + int nfds = 1; LIBSSH2_POLLFD *fds = NULL; fd_set set; struct timeval timeval_out; @@ -240,7 +242,7 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) if(rc > 0) { ssize_t nread; - memset((void *)buf, 0, bufsize); + memset(buf, 0, bufsize); /* Data in sock */ nread = read(sock, buf, bufsize); @@ -264,14 +266,13 @@ static int x11_send_receive(LIBSSH2_CHANNEL *channel, int sock) /* * Main, more than inspired by ssh2.c by Bagder */ -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { uint32_t hostaddr = 0; - int rc = 0; + int rc; libssh2_socket_t sock = LIBSSH2_INVALID_SOCKET; struct sockaddr_in sin; - LIBSSH2_SESSION *session; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; char *username = NULL; char *password = NULL; @@ -311,14 +312,14 @@ main(int argc, char *argv[]) } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); return 1; } sock = socket(AF_INET, SOCK_STREAM, 0); if(sock == LIBSSH2_INVALID_SOCKET) { - perror("socket"); + fprintf(stderr, "failed to open socket!\n"); return -1; } @@ -333,7 +334,7 @@ main(int argc, char *argv[]) /* Open a session */ session = libssh2_session_init(); rc = libssh2_session_handshake(session, sock); - if(rc != 0) { + if(rc) { fprintf(stderr, "Failed Start the SSH session\n"); return -1; } @@ -351,7 +352,7 @@ main(int argc, char *argv[]) /* Authenticate via password */ rc = libssh2_userauth_password(session, username, password); - if(rc != 0) { + if(rc) { fprintf(stderr, "Failed to authenticate\n"); session_shutdown(session); close(sock); @@ -359,8 +360,8 @@ main(int argc, char *argv[]) } /* Open a channel */ - channel = libssh2_channel_open_session(session); - if(channel == NULL) { + channel = libssh2_channel_open_session(session); + if(!channel) { fprintf(stderr, "Failed to open a new channel\n"); session_shutdown(session); close(sock); @@ -369,7 +370,7 @@ main(int argc, char *argv[]) /* Request a PTY */ rc = libssh2_channel_request_pty(channel, "xterm"); - if(rc != 0) { + if(rc) { fprintf(stderr, "Failed to request a pty\n"); session_shutdown(session); close(sock); @@ -378,7 +379,7 @@ main(int argc, char *argv[]) /* Request X11 */ rc = libssh2_channel_x11_req(channel, 0); - if(rc != 0) { + if(rc) { fprintf(stderr, "Failed to request X11 forwarding\n"); session_shutdown(session); close(sock); @@ -387,7 +388,7 @@ main(int argc, char *argv[]) /* Request a shell */ rc = libssh2_channel_shell(channel); - if(rc != 0) { + if(rc) { fprintf(stderr, "Failed to open a shell\n"); session_shutdown(session); close(sock); @@ -395,7 +396,7 @@ main(int argc, char *argv[]) } rc = _raw_mode(); - if(rc != 0) { + if(rc) { fprintf(stderr, "Failed to entered in raw mode\n"); session_shutdown(session); close(sock); @@ -422,11 +423,11 @@ main(int argc, char *argv[]) } buf = calloc(bufsiz, sizeof(char)); - if(buf == NULL) + if(!buf) break; fds = malloc(sizeof(LIBSSH2_POLLFD)); - if(fds == NULL) { + if(!fds) { free(buf); break; } @@ -444,13 +445,13 @@ main(int argc, char *argv[]) } /* Looping on X clients */ - if(gp_x11_chan != NULL) { + if(gp_x11_chan) { current_node = gp_x11_chan; } else current_node = NULL; - while(current_node != NULL) { + while(current_node) { struct chan_X11_list *next_node; rc = x11_send_receive(current_node->chan, current_node->sock); next_node = current_node->next; @@ -494,10 +495,9 @@ main(int argc, char *argv[]) #else -int -main(void) +int main(void) { - printf("Sorry, this platform is not supported."); + fprintf(stderr, "Sorry, this platform is not supported."); return 1; } diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index b318573900..7e61bc634b 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -110,7 +110,7 @@ static int run_command_varg(char **output, const char *command, va_list args) buf[0] = 0; buf_len = 0; while(buf_len < (sizeof(buf) - 1) && - fgets(&buf[buf_len], (int)(sizeof(buf) - buf_len), pipe) != NULL) { + fgets(&buf[buf_len], (int)(sizeof(buf) - buf_len), pipe)) { buf_len = strlen(buf); } @@ -119,7 +119,7 @@ static int run_command_varg(char **output, const char *command, va_list args) #else ret = pclose(pipe); #endif - if(ret != 0) { + if(ret) { fprintf(stderr, "Error running command '%s' (exit %d): %s\n", command, ret, buf); } @@ -159,7 +159,7 @@ static int build_openssh_server_docker_image(void) if(have_docker) { char buildcmd[1024]; const char *container_image_name = openssh_server_image(); - if(container_image_name != NULL) { + if(container_image_name) { int ret = run_command(NULL, "docker pull --quiet %s", container_image_name); if(ret == 0) { @@ -191,7 +191,7 @@ static int start_openssh_server(char **container_id_out) { if(have_docker) { const char *container_host_port = openssh_server_port(); - if(container_host_port != NULL) { + if(container_host_port) { return run_command(container_id_out, "docker run --rm -d -p %s:22 " "libssh2/openssh_server", @@ -235,12 +235,12 @@ static int is_running_inside_a_container(void) ssize_t read = 0; int found = 0; f = fopen(cgroup_filename, "r"); - if(f == NULL) { + if(!f) { /* Don't go further, we are not in a container */ return 0; } while((read = getline(&line, &len, f)) != -1) { - if(strstr(line, "docker") != NULL) { + if(strstr(line, "docker")) { found = 1; break; } @@ -263,7 +263,7 @@ static void portable_sleep(unsigned int seconds) static int ip_address_from_container(char *container_id, char **ip_address_out) { const char *active_docker_machine = docker_machine_name(); - if(active_docker_machine != NULL) { + if(active_docker_machine) { /* This can be flaky when tests run in parallel (see https://github.com/docker/machine/issues/2612), so we retry a few @@ -337,14 +337,14 @@ static libssh2_socket_t open_socket_to_container(char *container_id) if(have_docker) { int res; res = ip_address_from_container(container_id, &ip_address); - if(res != 0) { + if(res) { fprintf(stderr, "Failed to get IP address for container %s\n", container_id); goto cleanup; } res = port_from_container(container_id, &port_string); - if(res != 0) { + if(res) { fprintf(stderr, "Failed to get port for container %s\n", container_id); goto cleanup; @@ -424,7 +424,7 @@ int start_openssh_fixture(void) WSADATA wsadata; ret = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(ret != 0) { + if(ret) { fprintf(stderr, "WSAStartup failed with error: %d\n", ret); return 1; } @@ -433,7 +433,7 @@ int start_openssh_fixture(void) have_docker = (getenv("OPENSSH_NO_DOCKER") == NULL); ret = build_openssh_server_docker_image(); - if(ret == 0) { + if(!ret) { return start_openssh_server(&running_container_id); } else { diff --git a/tests/ossfuzz/ssh2_client_fuzzer.cc b/tests/ossfuzz/ssh2_client_fuzzer.cc index 320a601e3e..86d2ab99c3 100644 --- a/tests/ossfuzz/ssh2_client_fuzzer.cc +++ b/tests/ossfuzz/ssh2_client_fuzzer.cc @@ -10,12 +10,12 @@ #include "testinput.h" #define FUZZ_ASSERT(COND) \ - if(!(COND)) \ - { \ - fprintf(stderr, "Assertion failed: " #COND "\n%s", \ - strerror(errno)); \ - assert((COND)); \ - } + if(!(COND)) \ + { \ + fprintf(stderr, "Assertion failed: " #COND "\n%s", \ + strerror(errno)); \ + assert((COND)); \ + } extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { @@ -27,7 +27,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); goto EXIT_LABEL; } @@ -38,7 +38,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) written = send(socket_fds[1], data, size, 0); - if (written != size) + if(written != size) { // Handle whatever error case we're in. fprintf(stderr, "send() of %zu bytes returned %zu (%d)\n", @@ -49,7 +49,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) } rc = shutdown(socket_fds[1], SHUT_WR); - if (rc != 0) + if(rc) { fprintf(stderr, "socket shutdown failed (%d)\n", rc); goto EXIT_LABEL; @@ -61,7 +61,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) libssh2_session_set_blocking(session, 1); } else { - goto EXIT_LABEL; + goto EXIT_LABEL; } if(libssh2_session_handshake(session, socket_fds[0])) { @@ -73,9 +73,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) EXIT_LABEL: - if (session != NULL) + if(session) { - if (handshake_completed) + if(handshake_completed) { libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing"); diff --git a/tests/runner.c b/tests/runner.c index aff8cae5bc..c2585073d0 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -41,7 +41,7 @@ int main(void) { int exit_code = 1; LIBSSH2_SESSION *session = start_session_fixture(); - if(session != NULL) { + if(session) { exit_code = (test(session) == 0) ? 0 : 1; } stop_session_fixture(); diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 24a6aa1e74..ebaa20db3a 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -70,7 +70,7 @@ static int connect_to_server(void) } rc = libssh2_session_handshake(connected_session, connected_socket); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_session_handshake"); return -1; } @@ -107,11 +107,11 @@ LIBSSH2_SESSION *start_session_fixture(void) setup_fixture_workdir(); rc = start_openssh_fixture(); - if(rc != 0) { + if(rc) { return NULL; } rc = libssh2_init(0); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2_init failed (%d)\n", rc); return NULL; } @@ -120,7 +120,7 @@ LIBSSH2_SESSION *start_session_fixture(void) if(getenv("FIXTURE_TRACE_ALL")) { libssh2_trace(connected_session, ~0); } - if(connected_session == NULL) { + if(!connected_session) { fprintf(stderr, "libssh2_session_init_ex failed\n"); return NULL; } @@ -153,7 +153,7 @@ LIBSSH2_SESSION *start_session_fixture(void) libssh2_session_set_blocking(connected_session, 1); rc = connect_to_server(); - if(rc != 0) { + if(rc) { return NULL; } diff --git a/tests/simple.c b/tests/simple.c index 33e26f259b..50fba3a351 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) (void)argc; rc = libssh2_init(LIBSSH2_INIT_NO_CRYPTO); - if(rc != 0) { + if(rc) { fprintf(stderr, "libssh2_init() failed: %d\n", rc); return 1; } diff --git a/tests/ssh2.c b/tests/ssh2.c index 4d9bbc5710..479a119026 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -2,7 +2,6 @@ #include "libssh2_setup.h" #include -#include #ifdef HAVE_SYS_SOCKET_H #include @@ -24,6 +23,11 @@ #include #include +static const char *pubkey = "etc/user.pub"; +static const char *privkey = "etc/user"; +static const char *username = "username"; +static const char *password = "password"; + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -32,22 +36,17 @@ int main(int argc, char *argv[]) struct sockaddr_in sin; const char *fingerprint; char *userauthlist; - LIBSSH2_SESSION *session; + int rc; + LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; - const char *pubkey = "etc/user.pub"; - const char *privkey = "etc/user"; - const char *username = "username"; - const char *password = "password"; - int ec = 1; #ifdef WIN32 WSADATA wsadata; - int err; - err = WSAStartup(MAKEWORD(2, 0), &wsadata); - if(err != 0) { - fprintf(stderr, "WSAStartup failed with error: %d\n", err); - return -1; + rc = WSAStartup(MAKEWORD(2, 0), &wsadata); + if(rc) { + fprintf(stderr, "WSAStartup failed with error: %d\n", rc); + return 1; } #endif @@ -55,17 +54,30 @@ int main(int argc, char *argv[]) (void)argv; if(getenv("USER")) - username = getenv("USER"); + username = getenv("USER"); if(getenv("PRIVKEY")) - privkey = getenv("PRIVKEY"); + privkey = getenv("PRIVKEY"); if(getenv("PUBKEY")) - pubkey = getenv("PUBKEY"); + pubkey = getenv("PUBKEY"); hostaddr = htonl(0x7F000001); + rc = libssh2_init(0); + if(rc) { + fprintf(stderr, "libssh2 initialization failed (%d)\n", rc); + return 1; + } + + rc = 1; + sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "failed to create socket!\n"); + goto shutdown; + } + #ifndef WIN32 fcntl(sock, F_SETFL, 0); #endif @@ -74,64 +86,70 @@ int main(int argc, char *argv[]) sin.sin_addr.s_addr = hostaddr; if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { fprintf(stderr, "failed to connect!\n"); - return 1; + goto shutdown; } - /* Create a session instance and start it up - * This will trade welcome banners, exchange keys, - * and setup crypto, compression, and MAC layers + /* Create a session instance and start it up. This will trade welcome + * banners, exchange keys, and setup crypto, compression, and MAC layers */ session = libssh2_session_init(); - if(libssh2_session_handshake(session, sock)) { - fprintf(stderr, "Failure establishing SSH session\n"); - return 1; + if(!session) { + fprintf(stderr, "Could not initialize SSH session!\n"); + goto shutdown; + } + + rc = libssh2_session_handshake(session, sock); + if(rc) { + fprintf(stderr, "Failure establishing SSH session: %d\n", rc); + goto shutdown; } - /* At this point we haven't authenticated, - * The first thing to do is check the hostkey's - * fingerprint against our known hosts - * Your app may have it hard coded, may go to a file, - * may present it to the user, that's your call + /* At this point we have not yet authenticated. The first thing to do + * is check the hostkey's fingerprint against our known hosts Your app + * may have it hard coded, may go to a file, may present it to the + * user, that's your call */ fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); - printf("Fingerprint: "); + fprintf(stderr, "Fingerprint: "); for(i = 0; i < 20; i++) { - printf("%02X ", (unsigned char)fingerprint[i]); + fprintf(stderr, "%02X ", (unsigned char)fingerprint[i]); } - printf("\n"); + fprintf(stderr, "\n"); /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); - printf("Authentication methods: %s\n", userauthlist); - if(strstr(userauthlist, "password") != NULL) { - auth_pw |= 1; - } - if(strstr(userauthlist, "keyboard-interactive") != NULL) { - auth_pw |= 2; - } - if(strstr(userauthlist, "publickey") != NULL) { - auth_pw |= 4; - } + if(userauthlist) { + fprintf(stderr, "Authentication methods: %s\n", userauthlist); + if(strstr(userauthlist, "password")) { + auth_pw |= 1; + } + if(strstr(userauthlist, "keyboard-interactive")) { + auth_pw |= 2; + } + if(strstr(userauthlist, "publickey")) { + auth_pw |= 4; + } - if(auth_pw & 4) { - /* Authenticate by public key */ - if(libssh2_userauth_publickey_fromfile(session, username, - pubkey, privkey, - password)) { - printf("\tAuthentication by public key failed!\n"); - goto shutdown; + if(auth_pw & 4) { + /* Authenticate by public key */ + if(libssh2_userauth_publickey_fromfile(session, username, + pubkey, privkey, + password)) { + fprintf(stderr, "Authentication by public key failed!\n"); + goto shutdown; + } + else { + fprintf(stderr, "Authentication by public key succeeded.\n"); + } } else { - printf("\tAuthentication by public key succeeded.\n"); + fprintf(stderr, "No supported authentication methods found!\n"); + goto shutdown; } } - else { - printf("No supported authentication methods found!\n"); - goto shutdown; - } - /* Request a shell */ + /* Request a session channel on which to run a shell */ channel = libssh2_channel_open_session(session); if(!channel) { fprintf(stderr, "Unable to open a session\n"); @@ -144,7 +162,8 @@ int main(int argc, char *argv[]) libssh2_channel_setenv(channel, "FOO", "bar"); /* Request a terminal with 'vanilla' terminal emulation - * See /etc/termcap for more options + * See /etc/termcap for more options. This is useful when opening + * an interactive shell. */ if(libssh2_channel_request_pty(channel, "vanilla")) { fprintf(stderr, "Failed requesting pty\n"); @@ -157,9 +176,10 @@ int main(int argc, char *argv[]) goto shutdown; } - ec = 0; + rc = 0; skip_shell: + if(channel) { libssh2_channel_free(channel); channel = NULL; @@ -167,16 +187,22 @@ int main(int argc, char *argv[]) shutdown: - libssh2_session_disconnect(session, "Normal Shutdown"); - libssh2_session_free(session); + if(session) { + libssh2_session_disconnect(session, "Normal Shutdown"); + libssh2_session_free(session); + } + if(sock != LIBSSH2_INVALID_SOCKET) { #ifdef WIN32 - Sleep(1000); - closesocket(sock); + closesocket(sock); #else - sleep(1); - close(sock); + close(sock); #endif + } + + fprintf(stderr, "all done\n"); + + libssh2_exit(); - return ec; + return rc; } diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index 361c4c21c2..c82413ee81 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -27,7 +27,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } @@ -39,7 +39,7 @@ int test(LIBSSH2_SESSION *session) /* } */ rc = libssh2_channel_request_auth_agent(channel); - if(rc != 0) { + if(rc) { fprintf(stderr, "Auth agent request for agent forwarding failed, " "error code %d\n", rc); return 1; diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index 3ab01ab010..1a61849431 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -21,7 +21,7 @@ int test(LIBSSH2_SESSION *session) char *expected_hostkey = NULL; const char *hostkey = libssh2_session_hostkey(session, &len, &type); - if(hostkey == NULL) { + if(!hostkey) { print_last_session_error("libssh2_session_hostkey"); return 1; } @@ -41,7 +41,7 @@ int test(LIBSSH2_SESSION *session) return 1; } - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_base64_decode"); return 1; } diff --git a/tests/test_hostkey_hash.c b/tests/test_hostkey_hash.c index 41f1e44d7c..9090ca6836 100644 --- a/tests/test_hostkey_hash.c +++ b/tests/test_hostkey_hash.c @@ -62,7 +62,7 @@ int test(LIBSSH2_SESSION *session) (void)EXPECTED_ECDSA_HOSTKEY; hostkey = libssh2_session_hostkey(session, &len, &type); - if(hostkey == NULL) { + if(!hostkey) { print_last_session_error("libssh2_session_hostkey"); return 1; } @@ -70,7 +70,7 @@ int test(LIBSSH2_SESSION *session) if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) { md5_hash = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_MD5); - if(md5_hash == NULL) { + if(!md5_hash) { print_last_session_error( "libssh2_hostkey_hash(LIBSSH2_HOSTKEY_HASH_MD5)"); return 1; @@ -86,7 +86,7 @@ int test(LIBSSH2_SESSION *session) } sha1_hash = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); - if(sha1_hash == NULL) { + if(!sha1_hash) { print_last_session_error( "libssh2_hostkey_hash(LIBSSH2_HOSTKEY_HASH_SHA1)"); return 1; @@ -103,7 +103,7 @@ int test(LIBSSH2_SESSION *session) sha256_hash = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256); - if(sha256_hash == NULL) { + if(!sha256_hash) { print_last_session_error( "libssh2_hostkey_hash(LIBSSH2_HOSTKEY_HASH_SHA256)"); return 1; @@ -122,7 +122,7 @@ int test(LIBSSH2_SESSION *session) else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) { md5_hash = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_MD5); - if(md5_hash == NULL) { + if(!md5_hash) { print_last_session_error( "libssh2_hostkey_hash(LIBSSH2_HOSTKEY_HASH_MD5)"); return 1; @@ -138,7 +138,7 @@ int test(LIBSSH2_SESSION *session) } sha1_hash = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); - if(sha1_hash == NULL) { + if(!sha1_hash) { print_last_session_error( "libssh2_hostkey_hash(LIBSSH2_HOSTKEY_HASH_SHA1)"); return 1; @@ -155,7 +155,7 @@ int test(LIBSSH2_SESSION *session) sha256_hash = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256); - if(sha256_hash == NULL) { + if(!sha256_hash) { print_last_session_error( "libssh2_hostkey_hash(LIBSSH2_HOSTKEY_HASH_SHA256)"); return 1; diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c index 9a37afb425..708ac0973a 100644 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c @@ -32,12 +32,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "keyboard-interactive") == NULL) { + if(!strstr(userauth_list, "keyboard-interactive")) { fprintf(stderr, "'keyboard-interactive' was expected in userauth list: %s\n", userauth_list); diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index 8683f9fe8e..860da944e5 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -223,7 +223,7 @@ LIBSSH2_ALLOC_FUNC(test_alloc) { int *threshold_int_ptr = *abstract; alloc_count++; - if(*abstract != NULL && *threshold_int_ptr == alloc_count) { + if(*abstract && *threshold_int_ptr == alloc_count) { return NULL; } @@ -252,7 +252,7 @@ int test_case(int num, alloc_count = 0; free_count = 0; session = libssh2_session_init_ex(test_alloc, test_free, NULL, abstract); - if(session == NULL) { + if(!session) { fprintf(stderr, "libssh2_session_init_ex failed\n"); return 1; } diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c index f15ab7dcc9..40fa33204f 100644 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c @@ -34,12 +34,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "keyboard-interactive") == NULL) { + if(!strstr(userauth_list, "keyboard-interactive")) { fprintf(stderr, "'keyboard-interactive' was expected in userauth list: %s\n", userauth_list); @@ -48,7 +48,7 @@ int test(LIBSSH2_SESSION *session) rc = libssh2_userauth_keyboard_interactive_ex( session, USERNAME, (unsigned int)strlen(USERNAME), kbd_callback); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_keyboard_interactive_ex"); return 1; } diff --git a/tests/test_password_auth_fails_with_wrong_password.c b/tests/test_password_auth_fails_with_wrong_password.c index e72c7ff863..88948fbacb 100644 --- a/tests/test_password_auth_fails_with_wrong_password.c +++ b/tests/test_password_auth_fails_with_wrong_password.c @@ -10,12 +10,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "password") == NULL) { + if(!strstr(userauth_list, "password")) { fprintf(stderr, "'password' was expected in userauth list: %s\n", userauth_list); return 1; diff --git a/tests/test_password_auth_fails_with_wrong_username.c b/tests/test_password_auth_fails_with_wrong_username.c index 12516c883a..e56428d6e2 100644 --- a/tests/test_password_auth_fails_with_wrong_username.c +++ b/tests/test_password_auth_fails_with_wrong_username.c @@ -11,12 +11,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, WRONG_USERNAME, (unsigned int)strlen(WRONG_USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "password") == NULL) { + if(!strstr(userauth_list, "password")) { fprintf(stderr, "'password' was expected in userauth list: %s\n", userauth_list); return 1; diff --git a/tests/test_password_auth_succeeds_with_correct_credentials.c b/tests/test_password_auth_succeeds_with_correct_credentials.c index 01be0c5932..6df9c0eb3a 100644 --- a/tests/test_password_auth_succeeds_with_correct_credentials.c +++ b/tests/test_password_auth_succeeds_with_correct_credentials.c @@ -11,12 +11,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "password") == NULL) { + if(!strstr(userauth_list, "password")) { fprintf(stderr, "'password' was expected in userauth list: %s\n", userauth_list); return 1; @@ -26,7 +26,7 @@ int test(LIBSSH2_SESSION *session) (unsigned int)strlen(USERNAME), PASSWORD, (unsigned int)strlen(PASSWORD), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_password_ex"); return 1; } diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c index c371c21c2f..0a10e88836 100644 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ b/tests/test_public_key_auth_fails_with_wrong_key.c @@ -11,12 +11,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c index bc5319c6cf..eace1e3331 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -26,7 +26,7 @@ int test(LIBSSH2_SESSION *session) rc = libssh2_userauth_publickey_fromfile_ex( session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c index 2d1650c8d4..31e770506c 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -27,7 +27,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c index e0380f69dc..1eab9f71f9 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -27,7 +27,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index 04ae61b684..f594d9f762 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -16,12 +16,12 @@ int test(LIBSSH2_SESSION *session) userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -40,7 +40,7 @@ int test(LIBSSH2_SESSION *session) free(buffer); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } @@ -54,7 +54,7 @@ static int read_file(const char *path, char **out_buffer, size_t *out_len) char *buffer = NULL; size_t len = 0; - if(out_buffer == NULL || out_len == NULL || path == NULL) { + if(!out_buffer || !out_len || !path) { fprintf(stderr, "invalid params."); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c index 7a305cef34..1d5debf7e0 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c @@ -13,12 +13,12 @@ int test(LIBSSH2_SESSION *session) userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -28,7 +28,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), PASSWORD); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c index 15803afef2..e254844be5 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c @@ -13,12 +13,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -28,7 +28,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), PASSWORD); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c index 6b905e6e9f..ff31ae8c57 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -27,7 +27,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c index 4440f124ba..3d4b8d68fb 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -27,7 +27,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c index f5c51f98d8..4a0cec3385 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -27,7 +27,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c index 65c5597bf7..05ecbe2b40 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -12,12 +12,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -27,7 +27,7 @@ int test(LIBSSH2_SESSION *session) session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } diff --git a/tests/test_read.c b/tests/test_read.c index 03ab99dc39..c9ee3b7b44 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -32,12 +32,12 @@ int test(LIBSSH2_SESSION *session) const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); - if(userauth_list == NULL) { + if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; } - if(strstr(userauth_list, "publickey") == NULL) { + if(!strstr(userauth_list, "publickey")) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; @@ -46,7 +46,7 @@ int test(LIBSSH2_SESSION *session) rc = libssh2_userauth_publickey_fromfile_ex( session, USERNAME, (unsigned int)strlen(USERNAME), srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc != 0) { + if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; } From 146a25a06dd2365a4330dad34fefcdcee1a206aa Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 14 Apr 2023 19:14:10 +0000 Subject: [PATCH 268/424] crypto: add `LIBSSH2_NO_HMAC_RIPEMD` option See also: 38015f4e46d8dbeea522dc7ee664522d4f47fc75 See also: be31457f3071686b555a0f0b19e5dcf63d67fc27 Ref: https://github.com/stribika/stribika.github.io/issues/46 Closes #965 --- src/crypto.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/crypto.h b/src/crypto.h index 168a8d3f65..658a177ebf 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -57,6 +57,11 @@ #define LIBSSH2_MD5 0 #endif +#ifdef LIBSSH2_NO_HMAC_RIPEMD +#undef LIBSSH2_HMAC_RIPEMD +#define LIBSSH2_HMAC_RIPEMD 0 +#endif + #ifdef LIBSSH2_NO_DSA #undef LIBSSH2_DSA #define LIBSSH2_DSA 0 From 8b4387d0dc079e69a4b7e1560b44ccfb32997117 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 14 Apr 2023 19:15:18 +0000 Subject: [PATCH 269/424] checksrc: fix `SIZEOFNOPAREN` warnings `s/sizeof ([a-z0-9._>*-]+)/sizeof(\1)/g` Closes #962 --- Makefile.am | 1 - ci/checksrc.sh | 1 - src/agent.c | 16 ++++++------ src/agent_win.c | 4 +-- src/os400qc3.c | 68 +++++++++++++++++++++++++------------------------ 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Makefile.am b/Makefile.am index d64e2ca632..e2010224b7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,7 +80,6 @@ coverage: init-coverage build-coverage gen-coverage checksrc: perl ci/checksrc.pl -i4 -m79 \ - -ASIZEOFNOPAREN \ -ASNPRINTF \ -ACOPYRIGHT \ -AFOPENMODE \ diff --git a/ci/checksrc.sh b/ci/checksrc.sh index aff58909ec..4de80e6c09 100755 --- a/ci/checksrc.sh +++ b/ci/checksrc.sh @@ -6,7 +6,6 @@ FILES="src/*.[ch] include/*.h example/*.c tests/*.[ch]" WHITELIST="-Wsrc/libssh2_config.h" perl ./ci/checksrc.pl -i4 -m79 \ - -ASIZEOFNOPAREN \ -ASNPRINTF \ -ACOPYRIGHT \ -AFOPENMODE \ diff --git a/src/agent.c b/src/agent.c index 35613c5bf7..9ad68a04c0 100644 --- a/src/agent.c +++ b/src/agent.c @@ -115,10 +115,10 @@ agent_connect_unix(LIBSSH2_AGENT *agent) "failed creating socket"); s_un.sun_family = AF_UNIX; - strncpy(s_un.sun_path, path, sizeof s_un.sun_path); + strncpy(s_un.sun_path, path, sizeof(s_un.sun_path)); s_un.sun_path[sizeof(s_un.sun_path)-1] = 0; /* make sure there's a trailing zero */ - if(connect(agent->fd, (struct sockaddr*)(&s_un), sizeof s_un) != 0) { + if(connect(agent->fd, (struct sockaddr*)(&s_un), sizeof(s_un)) != 0) { close(agent->fd); return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL, "failed connecting with agent"); @@ -171,7 +171,7 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) if(transctx->state == agent_NB_state_request_created) { _libssh2_htonu32(buf, (uint32_t)transctx->request_len); rc = (int)_send_all(agent->session->send, agent->fd, - buf, sizeof buf, 0, + buf, sizeof(buf), 0, &agent->session->abstract); if(rc == -EAGAIN) return LIBSSH2_ERROR_EAGAIN; @@ -197,7 +197,7 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) /* Receive the length of a response */ if(transctx->state == agent_NB_state_request_sent) { rc = (int)_recv_all(agent->session->recv, agent->fd, - buf, sizeof buf, 0, + buf, sizeof(buf), 0, &agent->session->abstract); if(rc < 0) { if(rc == -EAGAIN) @@ -594,7 +594,7 @@ agent_list_identities(LIBSSH2_AGENT *agent) rc = LIBSSH2_ERROR_AGENT_PROTOCOL; goto error; } - identity = LIBSSH2_ALLOC(agent->session, sizeof *identity); + identity = LIBSSH2_ALLOC(agent->session, sizeof(*identity)); if(!identity) { rc = LIBSSH2_ERROR_ALLOC; goto error; @@ -706,7 +706,7 @@ libssh2_agent_init(LIBSSH2_SESSION *session) { LIBSSH2_AGENT *agent; - agent = LIBSSH2_CALLOC(session, sizeof *agent); + agent = LIBSSH2_CALLOC(session, sizeof(*agent)); if(!agent) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate space for agent connection"); @@ -756,7 +756,7 @@ libssh2_agent_connect(LIBSSH2_AGENT *agent) LIBSSH2_API int libssh2_agent_list_identities(LIBSSH2_AGENT *agent) { - memset(&agent->transctx, 0, sizeof agent->transctx); + memset(&agent->transctx, 0, sizeof(agent->transctx)); /* Abandon the last fetched identities */ agent_free_identities(agent); return agent_list_identities(agent); @@ -815,7 +815,7 @@ libssh2_agent_userauth(LIBSSH2_AGENT *agent, int rc; if(agent->session->userauth_pblc_state == libssh2_NB_state_idle) { - memset(&agent->transctx, 0, sizeof agent->transctx); + memset(&agent->transctx, 0, sizeof(agent->transctx)); agent->identity = identity->node; } diff --git a/src/agent_win.c b/src/agent_win.c index 95e2b8cd47..db500ec11c 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -262,7 +262,7 @@ agent_transact_openssh(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) /* Send the length of the request */ if(transctx->state == agent_NB_state_request_created) { _libssh2_htonu32(buf, (uint32_t)transctx->request_len); - rc = win32_openssh_send_all(agent, buf, sizeof buf, + rc = win32_openssh_send_all(agent, buf, sizeof(buf), &transctx->send_recv_total); if(rc == LIBSSH2_ERROR_EAGAIN) return LIBSSH2_ERROR_EAGAIN; @@ -287,7 +287,7 @@ agent_transact_openssh(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) /* Receive the length of the body */ if(transctx->state == agent_NB_state_request_sent) { - rc = win32_openssh_recv_all(agent, buf, sizeof buf, + rc = win32_openssh_recv_all(agent, buf, sizeof(buf), &transctx->send_recv_total); if(rc == LIBSSH2_ERROR_EAGAIN) return LIBSSH2_ERROR_EAGAIN; diff --git a/src/os400qc3.c b/src/os400qc3.c index f531bbd191..2839406106 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -359,7 +359,7 @@ _libssh2_random(unsigned char *buf, size_t len) { Qus_EC_t errcode; - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3GenPRNs(buf, len, Qc3PRN_TYPE_NORMAL, Qc3PRN_NO_PARITY, (char *) &errcode); return errcode.Bytes_Available? -1: 0; @@ -370,7 +370,7 @@ _libssh2_bn_init(void) { _libssh2_bn *bignum; - bignum = (_libssh2_bn *) malloc(sizeof *bignum); + bignum = (_libssh2_bn *) malloc(sizeof(*bignum)); if(bignum) { bignum->bignum = NULL; bignum->length = 0; @@ -476,7 +476,7 @@ int _libssh2_bn_set_word(_libssh2_bn *bn, unsigned long val) { val = htonl(val); - return _libssh2_bn_from_bin(bn, sizeof val, (unsigned char *) &val); + return _libssh2_bn_from_bin(bn, sizeof(val), (unsigned char *) &val); } int @@ -593,7 +593,7 @@ asn1_new(unsigned int type, unsigned int length) unsigned int i; unsigned char *buf; - e = (asn1Element *) malloc(sizeof *e); + e = (asn1Element *) malloc(sizeof(*e)); if(e) { if(length >= 0x80) @@ -690,7 +690,7 @@ asn1containerv(unsigned int type, valiststr args) unsigned char *bp; unsigned int length = 0; - memcpy((char *) &va, (char *) &args, sizeof args); + memcpy((char *) &va, (char *) &args, sizeof(args)); while((p = va_arg(va.list, asn1Element *))) length += p->end - p->header; va_end(va.list); @@ -901,10 +901,10 @@ static _libssh2_os400qc3_crypto_ctx * libssh2_init_crypto_ctx(_libssh2_os400qc3_crypto_ctx *ctx) { if(!ctx) - ctx = (_libssh2_os400qc3_crypto_ctx *) malloc(sizeof *ctx); + ctx = (_libssh2_os400qc3_crypto_ctx *) malloc(sizeof(*ctx)); if(ctx) { - memset((char *) ctx, 0, sizeof *ctx); + memset((char *) ctx, 0, sizeof(*ctx)); ctx->hash.Final_Op_Flag = Qc3_Continue; } @@ -915,7 +915,7 @@ static int null_token(const char *token) { return !memcmp(token, nulltoken.Key_Context_Token, - sizeof nulltoken.Key_Context_Token); + sizeof(nulltoken.Key_Context_Token)); } void @@ -926,11 +926,13 @@ _libssh2_os400qc3_crypto_dtor(_libssh2_os400qc3_crypto_ctx *x) if(!null_token(x->hash.Alg_Context_Token)) { Qc3DestroyAlgorithmContext(x->hash.Alg_Context_Token, (char *) &ecnull); - memset(x->hash.Alg_Context_Token, 0, sizeof x->hash.Alg_Context_Token); + memset(x->hash.Alg_Context_Token, 0, + sizeof(x->hash.Alg_Context_Token)); } if(!null_token(x->key.Key_Context_Token)) { Qc3DestroyKeyContext(x->key.Key_Context_Token, (char *) &ecnull); - memset(x->key.Key_Context_Token, 0, sizeof x->key.Key_Context_Token); + memset(x->key.Key_Context_Token, 0, + sizeof(x->key.Key_Context_Token)); } if(x->kek) { _libssh2_os400qc3_crypto_dtor(x->kek); @@ -954,10 +956,10 @@ libssh2_os400qc3_hash_init(Qc3_Format_ALGD0100_T *x, unsigned int algorithm) if(!x) return 0; - memset((char *) x, 0, sizeof *x); + memset((char *) x, 0, sizeof(*x)); x->Final_Op_Flag = Qc3_Continue; algd.Hash_Alg = algorithm; - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3CreateAlgorithmContext((char *) &algd, Qc3_Alg_Hash, x->Alg_Context_Token, &errcode); return errcode.Bytes_Available? 0: 1; @@ -983,7 +985,7 @@ libssh2_os400qc3_hash_final(Qc3_Format_ALGD0100_T *ctx, unsigned char *out) Qc3CalculateHash(&data, &zero, Qc3_Data, (char *) ctx, Qc3_Alg_Token, anycsp, NULL, (char *) out, (char *) &ecnull); Qc3DestroyAlgorithmContext(ctx->Alg_Context_Token, (char *) &ecnull); - memset(ctx->Alg_Context_Token, 0, sizeof ctx->Alg_Context_Token); + memset(ctx->Alg_Context_Token, 0, sizeof(ctx->Alg_Context_Token)); } int @@ -1073,10 +1075,10 @@ _libssh2_cipher_init(_libssh2_cipher_ctx *h, _libssh2_cipher_type(algo), algd.Reserved = 0; algd.MAC_Length = 0; algd.Effective_Key_Size = 0; - memset(algd.Init_Vector, 0, sizeof algd.Init_Vector); + memset(algd.Init_Vector, 0, sizeof(algd.Init_Vector)); if(algo.mode != Qc3_ECB && algo.size) memcpy(algd.Init_Vector, iv, algo.size); - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3CreateAlgorithmContext((char *) &algd, algo.fmt, h->hash.Alg_Context_Token, &errcode); if(errcode.Bytes_Available) @@ -1103,7 +1105,7 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx, (void) algo; - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); if(encrypt) Qc3EncryptData((char *) block, &blksize, Qc3_Data, ctx->hash.Alg_Context_Token, Qc3_Alg_Token, @@ -1196,7 +1198,7 @@ _libssh2_rsa_new(libssh2_rsa_ctx **rsa, if(!ret) { Qus_EC_t errcode; - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); i = structkey->end - structkey->header; Qc3CreateKeyContext(structkey->header, &i, berstring, &keytype, qc3clear, NULL, NULL, ctx->key.Key_Context_Token, @@ -1233,7 +1235,7 @@ _libssh2_rsa_new(libssh2_rsa_ctx **rsa, void _libssh2_os400qc3_dh_init(_libssh2_dh_ctx *dhctx) { - memset((char *) dhctx, 0, sizeof *dhctx); + memset((char *) dhctx, 0, sizeof(*dhctx)); } int @@ -1275,7 +1277,7 @@ _libssh2_os400qc3_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, pkcs3len = pkcs3->end - pkcs3->header; pubkeysize = (_libssh2_bn_bits(p) + 7) >> 3; pubkey = alloca(pubkeysize); - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3GenDHKeyPair((char *) pkcs3->header, &pkcs3len, anycsp, NULL, dhctx->token, pubkey, &pubkeysize, &pubkeylen, &errcode); asn1delete(pkcs3); @@ -1300,7 +1302,7 @@ _libssh2_os400qc3_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, _libssh2_bn_to_bin(f, pubkey); secretbufsize = (_libssh2_bn_bits(p) + 7) >> 3; secretbuf = alloca(pubkeysize); - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3CalculateDHSecretKey(dhctx->token, pubkey, &pubkeysize, secretbuf, &secretbufsize, &secretbuflen, &errcode); @@ -1315,7 +1317,7 @@ _libssh2_os400qc3_dh_dtor(_libssh2_dh_ctx *dhctx) { if(!null_token(dhctx->token)) { Qc3DestroyAlgorithmContext(dhctx->token, (char *) &ecnull); - memset((char *) dhctx, 0, sizeof *dhctx); + memset((char *) dhctx, 0, sizeof(*dhctx)); } } @@ -1348,7 +1350,7 @@ asn1getword(asn1Element *e, unsigned long *v) return -1; for(cp = e->beg; cp < e->end && !*cp; cp++) ; - if(e->end - cp > sizeof a) + if(e->end - cp > sizeof(a)) return -1; for(a = 0; cp < e->end; cp++) a = (a << 8) | *cp; @@ -1436,7 +1438,7 @@ pbkdf2(LIBSSH2_SESSION *session, char **dk, const unsigned char *passphrase, for(i = 1; i <= l; i++) { ni = htonl(i); libssh2_os400qc3_hmac_update(&hctx, pkcs5->salt, pkcs5->saltlen); - libssh2_os400qc3_hmac_update(&hctx, (char *) &ni, sizeof ni); + libssh2_os400qc3_hmac_update(&hctx, (char *) &ni, sizeof(ni)); libssh2_os400qc3_hmac_final(&hctx, mac); memcpy(buf, mac, pkcs5->hashlen); for(j = 1; j < pkcs5->itercount; j++) { @@ -1719,7 +1721,7 @@ pkcs8kek(LIBSSH2_SESSION *session, _libssh2_os400qc3_crypto_ctx **ctx, /* PKCS#5: parse the PBES AlgorithmIdentifier and recursively get all encryption parameters. */ - memset((char *) &pkcs5, 0, sizeof pkcs5); + memset((char *) &pkcs5, 0, sizeof(pkcs5)); if(parse_pkcs5_algorithm(session, &pkcs5, &pkcs5alg, pbestable)) return -1; @@ -1728,7 +1730,7 @@ pkcs8kek(LIBSSH2_SESSION *session, _libssh2_os400qc3_crypto_ctx **ctx, return -1; /* Prepare the algorithm descriptor. */ - memset((char *) &algd, 0, sizeof algd); + memset((char *) &algd, 0, sizeof(algd)); algd.Block_Cipher_Alg = pkcs5.cipher; algd.Block_Length = pkcs5.blocksize; algd.Mode = pkcs5.mode; @@ -1744,7 +1746,7 @@ pkcs8kek(LIBSSH2_SESSION *session, _libssh2_os400qc3_crypto_ctx **ctx, return -1; } libssh2_init_crypto_ctx(*ctx); - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3CreateKeyContext(dk, &pkcs5.dklen, binstring, &algd.Block_Cipher_Alg, qc3clear, NULL, NULL, (*ctx)->key.Key_Context_Token, (char *) &errcode); @@ -1791,7 +1793,7 @@ rsapkcs8privkey(LIBSSH2_SESSION *session, return -1; } - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); pkilen = pki.end - pki.beg; Qc3CreateKeyContext((unsigned char *) pki.beg, &pkilen, berstring, rsaprivate, &keyform, kek, kea, @@ -1883,7 +1885,7 @@ rsapkcs8pubkey(LIBSSH2_SESSION *session, return -1; } - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); pkilen = pki.end - pki.beg; Qc3ExtractPublicKey(pki.beg, &pkilen, berstring, &keyform, kek, kea, buf, (int *) &datalen, &len, &errcode); @@ -2341,7 +2343,7 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx *rsa, size_t hash_len, int slen = (int)sig_len; int mlen = (int)m_len; - memset(&algd, 0, sizeof algd); + memset(&algd, 0, sizeof(algd)); algd.Public_Key_Alg = Qc3_RSA; algd.PKA_Block_Format = Qc3_PKCS1_01; switch(hash_len) { @@ -2358,7 +2360,7 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx *rsa, size_t hash_len, return -1; } - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3VerifySignature((char *) sig, &slen, (char *) m, &mlen, Qc3_Data, (char *) &algd, Qc3_Alg_Public_Key, (char *) &rsa->key, Qc3_Key_Token, anycsp, @@ -2389,13 +2391,13 @@ _libssh2_os400qc3_rsa_signv(LIBSSH2_SESSION *session, int siglen; unsigned char *sig; char sigbuf[8192]; - int sigbufsize = sizeof sigbuf; + int sigbufsize = sizeof(sigbuf); algd.Public_Key_Alg = Qc3_RSA; algd.PKA_Block_Format = Qc3_PKCS1_01; - memset(algd.Reserved, 0, sizeof algd.Reserved); + memset(algd.Reserved, 0, sizeof(algd.Reserved)); algd.Signing_Hash_Alg = algo; - set_EC_length(errcode, sizeof errcode); + set_EC_length(errcode, sizeof(errcode)); Qc3CalculateSignature((char *) vector, &veccount, Qc3_Array, (char *) &algd, Qc3_Alg_Public_Key, (char *) &ctx->key, Qc3_Key_Token, From 1b0c93b7553e5182af36394a8c4dc83905e94a14 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 14 Apr 2023 19:16:27 +0000 Subject: [PATCH 270/424] checksrc: fix `NOTEQUALSZERO` warnings Closes #963 --- Makefile.am | 1 - ci/checksrc.sh | 1 - example/direct_tcpip.c | 2 +- example/tcpip-forward.c | 2 +- src/kex.c | 22 ++++++------- src/libgcrypt.c | 40 +++++++++++------------ src/mbedtls.c | 71 ++++++++++++++++++++--------------------- src/misc.c | 2 +- src/openssl.c | 61 +++++++++++++++++++---------------- src/packet.c | 6 ++-- src/scp.c | 6 ++-- src/sftp.c | 18 +++++------ 12 files changed, 117 insertions(+), 115 deletions(-) diff --git a/Makefile.am b/Makefile.am index e2010224b7..ad5a5541c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,7 +84,6 @@ checksrc: -ACOPYRIGHT \ -AFOPENMODE \ -AEQUALSNULL \ - -ANOTEQUALSZERO \ -ATYPEDEFSTRUCT \ -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \ tests/*.[ch] diff --git a/ci/checksrc.sh b/ci/checksrc.sh index 4de80e6c09..a1cdb035b6 100755 --- a/ci/checksrc.sh +++ b/ci/checksrc.sh @@ -10,6 +10,5 @@ perl ./ci/checksrc.pl -i4 -m79 \ -ACOPYRIGHT \ -AFOPENMODE \ -AEQUALSNULL \ - -ANOTEQUALSZERO \ -ATYPEDEFSTRUCT \ $WHITELIST $FILES diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 503aa9fcef..34fecd3c02 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -265,7 +265,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "failed to recv()!\n"); goto shutdown; } - else if(0 == len) { + else if(len == 0) { fprintf(stderr, "The client at %s:%d disconnected!\n", shost, sport); goto shutdown; diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 0fd7ca8f99..874ff51f31 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -262,7 +262,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "failed to recv()!\n"); goto shutdown; } - else if(0 == len) { + else if(len == 0) { fprintf(stderr, "The local server at %s:%d disconnected!\n", local_destip, local_destport); goto shutdown; diff --git a/src/kex.c b/src/kex.c index 4965388c71..10171b0c4e 100644 --- a/src/kex.c +++ b/src/kex.c @@ -1866,7 +1866,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, /* Compute the shared secret K */ rc = _libssh2_ecdh_gen_k(&exchange_state->k, private_key, server_public_key, server_public_key_len); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE, "Unable to create ECDH shared secret"); goto clean_exit; @@ -1909,7 +1909,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, break; } - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, "Unable to verify hostkey signature"); goto clean_exit; @@ -2214,7 +2214,7 @@ kex_method_ecdh_key_exchange if(key_state->state == libssh2_NB_state_created) { rc = kex_session_ecdh_curve_type(session->kex->name, &type); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, -1, "Unknown KEX nistp curve type"); goto ecdh_clean_exit; @@ -2224,7 +2224,7 @@ kex_method_ecdh_key_exchange &key_state->public_key_oct, &key_state->public_key_oct_len, type); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, rc, "Unable to create private key"); goto ecdh_clean_exit; @@ -2277,7 +2277,7 @@ kex_method_ecdh_key_exchange rc = kex_session_ecdh_curve_type(session->kex->name, &type); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, -1, "Unknown KEX nistp curve type"); goto ecdh_clean_exit; @@ -2505,7 +2505,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, /* Compute the shared secret K */ rc = _libssh2_curve25519_gen_k(&exchange_state->k, private_key, server_public_key); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE, "Unable to create ECDH shared secret"); goto clean_exit; @@ -2536,7 +2536,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, /*/ verify hash */ LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(256); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, "Unable to verify hostkey signature"); goto clean_exit; @@ -2827,10 +2827,10 @@ kex_method_curve25519_key_exchange unsigned char *s = NULL; rc = strcmp(session->kex->name, "curve25519-sha256@libssh.org"); - if(rc != 0) + if(rc) rc = strcmp(session->kex->name, "curve25519-sha256"); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, -1, "Unknown KEX curve25519 curve type"); goto clean_exit; @@ -2840,7 +2840,7 @@ kex_method_curve25519_key_exchange &key_state->curve25519_public_key, &key_state->curve25519_private_key); - if(rc != 0) { + if(rc) { ret = _libssh2_error(session, rc, "Unable to create private key"); goto clean_exit; @@ -4134,7 +4134,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, } /* weird situation, no algorithm found */ - if(0 == ialg) + if(ialg == 0) return _libssh2_error(session, LIBSSH2_ERROR_INVAL, "No algorithm found"); diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 699f05fdf3..1ef4d521aa 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -98,12 +98,12 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, rc = gcry_sexp_build(&s_hash, NULL, "(data (flags pkcs1) (hash sha1 %b))", SHA_DIGEST_LENGTH, hash); - if(rc != 0) { + if(rc) { return -1; } rc = gcry_sexp_build(&s_sig, NULL, "(sig-val(rsa(s %b)))", sig_len, sig); - if(rc != 0) { + if(rc) { gcry_sexp_release(s_hash); return -1; } @@ -200,55 +200,55 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, } /* First read Version field (should be 0). */ ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen); - if(ret != 0 || (nlen != 1 && *n != '\0')) { + if(ret || (nlen != 1 && *n != '\0')) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &e, &elen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &d, &dlen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &q, &qlen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &e1, &e1len); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &e2, &e2len); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &coeff, &coefflen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } @@ -318,42 +318,42 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, /* First read Version field (should be 0). */ ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen); - if(ret != 0 || (plen != 1 && *p != '\0')) { + if(ret || (plen != 1 && *p != '\0')) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &q, &qlen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &g, &glen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &y, &ylen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } ret = _libssh2_pem_decode_integer(&data, &datalen, &x, &xlen); - if(ret != 0) { + if(ret) { ret = -1; goto fail; } - if(datalen != 0) { + if(datalen) { ret = -1; goto fail; } @@ -397,7 +397,7 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, gcry_sexp_release(data); - if(rc != 0) { + if(rc) { return -1; } @@ -458,7 +458,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, gcry_sexp_release(data); - if(ret != 0) { + if(ret) { return -1; } diff --git a/src/mbedtls.c b/src/mbedtls.c index 90c8ce095a..d857358a0d 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -69,7 +69,7 @@ _libssh2_mbedtls_init(void) ret = mbedtls_ctr_drbg_seed(&_libssh2_mbedtls_ctr_drbg, mbedtls_entropy_func, &_libssh2_mbedtls_entropy, NULL, 0); - if(ret != 0) + if(ret) mbedtls_ctr_drbg_free(&_libssh2_mbedtls_ctr_drbg); } @@ -348,9 +348,9 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, /* !checksrc! disable ASSIGNWITHINCONDITION 1 */ if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(E)), - edata, elen) ) != 0 || + edata, elen)) || (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(N)), - ndata, nlen) ) != 0) { + ndata, nlen))) { ret = -1; } @@ -362,18 +362,17 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, if(!ret && ddata) { /* !checksrc! disable ASSIGNWITHINCONDITION 1 */ if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(D)), - ddata, dlen) ) != 0 || + ddata, dlen)) || (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(P)), - pdata, plen) ) != 0 || + pdata, plen)) || (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(Q)), - qdata, qlen) ) != 0 || + qdata, qlen)) || (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DP)), - e1data, e1len) ) != 0 || + e1data, e1len)) || (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DQ)), - e2data, e2len) ) != 0 || + e2data, e2len)) || (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(QP)), - coeffdata, coefflen) ) - != 0) { + coeffdata, coefflen))) { ret = -1; } ret = mbedtls_rsa_check_privkey(ctx); @@ -418,7 +417,7 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa, #else ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase); #endif - if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) { + if(ret || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) { mbedtls_pk_free(&pkey); mbedtls_rsa_free(*rsa); LIBSSH2_FREE(session, *rsa); @@ -476,7 +475,7 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, #endif _libssh2_mbedtls_safe_free(filedata_nullterm, filedata_len); - if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) { + if(ret || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) { mbedtls_pk_free(&pkey); mbedtls_rsa_free(*rsa); LIBSSH2_FREE(session, *rsa); @@ -524,7 +523,7 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, } ret = _libssh2_mbedtls_hash(m, m_len, md_type, hash); - if(ret != 0) { + if(ret) { free(hash); return -1; /* failure */ } @@ -742,7 +741,7 @@ _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session, #else ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase); #endif - if(ret != 0) { + if(ret) { mbedtls_strerror(ret, (char *)buf, sizeof(buf)); mbedtls_pk_free(&pkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf); @@ -800,7 +799,7 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, #endif _libssh2_mbedtls_safe_free(privatekeydata_nullterm, privatekeydata_len); - if(ret != 0) { + if(ret) { mbedtls_strerror(ret, (char *)buf, sizeof(buf)); mbedtls_pk_free(&pkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf); @@ -923,7 +922,7 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session, if(mbedtls_ecdsa_genkey(*privkey, (mbedtls_ecp_group_id)curve, mbedtls_ctr_drbg_random, - &_libssh2_mbedtls_ctr_drbg) != 0) + &_libssh2_mbedtls_ctr_drbg)) goto failed; plen = 2 * mbedtls_mpi_size(&(*privkey)->MBEDTLS_PRIVATE(grp).P) + 1; @@ -967,12 +966,12 @@ _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ctx, mbedtls_ecdsa_init(*ctx); if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), - (mbedtls_ecp_group_id)curve) != 0) + (mbedtls_ecp_group_id)curve)) goto failed; if(mbedtls_ecp_point_read_binary(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q), - k, k_len) != 0) + k, k_len)) goto failed; if(mbedtls_ecp_check_pubkey(&(*ctx)->MBEDTLS_PRIVATE(grp), @@ -1009,7 +1008,7 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, if(mbedtls_ecp_point_read_binary(&privkey->MBEDTLS_PRIVATE(grp), &pubkey, - server_pubkey, server_pubkey_len) != 0) { + server_pubkey, server_pubkey_len)) { rc = -1; goto cleanup; } @@ -1018,12 +1017,12 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, &pubkey, &privkey->MBEDTLS_PRIVATE(d), mbedtls_ctr_drbg_random, - &_libssh2_mbedtls_ctr_drbg) != 0) { + &_libssh2_mbedtls_ctr_drbg)) { rc = -1; goto cleanup; } - if(mbedtls_ecp_check_privkey(&privkey->MBEDTLS_PRIVATE(grp), *k) != 0) + if(mbedtls_ecp_check_privkey(&privkey->MBEDTLS_PRIVATE(grp), *k)) rc = -1; cleanup: @@ -1062,10 +1061,10 @@ _libssh2_mbedtls_ecdsa_verify(libssh2_ecdsa_ctx *ctx, mbedtls_mpi_init(&pr); mbedtls_mpi_init(&ps); - if(mbedtls_mpi_read_binary(&pr, r, r_len) != 0) + if(mbedtls_mpi_read_binary(&pr, r, r_len)) goto cleanup; - if(mbedtls_mpi_read_binary(&ps, s, s_len) != 0) + if(mbedtls_mpi_read_binary(&ps, s, s_len)) goto cleanup; switch(_libssh2_ecdsa_get_curve_type(ctx)) { @@ -1105,11 +1104,11 @@ _libssh2_mbedtls_parse_eckey(libssh2_ecdsa_ctx **ctx, #if MBEDTLS_VERSION_NUMBER >= 0x03000000 if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len, mbedtls_ctr_drbg_random, - &_libssh2_mbedtls_ctr_drbg) != 0) + &_libssh2_mbedtls_ctr_drbg)) goto failed; #else - if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len) != 0) + if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len)) goto failed; #endif @@ -1149,23 +1148,23 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx, if(_libssh2_openssh_pem_parse_memory(session, pwd, (const char *)data, data_len, - &decrypted) != 0) + &decrypted)) goto failed; - if(_libssh2_get_string(decrypted, &name, NULL) != 0) + if(_libssh2_get_string(decrypted, &name, NULL)) goto failed; if(_libssh2_mbedtls_ecdsa_curve_type_from_name((const char *)name, - &type) != 0) + &type)) goto failed; - if(_libssh2_get_string(decrypted, &curve, &curvelen) != 0) + if(_libssh2_get_string(decrypted, &curve, &curvelen)) goto failed; - if(_libssh2_get_string(decrypted, &point_buf, &pointlen) != 0) + if(_libssh2_get_string(decrypted, &point_buf, &pointlen)) goto failed; - if(_libssh2_get_bignum_bytes(decrypted, &exponent, &exponentlen) != 0) + if(_libssh2_get_bignum_bytes(decrypted, &exponent, &exponentlen)) goto failed; *ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx)); @@ -1176,11 +1175,11 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx, mbedtls_ecdsa_init(*ctx); if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), - (mbedtls_ecp_group_id)type) != 0) + (mbedtls_ecp_group_id)type)) goto failed; if(mbedtls_mpi_read_binary(&(*ctx)->MBEDTLS_PRIVATE(d), - exponent, exponentlen) != 0) + exponent, exponentlen)) goto failed; if(mbedtls_ecp_mul(&(*ctx)->MBEDTLS_PRIVATE(grp), @@ -1188,7 +1187,7 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx, &(*ctx)->MBEDTLS_PRIVATE(d), &(*ctx)->MBEDTLS_PRIVATE(grp).G, mbedtls_ctr_drbg_random, - &_libssh2_mbedtls_ctr_drbg) != 0) + &_libssh2_mbedtls_ctr_drbg)) goto failed; if(mbedtls_ecp_check_privkey(&(*ctx)->MBEDTLS_PRIVATE(grp), @@ -1225,7 +1224,7 @@ _libssh2_mbedtls_ecdsa_new_private(libssh2_ecdsa_ctx **ctx, unsigned char *data; size_t data_len; - if(mbedtls_pk_load_file(filename, &data, &data_len) != 0) + if(mbedtls_pk_load_file(filename, &data, &data_len)) goto cleanup; mbedtls_pk_init(&pkey); @@ -1341,7 +1340,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, &ctx->MBEDTLS_PRIVATE(d), hash, hash_len, mbedtls_ctr_drbg_random, - &_libssh2_mbedtls_ctr_drbg) != 0) + &_libssh2_mbedtls_ctr_drbg)) goto cleanup; r_len = mbedtls_mpi_size(&pr) + 1; diff --git a/src/misc.c b/src/misc.c index d0c7aeeefa..c970657346 100644 --- a/src/misc.c +++ b/src/misc.c @@ -396,7 +396,7 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session, *outptr = NULL; /* set to NULL in case of failure before we reach the end */ - if(0 == insize) + if(insize == 0) insize = strlen(indata); base64data = output = LIBSSH2_ALLOC(session, insize * 4 / 3 + 4); diff --git a/src/openssl.c b/src/openssl.c index baff5194d6..60076d3b45 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -212,7 +212,7 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, ret = -1; /* unsupported digest */ } - if(ret != 0) { + if(ret) { free(hash); return -1; /* failure */ } @@ -790,7 +790,7 @@ static int _libssh2_rsa_new_additional_parameters(RSA *rsa) BN_clear_free(aux); BN_CTX_free(ctx); - if(rc != 0) { + if(rc) { if(dmp1) BN_clear_free(dmp1); if(dmq1) @@ -862,14 +862,15 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } - if((rc = _libssh2_rsa_new(&rsa, - e, (unsigned long)elen, - n, (unsigned long)nlen, - d, (unsigned long)dlen, - p, (unsigned long)plen, - q, (unsigned long)qlen, - NULL, 0, NULL, 0, - coeff, (unsigned long)coefflen)) != 0) { + rc = _libssh2_rsa_new(&rsa, + e, (unsigned long)elen, + n, (unsigned long)nlen, + d, (unsigned long)dlen, + p, (unsigned long)plen, + q, (unsigned long)qlen, + NULL, 0, NULL, 0, + coeff, (unsigned long)coefflen); + if(rc) { _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Could not create RSA private key")); @@ -943,7 +944,7 @@ _libssh2_rsa_new_openssh_private(libssh2_rsa_ctx ** rsa, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) { + if(rc || buf == NULL) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1176,7 +1177,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, g, (unsigned long)glen, pub_key, (unsigned long)pub_len, priv_key, (unsigned long)priv_len); - if(rc != 0) { + if(rc) { _libssh2_debug((session, LIBSSH2_ERROR_PROTO, "Could not create DSA private key")); @@ -1247,7 +1248,7 @@ _libssh2_dsa_new_openssh_private(libssh2_dsa_ctx ** dsa, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) { + if(rc || buf == NULL) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1819,7 +1820,7 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) { + if(rc || buf == NULL) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1891,7 +1892,7 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) { + if(rc || buf == NULL) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -2399,7 +2400,7 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx) defined(OPENSSL_VERSION_MAJOR) && \ OPENSSL_VERSION_MAJOR < 3 && \ !defined(LIBRESSL_VERSION_NUMBER) - if(FIPS_mode() != 0) + if(FIPS_mode()) return 0; #endif @@ -2603,8 +2604,10 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } - if((rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, point_buf, - pointlen, curve_type)) != 0) { + rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, + point_buf, pointlen, + curve_type); + if(rc) { rc = -1; _libssh2_error(session, LIBSSH2_ERROR_PROTO, "ECDSA could not create key"); @@ -2683,8 +2686,10 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } - if((rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, point_buf, - pointlen, LIBSSH2_EC_CURVE_NISTP256)) != 0) { + rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, + point_buf, pointlen, + LIBSSH2_EC_CURVE_NISTP256); + if(rc) { rc = -1; _libssh2_error(session, LIBSSH2_ERROR_PROTO, "ECDSA could not create key"); @@ -2822,7 +2827,7 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) { + if(rc || buf == NULL) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -2884,7 +2889,7 @@ _libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) { + if(rc || buf == NULL) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -3304,7 +3309,7 @@ _libssh2_pub_priv_openssh_keyfile(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) { + if(rc || buf == NULL) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -3358,7 +3363,7 @@ _libssh2_pub_priv_openssh_keyfile(LIBSSH2_SESSION *session, if(decrypted) _libssh2_string_buf_free(session, decrypted); - if(rc != 0) { + if(rc) { _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unsupported OpenSSH key type"); } @@ -3406,7 +3411,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, method_len, pubkeydata, pubkeydata_len, privatekey, passphrase); - if(rc != 0) { + if(rc) { return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public key " @@ -3502,7 +3507,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) + if(rc || buf == NULL) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted " "key data not found"); @@ -3644,7 +3649,7 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc != 0 || buf == NULL) + if(rc || buf == NULL) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted " "key data not found"); @@ -3753,7 +3758,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, privatekeydata, privatekeydata_len, (unsigned const char *)passphrase); - if(st != 0) + if(st) return st; return 0; } diff --git a/src/packet.c b/src/packet.c index c682fc7f1e..644386a8e6 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1211,9 +1211,9 @@ _libssh2_packet_askv(LIBSSH2_SESSION * session, size_t i, packet_types_len = strlen((const char *) packet_types); for(i = 0; i < packet_types_len; i++) { - if(0 == _libssh2_packet_ask(session, packet_types[i], data, - data_len, match_ofs, - match_buf, match_len)) { + if(_libssh2_packet_ask(session, packet_types[i], data, + data_len, match_ofs, + match_buf, match_len) == 0) { return 0; } } diff --git a/src/scp.c b/src/scp.c index 530679abe8..24c70ac321 100644 --- a/src/scp.c +++ b/src/scp.c @@ -939,7 +939,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, else if(!rc) /* remain in the same state */ goto scp_send_empty_channel; - else if(session->scpSend_response[0] != 0) { + else if(session->scpSend_response[0]) { _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote"); goto scp_send_error; @@ -994,7 +994,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, else if(!rc) /* remain in the same state */ goto scp_send_empty_channel; - else if(session->scpSend_response[0] != 0) { + else if(session->scpSend_response[0]) { _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid SCP ACK response"); goto scp_send_error; @@ -1064,7 +1064,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, else if(rc == 0) goto scp_send_empty_channel; - else if(session->scpSend_response[0] != 0) { + else if(session->scpSend_response[0]) { size_t err_len; char *err_msg; diff --git a/src/sftp.c b/src/sftp.c index 76e62c08ef..f098a45a4a 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -684,13 +684,13 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p, buf.dataptr = buf.data; buf.len = data_len; - if(_libssh2_get_u32(&buf, &flags) != 0) { + if(_libssh2_get_u32(&buf, &flags)) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } attrs->flags = flags; if(attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) { - if(_libssh2_get_u64(&buf, &(attrs->filesize)) != 0) { + if(_libssh2_get_u64(&buf, &(attrs->filesize))) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } } @@ -698,8 +698,8 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p, if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) { uint32_t uid = 0; uint32_t gid = 0; - if(_libssh2_get_u32(&buf, &uid) != 0 || - _libssh2_get_u32(&buf, &gid) != 0) { + if(_libssh2_get_u32(&buf, &uid) || + _libssh2_get_u32(&buf, &gid)) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } attrs->uid = uid; @@ -708,7 +708,7 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p, if(attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) { uint32_t permissions; - if(_libssh2_get_u32(&buf, &permissions) != 0) { + if(_libssh2_get_u32(&buf, &permissions)) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } attrs->permissions = permissions; @@ -717,8 +717,8 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p, if(attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) { uint32_t atime; uint32_t mtime; - if(_libssh2_get_u32(&buf, &atime) != 0 || - _libssh2_get_u32(&buf, &mtime) != 0) { + if(_libssh2_get_u32(&buf, &atime) || + _libssh2_get_u32(&buf, &mtime)) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } attrs->atime = atime; @@ -920,7 +920,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) buf.len = data_len; endp = &buf.data[data_len]; - if(_libssh2_get_u32(&buf, &(sftp_handle->version)) != 0) { + if(_libssh2_get_u32(&buf, &(sftp_handle->version))) { LIBSSH2_FREE(session, data); rc = LIBSSH2_ERROR_BUFFER_TOO_SMALL; goto sftp_init_error; @@ -1599,7 +1599,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, rc = sftp_packet_requirev(sftp, 2, read_responses, chunk->request_id, &data, &data_len, 9); - if(rc == LIBSSH2_ERROR_EAGAIN && bytes_in_buffer != 0) { + if(rc == LIBSSH2_ERROR_EAGAIN && bytes_in_buffer) { /* do not return EAGAIN if we have already * written data into the buffer */ return bytes_in_buffer; From cd5b114e7dc266c6a5cb9847b625184f0bb64613 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 14 Apr 2023 19:28:22 +0000 Subject: [PATCH 271/424] Makefile.am: add new OS400 header [ci skip] Follow-up to 6dc42e9d625deb816a051d312d09e68926959e78 --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index ad5a5541c2..b0f696ac6c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,6 +29,7 @@ OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ os400/os400sys.c os400/ccsid.c \ os400/libssh2_config.h os400/macros.h os400/libssh2_ccsid.h \ os400/include/alloca.h os400/include/sys/socket.h os400/include/stdio.h \ + os400/include/assert.h \ os400/libssh2rpg/libssh2.rpgle.in \ os400/libssh2rpg/libssh2_ccsid.rpgle.in \ os400/libssh2rpg/libssh2_publickey.rpgle \ From 5d399233d8d260aea07c05ebf069200c35e40ee6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 15 Apr 2023 02:46:09 +0000 Subject: [PATCH 272/424] checksrc: fix `EQUALSNULL` warnings `s/([a-z0-9._>*-]+) == NULL/!\1/g` Closes #964 --- Makefile.am | 1 - ci/checksrc.sh | 1 - src/agent.c | 6 +- src/agent_win.c | 4 +- src/bcrypt_pbkdf.c | 2 +- src/channel.c | 2 +- src/comp.c | 2 +- src/hostkey.c | 18 +- src/kex.c | 23 +-- src/mbedtls.c | 48 ++--- src/misc.c | 14 +- src/openssl.c | 294 ++++++++++++++-------------- src/packet.c | 2 +- src/pem.c | 23 +-- src/session.c | 8 +- src/sftp.c | 6 +- src/transport.c | 4 +- src/userauth.c | 22 +-- tests/openssh_fixture.c | 2 +- tests/test_agent_forward_succeeds.c | 10 +- 20 files changed, 248 insertions(+), 244 deletions(-) diff --git a/Makefile.am b/Makefile.am index b0f696ac6c..677be76a23 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,7 +84,6 @@ checksrc: -ASNPRINTF \ -ACOPYRIGHT \ -AFOPENMODE \ - -AEQUALSNULL \ -ATYPEDEFSTRUCT \ -Wsrc/libssh2_config.h src/*.[ch] include/*.h example/*.c \ tests/*.[ch] diff --git a/ci/checksrc.sh b/ci/checksrc.sh index a1cdb035b6..13a57ffe5f 100755 --- a/ci/checksrc.sh +++ b/ci/checksrc.sh @@ -9,6 +9,5 @@ perl ./ci/checksrc.pl -i4 -m79 \ -ASNPRINTF \ -ACOPYRIGHT \ -AFOPENMODE \ - -AEQUALSNULL \ -ATYPEDEFSTRUCT \ $WHITELIST $FILES diff --git a/src/agent.c b/src/agent.c index 9ad68a04c0..de22112f85 100644 --- a/src/agent.c +++ b/src/agent.c @@ -299,12 +299,12 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx) filemap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, PAGEANT_MAX_MSGLEN, mapname); - if(filemap == NULL || filemap == INVALID_HANDLE_VALUE) + if(!filemap || filemap == INVALID_HANDLE_VALUE) return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL, "failed setting up pageant filemap"); p2 = p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0); - if(p == NULL || p2 == NULL) { + if(!p || !p2) { CloseHandle(filemap); return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL, "failed to open pageant filemap for writing"); @@ -858,7 +858,7 @@ libssh2_agent_free(LIBSSH2_AGENT *agent) libssh2_agent_disconnect(agent); } - if(agent->identity_agent_path != NULL) + if(agent->identity_agent_path) LIBSSH2_FREE(agent->session, agent->identity_agent_path); agent_free_identities(agent); diff --git a/src/agent_win.c b/src/agent_win.c index db500ec11c..323ed6babb 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -184,7 +184,7 @@ agent_connect_openssh(LIBSSH2_AGENT *agent) } event = CreateEventA(NULL, TRUE, FALSE, NULL); - if(event == NULL) { + if(!event) { ret = _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL, "unable to create async I/O event"); goto cleanup; @@ -197,7 +197,7 @@ agent_connect_openssh(LIBSSH2_AGENT *agent) agent->fd = 0; /* Mark as the connection has been established */ cleanup: - if(event != NULL) + if(event) CloseHandle(event); if(pipe != INVALID_HANDLE_VALUE) CloseHandle(pipe); diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 2b84c70759..c9e6acb0d7 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -123,7 +123,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, keylen > sizeof(out) * sizeof(out) || saltlen > 1<<20) return -1; countsalt = calloc(1, saltlen + 4); - if(countsalt == NULL) + if(!countsalt) return -1; stride = (keylen + sizeof(out) - 1) / sizeof(out); amt = (keylen + stride - 1) / stride; diff --git a/src/channel.c b/src/channel.c index ff5c17e5a9..4573556e25 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2274,7 +2274,7 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id) uint32_t read_local_id; read_packet = _libssh2_list_first(&session->packets); - if(read_packet == NULL) + if(!read_packet) return 0; while(read_packet) { diff --git a/src/comp.c b/src/comp.c index 81ca89bf3b..cd1146e47c 100644 --- a/src/comp.c +++ b/src/comp.c @@ -235,7 +235,7 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session, out_maxlen = payload_limit; /* If strm is null, then we have not yet been initialized. */ - if(strm == NULL) + if(!strm) return _libssh2_error(session, LIBSSH2_ERROR_COMPRESS, "decompression uninitialized"); diff --git a/src/hostkey.c b/src/hostkey.c index 5e973cabb7..5384593f81 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -722,7 +722,7 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session, libssh2_curve_type type; struct string_buf buf; - if(abstract != NULL && *abstract) { + if(abstract && *abstract) { hostkey_method_ssh_ecdsa_dtor(session, abstract); *abstract = NULL; } @@ -780,7 +780,7 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session, key_len, type)) return -1; - if(abstract != NULL) + if(abstract) *abstract = ecdsactx; return 0; @@ -800,7 +800,7 @@ hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx *ec_ctx = NULL; int ret; - if(abstract != NULL && *abstract) { + if(abstract && *abstract) { hostkey_method_ssh_ecdsa_dtor(session, abstract); *abstract = NULL; } @@ -808,7 +808,7 @@ hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session, ret = _libssh2_ecdsa_new_private(&ec_ctx, session, privkeyfile, passphrase); - if(abstract != NULL) + if(abstract) *abstract = ec_ctx; return ret; @@ -829,7 +829,7 @@ hostkey_method_ssh_ecdsa_initPEMFromMemory(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx *ec_ctx = NULL; int ret; - if(abstract != NULL && *abstract) { + if(abstract && *abstract) { hostkey_method_ssh_ecdsa_dtor(session, abstract); *abstract = NULL; } @@ -842,7 +842,7 @@ hostkey_method_ssh_ecdsa_initPEMFromMemory(LIBSSH2_SESSION * session, return -1; } - if(abstract != NULL) + if(abstract) *abstract = ec_ctx; return 0; @@ -954,7 +954,7 @@ hostkey_method_ssh_ecdsa_dtor(LIBSSH2_SESSION * session, void **abstract) libssh2_ecdsa_ctx *keyctx = (libssh2_ecdsa_ctx *) (*abstract); (void) session; - if(keyctx != NULL) + if(keyctx) _libssh2_ecdsa_free(keyctx); *abstract = NULL; @@ -1140,7 +1140,7 @@ hostkey_method_ssh_ed25519_initPEMFromMemory(LIBSSH2_SESSION * session, libssh2_ed25519_ctx *ed_ctx = NULL; int ret; - if(abstract != NULL && *abstract) { + if(abstract && *abstract) { hostkey_method_ssh_ed25519_dtor(session, abstract); *abstract = NULL; } @@ -1153,7 +1153,7 @@ hostkey_method_ssh_ed25519_initPEMFromMemory(LIBSSH2_SESSION * session, return -1; } - if(abstract != NULL) + if(abstract) *abstract = ed_ctx; return 0; diff --git a/src/kex.c b/src/kex.c index 10171b0c4e..2b12fdfba6 100644 --- a/src/kex.c +++ b/src/kex.c @@ -468,7 +468,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, (const char *) session->server_hostkey_sha256, SHA256_DIGEST_LENGTH, &base64Fingerprint); - if(base64Fingerprint != NULL) { + if(base64Fingerprint) { _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server's SHA256 Fingerprint: %s", base64Fingerprint)); @@ -1675,7 +1675,7 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type) int ret = 0; libssh2_curve_type type; - if(name == NULL) + if(!name) return -1; if(strcmp(name, "ecdh-sha2-nistp256") == 0) @@ -1830,7 +1830,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, (const char *) session->server_hostkey_sha256, SHA256_DIGEST_LENGTH, &base64Fingerprint); - if(base64Fingerprint != NULL) { + if(base64Fingerprint) { _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server's SHA256 Fingerprint: %s", base64Fingerprint)); @@ -2462,7 +2462,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, (const char *) session->server_hostkey_sha256, SHA256_DIGEST_LENGTH, &base64Fingerprint); - if(base64Fingerprint != NULL) { + if(base64Fingerprint) { _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server's SHA256 Fingerprint: %s", base64Fingerprint)); @@ -3306,7 +3306,7 @@ kex_agree_instr(unsigned char *haystack, size_t haystack_len, unsigned char *end_haystack; size_t left; - if(haystack == NULL || needle == NULL) { + if(!haystack || !needle) { return NULL; } @@ -3327,6 +3327,7 @@ kex_agree_instr(unsigned char *haystack, size_t haystack_len, /* Search until we run out of comas or we run out of haystack, whichever comes first */ + /* !checksrc! disable EQUALSNULL 1 */ while((s = (unsigned char *) memchr((char *) s, ',', left)) != NULL) { /* Advance buffer past coma if we can */ left = end_haystack - s; @@ -4070,7 +4071,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, const LIBSSH2_COMMON_METHOD **mlist; /* to prevent coredumps due to dereferencing of NULL */ - if(NULL == algs) + if(!algs) return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE, "algs must not be NULL"); @@ -4110,7 +4111,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, } /* switch */ /* weird situation */ - if(NULL == mlist) + if(!mlist) return _libssh2_error(session, LIBSSH2_ERROR_INVAL, "No algorithm found"); @@ -4127,7 +4128,7 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, */ /* count the number of supported algorithms */ - for(i = 0, ialg = 0; NULL != mlist[i]; i++) { + for(i = 0, ialg = 0; mlist[i]; i++) { /* do not count fields with NULL name */ if(mlist[i]->name) ialg++; @@ -4140,15 +4141,15 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, /* allocate buffer */ *algs = (const char **) LIBSSH2_ALLOC(session, ialg*sizeof(const char *)); - if(NULL == *algs) { + if(!*algs) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Memory allocation failed"); } /* Past this point *algs must be deallocated in case of an error!! */ /* copy non-NULL pointers only */ - for(i = 0, j = 0; NULL != mlist[i] && j < ialg; i++) { - if(NULL == mlist[i]->name) { + for(i = 0, j = 0; mlist[i] && j < ialg; i++) { + if(!mlist[i]->name) { /* maybe a weird situation but if it occurs, do not include NULL pointers */ continue; diff --git a/src/mbedtls.c b/src/mbedtls.c index d857358a0d..b6e1ba0f6a 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -192,7 +192,7 @@ _libssh2_mbedtls_hash_init(mbedtls_md_context_t *ctx, if(!md_info) return 0; - hmac = key == NULL ? 0 : 1; + hmac = key ? 1 : 0; mbedtls_md_init(ctx); ret = mbedtls_md_setup(ctx, md_info, hmac); @@ -336,7 +336,7 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, libssh2_rsa_ctx *ctx; ctx = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx)); - if(ctx != NULL) { + if(ctx) { #if MBEDTLS_VERSION_NUMBER >= 0x03000000 mbedtls_rsa_init(ctx); #else @@ -400,7 +400,7 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa, mbedtls_rsa_context *pk_rsa; *rsa = (libssh2_rsa_ctx *) LIBSSH2_ALLOC(session, sizeof(libssh2_rsa_ctx)); - if(*rsa == NULL) + if(!*rsa) return -1; #if MBEDTLS_VERSION_NUMBER >= 0x03000000 @@ -446,7 +446,7 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, size_t pwd_len; *rsa = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx)); - if(*rsa == NULL) + if(!*rsa) return -1; /* @@ -454,14 +454,14 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, private-key from memory will fail if the last byte is not a null byte */ filedata_nullterm = mbedtls_calloc(filedata_len + 1, 1); - if(filedata_nullterm == NULL) { + if(!filedata_nullterm) { return -1; } memcpy(filedata_nullterm, filedata, filedata_len); mbedtls_pk_init(&pkey); - pwd_len = passphrase != NULL ? strlen((const char *)passphrase) : 0; + pwd_len = passphrase ? strlen((const char *)passphrase) : 0; #if MBEDTLS_VERSION_NUMBER >= 0x03000000 ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata_nullterm, filedata_len + 1, @@ -505,7 +505,7 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, return -1; hash = malloc(hash_len); - if(hash == NULL) + if(!hash) return -1; if(hash_len == SHA_DIGEST_LENGTH) { @@ -699,7 +699,7 @@ _libssh2_mbedtls_pub_priv_key(LIBSSH2_SESSION *session, rsa = mbedtls_pk_rsa(*pkey); key = gen_publickey_from_rsa(session, rsa, &keylen); - if(key == NULL) { + if(!key) { ret = -1; } @@ -776,14 +776,14 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, private-key from memory will fail if the last byte is not a null byte */ privatekeydata_nullterm = mbedtls_calloc(privatekeydata_len + 1, 1); - if(privatekeydata_nullterm == NULL) { + if(!privatekeydata_nullterm) { return -1; } memcpy(privatekeydata_nullterm, privatekeydata, privatekeydata_len); mbedtls_pk_init(&pkey); - pwd_len = passphrase != NULL ? strlen((const char *)passphrase) : 0; + pwd_len = passphrase ? strlen((const char *)passphrase) : 0; #if MBEDTLS_VERSION_NUMBER >= 0x03000000 ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)privatekeydata_nullterm, @@ -915,7 +915,7 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session, *privkey = LIBSSH2_ALLOC(session, sizeof(mbedtls_ecp_keypair)); - if(*privkey == NULL) + if(!*privkey) goto failed; mbedtls_ecdsa_init(*privkey); @@ -928,7 +928,7 @@ _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session, plen = 2 * mbedtls_mpi_size(&(*privkey)->MBEDTLS_PRIVATE(grp).P) + 1; *pubkey_oct = LIBSSH2_ALLOC(session, plen); - if(*pubkey_oct == NULL) + if(!*pubkey_oct) goto failed; if(mbedtls_ecp_point_write_binary(&(*privkey)->MBEDTLS_PRIVATE(grp), @@ -960,7 +960,7 @@ _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ctx, { *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair)); - if(*ctx == NULL) + if(!*ctx) goto failed; mbedtls_ecdsa_init(*ctx); @@ -1001,7 +1001,7 @@ _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, mbedtls_ecp_point pubkey; int rc = 0; - if(*k == NULL) + if(!*k) return -1; mbedtls_ecp_point_init(&pubkey); @@ -1117,7 +1117,7 @@ _libssh2_mbedtls_parse_eckey(libssh2_ecdsa_ctx **ctx, *ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx)); - if(*ctx == NULL) + if(!*ctx) goto failed; mbedtls_ecdsa_init(*ctx); @@ -1169,7 +1169,7 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx, *ctx = LIBSSH2_ALLOC(session, sizeof(libssh2_ecdsa_ctx)); - if(*ctx == NULL) + if(!*ctx) goto failed; mbedtls_ecdsa_init(*ctx); @@ -1205,7 +1205,7 @@ _libssh2_mbedtls_parse_openssh_key(libssh2_ecdsa_ctx **ctx, _libssh2_string_buf_free(session, decrypted); } - return (*ctx == NULL) ? -1 : 0; + return *ctx ? 0 : -1; } /* _libssh2_ecdsa_new_private @@ -1241,7 +1241,7 @@ _libssh2_mbedtls_ecdsa_new_private(libssh2_ecdsa_ctx **ctx, _libssh2_mbedtls_safe_free(data, data_len); - return (*ctx == NULL) ? -1 : 0; + return *ctx ? 0 : -1; } /* _libssh2_ecdsa_new_private @@ -1264,7 +1264,7 @@ _libssh2_mbedtls_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx **ctx, ntdata = LIBSSH2_ALLOC(session, data_len + 1); - if(ntdata == NULL) + if(!ntdata) goto cleanup; memcpy(ntdata, data, data_len); @@ -1282,7 +1282,7 @@ _libssh2_mbedtls_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx **ctx, _libssh2_mbedtls_safe_free(ntdata, data_len); - return (*ctx == NULL) ? -1 : 0; + return *ctx ? 0 : -1; } static unsigned char * @@ -1349,7 +1349,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, tmp_sign = LIBSSH2_CALLOC(session, tmp_sign_len); - if(tmp_sign == NULL) + if(!tmp_sign) goto cleanup; sp = tmp_sign; @@ -1360,7 +1360,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, *sign = LIBSSH2_CALLOC(session, *sign_len); - if(*sign == NULL) + if(!*sign) goto cleanup; memcpy(*sign, tmp_sign, *sign_len); @@ -1372,7 +1372,7 @@ _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, _libssh2_mbedtls_safe_free(tmp_sign, tmp_sign_len); - return (*sign == NULL) ? -1 : 0; + return *sign ? 0 : -1; } /* _libssh2_ecdsa_get_curve_type @@ -1400,7 +1400,7 @@ _libssh2_mbedtls_ecdsa_curve_type_from_name(const char *name, int ret = 0; libssh2_curve_type type; - if(name == NULL || strlen(name) != 19) + if(!name || strlen(name) != 19) return -1; if(strcmp(name, "ecdsa-sha2-nistp256") == 0) diff --git a/src/misc.c b/src/misc.c index c970657346..74c7573f6c 100644 --- a/src/misc.c +++ b/src/misc.c @@ -86,8 +86,8 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...) int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode, const char *errmsg, int errflags) { - if(session == NULL) { - if(errmsg != NULL) + if(!session) { + if(errmsg) fprintf(stderr, "Session is NULL, error: %s\n", errmsg); return errcode; } @@ -98,7 +98,7 @@ int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode, session->err_code = errcode; session->err_flags = 0; - if((errmsg != NULL) && ((errflags & LIBSSH2_ERR_FLAG_DUP) != 0)) { + if(errmsg && ((errflags & LIBSSH2_ERR_FLAG_DUP) != 0)) { size_t len = strlen(errmsg); char *copy = LIBSSH2_ALLOC(session, len + 1); if(copy) { @@ -400,7 +400,7 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session, insize = strlen(indata); base64data = output = LIBSSH2_ALLOC(session, insize * 4 / 3 + 4); - if(NULL == output) + if(!output) return 0; while(insize > 0) { @@ -756,7 +756,7 @@ struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session) struct string_buf *ret; ret = _libssh2_calloc(session, sizeof(*ret)); - if(ret == NULL) + if(!ret) return NULL; return ret; @@ -764,10 +764,10 @@ struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session) void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf) { - if(buf == NULL) + if(!buf) return; - if(buf->data != NULL) + if(buf->data) LIBSSH2_FREE(session, buf->data); LIBSSH2_FREE(session, buf); diff --git a/src/openssl.c b/src/openssl.c index 60076d3b45..af5fa6c1fd 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -187,7 +187,7 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, int ret; int nid_type; unsigned char *hash = malloc(hash_len); - if(hash == NULL) + if(!hash) return -1; if(hash_len == SHA_DIGEST_LENGTH) { @@ -352,7 +352,7 @@ _libssh2_ecdsa_curve_type_from_name(const char *name, int ret = 0; libssh2_curve_type type; - if(name == NULL || strlen(name) != 19) + if(!name || strlen(name) != 19) return -1; if(strcmp(name, "ecdsa-sha2-nistp256") == 0) @@ -400,10 +400,10 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx, ret = EC_POINT_oct2point(ec_group, point, k, k_len, NULL); ret = EC_KEY_set_public_key(ec_key, point); - if(point != NULL) + if(point) EC_POINT_free(point); - if(ec_ctx != NULL) + if(ec_ctx) *ec_ctx = ec_key; } @@ -655,7 +655,7 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, RSA *rsa, len = 4 + 7 + 4 + e_bytes + 4 + n_bytes; key = LIBSSH2_ALLOC(session, len); - if(key == NULL) { + if(!key) { return NULL; } @@ -692,18 +692,18 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, "Computing public key from RSA private key envelope")); rsa = EVP_PKEY_get1_RSA(pk); - if(rsa == NULL) { + if(!rsa) { /* Assume memory allocation error... what else could it be ? */ goto __alloc_error; } method_buf = LIBSSH2_ALLOC(session, 7); /* ssh-rsa. */ - if(method_buf == NULL) { + if(!method_buf) { goto __alloc_error; } key = gen_publickey_from_rsa(session, rsa, &key_len); - if(key == NULL) { + if(!key) { goto __alloc_error; } RSA_free(rsa); @@ -716,10 +716,10 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, return 0; __alloc_error: - if(rsa != NULL) { + if(rsa) { RSA_free(rsa); } - if(method_buf != NULL) { + if(method_buf) { LIBSSH2_FREE(session, method_buf); } @@ -749,23 +749,23 @@ static int _libssh2_rsa_new_additional_parameters(RSA *rsa) #endif ctx = BN_CTX_new(); - if(ctx == NULL) + if(!ctx) return -1; aux = BN_new(); - if(aux == NULL) { + if(!aux) { rc = -1; goto out; } dmp1 = BN_new(); - if(dmp1 == NULL) { + if(!dmp1) { rc = -1; goto out; } dmq1 = BN_new(); - if(dmq1 == NULL) { + if(!dmq1) { rc = -1; goto out; } @@ -877,10 +877,10 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } - if(rsa != NULL) + if(rsa) rc = _libssh2_rsa_new_additional_parameters(rsa); - if(rsa != NULL && pubkeydata != NULL && method != NULL) { + if(rsa && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_RSA(pk, rsa); @@ -892,7 +892,7 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(rsa_ctx != NULL) + if(rsa_ctx) *rsa_ctx = rsa; else RSA_free(rsa); @@ -901,7 +901,7 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, fail: - if(rsa != NULL) + if(rsa) RSA_free(rsa); return _libssh2_error(session, @@ -920,7 +920,7 @@ _libssh2_rsa_new_openssh_private(libssh2_rsa_ctx ** rsa, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -944,7 +944,7 @@ _libssh2_rsa_new_openssh_private(libssh2_rsa_ctx ** rsa, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1048,7 +1048,7 @@ gen_publickey_from_dsa(LIBSSH2_SESSION* session, DSA *dsa, len = 4 + 7 + 4 + p_bytes + 4 + q_bytes + 4 + g_bytes + 4 + k_bytes; key = LIBSSH2_ALLOC(session, len); - if(key == NULL) { + if(!key) { return NULL; } @@ -1087,18 +1087,18 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, "Computing public key from DSA private key envelope")); dsa = EVP_PKEY_get1_DSA(pk); - if(dsa == NULL) { + if(!dsa) { /* Assume memory allocation error... what else could it be ? */ goto __alloc_error; } method_buf = LIBSSH2_ALLOC(session, 7); /* ssh-dss. */ - if(method_buf == NULL) { + if(!method_buf) { goto __alloc_error; } key = gen_publickey_from_dsa(session, dsa, &key_len); - if(key == NULL) { + if(!key) { goto __alloc_error; } DSA_free(dsa); @@ -1111,10 +1111,10 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, return 0; __alloc_error: - if(dsa != NULL) { + if(dsa) { DSA_free(dsa); } - if(method_buf != NULL) { + if(method_buf) { LIBSSH2_FREE(session, method_buf); } @@ -1184,7 +1184,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } - if(dsa != NULL && pubkeydata != NULL && method != NULL) { + if(dsa && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_DSA(pk, dsa); @@ -1196,7 +1196,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(dsa_ctx != NULL) + if(dsa_ctx) *dsa_ctx = dsa; else DSA_free(dsa); @@ -1205,7 +1205,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, fail: - if(dsa != NULL) + if(dsa) DSA_free(dsa); return _libssh2_error(session, @@ -1224,7 +1224,7 @@ _libssh2_dsa_new_openssh_private(libssh2_dsa_ctx ** dsa, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -1248,7 +1248,7 @@ _libssh2_dsa_new_openssh_private(libssh2_dsa_ctx ** dsa, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1366,7 +1366,7 @@ _libssh2_curve25519_new(LIBSSH2_SESSION *session, int rc = -1; pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL); - if(pctx == NULL) + if(!pctx) return -1; if(EVP_PKEY_keygen_init(pctx) != 1 || @@ -1374,10 +1374,10 @@ _libssh2_curve25519_new(LIBSSH2_SESSION *session, goto cleanExit; } - if(out_private_key != NULL) { + if(out_private_key) { privLen = LIBSSH2_ED25519_KEY_LEN; priv = LIBSSH2_ALLOC(session, privLen); - if(priv == NULL) + if(!priv) goto cleanExit; if(EVP_PKEY_get_raw_private_key(key, priv, &privLen) != 1 || @@ -1389,10 +1389,10 @@ _libssh2_curve25519_new(LIBSSH2_SESSION *session, priv = NULL; } - if(out_public_key != NULL) { + if(out_public_key) { pubLen = LIBSSH2_ED25519_KEY_LEN; pub = LIBSSH2_ALLOC(session, pubLen); - if(pub == NULL) + if(!pub) goto cleanExit; if(EVP_PKEY_get_raw_public_key(key, pub, &pubLen) != 1 || @@ -1539,7 +1539,7 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, if(tmp_len > 0) { unsigned char *comment = LIBSSH2_CALLOC(session, tmp_len + 1); - if(comment != NULL) { + if(comment) { memcpy(comment, buf, tmp_len); memcpy(comment + tmp_len, "\0", 1); @@ -1570,7 +1570,7 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, "private key envelope")); method_buf = LIBSSH2_ALLOC(session, 11); /* ssh-ed25519. */ - if(method_buf == NULL) { + if(!method_buf) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1580,7 +1580,7 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, pub_key(32). */ key_len = LIBSSH2_ED25519_KEY_LEN + 19; key = LIBSSH2_CALLOC(session, key_len); - if(key == NULL) { + if(!key) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1593,25 +1593,25 @@ gen_publickey_from_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, memcpy(method_buf, "ssh-ed25519", 11); - if(method != NULL) + if(method) *method = method_buf; else LIBSSH2_FREE(session, method_buf); - if(method_len != NULL) + if(method_len) *method_len = 11; - if(pubkeydata != NULL) + if(pubkeydata) *pubkeydata = key; else LIBSSH2_FREE(session, key); - if(pubkeydata_len != NULL) + if(pubkeydata_len) *pubkeydata_len = key_len; - if(out_ctx != NULL) + if(out_ctx) *out_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); return 0; @@ -1671,13 +1671,13 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } - if(flags != NULL && _libssh2_get_byte(decrypted, flags)) { + if(flags && _libssh2_get_byte(decrypted, flags)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "No SK flags."); return -1; } - if(key_handle != NULL && handle_len != NULL) { + if(key_handle && handle_len) { unsigned char *handle = NULL; if(_libssh2_get_string(decrypted, &handle, handle_len)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -1706,7 +1706,7 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, /* sk-ssh-ed25519@openssh.com. */ method_buf = LIBSSH2_ALLOC(session, strlen(key_type)); - if(method_buf == NULL) { + if(!method_buf) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1716,7 +1716,7 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, pub_key(32) + application_len(4) + application(X). */ key_len = LIBSSH2_ED25519_KEY_LEN + 38 + app_len; key = LIBSSH2_CALLOC(session, key_len); - if(key == NULL) { + if(!key) { _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for ED25519 key"); goto clean_exit; @@ -1728,7 +1728,7 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, _libssh2_store_str(&p, (const char *)pub_key, LIBSSH2_ED25519_KEY_LEN); _libssh2_store_str(&p, (const char *)app, app_len); - if(application != NULL && app_len > 0) { + if(application && app_len > 0) { *application = (const char *)LIBSSH2_ALLOC(session, app_len + 1); _libssh2_explicit_zero((void *)*application, app_len + 1); memcpy((void *)*application, app, app_len); @@ -1736,25 +1736,25 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, memcpy(method_buf, key_type, strlen(key_type)); - if(method != NULL) + if(method) *method = method_buf; else LIBSSH2_FREE(session, method_buf); - if(method_len != NULL) + if(method_len) *method_len = strlen(key_type); - if(pubkeydata != NULL) + if(pubkeydata) *pubkeydata = key; - else if(key != NULL) + else if(key) LIBSSH2_FREE(session, key); - if(pubkeydata_len != NULL) + if(pubkeydata_len) *pubkeydata_len = key_len; - if(out_ctx != NULL) + if(out_ctx) *out_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); return 0; @@ -1771,12 +1771,12 @@ gen_publickey_from_sk_ed25519_openssh_priv_data(LIBSSH2_SESSION *session, if(key) LIBSSH2_FREE(session, key); - if(application != NULL && *application != NULL) { + if(application && *application) { LIBSSH2_FREE(session, (void *)application); *application = NULL; } - if(key_handle != NULL && *key_handle != NULL) { + if(key_handle && *key_handle) { LIBSSH2_FREE(session, (void *)key_handle); *key_handle = NULL; } @@ -1796,7 +1796,7 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, struct string_buf *decrypted = NULL; libssh2_ed25519_ctx *ctx = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -1820,7 +1820,7 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1843,9 +1843,9 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, _libssh2_string_buf_free(session, decrypted); if(rc == 0) { - if(ed_ctx != NULL) + if(ed_ctx) *ed_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); } @@ -1868,7 +1868,7 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, struct string_buf *decrypted = NULL; libssh2_ed25519_ctx *ctx = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -1892,7 +1892,7 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -1919,9 +1919,9 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, _libssh2_string_buf_free(session, decrypted); if(rc == 0) { - if(ed_ctx != NULL) + if(ed_ctx) *ed_ctx = ctx; - else if(ctx != NULL) + else if(ctx) _libssh2_ed25519_free(ctx); } @@ -1996,7 +1996,7 @@ _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, { libssh2_ed25519_ctx *ctx = NULL; - if(ed_ctx == NULL) + if(!ed_ctx) return -1; ctx = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, @@ -2005,7 +2005,7 @@ _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "could not create ED25519 public key"); - if(ed_ctx != NULL) + if(ed_ctx) *ed_ctx = ctx; else if(ctx) _libssh2_ed25519_free(ctx); @@ -2133,7 +2133,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, unsigned char *out_buffer = NULL; ECDSA_SIG *sig = ECDSA_do_sign(hash, (int) hash_len, ec_ctx); - if(sig == NULL) + if(!sig) return -1; #ifdef HAVE_OPAQUE_STRUCTS ECDSA_SIG_get0(sig, &pr, &ps); @@ -2146,7 +2146,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, s_len = BN_num_bytes(ps) + 1; temp_buffer = malloc(r_len + s_len + 8); - if(temp_buffer == NULL) { + if(!temp_buffer) { rc = -1; goto clean_exit; } @@ -2158,7 +2158,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, out_buffer_len = (size_t)(sp - temp_buffer); out_buffer = LIBSSH2_CALLOC(session, out_buffer_len); - if(out_buffer == NULL) { + if(!out_buffer) { rc = -1; goto clean_exit; } @@ -2170,7 +2170,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, clean_exit: - if(temp_buffer != NULL) + if(temp_buffer) free(temp_buffer); if(sig) @@ -2186,7 +2186,7 @@ _libssh2_sha1_init(libssh2_sha1_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha1"))) @@ -2209,7 +2209,7 @@ _libssh2_sha1(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"))) { @@ -2238,7 +2238,7 @@ _libssh2_sha256_init(libssh2_sha256_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha256"))) @@ -2261,7 +2261,7 @@ _libssh2_sha256(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha256"))) { @@ -2290,7 +2290,7 @@ _libssh2_sha384_init(libssh2_sha384_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha384"))) @@ -2313,7 +2313,7 @@ _libssh2_sha384(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha384"))) { @@ -2342,7 +2342,7 @@ _libssh2_sha512_init(libssh2_sha512_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha512"))) @@ -2365,7 +2365,7 @@ _libssh2_sha512(const unsigned char *message, size_t len, #ifdef HAVE_OPAQUE_STRUCTS EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - if(ctx == NULL) + if(!ctx) return 1; /* error */ if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha512"))) { @@ -2407,7 +2407,7 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx) #ifdef HAVE_OPAQUE_STRUCTS *ctx = EVP_MD_CTX_new(); - if(*ctx == NULL) + if(!*ctx) return 0; if(EVP_DigestInit(*ctx, EVP_get_digestbyname("md5"))) @@ -2452,11 +2452,11 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, "Computing public key from EC private key envelope")); bn_ctx = BN_CTX_new(); - if(bn_ctx == NULL) + if(!bn_ctx) return -1; ec = EVP_PKEY_get1_EC_KEY(pk); - if(ec == NULL) { + if(!ec) { rc = -1; goto clean_exit; } @@ -2471,7 +2471,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, *method_len = 19; method_buf = LIBSSH2_ALLOC(session, *method_len); - if(method_buf == NULL) { + if(!method_buf) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "out of memory"); } @@ -2502,7 +2502,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, } octal_value = malloc(octal_len); - if(octal_value == NULL) { + if(!octal_value) { rc = -1; goto clean_exit; } @@ -2518,7 +2518,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, + pub_key_len(4) + pub_key(~65). */ key_len = 4 + *method_len + 4 + 8 + 4 + octal_len; key = LIBSSH2_ALLOC(session, key_len); - if(key == NULL) { + if(!key) { rc = -1; goto clean_exit; } @@ -2546,20 +2546,20 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, clean_exit: - if(ec != NULL) + if(ec) EC_KEY_free(ec); - if(bn_ctx != NULL) { + if(bn_ctx) { BN_CTX_free(bn_ctx); } - if(octal_value != NULL) + if(octal_value) free(octal_value); if(rc == 0) return 0; - if(method_buf != NULL) + if(method_buf) LIBSSH2_FREE(session, method_buf); return -1; @@ -2615,7 +2615,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, } bn_exponent = BN_new(); - if(bn_exponent == NULL) { + if(!bn_exponent) { rc = -1; _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for private key data"); @@ -2625,7 +2625,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, BN_bin2bn(exponent, (int) exponentlen, bn_exponent); rc = (EC_KEY_set_private_key(ec_key, bn_exponent) != 1); - if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) { + if(rc == 0 && ec_key && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_EC_KEY(pk, ec_key); @@ -2637,7 +2637,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(ec_ctx != NULL) + if(ec_ctx) *ec_ctx = ec_key; else EC_KEY_free(ec_key); @@ -2645,7 +2645,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return rc; fail: - if(ec_key != NULL) + if(ec_key) EC_KEY_free(ec_key); return rc; @@ -2702,13 +2702,13 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } - if(flags != NULL && _libssh2_get_byte(decrypted, flags)) { + if(flags && _libssh2_get_byte(decrypted, flags)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "No SK flags."); goto fail; } - if(key_handle != NULL && handle_len != NULL) { + if(key_handle && handle_len) { unsigned char *handle = NULL; if(_libssh2_get_string(decrypted, &handle, handle_len)) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -2725,7 +2725,7 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, } } - if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) { + if(rc == 0 && ec_key && pubkeydata && method) { EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_EC_KEY(pk, ec_key); @@ -2737,11 +2737,11 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); } - if(rc == 0 && pubkeydata != NULL) { + if(rc == 0 && pubkeydata) { key_len = *pubkeydata_len + app_len + 4; key = LIBSSH2_ALLOC(session, key_len); - if(key == NULL) { + if(!key) { rc = -1; goto fail; } @@ -2751,7 +2751,7 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, memcpy(key, *pubkeydata, *pubkeydata_len); _libssh2_store_str(&p, (const char *)app, app_len); - if(application != NULL && app_len > 0) { + if(application && app_len > 0) { *application = (const char *)LIBSSH2_ALLOC(session, app_len + 1); _libssh2_explicit_zero((void *)*application, app_len + 1); memcpy((void *)*application, app, app_len); @@ -2760,13 +2760,13 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, *pubkeydata); *pubkeydata_len = key_len; - if(pubkeydata != NULL) + if(pubkeydata) *pubkeydata = key; - else if(key != NULL) + else if(key) LIBSSH2_FREE(session, key); } - if(ec_ctx != NULL) + if(ec_ctx) *ec_ctx = ec_key; else EC_KEY_free(ec_key); @@ -2774,15 +2774,15 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return rc; fail: - if(ec_key != NULL) + if(ec_key) EC_KEY_free(ec_key); - if(application != NULL && *application != NULL) { + if(application && *application) { LIBSSH2_FREE(session, (void *)application); *application = NULL; } - if(key_handle != NULL && *key_handle != NULL) { + if(key_handle && *key_handle) { LIBSSH2_FREE(session, (void *)key_handle); *key_handle = NULL; } @@ -2803,7 +2803,7 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, libssh2_curve_type type; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -2827,7 +2827,7 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -2865,7 +2865,7 @@ _libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -2889,7 +2889,7 @@ _libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -3021,12 +3021,12 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session, goto clean_exit; } - if(out_private_key != NULL) + if(out_private_key) *out_private_key = private_key; if(out_public_key_octal) { *out_public_key_octal = LIBSSH2_ALLOC(session, octal_len); - if(*out_public_key_octal == NULL) { + if(!*out_public_key_octal) { ret = -1; goto clean_exit; } @@ -3034,7 +3034,7 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session, memcpy(*out_public_key_octal, octal_value, octal_len); } - if(out_public_key_octal_len != NULL) + if(out_public_key_octal_len) *out_public_key_octal_len = octal_len; clean_exit: @@ -3067,13 +3067,13 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key, if(!bn_ctx) return -1; - if(k == NULL) + if(!k) return -1; private_key_group = EC_KEY_get0_group(private_key); server_public_key_point = EC_POINT_new(private_key_group); - if(server_public_key_point == NULL) + if(!server_public_key_point) return -1; rc = EC_POINT_oct2point(private_key_group, server_public_key_point, @@ -3102,13 +3102,13 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key, clean_exit: - if(server_public_key_point != NULL) + if(server_public_key_point) EC_POINT_free(server_public_key_point); - if(bn_ctx != NULL) + if(bn_ctx) BN_CTX_free(bn_ctx); - if(secret != NULL) + if(secret) free(secret); return ret; @@ -3129,7 +3129,7 @@ _libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session, size_t sig_len = 0; unsigned char *sig = NULL; - if(md_ctx != NULL) { + if(md_ctx) { if(EVP_DigestSignInit(md_ctx, NULL, NULL, NULL, ctx) != 1) goto clean_exit; if(EVP_DigestSign(md_ctx, NULL, &sig_len, message, message_len) != 1) @@ -3139,7 +3139,7 @@ _libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session, goto clean_exit; sig = LIBSSH2_CALLOC(session, sig_len); - if(sig == NULL) + if(!sig) goto clean_exit; rc = EVP_DigestSign(md_ctx, sig, &sig_len, message, message_len); @@ -3175,11 +3175,11 @@ _libssh2_curve25519_gen_k(_libssh2_bn **k, BN_CTX *bn_ctx = NULL; size_t out_len = 0; - if(k == NULL || *k == NULL) + if(!k || !*k) return -1; bn_ctx = BN_CTX_new(); - if(bn_ctx == NULL) + if(!bn_ctx) return -1; peer_key = EVP_PKEY_new_raw_public_key(EVP_PKEY_X25519, NULL, @@ -3190,12 +3190,12 @@ _libssh2_curve25519_gen_k(_libssh2_bn **k, private_key, LIBSSH2_ED25519_KEY_LEN); - if(peer_key == NULL || server_key == NULL) { + if(!peer_key || !server_key) { goto cleanExit; } server_key_ctx = EVP_PKEY_CTX_new(server_key, NULL); - if(server_key_ctx == NULL) { + if(!server_key_ctx) { goto cleanExit; } @@ -3236,7 +3236,7 @@ _libssh2_curve25519_gen_k(_libssh2_bn **k, EVP_PKEY_free(peer_key); if(server_key) EVP_PKEY_free(server_key); - if(bn_ctx != NULL) + if(bn_ctx) BN_CTX_free(bn_ctx); return (rc == 1) ? 0 : -1; @@ -3250,7 +3250,7 @@ _libssh2_ed25519_verify(libssh2_ed25519_ctx *ctx, const uint8_t *s, int ret = -1; EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); - if(NULL == md_ctx) + if(!md_ctx) return -1; ret = EVP_DigestVerifyInit(md_ctx, NULL, NULL, NULL, ctx); @@ -3282,7 +3282,7 @@ _libssh2_pub_priv_openssh_keyfile(LIBSSH2_SESSION *session, struct string_buf *decrypted = NULL; int rc = 0; - if(session == NULL) { + if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); return -1; @@ -3309,7 +3309,7 @@ _libssh2_pub_priv_openssh_keyfile(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) { + if(rc || !buf) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted key data not found"); return -1; @@ -3392,7 +3392,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, privatekey)); bp = BIO_new_file(privatekey, "r"); - if(bp == NULL) { + if(!bp) { return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public key from private key " @@ -3403,7 +3403,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); - if(pk == NULL) { + if(!pk) { /* Try OpenSSH format */ rc = _libssh2_pub_priv_openssh_keyfile(session, @@ -3484,14 +3484,14 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(key_ctx != NULL) + if(key_ctx) *key_ctx = NULL; - if(session == NULL) + if(!session) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); - if(key_type != NULL && (strlen(key_type) > 11 || strlen(key_type) < 7)) + if(key_type && (strlen(key_type) > 11 || strlen(key_type) < 7)) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "type is invalid"); @@ -3507,7 +3507,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) + if(rc || !buf) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted " "key data not found"); @@ -3516,7 +3516,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, #if LIBSSH2_ED25519 if(strcmp("ssh-ed25519", (const char *)buf) == 0) { - if(key_type == NULL || strcmp("ssh-ed25519", key_type) == 0) { + if(!key_type || strcmp("ssh-ed25519", key_type) == 0) { rc = gen_publickey_from_ed25519_openssh_priv_data(session, decrypted, method, @@ -3528,7 +3528,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, } if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { - if(key_type == NULL || + if(!key_type || strcmp("sk-ssh-ed25519@openssh.com", key_type) == 0) { rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, decrypted, @@ -3546,7 +3546,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, #endif #if LIBSSH2_RSA if(strcmp("ssh-rsa", (const char *)buf) == 0) { - if(key_type == NULL || strcmp("ssh-rsa", key_type) == 0) { + if(!key_type || strcmp("ssh-rsa", key_type) == 0) { rc = gen_publickey_from_rsa_openssh_priv_data(session, decrypted, method, method_len, pubkeydata, @@ -3557,7 +3557,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, #endif #if LIBSSH2_DSA if(strcmp("ssh-dss", (const char *)buf) == 0) { - if(key_type == NULL || strcmp("ssh-dss", key_type) == 0) { + if(!key_type || strcmp("ssh-dss", key_type) == 0) { rc = gen_publickey_from_dsa_openssh_priv_data(session, decrypted, method, method_len, pubkeydata, @@ -3582,7 +3582,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, } else if(_libssh2_ecdsa_curve_type_from_name((const char *)buf, &type) == 0) { - if(key_type == NULL || strcmp("ssh-ecdsa", key_type) == 0) { + if(!key_type || strcmp("ssh-ecdsa", key_type) == 0) { rc = gen_publickey_from_ecdsa_openssh_priv_data(session, type, decrypted, method, method_len, @@ -3626,14 +3626,14 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, unsigned char *buf = NULL; struct string_buf *decrypted = NULL; - if(key_ctx != NULL) + if(key_ctx) *key_ctx = NULL; - if(session == NULL) + if(!session) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Session is required"); - if(key_type != NULL && strlen(key_type) < 7) + if(key_type && strlen(key_type) < 7) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "type is invalid"); @@ -3649,7 +3649,7 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, /* We have a new key file, now try and parse it using supported types */ rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || buf == NULL) + if(rc || !buf) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Public key type in decrypted " "key data not found"); @@ -3659,7 +3659,7 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, #if LIBSSH2_ED25519 if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { *algorithm = LIBSSH2_HOSTKEY_TYPE_ED25519; - if(key_type == NULL || + if(!key_type || strcmp("sk-ssh-ed25519@openssh.com", key_type) == 0) { rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, decrypted, @@ -3748,7 +3748,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); - if(pk == NULL) { + if(!pk) { /* Try OpenSSH format */ st = _libssh2_pub_priv_openssh_keyfilememory(session, NULL, NULL, method, @@ -3842,7 +3842,7 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); - if(pk == NULL) { + if(!pk) { /* Try OpenSSH format */ st = _libssh2_sk_pub_openssh_keyfilememory(session, NULL, NULL, method, diff --git a/src/packet.c b/src/packet.c index 644386a8e6..a5e32d1780 100644 --- a/src/packet.c +++ b/src/packet.c @@ -649,7 +649,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, _libssh2_get_string(&buf, &name, &name_len); _libssh2_get_string(&buf, &value, &value_len); - if(name != NULL && value != NULL) { + if(name && value) { _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server to Client extension %.*s: %.*s", diff --git a/src/pem.c b/src/pem.c index e4dc1f742a..69120e642e 100644 --- a/src/pem.c +++ b/src/pem.c @@ -142,6 +142,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, } all_methods = libssh2_crypt_methods(); + /* !checksrc! disable EQUALSNULL 1 */ while((cur_method = *all_methods++) != NULL) { if(*cur_method->pem_annotation && memcmp(line, cur_method->pem_annotation, @@ -153,7 +154,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, } /* None of the available crypt methods were able to decrypt the key */ - if(method == NULL) + if(!method) return -1; /* Decode IV from hex */ @@ -441,7 +442,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, kdf_buf.len = kdf_len; } - if((passphrase == NULL || strlen((const char *)passphrase) == 0) && + if((!passphrase || strlen((const char *)passphrase) == 0) && strcmp((const char *)ciphername, "none") != 0) { /* passphrase required */ ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED; @@ -491,6 +492,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, const LIBSSH2_CRYPT_METHOD **all_methods, *cur_method; all_methods = libssh2_crypt_methods(); + /* !checksrc! disable EQUALSNULL 1 */ while((cur_method = *all_methods++) != NULL) { if(*cur_method->name && memcmp(ciphername, cur_method->name, @@ -501,7 +503,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, /* None of the available crypt methods were able to decrypt the key */ - if(method == NULL) { + if(!method) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "No supported cipher found"); goto out; @@ -518,14 +520,13 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, total_len = keylen + ivlen; key = LIBSSH2_CALLOC(session, total_len); - if(key == NULL) { + if(!key) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Could not alloc key"); goto out; } - if(strcmp((const char *)kdfname, "bcrypt") == 0 && - passphrase != NULL) { + if(strcmp((const char *)kdfname, "bcrypt") == 0 && passphrase) { if((_libssh2_get_string(&kdf_buf, &salt, &salt_len)) || (_libssh2_get_u32(&kdf_buf, &rounds) != 0) ) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -555,14 +556,14 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, blocksize = method->blocksize; key_part = LIBSSH2_CALLOC(session, keylen); - if(key_part == NULL) { + if(!key_part) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Could not alloc key part"); goto out; } iv_part = LIBSSH2_CALLOC(session, ivlen); - if(iv_part == NULL) { + if(!iv_part) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Could not alloc iv part"); goto out; @@ -613,7 +614,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, goto out; } - if(decrypted_buf != NULL) { + if(decrypted_buf) { /* copy data to out-going buffer */ struct string_buf *out_buf = _libssh2_string_buf_new(session); if(!out_buf) { @@ -624,7 +625,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, } out_buf->data = LIBSSH2_CALLOC(session, decrypted.len); - if(out_buf->data == NULL) { + if(!out_buf->data) { ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for " "decrypted struct"); @@ -745,7 +746,7 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session, size_t off = 0; int ret; - if(filedata == NULL || filedata_len <= 0) + if(!filedata || filedata_len <= 0) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Error parsing PEM: filedata missing"); diff --git a/src/session.c b/src/session.c index a37eccef84..c5800a36de 100644 --- a/src/session.c +++ b/src/session.c @@ -911,8 +911,8 @@ session_free(LIBSSH2_SESSION *session) } if(session->free_state == libssh2_NB_state_created) { + /* !checksrc! disable EQUALSNULL 1 */ while((ch = _libssh2_list_first(&session->channels)) != NULL) { - rc = _libssh2_channel_free(ch); if(rc == LIBSSH2_ERROR_EAGAIN) return rc; @@ -922,6 +922,7 @@ session_free(LIBSSH2_SESSION *session) } if(session->free_state == libssh2_NB_state_sent) { + /* !checksrc! disable EQUALSNULL 1 */ while((l = _libssh2_list_first(&session->listeners)) != NULL) { rc = _libssh2_channel_forward_cancel(l); if(rc == LIBSSH2_ERROR_EAGAIN) @@ -1108,6 +1109,7 @@ session_free(LIBSSH2_SESSION *session) } /* Cleanup all remaining packets */ + /* !checksrc! disable EQUALSNULL 1 */ while((pkg = _libssh2_list_first(&session->packets)) != NULL) { packets_left++; _libssh2_debug((session, LIBSSH2_TRACE_TRANS, @@ -1901,10 +1903,10 @@ LIBSSH2_API const char * libssh2_session_banner_get(LIBSSH2_SESSION *session) { /* to avoid a coredump when session is NULL */ - if(NULL == session) + if(!session) return NULL; - if(NULL == session->remote.banner) + if(!session->remote.banner) return NULL; return (const char *) session->remote.banner; diff --git a/src/sftp.c b/src/sftp.c index f098a45a4a..3736781200 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -508,7 +508,7 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, LIBSSH2_SESSION *session = sftp->channel->session; int rc; - if(data == NULL || data_len == NULL || required_size == 0) { + if(!data || !data_len || required_size == 0) { return LIBSSH2_ERROR_BAD_USE; } @@ -562,7 +562,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses, int i; int rc; - if(data == NULL || data_len == NULL || required_size == 0) { + if(!data || !data_len || required_size == 0) { return LIBSSH2_ERROR_BAD_USE; } @@ -785,7 +785,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) * including *EAGAIN). */ - assert(session->sftpInit_sftp == NULL); + assert(!session->sftpInit_sftp); session->sftpInit_sftp = NULL; session->sftpInit_state = libssh2_NB_state_created; } diff --git a/src/transport.c b/src/transport.c index 14d511e565..f0e99848c3 100644 --- a/src/transport.c +++ b/src/transport.c @@ -202,7 +202,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) /* Check for and deal with decompression */ compressed = - session->local.comp != NULL && + session->local.comp && session->local.comp->compress && ((session->state & LIBSSH2_STATE_AUTHENTICATED) || session->local.comp->use_in_auth); @@ -772,7 +772,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0; compressed = - session->local.comp != NULL && + session->local.comp && session->local.comp->compress && ((session->state & LIBSSH2_STATE_AUTHENTICATED) || session->local.comp->use_in_auth); diff --git a/src/userauth.c b/src/userauth.c index 80fffb0783..274fd0c3a4 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -252,7 +252,7 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *user, LIBSSH2_API int libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner) { - if(NULL == session) + if(!session) return LIBSSH2_ERROR_MISSING_USERAUTH_BANNER; if(!session->userauth_banner) { @@ -261,7 +261,7 @@ libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner) "Missing userauth banner"); } - if(banner != NULL) + if(banner) *banner = session->userauth_banner; return LIBSSH2_ERROR_NONE; @@ -596,7 +596,7 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, } sp1 = memchr(pubkey, ' ', pubkey_len); - if(sp1 == NULL) { + if(!sp1) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid public key data"); @@ -605,7 +605,7 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, sp1++; sp2 = memchr(sp1, ' ', pubkey_len - (sp1 - pubkey)); - if(sp2 == NULL) { + if(!sp2) { /* Assume that the id string is missing, but that it's okay */ sp2 = pubkey + pubkey_len; } @@ -700,7 +700,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, } sp1 = memchr(pubkey, ' ', pubkey_len); - if(sp1 == NULL) { + if(!sp1) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid public key data"); @@ -710,7 +710,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, sp_len = sp1 > pubkey ? (sp1 - pubkey) : 0; sp2 = memchr(sp1, ' ', pubkey_len - sp_len); - if(sp2 == NULL) { + if(!sp2) { /* Assume that the id string is missing, but that it's okay */ sp2 = pubkey + pubkey_len; } @@ -979,7 +979,7 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, LIBSSH2_FREE(session, sig_info.sig_r); - if(sig_info.sig_s != NULL) { + if(sig_info.sig_s) { LIBSSH2_FREE(session, sig_info.sig_s); } } @@ -1305,7 +1305,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, *key_method, *key_method_len); - if(supported_algs == NULL || session->server_sign_algorithms == NULL) { + if(!supported_algs || !session->server_sign_algorithms) { /* no upgrading key algorithm supported, do nothing */ return LIBSSH2_ERROR_NONE; } @@ -1383,7 +1383,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, s = p ? (p + 1) : NULL; } - if(match != NULL) { + if(match) { if(*key_method) LIBSSH2_FREE(session, *key_method); @@ -1923,7 +1923,7 @@ libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session, { int rc; - if(NULL == passphrase) + if(!passphrase) /* if given a NULL pointer, make it point to a zero-length string to save us from having to check this all over */ passphrase = ""; @@ -1951,7 +1951,7 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, { int rc; - if(NULL == passphrase) + if(!passphrase) /* if given a NULL pointer, make it point to a zero-length string to save us from having to check this all over */ passphrase = ""; diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 7e61bc634b..86b5d23d81 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -430,7 +430,7 @@ int start_openssh_fixture(void) } #endif - have_docker = (getenv("OPENSSH_NO_DOCKER") == NULL); + have_docker = !getenv("OPENSSH_NO_DOCKER"); ret = build_openssh_server_docker_image(); if(!ret) { diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index c82413ee81..cb70baeece 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -33,10 +33,12 @@ int test(LIBSSH2_SESSION *session) } channel = libssh2_channel_open_session(session); - /* if(channel == NULL) { */ - /* printf("Error opening channel\n"); */ - /* return 1; */ - /* } */ + #if 0 + if(!channel) { + printf("Error opening channel\n"); + return 1; + } + #endif rc = libssh2_channel_request_auth_agent(channel); if(rc) { From c627c1256bf5c3c79fe9638ed340d22214765c40 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 15 Apr 2023 02:49:52 +0000 Subject: [PATCH 273/424] tidy-up: more whitespace in src Closes #966 --- src/blowfish.c | 12 ++--- src/channel.c | 42 +++++++-------- src/comp.c | 18 +++---- src/crypt.c | 2 +- src/hostkey.c | 90 ++++++++++++++++---------------- src/keepalive.c | 10 ++-- src/kex.c | 134 +++++++++++++++++++++++------------------------- src/knownhost.c | 2 +- src/libgcrypt.c | 45 ++++++++-------- src/mac.c | 32 ++++++------ src/mbedtls.c | 133 +++++++++++++++++++++++------------------------ src/misc.c | 16 +++--- src/openssl.c | 76 +++++++++++++++------------ src/packet.c | 10 ++-- src/pem.c | 12 ++--- src/scp.c | 10 ++-- src/session.c | 28 +++++----- src/sftp.c | 18 +++---- src/sftp.h | 2 +- src/transport.c | 40 +++++++-------- src/userauth.c | 36 ++++++------- src/wincng.c | 22 ++++---- 22 files changed, 396 insertions(+), 394 deletions(-) diff --git a/src/blowfish.c b/src/blowfish.c index 40134ef38b..b580b71712 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -62,8 +62,8 @@ /* Blowfish context */ typedef struct BlowfishContext { - uint32_t S[4][256]; /* S-Boxes */ - uint32_t P[BLF_N + 2]; /* Subkeys */ + uint32_t S[4][256]; /* S-Boxes */ + uint32_t P[BLF_N + 2]; /* Subkeys */ } blf_ctx; /* Raw access to customized Blowfish @@ -104,10 +104,10 @@ static uint32_t Blowfish_stream2word(const uint8_t *, uint16_t, uint16_t *); /* Function for Feistel Networks */ -#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \ - + (s)[0x100 + (((x)>>16)&0xFF)]) \ - ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \ - + (s)[0x300 + ( (x) &0xFF)]) +#define F(s, x) ((((s)[ (((x) >> 24) & 0xFF)] \ + + (s)[0x100 + (((x) >> 16) & 0xFF)]) \ + ^ (s)[0x200 + (((x) >> 8) & 0xFF)]) \ + + (s)[0x300 + ( (x) & 0xFF)]) #define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n]) diff --git a/src/channel.c b/src/channel.c index 4573556e25..ef8827fc91 100644 --- a/src/channel.c +++ b/src/channel.c @@ -327,14 +327,14 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, /* Clear out packets meant for this channel */ _libssh2_htonu32(channel_id, session->open_channel->local.id); while((_libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA, - &session->open_data, - &session->open_data_len, 1, - channel_id, 4) >= 0) - || - (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA, - &session->open_data, - &session->open_data_len, 1, - channel_id, 4) >= 0)) { + &session->open_data, + &session->open_data_len, 1, + channel_id, 4) >= 0) + || + (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA, + &session->open_data, + &session->open_data_len, 1, + channel_id, 4) >= 0)) { LIBSSH2_FREE(session, session->open_data); session->open_data = NULL; } @@ -1181,10 +1181,10 @@ static int channel_request_auth_agent(LIBSSH2_CHANNEL *channel, size_t data_len; unsigned char code; - rc = _libssh2_packet_requirev( - session, reply_codes, &data, &data_len, 1, - channel->req_auth_agent_local_channel, - 4, &channel->req_auth_agent_requirev_state); + rc = _libssh2_packet_requirev(session, reply_codes, &data, &data_len, + 1, channel->req_auth_agent_local_channel, + 4, + &channel->req_auth_agent_requirev_state); if(rc == LIBSSH2_ERROR_EAGAIN) { return rc; } @@ -1300,9 +1300,9 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width, sizeof(channel->reqPTY_packet_requirev_state)); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "changing tty size on channel %lu/%lu", - channel->local.id, - channel->remote.id)); + "changing tty size on channel %lu/%lu", + channel->local.id, + channel->remote.id)); s = channel->reqPTY_packet; @@ -1654,7 +1654,7 @@ LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL * channel, int blocking) { if(channel) - (void) _libssh2_session_set_blocking(channel->session, blocking); + (void)_libssh2_session_set_blocking(channel->session, blocking); } /* @@ -2387,7 +2387,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, */ session->socket_block_directions = LIBSSH2_SESSION_BLOCK_INBOUND; - return (rc == LIBSSH2_ERROR_EAGAIN?rc:0); + return rc == LIBSSH2_ERROR_EAGAIN ? rc : 0; } channel->write_bufwrite = buflen; @@ -2855,10 +2855,10 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel) /* Clear out packets meant for this channel */ _libssh2_htonu32(channel_id, channel->local.id); while((_libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA, &data, - &data_len, 1, channel_id, 4) >= 0) - || - (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA, &data, - &data_len, 1, channel_id, 4) >= 0)) { + &data_len, 1, channel_id, 4) >= 0) + || + (_libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA, &data, + &data_len, 1, channel_id, 4) >= 0)) { LIBSSH2_FREE(session, data); } diff --git a/src/comp.c b/src/comp.c index cd1146e47c..527c516ad0 100644 --- a/src/comp.c +++ b/src/comp.c @@ -61,12 +61,12 @@ comp_method_none_comp(LIBSSH2_SESSION *session, size_t src_len, void **abstract) { - (void) session; - (void) abstract; - (void) dest; - (void) dest_len; - (void) src; - (void) src_len; + (void)session; + (void)abstract; + (void)dest; + (void)dest_len; + (void)src; + (void)src_len; return 0; } @@ -84,9 +84,9 @@ comp_method_none_decomp(LIBSSH2_SESSION * session, const unsigned char *src, size_t src_len, void **abstract) { - (void) session; - (void) payload_limit; - (void) abstract; + (void)session; + (void)payload_limit; + (void)abstract; *dest = (unsigned char *) src; *dest_len = src_len; return 0; diff --git a/src/crypt.c b/src/crypt.c index aefada0846..fbeb5a5a82 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -54,7 +54,7 @@ */ static int crypt_none_crypt(LIBSSH2_SESSION * session, unsigned char *buf, - void **abstract) + void **abstract) { /* Do nothing to the data! */ return 0; diff --git a/src/hostkey.c b/src/hostkey.c index 5384593f81..2eda90fd44 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -200,7 +200,7 @@ hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION * session, size_t m_len, void **abstract) { libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); - (void) session; + (void)session; /* Skip past keyname_len(4) + keyname(7){"ssh-rsa"} + signature_len(4) */ if(sig_len < 15) @@ -260,13 +260,13 @@ hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session, static int hostkey_method_ssh_rsa_sha2_256_sig_verify(LIBSSH2_SESSION * session, - const unsigned char *sig, - size_t sig_len, - const unsigned char *m, - size_t m_len, void **abstract) + const unsigned char *sig, + size_t sig_len, + const unsigned char *m, + size_t m_len, void **abstract) { libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); - (void) session; + (void)session; /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-256"} + signature_len(4) */ @@ -287,11 +287,11 @@ hostkey_method_ssh_rsa_sha2_256_sig_verify(LIBSSH2_SESSION * session, static int hostkey_method_ssh_rsa_sha2_256_signv(LIBSSH2_SESSION * session, - unsigned char **signature, - size_t *signature_len, - int veccount, - const struct iovec datavec[], - void **abstract) + unsigned char **signature, + size_t *signature_len, + int veccount, + const struct iovec datavec[], + void **abstract) { libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); @@ -330,13 +330,13 @@ hostkey_method_ssh_rsa_sha2_256_signv(LIBSSH2_SESSION * session, static int hostkey_method_ssh_rsa_sha2_512_sig_verify(LIBSSH2_SESSION * session, - const unsigned char *sig, - size_t sig_len, - const unsigned char *m, - size_t m_len, void **abstract) + const unsigned char *sig, + size_t sig_len, + const unsigned char *m, + size_t m_len, void **abstract) { libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); - (void) session; + (void)session; /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-512"} + signature_len(4) */ @@ -357,11 +357,11 @@ hostkey_method_ssh_rsa_sha2_512_sig_verify(LIBSSH2_SESSION * session, */ static int hostkey_method_ssh_rsa_sha2_512_signv(LIBSSH2_SESSION * session, - unsigned char **signature, - size_t *signature_len, - int veccount, - const struct iovec datavec[], - void **abstract) + unsigned char **signature, + size_t *signature_len, + int veccount, + const struct iovec datavec[], + void **abstract) { libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); @@ -404,7 +404,7 @@ static int hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract) { libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); - (void) session; + (void)session; _libssh2_rsa_free(rsactx); @@ -673,7 +673,7 @@ static int hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, void **abstract) { libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract); - (void) session; + (void)session; _libssh2_dsa_free(dsactx); @@ -712,9 +712,9 @@ hostkey_method_ssh_ecdsa_dtor(LIBSSH2_SESSION * session, */ static int hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session, - const unsigned char *hostkey_data, - size_t hostkey_data_len, - void **abstract) + const unsigned char *hostkey_data, + size_t hostkey_data_len, + void **abstract) { libssh2_ecdsa_ctx *ecdsactx = NULL; unsigned char *type_str, *domain, *public_key; @@ -793,9 +793,9 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session, */ static int hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session, - const char *privkeyfile, - unsigned const char *passphrase, - void **abstract) + const char *privkeyfile, + unsigned const char *passphrase, + void **abstract) { libssh2_ecdsa_ctx *ec_ctx = NULL; int ret; @@ -821,10 +821,10 @@ hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION * session, */ static int hostkey_method_ssh_ecdsa_initPEMFromMemory(LIBSSH2_SESSION * session, - const char *privkeyfiledata, - size_t privkeyfiledata_len, - unsigned const char *passphrase, - void **abstract) + const char *privkeyfiledata, + size_t privkeyfiledata_len, + unsigned const char *passphrase, + void **abstract) { libssh2_ecdsa_ctx *ec_ctx = NULL; int ret; @@ -866,7 +866,7 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session, struct string_buf buf; libssh2_ecdsa_ctx *ctx = (libssh2_ecdsa_ctx *) (*abstract); - (void) session; + (void)session; if(sig_len < 35) return -1; @@ -952,7 +952,7 @@ static int hostkey_method_ssh_ecdsa_dtor(LIBSSH2_SESSION * session, void **abstract) { libssh2_ecdsa_ctx *keyctx = (libssh2_ecdsa_ctx *) (*abstract); - (void) session; + (void)session; if(keyctx) _libssh2_ecdsa_free(keyctx); @@ -1102,9 +1102,9 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session, */ static int hostkey_method_ssh_ed25519_initPEM(LIBSSH2_SESSION * session, - const char *privkeyfile, - unsigned const char *passphrase, - void **abstract) + const char *privkeyfile, + unsigned const char *passphrase, + void **abstract) { libssh2_ed25519_ctx *ec_ctx = NULL; int ret; @@ -1172,7 +1172,7 @@ hostkey_method_ssh_ed25519_sig_verify(LIBSSH2_SESSION * session, size_t m_len, void **abstract) { libssh2_ed25519_ctx *ctx = (libssh2_ed25519_ctx *) (*abstract); - (void) session; + (void)session; if(sig_len < 19) return -1; @@ -1195,11 +1195,11 @@ hostkey_method_ssh_ed25519_sig_verify(LIBSSH2_SESSION * session, */ static int hostkey_method_ssh_ed25519_signv(LIBSSH2_SESSION * session, - unsigned char **signature, - size_t *signature_len, - int veccount, - const struct iovec datavec[], - void **abstract) + unsigned char **signature, + size_t *signature_len, + int veccount, + const struct iovec datavec[], + void **abstract) { libssh2_ed25519_ctx *ctx = (libssh2_ed25519_ctx *) (*abstract); @@ -1221,7 +1221,7 @@ static int hostkey_method_ssh_ed25519_dtor(LIBSSH2_SESSION * session, void **abstract) { libssh2_ed25519_ctx *keyctx = (libssh2_ed25519_ctx*) (*abstract); - (void) session; + (void)session; if(keyctx) _libssh2_ed25519_free(keyctx); diff --git a/src/keepalive.c b/src/keepalive.c index 2151b17100..f34255d765 100644 --- a/src/keepalive.c +++ b/src/keepalive.c @@ -42,9 +42,9 @@ /* Keep-alive stuff. */ LIBSSH2_API void -libssh2_keepalive_config (LIBSSH2_SESSION *session, - int want_reply, - unsigned interval) +libssh2_keepalive_config(LIBSSH2_SESSION *session, + int want_reply, + unsigned interval) { if(interval == 1) session->keepalive_interval = 2; @@ -54,8 +54,8 @@ libssh2_keepalive_config (LIBSSH2_SESSION *session, } LIBSSH2_API int -libssh2_keepalive_send (LIBSSH2_SESSION *session, - int *seconds_to_next) +libssh2_keepalive_send(LIBSSH2_SESSION *session, + int *seconds_to_next) { time_t now; diff --git a/src/kex.c b/src/kex.c index 2b12fdfba6..53f07a5af6 100644 --- a/src/kex.c +++ b/src/kex.c @@ -176,10 +176,10 @@ static void _libssh2_sha_algo_ctx_final(int sha_algo, void *ctx, } static void _libssh2_sha_algo_value_hash(int sha_algo, - LIBSSH2_SESSION *session, - kmdhgGPshakex_state_t *exchange_state, - unsigned char **data, size_t data_len, - const unsigned char *version) + LIBSSH2_SESSION *session, + kmdhgGPshakex_state_t *exchange_state, + unsigned char **data, size_t data_len, + const unsigned char *version) { if(sha_algo == 512) { LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(512, *data, data_len, version); @@ -234,7 +234,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, digest_len = SHA1_DIGEST_LENGTH; else { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "sha algo value is unimplemented"); + "sha algo value is unimplemented"); goto clean_exit; } @@ -479,8 +479,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, if(session->hostkey->init(session, session->server_hostkey, - session->server_hostkey_len, - &session->server_hostkey_abstract)) { + session->server_hostkey_len, + &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, "Unable to initialize hostkey importer"); goto clean_exit; @@ -537,8 +537,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 4); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - session->local.banner, - strlen((char *) session->local.banner) - 2); + session->local.banner, + strlen((char *) session->local.banner) - 2); } else { _libssh2_htonu32(exchange_state->h_sig_comp, @@ -546,9 +546,9 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, exchange_state->h_sig_comp, 4); _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - (unsigned char *) - LIBSSH2_SSH_DEFAULT_BANNER, - sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); + (unsigned char *) + LIBSSH2_SSH_DEFAULT_BANNER, + sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); } _libssh2_htonu32(exchange_state->h_sig_comp, @@ -853,7 +853,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, if(session->local.comp && session->local.comp->init) { if(session->local.comp->init(session, 1, - &session->local.comp_abstract)) { + &session->local.comp_abstract)) { ret = LIBSSH2_ERROR_KEX_FAILURE; goto clean_exit; } @@ -868,7 +868,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, if(session->remote.comp && session->remote.comp->init) { if(session->remote.comp->init(session, 0, - &session->remote.comp_abstract)) { + &session->remote.comp_abstract)) { ret = LIBSSH2_ERROR_KEX_FAILURE; goto clean_exit; } @@ -1050,8 +1050,8 @@ kex_method_diffie_hellman_group14_key_exchange(LIBSSH2_SESSION *session, key_state->state = libssh2_NB_state_created; } ret = hashfunc(session, key_state->g, key_state->p, - 256, sha_algo_value, exchange_hash_ctx, SSH_MSG_KEXDH_INIT, - SSH_MSG_KEXDH_REPLY, NULL, 0, &key_state->exchange_state); + 256, sha_algo_value, exchange_hash_ctx, SSH_MSG_KEXDH_INIT, + SSH_MSG_KEXDH_REPLY, NULL, 0, &key_state->exchange_state); if(ret == LIBSSH2_ERROR_EAGAIN) { return ret; } @@ -1077,9 +1077,9 @@ kex_method_diffie_hellman_group14_sha1_key_exchange(LIBSSH2_SESSION *session, { libssh2_sha1_ctx ctx; return kex_method_diffie_hellman_group14_key_exchange(session, - key_state, 1, - &ctx, - diffie_hellman_sha_algo); + key_state, 1, + &ctx, + diffie_hellman_sha_algo); } @@ -1094,9 +1094,9 @@ kex_method_diffie_hellman_group14_sha256_key_exchange(LIBSSH2_SESSION *session, { libssh2_sha256_ctx ctx; return kex_method_diffie_hellman_group14_key_exchange(session, - key_state, 256, - &ctx, - diffie_hellman_sha_algo); + key_state, 256, + &ctx, + diffie_hellman_sha_algo); } /* kex_method_diffie_hellman_group16_sha512_key_exchange @@ -1325,8 +1325,9 @@ kex_method_diffie_hellman_group18_sha512_key_exchange(LIBSSH2_SESSION *session, * Negotiates random(ish) group for secret derivation */ static int -kex_method_diffie_hellman_group_exchange_sha1_key_exchange -(LIBSSH2_SESSION * session, key_exchange_state_low_t * key_state) +kex_method_diffie_hellman_group_exchange_sha1_key_exchange( + LIBSSH2_SESSION * session, + key_exchange_state_low_t * key_state) { int ret = 0; int rc; @@ -1442,8 +1443,9 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange * Negotiates random(ish) group for secret derivation */ static int -kex_method_diffie_hellman_group_exchange_sha256_key_exchange -(LIBSSH2_SESSION * session, key_exchange_state_low_t * key_state) +kex_method_diffie_hellman_group_exchange_sha256_key_exchange( + LIBSSH2_SESSION * session, + key_exchange_state_low_t * key_state) { int ret = 0; int rc; @@ -1741,7 +1743,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, buf.dataptr = buf.data; buf.dataptr++; /* Advance past packet type */ - if(_libssh2_copy_string(session, &buf, &(session->server_hostkey), + if(_libssh2_copy_string(session, &buf, &(session->server_hostkey), &server_public_key_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for a copy " @@ -1840,8 +1842,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, #endif /* LIBSSH2DEBUG */ if(session->hostkey->init(session, session->server_hostkey, - session->server_hostkey_len, - &session->server_hostkey_abstract)) { + session->server_hostkey_len, + &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, "Unable to initialize hostkey importer"); goto clean_exit; @@ -2006,8 +2008,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, } LIBSSH2_KEX_METHOD_EC_SHA_VALUE_HASH(secret, - session->local.crypt-> - secret_len, "C"); + session->local.crypt-> + secret_len, "C"); if(!secret) { LIBSSH2_FREE(session, iv); @@ -2151,7 +2153,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(session->local.comp && session->local.comp->init) { if(session->local.comp->init(session, 1, - &session->local.comp_abstract)) { + &session->local.comp_abstract)) { ret = LIBSSH2_ERROR_KEX_FAILURE; goto clean_exit; } @@ -2166,14 +2168,13 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(session->remote.comp && session->remote.comp->init) { if(session->remote.comp->init(session, 0, - &session->remote.comp_abstract)) { + &session->remote.comp_abstract)) { ret = LIBSSH2_ERROR_KEX_FAILURE; goto clean_exit; } } _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server to Client compression initialized")); - } clean_exit: @@ -2322,7 +2323,6 @@ kex_method_ecdh_key_exchange /* curve25519_sha256 * Elliptic Curve Key Exchange */ - static int curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, size_t data_len, @@ -2472,8 +2472,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, #endif /* LIBSSH2DEBUG */ if(session->hostkey->init(session, session->server_hostkey, - session->server_hostkey_len, - &session->server_hostkey_abstract)) { + session->server_hostkey_len, + &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, "Unable to initialize hostkey importer"); goto clean_exit; @@ -2483,7 +2483,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(_libssh2_get_string(&buf, &server_public_key, &server_public_key_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected key length"); goto clean_exit; } @@ -2604,7 +2604,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, /* Cleanup any existing cipher */ if(session->local.crypt->dtor) { session->local.crypt->dtor(session, - &session->local.crypt_abstract); + &session->local.crypt_abstract); } /* Calculate IV/Secret/Key for each direction */ @@ -2766,7 +2766,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(session->local.comp && session->local.comp->init) { if(session->local.comp->init(session, 1, - &session->local.comp_abstract)) { + &session->local.comp_abstract)) { ret = LIBSSH2_ERROR_KEX_FAILURE; goto clean_exit; } @@ -2776,12 +2776,12 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(session->remote.comp && session->remote.comp->dtor) { session->remote.comp->dtor(session, 0, - &session->remote.comp_abstract); + &session->remote.comp_abstract); } if(session->remote.comp && session->remote.comp->init) { if(session->remote.comp->init(session, 0, - &session->remote.comp_abstract)) { + &session->remote.comp_abstract)) { ret = LIBSSH2_ERROR_KEX_FAILURE; goto clean_exit; } @@ -2809,7 +2809,6 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, * Elliptic Curve X25519 Key Exchange with SHA256 hash * */ - static int kex_method_curve25519_key_exchange (LIBSSH2_SESSION * session, key_exchange_state_low_t * key_state) @@ -3042,7 +3041,7 @@ static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { &kex_method_diffie_helman_group1_sha1, &kex_method_diffie_helman_group_exchange_sha1, &kex_method_extension_negotiation, - NULL + NULL }; typedef struct _LIBSSH2_COMMON_METHOD @@ -3105,7 +3104,7 @@ kex_method_list(unsigned char *buf, uint32_t list_strlen, #define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) \ (uint32_t)((prefvar) ? strlen(prefvar) : \ - kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar))) + kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar))) #define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \ do { \ @@ -3168,8 +3167,8 @@ static int kexinit(LIBSSH2_SESSION * session) LIBSSH2_METHOD_PREFS_LEN(session->remote.lang_prefs, NULL); data_len += kex_len + hostkey_len + crypt_cs_len + crypt_sc_len + - comp_cs_len + comp_sc_len + mac_cs_len + mac_sc_len + - lang_cs_len + lang_sc_len; + comp_cs_len + comp_sc_len + mac_cs_len + mac_sc_len + + lang_cs_len + lang_sc_len; s = data = LIBSSH2_ALLOC(session, data_len); if(!data) { @@ -3478,7 +3477,7 @@ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex, * Can we agree on a hostkey that works with this kex? */ if(kex_agree_hostkey(session, method->flags, hostkey, - hostkey_len) == 0) { + hostkey_len) == 0) { session->kex = method; if(session->burn_optimistic_kexinit && (kex == q)) { /* Server sent an optimistic packet, and client agrees @@ -3504,7 +3503,7 @@ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex, * Can we agree on a hostkey that works with this kex? */ if(kex_agree_hostkey(session, (*kexp)->flags, hostkey, - hostkey_len) == 0) { + hostkey_len) == 0) { session->kex = *kexp; if(session->burn_optimistic_kexinit && (kex == s)) { /* Server sent an optimistic packet, and client agrees @@ -3533,7 +3532,7 @@ static int kex_agree_crypt(LIBSSH2_SESSION * session, const LIBSSH2_CRYPT_METHOD **cryptp = libssh2_crypt_methods(); unsigned char *s; - (void) session; + (void)session; if(endpoint->crypt_prefs) { s = (unsigned char *) endpoint->crypt_prefs; @@ -3588,7 +3587,7 @@ static int kex_agree_mac(LIBSSH2_SESSION * session, { const LIBSSH2_MAC_METHOD **macp = _libssh2_mac_methods(); unsigned char *s; - (void) session; + (void)session; if(endpoint->mac_prefs) { s = (unsigned char *) endpoint->mac_prefs; @@ -3641,7 +3640,7 @@ static int kex_agree_comp(LIBSSH2_SESSION *session, { const LIBSSH2_COMP_METHOD **compp = _libssh2_comp_methods(session); unsigned char *s; - (void) session; + (void)session; if(endpoint->comp_prefs) { s = (unsigned char *) endpoint->comp_prefs; @@ -3890,7 +3889,7 @@ _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, session->remote.kexinit_len = key_state->data_len; if(kex_agree_methods(session, key_state->data, - key_state->data_len)) + key_state->data_len)) rc = LIBSSH2_ERROR_KEX_FAILURE; key_state->state = libssh2_NB_state_sent2; @@ -3950,44 +3949,42 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, switch(method_type) { case LIBSSH2_METHOD_KEX: prefvar = &session->kex_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_kex_methods; + mlist = (const LIBSSH2_COMMON_METHOD **)libssh2_kex_methods; break; case LIBSSH2_METHOD_HOSTKEY: prefvar = &session->hostkey_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_hostkey_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)libssh2_hostkey_methods(); break; case LIBSSH2_METHOD_CRYPT_CS: prefvar = &session->local.crypt_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_crypt_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)libssh2_crypt_methods(); break; case LIBSSH2_METHOD_CRYPT_SC: prefvar = &session->remote.crypt_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_crypt_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)libssh2_crypt_methods(); break; case LIBSSH2_METHOD_MAC_CS: prefvar = &session->local.mac_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) _libssh2_mac_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)_libssh2_mac_methods(); break; case LIBSSH2_METHOD_MAC_SC: prefvar = &session->remote.mac_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) _libssh2_mac_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)_libssh2_mac_methods(); break; case LIBSSH2_METHOD_COMP_CS: prefvar = &session->local.comp_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) - _libssh2_comp_methods(session); + mlist = (const LIBSSH2_COMMON_METHOD **)_libssh2_comp_methods(session); break; case LIBSSH2_METHOD_COMP_SC: prefvar = &session->remote.comp_prefs; - mlist = (const LIBSSH2_COMMON_METHOD **) - _libssh2_comp_methods(session); + mlist = (const LIBSSH2_COMMON_METHOD **)_libssh2_comp_methods(session); break; case LIBSSH2_METHOD_LANG_CS: @@ -4077,27 +4074,26 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, switch(method_type) { case LIBSSH2_METHOD_KEX: - mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_kex_methods; + mlist = (const LIBSSH2_COMMON_METHOD **)libssh2_kex_methods; break; case LIBSSH2_METHOD_HOSTKEY: - mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_hostkey_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)libssh2_hostkey_methods(); break; case LIBSSH2_METHOD_CRYPT_CS: case LIBSSH2_METHOD_CRYPT_SC: - mlist = (const LIBSSH2_COMMON_METHOD **) libssh2_crypt_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)libssh2_crypt_methods(); break; case LIBSSH2_METHOD_MAC_CS: case LIBSSH2_METHOD_MAC_SC: - mlist = (const LIBSSH2_COMMON_METHOD **) _libssh2_mac_methods(); + mlist = (const LIBSSH2_COMMON_METHOD **)_libssh2_mac_methods(); break; case LIBSSH2_METHOD_COMP_CS: case LIBSSH2_METHOD_COMP_SC: - mlist = (const LIBSSH2_COMMON_METHOD **) - _libssh2_comp_methods(session); + mlist = (const LIBSSH2_COMMON_METHOD **)_libssh2_comp_methods(session); break; case LIBSSH2_METHOD_SIGN_ALGO: diff --git a/src/knownhost.c b/src/knownhost.c index c43762f8cd..30a464514a 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -122,7 +122,7 @@ static struct libssh2_knownhost *knownhost_to_external(struct known_host *node) ext->magic = KNOWNHOST_MAGIC; ext->node = node; ext->name = ((node->typemask & LIBSSH2_KNOWNHOST_TYPE_MASK) == - LIBSSH2_KNOWNHOST_TYPE_PLAIN)? node->name:NULL; + LIBSSH2_KNOWNHOST_TYPE_PLAIN) ? node->name : NULL; ext->key = node->key; ext->typemask = node->typemask; diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 1ef4d521aa..1013129b9a 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -59,17 +59,17 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, const unsigned char *coeffdata, unsigned long coefflen) { int rc; - (void) e1data; - (void) e1len; - (void) e2data; - (void) e2len; + + (void)e1data; + (void)e1len; + (void)e2data; + (void)e2len; if(ddata) { - rc = gcry_sexp_build - (rsa, NULL, - "(private-key(rsa(n%b)(e%b)(d%b)(q%b)(p%b)(u%b)))", - nlen, ndata, elen, edata, dlen, ddata, plen, pdata, - qlen, qdata, coefflen, coeffdata); + rc = gcry_sexp_build(rsa, NULL, + "(private-key(rsa(n%b)(e%b)(d%b)(q%b)(p%b)(u%b)))", + nlen, ndata, elen, edata, dlen, ddata, plen, pdata, + qlen, qdata, coefflen, coeffdata); } else { rc = gcry_sexp_build(rsa, NULL, "(public-key(rsa(n%b)(e%b)))", @@ -130,10 +130,9 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, int rc; if(x_len) { - rc = gcry_sexp_build - (dsactx, NULL, - "(private-key(dsa(p%b)(q%b)(g%b)(y%b)(x%b)))", - p_len, p, q_len, q, g_len, g, y_len, y, x_len, x); + rc = gcry_sexp_build(dsactx, NULL, + "(private-key(dsa(p%b)(q%b)(g%b)(y%b)(x%b)))", + p_len, p, q_len, q, g_len, g, y_len, y, x_len, x); } else { rc = gcry_sexp_build(dsactx, NULL, @@ -198,7 +197,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, ret = -1; goto fail; } -/* First read Version field (should be 0). */ + /* First read Version field (should be 0). */ ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen); if(ret || (nlen != 1 && *n != '\0')) { ret = -1; @@ -254,7 +253,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, } if(_libssh2_rsa_new(rsa, e, elen, n, nlen, d, dlen, p, plen, - q, qlen, e1, e1len, e2, e2len, coeff, coefflen)) { + q, qlen, e1, e1len, e2, e2len, coeff, coefflen)) { ret = -1; goto fail; } @@ -316,7 +315,7 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, goto fail; } -/* First read Version field (should be 0). */ + /* First read Version field (should be 0). */ ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen); if(ret || (plen != 1 && *p != '\0')) { ret = -1; @@ -388,8 +387,8 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, } if(gcry_sexp_build(&data, NULL, - "(data (flags pkcs1) (hash sha1 %b))", - hash_len, hash)) { + "(data (flags pkcs1) (hash sha1 %b))", + hash_len, hash)) { return -1; } @@ -464,7 +463,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, memset(sig, 0, 40); -/* Extract R. */ + /* Extract R. */ data = gcry_sexp_find_token(sig_sexp, "r", 0); if(!data) @@ -486,7 +485,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, gcry_sexp_release(data); -/* Extract S. */ + /* Extract S. */ data = gcry_sexp_find_token(sig_sexp, "s", 0); if(!data) @@ -533,12 +532,12 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, hash[0] = 0; if(gcry_sexp_build(&s_hash, NULL, "(data(flags raw)(value %b))", - SHA_DIGEST_LENGTH + 1, hash)) { + SHA_DIGEST_LENGTH + 1, hash)) { return -1; } if(gcry_sexp_build(&s_sig, NULL, "(sig-val(dsa(r %b)(s %b)))", - 20, sig, 20, sig + 20)) { + 20, sig, 20, sig + 20)) { gcry_sexp_release(s_hash); return -1; } @@ -560,7 +559,7 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, int mode = _libssh2_gcry_mode(algo); size_t keylen = gcry_cipher_get_algo_keylen(cipher); - (void) encrypt; + (void)encrypt; ret = gcry_cipher_open(h, cipher, mode, 0); if(ret) { diff --git a/src/mac.c b/src/mac.c index f0ce99336d..ca0a415141 100644 --- a/src/mac.c +++ b/src/mac.c @@ -84,7 +84,7 @@ mac_method_common_init(LIBSSH2_SESSION * session, unsigned char *key, { *abstract = key; *free_key = 0; - (void) session; + (void)session; return 0; } @@ -113,15 +113,15 @@ mac_method_common_dtor(LIBSSH2_SESSION * session, void **abstract) */ static int mac_method_hmac_sha2_512_hash(LIBSSH2_SESSION * session, - unsigned char *buf, uint32_t seqno, - const unsigned char *packet, - size_t packet_len, - const unsigned char *addtl, - size_t addtl_len, void **abstract) + unsigned char *buf, uint32_t seqno, + const unsigned char *packet, + size_t packet_len, + const unsigned char *addtl, + size_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; - (void) session; + (void)session; _libssh2_htonu32(seqno_buf, seqno); @@ -158,15 +158,15 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_512 = { */ static int mac_method_hmac_sha2_256_hash(LIBSSH2_SESSION * session, - unsigned char *buf, uint32_t seqno, - const unsigned char *packet, - size_t packet_len, - const unsigned char *addtl, - size_t addtl_len, void **abstract) + unsigned char *buf, uint32_t seqno, + const unsigned char *packet, + size_t packet_len, + const unsigned char *addtl, + size_t addtl_len, void **abstract) { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; - (void) session; + (void)session; _libssh2_htonu32(seqno_buf, seqno); @@ -211,7 +211,7 @@ mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; - (void) session; + (void)session; _libssh2_htonu32(seqno_buf, seqno); @@ -284,7 +284,7 @@ mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; - (void) session; + (void)session; _libssh2_htonu32(seqno_buf, seqno); @@ -357,7 +357,7 @@ mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; - (void) session; + (void)session; _libssh2_htonu32(seqno_buf, seqno); diff --git a/src/mbedtls.c b/src/mbedtls.c index b6e1ba0f6a..e8d4f65209 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -145,8 +145,8 @@ _libssh2_mbedtls_cipher_crypt(_libssh2_cipher_ctx *ctx, unsigned char *output; size_t osize, olen, finish_olen; - (void) encrypt; - (void) algo; + (void)encrypt; + (void)algo; osize = blocklen + mbedtls_cipher_get_block_size(ctx); @@ -182,8 +182,8 @@ _libssh2_mbedtls_cipher_dtor(_libssh2_cipher_ctx *ctx) int _libssh2_mbedtls_hash_init(mbedtls_md_context_t *ctx, - mbedtls_md_type_t mdtype, - const unsigned char *key, unsigned long keylen) + mbedtls_md_type_t mdtype, + const unsigned char *key, unsigned long keylen) { const mbedtls_md_info_t *md_info; int ret, hmac; @@ -315,22 +315,22 @@ _libssh2_mbedtls_bignum_random(_libssh2_bn *bn, int bits, int top, int bottom) int _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, - const unsigned char *edata, - unsigned long elen, - const unsigned char *ndata, - unsigned long nlen, - const unsigned char *ddata, - unsigned long dlen, - const unsigned char *pdata, - unsigned long plen, - const unsigned char *qdata, - unsigned long qlen, - const unsigned char *e1data, - unsigned long e1len, - const unsigned char *e2data, - unsigned long e2len, - const unsigned char *coeffdata, - unsigned long coefflen) + const unsigned char *edata, + unsigned long elen, + const unsigned char *ndata, + unsigned long nlen, + const unsigned char *ddata, + unsigned long dlen, + const unsigned char *pdata, + unsigned long plen, + const unsigned char *qdata, + unsigned long qlen, + const unsigned char *e1data, + unsigned long e1len, + const unsigned char *e2data, + unsigned long e2len, + const unsigned char *coeffdata, + unsigned long coefflen) { int ret; libssh2_rsa_ctx *ctx; @@ -391,9 +391,9 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, int _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa, - LIBSSH2_SESSION *session, - const char *filename, - const unsigned char *passphrase) + LIBSSH2_SESSION *session, + const char *filename, + const unsigned char *passphrase) { int ret; mbedtls_pk_context pkey; @@ -434,10 +434,10 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa, int _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, - LIBSSH2_SESSION *session, - const char *filedata, - size_t filedata_len, - unsigned const char *passphrase) + LIBSSH2_SESSION *session, + const char *filedata, + size_t filedata_len, + unsigned const char *passphrase) { int ret; mbedtls_pk_context pkey; @@ -492,10 +492,10 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, int _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, - size_t hash_len, - const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len) + size_t hash_len, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, unsigned long m_len) { int ret; int md_type; @@ -544,9 +544,9 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, int _libssh2_mbedtls_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, - const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len) + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, unsigned long m_len) { return _libssh2_mbedtls_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, sig, sig_len, m, m_len); @@ -554,11 +554,11 @@ _libssh2_mbedtls_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, int _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, - libssh2_rsa_ctx *rsa, - const unsigned char *hash, - size_t hash_len, - unsigned char **signature, - size_t *signature_len) + libssh2_rsa_ctx *rsa, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, + size_t *signature_len) { int ret; unsigned char *sig; @@ -611,13 +611,14 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session, int _libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION * session, - libssh2_rsa_ctx * rsactx, - const unsigned char *hash, - size_t hash_len, - unsigned char **signature, size_t *signature_len) + libssh2_rsa_ctx * rsactx, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, + size_t *signature_len) { return _libssh2_mbedtls_rsa_sha2_sign(session, rsactx, hash, hash_len, - signature, signature_len); + signature, signature_len); } void @@ -629,8 +630,8 @@ _libssh2_mbedtls_rsa_free(libssh2_rsa_ctx *ctx) static unsigned char * gen_publickey_from_rsa(LIBSSH2_SESSION *session, - mbedtls_rsa_context *rsa, - size_t *keylen) + mbedtls_rsa_context *rsa, + size_t *keylen) { uint32_t e_bytes, n_bytes; uint32_t len; @@ -670,11 +671,11 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, static int _libssh2_mbedtls_pub_priv_key(LIBSSH2_SESSION *session, - unsigned char **method, - size_t *method_len, - unsigned char **pubkeydata, - size_t *pubkeydata_len, - mbedtls_pk_context *pkey) + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + mbedtls_pk_context *pkey) { unsigned char *key = NULL, *mth = NULL; size_t keylen = 0, mthlen = 0; @@ -722,12 +723,12 @@ _libssh2_mbedtls_pub_priv_key(LIBSSH2_SESSION *session, int _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session, - unsigned char **method, - size_t *method_len, - unsigned char **pubkeydata, - size_t *pubkeydata_len, - const char *privatekey, - const char *passphrase) + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + const char *privatekey, + const char *passphrase) { mbedtls_pk_context pkey; char buf[1024]; @@ -748,7 +749,7 @@ _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session, } ret = _libssh2_mbedtls_pub_priv_key(session, method, method_len, - pubkeydata, pubkeydata_len, &pkey); + pubkeydata, pubkeydata_len, &pkey); mbedtls_pk_free(&pkey); @@ -757,13 +758,13 @@ _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session, int _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, - unsigned char **method, - size_t *method_len, - unsigned char **pubkeydata, - size_t *pubkeydata_len, - const char *privatekeydata, - size_t privatekeydata_len, - const char *passphrase) + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + const char *privatekeydata, + size_t privatekeydata_len, + const char *passphrase) { mbedtls_pk_context pkey; char buf[1024]; @@ -806,7 +807,7 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, } ret = _libssh2_mbedtls_pub_priv_key(session, method, method_len, - pubkeydata, pubkeydata_len, &pkey); + pubkeydata, pubkeydata_len, &pkey); mbedtls_pk_free(&pkey); diff --git a/src/misc.c b/src/misc.c index 74c7573f6c..47d9dc8f80 100644 --- a/src/misc.c +++ b/src/misc.c @@ -162,7 +162,7 @@ _libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, { ssize_t rc; - (void) abstract; + (void)abstract; rc = recv(sock, buffer, length, flags); #ifdef WIN32 @@ -195,7 +195,7 @@ _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length, { ssize_t rc; - (void) abstract; + (void)abstract; rc = send(sock, buffer, length, flags); #ifdef WIN32 @@ -372,7 +372,7 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, /* ---- Base64 Encoding/Decoding Table --- */ static const char table64[]= - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* * _libssh2_base64_encode @@ -545,8 +545,8 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION * session, int bitmask) { - (void) session; - (void) bitmask; + (void)session; + (void)bitmask; return 0; } @@ -554,9 +554,9 @@ LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session, void *handler_context, libssh2_trace_handler_func callback) { - (void) session; - (void) handler_context; - (void) callback; + (void)session; + (void)handler_context; + (void)callback; return 0; } #endif diff --git a/src/openssl.c b/src/openssl.c index af5fa6c1fd..23c8d53b05 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -420,9 +420,9 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx, int _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx, - const unsigned char *r, size_t r_len, - const unsigned char *s, size_t s_len, - const unsigned char *m, size_t m_len) + const unsigned char *r, size_t r_len, + const unsigned char *s, size_t s_len, + const unsigned char *m, size_t m_len) { int ret = 0; EC_KEY *ec_key = (EC_KEY*)ctx; @@ -491,8 +491,9 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, unsigned char buf[EVP_MAX_BLOCK_LENGTH]; int ret; int rc = 1; - (void) algo; - (void) encrypt; + + (void)algo; + (void)encrypt; #ifdef HAVE_OPAQUE_STRUCTS ret = EVP_Cipher(*ctx, buf, block, (unsigned int) blocksize); @@ -544,7 +545,8 @@ static int passphrase_cb(char *buf, int size, int rwflag, char *passphrase) { int passphrase_len = (int) strlen(passphrase); - (void) rwflag; + + (void)rwflag; if(passphrase_len > (size - 1)) { passphrase_len = size - 1; @@ -1003,11 +1005,14 @@ _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx ** dsa, _libssh2_init_if_needed(); rc = read_private_key_from_memory((void **)dsa, read_dsa, - filedata, filedata_len, passphrase); + filedata, filedata_len, + passphrase); if(rc) { rc = read_openssh_private_key_from_memory((void **)dsa, session, - "ssh-dsa", filedata, filedata_len, passphrase); + "ssh-dsa", + filedata, filedata_len, + passphrase); } return rc; @@ -1298,9 +1303,10 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, int _libssh2_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx ** ec_ctx, - LIBSSH2_SESSION * session, - const char *filedata, size_t filedata_len, - unsigned const char *passphrase) + LIBSSH2_SESSION * session, + const char *filedata, + size_t filedata_len, + unsigned const char *passphrase) { int rc; @@ -1310,12 +1316,14 @@ _libssh2_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx ** ec_ctx, _libssh2_init_if_needed(); rc = read_private_key_from_memory((void **) ec_ctx, read_ec, - filedata, filedata_len, passphrase); + filedata, filedata_len, + passphrase); if(rc) { rc = read_openssh_private_key_from_memory((void **)ec_ctx, session, - "ssh-ecdsa", filedata, - filedata_len, passphrase); + "ssh-ecdsa", + filedata, filedata_len, + passphrase); } return rc; @@ -1333,7 +1341,7 @@ int _libssh2_ecdsa_new_private_frommemory_sk(libssh2_ecdsa_ctx ** ec_ctx, { int algorithm; return _libssh2_sk_pub_openssh_keyfilememory(session, - (void **)ec_ctx, + (void **)ec_ctx, "sk-ecdsa-sha2-nistp256@openssh.com", NULL, NULL, @@ -1942,7 +1950,8 @@ _libssh2_ed25519_new_private_frommemory(libssh2_ed25519_ctx ** ed_ctx, if(read_private_key_from_memory((void **)&ctx, (pem_read_bio_func) &PEM_read_bio_PrivateKey, - filedata, filedata_len, passphrase) == 0) { + filedata, filedata_len, + passphrase) == 0) { if(EVP_PKEY_id(ctx) != EVP_PKEY_ED25519) { _libssh2_ed25519_free(ctx); return _libssh2_error(session, LIBSSH2_ERROR_PROTO, @@ -2082,7 +2091,8 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, const BIGNUM * r; const BIGNUM * s; int r_len, s_len; - (void) hash_len; + + (void)hash_len; sig = DSA_do_sign(hash, SHA_DIGEST_LENGTH, dsactx); if(!sig) { @@ -2121,8 +2131,8 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, int _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, - const unsigned char *hash, unsigned long hash_len, - unsigned char **signature, size_t *signature_len) + const unsigned char *hash, unsigned long hash_len, + unsigned char **signature, size_t *signature_len) { int r_len, s_len; int rc = 0; @@ -2448,8 +2458,8 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, libssh2_curve_type type; _libssh2_debug((session, - LIBSSH2_TRACE_AUTH, - "Computing public key from EC private key envelope")); + LIBSSH2_TRACE_AUTH, + "Computing public key from EC private key envelope")); bn_ctx = BN_CTX_new(); if(!bn_ctx) @@ -2473,7 +2483,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, method_buf = LIBSSH2_ALLOC(session, *method_len); if(!method_buf) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "out of memory"); + "out of memory"); } if(is_sk) @@ -2486,8 +2496,8 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, memcpy(method_buf, "ecdsa-sha2-nistp521", *method_len); else { _libssh2_debug((session, - LIBSSH2_TRACE_ERROR, - "Unsupported EC private key type")); + LIBSSH2_TRACE_ERROR, + "Unsupported EC private key type")); rc = -1; goto clean_exit; } @@ -2805,7 +2815,7 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Session is required"); + "Session is required"); return -1; } @@ -2867,7 +2877,7 @@ _libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, if(!session) { _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Session is required"); + "Session is required"); return -1; } @@ -3551,7 +3561,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, method, method_len, pubkeydata, pubkeydata_len, - (libssh2_rsa_ctx**)key_ctx); + (libssh2_rsa_ctx**)key_ctx); } } #endif @@ -3559,10 +3569,10 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, if(strcmp("ssh-dss", (const char *)buf) == 0) { if(!key_type || strcmp("ssh-dss", key_type) == 0) { rc = gen_publickey_from_dsa_openssh_priv_data(session, decrypted, - method, method_len, + method, method_len, pubkeydata, pubkeydata_len, - (libssh2_dsa_ctx**)key_ctx); + (libssh2_dsa_ctx**)key_ctx); } } #endif @@ -3578,7 +3588,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, NULL, NULL, NULL, NULL, - (libssh2_ecdsa_ctx**)key_ctx); + (libssh2_ecdsa_ctx**)key_ctx); } else if(_libssh2_ecdsa_curve_type_from_name((const char *)buf, &type) == 0) { @@ -3588,7 +3598,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, method, method_len, pubkeydata, pubkeydata_len, - (libssh2_ecdsa_ctx**)key_ctx); + (libssh2_ecdsa_ctx**)key_ctx); } } } @@ -3687,7 +3697,7 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, application, key_handle, handle_len, - (libssh2_ecdsa_ctx**)key_ctx); + (libssh2_ecdsa_ctx**)key_ctx); } } #endif @@ -3757,7 +3767,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, pubkeydata_len, privatekeydata, privatekeydata_len, - (unsigned const char *)passphrase); + (unsigned const char *)passphrase); if(st) return st; return 0; diff --git a/src/packet.c b/src/packet.c index a5e32d1780..3ce2e8cc98 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1240,8 +1240,8 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type, { if(state->start == 0) { if(_libssh2_packet_ask(session, packet_type, data, data_len, - match_ofs, match_buf, - match_len) == 0) { + match_ofs, match_buf, + match_len) == 0) { /* A packet was available in the packet brigade */ return 0; } @@ -1305,7 +1305,7 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session, all_packets[254] = 0; if(_libssh2_packet_askv(session, all_packets, &data, &data_len, 0, - NULL, 0) == 0) { + NULL, 0) == 0) { i = data[0]; /* A packet was available in the packet brigade, burn it */ LIBSSH2_FREE(session, data); @@ -1334,7 +1334,7 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session, /* Be lazy, let packet_ask pull it out of the brigade */ if(0 == _libssh2_packet_ask(session, (unsigned char)ret, - &data, &data_len, 0, NULL, 0)) { + &data, &data_len, 0, NULL, 0)) { /* Smoke 'em if you got 'em */ LIBSSH2_FREE(session, data); *state = libssh2_NB_state_idle; @@ -1363,7 +1363,7 @@ _libssh2_packet_requirev(LIBSSH2_SESSION *session, packet_requirev_state_t * state) { if(_libssh2_packet_askv(session, packet_types, data, data_len, match_ofs, - match_buf, match_len) == 0) { + match_buf, match_len) == 0) { /* One of the packets listed was available in the packet brigade */ state->start = 0; return 0; diff --git a/src/pem.c b/src/pem.c index 69120e642e..571d6e072a 100644 --- a/src/pem.c +++ b/src/pem.c @@ -427,7 +427,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, if(_libssh2_get_string(&decoded, &kdfname, &tmp_len) || tmp_len == 0) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "kdfname is missing"); + "kdfname is missing"); goto out; } @@ -480,7 +480,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, if(_libssh2_get_string(&decoded, &buf, &tmp_len) || tmp_len == 0) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Private key data not found"); + "Private key data not found"); goto out; } @@ -505,7 +505,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, if(!method) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "No supported cipher found"); + "No supported cipher found"); goto out; } } @@ -522,7 +522,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, key = LIBSSH2_CALLOC(session, total_len); if(!key) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Could not alloc key"); + "Could not alloc key"); goto out; } @@ -547,7 +547,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, } else { ret = _libssh2_error(session, LIBSSH2_ERROR_KEYFILE_AUTH_FAILED, - "bcrypted without passphrase"); + "bcrypted without passphrase"); LIBSSH2_FREE(session, key); goto out; } @@ -574,7 +574,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, /* Initialize the decryption */ if(method->init(session, method, iv_part, &free_iv, key_part, - &free_secret, 0, &abstract)) { + &free_secret, 0, &abstract)) { ret = LIBSSH2_ERROR_DECRYPT; goto out; } diff --git a/src/scp.c b/src/scp.c index 24c70ac321..4fb81b92ae 100644 --- a/src/scp.c +++ b/src/scp.c @@ -282,7 +282,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) session->scpRecv_atime = 0; session->scpRecv_command_len = - _libssh2_shell_quotedsize(path) + sizeof("scp -f ") + (sb?1:0); + _libssh2_shell_quotedsize(path) + sizeof("scp -f ") + (sb ? 1 : 0); session->scpRecv_command = LIBSSH2_ALLOC(session, session->scpRecv_command_len); @@ -296,7 +296,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) snprintf((char *)session->scpRecv_command, session->scpRecv_command_len, - "scp -%sf ", sb?"p":""); + "scp -%sf ", sb ? "p" : ""); cmd_len = strlen((char *)session->scpRecv_command); cmd_len += shell_quotearg(path, @@ -384,7 +384,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) if((session->scpRecv_state == libssh2_NB_state_sent2) || (session->scpRecv_state == libssh2_NB_state_sent3)) { while(sb && (session->scpRecv_response_len < - LIBSSH2_SCP_RESPONSE_BUFLEN)) { + LIBSSH2_SCP_RESPONSE_BUFLEN)) { unsigned char *s, *p; if(session->scpRecv_state == libssh2_NB_state_sent2) { @@ -843,7 +843,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, if(session->scpSend_state == libssh2_NB_state_idle) { session->scpSend_command_len = _libssh2_shell_quotedsize(path) + sizeof("scp -t ") + - ((mtime || atime)?1:0); + ((mtime || atime) ? 1 : 0); session->scpSend_command = LIBSSH2_ALLOC(session, session->scpSend_command_len); @@ -857,7 +857,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, snprintf((char *)session->scpSend_command, session->scpSend_command_len, - "scp -%st ", (mtime || atime)?"p":""); + "scp -%st ", (mtime || atime) ? "p" : ""); cmd_len = strlen((char *)session->scpSend_command); cmd_len += shell_quotearg(path, diff --git a/src/session.c b/src/session.c index c5800a36de..eea239e2b0 100644 --- a/src/session.c +++ b/src/session.c @@ -75,7 +75,7 @@ static LIBSSH2_ALLOC_FUNC(libssh2_default_alloc) { - (void) abstract; + (void)abstract; return malloc(count); } @@ -84,7 +84,7 @@ LIBSSH2_ALLOC_FUNC(libssh2_default_alloc) static LIBSSH2_FREE_FUNC(libssh2_default_free) { - (void) abstract; + (void)abstract; free(ptr); } @@ -93,7 +93,7 @@ LIBSSH2_FREE_FUNC(libssh2_default_free) static LIBSSH2_REALLOC_FUNC(libssh2_default_realloc) { - (void) abstract; + (void)abstract; return realloc(ptr, count); } @@ -121,15 +121,15 @@ banner_receive(LIBSSH2_SESSION * session) } while((banner_len < sizeof(session->banner_TxRx_banner)) && - ((banner_len == 0) - || (session->banner_TxRx_banner[banner_len - 1] != '\n'))) { + ((banner_len == 0) + || (session->banner_TxRx_banner[banner_len - 1] != '\n'))) { char c = '\0'; /* no incoming block yet! */ session->socket_block_directions &= ~LIBSSH2_SESSION_BLOCK_INBOUND; ret = LIBSSH2_RECV(session, &c, 1, - LIBSSH2_SOCKET_RECV_FLAGS(session)); + LIBSSH2_SOCKET_RECV_FLAGS(session)); if(ret < 0) { if(session->api_block_mode || (ret != -EAGAIN)) /* ignore EAGAIN when non-blocking */ @@ -174,8 +174,8 @@ banner_receive(LIBSSH2_SESSION * session) } while(banner_len && - ((session->banner_TxRx_banner[banner_len - 1] == '\n') || - (session->banner_TxRx_banner[banner_len - 1] == '\r'))) { + ((session->banner_TxRx_banner[banner_len - 1] == '\n') || + (session->banner_TxRx_banner[banner_len - 1] == '\r'))) { banner_len--; } @@ -249,9 +249,9 @@ banner_send(LIBSSH2_SESSION * session) session->socket_block_directions &= ~LIBSSH2_SESSION_BLOCK_OUTBOUND; ret = LIBSSH2_SEND(session, - banner + session->banner_TxRx_total_send, - banner_len - session->banner_TxRx_total_send, - LIBSSH2_SOCKET_SEND_FLAGS(session)); + banner + session->banner_TxRx_total_send, + banner_len - session->banner_TxRx_total_send, + LIBSSH2_SOCKET_SEND_FLAGS(session)); if(ret < 0) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Error sending %d bytes: %d", @@ -414,7 +414,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd) size_t size = sizeof(int); callstat = getsockopt(sockfd, SOL_SOCKET, SO_STATE, - (char *)&sockstat, &size); + (char *)&sockstat, &size); if(callstat == -1) { return 0; } @@ -1428,7 +1428,7 @@ _libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking) { int bl = session->api_block_mode; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Setting blocking mode %s", blocking?"ON":"OFF")); + "Setting blocking mode %s", blocking ? "ON" : "OFF")); session->api_block_mode = blocking; return bl; @@ -1442,7 +1442,7 @@ _libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking) LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking) { - (void) _libssh2_session_set_blocking(session, blocking); + (void)_libssh2_session_set_blocking(session, blocking); } /* libssh2_session_get_blocking diff --git a/src/sftp.c b/src/sftp.c index 3736781200..a7c25cc836 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -573,7 +573,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses, while(sftp->channel->session->socket_state == LIBSSH2_SOCKET_CONNECTED) { for(i = 0; i < num_valid_responses; i++) { if(sftp_packet_ask(sftp, valid_responses[i], request_id, - data, data_len) == 0) { + data, data_len) == 0) { /* * Set to zero before all returns to say * the timeout is not active @@ -741,8 +741,8 @@ LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor) { LIBSSH2_SFTP *sftp = (LIBSSH2_SFTP *) (*channel_abstract); - (void) session_abstract; - (void) channel; + (void)session_abstract; + (void)channel; /* Free the partial packet storage for sftp_packet_read */ if(sftp->partial_packet) { @@ -971,7 +971,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) sftp_init_error: while(_libssh2_channel_free(session->sftpInit_channel) == - LIBSSH2_ERROR_EAGAIN); + LIBSSH2_ERROR_EAGAIN); session->sftpInit_channel = NULL; if(session->sftpInit_sftp) { LIBSSH2_FREE(session, session->sftpInit_sftp); @@ -1107,7 +1107,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, }; unsigned char *s; ssize_t rc; - int open_file = (open_type == LIBSSH2_SFTP_OPENFILE)?1:0; + int open_file = (open_type == LIBSSH2_SFTP_OPENFILE) ? 1 : 0; if(sftp->open_state == libssh2_NB_state_idle) { sftp->last_errno = LIBSSH2_FX_OK; @@ -2059,8 +2059,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, acked but we haven't been able to return as such yet, so we will get that data as well passed in here again. */ - already = (size_t) (handle->u.file.offset_sent - - handle->u.file.offset)+ + already = (size_t)(handle->u.file.offset_sent - + handle->u.file.offset)+ handle->u.file.acked; if(count >= already) { @@ -2839,8 +2839,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, size_t data_len = 0; int retcode; uint32_t packet_len = - source_filename_len + dest_filename_len + 17 + (sftp->version >= - 5 ? 4 : 0); + source_filename_len + dest_filename_len + 17 + + (sftp->version >= 5 ? 4 : 0); /* packet_len(4) + packet_type(1) + request_id(4) + source_filename_len(4) + dest_filename_len(4) + flags(4){SFTP5+) */ unsigned char *data = NULL; diff --git a/src/sftp.h b/src/sftp.h index 129b8f085f..b0019b88bf 100644 --- a/src/sftp.h +++ b/src/sftp.h @@ -68,7 +68,7 @@ struct sftp_zombie_requests { }; #ifndef MIN -#define MIN(x,y) ((x)<(y)?(x):(y)) +#define MIN(x,y) ((x) < (y) ? (x) : (y)) #endif struct _LIBSSH2_SFTP_PACKET diff --git a/src/transport.c b/src/transport.c index f0e99848c3..19ad6ec2a8 100644 --- a/src/transport.c +++ b/src/transport.c @@ -141,7 +141,7 @@ decrypt(LIBSSH2_SESSION * session, unsigned char *source, while(len >= blocksize) { if(session->remote.crypt->crypt(session, source, blocksize, - &session->remote.crypt_abstract)) { + &session->remote.crypt_abstract)) { LIBSSH2_FREE(session, p->payload); return LIBSSH2_ERROR_DECRYPT; } @@ -201,11 +201,10 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) session->fullpacket_payload_len -= p->padding_length; /* Check for and deal with decompression */ - compressed = - session->local.comp && - session->local.comp->compress && - ((session->state & LIBSSH2_STATE_AUTHENTICATED) || - session->local.comp->use_in_auth); + compressed = session->local.comp && + session->local.comp->compress && + ((session->state & LIBSSH2_STATE_AUTHENTICATED) || + session->local.comp->use_in_auth); if(compressed && session->remote.comp_abstract) { /* @@ -372,10 +371,9 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) } /* now read a big chunk from the network into the temp buffer */ - nread = - LIBSSH2_RECV(session, &p->buf[remainbuf], - PACKETBUFSIZE - remainbuf, - LIBSSH2_SOCKET_RECV_FLAGS(session)); + nread = LIBSSH2_RECV(session, &p->buf[remainbuf], + PACKETBUFSIZE - remainbuf, + LIBSSH2_SOCKET_RECV_FLAGS(session)); if(nread <= 0) { /* check if this is due to EAGAIN and return the special return code if so, error out normally otherwise */ @@ -461,9 +459,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) /* total_num is the number of bytes following the initial (5 bytes) packet length and padding length fields */ - total_num = - p->packet_length - 1 + - (encrypted ? session->remote.mac->mac_len : 0); + total_num = p->packet_length - 1 + + (encrypted ? session->remote.mac->mac_len : 0); /* RFC4253 section 6.1 Maximum Packet Length says: * @@ -658,7 +655,7 @@ send_existing(LIBSSH2_SESSION *session, const unsigned char *data, length = p->ototal_num - p->osent; rc = LIBSSH2_SEND(session, &p->outbuf[p->osent], length, - LIBSSH2_SOCKET_SEND_FLAGS(session)); + LIBSSH2_SOCKET_SEND_FLAGS(session)); if(rc < 0) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Error sending %d bytes: %d", length, -rc)); @@ -771,11 +768,10 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0; - compressed = - session->local.comp && - session->local.comp->compress && - ((session->state & LIBSSH2_STATE_AUTHENTICATED) || - session->local.comp->use_in_auth); + compressed = session->local.comp && + session->local.comp->compress && + ((session->state & LIBSSH2_STATE_AUTHENTICATED) || + session->local.comp->use_in_auth); if(encrypted && compressed && session->local.comp_abstract) { /* the idea here is that these function must fail if the output gets @@ -892,8 +888,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, for(i = 0; i < packet_length; i += session->local.crypt->blocksize) { unsigned char *ptr = &p->outbuf[i]; if(session->local.crypt->crypt(session, ptr, - session->local.crypt->blocksize, - &session->local.crypt_abstract)) + session->local.crypt->blocksize, + &session->local.crypt_abstract)) return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */ } } @@ -901,7 +897,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, session->local.seqno++; ret = LIBSSH2_SEND(session, p->outbuf, total_length, - LIBSSH2_SOCKET_SEND_FLAGS(session)); + LIBSSH2_SOCKET_SEND_FLAGS(session)); if(ret < 0) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, "Error sending %d bytes: %d", total_length, -ret)); diff --git a/src/userauth.c b/src/userauth.c index 274fd0c3a4..3cf0138bd9 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -223,7 +223,7 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, } session->userauth_list_state = libssh2_NB_state_idle; - return (char *) session->userauth_list_data; + return (char *)session->userauth_list_data; } /* libssh2_userauth_list @@ -276,7 +276,7 @@ libssh2_userauth_banner(LIBSSH2_SESSION *session, char **banner) LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION * session) { - return (session->state & LIBSSH2_STATE_AUTHENTICATED)?1:0; + return (session->state & LIBSSH2_STATE_AUTHENTICATED) ? 1 : 0; } @@ -610,9 +610,9 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, sp2 = pubkey + pubkey_len; } - if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, - (const char *) sp1, - (unsigned int)(sp2 - sp1))) { + if(libssh2_base64_decode(session, (char **)&tmp, &tmp_len, + (const char *)sp1, + (unsigned int)(sp2 - sp1))) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid key data, not base64 encoded"); @@ -715,9 +715,9 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, sp2 = pubkey + pubkey_len; } - if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, - (const char *) sp1, - (unsigned int)(sp2 - sp1))) { + if(libssh2_base64_decode(session, (char **)&tmp, &tmp_len, + (const char *)sp1, + (unsigned int)(sp2 - sp1))) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid key data, not base64 encoded"); @@ -843,7 +843,7 @@ sign_frommemory(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, datavec.iov_len = data_len; if(privkeyobj->signv(session, sig, sig_len, 1, &datavec, - &hostkey_abstract)) { + &hostkey_abstract)) { if(privkeyobj->dtor) { privkeyobj->dtor(session, &hostkey_abstract); } @@ -879,7 +879,7 @@ sign_fromfile(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, datavec.iov_len = data_len; if(privkeyobj->signv(session, sig, sig_len, 1, &datavec, - &hostkey_abstract)) { + &hostkey_abstract)) { if(privkeyobj->dtor) { privkeyobj->dtor(session, &hostkey_abstract); } @@ -1106,8 +1106,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, datavec[2].iov_len = session->userauth_host_packet_len; if(privkeyobj && privkeyobj->signv && - privkeyobj->signv(session, &sig, &sig_len, 3, - datavec, &abstract)) { + privkeyobj->signv(session, &sig, &sig_len, 3, + datavec, &abstract)) { LIBSSH2_FREE(session, session->userauth_host_method); session->userauth_host_method = NULL; LIBSSH2_FREE(session, session->userauth_host_packet); @@ -1478,8 +1478,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, * the key default algo */ if(auth_attempts == 1) { rc = _libssh2_key_sign_algorithm(session, - &session->userauth_pblc_method, - &session->userauth_pblc_method_len); + &session->userauth_pblc_method, + &session->userauth_pblc_method_len); if(rc) return rc; @@ -1972,7 +1972,7 @@ libssh2_userauth_publickey(LIBSSH2_SESSION *session, const unsigned char *pubkeydata, size_t pubkeydata_len, LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC - ((*sign_callback)), + ((*sign_callback)), void **abstract) { int rc; @@ -1999,7 +1999,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, const char *username, unsigned int username_len, LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC - ((*response_callback))) + ((*response_callback))) { unsigned char *s; @@ -2273,7 +2273,7 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION *session, const char *user, unsigned int user_len, LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC - ((*response_callback))) + ((*response_callback))) { int rc; BLOCK_ADJUST(rc, session, @@ -2295,7 +2295,7 @@ libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, size_t privatekeydata_len, const char *passphrase, LIBSSH2_USERAUTH_SK_SIGN_FUNC - ((*sign_callback)), + ((*sign_callback)), void **abstract) { unsigned char *pubkeydata = NULL; diff --git a/src/wincng.c b/src/wincng.c index e35de1130c..ea9ba9e1cc 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -604,12 +604,12 @@ _libssh2_wincng_hmac_cleanup(_libssh2_wincng_hash_ctx *ctx) int _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx, - unsigned long hashlen, - const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, - unsigned long m_len, - unsigned long flags) + unsigned long hashlen, + const unsigned char *sig, + unsigned long sig_len, + const unsigned char *m, + unsigned long m_len, + unsigned long flags) { BCRYPT_PKCS1_PADDING_INFO paddingInfoPKCS1; BCRYPT_ALG_HANDLE hAlgHash; @@ -1267,11 +1267,11 @@ _libssh2_wincng_rsa_sha2_verify(libssh2_rsa_ctx* rsa, int _libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session, - libssh2_rsa_ctx *rsa, - const unsigned char *hash, - size_t hash_len, - unsigned char **signature, - size_t *signature_len) + libssh2_rsa_ctx *rsa, + const unsigned char *hash, + size_t hash_len, + unsigned char **signature, + size_t *signature_len) { BCRYPT_PKCS1_PADDING_INFO paddingInfo; unsigned char *data, *sig; From bf3b44ca1856a7f7d4d55638b2f7a14685af7876 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 15 Apr 2023 02:50:41 +0000 Subject: [PATCH 274/424] cmake: use a single build rule for all tests - use the complete filename of test sources in the input list. - build all tests with the ability to access libssh2 internals. This is necessary for `test_keyboard_interactive_auth_info_request` now and might be necessary for others in the future, e.g. to avoid the depreacted public base64 decoding API. - move `test_keyboard_interactive_auth_info_request` into the main test build loop. - move `simple` into the main test build loop too. - build `ssh2` also in static mode. - cleanup the way we detect and enable gcov. - fix indentation. Closes #967 --- cmake/max_warnings.cmake | 10 ++-- tests/CMakeLists.txt | 118 ++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 62 deletions(-) diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index dfa614eafa..0a83f50ac1 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -167,11 +167,11 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I endif() if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) list(APPEND WPICKY_ENABLE - -Walloc-zero # gcc 7.0 - -Wduplicated-branches # gcc 7.0 - -Wformat-overflow=2 # gcc 7.0 - -Wformat-truncation=1 # gcc 7.0 - -Wrestrict # gcc 7.0 + -Walloc-zero # gcc 7.0 + -Wduplicated-branches # gcc 7.0 + -Wformat-overflow=2 # gcc 7.0 + -Wformat-truncation=1 # gcc 7.0 + -Wrestrict # gcc 7.0 ) endif() if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f92bf631e7..ed436cb0be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,41 +40,44 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) set(TESTS - warmup - hostkey - hostkey_hash - password_auth_succeeds_with_correct_credentials - password_auth_fails_with_wrong_password - password_auth_fails_with_wrong_username - public_key_auth_fails_with_wrong_key - public_key_auth_succeeds_with_correct_rsa_key - public_key_auth_succeeds_with_correct_encrypted_rsa_key - keyboard_interactive_auth_fails_with_wrong_response - keyboard_interactive_auth_succeeds_with_correct_response - agent_forward_succeeds - read - ) + simple + ssh2 + test_warmup # keep this the first test + test_hostkey + test_hostkey_hash + test_password_auth_succeeds_with_correct_credentials + test_password_auth_fails_with_wrong_password + test_password_auth_fails_with_wrong_username + test_public_key_auth_fails_with_wrong_key + test_public_key_auth_succeeds_with_correct_rsa_key + test_public_key_auth_succeeds_with_correct_encrypted_rsa_key + test_keyboard_interactive_auth_fails_with_wrong_response + test_keyboard_interactive_auth_succeeds_with_correct_response + test_keyboard_interactive_auth_info_request + test_agent_forward_succeeds + test_read +) if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR CRYPTO_BACKEND STREQUAL "wolfSSL") list(APPEND TESTS - public_key_auth_succeeds_with_correct_rsa_openssh_key + test_public_key_auth_succeeds_with_correct_rsa_openssh_key ) if(OPENSSL_VERSION VERSION_GREATER "1.1.0" OR CRYPTO_BACKEND STREQUAL "wolfSSL") list(APPEND TESTS - public_key_auth_succeeds_with_correct_ed25519_key - public_key_auth_succeeds_with_correct_encrypted_ed25519_key - public_key_auth_succeeds_with_correct_ed25519_key_from_mem - public_key_auth_succeeds_with_correct_ecdsa_key - public_key_auth_succeeds_with_correct_signed_ecdsa_key - public_key_auth_succeeds_with_correct_signed_rsa_key + test_public_key_auth_succeeds_with_correct_ed25519_key + test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key + test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem + test_public_key_auth_succeeds_with_correct_ecdsa_key + test_public_key_auth_succeeds_with_correct_signed_ecdsa_key + test_public_key_auth_succeeds_with_correct_signed_rsa_key ) endif() endif() if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") list(APPEND TESTS - public_key_auth_succeeds_with_correct_dsa_key - ) + test_public_key_auth_succeeds_with_correct_dsa_key + ) endif() add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) @@ -83,22 +86,42 @@ target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURC # test building against shared libssh2 lib if(BUILD_SHARED_LIBS) - foreach(test simple ssh2) - add_executable(test_${test}_shared ${test}.c) - target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) - target_link_libraries(test_${test}_shared ${LIB_SHARED} ${LIBRARIES}) + foreach(test ssh2) + add_executable(${test}_shared ${test}.c) + target_include_directories(${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) + target_link_libraries(${test}_shared ${LIB_SHARED} ${LIBRARIES}) endforeach() endif() +if(CMAKE_COMPILER_IS_GNUCC) + find_program(GCOV_PATH gcov) + if(GCOV_PATH) + set(GCOV_OPTIONS -g --coverage) + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) + set(GCOV_OPTIONS "${GCOV_OPTIONS} -fprofile-abs-path") + endif() + endif() +endif() + foreach(test ${TESTS}) - add_executable(test_${test} test_${test}.c) - list(APPEND TEST_TARGETS test_${test}) - target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) - target_link_libraries(test_${test} runner ${LIB_STATIC} ${LIBRARIES}) - - add_test( - NAME test_${test} COMMAND $ - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(${test} ${test}.c) + target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}") + target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") + + # build a single test with gcov + if(GCOV_PATH AND test STREQUAL test_keyboard_interactive_auth_info_request) + target_compile_options(${test} BEFORE PRIVATE ${GCOV_OPTIONS}) + target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES} gcov) + else() + target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES}) + endif() + + if(test MATCHES "^test_") + list(APPEND TEST_TARGETS ${test}) + add_test( + NAME ${test} COMMAND $ + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + endif() endforeach() # MAC tests @@ -109,7 +132,7 @@ foreach(test hmac-sha1-96 hmac-sha2-256 hmac-sha2-512 - ) +) add_test(NAME test_${test} COMMAND "$") set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_MAC=${test}") endforeach() @@ -119,7 +142,7 @@ set(TESTS aes128-ctr aes192-ctr aes256-ctr - ) +) # Due to a bug with mbedTLS support, these crypt methods fail. Until that bug # is fixed, don't run them there to avoid this known issue causing red tests. # See https://github.com/libssh2/libssh2/issues/793 @@ -130,32 +153,13 @@ if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") aes192-cbc aes256-cbc rijndael-cbc@lysator.liu.se - ) + ) endif() foreach(test ${TESTS}) add_test(NAME test_${test} COMMAND "$") set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") endforeach() -add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) -target_compile_definitions(test_keyboard_interactive_auth_info_request PRIVATE "${CRYPTO_BACKEND_DEFINE}") -target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") -find_program(GCOV_PATH gcov) -set(TGT_OPTIONS -g --coverage -fprofile-abs-path) -if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) - set(TGT_OPTIONS -g --coverage) -endif() -if(CMAKE_COMPILER_IS_GNUCC AND GCOV_PATH) - target_compile_options(test_keyboard_interactive_auth_info_request BEFORE PRIVATE - ${TGT_OPTIONS}) - target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} ${LIB_STATIC} gcov) -else() - target_link_libraries(test_keyboard_interactive_auth_info_request ${LIBRARIES} ${LIB_STATIC}) -endif() -add_test( - NAME test_keyboard_interactive_auth_info_request COMMAND $ - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - add_custom_target(coverage COMMAND gcovr -r "${CMAKE_SOURCE_DIR}" --exclude tests/* COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/coverage/" From 31e6d95d01938c9ae658ec1118daa42e9e845783 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 15 Apr 2023 02:51:26 +0000 Subject: [PATCH 275/424] cmake: make Windows builds initialize faster By skipping unixy header checks that always fail with the MSVC toolchain or all Windows toolchains. Closes #968 --- CMakeLists.txt | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 408d265147..a3ff59888c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,20 +120,21 @@ set(LIB_SHARED "libssh2_shared") # Must match libssh2_shared_EXPORTS macro in i # Auto-detection ## Platform checks -check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(inttypes.h HAVE_INTTYPES_H) -check_include_files(sys/select.h HAVE_SYS_SELECT_H) - -check_include_files(sys/uio.h HAVE_SYS_UIO_H) -check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) -check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) -check_include_files(sys/time.h HAVE_SYS_TIME_H) -check_include_files(sys/un.h HAVE_SYS_UN_H) -check_include_files(sys/param.h HAVE_SYS_PARAM_H) - -# for example and tests -check_include_files(arpa/inet.h HAVE_ARPA_INET_H) -check_include_files(netinet/in.h HAVE_NETINET_IN_H) +if(NOT MSVC) + check_include_files(unistd.h HAVE_UNISTD_H) + check_include_files(sys/time.h HAVE_SYS_TIME_H) + check_include_files(sys/param.h HAVE_SYS_PARAM_H) +endif() +if(NOT WIN32) + check_include_files(sys/select.h HAVE_SYS_SELECT_H) + check_include_files(sys/uio.h HAVE_SYS_UIO_H) + check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) + check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) + check_include_files(sys/un.h HAVE_SYS_UN_H) + check_include_files(arpa/inet.h HAVE_ARPA_INET_H) # example and tests + check_include_files(netinet/in.h HAVE_NETINET_IN_H) # example and tests +endif() check_type_size("long long" LONGLONG) From 0a500b3554c29451708353279eefce750f4bca6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rgen=20Sigvardsson?= Date: Sat, 15 Apr 2023 18:11:19 +0200 Subject: [PATCH 276/424] scp: option to not quote paths (#803) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new flag named `LIBSSH2_FLAG_QUOTE_PATHS` has been added, to make libssh2 not quote file paths sent to the remote's scp subsystem. Some custom ssh daemons cannot handle quoted paths, and this makes this flag useful. Authored-by: Jörgen Sigvardsson --- include/libssh2.h | 1 + src/libssh2_priv.h | 5 +++-- src/scp.c | 37 +++++++++++++++++++++++++++++++------ src/session.c | 5 +++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index 6bce4e2647..0dd1beb8f2 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -372,6 +372,7 @@ typedef struct _LIBSSH2_SK_SIG_INFO { /* flags */ #define LIBSSH2_FLAG_SIGPIPE 1 #define LIBSSH2_FLAG_COMPRESS 2 +#define LIBSSH2_FLAG_QUOTE_PATHS 3 typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION; typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL; diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 012897273b..428dad1c7c 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -578,8 +578,9 @@ struct _LIBSSH2_PUBLICKEY #define LIBSSH2_SCP_RESPONSE_BUFLEN 256 struct flags { - int sigpipe; /* LIBSSH2_FLAG_SIGPIPE */ - int compress; /* LIBSSH2_FLAG_COMPRESS */ + int sigpipe; /* LIBSSH2_FLAG_SIGPIPE */ + int compress; /* LIBSSH2_FLAG_COMPRESS */ + int quote_paths; /* LIBSSH2_FLAG_QUOTE_PATHS */ }; struct _LIBSSH2_SESSION diff --git a/src/scp.c b/src/scp.c index 4fb81b92ae..6ade9102d2 100644 --- a/src/scp.c +++ b/src/scp.c @@ -299,9 +299,21 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) "scp -%sf ", sb ? "p" : ""); cmd_len = strlen((char *)session->scpRecv_command); - cmd_len += shell_quotearg(path, - &session->scpRecv_command[cmd_len], - session->scpRecv_command_len - cmd_len); + + if(!session->flag.quote_paths) { + size_t path_len; + + path_len = strlen(path); + + /* no NUL-termination neeed, so memcpy will do */ + memcpy(&session->scpRecv_command[cmd_len], path, path_len); + cmd_len += path_len; + } + else { + cmd_len += shell_quotearg(path, + &session->scpRecv_command[cmd_len], + session->scpRecv_command_len - cmd_len); + } /* the command to exec should _not_ be NUL-terminated */ session->scpRecv_command_len = cmd_len; @@ -860,9 +872,22 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, "scp -%st ", (mtime || atime) ? "p" : ""); cmd_len = strlen((char *)session->scpSend_command); - cmd_len += shell_quotearg(path, - &session->scpSend_command[cmd_len], - session->scpSend_command_len - cmd_len); + + if(!session->flag.quote_paths) { + size_t path_len; + + path_len = strlen(path); + + /* no NUL-termination neeed, so memcpy will do */ + memcpy(&session->scpSend_command[cmd_len], path, path_len); + cmd_len += path_len; + + } + else { + cmd_len += shell_quotearg(path, + &session->scpSend_command[cmd_len], + session->scpSend_command_len - cmd_len); + } /* the command to exec should _not_ be NUL-terminated */ session->scpSend_command_len = cmd_len; diff --git a/src/session.c b/src/session.c index eea239e2b0..35d2d68ae2 100644 --- a/src/session.c +++ b/src/session.c @@ -524,6 +524,8 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), session->api_timeout = 0; /* timeout-free API by default */ session->api_block_mode = 1; /* blocking API by default */ session->packet_read_timeout = LIBSSH2_DEFAULT_READ_TIMEOUT; + session->flag.quote_paths = 1; /* default behavior is to quote paths + for the scp subsystem */ _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "New session resource allocated")); _libssh2_init_if_needed(); @@ -1409,6 +1411,9 @@ libssh2_session_flag(LIBSSH2_SESSION * session, int flag, int value) case LIBSSH2_FLAG_COMPRESS: session->flag.compress = value; break; + case LIBSSH2_FLAG_QUOTE_PATHS: + session->flag.quote_paths = value; + break; default: /* unknown flag */ return LIBSSH2_ERROR_INVAL; From f1e80d8d8ce9570d81836da96ba02f4d4552a7b3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 15 Apr 2023 16:15:04 +0000 Subject: [PATCH 277/424] cmake: optimize non-blocking tests on WIN32/non-WIN32 Skip testing unixy methods on Windows and vice versa. I continue to assume that CMake doesn't define `WIN32` with Cygwin (as Cygwin doesn't define `_WIN32`/`WIN32` for C), though I haven't tested this. Closes #970 --- cmake/CheckNonblockingSocketSupport.cmake | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index b34b8b9864..12e2bd6476 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -27,7 +27,8 @@ include(CheckCSourceCompiles) macro(check_nonblocking_socket_support) # There are two known platforms (AIX 3.x and SunOS 4.1.x) where the # O_NONBLOCK define is found but does not work. - check_c_source_compiles(" + if(NOT WIN32) + check_c_source_compiles(" #include #include #include @@ -52,10 +53,12 @@ int main(void) int socket = 0; (void)fcntl(socket, F_SETFL, O_NONBLOCK); }" - HAVE_O_NONBLOCK) + HAVE_O_NONBLOCK) + endif() if(NOT HAVE_O_NONBLOCK) - check_c_source_compiles("/* FIONBIO test (old-style unix) */ + if(NOT WIN32) + check_c_source_compiles("/* FIONBIO test (old-style unix) */ #include #include @@ -65,10 +68,12 @@ int main(void) int flags = 0; (void)ioctl(socket, FIONBIO, &flags); }" - HAVE_FIONBIO) + HAVE_FIONBIO) + endif() if(NOT HAVE_FIONBIO) - check_c_source_compiles("/* ioctlsocket test (Windows) */ + if(WIN32) + check_c_source_compiles("/* ioctlsocket test (Windows) */ #undef inline #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -82,7 +87,8 @@ int main(void) unsigned long flags = 0; (void)ioctlsocket(sd, FIONBIO, &flags); }" - HAVE_IOCTLSOCKET) + HAVE_IOCTLSOCKET) + endif() if(NOT HAVE_IOCTLSOCKET) check_c_source_compiles("/* IoctlSocket test (Amiga?) */ @@ -93,7 +99,7 @@ int main(void) int socket = 0; (void)IoctlSocket(socket, FIONBIO, (long)1); }" - HAVE_IOCTLSOCKET_CASE) + HAVE_IOCTLSOCKET_CASE) if(NOT HAVE_IOCTLSOCKET_CASE) check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */ @@ -105,7 +111,7 @@ int main(void) int socket = 0; (void)setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); }" - HAVE_SO_NONBLOCK) + HAVE_SO_NONBLOCK) if(NOT HAVE_SO_NONBLOCK) # No non-blocking socket method found From 78cb64a85955f2cd9700c4fbad3f02d589dd7169 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 15:43:43 +0000 Subject: [PATCH 278/424] tests: switch Dockerfile to debian:testing-slim From debian:bullseye - doesn't need manual bumps. - is ahead of stable and should be stable enough for our purpose. - slim is saving resources. Closes #971 --- tests/openssh_server/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index c2f5e14612..7c22fc997f 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -FROM debian:bullseye +FROM debian:testing-slim RUN apt-get update \ && apt-get install -y openssh-server \ From 9ffbb05b445496c63f69e85db489d839dce3e68f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 15:48:59 +0000 Subject: [PATCH 279/424] src: add and use `LIBSSH2_MIN/MAX` macros Also for #797 Closes #974 --- src/bcrypt_pbkdf.c | 4 +--- src/libssh2_priv.h | 3 +++ src/sftp.c | 12 +++++++----- src/sftp.h | 4 ---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index c9e6acb0d7..5382c0bdb8 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -28,8 +28,6 @@ #define LIBSSH2_BCRYPT_PBKDF_C #include "blowfish.c" -#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b)) - /* * pkcs #5 pbkdf2 implementation using the "bcrypt" hash * @@ -164,7 +162,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, /* * pbkdf2 deviation: output the key material non-linearly. */ - amt = MINIMUM(amt, keylen); + amt = LIBSSH2_MIN(amt, keylen); for(i = 0; i < amt; i++) { size_t dest = i * stride + (count - 1); if(dest >= origkeylen) { diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 428dad1c7c..58e1ba9659 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -156,6 +156,9 @@ struct iovec { #define UINT_MAX 0xFFFFFFFF #endif +#define LIBSSH2_MAX(x, y) ((x) > (y) ? (x) : (y)) +#define LIBSSH2_MIN(x, y) ((x) < (y) ? (x) : (y)) + /* RFC4253 section 6.1 Maximum Packet Length says: * * "All implementations MUST be able to process packets with diff --git a/src/sftp.c b/src/sftp.c index a7c25cc836..f8d811ae8d 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1405,7 +1405,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, return that now as we can't risk being interrupted later with data partially written to the buffer. */ if(filep->data_left) { - size_t copy = MIN(buffer_size, filep->data_left); + size_t copy = LIBSSH2_MIN(buffer_size, filep->data_left); memcpy(buffer, &filep->data[ filep->data_len - filep->data_left], copy); @@ -1519,8 +1519,9 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, /* add this new entry LAST in the list */ _libssh2_list_add(&handle->packet_list, &chunk->node); - count -= MIN(size, count); /* deduct the size we used, as we might - * have to create more packets */ + /* deduct the size we used, as we might have to create + more packets */ + count -= LIBSSH2_MIN(size, count); _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "read request id %d sent (offset: %d, size: %d)", request_id, (int)chunk->offset, (int)chunk->len)); @@ -2076,7 +2077,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, while(count) { /* TODO: Possibly this should have some logic to prevent a very very small fraction to be left but lets ignore that for now */ - uint32_t size = (uint32_t)(MIN(MAX_SFTP_OUTGOING_SIZE, count)); + uint32_t size = + (uint32_t)(LIBSSH2_MIN(MAX_SFTP_OUTGOING_SIZE, count)); uint32_t request_id; /* 25 = packet_len(4) + packet_type(1) + request_id(4) + @@ -2226,7 +2228,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, acked += handle->u.file.acked; if(acked) { - ssize_t ret = MIN(acked, org_count); + ssize_t ret = LIBSSH2_MIN(acked, org_count); /* we got data acked so return that amount, but no more than what was asked to get sent! */ diff --git a/src/sftp.h b/src/sftp.h index b0019b88bf..891a89db1d 100644 --- a/src/sftp.h +++ b/src/sftp.h @@ -67,10 +67,6 @@ struct sftp_zombie_requests { uint32_t request_id; }; -#ifndef MIN -#define MIN(x,y) ((x) < (y) ? (x) : (y)) -#endif - struct _LIBSSH2_SFTP_PACKET { struct list_node node; /* linked list header */ From c9160bf89cfdceeb58e0401f65d787f79909245e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 16:15:44 +0000 Subject: [PATCH 280/424] tests: try debian:testing for Dockerfile Follow-up to 78cb64a85955f2cd9700c4fbad3f02d589dd7169 --- tests/openssh_server/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index 7c22fc997f..39921c2cba 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -FROM debian:testing-slim +FROM debian:testing RUN apt-get update \ && apt-get install -y openssh-server \ From 5644eea2161b17f7c16e18f3a10465ebb217ca1f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 16:20:20 +0000 Subject: [PATCH 281/424] session: simplify preprocessor logic - by using #elif - by merging two blocks Closes #972 --- src/session.c | 105 ++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 77 deletions(-) diff --git a/src/session.c b/src/session.c index 35d2d68ae2..6998ed1e07 100644 --- a/src/session.c +++ b/src/session.c @@ -217,9 +217,6 @@ banner_send(LIBSSH2_SESSION * session) char *banner = (char *) LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF; size_t banner_len = sizeof(LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF) - 1; ssize_t ret; -#ifdef LIBSSH2DEBUG - char banner_dup[256]; -#endif if(session->banner_TxRx_state == libssh2_NB_state_idle) { if(session->local.banner) { @@ -228,18 +225,22 @@ banner_send(LIBSSH2_SESSION * session) banner = (char *) session->local.banner; } #ifdef LIBSSH2DEBUG - /* Hack and slash to avoid sending CRLF in debug output */ - if(banner_len < 256) { - memcpy(banner_dup, banner, banner_len - 2); - banner_dup[banner_len - 2] = '\0'; - } - else { - memcpy(banner_dup, banner, 255); - banner_dup[255] = '\0'; - } + { + char banner_dup[256]; - _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Sending Banner: %s", - banner_dup)); + /* Hack and slash to avoid sending CRLF in debug output */ + if(banner_len < 256) { + memcpy(banner_dup, banner, banner_len - 2); + banner_dup[banner_len - 2] = '\0'; + } + else { + memcpy(banner_dup, banner, 255); + banner_dup[255] = '\0'; + } + + _libssh2_debug((session, LIBSSH2_TRACE_TRANS, + "Sending Banner: %s", banner_dup)); + } #endif session->banner_TxRx_state = libssh2_NB_state_created; @@ -292,8 +293,6 @@ static int session_nonblock(libssh2_socket_t sockfd, /* operate on this */ int nonblock /* TRUE or FALSE */ ) { -#undef SETBLOCK -#define SETBLOCK 0 #ifdef HAVE_O_NONBLOCK /* most recent unix versions */ int flags; @@ -303,54 +302,30 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); else return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK)); -#undef SETBLOCK -#define SETBLOCK 1 -#endif - -#if defined(HAVE_FIONBIO) && (SETBLOCK == 0) +#elif defined(HAVE_FIONBIO) /* older unix versions and VMS */ int flags; flags = nonblock; return ioctl(sockfd, FIONBIO, &flags); -#undef SETBLOCK -#define SETBLOCK 2 -#endif - -#if defined(HAVE_IOCTLSOCKET) && (SETBLOCK == 0) - /* Windows? */ +#elif defined(HAVE_IOCTLSOCKET) + /* Windows */ unsigned long flags; flags = nonblock; return ioctlsocket(sockfd, FIONBIO, &flags); -#undef SETBLOCK -#define SETBLOCK 3 -#endif - -#if defined(HAVE_IOCTLSOCKET_CASE) && (SETBLOCK == 0) +#elif defined(HAVE_IOCTLSOCKET_CASE) /* presumably for Amiga */ return IoctlSocket(sockfd, FIONBIO, (long) nonblock); -#undef SETBLOCK -#define SETBLOCK 4 -#endif - -#if defined(HAVE_SO_NONBLOCK) && (SETBLOCK == 0) +#elif defined(HAVE_SO_NONBLOCK) /* BeOS */ long b = nonblock ? 1 : 0; return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); -#undef SETBLOCK -#define SETBLOCK 5 -#endif - -#ifdef HAVE_DISABLED_NONBLOCKING +#elif defined(HAVE_DISABLED_NONBLOCKING) (void)sockfd; (void)nonblock; return 0; /* returns success */ -#undef SETBLOCK -#define SETBLOCK 6 -#endif - -#if(SETBLOCK == 0) +#else #error "no non-blocking method was found/used/set" #endif } @@ -363,8 +338,6 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ static int get_socket_nonblocking(libssh2_socket_t sockfd) { /* operate on this */ -#undef GETBLOCK -#define GETBLOCK 0 #ifdef HAVE_O_NONBLOCK /* most recent unix versions */ int flags = fcntl(sockfd, F_GETFL, 0); @@ -374,12 +347,8 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return (flags & O_NONBLOCK); -#undef GETBLOCK -#define GETBLOCK 1 -#endif - -#if defined(WSAEWOULDBLOCK) && (GETBLOCK == 0) - /* Windows? */ +#elif defined(WSAEWOULDBLOCK) + /* Windows */ unsigned int option_value; socklen_t option_len = sizeof(option_value); @@ -389,11 +358,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return (int) option_value; -#undef GETBLOCK -#define GETBLOCK 2 -#endif - -#if defined(HAVE_SO_NONBLOCK) && (GETBLOCK == 0) +#elif defined(HAVE_SO_NONBLOCK) /* BeOS */ long b; if(getsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b))) { @@ -401,12 +366,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return (int) b; -#undef GETBLOCK -#define GETBLOCK 5 -#endif - -#if defined(SO_STATE) && defined(__VMS) && (GETBLOCK == 0) - +#elif defined(SO_STATE) && defined(__VMS) /* VMS TCP/IP Services */ size_t sockstat = 0; @@ -422,19 +382,10 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return 0; - -#undef GETBLOCK -#define GETBLOCK 6 -#endif - -#ifdef HAVE_DISABLED_NONBLOCKING +#elif defined(HAVE_DISABLED_NONBLOCKING) (void)sockfd; return 1; /* returns blocking */ -#undef GETBLOCK -#define GETBLOCK 7 -#endif - -#if(GETBLOCK == 0) +#else #error "no non-blocking method was found/used/get" #endif } From 819573f94ef252836356836bb7d9697ae93605e6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 16:54:19 +0000 Subject: [PATCH 282/424] tests: restore debian:bullseye in Dockerfile Follow-up to 78cb64a85955f2cd9700c4fbad3f02d589dd7169 --- tests/openssh_server/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index 39921c2cba..c2f5e14612 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -FROM debian:testing +FROM debian:bullseye RUN apt-get update \ && apt-get install -y openssh-server \ From 16071c225feaa70566caf4f8bde79d97a4615481 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 17:22:10 +0000 Subject: [PATCH 283/424] build: add `-Wbad-function-cast` picky warning Also adjust minimum gcc versions in comment. Closes #975 --- acinclude.m4 | 3 ++- cmake/max_warnings.cmake | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 9f60b9c1ca..3936592345 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -241,6 +241,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], # dnl Only clang 3.0 or later (possibly earlier) if test "$compiler_num" -ge "300"; then + CURL_ADD_COMPILER_WARNINGS([WARN], [bad-function-cast]) CURL_ADD_COMPILER_WARNINGS([WARN], [conversion]) CURL_ADD_COMPILER_WARNINGS([WARN], [empty-body]) CURL_ADD_COMPILER_WARNINGS([WARN], [ignored-qualifiers]) @@ -332,7 +333,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], dnl only if the compiler is newer than 2.95 since we got lots of dnl "`_POSIX_C_SOURCE' is not defined" in system headers with dnl gcc 2.95.4 on FreeBSD 4.9! - WARN="$WARN -Wundef -Wno-long-long -Wno-multichar -Wshadow -Wsign-compare -Wunused" + WARN="$WARN -Wbad-function-cast -Wundef -Wno-long-long -Wno-multichar -Wshadow -Wsign-compare -Wunused" fi if test "$gccnum" -ge "296"; then diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index 0a83f50ac1..da0e403a02 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -64,19 +64,20 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I # Assume these options always exist with both clang and gcc. # Require clang 3.0 / gcc 2.95 or later. list(APPEND WPICKY_ENABLE + -Wbad-function-cast # clang 3.0 gcc 2.95 -Wconversion # clang 3.0 gcc 2.95 -Winline # clang 1.0 gcc 1.0 -Wmissing-declarations # clang 1.0 gcc 2.7 -Wmissing-prototypes # clang 1.0 gcc 1.0 - -Wnested-externs # clang 1.0 gcc 1.0 + -Wnested-externs # clang 1.0 gcc 2.7 -Wno-long-long # clang 1.0 gcc 2.95 -Wno-multichar # clang 1.0 gcc 2.95 - -Wpointer-arith # clang 1.0 gcc 1.0 + -Wpointer-arith # clang 1.0 gcc 1.4 -Wshadow # clang 1.0 gcc 2.95 -Wsign-compare # clang 1.0 gcc 2.95 -Wundef # clang 1.0 gcc 2.95 -Wunused # clang 1.1 gcc 2.95 - -Wwrite-strings # clang 1.0 gcc 1.0 + -Wwrite-strings # clang 1.0 gcc 1.4 ) # Always enable with clang, version dependent with gcc From 29fd14e22a3df59aef2f273534db775ec9ca984f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 18:38:38 +0000 Subject: [PATCH 284/424] ssh2.sh: revert likely wrong quoting [ci skip] Follow-up to 50124428509ffc2f5d08d8d3c152fa36546c9a75 --- tests/ssh2.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ssh2.sh b/tests/ssh2.sh index 3c99486920..4e475e6e75 100755 --- a/tests/ssh2.sh +++ b/tests/ssh2.sh @@ -23,7 +23,7 @@ chmod go-rwx "$srcdir"/etc/host* "$SSHD" -f /dev/null -h "$srcdir/etc/host" \ -o 'Port 4711' \ -o 'Protocol 2' \ - -o "AuthorizedKeysFile \"$srcdir/etc/user.pub\"" \ + -o "AuthorizedKeysFile $srcdir/etc/user.pub" \ -o 'UsePrivilegeSeparation no' \ -o 'StrictModes no' \ -D \ From 238def4da87272c0eccc9175c1c83a1349865394 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 19:18:40 +0000 Subject: [PATCH 285/424] autotools: rename a variable To match its counterpart we use for clang and to better match the original code in curl. Follow-up to ec0feae7920d695ce234a5aba13014bf29824c09 Closes #977 --- acinclude.m4 | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 3936592345..9f77137161 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -299,7 +299,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], gccver=`$CC -dumpversion` num1=`echo $gccver | cut -d . -f1` num2=`echo $gccver | cut -d . -f2` - gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null` + compiler_num=`(expr $num1 "*" 100 + $num2) 2>/dev/null` AC_MSG_RESULT($gccver) if test "$ICC" = "yes"; then @@ -316,7 +316,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], WARN="-wd279,269,981,1418,1419" - if test "$gccnum" -gt "600"; then + if test "$compiler_num" -gt "600"; then dnl icc 6.0 and older doesn't have the -Wall flag WARN="-Wall $WARN" fi @@ -324,24 +324,24 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], dnl this is a set of options we believe *ALL* gcc versions support: WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes" - if test "$gccnum" -ge "207"; then + if test "$compiler_num" -ge "207"; then dnl gcc 2.7 or later WARN="$WARN -Wmissing-declarations" fi - if test "$gccnum" -gt "295"; then + if test "$compiler_num" -gt "295"; then dnl only if the compiler is newer than 2.95 since we got lots of dnl "`_POSIX_C_SOURCE' is not defined" in system headers with dnl gcc 2.95.4 on FreeBSD 4.9! WARN="$WARN -Wbad-function-cast -Wundef -Wno-long-long -Wno-multichar -Wshadow -Wsign-compare -Wunused" fi - if test "$gccnum" -ge "296"; then + if test "$compiler_num" -ge "296"; then dnl gcc 2.96 or later WARN="$WARN -Wfloat-equal" fi - if test "$gccnum" -gt "296"; then + if test "$compiler_num" -gt "296"; then dnl this option does not exist in 2.96 WARN="$WARN -Wno-format-nonliteral" fi @@ -351,33 +351,33 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], dnl Also, on gcc 4.0.X it is totally unbearable and complains all dnl over making it unusable for generic purposes. Let's not use it. - if test "$gccnum" -ge "303"; then + if test "$compiler_num" -ge "303"; then dnl gcc 3.3 and later WARN="$WARN -Wendif-labels -Wstrict-prototypes" fi - if test "$gccnum" -ge "304"; then + if test "$compiler_num" -ge "304"; then # try these on gcc 3.4 WARN="$WARN -Wdeclaration-after-statement" fi dnl Only gcc 4.0 or later - if test "$gccnum" -ge "400"; then + if test "$compiler_num" -ge "400"; then WARN="$WARN -Wstrict-aliasing=3" fi # dnl Only gcc 4.1 or later (possibly earlier) - if test "$gccnum" -ge "401"; then + if test "$compiler_num" -ge "401"; then CURL_ADD_COMPILER_WARNINGS([WARN], [no-system-headers]) fi # dnl Only gcc 4.2 or later - if test "$gccnum" -ge "402"; then + if test "$compiler_num" -ge "402"; then CURL_ADD_COMPILER_WARNINGS([WARN], [cast-align]) fi # dnl Only gcc 4.3 or later - if test "$gccnum" -ge "403"; then + if test "$compiler_num" -ge "403"; then CURL_ADD_COMPILER_WARNINGS([WARN], [type-limits old-style-declaration]) CURL_ADD_COMPILER_WARNINGS([WARN], [missing-parameter-type empty-body]) CURL_ADD_COMPILER_WARNINGS([WARN], [ignored-qualifiers]) @@ -389,7 +389,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], fi # dnl Only gcc 4.5 or later - if test "$gccnum" -ge "405"; then + if test "$compiler_num" -ge "405"; then dnl Only windows targets case $host_os in mingw*) @@ -399,22 +399,22 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], fi # dnl Only gcc 4.6 or later - if test "$gccnum" -ge "406"; then + if test "$compiler_num" -ge "406"; then CURL_ADD_COMPILER_WARNINGS([WARN], [double-promotion]) fi # dnl only gcc 4.8 or later - if test "$gccnum" -ge "408"; then + if test "$compiler_num" -ge "408"; then WARN="$WARN -Wformat=2" fi # dnl Only gcc 5 or later - if test "$gccnum" -ge "500"; then + if test "$compiler_num" -ge "500"; then WARN="$WARN -Warray-bounds=2" fi # dnl Only gcc 6 or later - if test "$gccnum" -ge "600"; then + if test "$compiler_num" -ge "600"; then CURL_ADD_COMPILER_WARNINGS([WARN], [shift-negative-value]) WARN="$WARN -Wshift-overflow=2" CURL_ADD_COMPILER_WARNINGS([WARN], [null-dereference]) @@ -424,7 +424,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], fi # dnl Only gcc 7 or later - if test "$gccnum" -ge "700"; then + if test "$compiler_num" -ge "700"; then CURL_ADD_COMPILER_WARNINGS([WARN], [duplicated-branches]) CURL_ADD_COMPILER_WARNINGS([WARN], [restrict]) CURL_ADD_COMPILER_WARNINGS([WARN], [alloc-zero]) @@ -433,7 +433,7 @@ AC_DEFUN([CURL_CC_DEBUG_OPTS], fi # dnl Only gcc 10 or later - if test "$gccnum" -ge "1000"; then + if test "$compiler_num" -ge "1000"; then CURL_ADD_COMPILER_WARNINGS([WARN], [arith-conversion]) CURL_ADD_COMPILER_WARNINGS([WARN], [enum-conversion]) fi From 9ecb22daab7a56b9357771573755c31a8670f043 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 14 Apr 2023 23:27:54 +0000 Subject: [PATCH 286/424] tests: build improvements and more - rename tests to have more succint names and a more useful natural order. - rename `simple` and `ssh2` in tests to have the `test_` prefix. This avoids a name collisions with `ssh2` in examples. - cmake: drop the `example-` prefix for generated examples. Bringing their names in sync with other build tools, like autotools. - move common auth test code into the fixture and simplify tests by using that. - move feature guards from CMake to preprocessor for auth tests. Now it works with all build tools and it's easier to keep it in sync with the lib itself. For this we need to include `libssh2_priv.h` in tests, which in turn needs tweaking on the trick we use to suppress extra MSVS warnings when building tests and examples. - move mbedTLS blocklist for crypto tests from CMake to the test fixture. - add ed25519 hostkey tests to `test_hostkey` and `test_hostkey_hash`. - add shell script to regenerate all test keys used for our tests. - alpha-sort tests. - rename `signed_*` keys to begin with `key` like the rest of the keys do. - whitespace fixes. Closes #969 --- example/CMakeLists.txt | 8 +- src/libssh2_setup.h | 3 +- tests/CMakeLists.txt | 105 +++---- tests/Makefile.am | 60 ++-- tests/gen_keys.sh | 74 +++++ tests/key_ecdsa.pub | 2 +- tests/{signed_key_ecdsa => key_ecdsa_signed} | 0 ...dsa-cert.pub => key_ecdsa_signed-cert.pub} | 2 +- ...ned_key_ecdsa.pub => key_ecdsa_signed.pub} | 2 +- tests/key_rsa_openssh.pub | 2 +- tests/{signed_key_rsa => key_rsa_signed} | 0 ...y_rsa-cert.pub => key_rsa_signed-cert.pub} | 2 +- ...{signed_key_rsa.pub => key_rsa_signed.pub} | 2 +- tests/runner.c | 7 +- tests/session_fixture.c | 291 ++++++++++++++++-- tests/session_fixture.h | 27 +- tests/ssh2.sh | 2 +- tests/{test_warmup.c => test_aa_warmup.c} | 0 ...ard_succeeds.c => test_agent_forward_ok.c} | 9 +- tests/test_auth_keyboard_fail.c | 8 + ...st.c => test_auth_keyboard_info_request.c} | 2 + tests/test_auth_keyboard_ok.c | 8 + tests/test_auth_password_fail_password.c | 8 + tests/test_auth_password_fail_username.c | 8 + tests/test_auth_password_ok.c | 8 + tests/test_auth_pubkey_fail.c | 10 + tests/test_auth_pubkey_ok_dsa.c | 16 + tests/test_auth_pubkey_ok_ecdsa.c | 16 + tests/test_auth_pubkey_ok_ecdsa_signed.c | 17 + tests/test_auth_pubkey_ok_ed25519.c | 16 + tests/test_auth_pubkey_ok_ed25519_encrypted.c | 16 + tests/test_auth_pubkey_ok_ed25519_mem.c | 16 + tests/test_auth_pubkey_ok_rsa.c | 11 + tests/test_auth_pubkey_ok_rsa_encrypted.c | 11 + tests/test_auth_pubkey_ok_rsa_openssh.c | 16 + tests/test_auth_pubkey_ok_rsa_signed.c | 16 + tests/test_hostkey.c | 10 +- tests/test_hostkey_hash.c | 29 +- ...teractive_auth_fails_with_wrong_response.c | 56 ---- ...tive_auth_succeeds_with_correct_response.c | 57 ---- ..._password_auth_fails_with_wrong_password.c | 35 --- ..._password_auth_fails_with_wrong_username.c | 35 --- ...d_auth_succeeds_with_correct_credentials.c | 41 --- ...est_public_key_auth_fails_with_wrong_key.c | 35 --- ...c_key_auth_succeeds_with_correct_dsa_key.c | 35 --- ...key_auth_succeeds_with_correct_ecdsa_key.c | 36 --- ...y_auth_succeeds_with_correct_ed25519_key.c | 36 --- ...cceeds_with_correct_ed25519_key_from_mem.c | 96 ------ ...ceeds_with_correct_encrypted_ed25519_key.c | 37 --- ..._succeeds_with_correct_encrypted_rsa_key.c | 37 --- ...c_key_auth_succeeds_with_correct_rsa_key.c | 36 --- ...th_succeeds_with_correct_rsa_openssh_key.c | 36 --- ...h_succeeds_with_correct_signed_ecdsa_key.c | 36 --- ...uth_succeeds_with_correct_signed_rsa_key.c | 36 --- tests/test_read.c | 10 +- tests/{simple.c => test_simple.c} | 0 tests/{ssh2.c => test_ssh2.c} | 0 57 files changed, 707 insertions(+), 823 deletions(-) create mode 100755 tests/gen_keys.sh rename tests/{signed_key_ecdsa => key_ecdsa_signed} (100%) rename tests/{signed_key_ecdsa-cert.pub => key_ecdsa_signed-cert.pub} (97%) rename tests/{signed_key_ecdsa.pub => key_ecdsa_signed.pub} (86%) rename tests/{signed_key_rsa => key_rsa_signed} (100%) rename tests/{signed_key_rsa-cert.pub => key_rsa_signed-cert.pub} (96%) rename tests/{signed_key_rsa.pub => key_rsa_signed.pub} (95%) rename tests/{test_warmup.c => test_aa_warmup.c} (100%) rename tests/{test_agent_forward_succeeds.c => test_agent_forward_ok.c} (77%) create mode 100644 tests/test_auth_keyboard_fail.c rename tests/{test_keyboard_interactive_auth_info_request.c => test_auth_keyboard_info_request.c} (99%) create mode 100644 tests/test_auth_keyboard_ok.c create mode 100644 tests/test_auth_password_fail_password.c create mode 100644 tests/test_auth_password_fail_username.c create mode 100644 tests/test_auth_password_ok.c create mode 100644 tests/test_auth_pubkey_fail.c create mode 100644 tests/test_auth_pubkey_ok_dsa.c create mode 100644 tests/test_auth_pubkey_ok_ecdsa.c create mode 100644 tests/test_auth_pubkey_ok_ecdsa_signed.c create mode 100644 tests/test_auth_pubkey_ok_ed25519.c create mode 100644 tests/test_auth_pubkey_ok_ed25519_encrypted.c create mode 100644 tests/test_auth_pubkey_ok_ed25519_mem.c create mode 100644 tests/test_auth_pubkey_ok_rsa.c create mode 100644 tests/test_auth_pubkey_ok_rsa_encrypted.c create mode 100644 tests/test_auth_pubkey_ok_rsa_openssh.c create mode 100644 tests/test_auth_pubkey_ok_rsa_signed.c delete mode 100644 tests/test_keyboard_interactive_auth_fails_with_wrong_response.c delete mode 100644 tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c delete mode 100644 tests/test_password_auth_fails_with_wrong_password.c delete mode 100644 tests/test_password_auth_fails_with_wrong_username.c delete mode 100644 tests/test_password_auth_succeeds_with_correct_credentials.c delete mode 100644 tests/test_public_key_auth_fails_with_wrong_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_dsa_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_rsa_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c delete mode 100644 tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c rename tests/{simple.c => test_simple.c} (100%) rename tests/{ssh2.c => test_ssh2.c} (100%) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index a8661e93c9..26f83429de 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -45,11 +45,11 @@ include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) set(EXAMPLES ${noinst_PROGRAMS}) foreach(example ${EXAMPLES}) - add_executable(example-${example} ${example}.c) - list(APPEND EXAMPLE_TARGETS example-${example}) + add_executable(${example} ${example}.c) + list(APPEND EXAMPLE_TARGETS ${example}) # to find generated header - target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ../src) - target_link_libraries(example-${example} ${LIB_STATIC} ${LIBRARIES}) + target_include_directories(${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ../src) + target_link_libraries(${example} ${LIB_STATIC} ${LIBRARIES}) endforeach() add_target_to_copy_dependencies( diff --git a/src/libssh2_setup.h b/src/libssh2_setup.h index 638e6c4aa2..a110d6190f 100644 --- a/src/libssh2_setup.h +++ b/src/libssh2_setup.h @@ -73,7 +73,8 @@ # ifndef _CRT_SECURE_NO_WARNINGS # define _CRT_SECURE_NO_WARNINGS /* for fopen(), getenv() */ # endif -# ifndef LIBSSH2_LIBRARY /* apply to examples and tests only */ +# if !defined(LIBSSH2_LIBRARY) || defined(LIBSSH2_TESTS) + /* apply to examples and tests only */ # ifndef _CRT_NONSTDC_NO_DEPRECATE # define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write() */ # endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ed436cb0be..61dc2e9975 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,84 +39,71 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) +if(CMAKE_COMPILER_IS_GNUCC) + find_program(GCOV_PATH gcov) + if(GCOV_PATH) + set(GCOV_OPTIONS -g --coverage) + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) + set(GCOV_OPTIONS "${GCOV_OPTIONS} -fprofile-abs-path") + endif() + endif() +endif() + set(TESTS - simple - ssh2 - test_warmup # keep this the first test + test_aa_warmup # keep this first + test_agent_forward_ok + test_auth_keyboard_fail + test_auth_keyboard_info_request + test_auth_keyboard_ok + test_auth_password_fail_password + test_auth_password_fail_username + test_auth_password_ok + test_auth_pubkey_fail + test_auth_pubkey_ok_dsa + test_auth_pubkey_ok_ecdsa + test_auth_pubkey_ok_ecdsa_signed + test_auth_pubkey_ok_ed25519 + test_auth_pubkey_ok_ed25519_encrypted + test_auth_pubkey_ok_ed25519_mem + test_auth_pubkey_ok_rsa + test_auth_pubkey_ok_rsa_encrypted + test_auth_pubkey_ok_rsa_openssh + test_auth_pubkey_ok_rsa_signed test_hostkey test_hostkey_hash - test_password_auth_succeeds_with_correct_credentials - test_password_auth_fails_with_wrong_password - test_password_auth_fails_with_wrong_username - test_public_key_auth_fails_with_wrong_key - test_public_key_auth_succeeds_with_correct_rsa_key - test_public_key_auth_succeeds_with_correct_encrypted_rsa_key - test_keyboard_interactive_auth_fails_with_wrong_response - test_keyboard_interactive_auth_succeeds_with_correct_response - test_keyboard_interactive_auth_info_request - test_agent_forward_succeeds test_read + test_simple + test_ssh2 ) -if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR CRYPTO_BACKEND STREQUAL "wolfSSL") - list(APPEND TESTS - test_public_key_auth_succeeds_with_correct_rsa_openssh_key - ) - if(OPENSSL_VERSION VERSION_GREATER "1.1.0" OR CRYPTO_BACKEND STREQUAL "wolfSSL") - list(APPEND TESTS - test_public_key_auth_succeeds_with_correct_ed25519_key - test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key - test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem - test_public_key_auth_succeeds_with_correct_ecdsa_key - test_public_key_auth_succeeds_with_correct_signed_ecdsa_key - test_public_key_auth_succeeds_with_correct_signed_rsa_key - ) - endif() -endif() - -if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") - list(APPEND TESTS - test_public_key_auth_succeeds_with_correct_dsa_key - ) -endif() - add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) -target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include) +target_compile_definitions(runner PRIVATE "${CRYPTO_BACKEND_DEFINE}") +target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include "${CRYPTO_BACKEND_INCLUDE_DIR}") target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") # test building against shared libssh2 lib if(BUILD_SHARED_LIBS) - foreach(test ssh2) + foreach(test test_ssh2) add_executable(${test}_shared ${test}.c) target_include_directories(${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) target_link_libraries(${test}_shared ${LIB_SHARED} ${LIBRARIES}) endforeach() endif() -if(CMAKE_COMPILER_IS_GNUCC) - find_program(GCOV_PATH gcov) - if(GCOV_PATH) - set(GCOV_OPTIONS -g --coverage) - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) - set(GCOV_OPTIONS "${GCOV_OPTIONS} -fprofile-abs-path") - endif() - endif() -endif() - foreach(test ${TESTS}) add_executable(${test} ${test}.c) target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}") target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") # build a single test with gcov - if(GCOV_PATH AND test STREQUAL test_keyboard_interactive_auth_info_request) + if(GCOV_PATH AND test STREQUAL test_auth_keyboard_info_request) target_compile_options(${test} BEFORE PRIVATE ${GCOV_OPTIONS}) target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES} gcov) else() target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES}) endif() - if(test MATCHES "^test_") + if(NOT test STREQUAL "test_ssh2") # skip test that needs ssh2.sh to run list(APPEND TEST_TARGETS ${test}) add_test( NAME ${test} COMMAND $ @@ -138,24 +125,16 @@ foreach(test endforeach() # CRYPT tests -set(TESTS +foreach(test + 3des-cbc + aes128-cbc aes128-ctr + aes192-cbc aes192-ctr + aes256-cbc aes256-ctr + rijndael-cbc@lysator.liu.se ) -# Due to a bug with mbedTLS support, these crypt methods fail. Until that bug -# is fixed, don't run them there to avoid this known issue causing red tests. -# See https://github.com/libssh2/libssh2/issues/793 -if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") - list(APPEND TESTS - 3des-cbc - aes128-cbc - aes192-cbc - aes256-cbc - rijndael-cbc@lysator.liu.se - ) -endif() -foreach(test ${TESTS}) add_test(NAME test_${test} COMMAND "$") set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") endforeach() diff --git a/tests/Makefile.am b/tests/Makefile.am index d9f73165c0..8b3f7f9d9e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,37 +2,37 @@ SUBDIRS = ossfuzz AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/include -ctests = simple$(EXEEXT) +ctests = test_simple$(EXEEXT) TESTS = $(ctests) mansyntax.sh check_PROGRAMS = $(ctests) if SSHD TESTS += ssh2.sh -check_PROGRAMS += ssh2 +check_PROGRAMS += test_ssh2 endif INTEGRATION_TESTS = \ - test_warmup \ - test_agent_forward_succeeds \ + test_aa_warmup \ + test_agent_forward_ok \ + test_auth_keyboard_fail \ + test_auth_keyboard_info_request \ + test_auth_keyboard_ok \ + test_auth_password_fail_password \ + test_auth_password_fail_username \ + test_auth_password_ok \ + test_auth_pubkey_fail \ + test_auth_pubkey_ok_dsa \ + test_auth_pubkey_ok_ecdsa \ + test_auth_pubkey_ok_ecdsa_signed \ + test_auth_pubkey_ok_ed25519 \ + test_auth_pubkey_ok_ed25519_encrypted \ + test_auth_pubkey_ok_ed25519_mem \ + test_auth_pubkey_ok_rsa \ + test_auth_pubkey_ok_rsa_encrypted \ + test_auth_pubkey_ok_rsa_openssh \ + test_auth_pubkey_ok_rsa_signed \ test_hostkey \ test_hostkey_hash \ - test_keyboard_interactive_auth_fails_with_wrong_response \ - test_keyboard_interactive_auth_info_request \ - test_keyboard_interactive_auth_succeeds_with_correct_response \ - test_password_auth_fails_with_wrong_password \ - test_password_auth_fails_with_wrong_username \ - test_password_auth_succeeds_with_correct_credentials \ - test_public_key_auth_fails_with_wrong_key \ - test_public_key_auth_succeeds_with_correct_dsa_key \ - test_public_key_auth_succeeds_with_correct_ecdsa_key \ - test_public_key_auth_succeeds_with_correct_ed25519_key \ - test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem \ - test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key \ - test_public_key_auth_succeeds_with_correct_encrypted_rsa_key \ - test_public_key_auth_succeeds_with_correct_rsa_key \ - test_public_key_auth_succeeds_with_correct_rsa_openssh_key \ - test_public_key_auth_succeeds_with_correct_signed_ecdsa_key \ - test_public_key_auth_succeeds_with_correct_signed_rsa_key \ test_read # Integration tests using Docker @@ -48,7 +48,7 @@ check_LTLIBRARIES = librunner.la # This program uses an internal libssh2 function so it needs to be statically # linked against libssh2 -test_keyboard_interactive_auth_info_request_LDFLAGS = -static +test_auth_keyboard_info_request_LDFLAGS = -static # This must be last in the list so it resolves symbols in previous libraries LDADD += ../src/libssh2.la @@ -69,12 +69,9 @@ EXTRA_DIST = \ key_dsa_wrong.pub \ key_ecdsa \ key_ecdsa.pub \ - signed_key_ecdsa \ - signed_key_ecdsa.pub \ - signed_key_ecdsa-cert.pub \ - signed_key_rsa \ - signed_key_rsa-cert.pub \ - signed_key_rsa.pub \ + key_ecdsa_signed \ + key_ecdsa_signed-cert.pub \ + key_ecdsa_signed.pub \ key_ed25519 \ key_ed25519.pub \ key_ed25519_encrypted \ @@ -85,6 +82,9 @@ EXTRA_DIST = \ key_rsa_encrypted.pub \ key_rsa_openssh \ key_rsa_openssh.pub \ + key_rsa_signed \ + key_rsa_signed-cert.pub \ + key_rsa_signed.pub \ mansyntax.sh \ openssh_server/Dockerfile \ openssh_server/authorized_keys \ @@ -95,9 +95,9 @@ EXTRA_DIST = \ openssh_server/ssh_host_ecdsa_key \ openssh_server/ssh_host_ed25519_key \ openssh_server/ssh_host_rsa_key \ - simple.c \ + test_simple.c \ sshdwrap \ - ssh2.c \ + test_ssh2.c \ ssh2.sh \ sshd_fixture.sh.in \ test_read_3des-cbc \ diff --git a/tests/gen_keys.sh b/tests/gen_keys.sh new file mode 100755 index 0000000000..63e2149d3d --- /dev/null +++ b/tests/gen_keys.sh @@ -0,0 +1,74 @@ +#!/bin/sh -e + +# Generate test keys + +# tests/openssh_server + +rm ./openssh_server/*_key || true + +ssh-keygen -t rsa -b 2048 -N '' -m PEM -C '' -f 'openssh_server/ssh_host_rsa_key' +ssh-keygen -t ecdsa -b 256 -N '' -m PEM -C '' -f 'openssh_server/ssh_host_ecdsa_key' +ssh-keygen -t ed25519 -N '' -C '' -f 'openssh_server/ssh_host_ed25519_key' + +rm ./openssh_server/ca_* || true + +ssh-keygen -t ecdsa -b 521 -N '' -C 'ca_ecdsa' -f 'openssh_server/ca_ecdsa' +ssh-keygen -t rsa -b 3072 -N '' -C 'ca_rsa' -f 'openssh_server/ca_rsa' + +# tests + +rm './key_'* || true + +pw='libssh2' +id='identity' +pr='libssh2' + +ssh-keygen -t dsa -N '' -m PEM -C 'key_dsa' -f 'key_dsa' +ssh-keygen -t dsa -N '' -m PEM -C 'key_dsa_wrong' -f 'key_dsa_wrong' # FIXME? + +ssh-keygen -t rsa -b 2048 -N '' -m PEM -C 'key_rsa' -f 'key_rsa' +ssh-keygen -t rsa -b 2048 -N "${pw}" -m PEM -C 'key_rsa_encrypted' -f 'key_rsa_encrypted' +ssh-keygen -t rsa -b 2048 -N '' -C 'key_rsa_openssh' -f 'key_rsa_openssh' +ssh-keygen -t rsa -b 4096 -N '' -C 'key_rsa_signed' -f 'key_rsa_signed' + ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_rsa' 'key_rsa_signed.pub' + +ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa' -f 'key_ecdsa' +ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa_signed' -f 'key_ecdsa_signed' + ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_ecdsa' 'key_ecdsa_signed.pub' + +ssh-keygen -t ed25519 -N '' -C 'key_ed25519' -f 'key_ed25519' +ssh-keygen -t ed25519 -N "${pw}" -C 'key_ed25519_encrypted' -f 'key_ed25519_encrypted' + +cat \ + 'key_dsa.pub' \ + 'key_rsa.pub' \ + 'key_rsa_encrypted.pub' \ + 'key_rsa_openssh.pub' \ + 'key_ecdsa.pub' \ + 'key_ed25519.pub' \ + 'key_ed25519_encrypted.pub' \ + > openssh_server/authorized_keys + +# tests/etc + +rm etc/host* etc/user* || true + +ssh-keygen -t rsa -b 2048 -N '' -m PEM -C 'etc_host_rsa' -f 'etc/host' +ssh-keygen -t rsa -b 2048 -N '' -m PEM -C 'etc_user_rsa' -f 'etc/user' + +# tests/test_*.c + +echo 'Add these public keys and hashes to:' +echo ' - test_hostkey.c' +echo ' - test_hostkey_hash.c' + +for fn in ./openssh_server/*_key.pub; do + pub="$(grep -a -o -E ' [A-Za-z0-9+/=]+' < "${fn}" | head -1 | cut -c 2-)" + printf '====== %s\n' "${fn}" + printf 'BASE64 %s\n' "${pub}" + { + printf 'MD5 %s\n' "$(printf '%s' "${pub}" | openssl base64 -d -A | openssl dgst -hex -md5)" + printf 'SHA1 %s\n' "$(printf '%s' "${pub}" | openssl base64 -d -A | openssl dgst -hex -sha1)" + printf 'SHA256 %s\n' "$(printf '%s' "${pub}" | openssl base64 -d -A | openssl dgst -hex -sha256)" + } | tr '[:lower:]' '[:upper:]' +done diff --git a/tests/key_ecdsa.pub b/tests/key_ecdsa.pub index 597f63fcd4..7f50e19f08 100644 --- a/tests/key_ecdsa.pub +++ b/tests/key_ecdsa.pub @@ -1 +1 @@ -ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBOiyJJwf+hFJrOkik9IQVxjhhVnI1vKl4BGLj03erLvw4TXXwoZzlPx6J936fU9JvvPw+d8PA4viMEfFbmdbHREKhwi3u1vZrfj0mB8SXw96AcZwX8PAL556wgom+/Qx+Q== +ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBOiyJJwf+hFJrOkik9IQVxjhhVnI1vKl4BGLj03erLvw4TXXwoZzlPx6J936fU9JvvPw+d8PA4viMEfFbmdbHREKhwi3u1vZrfj0mB8SXw96AcZwX8PAL556wgom+/Qx+Q== diff --git a/tests/signed_key_ecdsa b/tests/key_ecdsa_signed similarity index 100% rename from tests/signed_key_ecdsa rename to tests/key_ecdsa_signed diff --git a/tests/signed_key_ecdsa-cert.pub b/tests/key_ecdsa_signed-cert.pub similarity index 97% rename from tests/signed_key_ecdsa-cert.pub rename to tests/key_ecdsa_signed-cert.pub index ee32719bd6..3f1db684ac 100644 --- a/tests/signed_key_ecdsa-cert.pub +++ b/tests/key_ecdsa_signed-cert.pub @@ -1 +1 @@ -ecdsa-sha2-nistp384-cert-v01@openssh.com AAAAKGVjZHNhLXNoYTItbmlzdHAzODQtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgQCXc1JaqZ4XzkudbzP/pgEUbkioo7pl9aB09h6sg7KYAAAAIbmlzdHAzODQAAABhBG/X9+c3VK4iSDbbaNifJKognzwnkzdsHokZ6WgqEi+dl085JUW4UGO4Xs0+sauybztCy1AVsOIuEiVwM0cirRWFLmK0c0yO0LpiZFHHuaVBJc9tFEXkxyXG8MkIzIAhqAAAAAAAAAABAAAAAQAAAAhpZGVudGl0eQAAAAsAAAAHbGlic3NoMgAAAAAAAAAA//////////8AAAAAAAAAggAAABVwZXJtaXQtWDExLWZvcndhcmRpbmcAAAAAAAAAF3Blcm1pdC1hZ2VudC1mb3J3YXJkaW5nAAAAAAAAABZwZXJtaXQtcG9ydC1mb3J3YXJkaW5nAAAAAAAAAApwZXJtaXQtcHR5AAAAAAAAAA5wZXJtaXQtdXNlci1yYwAAAAAAAAAAAAAArAAAABNlY2RzYS1zaGEyLW5pc3RwNTIxAAAACG5pc3RwNTIxAAAAhQQAfv15s+G2xg56J+audKAM4G9qOTFrbZRo0CTwvkb/oHrf9/2RSWqYsx/0m5mYCZVlecnZqwRHAOolXbc/Yb4cGjsALUj3UDirsnYR7Ve+SwnunkpvW/H3a98sA3sS+HCpd5RbpfWClSBOI9JEAlPtS1CrEQ7EmO7hmlFOH2cL0qfHCyYAAACnAAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAACMAAAAQgGxnhh8z8LNk5pMw0D9InyEtVRm8OJi23XEhqj/ieT/BsLZXbu65UAcMjrUn6DPdERxF9Dwe9pdIAWOLLjLHYEFBQAAAEIAlxz+XjUKa9Q2vpH0y8IgJMm0H1hTBUM1DQEoL8No1BVtgtIO20mac2fE3I35JxNDmmXoW+FuzmJnyrY9rxY+YXM= ./signed_key_ecdsa.pub +ecdsa-sha2-nistp384-cert-v01@openssh.com AAAAKGVjZHNhLXNoYTItbmlzdHAzODQtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgQCXc1JaqZ4XzkudbzP/pgEUbkioo7pl9aB09h6sg7KYAAAAIbmlzdHAzODQAAABhBG/X9+c3VK4iSDbbaNifJKognzwnkzdsHokZ6WgqEi+dl085JUW4UGO4Xs0+sauybztCy1AVsOIuEiVwM0cirRWFLmK0c0yO0LpiZFHHuaVBJc9tFEXkxyXG8MkIzIAhqAAAAAAAAAABAAAAAQAAAAhpZGVudGl0eQAAAAsAAAAHbGlic3NoMgAAAAAAAAAA//////////8AAAAAAAAAggAAABVwZXJtaXQtWDExLWZvcndhcmRpbmcAAAAAAAAAF3Blcm1pdC1hZ2VudC1mb3J3YXJkaW5nAAAAAAAAABZwZXJtaXQtcG9ydC1mb3J3YXJkaW5nAAAAAAAAAApwZXJtaXQtcHR5AAAAAAAAAA5wZXJtaXQtdXNlci1yYwAAAAAAAAAAAAAArAAAABNlY2RzYS1zaGEyLW5pc3RwNTIxAAAACG5pc3RwNTIxAAAAhQQAfv15s+G2xg56J+audKAM4G9qOTFrbZRo0CTwvkb/oHrf9/2RSWqYsx/0m5mYCZVlecnZqwRHAOolXbc/Yb4cGjsALUj3UDirsnYR7Ve+SwnunkpvW/H3a98sA3sS+HCpd5RbpfWClSBOI9JEAlPtS1CrEQ7EmO7hmlFOH2cL0qfHCyYAAACnAAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAACMAAAAQgGxnhh8z8LNk5pMw0D9InyEtVRm8OJi23XEhqj/ieT/BsLZXbu65UAcMjrUn6DPdERxF9Dwe9pdIAWOLLjLHYEFBQAAAEIAlxz+XjUKa9Q2vpH0y8IgJMm0H1hTBUM1DQEoL8No1BVtgtIO20mac2fE3I35JxNDmmXoW+FuzmJnyrY9rxY+YXM= key_ecdsa_signed.pub diff --git a/tests/signed_key_ecdsa.pub b/tests/key_ecdsa_signed.pub similarity index 86% rename from tests/signed_key_ecdsa.pub rename to tests/key_ecdsa_signed.pub index 3b208f8a46..888665459e 100644 --- a/tests/signed_key_ecdsa.pub +++ b/tests/key_ecdsa_signed.pub @@ -1 +1 @@ -ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBG/X9+c3VK4iSDbbaNifJKognzwnkzdsHokZ6WgqEi+dl085JUW4UGO4Xs0+sauybztCy1AVsOIuEiVwM0cirRWFLmK0c0yO0LpiZFHHuaVBJc9tFEXkxyXG8MkIzIAhqA== +ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBG/X9+c3VK4iSDbbaNifJKognzwnkzdsHokZ6WgqEi+dl085JUW4UGO4Xs0+sauybztCy1AVsOIuEiVwM0cirRWFLmK0c0yO0LpiZFHHuaVBJc9tFEXkxyXG8MkIzIAhqA== key_ecdsa_signed diff --git a/tests/key_rsa_openssh.pub b/tests/key_rsa_openssh.pub index 9fc4ac2742..ecd0079091 100644 --- a/tests/key_rsa_openssh.pub +++ b/tests/key_rsa_openssh.pub @@ -1 +1 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTe1lN2L/yet0Ma1JzXkQf3t1f+pauALec2FsGZy87KRJW1AOxcTTiePjlFwP1yfSK1lWXQ+uf0b61gkKqqR52FDky24HJWuYlfXlEQMn2d/PNDNVDDbO4TXKyNxxUHFJ6qYMNd4kWjOH+6rmYoWKsWV+3mDRbHagbVPEYL8wep8OTqKOqruVLVPzZyYZkBtn4XOFi6UE8WKiSVdK1Am1O5UxvlD95t32eYch6wQ9azgMqja6spe/L5UJgP83QZFknVC3wPZWkjqomVFql0FpaQclENwyY/OZMxr0cT/f7bCL6s4A/1XpbsGmC0xak4/THHbOn+0LdIej2nGV8JFoR will@iCube.local +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTe1lN2L/yet0Ma1JzXkQf3t1f+pauALec2FsGZy87KRJW1AOxcTTiePjlFwP1yfSK1lWXQ+uf0b61gkKqqR52FDky24HJWuYlfXlEQMn2d/PNDNVDDbO4TXKyNxxUHFJ6qYMNd4kWjOH+6rmYoWKsWV+3mDRbHagbVPEYL8wep8OTqKOqruVLVPzZyYZkBtn4XOFi6UE8WKiSVdK1Am1O5UxvlD95t32eYch6wQ9azgMqja6spe/L5UJgP83QZFknVC3wPZWkjqomVFql0FpaQclENwyY/OZMxr0cT/f7bCL6s4A/1XpbsGmC0xak4/THHbOn+0LdIej2nGV8JFoR diff --git a/tests/signed_key_rsa b/tests/key_rsa_signed similarity index 100% rename from tests/signed_key_rsa rename to tests/key_rsa_signed diff --git a/tests/signed_key_rsa-cert.pub b/tests/key_rsa_signed-cert.pub similarity index 96% rename from tests/signed_key_rsa-cert.pub rename to tests/key_rsa_signed-cert.pub index 34dd79d104..de7a8301cf 100644 --- a/tests/signed_key_rsa-cert.pub +++ b/tests/key_rsa_signed-cert.pub @@ -1 +1 @@ -ssh-rsa-cert-v01@openssh.com AAAAHHNzaC1yc2EtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgqdnJWdHT2qMpEe6kVJ81q9c0U3ODMvcuWfJJkV8UVBoAAAADAQABAAACAQCwMtW6rz83hgCKqV1Xf2KPgtWA5pkVA3jY4CosgWsV8rjwSpq+AMmB1wzVdTT/zrEEyy2iLoIwiAXQ7wlpo1QQWklnChIdlbaxg+F0UullsYIYoExrL+9YMwRGwmd00yIe/POHlBCa10qeBWfdMmjt5ZDlakPVYwFjvK5lZ0UW1FM1ucqX5HoIPhVONfReZonCP+jwvin44IMaqtdaSy4k71Qq7RuRbMYeTzpNaxv2CbxubvY5E7wlDrT47e25Dn/XeoV2VEX9T87ZAMnwmeyDbKW2Dv48l4Zze3Y8veUojfH3NlA/F9+1PwdTlqKsf45E/VVLyTTtn1KJy2hLyuav8Qt6Wgew41G2F9alDJab11urcogRiHyI/oPo0c6Km1vieF7IfW72yE5TFTZtbzSNS+W0GCo1xh4TUx8bBNXHO4+mDFt2gNCgX+Hf64FlPqM0kaZSUtBVKrWSupgTbMSXfHbRV5NJvSdGpPUWeFD1ifxYcPhxwJlznTXVQumEglDueIMsnE8yKEYjREtuao8/r9+ORtqf9OPZsT9j+bwROevLFnKZkzfD9xYQyU2aMrRDuo8R6SD7SiI6tXRwlohdflXA6ng9RTNyqVROQDOJ94bGPD5b4Bbnm31s2GhhWjoByQGlkNW4BRDEJmgG9sE8ztAxl7d8CV2V93BOisaPkwAAAAAAAAABAAAAAQAAAAhpZGVudGl0eQAAAAsAAAAHbGlic3NoMgAAAAAAAAAA//////////8AAAAAAAAAggAAABVwZXJtaXQtWDExLWZvcndhcmRpbmcAAAAAAAAAF3Blcm1pdC1hZ2VudC1mb3J3YXJkaW5nAAAAAAAAABZwZXJtaXQtcG9ydC1mb3J3YXJkaW5nAAAAAAAAAApwZXJtaXQtcHR5AAAAAAAAAA5wZXJtaXQtdXNlci1yYwAAAAAAAAAAAAABlwAAAAdzc2gtcnNhAAAAAwEAAQAAAYEAxIgbEZbIoQoNJyRjalEYbMwmcNRcGZg6ZA+uC+hxX9lPxhVxYAwbWCWfM3YLmvkQPRf0DYateDlHpiV9/R4IAKMfwHMINbyj5ulj2AG9wzMs10+MLN9kmxXeZXf7EK6iVHjMWhS7tX9NnmNFLbUHuPpzI6DODHvfEIaO084KQyIJ/Z5bONko7eijPZrqkwSFb+FEsIvSLBZ/ueHtAhI34IhclPP/Gx+r6da7TDwOpuL7oncrdqT+zxxZ1J4pEBrGhuJXTvw/xtBRbTKj13gtcEFyOUR50Z7PU4iOhKd694euGSOYgWGXhtehZPp7hr7afli1hOZtNb3xB3OaPqdPY/jYtZkOaZlKtwDjPzGTIfngpE7LZwsp4P2xxGUyCkItZ57uveDHKvFtb9+MIDMgTd27xOuTYYyHS7m5x7w4M1Z9du8IzxHXlQ/UobQAsTUuGusSQloOpZR1cs3s6p4+vLpl63tNjLFy2xYpFf3xL1Dl1Kf6w3qPiyYs5NmxwJcpAAABlAAAAAxyc2Etc2hhMi01MTIAAAGAK6d2jj8qv89wqRuE2bUFKKJDH4aIs7PGzKclTjZFomlkGvjRF/bsdDeUgwWdJ98j2TPdUvsAMlQrDS1e0OrDicen6eHrFhirpQxVLsAxj/c56nLedvzpbA/BLh8cFcq1vUZ1QHb2WOgOqWRcRbH/3TZhlA+gJ46kKs3QEw9uYy6m906xGwCWRiBUetfll5hS1sWCbAP2LLnA/OJUbIK9vKynombePRApY3LuZ8Hr0JCGgeBnfsesFbWLN6Gb+jT0KR4ah7O39lqecmvdUOR5XcMaSp+sgPpdBr7CzA5lkZnoI/M2J7AV1P5SX/q7/khJMKHuKwAsYf5kNAQdnEnwrqNTp//+qIWe5KjAtc0N5UOF5aK0e1iNaBxSHZA08psRLCCUf3PW3zMIlphUF7qIrRfV+s5fUMW0iIS2iUqI8dTrD0OH0wU10ERKQPixNCqtxBSbJzOyhDWPkTNfBshS8zA2/OVfug0zuxaINpAnZaiCcMnyCjATuWtvWpad6yF9 signed_key_rsa +ssh-rsa-cert-v01@openssh.com AAAAHHNzaC1yc2EtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgqdnJWdHT2qMpEe6kVJ81q9c0U3ODMvcuWfJJkV8UVBoAAAADAQABAAACAQCwMtW6rz83hgCKqV1Xf2KPgtWA5pkVA3jY4CosgWsV8rjwSpq+AMmB1wzVdTT/zrEEyy2iLoIwiAXQ7wlpo1QQWklnChIdlbaxg+F0UullsYIYoExrL+9YMwRGwmd00yIe/POHlBCa10qeBWfdMmjt5ZDlakPVYwFjvK5lZ0UW1FM1ucqX5HoIPhVONfReZonCP+jwvin44IMaqtdaSy4k71Qq7RuRbMYeTzpNaxv2CbxubvY5E7wlDrT47e25Dn/XeoV2VEX9T87ZAMnwmeyDbKW2Dv48l4Zze3Y8veUojfH3NlA/F9+1PwdTlqKsf45E/VVLyTTtn1KJy2hLyuav8Qt6Wgew41G2F9alDJab11urcogRiHyI/oPo0c6Km1vieF7IfW72yE5TFTZtbzSNS+W0GCo1xh4TUx8bBNXHO4+mDFt2gNCgX+Hf64FlPqM0kaZSUtBVKrWSupgTbMSXfHbRV5NJvSdGpPUWeFD1ifxYcPhxwJlznTXVQumEglDueIMsnE8yKEYjREtuao8/r9+ORtqf9OPZsT9j+bwROevLFnKZkzfD9xYQyU2aMrRDuo8R6SD7SiI6tXRwlohdflXA6ng9RTNyqVROQDOJ94bGPD5b4Bbnm31s2GhhWjoByQGlkNW4BRDEJmgG9sE8ztAxl7d8CV2V93BOisaPkwAAAAAAAAABAAAAAQAAAAhpZGVudGl0eQAAAAsAAAAHbGlic3NoMgAAAAAAAAAA//////////8AAAAAAAAAggAAABVwZXJtaXQtWDExLWZvcndhcmRpbmcAAAAAAAAAF3Blcm1pdC1hZ2VudC1mb3J3YXJkaW5nAAAAAAAAABZwZXJtaXQtcG9ydC1mb3J3YXJkaW5nAAAAAAAAAApwZXJtaXQtcHR5AAAAAAAAAA5wZXJtaXQtdXNlci1yYwAAAAAAAAAAAAABlwAAAAdzc2gtcnNhAAAAAwEAAQAAAYEAxIgbEZbIoQoNJyRjalEYbMwmcNRcGZg6ZA+uC+hxX9lPxhVxYAwbWCWfM3YLmvkQPRf0DYateDlHpiV9/R4IAKMfwHMINbyj5ulj2AG9wzMs10+MLN9kmxXeZXf7EK6iVHjMWhS7tX9NnmNFLbUHuPpzI6DODHvfEIaO084KQyIJ/Z5bONko7eijPZrqkwSFb+FEsIvSLBZ/ueHtAhI34IhclPP/Gx+r6da7TDwOpuL7oncrdqT+zxxZ1J4pEBrGhuJXTvw/xtBRbTKj13gtcEFyOUR50Z7PU4iOhKd694euGSOYgWGXhtehZPp7hr7afli1hOZtNb3xB3OaPqdPY/jYtZkOaZlKtwDjPzGTIfngpE7LZwsp4P2xxGUyCkItZ57uveDHKvFtb9+MIDMgTd27xOuTYYyHS7m5x7w4M1Z9du8IzxHXlQ/UobQAsTUuGusSQloOpZR1cs3s6p4+vLpl63tNjLFy2xYpFf3xL1Dl1Kf6w3qPiyYs5NmxwJcpAAABlAAAAAxyc2Etc2hhMi01MTIAAAGAK6d2jj8qv89wqRuE2bUFKKJDH4aIs7PGzKclTjZFomlkGvjRF/bsdDeUgwWdJ98j2TPdUvsAMlQrDS1e0OrDicen6eHrFhirpQxVLsAxj/c56nLedvzpbA/BLh8cFcq1vUZ1QHb2WOgOqWRcRbH/3TZhlA+gJ46kKs3QEw9uYy6m906xGwCWRiBUetfll5hS1sWCbAP2LLnA/OJUbIK9vKynombePRApY3LuZ8Hr0JCGgeBnfsesFbWLN6Gb+jT0KR4ah7O39lqecmvdUOR5XcMaSp+sgPpdBr7CzA5lkZnoI/M2J7AV1P5SX/q7/khJMKHuKwAsYf5kNAQdnEnwrqNTp//+qIWe5KjAtc0N5UOF5aK0e1iNaBxSHZA08psRLCCUf3PW3zMIlphUF7qIrRfV+s5fUMW0iIS2iUqI8dTrD0OH0wU10ERKQPixNCqtxBSbJzOyhDWPkTNfBshS8zA2/OVfug0zuxaINpAnZaiCcMnyCjATuWtvWpad6yF9 key_rsa_signed diff --git a/tests/signed_key_rsa.pub b/tests/key_rsa_signed.pub similarity index 95% rename from tests/signed_key_rsa.pub rename to tests/key_rsa_signed.pub index 34376b1def..d8ae239fc6 100644 --- a/tests/signed_key_rsa.pub +++ b/tests/key_rsa_signed.pub @@ -1 +1 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCwMtW6rz83hgCKqV1Xf2KPgtWA5pkVA3jY4CosgWsV8rjwSpq+AMmB1wzVdTT/zrEEyy2iLoIwiAXQ7wlpo1QQWklnChIdlbaxg+F0UullsYIYoExrL+9YMwRGwmd00yIe/POHlBCa10qeBWfdMmjt5ZDlakPVYwFjvK5lZ0UW1FM1ucqX5HoIPhVONfReZonCP+jwvin44IMaqtdaSy4k71Qq7RuRbMYeTzpNaxv2CbxubvY5E7wlDrT47e25Dn/XeoV2VEX9T87ZAMnwmeyDbKW2Dv48l4Zze3Y8veUojfH3NlA/F9+1PwdTlqKsf45E/VVLyTTtn1KJy2hLyuav8Qt6Wgew41G2F9alDJab11urcogRiHyI/oPo0c6Km1vieF7IfW72yE5TFTZtbzSNS+W0GCo1xh4TUx8bBNXHO4+mDFt2gNCgX+Hf64FlPqM0kaZSUtBVKrWSupgTbMSXfHbRV5NJvSdGpPUWeFD1ifxYcPhxwJlznTXVQumEglDueIMsnE8yKEYjREtuao8/r9+ORtqf9OPZsT9j+bwROevLFnKZkzfD9xYQyU2aMrRDuo8R6SD7SiI6tXRwlohdflXA6ng9RTNyqVROQDOJ94bGPD5b4Bbnm31s2GhhWjoByQGlkNW4BRDEJmgG9sE8ztAxl7d8CV2V93BOisaPkw== signed_key_rsa +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCwMtW6rz83hgCKqV1Xf2KPgtWA5pkVA3jY4CosgWsV8rjwSpq+AMmB1wzVdTT/zrEEyy2iLoIwiAXQ7wlpo1QQWklnChIdlbaxg+F0UullsYIYoExrL+9YMwRGwmd00yIe/POHlBCa10qeBWfdMmjt5ZDlakPVYwFjvK5lZ0UW1FM1ucqX5HoIPhVONfReZonCP+jwvin44IMaqtdaSy4k71Qq7RuRbMYeTzpNaxv2CbxubvY5E7wlDrT47e25Dn/XeoV2VEX9T87ZAMnwmeyDbKW2Dv48l4Zze3Y8veUojfH3NlA/F9+1PwdTlqKsf45E/VVLyTTtn1KJy2hLyuav8Qt6Wgew41G2F9alDJab11urcogRiHyI/oPo0c6Km1vieF7IfW72yE5TFTZtbzSNS+W0GCo1xh4TUx8bBNXHO4+mDFt2gNCgX+Hf64FlPqM0kaZSUtBVKrWSupgTbMSXfHbRV5NJvSdGpPUWeFD1ifxYcPhxwJlznTXVQumEglDueIMsnE8yKEYjREtuao8/r9+ORtqf9OPZsT9j+bwROevLFnKZkzfD9xYQyU2aMrRDuo8R6SD7SiI6tXRwlohdflXA6ng9RTNyqVROQDOJ94bGPD5b4Bbnm31s2GhhWjoByQGlkNW4BRDEJmgG9sE8ztAxl7d8CV2V93BOisaPkw== key_rsa_signed diff --git a/tests/runner.c b/tests/runner.c index c2585073d0..f768cd7002 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -40,10 +40,15 @@ int main(void) { int exit_code = 1; - LIBSSH2_SESSION *session = start_session_fixture(); + int skipped; + LIBSSH2_SESSION *session = start_session_fixture(&skipped); if(session) { exit_code = (test(session) == 0) ? 0 : 1; } + else if(skipped) { + fprintf(stderr, "Test skipped.\n"); + exit_code = 0; + } stop_session_fixture(); return exit_code; } diff --git a/tests/session_fixture.c b/tests/session_fixture.c index ebaa20db3a..4997d4abf8 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -99,10 +99,34 @@ static void setup_fixture_workdir(void) chdir(wd); } -LIBSSH2_SESSION *start_session_fixture(void) +LIBSSH2_SESSION *start_session_fixture(int *skipped) { int rc; - const char *env; + + const char *crypt = getenv("FIXTURE_TEST_CRYPT"); + const char *mac = getenv("FIXTURE_TEST_MAC"); + + *skipped = 0; + + if(crypt) { +#ifdef LIBSSH2_MBEDTLS + /* Due to a bug with mbedTLS support, these crypt methods fail. + Until that bug is fixed, don't run them there to avoid this + known issue causing red tests. + See: https://github.com/libssh2/libssh2/issues/793 + */ + if(strcmp(crypt, "3des-cbc") == 0 || + strcmp(crypt, "aes128-cbc") == 0 || + strcmp(crypt, "aes192-cbc") == 0 || + strcmp(crypt, "aes256-cbc") == 0 || + strcmp(crypt, "rijndael-cbc@lysator.liu.se") == 0) { + fprintf(stderr, "crypt algorithm (%s) skipped " + "for this crypto backend.\n", crypt); + *skipped = 1; + return NULL; + } +#endif + } setup_fixture_workdir(); @@ -126,26 +150,25 @@ LIBSSH2_SESSION *start_session_fixture(void) } /* Override crypt algorithm for the test */ - env = getenv("FIXTURE_TEST_CRYPT"); - if(env) { + if(crypt) { if(libssh2_session_method_pref(connected_session, - LIBSSH2_METHOD_CRYPT_CS, env) || + LIBSSH2_METHOD_CRYPT_CS, crypt) || libssh2_session_method_pref(connected_session, - LIBSSH2_METHOD_CRYPT_SC, env)) { + LIBSSH2_METHOD_CRYPT_SC, crypt)) { fprintf(stderr, "libssh2_session_method_pref CRYPT failed " - "(probably disabled in the build): '%s'\n", env); + "(probably disabled in the build): '%s'\n", crypt); return NULL; } } + /* Override mac algorithm for the test */ - env = getenv("FIXTURE_TEST_MAC"); - if(env) { + if(mac) { if(libssh2_session_method_pref(connected_session, - LIBSSH2_METHOD_MAC_CS, env) || + LIBSSH2_METHOD_MAC_CS, mac) || libssh2_session_method_pref(connected_session, - LIBSSH2_METHOD_MAC_SC, env)) { + LIBSSH2_METHOD_MAC_SC, mac)) { fprintf(stderr, "libssh2_session_method_pref MAC failed " - "(probably disabled in the build): '%s'\n", env); + "(probably disabled in the build): '%s'\n", mac); return NULL; } } @@ -169,7 +192,7 @@ void print_last_session_error(const char *function) fprintf(stderr, "%s failed (%d): %s\n", function, rc, message); } else { - fprintf(stderr, "No session"); + fprintf(stderr, "No session\n"); } } @@ -182,7 +205,7 @@ void stop_session_fixture(void) connected_session = NULL; } else { - fprintf(stderr, "Cannot stop session - none started"); + fprintf(stderr, "Cannot stop session - none started\n"); } stop_openssh_fixture(); @@ -206,16 +229,244 @@ const char *srcdir_path(const char *file) assert(curpath < NUMPATHS); if(p) { /* Ensure the final string is nul-terminated on Windows */ - filepath[curpath][sizeof(filepath[0])-1] = 0; - snprintf(filepath[curpath], sizeof(filepath[0])-1, "%s/%s", - p, file); + filepath[curpath][sizeof(filepath[0]) - 1] = 0; + snprintf(filepath[curpath], sizeof(filepath[0]) - 1, "%s/%s", + p, file); } else { /* Ensure the final string is nul-terminated on Windows */ - filepath[curpath][sizeof(filepath[0])-1] = 0; - snprintf(filepath[curpath], sizeof(filepath[0])-1, "%s", - file); + filepath[curpath][sizeof(filepath[0]) - 1] = 0; + snprintf(filepath[curpath], sizeof(filepath[0]) - 1, "%s", + file); } return filepath[curpath++]; } + +static const char *kbd_password; + +static void kbd_callback(const char *name, int name_len, + const char *instruct, int instruct_len, + int num_prompts, + const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, + LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, + void **abstract) +{ + int i; + (void)abstract; + + fprintf(stdout, "Kb-int name: %.*s\n", name_len, name); + fprintf(stdout, "Kb-int instruction: %.*s\n", instruct_len, instruct); + for(i = 0; i < num_prompts; ++i) { + fprintf(stdout, "Kb-int prompt %d: %.*s\n", i, + (int)prompts[i].length, prompts[i].text); + } + + if(num_prompts == 1) { + responses[0].text = strdup(kbd_password); + responses[0].length = (unsigned int)strlen(kbd_password); + } +} + +int test_auth_keyboard(LIBSSH2_SESSION *session, int flags, + const char *username, + const char *password) +{ + int rc; + + const char *userauth_list = + libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); + if(!userauth_list) { + print_last_session_error("libssh2_userauth_list"); + return 1; + } + + if(!strstr(userauth_list, "keyboard-interactive")) { + fprintf(stderr, + "'keyboard-interactive' was expected in userauth list: %s\n", + userauth_list); + return 1; + } + + kbd_password = password; + + rc = libssh2_userauth_keyboard_interactive_ex(session, username, + (unsigned int)strlen(username), + kbd_callback); + + if((flags & TEST_AUTH_SHOULDFAIL) != 0) { + if(rc == 0) { + fprintf(stderr, "Keyboard-interactive auth succeeded " + "with wrong response\n"); + return 1; + } + } + else { + if(rc) { + print_last_session_error( + "libssh2_userauth_keyboard_interactive_ex"); + return 1; + } + } + + return 0; +} + +int test_auth_password(LIBSSH2_SESSION *session, int flags, + const char *username, + const char *password) +{ + int rc; + + const char *userauth_list = + libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); + if(!userauth_list) { + print_last_session_error("libssh2_userauth_list"); + return 1; + } + + if(!strstr(userauth_list, "password")) { + fprintf(stderr, "'password' was expected in userauth list: %s\n", + userauth_list); + return 1; + } + + rc = libssh2_userauth_password_ex(session, username, + (unsigned int)strlen(username), + password, + (unsigned int)strlen(password), + NULL); + + if((flags & TEST_AUTH_SHOULDFAIL) != 0) { + if(rc == 0) { + fprintf(stderr, "Password auth succeeded with wrong password\n"); + return 1; + } + } + else { + if(rc) { + print_last_session_error("libssh2_userauth_password_ex"); + return 1; + } + + if(libssh2_userauth_authenticated(session) == 0) { + fprintf(stderr, "Password auth appeared to succeed but " + "libssh2_userauth_authenticated returned 0\n"); + return 1; + } + } + + return 0; +} + +static int read_file(const char *path, char **out_buffer, size_t *out_len) +{ + FILE *fp = NULL; + char *buffer = NULL; + size_t len = 0; + + if(!out_buffer || !out_len || !path) { + fprintf(stderr, "invalid params.\n"); + return 1; + } + + *out_buffer = NULL; + *out_len = 0; + + fp = fopen(path, "r"); + + if(!fp) { + fprintf(stderr, "File could not be read: %s\n", path); + return 1; + } + + fseek(fp, 0L, SEEK_END); + len = ftell(fp); + rewind(fp); + + buffer = calloc(1, len + 1); + if(!buffer) { + fclose(fp); + fprintf(stderr, "Could not alloc memory.\n"); + return 1; + } + + if(1 != fread(buffer, len, 1, fp)) { + fclose(fp); + free(buffer); + fprintf(stderr, "Could not read file into memory.\n"); + return 1; + } + + fclose(fp); + + *out_buffer = buffer; + *out_len = len; + + return 0; +} + +int test_auth_pubkey(LIBSSH2_SESSION *session, int flags, + const char *username, + const char *password, + const char *fn_pub, + const char *fn_priv) +{ + int rc; + + const char *userauth_list = + libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); + if(!userauth_list) { + print_last_session_error("libssh2_userauth_list"); + return 1; + } + + if(!strstr(userauth_list, "publickey")) { + fprintf(stderr, "'publickey' was expected in userauth list: %s\n", + userauth_list); + return 1; + } + + if((flags & TEST_AUTH_FROMMEM) != 0) { + char *buffer = NULL; + size_t len = 0; + + if(read_file(srcdir_path(fn_priv), &buffer, &len)) { + fprintf(stderr, "Reading key file failed.\n"); + return 1; + } + + rc = libssh2_userauth_publickey_frommemory(session, + username, strlen(username), + NULL, 0, + buffer, len, + NULL); + + free(buffer); + } + else { + rc = libssh2_userauth_publickey_fromfile_ex(session, username, + (unsigned int)strlen(username), + srcdir_path(fn_pub), + srcdir_path(fn_priv), + password); + } + + if((flags & TEST_AUTH_SHOULDFAIL) != 0) { + if(rc == 0) { + fprintf(stderr, "Public-key auth succeeded with wrong key\n"); + return 1; + } + } + else { + if(rc) { + print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); + return 1; + } + } + + return 0; +} diff --git a/tests/session_fixture.h b/tests/session_fixture.h index 5314fa5789..91db09a934 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -38,16 +38,31 @@ #ifndef LIBSSH2_TESTS_SESSION_FIXTURE_H #define LIBSSH2_TESTS_SESSION_FIXTURE_H -#include "libssh2_setup.h" -#include +#define LIBSSH2_TESTS -#if defined(_MSC_VER) && _MSC_VER < 1900 -#define snprintf _snprintf -#endif +#include "libssh2_priv.h" +#include -LIBSSH2_SESSION *start_session_fixture(void); +LIBSSH2_SESSION *start_session_fixture(int *skipped); void stop_session_fixture(void); void print_last_session_error(const char *function); const char *srcdir_path(const char *file); +#define TEST_AUTH_SHOULDFAIL 1 +#define TEST_AUTH_FROMMEM 2 + +int test_auth_keyboard(LIBSSH2_SESSION *session, int flags, + const char *username, + const char *password); + +int test_auth_password(LIBSSH2_SESSION *session, int flags, + const char *username, + const char *password); + +int test_auth_pubkey(LIBSSH2_SESSION *session, int flags, + const char *username, + const char *password, + const char *fn_pub, + const char *fn_priv); + #endif diff --git a/tests/ssh2.sh b/tests/ssh2.sh index 4e475e6e75..fa604cb2d7 100755 --- a/tests/ssh2.sh +++ b/tests/ssh2.sh @@ -8,7 +8,7 @@ srcdir="${srcdir:-$PWD}" SSHD="${SSHD:-/usr/sbin/sshd}" -cmd="./ssh2${EXEEXT}" +cmd="./test_ssh2${EXEEXT}" srcdir="$(cd "$srcdir" || exit; pwd)" export PRIVKEY="$srcdir/etc/user" diff --git a/tests/test_warmup.c b/tests/test_aa_warmup.c similarity index 100% rename from tests/test_warmup.c rename to tests/test_aa_warmup.c diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_ok.c similarity index 77% rename from tests/test_agent_forward_succeeds.c rename to tests/test_agent_forward_ok.c index cb70baeece..7c9cfe3c5d 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_ok.c @@ -23,10 +23,11 @@ int test(LIBSSH2_SESSION *session) return 1; } - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); + rc = libssh2_userauth_publickey_fromfile_ex(session, USERNAME, + (unsigned int)strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), + srcdir_path(KEY_FILE_PRIVATE), + NULL); if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; diff --git a/tests/test_auth_keyboard_fail.c b/tests/test_auth_keyboard_fail.c new file mode 100644 index 0000000000..e8e5942be8 --- /dev/null +++ b/tests/test_auth_keyboard_fail.c @@ -0,0 +1,8 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + return test_auth_keyboard(session, TEST_AUTH_SHOULDFAIL, + "libssh2", /* set in Dockerfile */ + "I'm the wrong password"); +} diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_auth_keyboard_info_request.c similarity index 99% rename from tests/test_keyboard_interactive_auth_info_request.c rename to tests/test_auth_keyboard_info_request.c index 860da944e5..405a266219 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_auth_keyboard_info_request.c @@ -249,8 +249,10 @@ int test_case(int num, char *message; int error_code; LIBSSH2_SESSION *session = NULL; + alloc_count = 0; free_count = 0; + session = libssh2_session_init_ex(test_alloc, test_free, NULL, abstract); if(!session) { fprintf(stderr, "libssh2_session_init_ex failed\n"); diff --git a/tests/test_auth_keyboard_ok.c b/tests/test_auth_keyboard_ok.c new file mode 100644 index 0000000000..1871f74f97 --- /dev/null +++ b/tests/test_auth_keyboard_ok.c @@ -0,0 +1,8 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + return test_auth_keyboard(session, 0, + "libssh2", /* set in Dockerfile */ + "my test password"); /* set in Dockerfile */ +} diff --git a/tests/test_auth_password_fail_password.c b/tests/test_auth_password_fail_password.c new file mode 100644 index 0000000000..c1383213d4 --- /dev/null +++ b/tests/test_auth_password_fail_password.c @@ -0,0 +1,8 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + return test_auth_password(session, TEST_AUTH_SHOULDFAIL, + "libssh2", /* set in Dockerfile */ + "I'm the wrong password"); +} diff --git a/tests/test_auth_password_fail_username.c b/tests/test_auth_password_fail_username.c new file mode 100644 index 0000000000..6478d0f444 --- /dev/null +++ b/tests/test_auth_password_fail_username.c @@ -0,0 +1,8 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + return test_auth_password(session, TEST_AUTH_SHOULDFAIL, + "I'm the wrong username", + "my test password"); /* set in Dockerfile */ +} diff --git a/tests/test_auth_password_ok.c b/tests/test_auth_password_ok.c new file mode 100644 index 0000000000..9e2ca45f5b --- /dev/null +++ b/tests/test_auth_password_ok.c @@ -0,0 +1,8 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + return test_auth_password(session, 0, + "libssh2", /* set in Dockerfile */ + "my test password"); /* set in Dockerfile */ +} diff --git a/tests/test_auth_pubkey_fail.c b/tests/test_auth_pubkey_fail.c new file mode 100644 index 0000000000..a47671bdcf --- /dev/null +++ b/tests/test_auth_pubkey_fail.c @@ -0,0 +1,10 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + return test_auth_pubkey(session, TEST_AUTH_SHOULDFAIL, + "libssh2", /* set in Dockerfile */ + NULL, + "key_dsa_wrong.pub", + "key_dsa_wrong"); +} diff --git a/tests/test_auth_pubkey_ok_dsa.c b/tests/test_auth_pubkey_ok_dsa.c new file mode 100644 index 0000000000..7405676bd9 --- /dev/null +++ b/tests/test_auth_pubkey_ok_dsa.c @@ -0,0 +1,16 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if LIBSSH2_DSA + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + NULL, + "key_dsa.pub", + "key_dsa"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_auth_pubkey_ok_ecdsa.c b/tests/test_auth_pubkey_ok_ecdsa.c new file mode 100644 index 0000000000..ef5e5bc2b7 --- /dev/null +++ b/tests/test_auth_pubkey_ok_ecdsa.c @@ -0,0 +1,16 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if LIBSSH2_ECDSA + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + NULL, + "key_ecdsa.pub", + "key_ecdsa"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_auth_pubkey_ok_ecdsa_signed.c b/tests/test_auth_pubkey_ok_ecdsa_signed.c new file mode 100644 index 0000000000..d4fa592693 --- /dev/null +++ b/tests/test_auth_pubkey_ok_ecdsa_signed.c @@ -0,0 +1,17 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if LIBSSH2_ECDSA && \ + (defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)) + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + NULL, + "key_ecdsa_signed-cert.pub", + "key_ecdsa_signed"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_auth_pubkey_ok_ed25519.c b/tests/test_auth_pubkey_ok_ed25519.c new file mode 100644 index 0000000000..e3fea09fc7 --- /dev/null +++ b/tests/test_auth_pubkey_ok_ed25519.c @@ -0,0 +1,16 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if LIBSSH2_ED25519 + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + NULL, + "key_ed25519.pub", + "key_ed25519"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_auth_pubkey_ok_ed25519_encrypted.c b/tests/test_auth_pubkey_ok_ed25519_encrypted.c new file mode 100644 index 0000000000..1ad774002a --- /dev/null +++ b/tests/test_auth_pubkey_ok_ed25519_encrypted.c @@ -0,0 +1,16 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if LIBSSH2_ED25519 + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + "libssh2", + "key_ed25519_encrypted.pub", + "key_ed25519_encrypted"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_auth_pubkey_ok_ed25519_mem.c b/tests/test_auth_pubkey_ok_ed25519_mem.c new file mode 100644 index 0000000000..3c7ee48c0d --- /dev/null +++ b/tests/test_auth_pubkey_ok_ed25519_mem.c @@ -0,0 +1,16 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if LIBSSH2_ED25519 + /* set in Dockerfile */ + return test_auth_pubkey(session, TEST_AUTH_FROMMEM, + "libssh2", + NULL, + NULL, + "key_ed25519"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_auth_pubkey_ok_rsa.c b/tests/test_auth_pubkey_ok_rsa.c new file mode 100644 index 0000000000..842e7a2dd8 --- /dev/null +++ b/tests/test_auth_pubkey_ok_rsa.c @@ -0,0 +1,11 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + NULL, + "key_rsa.pub", + "key_rsa"); +} diff --git a/tests/test_auth_pubkey_ok_rsa_encrypted.c b/tests/test_auth_pubkey_ok_rsa_encrypted.c new file mode 100644 index 0000000000..975fffadf1 --- /dev/null +++ b/tests/test_auth_pubkey_ok_rsa_encrypted.c @@ -0,0 +1,11 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + "libssh2", + "key_rsa_encrypted.pub", + "key_rsa_encrypted"); +} diff --git a/tests/test_auth_pubkey_ok_rsa_openssh.c b/tests/test_auth_pubkey_ok_rsa_openssh.c new file mode 100644 index 0000000000..95de8a1887 --- /dev/null +++ b/tests/test_auth_pubkey_ok_rsa_openssh.c @@ -0,0 +1,16 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + NULL, + "key_rsa_openssh.pub", + "key_rsa_openssh"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_auth_pubkey_ok_rsa_signed.c b/tests/test_auth_pubkey_ok_rsa_signed.c new file mode 100644 index 0000000000..905753affe --- /dev/null +++ b/tests/test_auth_pubkey_ok_rsa_signed.c @@ -0,0 +1,16 @@ +#include "runner.h" + +int test(LIBSSH2_SESSION *session) +{ +#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) + /* set in Dockerfile */ + return test_auth_pubkey(session, 0, + "libssh2", + NULL, + "key_rsa_signed-cert.pub", + "key_rsa_signed"); +#else + (void)session; + return 0; +#endif +} diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index 1a61849431..54ba5a77e3 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -12,6 +12,9 @@ static const char *EXPECTED_ECDSA_HOSTKEY = "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC+/syyeKJD9dC2ZH" "9Q7iJGReR4YM3rUCMsSynkyXojdfSClGCMY7JvWlt30ESjYvxoTfSRGx6WvaqYK/vPoYQ4="; +static const char *EXPECTED_ED25519_HOSTKEY = + "AAAAC3NzaC1lZDI1NTE5AAAAIIxtdyg2ZRXE70UwyPVUH3UyfDBV8GX5cPF636P6hjom"; + int test(LIBSSH2_SESSION *session) { int rc; @@ -26,7 +29,12 @@ int test(LIBSSH2_SESSION *session) return 1; } - if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) { + if(type == LIBSSH2_HOSTKEY_TYPE_ED25519) { + rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len, + EXPECTED_ED25519_HOSTKEY, + (unsigned int)strlen(EXPECTED_ED25519_HOSTKEY)); + } + else if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) { rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len, EXPECTED_ECDSA_HOSTKEY, (unsigned int)strlen(EXPECTED_ECDSA_HOSTKEY)); diff --git a/tests/test_hostkey_hash.c b/tests/test_hostkey_hash.c index 9090ca6836..a2218c22ff 100644 --- a/tests/test_hostkey_hash.c +++ b/tests/test_hostkey_hash.c @@ -12,6 +12,9 @@ static const char *EXPECTED_ECDSA_HOSTKEY = "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC+/syyeKJD9dC2ZH" "9Q7iJGReR4YM3rUCMsSynkyXojdfSClGCMY7JvWlt30ESjYvxoTfSRGx6WvaqYK/vPoYQ4="; +static const char *EXPECTED_ED25519_HOSTKEY = + "AAAAC3NzaC1lZDI1NTE5AAAAIIxtdyg2ZRXE70UwyPVUH3UyfDBV8GX5cPF636P6hjom"; + static const char *EXPECTED_RSA_MD5_HASH_DIGEST = "0C0ED1A5BB10275F76924CE187CE5C5E"; @@ -30,6 +33,9 @@ static const char *EXPECTED_ECDSA_SHA1_HASH_DIGEST = static const char *EXPECTED_ECDSA_SHA256_HASH_DIGEST = "56FCD975B166C3F0342D0036E44C311A86C0EAE40713B53FC776369BAE7F5264"; +static const char *EXPECTED_ED25519_SHA256_HASH_DIGEST = + "2638B020F6121FA750A7F4754B718419F621814C6E779D68ADF26AA68814ADDF"; + static const int MD5_HASH_SIZE = 16; static const int SHA1_HASH_SIZE = 20; static const int SHA256_HASH_SIZE = 32; @@ -60,6 +66,7 @@ int test(LIBSSH2_SESSION *session) /* these are the host keys under test, they are currently unused */ (void)EXPECTED_RSA_HOSTKEY; (void)EXPECTED_ECDSA_HOSTKEY; + (void)EXPECTED_ED25519_HOSTKEY; hostkey = libssh2_session_hostkey(session, &len, &type); if(!hostkey) { @@ -67,7 +74,26 @@ int test(LIBSSH2_SESSION *session) return 1; } - if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) { + if(type == LIBSSH2_HOSTKEY_TYPE_ED25519) { + + sha256_hash = libssh2_hostkey_hash(session, + LIBSSH2_HOSTKEY_HASH_SHA256); + if(!sha256_hash) { + print_last_session_error( + "libssh2_hostkey_hash(LIBSSH2_HOSTKEY_HASH_SHA256)"); + return 1; + } + + calculate_digest(sha256_hash, SHA256_HASH_SIZE, buf, BUFSIZ); + + if(strcmp(buf, EXPECTED_ED25519_SHA256_HASH_DIGEST) != 0) { + fprintf(stderr, + "ED25519 SHA256 hash not as expected - digest %s != %s\n", + buf, EXPECTED_ED25519_SHA256_HASH_DIGEST); + return 1; + } + } + else if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) { md5_hash = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_MD5); if(!md5_hash) { @@ -117,7 +143,6 @@ int test(LIBSSH2_SESSION *session) buf, EXPECTED_ECDSA_SHA256_HASH_DIGEST); return 1; } - } else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) { diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c deleted file mode 100644 index 708ac0973a..0000000000 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "runner.h" - -static const char *USERNAME = "libssh2"; /* set in Dockerfile */ -static const char *WRONG_PASSWORD = "i'm not the password"; - -static void kbd_callback(const char *name, int name_len, - const char *instruct, int instruct_len, - int num_prompts, - const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, - LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, - void **abstract) -{ - int i; - (void)abstract; - fprintf(stdout, "Kb-int name: %.*s\n", name_len, name); - fprintf(stdout, "Kb-int instruction: %.*s\n", instruct_len, instruct); - for(i = 0; i < num_prompts; ++i) { - fprintf(stdout, "Kb-int prompt %d: %.*s\n", i, - (int)prompts[i].length, prompts[i].text); - } - - if(num_prompts == 1) { - responses[0].text = strdup(WRONG_PASSWORD); - responses[0].length = (unsigned int)strlen(WRONG_PASSWORD); - } -} - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "keyboard-interactive")) { - fprintf(stderr, - "'keyboard-interactive' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_keyboard_interactive_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), kbd_callback); - if(rc == 0) { - fprintf(stderr, - "Keyboard-interactive auth succeeded with wrong response\n"); - return 1; - } - - return 0; -} diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c deleted file mode 100644 index 40fa33204f..0000000000 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *PASSWORD = "my test password"; - -static void kbd_callback(const char *name, int name_len, - const char *instruct, int instruct_len, - int num_prompts, - const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, - LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, - void **abstract) -{ - int i; - (void)abstract; - - fprintf(stdout, "Kb-int name: %.*s\n", name_len, name); - fprintf(stdout, "Kb-int instruction: %.*s\n", instruct_len, instruct); - for(i = 0; i < num_prompts; ++i) { - fprintf(stdout, "Kb-int prompt %d: %.*s\n", i, - (int)prompts[i].length, prompts[i].text); - } - - if(num_prompts == 1) { - responses[0].text = strdup(PASSWORD); - responses[0].length = (unsigned int)strlen(PASSWORD); - } -} - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "keyboard-interactive")) { - fprintf(stderr, - "'keyboard-interactive' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_keyboard_interactive_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), kbd_callback); - if(rc) { - print_last_session_error("libssh2_userauth_keyboard_interactive_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_password_auth_fails_with_wrong_password.c b/tests/test_password_auth_fails_with_wrong_password.c deleted file mode 100644 index 88948fbacb..0000000000 --- a/tests/test_password_auth_fails_with_wrong_password.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "runner.h" - -static const char *USERNAME = "libssh2"; /* set in Dockerfile */ -static const char *WRONG_PASSWORD = "i'm not the password"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "password")) { - fprintf(stderr, "'password' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_password_ex(session, USERNAME, - (unsigned int)strlen(USERNAME), - WRONG_PASSWORD, - (unsigned int)strlen(WRONG_PASSWORD), - NULL); - if(rc == 0) { - fprintf(stderr, "Password auth succeeded with wrong password\n"); - return 1; - } - - return 0; -} diff --git a/tests/test_password_auth_fails_with_wrong_username.c b/tests/test_password_auth_fails_with_wrong_username.c deleted file mode 100644 index e56428d6e2..0000000000 --- a/tests/test_password_auth_fails_with_wrong_username.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *PASSWORD = "my test password"; -static const char *WRONG_USERNAME = "i dont exist"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, WRONG_USERNAME, - (unsigned int)strlen(WRONG_USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "password")) { - fprintf(stderr, "'password' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_password_ex(session, WRONG_USERNAME, - (unsigned int)strlen(WRONG_USERNAME), - PASSWORD, - (unsigned int)strlen(PASSWORD), NULL); - if(rc == 0) { - fprintf(stderr, "Password auth succeeded with wrong username\n"); - return 1; - } - - return 0; -} diff --git a/tests/test_password_auth_succeeds_with_correct_credentials.c b/tests/test_password_auth_succeeds_with_correct_credentials.c deleted file mode 100644 index 6df9c0eb3a..0000000000 --- a/tests/test_password_auth_succeeds_with_correct_credentials.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *PASSWORD = "my test password"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "password")) { - fprintf(stderr, "'password' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_password_ex(session, USERNAME, - (unsigned int)strlen(USERNAME), - PASSWORD, - (unsigned int)strlen(PASSWORD), NULL); - if(rc) { - print_last_session_error("libssh2_userauth_password_ex"); - return 1; - } - - if(libssh2_userauth_authenticated(session) == 0) { - fprintf(stderr, "Password auth appeared to succeed but " - "libssh2_userauth_authenticated returned 0\n"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c deleted file mode 100644 index 0a10e88836..0000000000 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "runner.h" - -static const char *USERNAME = "libssh2"; /* set in Dockerfile */ -static const char *KEY_FILE_PRIVATE = "key_dsa_wrong"; -static const char *KEY_FILE_PUBLIC = "key_dsa_wrong.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); - if(rc == 0) { - fprintf(stderr, "Public-key auth succeeded with wrong key\n"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c deleted file mode 100644 index eace1e3331..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_dsa"; -static const char *KEY_FILE_PUBLIC = "key_dsa.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c deleted file mode 100644 index 31e770506c..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_ecdsa"; -static const char *KEY_FILE_PUBLIC = "key_ecdsa.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - const char *userauth_list = NULL; - - userauth_list = libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c deleted file mode 100644 index 1eab9f71f9..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_ed25519"; -static const char *KEY_FILE_PUBLIC = "key_ed25519.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - const char *userauth_list = NULL; - - userauth_list = libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c deleted file mode 100644 index f594d9f762..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "runner.h" - -#include - -static const char *USERNAME = "libssh2"; /* set in Dockerfile */ -static const char *KEY_FILE_ED25519_PRIVATE = "key_ed25519"; - -static int read_file(const char *path, char **buf, size_t *len); - -int test(LIBSSH2_SESSION *session) -{ - int rc; - char *buffer = NULL; - size_t len = 0; - const char *userauth_list = NULL; - - userauth_list = libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - if(read_file(srcdir_path(KEY_FILE_ED25519_PRIVATE), &buffer, &len)) { - fprintf(stderr, "Reading key file failed."); - return 1; - } - - rc = libssh2_userauth_publickey_frommemory(session, - USERNAME, strlen(USERNAME), - NULL, 0, - buffer, len, - NULL); - - free(buffer); - - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} - -static int read_file(const char *path, char **out_buffer, size_t *out_len) -{ - FILE *fp = NULL; - char *buffer = NULL; - size_t len = 0; - - if(!out_buffer || !out_len || !path) { - fprintf(stderr, "invalid params."); - return 1; - } - - *out_buffer = NULL; - *out_len = 0; - - fp = fopen(path, "r"); - - if(!fp) { - fprintf(stderr, "File could not be read."); - return 1; - } - - fseek(fp, 0L, SEEK_END); - len = ftell(fp); - rewind(fp); - - buffer = calloc(1, len + 1); - if(!buffer) { - fclose(fp); - fprintf(stderr, "Could not alloc memory."); - return 1; - } - - if(1 != fread(buffer, len, 1, fp)) { - fclose(fp); - free(buffer); - fprintf(stderr, "Could not read file into memory."); - return 1; - } - - fclose(fp); - - *out_buffer = buffer; - *out_len = len; - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c deleted file mode 100644 index 1d5debf7e0..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *PASSWORD = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_ed25519_encrypted"; -static const char *KEY_FILE_PUBLIC = "key_ed25519_encrypted.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - const char *userauth_list = NULL; - - userauth_list = libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - PASSWORD); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c deleted file mode 100644 index e254844be5..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *PASSWORD = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_rsa_encrypted"; -static const char *KEY_FILE_PUBLIC = "key_rsa_encrypted.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - PASSWORD); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c deleted file mode 100644 index ff31ae8c57..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_rsa"; -static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c deleted file mode 100644 index 3d4b8d68fb..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_rsa_openssh"; -static const char *KEY_FILE_PUBLIC = "key_rsa_openssh.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c deleted file mode 100644 index 4a0cec3385..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "signed_key_ecdsa"; -static const char *KEY_FILE_PUBLIC = "signed_key_ecdsa-cert.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - const char *userauth_list = NULL; - - userauth_list = libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c deleted file mode 100644 index 05ecbe2b40..0000000000 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "runner.h" - -/* configured in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "signed_key_rsa"; -static const char *KEY_FILE_PUBLIC = "signed_key_rsa-cert.pub"; - -int test(LIBSSH2_SESSION *session) -{ - int rc; - - const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); - if(!userauth_list) { - print_last_session_error("libssh2_userauth_list"); - return 1; - } - - if(!strstr(userauth_list, "publickey")) { - fprintf(stderr, "'publickey' was expected in userauth list: %s\n", - userauth_list); - return 1; - } - - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), - NULL); - if(rc) { - print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); - return 1; - } - - return 0; -} diff --git a/tests/test_read.c b/tests/test_read.c index c9ee3b7b44..2058e63db3 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -2,7 +2,7 @@ #include "runner.h" -/* configured in Dockerfile */ +/* set in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa"; static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; @@ -43,9 +43,11 @@ int test(LIBSSH2_SESSION *session) return 1; } - rc = libssh2_userauth_publickey_fromfile_ex( - session, USERNAME, (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE), NULL); + rc = libssh2_userauth_publickey_fromfile_ex(session, USERNAME, + (unsigned int)strlen(USERNAME), + srcdir_path(KEY_FILE_PUBLIC), + srcdir_path(KEY_FILE_PRIVATE), + NULL); if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); return 1; diff --git a/tests/simple.c b/tests/test_simple.c similarity index 100% rename from tests/simple.c rename to tests/test_simple.c diff --git a/tests/ssh2.c b/tests/test_ssh2.c similarity index 100% rename from tests/ssh2.c rename to tests/test_ssh2.c From fe64bad58fbebdd1bad6835e12cabf892bda1cd6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 16 Apr 2023 22:50:40 +0000 Subject: [PATCH 287/424] tests: switch to debian:bullseye-slim in Dockerfile 'slim' provides all we need, with less bloat. Tested in #976 Follow-up to 78cb64a85955f2cd9700c4fbad3f02d589dd7169 --- tests/openssh_server/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index c2f5e14612..a2712c16ba 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -FROM debian:bullseye +FROM debian:bullseye-slim RUN apt-get update \ && apt-get install -y openssh-server \ From 739e41bf4083538510d42d968012b2e243921abe Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 17 Apr 2023 14:30:51 +0000 Subject: [PATCH 288/424] switch to internal base64 decode that uses size_t Make the public `libssh2_base64_decode()` a wrapper for that. Bump up length sizes in callers. Also fix output size calculation to first divide then multiply. Closes #978 --- include/libssh2.h | 1 + src/knownhost.c | 10 +++++----- src/libgcrypt.c | 4 ++-- src/libssh2_priv.h | 9 ++++----- src/misc.c | 33 ++++++++++++++++++++++++++------- src/misc.h | 3 +++ src/os400qc3.c | 6 +++--- src/pem.c | 30 +++++++++++++++--------------- src/userauth.c | 18 +++++++++--------- src/wincng.c | 38 +++++++++++++++++++------------------- tests/Makefile.am | 4 +++- tests/test_hostkey.c | 26 +++++++++++++------------- tests/test_simple.c | 13 ++++++------- 13 files changed, 109 insertions(+), 86 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index 0dd1beb8f2..0a09c40f19 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -991,6 +991,7 @@ libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode, #define libssh2_scp_send(session, path, mode, size) \ libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0) +/* DEPRECATED */ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, unsigned int *dest_len, const char *src, unsigned int src_len); diff --git a/src/knownhost.c b/src/knownhost.c index 30a464514a..78df161318 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -141,7 +141,7 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, size_t hostlen = strlen(host); int rc; char *ptr; - unsigned int ptrlen; + size_t ptrlen; /* make sure we have a key type set */ if(!(typemask & LIBSSH2_KNOWNHOST_KEY_MASK)) @@ -169,15 +169,15 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, entry->name_len = hostlen; break; case LIBSSH2_KNOWNHOST_TYPE_SHA1: - rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen, - host, (unsigned int)hostlen); + rc = _libssh2_base64_decode(hosts->session, &ptr, &ptrlen, + host, hostlen); if(rc) goto error; entry->name = ptr; entry->name_len = ptrlen; - rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen, - salt, (unsigned int)strlen(salt)); + rc = _libssh2_base64_decode(hosts->session, &ptr, &ptrlen, + salt, strlen(salt)); if(rc) goto error; entry->salt = ptr; diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 1013129b9a..f182f3cc69 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -171,7 +171,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, { FILE *fp; unsigned char *data, *save_data; - unsigned int datalen; + size_t datalen; int ret; unsigned char *n, *e, *d, *p, *q, *e1, *e2, *coeff; unsigned int nlen, elen, dlen, plen, qlen, e1len, e2len, coefflen; @@ -288,7 +288,7 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, { FILE *fp; unsigned char *data, *save_data; - unsigned int datalen; + size_t datalen; int ret; unsigned char *p, *q, *g, *y, *x; unsigned int plen, qlen, glen, ylen, xlen; diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 58e1ba9659..e04181dc50 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -1084,7 +1084,6 @@ int _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void); const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void); -/* misc.c */ int _libssh2_bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, @@ -1098,12 +1097,12 @@ int _libssh2_pem_parse(LIBSSH2_SESSION * session, const char *headerbegin, const char *headerend, const unsigned char *passphrase, - FILE * fp, unsigned char **data, unsigned int *datalen); + FILE * fp, unsigned char **data, size_t *datalen); int _libssh2_pem_parse_memory(LIBSSH2_SESSION * session, const char *headerbegin, const char *headerend, const char *filedata, size_t filedata_len, - unsigned char **data, unsigned int *datalen); + unsigned char **data, size_t *datalen); /* OpenSSL keys */ int _libssh2_openssh_pem_parse(LIBSSH2_SESSION * session, @@ -1115,8 +1114,8 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session, const char *filedata, size_t filedata_len, struct string_buf **decrypted_buf); -int _libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen); -int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen, +int _libssh2_pem_decode_sequence(unsigned char **data, size_t *datalen); +int _libssh2_pem_decode_integer(unsigned char **data, size_t *datalen, unsigned char **i, unsigned int *ilen); /* global.c */ diff --git a/src/misc.c b/src/misc.c index 47d9dc8f80..4ce4efe641 100644 --- a/src/misc.c +++ b/src/misc.c @@ -317,27 +317,46 @@ static const short base64_reverse_table[256] = { /* libssh2_base64_decode * - * Decode a base64 chunk and store it into a newly alloc'd buffer + * Legacy public function. DEPRECATED. */ -/* FIXME: datalen, src_len -> size_t */ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, unsigned int *datalen, const char *src, unsigned int src_len) { - unsigned char *s, *d; + int rc; + size_t dlen; + + rc = _libssh2_base64_decode(session, data, &dlen, src, src_len); + + if(datalen) + *datalen = (unsigned int)dlen; + + return rc; +} + +/* _libssh2_base64_decode + * + * Decode a base64 chunk and store it into a newly alloc'd buffer + */ +int _libssh2_base64_decode(LIBSSH2_SESSION *session, + char **data, size_t *datalen, + const char *src, size_t src_len) +{ + unsigned char *d; + const char *s; short v; - int i = 0, len = 0; + ssize_t i = 0, len = 0; - *data = LIBSSH2_ALLOC(session, (3 * src_len / 4) + 1); + *data = LIBSSH2_ALLOC(session, ((src_len / 4) * 3) + 1); d = (unsigned char *) *data; if(!d) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for base64 decoding"); } - for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) { - v = base64_reverse_table[*s]; + for(s = src; s < (src + src_len); s++) { + v = base64_reverse_table[(unsigned char)*s]; if(v < 0) continue; switch(i % 4) { diff --git a/src/misc.h b/src/misc.h index 1ec4f20b71..579b7ce84d 100644 --- a/src/misc.h +++ b/src/misc.h @@ -98,6 +98,9 @@ void *_libssh2_list_prev(struct list_node *node); /* remove this node from the list */ void _libssh2_list_remove(struct list_node *entry); +int _libssh2_base64_decode(LIBSSH2_SESSION *session, + char **data, size_t *datalen, + const char *src, size_t src_len); size_t _libssh2_base64_encode(LIBSSH2_SESSION *session, const char *inp, size_t insize, char **outptr); diff --git a/src/os400qc3.c b/src/os400qc3.c index 2839406106..1af7710bb8 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -1995,7 +1995,7 @@ try_pem_load(LIBSSH2_SESSION *session, FILE *fp, loadkeyproc proc, void *loadkeydata) { unsigned char *data = NULL; - unsigned int datalen = 0; + size_t datalen = 0; int c; int ret; @@ -2159,7 +2159,7 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, { libssh2_rsa_ctx *ctx = libssh2_init_crypto_ctx(NULL); unsigned char *data = NULL; - unsigned int datalen = 0; + size_t datalen = 0; int ret; if(!ctx) @@ -2232,7 +2232,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, { loadpubkeydata p; unsigned char *data = NULL; - unsigned int datalen = 0; + size_t datalen = 0; const char *meth; int ret; diff --git a/src/pem.c b/src/pem.c index 571d6e072a..da7a55bade 100644 --- a/src/pem.c +++ b/src/pem.c @@ -109,7 +109,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, const char *headerbegin, const char *headerend, const unsigned char *passphrase, - FILE * fp, unsigned char **data, unsigned int *datalen) + FILE * fp, unsigned char **data, size_t *datalen) { char line[LINE_SIZE]; unsigned char iv[LINE_SIZE]; @@ -200,8 +200,8 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, return -1; } - if(libssh2_base64_decode(session, (char **) data, datalen, - b64data, (unsigned int)b64datalen)) { + if(_libssh2_base64_decode(session, (char **) data, datalen, + b64data, b64datalen)) { ret = -1; goto out; } @@ -296,7 +296,7 @@ _libssh2_pem_parse_memory(LIBSSH2_SESSION * session, const char *headerbegin, const char *headerend, const char *filedata, size_t filedata_len, - unsigned char **data, unsigned int *datalen) + unsigned char **data, size_t *datalen) { char line[LINE_SIZE]; char *b64data = NULL; @@ -345,8 +345,8 @@ _libssh2_pem_parse_memory(LIBSSH2_SESSION * session, return -1; } - if(libssh2_base64_decode(session, (char **) data, datalen, - b64data, (unsigned int)b64datalen)) { + if(_libssh2_base64_decode(session, (char **) data, datalen, + b64data, b64datalen)) { ret = -1; goto out; } @@ -384,7 +384,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, unsigned char *key_part = NULL; unsigned char *iv_part = NULL; unsigned char *f = NULL; - unsigned int f_len = 0; + size_t f_len = 0; int ret = 0, keylen = 0, ivlen = 0, total_len = 0; size_t kdf_len = 0, tmp_len = 0, salt_len = 0; @@ -392,8 +392,8 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, *decrypted_buf = NULL; /* decode file */ - if(libssh2_base64_decode(session, (char **)&f, &f_len, - b64data, (unsigned int)b64datalen)) { + if(_libssh2_base64_decode(session, (char **)&f, &f_len, + b64data, b64datalen)) { ret = -1; goto out; } @@ -816,7 +816,7 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session, static int read_asn1_length(const unsigned char *data, - unsigned int datalen, unsigned int *len) + size_t datalen, size_t *len) { unsigned int lenlen; int nextpos; @@ -850,9 +850,9 @@ read_asn1_length(const unsigned char *data, } int -_libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen) +_libssh2_pem_decode_sequence(unsigned char **data, size_t *datalen) { - unsigned int len; + size_t len; int lenlen; if(*datalen < 1) { @@ -878,10 +878,10 @@ _libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen) } int -_libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen, +_libssh2_pem_decode_integer(unsigned char **data, size_t *datalen, unsigned char **i, unsigned int *ilen) { - unsigned int len; + size_t len; int lenlen; if(*datalen < 1) { @@ -904,7 +904,7 @@ _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen, *datalen -= lenlen; *i = *data; - *ilen = len; + *ilen = (unsigned int)len; *data += len; *datalen -= len; diff --git a/src/userauth.c b/src/userauth.c index 3cf0138bd9..f649fc061a 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -568,7 +568,7 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, { unsigned char *pubkey = NULL, *sp1, *sp2, *tmp; size_t pubkey_len = pubkeyfiledata_len; - unsigned int tmp_len; + size_t tmp_len; if(pubkeyfiledata_len <= 1) { return _libssh2_error(session, LIBSSH2_ERROR_FILE, @@ -610,12 +610,12 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, sp2 = pubkey + pubkey_len; } - if(libssh2_base64_decode(session, (char **)&tmp, &tmp_len, - (const char *)sp1, - (unsigned int)(sp2 - sp1))) { + if(_libssh2_base64_decode(session, (char **)&tmp, &tmp_len, + (const char *)sp1, + sp2 - sp1)) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, - "Invalid key data, not base64 encoded"); + "Invalid key data, not base64 encoded"); } /* Wasting some bytes here (okay, more than some), but since it's likely @@ -652,7 +652,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, char c; unsigned char *pubkey = NULL, *sp1, *sp2, *tmp; size_t pubkey_len = 0, sp_len; - unsigned int tmp_len; + size_t tmp_len; _libssh2_debug((session, LIBSSH2_TRACE_AUTH, "Loading public key file: %s", pubkeyfile)); @@ -715,9 +715,9 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, sp2 = pubkey + pubkey_len; } - if(libssh2_base64_decode(session, (char **)&tmp, &tmp_len, - (const char *)sp1, - (unsigned int)(sp2 - sp1))) { + if(_libssh2_base64_decode(session, (char **)&tmp, &tmp_len, + (const char *)sp1, + sp2 - sp1)) { LIBSSH2_FREE(session, pubkey); return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid key data, not base64 encoded"); diff --git a/src/wincng.c b/src/wincng.c index ea9ba9e1cc..bcc3cf5e90 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -693,7 +693,7 @@ _libssh2_wincng_load_pem(LIBSSH2_SESSION *session, const char *headerbegin, const char *headerend, unsigned char **data, - unsigned int *datalen) + size_t *datalen) { FILE *fp; int ret; @@ -717,11 +717,11 @@ _libssh2_wincng_load_private(LIBSSH2_SESSION *session, const char *filename, const unsigned char *passphrase, unsigned char **ppbEncoded, - unsigned long *pcbEncoded, + size_t *pcbEncoded, int tryLoadRSA, int tryLoadDSA) { unsigned char *data = NULL; - unsigned int datalen = 0; + size_t datalen = 0; int ret = -1; if(ret && tryLoadRSA) { @@ -750,11 +750,11 @@ _libssh2_wincng_load_private_memory(LIBSSH2_SESSION *session, size_t privatekeydata_len, const unsigned char *passphrase, unsigned char **ppbEncoded, - unsigned long *pcbEncoded, + size_t *pcbEncoded, int tryLoadRSA, int tryLoadDSA) { unsigned char *data = NULL; - unsigned int datalen = 0; + size_t datalen = 0; int ret = -1; (void)passphrase; @@ -862,7 +862,7 @@ _libssh2_wincng_bn_ltob(unsigned char *pbInput, static int _libssh2_wincng_asn_decode_bn(unsigned char *pbEncoded, - unsigned long cbEncoded, + size_t cbEncoded, unsigned char **ppbDecoded, unsigned long *pcbDecoded) { @@ -871,7 +871,7 @@ _libssh2_wincng_asn_decode_bn(unsigned char *pbEncoded, unsigned long cbDecoded = 0, cbInteger; int ret; - ret = _libssh2_wincng_asn_decode(pbEncoded, cbEncoded, + ret = _libssh2_wincng_asn_decode(pbEncoded, (unsigned long)cbEncoded, X509_MULTI_BYTE_UINT, (void *)&pbInteger, &cbInteger); if(!ret) { @@ -890,7 +890,7 @@ _libssh2_wincng_asn_decode_bn(unsigned char *pbEncoded, static int _libssh2_wincng_asn_decode_bns(unsigned char *pbEncoded, - unsigned long cbEncoded, + size_t cbEncoded, unsigned char ***prpbDecoded, unsigned long **prcbDecoded, unsigned long *pcbCount) @@ -901,7 +901,7 @@ _libssh2_wincng_asn_decode_bns(unsigned char *pbEncoded, unsigned long cbDecoded, *rcbDecoded, index, length; int ret; - ret = _libssh2_wincng_asn_decode(pbEncoded, cbEncoded, + ret = _libssh2_wincng_asn_decode(pbEncoded, (unsigned long)cbEncoded, X509_SEQUENCE_OF_ANY, (void *)&pbDecoded, &cbDecoded); if(!ret) { @@ -1127,7 +1127,7 @@ static int _libssh2_wincng_rsa_new_private_parse(libssh2_rsa_ctx **rsa, LIBSSH2_SESSION *session, unsigned char *pbEncoded, - unsigned long cbEncoded) + size_t cbEncoded) { BCRYPT_KEY_HANDLE hKey; unsigned char *pbStructInfo; @@ -1136,7 +1136,7 @@ _libssh2_wincng_rsa_new_private_parse(libssh2_rsa_ctx **rsa, (void)session; - ret = _libssh2_wincng_asn_decode(pbEncoded, cbEncoded, + ret = _libssh2_wincng_asn_decode(pbEncoded, (unsigned long)cbEncoded, PKCS_RSA_PRIVATE_KEY, &pbStructInfo, &cbStructInfo); @@ -1179,7 +1179,7 @@ _libssh2_wincng_rsa_new_private(libssh2_rsa_ctx **rsa, { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; - unsigned long cbEncoded; + size_t cbEncoded; int ret; (void)session; @@ -1212,7 +1212,7 @@ _libssh2_wincng_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; - unsigned long cbEncoded; + size_t cbEncoded; int ret; (void)session; @@ -1459,7 +1459,7 @@ static int _libssh2_wincng_dsa_new_private_parse(libssh2_dsa_ctx **dsa, LIBSSH2_SESSION *session, unsigned char *pbEncoded, - unsigned long cbEncoded) + size_t cbEncoded) { unsigned char **rpbDecoded; unsigned long *rcbDecoded, index, length; @@ -1510,7 +1510,7 @@ _libssh2_wincng_dsa_new_private(libssh2_dsa_ctx **dsa, { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; - unsigned long cbEncoded; + size_t cbEncoded; int ret; ret = _libssh2_wincng_load_private(session, filename, passphrase, @@ -1541,7 +1541,7 @@ _libssh2_wincng_dsa_new_private_frommemory(libssh2_dsa_ctx **dsa, { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; - unsigned long cbEncoded; + size_t cbEncoded; int ret; ret = _libssh2_wincng_load_private_memory(session, filedata, filedata_len, @@ -1663,7 +1663,7 @@ _libssh2_wincng_pub_priv_keyfile_parse(LIBSSH2_SESSION *session, unsigned char **pubkeydata, size_t *pubkeydata_len, unsigned char *pbEncoded, - unsigned long cbEncoded) + size_t cbEncoded) { unsigned char **rpbDecoded; unsigned long *rcbDecoded; @@ -1791,7 +1791,7 @@ _libssh2_wincng_pub_priv_keyfile(LIBSSH2_SESSION *session, { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; - unsigned long cbEncoded; + size_t cbEncoded; int ret; ret = _libssh2_wincng_load_private(session, privatekey, @@ -1830,7 +1830,7 @@ _libssh2_wincng_pub_priv_keyfilememory(LIBSSH2_SESSION *session, { #ifdef HAVE_LIBCRYPT32 unsigned char *pbEncoded; - unsigned long cbEncoded; + size_t cbEncoded; int ret; ret = _libssh2_wincng_load_private_memory(session, privatekeydata, diff --git a/tests/Makefile.am b/tests/Makefile.am index 8b3f7f9d9e..18ed2382d4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,9 +46,11 @@ librunner_la_SOURCES = \ LDADD = librunner.la check_LTLIBRARIES = librunner.la -# This program uses an internal libssh2 function so it needs to be statically +# These programs use internal libssh2 functions so they need to be statically # linked against libssh2 test_auth_keyboard_info_request_LDFLAGS = -static +test_hostkey_LDFLAGS = -static +test_simple_LDFLAGS = -static # This must be last in the list so it resolves symbols in previous libraries LDADD += ../src/libssh2.la diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index 54ba5a77e3..ebc4c18998 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -20,7 +20,7 @@ int test(LIBSSH2_SESSION *session) int rc; size_t len; int type; - unsigned int expected_len = 0; + size_t expected_len = 0; char *expected_hostkey = NULL; const char *hostkey = libssh2_session_hostkey(session, &len, &type); @@ -30,19 +30,19 @@ int test(LIBSSH2_SESSION *session) } if(type == LIBSSH2_HOSTKEY_TYPE_ED25519) { - rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len, - EXPECTED_ED25519_HOSTKEY, - (unsigned int)strlen(EXPECTED_ED25519_HOSTKEY)); + rc = _libssh2_base64_decode(session, &expected_hostkey, &expected_len, + EXPECTED_ED25519_HOSTKEY, + strlen(EXPECTED_ED25519_HOSTKEY)); } else if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) { - rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len, - EXPECTED_ECDSA_HOSTKEY, - (unsigned int)strlen(EXPECTED_ECDSA_HOSTKEY)); + rc = _libssh2_base64_decode(session, &expected_hostkey, &expected_len, + EXPECTED_ECDSA_HOSTKEY, + strlen(EXPECTED_ECDSA_HOSTKEY)); } else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) { - rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len, - EXPECTED_RSA_HOSTKEY, - (unsigned int)strlen(EXPECTED_RSA_HOSTKEY)); + rc = _libssh2_base64_decode(session, &expected_hostkey, &expected_len, + EXPECTED_RSA_HOSTKEY, + strlen(EXPECTED_RSA_HOSTKEY)); } else { fprintf(stderr, "Unexpected type of hostkey: %i\n", type); @@ -50,13 +50,13 @@ int test(LIBSSH2_SESSION *session) } if(rc) { - print_last_session_error("libssh2_base64_decode"); + print_last_session_error("_libssh2_base64_decode"); return 1; } if(len != expected_len) { - fprintf(stderr, "Hostkey does not have the expected length %ld!=%d\n", - (unsigned long)len, expected_len); + fprintf(stderr, "Hostkey does not have the expected length %ld!=%ld\n", + (unsigned long)len, (unsigned long)expected_len); return 1; } diff --git a/tests/test_simple.c b/tests/test_simple.c index 50fba3a351..487b556e40 100644 --- a/tests/test_simple.c +++ b/tests/test_simple.c @@ -36,7 +36,7 @@ * OF SUCH DAMAGE. */ -#include +#include "libssh2_priv.h" #include #include @@ -44,20 +44,19 @@ static int test_libssh2_base64_decode(LIBSSH2_SESSION *session) { char *data; - unsigned int datalen; + size_t datalen; const char *src = "Zm5vcmQ="; - size_t src_len = strlen(src); int ret; - ret = libssh2_base64_decode(session, &data, &datalen, - src, (unsigned int)src_len); + ret = _libssh2_base64_decode(session, &data, &datalen, + src, strlen(src)); if(ret) return ret; if(datalen != 5 || strcmp(data, "fnord") != 0) { fprintf(stderr, - "libssh2_base64_decode() failed (%d, %.*s)\n", - datalen, datalen, data); + "_libssh2_base64_decode() failed (%d, %.*s)\n", + (unsigned int)datalen, (unsigned int)datalen, data); return 1; } From 01f3fbf01c0a670e114f50297137a7625a489e88 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 17 Apr 2023 14:31:50 +0000 Subject: [PATCH 289/424] ci: rename Logging to Debug in AppVeyor --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index dc99c1858a..2571eb8365 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -42,7 +42,7 @@ environment: CRYPTO_BACKEND: "OpenSSL" CONFIGURATION: "Release" - - job_name: "VS2015, OpenSSL, x64, Logging" + - job_name: "VS2015, OpenSSL, x64, Debug" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x64" @@ -93,7 +93,7 @@ environment: CONFIGURATION: "Release" SKIP_CTEST: "yes" - - job_name: "VS2022, WinCNG, x64, Logging" + - job_name: "VS2022, WinCNG, x64, Debug" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" PLATFORM: "x64" From 191c4e8c71d4a3f41ea9db15ba581a35bf177762 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 18 Apr 2023 08:19:34 +0000 Subject: [PATCH 290/424] build: assume non-blocking I/O on Windows Drop checks from Windows builds and enable it based on `WIN32`. This saves detection time and also makes 3rd party builds simpler. Also: - delete `HAVE_DISABLED_NONBLOCKING`, that we used in build tools to explicitly disable an explicit `#error` in `session.c`. - replace existing `WSAEWOULDBLOCK` check for Windows support with `WIN32`. Cleaner with the same result. Follow-up to f1e80d8d8ce9570d81836da96ba02f4d4552a7b3 Follow-up to 5644eea2161b17f7c16e18f3a10465ebb217ca1f Closes #980 --- CMakeLists.txt | 10 +++-- acinclude.m4 | 30 +------------ cmake/CheckNonblockingSocketSupport.cmake | 51 +++++------------------ os400/libssh2_config.h | 6 --- src/libssh2_config_cmake.h.in | 2 - src/libssh2_setup.h | 1 - src/session.c | 40 ++++++++---------- 7 files changed, 35 insertions(+), 105 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3ff59888c..2a28c9be6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,10 +188,12 @@ endif() # Non-blocking socket support tests. Use a separate, yet unset variable # for the socket libraries to not link against the other configured # dependencies which might not have been built yet. -cmake_push_check_state() -set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES}) -check_nonblocking_socket_support() -cmake_pop_check_state() +if(NOT WIN32) + cmake_push_check_state() + set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES}) + check_nonblocking_socket_support() + cmake_pop_check_state() +endif() ## Cryptography backend choice diff --git a/acinclude.m4 b/acinclude.m4 index 9f77137161..0a3a37da6b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -601,28 +601,6 @@ AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets]) dnl FIONBIO test was also bad dnl the code was bad, try a different program now, test 3 - AC_TRY_COMPILE([ -/* headers for ioctlsocket test (Windows) */ -#undef inline -#ifdef HAVE_WINDOWS_H -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#endif -],[ -/* ioctlsocket source code */ - SOCKET sd; - unsigned long flags = 0; - sd = socket(0, 0, 0); - ioctlsocket(sd, FIONBIO, &flags); -],[ -dnl ioctlsocket test was good -nonblock="ioctlsocket" -AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets]) -],[ -dnl ioctlsocket did not compile!, go to test 4 - AC_TRY_LINK([ /* headers for IoctlSocket test (Amiga?) */ #include @@ -635,7 +613,7 @@ dnl ioctlsocket test was good nonblock="IoctlSocket" AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets]) ],[ -dnl Ioctlsocket did not compile, do test 5! +dnl Ioctlsocket did not compile, do test 4! AC_TRY_COMPILE([ /* headers for SO_NONBLOCK test (BeOS) */ #include @@ -649,12 +627,8 @@ dnl the SO_NONBLOCK test was good nonblock="SO_NONBLOCK" AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets]) ],[ -dnl test 5 did not compile! +dnl test 4 did not compile! nonblock="nada" -AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets]) -]) -dnl end of fifth test - ]) dnl end of forth test diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index 12e2bd6476..6e02cccdfa 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -1,6 +1,6 @@ include(CheckCSourceCompiles) -# - check_nonblocking_socket_support() +# check_nonblocking_socket_support() # # Check for how to set a socket to non-blocking state. There seems to exist # four known different ways, with the one used almost everywhere being POSIX @@ -11,10 +11,8 @@ include(CheckCSourceCompiles) # method (if any): # HAVE_O_NONBLOCK # HAVE_FIONBIO -# HAVE_IOCTLSOCKET # HAVE_IOCTLSOCKET_CASE # HAVE_SO_NONBLOCK -# HAVE_DISABLED_NONBLOCKING # # The following variables may be set before calling this macro to # modify the way the check is run: @@ -27,8 +25,7 @@ include(CheckCSourceCompiles) macro(check_nonblocking_socket_support) # There are two known platforms (AIX 3.x and SunOS 4.1.x) where the # O_NONBLOCK define is found but does not work. - if(NOT WIN32) - check_c_source_compiles(" + check_c_source_compiles(" #include #include #include @@ -53,12 +50,10 @@ int main(void) int socket = 0; (void)fcntl(socket, F_SETFL, O_NONBLOCK); }" - HAVE_O_NONBLOCK) - endif() + HAVE_O_NONBLOCK) if(NOT HAVE_O_NONBLOCK) - if(NOT WIN32) - check_c_source_compiles("/* FIONBIO test (old-style unix) */ + check_c_source_compiles("/* FIONBIO test (old-style unix) */ #include #include @@ -68,30 +63,10 @@ int main(void) int flags = 0; (void)ioctl(socket, FIONBIO, &flags); }" - HAVE_FIONBIO) - endif() + HAVE_FIONBIO) if(NOT HAVE_FIONBIO) - if(WIN32) - check_c_source_compiles("/* ioctlsocket test (Windows) */ -#undef inline -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include - -int main(void) -{ - SOCKET sd = socket(0, 0, 0); - unsigned long flags = 0; - (void)ioctlsocket(sd, FIONBIO, &flags); -}" - HAVE_IOCTLSOCKET) - endif() - - if(NOT HAVE_IOCTLSOCKET) - check_c_source_compiles("/* IoctlSocket test (Amiga?) */ + check_c_source_compiles("/* IoctlSocket test (Amiga?) */ #include int main(void) @@ -99,10 +74,10 @@ int main(void) int socket = 0; (void)IoctlSocket(socket, FIONBIO, (long)1); }" - HAVE_IOCTLSOCKET_CASE) + HAVE_IOCTLSOCKET_CASE) - if(NOT HAVE_IOCTLSOCKET_CASE) - check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */ + if(NOT HAVE_IOCTLSOCKET_CASE) + check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */ #include int main(void) @@ -111,13 +86,7 @@ int main(void) int socket = 0; (void)setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); }" - HAVE_SO_NONBLOCK) - - if(NOT HAVE_SO_NONBLOCK) - # No non-blocking socket method found - set(HAVE_DISABLED_NONBLOCKING 1) - endif() - endif() + HAVE_SO_NONBLOCK) endif() endif() endif() diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index f3bf725dbf..99a6bcf7f5 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -59,9 +59,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_ARPA_INET_H 1 -/* disabled non-blocking sockets */ -#undef HAVE_DISABLED_NONBLOCKING - /* use FIONBIO for non-blocking sockets */ #undef HAVE_FIONBIO @@ -71,9 +68,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 -/* use ioctlsocket() for non-blocking sockets */ -#undef HAVE_IOCTLSOCKET - /* use Ioctlsocket() for non-blocking sockets */ #undef HAVE_IOCTLSOCKET_CASE diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 89784b4ff0..58dfa6b8ff 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -68,10 +68,8 @@ /* Socket non-blocking support */ #cmakedefine HAVE_O_NONBLOCK #cmakedefine HAVE_FIONBIO -#cmakedefine HAVE_IOCTLSOCKET #cmakedefine HAVE_IOCTLSOCKET_CASE #cmakedefine HAVE_SO_NONBLOCK -#cmakedefine HAVE_DISABLED_NONBLOCKING /* attribute to export symbol */ #if defined(LIBSSH2_EXPORTS) && defined(LIBSSH2_LIBRARY) diff --git a/src/libssh2_setup.h b/src/libssh2_setup.h index a110d6190f..48ebe20a32 100644 --- a/src/libssh2_setup.h +++ b/src/libssh2_setup.h @@ -22,7 +22,6 @@ /* Hand-crafted configuration for platforms which lack config tool. */ #elif defined(WIN32) -#define HAVE_IOCTLSOCKET #define HAVE_SELECT #define HAVE_SNPRINTF diff --git a/src/session.c b/src/session.c index 6998ed1e07..3613d52240 100644 --- a/src/session.c +++ b/src/session.c @@ -308,12 +308,6 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ flags = nonblock; return ioctl(sockfd, FIONBIO, &flags); -#elif defined(HAVE_IOCTLSOCKET) - /* Windows */ - unsigned long flags; - flags = nonblock; - - return ioctlsocket(sockfd, FIONBIO, &flags); #elif defined(HAVE_IOCTLSOCKET_CASE) /* presumably for Amiga */ return IoctlSocket(sockfd, FIONBIO, (long) nonblock); @@ -321,12 +315,15 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ /* BeOS */ long b = nonblock ? 1 : 0; return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); -#elif defined(HAVE_DISABLED_NONBLOCKING) +#elif defined(WIN32) + unsigned long flags; + + flags = nonblock; + return ioctlsocket(sockfd, FIONBIO, &flags); +#else (void)sockfd; (void)nonblock; return 0; /* returns success */ -#else -#error "no non-blocking method was found/used/set" #endif } @@ -347,17 +344,6 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return (flags & O_NONBLOCK); -#elif defined(WSAEWOULDBLOCK) - /* Windows */ - unsigned int option_value; - socklen_t option_len = sizeof(option_value); - - if(getsockopt - (sockfd, SOL_SOCKET, SO_ERROR, (void *) &option_value, &option_len)) { - /* Assume blocking on error */ - return 1; - } - return (int) option_value; #elif defined(HAVE_SO_NONBLOCK) /* BeOS */ long b; @@ -382,11 +368,19 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return 0; -#elif defined(HAVE_DISABLED_NONBLOCKING) +#elif defined(WIN32) + unsigned int option_value; + socklen_t option_len = sizeof(option_value); + + if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, + (void *) &option_value, &option_len)) { + /* Assume blocking on error */ + return 1; + } + return (int) option_value; +#else (void)sockfd; return 1; /* returns blocking */ -#else -#error "no non-blocking method was found/used/get" #endif } From 803f19f004eb6a5b525c48fff6f46a493d25775c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 18 Apr 2023 08:20:05 +0000 Subject: [PATCH 291/424] cmake: dedupe setting `-DHAVE_CONFIG_H` Move `libssh2_config.h` generation and setting `-DHAVE_CONFIG_H` to the root `CMakeFile.txt`. Also move symbol hiding setup there. It needs to be done before generating the config file for `LIBSSH2_API` value to be set in it. After this change the `HIDE_SYMBOLS` setting is accepted without an annoying CMake warning when not actually building a shared libssh2 lib. Closes #981 --- CMakeLists.txt | 25 +++++++++++++++++++++++++ example/CMakeLists.txt | 2 -- src/CMakeLists.txt | 29 ++--------------------------- tests/CMakeLists.txt | 2 -- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a28c9be6f..47870cd524 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,24 @@ endif() set(LIB_STATIC "libssh2_static") set(LIB_SHARED "libssh2_shared") # Must match libssh2_shared_EXPORTS macro in include/libssh2.h +# Symbol hiding + +option(HIDE_SYMBOLS "Set to ON to hide all libssh2 symbols that aren't officially external" ON) +mark_as_advanced(HIDE_SYMBOLS) +if(HIDE_SYMBOLS) + set(LIB_SHARED_DEFINITIONS LIBSSH2_EXPORTS) + if(WIN32) + elseif((CMAKE_C_COMPILER_ID MATCHES "Clang") OR + (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0) OR + (CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)) + set(LIB_SHARED_C_FLAGS -fvisibility=hidden) + set(LIBSSH2_API "__attribute__ ((__visibility__ (\"default\")))") + elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0) + set(LIB_SHARED_C_FLAGS -xldscope=hidden) + set(LIBSSH2_API "__global") + endif() +endif() + # Auto-detection ## Platform checks @@ -195,6 +213,13 @@ if(NOT WIN32) cmake_pop_check_state() endif() +# Config file + +add_definitions(-DHAVE_CONFIG_H) + +configure_file(src/libssh2_config_cmake.h.in + ${CMAKE_CURRENT_BINARY_DIR}/src/libssh2_config.h) + ## Cryptography backend choice set(CRYPTO_BACKEND diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 26f83429de..e580cf616e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -37,8 +37,6 @@ include(CopyRuntimeDependencies) list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) -add_definitions(-DHAVE_CONFIG_H) - transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake") # Get 'noinst_PROGRAMS' variable include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd284e5aff..4f0ad35f8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -126,7 +126,8 @@ if(BUILD_SHARED_LIBS) if(WIN32) set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES libssh2.rc) endif() - target_compile_definitions(${LIB_SHARED} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) + target_compile_definitions(${LIB_SHARED} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS} ${LIB_SHARED_DEFINITIONS}) + target_compile_options(${LIB_SHARED} PRIVATE ${LIB_SHARED_C_FLAGS}) target_link_libraries(${LIB_SHARED} PRIVATE ${LIBRARIES}) set_target_properties(${LIB_SHARED} PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") if(WIN32 AND BUILD_STATIC_LIBS AND NOT STATIC_LIB_SUFFIX AND @@ -142,34 +143,8 @@ if(BUILD_SHARED_LIBS) PUBLIC $ $/${CMAKE_INSTALL_INCLUDEDIR}>) - - # Symbol hiding - - option(HIDE_SYMBOLS "Set to ON to hide all libssh2 symbols that aren't officially external." ON) - mark_as_advanced(HIDE_SYMBOLS) - - if(HIDE_SYMBOLS) - target_compile_definitions(${LIB_SHARED} PRIVATE LIBSSH2_EXPORTS) - if(WIN32) - elseif((CMAKE_C_COMPILER_ID MATCHES "Clang") OR - (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0) OR - (CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)) - target_compile_options(${LIB_SHARED} PRIVATE -fvisibility=hidden) - set(LIBSSH2_API "__attribute__ ((__visibility__ (\"default\")))") - elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0) - target_compile_options(${LIB_SHARED} PRIVATE -xldscope=hidden) - set(LIBSSH2_API "__global") - endif() - endif() endif() -# Config file - -add_definitions(-DHAVE_CONFIG_H) - -configure_file(libssh2_config_cmake.h.in - ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h) - ## Installation install(FILES diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 61dc2e9975..2d9e204ceb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,8 +37,6 @@ include(CopyRuntimeDependencies) list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) -add_definitions(-DHAVE_CONFIG_H) - if(CMAKE_COMPILER_IS_GNUCC) find_program(GCOV_PATH gcov) if(GCOV_PATH) From 221335275816317b757e4ef912870763eec098b0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 18 Apr 2023 08:20:29 +0000 Subject: [PATCH 292/424] mansyntax: make it work on macOS, check reqs locally - use `gman` alias if present. This makes it work when the correct `man` command is provided via `brew` on macOS. - move CMake attempts to detect tools necessary to run `mansyntax.sh` into the script itself. - delete CMake TODO to move more test logic into CMake. This would make it CMake-specific and require maintaining it separately for each build tool. Just use our external script when a POSIX shell is available. Closes #982 --- tests/CMakeLists.txt | 15 ++++----------- tests/mansyntax.sh | 11 ++++++++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2d9e204ceb..877a9b1b9f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -150,16 +150,9 @@ add_target_to_copy_dependencies( DEPENDENCIES ${RUNTIME_DEPENDENCIES} BEFORE_TARGETS ${TEST_TARGETS}) - -# TODO convert mansyntax.sh into CMake script. -# XXX Just because we can find all three programs, doesn't mean sh can -# find man and grep find_program(SH_EXECUTABLE sh) -find_program(MAN_EXECUTABLE man) -find_program(GREP_EXECUTABLE grep) -mark_as_advanced(SH_EXECUTABLE MAN_EXECUTABLE GREP_EXECUTABLE) -if(SH_EXECUTABLE AND MAN_EXECUTABLE AND GREP_EXECUTABLE) - set(cmd "srcdir=${CMAKE_CURRENT_SOURCE_DIR}") - set(cmd "${cmd} ${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh") - add_test(mansyntax ${SH_EXECUTABLE} -c "${cmd}") +mark_as_advanced(SH_EXECUTABLE) +if(SH_EXECUTABLE) + add_test(mansyntax ${SH_EXECUTABLE} -c + "srcdir=${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh") endif() diff --git a/tests/mansyntax.sh b/tests/mansyntax.sh index 180140961b..b7ce93ac6b 100755 --- a/tests/mansyntax.sh +++ b/tests/mansyntax.sh @@ -5,6 +5,10 @@ set -e # # Run syntax checks for all manpages in the documentation tree. # +# Requirement on macOS: brew install man-db +# + +command -v gman >/dev/null 2>&1 && man() { gman "$@"; } srcdir="${srcdir:-$PWD}" dstdir="${builddir:-$PWD}" @@ -15,7 +19,8 @@ ec=0 # # Only test if suitable man is available # -if man --help | grep -q warnings; then +if command -v grep >/dev/null 2>&1 && \ + man --help | grep -q warnings; then trap 'rm -f "$dstdir/man3"' EXIT @@ -24,14 +29,14 @@ if man --help | grep -q warnings; then for manpage in "$mandir"/libssh2_*.*; do echo "$manpage" warnings=$(LANG=en_US.UTF-8 MANWIDTH=80 man -M "$dstdir" --warnings \ - -E UTF-8 -l "$manpage" 2>&1 >/dev/null) + -E UTF-8 -l "$manpage" >/dev/null 2>&1) if [ -n "$warnings" ]; then echo "$warnings" ec=1 fi done else - echo "man version not suitable, skipping tests" + echo 'mansyntax: Required tool not found, skipping tests.' fi exit "$ec" From 17801d206444a234c25084edb01e26485e130bcf Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 18 Apr 2023 08:41:20 +0000 Subject: [PATCH 293/424] tidy-up: fix more nits - fix indentation errors. - reformat `cmake/FindmbedTLS.cmake` - replace a macro with a variable in `example/sftp_RW_nonblock.c`. - delete macOS macro `_DARWIN_USE_64_BIT_INODE` from the OS/400 config header, `os400/libssh2_config.h`. - fix other minor nits. Closes #983 --- cmake/FindmbedTLS.cmake | 88 ++++++++++++++++++------------------ docs/libssh2_sftp_realpath.3 | 3 +- docs/libssh2_version.3 | 8 ++-- example/sftp_RW_nonblock.c | 14 +++--- example/sftp_nonblock.c | 4 +- example/ssh2.c | 12 ++--- os400/libssh2_config.h | 5 -- src/channel.c | 4 +- src/crypt.c | 6 +-- src/hostkey.c | 10 ++-- src/kex.c | 32 ++++++------- src/libgcrypt.c | 13 +++--- src/misc.c | 6 +-- src/openssl.c | 49 ++++++++++---------- src/packet.c | 9 ++-- src/pem.c | 16 +++---- src/scp.c | 1 - src/session.h | 36 +++++++-------- src/sftp.c | 2 +- src/userauth.c | 6 +-- src/version.c | 8 ---- src/wincng.c | 6 +-- tests/gen_keys.sh | 4 +- 23 files changed, 160 insertions(+), 182 deletions(-) diff --git a/cmake/FindmbedTLS.cmake b/cmake/FindmbedTLS.cmake index 2f4adbc519..906dcccbff 100644 --- a/cmake/FindmbedTLS.cmake +++ b/cmake/FindmbedTLS.cmake @@ -10,55 +10,53 @@ # MBEDX509_LIBRARY - path to mbedTLS X.509 library # MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library -FIND_PATH(MBEDTLS_INCLUDE_DIR mbedtls/version.h) +find_path(MBEDTLS_INCLUDE_DIR mbedtls/version.h) -IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) - # Already in cache, be silent - SET(MBEDTLS_FIND_QUIETLY TRUE) -ENDIF() +if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) + # Already in cache, be silent + set(MBEDTLS_FIND_QUIETLY TRUE) +endif() -FIND_LIBRARY(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509) -FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509) -FIND_LIBRARY(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto) +find_library(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509) +find_library(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509) +find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto) -IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) - SET(MBEDTLS_FOUND TRUE) -ENDIF() +if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) + set(MBEDTLS_FOUND TRUE) +endif() -IF(MBEDTLS_FOUND) - # split mbedTLS into -L and -l linker options, so we can set them for pkg-config - GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) - GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) - GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) - GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) - STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) - STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) - STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) - SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") +if(MBEDTLS_FOUND) + # split mbedTLS into -L and -l linker options, so we can set them for pkg-config + get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) + get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) + get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) + get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) + string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) + string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) + string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) + set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") - IF(NOT MBEDTLS_FIND_QUIETLY) - MESSAGE(STATUS "Found mbedTLS:") - FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) - STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) - IF (MBEDTLSMATCH) - STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) - MESSAGE(STATUS " version ${MBEDTLS_VERSION}") - ENDIF(MBEDTLSMATCH) - MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}") - MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}") - MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") - ENDIF(NOT MBEDTLS_FIND_QUIETLY) -ELSE(MBEDTLS_FOUND) - IF(MBEDTLS_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find mbedTLS") - ENDIF(MBEDTLS_FIND_REQUIRED) -ENDIF(MBEDTLS_FOUND) + if(NOT MBEDTLS_FIND_QUIETLY) + message(STATUS "Found mbedTLS:") + file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) + string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) + if(MBEDTLSMATCH) + string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) + message(STATUS " version ${MBEDTLS_VERSION}") + endif() + message(STATUS " TLS: ${MBEDTLS_LIBRARY}") + message(STATUS " X509: ${MBEDX509_LIBRARY}") + message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") + endif() +elseif(MBEDTLS_FIND_REQUIRED) + message(FATAL_ERROR "Could not find mbedTLS") +endif() -MARK_AS_ADVANCED( - MBEDTLS_INCLUDE_DIR - MBEDTLS_LIBRARY_DIR - MBEDTLS_LIBRARIES - MBEDTLS_LIBRARY - MBEDX509_LIBRARY - MBEDCRYPTO_LIBRARY +mark_as_advanced( + MBEDTLS_INCLUDE_DIR + MBEDTLS_LIBRARY_DIR + MBEDTLS_LIBRARIES + MBEDTLS_LIBRARY + MBEDX509_LIBRARY + MBEDCRYPTO_LIBRARY ) diff --git a/docs/libssh2_sftp_realpath.3 b/docs/libssh2_sftp_realpath.3 index c0221c29f4..9dd51c5af8 100644 --- a/docs/libssh2_sftp_realpath.3 +++ b/docs/libssh2_sftp_realpath.3 @@ -7,8 +7,7 @@ libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP #include #define libssh2_sftp_realpath(sftp, path, target, maxlen) \\ - libssh2_sftp_symlink_ex((sftp), \\ - (path), strlen(path), \\ + libssh2_sftp_symlink_ex((sftp), (path), strlen(path), \\ (target), (maxlen), \\ LIBSSH2_SFTP_REALPATH) .fi diff --git a/docs/libssh2_version.3 b/docs/libssh2_version.3 index 932c0af005..a2e608ebff 100644 --- a/docs/libssh2_version.3 +++ b/docs/libssh2_version.3 @@ -24,15 +24,17 @@ string or NULL if the \fIrequired_version\fP isn't fulfilled. To make sure you run with the correct libssh2 version: .nf -if (!libssh2_version(LIBSSH2_VERSION_NUM)) { - fprintf (stderr, \&"Runtime libssh2 version too old!\&"); +if(!libssh2_version(LIBSSH2_VERSION_NUM)) { + fprintf(stderr, \&"Runtime libssh2 version too old!\&"); exit(1); } .fi Unconditionally get the version number: -printf(\&"libssh2 version: %s\&", libssh2_version(0) ); +.nf +printf(\&"libssh2 version: %s\&", libssh2_version(0)); +.fi .SH AVAILABILITY This function was added in libssh2 1.1, in previous versions there way no way to extract this info in run-time. diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 9696e86abe..22fceb73ee 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -37,16 +37,14 @@ #include #include -#define STORAGE "/tmp/sftp-storage" /* this is the local file name this - example uses to store the downloaded - file in */ - static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; static const char *username = "username"; static const char *password = "password"; static const char *sftppath = "/tmp/TEST"; /* source path */ static const char *dest = "/tmp/TEST2"; /* destination path */ +static const char *storage = "/tmp/sftp-storage"; /* local file name to store + the downloaded file in */ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { @@ -170,9 +168,9 @@ int main(int argc, char *argv[]) } fprintf(stderr, "\n"); - tempstorage = fopen(STORAGE, "wb"); + tempstorage = fopen(storage, "wb"); if(!tempstorage) { - fprintf(stderr, "Can't open temp storage file %s\n", STORAGE); + fprintf(stderr, "Can't open temp storage file %s\n", storage); goto shutdown; } @@ -274,10 +272,10 @@ int main(int argc, char *argv[]) libssh2_sftp_close(sftp_handle); fclose(tempstorage); - tempstorage = fopen(STORAGE, "rb"); + tempstorage = fopen(storage, "rb"); if(!tempstorage) { /* weird, we can't read the file we just wrote to... */ - fprintf(stderr, "can't open %s for reading\n", STORAGE); + fprintf(stderr, "can't open %s for reading\n", storage); goto shutdown; } diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 741eeff1f0..b44574c471 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -50,8 +50,8 @@ static const char *sftppath = "/tmp/TEST"; /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) { - return (newer.tv_sec - older.tv_sec) * 1000 + - (newer.tv_usec - older.tv_usec) / 1000; + return (newer.tv_sec - older.tv_sec) * 1000 + + (newer.tv_usec - older.tv_usec) / 1000; } #endif diff --git a/example/ssh2.c b/example/ssh2.c index 52444b7b86..6267244eae 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -279,12 +279,12 @@ int main(int argc, char *argv[]) /* Instead of just running a single command with libssh2_channel_exec, * a shell can be opened on the channel instead, for interactive use. * You usually want a pty allocated first in that case (see above). */ - #if 0 - if(libssh2_channel_shell(channel)) { - fprintf(stderr, "Unable to request shell on allocated pty\n"); - goto shutdown; - } - #endif + #if 0 + if(libssh2_channel_shell(channel)) { + fprintf(stderr, "Unable to request shell on allocated pty\n"); + goto shutdown; + } + #endif /* At this point the shell can be interacted with using * libssh2_channel_read() diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 99a6bcf7f5..186187ffa2 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -190,11 +190,6 @@ significant byte first (like Motorola and SPARC, unlike Intel). */ #define WORDS_BIGENDIAN 1 -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS diff --git a/src/channel.c b/src/channel.c index ef8827fc91..87126eeb2f 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1821,7 +1821,7 @@ libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel, *exitsignal = LIBSSH2_ALLOC(session, namelen + 1); if(!*exitsignal) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for signal name"); + "Unable to allocate memory for signal name"); } memcpy(*exitsignal, channel->exit_signal, namelen); (*exitsignal)[namelen] = '\0'; @@ -2660,7 +2660,7 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel) return rc; } _libssh2_error(session, rc, - "Unable to send EOF, but closing channel anyway"); + "Unable to send EOF, but closing channel anyway"); } } diff --git a/src/crypt.c b/src/crypt.c index fbeb5a5a82..87d80518bc 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -323,9 +323,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_3des_cbc = { towards the start are chosen in preference to ones further down the list. */ static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = { #if LIBSSH2_AES_CTR - &libssh2_crypt_method_aes256_ctr, - &libssh2_crypt_method_aes192_ctr, - &libssh2_crypt_method_aes128_ctr, + &libssh2_crypt_method_aes256_ctr, + &libssh2_crypt_method_aes192_ctr, + &libssh2_crypt_method_aes128_ctr, #endif /* LIBSSH2_AES */ #if LIBSSH2_AES &libssh2_crypt_method_aes256_cbc, diff --git a/src/hostkey.c b/src/hostkey.c index 2eda90fd44..3ad7575e22 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -269,7 +269,7 @@ hostkey_method_ssh_rsa_sha2_256_sig_verify(LIBSSH2_SESSION * session, (void)session; /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-256"} + - signature_len(4) */ + signature_len(4) */ if(sig_len < 20) return -1; @@ -339,7 +339,7 @@ hostkey_method_ssh_rsa_sha2_512_sig_verify(LIBSSH2_SESSION * session, (void)session; /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-512"} + - signature_len(4) */ + signature_len(4) */ if(sig_len < 20) return -1; @@ -510,7 +510,7 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session, return -1; if(_libssh2_get_string(&buf, &p, &p_len)) - return -1; + return -1; if(_libssh2_get_string(&buf, &q, &q_len)) return -1; @@ -877,14 +877,14 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session, buf.dataptr = buf.data; buf.len = sig_len; - if(_libssh2_get_string(&buf, &name, &name_len) || name_len != 19) + if(_libssh2_get_string(&buf, &name, &name_len) || name_len != 19) return -1; if(_libssh2_get_u32(&buf, &len) != 0 || len < 8) return -1; if(_libssh2_get_string(&buf, &r, &r_len)) - return -1; + return -1; if(_libssh2_get_string(&buf, &s, &s_len)) return -1; diff --git a/src/kex.c b/src/kex.c index 53f07a5af6..2a73c5b8b2 100644 --- a/src/kex.c +++ b/src/kex.c @@ -437,7 +437,6 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, { char fingerprint[64], *fprint = fingerprint; int i; - for(i = 0; i < 20; i++, fprint += 3) { snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); } @@ -620,9 +619,9 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, exchange_state->h_sig_comp); if(session->hostkey-> - sig_verify(session, exchange_state->h_sig, - exchange_state->h_sig_len, exchange_state->h_sig_comp, - digest_len, &session->server_hostkey_abstract)) { + sig_verify(session, exchange_state->h_sig, + exchange_state->h_sig_len, exchange_state->h_sig_comp, + digest_len, &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, "Unable to verify hostkey signature"); goto clean_exit; @@ -1718,7 +1717,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(data_len < 5) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Host key data is too short"); + "Host key data is too short"); return ret; } @@ -1745,9 +1744,9 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(_libssh2_copy_string(session, &buf, &(session->server_hostkey), &server_public_key_len)) { - ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for a copy " - "of the host key"); + ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for a copy " + "of the host key"); goto clean_exit; } @@ -1800,7 +1799,6 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, { char fingerprint[64], *fprint = fingerprint; int i; - for(i = 0; i < 20; i++, fprint += 3) { snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); } @@ -1853,7 +1851,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(_libssh2_get_string(&buf, &server_public_key, &server_public_key_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected key length"); goto clean_exit; } @@ -1949,13 +1947,13 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, } /* The first key exchange has been performed, - switch to active crypt/comp/mac mode */ + switch to active crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Received NEWKEYS message")); /* This will actually end up being just packet_type(1) - for this packet type anyway */ + for this packet type anyway */ LIBSSH2_FREE(session, exchange_state->tmp); if(!session->session_id) { @@ -2430,7 +2428,6 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, { char fingerprint[64], *fprint = fingerprint; int i; - for(i = 0; i < 20; i++, fprint += 3) { snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); } @@ -2573,15 +2570,14 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, goto clean_exit; } - /* The first key exchange has been performed, switch to active - crypt/comp/mac mode */ - + /* The first key exchange has been performed, + switch to active crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Received NEWKEYS message")); - /* This will actually end up being just packet_type(1) for this packet - type anyway */ + /* This will actually end up being just packet_type(1) + for this packet type anyway */ LIBSSH2_FREE(session, exchange_state->tmp); if(!session->session_id) { diff --git a/src/libgcrypt.c b/src/libgcrypt.c index f182f3cc69..8ff70fd905 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -160,8 +160,8 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, (void)passphrase; return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unable to extract private key from memory: " - "Method unimplemented in libgcrypt backend"); + "Unable to extract private key from memory: " + "Method unimplemented in libgcrypt backend"); } int @@ -197,6 +197,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, ret = -1; goto fail; } + /* First read Version field (should be 0). */ ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen); if(ret || (nlen != 1 && *n != '\0')) { @@ -277,8 +278,8 @@ _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx ** dsa, (void)passphrase; return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unable to extract private key from memory: " - "Method unimplemented in libgcrypt backend"); + "Unable to extract private key from memory: " + "Method unimplemented in libgcrypt backend"); } int @@ -646,8 +647,8 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, (void)passphrase; return _libssh2_error(session, LIBSSH2_ERROR_FILE, - "Unable to extract public key from private key file: " - "Method unimplemented in libgcrypt backend"); + "Unable to extract public key from private key file: " + "Method unimplemented in libgcrypt backend"); } int diff --git a/src/misc.c b/src/misc.c index 4ce4efe641..d1e33989fc 100644 --- a/src/misc.c +++ b/src/misc.c @@ -204,10 +204,10 @@ _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length, #else if(rc < 0) { #ifdef EWOULDBLOCK /* For VMS and other special unixes */ - if(errno == EWOULDBLOCK) - return -EAGAIN; + if(errno == EWOULDBLOCK) + return -EAGAIN; #endif - return -errno; + return -errno; } #endif return rc; diff --git a/src/openssl.c b/src/openssl.c index 23c8d53b05..419a06496c 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -631,7 +631,7 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, "ssh-rsa", filedata, filedata_len, passphrase); } -return rc; + return rc; } static unsigned char * @@ -2410,8 +2410,9 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx) defined(OPENSSL_VERSION_MAJOR) && \ OPENSSL_VERSION_MAJOR < 3 && \ !defined(LIBRESSL_VERSION_NUMBER) - if(FIPS_mode()) - return 0; + + if(FIPS_mode()) + return 0; #endif #ifdef HAVE_OPAQUE_STRUCTS @@ -2520,8 +2521,8 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, /* convert to octal */ if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED, octal_value, octal_len, bn_ctx) != octal_len) { - rc = -1; - goto clean_exit; + rc = -1; + goto clean_exit; } /* Key form is: type_len(4) + type(method_len) + domain_len(4) + domain(8) @@ -3027,8 +3028,8 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session, /* convert to octal */ if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED, octal_value, octal_len, bn_ctx) != octal_len) { - ret = -1; - goto clean_exit; + ret = -1; + goto clean_exit; } if(out_private_key) @@ -3514,15 +3515,15 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, if(rc) return rc; - /* We have a new key file, now try and parse it using supported types */ - rc = _libssh2_get_string(decrypted, &buf, NULL); + /* We have a new key file, now try and parse it using supported types */ + rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || !buf) - return _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Public key type in decrypted " - "key data not found"); + if(rc || !buf) + return _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Public key type in decrypted " + "key data not found"); - rc = LIBSSH2_ERROR_FILE; + rc = LIBSSH2_ERROR_FILE; #if LIBSSH2_ED25519 if(strcmp("ssh-ed25519", (const char *)buf) == 0) { @@ -3535,7 +3536,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, pubkeydata_len, (libssh2_ed25519_ctx**)key_ctx); } - } + } if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { if(!key_type || @@ -3563,7 +3564,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, pubkeydata_len, (libssh2_rsa_ctx**)key_ctx); } - } + } #endif #if LIBSSH2_DSA if(strcmp("ssh-dss", (const char *)buf) == 0) { @@ -3574,7 +3575,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, pubkeydata_len, (libssh2_dsa_ctx**)key_ctx); } - } + } #endif #if LIBSSH2_ECDSA { @@ -3656,15 +3657,15 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, if(rc) return rc; - /* We have a new key file, now try and parse it using supported types */ - rc = _libssh2_get_string(decrypted, &buf, NULL); + /* We have a new key file, now try and parse it using supported types */ + rc = _libssh2_get_string(decrypted, &buf, NULL); - if(rc || !buf) - return _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Public key type in decrypted " - "key data not found"); + if(rc || !buf) + return _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Public key type in decrypted " + "key data not found"); - rc = LIBSSH2_ERROR_FILE; + rc = LIBSSH2_ERROR_FILE; #if LIBSSH2_ED25519 if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { diff --git a/src/packet.c b/src/packet.c index 3ce2e8cc98..2be61d3b1c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -816,8 +816,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, * Spec says we MAY ignore bytes sent beyond * packet_size */ - _libssh2_error(session, - LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, "Packet contains more data than we offered" " to receive, truncating"); datalen = channelp->remote.packet_size + data_head; @@ -827,8 +826,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, * Spec says we MAY ignore bytes sent beyond * window_size */ - _libssh2_error(session, - LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, "The current receive window is full," " data ignored"); LIBSSH2_FREE(session, data); @@ -840,8 +838,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, if(channelp->read_avail + datalen - data_head > channelp->remote.window_size) { - _libssh2_error(session, - LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, "Remote sent more data than current " "window allows, truncating"); datalen = channelp->remote.window_size - diff --git a/src/pem.c b/src/pem.c index da7a55bade..94bcfae86d 100644 --- a/src/pem.c +++ b/src/pem.c @@ -394,8 +394,8 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, /* decode file */ if(_libssh2_base64_decode(session, (char **)&f, &f_len, b64data, b64datalen)) { - ret = -1; - goto out; + ret = -1; + goto out; } /* Parse the file */ @@ -458,8 +458,8 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, if(!strcmp((const char *)kdfname, "none") && strcmp((const char *)ciphername, "none") != 0) { - ret =_libssh2_error(session, LIBSSH2_ERROR_PROTO, - "invalid format"); + ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "invalid format"); goto out; } @@ -608,10 +608,10 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, if(_libssh2_get_u32(&decrypted, &check1) != 0 || _libssh2_get_u32(&decrypted, &check2) != 0 || check1 != check2) { - _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Private key unpack failed (correct password?)"); - ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED; - goto out; + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Private key unpack failed (correct password?)"); + ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED; + goto out; } if(decrypted_buf) { diff --git a/src/scp.c b/src/scp.c index 6ade9102d2..6d58995b2b 100644 --- a/src/scp.c +++ b/src/scp.c @@ -693,7 +693,6 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) *(p++) = '\0'; /* Make sure we don't get fooled by leftover values */ - session->scpRecv_mode = strtol(s, &e, 8); if(e && *e) { _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, diff --git a/src/session.h b/src/session.h index 9f8f2c7060..0fab9de2cf 100644 --- a/src/session.h +++ b/src/session.h @@ -53,15 +53,15 @@ */ #define BLOCK_ADJUST(rc, sess, x) \ do { \ - time_t entry_time = time(NULL); \ - do { \ - rc = x; \ - /* the order of the check below is important to properly deal with \ - the case when the 'sess' is freed */ \ - if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \ - break; \ - rc = _libssh2_wait_socket(sess, entry_time); \ - } while(!rc); \ + time_t entry_time = time(NULL); \ + do { \ + rc = x; \ + /* the order of the check below is important to properly \ + deal with the case when the 'sess' is freed */ \ + if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \ + break; \ + rc = _libssh2_wait_socket(sess, entry_time); \ + } while(!rc); \ } while(0) /* @@ -72,15 +72,15 @@ */ #define BLOCK_ADJUST_ERRNO(ptr, sess, x) \ do { \ - time_t entry_time = time(NULL); \ - int rc; \ - do { \ - ptr = x; \ - if(!sess->api_block_mode || \ - (ptr != NULL) || \ - (libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) ) \ - break; \ - rc = _libssh2_wait_socket(sess, entry_time); \ + time_t entry_time = time(NULL); \ + int rc; \ + do { \ + ptr = x; \ + if(!sess->api_block_mode || \ + (ptr != NULL) || \ + (libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) ) \ + break; \ + rc = _libssh2_wait_socket(sess, entry_time); \ } while(!rc); \ } while(0) diff --git a/src/sftp.c b/src/sftp.c index f8d811ae8d..d6c39e1e9e 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1654,7 +1654,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, requested, which shouldn't happen for normal files. See: https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02 #section-6.4 - */ + */ return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, "Read Packet At Unexpected Offset"); } diff --git a/src/userauth.c b/src/userauth.c index f649fc061a..e024bb002d 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -920,7 +920,7 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, if(sig_info.sig_s_len > 0 && sig_info.sig_s) { /* sig length, sig_r, sig_s, flags, counter, plus 4 bytes for each - component's length, and up to 1 extra byte for each component */ + component's length, and up to 1 extra byte for each component */ *sig_len = 4 + 5 + sig_info.sig_r_len + 5 + sig_info.sig_s_len + 5; *sig = LIBSSH2_ALLOC(session, *sig_len); @@ -1321,7 +1321,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, i = filtered_algs; /* this walks the server algo list and the supported algo list and creates - a filtered list that includes matches */ + a filtered list that includes matches */ while(s && *s) { p = strchr(s, ','); @@ -1359,7 +1359,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, } /* now that we have the possible supported algos, match based on the prefs - or what is supported by the crypto backend, look for a match */ + or what is supported by the crypto backend, look for a match */ while(s && *s && !match) { p = strchr(s, ','); diff --git a/src/version.c b/src/version.c index e573f73a17..404b319795 100644 --- a/src/version.c +++ b/src/version.c @@ -37,14 +37,6 @@ #include "libssh2_priv.h" -/* - libssh2_version() can be used like this: - - if(!libssh2_version(LIBSSH2_VERSION_NUM)) { - fprintf(stderr, "Runtime libssh2 version too old!\n"); - exit(1); - } -*/ LIBSSH2_API const char *libssh2_version(int req_version_num) { diff --git a/src/wincng.c b/src/wincng.c index bcc3cf5e90..e794c59bdd 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -1288,7 +1288,7 @@ _libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session, paddingInfo.pszAlgId = BCRYPT_SHA512_ALGORITHM; else { _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unsupported hash digest length"); + "Unsupported hash digest length"); return -1; } @@ -1855,8 +1855,8 @@ _libssh2_wincng_pub_priv_keyfilememory(LIBSSH2_SESSION *session, (void)passphrase; return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unable to extract public key from private key in memory: " - "Method unsupported in Windows CNG backend"); + "Unable to extract public key from private key in memory: " + "Method unsupported in Windows CNG backend"); #endif /* HAVE_LIBCRYPT32 */ } diff --git a/tests/gen_keys.sh b/tests/gen_keys.sh index 63e2149d3d..3f8c0f6010 100755 --- a/tests/gen_keys.sh +++ b/tests/gen_keys.sh @@ -30,11 +30,11 @@ ssh-keygen -t rsa -b 2048 -N '' -m PEM -C 'key_rsa' ssh-keygen -t rsa -b 2048 -N "${pw}" -m PEM -C 'key_rsa_encrypted' -f 'key_rsa_encrypted' ssh-keygen -t rsa -b 2048 -N '' -C 'key_rsa_openssh' -f 'key_rsa_openssh' ssh-keygen -t rsa -b 4096 -N '' -C 'key_rsa_signed' -f 'key_rsa_signed' - ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_rsa' 'key_rsa_signed.pub' +ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_rsa' 'key_rsa_signed.pub' ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa' -f 'key_ecdsa' ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa_signed' -f 'key_ecdsa_signed' - ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_ecdsa' 'key_ecdsa_signed.pub' +ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_ecdsa' 'key_ecdsa_signed.pub' ssh-keygen -t ed25519 -N '' -C 'key_ed25519' -f 'key_ed25519' ssh-keygen -t ed25519 -N "${pw}" -C 'key_ed25519_encrypted' -f 'key_ed25519_encrypted' From e4d827479c1df6b332f7b611922161bf4d76c1f2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:19:55 +0000 Subject: [PATCH 294/424] HACKING-CRYPTO: fix stray whitespace --- docs/HACKING-CRYPTO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index e23ac2288e..94bba5abb2 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -416,7 +416,7 @@ The preferred Diffie-Hellman group length in bits. Usually defined as 4096. LIBSSH2_DH_GEX_MAXGROUP The maximum Diffie-Hellman group length in bits supported by the backend. Usually defined as 8192. - + LIBSSH2_DH_MAX_MODULUS_BITS The maximum Diffie-Hellman modulus bit count accepted from the server. This value must be supported by the backend. Usually 16384. From 2d0bd5837b06217fcd672977d1b2ceb44ec7f0a5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:07:20 +0000 Subject: [PATCH 295/424] ci: really enable logging in AppVeyor CMake builds `CONFIGURATION` was never passed to the cmake command, so it had never enabled logging when set to `Debug`. Also `CONFIGURATION` is ambiguous depending on the "generator" used by CMake. In case of Visual Studio, this is a build/ctest-time setting, not a cmake-config parameter. So set this permanently to `Release` and enable logging via our dedicated CMake option `ENABLE_DEBUG_LOGGING`. Tested in #979 --- appveyor.yml | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 2571eb8365..b3f9f1140e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,6 +25,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. environment: + CONFIGURATION: "Release" matrix: - job_name: "VS2022, OpenSSL3, x64" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" @@ -32,7 +33,6 @@ environment: PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - CONFIGURATION: "Release" - job_name: "VS2015, OpenSSL, x86" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" @@ -40,15 +40,14 @@ environment: PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - CONFIGURATION: "Release" - - job_name: "VS2015, OpenSSL, x64, Debug" + - job_name: "VS2015, OpenSSL, x64, Logging" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - CONFIGURATION: "Debug" + ENABLE_DEBUG_LOGGING: "ON" - job_name: "VS2013, OpenSSL, x64" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" @@ -56,7 +55,6 @@ environment: PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - CONFIGURATION: "Release" - job_name: "VS2013, OpenSSL, x86" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" @@ -64,7 +62,6 @@ environment: PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - CONFIGURATION: "Release" - job_name: "VS2013, OpenSSL, x64, Static-only, Build-only" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" @@ -72,7 +69,6 @@ environment: PLATFORM: "x64" BUILD_SHARED_LIBS: "OFF" CRYPTO_BACKEND: "OpenSSL" - CONFIGURATION: "Release" SKIP_CTEST: "yes" - job_name: "VS2010, WinCNG, x64, Build-only" @@ -81,7 +77,6 @@ environment: PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - CONFIGURATION: "Release" SKIP_CTEST: "yes" - job_name: "VS2008, WinCNG, x86, Build-only" @@ -90,16 +85,15 @@ environment: PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - CONFIGURATION: "Release" SKIP_CTEST: "yes" - - job_name: "VS2022, WinCNG, x64, Debug" + - job_name: "VS2022, WinCNG, x64, Logging" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - CONFIGURATION: "Debug" + ENABLE_DEBUG_LOGGING: "ON" - job_name: "VS2022, WinCNG, ARM64, Build-only" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" @@ -107,7 +101,6 @@ environment: PLATFORM: "ARM64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - CONFIGURATION: "Release" - job_name: "VS2015, WinCNG, x86" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" @@ -115,7 +108,6 @@ environment: PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - CONFIGURATION: "Release" - job_name: "VS2015, WinCNG, x64" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" @@ -123,7 +115,6 @@ environment: PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - CONFIGURATION: "Release" matrix: fast_finish: true @@ -159,6 +150,9 @@ build_script: } } } + if($env:ENABLE_DEBUG_LOGGING -eq "ON") { + $env:CMAKE_ARG += " -DENABLE_DEBUG_LOGGING=ON" + } - echo cmake "-G%GENERATOR%" %CMAKE_ARG% -DENABLE_WERROR=ON -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% - cmake . -B _builds "-G%GENERATOR%" %CMAKE_ARG% -DENABLE_WERROR=ON -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DCRYPTO_BACKEND=%CRYPTO_BACKEND% - cmake --build _builds --config "%CONFIGURATION%" From 3336b00f7228dd335806d7731c2323adaa9d4dcb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:04:11 +0000 Subject: [PATCH 296/424] tests: add `FIXTURE_TRACE_ALL_CONNECT` option Works like the `FIXTURE_TRACE_ALL` envvar, but enables full trace for the connection phase only. Also fix a possible NULL deref with `FIXTURE_TRACE_ALL` and a failed `libssh2_session_init_ex()`. Tested in #979 --- tests/session_fixture.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 4997d4abf8..2ae92ec1b6 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -141,14 +141,20 @@ LIBSSH2_SESSION *start_session_fixture(int *skipped) } connected_session = libssh2_session_init_ex(NULL, NULL, NULL, NULL); - if(getenv("FIXTURE_TRACE_ALL")) { - libssh2_trace(connected_session, ~0); - } if(!connected_session) { fprintf(stderr, "libssh2_session_init_ex failed\n"); return NULL; } + if(getenv("FIXTURE_TRACE_ALL_CONNECT")) { + libssh2_trace(connected_session, ~0); + fprintf(stdout, "Trace all enabled for connect_to_server.\n"); + } + else if(getenv("FIXTURE_TRACE_ALL")) { + libssh2_trace(connected_session, ~0); + fprintf(stdout, "Trace all enabled.\n"); + } + /* Override crypt algorithm for the test */ if(crypt) { if(libssh2_session_method_pref(connected_session, @@ -180,6 +186,10 @@ LIBSSH2_SESSION *start_session_fixture(int *skipped) return NULL; } + if(getenv("FIXTURE_TRACE_ALL_CONNECT")) { + libssh2_trace(connected_session, 0); + } + return connected_session; } From e8ceea0c8ea7b81ce0beb89caeeef8945ba2fa68 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:13:09 +0000 Subject: [PATCH 297/424] ci: enable FIXTURE_TRACE_ALL_CONNECT for WinCNG tests To hopefully help finding the WinCNG hostkey verification intermittent failure #804. Tested in #979 --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index b3f9f1140e..13a75d8238 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -177,6 +177,9 @@ before_test: test_script: - ps: | if($env:SKIP_CTEST -ne "yes" -and $env:PLATFORM -ne "ARM64") { + if($env:CRYPTO_BACKEND -eq "WinCNG") { + $env:FIXTURE_TRACE_ALL_CONNECT = "1" + } $env:OPENSSH_SERVER_IMAGE=[string] (& bash -c "echo ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)") cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure --timeout 900 } From d1bf8fadf70aadb5f22629d0a6091b29336e5a60 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:17:20 +0000 Subject: [PATCH 298/424] ci: delete config elements for unused 32-bit Linux builds They have been disabled since d9b4222ef1c5ab9b9e499fe6234556e5cca7c4fe Tested in #979 --- .github/workflows/ci.yml | 10 -------- cmake/Toolchain-Linux-32.cmake | 42 ---------------------------------- 2 files changed, 52 deletions(-) delete mode 100644 cmake/Toolchain-Linux-32.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b8dd424d6..94b4589fc3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,16 +46,6 @@ jobs: ENABLE_ZLIB_COMPRESSION: ${{ matrix.enable_zlib_compression }} steps: - uses: actions/checkout@v3 - - name: Install 32 Bit Dependencies - if: ${{ matrix.address_size == 32 }} - run: | - sudo dpkg --add-architecture i386 - sudo apt-get update -qq - sudo apt-get install -y gcc-multilib - sudo apt-get install -y libssl-dev:i386 libgcrypt20-dev:i386 zlib1g-dev:i386 build-essential gcc-multilib - sudo dpkg --purge --force-depends gcc-multilib - sudo dpkg --purge --force-depends libssl-dev - echo "TOOLCHAIN_OPTION=-DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Linux-32.cmake" >> $GITHUB_ENV - name: Install 64 Bit Dependencies if: ${{ matrix.address_size == 64 }} run: | diff --git a/cmake/Toolchain-Linux-32.cmake b/cmake/Toolchain-Linux-32.cmake deleted file mode 100644 index 9535a64621..0000000000 --- a/cmake/Toolchain-Linux-32.cmake +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2014 Alexander Lamaison -# -# Redistribution and use in source and binary forms, -# with or without modification, are permitted provided -# that the following conditions are met: -# -# Redistributions of source code must retain the above -# copyright notice, this list of conditions and the -# following disclaimer. -# -# Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# Neither the name of the copyright holder nor the names -# of any other contributors may be used to endorse or -# promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -# OF SUCH DAMAGE. - -# Cross-compile 32-bit binary on 64-bit linux host -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR "i386") - -set(CMAKE_CXX_COMPILER_ARG1 "-m32") -set(CMAKE_C_COMPILER_ARG1 "-m32") From 31acf572996519696498f0dcb47aab2ba46f935f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:16:48 +0000 Subject: [PATCH 299/424] wincng: fix unused variables with `LIBSSH2_RSA_SHA2` disabled Tested in #979 --- src/wincng.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wincng.c b/src/wincng.c index e794c59bdd..7fed2c4262 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -2723,6 +2723,9 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, memcmp(key_method, "ssh-rsa", key_method_len) == 0) { return "rsa-sha2-512,rsa-sha2-256,ssh-rsa"; } +#else + (void)key_method; + (void)key_method_len; #endif return NULL; From 6c01fa5bb7c0a3e9c7e31eeb1db948fd49212592 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:19:14 +0000 Subject: [PATCH 300/424] wincng: constify data arg of `libssh2_wincng_hash()` Tested in #979 --- src/wincng.c | 2 +- src/wincng.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wincng.c b/src/wincng.c index 7fed2c4262..c96e742381 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -552,7 +552,7 @@ _libssh2_wincng_hash_final(_libssh2_wincng_hash_ctx *ctx, } int -_libssh2_wincng_hash(unsigned char *data, unsigned long datalen, +_libssh2_wincng_hash(const unsigned char *data, unsigned long datalen, BCRYPT_ALG_HANDLE hAlg, unsigned char *hash, unsigned long hashlen) { diff --git a/src/wincng.h b/src/wincng.h index 0f967a0b17..a0deb9ec56 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -474,7 +474,7 @@ int _libssh2_wincng_hash_final(_libssh2_wincng_hash_ctx *ctx, unsigned char *hash); int -_libssh2_wincng_hash(unsigned char *data, unsigned long datalen, +_libssh2_wincng_hash(const unsigned char *data, unsigned long datalen, BCRYPT_ALG_HANDLE hAlg, unsigned char *hash, unsigned long hashlen); From 8d10b21731195d0406c899edf6f0043b987d5819 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 18:22:53 +0000 Subject: [PATCH 301/424] base64: do not use `snprintf()` on encoding This also significantly (by 7-8x in my limited tests with a short string) speeds up this function. The impact is still minor as this function is only used in `knownhost.c` in release builds. Closes #985 --- src/misc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/misc.c b/src/misc.c index d1e33989fc..c7ec0ffe08 100644 --- a/src/misc.c +++ b/src/misc.c @@ -443,22 +443,22 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session, switch(inputparts) { case 1: /* only one byte read */ - snprintf(output, 5, "%c%c==", - table64[obuf[0]], - table64[obuf[1]]); + output[0] = table64[obuf[0]]; + output[1] = table64[obuf[1]]; + output[2] = '='; + output[3] = '='; break; case 2: /* two bytes read */ - snprintf(output, 5, "%c%c%c=", - table64[obuf[0]], - table64[obuf[1]], - table64[obuf[2]]); + output[0] = table64[obuf[0]]; + output[1] = table64[obuf[1]]; + output[2] = table64[obuf[2]]; + output[3] = '='; break; default: - snprintf(output, 5, "%c%c%c%c", - table64[obuf[0]], - table64[obuf[1]], - table64[obuf[2]], - table64[obuf[3]]); + output[0] = table64[obuf[0]]; + output[1] = table64[obuf[1]]; + output[2] = table64[obuf[2]]; + output[3] = table64[obuf[3]]; break; } output += 4; From 9a54f212a6671bf84b85f1b62056cbc7031bd07b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 19 Apr 2023 21:55:30 +0000 Subject: [PATCH 302/424] scp: fix typo in comments [ci skip] Follow-up to 0a500b3554c29451708353279eefce750f4bca6c --- src/scp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scp.c b/src/scp.c index 6d58995b2b..b68cb8e340 100644 --- a/src/scp.c +++ b/src/scp.c @@ -305,7 +305,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) path_len = strlen(path); - /* no NUL-termination neeed, so memcpy will do */ + /* no NUL-termination needed, so memcpy will do */ memcpy(&session->scpRecv_command[cmd_len], path, path_len); cmd_len += path_len; } @@ -877,7 +877,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, path_len = strlen(path); - /* no NUL-termination neeed, so memcpy will do */ + /* no NUL-termination needed, so memcpy will do */ memcpy(&session->scpSend_command[cmd_len], path, path_len); cmd_len += path_len; From 857e431648df6edcb3e17138d877f2e65d2d769d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 09:44:56 +0000 Subject: [PATCH 303/424] crypto: add/fix algo guards and extend `NO` options Add new guard `LIBSSH2_RSA_SHA1`. Add missing guards for `LIBSSH2_RSA`, `LIBSSH2_DSA`. Fix warnings when all options are disabled. This is still not complete and it's possible to break a build with certain crypto backends (e.g. mbedTLS) and/or combination of options. It's not guaranteed that all bits everywhere get disabled by these settings. Consider this a "best effort". Add these new options to disable certain crypto elements: - `LIBSSH2_NO_3DES` - `LIBSSH2_NO_AES_CTR` - `LIBSSH2_NO_BLOWFISH` - `LIBSSH2_NO_CAST` - `LIBSSH2_NO_ECDSA` - `LIBSSH2_NO_RC4` - `LIBSSH2_NO_RSA_SHA1` - `LIBSSH2_NO_RSA` The goal is to offer a way to disable legacy/obsolete/insecure ones. See also: 146a25a06dd2365a4330dad34fefcdcee1a206aa `LIBSSH2_NO_HMAC_RIPEMD` See also: 38015f4e46d8dbeea522dc7ee664522d4f47fc75 `LIBSSH2_NO_DSA` See also: be31457f3071686b555a0f0b19e5dcf63d67fc27 `LIBSSH2_NO_MD5` Closes #986 --- src/crypto.h | 42 +++++++++++++++++++ src/hostkey.c | 20 ++++++++- src/libgcrypt.c | 16 ++++++++ src/libgcrypt.h | 1 + src/mbedtls.h | 1 + src/openssl.c | 49 ++++++++++++++--------- src/openssl.h | 6 +++ src/os400qc3.h | 1 + src/wincng.c | 15 +++++-- src/wincng.h | 1 + tests/test_auth_pubkey_ok_rsa.c | 5 +++ tests/test_auth_pubkey_ok_rsa_encrypted.c | 5 +++ tests/test_auth_pubkey_ok_rsa_openssh.c | 3 +- tests/test_auth_pubkey_ok_rsa_signed.c | 3 +- 14 files changed, 141 insertions(+), 27 deletions(-) diff --git a/src/crypto.h b/src/crypto.h index 658a177ebf..2c1fb74014 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -67,6 +67,46 @@ #define LIBSSH2_DSA 0 #endif +#ifdef LIBSSH2_NO_RSA +#undef LIBSSH2_RSA +#define LIBSSH2_RSA 0 +#endif + +#ifdef LIBSSH2_NO_RSA_SHA1 +#undef LIBSSH2_RSA_SHA1 +#define LIBSSH2_RSA_SHA1 0 +#endif + +#ifdef LIBSSH2_NO_ECDSA +#undef LIBSSH2_ECDSA +#define LIBSSH2_ECDSA 0 +#endif + +#ifdef LIBSSH2_NO_AES_CTR +#undef LIBSSH2_AES_CTR +#define LIBSSH2_AES_CTR 0 +#endif + +#ifdef LIBSSH2_NO_BLOWFISH +#undef LIBSSH2_BLOWFISH +#define LIBSSH2_BLOWFISH 0 +#endif + +#ifdef LIBSSH2_NO_RC4 +#undef LIBSSH2_RC4 +#define LIBSSH2_RC4 0 +#endif + +#ifdef LIBSSH2_NO_CAST +#undef LIBSSH2_CAST +#define LIBSSH2_CAST 0 +#endif + +#ifdef LIBSSH2_NO_3DES +#undef LIBSSH2_3DES +#define LIBSSH2_3DES 0 +#endif + #define LIBSSH2_ED25519_KEY_LEN 32 #define LIBSSH2_ED25519_PRIVATE_KEY_LEN 64 #define LIBSSH2_ED25519_SIG_LEN 64 @@ -92,6 +132,7 @@ int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, LIBSSH2_SESSION * session, const char *filename, unsigned const char *passphrase); +#if LIBSSH2_RSA_SHA1 int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, const unsigned char *sig, size_t sig_len, @@ -102,6 +143,7 @@ int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, size_t hash_len, unsigned char **signature, size_t *signature_len); +#endif #if LIBSSH2_RSA_SHA2 int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, libssh2_rsa_ctx * rsactx, diff --git a/src/hostkey.c b/src/hostkey.c index 3ad7575e22..1586ecf828 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -87,18 +87,22 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, } /* we accept one of 3 header types */ +#if LIBSSH2_RSA_SHA1 if(type_len == 7 && strncmp("ssh-rsa", (char *)type, 7) == 0) { /* ssh-rsa */ } + else +#endif #if LIBSSH2_RSA_SHA2 - else if(type_len == 12 && strncmp("rsa-sha2-256", (char *)type, 12) == 0) { + if(type_len == 12 && strncmp("rsa-sha2-256", (char *)type, 12) == 0) { /* rsa-sha2-256 */ } else if(type_len == 12 && strncmp("rsa-sha2-512", (char *)type, 12) == 0) { /* rsa-sha2-512 */ } + else #endif - else { + { _libssh2_debug((session, LIBSSH2_TRACE_ERROR, "unexpected rsa type: %.*s", type_len, type)); return -1; @@ -187,6 +191,7 @@ hostkey_method_ssh_rsa_initPEMFromMemory(LIBSSH2_SESSION * session, return 0; } +#if LIBSSH2_RSA_SHA1 /* * hostkey_method_ssh_rsa_sign * @@ -250,6 +255,7 @@ hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session, return 0; #endif } +#endif /* * hostkey_method_ssh_rsa_sha2_256_sig_verify @@ -413,6 +419,8 @@ hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract) return 0; } +#if LIBSSH2_RSA_SHA1 + static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = { "ssh-rsa", SHA_DIGEST_LENGTH, @@ -425,6 +433,8 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = { hostkey_method_ssh_rsa_dtor, }; +#endif /* LIBSSH2_RSA_SHA1 */ + #if LIBSSH2_RSA_SHA2 static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_256 = { @@ -453,6 +463,8 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_512 = { #endif /* LIBSSH2_RSA_SHA2 */ +#if LIBSSH2_RSA_SHA1 + static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_cert = { "ssh-rsa-cert-v01@openssh.com", SHA_DIGEST_LENGTH, @@ -465,6 +477,8 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_cert = { hostkey_method_ssh_rsa_dtor, }; +#endif /* LIBSSH2_RSA_SHA1 */ + #endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA @@ -1263,8 +1277,10 @@ static const LIBSSH2_HOSTKEY_METHOD *hostkey_methods[] = { &hostkey_method_ssh_rsa_sha2_512, &hostkey_method_ssh_rsa_sha2_256, #endif /* LIBSSH2_RSA_SHA2 */ +#if LIBSSH2_RSA_SHA1 &hostkey_method_ssh_rsa, &hostkey_method_ssh_rsa_cert, +#endif /* LIBSSH2_RSA_SHA1 */ #endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA &hostkey_method_ssh_dss, diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 8ff70fd905..59b57ad05a 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -40,6 +40,7 @@ #include +#if LIBSSH2_RSA int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, const unsigned char *edata, @@ -83,6 +84,7 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, return 0; } +#if LIBSSH2_RSA_SHA1 int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, const unsigned char *sig, @@ -114,7 +116,10 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, return (rc == 0) ? 0 : -1; } +#endif +#endif +#if LIBSSH2_DSA int _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, const unsigned char *p, @@ -147,7 +152,9 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, return 0; } +#endif +#if LIBSSH2_RSA int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, LIBSSH2_SESSION * session, @@ -265,7 +272,9 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, LIBSSH2_FREE(session, save_data); return ret; } +#endif +#if LIBSSH2_DSA int _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx ** dsa, LIBSSH2_SESSION * session, @@ -369,7 +378,10 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, LIBSSH2_FREE(session, save_data); return ret; } +#endif +#if LIBSSH2_RSA +#if LIBSSH2_RSA_SHA1 int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, libssh2_rsa_ctx * rsactx, @@ -429,7 +441,10 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, return rc; } +#endif +#endif +#if LIBSSH2_DSA int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, const unsigned char *hash, @@ -549,6 +564,7 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, return (rc == 0) ? 0 : -1; } +#endif int _libssh2_cipher_init(_libssh2_cipher_ctx * h, diff --git a/src/libgcrypt.h b/src/libgcrypt.h index 0e2d9bc81a..de2389f25a 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -57,6 +57,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA1 1 #define LIBSSH2_RSA_SHA2 0 #define LIBSSH2_DSA 1 #define LIBSSH2_ECDSA 0 diff --git a/src/mbedtls.h b/src/mbedtls.h index 66290f232f..b9654b70c4 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -81,6 +81,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA1 1 #define LIBSSH2_RSA_SHA2 1 #define LIBSSH2_DSA 0 #ifdef MBEDTLS_ECDSA_C diff --git a/src/openssl.c b/src/openssl.c index 419a06496c..9e4a03a481 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -70,6 +70,7 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, size_t privatekeydata_len, unsigned const char *passphrase); +#if LIBSSH2_RSA || LIBSSH2_DSA || LIBSSH2_ECDSA static unsigned char * write_bn(unsigned char *buf, const BIGNUM *bn, int bn_bytes) { @@ -87,6 +88,7 @@ write_bn(unsigned char *buf, const BIGNUM *bn, int bn_bytes) return p + bn_bytes; } +#endif int _libssh2_openssl_random(void *buf, size_t len) @@ -98,6 +100,7 @@ _libssh2_openssl_random(void *buf, size_t len) return RAND_bytes(buf, (int)len) == 1 ? 0 : -1; } +#if LIBSSH2_RSA int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, const unsigned char *edata, @@ -226,6 +229,7 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, return (ret == 1) ? 0 : -1; } +#if LIBSSH2_RSA_SHA1 int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, const unsigned char *sig, @@ -235,6 +239,8 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, return _libssh2_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, sig, sig_len, m, m_len); } +#endif +#endif #if LIBSSH2_DSA int @@ -587,7 +593,7 @@ read_private_key_from_memory(void **key_ctx, } - +#if LIBSSH2_RSA || LIBSSH2_DSA || LIBSSH2_ECDSA static int read_private_key_from_file(void **key_ctx, pem_read_bio_func read_private_key, @@ -609,7 +615,9 @@ read_private_key_from_file(void **key_ctx, BIO_free(bp); return (*key_ctx) ? 0 : -1; } +#endif +#if LIBSSH2_RSA int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, LIBSSH2_SESSION * session, @@ -989,6 +997,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, return rc; } +#endif #if LIBSSH2_DSA int @@ -1296,7 +1305,6 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, return rc; } - #endif /* LIBSSH_DSA */ #if LIBSSH2_ECDSA @@ -2024,6 +2032,7 @@ _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, #endif /* LIBSSH2_ED25519 */ +#if LIBSSH2_RSA int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, libssh2_rsa_ctx * rsactx, @@ -2068,7 +2077,7 @@ _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, return 0; } - +#if LIBSSH2_RSA_SHA1 int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, libssh2_rsa_ctx * rsactx, @@ -2079,7 +2088,8 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, return _libssh2_rsa_sha2_sign(session, rsactx, hash, hash_len, signature, signature_len); } - +#endif +#endif #if LIBSSH2_DSA int @@ -3442,30 +3452,29 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, switch(pktype) { #if LIBSSH2_ED25519 - case EVP_PKEY_ED25519 : + case EVP_PKEY_ED25519: st = gen_publickey_from_ed_evp( session, method, method_len, pubkeydata, pubkeydata_len, pk); break; #endif /* LIBSSH2_ED25519 */ - case EVP_PKEY_RSA : +#if LIBSSH2_RSA + case EVP_PKEY_RSA: st = gen_publickey_from_rsa_evp( session, method, method_len, pubkeydata, pubkeydata_len, pk); break; - +#endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA - case EVP_PKEY_DSA : + case EVP_PKEY_DSA: st = gen_publickey_from_dsa_evp( session, method, method_len, pubkeydata, pubkeydata_len, pk); break; -#endif /* LIBSSH_DSA */ - +#endif /* LIBSSH2_DSA */ #if LIBSSH2_ECDSA - case EVP_PKEY_EC : + case EVP_PKEY_EC: st = gen_publickey_from_ec_evp( session, method, method_len, pubkeydata, pubkeydata_len, 0, pk); break; -#endif - +#endif /* LIBSSH2_ECDSA */ default : st = _libssh2_error(session, LIBSSH2_ERROR_FILE, @@ -3782,29 +3791,31 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, switch(pktype) { #if LIBSSH2_ED25519 - case EVP_PKEY_ED25519 : + case EVP_PKEY_ED25519: st = gen_publickey_from_ed_evp( session, method, method_len, pubkeydata, pubkeydata_len, pk); break; #endif /* LIBSSH2_ED25519 */ - case EVP_PKEY_RSA : +#if LIBSSH2_RSA + case EVP_PKEY_RSA: st = gen_publickey_from_rsa_evp(session, method, method_len, pubkeydata, pubkeydata_len, pk); break; +#endif /* LIBSSH2_RSA */ #if LIBSSH2_DSA - case EVP_PKEY_DSA : + case EVP_PKEY_DSA: st = gen_publickey_from_dsa_evp(session, method, method_len, pubkeydata, pubkeydata_len, pk); break; -#endif /* LIBSSH_DSA */ +#endif /* LIBSSH2_DSA */ #if LIBSSH2_ECDSA - case EVP_PKEY_EC : + case EVP_PKEY_EC: st = gen_publickey_from_ec_evp(session, method, method_len, pubkeydata, pubkeydata_len, 0, pk); break; #endif /* LIBSSH2_ECDSA */ - default : + default: st = _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public key " diff --git a/src/openssl.h b/src/openssl.h index 34de8cafc2..13535aa5d3 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -105,9 +105,11 @@ #ifdef OPENSSL_NO_RSA # define LIBSSH2_RSA 0 +# define LIBSSH2_RSA_SHA1 0 # define LIBSSH2_RSA_SHA2 0 #else # define LIBSSH2_RSA 1 +# define LIBSSH2_RSA_SHA1 1 # define LIBSSH2_RSA_SHA2 1 #endif @@ -353,13 +355,17 @@ extern void _libssh2_openssl_crypto_exit(void); #define libssh2_crypto_init() _libssh2_openssl_crypto_init() #define libssh2_crypto_exit() _libssh2_openssl_crypto_exit() +#if LIBSSH2_RSA #define libssh2_rsa_ctx RSA #define _libssh2_rsa_free(rsactx) RSA_free(rsactx) +#endif +#if LIBSSH2_DSA #define libssh2_dsa_ctx DSA #define _libssh2_dsa_free(dsactx) DSA_free(dsactx) +#endif #if LIBSSH2_ECDSA #define libssh2_ecdsa_ctx EC_KEY diff --git a/src/os400qc3.h b/src/os400qc3.h index 68ef0b9844..990daefbda 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -177,6 +177,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA1 1 #define LIBSSH2_RSA_SHA2 1 #define LIBSSH2_DSA 0 #define LIBSSH2_ECDSA 0 diff --git a/src/wincng.c b/src/wincng.c index c96e742381..4653610510 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -953,6 +953,7 @@ _libssh2_wincng_asn_decode_bns(unsigned char *pbEncoded, } #endif /* HAVE_LIBCRYPT32 */ +#if LIBSSH2_RSA || LIBSSH2_DSA static unsigned long _libssh2_wincng_bn_size(const unsigned char *bignum, unsigned long length) @@ -972,8 +973,10 @@ _libssh2_wincng_bn_size(const unsigned char *bignum, return length - offset; } +#endif +#if LIBSSH2_RSA /*******************************************************************/ /* * Windows CNG backend: RSA functions @@ -1238,6 +1241,7 @@ _libssh2_wincng_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, #endif /* HAVE_LIBCRYPT32 */ } +#if LIBSSH2_RSA_SHA1 int _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, const unsigned char *sig, @@ -1250,7 +1254,9 @@ _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, m, (unsigned long)m_len, BCRYPT_PAD_PKCS1); } +#endif +#if LIBSSH2_RSA_SHA2 int _libssh2_wincng_rsa_sha2_verify(libssh2_rsa_ctx* rsa, size_t hash_len, @@ -1264,6 +1270,7 @@ _libssh2_wincng_rsa_sha2_verify(libssh2_rsa_ctx* rsa, m, (unsigned long)m_len, BCRYPT_PAD_PKCS1); } +#endif int _libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session, @@ -1338,7 +1345,7 @@ _libssh2_wincng_rsa_free(libssh2_rsa_ctx *rsa) _libssh2_wincng_safe_free(rsa->pbKeyObject, rsa->cbKeyObject); _libssh2_wincng_safe_free(rsa, sizeof(libssh2_rsa_ctx)); } - +#endif /*******************************************************************/ /* @@ -1665,11 +1672,11 @@ _libssh2_wincng_pub_priv_keyfile_parse(LIBSSH2_SESSION *session, unsigned char *pbEncoded, size_t cbEncoded) { - unsigned char **rpbDecoded; - unsigned long *rcbDecoded; + unsigned char **rpbDecoded = NULL; + unsigned long *rcbDecoded = NULL; unsigned char *key = NULL, *mth = NULL; unsigned long keylen = 0, mthlen = 0; - unsigned long index, offset, length; + unsigned long index, offset, length = 0; int ret; ret = _libssh2_wincng_asn_decode_bns(pbEncoded, cbEncoded, diff --git a/src/wincng.h b/src/wincng.h index a0deb9ec56..df346c9e61 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -65,6 +65,7 @@ #define LIBSSH2_3DES 1 #define LIBSSH2_RSA 1 +#define LIBSSH2_RSA_SHA1 1 #define LIBSSH2_RSA_SHA2 1 #define LIBSSH2_DSA 1 #define LIBSSH2_ECDSA 0 diff --git a/tests/test_auth_pubkey_ok_rsa.c b/tests/test_auth_pubkey_ok_rsa.c index 842e7a2dd8..96a63377d1 100644 --- a/tests/test_auth_pubkey_ok_rsa.c +++ b/tests/test_auth_pubkey_ok_rsa.c @@ -2,10 +2,15 @@ int test(LIBSSH2_SESSION *session) { +#if LIBSSH2_RSA_SHA1 /* set in Dockerfile */ return test_auth_pubkey(session, 0, "libssh2", NULL, "key_rsa.pub", "key_rsa"); +#else + (void)session; + return 0; +#endif } diff --git a/tests/test_auth_pubkey_ok_rsa_encrypted.c b/tests/test_auth_pubkey_ok_rsa_encrypted.c index 975fffadf1..846acb155e 100644 --- a/tests/test_auth_pubkey_ok_rsa_encrypted.c +++ b/tests/test_auth_pubkey_ok_rsa_encrypted.c @@ -2,10 +2,15 @@ int test(LIBSSH2_SESSION *session) { +#if LIBSSH2_RSA_SHA1 /* set in Dockerfile */ return test_auth_pubkey(session, 0, "libssh2", "libssh2", "key_rsa_encrypted.pub", "key_rsa_encrypted"); +#else + (void)session; + return 0; +#endif } diff --git a/tests/test_auth_pubkey_ok_rsa_openssh.c b/tests/test_auth_pubkey_ok_rsa_openssh.c index 95de8a1887..c1e9b603b5 100644 --- a/tests/test_auth_pubkey_ok_rsa_openssh.c +++ b/tests/test_auth_pubkey_ok_rsa_openssh.c @@ -2,7 +2,8 @@ int test(LIBSSH2_SESSION *session) { -#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) +#if LIBSSH2_RSA_SHA1 && \ + (defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)) /* set in Dockerfile */ return test_auth_pubkey(session, 0, "libssh2", diff --git a/tests/test_auth_pubkey_ok_rsa_signed.c b/tests/test_auth_pubkey_ok_rsa_signed.c index 905753affe..d098e86a16 100644 --- a/tests/test_auth_pubkey_ok_rsa_signed.c +++ b/tests/test_auth_pubkey_ok_rsa_signed.c @@ -2,7 +2,8 @@ int test(LIBSSH2_SESSION *session) { -#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) +#if LIBSSH2_RSA_SHA1 && \ + (defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)) /* set in Dockerfile */ return test_auth_pubkey(session, 0, "libssh2", From 5e3acb9da9bc14add324cc1c8b8cf83dd40a4829 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 09:58:10 +0000 Subject: [PATCH 304/424] tidy-up: whitespace nits [ci skip] --- src/channel.c | 4 ++-- src/pem.c | 2 +- src/session.c | 4 ++-- src/session.h | 6 +++--- src/userauth.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/channel.c b/src/channel.c index 87126eeb2f..ed3032a710 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2086,7 +2086,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, /* expand the receiving window first if it has become too narrow */ if((channel->read_state == libssh2_NB_state_jump1) || (channel->remote.window_size < - channel->remote.window_size_initial / 4 * 3 + buflen) ) { + channel->remote.window_size_initial / 4 * 3 + buflen)) { uint32_t adjustment = (uint32_t)(channel->remote.window_size_initial + buflen - channel->remote.window_size); @@ -2737,7 +2737,7 @@ libssh2_channel_close(LIBSSH2_CHANNEL *channel) if(!channel) return LIBSSH2_ERROR_BAD_USE; - BLOCK_ADJUST(rc, channel->session, _libssh2_channel_close(channel) ); + BLOCK_ADJUST(rc, channel->session, _libssh2_channel_close(channel)); return rc; } diff --git a/src/pem.c b/src/pem.c index 94bcfae86d..16717b73e9 100644 --- a/src/pem.c +++ b/src/pem.c @@ -528,7 +528,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, if(strcmp((const char *)kdfname, "bcrypt") == 0 && passphrase) { if((_libssh2_get_string(&kdf_buf, &salt, &salt_len)) || - (_libssh2_get_u32(&kdf_buf, &rounds) != 0) ) { + (_libssh2_get_u32(&kdf_buf, &rounds) != 0)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "kdf contains unexpected values"); LIBSSH2_FREE(session, key); diff --git a/src/session.c b/src/session.c index 3613d52240..b1f31e9088 100644 --- a/src/session.c +++ b/src/session.c @@ -812,7 +812,7 @@ libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t sock) { int rc; - BLOCK_ADJUST(rc, session, session_startup(session, sock) ); + BLOCK_ADJUST(rc, session, session_startup(session, sock)); return rc; } @@ -1107,7 +1107,7 @@ libssh2_session_free(LIBSSH2_SESSION * session) { int rc; - BLOCK_ADJUST(rc, session, session_free(session) ); + BLOCK_ADJUST(rc, session, session_free(session)); return rc; } diff --git a/src/session.h b/src/session.h index 0fab9de2cf..c88a4f53dd 100644 --- a/src/session.h +++ b/src/session.h @@ -41,9 +41,9 @@ /* Conveniance-macros to allow code like this; - int rc = BLOCK_ADJUST(rc, session, session_startup(session, sock) ); + int rc = BLOCK_ADJUST(rc, session, session_startup(session, sock)); - int rc = BLOCK_ADJUST_ERRNO(ptr, session, session_startup(session, sock) ); + int rc = BLOCK_ADJUST_ERRNO(ptr, session, session_startup(session, sock)); The point of course being to make sure that while in non-blocking mode these always return no matter what the return code is, but in blocking mode @@ -78,7 +78,7 @@ ptr = x; \ if(!sess->api_block_mode || \ (ptr != NULL) || \ - (libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) ) \ + (libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN)) \ break; \ rc = _libssh2_wait_socket(sess, entry_time); \ } while(!rc); \ diff --git a/src/userauth.c b/src/userauth.c index e024bb002d..40b64860bc 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -2158,7 +2158,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, for(i = 0; i < session->userauth_kybd_num_prompts; i++) { /* string response[1] (ISO-10646 UTF-8) */ if(session->userauth_kybd_responses[i].length <= - (SIZE_MAX - 4 - session->userauth_kybd_packet_len) ) { + (SIZE_MAX - 4 - session->userauth_kybd_packet_len)) { session->userauth_kybd_packet_len += 4 + session->userauth_kybd_responses[i].length; } From d09ca26563a02069523a7bd53f9fdebb6086eee1 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 10:01:23 +0000 Subject: [PATCH 305/424] tidy-up: align comments [ci skip] --- src/userauth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/userauth.c b/src/userauth.c index 40b64860bc..ed89b9eaff 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -2151,8 +2151,8 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, " invoked")); session->userauth_kybd_packet_len = - 1 /* byte SSH_MSG_USERAUTH_INFO_RESPONSE */ - + 4 /* int num-responses */ + 1 /* byte SSH_MSG_USERAUTH_INFO_RESPONSE */ + + 4 /* int num-responses */ ; for(i = 0; i < session->userauth_kybd_num_prompts; i++) { From 3c953c05d67eb1ebcfd3316f279f12c4b1d600b4 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 20 Apr 2023 06:46:44 -0700 Subject: [PATCH 306/424] Add support for AES-GCM crypto protocols (#797) Add support for aes256-gcm@openssh.com and aes128-gcm@openssh.com ciphers, which are the OpenSSH implementations of AES-GCM cryptography. It is similar to RFC5647 but has changes to the MAC protocol negotiation. These are implemented for recent versions of OpenSSL only. The ciphers work differently than most previous ones in two big areas: the cipher includes its own integrated MAC, and the packet length field in the SSH frame is left unencrypted. The code changes necessary are gated by flags in the LIBSSH2_CRYPT_METHOD configuration structure. These differences mean that both the first and last parts of a block require special handling during encryption. The first part is where the packet length field is, which must be kept out of the encryption path but in the authenticated part (as AAD). The last part is where the Authentication Tag is found, which is calculated and appended during encryption or removed and validated on decryption. As encryption/ decryption is performed on each packet in a loop, one block at a time, flags indicating when the first and last blocks are being processed are passed down to the encryption layers. The strict block-by-block encryption that occurs with other protocols is inappropriate for AES-GCM, since the packet length shifts the first encrypted byte 4 bytes into the block. Additionally, the final part of the block must contain the AES-GCM's Authentication Tag, so it must be presented to the lower encryption layer whole. These requirements mean added code to consolidate blocks as they are passed down. When AES-GCM is negotiated as the cipher, its built-in MAC is automatically used as the SSH MAC so further MAC negotiation is not necessary. The SSH negotiation is skipped when _libssh2_mac_override() indicates that such a cipher is in use. The virtual MAC configuration block mac_method_hmac_aesgcm is then used as the MAC placeholder. This work was sponsored by Anders Borum. Integration-patches-by: Viktor Szakats * fix checksrc errors * fix openssl.c warning * fix transport.c warnings * switch to `LIBSSH2_MIN/MAX()` from `MIN()`/`MAX()` * fix indent * fix libgcrypt unused warning * fix mbedtls unused warning * fix wincng unused warning * fix old openssl unused variable warnings * delete blank lines * updates to help merging with the ETM patch --- docs/HACKING-CRYPTO | 3 +- src/crypt.c | 41 ++++++++++-- src/crypto.h | 3 +- src/kex.c | 11 ++++ src/libgcrypt.c | 4 +- src/libgcrypt.h | 1 + src/libssh2_priv.h | 26 +++++++- src/mac.c | 29 +++++++++ src/mac.h | 2 + src/mbedtls.c | 3 +- src/mbedtls.h | 7 +- src/openssl.c | 113 +++++++++++++++++++++++++++++++-- src/openssl.h | 9 +++ src/os400qc3.c | 3 +- src/os400qc3.h | 1 + src/pem.c | 12 +++- src/transport.c | 151 +++++++++++++++++++++++++++++++++++--------- src/wincng.c | 3 +- src/wincng.h | 7 +- 19 files changed, 373 insertions(+), 56 deletions(-) diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index 94bba5abb2..b85198327f 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -323,7 +323,8 @@ int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx, _libssh2_cipher_type(algo), int encrypt, unsigned char *block, - size_t blocksize); + size_t blocksize, + int firstlast); Encrypt or decrypt in-place data at (block, blocksize) using the given context and/or algorithm. Return 0 if OK, else -1. diff --git a/src/crypt.c b/src/crypt.c index 87d80518bc..fb47e19ca4 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -54,7 +54,7 @@ */ static int crypt_none_crypt(LIBSSH2_SESSION * session, unsigned char *buf, - void **abstract) + void **abstract, int firstlast) { /* Do nothing to the data! */ return 0; @@ -106,12 +106,12 @@ crypt_init(LIBSSH2_SESSION * session, static int crypt_encrypt(LIBSSH2_SESSION * session, unsigned char *block, - size_t blocksize, void **abstract) + size_t blocksize, void **abstract, int firstlast) { struct crypt_ctx *cctx = *(struct crypt_ctx **) abstract; (void) session; return _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block, - blocksize); + blocksize, firstlast); } static int @@ -126,6 +126,34 @@ crypt_dtor(LIBSSH2_SESSION * session, void **abstract) return 0; } +#if LIBSSH2_AES_GCM +static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes256_gcm = { + "aes256-gcm@openssh.com", + "", + 16, /* blocksize */ + 12, /* initial value length */ + 32, /* secret length -- 32*8 == 256bit */ + LIBSSH2_CRYPT_FLAG_INTEGRATED_MAC | LIBSSH2_CRYPT_FLAG_PKTLEN_AAD, + &crypt_init, + &crypt_encrypt, + &crypt_dtor, + _libssh2_cipher_aes256gcm +}; + +static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes128_gcm = { + "aes128-gcm@openssh.com", + "", + 16, /* blocksize */ + 12, /* initial value length */ + 16, /* secret length -- 16*8 == 128bit */ + LIBSSH2_CRYPT_FLAG_INTEGRATED_MAC | LIBSSH2_CRYPT_FLAG_PKTLEN_AAD, + &crypt_init, + &crypt_encrypt, + &crypt_dtor, + _libssh2_cipher_aes128gcm +}; +#endif + #if LIBSSH2_AES_CTR static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes128_ctr = { "aes128-ctr", @@ -269,7 +297,8 @@ crypt_init_arcfour128(LIBSSH2_SESSION * session, size_t discard = 1536; for(; discard; discard -= 8) _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block, - method->blocksize); + method->blocksize, MIDDLE_BLOCK); + /* Not all middle, but here it doesn't matter */ } return rc; @@ -322,6 +351,10 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_3des_cbc = { /* These are the crypt methods that are available to be negotiated. Methods towards the start are chosen in preference to ones further down the list. */ static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = { +#if LIBSSH2_AES_GCM + &libssh2_crypt_method_aes256_gcm, + &libssh2_crypt_method_aes128_gcm, +#endif /* LIBSSH2_AES_GCM */ #if LIBSSH2_AES_CTR &libssh2_crypt_method_aes256_ctr, &libssh2_crypt_method_aes192_ctr, diff --git a/src/crypto.h b/src/crypto.h index 2c1fb74014..b517b16f2c 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -332,7 +332,8 @@ int _libssh2_cipher_init(_libssh2_cipher_ctx * h, int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, _libssh2_cipher_type(algo), - int encrypt, unsigned char *block, size_t blocksize); + int encrypt, unsigned char *block, size_t blocksize, + int firstlast); int _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, unsigned char **method, diff --git a/src/kex.c b/src/kex.c index 2a73c5b8b2..886a456857 100644 --- a/src/kex.c +++ b/src/kex.c @@ -3582,9 +3582,18 @@ static int kex_agree_mac(LIBSSH2_SESSION * session, size_t mac_len) { const LIBSSH2_MAC_METHOD **macp = _libssh2_mac_methods(); + const LIBSSH2_MAC_METHOD *override; unsigned char *s; (void)session; + override = _libssh2_mac_override(endpoint->crypt); + if(override) { + /* This crypto method has its own hmac method built-in, so a separate + * negotiation (and use) of a separate hmac method is unnecessary */ + endpoint->mac = override; + return 0; + } + if(endpoint->mac_prefs) { s = (unsigned char *) endpoint->mac_prefs; @@ -3747,6 +3756,8 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data, return -1; } + /* This must happen after kex_agree_crypt since some MACs depend on the + negotiated crypto method */ if(kex_agree_mac(session, &session->local, mac_cs, mac_cs_len) || kex_agree_mac(session, &session->remote, mac_sc, mac_sc_len)) { return -1; diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 59b57ad05a..ccee583491 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -607,11 +607,13 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, _libssh2_cipher_type(algo), - int encrypt, unsigned char *block, size_t blklen) + int encrypt, unsigned char *block, size_t blklen, + int firstlast) { int ret; (void)algo; + (void)firstlast; if(encrypt) { ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen); diff --git a/src/libgcrypt.h b/src/libgcrypt.h index de2389f25a..f750f9b4ca 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -51,6 +51,7 @@ #define LIBSSH2_AES 1 #define LIBSSH2_AES_CTR 1 +#define LIBSSH2_AES_GCM 0 #define LIBSSH2_BLOWFISH 1 #define LIBSSH2_RC4 1 #define LIBSSH2_CAST 1 diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index e04181dc50..55e1a4ab3c 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -948,12 +948,36 @@ struct _LIBSSH2_CRYPT_METHOD int *free_iv, unsigned char *secret, int *free_secret, int encrypt, void **abstract); int (*crypt) (LIBSSH2_SESSION * session, unsigned char *block, - size_t blocksize, void **abstract); + size_t blocksize, void **abstract, int firstlast); int (*dtor) (LIBSSH2_SESSION * session, void **abstract); _libssh2_cipher_type(algo); }; +/* Bit flags for _LIBSSH2_CRYPT_METHOD */ + +/* Crypto method has integrated message authentication */ +#define LIBSSH2_CRYPT_FLAG_INTEGRATED_MAC 1 +/* Crypto method does not encrypt the packet length */ +#define LIBSSH2_CRYPT_FLAG_PKTLEN_AAD 2 + +/* Convenience macros for accessing crypt flags */ +/* Local crypto flags */ +#define CRYPT_FLAG_L(session, flag) ((session)->local.crypt && \ + ((session)->local.crypt->flags & LIBSSH2_CRYPT_FLAG_##flag)) +/* Remote crypto flags */ +#define CRYPT_FLAG_R(session, flag) ((session)->remote.crypt && \ + ((session)->remote.crypt->flags & LIBSSH2_CRYPT_FLAG_##flag)) + +/* Values for firstlast */ +#define FIRST_BLOCK 1 +#define MIDDLE_BLOCK 0 +#define LAST_BLOCK 2 + +/* Convenience macros for accessing firstlast */ +#define IS_FIRST(firstlast) (firstlast & FIRST_BLOCK) +#define IS_LAST(firstlast) (firstlast & LAST_BLOCK) + struct _LIBSSH2_COMP_METHOD { const char *name; diff --git a/src/mac.c b/src/mac.c index ca0a415141..06ca396a81 100644 --- a/src/mac.c +++ b/src/mac.c @@ -423,3 +423,32 @@ _libssh2_mac_methods(void) { return mac_methods; } + +#if LIBSSH2_AES_GCM +/* Stub for aes256-gcm@openssh.com crypto type, which has an integrated + HMAC method. This must not be added to mac_methods[] since it cannot be + negotiated separately. */ +static const LIBSSH2_MAC_METHOD mac_method_hmac_aesgcm = { + "INTEGRATED-AES-GCM", /* made up name for display only */ + 16, + 16, + NULL, + NULL, + NULL, +}; +#endif /* LIBSSH2_AES_GCM */ + +/* See if the negotiated crypto method has its own authentication scheme that + * obviates the need for a separate negotiated hmac method */ +const LIBSSH2_MAC_METHOD * +_libssh2_mac_override(const LIBSSH2_CRYPT_METHOD *crypt) +{ +#if LIBSSH2_AES_GCM + if(!strcmp(crypt->name, "aes256-gcm@openssh.com") || + !strcmp(crypt->name, "aes128-gcm@openssh.com")) + return &mac_method_hmac_aesgcm; +#else + (void) crypt; +#endif /* LIBSSH2_AES_GCM */ + return NULL; +} diff --git a/src/mac.h b/src/mac.h index c6e48bba71..7d21a3af52 100644 --- a/src/mac.h +++ b/src/mac.h @@ -62,5 +62,7 @@ struct _LIBSSH2_MAC_METHOD typedef struct _LIBSSH2_MAC_METHOD LIBSSH2_MAC_METHOD; const LIBSSH2_MAC_METHOD **_libssh2_mac_methods(void); +const LIBSSH2_MAC_METHOD *_libssh2_mac_override( + const LIBSSH2_CRYPT_METHOD *crypt); #endif /* __LIBSSH2_MAC_H */ diff --git a/src/mbedtls.c b/src/mbedtls.c index e8d4f65209..c7d0b56bf0 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -139,7 +139,7 @@ _libssh2_mbedtls_cipher_crypt(_libssh2_cipher_ctx *ctx, _libssh2_cipher_type(algo), int encrypt, unsigned char *block, - size_t blocklen) + size_t blocklen, int firstlast) { int ret; unsigned char *output; @@ -147,6 +147,7 @@ _libssh2_mbedtls_cipher_crypt(_libssh2_cipher_ctx *ctx, (void)encrypt; (void)algo; + (void)firstlast; osize = blocklen + mbedtls_cipher_get_block_size(ctx); diff --git a/src/mbedtls.h b/src/mbedtls.h index b9654b70c4..5053b101ed 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -67,6 +67,7 @@ #define LIBSSH2_AES 1 #define LIBSSH2_AES_CTR 1 +#define LIBSSH2_AES_GCM 0 #ifdef MBEDTLS_CIPHER_BLOWFISH_CBC # define LIBSSH2_BLOWFISH 1 #else @@ -390,8 +391,8 @@ typedef enum { #define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \ _libssh2_mbedtls_cipher_init(ctx, type, iv, secret, encrypt) -#define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen) \ - _libssh2_mbedtls_cipher_crypt(ctx, type, encrypt, block, blocklen) +#define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) \ + _libssh2_mbedtls_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) #define _libssh2_cipher_dtor(ctx) \ _libssh2_mbedtls_cipher_dtor(ctx) @@ -472,7 +473,7 @@ _libssh2_mbedtls_cipher_crypt(_libssh2_cipher_ctx *ctx, _libssh2_cipher_type(type), int encrypt, unsigned char *block, - size_t blocklen); + size_t blocklen, int firstlast); void _libssh2_mbedtls_cipher_dtor(_libssh2_cipher_ctx *ctx); diff --git a/src/openssl.c b/src/openssl.c index 9e4a03a481..99d1e1235b 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -40,6 +40,7 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ +#include #include #ifndef EVP_MAX_BLOCK_LENGTH @@ -481,9 +482,26 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, unsigned char *iv, unsigned char *secret, int encrypt) { #ifdef HAVE_OPAQUE_STRUCTS +#if LIBSSH2_AES_GCM + const int is_aesgcm = (algo == EVP_aes_128_gcm) || + (algo == EVP_aes_256_gcm); +#endif /* LIBSSH2_AES_GCM */ + int rc; + *h = EVP_CIPHER_CTX_new(); - return !EVP_CipherInit(*h, algo(), secret, iv, encrypt); + rc = !EVP_CipherInit(*h, algo(), secret, iv, encrypt); +#if LIBSSH2_AES_GCM + if(is_aesgcm) { + /* Sets both fixed and invocation_counter parts of IV */ + rc |= !EVP_CIPHER_CTX_ctrl(*h, EVP_CTRL_AEAD_SET_IV_FIXED, -1, iv); + } +#endif /* LIBSSH2_AES_GCM */ + + return rc; #else +# if LIBSSH2_AES_GCM +# error AES-GCM is only supported with opaque structs in use +# endif /* LIBSSH2_AES_GCM */ EVP_CIPHER_CTX_init(h); return !EVP_CipherInit(h, algo(), secret, iv, encrypt); #endif @@ -492,32 +510,113 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, _libssh2_cipher_type(algo), - int encrypt, unsigned char *block, size_t blocksize) + int encrypt, unsigned char *block, size_t blocksize, + int firstlast) { unsigned char buf[EVP_MAX_BLOCK_LENGTH]; - int ret; + int ret = 1; int rc = 1; +#if LIBSSH2_AES_GCM + const int is_aesgcm = (algo == EVP_aes_128_gcm) || + (algo == EVP_aes_256_gcm); + char lastiv[1]; +#else + const int is_aesgcm = 0; +#endif /* LIBSSH2_AES_GCM */ + /* length of AES-GCM Authentication Tag */ + const int authlen = is_aesgcm ? 16 : 0; + /* length of AAD, only on the first block */ + const int aadlen = (is_aesgcm && IS_FIRST(firstlast)) ? 4 : 0; + /* size of AT, if present */ + const int authenticationtag = IS_LAST(firstlast) ? authlen : 0; + /* length to encrypt */ + const int cryptlen = (unsigned int)blocksize - aadlen - authenticationtag; + (void)algo; + + assert(blocksize <= sizeof(buf)); + assert(cryptlen >= 0); + +#if LIBSSH2_AES_GCM + /* First block */ + if(IS_FIRST(firstlast)) { + /* Increments invocation_counter portion of IV */ + if(is_aesgcm) { + ret = EVP_CIPHER_CTX_ctrl(*ctx, EVP_CTRL_GCM_IV_GEN, 1, lastiv); + } + + if(aadlen) { + /* Include the 4 byte packet length as AAD */ + ret = EVP_Cipher(*ctx, NULL, block, aadlen); + } + } + + /* Last portion of block to encrypt/decrypt */ + if(IS_LAST(firstlast)) { + if(is_aesgcm && !encrypt) { + /* set tag on decryption */ + ret = EVP_CIPHER_CTX_ctrl(*ctx, EVP_CTRL_GCM_SET_TAG, authlen, + block + blocksize - authlen); + } + } +#else (void)encrypt; + (void)firstlast; +#endif /* LIBSSH2_AES_GCM */ + if(cryptlen > 0) { #ifdef HAVE_OPAQUE_STRUCTS - ret = EVP_Cipher(*ctx, buf, block, (unsigned int) blocksize); + ret = EVP_Cipher(*ctx, buf + aadlen, block + aadlen, cryptlen); #else - ret = EVP_Cipher(ctx, buf, block, (unsigned int) blocksize); + ret = EVP_Cipher(ctx, buf + aadlen, block + aadlen, cryptlen); #endif + } #if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || \ defined(LIBSSH2_WOLFSSL) if(ret != -1) #else - if(ret == 1) + if(ret >= 1) #endif { rc = 0; - memcpy(block, buf, blocksize); + if(IS_LAST(firstlast)) { + /* This is the last block. + encrypt: compute tag, if applicable + decrypt: verify tag, if applicable + in!=NULL is equivalent to EVP_CipherUpdate + in==NULL is equivalent to EVP_CipherFinal */ +#ifdef HAVE_OPAQUE_STRUCTS + ret = EVP_Cipher(*ctx, NULL, NULL, 0); /* final */ +#else + ret = EVP_Cipher(ctx, NULL, NULL, 0); /* final */ +#endif + if(ret < 0) { + ret = 0; + } + else { + ret = 1; +#if LIBSSH2_AES_GCM + if(is_aesgcm && encrypt) { + /* write the Authentication Tag a.k.a. MAC at the end + of the block */ + assert(authenticationtag == authlen); + ret = EVP_CIPHER_CTX_ctrl(*ctx, EVP_CTRL_GCM_GET_TAG, + authlen, block + blocksize - authenticationtag); + } +#endif /* LIBSSH2_AES_GCM */ + } + } + /* Copy en/decrypted data back to the caller. + The first aadlen should not be touched because they weren't + encrypted and are unmodified. */ + memcpy(block + aadlen, buf + aadlen, cryptlen); + rc = !ret; } + /* TODO: the return code should distinguish between decryption errors and + invalid MACs */ return rc; } diff --git a/src/openssl.h b/src/openssl.h index 13535aa5d3..3cd0deb08c 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -159,6 +159,12 @@ # define LIBSSH2_AES 0 #endif +#if (OPENSSL_VERSION_NUMBER >= 0x01010100fL && !defined(OPENSSL_NO_AES)) +# define LIBSSH2_AES_GCM 1 +#else +# define LIBSSH2_AES_GCM 0 +#endif + #ifdef OPENSSL_NO_BF # define LIBSSH2_BLOWFISH 0 #else @@ -395,6 +401,9 @@ libssh2_curve_type; #define _libssh2_cipher_ctx EVP_CIPHER_CTX #endif +#define _libssh2_cipher_aes256gcm EVP_aes_256_gcm +#define _libssh2_cipher_aes128gcm EVP_aes_128_gcm + #define _libssh2_cipher_aes256 EVP_aes_256_cbc #define _libssh2_cipher_aes192 EVP_aes_192_cbc #define _libssh2_cipher_aes128 EVP_aes_128_cbc diff --git a/src/os400qc3.c b/src/os400qc3.c index 1af7710bb8..870b510092 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -1097,7 +1097,8 @@ _libssh2_cipher_init(_libssh2_cipher_ctx *h, _libssh2_cipher_type(algo), int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx, _libssh2_cipher_type(algo), - int encrypt, unsigned char *block, size_t blocksize) + int encrypt, unsigned char *block, size_t blocksize, + int firstlast) { Qus_EC_t errcode; int outlen; diff --git a/src/os400qc3.h b/src/os400qc3.h index 990daefbda..297503b194 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -171,6 +171,7 @@ #define LIBSSH2_AES 1 #define LIBSSH2_AES_CTR 1 +#define LIBSSH2_AES_GCM 0 #define LIBSSH2_BLOWFISH 0 #define LIBSSH2_RC4 1 #define LIBSSH2_CAST 0 diff --git a/src/pem.c b/src/pem.c index 16717b73e9..255539a1ba 100644 --- a/src/pem.c +++ b/src/pem.c @@ -260,7 +260,11 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, while(len_decrypted <= (int)*datalen - blocksize) { if(method->crypt(session, *data + len_decrypted, blocksize, - &abstract)) { + &abstract, + len_decrypted == 0 ? FIRST_BLOCK : + ((len_decrypted == (int)*datalen - blocksize) ? + LAST_BLOCK : MIDDLE_BLOCK) + )) { ret = LIBSSH2_ERROR_DECRYPT; _libssh2_explicit_zero((char *)secret, sizeof(secret)); method->dtor(session, &abstract); @@ -589,7 +593,11 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, while((size_t)len_decrypted <= decrypted.len - blocksize) { if(method->crypt(session, decrypted.data + len_decrypted, blocksize, - &abstract)) { + &abstract, + len_decrypted == 0 ? FIRST_BLOCK : ( + ((size_t)len_decrypted == decrypted.len - blocksize) ? + LAST_BLOCK : MIDDLE_BLOCK) + )) { ret = LIBSSH2_ERROR_DECRYPT; method->dtor(session, &abstract); goto out; diff --git a/src/transport.c b/src/transport.c index 19ad6ec2a8..b2f646108b 100644 --- a/src/transport.c +++ b/src/transport.c @@ -130,18 +130,38 @@ debugdump(LIBSSH2_SESSION * session, static int decrypt(LIBSSH2_SESSION * session, unsigned char *source, - unsigned char *dest, ssize_t len) + unsigned char *dest, ssize_t len, int firstlast) { struct transportpacket *p = &session->packet; int blocksize = session->remote.crypt->blocksize; /* if we get called with a len that isn't an even number of blocksizes - we risk losing those extra bytes */ - assert((len % blocksize) == 0); + we risk losing those extra bytes. AAD is an exception, since those first + few bytes aren't encrypted so it throws off the rest of the count. */ + if(!CRYPT_FLAG_L(session, PKTLEN_AAD)) + assert((len % blocksize) == 0); + + while(len > 0) { + /* normally decrypt up to blocksize bytes at a time */ + ssize_t decryptlen = LIBSSH2_MIN(blocksize, len); + /* The first block is special (since it needs to be decoded to get the + length of the remainder of the block) and takes priority. When the + length finally gets to the last blocksize bytes, and there's no + more data to come, it's the end. */ + int lowerfirstlast = IS_FIRST(firstlast) ? FIRST_BLOCK : + ((len <= blocksize) ? firstlast : MIDDLE_BLOCK); + /* If the last block would be less than a whole blocksize, combine it + with the previous block to make it larger. This ensures that the + whole MAC is included in a single decrypt call. */ + if(CRYPT_FLAG_L(session, PKTLEN_AAD) && IS_LAST(firstlast) + && (len < blocksize*2)) { + decryptlen = len; + lowerfirstlast = LAST_BLOCK; + } - while(len >= blocksize) { - if(session->remote.crypt->crypt(session, source, blocksize, - &session->remote.crypt_abstract)) { + if(session->remote.crypt->crypt(session, source, decryptlen, + &session->remote.crypt_abstract, + lowerfirstlast)) { LIBSSH2_FREE(session, p->payload); return LIBSSH2_ERROR_DECRYPT; } @@ -149,11 +169,11 @@ decrypt(LIBSSH2_SESSION * session, unsigned char *source, /* if the crypt() function would write to a given address it wouldn't have to memcpy() and we could avoid this memcpy() too */ - memcpy(dest, source, blocksize); + memcpy(dest, source, decryptlen); - len -= blocksize; /* less bytes left */ - dest += blocksize; /* advance write pointer */ - source += blocksize; /* advance read pointer */ + len -= decryptlen; /* less bytes left */ + dest += decryptlen; /* advance write pointer */ + source += decryptlen; /* advance read pointer */ } return LIBSSH2_ERROR_NONE; /* all is fine */ } @@ -174,7 +194,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) session->fullpacket_macstate = LIBSSH2_MAC_CONFIRMED; session->fullpacket_payload_len = p->packet_length - 1; - if(encrypted) { + if(encrypted && !CRYPT_FLAG_L(session, INTEGRATED_MAC)) { /* Calculate MAC hash */ session->remote.mac->hash(session, macbuf, /* store hash here */ @@ -286,6 +306,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) int blocksize; /* minimum number of bytes we need before we can use them */ int encrypted = 1; /* whether the packet is encrypted or not */ + int firstlast = FIRST_BLOCK; /* if the first or last block to decrypt */ /* default clear the bit */ session->socket_block_directions &= ~LIBSSH2_SESSION_BLOCK_INBOUND; @@ -423,12 +444,15 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) } if(encrypted) { - rc = decrypt(session, &p->buf[p->readidx], block, blocksize); + /* first decrypted block */ + rc = decrypt(session, &p->buf[p->readidx], + block, blocksize, FIRST_BLOCK); if(rc != LIBSSH2_ERROR_NONE) { return rc; } - /* save the first 5 bytes of the decrypted package, to be - used in the hash calculation later down. */ + /* Save the first 5 bytes of the decrypted package, to be + used in the hash calculation later down. + This is ignored in the INTEGRATED_MAC case. */ memcpy(p->init, block, 5); } else { @@ -451,12 +475,15 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) return LIBSSH2_ERROR_OUT_OF_BOUNDARY; } + /* padding_length has not been authenticated yet, but it won't + actually be used (except for the sanity check immediately + following) until after the entire packet is authenticated, + so this is safe. */ p->padding_length = block[4]; if(p->padding_length > p->packet_length - 1) { return LIBSSH2_ERROR_DECRYPT; } - /* total_num is the number of bytes following the initial (5 bytes) packet length and padding length fields */ total_num = p->packet_length - 1 + @@ -524,35 +551,53 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) since it is used for the hash later on. */ int skip = session->remote.mac->mac_len; + if(CRYPT_FLAG_R(session, INTEGRATED_MAC)) + /* This crypto method DOES need the MAC to go through + decryption so it can be authenticated. */ + skip = 0; + /* if what we have plus numbytes is bigger than the total minus the skip margin, we should lower the amount to decrypt even more */ - if((p->data_num + numbytes) > (p->total_num - skip)) { - numdecrypt = (p->total_num - skip) - p->data_num; + if((p->data_num + numbytes) >= (p->total_num - skip)) { + /* decrypt the entire rest of the package */ + numdecrypt = LIBSSH2_MAX(0, + (int)(p->total_num - skip) - (int)p->data_num); + firstlast = LAST_BLOCK; } else { ssize_t frac; numdecrypt = numbytes; frac = numdecrypt % blocksize; if(frac) { - /* not an aligned amount of blocks, - align it */ + /* not an aligned amount of blocks, align it by reducing + the number of bytes processed this loop */ numdecrypt -= frac; /* and make it no unencrypted data after it */ numbytes = 0; } + if(CRYPT_FLAG_R(session, INTEGRATED_MAC)) { + /* Make sure that we save enough bytes to make the last + * block large enough to hold the entire integrated MAC */ + numdecrypt = LIBSSH2_MIN(numdecrypt, + (int)(p->total_num - skip - blocksize - p->data_num)); + numbytes = 0; + } + firstlast = MIDDLE_BLOCK; } } else { /* unencrypted data should not be decrypted at all */ numdecrypt = 0; } + assert(numdecrypt >= 0); /* if there are bytes to decrypt, do that */ if(numdecrypt > 0) { /* now decrypt the lot */ - rc = decrypt(session, &p->buf[p->readidx], p->wptr, numdecrypt); + rc = decrypt(session, &p->buf[p->readidx], p->wptr, numdecrypt, + firstlast); if(rc != LIBSSH2_ERROR_NONE) { p->total_num = 0; /* no packet buffer available */ return rc; @@ -731,6 +776,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, int rc; const unsigned char *orgdata = data; size_t orgdata_len = data_len; + size_t crypt_offset; /* * If the last read operation was interrupted in the middle of a key @@ -829,12 +875,14 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, packet_length = data_len + 1 + 4; /* 1 is for padding_length field 4 for the packet_length field */ + /* subtract 4 bytes of the packet_length field when padding AES-GCM */ + crypt_offset = (encrypted && CRYPT_FLAG_R(session, PKTLEN_AAD)) ? 4 : 0; /* at this point we have it all except the padding */ /* first figure out our minimum padding amount to make it an even block size */ - padding_length = blocksize - (packet_length % blocksize); + padding_length = blocksize - ((packet_length - crypt_offset) % blocksize); /* if the padding becomes too small we add another blocksize worth of it (taken from the original libssh2 where it didn't have any @@ -877,19 +925,62 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, /* Calculate MAC hash. Put the output at index packet_length, since that size includes the whole packet. The MAC is calculated on the entire unencrypted packet, including all - fields except the MAC field itself. */ - session->local.mac->hash(session, p->outbuf + packet_length, - session->local.seqno, p->outbuf, - packet_length, NULL, 0, - &session->local.mac_abstract); + fields except the MAC field itself. This is skipped in the + INTEGRATED_MAC case, where the crypto algorithm also does its + own hash. */ + if(!CRYPT_FLAG_R(session, INTEGRATED_MAC)) { + session->local.mac->hash(session, p->outbuf + packet_length, + session->local.seqno, p->outbuf, + packet_length, NULL, 0, + &session->local.mac_abstract); + } /* Encrypt the whole packet data, one block size at a time. - The MAC field is not encrypted. */ - for(i = 0; i < packet_length; i += session->local.crypt->blocksize) { + The MAC field is not encrypted unless INTEGRATED_MAC. */ + /* Some crypto back-ends could handle a single crypt() call for + encryption, but (presumably) others cannot, so break it up + into blocksize-sized chunks to satisfy them all. */ + for(i = 0; i < packet_length; + i += session->local.crypt->blocksize) { unsigned char *ptr = &p->outbuf[i]; + size_t bsize = LIBSSH2_MIN(session->local.crypt->blocksize, + (int)(packet_length-i)); + /* The INTEGRATED_MAC case always has an extra call below, + so it will never be LAST_BLOCK up here. */ + int firstlast = i == 0 ? FIRST_BLOCK : + (!CRYPT_FLAG_L(session, INTEGRATED_MAC) + && (i == packet_length - session->local.crypt->blocksize) + ? LAST_BLOCK: MIDDLE_BLOCK); + /* In the AAD case, the last block would be only 4 bytes + because everything is offset by 4 since the initial + packet_length isn't encrypted. In this case, combine that + last short packet with the previous one since AES-GCM + crypt() assumes that the entire MAC is available in that + packet so it can set that to the authentication tag. */ + if(!CRYPT_FLAG_L(session, INTEGRATED_MAC)) + if(i > packet_length - 2*bsize) { + /* increase the final block size */ + bsize = packet_length - i; + /* advance the loop counter by the extra amount */ + i += bsize - session->local.crypt->blocksize; + } if(session->local.crypt->crypt(session, ptr, - session->local.crypt->blocksize, - &session->local.crypt_abstract)) + bsize, + &session->local.crypt_abstract, + firstlast)) + return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */ + } + /* Call crypt() one last time so it can be filled in with + the MAC */ + if(CRYPT_FLAG_L(session, INTEGRATED_MAC)) { + int authlen = session->local.mac->mac_len; + assert((size_t)total_length <= + packet_length + session->local.crypt->blocksize); + if(session->local.crypt->crypt(session, + &p->outbuf[packet_length], + authlen, + &session->local.crypt_abstract, + LAST_BLOCK)) return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */ } } diff --git a/src/wincng.c b/src/wincng.c index 4653610510..3c842bc147 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -2010,13 +2010,14 @@ _libssh2_wincng_cipher_crypt(_libssh2_cipher_ctx *ctx, _libssh2_cipher_type(type), int encrypt, unsigned char *block, - size_t blocklen) + size_t blocklen, int firstlast) { unsigned char *pbOutput, *pbInput; unsigned long cbOutput, cbInput; int ret; (void)type; + (void)firstlast; cbInput = (unsigned long)blocklen; diff --git a/src/wincng.h b/src/wincng.h index df346c9e61..558adda667 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -59,6 +59,7 @@ #define LIBSSH2_AES 1 #define LIBSSH2_AES_CTR 1 +#define LIBSSH2_AES_GCM 0 #define LIBSSH2_BLOWFISH 0 #define LIBSSH2_RC4 1 #define LIBSSH2_CAST 0 @@ -377,8 +378,8 @@ struct _libssh2_wincng_cipher_type { #define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \ _libssh2_wincng_cipher_init(ctx, type, iv, secret, encrypt) -#define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen) \ - _libssh2_wincng_cipher_crypt(ctx, type, encrypt, block, blocklen) +#define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) \ + _libssh2_wincng_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) #define _libssh2_cipher_dtor(ctx) \ _libssh2_wincng_cipher_dtor(ctx) @@ -606,7 +607,7 @@ _libssh2_wincng_cipher_crypt(_libssh2_cipher_ctx *ctx, _libssh2_cipher_type(type), int encrypt, unsigned char *block, - size_t blocklen); + size_t blocklen, int firstlast); void _libssh2_wincng_cipher_dtor(_libssh2_cipher_ctx *ctx); From 2d7be5f5d83b17b54a89b0ba70d8ea0cc1497517 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 13:54:54 +0000 Subject: [PATCH 307/424] tidy-up: indentation fixes [ci skip] --- src/kex.c | 15 +++++++-------- src/transport.c | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/kex.c b/src/kex.c index 886a456857..2c5266570a 100644 --- a/src/kex.c +++ b/src/kex.c @@ -3751,27 +3751,26 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data, } if(kex_agree_crypt(session, &session->local, crypt_cs, crypt_cs_len) - || kex_agree_crypt(session, &session->remote, crypt_sc, - crypt_sc_len)) { + || kex_agree_crypt(session, &session->remote, crypt_sc, crypt_sc_len)) { return -1; } /* This must happen after kex_agree_crypt since some MACs depend on the negotiated crypto method */ - if(kex_agree_mac(session, &session->local, mac_cs, mac_cs_len) || - kex_agree_mac(session, &session->remote, mac_sc, mac_sc_len)) { + if(kex_agree_mac(session, &session->local, mac_cs, mac_cs_len) + || kex_agree_mac(session, &session->remote, mac_sc, mac_sc_len)) { return -1; } - if(kex_agree_comp(session, &session->local, comp_cs, comp_cs_len) || - kex_agree_comp(session, &session->remote, comp_sc, comp_sc_len)) { + if(kex_agree_comp(session, &session->local, comp_cs, comp_cs_len) + || kex_agree_comp(session, &session->remote, comp_sc, comp_sc_len)) { return -1; } #if 0 if(libssh2_kex_agree_lang(session, &session->local, lang_cs, lang_cs_len) - || libssh2_kex_agree_lang(session, &session->remote, lang_sc, - lang_sc_len)) { + || libssh2_kex_agree_lang(session, &session->remote, lang_sc, + lang_sc_len)) { return -1; } #endif diff --git a/src/transport.c b/src/transport.c index b2f646108b..3e3119cee9 100644 --- a/src/transport.c +++ b/src/transport.c @@ -437,7 +437,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) /* we can't act on anything less than blocksize, but this check is only done for the initial block since once we have got the start of a block we can in fact deal with fractions - */ + */ session->socket_block_directions |= LIBSSH2_SESSION_BLOCK_INBOUND; return LIBSSH2_ERROR_EAGAIN; From 5e560020555ada31c393092e07dd581bfc29a728 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 13:55:30 +0000 Subject: [PATCH 308/424] crypto: add `LIBSSH2_NO_AES_CBC` option Also rename internal `LIBSSH2_AES` to `LIBSSH2_AES_CBC`. Follow-up to 857e431648df6edcb3e17138d877f2e65d2d769d Closes #990 --- src/crypt.c | 10 +++++----- src/crypto.h | 5 +++++ src/libgcrypt.h | 2 +- src/mbedtls.h | 2 +- src/openssl.h | 4 ++-- src/os400qc3.h | 2 +- src/wincng.h | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/crypt.c b/src/crypt.c index fb47e19ca4..9652e6cd48 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -195,7 +195,7 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes256_ctr = { }; #endif -#if LIBSSH2_AES +#if LIBSSH2_AES_CBC static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes128_cbc = { "aes128-cbc", "DEK-Info: AES-128-CBC", @@ -249,7 +249,7 @@ static const LIBSSH2_CRYPT_METHOD &crypt_dtor, _libssh2_cipher_aes256 }; -#endif /* LIBSSH2_AES */ +#endif /* LIBSSH2_AES_CBC */ #if LIBSSH2_BLOWFISH static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_blowfish_cbc = { @@ -359,13 +359,13 @@ static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = { &libssh2_crypt_method_aes256_ctr, &libssh2_crypt_method_aes192_ctr, &libssh2_crypt_method_aes128_ctr, -#endif /* LIBSSH2_AES */ -#if LIBSSH2_AES +#endif /* LIBSSH2_AES_CTR */ +#if LIBSSH2_AES_CBC &libssh2_crypt_method_aes256_cbc, &libssh2_crypt_method_rijndael_cbc_lysator_liu_se, /* == aes256-cbc */ &libssh2_crypt_method_aes192_cbc, &libssh2_crypt_method_aes128_cbc, -#endif /* LIBSSH2_AES */ +#endif /* LIBSSH2_AES_CBC */ #if LIBSSH2_BLOWFISH &libssh2_crypt_method_blowfish_cbc, #endif /* LIBSSH2_BLOWFISH */ diff --git a/src/crypto.h b/src/crypto.h index b517b16f2c..381af8bc3b 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -87,6 +87,11 @@ #define LIBSSH2_AES_CTR 0 #endif +#ifdef LIBSSH2_NO_AES_CBC +#undef LIBSSH2_AES_CBC +#define LIBSSH2_AES_CBC 0 +#endif + #ifdef LIBSSH2_NO_BLOWFISH #undef LIBSSH2_BLOWFISH #define LIBSSH2_BLOWFISH 0 diff --git a/src/libgcrypt.h b/src/libgcrypt.h index f750f9b4ca..761f446c16 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -49,7 +49,7 @@ #define LIBSSH2_HMAC_SHA256 1 #define LIBSSH2_HMAC_SHA512 1 -#define LIBSSH2_AES 1 +#define LIBSSH2_AES_CBC 1 #define LIBSSH2_AES_CTR 1 #define LIBSSH2_AES_GCM 0 #define LIBSSH2_BLOWFISH 1 diff --git a/src/mbedtls.h b/src/mbedtls.h index 5053b101ed..8065844050 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -65,7 +65,7 @@ #define LIBSSH2_HMAC_SHA256 1 #define LIBSSH2_HMAC_SHA512 1 -#define LIBSSH2_AES 1 +#define LIBSSH2_AES_CBC 1 #define LIBSSH2_AES_CTR 1 #define LIBSSH2_AES_GCM 0 #ifdef MBEDTLS_CIPHER_BLOWFISH_CBC diff --git a/src/openssl.h b/src/openssl.h index 3cd0deb08c..1487af1133 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -153,10 +153,10 @@ #if (OPENSSL_VERSION_NUMBER >= 0x00907000L && !defined(OPENSSL_NO_AES)) || \ (defined(LIBSSH2_WOLFSSL) && defined(WOLFSSL_AES_COUNTER)) # define LIBSSH2_AES_CTR 1 -# define LIBSSH2_AES 1 +# define LIBSSH2_AES_CBC 1 #else # define LIBSSH2_AES_CTR 0 -# define LIBSSH2_AES 0 +# define LIBSSH2_AES_CBC 0 #endif #if (OPENSSL_VERSION_NUMBER >= 0x01010100fL && !defined(OPENSSL_NO_AES)) diff --git a/src/os400qc3.h b/src/os400qc3.h index 297503b194..5d1ba48a05 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -169,7 +169,7 @@ #define LIBSSH2_HMAC_SHA256 1 #define LIBSSH2_HMAC_SHA512 1 -#define LIBSSH2_AES 1 +#define LIBSSH2_AES_CBC 1 #define LIBSSH2_AES_CTR 1 #define LIBSSH2_AES_GCM 0 #define LIBSSH2_BLOWFISH 0 diff --git a/src/wincng.h b/src/wincng.h index 558adda667..21b25605e2 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -57,7 +57,7 @@ #define LIBSSH2_HMAC_SHA256 1 #define LIBSSH2_HMAC_SHA512 1 -#define LIBSSH2_AES 1 +#define LIBSSH2_AES_CBC 1 #define LIBSSH2_AES_CTR 1 #define LIBSSH2_AES_GCM 0 #define LIBSSH2_BLOWFISH 0 From a4544c0117867d5cc0830497b1626f810ccc0743 Mon Sep 17 00:00:00 2001 From: Keith Dart Date: Fri, 11 Feb 2022 23:20:48 -0800 Subject: [PATCH 309/424] channel: add support for "signal" message Can send specific signals to remote process. Allows for slightly improved remote process management, if the server supports it. Integration-patches-by: Viktor Szakats * doc updates * change `signame_len` to `size_t` * variable scopes * fix checksrc warnings Closes #672 Closes #991 --- docs/Makefile.am | 1 + docs/libssh2_channel_signal_ex.3 | 32 ++++++++++++ include/libssh2.h | 6 +++ src/channel.c | 84 ++++++++++++++++++++++++++++++++ src/libssh2_priv.h | 5 ++ 5 files changed, 128 insertions(+) create mode 100644 docs/libssh2_channel_signal_ex.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index 8e998638fd..bb2e4434b7 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -50,6 +50,7 @@ dist_man_MANS = \ libssh2_channel_setenv.3 \ libssh2_channel_setenv_ex.3 \ libssh2_channel_shell.3 \ + libssh2_channel_signal_ex.3 \ libssh2_channel_subsystem.3 \ libssh2_channel_wait_closed.3 \ libssh2_channel_wait_eof.3 \ diff --git a/docs/libssh2_channel_signal_ex.3 b/docs/libssh2_channel_signal_ex.3 new file mode 100644 index 0000000000..236657e3b2 --- /dev/null +++ b/docs/libssh2_channel_signal_ex.3 @@ -0,0 +1,32 @@ +.TH libssh2_channel_signal_ex 3 "20 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.SH NAME +libssh2_channel_signal_ex -- Send a signal to process previously opened on channel. +.SH SYNOPSIS +.nf +#include + +int +libssh2_channel_signal_ex(LIBSSH2_CHANNEL *channel, + const char *signame, + size_t signame_len) +.fi +.SH DESCRIPTION +A signal can be delivered to the remote process/service. Some servers or +systems may not implement signals, in which case they will probably ignore this +message. + +\fIchannel\fP - Previously opened channel instance such as returned by +.BR libssh2_channel_open_ex(3) + +\fIsigname\fP - The signal name is the same as the signal name constant, without the leading "SIG". + +\fIsigname_len\fP - Length of passed signal name parameter. + +There is also a macro \fIlibssh2_channel_signal(channel, signame)\fP that supplies the strlen of the signame. + +.SH RETURN VALUE +Normal channel error codes. +LIBSSH2_ERROR_EAGAIN when it would block. + +.SH SEE ALSO +.BR libssh2_channel_get_exit_signal(3) diff --git a/include/libssh2.h b/include/libssh2.h index 0a09c40f19..68bab7c8aa 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -850,6 +850,12 @@ LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, #define libssh2_channel_x11_req(channel, screen_number) \ libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number)) +LIBSSH2_API int libssh2_channel_signal_ex(LIBSSH2_CHANNEL *channel, + const char *signame, + size_t signame_len); +#define libssh2_channel_signal(channel, signame) \ + libssh2_channel_signal_ex((channel), signame, strlen(signame)) + LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, const char *request, unsigned int request_len, diff --git a/src/channel.c b/src/channel.c index ed3032a710..1c119cfc63 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2987,3 +2987,87 @@ libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel, return channel->local.window_size; } + +/* A signal can be delivered to the remote process/service using the + following message. Some systems may not implement signals, in which + case they SHOULD ignore this message. + + byte SSH_MSG_CHANNEL_REQUEST + uint32 recipient channel + string "signal" + boolean FALSE + string signal name (without the "SIG" prefix) + + 'signal name' values will be encoded as discussed in the passage + describing SSH_MSG_CHANNEL_REQUEST messages using "exit-signal" in + this section. + */ +static int channel_signal(LIBSSH2_CHANNEL *channel, + const char *signame, + size_t signame_len) +{ + LIBSSH2_SESSION *session = channel->session; + int retcode = LIBSSH2_ERROR_PROTO; + + if(channel->sendsignal_state == libssh2_NB_state_idle) { + unsigned char *s; + + /* 20 = packet_type(1) + channel(4) + + signal_len + sizeof(signal) - 1 + want_reply(1) + + signame_len_len(4) */ + channel->sendsignal_packet_len = 20 + signame_len; + + s = channel->sendsignal_packet = + LIBSSH2_ALLOC(session, channel->sendsignal_packet_len); + if(!channel->sendsignal_packet) + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "signal request"); + + *(s++) = SSH_MSG_CHANNEL_REQUEST; + _libssh2_store_u32(&s, channel->remote.id); + _libssh2_store_str(&s, "signal", sizeof("signal") - 1); + *(s++) = 0x00; /* Don't reply */ + _libssh2_store_str(&s, signame, signame_len); + + channel->sendsignal_state = libssh2_NB_state_created; + } + + if(channel->sendsignal_state == libssh2_NB_state_created) { + int rc; + + rc = _libssh2_transport_send(session, channel->sendsignal_packet, + channel->sendsignal_packet_len, + NULL, 0); + if(rc == LIBSSH2_ERROR_EAGAIN) { + _libssh2_error(session, rc, "Would block sending signal request"); + return rc; + } + else if(rc) { + LIBSSH2_FREE(session, channel->sendsignal_packet); + channel->sendsignal_state = libssh2_NB_state_idle; + return _libssh2_error(session, rc, "Unable to send signal packet"); + } + LIBSSH2_FREE(session, channel->sendsignal_packet); + retcode = LIBSSH2_ERROR_NONE; + } + + channel->sendsignal_state = libssh2_NB_state_idle; + + return retcode; +} + +LIBSSH2_API int +libssh2_channel_signal_ex(LIBSSH2_CHANNEL *channel, + const char *signame, + size_t signame_len) +{ + int rc; + + if(!channel) + return LIBSSH2_ERROR_BAD_USE; + + BLOCK_ADJUST(rc, channel->session, + channel_signal(channel, signame, signame_len)); + return rc; +} diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 55e1a4ab3c..0ba35db499 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -466,6 +466,11 @@ struct _LIBSSH2_CHANNEL size_t req_auth_agent_packet_len; unsigned char req_auth_agent_local_channel[4]; packet_requirev_state_t req_auth_agent_requirev_state; + + /* State variables used in libssh2_channel_signal_ex() */ + libssh2_nonblocking_states sendsignal_state; + unsigned char *sendsignal_packet; + size_t sendsignal_packet_len; }; struct _LIBSSH2_LISTENER From 6812985e6089a7610005366b51d64d46d9a31265 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 23:04:26 +0000 Subject: [PATCH 310/424] docs: fix typo in argument name [ci skip] --- docs/libssh2_userauth_publickey_fromfile_ex.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/libssh2_userauth_publickey_fromfile_ex.3 b/docs/libssh2_userauth_publickey_fromfile_ex.3 index 51091d7c29..fbd75ebde5 100644 --- a/docs/libssh2_userauth_publickey_fromfile_ex.3 +++ b/docs/libssh2_userauth_publickey_fromfile_ex.3 @@ -8,7 +8,7 @@ libssh2_userauth_publickey_fromfile_ex - authenticate a session with a public ke int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, const char *username, - unsigned int ousername_len, + unsigned int username_len, const char *publickey, const char *privatekey, const char *passphrase); From 0048f3060ecc008d5a04095ca48f5c0421e66c08 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Apr 2023 11:23:52 +0200 Subject: [PATCH 311/424] support encrypt-then-mac (etm) MACs (#987) Support for calculating MAC (message authentication code) on encrypted data instead of plain text data. This adds support for the following MACs: - `hmac-sha1-etm@openssh.com` - `hmac-sha2-256-etm@openssh.com` - `hmac-sha2-512-etm@openssh.com` Integration-patches-by: Viktor Szakats * rebase on master * fix checksec warnings * fix compiler warning * fix indent/whitespace/eol * rebase/manual merge onto AES-GCM patch #797 * more manual merge of `libssh2_transport_send()` based on dfandrich/shellfish Fixes #582 Closes #655 Closes #987 --- src/libssh2_priv.h | 3 +- src/mac.c | 49 ++++- src/mac.h | 2 + src/transport.c | 231 +++++++++++++++++------- tests/CMakeLists.txt | 3 + tests/Makefile.am | 5 +- tests/test_auth_keyboard_info_request.c | 2 +- 7 files changed, 226 insertions(+), 69 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 0ba35db499..fe7a6af53c 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -541,7 +541,8 @@ struct transportpacket packet_length + padding_length + 4 + mac_length. */ unsigned char *payload; /* this is a pointer to a LIBSSH2_ALLOC() - area to which we write decrypted data */ + area to which we write incoming packet data + which is not yet decrypted in etm mode. */ unsigned char *wptr; /* write pointer into the payload to where we are currently writing decrypted data */ diff --git a/src/mac.c b/src/mac.c index 06ca396a81..01c5faa264 100644 --- a/src/mac.c +++ b/src/mac.c @@ -71,7 +71,8 @@ static LIBSSH2_MAC_METHOD mac_method_none = { 0, NULL, mac_none_MAC, - NULL + NULL, + 0 }; #endif /* defined(LIBSSH2DEBUG) && defined(LIBSSH2_MAC_NONE_INSECURE) */ @@ -138,8 +139,6 @@ mac_method_hmac_sha2_512_hash(LIBSSH2_SESSION * session, return 0; } - - static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_512 = { "hmac-sha2-512", 64, @@ -147,7 +146,19 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_512 = { mac_method_common_init, mac_method_hmac_sha2_512_hash, mac_method_common_dtor, + 0 +}; + +static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_512_etm = { + "hmac-sha2-512-etm@openssh.com", + 64, + 64, + mac_method_common_init, + mac_method_hmac_sha2_512_hash, + mac_method_common_dtor, + 1 }; + #endif @@ -192,7 +203,19 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_256 = { mac_method_common_init, mac_method_hmac_sha2_256_hash, mac_method_common_dtor, + 0 }; + +static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_256_etm = { + "hmac-sha2-256-etm@openssh.com", + 32, + 32, + mac_method_common_init, + mac_method_hmac_sha2_256_hash, + mac_method_common_dtor, + 1 +}; + #endif @@ -237,6 +260,17 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_sha1 = { mac_method_common_init, mac_method_hmac_sha1_hash, mac_method_common_dtor, + 0 +}; + +static const LIBSSH2_MAC_METHOD mac_method_hmac_sha1_etm = { + "hmac-sha1-etm@openssh.com", + 20, + 20, + mac_method_common_init, + mac_method_hmac_sha1_hash, + mac_method_common_dtor, + 1 }; /* mac_method_hmac_sha1_96_hash @@ -268,6 +302,7 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_sha1_96 = { mac_method_common_init, mac_method_hmac_sha1_96_hash, mac_method_common_dtor, + 0 }; #if LIBSSH2_MD5 @@ -310,6 +345,7 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_md5 = { mac_method_common_init, mac_method_hmac_md5_hash, mac_method_common_dtor, + 0 }; /* mac_method_hmac_md5_96_hash @@ -339,6 +375,7 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_md5_96 = { mac_method_common_init, mac_method_hmac_md5_96_hash, mac_method_common_dtor, + 0 }; #endif /* LIBSSH2_MD5 */ @@ -383,6 +420,7 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_ripemd160 = { mac_method_common_init, mac_method_hmac_ripemd160_hash, mac_method_common_dtor, + 0 }; static const LIBSSH2_MAC_METHOD mac_method_hmac_ripemd160_openssh_com = { @@ -392,17 +430,21 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_ripemd160_openssh_com = { mac_method_common_init, mac_method_hmac_ripemd160_hash, mac_method_common_dtor, + 0 }; #endif /* LIBSSH2_HMAC_RIPEMD */ static const LIBSSH2_MAC_METHOD *mac_methods[] = { #if LIBSSH2_HMAC_SHA256 &mac_method_hmac_sha2_256, + &mac_method_hmac_sha2_256_etm, #endif #if LIBSSH2_HMAC_SHA512 &mac_method_hmac_sha2_512, + &mac_method_hmac_sha2_512_etm, #endif &mac_method_hmac_sha1, + &mac_method_hmac_sha1_etm, &mac_method_hmac_sha1_96, #if LIBSSH2_MD5 &mac_method_hmac_md5, @@ -435,6 +477,7 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_aesgcm = { NULL, NULL, NULL, + 0 }; #endif /* LIBSSH2_AES_GCM */ diff --git a/src/mac.h b/src/mac.h index 7d21a3af52..82379b91cb 100644 --- a/src/mac.h +++ b/src/mac.h @@ -57,6 +57,8 @@ struct _LIBSSH2_MAC_METHOD size_t packet_len, const unsigned char *addtl, size_t addtl_len, void **abstract); int (*dtor) (LIBSSH2_SESSION * session, void **abstract); + + int etm; /* encrypt-then-mac */ }; typedef struct _LIBSSH2_MAC_METHOD LIBSSH2_MAC_METHOD; diff --git a/src/transport.c b/src/transport.c index 3e3119cee9..8646608bc3 100644 --- a/src/transport.c +++ b/src/transport.c @@ -197,21 +197,81 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) if(encrypted && !CRYPT_FLAG_L(session, INTEGRATED_MAC)) { /* Calculate MAC hash */ - session->remote.mac->hash(session, macbuf, /* store hash here */ - session->remote.seqno, - p->init, 5, - p->payload, - session->fullpacket_payload_len, - &session->remote.mac_abstract); + int etm = session->remote.mac->etm; + size_t mac_len = session->remote.mac->mac_len; + if(etm) { + /* store hash here */ + session->remote.mac->hash(session, macbuf, + session->remote.seqno, + p->payload, p->total_num - mac_len, + NULL, 0, + &session->remote.mac_abstract); + } + else { + /* store hash here */ + session->remote.mac->hash(session, macbuf, + session->remote.seqno, + p->init, 5, + p->payload, + session->fullpacket_payload_len, + &session->remote.mac_abstract); + } /* Compare the calculated hash with the MAC we just read from * the network. The read one is at the very end of the payload * buffer. Note that 'payload_len' here is the packet_length * field which includes the padding but not the MAC. */ - if(memcmp(macbuf, p->payload + session->fullpacket_payload_len, - session->remote.mac->mac_len)) { + if(memcmp(macbuf, p->payload + p->total_num - mac_len, mac_len)) { + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Failed MAC check")); session->fullpacket_macstate = LIBSSH2_MAC_INVALID; + + } + else if(etm) { + /* MAC was ok and we start by decrypting the first block that + contains padding length since this allows us to decrypt + all other blocks to the right location in memory + avoiding moving a larger block of memory one byte. */ + unsigned char first_block[MAX_BLOCKSIZE]; + ssize_t decrypt_size; + unsigned char *decrypt_buffer; + int blocksize = session->remote.crypt->blocksize; + + rc = decrypt(session, p->payload + 4, + first_block, blocksize, FIRST_BLOCK); + if(rc) { + return rc; + } + + /* we need buffer for decrypt */ + decrypt_size = p->total_num - mac_len - 4; + decrypt_buffer = LIBSSH2_ALLOC(session, decrypt_size); + if(!decrypt_buffer) { + return LIBSSH2_ERROR_ALLOC; + } + + /* grab padding length and copy anything else + into target buffer */ + p->padding_length = first_block[0]; + if(blocksize > 1) { + memcpy(decrypt_buffer, first_block + 1, blocksize - 1); + } + + /* decrypt all other blocks packet */ + if(blocksize < decrypt_size) { + rc = decrypt(session, p->payload + blocksize + 4, + decrypt_buffer + blocksize - 1, + decrypt_size - blocksize, LAST_BLOCK); + if(rc) { + LIBSSH2_FREE(session, decrypt_buffer); + return rc; + } + } + + /* replace encrypted payload with plain text payload */ + LIBSSH2_FREE(session, p->payload); + p->payload = decrypt_buffer; } } @@ -348,6 +408,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) } do { + int etm; if(session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) { return LIBSSH2_ERROR_SOCKET_DISCONNECT; } @@ -361,6 +422,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) make the checks below work fine still */ } + etm = encrypted && session->local.mac ? session->local.mac->etm : 0; + /* read/use a whole big chunk into a temporary area stored in the LIBSSH2_SESSION struct. We will decrypt data from that buffer into the packet buffer so this temp one doesn't have @@ -429,45 +492,55 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) (5 bytes) packet length and padding length fields */ + /* packet length is not encrypted in encode-then-mac mode + and we donøt need to decrypt first block */ + ssize_t required_size = etm ? 4 : blocksize; + /* No payload package area allocated yet. To know the - size of this payload, we need to decrypt the first + size of this payload, we need enough to decrypt the first blocksize data. */ - if(numbytes < blocksize) { + if(numbytes < required_size) { /* we can't act on anything less than blocksize, but this check is only done for the initial block since once we have got the start of a block we can in fact deal with fractions - */ + */ session->socket_block_directions |= LIBSSH2_SESSION_BLOCK_INBOUND; return LIBSSH2_ERROR_EAGAIN; } - if(encrypted) { - /* first decrypted block */ - rc = decrypt(session, &p->buf[p->readidx], - block, blocksize, FIRST_BLOCK); - if(rc != LIBSSH2_ERROR_NONE) { - return rc; - } - /* Save the first 5 bytes of the decrypted package, to be - used in the hash calculation later down. - This is ignored in the INTEGRATED_MAC case. */ - memcpy(p->init, block, 5); + if(etm) { + p->packet_length = _libssh2_ntohu32(&p->buf[p->readidx]); } else { - /* the data is plain, just copy it verbatim to - the working block buffer */ - memcpy(block, &p->buf[p->readidx], blocksize); - } + if(encrypted) { + /* first decrypted block */ + rc = decrypt(session, &p->buf[p->readidx], + block, blocksize, FIRST_BLOCK); + if(rc != LIBSSH2_ERROR_NONE) { + return rc; + } + /* Save the first 5 bytes of the decrypted package, to be + used in the hash calculation later down. + This is ignored in the INTEGRATED_MAC case. */ + memcpy(p->init, block, 5); + } + else { + /* the data is plain, just copy it verbatim to + the working block buffer */ + memcpy(block, &p->buf[p->readidx], blocksize); + } - /* advance the read pointer */ - p->readidx += blocksize; + /* advance the read pointer */ + p->readidx += blocksize; + + /* we now have the initial blocksize bytes decrypted, + * and we can extract packet and padding length from it + */ + p->packet_length = _libssh2_ntohu32(block); + } - /* we now have the initial blocksize bytes decrypted, - * and we can extract packet and padding length from it - */ - p->packet_length = _libssh2_ntohu32(block); if(p->packet_length < 1) { return LIBSSH2_ERROR_DECRYPT; } @@ -475,19 +548,27 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) return LIBSSH2_ERROR_OUT_OF_BOUNDARY; } - /* padding_length has not been authenticated yet, but it won't - actually be used (except for the sanity check immediately - following) until after the entire packet is authenticated, - so this is safe. */ - p->padding_length = block[4]; - if(p->padding_length > p->packet_length - 1) { - return LIBSSH2_ERROR_DECRYPT; + if(etm) { + /* we collect entire undecrypted packet including the + packet length field that we run MAC over */ + total_num = 4 + p->packet_length + + session->remote.mac->mac_len; } + else { + /* padding_length has not been authenticated yet, but it won't + actually be used (except for the sanity check immediately + following) until after the entire packet is authenticated, + so this is safe. */ + p->padding_length = block[4]; + if(p->padding_length > p->packet_length - 1) { + return LIBSSH2_ERROR_DECRYPT; + } - /* total_num is the number of bytes following the initial - (5 bytes) packet length and padding length fields */ - total_num = p->packet_length - 1 + - (encrypted ? session->remote.mac->mac_len : 0); + /* total_num is the number of bytes following the initial + (5 bytes) packet length and padding length fields */ + total_num = p->packet_length - 1 + + (encrypted ? session->remote.mac->mac_len : 0); + } /* RFC4253 section 6.1 Maximum Packet Length says: * @@ -511,13 +592,17 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) /* init write pointer to start of payload buffer */ p->wptr = p->payload; - if(blocksize > 5) { + if(!etm && blocksize > 5) { /* copy the data from index 5 to the end of the blocksize from the temporary buffer to the start of the decrypted buffer */ if(blocksize - 5 <= (int) total_num) { memcpy(p->wptr, &block[5], blocksize - 5); p->wptr += blocksize - 5; /* advance write pointer */ + if(etm) { + /* advance past unencrypted packet length */ + p->wptr += 4; + } } else { if(p->payload) @@ -531,7 +616,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) p->data_num = p->wptr - p->payload; /* we already dealt with a blocksize worth of data */ - numbytes -= blocksize; + if(!etm) + numbytes -= blocksize; } /* how much there is left to add to the current payload @@ -544,7 +630,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) numbytes = remainpack; } - if(encrypted) { + if(encrypted && !etm) { /* At the end of the incoming stream, there is a MAC, and we don't want to decrypt that since we need it "raw". We MUST however decrypt the padding data @@ -772,11 +858,12 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, struct transportpacket *p = &session->packet; int encrypted; int compressed; + int etm; ssize_t ret; int rc; const unsigned char *orgdata = data; size_t orgdata_len = data_len; - size_t crypt_offset; + size_t crypt_offset, etm_crypt_offset; /* * If the last read operation was interrupted in the middle of a key @@ -814,6 +901,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0; + etm = encrypted && session->local.mac ? session->local.mac->etm : 0; + compressed = session->local.comp && session->local.comp->compress && ((session->state & LIBSSH2_STATE_AUTHENTICATED) || @@ -875,8 +964,11 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, packet_length = data_len + 1 + 4; /* 1 is for padding_length field 4 for the packet_length field */ - /* subtract 4 bytes of the packet_length field when padding AES-GCM */ - crypt_offset = (encrypted && CRYPT_FLAG_R(session, PKTLEN_AAD)) ? 4 : 0; + /* subtract 4 bytes of the packet_length field when padding AES-GCM + or with ETM */ + crypt_offset = (etm || (encrypted && CRYPT_FLAG_R(session, PKTLEN_AAD))) + ? 4 : 0; + etm_crypt_offset = etm ? 4 : 0; /* at this point we have it all except the padding */ @@ -928,7 +1020,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, fields except the MAC field itself. This is skipped in the INTEGRATED_MAC case, where the crypto algorithm also does its own hash. */ - if(!CRYPT_FLAG_R(session, INTEGRATED_MAC)) { + if(!etm && !CRYPT_FLAG_R(session, INTEGRATED_MAC)) { session->local.mac->hash(session, p->outbuf + packet_length, session->local.seqno, p->outbuf, packet_length, NULL, 0, @@ -940,23 +1032,23 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, /* Some crypto back-ends could handle a single crypt() call for encryption, but (presumably) others cannot, so break it up into blocksize-sized chunks to satisfy them all. */ - for(i = 0; i < packet_length; + for(i = etm_crypt_offset; i < packet_length; i += session->local.crypt->blocksize) { unsigned char *ptr = &p->outbuf[i]; size_t bsize = LIBSSH2_MIN(session->local.crypt->blocksize, (int)(packet_length-i)); - /* The INTEGRATED_MAC case always has an extra call below, - so it will never be LAST_BLOCK up here. */ + /* The INTEGRATED_MAC case always has an extra call below, so it + will never be LAST_BLOCK up here. */ int firstlast = i == 0 ? FIRST_BLOCK : (!CRYPT_FLAG_L(session, INTEGRATED_MAC) && (i == packet_length - session->local.crypt->blocksize) ? LAST_BLOCK: MIDDLE_BLOCK); - /* In the AAD case, the last block would be only 4 bytes - because everything is offset by 4 since the initial - packet_length isn't encrypted. In this case, combine that - last short packet with the previous one since AES-GCM - crypt() assumes that the entire MAC is available in that - packet so it can set that to the authentication tag. */ + /* In the AAD case, the last block would be only 4 bytes because + everything is offset by 4 since the initial packet_length isn't + encrypted. In this case, combine that last short packet with the + previous one since AES-GCM crypt() assumes that the entire MAC + is available in that packet so it can set that to the + authentication tag. */ if(!CRYPT_FLAG_L(session, INTEGRATED_MAC)) if(i > packet_length - 2*bsize) { /* increase the final block size */ @@ -964,25 +1056,38 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, /* advance the loop counter by the extra amount */ i += bsize - session->local.crypt->blocksize; } + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "crypting bytes %d-%d", i, + i + session->local.crypt->blocksize - 1)); if(session->local.crypt->crypt(session, ptr, bsize, &session->local.crypt_abstract, firstlast)) return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */ } - /* Call crypt() one last time so it can be filled in with - the MAC */ + /* Call crypt() one last time so it can be filled in with the MAC */ if(CRYPT_FLAG_L(session, INTEGRATED_MAC)) { int authlen = session->local.mac->mac_len; assert((size_t)total_length <= packet_length + session->local.crypt->blocksize); - if(session->local.crypt->crypt(session, - &p->outbuf[packet_length], + if(session->local.crypt->crypt(session, &p->outbuf[packet_length], authlen, &session->local.crypt_abstract, LAST_BLOCK)) return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */ } + + if(etm) { + /* Calculate MAC hash. Put the output at index packet_length, + since that size includes the whole packet. The MAC is + calculated on the entire packet (length plain the rest + encrypted), including all fields except the MAC field + itself. */ + session->local.mac->hash(session, p->outbuf + packet_length, + session->local.seqno, p->outbuf, + packet_length, NULL, 0, + &session->local.mac_abstract); + } } session->local.seqno++; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 877a9b1b9f..520780a4c1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -117,6 +117,9 @@ foreach(test hmac-sha1-96 hmac-sha2-256 hmac-sha2-512 + hmac-sha1-etm@openssh.com + hmac-sha2-256-etm@openssh.com + hmac-sha2-512-etm@openssh.com ) add_test(NAME test_${test} COMMAND "$") set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_MAC=${test}") diff --git a/tests/Makefile.am b/tests/Makefile.am index 18ed2382d4..3781621803 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -115,4 +115,7 @@ EXTRA_DIST = \ test_read_hmac-sha1-96 \ test_read_hmac-sha2-256 \ test_read_hmac-sha2-512 \ - test_read_rijndael-cbc + test_read_rijndael-cbc \ + test_read_hmac-sha1-etm@openssh.com \ + test_read_hmac-sha2-256-etm@openssh.com \ + test_read_hmac-sha2-512-etm@openssh.com diff --git a/tests/test_auth_keyboard_info_request.c b/tests/test_auth_keyboard_info_request.c index 405a266219..83860ffc18 100644 --- a/tests/test_auth_keyboard_info_request.c +++ b/tests/test_auth_keyboard_info_request.c @@ -310,7 +310,7 @@ int main(void) for(i = 0; i < FAILED_MALLOC_TEST_CASES_LEN; i++) { int tc = i + TEST_CASES_LEN + 1; - int malloc_call_num = 5 + i; + int malloc_call_num = 3 + i; test_case(tc, failed_malloc_test_cases[i].data, failed_malloc_test_cases[i].data_len, From 7b21ef300cc0231507d44d7ebbbc0ebb34c65705 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 21 Apr 2023 03:09:04 -0700 Subject: [PATCH 312/424] tests: add AES-GCM protocol read tests (#992) Closes #992 --- tests/CMakeLists.txt | 7 ++++-- tests/Makefile.am | 2 ++ tests/session_fixture.c | 51 ++++++++++++++++++++++++++------------ tests/test_read_aes128-gcm | 2 ++ tests/test_read_aes256-gcm | 2 ++ 5 files changed, 46 insertions(+), 18 deletions(-) create mode 100755 tests/test_read_aes128-gcm create mode 100755 tests/test_read_aes256-gcm diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 520780a4c1..f2c23ff994 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -130,14 +130,17 @@ foreach(test 3des-cbc aes128-cbc aes128-ctr + aes128-gcm@openssh.com aes192-cbc aes192-ctr aes256-cbc aes256-ctr + aes256-gcm@openssh.com rijndael-cbc@lysator.liu.se ) - add_test(NAME test_${test} COMMAND "$") - set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") + string(REGEX REPLACE "@.*" "" testfn "${test}") + add_test(NAME test_${testfn} COMMAND "$") + set_tests_properties(test_${testfn} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") endforeach() add_custom_target(coverage diff --git a/tests/Makefile.am b/tests/Makefile.am index 3781621803..55f18dff74 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -105,10 +105,12 @@ EXTRA_DIST = \ test_read_3des-cbc \ test_read_aes128-cbc \ test_read_aes128-ctr \ + test_read_aes128-gcm \ test_read_aes192-cbc \ test_read_aes192-ctr \ test_read_aes256-cbc \ test_read_aes256-ctr \ + test_read_aes256-gcm \ test_read_hmac-md5 \ test_read_hmac-md5-96 \ test_read_hmac-sha1 \ diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 2ae92ec1b6..3485b644e5 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -99,6 +99,33 @@ static void setup_fixture_workdir(void) chdir(wd); } +/* List of crypto protocols for which tests are skipped */ +static char const *skip_crypt[] = { +#ifdef LIBSSH2_MBEDTLS + /* Due to a bug with mbedTLS support, these crypt methods fail. + Until that bug is fixed, don't run them there to avoid this + known issue causing red tests. + See: https://github.com/libssh2/libssh2/issues/793 + */ + "3des-cbc", + "aes128-cbc", + "aes192-cbc", + "aes256-cbc", + "aes128-gcm@openssh.com", + "aes256-gcm@openssh.com", + "rijndael-cbc@lysator.liu.se", +#endif + +#if defined(LIBSSH2_LIBGCRYPT) || defined(LIBSSH2_OS400QC3) || \ + defined(LIBSSH2_WINCNG) + /* Support for AES-GCM hasn't been added to these back-ends yet */ + "aes128-gcm@openssh.com", + "aes256-gcm@openssh.com", +#endif + + NULL +}; + LIBSSH2_SESSION *start_session_fixture(int *skipped) { int rc; @@ -109,23 +136,15 @@ LIBSSH2_SESSION *start_session_fixture(int *skipped) *skipped = 0; if(crypt) { -#ifdef LIBSSH2_MBEDTLS - /* Due to a bug with mbedTLS support, these crypt methods fail. - Until that bug is fixed, don't run them there to avoid this - known issue causing red tests. - See: https://github.com/libssh2/libssh2/issues/793 - */ - if(strcmp(crypt, "3des-cbc") == 0 || - strcmp(crypt, "aes128-cbc") == 0 || - strcmp(crypt, "aes192-cbc") == 0 || - strcmp(crypt, "aes256-cbc") == 0 || - strcmp(crypt, "rijndael-cbc@lysator.liu.se") == 0) { - fprintf(stderr, "crypt algorithm (%s) skipped " - "for this crypto backend.\n", crypt); - *skipped = 1; - return NULL; + char const * const *cr; + for(cr = skip_crypt; *cr; ++cr) { + if(strcmp(*cr, crypt) == 0) { + fprintf(stderr, "crypt algorithm (%s) skipped " + "for this crypto backend.\n", crypt); + *skipped = 1; + return NULL; + } } -#endif } setup_fixture_workdir(); diff --git a/tests/test_read_aes128-gcm b/tests/test_read_aes128-gcm new file mode 100755 index 0000000000..ec9d2e8d5f --- /dev/null +++ b/tests/test_read_aes128-gcm @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes128-gcm@openssh.com exec ./test_read diff --git a/tests/test_read_aes256-gcm b/tests/test_read_aes256-gcm new file mode 100755 index 0000000000..4ad55b7b63 --- /dev/null +++ b/tests/test_read_aes256-gcm @@ -0,0 +1,2 @@ +#!/bin/sh +FIXTURE_TEST_CRYPT=aes256-gcm@openssh.com exec ./test_read From cd5977deac862e42501ea63850aa3eecc8c74072 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Apr 2023 14:01:31 +0000 Subject: [PATCH 313/424] cmake: restore a dash char in comment [ci skip] It's a CMake comment header convention. --- cmake/CheckNonblockingSocketSupport.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index 6e02cccdfa..4af73a29a2 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -1,6 +1,6 @@ include(CheckCSourceCompiles) -# check_nonblocking_socket_support() +# - check_nonblocking_socket_support() # # Check for how to set a socket to non-blocking state. There seems to exist # four known different ways, with the one used almost everywhere being POSIX From f7e889b6278393c5b7796a5bc88fe86dd8129cf6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 20:24:42 +0000 Subject: [PATCH 314/424] build: add autotools test_read support and more Keep a single list for mac and crypt algos that we use in both CMake and autotools. Use the same test names across build tools. Use the TAP protocol to track individual tests run from a single shell script. Also: - enable the rest of our tests with autotools. - set `make check` verbose to see errors in case they happen. - silence stray 'command not found' error when running `mansyntax.sh` on Windows. GitHub Actions Windows docker tests disabled due to: ``` Command: docker build --quiet -t libssh2/openssh_server ../tests/openssh_server Error running command 'docker build --quiet -t libssh2/openssh_server ../tests/openssh_server' (exit 1): Sending build context to Docker daemon 22.02kB Step 1/42 : FROM debian:bullseye-slim bullseye-slim: Pulling from library/debian no matching manifest for windows/amd64 10.0.20348 in the manifest list entries Failed to build docker image ``` Closes #993 --- .github/workflows/ci.yml | 4 ++-- .gitignore | 3 ++- configure.ac | 9 ++++++++ tests/CMakeLists.txt | 43 +++++++++-------------------------- tests/Makefile.am | 33 +++++++++------------------ tests/mansyntax.sh | 2 +- tests/test_read_3des-cbc | 2 -- tests/test_read_aes128-cbc | 2 -- tests/test_read_aes128-ctr | 3 --- tests/test_read_aes128-gcm | 2 -- tests/test_read_aes192-cbc | 2 -- tests/test_read_aes192-ctr | 2 -- tests/test_read_aes256-cbc | 2 -- tests/test_read_aes256-ctr | 2 -- tests/test_read_aes256-gcm | 2 -- tests/test_read_algos.test | 36 +++++++++++++++++++++++++++++ tests/test_read_algos.txt | 19 ++++++++++++++++ tests/test_read_hmac-md5 | 2 -- tests/test_read_hmac-md5-96 | 2 -- tests/test_read_hmac-sha1 | 2 -- tests/test_read_hmac-sha1-96 | 2 -- tests/test_read_hmac-sha2-256 | 2 -- tests/test_read_hmac-sha2-512 | 2 -- tests/test_read_rijndael-cbc | 2 -- 24 files changed, 91 insertions(+), 91 deletions(-) delete mode 100755 tests/test_read_3des-cbc delete mode 100755 tests/test_read_aes128-cbc delete mode 100755 tests/test_read_aes128-ctr delete mode 100755 tests/test_read_aes128-gcm delete mode 100755 tests/test_read_aes192-cbc delete mode 100755 tests/test_read_aes192-ctr delete mode 100755 tests/test_read_aes256-cbc delete mode 100755 tests/test_read_aes256-ctr delete mode 100755 tests/test_read_aes256-gcm create mode 100755 tests/test_read_algos.test create mode 100644 tests/test_read_algos.txt delete mode 100755 tests/test_read_hmac-md5 delete mode 100755 tests/test_read_hmac-md5-96 delete mode 100755 tests/test_read_hmac-sha1 delete mode 100755 tests/test_read_hmac-sha1-96 delete mode 100755 tests/test_read_hmac-sha2-256 delete mode 100755 tests/test_read_hmac-sha2-512 delete mode 100755 tests/test_read_rijndael-cbc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94b4589fc3..fee66b19b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,7 @@ jobs: autoreconf -fi ./configure --enable-debug --enable-werror make -j3 - make check + make check VERBOSE=1 - name: Build with CMake timeout-minutes: 10 if: ${{ matrix.b == 'cmake' }} @@ -108,4 +108,4 @@ jobs: autoreconf -fi ./configure --enable-debug --enable-static --disable-shared --with-crypto=openssl make -j3 - make check + make check VERBOSE=1 diff --git a/.gitignore b/.gitignore index 3eda965d92..ae793d80e9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,8 @@ depcomp libtool ltmain.sh missing -ssh2_sample +tap-driver.sh +test-driver libssh2-*.tar.bz2 libssh2-*.tar.gz libssh2-*.tar.xz diff --git a/configure.ac b/configure.ac index d3685e8758..fdbf80d5ed 100644 --- a/configure.ac +++ b/configure.ac @@ -3,6 +3,7 @@ AC_INIT(libssh2, [-], libssh2-devel@lists.haxx.se) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([src]) AC_CONFIG_HEADERS([src/libssh2_config.h]) +AC_REQUIRE_AUX_FILE([tap-driver.sh]) AM_MAINTAINER_MODE m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) @@ -371,6 +372,14 @@ fi AM_CONDITIONAL([HAVE_WINDRES], [test "x$have_windows_h" = "xyes" && test "x${enable_shared}" = "xyes" && test -n "${RC}"]) +case "`uname`" in + *_NT*) host_windows=yes + ;; + *) host_windows=no + ;; +esac +AM_CONDITIONAL([HOST_WINDOWS], [test "x$host_windows" = "xyes"]) + # Configure parameters LIBSSH2_CHECK_OPTION_WERROR diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f2c23ff994..8c7c396e33 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -109,38 +109,17 @@ foreach(test ${TESTS}) endif() endforeach() -# MAC tests -foreach(test - hmac-md5 - hmac-md5-96 - hmac-sha1 - hmac-sha1-96 - hmac-sha2-256 - hmac-sha2-512 - hmac-sha1-etm@openssh.com - hmac-sha2-256-etm@openssh.com - hmac-sha2-512-etm@openssh.com -) - add_test(NAME test_${test} COMMAND "$") - set_tests_properties(test_${test} PROPERTIES ENVIRONMENT "FIXTURE_TEST_MAC=${test}") -endforeach() - -# CRYPT tests -foreach(test - 3des-cbc - aes128-cbc - aes128-ctr - aes128-gcm@openssh.com - aes192-cbc - aes192-ctr - aes256-cbc - aes256-ctr - aes256-gcm@openssh.com - rijndael-cbc@lysator.liu.se -) - string(REGEX REPLACE "@.*" "" testfn "${test}") - add_test(NAME test_${testfn} COMMAND "$") - set_tests_properties(test_${testfn} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") +# CRYPT/MAC algo tests +file(READ "test_read_algos.txt" TESTS) +string(REGEX REPLACE "\\\n" ";" TESTS ${TESTS}) +foreach(test ${TESTS}) + set(testname test_read-${test}) + add_test(NAME ${testname} COMMAND "$") + if(test MATCHES "mac-") + set_tests_properties(${testname} PROPERTIES ENVIRONMENT "FIXTURE_TEST_MAC=${test}") + else() + set_tests_properties(${testname} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") + endif() endforeach() add_custom_target(coverage diff --git a/tests/Makefile.am b/tests/Makefile.am index 55f18dff74..0eef9a2233 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,11 @@ ctests = test_simple$(EXEEXT) TESTS = $(ctests) mansyntax.sh check_PROGRAMS = $(ctests) +TEST_EXTENSIONS = .test +# 'TEST' in 'TEST_LOG_DRIVER' is the test extension in uppercase. +TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/tap-driver.sh +TESTS += test_read_algos.test + if SSHD TESTS += ssh2.sh check_PROGRAMS += test_ssh2 @@ -36,8 +41,9 @@ INTEGRATION_TESTS = \ test_read # Integration tests using Docker -# Enable this once the tests are working -#TESTS += $(INTEGRATION_TESTS) +if ! HOST_WINDOWS +TESTS += $(INTEGRATION_TESTS) +endif check_PROGRAMS += $(INTEGRATION_TESTS) librunner_la_SOURCES = \ runner.c runner.h \ @@ -97,27 +103,10 @@ EXTRA_DIST = \ openssh_server/ssh_host_ecdsa_key \ openssh_server/ssh_host_ed25519_key \ openssh_server/ssh_host_rsa_key \ + test_read_algos.test \ + test_read_algos.txt \ test_simple.c \ - sshdwrap \ test_ssh2.c \ ssh2.sh \ sshd_fixture.sh.in \ - test_read_3des-cbc \ - test_read_aes128-cbc \ - test_read_aes128-ctr \ - test_read_aes128-gcm \ - test_read_aes192-cbc \ - test_read_aes192-ctr \ - test_read_aes256-cbc \ - test_read_aes256-ctr \ - test_read_aes256-gcm \ - test_read_hmac-md5 \ - test_read_hmac-md5-96 \ - test_read_hmac-sha1 \ - test_read_hmac-sha1-96 \ - test_read_hmac-sha2-256 \ - test_read_hmac-sha2-512 \ - test_read_rijndael-cbc \ - test_read_hmac-sha1-etm@openssh.com \ - test_read_hmac-sha2-256-etm@openssh.com \ - test_read_hmac-sha2-512-etm@openssh.com + sshdwrap diff --git a/tests/mansyntax.sh b/tests/mansyntax.sh index b7ce93ac6b..3b9a73d19b 100755 --- a/tests/mansyntax.sh +++ b/tests/mansyntax.sh @@ -20,7 +20,7 @@ ec=0 # Only test if suitable man is available # if command -v grep >/dev/null 2>&1 && \ - man --help | grep -q warnings; then + man --help 2>/dev/null | grep -q warnings; then trap 'rm -f "$dstdir/man3"' EXIT diff --git a/tests/test_read_3des-cbc b/tests/test_read_3des-cbc deleted file mode 100755 index 9e8db19bce..0000000000 --- a/tests/test_read_3des-cbc +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=3des-cbc exec ./test_read diff --git a/tests/test_read_aes128-cbc b/tests/test_read_aes128-cbc deleted file mode 100755 index 30f31c3bf3..0000000000 --- a/tests/test_read_aes128-cbc +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes128-cbc exec ./test_read diff --git a/tests/test_read_aes128-ctr b/tests/test_read_aes128-ctr deleted file mode 100755 index 256ddd5681..0000000000 --- a/tests/test_read_aes128-ctr +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes128-ctr exec ./test_read - diff --git a/tests/test_read_aes128-gcm b/tests/test_read_aes128-gcm deleted file mode 100755 index ec9d2e8d5f..0000000000 --- a/tests/test_read_aes128-gcm +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes128-gcm@openssh.com exec ./test_read diff --git a/tests/test_read_aes192-cbc b/tests/test_read_aes192-cbc deleted file mode 100755 index 6daaae2090..0000000000 --- a/tests/test_read_aes192-cbc +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes192-cbc exec ./test_read diff --git a/tests/test_read_aes192-ctr b/tests/test_read_aes192-ctr deleted file mode 100755 index 726d76b3c4..0000000000 --- a/tests/test_read_aes192-ctr +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes192-ctr exec ./test_read diff --git a/tests/test_read_aes256-cbc b/tests/test_read_aes256-cbc deleted file mode 100755 index 61c6946e93..0000000000 --- a/tests/test_read_aes256-cbc +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes256-cbc exec ./test_read diff --git a/tests/test_read_aes256-ctr b/tests/test_read_aes256-ctr deleted file mode 100755 index 1d0e5cd0dd..0000000000 --- a/tests/test_read_aes256-ctr +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes256-ctr exec ./test_read diff --git a/tests/test_read_aes256-gcm b/tests/test_read_aes256-gcm deleted file mode 100755 index 4ad55b7b63..0000000000 --- a/tests/test_read_aes256-gcm +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=aes256-gcm@openssh.com exec ./test_read diff --git a/tests/test_read_algos.test b/tests/test_read_algos.test new file mode 100755 index 0000000000..1b0556adc1 --- /dev/null +++ b/tests/test_read_algos.test @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# https://testanything.org/tap-specification.html + +if [[ "$(uname)" = *'_NT'* ]]; then + echo "1..0 # skip test_read tests due to docker issues" + exit 0 +fi + +testbin='./test_read' + +d="$(dirname "$0")" +algos="$(cat "${d}/test_read_algos.txt")" + +count=1 +total="$(echo "${algos}" | wc -l | tr -d ' ')" + +echo "${count}..${total}" + +while read -r test; do + if [[ "${test}" = *'mac-'* ]]; then + if FIXTURE_TEST_MAC="${test}" "${testbin}"; then + res='ok' + else + res='not ok' + fi + else + if FIXTURE_TEST_CRYPT="${test}" "${testbin}"; then + res='ok' + else + res='not ok' + fi + fi + echo "${res} ${count} - test_read-${test}" + ((count++)) +done <<< "${algos}" diff --git a/tests/test_read_algos.txt b/tests/test_read_algos.txt new file mode 100644 index 0000000000..35ce3cdd27 --- /dev/null +++ b/tests/test_read_algos.txt @@ -0,0 +1,19 @@ +3des-cbc +aes128-cbc +aes128-ctr +aes128-gcm@openssh.com +aes192-cbc +aes192-ctr +aes256-cbc +aes256-ctr +aes256-gcm@openssh.com +rijndael-cbc@lysator.liu.se +hmac-md5 +hmac-md5-96 +hmac-sha1 +hmac-sha1-96 +hmac-sha1-etm@openssh.com +hmac-sha2-256 +hmac-sha2-256-etm@openssh.com +hmac-sha2-512 +hmac-sha2-512-etm@openssh.com diff --git a/tests/test_read_hmac-md5 b/tests/test_read_hmac-md5 deleted file mode 100755 index c0ab4fffff..0000000000 --- a/tests/test_read_hmac-md5 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_MAC=hmac-md5 exec ./test_read diff --git a/tests/test_read_hmac-md5-96 b/tests/test_read_hmac-md5-96 deleted file mode 100755 index deceff14c8..0000000000 --- a/tests/test_read_hmac-md5-96 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_MAC=hmac-md5-96 exec ./test_read diff --git a/tests/test_read_hmac-sha1 b/tests/test_read_hmac-sha1 deleted file mode 100755 index 6dc31374c9..0000000000 --- a/tests/test_read_hmac-sha1 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_MAC=hmac-sha1 exec ./test_read diff --git a/tests/test_read_hmac-sha1-96 b/tests/test_read_hmac-sha1-96 deleted file mode 100755 index 40173ad004..0000000000 --- a/tests/test_read_hmac-sha1-96 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_MAC=hmac-sha1-96 exec ./test_read diff --git a/tests/test_read_hmac-sha2-256 b/tests/test_read_hmac-sha2-256 deleted file mode 100755 index 15b2432309..0000000000 --- a/tests/test_read_hmac-sha2-256 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_MAC=hmac-sha2-256 exec ./test_read diff --git a/tests/test_read_hmac-sha2-512 b/tests/test_read_hmac-sha2-512 deleted file mode 100755 index 77e5cee643..0000000000 --- a/tests/test_read_hmac-sha2-512 +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_MAC=hmac-sha2-512 exec ./test_read diff --git a/tests/test_read_rijndael-cbc b/tests/test_read_rijndael-cbc deleted file mode 100755 index 85fb980ef4..0000000000 --- a/tests/test_read_rijndael-cbc +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -FIXTURE_TEST_CRYPT=rijndael-cbc@lysator.liu.se exec ./test_read From fba0b52b6a8f719b5260530c3f220a653a19f33f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Apr 2023 13:34:26 +0000 Subject: [PATCH 315/424] ci: add Windows Server 2016 into the test mix We had Windows Server 2012 R2 (8.1) and Windows Server 2019 (10) before this patch. After, we also have Windows Server 2016 (10). The WinCNG flakey tests should have a better chance when running on the newer OS. This update does not change the compiler mix. Also change the test fixture to not use the `--quiet` option with the `docker pull` commant. This option requires docker v19.03, and AppVeyor's Visual Studio 2017 image doesn't support it. Log output did not change without `--quiet`, so it seems safe to delete it. In case we'd need it, another solution is to retry without `--quiet` if the command fails. docker's exit status is 125 in that case. Ref: https://github.com/libssh2/libssh2/issues/804#issuecomment-1515232799 Ref: https://www.appveyor.com/docs/windows-images-software/ Closes #994 --- appveyor.yml | 22 +++++++++++----------- tests/openssh_fixture.c | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 13a75d8238..6ea97a53b1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,21 +27,21 @@ environment: CONFIGURATION: "Release" matrix: - - job_name: "VS2022, OpenSSL3, x64" + - job_name: "VS2022, OpenSSL3, x64, Server 2019" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2015, OpenSSL, x86" - APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + - job_name: "VS2015, OpenSSL, x86, Server 2016" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2015, OpenSSL, x64, Logging" + - job_name: "VS2015, OpenSSL, x64, Server 2012 R2, Logging" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x64" @@ -49,21 +49,21 @@ environment: CRYPTO_BACKEND: "OpenSSL" ENABLE_DEBUG_LOGGING: "ON" - - job_name: "VS2013, OpenSSL, x64" + - job_name: "VS2013, OpenSSL, x64, Server 2012 R2" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, x86" + - job_name: "VS2013, OpenSSL, x86, Server 2012 R2" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, x64, Static-only, Build-only" + - job_name: "VS2013, OpenSSL, x64, Build-only, Static-only" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" PLATFORM: "x64" @@ -87,7 +87,7 @@ environment: CRYPTO_BACKEND: "WinCNG" SKIP_CTEST: "yes" - - job_name: "VS2022, WinCNG, x64, Logging" + - job_name: "VS2022, WinCNG, x64, Server 2019, Logging" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" PLATFORM: "x64" @@ -102,14 +102,14 @@ environment: BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - - job_name: "VS2015, WinCNG, x86" - APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" + - job_name: "VS2015, WinCNG, x86, Server 2016" + APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "WinCNG" - - job_name: "VS2015, WinCNG, x64" + - job_name: "VS2015, WinCNG, x64, Server 2012 R2" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x64" diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 86b5d23d81..c05f501fbc 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -160,7 +160,7 @@ static int build_openssh_server_docker_image(void) char buildcmd[1024]; const char *container_image_name = openssh_server_image(); if(container_image_name) { - int ret = run_command(NULL, "docker pull --quiet %s", + int ret = run_command(NULL, "docker pull %s", container_image_name); if(ret == 0) { ret = run_command(NULL, "docker tag %s libssh2/openssh_server", From bc4e619e76071393e466c29220fc4ef5764c2820 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Sat, 22 Apr 2023 01:54:20 -0700 Subject: [PATCH 316/424] Agent forwarding implementation (#752) This PR contains a series of patches that date back many years and I believe were discussed on the mailing list, but never merged. We have been using these in our local copy of libssh2 without issue since 2015, if not earlier. I believe this is the full set of changes, as we tried to use comments to mark where our copy of libssh2 differs from the canonical version. This also contains changes I made earlier this year, but which were not discussed on the mailing list, to support certificates and FIDO2 keys with agent forwarding. Note that this is not a complete implementation of agent forwarding, as that is outside the scope of libssh2. Clients still need to provide their own implementation that parses ssh-agent methods after calling libssh2_channel_read() and calls the appropriate callback messages in libssh2. See the man page changes in this PR for more details. Integration-patches-by: Viktor Szakats * prefer size_t * prefer unsigned int over u_int in public function * add const * docs, indent, checksrc, debug call, compiler warning fixes --- docs/Makefile.am | 1 + docs/libssh2_agent_sign.3 | 52 +++++++++ docs/libssh2_agent_userauth.3 | 1 + docs/libssh2_session_callback_set.3 | 59 ++++++++++ docs/libssh2_userauth_publickey_sk.3 | 9 ++ include/libssh2.h | 52 +++++++-- src/agent.c | 60 +++++++++- src/hostkey.c | 13 +++ src/libssh2_priv.h | 44 ++++++- src/packet.c | 164 +++++++++++++++++++++++++++ src/session.c | 15 +++ src/userauth.c | 107 ++++++++++++++--- 12 files changed, 551 insertions(+), 26 deletions(-) create mode 100644 docs/libssh2_agent_sign.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index bb2e4434b7..6eb335374a 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -10,6 +10,7 @@ dist_man_MANS = \ libssh2_agent_init.3 \ libssh2_agent_list_identities.3 \ libssh2_agent_set_identity_path.3 \ + libssh2_agent_sign.3 \ libssh2_agent_userauth.3 \ libssh2_banner_set.3 \ libssh2_base64_decode.3 \ diff --git a/docs/libssh2_agent_sign.3 b/docs/libssh2_agent_sign.3 new file mode 100644 index 0000000000..670e5940ea --- /dev/null +++ b/docs/libssh2_agent_sign.3 @@ -0,0 +1,52 @@ +.TH libssh2_agent_sign 3 "1 Oct 2022" "libssh2 1.11.0" "libssh2 manual" +.SH NAME +libssh2_agent_sign - sign data, with the help of ssh-agent +.SH SYNOPSIS +.nf +#include + +int +libssh2_agent_sign(LIBSSH2_AGENT *agent, + struct libssh2_agent_publickey *identity, + unsigned char **sig, + size_t *s_len, + const unsigned char *data, + size_t d_len, + const char *method, + unsigned int method_len); +.fi +.SH DESCRIPTION +\fIagent\fP - ssh-agent handle as returned by +.BR libssh2_agent_init(3) + +\fIidentity\fP - Public key to authenticate with, as returned by +.BR libssh2_agent_get_identity(3) + +\fIsig\fP - A pointer to a buffer in which to place the signature. The caller +is responsible for freeing the signature with LIBSSH2_FREE. + +\fIs_len\fP - A pointer to the length of the sig parameter. + +\fIdata\fP - The data to sign. + +\fId_len\fP - The length of the data parameter. + +\fImethod\fP - A buffer indicating the signing method. This should match the +string at the start of identity->blob. + +\fImethod_len\fP - The length of the method parameter. + +Sign data using an ssh-agent. This function can be used in a callback +registered with libssh2_session_callback_set(3) using +LIBSSH2_CALLBACK_AUTHAGENT_SIGN to sign an authentication challenge from a +server. However, the client is responsible for implementing the code that calls +this callback in response to a SSH2_AGENTC_SIGN_REQUEST message. +.SH RETURN VALUE +Returns 0 if succeeded, or a negative value for error. +.SH AVAILABILITY +Added in libssh2 1.11.0 +.SH SEE ALSO +.BR libssh2_agent_init(3) +.BR libssh2_agent_get_identity(3) +.BR libssh2_agent_userauth(3) +.BR libssh2_session_callback_set(3) diff --git a/docs/libssh2_agent_userauth.3 b/docs/libssh2_agent_userauth.3 index 8513e6513f..0eeea004e6 100644 --- a/docs/libssh2_agent_userauth.3 +++ b/docs/libssh2_agent_userauth.3 @@ -30,3 +30,4 @@ Added in libssh2 1.2 .SH SEE ALSO .BR libssh2_agent_init(3) .BR libssh2_agent_get_identity(3) +.BR libssh2_agent_sign(3) diff --git a/docs/libssh2_session_callback_set.3 b/docs/libssh2_session_callback_set.3 index 9a94c00f50..861b320ed9 100644 --- a/docs/libssh2_session_callback_set.3 +++ b/docs/libssh2_session_callback_set.3 @@ -71,8 +71,67 @@ to the abstract pointer set in the \fIlibssh2_session_init_ex(3)\fP call. The callback returns the number of bytes read, or -1 for error. The special return code \fB-EAGAIN\fP can be returned to signal that the read was aborted to prevent getting blocked and it needs to be called again. +.IP LIBSSH2_CALLBACK_AUTHAGENT +Called during authentication process to allow the client to connect to the +ssh-agent and perform any setup, such as configuring the agent or adding keys. + +The prototype of the callback: + +.nf +void authagent(LIBSSH2_SESSION* session, LIBSSH2_CHANNEL *channel, + void **abstract); +.fi +.IP LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES +Not called by libssh2. The client is responsible for calling this method when +a SSH2_AGENTC_REQUEST_IDENTITIES message has been received. + +The prototype of the callback: + +.nf +void identities(LIBSSH2_SESSION* session, void *buffer, + const char *agent_path, + void **abstract) +.fi + +\fBbuffer\fP must be filled in by the callback. Different clients may implement +this differently. For example, one client may pass in an unsigned char ** for +this parameter, while another may pass in a pointer to a struct. + +Regardless of the type of buffer used, the client will need to send back a list +of identities in the following format. + +uint32 buffer length +uint32 number of entries +entries + +Where each entry in the entries list is of the format: + +string data +cstring comment + +\fBagent_path\fP The path to a running ssh-agent on the client machine, from +which identities can be listed. +.IP LIBSSH2_CALLBACK_AUTHAGENT_SIGN +Not called by libssh2. The client is responsible for calling this method when +a SSH2_AGENTC_SIGN_REQUEST message has been received. + +The prototype of the callback: + +.nf +void sign(LIBSSH2_SESSION* session, + unsigned char *blob, unsigned int blen, + const unsigned char *data, unsigned int dlen, + unsigned char **sig, unsigned int *sig_len, + const char *agent_path, + void **abstract); +.fi + +When interfacing with an ssh-agent installed on the client system, this method +can call libssh2_agent_sign(3) to perform signing. + .SH RETURN VALUE Pointer to previous callback handler. Returns NULL if no prior callback handler was set or the callback type was unknown. .SH SEE ALSO .BR libssh2_session_init_ex(3) +.BR libssh2_agent_sign(3) diff --git a/docs/libssh2_userauth_publickey_sk.3 b/docs/libssh2_userauth_publickey_sk.3 index 663acd5eb8..38df52f274 100644 --- a/docs/libssh2_userauth_publickey_sk.3 +++ b/docs/libssh2_userauth_publickey_sk.3 @@ -9,6 +9,8 @@ int libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, const char *username, size_t username_len, + const unsigned char *publickeydata, + size_t publickeydata_len, const char *privatekeydata, size_t privatekeydata_len, const char *passphrase, @@ -43,6 +45,13 @@ int name(LIBSSH2_SESSION *session, LIBSSH2_SK_SIG_INFO *sig_info, \fIusername_len\fP - Length of username parameter. +\fIpublickeydata\fP - Buffer containing the contents of a public key file. If +NULL, the public key will be extracted from the privatekeydata. When using +certificate authentication, this buffer should contain the public certificate +data. + +\fIpublickeydata_len\fP - Length of public key data. + \fIprivatekeydata\fP - Buffer containing the contents of a private key file. \fIprivatekeydata_len\fP - Length of private key data. diff --git a/include/libssh2.h b/include/libssh2.h index 68bab7c8aa..2869831754 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -333,6 +333,22 @@ typedef struct _LIBSSH2_SK_SIG_INFO { void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \ const char *shost, int sport, void **abstract) +#define LIBSSH2_AUTHAGENT_FUNC(name) \ + void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \ + void **abstract) + +#define LIBSSH2_ADD_IDENTITIES_FUNC(name) \ + void name(LIBSSH2_SESSION *session, void *buffer, \ + const char *agent_path, void **abstract) + +#define LIBSSH2_AUTHAGENT_SIGN_FUNC(name) \ + int name(LIBSSH2_SESSION* session, \ + unsigned char *blob, unsigned int blen, \ + const unsigned char *data, unsigned int dlen, \ + unsigned char **signature, unsigned int *sigLen, \ + const char *agentPath, \ + void **abstract) + #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \ void name(LIBSSH2_SESSION *session, void **session_abstract, \ LIBSSH2_CHANNEL *channel, void **channel_abstract) @@ -348,13 +364,16 @@ typedef struct _LIBSSH2_SK_SIG_INFO { int flags, void **abstract) /* libssh2_session_callback_set() constants */ -#define LIBSSH2_CALLBACK_IGNORE 0 -#define LIBSSH2_CALLBACK_DEBUG 1 -#define LIBSSH2_CALLBACK_DISCONNECT 2 -#define LIBSSH2_CALLBACK_MACERROR 3 -#define LIBSSH2_CALLBACK_X11 4 -#define LIBSSH2_CALLBACK_SEND 5 -#define LIBSSH2_CALLBACK_RECV 6 +#define LIBSSH2_CALLBACK_IGNORE 0 +#define LIBSSH2_CALLBACK_DEBUG 1 +#define LIBSSH2_CALLBACK_DISCONNECT 2 +#define LIBSSH2_CALLBACK_MACERROR 3 +#define LIBSSH2_CALLBACK_X11 4 +#define LIBSSH2_CALLBACK_SEND 5 +#define LIBSSH2_CALLBACK_RECV 6 +#define LIBSSH2_CALLBACK_AUTHAGENT 7 +#define LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES 8 +#define LIBSSH2_CALLBACK_AUTHAGENT_SIGN 9 /* libssh2_session_method_pref() constants */ #define LIBSSH2_METHOD_KEX 0 @@ -747,6 +766,8 @@ LIBSSH2_API int libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, const char *username, size_t username_len, + const unsigned char *pubkeydata, + size_t pubkeydata_len, const char *privatekeydata, size_t privatekeydata_len, const char *passphrase, @@ -1331,6 +1352,23 @@ libssh2_agent_userauth(LIBSSH2_AGENT *agent, const char *username, struct libssh2_agent_publickey *identity); +/* + * libssh2_agent_sign() + * + * Sign a payload using a system-installed ssh-agent. + * + * Returns 0 if succeeded, or a negative value for error. + */ +LIBSSH2_API int +libssh2_agent_sign(LIBSSH2_AGENT *agent, + struct libssh2_agent_publickey *identity, + unsigned char **sig, + size_t *s_len, + const unsigned char *data, + size_t d_len, + const char *method, + unsigned int method_len); + /* * libssh2_agent_disconnect() * diff --git a/src/agent.c b/src/agent.c index de22112f85..9b38d91079 100644 --- a/src/agent.c +++ b/src/agent.c @@ -383,6 +383,7 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, int rc; unsigned char *method_name = NULL; uint32_t sign_flags = 0; + ssize_t plain_len; /* Create a request to sign the data */ if(transctx->state == agent_NB_state_init) { @@ -478,9 +479,13 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, memcpy(method_name, s, method_len); s += method_len; + plain_len = plain_method((char *)session->userauth_pblc_method, + session->userauth_pblc_method_len); + /* check to see if we match requested */ - if((size_t)method_len != session->userauth_pblc_method_len || - memcmp(method_name, session->userauth_pblc_method, method_len)) { + if(((size_t)method_len != session->userauth_pblc_method_len && + method_len != plain_len) || + memcmp(method_name, session->userauth_pblc_method, method_len)) { _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Agent sign method %.*s", @@ -829,6 +834,57 @@ libssh2_agent_userauth(LIBSSH2_AGENT *agent, return rc; } +/* + * libssh2_agent_sign + * + * Sign a payload using a system-installed ssh-agent. + * + * Returns 0 if succeeded, or a negative value for error. + */ +LIBSSH2_API int +libssh2_agent_sign(LIBSSH2_AGENT *agent, + struct libssh2_agent_publickey *identity, + unsigned char **sig, + size_t *s_len, + const unsigned char *data, + size_t d_len, + const char *method, + unsigned int method_len) +{ + void *abstract = agent; + int rc; + uint32_t methodLen; + + if(agent->session->userauth_pblc_state == libssh2_NB_state_idle) { + memset(&agent->transctx, 0, sizeof(agent->transctx)); + agent->identity = identity->node; + } + + if(identity->blob_len < sizeof(uint32_t)) { + return LIBSSH2_ERROR_BUFFER_TOO_SMALL; + } + + methodLen = _libssh2_ntohu32(identity->blob); + + if(identity->blob_len < sizeof(uint32_t) + methodLen) { + return LIBSSH2_ERROR_BUFFER_TOO_SMALL; + } + + agent->session->userauth_pblc_method_len = method_len; + agent->session->userauth_pblc_method = LIBSSH2_ALLOC(agent->session, + method_len); + + memcpy(agent->session->userauth_pblc_method, method, methodLen); + + rc = agent_sign(agent->session, sig, s_len, data, d_len, &abstract); + + LIBSSH2_FREE(agent->session, agent->session->userauth_pblc_method); + agent->session->userauth_pblc_method = NULL; + agent->session->userauth_pblc_method_len = 0; + + return rc; +} + /* * libssh2_agent_disconnect * diff --git a/src/hostkey.c b/src/hostkey.c index 1586ecf828..f38236768c 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -1257,6 +1257,18 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_ed25519 = { hostkey_method_ssh_ed25519_dtor, }; +static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_ed25519_cert = { + "ssh-ed25519-cert-v01@openssh.com", + SHA256_DIGEST_LENGTH, + hostkey_method_ssh_ed25519_init, + hostkey_method_ssh_ed25519_initPEM, + hostkey_method_ssh_ed25519_initPEMFromMemory, + hostkey_method_ssh_ed25519_sig_verify, + hostkey_method_ssh_ed25519_signv, + NULL, /* encrypt */ + hostkey_method_ssh_ed25519_dtor, +}; + #endif /* LIBSSH2_ED25519 */ @@ -1271,6 +1283,7 @@ static const LIBSSH2_HOSTKEY_METHOD *hostkey_methods[] = { #endif #if LIBSSH2_ED25519 &hostkey_method_ssh_ed25519, + &hostkey_method_ssh_ed25519_cert, #endif #if LIBSSH2_RSA #if LIBSSH2_RSA_SHA2 diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index fe7a6af53c..82a5778bd6 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -199,6 +199,21 @@ struct iovec { channel->session->x11(((channel)->session), (channel), \ (shost), (sport), (&(channel)->session->abstract)) +#define LIBSSH2_AUTHAGENT(channel) \ + channel->session->authagent(((channel)->session), (channel), \ + (&(channel)->session->abstract)) + +#define LIBSSH2_ADD_IDENTITIES(session, buffer, agentPath) \ + session->addLocalIdentities((session), (buffer), \ + (agentPath), (&(session->abstract))) + +#define LIBSSH2_AUTHAGENT_SIGN(session, blob, blen, \ + data, dlen, sig, sigLen, \ + agentPath) \ + session->agentSignCallback((session), (blob), (blen), \ + (data), (dlen), (sig), (sigLen), \ + (agentPath), (&(session->abstract))) + #define LIBSSH2_CHANNEL_CLOSE(session, channel) \ channel->close_cb((session), &(session)->abstract, \ (channel), &(channel)->abstract) @@ -238,7 +253,8 @@ typedef enum libssh2_NB_state_jump3, libssh2_NB_state_jump4, libssh2_NB_state_jump5, - libssh2_NB_state_end + libssh2_NB_state_end, + libssh2_NB_state_jumpauthagent } libssh2_nonblocking_states; typedef struct packet_require_state_t @@ -344,6 +360,24 @@ typedef struct packet_x11_open_state_t LIBSSH2_CHANNEL *channel; } packet_x11_open_state_t; +#define AuthAgentUnavail "Auth Agent unavailable" + +typedef struct packet_authagent_state_t +{ + libssh2_nonblocking_states state; + unsigned char packet[17 + (sizeof(AuthAgentUnavail) - 1)]; + uint32_t sender_channel; + uint32_t initial_window_size; + uint32_t packet_size; + LIBSSH2_CHANNEL *channel; +} packet_authagent_state_t; + +typedef enum +{ + libssh2_requires_size_decryption = (1 << 0), + libssh2_requires_size_field_in_packet = (1 << 1) +} libssh2_crypt_flags; + struct _LIBSSH2_PACKET { struct list_node node; /* linked list header */ @@ -518,7 +552,7 @@ typedef struct _libssh2_endpoint_data char *lang_prefs; } libssh2_endpoint_data; -#define PACKETBUFSIZE (1024*16) +#define PACKETBUFSIZE MAX_SSH_PACKET_LEN struct transportpacket { @@ -606,6 +640,9 @@ struct _LIBSSH2_SESSION LIBSSH2_DISCONNECT_FUNC((*ssh_msg_disconnect)); LIBSSH2_MACERROR_FUNC((*macerror)); LIBSSH2_X11_OPEN_FUNC((*x11)); + LIBSSH2_AUTHAGENT_FUNC((*authagent)); + LIBSSH2_ADD_IDENTITIES_FUNC((*addLocalIdentities)); + LIBSSH2_AUTHAGENT_SIGN_FUNC((*agentSignCallback)); LIBSSH2_SEND_FUNC((*send)); LIBSSH2_RECV_FUNC((*recv)); @@ -820,6 +857,7 @@ struct _LIBSSH2_SESSION states */ packet_queue_listener_state_t packAdd_Qlstn_state; packet_x11_open_state_t packAdd_x11open_state; + packet_authagent_state_t packAdd_authagent_state; /* State variables used in fullpacket() */ libssh2_nonblocking_states fullpacket_state; @@ -1151,6 +1189,8 @@ int _libssh2_pem_decode_integer(unsigned char **data, size_t *datalen, /* global.c */ void _libssh2_init_if_needed(void); +/* Utility function for certificate auth */ +size_t plain_method(char *method, size_t method_len); #define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0])) diff --git a/src/packet.c b/src/packet.c index 2be61d3b1c..33efad8f44 100644 --- a/src/packet.c +++ b/src/packet.c @@ -460,6 +460,154 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, return 0; } +/* + * packet_authagent_open + * + * Open a connection to authentication agent + */ +static inline int +packet_authagent_open(LIBSSH2_SESSION * session, + unsigned char *data, size_t datalen, + packet_authagent_state_t *authagent_state) +{ + int failure_code = SSH_OPEN_CONNECT_FAILED; + /* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */ + size_t packet_len = 17 + (sizeof(X11FwdUnAvil) - 1); + unsigned char *p; + LIBSSH2_CHANNEL *channel = authagent_state->channel; + int rc; + + (void)datalen; + + if(authagent_state->state == libssh2_NB_state_idle) { + unsigned char *s = data + (sizeof("auth-agent@openssh.org") - 1) + 5; + authagent_state->sender_channel = _libssh2_ntohu32(s); + s += 4; + authagent_state->initial_window_size = _libssh2_ntohu32(s); + s += 4; + authagent_state->packet_size = _libssh2_ntohu32(s); + + _libssh2_debug((session, LIBSSH2_TRACE_CONN, + "Auth Agent Connection Received on channel %lu", + authagent_state->sender_channel)); + + authagent_state->state = libssh2_NB_state_allocated; + } + + if(session->authagent) { + if(authagent_state->state == libssh2_NB_state_allocated) { + channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); + authagent_state->channel = channel; + + if(!channel) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "allocate a channel for new connection"); + failure_code = SSH_OPEN_RESOURCE_SHORTAGE; + goto authagent_exit; + } + memset(channel, 0, sizeof(LIBSSH2_CHANNEL)); + + channel->session = session; + channel->channel_type_len = sizeof("auth agent") - 1; + channel->channel_type = LIBSSH2_ALLOC(session, + channel->channel_type_len + + 1); + if(!channel->channel_type) { + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "allocate a channel for new connection"); + LIBSSH2_FREE(session, channel); + failure_code = SSH_OPEN_RESOURCE_SHORTAGE; + goto authagent_exit; + } + memcpy(channel->channel_type, "auth agent", + channel->channel_type_len + 1); + + channel->remote.id = authagent_state->sender_channel; + channel->remote.window_size_initial = + LIBSSH2_CHANNEL_WINDOW_DEFAULT; + channel->remote.window_size = LIBSSH2_CHANNEL_WINDOW_DEFAULT; + channel->remote.packet_size = LIBSSH2_CHANNEL_PACKET_DEFAULT; + + channel->local.id = _libssh2_channel_nextid(session); + channel->local.window_size_initial = + authagent_state->initial_window_size; + channel->local.window_size = authagent_state->initial_window_size; + channel->local.packet_size = authagent_state->packet_size; + + _libssh2_debug((session, LIBSSH2_TRACE_CONN, + "Auth Agent Connection established: channel " + "%lu/%lu win %lu/%lu packet %lu/%lu", + channel->local.id, channel->remote.id, + channel->local.window_size, + channel->remote.window_size, + channel->local.packet_size, + channel->remote.packet_size)); + + p = authagent_state->packet; + *(p++) = SSH_MSG_CHANNEL_OPEN_CONFIRMATION; + _libssh2_store_u32(&p, channel->remote.id); + _libssh2_store_u32(&p, channel->local.id); + _libssh2_store_u32(&p, channel->remote.window_size_initial); + _libssh2_store_u32(&p, channel->remote.packet_size); + + authagent_state->state = libssh2_NB_state_created; + } + + if(authagent_state->state == libssh2_NB_state_created) { + rc = _libssh2_transport_send(session, authagent_state->packet, 17, + NULL, 0); + if(rc == LIBSSH2_ERROR_EAGAIN) { + return rc; + } + else if(rc) { + authagent_state->state = libssh2_NB_state_idle; + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send channel open " + "confirmation"); + } + + /* Link the channel into the session */ + _libssh2_list_add(&session->channels, &channel->node); + + /* mess with stuff so we don't keep reading the same packet + over and over */ + session->packet.total_num = 0; + session->fullpacket_state = libssh2_NB_state_idle; + + /* Pass control to the callback, they may turn right around and + and free the channel, or actually use it */ + + LIBSSH2_AUTHAGENT(channel); + + authagent_state->state = libssh2_NB_state_idle; + return 0; + } + } + else + failure_code = SSH_OPEN_RESOURCE_SHORTAGE; + + /* fall-through */ +authagent_exit: + p = authagent_state->packet; + *(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE; + _libssh2_store_u32(&p, authagent_state->sender_channel); + _libssh2_store_u32(&p, failure_code); + _libssh2_store_str(&p, AuthAgentUnavail, sizeof(AuthAgentUnavail) - 1); + _libssh2_htonu32(p, 0); + + rc = _libssh2_transport_send(session, authagent_state->packet, packet_len, + NULL, 0); + if(rc == LIBSSH2_ERROR_EAGAIN) { + return rc; + } + else if(rc) { + authagent_state->state = libssh2_NB_state_idle; + return _libssh2_error(session, rc, "Unable to send open failure"); + } + authagent_state->state = libssh2_NB_state_idle; + return 0; +} + /* * _libssh2_packet_add * @@ -513,6 +661,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, goto libssh2_packet_add_jump_point4; case libssh2_NB_state_jump5: goto libssh2_packet_add_jump_point5; + case libssh2_NB_state_jumpauthagent: + goto libssh2_packet_add_jump_authagent; default: /* nothing to do */ break; } @@ -1051,6 +1201,20 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, rc = packet_x11_open(session, data, datalen, &session->packAdd_x11open_state); } + else if((datalen >= (sizeof("auth-agent@openssh.com") + 4)) && + ((sizeof("auth-agent@openssh.com") - 1) == + _libssh2_ntohu32(data + 1)) && + (memcmp(data + 5, "auth-agent@openssh.com", + sizeof("auth-agent@openssh.com") - 1) == 0)) { + + /* init the state struct */ + memset(&session->packAdd_authagent_state, 0, + sizeof(session->packAdd_authagent_state)); + + libssh2_packet_add_jump_authagent: + rc = packet_authagent_open(session, data, datalen, + &session->packAdd_authagent_state); + } if(rc == LIBSSH2_ERROR_EAGAIN) return rc; diff --git a/src/session.c b/src/session.c index b1f31e9088..c9317dd4d8 100644 --- a/src/session.c +++ b/src/session.c @@ -536,6 +536,21 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session, oldcb = session->recv; session->recv = callback; return oldcb; + + case LIBSSH2_CALLBACK_AUTHAGENT: + oldcb = session->authagent; + session->authagent = callback; + return oldcb; + + case LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES: + oldcb = session->addLocalIdentities; + session->addLocalIdentities = callback; + return oldcb; + + case LIBSSH2_CALLBACK_AUTHAGENT_SIGN: + oldcb = session->agentSignCallback; + session->agentSignCallback = callback; + return oldcb; } _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Setting Callback %d", cbtype)); diff --git a/src/userauth.c b/src/userauth.c index ed89b9eaff..a1c62f69b0 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1249,7 +1249,7 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, return rc; } -static size_t plain_method_len(const char *method, size_t method_len) +size_t plain_method(char *method, size_t method_len) { if(!strncmp("ssh-rsa-cert-v01@openssh.com", method, @@ -1268,6 +1268,29 @@ static size_t plain_method_len(const char *method, size_t method_len) method_len)) { return 19; } + + if(!strncmp("ssh-ed25519-cert-v01@openssh.com", + method, + method_len)) { + return 11; + } + + if(!strncmp("sk-ecdsa-sha2-nistp256-cert-v01@openssh.com", + method, + method_len)) { + const char *new_method = "sk-ecdsa-sha2-nistp256@openssh.com"; + memcpy(method, new_method, strlen(new_method)); + return strlen(new_method); + } + + if(!strncmp("sk-ssh-ed25519-cert-v01@openssh.com", + method, + method_len)) { + const char *new_method = "sk-ssh-ed25519@openssh.com"; + memcpy(method, new_method, strlen(new_method)); + return strlen(new_method); + } + return method_len; } @@ -1701,8 +1724,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, session->userauth_pblc_b = NULL; session->userauth_pblc_method_len = - plain_method_len((const char *)session->userauth_pblc_method, - session->userauth_pblc_method_len); + plain_method((char *)session->userauth_pblc_method, + session->userauth_pblc_method_len); if(strncmp((const char *)session->userauth_pblc_method, "sk-ecdsa-sha2-nistp256@openssh.com", @@ -2291,6 +2314,8 @@ LIBSSH2_API int libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, const char *username, size_t username_len, + const unsigned char *publickeydata, + size_t publickeydata_len, const char *privatekeydata, size_t privatekeydata_len, const char *passphrase, @@ -2298,11 +2323,19 @@ libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, ((*sign_callback)), void **abstract) { + int rc = LIBSSH2_ERROR_NONE; + + unsigned char *tmp_method = NULL; + size_t tmp_method_len = 0; + + unsigned char *tmp_publickeydata = NULL; + size_t tmp_publickeydata_len = 0; + unsigned char *pubkeydata = NULL; size_t pubkeydata_len = 0; + LIBSSH2_PRIVKEY_SK sk_info = { 0 }; void *sign_abstract = &sk_info; - int rc; sk_info.sign_callback = sign_callback; sk_info.orig_abstract = abstract; @@ -2310,37 +2343,81 @@ libssh2_userauth_publickey_sk(LIBSSH2_SESSION *session, if(privatekeydata_len && privatekeydata) { if(_libssh2_sk_pub_keyfilememory(session, - &session->userauth_pblc_method, - &session->userauth_pblc_method_len, - &pubkeydata, &pubkeydata_len, + &tmp_method, + &tmp_method_len, + &tmp_publickeydata, + &tmp_publickeydata_len, &(sk_info.algorithm), &(sk_info.flags), &(sk_info.application), &(sk_info.key_handle), &(sk_info.handle_len), privatekeydata, privatekeydata_len, - passphrase)) + passphrase)) { return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public key " "from private key."); + } + else if(publickeydata_len == 0 || !publickeydata) { + session->userauth_pblc_method = tmp_method; + session->userauth_pblc_method_len = tmp_method_len; + + pubkeydata_len = tmp_publickeydata_len; + pubkeydata = tmp_publickeydata; + } + else { + const char *ecdsa = "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com"; + const char *ed25519 = "sk-ssh-ed25519-cert-v01@openssh.com"; + + if(tmp_method) { + LIBSSH2_FREE(session, tmp_method); + } + + if(!strncmp((char *)publickeydata, ecdsa, strlen(ecdsa))) { + session->userauth_pblc_method_len = strlen(ecdsa); + session->userauth_pblc_method = + LIBSSH2_ALLOC(session, session->userauth_pblc_method_len); + + memcpy(session->userauth_pblc_method, ecdsa, + session->userauth_pblc_method_len); + } + else if(!strncmp((char *)publickeydata, ed25519, + strlen(ed25519))) { + session->userauth_pblc_method_len = strlen(ed25519); + session->userauth_pblc_method = + LIBSSH2_ALLOC(session, session->userauth_pblc_method_len); + + memcpy(session->userauth_pblc_method, ed25519, + session->userauth_pblc_method_len); + } + + rc = memory_read_publickey(session, + &session->userauth_pblc_method, + &session->userauth_pblc_method_len, + &pubkeydata, &pubkeydata_len, + (char *)publickeydata, + publickeydata_len); + } } else { return _libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid data in public and private key."); } - rc = _libssh2_userauth_publickey(session, username, username_len, - pubkeydata, pubkeydata_len, - libssh2_sign_sk, &sign_abstract); - - while(rc == LIBSSH2_ERROR_EAGAIN) { + if(rc == LIBSSH2_ERROR_NONE) { rc = _libssh2_userauth_publickey(session, username, username_len, pubkeydata, pubkeydata_len, libssh2_sign_sk, &sign_abstract); + + while(rc == LIBSSH2_ERROR_EAGAIN) { + rc = _libssh2_userauth_publickey(session, username, username_len, + pubkeydata, pubkeydata_len, + libssh2_sign_sk, &sign_abstract); + } } - if(pubkeydata) - LIBSSH2_FREE(session, pubkeydata); + if(tmp_publickeydata) + LIBSSH2_FREE(session, tmp_publickeydata); if(sk_info.application) { LIBSSH2_FREE(session, (void *)sk_info.application); From fdf824d6f4c945bb28d825ae173a1b390bb8ceed Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Apr 2023 08:58:57 +0000 Subject: [PATCH 317/424] ci: reduce algo test runtime on AppVeyor Make the block count customizable in `test_read` via environment `FIXTURE_XFER_COUNT`. Set the custom count lower than the default when running on AppVeyor. The goal is to reduce CI roundtrip times. Closes #995 --- appveyor.yml | 1 + tests/test_read.c | 56 ++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 6ea97a53b1..a8bb9ff829 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,6 +26,7 @@ environment: CONFIGURATION: "Release" + FIXTURE_XFER_COUNT: 35020 matrix: - job_name: "VS2022, OpenSSL3, x64, Server 2019" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" diff --git a/tests/test_read.c b/tests/test_read.c index 2058e63db3..24160b8547 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -2,33 +2,32 @@ #include "runner.h" +#include /* for getenv() */ + /* set in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa"; static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; -/* Size and number of blocks to transfer - * This needs to be large to increase the chance of timing effects causing - * different code paths to be hit in the unframing code, but not so long that - * the integration tests take too long. 5 seconds of run time is probably a - * reasonable compromise. The block size is an odd number to increase the - * chance that various internal buffer and block boundaries are overlapped. */ -#define XFER_BS 997 -#define XFER_COUNT 140080 - -#define STRINGIFY(x) STRINGIFY2(x) -#define STRINGIFY2(x) #x - -/* command to transfer the desired amount of data */ -#define REMOTE_COMMAND "dd if=/dev/zero bs=" STRINGIFY(XFER_BS) \ - " count=" STRINGIFY(XFER_COUNT) " status=none" - int test(LIBSSH2_SESSION *session) { int rc; - long xfer_bytes = 0; + unsigned long xfer_bytes = 0; LIBSSH2_CHANNEL *channel; + /* Size and number of blocks to transfer + * This needs to be large to increase the chance of timing effects causing + * different code paths to be hit in the unframing code, but not so long + * that the integration tests take too long. 5 seconds of run time is + * probably a reasonable compromise. The block size is an odd number to + * increase the chance that various internal buffer and block boundaries + * are overlapped. */ + const unsigned long xfer_bs = 997; + unsigned long xfer_count = 140080; + + char remote_command[256]; + const char *env; + const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); @@ -60,8 +59,19 @@ int test(LIBSSH2_SESSION *session) goto shutdown; } + env = getenv("FIXTURE_XFER_COUNT"); + if(env) { + xfer_count = (unsigned long)strtol(env, NULL, 0); + fprintf(stderr, "Custom xfer_count: %lu\n", xfer_count); + } + + /* command to transfer the desired amount of data */ + snprintf(remote_command, sizeof(remote_command), + "dd if=/dev/zero bs=%lu count=%lu status=none", + xfer_bs, xfer_count); + /* Send the command to transfer data */ - if(libssh2_channel_exec(channel, REMOTE_COMMAND)) { + if(libssh2_channel_exec(channel, remote_command)) { fprintf(stderr, "Unable to request command on channel\n"); goto shutdown; } @@ -73,8 +83,8 @@ int test(LIBSSH2_SESSION *session) if(err < 0) fprintf(stderr, "Unable to read response: %d\n", (int)err); else { - int i; - for(i = 0; i < err; ++i) { + unsigned int i; + for(i = 0; i < (unsigned long)err; ++i) { if(buf[i]) { fprintf(stderr, "Bad data received\n"); /* Test will fail below due to bad data length */ @@ -97,9 +107,9 @@ int test(LIBSSH2_SESSION *session) shutdown: /* Test check */ - if(xfer_bytes != XFER_COUNT * XFER_BS) { - fprintf(stderr, "Not enough bytes received: %ld not %ld\n", - xfer_bytes, (long)XFER_COUNT * XFER_BS); + if(xfer_bytes != xfer_count * xfer_bs) { + fprintf(stderr, "Not enough bytes received: %lu not %lu\n", + xfer_bytes, xfer_count * xfer_bs); return 1; /* error */ } return 0; From a459a25302a31f6e2aba3c4e15b1472b83b596fc Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Apr 2023 20:06:30 +0000 Subject: [PATCH 318/424] tests: improve running tests TL;DR: Sync test builds between autotools and CMake. Sync sshd configuration between Docker and non-Docker fixtures. Bump up sshd_config for recent OpenSSH releases. This also opens up the path to have non-Docker tests that use a local sshd process. Though sshd is practically unusable on Windows CI machines out of the box, so this will need further efforts. Details: - cmake: run sshd fixture test just like autotool did already. - sync tests and their order between autotools and CMake. It makes `test_aa_warmup` the first test with both. - cmake: load test lists from `Makefile.am`. Needed to update the loader to throw away certain lines to keep the converted output conform CMake syntax. Using regexp might be an alternative way of doing this, but couldn't make it work. - cmake: use the official way to configure test environment variables. Switch to syntax that's extendable. - cmake: allow to run the same test both under Docker and sshd fixture. Useful for testing the sshd fixture runner, or how the same test behaves in each fixture. - update test fixture to read the username from `USER` envvar instead of using the Dockfile-specific hardwired one, when running outside Docker. - rework `ssh2.sh` into `sshd_fixture.sh`, to: - allow running any tests (not just `test_ssh2`). - configure Docker tests for running outside Docker. - fixup `SSHD` path when running on Windows (e.g. in AppVeyor CI). Fixes: `sshd re-exec requires execution with an absolute path` - allow overriding `PUBKEY` and `PRIVKEY` envvars. - allow overriding `ssh_config` via `SSHD_FIXTURE_CONFIG`. - prepare support for running multiple tests via sshd_fixture. Add a TAP runner for autotools and extend CMake logic. The TAP runner loads the test list from `Makefile.am`. Notice however that on Windows, `sshd_fixture.sh` is very flaky with GitHub Actions. And consistently broken for subsequent tests in AppVeyor CI: 'libssh2_session_handshake failed (-43): Failed getting banner' Another way to try is a single sshd instance serving all tests. For CMake this would probably mean using an external script. - ed25519 test keys were identical for auth and host. Regenerate the auth keypair to make them distinct. - sync the sshd environment between Docker and sshd_fixture. - use common via `openssh_server/sshd_config`. - accept same auth keys. - offer the same host keys. - sync TrustedUserCAKeys. - delete now unused keypairs: `etc/host*`, `etc/user*`. - bump up startup delay for Windows (randomly, to 5 secs, from 3). - delete `UsePrivilegeSeparation no` to avoid deprecation warnings. `command-line line 0: Deprecated option UsePrivilegeSeparation` - delete `Protocol 2` to avoid deprecation warnings. It has been the default since OpenSSH 3.0 (2001-11-06). - delete `StrictModes no` (CI tests work without it, Docker tests never used it). - bump `Dockerfile` base image to `testing-slim` (from `bullseye-slim`). It needed `sshd_config` updates to keep things working with OpenSSH 9.2 (compared to bullseye's 8.4). - replace `ChallengeResponseAuthentication` alias with `KbdInteractiveAuthentication`. The former is no longer present in default `sshd_config` since OpenSSH 8.7 (2021-08-20). This broke the `Dockerfile` script. The new name is documented since OpenSSH 4.9 (2008-03-31) - add `PubkeyAcceptedKeyTypes +ssh-rsa,ssh-dss,ssh-rsa-cert-v01@openssh.com` and `HostKeyAlgorithms +ssh-rsa`. Original-patch-by: Eric van Gyzen (@vangyzen on github) Fixes #691 There is a new name for `PubkeyAcceptedKeyTypes`: `PubkeyAcceptedAlgorithms`. It requires OpenSSH 8.5 (2021-03-03) and breaks some envs so we're not using it just yet. - drop `rijndael-cbc@lysator.liu.se` tests and references from config. This is a draft alias for `aes256-cbc`. No need to test it twice. Also this alias is no longer recognized by OpenSSH 8.5 (2021-03-03). - update `mansyntax.sh` and `sshd_fixture.sh` to not rely on `srcdir`. Hopefully this works with out-of-tree builds. - fix `test_read_algos.test` to honor CRLF EOLs in their inputs (necessary when running on Windows.) - fix `test_read_algos.test` to honor `EXEEXT`. Might be useful when running tests under cross-builds? - `test_ssh2.c`: - use libssh2 API to set blocking mode. This makes it support all platforms. - adapt socket open timeout logic from `openssh_fixture.c`. Sadly this did not help fix flakiness on GHA Windows. - tests: delete unused C headers and variable initialization. - delete unused test files: `sshd_fixture.sh.in`, `sshdwrap`, `etc/sshd_config`. Ref: cf80f2f4b5255cc85a04ee43b27a29c678c1edb1 - autotools: delete stray `.c` test sources from `EXTRA_DIST` in tests. - `tests/.gitignore`: drop two stray tests. - autotools: fix passing `SSHD` containing space (Windows needs this). - autotools: sort `EXTRA_DIST` in tests. - cmake: fix to add `test_ssh2` to `TEST_TARGETS`. - fix `authorized_key` order in `tests/gen_keys.sh`. - silence shellcheck warning in `ci/checksrc.sh`. - set `SSHD` for autotools on GitHub Actions Windows. [skipped] Auto-detection doesn't work (maybe because sshd is installed via Git for Windows and we're using MSYS2's shell.) It enables running sshd fixture (non-Docker) tests in these jobs. I did not include this in the final patch due to flakiness: ``` Connection to 127.0.0.1:4711 attempt #0 failed: retrying... Connection to 127.0.0.1:4711 attempt #1 failed: retrying... Connection to 127.0.0.1:4711 attempt #2 failed: retrying... Failure establishing SSH session: -43 ``` Can be enabled with: `export SSHD='C:/Program Files/Git/usr/bin/sshd.exe'` Closes #996 --- CMakeLists.txt | 10 ++- ci/checksrc.sh | 1 + tests/.gitignore | 3 +- tests/CMakeLists.txt | 101 +++++++++++------------- tests/Makefile.am | 77 ++++++++++-------- tests/etc/host | 27 ------- tests/etc/host.pub | 1 - tests/etc/sshd_config | 3 - tests/etc/user | 27 ------- tests/etc/user.pub | 1 - tests/gen_keys.sh | 9 +-- tests/key_ed25519 | 8 +- tests/key_ed25519.pub | 2 +- tests/mansyntax.sh | 3 +- tests/openssh_fixture.c | 12 ++- tests/openssh_fixture.h | 1 + tests/openssh_server/Dockerfile | 9 +-- tests/openssh_server/authorized_keys | 2 +- tests/openssh_server/sshd_config | 4 + tests/session_fixture.c | 16 ++-- tests/ssh2.sh | 47 ----------- tests/sshd_fixture.sh | 73 +++++++++++++++++ tests/sshd_fixture.sh.in | 51 ------------ tests/sshdwrap | 28 ------- tests/test_auth_keyboard_info_request.c | 2 +- tests/test_read_algos.test | 5 +- tests/test_read_algos.txt | 1 - tests/test_ssh2.c | 51 +++++++++--- tests/test_sshd.test | 35 ++++++++ 29 files changed, 288 insertions(+), 322 deletions(-) delete mode 100644 tests/etc/host delete mode 100644 tests/etc/host.pub delete mode 100644 tests/etc/sshd_config delete mode 100644 tests/etc/user delete mode 100644 tests/etc/user.pub create mode 100644 tests/openssh_server/sshd_config delete mode 100755 tests/ssh2.sh create mode 100755 tests/sshd_fixture.sh delete mode 100644 tests/sshd_fixture.sh.in delete mode 100755 tests/sshdwrap create mode 100755 tests/test_sshd.test diff --git a/CMakeLists.txt b/CMakeLists.txt index 47870cd524..c211382cfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,7 +375,15 @@ endif() # Convert GNU Make assignments into CMake ones. function(transform_makefile_inc INPUT_FILE OUTPUT_FILE) - file(READ ${INPUT_FILE} MAKEFILE_INC_CMAKE) + file(STRINGS ${INPUT_FILE} LINES) + + unset(MAKEFILE_INC_CMAKE) + foreach(LINE IN LISTS LINES) + if(NOT LINE MATCHES " \\+= " AND + NOT LINE MATCHES "^(if|endif)") + set(MAKEFILE_INC_CMAKE "${MAKEFILE_INC_CMAKE}\n${LINE}") + endif() + endforeach() string(REGEX REPLACE "\\\\\n" "" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE}) string(REGEX REPLACE "([A-Za-z_]+) *= *([^\n]*)" "set(\\1 \\2)" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE}) diff --git a/ci/checksrc.sh b/ci/checksrc.sh index 13a57ffe5f..3de54115b4 100755 --- a/ci/checksrc.sh +++ b/ci/checksrc.sh @@ -5,6 +5,7 @@ set -e FILES="src/*.[ch] include/*.h example/*.c tests/*.[ch]" WHITELIST="-Wsrc/libssh2_config.h" +# shellcheck disable=SC2086 perl ./ci/checksrc.pl -i4 -m79 \ -ASNPRINTF \ -ACOPYRIGHT \ diff --git a/tests/.gitignore b/tests/.gitignore index b0ebd8f328..966f4ea962 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -4,5 +4,4 @@ *.gcda Makefile Makefile.in -simple -ssh2 +Makefile.am.cmake diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8c7c396e33..51f3a4d972 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,6 +37,10 @@ include(CopyRuntimeDependencies) list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) +transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake") +# Get 'DOCKER_TESTS', 'STANDALONE_TESTS', 'SSHD_TESTS' variables +include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) + if(CMAKE_COMPILER_IS_GNUCC) find_program(GCOV_PATH gcov) if(GCOV_PATH) @@ -47,32 +51,14 @@ if(CMAKE_COMPILER_IS_GNUCC) endif() endif() -set(TESTS - test_aa_warmup # keep this first - test_agent_forward_ok - test_auth_keyboard_fail - test_auth_keyboard_info_request - test_auth_keyboard_ok - test_auth_password_fail_password - test_auth_password_fail_username - test_auth_password_ok - test_auth_pubkey_fail - test_auth_pubkey_ok_dsa - test_auth_pubkey_ok_ecdsa - test_auth_pubkey_ok_ecdsa_signed - test_auth_pubkey_ok_ed25519 - test_auth_pubkey_ok_ed25519_encrypted - test_auth_pubkey_ok_ed25519_mem - test_auth_pubkey_ok_rsa - test_auth_pubkey_ok_rsa_encrypted - test_auth_pubkey_ok_rsa_openssh - test_auth_pubkey_ok_rsa_signed - test_hostkey - test_hostkey_hash - test_read - test_simple - test_ssh2 -) +find_program(SH_EXECUTABLE sh) +mark_as_advanced(SH_EXECUTABLE) +if(SH_EXECUTABLE) + find_program(SSHD_EXECUTABLE sshd) + mark_as_advanced(SSHD_EXECUTABLE) + + add_test(NAME mansyntax COMMAND ${SH_EXECUTABLE} -c "${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh") +endif() add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) target_compile_definitions(runner PRIVATE "${CRYPTO_BACKEND_DEFINE}") @@ -88,37 +74,53 @@ if(BUILD_SHARED_LIBS) endforeach() endif() -foreach(test ${TESTS}) - add_executable(${test} ${test}.c) - target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}") - target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") +foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS}) + # We support the same target as both Docker and SSHD test. Build those just once. + if(NOT TARGET ${test}) + add_executable(${test} ${test}.c) + target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}") + target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") - # build a single test with gcov - if(GCOV_PATH AND test STREQUAL test_auth_keyboard_info_request) - target_compile_options(${test} BEFORE PRIVATE ${GCOV_OPTIONS}) - target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES} gcov) - else() - target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES}) - endif() + # build a single test with gcov + if(GCOV_PATH AND test STREQUAL test_auth_keyboard_info_request) + target_compile_options(${test} BEFORE PRIVATE ${GCOV_OPTIONS}) + target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES} gcov) + else() + target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES}) + endif() - if(NOT test STREQUAL "test_ssh2") # skip test that needs ssh2.sh to run list(APPEND TEST_TARGETS ${test}) - add_test( - NAME ${test} COMMAND $ - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") endif() endforeach() +foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS}) + add_test(NAME ${test} COMMAND $ + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +endforeach() + +if(SSHD_EXECUTABLE) + # On Windows / AppVeyor CI, subsequent tests are broken: + # 'libssh2_session_handshake failed (-43): Failed getting banner' + if(WIN32) + list(GET SSHD_TESTS 0 SSHD_TESTS) + endif() + foreach(test ${SSHD_TESTS}) + set(testname sshd-${test}) + add_test(NAME ${testname} COMMAND ${SH_EXECUTABLE} -c "${CMAKE_CURRENT_SOURCE_DIR}/sshd_fixture.sh $") + set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "SSHD=${SSHD_EXECUTABLE}") + endforeach() +endif() + # CRYPT/MAC algo tests -file(READ "test_read_algos.txt" TESTS) -string(REGEX REPLACE "\\\n" ";" TESTS ${TESTS}) -foreach(test ${TESTS}) +file(READ "test_read_algos.txt" ALGO_TESTS) +string(REGEX REPLACE "\\\n" ";" ALGO_TESTS ${ALGO_TESTS}) +foreach(test ${ALGO_TESTS}) set(testname test_read-${test}) add_test(NAME ${testname} COMMAND "$") if(test MATCHES "mac-") - set_tests_properties(${testname} PROPERTIES ENVIRONMENT "FIXTURE_TEST_MAC=${test}") + set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "FIXTURE_TEST_MAC=${test}") else() - set_tests_properties(${testname} PROPERTIES ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") + set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}") endif() endforeach() @@ -134,10 +136,3 @@ add_target_to_copy_dependencies( TARGET copy_test_dependencies DEPENDENCIES ${RUNTIME_DEPENDENCIES} BEFORE_TARGETS ${TEST_TARGETS}) - -find_program(SH_EXECUTABLE sh) -mark_as_advanced(SH_EXECUTABLE) -if(SH_EXECUTABLE) - add_test(mansyntax ${SH_EXECUTABLE} -c - "srcdir=${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh") -endif() diff --git a/tests/Makefile.am b/tests/Makefile.am index 0eef9a2233..3803c0765b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,21 +2,12 @@ SUBDIRS = ossfuzz AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/include -ctests = test_simple$(EXEEXT) -TESTS = $(ctests) mansyntax.sh -check_PROGRAMS = $(ctests) - -TEST_EXTENSIONS = .test -# 'TEST' in 'TEST_LOG_DRIVER' is the test extension in uppercase. -TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/tap-driver.sh -TESTS += test_read_algos.test - -if SSHD -TESTS += ssh2.sh -check_PROGRAMS += test_ssh2 -endif - -INTEGRATION_TESTS = \ +# Keep this list sorted +# +# NOTE: test_auth_keyboard_info_request does not use the network, but when +# run as Windows standalone test, it intermittently fails on GHA with: +# `Terminate batch job (Y/N)?` +DOCKER_TESTS = \ test_aa_warmup \ test_agent_forward_ok \ test_auth_keyboard_fail \ @@ -40,11 +31,41 @@ INTEGRATION_TESTS = \ test_hostkey_hash \ test_read -# Integration tests using Docker +STANDALONE_TESTS = \ + test_simple + +SSHD_TESTS = \ + test_ssh2 \ + test_auth_pubkey_ok_ed25519 + +# FIXME: Exported by autotools with the same value by default anyway? +TESTS_ENVIRONMENT = srcdir=$(top_srcdir)/tests builddir=$(top_builddir)/tests + +# Tests to run +TESTS = mansyntax.sh + if ! HOST_WINDOWS -TESTS += $(INTEGRATION_TESTS) +TESTS += $(DOCKER_TESTS) endif -check_PROGRAMS += $(INTEGRATION_TESTS) + +TESTS += $(STANDALONE_TESTS) + +# TAP tests +TEST_EXTENSIONS = .test +# 'TEST' in 'TEST_LOG_DRIVER' is the test extension in uppercase. +TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/tap-driver.sh + +TESTS_ENVIRONMENT += EXEEXT=$(EXEEXT) +if SSHD +TESTS += test_sshd.test +TESTS_ENVIRONMENT += SSHD="$(SSHD)" +endif +TESTS += test_read_algos.test + +# Tests to build +check_PROGRAMS = $(DOCKER_TESTS) $(STANDALONE_TESTS) $(SSHD_TESTS) + +# Internal library used by tests librunner_la_SOURCES = \ runner.c runner.h \ session_fixture.c session_fixture.h \ @@ -61,16 +82,8 @@ test_simple_LDFLAGS = -static # This must be last in the list so it resolves symbols in previous libraries LDADD += ../src/libssh2.la -TESTS_ENVIRONMENT = SSHD=$(SSHD) EXEEXT=$(EXEEXT) -TESTS_ENVIRONMENT += srcdir=$(top_srcdir)/tests builddir=$(top_builddir)/tests - EXTRA_DIST = \ CMakeLists.txt \ - etc/host \ - etc/host.pub \ - etc/sshd_config \ - etc/user \ - etc/user.pub \ key_dsa \ key_dsa.pub \ key_dsa_wrong \ @@ -96,17 +109,15 @@ EXTRA_DIST = \ mansyntax.sh \ openssh_server/Dockerfile \ openssh_server/authorized_keys \ - openssh_server/ca_rsa \ - openssh_server/ca_rsa.pub \ openssh_server/ca_ecdsa \ openssh_server/ca_ecdsa.pub \ + openssh_server/ca_rsa \ + openssh_server/ca_rsa.pub \ openssh_server/ssh_host_ecdsa_key \ openssh_server/ssh_host_ed25519_key \ openssh_server/ssh_host_rsa_key \ + openssh_server/sshd_config \ test_read_algos.test \ test_read_algos.txt \ - test_simple.c \ - test_ssh2.c \ - ssh2.sh \ - sshd_fixture.sh.in \ - sshdwrap + test_sshd.test \ + sshd_fixture.sh diff --git a/tests/etc/host b/tests/etc/host deleted file mode 100644 index c4ead71141..0000000000 --- a/tests/etc/host +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEAwJaOo3i1X3N401hMd92lRec0tPMBgaF6ZDanovBiQP+PNo6g -VNtuF15AspbyxrViqtAyjLWQQlKGWgEFb2ga3ukzJll4dKPtNff3mO++W19ia0WQ -ZFWTAGcYqet4fvSALIpG+t/3u5MZXMNZPyCU8u1l+QXX14f6dEjzgRw7s3fSy/uv -Qawkgn8TQFvtSBOfvUTJPTAhhZqxZAt3nGH8d6vqD1hBNvdOpsohy6EgFh8V+kxn -UdQntrYe9WSz0djt0RRrdAvRkM0hq1UY8C9FTQQWni1n168c7FVrf65+GdJOn7NQ -Du0Whmh/R3flXR0kIBG+F7e8+e9W9OhlionkPwIBIwKCAQEAqpP6rgvT2DMTPtkt -yUCoU9tpMo4XRu4b8lxLVc2Y2nvz391pb7sJvO0Uu2/BFmYkMORKB5l/xbbOxL8T -cU2UJIVn0YJyAOj2rCTFW5KEB8mDDo4SLPtWUNBXrHF5WoDJTAVyEWdJInr5NOeJ -j68k1yoJ3JAlkwNozWUvclrVytZNohPhiYdKkj2DPlWKL//0INGIo9TU31AGJx2R -ymy105EFCXWDv1GAIWwqBjNNxzlyxDauuGTwWr2iYDyectBYApCkjyJzMpFn4Yiu -Mq5XomwkQhefK3y32bRasm+HSrQsGswSvSyS8I5YosjSKMmiWdYj4WxrSciT6gG/ -KHanEwKBgQDucA7E/s9aKs6rECypXPaCORxvbLqdqAiwzJ0edufE+g0aQU/Zm3xj -m6LGovdEcaBog4rfKCSB9NRKi35m4HV9PO4YBw6/lQ0NeO6jrb8OnZp/P97FbomT -AXBibzUjQ8fhbPCaJF/2TUEoyhNbzJkpl+M0zu2aQ3MUYVd4dZ4y4wKBgQDOxfeA -RH3ZPvdYI50jxW+/kKcio+APZZJ9xhtqOKzmEuJOPzlngWk5WQgS8B1aicHyFRhw -UT2vKeJvqqoeLbIE9Fm6qlpN22594S88+LOiMda4wRswxG9wBZ2J4+rrYKpcb1gt -JXvVKY7h5qLWGCR0x+ovOcNXABWsF8CAnOnb9QKBgA2gANgOj4F+yfslfuUbQUlF -F5FWq5P6+S6sm0ORxBniZyYSXFWT2zjkUnHAK2L/LbzUURQQ7CSu5487K8tdSIrQ -SB6hUUzGsEnppzyNleOT+jMoOJ2RSbCg/xuRU35bpQWRMlHzczKlVC43btILsPsP -/lrJ/vLfSGeQiKfMNOz3AoGAC9DMUHjxP50ytJRSH00cVBbk+qpHUVZC4p2bKqQn -IxcFnhI9y2Z7CpdfjA24iNSr/zRny+dinEuJSDWjUi5/M3utWx+tY4jhvgzeIL3B -HzYMRRJZUz5sxJKbSbVAn7xhgZ/2aPrT4EuEge/sDDvk03kjUyffRszOCdV4tuRl -IoMCgYEAnrexTd5GuxEEBg3qJgN4IMwoBzZlJ1voaI6I/AMuvQ5kVklYvHTPTZOI -kSIrvaG8xaOdf0f76XNdT7U/dkx0C0vcesy5++hqakmeRCHjfsE1wN7m+hGo5WcR -Jq8Ph9ZnH5RKjqDsHh7Y4BCewQNrMBqNQEzDebZCDBUTnK9OgOg= ------END RSA PRIVATE KEY----- diff --git a/tests/etc/host.pub b/tests/etc/host.pub deleted file mode 100644 index e1ad7f98ec..0000000000 --- a/tests/etc/host.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwJaOo3i1X3N401hMd92lRec0tPMBgaF6ZDanovBiQP+PNo6gVNtuF15AspbyxrViqtAyjLWQQlKGWgEFb2ga3ukzJll4dKPtNff3mO++W19ia0WQZFWTAGcYqet4fvSALIpG+t/3u5MZXMNZPyCU8u1l+QXX14f6dEjzgRw7s3fSy/uvQawkgn8TQFvtSBOfvUTJPTAhhZqxZAt3nGH8d6vqD1hBNvdOpsohy6EgFh8V+kxnUdQntrYe9WSz0djt0RRrdAvRkM0hq1UY8C9FTQQWni1n168c7FVrf65+GdJOn7NQDu0Whmh/R3flXR0kIBG+F7e8+e9W9OhlionkPw== jas@mocca diff --git a/tests/etc/sshd_config b/tests/etc/sshd_config deleted file mode 100644 index 331dcc9061..0000000000 --- a/tests/etc/sshd_config +++ /dev/null @@ -1,3 +0,0 @@ -Port 4711 -Protocol 2 -AuthorizedKeysFile /home/jas/src/libssh2/tests/etc/user.pub diff --git a/tests/etc/user b/tests/etc/user deleted file mode 100644 index 01bf6ac98d..0000000000 --- a/tests/etc/user +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEoQIBAAKCAQEAxIgBuZS39D4bFnWminE7svGQLdVKx1aWKnEYEa+XtNU4DKZ/ -pxUHg0zbEBya+IkX1yqQYWALoiOwI8XhdemLp8g03BX7o+DLSWisfiHpCDVGAuNq -RDF7qnFyL/ZBH6e0XKMtsoB51TDuBc4Rxh6p1V2QL/fg8BoHcCrnKkoqN8PSoKUX -2lPKJ3JIF/P8cDLbKYCvbSTFOdf56eqg0GJe7jFtSwweE9yz3IWZ3kSS1E/9E6sX -aNCu/hUt1bvQthICQyBNoTtQP/igEUJ7n0GMetsnq9wiUSomLzWqIWNqmvOv62aC -XRi5sYgpSAR4Zvnm3Cx/Wl0BEPz2rrFkG+G0SQIBIwKCAQEAgSYtBOyzZfztOqUV -q277WFWZQrC8HJf8R8aparU3zpq+braOZnuImByP9KUVYX6pRECKw6WD/NWfonq4 -uzMSoXTviVBGRx6xeWIK880kG1Y1UlruD447Ur+ULiV7QLAIzylnLCiKk2lL9S+l -R63AD95mEOS4Y0ROB+Gt2fY5ABHRMqhGLvRKK8qwn35C1Z9qnTGhgiRbeoc373A5 -ZAYyegyLnbvyV47UfPYS/TVzxZ9RCx3D3I/9fI7ZAFafkkIufQX3QPaVxf0zFUwW -de/f+gTbySTL4RDF185Evunx+tYvzCyIimB0cTE5dfsCWcHDtO6DwehKiOgJsbeW -IrpeTwKBgQDnEMfv7ORR35Ouj91iNCSfLU/v0TSzAJBfqYovByhXRsopgWAKXUmH -mWpBBP5vcGu3NvKfiZcMMbBPfllvlxkafQwvCqrdn5mg01MdAHMWP/O9yfvuxMDE -KycU2G2CT8j85mIPn19WeIgXC/kws+P0RAVNCBNeq89Gvp4IdLN67wKBgQDZvTYh -TPCYG32jBK+CcWmOna2SLvBloDcNevhzfu3RGjLIXzUHGxLdx7slsP/tpndmXIAL -CgV6GfrLxix5bO08203S2qnnwP8VrjjNIv1CyZIbbQFAFIeC3QxZMZHnXieLrO0z -qF5CuUXcL3cMeGmF/0HN/rB+4sF0qfv8wD8kRwKBgFXTCG8O2HYueK6NNPiXBknA -X4T17wCocCOIHWHstzZcHzP82oeBvDmuAuTzOe7gnQmJcA9e/ZbQoJKOA/Y/b7lh -pXCO7wHcMb9kb1PqOWAJIASqG78V4TLrdOp8Re6Sqb0FHRu+2kSwbQ/f4DapN2lb -F+lpZke8KGq71ExImm99AoGAN/10UbSy5UjlytVRs9QFM00eAQTBeTfTpGFzFmJ3 -qsw48bIU8zLY9zNcAmC21rXG7m+Oo8C/lG0UmsyPF+jPSinDjf22qU7iger4qccr -Lm5YxTlJduC1IaaOJZBnWMBwkaF+0sTlCdfew5ctPbiQKcVLb3wBf7amxjpWvVYB -m50CgYAT6t2/Suav21J5zpzyrrt+oMZQ3MMzBnPHFRUQ1FdqZnE4eW5a10g0P+E+ -YeTol+fYxL34+cI5PREK3dcnW1E8g8KOsOQqMgWdTfZEDHYRLqEyGIhu20aqfJCY -qu9tBburQoSlym9aQp41CMxIyHrL4GnwRlJkTTEVhDuab1HmKw== ------END RSA PRIVATE KEY----- diff --git a/tests/etc/user.pub b/tests/etc/user.pub deleted file mode 100644 index c60e90d108..0000000000 --- a/tests/etc/user.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxIgBuZS39D4bFnWminE7svGQLdVKx1aWKnEYEa+XtNU4DKZ/pxUHg0zbEBya+IkX1yqQYWALoiOwI8XhdemLp8g03BX7o+DLSWisfiHpCDVGAuNqRDF7qnFyL/ZBH6e0XKMtsoB51TDuBc4Rxh6p1V2QL/fg8BoHcCrnKkoqN8PSoKUX2lPKJ3JIF/P8cDLbKYCvbSTFOdf56eqg0GJe7jFtSwweE9yz3IWZ3kSS1E/9E6sXaNCu/hUt1bvQthICQyBNoTtQP/igEUJ7n0GMetsnq9wiUSomLzWqIWNqmvOv62aCXRi5sYgpSAR4Zvnm3Cx/Wl0BEPz2rrFkG+G0SQ== jas@mocca diff --git a/tests/gen_keys.sh b/tests/gen_keys.sh index 3f8c0f6010..23c5e63486 100755 --- a/tests/gen_keys.sh +++ b/tests/gen_keys.sh @@ -44,18 +44,11 @@ cat \ 'key_rsa.pub' \ 'key_rsa_encrypted.pub' \ 'key_rsa_openssh.pub' \ - 'key_ecdsa.pub' \ 'key_ed25519.pub' \ 'key_ed25519_encrypted.pub' \ + 'key_ecdsa.pub' \ > openssh_server/authorized_keys -# tests/etc - -rm etc/host* etc/user* || true - -ssh-keygen -t rsa -b 2048 -N '' -m PEM -C 'etc_host_rsa' -f 'etc/host' -ssh-keygen -t rsa -b 2048 -N '' -m PEM -C 'etc_user_rsa' -f 'etc/user' - # tests/test_*.c echo 'Add these public keys and hashes to:' diff --git a/tests/key_ed25519 b/tests/key_ed25519 index bfb1ad566d..bdf07a8ee5 100644 --- a/tests/key_ed25519 +++ b/tests/key_ed25519 @@ -1,7 +1,7 @@ -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW -QyNTUxOQAAACCMbXcoNmUVxO9FMMj1VB91MnwwVfBl+XDxet+j+oY6JgAAAJg8nvUxPJ71 -MQAAAAtzc2gtZWQyNTUxOQAAACCMbXcoNmUVxO9FMMj1VB91MnwwVfBl+XDxet+j+oY6Jg -AAAECnhCuTDYdz3kUn48BXkaCXXdbKdH7wSIQ/CUx1cbnR0Ixtdyg2ZRXE70UwyPVUH3Uy -fDBV8GX5cPF636P6hjomAAAAEHdpbGxAaUN1YmUubG9jYWwBAgMEBQ== +QyNTUxOQAAACBRINCCN823NclhoUcyHOSsE0ZZsddEUD9LEut/taDD4gAAAJDgVkFO4FZB +TgAAAAtzc2gtZWQyNTUxOQAAACBRINCCN823NclhoUcyHOSsE0ZZsddEUD9LEut/taDD4g +AAAECD4khMmQkiGtn/wwcwqKNRo3oCetwMOOlhli8S8So8OVEg0II3zbc1yWGhRzIc5KwT +Rlmx10RQP0sS63+1oMPiAAAAC2tleV9lZDI1NTE5AQI= -----END OPENSSH PRIVATE KEY----- diff --git a/tests/key_ed25519.pub b/tests/key_ed25519.pub index cd592194b5..ccc3b90f50 100644 --- a/tests/key_ed25519.pub +++ b/tests/key_ed25519.pub @@ -1 +1 @@ -ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIxtdyg2ZRXE70UwyPVUH3UyfDBV8GX5cPF636P6hjom +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFEg0II3zbc1yWGhRzIc5KwTRlmx10RQP0sS63+1oMPi key_ed25519 diff --git a/tests/mansyntax.sh b/tests/mansyntax.sh index 3b9a73d19b..9c95ad44e8 100755 --- a/tests/mansyntax.sh +++ b/tests/mansyntax.sh @@ -10,9 +10,8 @@ set -e command -v gman >/dev/null 2>&1 && man() { gman "$@"; } -srcdir="${srcdir:-$PWD}" dstdir="${builddir:-$PWD}" -mandir="${srcdir}/../docs" +mandir="$(dirname "$0")/../docs" ec=0 diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index c05f501fbc..407cdcbf77 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #if defined(WIN32) && defined(_WIN64) @@ -64,6 +63,11 @@ static int have_docker = 0; +int openssh_fixture_have_docker(void) +{ + return have_docker; +} + static int run_command_varg(char **output, const char *command, va_list args) { static const char redirect_stderr[] = "%s 2>&1"; @@ -229,10 +233,10 @@ static int is_running_inside_a_container(void) return 0; #else const char *cgroup_filename = "/proc/self/cgroup"; - FILE *f = NULL; + FILE *f; char *line = NULL; size_t len = 0; - ssize_t read = 0; + ssize_t read; int found = 0; f = fopen(cgroup_filename, "r"); if(!f) { @@ -331,7 +335,7 @@ static libssh2_socket_t open_socket_to_container(char *container_id) uint32_t hostaddr; libssh2_socket_t sock; struct sockaddr_in sin; - int counter = 0; + int counter; libssh2_socket_t ret = LIBSSH2_INVALID_SOCKET; if(have_docker) { diff --git a/tests/openssh_fixture.h b/tests/openssh_fixture.h index 055ee4effd..745e6c1f3c 100644 --- a/tests/openssh_fixture.h +++ b/tests/openssh_fixture.h @@ -41,5 +41,6 @@ int start_openssh_fixture(void); void stop_openssh_fixture(void); libssh2_socket_t open_socket_to_openssh_server(void); +int openssh_fixture_have_docker(void); #endif diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index a2712c16ba..4283ace96c 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -33,7 +33,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. -FROM debian:bullseye-slim +FROM debian:testing-slim RUN apt-get update \ && apt-get install -y openssh-server \ @@ -78,11 +78,10 @@ RUN chmod 600 /etc/ssh/ca_rsa RUN adduser --disabled-password --gecos 'Test user for libssh2 integration tests' libssh2 RUN echo 'libssh2:my test password' | chpasswd -RUN sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config +RUN sed -i 's/KbdInteractiveAuthentication no/KbdInteractiveAuthentication yes/' /etc/ssh/sshd_config +COPY sshd_config /tmp/etc/ssh/sshd_config +RUN cat /tmp/etc/ssh/sshd_config >> /etc/ssh/sshd_config RUN echo "TrustedUserCAKeys /etc/ssh/ca_main.pub" >> /etc/ssh/sshd_config -RUN echo "PubkeyAcceptedKeyTypes=+ssh-dss" >> /etc/ssh/sshd_config -RUN echo "MACs +hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512,hmac-md5,hmac-md5-96,umac-64@openssh.com,umac-128@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com" >> /etc/ssh/sshd_config -RUN echo "Ciphers +3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com" >> /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login diff --git a/tests/openssh_server/authorized_keys b/tests/openssh_server/authorized_keys index cdd6eef505..7679a46b35 100644 --- a/tests/openssh_server/authorized_keys +++ b/tests/openssh_server/authorized_keys @@ -2,6 +2,6 @@ ssh-dss AAAAB3NzaC1kc3MAAACBAK2Jh2Ck+8W1+LsFrjgOIH7XHySiONPSdG+faFTZprinh9cjyR3o ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAnak1T7zHJ+hVRFBDQ9pf1KVzmd5gaNc7y7NPmL13aOG3sYeJevi1x1WM/R3tb8XnUnzZUX9GJN0MYovvZsw9bknG1mDP72LFbGp/gzPddGIKHBBpvceDaJ85sM/ME3XOtD7uuXQuNAuEHwEzSMMiSIEMcQS+lXIcMLr5xPLEkyNvqsO5RqSjMTLHKHgY8gLWx7oQ1avokhwuDxF7P3Pqtj+rW2Te6vR0i1H6EyFPsBkzkgNXb33cus8M1CnTmYTSgJgmHO2LLcGpjQ5sL8T/PWIWHaSqTnkrFXEMysgoteXnAYILjzyBaqq2WV4KA3TluGdAP2p8gC32QtKmIuis3Q== awl03@bounty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC92YlGoc4PJy6DzX916JJZhxkvmkWBLGJdWOL7R9B6iaYEKebBxzTE3P1RcnxnuI06kklVq/KcDP9sLlgawTZcDg7ifM7HncPOi18OON8vvVVzodikHzuupjhpI5YTT9wwV2fDVi2URsBjvX4AFiZ5WM3/NwqdKpYABzWieBikXGJ58Tsnw+zQw2qMmKKESBuzSN538loTAj5iEH/GAKYDbbH9t2a17qhNCNEw4vrtURT9JqwO1cOg7N1OKpmqCPEbK0wuSTljNC230VJ06X/8UqahWWSH6MreGy6gwpPi6i9wFiFLur301R0dTPiKVhz6bguhcC1EAlhSgjfelFJt awl03@bounty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTe1lN2L/yet0Ma1JzXkQf3t1f+pauALec2FsGZy87KRJW1AOxcTTiePjlFwP1yfSK1lWXQ+uf0b61gkKqqR52FDky24HJWuYlfXlEQMn2d/PNDNVDDbO4TXKyNxxUHFJ6qYMNd4kWjOH+6rmYoWKsWV+3mDRbHagbVPEYL8wep8OTqKOqruVLVPzZyYZkBtn4XOFi6UE8WKiSVdK1Am1O5UxvlD95t32eYch6wQ9azgMqja6spe/L5UJgP83QZFknVC3wPZWkjqomVFql0FpaQclENwyY/OZMxr0cT/f7bCL6s4A/1XpbsGmC0xak4/THHbOn+0LdIej2nGV8JFoR -ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIxtdyg2ZRXE70UwyPVUH3UyfDBV8GX5cPF636P6hjom +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFEg0II3zbc1yWGhRzIc5KwTRlmx10RQP0sS63+1oMPi ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICHxEyUTOVHXvdMFARedFQ+H9DW/n8Zy3daKKRqnTDMq ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBOiyJJwf+hFJrOkik9IQVxjhhVnI1vKl4BGLj03erLvw4TXXwoZzlPx6J936fU9JvvPw+d8PA4viMEfFbmdbHREKhwi3u1vZrfj0mB8SXw96AcZwX8PAL556wgom+/Qx+Q== diff --git a/tests/openssh_server/sshd_config b/tests/openssh_server/sshd_config new file mode 100644 index 0000000000..1069566f2a --- /dev/null +++ b/tests/openssh_server/sshd_config @@ -0,0 +1,4 @@ +HostKeyAlgorithms +ssh-rsa +PubkeyAcceptedKeyTypes +ssh-rsa,ssh-dss,ssh-rsa-cert-v01@openssh.com +MACs +hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512,hmac-md5,hmac-md5-96,umac-64@openssh.com,umac-128@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com +Ciphers +3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 3485b644e5..e23a5fcf2d 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -392,9 +392,9 @@ int test_auth_password(LIBSSH2_SESSION *session, int flags, static int read_file(const char *path, char **out_buffer, size_t *out_len) { - FILE *fp = NULL; - char *buffer = NULL; - size_t len = 0; + FILE *fp; + char *buffer; + size_t len; if(!out_buffer || !out_len || !path) { fprintf(stderr, "invalid params.\n"); @@ -444,10 +444,14 @@ int test_auth_pubkey(LIBSSH2_SESSION *session, int flags, const char *fn_priv) { int rc; + const char *userauth_list; - const char *userauth_list = - libssh2_userauth_list(session, username, - (unsigned int)strlen(username)); + /* Ignore our hard-wired Dockerfile user when not running under Docker */ + if(!openssh_fixture_have_docker() && strcmp(username, "libssh2") == 0) + username = getenv("USER"); + + userauth_list = libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; diff --git a/tests/ssh2.sh b/tests/ssh2.sh deleted file mode 100755 index fa604cb2d7..0000000000 --- a/tests/ssh2.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh - -# Written by Simon Josefsson. - -# Start sshd, invoke parameters, saving exit code, kill sshd, and -# return exit code. - -srcdir="${srcdir:-$PWD}" -SSHD="${SSHD:-/usr/sbin/sshd}" - -cmd="./test_ssh2${EXEEXT}" -srcdir="$(cd "$srcdir" || exit; pwd)" - -export PRIVKEY="$srcdir/etc/user" -export PUBKEY="$srcdir/etc/user.pub" - -if test -n "$DEBUG"; then - libssh2_sshd_params="-d -d" -fi - -chmod go-rwx "$srcdir"/etc/host* -# shellcheck disable=SC2086 -"$SSHD" -f /dev/null -h "$srcdir/etc/host" \ - -o 'Port 4711' \ - -o 'Protocol 2' \ - -o "AuthorizedKeysFile $srcdir/etc/user.pub" \ - -o 'UsePrivilegeSeparation no' \ - -o 'StrictModes no' \ - -D \ - $libssh2_sshd_params & -sshdpid=$! - -trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT - -: "started sshd (${sshdpid})" - -sleep 3 - -: "Invoking $cmd..." -eval "$cmd" -ec=$? -: "Self-test exit code $ec" - -: "killing sshd (${sshdpid})" -kill "${sshdpid}" > /dev/null 2>&1 -trap "" EXIT -exit "$ec" diff --git a/tests/sshd_fixture.sh b/tests/sshd_fixture.sh new file mode 100755 index 0000000000..5d8969db4f --- /dev/null +++ b/tests/sshd_fixture.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# Written by Simon Josefsson + +# Start sshd, invoke parameters, saving exit code, kill sshd, and +# return exit code. + +if [ -n "$1" ]; then + cmd="$*" +else + cmd="${cmd:-./test_ssh2}" +fi + +d="$(dirname "$0")" +d="$(cd "${d}" || exit; pwd)" # sshd needs absolute paths + +SSHD="${SSHD:-/usr/sbin/sshd}" +[[ "$(uname)" = *'_NT'* ]] && SSHD="$(cygpath -u "${SSHD}")" + +# for our test clients: +[ -z "${PRIVKEY}" ] && export PRIVKEY="${d}/key_rsa" +[ -z "${PUBKEY}" ] && export PUBKEY="${d}/key_rsa.pub" +cakeys="${d}/ca_main.pub" + +if [ -n "${DEBUG}" ]; then + libssh2_sshd_params="-d -d" +fi + +cat \ + "${d}/openssh_server/ca_ecdsa.pub" \ + "${d}/openssh_server/ca_rsa.pub" \ + > "${cakeys}" + +chmod go-rwx \ + "${d}"/openssh_server/ssh_host_* \ + "${cakeys}" + +export OPENSSH_NO_DOCKER=1 + +# shellcheck disable=SC2086 +"${SSHD}" \ + -f "${SSHD_FIXTURE_CONFIG:-${d}/openssh_server/sshd_config}" \ + -o 'Port 4711' \ + -h "${d}/openssh_server/ssh_host_rsa_key" \ + -h "${d}/openssh_server/ssh_host_ecdsa_key" \ + -h "${d}/openssh_server/ssh_host_ed25519_key" \ + -o "AuthorizedKeysFile ${PUBKEY} ${d}/key_dsa.pub ${d}/key_rsa.pub ${d}/key_rsa_encrypted.pub ${d}/key_rsa_openssh.pub ${d}/key_ed25519.pub ${d}/key_ed25519_encrypted.pub ${d}/key_ecdsa.pub" \ + -o "TrustedUserCAKeys ${cakeys}" \ + -D \ + ${libssh2_sshd_params} & +sshdpid=$! + +trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT + +: "started sshd (${sshdpid})" + +if [[ "$(uname)" = *'_NT'* ]]; then + sleep 5 +else + sleep 3 +fi + +: "Invoking '${cmd}'..." +eval "${cmd}" +ec=$? +: "Self-test exit code ${ec}" + +rm -f "${cakeys}" + +: "killing sshd (${sshdpid})" +kill "${sshdpid}" > /dev/null 2>&1 +trap '' EXIT +exit "${ec}" diff --git a/tests/sshd_fixture.sh.in b/tests/sshd_fixture.sh.in deleted file mode 100644 index 086cdb2678..0000000000 --- a/tests/sshd_fixture.sh.in +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -# Written by Simon Josefsson. - -# Start sshd, invoke parameters, saving exit code, kill sshd, and -# return exit code. - -srcdir="@SSHD_TEST_CONFIG_DIR@" -SSHD="@SSHD_EXECUTABLE@" - -cmd="\"$1\"" - -export PRIVKEY="$srcdir/etc/user" -export PUBKEY="$srcdir/etc/user.pub" - -if test -n "$DEBUG"; then - libssh2_sshd_params="-d -d" -fi - -chmod go-rwx "$srcdir"/etc/host* -# shellcheck disable=SC2086 -"$SSHD" -f /dev/null -h "$srcdir/etc/host" \ - -o 'Port 4711' \ - -o 'Protocol 2' \ - -o "AuthorizedKeysFile \"$srcdir/etc/user.pub\"" \ - -o 'UsePrivilegeSeparation no' \ - -o 'StrictModes no' \ - -D \ - $libssh2_sshd_params & -sshdpid=$! - -trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT - -: "started sshd (${sshdpid})" - -sleep 3 - -if ! kill -0 "${sshdpid}"; then - echo "SSHD exited before test started" - exit 1 -fi - -: "Invoking $cmd..." -eval "$cmd" -ec=$? -: "Self-test exit code $ec" - -: "killing sshd (${sshdpid})" -kill "${sshdpid}" > /dev/null 2>&1 -trap "" EXIT -exit "$ec" diff --git a/tests/sshdwrap b/tests/sshdwrap deleted file mode 100755 index 496056ddc8..0000000000 --- a/tests/sshdwrap +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -x - -# Written by Simon Josefsson - -# Start sshd, invoke parameters, saving exit code, kill sshd, and -# return exit code. - -cmd="$*" -SSHD="${SSHD:-/usr/sbin/sshd}" - -"$SSHD" -f etc/sshd_config -h "$PWD/etc/host" -D & -sshdpid=$! - -trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT - -: "started sshd (${sshdpid})" - -sleep 1 - -: "Invoking $cmd..." -eval "$cmd" -ec=$? -: "Self-test exit code $ec" - -: "killing sshd (${sshdpid})" -kill "${sshdpid}" > /dev/null 2>&1 -trap "" EXIT -exit "$ec" diff --git a/tests/test_auth_keyboard_info_request.c b/tests/test_auth_keyboard_info_request.c index 83860ffc18..a127c72329 100644 --- a/tests/test_auth_keyboard_info_request.c +++ b/tests/test_auth_keyboard_info_request.c @@ -248,7 +248,7 @@ int test_case(int num, int rc; char *message; int error_code; - LIBSSH2_SESSION *session = NULL; + LIBSSH2_SESSION *session; alloc_count = 0; free_count = 0; diff --git a/tests/test_read_algos.test b/tests/test_read_algos.test index 1b0556adc1..b5c5a9c772 100755 --- a/tests/test_read_algos.test +++ b/tests/test_read_algos.test @@ -3,14 +3,15 @@ # https://testanything.org/tap-specification.html if [[ "$(uname)" = *'_NT'* ]]; then + # 'no matching manifest for windows/amd64 in the manifest list entries' echo "1..0 # skip test_read tests due to docker issues" exit 0 fi -testbin='./test_read' +testbin="./test_read${EXEEXT}" d="$(dirname "$0")" -algos="$(cat "${d}/test_read_algos.txt")" +algos="$(tr -d $"\r" < "${d}/test_read_algos.txt")" count=1 total="$(echo "${algos}" | wc -l | tr -d ' ')" diff --git a/tests/test_read_algos.txt b/tests/test_read_algos.txt index 35ce3cdd27..a6f6173880 100644 --- a/tests/test_read_algos.txt +++ b/tests/test_read_algos.txt @@ -7,7 +7,6 @@ aes192-ctr aes256-cbc aes256-ctr aes256-gcm@openssh.com -rijndael-cbc@lysator.liu.se hmac-md5 hmac-md5-96 hmac-sha1 diff --git a/tests/test_ssh2.c b/tests/test_ssh2.c index 479a119026..a1374b8a2a 100644 --- a/tests/test_ssh2.c +++ b/tests/test_ssh2.c @@ -16,18 +16,25 @@ #include #endif -#include -#include -#include #include #include -#include -static const char *pubkey = "etc/user.pub"; -static const char *privkey = "etc/user"; +static const char *hostname = "127.0.0.1"; +static const unsigned short port_number = 4711; +static const char *pubkey = "key_rsa.pub"; +static const char *privkey = "key_rsa"; static const char *username = "username"; static const char *password = "password"; +static void portable_sleep(unsigned int seconds) +{ +#ifdef WIN32 + Sleep(seconds); +#else + sleep(seconds); +#endif +} + int main(int argc, char *argv[]) { uint32_t hostaddr; @@ -39,6 +46,7 @@ int main(int argc, char *argv[]) int rc; LIBSSH2_SESSION *session = NULL; LIBSSH2_CHANNEL *channel; + int counter; #ifdef WIN32 WSADATA wsadata; @@ -62,7 +70,11 @@ int main(int argc, char *argv[]) if(getenv("PUBKEY")) pubkey = getenv("PUBKEY"); - hostaddr = htonl(0x7F000001); + hostaddr = inet_addr(hostname); + if(hostaddr == (uint32_t)(-1)) { + fprintf(stderr, "Failed to convert %s host address\n", hostname); + return 1; + } rc = libssh2_init(0); if(rc) { @@ -78,14 +90,25 @@ int main(int argc, char *argv[]) goto shutdown; } -#ifndef WIN32 - fcntl(sock, F_SETFL, 0); -#endif sin.sin_family = AF_INET; - sin.sin_port = htons(4711); + sin.sin_port = htons(port_number); sin.sin_addr.s_addr = hostaddr; - if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) { - fprintf(stderr, "failed to connect!\n"); + + for(counter = 0; counter < 3; ++counter) { + if(connect(sock, (struct sockaddr*)(&sin), + sizeof(struct sockaddr_in))) { + fprintf(stderr, + "Connection to %s:%d attempt #%d failed: retrying...\n", + hostname, port_number, counter); + portable_sleep(1 + 2*counter); + } + else { + break; + } + } + if(sock == LIBSSH2_INVALID_SOCKET) { + fprintf(stderr, "Failed to connect to %s:%d\n", + hostname, port_number); goto shutdown; } @@ -98,6 +121,8 @@ int main(int argc, char *argv[]) goto shutdown; } + libssh2_session_set_blocking(session, 1); + rc = libssh2_session_handshake(session, sock); if(rc) { fprintf(stderr, "Failure establishing SSH session: %d\n", rc); diff --git a/tests/test_sshd.test b/tests/test_sshd.test new file mode 100755 index 0000000000..03ca3d75fa --- /dev/null +++ b/tests/test_sshd.test @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# https://testanything.org/tap-specification.html + +d="$(dirname "$0")" +uname="$(uname)" + +# Load list of SSHD tests from Makefile.am +tests='' +load=0 +while read -r l; do + if [[ "${l}" = 'SSHD_TESTS ='* ]]; then + load=1 + elif [ "${load}" = '1' ]; then + tests="${tests} ${l/\\}" + [[ ! "${l}" = *"\\" ]] && break + # On Windows, subsequent tests may be flaky + [[ "${uname}" = *'_NT'* ]] && break + fi +done <<< "$(tr -d $"\r" < "${d}/Makefile.am")" + +count=1 +total="$(echo "${tests}" | wc -w | tr -d ' ')" + +echo "${count}..${total}" + +for test in ${tests}; do + if "${d}/sshd_fixture.sh" "./${test}${EXEEXT}"; then + res='ok' + else + res='not ok' + fi + echo "${res} ${count} - sshd-${test}" + ((count++)) +done From 66fa286779ce214625c43dbd0f2dccd89f9f96f8 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 10:18:38 +0000 Subject: [PATCH 319/424] tidy-up: tiny nits [ci skip] --- src/session.c | 2 +- tests/mansyntax.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/session.c b/src/session.c index c9317dd4d8..a96c9d88c8 100644 --- a/src/session.c +++ b/src/session.c @@ -1355,7 +1355,7 @@ libssh2_session_set_last_error(LIBSSH2_SESSION* session, LIBSSH2_ERR_FLAG_DUP); } -/* Libssh2_session_flag +/* libssh2_session_flag * * Set/Get session flags * diff --git a/tests/mansyntax.sh b/tests/mansyntax.sh index 9c95ad44e8..2f3d3e818f 100755 --- a/tests/mansyntax.sh +++ b/tests/mansyntax.sh @@ -1,4 +1,5 @@ #!/bin/sh + set -e # Written by Mikhail Gusarov From 097c8f0dae558643d43051947a1c35b65e1c5761 Mon Sep 17 00:00:00 2001 From: Zenju Date: Tue, 25 Apr 2023 12:45:49 +0200 Subject: [PATCH 320/424] openssl: fix misleading error message if wrong passphrase (#789) Fixes #608 --- src/openssl.c | 21 ++++++++++++++++++--- src/pem.c | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/openssl.c b/src/openssl.c index 99d1e1235b..590b28cca7 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -3849,6 +3849,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, BIO* bp; EVP_PKEY* pk; int pktype; + unsigned long sslError; _libssh2_debug((session, LIBSSH2_TRACE_AUTH, @@ -3865,6 +3866,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, "computing public key"); BIO_reset(bp); pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); + sslError = ERR_get_error(); BIO_free(bp); if(!pk) { @@ -3877,9 +3879,22 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, privatekeydata, privatekeydata_len, (unsigned const char *)passphrase); - if(st) - return st; - return 0; + if(st == 0) + return 0; + +#if OPENSSL_VERSION_NUMBER >= 0x30000000L /* OpenSSL 3.0.0 */ + if((ERR_GET_LIB(sslError) == ERR_LIB_PEM && + ERR_GET_REASON(sslError) == PEM_R_BAD_DECRYPT) || + (ERR_GET_LIB(sslError) == ERR_LIB_PROV && + ERR_GET_REASON(sslError) == EVP_R_BAD_DECRYPT)) + return _libssh2_error(session, LIBSSH2_ERROR_KEYFILE_AUTH_FAILED, + "Wrong passphrase for private key"); +#endif + return _libssh2_error(session, + LIBSSH2_ERROR_FILE, + "Unable to extract public key " + "from private key file: " + "Unsupported private key file format"); } #ifdef HAVE_OPAQUE_STRUCTS diff --git a/src/pem.c b/src/pem.c index 255539a1ba..a02378e91a 100644 --- a/src/pem.c +++ b/src/pem.c @@ -764,7 +764,8 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session, if(off >= filedata_len) return _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Error parsing PEM: offset out of bounds"); + "Error parsing PEM: " + "OpenSSH header not found"); if(readline_memory(line, LINE_SIZE, filedata, filedata_len, &off)) { return -1; From 4e256cf18ab96d1132de53e86d781acbe24fc3b2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 09:27:17 +0000 Subject: [PATCH 321/424] test/CMakeLists.txt: reuse `Makefile.am` librunner source list Follow-up to a459a25302a31f6e2aba3c4e15b1472b83b596fc Closes #998 --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 51f3a4d972..8d2e9c3c7f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,7 +38,7 @@ include(CopyRuntimeDependencies) list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake") -# Get 'DOCKER_TESTS', 'STANDALONE_TESTS', 'SSHD_TESTS' variables +# Get 'DOCKER_TESTS', 'STANDALONE_TESTS', 'SSHD_TESTS', 'librunner_la_SOURCES' variables include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake) if(CMAKE_COMPILER_IS_GNUCC) @@ -60,7 +60,7 @@ if(SH_EXECUTABLE) add_test(NAME mansyntax COMMAND ${SH_EXECUTABLE} -c "${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh") endif() -add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) +add_library(runner STATIC ${librunner_la_SOURCES}) target_compile_definitions(runner PRIVATE "${CRYPTO_BACKEND_DEFINE}") target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include "${CRYPTO_BACKEND_INCLUDE_DIR}") target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") From 437af7e88f9ffd5080c54f1223d446769e9ad8a2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 20 Apr 2023 22:55:49 +0000 Subject: [PATCH 322/424] kex: fix overlapping memcpy() to memmove() Noticed this when libasan started kicking out errors when sending in MACs preferences that were not supported yet. Reported-by: fourierules on github Fixes #611 Closes #1000 --- src/kex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kex.c b/src/kex.c index 2c5266570a..d8884c045f 100644 --- a/src/kex.c +++ b/src/kex.c @@ -4027,7 +4027,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, if(!kex_get_method_by_name(s, method_len, mlist)) { /* Strip out unsupported method */ if(p) { - memcpy(s, p + 1, strlen(s) - method_len); + memmove(s, p + 1, strlen(s) - method_len); } else { if(s > newprefs) { From f2de2fda4e0cc314465ed00e59a541627f5d3ca4 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 14:45:07 +0000 Subject: [PATCH 323/424] cmake: use portable mkdir for tests/coverage target [ci skip] Makes `make coverage` work without a POSIX mkdir. Tested locally. Ref: https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-E-arg-make_directory --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8d2e9c3c7f..f0fd0862c7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -126,7 +126,7 @@ endforeach() add_custom_target(coverage COMMAND gcovr -r "${CMAKE_SOURCE_DIR}" --exclude tests/* - COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/coverage/" + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/coverage/" COMMAND gcovr -r "${CMAKE_SOURCE_DIR}" --exclude tests/* --html-details --output "${CMAKE_CURRENT_BINARY_DIR}/coverage/index.html") add_custom_target(clean-coverage From 6939f08a88fab28d1e82bac8b44af9aed741cba2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 15:50:37 +0000 Subject: [PATCH 324/424] libssh2_priv.h: whitespace fixes [ci skip] --- src/libssh2_priv.h | 59 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 82a5778bd6..309a7206f2 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -96,7 +96,7 @@ # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ defined(WINAPI_FAMILY) # include -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) # define LIBSSH2_WINDOWS_APP # endif @@ -170,32 +170,32 @@ struct iovec { #define MAX_SHA_DIGEST_LEN SHA512_DIGEST_LENGTH #define LIBSSH2_ALLOC(session, count) \ - session->alloc((count), &(session)->abstract) + session->alloc((count), &(session)->abstract) #define LIBSSH2_CALLOC(session, count) _libssh2_calloc(session, count) #define LIBSSH2_REALLOC(session, ptr, count) \ - ((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : \ - session->alloc((count), &(session)->abstract)) + ((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : \ + session->alloc((count), &(session)->abstract)) #define LIBSSH2_FREE(session, ptr) \ - session->free((ptr), &(session)->abstract) + session->free((ptr), &(session)->abstract) #define LIBSSH2_IGNORE(session, data, datalen) \ - session->ssh_msg_ignore((session), (data), (int)(datalen), \ - &(session)->abstract) + session->ssh_msg_ignore((session), (data), (int)(datalen), \ + &(session)->abstract) #define LIBSSH2_DEBUG(session, always_display, message, message_len, \ - language, language_len) \ + language, language_len) \ session->ssh_msg_debug((session), (always_display), \ (message), (int)(message_len), \ (language), (int)(language_len), \ &(session)->abstract) #define LIBSSH2_DISCONNECT(session, reason, message, message_len, \ - language, language_len) \ + language, language_len) \ session->ssh_msg_disconnect((session), (reason), \ (message), (int)(message_len), \ (language), (int)(language_len), \ &(session)->abstract) -#define LIBSSH2_MACERROR(session, data, datalen) \ +#define LIBSSH2_MACERROR(session, data, datalen) \ session->macerror((session), (data), (int)(datalen), &(session)->abstract) -#define LIBSSH2_X11_OPEN(channel, shost, sport) \ +#define LIBSSH2_X11_OPEN(channel, shost, sport) \ channel->session->x11(((channel)->session), (channel), \ (shost), (sport), (&(channel)->session->abstract)) @@ -214,7 +214,7 @@ struct iovec { (data), (dlen), (sig), (sigLen), \ (agentPath), (&(session->abstract))) -#define LIBSSH2_CHANNEL_CLOSE(session, channel) \ +#define LIBSSH2_CHANNEL_CLOSE(session, channel) \ channel->close_cb((session), &(session)->abstract, \ (channel), &(channel)->abstract) @@ -223,9 +223,9 @@ struct iovec { #define LIBSSH2_RECV_FD(session, fd, buffer, length, flags) \ (session->recv)(fd, buffer, length, flags, &session->abstract) -#define LIBSSH2_SEND(session, buffer, length, flags) \ +#define LIBSSH2_SEND(session, buffer, length, flags) \ LIBSSH2_SEND_FD(session, session->socket_fd, buffer, length, flags) -#define LIBSSH2_RECV(session, buffer, length, flags) \ +#define LIBSSH2_RECV(session, buffer, length, flags) \ LIBSSH2_RECV_FD(session, session->socket_fd, buffer, length, flags) typedef struct _LIBSSH2_KEX_METHOD LIBSSH2_KEX_METHOD; @@ -630,21 +630,22 @@ struct _LIBSSH2_SESSION { /* Memory management callbacks */ void *abstract; - LIBSSH2_ALLOC_FUNC((*alloc)); - LIBSSH2_REALLOC_FUNC((*realloc)); - LIBSSH2_FREE_FUNC((*free)); + + LIBSSH2_ALLOC_FUNC((*alloc)); + LIBSSH2_REALLOC_FUNC((*realloc)); + LIBSSH2_FREE_FUNC((*free)); /* Other callbacks */ - LIBSSH2_IGNORE_FUNC((*ssh_msg_ignore)); - LIBSSH2_DEBUG_FUNC((*ssh_msg_debug)); - LIBSSH2_DISCONNECT_FUNC((*ssh_msg_disconnect)); - LIBSSH2_MACERROR_FUNC((*macerror)); - LIBSSH2_X11_OPEN_FUNC((*x11)); - LIBSSH2_AUTHAGENT_FUNC((*authagent)); - LIBSSH2_ADD_IDENTITIES_FUNC((*addLocalIdentities)); - LIBSSH2_AUTHAGENT_SIGN_FUNC((*agentSignCallback)); - LIBSSH2_SEND_FUNC((*send)); - LIBSSH2_RECV_FUNC((*recv)); + LIBSSH2_IGNORE_FUNC((*ssh_msg_ignore)); + LIBSSH2_DEBUG_FUNC((*ssh_msg_debug)); + LIBSSH2_DISCONNECT_FUNC((*ssh_msg_disconnect)); + LIBSSH2_MACERROR_FUNC((*macerror)); + LIBSSH2_X11_OPEN_FUNC((*x11)); + LIBSSH2_AUTHAGENT_FUNC((*authagent)); + LIBSSH2_ADD_IDENTITIES_FUNC((*addLocalIdentities)); + LIBSSH2_AUTHAGENT_SIGN_FUNC((*agentSignCallback)); + LIBSSH2_SEND_FUNC((*send)); + LIBSSH2_RECV_FUNC((*recv)); /* Method preferences -- NULL yields "load order" */ char *kex_prefs; @@ -921,9 +922,9 @@ struct _LIBSSH2_SESSION /* session.flag helpers */ #ifdef MSG_NOSIGNAL -#define LIBSSH2_SOCKET_SEND_FLAGS(session) \ +#define LIBSSH2_SOCKET_SEND_FLAGS(session) \ (((session)->flag.sigpipe) ? 0 : MSG_NOSIGNAL) -#define LIBSSH2_SOCKET_RECV_FLAGS(session) \ +#define LIBSSH2_SOCKET_RECV_FLAGS(session) \ (((session)->flag.sigpipe) ? 0 : MSG_NOSIGNAL) #else /* If MSG_NOSIGNAL isn't defined we're SOL on blocking SIGPIPE */ From 9ef75298fae0728305d9d38ba1e3c838ad0513f7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 15:56:36 +0000 Subject: [PATCH 325/424] libssh2_priv.h: whitespace fixes cont. [ci skip] --- src/libssh2_priv.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 309a7206f2..7a2de85b13 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -681,7 +681,7 @@ struct _LIBSSH2_SESSION #if LIBSSH2_MD5 unsigned char server_hostkey_md5[MD5_DIGEST_LENGTH]; int server_hostkey_md5_valid; -#endif /* ! LIBSSH2_MD5 */ +#endif /* ! LIBSSH2_MD5 */ unsigned char server_hostkey_sha1[SHA_DIGEST_LENGTH]; int server_hostkey_sha1_valid; @@ -996,7 +996,7 @@ struct _LIBSSH2_CRYPT_METHOD size_t blocksize, void **abstract, int firstlast); int (*dtor) (LIBSSH2_SESSION * session, void **abstract); - _libssh2_cipher_type(algo); + _libssh2_cipher_type(algo); }; /* Bit flags for _LIBSSH2_CRYPT_METHOD */ @@ -1203,19 +1203,19 @@ size_t plain_method(char *method, size_t method_len); #endif /* In Windows the default file mode is text but an application can override it. -Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 -*/ + Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 + */ #if defined(WIN32) || defined(MSDOS) #define FOPEN_READTEXT "rt" #define FOPEN_WRITETEXT "wt" #define FOPEN_APPENDTEXT "at" #elif defined(__CYGWIN__) /* Cygwin has specific behavior we need to address when WIN32 is not defined. -https://cygwin.com/cygwin-ug-net/using-textbinary.html -For write we want our output to have line endings of LF and be compatible with -other Cygwin utilities. For read we want to handle input that may have line -endings either CRLF or LF so 't' is appropriate. -*/ + https://cygwin.com/cygwin-ug-net/using-textbinary.html + For write we want our output to have line endings of LF and be compatible with + other Cygwin utilities. For read we want to handle input that may have line + endings either CRLF or LF so 't' is appropriate. + */ #define FOPEN_READTEXT "rt" #define FOPEN_WRITETEXT "w" #define FOPEN_APPENDTEXT "a" From 55dfb7e051966a0579f6843e9332619ea20bf17c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 18:33:17 +0000 Subject: [PATCH 326/424] libssh2_priv.h: fix checksrc warning [ci skip] Regression from 9ef75298fae0728305d9d38ba1e3c838ad0513f7 --- src/libssh2_priv.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 7a2de85b13..b3b651797e 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -1212,9 +1212,9 @@ size_t plain_method(char *method, size_t method_len); #elif defined(__CYGWIN__) /* Cygwin has specific behavior we need to address when WIN32 is not defined. https://cygwin.com/cygwin-ug-net/using-textbinary.html - For write we want our output to have line endings of LF and be compatible with - other Cygwin utilities. For read we want to handle input that may have line - endings either CRLF or LF so 't' is appropriate. + For write we want our output to have line endings of LF and be compatible + with other Cygwin utilities. For read we want to handle input that may have + line endings either CRLF or LF so 't' is appropriate. */ #define FOPEN_READTEXT "rt" #define FOPEN_WRITETEXT "w" From e53aae0e16dbf53ddd1a4fcfc50e365a15fcb8b9 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 17:46:45 +0000 Subject: [PATCH 327/424] tidy-up: `gettimeofday()` fallback and use Simplify the way we handle `gettimeofday()` fallback for platforms without native support or without any support. Make it similar to how we handle `snprintf()`. In case of no native `gettimeofday()` support and a non-Windows platform, our local fallback returns zero in `tv_usec` and `tv_sec`, ending up with a zero `timeout_remaining` in `session.c`, same as before this patch. Also: - drop unused `sys/time.h` headers. - fix our fallback code to compile with any Windows compilers (not just MSVC) - delete unnecessary casts. Closes #1001 --- example/direct_tcpip.c | 3 --- example/scp_write_nonblock.c | 3 --- example/sftp_RW_nonblock.c | 3 --- example/sftp_write_nonblock.c | 3 --- example/sftp_write_sliding.c | 3 --- example/ssh2_agent_forwarding.c | 3 --- example/ssh2_echo.c | 3 --- example/ssh2_exec.c | 3 --- example/tcpip-forward.c | 3 --- example/x11.c | 3 --- src/libssh2_priv.h | 13 ++++++++++-- src/misc.c | 36 ++++++++++++++++----------------- src/misc.h | 13 ------------ src/packet.c | 4 ---- src/session.c | 28 +++++-------------------- 15 files changed, 34 insertions(+), 90 deletions(-) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 34fecd3c02..1d9b041a04 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -22,9 +22,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 7a2754eedb..2cc176c2b9 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -20,9 +20,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 22fceb73ee..023aefbdbc 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -27,9 +27,6 @@ #ifdef HAVE_NETINET_IN_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 5c662f8303..958084b7ba 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -26,9 +26,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 15cca39c72..b8169002f8 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -26,9 +26,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 3583daaa5f..8718e885af 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -29,9 +29,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index f918a1cc80..1fa87b7ad8 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -24,9 +24,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 4c368bf3a0..d180f62daf 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -26,9 +26,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index 874ff51f31..a0b1cd69ba 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -22,9 +22,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #include #include diff --git a/example/x11.c b/example/x11.c index 87d1aa3b73..6254519f57 100644 --- a/example/x11.c +++ b/example/x11.c @@ -29,9 +29,6 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #ifdef HAVE_SYS_UN_H #include #endif diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index b3b651797e..70c2ee4781 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -64,7 +64,6 @@ # ifdef HAVE_SYS_SELECT_H # include # else -# include # include # endif # endif @@ -112,12 +111,22 @@ /* Use local implementation when not available */ #if !defined(HAVE_SNPRINTF) -#define LIBSSH2_SNPRINTF #undef snprintf #define snprintf _libssh2_snprintf +#define LIBSSH2_SNPRINTF int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...); #endif +#if !defined(HAVE_GETTIMEOFDAY) +#define HAVE_GETTIMEOFDAY +#undef gettimeofday +#define gettimeofday _libssh2_gettimeofday +#define LIBSSH2_GETTIMEOFDAY +int _libssh2_gettimeofday(struct timeval *tp, void *tzp); +#elif defined(HAVE_SYS_TIME_H) +#include +#endif + /* "inline" keyword is valid only with C++ engine! */ #ifdef __GNUC__ #undef inline diff --git a/src/misc.c b/src/misc.c index c7ec0ffe08..8151eab77c 100644 --- a/src/misc.c +++ b/src/misc.c @@ -46,10 +46,6 @@ #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif - #ifdef WIN32 /* Force parameter type. */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) @@ -533,7 +529,7 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, } } - _libssh2_gettimeofday(&now, NULL); + gettimeofday(&now, NULL); if(!firstsec) { firstsec = now.tv_sec; } @@ -672,8 +668,8 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */ #endif -/* this define is defined in misc.h for the correct platforms */ -#ifdef LIBSSH2_GETTIMEOFDAY_WIN32 +/* Defined in libssh2_priv.h for the correct platforms */ +#ifdef LIBSSH2_GETTIMEOFDAY /* * _libssh2_gettimeofday * Implementation according to: @@ -696,27 +692,31 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */ * Danny Smith */ -/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */ -#define _W32_FT_OFFSET (116444736000000000) - -int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp) +int _libssh2_gettimeofday(struct timeval *tp, void *tzp) { - union { - unsigned __int64 ns100; /* time since 1 Jan 1601 in 100ns units */ - FILETIME ft; - } _now; (void)tzp; if(tp) { +#ifdef WIN32 + /* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */ + #define _WIN32_FT_OFFSET (116444736000000000) + + union { + libssh2_uint64_t ns100; /* time since 1 Jan 1601 in 100ns units */ + FILETIME ft; + } _now; GetSystemTimeAsFileTime(&_now.ft); tp->tv_usec = (long)((_now.ns100 / 10) % 1000000); - tp->tv_sec = (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000); + tp->tv_sec = (long)((_now.ns100 - _WIN32_FT_OFFSET) / 10000000); +#else + /* Platforms without a native implementation or local replacement */ + tp->tv_usec = 0; + tp->tv_sec = 0; +#endif } /* Always return 0 as per Open Group Base Specifications Issue 6. Do not set errno on error. */ return 0; } - - #endif void *_libssh2_calloc(LIBSSH2_SESSION* session, size_t size) diff --git a/src/misc.h b/src/misc.h index 579b7ce84d..d8a26c87c8 100644 --- a/src/misc.h +++ b/src/misc.h @@ -131,19 +131,6 @@ int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf, int _libssh2_check_length(struct string_buf *buf, size_t requested_len); int _libssh2_eob(struct string_buf *buf); -#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) -/* provide a private one */ -#undef HAVE_GETTIMEOFDAY -int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp); -#define HAVE_LIBSSH2_GETTIMEOFDAY -#define LIBSSH2_GETTIMEOFDAY_WIN32 /* enable the win32 implementation */ -#else -#ifdef HAVE_GETTIMEOFDAY -#define _libssh2_gettimeofday(x,y) gettimeofday(x,y) -#define HAVE_LIBSSH2_GETTIMEOFDAY -#endif -#endif - void _libssh2_xor_data(unsigned char *output, const unsigned char *input1, const unsigned char *input2, diff --git a/src/packet.c b/src/packet.c index 33efad8f44..2bf37a20bf 100644 --- a/src/packet.c +++ b/src/packet.c @@ -46,10 +46,6 @@ #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif - #ifdef HAVE_INTTYPES_H #include #endif diff --git a/src/session.c b/src/session.c index a96c9d88c8..7b1f6828d5 100644 --- a/src/session.c +++ b/src/session.c @@ -50,9 +50,6 @@ #include #include -#ifdef HAVE_GETTIMEOFDAY -#include -#endif #ifdef HAVE_ALLOCA_H #include #endif @@ -1721,23 +1718,15 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) } #ifdef HAVE_POLL -#ifdef HAVE_LIBSSH2_GETTIMEOFDAY { struct timeval tv_begin, tv_end; - _libssh2_gettimeofday((struct timeval *) &tv_begin, NULL); + gettimeofday(&tv_begin, NULL); sysret = poll(sockets, nfds, (int)timeout_remaining); - _libssh2_gettimeofday((struct timeval *) &tv_end, NULL); + gettimeofday(&tv_end, NULL); timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000; timeout_remaining -= (tv_end.tv_usec - tv_begin.tv_usec) / 1000; } -#else - /* If the platform doesn't support gettimeofday, - * then just make the call non-blocking and walk away - */ - sysret = poll(sockets, nfds, (int)timeout_remaining); - timeout_remaining = 0; -#endif /* HAVE_LIBSSH2_GETTIMEOFDAY */ if(sysret > 0) { for(i = 0; i < nfds; i++) { @@ -1784,24 +1773,17 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) #elif defined(HAVE_SELECT) tv.tv_sec = timeout_remaining / 1000; tv.tv_usec = (timeout_remaining % 1000) * 1000; -#ifdef HAVE_LIBSSH2_GETTIMEOFDAY + { struct timeval tv_begin, tv_end; - _libssh2_gettimeofday((struct timeval *) &tv_begin, NULL); + gettimeofday(&tv_begin, NULL); sysret = select((int)(maxfd + 1), &rfds, &wfds, NULL, &tv); - _libssh2_gettimeofday((struct timeval *) &tv_end, NULL); + gettimeofday(&tv_end, NULL); timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000; timeout_remaining -= (tv_end.tv_usec - tv_begin.tv_usec) / 1000; } -#else - /* If the platform doesn't support gettimeofday, - * then just make the call non-blocking and walk away - */ - sysret = select((int)(maxfd + 1), &rfds, &wfds, NULL, &tv); - timeout_remaining = 0; -#endif if(sysret > 0) { for(i = 0; i < nfds; i++) { From 5981bcb19bd17d35867cd7f367ed6ad7adaa3bf8 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Wed, 26 Apr 2023 08:50:50 -0400 Subject: [PATCH 328/424] fix a couple of small regressions (#1004) - openssl: fix potentially missing `ERR_*` constants by including `openssl/err.h`. This could happen with recent version of Xcode or when building against OpenSSL built with the `OPENSSL_NO_ENGINE` option. Regression from 097c8f0dae558643d43051947a1c35b65e1c5761 (#789) - channel: fix an issue that would corrupt the data stream when attempting to initialize the agent in non-blocking mode, as it is necessary to propagate the `EAGAIN` signal upstream when the transport returns `EAGAIN`. Regression from bc4e619e76071393e466c29220fc4ef5764c2820 (#752) - packet: the current code does not set the state machine upon reaching this point which means that if the code is suspended due to the transport returning an `EAGAIN`, this will re-initialize the structure every time. The issue is that this keeps assigning a new channel-id downstream, which does not match the initial channel-id that is initially generated, causing a lookup later to fail as there is no matching channel. Regression from bc4e619e76071393e466c29220fc4ef5764c2820 (#752) --- src/channel.c | 1 + src/openssl.h | 1 + src/packet.c | 1 + 3 files changed, 3 insertions(+) diff --git a/src/channel.c b/src/channel.c index 1c119cfc63..8aee7b5267 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1165,6 +1165,7 @@ static int channel_request_auth_agent(LIBSSH2_CHANNEL *channel, if(rc == LIBSSH2_ERROR_EAGAIN) { _libssh2_error(session, rc, "Would block sending auth-agent request"); + return rc; } else if(rc) { channel->req_auth_agent_state = libssh2_NB_state_idle; diff --git a/src/openssl.h b/src/openssl.h index 1487af1133..9b729632fb 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -89,6 +89,7 @@ #ifndef OPENSSL_NO_MD5 #include #endif +#include #include #include #include diff --git a/src/packet.c b/src/packet.c index 2bf37a20bf..9023f3bf83 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1208,6 +1208,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, sizeof(session->packAdd_authagent_state)); libssh2_packet_add_jump_authagent: + session->packAdd_state = libssh2_NB_state_jumpauthagent; rc = packet_authagent_open(session, data, datalen, &session->packAdd_authagent_state); } From 5db836b2a829c6fff1e8c7acaa4b21b246ae1757 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 25 Apr 2023 19:15:00 +0000 Subject: [PATCH 329/424] libssh2_priv.h: assume `HAVE_LONGLONG` Unless I'm missing something, it looks like `libssh2.h` has been using `libssh2_int64_t` unconditionally since at least 2010-04-17 when `libssh2_scp_send64()` landed via commit be9ee7095e2d5021985f57d88f5f889d3c2b9d8f. This makes it redundant to detect `HAVE_LONGLONG` to fallback to a 32-bit `scpRecv_size` in `libssh2_priv.h`. Then deal with possible combinations of this flag and `strtoll()` options, which was error-prone. Instead, assume in `libssh2_priv.h` that we have `libssh2_int64_t`, and use it always. For MSVC, this means `_MSC_VER` `1310` (from year 2003) is now required. Based on the above, this was already so before this patch. If there happens to be no 64-bit `strtoll()` detected, fall back to the 32-bit `strtol()` (this should never happen with MSVC, and probably neither with any other reasonably modern toolchain.) Also make sure to set `HAVE_STRTOI64` for older, non-CMake, MSVC builds (e.g. `Makefile.mk` or `NMakefile` ones). Closes #1002 --- CMakeLists.txt | 3 --- configure.ac | 6 ------ os400/libssh2_config.h | 3 --- src/libssh2_config_cmake.h.in | 3 --- src/libssh2_priv.h | 20 +++++++++----------- src/libssh2_setup.h | 6 ++---- 6 files changed, 11 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c211382cfa..c3d742c157 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ include(CheckFunctionExists) include(CheckSymbolExists) include(CheckIncludeFiles) -include(CheckTypeSize) include(CheckSymbolExists) include(CMakePushCheckState) @@ -154,8 +153,6 @@ if(NOT WIN32) check_include_files(netinet/in.h HAVE_NETINET_IN_H) # example and tests endif() -check_type_size("long long" LONGLONG) - # CMake uses C syntax in check_symbol_exists() that generates a warning with # MSVC. To not break detection with ENABLE_WERRROR, we disable it for the # duration of these tests. diff --git a/configure.ac b/configure.ac index fdbf80d5ed..466193cfd9 100644 --- a/configure.ac +++ b/configure.ac @@ -47,12 +47,6 @@ case "$host" in ;; esac -AC_CHECK_TYPE(long long, - [AC_DEFINE(HAVE_LONGLONG, 1, - [Define to 1 if the compiler supports the 'long long' data type.])] - longlong="yes" -) - dnl Our configure and build reentrant settings CURL_CONFIGURE_REENTRANT diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index 186187ffa2..d137b41a93 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -74,9 +74,6 @@ /* Define if you have the gcrypt library. */ #undef HAVE_LIBGCRYPT -/* Define to 1 if the compiler supports the 'long long' data type. */ -#define HAVE_LONGLONG 1 - /* Define to 1 if you have the header file. */ #define HAVE_NETINET_IN_H 1 diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index 58dfa6b8ff..5de5c58c3a 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -50,9 +50,6 @@ #cmakedefine HAVE_ARPA_INET_H #cmakedefine HAVE_NETINET_IN_H -/* Types */ -#cmakedefine HAVE_LONGLONG - /* Functions */ #cmakedefine HAVE_GETTIMEOFDAY #cmakedefine HAVE_STRTOLL diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 70c2ee4781..49b2095d35 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -891,17 +891,7 @@ struct _LIBSSH2_SESSION unsigned char scpRecv_response[LIBSSH2_SCP_RESPONSE_BUFLEN]; size_t scpRecv_response_len; long scpRecv_mode; -#if defined(HAVE_LONGLONG) && defined(HAVE_STRTOLL) - /* we have the type and we can parse such numbers */ - long long scpRecv_size; -#define scpsize_strtol strtoll -#elif defined(HAVE_STRTOI64) - __int64 scpRecv_size; -#define scpsize_strtol _strtoi64 -#else - long scpRecv_size; -#define scpsize_strtol strtol -#endif + libssh2_int64_t scpRecv_size; long scpRecv_mtime; long scpRecv_atime; LIBSSH2_CHANNEL *scpRecv_channel; @@ -923,6 +913,14 @@ struct _LIBSSH2_SESSION long packet_read_timeout; }; +#if defined(HAVE_STRTOLL) +#define scpsize_strtol strtoll +#elif defined(HAVE_STRTOI64) +#define scpsize_strtol _strtoi64 +#else +#define scpsize_strtol strtol +#endif + /* session.state bits */ #define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000001 #define LIBSSH2_STATE_NEWKEYS 0x00000002 diff --git a/src/libssh2_setup.h b/src/libssh2_setup.h index 48ebe20a32..b3b4ab508f 100644 --- a/src/libssh2_setup.h +++ b/src/libssh2_setup.h @@ -31,14 +31,12 @@ # define HAVE_SYS_TIME_H # define HAVE_SYS_PARAM_H # define HAVE_GETTIMEOFDAY -# define HAVE_LONGLONG # define HAVE_STRTOLL #elif defined(_MSC_VER) -# if _MSC_VER >= 1310 -# define HAVE_LONGLONG -# endif # if _MSC_VER >= 1800 # define HAVE_STRTOLL +# else +# define HAVE_STRTOI64 # endif # if _MSC_VER < 1900 # undef HAVE_SNPRINTF From 2c18b6fc8df060c770fa7e5da704c32cf40a5757 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 09:57:49 +0000 Subject: [PATCH 330/424] build: fix `make distcheck` regressions - add #included C files to `EXTRA_DIST`. Regression from 4f0f4bff5a92dce6a6cd7a5600a8ee5660402c3f - fix `tests/sshd_fixture.sh` to not write into the test dir, by using a pre-assembled `TrustedUserCAKeys` file. Update `Dockerfile` too to use this. Regression from a459a25302a31f6e2aba3c4e15b1472b83b596fc Also update `tests/sshd_fixture.sh` to use `openssh_server/authorized_keys` like `Dockerfile` does. And a few more cosmetic updates. Closes #1006 --- src/Makefile.am | 5 +++-- src/Makefile.inc | 8 ++++++++ tests/Makefile.am | 1 + tests/gen_keys.sh | 11 +++++++++-- tests/openssh_server/Dockerfile | 20 ++++++++++---------- tests/openssh_server/ca_user_keys.pub | 2 ++ tests/sshd_fixture.sh | 11 ++--------- 7 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 tests/openssh_server/ca_user_keys.pub diff --git a/src/Makefile.am b/src/Makefile.am index ed6cfa2eac..cb7ecb0460 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign nostdinc -# Get the CSOURCES and HHEADERS defines +# Get the CSOURCES, HHEADERS and EXTRA_DIST_SOURCES defines include Makefile.inc libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS) @@ -8,7 +8,8 @@ if HAVE_WINDRES libssh2_la_SOURCES += libssh2.rc endif -EXTRA_DIST = libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt +EXTRA_DIST = $(EXTRA_DIST_SOURCES) \ + libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt lib_LTLIBRARIES = libssh2.la diff --git a/src/Makefile.inc b/src/Makefile.inc index 1614271ea6..19c07e195c 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -44,3 +44,11 @@ HHEADERS = \ userauth.h \ userauth_kbd_packet.h \ wincng.h + +EXTRA_DIST_SOURCES = \ + blowfish.c \ + libgcrypt.c \ + mbedtls.c \ + openssl.c \ + os400qc3.c \ + wincng.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 3803c0765b..7e29a9cfe0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -113,6 +113,7 @@ EXTRA_DIST = \ openssh_server/ca_ecdsa.pub \ openssh_server/ca_rsa \ openssh_server/ca_rsa.pub \ + openssh_server/ca_user_keys.pub \ openssh_server/ssh_host_ecdsa_key \ openssh_server/ssh_host_ed25519_key \ openssh_server/ssh_host_rsa_key \ diff --git a/tests/gen_keys.sh b/tests/gen_keys.sh index 23c5e63486..ea82857c17 100755 --- a/tests/gen_keys.sh +++ b/tests/gen_keys.sh @@ -1,4 +1,6 @@ -#!/bin/sh -e +#!/bin/sh + +set -e # Generate test keys @@ -47,7 +49,12 @@ cat \ 'key_ed25519.pub' \ 'key_ed25519_encrypted.pub' \ 'key_ecdsa.pub' \ - > openssh_server/authorized_keys + > 'openssh_server/authorized_keys' + +cat \ + 'openssh_server/ca_ecdsa.pub' \ + 'openssh_server/ca_rsa.pub' \ + > 'openssh_server/ca_user_keys.pub' # tests/test_*.c diff --git a/tests/openssh_server/Dockerfile b/tests/openssh_server/Dockerfile index 4283ace96c..f75e206f06 100644 --- a/tests/openssh_server/Dockerfile +++ b/tests/openssh_server/Dockerfile @@ -46,6 +46,8 @@ RUN mkdir /var/run/sshd # # Copying to a temp location, then moving because chmodding the copied file has # no effect (Docker AUFS-related bug maybe?) + +# Host keys COPY ssh_host_rsa_key /tmp/etc/ssh/ssh_host_rsa_key RUN mv /tmp/etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key RUN chmod 600 /etc/ssh/ssh_host_rsa_key @@ -58,30 +60,28 @@ COPY ssh_host_ed25519_key /tmp/etc/ssh/ssh_host_ed25519_key RUN mv /tmp/etc/ssh/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key RUN chmod 600 /etc/ssh/ssh_host_ed25519_key -COPY ca_ecdsa.pub /tmp/etc/ssh/ca_ecdsa.pub -RUN mv /tmp/etc/ssh/ca_ecdsa.pub /etc/ssh/ca_ecdsa.pub -RUN cp /etc/ssh/ca_ecdsa.pub /etc/ssh/ca_main.pub -RUN chmod 600 /etc/ssh/ca_main.pub - +# Trusted CA keys COPY ca_ecdsa /tmp/etc/ssh/ca_ecdsa RUN mv /tmp/etc/ssh/ca_ecdsa /etc/ssh/ca_ecdsa RUN chmod 600 /etc/ssh/ca_ecdsa -COPY ca_rsa.pub /tmp/etc/ssh/ca_rsa.pub -RUN mv /tmp/etc/ssh/ca_rsa.pub /etc/ssh/ca_rsa.pub -RUN cat /etc/ssh/ca_rsa.pub >> /etc/ssh/ca_main.pub - COPY ca_rsa /tmp/etc/ssh/ca_rsa RUN mv /tmp/etc/ssh/ca_rsa /etc/ssh/ca_rsa RUN chmod 600 /etc/ssh/ca_rsa +COPY ca_user_keys.pub /tmp/etc/ssh/ca_user_keys.pub +RUN cp /tmp/etc/ssh/ca_user_keys.pub /etc/ssh/ca_user_keys.pub +RUN chmod 600 /etc/ssh/ca_user_keys.pub + +# User RUN adduser --disabled-password --gecos 'Test user for libssh2 integration tests' libssh2 RUN echo 'libssh2:my test password' | chpasswd +# Config RUN sed -i 's/KbdInteractiveAuthentication no/KbdInteractiveAuthentication yes/' /etc/ssh/sshd_config COPY sshd_config /tmp/etc/ssh/sshd_config RUN cat /tmp/etc/ssh/sshd_config >> /etc/ssh/sshd_config -RUN echo "TrustedUserCAKeys /etc/ssh/ca_main.pub" >> /etc/ssh/sshd_config +RUN echo "TrustedUserCAKeys /etc/ssh/ca_user_keys.pub" >> /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login diff --git a/tests/openssh_server/ca_user_keys.pub b/tests/openssh_server/ca_user_keys.pub new file mode 100644 index 0000000000..19ec03f3c9 --- /dev/null +++ b/tests/openssh_server/ca_user_keys.pub @@ -0,0 +1,2 @@ +ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBAB+/Xmz4bbGDnon5q50oAzgb2o5MWttlGjQJPC+Rv+get/3/ZFJapizH/SbmZgJlWV5ydmrBEcA6iVdtz9hvhwaOwAtSPdQOKuydhHtV75LCe6eSm9b8fdr3ywDexL4cKl3lFul9YKVIE4j0kQCU+1LUKsRDsSY7uGaUU4fZwvSp8cLJg== CA +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDEiBsRlsihCg0nJGNqURhszCZw1FwZmDpkD64L6HFf2U/GFXFgDBtYJZ8zdgua+RA9F/QNhq14OUemJX39HggAox/Acwg1vKPm6WPYAb3DMyzXT4ws32SbFd5ld/sQrqJUeMxaFLu1f02eY0UttQe4+nMjoM4Me98Qho7TzgpDIgn9nls42Sjt6KM9muqTBIVv4USwi9IsFn+54e0CEjfgiFyU8/8bH6vp1rtMPA6m4vuidyt2pP7PHFnUnikQGsaG4ldO/D/G0FFtMqPXeC1wQXI5RHnRns9TiI6Ep3r3h64ZI5iBYZeG16Fk+nuGvtp+WLWE5m01vfEHc5o+p09j+Ni1mQ5pmUq3AOM/MZMh+eCkTstnCyng/bHEZTIKQi1nnu694Mcq8W1v34wgMyBN3bvE65NhjIdLubnHvDgzVn127wjPEdeVD9ShtACxNS4a6xJCWg6llHVyzezqnj68umXre02MsXLbFikV/fEvUOXUp/rDeo+LJizk2bHAlyk= ca_rsa diff --git a/tests/sshd_fixture.sh b/tests/sshd_fixture.sh index 5d8969db4f..539a62509a 100755 --- a/tests/sshd_fixture.sh +++ b/tests/sshd_fixture.sh @@ -20,17 +20,12 @@ SSHD="${SSHD:-/usr/sbin/sshd}" # for our test clients: [ -z "${PRIVKEY}" ] && export PRIVKEY="${d}/key_rsa" [ -z "${PUBKEY}" ] && export PUBKEY="${d}/key_rsa.pub" -cakeys="${d}/ca_main.pub" +cakeys="${d}/openssh_server/ca_user_keys.pub" if [ -n "${DEBUG}" ]; then libssh2_sshd_params="-d -d" fi -cat \ - "${d}/openssh_server/ca_ecdsa.pub" \ - "${d}/openssh_server/ca_rsa.pub" \ - > "${cakeys}" - chmod go-rwx \ "${d}"/openssh_server/ssh_host_* \ "${cakeys}" @@ -44,7 +39,7 @@ export OPENSSH_NO_DOCKER=1 -h "${d}/openssh_server/ssh_host_rsa_key" \ -h "${d}/openssh_server/ssh_host_ecdsa_key" \ -h "${d}/openssh_server/ssh_host_ed25519_key" \ - -o "AuthorizedKeysFile ${PUBKEY} ${d}/key_dsa.pub ${d}/key_rsa.pub ${d}/key_rsa_encrypted.pub ${d}/key_rsa_openssh.pub ${d}/key_ed25519.pub ${d}/key_ed25519_encrypted.pub ${d}/key_ecdsa.pub" \ + -o "AuthorizedKeysFile ${PUBKEY} ${d}/openssh_server/authorized_keys" \ -o "TrustedUserCAKeys ${cakeys}" \ -D \ ${libssh2_sshd_params} & @@ -65,8 +60,6 @@ eval "${cmd}" ec=$? : "Self-test exit code ${ec}" -rm -f "${cakeys}" - : "killing sshd (${sshdpid})" kill "${sshdpid}" > /dev/null 2>&1 trap '' EXIT From 6c6bf4e5c004243a8d08e6a46a050b3bf063888f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 13:00:39 +0000 Subject: [PATCH 331/424] vms: fix to include `sys/socket.h` Due to a typo in the `HAVE_*` macro, this header was never included. A comment suggests that `socklen_t` is not defined on VMS and defines it manually. This symbol is usually in `sys/socket.h`, so the typo may have been the reason for it to be missing. Closes #1007 --- vms/libssh2_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vms/libssh2_config.h b/vms/libssh2_config.h index 9eac4d71e8..34d66c3b47 100644 --- a/vms/libssh2_config.h +++ b/vms/libssh2_config.h @@ -19,7 +19,7 @@ typedef unsigned int socklen_t; /* missing in headers on VMS */ #define HAVE_SELECT #define HAVE_UIO -#define HAVE_SYS_SOCKET.H +#define HAVE_SYS_SOCKET_H #define HAVE_NETINET_IN_H #define HAVE_ARPA_INET_H From d7bec41df3d4c5bef66c75b82b9c80ffdd93f3ab Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 17:55:27 +0000 Subject: [PATCH 332/424] tidy-up: formatting nits [ci skip] --- docs/libssh2_trace_sethandler.3 | 4 ++-- src/wincng.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/libssh2_trace_sethandler.3 b/docs/libssh2_trace_sethandler.3 index badf23321f..03eada56d5 100644 --- a/docs/libssh2_trace_sethandler.3 +++ b/docs/libssh2_trace_sethandler.3 @@ -6,13 +6,13 @@ libssh2_trace_sethandler - set a trace output handler #include typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION *session, - void* context, + void *context, const char *data, size_t length); int libssh2_trace_sethandler(LIBSSH2_SESSION *session, - void* context, + void *context, libssh2_trace_handler_func callback); .fi .SH DESCRIPTION diff --git a/src/wincng.c b/src/wincng.c index 3c842bc147..ae3c188945 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -1258,7 +1258,7 @@ _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, #if LIBSSH2_RSA_SHA2 int -_libssh2_wincng_rsa_sha2_verify(libssh2_rsa_ctx* rsa, +_libssh2_wincng_rsa_sha2_verify(libssh2_rsa_ctx *rsa, size_t hash_len, const unsigned char *sig, size_t sig_len, From 592e2b37fa79345e57e5c4152ec34bfc174c404b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 17:49:01 +0000 Subject: [PATCH 333/424] docs: simplify `.TH` header & other cleanups [ci skip] - simplify `.TH` headers. - delete empty lines before sections. - update template with an `AVAILABILITY` section. Left libssh2 version number in the `.TH` header for entries without an `AVAILABILITY` section, or where there was a different version number there. --- docs/libssh2_agent_connect.3 | 2 +- docs/libssh2_agent_disconnect.3 | 2 +- docs/libssh2_agent_free.3 | 2 +- docs/libssh2_agent_get_identity.3 | 2 +- docs/libssh2_agent_get_identity_path.3 | 2 +- docs/libssh2_agent_init.3 | 2 +- docs/libssh2_agent_list_identities.3 | 2 +- docs/libssh2_agent_set_identity_path.3 | 2 +- docs/libssh2_agent_sign.3 | 2 +- docs/libssh2_agent_userauth.3 | 2 +- docs/libssh2_banner_set.3 | 2 +- docs/libssh2_base64_decode.3 | 2 +- docs/libssh2_channel_close.3 | 5 +---- docs/libssh2_channel_direct_streamlocal_ex.3 | 3 +-- docs/libssh2_channel_direct_tcpip.3 | 2 +- docs/libssh2_channel_direct_tcpip_ex.3 | 3 +-- docs/libssh2_channel_eof.3 | 2 +- docs/libssh2_channel_exec.3 | 2 +- docs/libssh2_channel_flush.3 | 2 +- docs/libssh2_channel_flush_ex.3 | 3 +-- docs/libssh2_channel_flush_stderr.3 | 2 +- docs/libssh2_channel_forward_accept.3 | 2 +- docs/libssh2_channel_forward_cancel.3 | 5 +---- docs/libssh2_channel_forward_listen.3 | 2 +- docs/libssh2_channel_forward_listen_ex.3 | 2 +- docs/libssh2_channel_free.3 | 4 +--- docs/libssh2_channel_get_exit_signal.3 | 3 +-- docs/libssh2_channel_get_exit_status.3 | 3 +-- docs/libssh2_channel_handle_extended_data.3 | 2 +- docs/libssh2_channel_handle_extended_data2.3 | 4 +--- docs/libssh2_channel_ignore_extended_data.3 | 2 +- docs/libssh2_channel_open_ex.3 | 5 +---- docs/libssh2_channel_open_session.3 | 2 +- docs/libssh2_channel_process_startup.3 | 2 +- docs/libssh2_channel_read.3 | 2 +- docs/libssh2_channel_read_ex.3 | 3 +-- docs/libssh2_channel_read_stderr.3 | 2 +- docs/libssh2_channel_receive_window_adjust.3 | 2 +- docs/libssh2_channel_receive_window_adjust2.3 | 2 +- docs/libssh2_channel_request_auth_agent.3 | 3 +-- docs/libssh2_channel_request_pty.3 | 2 +- docs/libssh2_channel_request_pty_ex.3 | 2 +- docs/libssh2_channel_request_pty_size.3 | 2 +- docs/libssh2_channel_request_pty_size_ex.3 | 5 +---- docs/libssh2_channel_send_eof.3 | 5 +---- docs/libssh2_channel_set_blocking.3 | 2 +- docs/libssh2_channel_setenv.3 | 2 +- docs/libssh2_channel_setenv_ex.3 | 2 +- docs/libssh2_channel_shell.3 | 2 +- docs/libssh2_channel_signal_ex.3 | 4 +--- docs/libssh2_channel_subsystem.3 | 2 +- docs/libssh2_channel_wait_closed.3 | 2 +- docs/libssh2_channel_wait_eof.3 | 2 +- docs/libssh2_channel_window_read.3 | 2 +- docs/libssh2_channel_window_read_ex.3 | 3 +-- docs/libssh2_channel_window_write.3 | 2 +- docs/libssh2_channel_window_write_ex.3 | 3 +-- docs/libssh2_channel_write.3 | 2 +- docs/libssh2_channel_write_ex.3 | 2 +- docs/libssh2_channel_write_stderr.3 | 2 +- docs/libssh2_channel_x11_req.3 | 2 +- docs/libssh2_channel_x11_req_ex.3 | 5 +---- docs/libssh2_crypto_engine.3 | 2 +- docs/libssh2_exit.3 | 2 +- docs/libssh2_free.3 | 2 +- docs/libssh2_hostkey_hash.3 | 2 +- docs/libssh2_init.3 | 2 +- docs/libssh2_keepalive_config.3 | 2 +- docs/libssh2_keepalive_send.3 | 2 +- docs/libssh2_knownhost_add.3 | 2 +- docs/libssh2_knownhost_addc.3 | 2 +- docs/libssh2_knownhost_check.3 | 2 +- docs/libssh2_knownhost_checkp.3 | 2 +- docs/libssh2_knownhost_del.3 | 2 +- docs/libssh2_knownhost_free.3 | 2 +- docs/libssh2_knownhost_get.3 | 2 +- docs/libssh2_knownhost_init.3 | 2 +- docs/libssh2_knownhost_readfile.3 | 2 +- docs/libssh2_knownhost_readline.3 | 2 +- docs/libssh2_knownhost_writefile.3 | 2 +- docs/libssh2_knownhost_writeline.3 | 2 +- docs/libssh2_poll.3 | 2 +- docs/libssh2_poll_channel_read.3 | 2 +- docs/libssh2_publickey_add.3 | 2 +- docs/libssh2_publickey_add_ex.3 | 2 +- docs/libssh2_publickey_init.3 | 7 +++---- docs/libssh2_publickey_list_fetch.3 | 7 +++---- docs/libssh2_publickey_list_free.3 | 7 +++---- docs/libssh2_publickey_remove.3 | 2 +- docs/libssh2_publickey_remove_ex.3 | 7 +++---- docs/libssh2_publickey_shutdown.3 | 7 +++---- docs/libssh2_scp_recv.3 | 2 +- docs/libssh2_scp_recv2.3 | 2 +- docs/libssh2_scp_send.3 | 2 +- docs/libssh2_scp_send64.3 | 2 +- docs/libssh2_scp_send_ex.3 | 2 +- docs/libssh2_session_abstract.3 | 4 +--- docs/libssh2_session_banner_get.3 | 2 +- docs/libssh2_session_banner_set.3 | 2 +- docs/libssh2_session_block_directions.3 | 2 +- docs/libssh2_session_callback_set.3 | 2 +- docs/libssh2_session_disconnect.3 | 2 +- docs/libssh2_session_disconnect_ex.3 | 3 +-- docs/libssh2_session_flag.3 | 2 +- docs/libssh2_session_free.3 | 2 +- docs/libssh2_session_get_blocking.3 | 2 +- docs/libssh2_session_get_read_timeout.3 | 2 +- docs/libssh2_session_get_timeout.3 | 2 +- docs/libssh2_session_handshake.3 | 2 +- docs/libssh2_session_hostkey.3 | 2 +- docs/libssh2_session_init.3 | 2 +- docs/libssh2_session_init_ex.3 | 2 +- docs/libssh2_session_last_errno.3 | 4 +--- docs/libssh2_session_last_error.3 | 4 +--- docs/libssh2_session_method_pref.3 | 5 +---- docs/libssh2_session_methods.3 | 2 +- docs/libssh2_session_set_blocking.3 | 4 +--- docs/libssh2_session_set_last_error.3 | 5 +---- docs/libssh2_session_set_read_timeout.3 | 2 +- docs/libssh2_session_set_timeout.3 | 2 +- docs/libssh2_session_startup.3 | 3 +-- docs/libssh2_session_supported_algs.3 | 2 +- docs/libssh2_sftp_close.3 | 2 +- docs/libssh2_sftp_close_handle.3 | 5 +---- docs/libssh2_sftp_closedir.3 | 2 +- docs/libssh2_sftp_fsetstat.3 | 2 +- docs/libssh2_sftp_fstat.3 | 2 +- docs/libssh2_sftp_fstat_ex.3 | 2 +- docs/libssh2_sftp_fsync.3 | 4 +--- docs/libssh2_sftp_get_channel.3 | 2 +- docs/libssh2_sftp_init.3 | 2 +- docs/libssh2_sftp_last_error.3 | 4 +--- docs/libssh2_sftp_lstat.3 | 2 +- docs/libssh2_sftp_mkdir.3 | 2 +- docs/libssh2_sftp_mkdir_ex.3 | 2 +- docs/libssh2_sftp_open.3 | 2 +- docs/libssh2_sftp_open_ex.3 | 2 +- docs/libssh2_sftp_open_ex_r.3 | 4 +++- docs/libssh2_sftp_open_r.3 | 2 +- docs/libssh2_sftp_opendir.3 | 2 +- docs/libssh2_sftp_read.3 | 2 +- docs/libssh2_sftp_readdir.3 | 2 +- docs/libssh2_sftp_readdir_ex.3 | 2 +- docs/libssh2_sftp_readlink.3 | 2 +- docs/libssh2_sftp_realpath.3 | 2 +- docs/libssh2_sftp_rename.3 | 2 +- docs/libssh2_sftp_rename_ex.3 | 5 +---- docs/libssh2_sftp_rewind.3 | 2 +- docs/libssh2_sftp_rmdir.3 | 2 +- docs/libssh2_sftp_rmdir_ex.3 | 2 +- docs/libssh2_sftp_seek.3 | 2 +- docs/libssh2_sftp_seek64.3 | 2 +- docs/libssh2_sftp_setstat.3 | 2 +- docs/libssh2_sftp_shutdown.3 | 4 +--- docs/libssh2_sftp_stat.3 | 2 +- docs/libssh2_sftp_stat_ex.3 | 2 +- docs/libssh2_sftp_statvfs.3 | 4 +--- docs/libssh2_sftp_symlink.3 | 2 +- docs/libssh2_sftp_symlink_ex.3 | 3 +-- docs/libssh2_sftp_tell.3 | 2 +- docs/libssh2_sftp_tell64.3 | 2 +- docs/libssh2_sftp_unlink.3 | 2 +- docs/libssh2_sftp_unlink_ex.3 | 5 +---- docs/libssh2_sftp_write.3 | 3 +-- docs/libssh2_sign_sk.3 | 4 +--- docs/libssh2_trace.3 | 2 +- docs/libssh2_trace_sethandler.3 | 2 +- docs/libssh2_userauth_authenticated.3 | 4 +--- docs/libssh2_userauth_banner.3 | 2 +- docs/libssh2_userauth_hostbased_fromfile.3 | 2 +- docs/libssh2_userauth_hostbased_fromfile_ex.3 | 5 +---- docs/libssh2_userauth_keyboard_interactive.3 | 2 +- docs/libssh2_userauth_keyboard_interactive_ex.3 | 2 +- docs/libssh2_userauth_list.3 | 2 +- docs/libssh2_userauth_password.3 | 2 +- docs/libssh2_userauth_password_ex.3 | 4 +--- docs/libssh2_userauth_publickey.3 | 2 +- docs/libssh2_userauth_publickey_fromfile.3 | 2 +- docs/libssh2_userauth_publickey_fromfile_ex.3 | 5 +---- docs/libssh2_userauth_publickey_frommemory.3 | 2 +- docs/libssh2_userauth_publickey_sk.3 | 6 +++--- docs/libssh2_version.3 | 2 +- docs/template.3 | 7 +++---- 183 files changed, 199 insertions(+), 283 deletions(-) diff --git a/docs/libssh2_agent_connect.3 b/docs/libssh2_agent_connect.3 index 491ca06d5b..07c683ded3 100644 --- a/docs/libssh2_agent_connect.3 +++ b/docs/libssh2_agent_connect.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daiki Ueno .\" -.TH libssh2_agent_connect 3 "23 Dec 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_agent_connect 3 "23 Dec 2009" "libssh2" "libssh2" .SH NAME libssh2_agent_connect - connect to an ssh-agent .SH SYNOPSIS diff --git a/docs/libssh2_agent_disconnect.3 b/docs/libssh2_agent_disconnect.3 index 41eb1d40ab..b87a4b1b90 100644 --- a/docs/libssh2_agent_disconnect.3 +++ b/docs/libssh2_agent_disconnect.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daiki Ueno .\" -.TH libssh2_agent_disconnect 3 "23 Dec 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_agent_disconnect 3 "23 Dec 2009" "libssh2" "libssh2" .SH NAME libssh2_agent_disconnect - close a connection to an ssh-agent .SH SYNOPSIS diff --git a/docs/libssh2_agent_free.3 b/docs/libssh2_agent_free.3 index 2f18cc8d7b..3df9632a72 100644 --- a/docs/libssh2_agent_free.3 +++ b/docs/libssh2_agent_free.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daiki Ueno .\" -.TH libssh2_agent_free 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_agent_free 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_agent_free - free an ssh-agent handle .SH SYNOPSIS diff --git a/docs/libssh2_agent_get_identity.3 b/docs/libssh2_agent_get_identity.3 index c4a33fa9c5..0663ae6d1e 100644 --- a/docs/libssh2_agent_get_identity.3 +++ b/docs/libssh2_agent_get_identity.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daiki Ueno .\" -.TH libssh2_agent_get_identity 3 "23 Dec 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_agent_get_identity 3 "23 Dec 2009" "libssh2" "libssh2" .SH NAME libssh2_agent_get_identity - get a public key off the collection of public keys managed by ssh-agent .SH SYNOPSIS diff --git a/docs/libssh2_agent_get_identity_path.3 b/docs/libssh2_agent_get_identity_path.3 index 748995da9e..6b296ec757 100644 --- a/docs/libssh2_agent_get_identity_path.3 +++ b/docs/libssh2_agent_get_identity_path.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2019 by Will Cosgrove .\" -.TH libssh2_agent_get_identity_path 3 "6 Mar 2019" "libssh2 1.9" "libssh2 manual" +.TH libssh2_agent_get_identity_path 3 "6 Mar 2019" "libssh2" "libssh2" .SH NAME libssh2_agent_get_identity_path - gets the custom ssh-agent socket path .SH SYNOPSIS diff --git a/docs/libssh2_agent_init.3 b/docs/libssh2_agent_init.3 index 4b25508f35..352a73a77e 100644 --- a/docs/libssh2_agent_init.3 +++ b/docs/libssh2_agent_init.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daiki Ueno .\" -.TH libssh2_agent_init 3 "23 Dec 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_agent_init 3 "23 Dec 2009" "libssh2" "libssh2" .SH NAME libssh2_agent_init - init an ssh-agent handle .SH SYNOPSIS diff --git a/docs/libssh2_agent_list_identities.3 b/docs/libssh2_agent_list_identities.3 index e1d7c40dcd..4e1b3a786f 100644 --- a/docs/libssh2_agent_list_identities.3 +++ b/docs/libssh2_agent_list_identities.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daiki Ueno .\" -.TH libssh2_agent_list_identities 3 "23 Dec 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_agent_list_identities 3 "23 Dec 2009" "libssh2" "libssh2" .SH NAME libssh2_agent_list_identities - request an ssh-agent to list of public keys. .SH SYNOPSIS diff --git a/docs/libssh2_agent_set_identity_path.3 b/docs/libssh2_agent_set_identity_path.3 index 6ee425999a..6097bc4e5b 100644 --- a/docs/libssh2_agent_set_identity_path.3 +++ b/docs/libssh2_agent_set_identity_path.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2019 by Will Cosgrove .\" -.TH libssh2_agent_set_identity_path 3 "6 Mar 2019" "libssh2 1.9" "libssh2 manual" +.TH libssh2_agent_set_identity_path 3 "6 Mar 2019" "libssh2" "libssh2" .SH NAME libssh2_agent_set_identity_path - set an ssh-agent socket path on disk .SH SYNOPSIS diff --git a/docs/libssh2_agent_sign.3 b/docs/libssh2_agent_sign.3 index 670e5940ea..95bf44bb80 100644 --- a/docs/libssh2_agent_sign.3 +++ b/docs/libssh2_agent_sign.3 @@ -1,4 +1,4 @@ -.TH libssh2_agent_sign 3 "1 Oct 2022" "libssh2 1.11.0" "libssh2 manual" +.TH libssh2_agent_sign 3 "1 Oct 2022" "libssh2" "libssh2" .SH NAME libssh2_agent_sign - sign data, with the help of ssh-agent .SH SYNOPSIS diff --git a/docs/libssh2_agent_userauth.3 b/docs/libssh2_agent_userauth.3 index 0eeea004e6..b0e7796278 100644 --- a/docs/libssh2_agent_userauth.3 +++ b/docs/libssh2_agent_userauth.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daiki Ueno .\" -.TH libssh2_agent_userauth 3 "23 Dec 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_agent_userauth 3 "23 Dec 2009" "libssh2" "libssh2" .SH NAME libssh2_agent_userauth - authenticate a session with a public key, with the help of ssh-agent .SH SYNOPSIS diff --git a/docs/libssh2_banner_set.3 b/docs/libssh2_banner_set.3 index c6e874de73..c443d8f18e 100644 --- a/docs/libssh2_banner_set.3 +++ b/docs/libssh2_banner_set.3 @@ -1,4 +1,4 @@ -.TH libssh2_banner_set 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_banner_set 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_banner_set - set the SSH protocol banner for the local client .SH SYNOPSIS diff --git a/docs/libssh2_base64_decode.3 b/docs/libssh2_base64_decode.3 index c05fbec357..8856f220cd 100644 --- a/docs/libssh2_base64_decode.3 +++ b/docs/libssh2_base64_decode.3 @@ -1,4 +1,4 @@ -.TH libssh2_base64_decode 3 "23 Dec 2008" "libssh2 1.0" "libssh2 manual" +.TH libssh2_base64_decode 3 "23 Dec 2008" "libssh2 1.0" "libssh2" .SH NAME libssh2_base64_decode - decode a base64 encoded string .SH SYNOPSIS diff --git a/docs/libssh2_channel_close.3 b/docs/libssh2_channel_close.3 index 1c6ef6f90b..abc1619c48 100644 --- a/docs/libssh2_channel_close.3 +++ b/docs/libssh2_channel_close.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_close 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_close 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_close - close a channel .SH SYNOPSIS @@ -17,14 +17,11 @@ will be sent to it. The remote host may still send data back until it sends its own close message in response. To wait for the remote end to close its connection as well, follow this command with .BR libssh2_channel_wait_closed(3) - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. - .SH SEE ALSO .BR libssh2_channel_open_ex(3) diff --git a/docs/libssh2_channel_direct_streamlocal_ex.3 b/docs/libssh2_channel_direct_streamlocal_ex.3 index c28f68d7a9..f737afa01b 100644 --- a/docs/libssh2_channel_direct_streamlocal_ex.3 +++ b/docs/libssh2_channel_direct_streamlocal_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_direct_streamlocal_ex 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.TH libssh2_channel_direct_streamlocal_ex 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2" .SH NAME libssh2_channel_direct_streamlocal_ex - Tunnel a UNIX socket connection through an SSH session .SH SYNOPSIS @@ -24,7 +24,6 @@ Tunnel a UNIX socket connection through the SSH transport via the remote host to a third party. Communication from the client to the SSH server remains encrypted, communication from the server to the 3rd party host travels in cleartext. - .SH RETURN VALUE Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. .SH ERRORS diff --git a/docs/libssh2_channel_direct_tcpip.3 b/docs/libssh2_channel_direct_tcpip.3 index 81c495df62..45d2aca022 100644 --- a/docs/libssh2_channel_direct_tcpip.3 +++ b/docs/libssh2_channel_direct_tcpip.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_direct_tcpip 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_direct_tcpip 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_direct_tcpip - convenience macro for \fIlibssh2_channel_direct_tcpip_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_direct_tcpip_ex.3 b/docs/libssh2_channel_direct_tcpip_ex.3 index 229635991e..e22f400d4b 100644 --- a/docs/libssh2_channel_direct_tcpip_ex.3 +++ b/docs/libssh2_channel_direct_tcpip_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_direct_tcpip_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_direct_tcpip_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_direct_tcpip_ex - Tunnel a TCP connection through an SSH session .SH SYNOPSIS @@ -30,7 +30,6 @@ Tunnel a TCP/IP connection through the SSH transport via the remote host to a third party. Communication from the client to the SSH server remains encrypted, communication from the server to the 3rd party host travels in cleartext. - .SH RETURN VALUE Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. .SH ERRORS diff --git a/docs/libssh2_channel_eof.3 b/docs/libssh2_channel_eof.3 index d948eece17..94e3ebe315 100644 --- a/docs/libssh2_channel_eof.3 +++ b/docs/libssh2_channel_eof.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_eof 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_eof 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_eof - check a channel's EOF status .SH SYNOPSIS diff --git a/docs/libssh2_channel_exec.3 b/docs/libssh2_channel_exec.3 index 312372cd62..723fda4d02 100644 --- a/docs/libssh2_channel_exec.3 +++ b/docs/libssh2_channel_exec.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_exec 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_exec 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_exec - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_flush.3 b/docs/libssh2_channel_flush.3 index 3e9c4fd0cd..49bc03d753 100644 --- a/docs/libssh2_channel_flush.3 +++ b/docs/libssh2_channel_flush.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_flush 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_flush 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_flush - convenience macro for \fIlibssh2_channel_flush_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_flush_ex.3 b/docs/libssh2_channel_flush_ex.3 index af5c48d3a5..6e7b167e46 100644 --- a/docs/libssh2_channel_flush_ex.3 +++ b/docs/libssh2_channel_flush_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_flush_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_flush_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_flush_ex - flush a channel .SH SYNOPSIS @@ -26,7 +26,6 @@ be flushed by passing on of the following Constants. Flush the read buffer for a given channel instance. Individual substreams may be flushed by number or using one of the provided macros. - .SH RETURN VALUE Return the number of bytes flushed or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While diff --git a/docs/libssh2_channel_flush_stderr.3 b/docs/libssh2_channel_flush_stderr.3 index b211c1b133..c758351fa5 100644 --- a/docs/libssh2_channel_flush_stderr.3 +++ b/docs/libssh2_channel_flush_stderr.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_flush_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_flush_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_flush_stderr - convenience macro for \fIlibssh2_channel_flush_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_forward_accept.3 b/docs/libssh2_channel_forward_accept.3 index fdf82a85e8..7f78505d6f 100644 --- a/docs/libssh2_channel_forward_accept.3 +++ b/docs/libssh2_channel_forward_accept.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_forward_accept 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_forward_accept 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_forward_accept - accept a queued connection .SH SYNOPSIS diff --git a/docs/libssh2_channel_forward_cancel.3 b/docs/libssh2_channel_forward_cancel.3 index 5663c0ab7c..55cb287b7c 100644 --- a/docs/libssh2_channel_forward_cancel.3 +++ b/docs/libssh2_channel_forward_cancel.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_forward_cancel 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_forward_cancel 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_forward_cancel - cancel a forwarded TCP port .SH SYNOPSIS @@ -13,16 +13,13 @@ libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener); .BR libssh2_channel_forward_listen_ex(3) Instruct the remote host to stop listening for new connections on a previously requested host/port. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. - .SH SEE ALSO .BR libssh2_channel_forward_listen_ex(3) diff --git a/docs/libssh2_channel_forward_listen.3 b/docs/libssh2_channel_forward_listen.3 index a5494a6d9d..d471a7cfff 100644 --- a/docs/libssh2_channel_forward_listen.3 +++ b/docs/libssh2_channel_forward_listen.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_forward_listen 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_forward_listen 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_forward_listen - convenience macro for \fIlibssh2_channel_forward_listen_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_forward_listen_ex.3 b/docs/libssh2_channel_forward_listen_ex.3 index 14f598af7a..9852d0bd35 100644 --- a/docs/libssh2_channel_forward_listen_ex.3 +++ b/docs/libssh2_channel_forward_listen_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_forward_listen_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_forward_listen_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_forward_listen_ex - listen to inbound connections .SH SYNOPSIS diff --git a/docs/libssh2_channel_free.3 b/docs/libssh2_channel_free.3 index d0ded79856..8e63845efa 100644 --- a/docs/libssh2_channel_free.3 +++ b/docs/libssh2_channel_free.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_free 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_free 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_free - free all resources associated with a channel .SH SYNOPSIS @@ -16,11 +16,9 @@ not yet been closed with .BR libssh2_channel_close(3) , it will be called automatically so that the remote end may know that it can safely free its own resources. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH SEE ALSO .BR libssh2_channel_close(3) diff --git a/docs/libssh2_channel_get_exit_signal.3 b/docs/libssh2_channel_get_exit_signal.3 index d2b46c7193..2f74edcb72 100644 --- a/docs/libssh2_channel_get_exit_signal.3 +++ b/docs/libssh2_channel_get_exit_signal.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_get_exit_signal 3 "4 Oct 2010" "libssh2 1.2.8" "libssh2 manual" +.TH libssh2_channel_get_exit_signal 3 "4 Oct 2010" "libssh2 1.2.8" "libssh2" .SH NAME libssh2_channel_get_exit_signal - get the remote exit signal .SH SYNOPSIS @@ -33,6 +33,5 @@ string is stored in a newly allocated buffer. string is stored in a newly allocated buffer. \fIlangtag_len\fP - If not NULL, is populated by reference with the length of langtag. - .SH RETURN VALUE Numeric error code corresponding to the the Error Code constants. diff --git a/docs/libssh2_channel_get_exit_status.3 b/docs/libssh2_channel_get_exit_status.3 index e619bc8b96..3357bba39c 100644 --- a/docs/libssh2_channel_get_exit_status.3 +++ b/docs/libssh2_channel_get_exit_status.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_get_exit_status 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_get_exit_status 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_get_exit_status - get the remote exit code .SH SYNOPSIS @@ -14,6 +14,5 @@ libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel) Returns the exit code raised by the process running on the remote host at the other end of the named channel. Note that the exit status may not be available if the remote end has not yet set its status to closed. - .SH RETURN VALUE Returns 0 on failure, otherwise the \fIExit Status\fP reported by remote host diff --git a/docs/libssh2_channel_handle_extended_data.3 b/docs/libssh2_channel_handle_extended_data.3 index 8adc6cb923..5fe06bc76e 100644 --- a/docs/libssh2_channel_handle_extended_data.3 +++ b/docs/libssh2_channel_handle_extended_data.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_handle_extended_data 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_handle_extended_data 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_handle_extended_data - set extended data handling mode .SH SYNOPSIS diff --git a/docs/libssh2_channel_handle_extended_data2.3 b/docs/libssh2_channel_handle_extended_data2.3 index 0988873b3f..62c08281f5 100644 --- a/docs/libssh2_channel_handle_extended_data2.3 +++ b/docs/libssh2_channel_handle_extended_data2.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_handle_extended_data2 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_handle_extended_data2 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_handle_extended_data2 - set extended data handling mode .SH SYNOPSIS @@ -28,10 +28,8 @@ arrives. Change how a channel deals with extended data packets. By default all extended data is queued until read by .BR libssh2_channel_read_ex(3) - .SH RETURN VALUE Return 0 on success or LIBSSH2_ERROR_EAGAIN when it would otherwise block. - .SH SEE ALSO .BR libssh2_channel_handle_extended_data(3) .BR libssh2_channel_read_ex(3) diff --git a/docs/libssh2_channel_ignore_extended_data.3 b/docs/libssh2_channel_ignore_extended_data.3 index 5f49abbaf6..09ff25792d 100644 --- a/docs/libssh2_channel_ignore_extended_data.3 +++ b/docs/libssh2_channel_ignore_extended_data.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_ignore_extended_data 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_ignore_extended_data 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_ignore_extended_data - convenience macro for \fIlibssh2_channel_handle_extended_data(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_open_ex.3 b/docs/libssh2_channel_open_ex.3 index f978675e50..0b203c2c89 100644 --- a/docs/libssh2_channel_open_ex.3 +++ b/docs/libssh2_channel_open_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_open_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_open_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_open_ex - establish a generic session channel .SH SYNOPSIS @@ -42,10 +42,8 @@ or via .BR libssh2_channel_direct_tcpip(3) or .BR libssh2_channel_forward_listen(3) - .SH RETURN VALUE Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. - .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. @@ -54,6 +52,5 @@ Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors. \fILIBSSH2_ERROR_CHANNEL_FAILURE\fP - \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. - .SH SEE ALSO Add related functions diff --git a/docs/libssh2_channel_open_session.3 b/docs/libssh2_channel_open_session.3 index 83e5e6205e..f63c8c79d4 100644 --- a/docs/libssh2_channel_open_session.3 +++ b/docs/libssh2_channel_open_session.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_open_session 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_open_session 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_open_session - convenience macro for \fIlibssh2_channel_open_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_process_startup.3 b/docs/libssh2_channel_process_startup.3 index e1cf436ca2..1237e4896e 100644 --- a/docs/libssh2_channel_process_startup.3 +++ b/docs/libssh2_channel_process_startup.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_process_startup 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_process_startup 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_process_startup - request a shell on a channel .SH SYNOPSIS diff --git a/docs/libssh2_channel_read.3 b/docs/libssh2_channel_read.3 index 80966e2881..c7f72a6c53 100644 --- a/docs/libssh2_channel_read.3 +++ b/docs/libssh2_channel_read.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_read 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_read 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_read - convenience macro for \fIlibssh2_channel_read_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_read_ex.3 b/docs/libssh2_channel_read_ex.3 index 7f895999ee..fed03f90f0 100644 --- a/docs/libssh2_channel_read_ex.3 +++ b/docs/libssh2_channel_read_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_read_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_read_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_read_ex - read data from a channel stream .SH SYNOPSIS @@ -44,6 +44,5 @@ only signals that no payload data was read. It is not an error. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. \fILIBSSH2_ERROR_CHANNEL_CLOSED\fP - The channel has been closed. - .SH SEE ALSO .BR libssh2_poll_channel_read(3) diff --git a/docs/libssh2_channel_read_stderr.3 b/docs/libssh2_channel_read_stderr.3 index e23e47b406..ef1f8fe422 100644 --- a/docs/libssh2_channel_read_stderr.3 +++ b/docs/libssh2_channel_read_stderr.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_read_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_read_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_read_stderr - convenience macro for \fIlibssh2_channel_read_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_receive_window_adjust.3 b/docs/libssh2_channel_receive_window_adjust.3 index 731558fc2e..8f7c1d794b 100644 --- a/docs/libssh2_channel_receive_window_adjust.3 +++ b/docs/libssh2_channel_receive_window_adjust.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_receive_window_adjust 3 "15 Mar 2009" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_receive_window_adjust 3 "15 Mar 2009" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_receive_window_adjust - adjust the channel window .SH SYNOPSIS diff --git a/docs/libssh2_channel_receive_window_adjust2.3 b/docs/libssh2_channel_receive_window_adjust2.3 index e4681f78ee..777307bf60 100644 --- a/docs/libssh2_channel_receive_window_adjust2.3 +++ b/docs/libssh2_channel_receive_window_adjust2.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_receive_window_adjust2 3 "26 Mar 2009" "libssh2 1.1" "libssh2 manual" +.TH libssh2_channel_receive_window_adjust2 3 "26 Mar 2009" "libssh2 1.1" "libssh2" .SH NAME libssh2_channel_receive_window_adjust2 - adjust the channel window .SH SYNOPSIS diff --git a/docs/libssh2_channel_request_auth_agent.3 b/docs/libssh2_channel_request_auth_agent.3 index 22f988d697..8ac659722d 100644 --- a/docs/libssh2_channel_request_auth_agent.3 +++ b/docs/libssh2_channel_request_auth_agent.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_request_auth_agent 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_request_auth_agent 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_request_auth_agent - request agent forwarding for a session .SH SYNOPSIS @@ -16,7 +16,6 @@ for the duration of the SSH session. \fIchannel\fP - Previously opened channel instance such as returned by .BR libssh2_channel_open_ex(3) - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While diff --git a/docs/libssh2_channel_request_pty.3 b/docs/libssh2_channel_request_pty.3 index 4adb846a4b..06e9f4803d 100644 --- a/docs/libssh2_channel_request_pty.3 +++ b/docs/libssh2_channel_request_pty.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_request_pty 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_request_pty 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_request_pty - convenience macro for \fIlibssh2_channel_request_pty_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_request_pty_ex.3 b/docs/libssh2_channel_request_pty_ex.3 index 933cdf2f1e..4186da2ebb 100644 --- a/docs/libssh2_channel_request_pty_ex.3 +++ b/docs/libssh2_channel_request_pty_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_request_pty_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_request_pty_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_request_pty_ex - short function description .SH SYNOPSIS diff --git a/docs/libssh2_channel_request_pty_size.3 b/docs/libssh2_channel_request_pty_size.3 index fd58bd3636..347f640843 100644 --- a/docs/libssh2_channel_request_pty_size.3 +++ b/docs/libssh2_channel_request_pty_size.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_request_pty_size 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_request_pty_size 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_request_pty_size - convenience macro for \fIlibssh2_channel_request_pty_size_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_request_pty_size_ex.3 b/docs/libssh2_channel_request_pty_size_ex.3 index ca172a148a..0624c75281 100644 --- a/docs/libssh2_channel_request_pty_size_ex.3 +++ b/docs/libssh2_channel_request_pty_size_ex.3 @@ -1,13 +1,10 @@ -.TH libssh2_channel_request_pty_size_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_request_pty_size_ex 3 "1 Jun 2007" "libssh2" "libssh2" .SH NAME libssh2_channel_request_pty_size_ex - TODO .SH SYNOPSIS .nf .fi .SH DESCRIPTION - .SH RETURN VALUE - .SH ERRORS - .SH SEE ALSO diff --git a/docs/libssh2_channel_send_eof.3 b/docs/libssh2_channel_send_eof.3 index 6dc0286018..5e26b02679 100644 --- a/docs/libssh2_channel_send_eof.3 +++ b/docs/libssh2_channel_send_eof.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_send_eof 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_send_eof 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_send_eof - send EOF to remote server .SH SYNOPSIS @@ -11,15 +11,12 @@ libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel); .SH DESCRIPTION Tell the remote host that no further data will be sent on the specified channel. Processes typically interpret this as a closed stdin descriptor. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. - .SH SEE ALSO .BR libssh2_channel_wait_eof(3) .BR libssh2_channel_eof(3) diff --git a/docs/libssh2_channel_set_blocking.3 b/docs/libssh2_channel_set_blocking.3 index 4c61b14a83..18dd6067ad 100644 --- a/docs/libssh2_channel_set_blocking.3 +++ b/docs/libssh2_channel_set_blocking.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_set_blocking 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_set_blocking 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_set_blocking - set or clear blocking mode on channel .SH SYNOPSIS diff --git a/docs/libssh2_channel_setenv.3 b/docs/libssh2_channel_setenv.3 index e9d553b7e7..986eea3094 100644 --- a/docs/libssh2_channel_setenv.3 +++ b/docs/libssh2_channel_setenv.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_setenv 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_setenv 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_setenv - convenience macro for \fIlibssh2_channel_setenv_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_setenv_ex.3 b/docs/libssh2_channel_setenv_ex.3 index c01b94b059..57e8f9d2ec 100644 --- a/docs/libssh2_channel_setenv_ex.3 +++ b/docs/libssh2_channel_setenv_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_setenv_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_setenv_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_setenv_ex - set an environment variable on the channel .SH SYNOPSIS diff --git a/docs/libssh2_channel_shell.3 b/docs/libssh2_channel_shell.3 index bbff5b6963..22438ccc1e 100644 --- a/docs/libssh2_channel_shell.3 +++ b/docs/libssh2_channel_shell.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_shell 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_shell 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_shell - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_signal_ex.3 b/docs/libssh2_channel_signal_ex.3 index 236657e3b2..d54de0759c 100644 --- a/docs/libssh2_channel_signal_ex.3 +++ b/docs/libssh2_channel_signal_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_signal_ex 3 "20 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.TH libssh2_channel_signal_ex 3 "20 Apr 2023" "libssh2 1.11.0" "libssh2" .SH NAME libssh2_channel_signal_ex -- Send a signal to process previously opened on channel. .SH SYNOPSIS @@ -23,10 +23,8 @@ message. \fIsigname_len\fP - Length of passed signal name parameter. There is also a macro \fIlibssh2_channel_signal(channel, signame)\fP that supplies the strlen of the signame. - .SH RETURN VALUE Normal channel error codes. LIBSSH2_ERROR_EAGAIN when it would block. - .SH SEE ALSO .BR libssh2_channel_get_exit_signal(3) diff --git a/docs/libssh2_channel_subsystem.3 b/docs/libssh2_channel_subsystem.3 index 6f3b8bcd28..aecdbfb34b 100644 --- a/docs/libssh2_channel_subsystem.3 +++ b/docs/libssh2_channel_subsystem.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_subsystem 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_subsystem 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_subsystem - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_wait_closed.3 b/docs/libssh2_channel_wait_closed.3 index cbd242f994..4797b9c3cf 100644 --- a/docs/libssh2_channel_wait_closed.3 +++ b/docs/libssh2_channel_wait_closed.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_wait_closed 3 "29 Nov 2007" "libssh2 0.19" "libssh2 manual" +.TH libssh2_channel_wait_closed 3 "29 Nov 2007" "libssh2 0.19" "libssh2" .SH NAME libssh2_channel_wait_closed - wait for the remote to close the channel .SH SYNOPSIS diff --git a/docs/libssh2_channel_wait_eof.3 b/docs/libssh2_channel_wait_eof.3 index 777f9f55dd..44708bc962 100644 --- a/docs/libssh2_channel_wait_eof.3 +++ b/docs/libssh2_channel_wait_eof.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_wait_eof 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_wait_eof 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_wait_eof - wait for the remote to reply to an EOF request .SH SYNOPSIS diff --git a/docs/libssh2_channel_window_read.3 b/docs/libssh2_channel_window_read.3 index 41efb4c8cd..a4c00e012e 100644 --- a/docs/libssh2_channel_window_read.3 +++ b/docs/libssh2_channel_window_read.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_window_read 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_window_read 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_window_read - convenience macro for \fIlibssh2_channel_window_read_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_window_read_ex.3 b/docs/libssh2_channel_window_read_ex.3 index f5cdab35f2..cbb5dd30ac 100644 --- a/docs/libssh2_channel_window_read_ex.3 +++ b/docs/libssh2_channel_window_read_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_window_read_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_window_read_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_window_read_ex - Check the status of the read window .SH SYNOPSIS @@ -20,7 +20,6 @@ window_size_initial as defined by the channel_open request The number of bytes which the remote end may send without overflowing the window limit .SH ERRORS - .SH SEE ALSO .BR libssh2_channel_receive_window_adjust(3), .BR libssh2_channel_window_write_ex(3) diff --git a/docs/libssh2_channel_window_write.3 b/docs/libssh2_channel_window_write.3 index 61815eb0aa..80721b772c 100644 --- a/docs/libssh2_channel_window_write.3 +++ b/docs/libssh2_channel_window_write.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_window_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_window_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_window_write - convenience macro for \fIlibssh2_channel_window_write_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_window_write_ex.3 b/docs/libssh2_channel_window_write_ex.3 index 2803d5b890..13e02970c3 100644 --- a/docs/libssh2_channel_window_write_ex.3 +++ b/docs/libssh2_channel_window_write_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_window_write_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_window_write_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_window_write_ex - Check the status of the write window .SH SYNOPSIS @@ -17,7 +17,6 @@ the channel_open request .SH RETURN VALUE Number of bytes which may be safely written on the channel without blocking. .SH ERRORS - .SH SEE ALSO .BR libssh2_channel_window_read_ex(3), .BR libssh2_channel_receive_window_adjust(3) diff --git a/docs/libssh2_channel_write.3 b/docs/libssh2_channel_write.3 index dd463be2dd..234eb00cc4 100644 --- a/docs/libssh2_channel_write.3 +++ b/docs/libssh2_channel_write.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_write - convenience macro for \fIlibssh2_channel_write_ex(3)\fP .SH SYNOPSIS diff --git a/docs/libssh2_channel_write_ex.3 b/docs/libssh2_channel_write_ex.3 index 0abf3c1283..467b983ba0 100644 --- a/docs/libssh2_channel_write_ex.3 +++ b/docs/libssh2_channel_write_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_write_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_write_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_write_ex - write data to a channel stream blocking .SH SYNOPSIS diff --git a/docs/libssh2_channel_write_stderr.3 b/docs/libssh2_channel_write_stderr.3 index 89a6088375..661bad480a 100644 --- a/docs/libssh2_channel_write_stderr.3 +++ b/docs/libssh2_channel_write_stderr.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_write_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_write_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_write_stderr - convenience macro for \fIlibssh2_channel_write_ex(3)\fP .SH SYNOPSIS diff --git a/docs/libssh2_channel_x11_req.3 b/docs/libssh2_channel_x11_req.3 index dfd71aac71..8181a257d9 100644 --- a/docs/libssh2_channel_x11_req.3 +++ b/docs/libssh2_channel_x11_req.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_x11_req 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_channel_x11_req 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_channel_x11_req - convenience macro for \fIlibssh2_channel_x11_req_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_channel_x11_req_ex.3 b/docs/libssh2_channel_x11_req_ex.3 index 32121e18ba..36c5d1e9c6 100644 --- a/docs/libssh2_channel_x11_req_ex.3 +++ b/docs/libssh2_channel_x11_req_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_channel_x11_req_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_channel_x11_req_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_channel_x11_req_ex - request an X11 forwarding channel .SH SYNOPSIS @@ -30,19 +30,16 @@ Request an X11 forwarding on \fIchannel\fP. To use X11 forwarding, .BR libssh2_session_callback_set(3) must first be called to set \fBLIBSSH2_CALLBACK_X11\fP. This callback will be invoked when the remote host accepts the X11 forwarding. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. \fILIBSSH2_ERROR_CHANNEL_REQUEST_DENIED\fP - - .SH SEE ALSO .BR libssh2_channel_open_ex(3) .BR libssh2_session_callback_set(3) diff --git a/docs/libssh2_crypto_engine.3 b/docs/libssh2_crypto_engine.3 index c1d95eafd0..58a39bcb83 100644 --- a/docs/libssh2_crypto_engine.3 +++ b/docs/libssh2_crypto_engine.3 @@ -1,4 +1,4 @@ -.TH libssh2_crypto_engine 3 "22 Nov 2021" "libssh2 1.11" "libssh2 manual" +.TH libssh2_crypto_engine 3 "22 Nov 2021" "libssh2" "libssh2" .SH NAME libssh2_crypto_engine - retrieve used crypto engine .SH SYNOPSIS diff --git a/docs/libssh2_exit.3 b/docs/libssh2_exit.3 index cfab6518c0..9f8f8438a0 100644 --- a/docs/libssh2_exit.3 +++ b/docs/libssh2_exit.3 @@ -1,4 +1,4 @@ -.TH libssh2_exit 3 "19 Mar 2010" "libssh2 1.2.5" "libssh2 manual" +.TH libssh2_exit 3 "19 Mar 2010" "libssh2" "libssh2" .SH NAME libssh2_exit - global library deinitialization .SH SYNOPSIS diff --git a/docs/libssh2_free.3 b/docs/libssh2_free.3 index db494e7df1..a057f800dc 100644 --- a/docs/libssh2_free.3 +++ b/docs/libssh2_free.3 @@ -1,4 +1,4 @@ -.TH libssh2_free 3 "13 Oct 2010" "libssh2 1.2.8" "libssh2 manual" +.TH libssh2_free 3 "13 Oct 2010" "libssh2" "libssh2" .SH NAME libssh2_free - deallocate libssh2 memory .SH SYNOPSIS diff --git a/docs/libssh2_hostkey_hash.3 b/docs/libssh2_hostkey_hash.3 index 663a00f835..27eebdf32e 100644 --- a/docs/libssh2_hostkey_hash.3 +++ b/docs/libssh2_hostkey_hash.3 @@ -1,4 +1,4 @@ -.TH libssh2_hostkey_hash 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_hostkey_hash 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_hostkey_hash - return a hash of the remote host's key .SH SYNOPSIS diff --git a/docs/libssh2_init.3 b/docs/libssh2_init.3 index 0adff7ba00..cebd519221 100644 --- a/docs/libssh2_init.3 +++ b/docs/libssh2_init.3 @@ -1,4 +1,4 @@ -.TH libssh2_init 3 "19 Mar 2010" "libssh2 1.2.5" "libssh2 manual" +.TH libssh2_init 3 "19 Mar 2010" "libssh2" "libssh2" .SH NAME libssh2_init - global library initialization .SH SYNOPSIS diff --git a/docs/libssh2_keepalive_config.3 b/docs/libssh2_keepalive_config.3 index 698befa721..584b03ec97 100644 --- a/docs/libssh2_keepalive_config.3 +++ b/docs/libssh2_keepalive_config.3 @@ -1,4 +1,4 @@ -.TH libssh2_keepalive_config 3 "12 Apr 2011" "libssh2 1.2.5" "libssh2 manual" +.TH libssh2_keepalive_config 3 "12 Apr 2011" "libssh2" "libssh2" .SH NAME libssh2_keepalive_config - short function description .SH SYNOPSIS diff --git a/docs/libssh2_keepalive_send.3 b/docs/libssh2_keepalive_send.3 index 78221efe17..1eef17b22d 100644 --- a/docs/libssh2_keepalive_send.3 +++ b/docs/libssh2_keepalive_send.3 @@ -1,4 +1,4 @@ -.TH libssh2_keepalive_send 3 "13 Apr 2011" "libssh2 1.2.5" "libssh2 manual" +.TH libssh2_keepalive_send 3 "13 Apr 2011" "libssh2" "libssh2" .SH NAME libssh2_keepalive_send - short function description .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_add.3 b/docs/libssh2_knownhost_add.3 index 79ea8b78a5..7100741b77 100644 --- a/docs/libssh2_knownhost_add.3 +++ b/docs/libssh2_knownhost_add.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009, 2010 by Daniel Stenberg .\" -.TH libssh2_knownhost_add 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_add 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_add - add a known host .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_addc.3 b/docs/libssh2_knownhost_addc.3 index e1575e6b0d..30fc9bc366 100644 --- a/docs/libssh2_knownhost_addc.3 +++ b/docs/libssh2_knownhost_addc.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009, 2010 by Daniel Stenberg .\" -.TH libssh2_knownhost_addc 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_addc 3 "28 May 2009" "libssh2 1.2" "libssh2" .SH NAME libssh2_knownhost_addc - add a known host .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_check.3 b/docs/libssh2_knownhost_check.3 index 3649645984..2524e9563a 100644 --- a/docs/libssh2_knownhost_check.3 +++ b/docs/libssh2_knownhost_check.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_check 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_check 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_check - check a host+key against the list of known hosts .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_checkp.3 b/docs/libssh2_knownhost_checkp.3 index 92e1403fa4..6c481011f9 100644 --- a/docs/libssh2_knownhost_checkp.3 +++ b/docs/libssh2_knownhost_checkp.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009-2010 by Daniel Stenberg .\" -.TH libssh2_knownhost_checkp 3 "1 May 2010" "libssh2 1.2.6" "libssh2 manual" +.TH libssh2_knownhost_checkp 3 "1 May 2010" "libssh2" "libssh2" .SH NAME libssh2_knownhost_checkp - check a host+key against the list of known hosts .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_del.3 b/docs/libssh2_knownhost_del.3 index d7cbeff9f1..f280f9eb44 100644 --- a/docs/libssh2_knownhost_del.3 +++ b/docs/libssh2_knownhost_del.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_del 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_del 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_del - delete a known host entry .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_free.3 b/docs/libssh2_knownhost_free.3 index 01ea209ab1..ee600ed0ac 100644 --- a/docs/libssh2_knownhost_free.3 +++ b/docs/libssh2_knownhost_free.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_free 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_free 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_free - free a collection of known hosts .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_get.3 b/docs/libssh2_knownhost_get.3 index 8a20b4295e..dff6179ce6 100644 --- a/docs/libssh2_knownhost_get.3 +++ b/docs/libssh2_knownhost_get.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_get 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_get 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_get - get a known host off the collection of known hosts .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_init.3 b/docs/libssh2_knownhost_init.3 index 159c7aac37..0b903be1ac 100644 --- a/docs/libssh2_knownhost_init.3 +++ b/docs/libssh2_knownhost_init.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_init 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_init 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_init - init a collection of known hosts .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_readfile.3 b/docs/libssh2_knownhost_readfile.3 index 3bc678e55a..590c546d29 100644 --- a/docs/libssh2_knownhost_readfile.3 +++ b/docs/libssh2_knownhost_readfile.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009-2011 by Daniel Stenberg .\" -.TH libssh2_knownhost_readfile 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_readfile 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_readfile - parse a file of known hosts .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_readline.3 b/docs/libssh2_knownhost_readline.3 index eb43c79fad..88e5736561 100644 --- a/docs/libssh2_knownhost_readline.3 +++ b/docs/libssh2_knownhost_readline.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_readline 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_readline 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_readline - read a known host line .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_writefile.3 b/docs/libssh2_knownhost_writefile.3 index 0457ecefd0..bbe772fb65 100644 --- a/docs/libssh2_knownhost_writefile.3 +++ b/docs/libssh2_knownhost_writefile.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_writefile 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_writefile 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_writefile - write a collection of known hosts to a file .SH SYNOPSIS diff --git a/docs/libssh2_knownhost_writeline.3 b/docs/libssh2_knownhost_writeline.3 index 4a0cbfc35f..95f57a6003 100644 --- a/docs/libssh2_knownhost_writeline.3 +++ b/docs/libssh2_knownhost_writeline.3 @@ -1,7 +1,7 @@ .\" .\" Copyright (c) 2009 by Daniel Stenberg .\" -.TH libssh2_knownhost_writeline 3 "28 May 2009" "libssh2 1.2" "libssh2 manual" +.TH libssh2_knownhost_writeline 3 "28 May 2009" "libssh2" "libssh2" .SH NAME libssh2_knownhost_writeline - convert a known host to a line for storage .SH SYNOPSIS diff --git a/docs/libssh2_poll.3 b/docs/libssh2_poll.3 index 34cef03726..be6eac0901 100644 --- a/docs/libssh2_poll.3 +++ b/docs/libssh2_poll.3 @@ -1,4 +1,4 @@ -.TH libssh2_poll 3 "14 Dec 2006" "libssh2 0.15" "libssh2 manual" +.TH libssh2_poll 3 "14 Dec 2006" "libssh2 0.15" "libssh2" .SH NAME libssh2_poll - poll for activity on a socket, channel or listener .SH SYNOPSIS diff --git a/docs/libssh2_poll_channel_read.3 b/docs/libssh2_poll_channel_read.3 index 45d5702da7..7e4e9596a6 100644 --- a/docs/libssh2_poll_channel_read.3 +++ b/docs/libssh2_poll_channel_read.3 @@ -1,4 +1,4 @@ -.TH libssh2_poll_channel_read 3 "14 Dec 2006" "libssh2 0.15" "libssh2 manual" +.TH libssh2_poll_channel_read 3 "14 Dec 2006" "libssh2 0.15" "libssh2" .SH NAME libssh2_poll_channel_read - check if data is available .SH SYNOPSIS diff --git a/docs/libssh2_publickey_add.3 b/docs/libssh2_publickey_add.3 index d967a71512..dc5376368f 100644 --- a/docs/libssh2_publickey_add.3 +++ b/docs/libssh2_publickey_add.3 @@ -1,4 +1,4 @@ -.TH libssh2_publickey_add 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_publickey_add 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_publickey_add - convenience macro for \fIlibssh2_publickey_add_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_publickey_add_ex.3 b/docs/libssh2_publickey_add_ex.3 index 5499b11ab0..8d397b7e14 100644 --- a/docs/libssh2_publickey_add_ex.3 +++ b/docs/libssh2_publickey_add_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_publickey_add_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_publickey_add_ex 3 "1 Jun 2007" "libssh2" "libssh2" .SH NAME libssh2_publickey_add_ex - Add a public key entry .SH SYNOPSIS diff --git a/docs/libssh2_publickey_init.3 b/docs/libssh2_publickey_init.3 index 2bf3d0625b..4e4f1e52af 100644 --- a/docs/libssh2_publickey_init.3 +++ b/docs/libssh2_publickey_init.3 @@ -1,13 +1,12 @@ -.TH libssh2_publickey_init 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_publickey_init 3 "1 Jun 2007" "libssh2" "libssh2" .SH NAME libssh2_publickey_init - TODO .SH SYNOPSIS .nf .fi .SH DESCRIPTION - .SH RETURN VALUE - .SH ERRORS - +.SH AVAILABILITY +Added in libssh2 ?.?.? .SH SEE ALSO diff --git a/docs/libssh2_publickey_list_fetch.3 b/docs/libssh2_publickey_list_fetch.3 index f38d494f4d..8c95d07961 100644 --- a/docs/libssh2_publickey_list_fetch.3 +++ b/docs/libssh2_publickey_list_fetch.3 @@ -1,13 +1,12 @@ -.TH libssh2_publickey_list_fetch 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_publickey_list_fetch 3 "1 Jun 2007" "libssh2" "libssh2" .SH NAME libssh2_publickey_list_fetch - TODO .SH SYNOPSIS .nf .fi .SH DESCRIPTION - .SH RETURN VALUE - .SH ERRORS - +.SH AVAILABILITY +Added in libssh2 ?.?.? .SH SEE ALSO diff --git a/docs/libssh2_publickey_list_free.3 b/docs/libssh2_publickey_list_free.3 index 3761c12872..1a4bb49d05 100644 --- a/docs/libssh2_publickey_list_free.3 +++ b/docs/libssh2_publickey_list_free.3 @@ -1,13 +1,12 @@ -.TH libssh2_publickey_list_free 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_publickey_list_free 3 "1 Jun 2007" "libssh2" "libssh2" .SH NAME libssh2_publickey_list_free - TODO .SH SYNOPSIS .nf .fi .SH DESCRIPTION - .SH RETURN VALUE - .SH ERRORS - +.SH AVAILABILITY +Added in libssh2 ?.?.? .SH SEE ALSO diff --git a/docs/libssh2_publickey_remove.3 b/docs/libssh2_publickey_remove.3 index 9295806da6..6942d0ddc3 100644 --- a/docs/libssh2_publickey_remove.3 +++ b/docs/libssh2_publickey_remove.3 @@ -1,4 +1,4 @@ -.TH libssh2_publickey_remove 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_publickey_remove 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_publickey_remove - convenience macro for \fIlibssh2_publickey_remove_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_publickey_remove_ex.3 b/docs/libssh2_publickey_remove_ex.3 index a83ee2d05c..5d09343ae4 100644 --- a/docs/libssh2_publickey_remove_ex.3 +++ b/docs/libssh2_publickey_remove_ex.3 @@ -1,13 +1,12 @@ -.TH libssh2_publickey_list_remove_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_publickey_list_remove_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_publickey_list_remove_ex - TODO .SH SYNOPSIS .nf .fi .SH DESCRIPTION - .SH RETURN VALUE - .SH ERRORS - +.SH AVAILABILITY +Added in libssh2 ?.?.? .SH SEE ALSO diff --git a/docs/libssh2_publickey_shutdown.3 b/docs/libssh2_publickey_shutdown.3 index 8eabf63386..86c51bef64 100644 --- a/docs/libssh2_publickey_shutdown.3 +++ b/docs/libssh2_publickey_shutdown.3 @@ -1,13 +1,12 @@ -.TH libssh2_publickey_shutdown 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_publickey_shutdown 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_publickey_shutdown - TODO .SH SYNOPSIS .nf .fi .SH DESCRIPTION - .SH RETURN VALUE - .SH ERRORS - +.SH AVAILABILITY +Added in libssh2 ?.?.? .SH SEE ALSO diff --git a/docs/libssh2_scp_recv.3 b/docs/libssh2_scp_recv.3 index 607d49ae95..7d194d46be 100644 --- a/docs/libssh2_scp_recv.3 +++ b/docs/libssh2_scp_recv.3 @@ -1,4 +1,4 @@ -.TH libssh2_scp_recv 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_scp_recv 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_scp_recv - request a remote file via SCP .SH SYNOPSIS diff --git a/docs/libssh2_scp_recv2.3 b/docs/libssh2_scp_recv2.3 index 06c88d6bfe..4d763fc2ee 100644 --- a/docs/libssh2_scp_recv2.3 +++ b/docs/libssh2_scp_recv2.3 @@ -1,4 +1,4 @@ -.TH libssh2_scp_recv2 3 "29 Jun 2015" "libssh2 1.6.1" "libssh2 manual" +.TH libssh2_scp_recv2 3 "29 Jun 2015" "libssh2 1.6.1" "libssh2" .SH NAME libssh2_scp_recv2 - request a remote file via SCP .SH SYNOPSIS diff --git a/docs/libssh2_scp_send.3 b/docs/libssh2_scp_send.3 index 65477c464f..678b6e9869 100644 --- a/docs/libssh2_scp_send.3 +++ b/docs/libssh2_scp_send.3 @@ -1,4 +1,4 @@ -.TH libssh2_scp_send 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_scp_send 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_scp_send - convenience macro for \fIlibssh2_scp_send_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_scp_send64.3 b/docs/libssh2_scp_send64.3 index 53b6d5c44c..df63b7e423 100644 --- a/docs/libssh2_scp_send64.3 +++ b/docs/libssh2_scp_send64.3 @@ -1,4 +1,4 @@ -.TH libssh2_scp_send64 3 "17 Apr 2010" "libssh2 1.2.6" "libssh2 manual" +.TH libssh2_scp_send64 3 "17 Apr 2010" "libssh2 1.2.6" "libssh2" .SH NAME libssh2_scp_send64 - Send a file via SCP .SH SYNOPSIS diff --git a/docs/libssh2_scp_send_ex.3 b/docs/libssh2_scp_send_ex.3 index cb4d362e05..9926d38399 100644 --- a/docs/libssh2_scp_send_ex.3 +++ b/docs/libssh2_scp_send_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_scp_send_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_scp_send_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_scp_send_ex - Send a file via SCP .SH SYNOPSIS diff --git a/docs/libssh2_session_abstract.3 b/docs/libssh2_session_abstract.3 index a28bff64b1..7f82b6e5c1 100644 --- a/docs/libssh2_session_abstract.3 +++ b/docs/libssh2_session_abstract.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_abstract 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_abstract 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_abstract - return a pointer to a session's abstract pointer .SH SYNOPSIS @@ -16,10 +16,8 @@ Return a pointer to where the abstract pointer provided to \fBlibssh2_session_init_ex(3)\fP is stored. By providing a doubly de-referenced pointer, the internal storage of the session instance may be modified in place. - .SH RETURN VALUE A pointer to session internal storage who's contents point to previously provided abstract data. - .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_banner_get.3 b/docs/libssh2_session_banner_get.3 index f1097b3ce0..9e5a23df49 100644 --- a/docs/libssh2_session_banner_get.3 +++ b/docs/libssh2_session_banner_get.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_banner_get 3 "9 Sep 2011" "libssh2 1.4.0" "libssh2 manual" +.TH libssh2_session_banner_get 3 "9 Sep 2011" "libssh2" "libssh2" .SH NAME libssh2_session_banner_get - get the remote banner .SH SYNOPSIS diff --git a/docs/libssh2_session_banner_set.3 b/docs/libssh2_session_banner_set.3 index bcb7923572..2ba53caec4 100644 --- a/docs/libssh2_session_banner_set.3 +++ b/docs/libssh2_session_banner_set.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_banner_set 3 "9 Sep 2011" "libssh2 1.4.0" "libssh2 manual" +.TH libssh2_session_banner_set 3 "9 Sep 2011" "libssh2" "libssh2" .SH NAME libssh2_session_banner_set - set the SSH protocol banner for the local client .SH SYNOPSIS diff --git a/docs/libssh2_session_block_directions.3 b/docs/libssh2_session_block_directions.3 index 0c40eaf195..def9c771d9 100644 --- a/docs/libssh2_session_block_directions.3 +++ b/docs/libssh2_session_block_directions.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_block_directions 3 "1 Oct 2008" "libssh2 1.0" "libssh2 manual" +.TH libssh2_session_block_directions 3 "1 Oct 2008" "libssh2" "libssh2" .SH NAME libssh2_session_block_directions - get directions to wait for .SH SYNOPSIS diff --git a/docs/libssh2_session_callback_set.3 b/docs/libssh2_session_callback_set.3 index 861b320ed9..ed578b4072 100644 --- a/docs/libssh2_session_callback_set.3 +++ b/docs/libssh2_session_callback_set.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_callback_set 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_callback_set 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_callback_set - set a callback function .SH SYNOPSIS diff --git a/docs/libssh2_session_disconnect.3 b/docs/libssh2_session_disconnect.3 index 63b087258b..1af247bb7b 100644 --- a/docs/libssh2_session_disconnect.3 +++ b/docs/libssh2_session_disconnect.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_disconnect 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_session_disconnect 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_session_disconnect - convenience macro for \fIlibssh2_session_disconnect_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_session_disconnect_ex.3 b/docs/libssh2_session_disconnect_ex.3 index 35eb8d7818..961791de7c 100644 --- a/docs/libssh2_session_disconnect_ex.3 +++ b/docs/libssh2_session_disconnect_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_disconnect_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_disconnect_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_disconnect_ex - terminate transport layer .SH SYNOPSIS @@ -33,7 +33,6 @@ is provided. It calls .BR libssh2_session_disconnect_ex(3) with \fIreason\fP set to SSH_DISCONNECT_BY_APPLICATION and \fIlang\fP set to an empty string. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While diff --git a/docs/libssh2_session_flag.3 b/docs/libssh2_session_flag.3 index 71d82e4c38..0ed517d1b6 100644 --- a/docs/libssh2_session_flag.3 +++ b/docs/libssh2_session_flag.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_flag 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_flag 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_flag - TODO .SH SYNOPSIS diff --git a/docs/libssh2_session_free.3 b/docs/libssh2_session_free.3 index 50d2cb28a9..12b12c8613 100644 --- a/docs/libssh2_session_free.3 +++ b/docs/libssh2_session_free.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_free 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_free 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_free - frees resources associated with a session instance .SH SYNOPSIS diff --git a/docs/libssh2_session_get_blocking.3 b/docs/libssh2_session_get_blocking.3 index 9bd12134dd..e3efbd0bdf 100644 --- a/docs/libssh2_session_get_blocking.3 +++ b/docs/libssh2_session_get_blocking.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_get_blocking 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_get_blocking 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_get_blocking - TODO .SH SYNOPSIS diff --git a/docs/libssh2_session_get_read_timeout.3 b/docs/libssh2_session_get_read_timeout.3 index a39e7aee56..324fe23889 100644 --- a/docs/libssh2_session_get_read_timeout.3 +++ b/docs/libssh2_session_get_read_timeout.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_get_read_timeout 3 "13 Jan 2023" "libssh2 1.10.1" "libssh2 manual" +.TH libssh2_session_get_read_timeout 3 "13 Jan 2023" "libssh2" "libssh2" .SH NAME libssh2_session_get_read_timeout - get the timeout for packet read functions .SH SYNOPSIS diff --git a/docs/libssh2_session_get_timeout.3 b/docs/libssh2_session_get_timeout.3 index 488918d2c7..62adeda14f 100644 --- a/docs/libssh2_session_get_timeout.3 +++ b/docs/libssh2_session_get_timeout.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_get_timeout 3 "4 May 2011" "libssh2 1.2.9" "libssh2 manual" +.TH libssh2_session_get_timeout 3 "4 May 2011" "libssh2" "libssh2" .SH NAME libssh2_session_get_timeout - get the timeout for blocking functions .SH SYNOPSIS diff --git a/docs/libssh2_session_handshake.3 b/docs/libssh2_session_handshake.3 index b22e2c5a39..6816645404 100644 --- a/docs/libssh2_session_handshake.3 +++ b/docs/libssh2_session_handshake.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_handshake 3 "7 Oct 2010" "libssh2 1.2.8" "libssh2 manual" +.TH libssh2_session_handshake 3 "7 Oct 2010" "libssh2" "libssh2" .SH NAME libssh2_session_handshake - perform the SSH handshake .SH SYNOPSIS diff --git a/docs/libssh2_session_hostkey.3 b/docs/libssh2_session_hostkey.3 index 8d45b53bce..d57c7eab5c 100644 --- a/docs/libssh2_session_hostkey.3 +++ b/docs/libssh2_session_hostkey.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_hostkey 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_hostkey 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_hostkey - get the remote key .SH SYNOPSIS diff --git a/docs/libssh2_session_init.3 b/docs/libssh2_session_init.3 index a9d524c483..ec114ecd20 100644 --- a/docs/libssh2_session_init.3 +++ b/docs/libssh2_session_init.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_init 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_session_init 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_session_init - convenience macro for \fIlibssh2_session_init_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_session_init_ex.3 b/docs/libssh2_session_init_ex.3 index e54ff7ff0a..ff2f557871 100644 --- a/docs/libssh2_session_init_ex.3 +++ b/docs/libssh2_session_init_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_init_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_init_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_init_ex - initializes an SSH session object .SH SYNOPSIS diff --git a/docs/libssh2_session_last_errno.3 b/docs/libssh2_session_last_errno.3 index e6076dc190..54d37656c8 100644 --- a/docs/libssh2_session_last_errno.3 +++ b/docs/libssh2_session_last_errno.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_last_errno 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_last_errno 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_last_errno - get the most recent error number .SH SYNOPSIS @@ -13,10 +13,8 @@ libssh2_session_last_errno(LIBSSH2_SESSION *session); .BR libssh2_session_init_ex(3) Determine the most recent error condition. - .SH RETURN VALUE Numeric error code corresponding to the the Error Code constants. - .SH SEE ALSO .BR libssh2_session_last_error(3) .BR libssh2_session_set_last_error(3) diff --git a/docs/libssh2_session_last_error.3 b/docs/libssh2_session_last_error.3 index fa7285cc45..f5172793bd 100644 --- a/docs/libssh2_session_last_error.3 +++ b/docs/libssh2_session_last_error.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_last_error 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_last_error 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_last_error - get the most recent error .SH SYNOPSIS @@ -25,10 +25,8 @@ buffer will be given to the calling scope. If necessary, the errmsg buffer will be duplicated. Determine the most recent error condition and its cause. - .SH RETURN VALUE Numeric error code corresponding to the the Error Code constants. - .SH SEE ALSO .BR libssh2_session_last_errno(3) .BR libssh2_session_set_last_error(3) diff --git a/docs/libssh2_session_method_pref.3 b/docs/libssh2_session_method_pref.3 index cb6f33d600..1e7718ec62 100644 --- a/docs/libssh2_session_method_pref.3 +++ b/docs/libssh2_session_method_pref.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_method_pref 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_method_pref 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_method_pref - set preferred key exchange method .SH SYNOPSIS @@ -24,19 +24,16 @@ Set preferred methods to be negotiated. These preferences must be set prior to calling .BR libssh2_session_handshake(3) as they are used during the protocol initiation phase. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_INVAL\fP - The requested method type was invalid. \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. \fILIBSSH2_ERROR_METHOD_NOT_SUPPORTED\fP - The requested method is not supported. - .SH SEE ALSO .BR libssh2_session_init_ex(3) .BR libssh2_session_handshake(3) diff --git a/docs/libssh2_session_methods.3 b/docs/libssh2_session_methods.3 index 089f7a13e2..9dc383d0d8 100644 --- a/docs/libssh2_session_methods.3 +++ b/docs/libssh2_session_methods.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_methods 3 "8 Nov 2021" "libssh2 1.11" "libssh2 manual" +.TH libssh2_session_methods 3 "8 Nov 2021" "libssh2 1.11" "libssh2" .SH NAME libssh2_session_methods - return the currently active algorithms .SH SYNOPSIS diff --git a/docs/libssh2_session_set_blocking.3 b/docs/libssh2_session_set_blocking.3 index 7cde73aacd..ec19213acd 100644 --- a/docs/libssh2_session_set_blocking.3 +++ b/docs/libssh2_session_set_blocking.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_set_blocking 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_set_blocking 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_set_blocking - set or clear blocking mode on session .SH SYNOPSIS @@ -23,9 +23,7 @@ session will return immediately with an empty buffer. If a write is performed on a session with no room for more data, a blocking session will wait for room. A non-blocking session will return immediately without writing anything. - .SH RETURN VALUE None - .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_set_last_error.3 b/docs/libssh2_session_set_last_error.3 index e00cbd2284..bca1bd556e 100644 --- a/docs/libssh2_session_set_last_error.3 +++ b/docs/libssh2_session_set_last_error.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_set_last_error 3 "26 Oct 2015" "libssh2 1.6.1" "libssh2 manual" +.TH libssh2_session_set_last_error 3 "26 Oct 2015" "libssh2" "libssh2" .SH NAME libssh2_session_set_last_error - sets the internal error state .SH SYNOPSIS @@ -23,13 +23,10 @@ This function is provided for high level language wrappers (i.e. Python or Perl) and other libraries that may extend libssh2 with additional features while still relying on its error reporting mechanism. - .SH RETURN VALUE Numeric error code corresponding to the the Error Code constants. - .SH AVAILABILITY Added in 1.6.1 - .SH SEE ALSO .BR libssh2_session_last_error(3) .BR libssh2_session_last_errno(3) diff --git a/docs/libssh2_session_set_read_timeout.3 b/docs/libssh2_session_set_read_timeout.3 index c97e7ae6a7..5be5265b76 100644 --- a/docs/libssh2_session_set_read_timeout.3 +++ b/docs/libssh2_session_set_read_timeout.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_set_read_timeout 3 "13 Jan 2023" "libssh2 1.10.1" "libssh2 manual" +.TH libssh2_session_set_read_timeout 3 "13 Jan 2023" "libssh2" "libssh2" .SH NAME libssh2_session_set_read_timeout - set timeout for packet read functions .SH SYNOPSIS diff --git a/docs/libssh2_session_set_timeout.3 b/docs/libssh2_session_set_timeout.3 index b151d11c98..01eed43e08 100644 --- a/docs/libssh2_session_set_timeout.3 +++ b/docs/libssh2_session_set_timeout.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_set_timeout 3 "4 May 2011" "libssh2 1.2.9" "libssh2 manual" +.TH libssh2_session_set_timeout 3 "4 May 2011" "libssh2" "libssh2" .SH NAME libssh2_session_set_timeout - set timeout for blocking functions .SH SYNOPSIS diff --git a/docs/libssh2_session_startup.3 b/docs/libssh2_session_startup.3 index af66243df5..cf5b5a13d3 100644 --- a/docs/libssh2_session_startup.3 +++ b/docs/libssh2_session_startup.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_startup 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_session_startup 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_session_startup - begin transport layer .SH SYNOPSIS @@ -38,7 +38,6 @@ host failed. the socket. \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. - .SH SEE ALSO .BR libssh2_session_free(3) .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_supported_algs.3 b/docs/libssh2_session_supported_algs.3 index 89de417e34..09439f6b3a 100644 --- a/docs/libssh2_session_supported_algs.3 +++ b/docs/libssh2_session_supported_algs.3 @@ -1,4 +1,4 @@ -.TH libssh2_session_supported_algs 3 "23 Oct 2011" "libssh2 1.4.0" "libssh2 manual" +.TH libssh2_session_supported_algs 3 "23 Oct 2011" "libssh2" "libssh2" .SH NAME libssh2_session_supported_algs - get list of supported algorithms .SH SYNOPSIS diff --git a/docs/libssh2_sftp_close.3 b/docs/libssh2_sftp_close.3 index f4155191bf..ea9f0d6e14 100644 --- a/docs/libssh2_sftp_close.3 +++ b/docs/libssh2_sftp_close.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_close 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_close 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_close - convenience macro for \fIlibssh2_sftp_close_handle(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_close_handle.3 b/docs/libssh2_sftp_close_handle.3 index 1f5d0ef1f4..5450d450f3 100644 --- a/docs/libssh2_sftp_close_handle.3 +++ b/docs/libssh2_sftp_close_handle.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_close_handle 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_close_handle 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_close_handle - close filehandle .SH SYNOPSIS @@ -23,12 +23,10 @@ Close an active LIBSSH2_SFTP_HANDLE. Because files and directories share the same underlying storage mechanism these methods may be used interchangeably. \fBlibssh2_sftp_close(3)\fP and \fBlibssh2_sftp_closedir(3)\fP are macros for \fBlibssh2_sftp_close_handle(3)\fP. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. @@ -39,6 +37,5 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. - .SH SEE ALSO .BR libssh2_sftp_open_ex(3) diff --git a/docs/libssh2_sftp_closedir.3 b/docs/libssh2_sftp_closedir.3 index f4b4452e2b..9d6b94e7b5 100644 --- a/docs/libssh2_sftp_closedir.3 +++ b/docs/libssh2_sftp_closedir.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_closedir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_closedir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_closedir - convenience macro for \fIlibssh2_sftp_close_handle(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_fsetstat.3 b/docs/libssh2_sftp_fsetstat.3 index 2f45f4f3a9..acf7ab96d8 100644 --- a/docs/libssh2_sftp_fsetstat.3 +++ b/docs/libssh2_sftp_fsetstat.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_fsetstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_fsetstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_fsetstat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_fstat.3 b/docs/libssh2_sftp_fstat.3 index 809b531158..9113bc169a 100644 --- a/docs/libssh2_sftp_fstat.3 +++ b/docs/libssh2_sftp_fstat.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_fstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_fstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_fstat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_fstat_ex.3 b/docs/libssh2_sftp_fstat_ex.3 index 3c6967b41f..2a559f944c 100644 --- a/docs/libssh2_sftp_fstat_ex.3 +++ b/docs/libssh2_sftp_fstat_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_fstat_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_fstat_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_fstat_ex - get or set attributes on an SFTP file handle .SH SYNOPSIS diff --git a/docs/libssh2_sftp_fsync.3 b/docs/libssh2_sftp_fsync.3 index 646760a01c..d293d2e682 100644 --- a/docs/libssh2_sftp_fsync.3 +++ b/docs/libssh2_sftp_fsync.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_fsync 3 "8 Apr 2013" "libssh2 1.4.4" "libssh2 manual" +.TH libssh2_sftp_fsync 3 "8 Apr 2013" "libssh2" "libssh2" .SH NAME libssh2_sftp_fsync - synchronize file to disk .SH SYNOPSIS @@ -17,7 +17,6 @@ For this to work requires fsync@openssh.com support on the server. \fIhandle\fP - SFTP File Handle as returned by .BR libssh2_sftp_open_ex(3) - .SH RETURN VALUE Returns 0 on success or negative on failure. If used in non-blocking mode, it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While @@ -32,7 +31,6 @@ was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. In particular, this can be returned if the SSH server does not support the fsync operation: the SFTP subcode \fILIBSSH2_FX_OP_UNSUPPORTED\fP will be returned in this case. - .SH AVAILABILITY Added in libssh2 1.4.4 and OpenSSH 6.3. .SH SEE ALSO diff --git a/docs/libssh2_sftp_get_channel.3 b/docs/libssh2_sftp_get_channel.3 index 1e24f10ebe..0a1d463675 100644 --- a/docs/libssh2_sftp_get_channel.3 +++ b/docs/libssh2_sftp_get_channel.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_get_channel 3 "9 Sep 2011" "libssh2 1.4.0" "libssh2 manual" +.TH libssh2_sftp_get_channel 3 "9 Sep 2011" "libssh2 1.4.0" "libssh2" .SH NAME libssh2_sftp_get_channel - return the channel of sftp .SH SYNOPSIS diff --git a/docs/libssh2_sftp_init.3 b/docs/libssh2_sftp_init.3 index ea602d82d3..3ebc3538e8 100644 --- a/docs/libssh2_sftp_init.3 +++ b/docs/libssh2_sftp_init.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_init 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_init 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_init - open SFTP channel for the given SSH session. .SH SYNOPSIS diff --git a/docs/libssh2_sftp_last_error.3 b/docs/libssh2_sftp_last_error.3 index 91dd6fdfa2..0933689c12 100644 --- a/docs/libssh2_sftp_last_error.3 +++ b/docs/libssh2_sftp_last_error.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_last_error 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_last_error 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_last_error - return the last SFTP-specific error code .SH SYNOPSIS @@ -17,9 +17,7 @@ Returns the last error code produced by the SFTP layer. Note that this only returns a sensible error code if libssh2 returned LIBSSH2_ERROR_SFTP_PROTOCOL in a previous call. Using \fBlibssh2_sftp_last_error(3)\fP without a preceding SFTP protocol error, it will return an unspecified value. - .SH RETURN VALUE Current error code state of the SFTP instance. - .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_lstat.3 b/docs/libssh2_sftp_lstat.3 index fc0ecd4ebb..1faf34f4ec 100644 --- a/docs/libssh2_sftp_lstat.3 +++ b/docs/libssh2_sftp_lstat.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_lstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_lstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_lstat - convenience macro for \fIlibssh2_sftp_stat_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_mkdir.3 b/docs/libssh2_sftp_mkdir.3 index 63e4c3b477..ba4f77d1f6 100644 --- a/docs/libssh2_sftp_mkdir.3 +++ b/docs/libssh2_sftp_mkdir.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_mkdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_mkdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_mkdir - convenience macro for \fIlibssh2_sftp_mkdir_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_mkdir_ex.3 b/docs/libssh2_sftp_mkdir_ex.3 index 4bf73b84af..946b6e6319 100644 --- a/docs/libssh2_sftp_mkdir_ex.3 +++ b/docs/libssh2_sftp_mkdir_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_mkdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_mkdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_mkdir_ex - create a directory on the remote file system .SH SYNOPSIS diff --git a/docs/libssh2_sftp_open.3 b/docs/libssh2_sftp_open.3 index 85d54f67fc..5643c93783 100644 --- a/docs/libssh2_sftp_open.3 +++ b/docs/libssh2_sftp_open.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_open 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_open 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_open - convenience macro for \fIlibssh2_sftp_open_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_open_ex.3 b/docs/libssh2_sftp_open_ex.3 index c23108c8b3..fed36092d4 100644 --- a/docs/libssh2_sftp_open_ex.3 +++ b/docs/libssh2_sftp_open_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_open_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_open_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_open_ex - open filehandle for file on SFTP. .SH SYNOPSIS diff --git a/docs/libssh2_sftp_open_ex_r.3 b/docs/libssh2_sftp_open_ex_r.3 index a7326718de..a2f65e3402 100644 --- a/docs/libssh2_sftp_open_ex_r.3 +++ b/docs/libssh2_sftp_open_ex_r.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_open_ex_r 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.TH libssh2_sftp_open_ex_r 3 "10 Apr 2023" "libssh2" "libssh2" .SH NAME libssh2_sftp_open_ex_r - open filehandle for file on SFTP. .SH SYNOPSIS @@ -68,6 +68,8 @@ returned by the server. \fILIBSSH2_ERROR_EAGAIN\fP - Marked for non-blocking I/O but the call would block. +.SH AVAILABILITY +Added in libssh2 1.11.0 .SH SEE ALSO .BR libssh2_sftp_close_handle(3) .BR libssh2_sftp_fstat_ex(3) diff --git a/docs/libssh2_sftp_open_r.3 b/docs/libssh2_sftp_open_r.3 index bccc0df38e..4bdd1fa19d 100644 --- a/docs/libssh2_sftp_open_r.3 +++ b/docs/libssh2_sftp_open_r.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_open_r 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2 manual" +.TH libssh2_sftp_open_r 3 "10 Apr 2023" "libssh2 1.11.0" "libssh2" .SH NAME libssh2_sftp_open_r - convenience macro for \fIlibssh2_sftp_open_ex_r(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_opendir.3 b/docs/libssh2_sftp_opendir.3 index ad78cea2e6..198eec6a8e 100644 --- a/docs/libssh2_sftp_opendir.3 +++ b/docs/libssh2_sftp_opendir.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_opendir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_opendir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_opendir - convenience macro for \fIlibssh2_sftp_open_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_read.3 b/docs/libssh2_sftp_read.3 index c998e2c913..9d874223ad 100644 --- a/docs/libssh2_sftp_read.3 +++ b/docs/libssh2_sftp_read.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_read 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_read 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_read - read data from an SFTP handle .SH SYNOPSIS diff --git a/docs/libssh2_sftp_readdir.3 b/docs/libssh2_sftp_readdir.3 index f0fc9561d1..cc1367f40d 100644 --- a/docs/libssh2_sftp_readdir.3 +++ b/docs/libssh2_sftp_readdir.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_readdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_readdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_readdir - convenience macro for \fIlibssh2_sftp_readdir_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_readdir_ex.3 b/docs/libssh2_sftp_readdir_ex.3 index 6ea3e0488f..cdac3ddb2a 100644 --- a/docs/libssh2_sftp_readdir_ex.3 +++ b/docs/libssh2_sftp_readdir_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_readdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_readdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_readdir_ex - read directory data from an SFTP handle .SH SYNOPSIS diff --git a/docs/libssh2_sftp_readlink.3 b/docs/libssh2_sftp_readlink.3 index e6d79be777..fe60158266 100644 --- a/docs/libssh2_sftp_readlink.3 +++ b/docs/libssh2_sftp_readlink.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_readlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_readlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_readlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP .SH SYNOPSIS diff --git a/docs/libssh2_sftp_realpath.3 b/docs/libssh2_sftp_realpath.3 index 9dd51c5af8..e11849c956 100644 --- a/docs/libssh2_sftp_realpath.3 +++ b/docs/libssh2_sftp_realpath.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_realpath 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_realpath 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP .SH SYNOPSIS diff --git a/docs/libssh2_sftp_rename.3 b/docs/libssh2_sftp_rename.3 index fd0e1185ea..3b34a2097d 100644 --- a/docs/libssh2_sftp_rename.3 +++ b/docs/libssh2_sftp_rename.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_rename 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_rename 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_rename - convenience macro for \fIlibssh2_sftp_rename_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_rename_ex.3 b/docs/libssh2_sftp_rename_ex.3 index d29b42aaad..7731bcff51 100644 --- a/docs/libssh2_sftp_rename_ex.3 +++ b/docs/libssh2_sftp_rename_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_rename_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_rename_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_rename_ex - rename an SFTP file .SH SYNOPSIS @@ -43,12 +43,10 @@ flag is not set and the destfile entry already exists, the operation will fail. Use of the other two flags indicate a preference (but not a requirement) for the remote end to perform an atomic rename operation and/or using native system calls when possible. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. @@ -59,6 +57,5 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. - .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_rewind.3 b/docs/libssh2_sftp_rewind.3 index 867bfd8b57..e84152894d 100644 --- a/docs/libssh2_sftp_rewind.3 +++ b/docs/libssh2_sftp_rewind.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_rewind 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_rewind 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_rewind - convenience macro for \fIlibssh2_sftp_seek64(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_rmdir.3 b/docs/libssh2_sftp_rmdir.3 index fb797c2332..49101ea0ce 100644 --- a/docs/libssh2_sftp_rmdir.3 +++ b/docs/libssh2_sftp_rmdir.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_rmdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_rmdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_rmdir - convenience macro for \fIlibssh2_sftp_rmdir_ex(3)\fP .SH SYNOPSIS diff --git a/docs/libssh2_sftp_rmdir_ex.3 b/docs/libssh2_sftp_rmdir_ex.3 index 1b1bb08144..bb1db0854a 100644 --- a/docs/libssh2_sftp_rmdir_ex.3 +++ b/docs/libssh2_sftp_rmdir_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_rmdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_rmdir_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_rmdir_ex - remove an SFTP directory .SH SYNOPSIS diff --git a/docs/libssh2_sftp_seek.3 b/docs/libssh2_sftp_seek.3 index ce3aeeb14a..f5d313bf1e 100644 --- a/docs/libssh2_sftp_seek.3 +++ b/docs/libssh2_sftp_seek.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_seek 3 "22 Dec 2008" "libssh2 1.0" "libssh2 manual" +.TH libssh2_sftp_seek 3 "22 Dec 2008" "libssh2 1.0" "libssh2" .SH NAME libssh2_sftp_seek - set the read/write position indicator within a file .SH SYNOPSIS diff --git a/docs/libssh2_sftp_seek64.3 b/docs/libssh2_sftp_seek64.3 index c7fd62a592..e3f5640707 100644 --- a/docs/libssh2_sftp_seek64.3 +++ b/docs/libssh2_sftp_seek64.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_seek64 3 "22 Dec 2008" "libssh2 1.0" "libssh2 manual" +.TH libssh2_sftp_seek64 3 "22 Dec 2008" "libssh2" "libssh2" .SH NAME libssh2_sftp_seek64 - set the read/write position within a file .SH SYNOPSIS diff --git a/docs/libssh2_sftp_setstat.3 b/docs/libssh2_sftp_setstat.3 index 07284d8931..6e1a67d035 100644 --- a/docs/libssh2_sftp_setstat.3 +++ b/docs/libssh2_sftp_setstat.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_setstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_setstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_setstat - convenience macro for \fIlibssh2_sftp_stat_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_shutdown.3 b/docs/libssh2_sftp_shutdown.3 index d73a7af9d8..1a22a4750a 100644 --- a/docs/libssh2_sftp_shutdown.3 +++ b/docs/libssh2_sftp_shutdown.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_shutdown 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_shutdown 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_shutdown - shut down an SFTP session .SH SYNOPSIS @@ -15,11 +15,9 @@ libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp); Destroys a previously initialized SFTP session and frees all resources associated with it. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_stat.3 b/docs/libssh2_sftp_stat.3 index 59abb59ead..1f4b37bc5b 100644 --- a/docs/libssh2_sftp_stat.3 +++ b/docs/libssh2_sftp_stat.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_stat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_stat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_stat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_stat_ex.3 b/docs/libssh2_sftp_stat_ex.3 index 6b03539594..2484a97f3b 100644 --- a/docs/libssh2_sftp_stat_ex.3 +++ b/docs/libssh2_sftp_stat_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_stat_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_stat_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_stat_ex - get status about an SFTP file .SH SYNOPSIS diff --git a/docs/libssh2_sftp_statvfs.3 b/docs/libssh2_sftp_statvfs.3 index 1b5feb1d0b..5f083a58a4 100644 --- a/docs/libssh2_sftp_statvfs.3 +++ b/docs/libssh2_sftp_statvfs.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_statvfs 3 "22 May 2010" "libssh2 1.2.6" "libssh2 manual" +.TH libssh2_sftp_statvfs 3 "22 May 2010" "libssh2" "libssh2" .SH NAME libssh2_sftp_statvfs, libssh2_sftp_fstatvfs - get file system statistics .SH SYNOPSIS @@ -30,7 +30,6 @@ statvfs@openssh.com and fstatvfs@openssh.com extension support on the server. \fIst\fP - Pointer to a LIBSSH2_SFTP_STATVFS structure to place file system statistics into. - .SH DATA TYPES LIBSSH2_SFTP_STATVFS is a typedefed struct that is defined as below @@ -58,7 +57,6 @@ The field \fIf_flag\fP is a bit mask. Bits are defined as follows: Read-only file system. .IP LIBSSH2_SFTP_ST_NOSUID Set-user-ID/set-group-ID bits are ignored by \fBexec\fP(3). - .SH RETURN VALUE Returns 0 on success or negative on failure. If used in non-blocking mode, it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While diff --git a/docs/libssh2_sftp_symlink.3 b/docs/libssh2_sftp_symlink.3 index 60c8550b08..8b8e612948 100644 --- a/docs/libssh2_sftp_symlink.3 +++ b/docs/libssh2_sftp_symlink.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_symlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_symlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_symlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP .SH SYNOPSIS diff --git a/docs/libssh2_sftp_symlink_ex.3 b/docs/libssh2_sftp_symlink_ex.3 index 8ef4a1f625..f0f485daa0 100644 --- a/docs/libssh2_sftp_symlink_ex.3 +++ b/docs/libssh2_sftp_symlink_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_symlink_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_symlink_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_symlink_ex - read or set a symbolic link .SH SYNOPSIS @@ -75,6 +75,5 @@ for the application to tell when it happens! \fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. - .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_tell.3 b/docs/libssh2_sftp_tell.3 index 4e99bd0391..2c65651737 100644 --- a/docs/libssh2_sftp_tell.3 +++ b/docs/libssh2_sftp_tell.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_tell 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_tell 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_tell - get the current read/write position indicator for a file .SH SYNOPSIS diff --git a/docs/libssh2_sftp_tell64.3 b/docs/libssh2_sftp_tell64.3 index d0c037775f..f3af30be0b 100644 --- a/docs/libssh2_sftp_tell64.3 +++ b/docs/libssh2_sftp_tell64.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_tell64 3 "22 Dec 2008" "libssh2 1.0" "libssh2 manual" +.TH libssh2_sftp_tell64 3 "22 Dec 2008" "libssh2 1.0" "libssh2" .SH NAME libssh2_sftp_tell64 - get the current read/write position indicator for a file .SH SYNOPSIS diff --git a/docs/libssh2_sftp_unlink.3 b/docs/libssh2_sftp_unlink.3 index f83fd7e95b..3d00a37adb 100644 --- a/docs/libssh2_sftp_unlink.3 +++ b/docs/libssh2_sftp_unlink.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_unlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_sftp_unlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_sftp_unlink - convenience macro for \fIlibssh2_sftp_unlink_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_sftp_unlink_ex.3 b/docs/libssh2_sftp_unlink_ex.3 index 9589305052..05861c6011 100644 --- a/docs/libssh2_sftp_unlink_ex.3 +++ b/docs/libssh2_sftp_unlink_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_unlink_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_unlink_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_unlink_ex - unlink an SFTP file .SH SYNOPSIS @@ -22,12 +22,10 @@ libssh2_sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename); filesystem entry Unlink (delete) a file from the remote filesystem. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. @@ -38,6 +36,5 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. \fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. - .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_write.3 b/docs/libssh2_sftp_write.3 index 8518eea014..6ca0171e1e 100644 --- a/docs/libssh2_sftp_write.3 +++ b/docs/libssh2_sftp_write.3 @@ -1,4 +1,4 @@ -.TH libssh2_sftp_write 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_sftp_write 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_sftp_write - write SFTP data .SH SYNOPSIS @@ -27,7 +27,6 @@ possible to write all bytes as requested. put it into a single SFTP protocol packet. This means that to get maximum performance when sending larger files, you should try to always pass in at least 32K of data to this function. - .SH WRITE AHEAD Starting in libssh2 version 1.2.8, the default behavior of libssh2 is to create several smaller outgoing packets for all data you pass to this function diff --git a/docs/libssh2_sign_sk.3 b/docs/libssh2_sign_sk.3 index a1dcbc2a47..cb5f56b461 100644 --- a/docs/libssh2_sign_sk.3 +++ b/docs/libssh2_sign_sk.3 @@ -1,4 +1,4 @@ -.TH libssh2_sign_sk 3 "1 Jun 2022" "libssh2 1.10.0" "libssh2 manual" +.TH libssh2_sign_sk 3 "1 Jun 2022" "libssh2 1.10.0" "libssh2" .SH NAME libssh2_sign_sk - Create a signature from a FIDO2 authenticator. .SH SYNOPSIS @@ -79,9 +79,7 @@ return 0. On failure, it should return a negative number. See \fIorig_abstract\fP - User-defined data. When a PIN is required, use this to pass in the PIN, or a function pointer to retrieve the PIN. - .SH RETURN VALUE Return 0 on success or negative on failure. - .SH SEE ALSO .BR libssh2_userauth_publickey_sk(3) diff --git a/docs/libssh2_trace.3 b/docs/libssh2_trace.3 index 94e6d634fb..113767f170 100644 --- a/docs/libssh2_trace.3 +++ b/docs/libssh2_trace.3 @@ -1,4 +1,4 @@ -.TH libssh2_trace 3 "26 Dec 2008" "libssh2 1.0" "libssh2 manual" +.TH libssh2_trace 3 "26 Dec 2008" "libssh2 1.0" "libssh2" .SH NAME libssh2_trace - enable debug info from inside libssh2 .SH SYNOPSIS diff --git a/docs/libssh2_trace_sethandler.3 b/docs/libssh2_trace_sethandler.3 index 03eada56d5..2262d8c0b9 100644 --- a/docs/libssh2_trace_sethandler.3 +++ b/docs/libssh2_trace_sethandler.3 @@ -1,4 +1,4 @@ -.TH libssh2_trace_sethandler 3 "15 Jan 2010" "libssh2 1.2.3" "libssh2 manual" +.TH libssh2_trace_sethandler 3 "15 Jan 2010" "libssh2" "libssh2" .SH NAME libssh2_trace_sethandler - set a trace output handler .SH SYNOPSIS diff --git a/docs/libssh2_userauth_authenticated.3 b/docs/libssh2_userauth_authenticated.3 index ea2cb4dabd..10d6810f46 100644 --- a/docs/libssh2_userauth_authenticated.3 +++ b/docs/libssh2_userauth_authenticated.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_authenticated 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_userauth_authenticated 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_userauth_authenticated - return authentication status .SH SYNOPSIS @@ -13,9 +13,7 @@ libssh2_userauth_authenticated(LIBSSH2_SESSION *session); .BR libssh2_session_init_ex(3) Indicates whether or not the named session has been successfully authenticated. - .SH RETURN VALUE Returns 1 if authenticated and 0 if not. - .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_userauth_banner.3 b/docs/libssh2_userauth_banner.3 index f463bcf879..8bfaddf4c3 100644 --- a/docs/libssh2_userauth_banner.3 +++ b/docs/libssh2_userauth_banner.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_banner 3 "1 Jun 2021" "libssh2 1.9.0" "libssh2 manual" +.TH libssh2_userauth_banner 3 "1 Jun 2021" "libssh2 1.9.0" "libssh2" .SH NAME libssh2_userauth_banner - get the server's userauth banner message .SH SYNOPSIS diff --git a/docs/libssh2_userauth_hostbased_fromfile.3 b/docs/libssh2_userauth_hostbased_fromfile.3 index 2d0c47594a..3e18d36f32 100644 --- a/docs/libssh2_userauth_hostbased_fromfile.3 +++ b/docs/libssh2_userauth_hostbased_fromfile.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_hostbased_fromfile 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_userauth_hostbased_fromfile 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_userauth_hostbased_fromfile - convenience macro for \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_userauth_hostbased_fromfile_ex.3 b/docs/libssh2_userauth_hostbased_fromfile_ex.3 index f1baa41a94..b71ceb28a8 100644 --- a/docs/libssh2_userauth_hostbased_fromfile_ex.3 +++ b/docs/libssh2_userauth_hostbased_fromfile_ex.3 @@ -1,13 +1,10 @@ -.TH libssh2_userauth_hostbased_fromfile_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_userauth_hostbased_fromfile_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_userauth_hostbased_fromfile_ex - TODO .SH SYNOPSIS .nf .fi .SH DESCRIPTION - .SH RETURN VALUE - .SH ERRORS - .SH SEE ALSO diff --git a/docs/libssh2_userauth_keyboard_interactive.3 b/docs/libssh2_userauth_keyboard_interactive.3 index 492ed50af6..27424c6b8d 100644 --- a/docs/libssh2_userauth_keyboard_interactive.3 +++ b/docs/libssh2_userauth_keyboard_interactive.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_keyboard_interactive 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_userauth_keyboard_interactive 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_userauth_keyboard_interactive - convenience macro for \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_userauth_keyboard_interactive_ex.3 b/docs/libssh2_userauth_keyboard_interactive_ex.3 index 6137c5ba25..cc8daa45ce 100644 --- a/docs/libssh2_userauth_keyboard_interactive_ex.3 +++ b/docs/libssh2_userauth_keyboard_interactive_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_keyboard_interactive_ex 3 "8 Mar 2008" "libssh2 0.19" "libssh2 manual" +.TH libssh2_userauth_keyboard_interactive_ex 3 "8 Mar 2008" "libssh2 0.19" "libssh2" .SH NAME libssh2_userauth_keyboard_interactive_ex - authenticate a session using keyboard-interactive authentication diff --git a/docs/libssh2_userauth_list.3 b/docs/libssh2_userauth_list.3 index aa77298b83..efb9207a8a 100644 --- a/docs/libssh2_userauth_list.3 +++ b/docs/libssh2_userauth_list.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_list 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_userauth_list 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_userauth_list - list supported authentication methods .SH SYNOPSIS diff --git a/docs/libssh2_userauth_password.3 b/docs/libssh2_userauth_password.3 index f067196ce0..e0a3300b20 100644 --- a/docs/libssh2_userauth_password.3 +++ b/docs/libssh2_userauth_password.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_password 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_userauth_password 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_userauth_password - convenience macro for \fIlibssh2_userauth_password_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_userauth_password_ex.3 b/docs/libssh2_userauth_password_ex.3 index 784ef802fc..aa5d860184 100644 --- a/docs/libssh2_userauth_password_ex.3 +++ b/docs/libssh2_userauth_password_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_password_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_userauth_password_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_userauth_password_ex - authenticate a session with username and password .SH SYNOPSIS @@ -39,12 +39,10 @@ Attempt basic password authentication. Note that many SSH servers which appear to support ordinary password authentication actually have it disabled and use Keyboard Interactive authentication (routed via PAM or another authentication backed) instead. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS Some of the errors this function may return include: diff --git a/docs/libssh2_userauth_publickey.3 b/docs/libssh2_userauth_publickey.3 index 5712f4cec3..10dafdfe3c 100644 --- a/docs/libssh2_userauth_publickey.3 +++ b/docs/libssh2_userauth_publickey.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_publickey 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_userauth_publickey 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_userauth_publickey - authenticate using a callback function .SH SYNOPSIS diff --git a/docs/libssh2_userauth_publickey_fromfile.3 b/docs/libssh2_userauth_publickey_fromfile.3 index 7be047d246..c26ad4702c 100644 --- a/docs/libssh2_userauth_publickey_fromfile.3 +++ b/docs/libssh2_userauth_publickey_fromfile.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_publickey_fromfile 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" +.TH libssh2_userauth_publickey_fromfile 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2" .SH NAME libssh2_userauth_publickey_fromfile - convenience macro for \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP calls .SH SYNOPSIS diff --git a/docs/libssh2_userauth_publickey_fromfile_ex.3 b/docs/libssh2_userauth_publickey_fromfile_ex.3 index fbd75ebde5..d060d68f92 100644 --- a/docs/libssh2_userauth_publickey_fromfile_ex.3 +++ b/docs/libssh2_userauth_publickey_fromfile_ex.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_publickey_fromfile_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" +.TH libssh2_userauth_publickey_fromfile_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2" .SH NAME libssh2_userauth_publickey_fromfile_ex - authenticate a session with a public key, read from a file .SH SYNOPSIS @@ -31,12 +31,10 @@ can be set to NULL. Attempt public key authentication using a PEM encoded private key file stored on disk - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. @@ -49,6 +47,5 @@ combination was invalid. \fILIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - Authentication using the supplied public key was not accepted. - .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_userauth_publickey_frommemory.3 b/docs/libssh2_userauth_publickey_frommemory.3 index 0509f1a785..6bd26fd1b9 100644 --- a/docs/libssh2_userauth_publickey_frommemory.3 +++ b/docs/libssh2_userauth_publickey_frommemory.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_publickey_frommemory 3 "1 Sep 2014" "libssh2 1.5" "libssh2 manual" +.TH libssh2_userauth_publickey_frommemory 3 "1 Sep 2014" "libssh2" "libssh2" .SH NAME libssh2_userauth_publickey_frommemory - authenticate a session with a public key, read from memory .SH SYNOPSIS diff --git a/docs/libssh2_userauth_publickey_sk.3 b/docs/libssh2_userauth_publickey_sk.3 index 38df52f274..bee31eae8b 100644 --- a/docs/libssh2_userauth_publickey_sk.3 +++ b/docs/libssh2_userauth_publickey_sk.3 @@ -1,4 +1,4 @@ -.TH libssh2_userauth_publickey_sk 3 "1 Jun 2022" "libssh2 1.10.0" "libssh2 manual" +.TH libssh2_userauth_publickey_sk 3 "1 Jun 2022" "libssh2" "libssh2" .SH NAME libssh2_userauth_publickey_sk - authenticate a session with a FIDO2 authenticator .SH SYNOPSIS @@ -124,12 +124,10 @@ memory. It will be freed by the caller. For Ed25519 signatures, set this to NULL. \fIsig_s_len\fP - The length of the sig_s parameter. - .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. - .SH ERRORS Some of the errors this function may return include: @@ -138,5 +136,7 @@ Some of the errors this function may return include: \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. \fILIBSSH2_ERROR_AUTHENTICATION_FAILED\fP - failed, invalid username/key. +.SH AVAILABILITY +Added in libssh2 1.10.0 .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_version.3 b/docs/libssh2_version.3 index a2e608ebff..2fe99a3d3b 100644 --- a/docs/libssh2_version.3 +++ b/docs/libssh2_version.3 @@ -1,4 +1,4 @@ -.TH libssh2_version 3 "23 Feb 2009" "libssh2 1.1" "libssh2 manual" +.TH libssh2_version 3 "23 Feb 2009" "libssh2" "libssh2" .SH NAME libssh2_version - return the libssh2 version number .SH SYNOPSIS diff --git a/docs/template.3 b/docs/template.3 index e6b0ac020c..473e0bd3bf 100644 --- a/docs/template.3 +++ b/docs/template.3 @@ -1,4 +1,4 @@ -.TH libssh2_template 3 "1 Jun 2022" "libssh2 1.10.0" "libssh2 manual" +.TH libssh2_template 3 "1 Jun 2022" "libssh2" "libssh2" .SH NAME libssh2_template - short function description .SH SYNOPSIS @@ -10,12 +10,11 @@ libssh2_template(void); .fi .SH DESCRIPTION Long text describing the function and its input arguments. - .SH RETURN VALUE Describe what the function returns. - .SH ERRORS Add error codes - +.SH AVAILABILITY +Added in libssh2 ?.?.? .SH SEE ALSO Add related functions From 33dddd2f8ac3bc811719e6422e9bec6458f91de3 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Wed, 26 Apr 2023 14:51:19 -0400 Subject: [PATCH 334/424] If SFTP fails to initialize, do not busy loop waiting for IO to happen (#720) Currently SFTP's init will busy loop waiting for the channel to close, even if the underlying transport returns EAGAIN. While this works for sockets, it might not work out if you have a different transport that needs to do some additional processing on the side. Integration-patches-by: Viktor Szakats --- src/libssh2_priv.h | 1 + src/sftp.c | 25 +++++++++++++++++-------- src/transport.c | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 49b2095d35..6cbb2532f7 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -262,6 +262,7 @@ typedef enum libssh2_NB_state_jump3, libssh2_NB_state_jump4, libssh2_NB_state_jump5, + libssh2_NB_state_error_closing, libssh2_NB_state_end, libssh2_NB_state_jumpauthagent } libssh2_nonblocking_states; diff --git a/src/sftp.c b/src/sftp.c index d6c39e1e9e..6f577378b0 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -894,6 +894,22 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) } } + if(session->sftpInit_state == libssh2_NB_state_error_closing) { + rc = _libssh2_channel_free(session->sftpInit_channel); + if(rc == LIBSSH2_ERROR_EAGAIN) { + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block closing channel"); + return NULL; + } + session->sftpInit_channel = NULL; + if(session->sftpInit_sftp) { + LIBSSH2_FREE(session, session->sftpInit_sftp); + session->sftpInit_sftp = NULL; + } + session->sftpInit_state = libssh2_NB_state_idle; + return NULL; + } + rc = sftp_packet_require(sftp_handle, SSH_FXP_VERSION, 0, &data, &data_len, 5); if(rc == LIBSSH2_ERROR_EAGAIN) { @@ -970,14 +986,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) return sftp_handle; sftp_init_error: - while(_libssh2_channel_free(session->sftpInit_channel) == - LIBSSH2_ERROR_EAGAIN); - session->sftpInit_channel = NULL; - if(session->sftpInit_sftp) { - LIBSSH2_FREE(session, session->sftpInit_sftp); - session->sftpInit_sftp = NULL; - } - session->sftpInit_state = libssh2_NB_state_idle; + session->sftpInit_state = libssh2_NB_state_error_closing; return NULL; } diff --git a/src/transport.c b/src/transport.c index 8646608bc3..bce6413dd7 100644 --- a/src/transport.c +++ b/src/transport.c @@ -777,7 +777,8 @@ send_existing(LIBSSH2_SESSION *session, const unsigned char *data, we don't add this one up until the previous one has been sent. To make the caller really notice his/hers flaw, we return error for this case */ - return LIBSSH2_ERROR_BAD_USE; + _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, + "Address is different, but will resume nonetheless")); } *ret = 1; /* set to make our parent return */ From 8890fb455f28c2395dce78f83f080136ecbb5b47 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 18:22:17 +0000 Subject: [PATCH 335/424] tests/sshd_fixture.sh: convert back to POSIX There was no strong reason to require bash. Let's use POSIX shell like before the recent overhaul. Follow-up to a459a25302a31f6e2aba3c4e15b1472b83b596fc Closes #1008 --- tests/sshd_fixture.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/sshd_fixture.sh b/tests/sshd_fixture.sh index 539a62509a..cc5e132496 100755 --- a/tests/sshd_fixture.sh +++ b/tests/sshd_fixture.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # Written by Simon Josefsson @@ -11,11 +11,13 @@ else cmd="${cmd:-./test_ssh2}" fi +uname="$(uname)" + d="$(dirname "$0")" d="$(cd "${d}" || exit; pwd)" # sshd needs absolute paths SSHD="${SSHD:-/usr/sbin/sshd}" -[[ "$(uname)" = *'_NT'* ]] && SSHD="$(cygpath -u "${SSHD}")" +[ "${uname#*_NT*}" != "${uname}" ] && SSHD="$(cygpath -u "${SSHD}")" # for our test clients: [ -z "${PRIVKEY}" ] && export PRIVKEY="${d}/key_rsa" @@ -49,7 +51,7 @@ trap 'kill "${sshdpid}"; echo signal killing sshd; exit 1;' EXIT : "started sshd (${sshdpid})" -if [[ "$(uname)" = *'_NT'* ]]; then +if [ "${uname#*_NT*}" != "${uname}" ]; then sleep 5 else sleep 3 From 23029a9d363a3cd269f43178486077ea6a657044 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 20:25:04 +0000 Subject: [PATCH 336/424] session_fixture: avoid no-op `chdir(getcwd())` If no `FIXTURE_WORKDIR` macro or envvar is present to set the cwd, avoid querying the cwd and then calling chdir with the result. Ref: 54bef4c5dad868a9d45fdbfca9729b191c0abab5 (patch) Ref: 10a5cbf945abcc60153ee3d59284d09fc64ea152 (individual commit) Closes #1009 --- tests/session_fixture.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/session_fixture.c b/tests/session_fixture.c index e23a5fcf2d..153083e8de 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -46,7 +46,6 @@ #ifdef _MSC_VER #include -#define getcwd _getcwd #define chdir _chdir #endif @@ -80,23 +79,15 @@ static int connect_to_server(void) static void setup_fixture_workdir(void) { -#ifdef WIN32 - char wd_buf[_MAX_PATH]; -#else - char wd_buf[MAXPATHLEN]; -#endif const char *wd = getenv("FIXTURE_WORKDIR"); #ifdef FIXTURE_WORKDIR if(!wd) { wd = FIXTURE_WORKDIR; } #endif - if(!wd) { - getcwd(wd_buf, sizeof(wd_buf)); - wd = wd_buf; + if(wd) { + chdir(wd); } - - chdir(wd); } /* List of crypto protocols for which tests are skipped */ From f4a4c05dc3bcd62ecaa1b0cac5997faefe16c83f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 26 Apr 2023 21:43:45 +0000 Subject: [PATCH 337/424] ci: add MSVC and UWP builds to GitHub Actions - add MSVC jobs to GitHub Actions. They are similar to the 'Build-only' jobs we have on AppVeyor CI, though only the ARM64 Windows one is identical. Major disadvantage is that we don't run tests here. Major advantage is they only take a few minutes to complete, compared to an hour on AppVeyor, so WinCNG build results now appear quicker. Docker tests might be possible, but my light attempts failed. Finding ZLIB also failed, so we still miss an MSVC test with it. Tool versions as of now: Server 2022, VS2022, OpenSSL 1.1.1 - add UWP builds for both ARM64 and x64. This hasn't been CI tested before. (We could probably enable UWP on AppVeyor CI as well. I haven't tried.) - fix two uncovered UWP issues in tests. - rename internal macro `LIBSSH2_WINDOWS_APP` to `LIBSSH2_WINDOWS_UWP`. Follow-up to 2addafb77b662e64248d156c71c69b91ba7b926e - fold long lines and quote truthy values in `.github/workflows/ci.yml`. Closes #1010 --- .github/workflows/ci.yml | 57 ++++++++++++++++++++++++++++++++++++---- src/agent.c | 8 +++--- src/agent_win.c | 4 +-- src/libssh2_priv.h | 2 +- tests/openssh_fixture.c | 16 +++++------ 5 files changed, 67 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fee66b19b1..00d2bd110f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,18 +26,18 @@ jobs: compiler: [gcc, clang] address_size: [64] crypto_backend: [OpenSSL, Libgcrypt, mbedTLS] - enable_zlib_compression: [OFF, ON] + enable_zlib_compression: ['OFF', 'ON'] b: [cmake] include: - compiler: gcc address_size: 64 crypto_backend: OpenSSL - enable_zlib_compression: OFF + enable_zlib_compression: 'OFF' b: configure - compiler: clang address_size: 64 crypto_backend: OpenSSL - enable_zlib_compression: OFF + enable_zlib_compression: 'OFF' b: configure env: CC: ${{ matrix.compiler }} @@ -57,7 +57,9 @@ jobs: MBEDTLSVER=mbedtls-3.4.0 curl -L https://github.com/Mbed-TLS/mbedtls/archive/$MBEDTLSVER.tar.gz | tar -xzf - cd mbedtls-$MBEDTLSVER - cmake $TOOLCHAIN_OPTION -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=../usr . + cmake $TOOLCHAIN_OPTION \ + -DUSE_SHARED_MBEDTLS_LIBRARY=ON \ + -DCMAKE_INSTALL_PREFIX:PATH=../usr . make -j3 install cd .. echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/usr/lib" >> $GITHUB_ENV @@ -75,7 +77,11 @@ jobs: run: | mkdir bin cd bin - cmake $TOOLCHAIN_OPTION -DENABLE_WERROR=ON -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=ON -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. + cmake $TOOLCHAIN_OPTION \ + -DENABLE_WERROR=ON \ + -DBUILD_SHARED_LIBS=ON \ + -DCRYPTO_BACKEND=$CRYPTO_BACKEND \ + -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. cmake --build . export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server) ctest -VV --output-on-failure @@ -109,3 +115,44 @@ jobs: ./configure --enable-debug --enable-static --disable-shared --with-crypto=openssl make -j3 make check VERBOSE=1 + + build_msvc: + name: msvc + runs-on: windows-latest + timeout-minutes: 30 + strategy: + matrix: + include: + - { arch: x64 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'OFF', zlib: 'OFF' } + - { arch: x64 , plat: windows, crypto: WinCNG , log: 'ON' , shared: 'ON' , zlib: 'OFF' } + - { arch: x64 , plat: windows, crypto: OpenSSL, log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: x64 , plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: arm64, plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: arm64, plat: uwp , crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + - { arch: x86 , plat: windows, crypto: WinCNG , log: 'OFF', shared: 'ON' , zlib: 'OFF' } + fail-fast: false + steps: + - uses: actions/checkout@v3 + - name: Configure with CMake + shell: bash + run: | + archgen=${{matrix.arch}}; [ "${archgen}" = 'x86' ] && archgen='Win32' + if [ "${{matrix.plat}}" = 'uwp' ]; then + system='WindowsStore' + options='-DCMAKE_SYSTEM_VERSION=10.0' + else + system='Windows' + fi + cmake . -B bld ${options} \ + -DCMAKE_SYSTEM_NAME=${system} \ + -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \ + -DCMAKE_GENERATOR_PLATFORM=${archgen} \ + -DVCPKG_TARGET_TRIPLET=${{matrix.arch}}-${{matrix.plat}} \ + -DENABLE_WERROR=ON \ + -DENABLE_DEBUG_LOGGING=${{matrix.log}} \ + -DBUILD_SHARED_LIBS=${{matrix.shared}} \ + -DCRYPTO_BACKEND=${{matrix.crypto}} \ + -DENABLE_ZLIB_COMPRESSION=${{matrix.zlib}} + - name: Build with CMake + run: | + cmake --build bld --config Release --target package diff --git a/src/agent.c b/src/agent.c index 9b38d91079..cb1fe20ba4 100644 --- a/src/agent.c +++ b/src/agent.c @@ -251,7 +251,7 @@ static struct agent_ops agent_ops_unix = { }; #endif /* PF_UNIX */ -#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) /* Code to talk to Pageant was taken from PuTTY. * * Portions copyright Robert de Bath, Joris van Rantwijk, Delian @@ -354,16 +354,16 @@ static struct agent_ops agent_ops_pageant = { agent_transact_pageant, agent_disconnect_pageant }; -#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) */ +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) */ static struct { const char *name; struct agent_ops *ops; } supported_backends[] = { -#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) {"Pageant", &agent_ops_pageant}, {"OpenSSH", &agent_ops_openssh}, -#endif +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) */ #ifdef PF_UNIX {"Unix", &agent_ops_unix}, #endif /* PF_UNIX */ diff --git a/src/agent_win.c b/src/agent_win.c index 323ed6babb..4a93e1cab2 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -41,7 +41,7 @@ #include "agent.h" #include -#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) +#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) #include /* for getenv() */ @@ -347,4 +347,4 @@ struct agent_ops agent_ops_openssh = { agent_transact_openssh, agent_disconnect_openssh }; -#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) */ +#endif /* defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) */ diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 6cbb2532f7..857b135910 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -97,7 +97,7 @@ # include # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define LIBSSH2_WINDOWS_APP +# define LIBSSH2_WINDOWS_UWP # endif # endif #endif diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 407cdcbf77..cbe08d99d9 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -61,6 +61,14 @@ #define LIBSSH2_SOCKET_MASK "%d" #endif +#ifdef LIBSSH2_WINDOWS_UWP +#define popen(x, y) (NULL) +#define pclose(x) (-1) +#elif defined(WIN32) +#define popen _popen +#define pclose _pclose +#endif + static int have_docker = 0; int openssh_fixture_have_docker(void) @@ -102,11 +110,7 @@ static int run_command_varg(char **output, const char *command, va_list args) } fprintf(stdout, "Command: %s\n", command_buf); -#ifdef WIN32 - pipe = _popen(buf, "r"); -#else pipe = popen(buf, "r"); -#endif if(!pipe) { fprintf(stderr, "Unable to execute command '%s'\n", command); return -1; @@ -118,11 +122,7 @@ static int run_command_varg(char **output, const char *command, va_list args) buf_len = strlen(buf); } -#ifdef WIN32 - ret = _pclose(pipe); -#else ret = pclose(pipe); -#endif if(ret) { fprintf(stderr, "Error running command '%s' (exit %d): %s\n", command, ret, buf); From d67aaaffc4c9b4a6f8295b4c1d4d4111a12e13d1 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Apr 2023 14:17:52 +0000 Subject: [PATCH 338/424] tidy-up: text nits, English contractions [ci skip] In input/output text and docs mostly. --- CMakeLists.txt | 6 +++--- acinclude.m4 | 2 +- configure.ac | 2 +- docs/AUTHORS | 2 +- docs/HACKING-CRYPTO | 2 +- docs/INSTALL_AUTOTOOLS | 8 ++++---- docs/INSTALL_CMAKE.md | 8 ++++---- docs/SECURITY.md | 10 +++++----- docs/TODO | 6 +++--- docs/libssh2_agent_connect.3 | 2 +- docs/libssh2_agent_init.3 | 2 +- docs/libssh2_banner_set.3 | 2 +- docs/libssh2_base64_decode.3 | 4 ++-- docs/libssh2_channel_close.3 | 2 +- docs/libssh2_channel_flush_ex.3 | 2 +- docs/libssh2_channel_forward_cancel.3 | 2 +- docs/libssh2_channel_free.3 | 2 +- docs/libssh2_channel_process_startup.3 | 2 +- docs/libssh2_channel_read_ex.3 | 2 +- docs/libssh2_channel_request_auth_agent.3 | 2 +- docs/libssh2_channel_request_pty_ex.3 | 2 +- docs/libssh2_channel_send_eof.3 | 2 +- docs/libssh2_channel_setenv_ex.3 | 2 +- docs/libssh2_channel_wait_closed.3 | 2 +- docs/libssh2_channel_wait_eof.3 | 2 +- docs/libssh2_channel_write_ex.3 | 2 +- docs/libssh2_channel_x11_req_ex.3 | 2 +- docs/libssh2_exit.3 | 2 +- docs/libssh2_knownhost_add.3 | 2 +- docs/libssh2_knownhost_addc.3 | 2 +- docs/libssh2_knownhost_check.3 | 2 +- docs/libssh2_knownhost_checkp.3 | 2 +- docs/libssh2_knownhost_init.3 | 2 +- docs/libssh2_session_abstract.3 | 2 +- docs/libssh2_session_banner_set.3 | 2 +- docs/libssh2_session_callback_set.3 | 6 +++--- docs/libssh2_session_disconnect_ex.3 | 2 +- docs/libssh2_session_free.3 | 2 +- docs/libssh2_session_method_pref.3 | 2 +- docs/libssh2_sftp_close_handle.3 | 2 +- docs/libssh2_sftp_fstat_ex.3 | 2 +- docs/libssh2_sftp_fsync.3 | 2 +- docs/libssh2_sftp_mkdir_ex.3 | 2 +- docs/libssh2_sftp_read.3 | 2 +- docs/libssh2_sftp_readdir_ex.3 | 2 +- docs/libssh2_sftp_rename_ex.3 | 2 +- docs/libssh2_sftp_rmdir_ex.3 | 2 +- docs/libssh2_sftp_shutdown.3 | 2 +- docs/libssh2_sftp_stat_ex.3 | 2 +- docs/libssh2_sftp_statvfs.3 | 2 +- docs/libssh2_sftp_symlink_ex.3 | 2 +- docs/libssh2_sftp_unlink_ex.3 | 2 +- docs/libssh2_sftp_write.3 | 10 +++++----- docs/libssh2_userauth_keyboard_interactive_ex.3 | 2 +- docs/libssh2_userauth_password_ex.3 | 2 +- docs/libssh2_userauth_publickey_fromfile_ex.3 | 2 +- docs/libssh2_userauth_publickey_frommemory.3 | 4 ++-- docs/libssh2_userauth_publickey_sk.3 | 2 +- docs/libssh2_version.3 | 2 +- example/scp_write.c | 2 +- example/scp_write_nonblock.c | 2 +- example/sftp_RW_nonblock.c | 6 +++--- example/sftp_append.c | 2 +- example/sftp_write.c | 2 +- example/sftp_write_nonblock.c | 2 +- example/sftp_write_sliding.c | 2 +- example/ssh2_agent.c | 2 +- example/ssh2_agent_forwarding.c | 6 +++--- maketgz | 2 +- src/channel.c | 2 +- tests/test_auth_keyboard_fail.c | 2 +- tests/test_auth_password_fail_password.c | 2 +- tests/test_auth_password_fail_username.c | 2 +- 73 files changed, 99 insertions(+), 99 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3d742c157..f84d4b778c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,7 @@ set(LIB_SHARED "libssh2_shared") # Must match libssh2_shared_EXPORTS macro in i # Symbol hiding -option(HIDE_SYMBOLS "Set to ON to hide all libssh2 symbols that aren't officially external" ON) +option(HIDE_SYMBOLS "Set to ON to hide all libssh2 symbols that are not officially external" ON) mark_as_advanced(HIDE_SYMBOLS) if(HIDE_SYMBOLS) set(LIB_SHARED_DEFINITIONS LIBSSH2_EXPORTS) @@ -168,7 +168,7 @@ else() endif() check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) if(NOT HAVE_STRTOLL) - # Try _strtoi64 if strtoll isn't available + # Try _strtoi64() if strtoll() is not available check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64) endif() check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) @@ -190,7 +190,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR # have been in a bad mood, because poll() only works on the /proc # filesystem here" # - # Mac OS X's poll has funny behaviors, like: + # macOS poll() has funny behaviors, like: # not being able to do poll on no filedescriptors (10.3?) # not being able to poll on some files (like anything in /dev) # not having reliable timeout support diff --git a/acinclude.m4 b/acinclude.m4 index 0a3a37da6b..49592e5c18 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -123,7 +123,7 @@ AC_DEFUN([CURL_CHECK_COMPILER_CLANG], [ clangver=`echo $fullclangver | grep "based on LLVM " | "$SED" 's/.*(based on LLVM \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*)/\1/'` if test -z "$clangver"; then if echo $fullclangver | grep "Apple LLVM version " >/dev/null; then - dnl Starting with XCode 7 / clang 3.7, Apple clang won't tell its upstream version + dnl Starting with Xcode 7 / clang 3.7, Apple clang won't tell its upstream version clangver="3.7" else clangver=`echo $fullclangver | "$SED" 's/.*version \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*/\1/'` diff --git a/configure.ac b/configure.ac index 466193cfd9..140cf179c0 100644 --- a/configure.ac +++ b/configure.ac @@ -303,7 +303,7 @@ case $host in dnl Interix: "does provide poll(), but the implementing developer must dnl have been in a bad mood, because poll() only works on the /proc dnl filesystem here" - dnl Mac OS X's poll has funny behaviors, like: + dnl macOS poll() has funny behaviors, like: dnl not being able to do poll on no fildescriptors (10.3?) dnl not being able to poll on some files (like anything in /dev) dnl not having reliable timeout support diff --git a/docs/AUTHORS b/docs/AUTHORS index 5c7445bf13..3abc939060 100644 --- a/docs/AUTHORS +++ b/docs/AUTHORS @@ -1,5 +1,5 @@ libssh2 is the result of many friendly people. This list is an attempt to - mention all contributors. If we've missed anyone, tell us! + mention all contributors. If we have missed anyone, tell us! This list of names is a-z sorted. diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO index b85198327f..f1c025bdc8 100644 --- a/docs/HACKING-CRYPTO +++ b/docs/HACKING-CRYPTO @@ -58,7 +58,7 @@ Terminates the crypto library use. May be an empty macro if not needed. 1.1) Crypto runtime detection The libssh2_crypto_engine_t enum must include the new engine, and -libssh2_crypto_engine() must return it when it's built in. +libssh2_crypto_engine() must return it when it is built in. 2) HMAC diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index b4a0cf194f..607ef079e7 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -46,7 +46,7 @@ cache files.) to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you +some point `config.cache' contains results you do not want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create @@ -57,7 +57,7 @@ a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're + `./configure' to configure the package for your system. If you are using `csh' on an old version of System V, you might need to type `sh ./configure' instead to prevent `csh' from trying to execute `configure' itself. @@ -148,7 +148,7 @@ is something like `gnu-as' or `x' (for the X Window System). The package recognizes. For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, +find the X include and library files automatically, but if it does not, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. @@ -170,7 +170,7 @@ where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't +`config.sub' is not included in this package, then this package does not need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 23a8ce9b50..600edad446 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -107,7 +107,7 @@ or cmake --build . --target RUN_TESTS ``` -How do I use libssh2 in my project if my project doesn't use CMake? +How do I use libssh2 in my project if my project does not use CMake? ------------------------------------------------------------------- If you are not using CMake for your own project, install libssh2 @@ -122,14 +122,14 @@ or ``` and then specify the install location to your project in the normal -way for your build environment. If you don't like the default install +way for your build environment. If you do not like the default install location, add `-DCMAKE_INSTALL_PREFIX=` when initially configuring the project. How can I use libssh2 in my project if it also uses CMake? ---------------------------------------------------------- -If your own project also uses CMake, you don't need to worry about +If your own project also uses CMake, you do not need to worry about setting it up with libssh2's location. Just add just the following lines and CMake will find libssh2 on your system, set up the necessary paths and link the library with your binary. @@ -139,7 +139,7 @@ paths and link the library with your binary. Of course, you still have to make libssh2 available on your system first. You can install it in the traditional way shown above, but you -don't have to. Instead you can just build it, which will export its +do not have to. Instead you can just build it, which will export its location to the user package registry [3] where `find_package` will find it. diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 4dfcf80698..99fef457d7 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -28,8 +28,8 @@ reference to the security nature of the commit if done prior to the public announcement. - The person discovering the issue, the reporter, reports the vulnerability - privately to `libssh2-security@haxx.se`. That's an email alias that reaches a - handful of selected and trusted people. + privately to `libssh2-security@haxx.se`. That is an email alias that reaches + a handful of selected and trusted people. - Messages that do not relate to the reporting or managing of an undisclosed security vulnerability in libssh2 are ignored and no further action is @@ -64,7 +64,7 @@ announcement. [distros@openwall](https://oss-security.openwall.org/wiki/mailing-lists/distros) when also informing and preparing them for the upcoming public security vulnerability announcement - attach the advisory draft for information. Note - that 'distros' won't accept an embargo longer than 14 days. + that 'distros' will not accept an embargo longer than 14 days. - Update the "security advisory" with the CVE number. @@ -90,10 +90,10 @@ LIBSSH2-SECURITY (at haxx dot se) -------------------------------- Who is on this list? There are a couple of criteria you must meet, and then we -might ask you to join the list or you can ask to join it. It really isn't very +might ask you to join the list or you can ask to join it. It really is not very formal. We basically only require that you have a long-term presence in the libssh2 project and you have shown an understanding for the project and its way -of working. You must've been around for a good while and you should have no +of working. You must have been around for a good while and you should have no plans in vanishing in the near future. We do not make the list of participants public mostly because it tends to vary diff --git a/docs/TODO b/docs/TODO index a097c4f0c5..5a65179a62 100644 --- a/docs/TODO +++ b/docs/TODO @@ -5,13 +5,13 @@ Things TODO Improvements" below for details * make sure the windowing code adapts better to slow situations so that it - doesn't then use as much memory as today. Possibly by an app-controllable + does not then use as much memory as today. Possibly by an app-controllable "Window mode"? * Decrease the number of mallocs. Everywhere. Will get easier once the buffering improvements have been done. -* Use SO_NOSIGPIPE for Mac OS/BSD systems where MSG_NOSIGNAL doesn't +* Use SO_NOSIGPIPE for Mac OS/BSD systems where MSG_NOSIGNAL does not exist/work * Extend the test suite to actually test lots of aspects of libssh2 @@ -119,7 +119,7 @@ I suggest we introduce two new helper functions: short return, nothing more should be attempted to get sent until select() (or equivalent) has been used on the master socket again. -I haven't yet figured out a sensible API for how these functions should return +I have not yet figured out a sensible API for how these functions should return that info, but if we agree on the general principles I guess we can work that out. diff --git a/docs/libssh2_agent_connect.3 b/docs/libssh2_agent_connect.3 index 07c683ded3..e8ba15878f 100644 --- a/docs/libssh2_agent_connect.3 +++ b/docs/libssh2_agent_connect.3 @@ -15,7 +15,7 @@ libssh2_agent_connect(LIBSSH2_AGENT *agent); Connect to an ssh-agent running on the system. Call \fBlibssh2_agent_disconnect(3)\fP to close the connection after -you're doing using it. +you are doing using it. .SH RETURN VALUE Returns 0 if succeeded, or a negative value for error. .SH AVAILABILITY diff --git a/docs/libssh2_agent_init.3 b/docs/libssh2_agent_init.3 index 352a73a77e..6a535dc7ce 100644 --- a/docs/libssh2_agent_init.3 +++ b/docs/libssh2_agent_init.3 @@ -17,7 +17,7 @@ representation of an ssh-agent connection. After the successful initialization, an application can call \fBlibssh2_agent_connect(3)\fP to connect to a running ssh-agent. -Call \fBlibssh2_agent_free(3)\fP to free the handle again after you're +Call \fBlibssh2_agent_free(3)\fP to free the handle again after you are doing using it. .SH RETURN VALUE Returns a handle pointer or NULL if something went wrong. The returned handle diff --git a/docs/libssh2_banner_set.3 b/docs/libssh2_banner_set.3 index c443d8f18e..11d2d770c3 100644 --- a/docs/libssh2_banner_set.3 +++ b/docs/libssh2_banner_set.3 @@ -24,7 +24,7 @@ started with .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH AVAILABILITY Marked as deprecated since 1.4.0 .SH ERRORS diff --git a/docs/libssh2_base64_decode.3 b/docs/libssh2_base64_decode.3 index 8856f220cd..627b89f2e7 100644 --- a/docs/libssh2_base64_decode.3 +++ b/docs/libssh2_base64_decode.3 @@ -12,7 +12,7 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, .fi .SH DESCRIPTION This function is deemed DEPRECATED and will be removed from libssh2 in a -future version. Don't use it! +future version. Do not use it! Decode a base64 chunk and store it into a newly allocated buffer. 'dest_len' will be set to hold the length of the returned buffer that '*dest' will point @@ -22,7 +22,7 @@ The returned buffer is allocated by this function, but it is not clear how to free that memory! .SH BUGS The memory that *dest points to is allocated by the malloc function libssh2 -uses, but there's no way for an application to free this data in a safe and +uses, but there is no way for an application to free this data in a safe and reliable way! .SH RETURN VALUE 0 if successful, \-1 if any error occurred. diff --git a/docs/libssh2_channel_close.3 b/docs/libssh2_channel_close.3 index abc1619c48..78d2729ba5 100644 --- a/docs/libssh2_channel_close.3 +++ b/docs/libssh2_channel_close.3 @@ -20,7 +20,7 @@ connection as well, follow this command with .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. .SH SEE ALSO diff --git a/docs/libssh2_channel_flush_ex.3 b/docs/libssh2_channel_flush_ex.3 index 6e7b167e46..0b125fa6c7 100644 --- a/docs/libssh2_channel_flush_ex.3 +++ b/docs/libssh2_channel_flush_ex.3 @@ -29,4 +29,4 @@ be flushed by number or using one of the provided macros. .SH RETURN VALUE Return the number of bytes flushed or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. diff --git a/docs/libssh2_channel_forward_cancel.3 b/docs/libssh2_channel_forward_cancel.3 index 55cb287b7c..c43989bb93 100644 --- a/docs/libssh2_channel_forward_cancel.3 +++ b/docs/libssh2_channel_forward_cancel.3 @@ -16,7 +16,7 @@ Instruct the remote host to stop listening for new connections on a previously r .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_channel_free.3 b/docs/libssh2_channel_free.3 index 8e63845efa..d41f09fb1d 100644 --- a/docs/libssh2_channel_free.3 +++ b/docs/libssh2_channel_free.3 @@ -19,6 +19,6 @@ can safely free its own resources. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH SEE ALSO .BR libssh2_channel_close(3) diff --git a/docs/libssh2_channel_process_startup.3 b/docs/libssh2_channel_process_startup.3 index 1237e4896e..e92a19f8d6 100644 --- a/docs/libssh2_channel_process_startup.3 +++ b/docs/libssh2_channel_process_startup.3 @@ -29,7 +29,7 @@ Initiate a request on a session type channel such as returned by .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_channel_read_ex.3 b/docs/libssh2_channel_read_ex.3 index fed03f90f0..5dcf3fe4dd 100644 --- a/docs/libssh2_channel_read_ex.3 +++ b/docs/libssh2_channel_read_ex.3 @@ -36,7 +36,7 @@ macros. .SH RETURN VALUE Actual number of bytes read or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. Note that a return value of zero (0) can in fact be a legitimate value and only signals that no payload data was read. It is not an error. diff --git a/docs/libssh2_channel_request_auth_agent.3 b/docs/libssh2_channel_request_auth_agent.3 index 8ac659722d..675eb2a0e2 100644 --- a/docs/libssh2_channel_request_auth_agent.3 +++ b/docs/libssh2_channel_request_auth_agent.3 @@ -19,4 +19,4 @@ for the duration of the SSH session. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. diff --git a/docs/libssh2_channel_request_pty_ex.3 b/docs/libssh2_channel_request_pty_ex.3 index 4186da2ebb..f36c82d197 100644 --- a/docs/libssh2_channel_request_pty_ex.3 +++ b/docs/libssh2_channel_request_pty_ex.3 @@ -41,7 +41,7 @@ success. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_channel_send_eof.3 b/docs/libssh2_channel_send_eof.3 index 5e26b02679..bbc393769e 100644 --- a/docs/libssh2_channel_send_eof.3 +++ b/docs/libssh2_channel_send_eof.3 @@ -14,7 +14,7 @@ channel. Processes typically interpret this as a closed stdin descriptor. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_SOCKET_SEND\fP - Unable to send data on socket. .SH SEE ALSO diff --git a/docs/libssh2_channel_setenv_ex.3 b/docs/libssh2_channel_setenv_ex.3 index 57e8f9d2ec..84889b2c08 100644 --- a/docs/libssh2_channel_setenv_ex.3 +++ b/docs/libssh2_channel_setenv_ex.3 @@ -33,7 +33,7 @@ server despite returning success. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_channel_wait_closed.3 b/docs/libssh2_channel_wait_closed.3 index 4797b9c3cf..ab62781844 100644 --- a/docs/libssh2_channel_wait_closed.3 +++ b/docs/libssh2_channel_wait_closed.3 @@ -16,7 +16,7 @@ examine the exit status. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative -number, it isn't really a failure per se. +number, it is not really a failure per se. .SH SEE ALSO .BR libssh2_channel_send_eof(3) .BR libssh2_channel_eof(3) diff --git a/docs/libssh2_channel_wait_eof.3 b/docs/libssh2_channel_wait_eof.3 index 44708bc962..59c751da82 100644 --- a/docs/libssh2_channel_wait_eof.3 +++ b/docs/libssh2_channel_wait_eof.3 @@ -14,7 +14,7 @@ Wait for the remote end to send EOF. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH SEE ALSO .BR libssh2_channel_send_eof(3) .BR libssh2_channel_eof(3) diff --git a/docs/libssh2_channel_write_ex.3 b/docs/libssh2_channel_write_ex.3 index 467b983ba0..9ca1c95f37 100644 --- a/docs/libssh2_channel_write_ex.3 +++ b/docs/libssh2_channel_write_ex.3 @@ -34,7 +34,7 @@ least 32K of data to this function. .SH RETURN VALUE Actual number of bytes written or negative on failure. LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_channel_x11_req_ex.3 b/docs/libssh2_channel_x11_req_ex.3 index 36c5d1e9c6..c0584e52a2 100644 --- a/docs/libssh2_channel_x11_req_ex.3 +++ b/docs/libssh2_channel_x11_req_ex.3 @@ -33,7 +33,7 @@ invoked when the remote host accepts the X11 forwarding. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_exit.3 b/docs/libssh2_exit.3 index 9f8f8438a0..84f834ec0b 100644 --- a/docs/libssh2_exit.3 +++ b/docs/libssh2_exit.3 @@ -9,7 +9,7 @@ void libssh2_exit(void); .fi .SH DESCRIPTION -Exit the libssh2 functions and free's all memory used internal. +Exit the libssh2 functions and frees all memory used internal. .SH AVAILABILITY Added in libssh2 1.2.5 .SH SEE ALSO diff --git a/docs/libssh2_knownhost_add.3 b/docs/libssh2_knownhost_add.3 index 7100741b77..d0af2b6d35 100644 --- a/docs/libssh2_knownhost_add.3 +++ b/docs/libssh2_knownhost_add.3 @@ -53,7 +53,7 @@ LIBSSH2_KNOWNHOST_KEY_RSA1, LIBSSH2_KNOWNHOST_KEY_SSHRSA or LIBSSH2_KNOWNHOST_KEY_SSHDSS. \fIstore\fP should point to a pointer that gets filled in to point to the -known host data after the addition. NULL can be passed if you don't care about +known host data after the addition. NULL can be passed if you do not care about this pointer. .SH RETURN VALUE Returns a regular libssh2 error code, where negative values are error codes diff --git a/docs/libssh2_knownhost_addc.3 b/docs/libssh2_knownhost_addc.3 index 30fc9bc366..21367e1168 100644 --- a/docs/libssh2_knownhost_addc.3 +++ b/docs/libssh2_knownhost_addc.3 @@ -58,7 +58,7 @@ LIBSSH2_KNOWNHOST_KEY_RSA1, LIBSSH2_KNOWNHOST_KEY_SSHRSA or LIBSSH2_KNOWNHOST_KEY_SSHDSS. \fIstore\fP should point to a pointer that gets filled in to point to the -known host data after the addition. NULL can be passed if you don't care about +known host data after the addition. NULL can be passed if you do not care about this pointer. .SH RETURN VALUE Returns a regular libssh2 error code, where negative values are error codes diff --git a/docs/libssh2_knownhost_check.3 b/docs/libssh2_knownhost_check.3 index 2524e9563a..1ce050f5ee 100644 --- a/docs/libssh2_knownhost_check.3 +++ b/docs/libssh2_knownhost_check.3 @@ -50,7 +50,7 @@ LIBSSH2_KNOWNHOST_CHECK_NOTFOUND - no host match was found LIBSSH2_KNOWNHOST_CHECK_MATCH - hosts and keys match. -LIBSSH2_KNOWNHOST_CHECK_MISMATCH - host was found, but the keys didn't match! +LIBSSH2_KNOWNHOST_CHECK_MISMATCH - host was found, but the keys did not match! .SH AVAILABILITY Added in libssh2 1.2 .SH EXAMPLE diff --git a/docs/libssh2_knownhost_checkp.3 b/docs/libssh2_knownhost_checkp.3 index 6c481011f9..f35f55ab12 100644 --- a/docs/libssh2_knownhost_checkp.3 +++ b/docs/libssh2_knownhost_checkp.3 @@ -55,7 +55,7 @@ LIBSSH2_KNOWNHOST_CHECK_NOTFOUND - no host match was found LIBSSH2_KNOWNHOST_CHECK_MATCH - hosts and keys match. -LIBSSH2_KNOWNHOST_CHECK_MISMATCH - host was found, but the keys didn't match! +LIBSSH2_KNOWNHOST_CHECK_MISMATCH - host was found, but the keys did not match! .SH AVAILABILITY Added in libssh2 1.2.6 .SH EXAMPLE diff --git a/docs/libssh2_knownhost_init.3 b/docs/libssh2_knownhost_init.3 index 0b903be1ac..d09142be1d 100644 --- a/docs/libssh2_knownhost_init.3 +++ b/docs/libssh2_knownhost_init.3 @@ -15,7 +15,7 @@ libssh2_knownhost_init(LIBSSH2_SESSION *session); Init a collection of known hosts for this session. Returns the handle to an internal representation of a known host collection. -Call \fBlibssh2_knownhost_free(3)\fP to free the collection again after you're +Call \fBlibssh2_knownhost_free(3)\fP to free the collection again after you are doing using it. .SH RETURN VALUE Returns a handle pointer or NULL if something went wrong. The returned handle diff --git a/docs/libssh2_session_abstract.3 b/docs/libssh2_session_abstract.3 index 7f82b6e5c1..67129253ea 100644 --- a/docs/libssh2_session_abstract.3 +++ b/docs/libssh2_session_abstract.3 @@ -17,7 +17,7 @@ Return a pointer to where the abstract pointer provided to de-referenced pointer, the internal storage of the session instance may be modified in place. .SH RETURN VALUE -A pointer to session internal storage who's contents point to previously +A pointer to session internal storage whose contents point to previously provided abstract data. .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_banner_set.3 b/docs/libssh2_session_banner_set.3 index 2ba53caec4..2581a622e3 100644 --- a/docs/libssh2_session_banner_set.3 +++ b/docs/libssh2_session_banner_set.3 @@ -21,7 +21,7 @@ corresponding to the protocol and libssh2 version will be sent by default. .SH RETURN VALUE Returns 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative -number, it isn't really a failure per se. +number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. .SH AVAILABILITY diff --git a/docs/libssh2_session_callback_set.3 b/docs/libssh2_session_callback_set.3 index ed578b4072..4c06db42cd 100644 --- a/docs/libssh2_session_callback_set.3 +++ b/docs/libssh2_session_callback_set.3 @@ -46,8 +46,8 @@ ssize_t sendcb(libssh2_socket_t sockfd, const void *buffer, \fBsockfd\fP is the socket to write to, \fBbuffer\fP points to the data to send, \fBlength\fP is the size of the data, \fBflags\fP is the flags that -would've been used to a \fIsend()\fP call and \fBabstract\fP is a pointer to -the abstract pointer set in the \fIlibssh2_session_init_ex(3)\fP call. +would have been used to a \fIsend()\fP call and \fBabstract\fP is a pointer +to the abstract pointer set in the \fIlibssh2_session_init_ex(3)\fP call. The callback returns the number of bytes sent, or -1 for error. The special return code \fB-EAGAIN\fP can be returned to signal that the send was aborted @@ -65,7 +65,7 @@ ssize_t recvcb(libssh2_socket_t sockfd, void *buffer, \fBsockfd\fP is the socket to read from, \fBbuffer\fP where to store received data into, \fBlength\fP is the size of the buffer, \fBflags\fP is the flags -that would've been used to a \fIrecv()\fP call and \fBabstract\fP is a pointer +that would have been used to a \fIrecv()\fP call and \fBabstract\fP is a pointer to the abstract pointer set in the \fIlibssh2_session_init_ex(3)\fP call. The callback returns the number of bytes read, or -1 for error. The special diff --git a/docs/libssh2_session_disconnect_ex.3 b/docs/libssh2_session_disconnect_ex.3 index 961791de7c..85d54a40e0 100644 --- a/docs/libssh2_session_disconnect_ex.3 +++ b/docs/libssh2_session_disconnect_ex.3 @@ -36,6 +36,6 @@ and \fIlang\fP set to an empty string. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH SEE ALSO .BR libssh2_session_init_ex(3) diff --git a/docs/libssh2_session_free.3 b/docs/libssh2_session_free.3 index 12b12c8613..c0de271f59 100644 --- a/docs/libssh2_session_free.3 +++ b/docs/libssh2_session_free.3 @@ -14,7 +14,7 @@ Frees all resources associated with a session instance. Typically called after .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH SEE ALSO .BR libssh2_session_init_ex(3) .BR libssh2_session_disconnect_ex(3) diff --git a/docs/libssh2_session_method_pref.3 b/docs/libssh2_session_method_pref.3 index 1e7718ec62..7038b5857a 100644 --- a/docs/libssh2_session_method_pref.3 +++ b/docs/libssh2_session_method_pref.3 @@ -27,7 +27,7 @@ as they are used during the protocol initiation phase. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_INVAL\fP - The requested method type was invalid. diff --git a/docs/libssh2_sftp_close_handle.3 b/docs/libssh2_sftp_close_handle.3 index 5450d450f3..b5d862d830 100644 --- a/docs/libssh2_sftp_close_handle.3 +++ b/docs/libssh2_sftp_close_handle.3 @@ -26,7 +26,7 @@ are macros for \fBlibssh2_sftp_close_handle(3)\fP. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_fstat_ex.3 b/docs/libssh2_sftp_fstat_ex.3 index 2a559f944c..04eccbde9c 100644 --- a/docs/libssh2_sftp_fstat_ex.3 +++ b/docs/libssh2_sftp_fstat_ex.3 @@ -85,7 +85,7 @@ Test for a socket .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_fsync.3 b/docs/libssh2_sftp_fsync.3 index d293d2e682..7766ed9c1c 100644 --- a/docs/libssh2_sftp_fsync.3 +++ b/docs/libssh2_sftp_fsync.3 @@ -20,7 +20,7 @@ For this to work requires fsync@openssh.com support on the server. .SH RETURN VALUE Returns 0 on success or negative on failure. If used in non-blocking mode, it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_mkdir_ex.3 b/docs/libssh2_sftp_mkdir_ex.3 index 946b6e6319..0ec51738d3 100644 --- a/docs/libssh2_sftp_mkdir_ex.3 +++ b/docs/libssh2_sftp_mkdir_ex.3 @@ -31,7 +31,7 @@ Create a directory on the remote file system. .SH RETURN VALUE Return 0 on success or negative on failure. LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_read.3 b/docs/libssh2_sftp_read.3 index 9d874223ad..c1709ef50e 100644 --- a/docs/libssh2_sftp_read.3 +++ b/docs/libssh2_sftp_read.3 @@ -29,7 +29,7 @@ to block. .SH RETURN VALUE Number of bytes actually populated into buffer, or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_readdir_ex.3 b/docs/libssh2_sftp_readdir_ex.3 index cdac3ddb2a..c655298ef7 100644 --- a/docs/libssh2_sftp_readdir_ex.3 +++ b/docs/libssh2_sftp_readdir_ex.3 @@ -41,7 +41,7 @@ statbuf style data into. .SH RETURN VALUE Number of bytes actually populated into buffer (not counting the terminating zero), or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would -otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't +otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH BUG Passing in a too small buffer for 'buffer' or 'longentry' when receiving data diff --git a/docs/libssh2_sftp_rename_ex.3 b/docs/libssh2_sftp_rename_ex.3 index 7731bcff51..b6d4a5d3ca 100644 --- a/docs/libssh2_sftp_rename_ex.3 +++ b/docs/libssh2_sftp_rename_ex.3 @@ -46,7 +46,7 @@ and/or using native system calls when possible. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_rmdir_ex.3 b/docs/libssh2_sftp_rmdir_ex.3 index bb1db0854a..c26829704c 100644 --- a/docs/libssh2_sftp_rmdir_ex.3 +++ b/docs/libssh2_sftp_rmdir_ex.3 @@ -23,7 +23,7 @@ remove. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_shutdown.3 b/docs/libssh2_sftp_shutdown.3 index 1a22a4750a..d3424499c1 100644 --- a/docs/libssh2_sftp_shutdown.3 +++ b/docs/libssh2_sftp_shutdown.3 @@ -18,6 +18,6 @@ associated with it. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH SEE ALSO .BR libssh2_sftp_init(3) diff --git a/docs/libssh2_sftp_stat_ex.3 b/docs/libssh2_sftp_stat_ex.3 index 2484a97f3b..14974cb012 100644 --- a/docs/libssh2_sftp_stat_ex.3 +++ b/docs/libssh2_sftp_stat_ex.3 @@ -61,7 +61,7 @@ struct LIBSSH2_SFTP_ATTRIBUTES { .SH RETURN VALUE Returns 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative -number, it isn't really a failure per se. +number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_statvfs.3 b/docs/libssh2_sftp_statvfs.3 index 5f083a58a4..c38cc14a63 100644 --- a/docs/libssh2_sftp_statvfs.3 +++ b/docs/libssh2_sftp_statvfs.3 @@ -60,7 +60,7 @@ Set-user-ID/set-group-ID bits are ignored by \fBexec\fP(3). .SH RETURN VALUE Returns 0 on success or negative on failure. If used in non-blocking mode, it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_symlink_ex.3 b/docs/libssh2_sftp_symlink_ex.3 index f0f485daa0..377ae975b1 100644 --- a/docs/libssh2_sftp_symlink_ex.3 +++ b/docs/libssh2_sftp_symlink_ex.3 @@ -57,7 +57,7 @@ number of bytes it copied to the target buffer (not including the terminating zero) or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. From 1.2.8, LIBSSH2_ERROR_BUFFER_TOO_SMALL is returned if the given 'target' buffer is too small to fit the requested object name. diff --git a/docs/libssh2_sftp_unlink_ex.3 b/docs/libssh2_sftp_unlink_ex.3 index 05861c6011..9a0107bbce 100644 --- a/docs/libssh2_sftp_unlink_ex.3 +++ b/docs/libssh2_sftp_unlink_ex.3 @@ -25,7 +25,7 @@ Unlink (delete) a file from the remote filesystem. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_sftp_write.3 b/docs/libssh2_sftp_write.3 index 6ca0171e1e..8b62e941c1 100644 --- a/docs/libssh2_sftp_write.3 +++ b/docs/libssh2_sftp_write.3 @@ -33,15 +33,15 @@ create several smaller outgoing packets for all data you pass to this function and it will return a positive number as soon as the first packet is acknowledged from the server. -This has the effect that sometimes more data has been sent off but isn't acked +This has the effect that sometimes more data has been sent off but is not acked yet when this function returns, and when this function is subsequently called again to write more data, libssh2 will immediately figure out that the data is already received remotely. In most normal situation this should not cause any problems, but it should be -noted that if you've once called libssh2_sftp_write() with data and it returns -short, you MUST still assume that the rest of the data might've been cached so -you need to make sure you don't alter that data and think that the version you +noted that if you have once called libssh2_sftp_write() with data and it returns +short, you MUST still assume that the rest of the data might have been cached so +you need to make sure you do not alter that data and think that the version you have in your next function invoke will be detected or used. The reason for this funny behavior is that SFTP can only send 32K data in each @@ -52,7 +52,7 @@ latency connections. And we want that. Actual number of bytes written or negative on failure. If used in non-blocking mode, it returns LIBSSH2_ERROR_EAGAIN when it would -otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't +otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. If this function returns 0 (zero) it should not be considered an error, but diff --git a/docs/libssh2_userauth_keyboard_interactive_ex.3 b/docs/libssh2_userauth_keyboard_interactive_ex.3 index cc8daa45ce..8e392aa75a 100644 --- a/docs/libssh2_userauth_keyboard_interactive_ex.3 +++ b/docs/libssh2_userauth_keyboard_interactive_ex.3 @@ -47,7 +47,7 @@ may use keyboard-interactive authentication type too. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative -number, it isn't really a failure per se. +number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_userauth_password_ex.3 b/docs/libssh2_userauth_password_ex.3 index aa5d860184..d63d2e0843 100644 --- a/docs/libssh2_userauth_password_ex.3 +++ b/docs/libssh2_userauth_password_ex.3 @@ -42,7 +42,7 @@ PAM or another authentication backed) instead. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS Some of the errors this function may return include: diff --git a/docs/libssh2_userauth_publickey_fromfile_ex.3 b/docs/libssh2_userauth_publickey_fromfile_ex.3 index d060d68f92..3d7cead0b0 100644 --- a/docs/libssh2_userauth_publickey_fromfile_ex.3 +++ b/docs/libssh2_userauth_publickey_fromfile_ex.3 @@ -34,7 +34,7 @@ on disk .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_userauth_publickey_frommemory.3 b/docs/libssh2_userauth_publickey_frommemory.3 index 6bd26fd1b9..f3b8cbe690 100644 --- a/docs/libssh2_userauth_publickey_frommemory.3 +++ b/docs/libssh2_userauth_publickey_frommemory.3 @@ -17,7 +17,7 @@ libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session, .fi .SH DESCRIPTION This function allows to authenticate a session with a public key read from memory. -It's only supported when libssh2 is backed by OpenSSL. +It is only supported when libssh2 is backed by OpenSSL. \fIsession\fP - Session instance as returned by .BR libssh2_session_init_ex(3) @@ -39,7 +39,7 @@ Attempt public key authentication using a PEM encoded private key file stored in .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/docs/libssh2_userauth_publickey_sk.3 b/docs/libssh2_userauth_publickey_sk.3 index bee31eae8b..bff7683787 100644 --- a/docs/libssh2_userauth_publickey_sk.3 +++ b/docs/libssh2_userauth_publickey_sk.3 @@ -127,7 +127,7 @@ NULL. .SH RETURN VALUE Return 0 on success or negative on failure. It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. While -LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. +LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. .SH ERRORS Some of the errors this function may return include: diff --git a/docs/libssh2_version.3 b/docs/libssh2_version.3 index 2fe99a3d3b..6bd4903621 100644 --- a/docs/libssh2_version.3 +++ b/docs/libssh2_version.3 @@ -19,7 +19,7 @@ bit number in the 0xMMmmpp format. MM for major, mm for minor and pp for patch number. .SH RETURN VALUE The version number of libssh2 is returned as a pointer to a zero terminated -string or NULL if the \fIrequired_version\fP isn't fulfilled. +string or NULL if the \fIrequired_version\fP is not fulfilled. .SH EXAMPLE To make sure you run with the correct libssh2 version: diff --git a/example/scp_write.c b/example/scp_write.c index ac66c0f138..7da38ac733 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { - fprintf(stderr, "Can't open local file %s\n", loclfile); + fprintf(stderr, "Cannot open local file %s\n", loclfile); return 1; } diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 2cc176c2b9..996778cbd3 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { - fprintf(stderr, "Can't open local file %s\n", loclfile); + fprintf(stderr, "Cannot open local file %s\n", loclfile); return 1; } diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 023aefbdbc..61dda86720 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) tempstorage = fopen(storage, "wb"); if(!tempstorage) { - fprintf(stderr, "Can't open temp storage file %s\n", storage); + fprintf(stderr, "Cannot open temp storage file %s\n", storage); goto shutdown; } @@ -271,8 +271,8 @@ int main(int argc, char *argv[]) tempstorage = fopen(storage, "rb"); if(!tempstorage) { - /* weird, we can't read the file we just wrote to... */ - fprintf(stderr, "can't open %s for reading\n", storage); + /* weird, we cannot read the file we just wrote to... */ + fprintf(stderr, "Cannot open %s for reading\n", storage); goto shutdown; } diff --git a/example/sftp_append.c b/example/sftp_append.c index db80e10611..6793ccb7d7 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { - fprintf(stderr, "Can't open local file %s\n", loclfile); + fprintf(stderr, "Cannot open local file %s\n", loclfile); return 1; } diff --git a/example/sftp_write.c b/example/sftp_write.c index 62b0ee0f23..b2169e4007 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { - fprintf(stderr, "Can't open local file %s\n", loclfile); + fprintf(stderr, "Cannot open local file %s\n", loclfile); return 1; } diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 958084b7ba..602a780cf2 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { - fprintf(stderr, "Can't open local file %s\n", loclfile); + fprintf(stderr, "Cannot open local file %s\n", loclfile); return 1; } diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index b8169002f8..b1b7972b23 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) local = fopen(loclfile, "rb"); if(!local) { - fprintf(stderr, "Can't open local file %s\n", loclfile); + fprintf(stderr, "Cannot open local file %s\n", loclfile); return 1; } diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 3bf66e479e..6ad7631398 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) prev_identity = identity; } if(rc) { - fprintf(stderr, "Couldn't continue authentication\n"); + fprintf(stderr, "Could not continue authentication\n"); goto shutdown; } } diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 8718e885af..047920c975 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -185,7 +185,7 @@ int main(int argc, char *argv[]) prev_identity = identity; } if(rc) { - fprintf(stderr, "Couldn't continue authentication\n"); + fprintf(stderr, "Could not continue authentication\n"); goto shutdown; } @@ -214,8 +214,8 @@ int main(int argc, char *argv[]) waitsocket(sock, session); } if(rc) { - fprintf(stderr, "Error, couldn't request auth agent, error code %d.\n", - rc); + fprintf(stderr, "Error, could not request auth agent, " + "error code %d.\n", rc); exit(1); } else { diff --git a/maketgz b/maketgz index 2fae14b9e2..3f5a1932fb 100755 --- a/maketgz +++ b/maketgz @@ -79,7 +79,7 @@ findprog() { # if { findprog automake >/dev/null 2>/dev/null; } then - echo "- Could not find or run automake, I hope you know what you're doing!" + echo "- Could not find or run automake, I hope you know what you are doing!" else echo "Runs automake --include-deps" automake --include-deps Makefile >/dev/null diff --git a/src/channel.c b/src/channel.c index 8aee7b5267..cf09429869 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2361,7 +2361,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, if(channel->local.close) return _libssh2_error(channel->session, LIBSSH2_ERROR_CHANNEL_CLOSED, - "We've already closed this channel"); + "We have already closed this channel"); else if(channel->local.eof) return _libssh2_error(channel->session, LIBSSH2_ERROR_CHANNEL_EOF_SENT, diff --git a/tests/test_auth_keyboard_fail.c b/tests/test_auth_keyboard_fail.c index e8e5942be8..e697d3df30 100644 --- a/tests/test_auth_keyboard_fail.c +++ b/tests/test_auth_keyboard_fail.c @@ -4,5 +4,5 @@ int test(LIBSSH2_SESSION *session) { return test_auth_keyboard(session, TEST_AUTH_SHOULDFAIL, "libssh2", /* set in Dockerfile */ - "I'm the wrong password"); + "I am the wrong password"); } diff --git a/tests/test_auth_password_fail_password.c b/tests/test_auth_password_fail_password.c index c1383213d4..0991f5efb3 100644 --- a/tests/test_auth_password_fail_password.c +++ b/tests/test_auth_password_fail_password.c @@ -4,5 +4,5 @@ int test(LIBSSH2_SESSION *session) { return test_auth_password(session, TEST_AUTH_SHOULDFAIL, "libssh2", /* set in Dockerfile */ - "I'm the wrong password"); + "I am the wrong password"); } diff --git a/tests/test_auth_password_fail_username.c b/tests/test_auth_password_fail_username.c index 6478d0f444..f6ea33a027 100644 --- a/tests/test_auth_password_fail_username.c +++ b/tests/test_auth_password_fail_username.c @@ -3,6 +3,6 @@ int test(LIBSSH2_SESSION *session) { return test_auth_password(session, TEST_AUTH_SHOULDFAIL, - "I'm the wrong username", + "I am the wrong username", "my test password"); /* set in Dockerfile */ } From a683133dfe96de126194f58f183131a84c7d36a2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Apr 2023 21:45:28 +0000 Subject: [PATCH 339/424] tidy-up: C header use - drop unused or duplicate C headers. - add missing ones (that worked by chance). (`string.h`, `stdlib.h`) - mention the functions that need certain headers. - move some headers from crypto header to crypto C source. - reorder headers in some places. - simplify the #if tree for `sys/select.h` in `libssh2_priv.h`. - move scp-specific macros next to their header to `scp.c` Follow-up to 5db836b2a829c6fff1e8c7acaa4b21b246ae1757 Closes #999 --- CMakeLists.txt | 2 +- example/direct_tcpip.c | 7 +------ example/scp.c | 4 ---- example/scp_nonblock.c | 7 ------- example/scp_write.c | 4 ---- example/scp_write_nonblock.c | 9 +-------- example/sftp.c | 5 +---- example/sftp_RW_nonblock.c | 7 ------- example/sftp_append.c | 4 ---- example/sftp_mkdir.c | 4 ---- example/sftp_mkdir_nonblock.c | 4 ---- example/sftp_nonblock.c | 7 ------- example/sftp_write.c | 4 ---- example/sftp_write_nonblock.c | 9 +-------- example/sftp_write_sliding.c | 10 ++-------- example/sftpdir.c | 5 +---- example/sftpdir_nonblock.c | 4 ---- example/ssh2.c | 5 +---- example/ssh2_agent.c | 6 +----- example/ssh2_agent_forwarding.c | 7 ------- example/ssh2_echo.c | 8 +------- example/ssh2_exec.c | 8 +------- example/subsystem_netconf.c | 4 ---- example/tcpip-forward.c | 7 +------ example/x11.c | 7 ------- include/libssh2.h | 4 ---- src/agent.c | 4 ++++ src/agent_win.c | 1 - src/bcrypt_pbkdf.c | 4 ---- src/channel.c | 3 ++- src/comp.c | 1 + src/libgcrypt.c | 2 -- src/libssh2_priv.h | 19 +++---------------- src/mbedtls.c | 2 ++ src/mbedtls.h | 4 +--- src/misc.c | 7 ++----- src/openssl.c | 2 +- src/os400qc3.c | 1 - src/packet.c | 6 ------ src/scp.c | 11 +++++++++-- src/session.c | 9 ++++----- src/sftp.c | 5 +++-- src/transport.c | 6 +----- src/userauth.c | 3 --- tests/openssh_fixture.c | 9 +++++---- tests/session_fixture.c | 20 ++++++++++---------- tests/test_ssh2.c | 2 +- 47 files changed, 62 insertions(+), 211 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f84d4b778c..ec5f74fde6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ check_include_files(inttypes.h HAVE_INTTYPES_H) if(NOT MSVC) check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) - check_include_files(sys/param.h HAVE_SYS_PARAM_H) + check_include_files(sys/param.h HAVE_SYS_PARAM_H) # tests endif() if(NOT WIN32) check_include_files(sys/select.h HAVE_SYS_SELECT_H) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 1d9b041a04..46d21e9082 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -10,9 +10,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -23,11 +20,9 @@ #include #endif -#include -#include -#include #include #include +#include #ifndef INADDR_NONE #define INADDR_NONE (in_addr_t)~0 diff --git a/example/scp.c b/example/scp.c index 2c0e0af68a..a80c5124d3 100644 --- a/example/scp.c +++ b/example/scp.c @@ -22,11 +22,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 615b4ea570..13951dc625 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -17,9 +17,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -33,11 +30,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/scp_write.c b/example/scp_write.c index 7da38ac733..7390548d25 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -18,11 +18,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 996778cbd3..29ff08bdf8 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -8,9 +8,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -21,12 +18,8 @@ #include #endif -#include -#include -#include #include -#include -#include +#include /* for time() */ static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp.c b/example/sftp.c index 3a3c5866f3..c85012bc43 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -28,11 +28,8 @@ #include #endif -#include -#include -#include #include -#include +#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 61dda86720..25f02a3142 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -18,9 +18,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -28,11 +25,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_append.c b/example/sftp_append.c index 6793ccb7d7..60ced4f388 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 3937d5bed6..2edfcba20e 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index acbec2b44d..b990237248 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index b44574c471..19685aca25 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -18,9 +18,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -34,11 +31,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_write.c b/example/sftp_write.c index b2169e4007..85818a710e 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 602a780cf2..4570318d9f 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -14,9 +14,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -27,12 +24,8 @@ #include #endif -#include -#include -#include #include -#include -#include +#include /* for time() */ static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index b1b7972b23..f6f2b33b86 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -14,9 +14,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -27,12 +24,9 @@ #include #endif -#include -#include -#include #include -#include -#include +#include /* for time() */ +#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftpdir.c b/example/sftpdir.c index 655db52588..8d9bd3d992 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -24,11 +24,8 @@ #include #endif -#include -#include -#include #include -#include +#include #if defined(_MSC_VER) #define __FILESIZE "I64u" diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 8237f6a7a5..ca12e6252f 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include #if defined(_MSC_VER) #define __FILESIZE "I64u" diff --git a/example/ssh2.c b/example/ssh2.c index 6267244eae..26f15cfeab 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -28,12 +28,9 @@ #include #endif -#include -#include -#include #include #include -#include +#include #if defined(_MSC_VER) && _MSC_VER < 1900 #define snprintf _snprintf diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 6ad7631398..9c7997d15c 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -22,12 +22,8 @@ #include #endif -#include -#include -#include #include -#include -#include +#include static const char *username = "username"; diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 047920c975..c12c1989c7 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -17,9 +17,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -30,12 +27,8 @@ #include #endif -#include -#include -#include #include #include -#include static const char *hostname = "127.0.0.1"; static const char *commandline = "uptime"; diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index 1fa87b7ad8..70115fede3 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -12,9 +12,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -25,12 +22,9 @@ #include #endif -#include -#include -#include #include #include -#include +#include static const char *hostname = "127.0.0.1"; static const char *commandline = "cat"; diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index d180f62daf..c39421fc1e 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -14,9 +14,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -27,12 +24,9 @@ #include #endif -#include -#include -#include #include #include -#include +#include static const char *hostname = "127.0.0.1"; static const char *commandline = "uptime"; diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index fd24039fea..7029fb8df7 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -14,11 +14,7 @@ #include #endif -#include -#include -#include #include -#include #include #ifndef INADDR_NONE diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index a0b1cd69ba..156075bbb9 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -10,9 +10,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -23,11 +20,9 @@ #include #endif -#include -#include -#include #include #include +#include #ifndef INADDR_NONE #define INADDR_NONE (in_addr_t)~0 diff --git a/example/x11.c b/example/x11.c index 6254519f57..fce0777106 100644 --- a/example/x11.c +++ b/example/x11.c @@ -20,9 +20,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -33,11 +30,7 @@ #include #endif -#include -#include -#include #include -#include #include #include diff --git a/include/libssh2.h b/include/libssh2.h index 2869831754..e13e2f139c 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -185,8 +185,6 @@ typedef int libssh2_socket_t; #ifdef LIBSSH2_USE_WIN32_LARGE_FILES # include -# include -# include # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%I64d" typedef struct _stati64 libssh2_struct_stat; typedef __int64 libssh2_struct_stat_size; @@ -197,8 +195,6 @@ typedef __int64 libssh2_struct_stat_size; */ #ifdef LIBSSH2_USE_WIN32_SMALL_FILES -# include -# include # ifndef _WIN32_WCE # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%d" typedef struct _stat libssh2_struct_stat; diff --git a/src/agent.c b/src/agent.c index cb1fe20ba4..76308f7d3c 100644 --- a/src/agent.c +++ b/src/agent.c @@ -39,7 +39,10 @@ #include "libssh2_priv.h" #include "agent.h" + #include +#include /* for getenv() */ + #ifdef HAVE_SYS_UN_H #include #else @@ -48,6 +51,7 @@ support them. */ #undef PF_UNIX #endif + #include "userauth.h" #include "session.h" diff --git a/src/agent_win.c b/src/agent_win.c index 4a93e1cab2..b735e102cd 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -39,7 +39,6 @@ #include "libssh2_priv.h" #include "agent.h" -#include #if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 5382c0bdb8..91be901cd9 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -20,10 +20,6 @@ #ifndef HAVE_BCRYPT_PBKDF #include -#include -#ifdef HAVE_SYS_PARAM_H -#include -#endif #define LIBSSH2_BCRYPT_PBKDF_C #include "blowfish.c" diff --git a/src/channel.c b/src/channel.c index cf09429869..06a6acaed8 100644 --- a/src/channel.c +++ b/src/channel.c @@ -39,13 +39,14 @@ */ #include "libssh2_priv.h" + #ifdef HAVE_UNISTD_H #include #endif -#include #ifdef HAVE_INTTYPES_H #include #endif + #include #include "channel.h" diff --git a/src/comp.c b/src/comp.c index 527c516ad0..f35650560d 100644 --- a/src/comp.c +++ b/src/comp.c @@ -37,6 +37,7 @@ */ #include "libssh2_priv.h" + #ifdef LIBSSH2_HAVE_ZLIB #include #undef compress /* dodge name clash with ZLIB macro */ diff --git a/src/libgcrypt.c b/src/libgcrypt.c index ccee583491..55d971b653 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -38,8 +38,6 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ -#include - #if LIBSSH2_RSA int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 857b135910..82c3afe250 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -47,6 +47,7 @@ #include "libssh2_setup.h" #include +#include #include #include @@ -59,14 +60,8 @@ */ #ifdef HAVE_POLL # include -#else -# if defined(HAVE_SELECT) && !defined(WIN32) -# ifdef HAVE_SYS_SELECT_H -# include -# else -# include -# endif -# endif +#elif defined(HAVE_SELECT) && defined(HAVE_SYS_SELECT_H) +# include #endif /* Needed for struct iovec on some platforms */ @@ -914,14 +909,6 @@ struct _LIBSSH2_SESSION long packet_read_timeout; }; -#if defined(HAVE_STRTOLL) -#define scpsize_strtol strtoll -#elif defined(HAVE_STRTOI64) -#define scpsize_strtol _strtoi64 -#else -#define scpsize_strtol strtol -#endif - /* session.state bits */ #define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000001 #define LIBSSH2_STATE_NEWKEYS 0x00000002 diff --git a/src/mbedtls.c b/src/mbedtls.c index c7d0b56bf0..4a441cbab1 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -37,6 +37,8 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ +#include + #if MBEDTLS_VERSION_NUMBER < 0x03000000 #define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) #define mbedtls_cipher_info_get_iv_size(c) (c->iv_size) diff --git a/src/mbedtls.h b/src/mbedtls.h index 8065844050..80a051ed08 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -39,9 +39,6 @@ #define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls -#include -#include - #include #include #include @@ -162,6 +159,7 @@ #define libssh2_sha1(data, datalen, hash) \ _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA1, hash) + /*******************************************************************/ /* * mbedTLS backend: SHA256 functions diff --git a/src/misc.c b/src/misc.c index 8151eab77c..10864b8bee 100644 --- a/src/misc.c +++ b/src/misc.c @@ -40,21 +40,18 @@ #include "libssh2_priv.h" #include "misc.h" -#include - #ifdef HAVE_UNISTD_H #include #endif +#include + #ifdef WIN32 /* Force parameter type. */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) #define send(s, b, l, f) send((s), (b), (int)(l), (f)) #endif -#include -#include - /* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible. We provide a safe wrapper if snprintf not found */ #ifdef LIBSSH2_SNPRINTF diff --git a/src/openssl.c b/src/openssl.c index 590b28cca7..89560efc01 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -40,8 +40,8 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ +#include #include -#include #ifndef EVP_MAX_BLOCK_LENGTH #define EVP_MAX_BLOCK_LENGTH 32 diff --git a/src/os400qc3.c b/src/os400qc3.c index 870b510092..ed7e8f6e3e 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -41,7 +41,6 @@ #include -#include #include #include #include diff --git a/src/packet.c b/src/packet.c index 9023f3bf83..8c8e6675f0 100644 --- a/src/packet.c +++ b/src/packet.c @@ -39,24 +39,18 @@ */ #include "libssh2_priv.h" -#include -#include #ifdef HAVE_UNISTD_H #include #endif - #ifdef HAVE_INTTYPES_H #include #endif - /* Needed for struct iovec on some platforms */ #ifdef HAVE_SYS_UIO_H #include #endif -#include - #include "transport.h" #include "channel.h" #include "packet.h" diff --git a/src/scp.c b/src/scp.c index b68cb8e340..b829dad8d7 100644 --- a/src/scp.c +++ b/src/scp.c @@ -37,12 +37,19 @@ */ #include "libssh2_priv.h" -#include -#include #include "channel.h" #include "session.h" +#include /* strtoll(), _strtoi64(), strtol() */ + +#if defined(HAVE_STRTOLL) +#define scpsize_strtol strtoll +#elif defined(HAVE_STRTOI64) +#define scpsize_strtol _strtoi64 +#else +#define scpsize_strtol strtol +#endif /* Max. length of a quoted string after libssh2_shell_quotearg() processing */ #define _libssh2_shell_quotedsize(s) (3 * strlen(s) + 2) diff --git a/src/session.c b/src/session.c index 7b1f6828d5..a4d602bad0 100644 --- a/src/session.c +++ b/src/session.c @@ -42,18 +42,17 @@ #ifdef WIN32 #include /* for socklen_t */ #endif - -#include #ifdef HAVE_UNISTD_H #include #endif -#include -#include - #ifdef HAVE_ALLOCA_H #include #endif +#include +#include +#include + #include "transport.h" #include "session.h" #include "channel.h" diff --git a/src/sftp.c b/src/sftp.c index 6f577378b0..1da891e261 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -37,14 +37,15 @@ * OF SUCH DAMAGE. */ -#include - #include "libssh2_priv.h" #include "libssh2_sftp.h" + #include "channel.h" #include "session.h" #include "sftp.h" +#include + /* This release of libssh2 implements Version 5 with automatic downgrade * based on server's declaration * https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-05.txt diff --git a/src/transport.c b/src/transport.c index bce6413dd7..4eeceab354 100644 --- a/src/transport.c +++ b/src/transport.c @@ -39,13 +39,9 @@ */ #include "libssh2_priv.h" + #include -#include #include -#ifdef LIBSSH2DEBUG -#include -#endif - #include #include "transport.h" diff --git a/src/userauth.c b/src/userauth.c index a1c62f69b0..78b511cc40 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -40,9 +40,6 @@ #include "libssh2_priv.h" #include -#include - -#include /* Needed for struct iovec on some platforms */ #ifdef HAVE_SYS_UIO_H diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index cbe08d99d9..5eab34339e 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -41,19 +41,20 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif -#ifdef HAVE_UNISTD_H -#include -#endif -#include + #include #include #include +#include #if defined(WIN32) && defined(_WIN64) #define LIBSSH2_SOCKET_MASK "%lld" diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 153083e8de..922a442b14 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -38,25 +38,25 @@ #include "session_fixture.h" #include "openssh_fixture.h" -#include -#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#include +#include +#include #ifdef _MSC_VER #include #define chdir _chdir #endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#include - static LIBSSH2_SESSION *connected_session = NULL; static libssh2_socket_t connected_socket = LIBSSH2_INVALID_SOCKET; diff --git a/tests/test_ssh2.c b/tests/test_ssh2.c index a1374b8a2a..2f918cc749 100644 --- a/tests/test_ssh2.c +++ b/tests/test_ssh2.c @@ -17,7 +17,7 @@ #endif #include -#include +#include /* for getenv() */ static const char *hostname = "127.0.0.1"; static const unsigned short port_number = 4711; From 59ed0a784e333d8831fa5a34e6da8b3d58c34a4c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 17 Apr 2023 11:07:21 +0000 Subject: [PATCH 340/424] kex: use distinctive error strings Use unique error strings to help localize errors. Closes #1011 --- src/kex.c | 78 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/kex.c b/src/kex.c index d8884c045f..e9579e665f 100644 --- a/src/kex.c +++ b/src/kex.c @@ -369,7 +369,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, /* Parse KEXDH_REPLY */ if(exchange_state->s_packet_len < 5) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected packet length"); + "Unexpected packet length DH-SHA"); goto clean_exit; } @@ -481,14 +481,15 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, session->server_hostkey_len, &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Unable to initialize hostkey importer"); + "Unable to initialize hostkey importer " + "DH-SHA"); goto clean_exit; } if(_libssh2_get_string(&buf, &(exchange_state->f_value), &(exchange_state->f_value_len))) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Unable to get f value"); + "Unable to get DH-SHA f value"); goto clean_exit; } @@ -498,7 +499,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, if(_libssh2_get_string(&buf, &(exchange_state->h_sig), &(exchange_state->h_sig_len))) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Unable to get h sig"); + "Unable to get DH-SHA h sig"); goto clean_exit; } @@ -514,7 +515,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, LIBSSH2_ALLOC(session, exchange_state->k_value_len); if(!exchange_state->k_value) { ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate buffer for K"); + "Unable to allocate buffer for DH-SHA K"); goto clean_exit; } _libssh2_htonu32(exchange_state->k_value, @@ -623,7 +624,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, exchange_state->h_sig_len, exchange_state->h_sig_comp, digest_len, &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, - "Unable to verify hostkey signature"); + "Unable to verify hostkey signature " + "DH-SHA"); goto clean_exit; } @@ -641,7 +643,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, } else if(rc) { ret = _libssh2_error(session, rc, - "Unable to send NEWKEYS message"); + "Unable to send NEWKEYS message DH-SHA"); goto clean_exit; } @@ -657,14 +659,16 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, return rc; } else if(rc) { - ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); + ret = _libssh2_error(session, rc, + "Timed out waiting for NEWKEYS DH-SHA"); goto clean_exit; } + /* The first key exchange has been performed, switch to active crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; _libssh2_debug((session, LIBSSH2_TRACE_KEX, - "Received NEWKEYS message")); + "Received NEWKEYS message DH-SHA")); /* This will actually end up being just packet_type(1) for this packet type anyway */ @@ -1385,7 +1389,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange( if(key_state->data_len < 9) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected key length DH-SHA1"); goto dh_gex_clean_exit; } @@ -1397,13 +1401,13 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange( if(_libssh2_get_bignum_bytes(&buf, &p, &p_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected value"); + "Unexpected value DH-SHA1 p"); goto dh_gex_clean_exit; } if(_libssh2_get_bignum_bytes(&buf, &g, &g_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected value"); + "Unexpected value DH-SHA1 g"); goto dh_gex_clean_exit; } @@ -1504,7 +1508,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange( if(key_state->data_len < 9) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected key length DH-SHA256"); goto dh_gex_clean_exit; } @@ -1516,13 +1520,13 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange( if(_libssh2_get_bignum_bytes(&buf, &p, &p_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected value"); + "Unexpected value DH-SHA256 p"); goto dh_gex_clean_exit; } if(_libssh2_get_bignum_bytes(&buf, &g, &g_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected value"); + "Unexpected value DH-SHA256 g"); goto dh_gex_clean_exit; } @@ -1746,7 +1750,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, &server_public_key_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for a copy " - "of the host key"); + "of the host ECDH key"); goto clean_exit; } @@ -1843,7 +1847,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, session->server_hostkey_len, &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Unable to initialize hostkey importer"); + "Unable to initialize hostkey importer " + "ECDH"); goto clean_exit; } @@ -1851,7 +1856,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(_libssh2_get_string(&buf, &server_public_key, &server_public_key_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected key length ECDH"); goto clean_exit; } @@ -1859,7 +1864,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(_libssh2_get_string(&buf, &exchange_state->h_sig, &(exchange_state->h_sig_len))) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Unexpected ecdh server sig length"); + "Unexpected ECDH server sig length"); goto clean_exit; } @@ -1881,7 +1886,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, LIBSSH2_ALLOC(session, exchange_state->k_value_len); if(!exchange_state->k_value) { ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate buffer for K"); + "Unable to allocate buffer for ECDH K"); goto clean_exit; } _libssh2_htonu32(exchange_state->k_value, @@ -1911,7 +1916,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, if(rc) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, - "Unable to verify hostkey signature"); + "Unable to verify hostkey signature " + "ECDH"); goto clean_exit; } @@ -1926,7 +1932,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, } else if(rc) { ret = _libssh2_error(session, rc, - "Unable to send NEWKEYS message"); + "Unable to send NEWKEYS message ECDH"); goto clean_exit; } @@ -1942,7 +1948,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, return rc; } else if(rc) { - ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); + ret = _libssh2_error(session, rc, + "Timed out waiting for NEWKEYS ECDH"); goto clean_exit; } @@ -1950,7 +1957,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, switch to active crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; _libssh2_debug((session, LIBSSH2_TRACE_KEX, - "Received NEWKEYS message")); + "Received NEWKEYS message ECDH")); /* This will actually end up being just packet_type(1) for this packet type anyway */ @@ -2353,7 +2360,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(data_len < 5) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected curve25519 key length 1"); goto clean_exit; } @@ -2364,7 +2371,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(_libssh2_get_string(&buf, &server_host_key, &hostkey_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected curve25519 key length 2"); goto clean_exit; } @@ -2374,7 +2381,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(!session->server_hostkey) { ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for a copy " - "of the host key"); + "of the host curve25519 key"); goto clean_exit; } @@ -2472,7 +2479,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, session->server_hostkey_len, &session->server_hostkey_abstract)) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Unable to initialize hostkey importer"); + "Unable to initialize hostkey importer " + "curve25519"); goto clean_exit; } @@ -2480,7 +2488,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(_libssh2_get_string(&buf, &server_public_key, &server_public_key_len)) { ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Unexpected key length"); + "Unexpected curve25519 key length"); goto clean_exit; } @@ -2504,7 +2512,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, server_public_key); if(rc) { ret = _libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE, - "Unable to create ECDH shared secret"); + "Unable to create curve25519 shared secret"); goto clean_exit; } @@ -2535,7 +2543,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, if(rc) { ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, - "Unable to verify hostkey signature"); + "Unable to verify hostkey signature " + "curve25519"); goto clean_exit; } @@ -2550,7 +2559,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, } else if(rc) { ret = _libssh2_error(session, rc, - "Unable to send NEWKEYS message"); + "Unable to send NEWKEYS message curve25519"); goto clean_exit; } @@ -2566,7 +2575,8 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, return rc; } else if(rc) { - ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); + ret = _libssh2_error(session, rc, + "Timed out waiting for NEWKEYS curve25519"); goto clean_exit; } @@ -2574,7 +2584,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, switch to active crypt/comp/mac mode */ session->state |= LIBSSH2_STATE_NEWKEYS; _libssh2_debug((session, LIBSSH2_TRACE_KEX, - "Received NEWKEYS message")); + "Received NEWKEYS message curve25519")); /* This will actually end up being just packet_type(1) for this packet type anyway */ From f36edf94e7af2797fd431a7dc7bbe31213dac7d7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Apr 2023 13:58:26 +0000 Subject: [PATCH 341/424] ci: convert `docker-bridge.bat` to shell script Convert `ci/appveyor/docker-bridge.bat` to a POSIX shell script. Also bump the tunnel to use ed25519 (was RSA-2048). Closes #997 --- ci/appveyor/docker-bridge.bat | 10 ---------- ci/appveyor/docker-bridge.ps1 | 3 ++- ci/appveyor/docker-bridge.sh | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) delete mode 100644 ci/appveyor/docker-bridge.bat create mode 100755 ci/appveyor/docker-bridge.sh diff --git a/ci/appveyor/docker-bridge.bat b/ci/appveyor/docker-bridge.bat deleted file mode 100644 index e83b285d82..0000000000 --- a/ci/appveyor/docker-bridge.bat +++ /dev/null @@ -1,10 +0,0 @@ -@echo off - -netsh interface portproxy add v4tov4 listenport=3389 listenaddress=%1 connectport=22 connectaddress=127.0.0.1 -netsh interface portproxy show all - -C:\msys64\usr\bin\sh -l -c "/usr/bin/ssh-keygen -b 2048 -t rsa -f auth -q -N '' && mkdir .ssh && mv auth.pub .ssh/authorized_keys" -C:\msys64\usr\bin\sh -l -c "/usr/bin/ssh-keygen -A" -C:\msys64\usr\bin\sh -l -c "/usr/bin/sshd" - -C:\msys64\usr\bin\sh -l -c '/usr/bin/curl -F "account=%APPVEYOR_ACCOUNT_NAME%" -F "project=%APPVEYOR_PROJECT_SLUG%" -F "buildid=%APPVEYOR_BUILD_VERSION%" -F "base=%APPVEYOR_REPO_BRANCH%" -F "hash=%APPVEYOR_REPO_COMMIT%" -F "repo=%APPVEYOR_REPO_NAME%" -F "ssh_host=%2" -F "ssh_port=%3" -F "ssh_user=`whoami`" -F "ssh_forward=127.0.0.1:%OPENSSH_SERVER_PORT% 127.0.0.1:%OPENSSH_SERVER_PORT%,127.0.0.1:2375 /var/run/docker.sock" -F "ssh_hostkey=`paste -d , /etc/ssh/ssh_host_*_key.pub`" -F "ssh_privkey=`paste -sd , auth`" -s "https://stuff.marc-hoersken.de/libssh2/dispatch.php"' diff --git a/ci/appveyor/docker-bridge.ps1 b/ci/appveyor/docker-bridge.ps1 index 03dbf7dd29..9778ee0193 100644 --- a/ci/appveyor/docker-bridge.ps1 +++ b/ci/appveyor/docker-bridge.ps1 @@ -19,4 +19,5 @@ $extip = (New-Object Net.WebClient).DownloadString('https://www.appveyor.com/too New-NetFirewallRule -DisplayName "SSH via RDP port" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 22,3389 # launch remote docker daemon with reverse SSH tunnel -& .\ci\appveyor\docker-bridge.bat $ip $extip $port +$scriptPath = (split-path -parent $MyInvocation.MyCommand.Definition) -replace '\\', '/' +& C:\msys64\usr\bin\sh -l -c "$scriptPath/docker-bridge.sh $ip $extip $port" diff --git a/ci/appveyor/docker-bridge.sh b/ci/appveyor/docker-bridge.sh new file mode 100755 index 0000000000..11488a0abc --- /dev/null +++ b/ci/appveyor/docker-bridge.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e + +netsh interface portproxy add v4tov4 listenport=3389 listenaddress="$1" connectport=22 connectaddress=127.0.0.1 +netsh interface portproxy show all + +ssh-keygen -t ed25519 -f auth -q -N '' && mkdir .ssh && mv auth.pub .ssh/authorized_keys +ssh-keygen -A +"$(command -v sshd)" & + +curl \ + -F "account=${APPVEYOR_ACCOUNT_NAME}" \ + -F "project=${APPVEYOR_PROJECT_SLUG}" \ + -F "buildid=${APPVEYOR_BUILD_VERSION}" \ + -F "base=${APPVEYOR_REPO_BRANCH}" \ + -F "hash=${APPVEYOR_REPO_COMMIT}" \ + -F "repo=${APPVEYOR_REPO_NAME}" \ + -F "ssh_host=$2" \ + -F "ssh_port=$3" \ + -F "ssh_user=$(whoami)" \ + -F "ssh_forward=127.0.0.1:${OPENSSH_SERVER_PORT} 127.0.0.1:${OPENSSH_SERVER_PORT},127.0.0.1:2375 /var/run/docker.sock" \ + -F "ssh_hostkey=$(paste -d , /etc/ssh/ssh_host_*_key.pub)" \ + -F "ssh_privkey=$(paste -sd , auth)" \ + -s 'https://stuff.marc-hoersken.de/libssh2/dispatch.php' From d93ccf4901ef26443707d341553994715414e207 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Apr 2023 16:25:25 +0000 Subject: [PATCH 342/424] ci: add macOS CI jobs + fix issues revealed Add macOS CI jobs, both cmake and autotools for all supported crypto backends (except BoringSSL), with debug, zlib enabled. Without running tests. It also introduces OpenSSL 1.1 into the CI with a non-MSVC compiler. Credits to curl's `macos.yml`, that I used as a base. Fix these issues uncovered by the new tests: - openssl: fix warning when built with wolfSSL, or OpenSSL 1.1 and earlier. CI missed it because apparently the only OpenSSL 1.1 test we had used MSVC, which did not complain. ``` ../src/openssl.c:3852:19: error: variable 'sslError' set but not used [-Werror,-Wunused-but-set-variable] unsigned long sslError; ^ ``` Regression from 097c8f0dae558643d43051947a1c35b65e1c5761 - pem: add hack to build without MD5 crypto-backend support. The Homebrew wolfSSL build comes with MD5 support disabled. We can expect this becoming the norm. FIPS also requires MD5 disabled. We deleted the same hack from `hostkey.c` a month ago: ad6aae302aaec84afbfacf0c1dfdc446d46eaf21 A better fix would be to guard the MD5 logic with our `LIBSSH2_MD5` macro. ``` pem.c:214:32: error: use of undeclared identifier 'MD5_DIGEST_LENGTH'; did you mean 'SHA_DIGEST_LENGTH'? unsigned char secret[2*MD5_DIGEST_LENGTH]; ^~~~~~~~~~~~~~~~~ SHA_DIGEST_LENGTH ``` Regression from 386e012292a96fcf0dc6861588397845df0aba2c - `configure.ac`: add crypto libs late. Fix it by adding crypto libs to `LIBS` at the end of the configuration process. Otherwise `configure` links crypto libs while doing feature tests, which can cause unwanted detections. For example LibreSSL publishes the function `explicit_bzero()`, which masks the system alternative, e.g. `memset_s()` on macOS. Then when trying to compile libssh2, its declaration is missing: ``` bcrypt_pbkdf.c:93:5: error: implicit declaration of function 'explicit_bzero' is invalid in C99 [-Werror,-Wimplicit-function-declaration] _libssh2_explicit_zero(ciphertext, sizeof(ciphertext)); ^ ../src/misc.h:50:43: note: expanded from macro '_libssh2_explicit_zero' ^ ``` Regression from 4f0f4bff5a92dce6a6cd7a5600a8ee5660402c3f - cmake: fix to list our own include directory before the crypto libs', when building tests. Otherwise a global crypto header path, such as `/usr/local/include`, containing an external `libssh2.h` of a different version, could cause weird errors: ``` cc -DHAVE_CONFIG_H -DLIBSSH2_LIBGCRYPT \ -I../src -I../../src -I/usr/local/include -I[...]/libssh2/include \ -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk \ -mmacosx-version-min=12.6 -MD -MT \ tests/CMakeFiles/test_aa_warmup.dir/test_aa_warmup.c.o \ -MF CMakeFiles/test_aa_warmup.dir/test_aa_warmup.c.o.d \ -o CMakeFiles/test_aa_warmup.dir/test_aa_warmup.c.o -c \ [...]/libssh2/tests/test_aa_warmup.c ``` ``` [ 62%] Building C object tests/CMakeFiles/test_aa_warmup.dir/test_aa_warmup.c.o In file included from /Users/runner/work/libssh2/libssh2/tests/test_aa_warmup.c:4: In file included from /Users/runner/work/libssh2/libssh2/tests/runner.h:42: In file included from /Users/runner/work/libssh2/libssh2/tests/session_fixture.h:43: /Users/runner/work/libssh2/libssh2/tests/../src/libssh2_priv.h:649:5: error: type name requires a specifier or qualifier LIBSSH2_AUTHAGENT_FUNC((*authagent)); ^ /Users/runner/work/libssh2/libssh2/tests/../src/libssh2_priv.h:649:30: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int] LIBSSH2_AUTHAGENT_FUNC((*authagent)); ^ /Users/runner/work/libssh2/libssh2/tests/../src/libssh2_priv.h:650:5: error: type name requires a specifier or qualifier LIBSSH2_ADD_IDENTITIES_FUNC((*addLocalIdentities)); ^ /Users/runner/work/libssh2/libssh2/tests/../src/libssh2_priv.h:650:35: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int] LIBSSH2_ADD_IDENTITIES_FUNC((*addLocalIdentities)); ^ /Users/runner/work/libssh2/libssh2/tests/../src/libssh2_priv.h:651:5: error: type name requires a specifier or qualifier LIBSSH2_AUTHAGENT_SIGN_FUNC((*agentSignCallback)); ^ /Users/runner/work/libssh2/libssh2/tests/../src/libssh2_priv.h:651:35: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int] LIBSSH2_AUTHAGENT_SIGN_FUNC((*agentSignCallback)); ^ 6 errors generated. ``` - `tests/session_fixture.h`: delete duplicate `libssh2.h`, `libssh2_priv.h` already includes it. Follow-up to a683133dfe96de126194f58f183131a84c7d36a2 CI logs with these errors: https://github.com/libssh2/libssh2/actions/runs/4824079094 https://github.com/libssh2/libssh2/actions/runs/4824270819 curl's `macos.yml`: https://github.com/curl/curl/blob/da2470de96e94e1c8d276b9ae6e4c97c2cf54239/.github/workflows/macos.yml Tidying-up while here: - tests/session_fixture.h: delete duplicate `libssh2.h`. `libssh2_priv.h` includes it already. Follow-up to a683133dfe96de126194f58f183131a84c7d36a2 - ci.yml: yamllint warnings and formatting. - ci.yml: msvc section formatting and step-naming sync with macOS. Follow-up to f4a4c05dc3bcd62ecaa1b0cac5997faefe16c83f - ci.yml: enable `--enable-werror` for msys2 jobs. Follow-up to 71cae949d577fdd632a271da0bec89f977dc5dd2 - appveyor.yml: show OpenSSL versions, link to image content. Closes #1013 --- .github/workflows/ci.yml | 99 +++++++++++++++++++++++++++++++++------- appveyor.yml | 14 +++--- configure.ac | 25 +++++----- src/openssl.c | 10 +++- src/pem.c | 6 +++ tests/CMakeLists.txt | 2 +- tests/session_fixture.h | 1 - 7 files changed, 119 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00d2bd110f..4e5062be86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: check_style: @@ -68,7 +68,7 @@ jobs: if: ${{ matrix.b == 'configure' }} run: | autoreconf -fi - ./configure --enable-debug --enable-werror + ./configure --enable-werror --enable-debug make -j3 make check VERBOSE=1 - name: Build with CMake @@ -103,16 +103,16 @@ jobs: - uses: actions/checkout@v3 - uses: msys2/setup-msys2@v2 with: - msystem: ${{matrix.sys}} + msystem: ${{ matrix.sys }} install: >- - mingw-w64-${{matrix.env}}-cc - mingw-w64-${{matrix.env}}-autotools - mingw-w64-${{matrix.env}}-openssl + mingw-w64-${{ matrix.env }}-cc + mingw-w64-${{ matrix.env }}-autotools + mingw-w64-${{ matrix.env }}-openssl - name: Building libssh2 shell: msys2 {0} run: | autoreconf -fi - ./configure --enable-debug --enable-static --disable-shared --with-crypto=openssl + ./configure --enable-werror --enable-debug --enable-static --disable-shared --with-crypto=openssl make -j3 make check VERBOSE=1 @@ -133,11 +133,11 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v3 - - name: Configure with CMake + - name: 'cmake generate' shell: bash run: | - archgen=${{matrix.arch}}; [ "${archgen}" = 'x86' ] && archgen='Win32' - if [ "${{matrix.plat}}" = 'uwp' ]; then + archgen=${{ matrix.arch }}; [ "${archgen}" = 'x86' ] && archgen='Win32' + if [ "${{ matrix.plat }}" = 'uwp' ]; then system='WindowsStore' options='-DCMAKE_SYSTEM_VERSION=10.0' else @@ -147,12 +147,77 @@ jobs: -DCMAKE_SYSTEM_NAME=${system} \ -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \ -DCMAKE_GENERATOR_PLATFORM=${archgen} \ - -DVCPKG_TARGET_TRIPLET=${{matrix.arch}}-${{matrix.plat}} \ + -DVCPKG_TARGET_TRIPLET=${{ matrix.arch }}-${{ matrix.plat }} \ -DENABLE_WERROR=ON \ - -DENABLE_DEBUG_LOGGING=${{matrix.log}} \ - -DBUILD_SHARED_LIBS=${{matrix.shared}} \ - -DCRYPTO_BACKEND=${{matrix.crypto}} \ - -DENABLE_ZLIB_COMPRESSION=${{matrix.zlib}} - - name: Build with CMake + -DENABLE_DEBUG_LOGGING=${{ matrix.log }} \ + -DBUILD_SHARED_LIBS=${{ matrix.shared }} \ + -DCRYPTO_BACKEND=${{ matrix.crypto }} \ + -DENABLE_ZLIB_COMPRESSION=${{ matrix.zlib }} + - name: 'cmake build' run: | cmake --build bld --config Release --target package + + build_macos: + name: macOS (${{ matrix.build }}, ${{ matrix.crypto.name }}) + runs-on: macos-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + build: [autotools, cmake] + crypto: + - name: OpenSSL 3 + install: openssl + configure: --with-crypto=openssl --with-libssl-prefix=/usr/local/opt/openssl + cmake: -DCRYPTO_BACKEND=OpenSSL -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl + - name: OpenSSL 1.1 + install: openssl@1.1 + configure: --with-crypto=openssl --with-libssl-prefix=/usr/local/opt/openssl@1.1 + cmake: -DCRYPTO_BACKEND=OpenSSL -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1 + - name: LibreSSL + install: libressl + configure: --with-crypto=openssl --with-libssl-prefix=/usr/local/opt/libressl + cmake: -DCRYPTO_BACKEND=OpenSSL -DOPENSSL_ROOT_DIR=/usr/local/opt/libressl + - name: wolfSSL + install: wolfssl + configure: --with-crypto=wolfssl --with-libwolfssl-prefix=/usr/local/opt/wolfssl + cmake: -DCRYPTO_BACKEND=wolfSSL + - name: libgcrypt + install: libgcrypt + configure: --with-crypto=libgcrypt --with-libgcrypt-prefix=/usr/local/opt/libgcrypt + cmake: -DCRYPTO_BACKEND=Libgcrypt + - name: mbedTLS + install: mbedtls + configure: --with-crypto=mbedtls --with-libmbedcrypto-prefix=/usr/local/opt/mbedtls + cmake: -DCRYPTO_BACKEND=mbedTLS -DMBEDCRYPTO_LIBRARY=/usr/local/opt/mbedtls/lib/libmbedcrypto.a -DMBEDTLS_LIBRARY=/usr/local/opt/mbedtls/lib/libmbedtls.a -DMBEDX509_LIBRARY=/usr/local/opt/mbedtls/lib/libmbedx509.a -DMBEDTLS_INCLUDE_DIR=/usr/local/opt/mbedtls/include + steps: + - name: 'brew install' + run: | + brew install automake ${{ matrix.crypto.install }} + + - uses: actions/checkout@v3 + + - name: 'autotools autoreconf' + if: ${{ matrix.build == 'autotools' }} + run: autoreconf -fi + - name: 'autotools configure' + if: ${{ matrix.build == 'autotools' }} + run: | + ./configure ${{ matrix.crypto.configure }} \ + --enable-werror \ + --enable-debug \ + --with-libz + - name: 'autotools make' + if: ${{ matrix.build == 'autotools' }} + run: make + + - name: 'cmake generate' + if: ${{ matrix.build == 'cmake' }} + run: | + cmake . -B bld ${{ matrix.crypto.cmake }} \ + -DENABLE_WERROR=ON \ + -DENABLE_DEBUG_LOGGING=ON \ + -DENABLE_ZLIB_COMPRESSION=ON + - name: 'cmake build' + if: ${{ matrix.build == 'cmake' }} + run: cmake --build bld diff --git a/appveyor.yml b/appveyor.yml index a8bb9ff829..898baf75af 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,25 +24,27 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# https://www.appveyor.com/docs/windows-images-software/ + environment: CONFIGURATION: "Release" FIXTURE_XFER_COUNT: 35020 matrix: - - job_name: "VS2022, OpenSSL3, x64, Server 2019" + - job_name: "VS2022, OpenSSL 3, x64, Server 2019" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" GENERATOR: "Visual Studio 17 2022" PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2015, OpenSSL, x86, Server 2016" + - job_name: "VS2015, OpenSSL 1.1, x86, Server 2016" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2015, OpenSSL, x64, Server 2012 R2, Logging" + - job_name: "VS2015, OpenSSL 1.1, x64, Server 2012 R2, Logging" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 14 2015" PLATFORM: "x64" @@ -50,21 +52,21 @@ environment: CRYPTO_BACKEND: "OpenSSL" ENABLE_DEBUG_LOGGING: "ON" - - job_name: "VS2013, OpenSSL, x64, Server 2012 R2" + - job_name: "VS2013, OpenSSL 1.1, x64, Server 2012 R2" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" PLATFORM: "x64" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, x86, Server 2012 R2" + - job_name: "VS2013, OpenSSL 1.1, x86, Server 2012 R2" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" PLATFORM: "x86" BUILD_SHARED_LIBS: "ON" CRYPTO_BACKEND: "OpenSSL" - - job_name: "VS2013, OpenSSL, x64, Build-only, Static-only" + - job_name: "VS2013, OpenSSL 1.0.2, x64, Build-only, Static-only" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2015" GENERATOR: "Visual Studio 12 2013" PLATFORM: "x64" diff --git a/configure.ac b/configure.ac index 140cf179c0..42f7b2593d 100644 --- a/configure.ac +++ b/configure.ac @@ -117,18 +117,6 @@ else test "$found_crypto_str" = "" && found_crypto_str="$found_crypto" fi -if test "$found_crypto" = "openssl"; then - LIBS="${LIBS} ${LTLIBSSL}" -elif test "$found_crypto" = "wolfssl"; then - LIBS="${LIBS} ${LTLIBWOLFSSL}" -elif test "$found_crypto" = "libgcrypt"; then - LIBS="${LIBS} ${LTLIBGCRYPT}" -elif test "$found_crypto" = "wincng"; then - LIBS="${LIBS} ${LTLIBBCRYPT}" -elif test "$found_crypto" = "mbedtls"; then - LIBS="${LIBS} ${LTLIBMBEDCRYPTO}" -fi - # libz AC_ARG_WITH([libz], @@ -377,6 +365,19 @@ AM_CONDITIONAL([HOST_WINDOWS], [test "x$host_windows" = "xyes"]) # Configure parameters LIBSSH2_CHECK_OPTION_WERROR +# Append crypto lib +if test "$found_crypto" = "openssl"; then + LIBS="${LIBS} ${LTLIBSSL}" +elif test "$found_crypto" = "wolfssl"; then + LIBS="${LIBS} ${LTLIBWOLFSSL}" +elif test "$found_crypto" = "libgcrypt"; then + LIBS="${LIBS} ${LTLIBGCRYPT}" +elif test "$found_crypto" = "wincng"; then + LIBS="${LIBS} ${LTLIBBCRYPT}" +elif test "$found_crypto" = "mbedtls"; then + LIBS="${LIBS} ${LTLIBMBEDCRYPTO}" +fi + AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile diff --git a/src/openssl.c b/src/openssl.c index 89560efc01..02bcc6e1b5 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -3835,6 +3835,10 @@ read_openssh_private_key_from_memory(void **key_ctx, LIBSSH2_SESSION *session, passphrase); } +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +#define HAVE_SSLERROR_BAD_DECRYPT +#endif + int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, unsigned char **method, @@ -3849,7 +3853,9 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, BIO* bp; EVP_PKEY* pk; int pktype; +#ifdef HAVE_SSLERROR_BAD_DECRYPT unsigned long sslError; +#endif _libssh2_debug((session, LIBSSH2_TRACE_AUTH, @@ -3866,7 +3872,9 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, "computing public key"); BIO_reset(bp); pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); +#ifdef HAVE_SSLERROR_BAD_DECRYPT sslError = ERR_get_error(); +#endif BIO_free(bp); if(!pk) { @@ -3882,7 +3890,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, if(st == 0) return 0; -#if OPENSSL_VERSION_NUMBER >= 0x30000000L /* OpenSSL 3.0.0 */ +#ifdef HAVE_SSLERROR_BAD_DECRYPT if((ERR_GET_LIB(sslError) == ERR_LIB_PEM && ERR_GET_REASON(sslError) == PEM_R_BAD_DECRYPT) || (ERR_GET_LIB(sslError) == ERR_LIB_PROV && diff --git a/src/pem.c b/src/pem.c index a02378e91a..6e17e3264f 100644 --- a/src/pem.c +++ b/src/pem.c @@ -104,6 +104,12 @@ static unsigned char hex_decode(char digit) ((digit >= 'A') ? (0xA + (digit - 'A')) : (digit - '0')); } +/* Hack to fix builds with crypto backends with MD5 support disabled. + FIXME: Honor our LIBSSH2_MD5 macro for MD5-dependent logic. */ +#ifdef OPENSSL_NO_MD5 +#define MD5_DIGEST_LENGTH 16 +#endif + int _libssh2_pem_parse(LIBSSH2_SESSION * session, const char *headerbegin, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f0fd0862c7..793f0800e0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -79,7 +79,7 @@ foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS}) if(NOT TARGET ${test}) add_executable(${test} ${test}.c) target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}") - target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") + target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include "${CRYPTO_BACKEND_INCLUDE_DIR}") # build a single test with gcov if(GCOV_PATH AND test STREQUAL test_auth_keyboard_info_request) diff --git a/tests/session_fixture.h b/tests/session_fixture.h index 91db09a934..1fad3ba7bf 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -41,7 +41,6 @@ #define LIBSSH2_TESTS #include "libssh2_priv.h" -#include LIBSSH2_SESSION *start_session_fixture(int *skipped); void stop_session_fixture(void); From ccac522260ab93935399b3e47a27e94a6ccab51d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Apr 2023 14:10:11 +0000 Subject: [PATCH 343/424] checksrc: update and apply fixes Update to latest revision and fix new issues detected. Closes #1014 --- ci/checksrc.pl | 19 ++++++++++++++----- src/openssl.c | 2 +- src/pem.c | 2 +- src/sftp.c | 6 +++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ci/checksrc.pl b/ci/checksrc.pl index 2aab0ad8fb..540b22978f 100755 --- a/ci/checksrc.pl +++ b/ci/checksrc.pl @@ -90,6 +90,7 @@ 'SPACEBEFORECOMMA' => 'space before a comma', 'SPACEBEFOREPAREN' => 'space before an open parenthesis', 'SPACESEMICOLON' => 'space before semicolon', + 'SPACESWITCHCOLON' => 'space before colon of switch label', 'TABS' => 'TAB characters not allowed', 'TRAILINGSPACE' => 'Trailing whitespace on the line', 'TYPEDEFSTRUCT' => 'typedefed struct', @@ -517,7 +518,8 @@ sub scanfile { my $nostr = nostrings($l); # check spaces after for/if/while/function call - if($nostr =~ /^(.*)(for|if|while| ([a-zA-Z0-9_]+)) \((.)/) { + if($nostr =~ /^(.*)(for|if|while|switch| ([a-zA-Z0-9_]+)) \((.)/) { + my ($leading, $word, $extra, $first)=($1,$2,$3,$4); if($1 =~ / *\#/) { # this is a #if, treat it differently } @@ -527,15 +529,16 @@ sub scanfile { elsif(defined $3 && $3 eq "case") { # case must have a space } - elsif($4 eq "*") { - # (* beginning makes the space OK! + elsif(($first eq "*") && ($word !~ /(for|if|while|switch)/)) { + # A "(*" beginning makes the space OK because it wants to + # allow funcion pointer declared } elsif($1 =~ / *typedef/) { # typedefs can use space-paren } else { - checkwarn("SPACEBEFOREPAREN", $line, length($1)+length($2), $file, $l, - "$2 with space"); + checkwarn("SPACEBEFOREPAREN", $line, length($leading)+length($word), $file, $l, + "$word with space"); } } # check for '== NULL' in if/while conditions but not if the thing on @@ -688,6 +691,12 @@ sub scanfile { $line, length($1), $file, $ol, "no space before semicolon"); } + # check for space before the colon in a switch label + if($l =~ /^( *(case .+|default)) :/) { + checkwarn("SPACESWITCHCOLON", + $line, length($1), $file, $ol, "no space before colon of switch label"); + } + # scan for use of banned functions if($l =~ /^(.*\W) (gmtime|localtime| diff --git a/src/openssl.c b/src/openssl.c index 02bcc6e1b5..a4036f7074 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -3574,7 +3574,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, session, method, method_len, pubkeydata, pubkeydata_len, 0, pk); break; #endif /* LIBSSH2_ECDSA */ - default : + default: st = _libssh2_error(session, LIBSSH2_ERROR_FILE, "Unable to extract public key " diff --git a/src/pem.c b/src/pem.c index 6e17e3264f..f4cac17413 100644 --- a/src/pem.c +++ b/src/pem.c @@ -782,7 +782,7 @@ _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION * session, *line = '\0'; do { - if (*line) { + if(*line) { char *tmp; size_t linelen; diff --git a/src/sftp.c b/src/sftp.c index 1da891e261..629311dfdf 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -521,7 +521,7 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Got %d", (int) packet_type)); - if (*data_len < required_size) { + if(*data_len < required_size) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } @@ -539,7 +539,7 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Got %d", (int) packet_type)); - if (*data_len < required_size) { + if(*data_len < required_size) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } @@ -581,7 +581,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses, */ sftp->requirev_start = 0; - if (*data_len < required_size) { + if(*data_len < required_size) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; } From fc7e79e44274d259ba6fad511ea1b4213b8b6b35 Mon Sep 17 00:00:00 2001 From: Zenju Date: Mon, 1 May 2023 22:17:18 +0200 Subject: [PATCH 344/424] sftp: remove packet limit for directory reading (#791) Currently libssh2 cannot read huge directory listings when the package size of `LIBSSH2_SFTP_PACKET_MAXLEN` (256KB) is hit. For example AWS always sends a single package with all files of a directory, no matter how big it is: https://freefilesync.org/forum/viewtopic.php?t=10020 Package size is probably around 7MB in this case! `LIBSSH2_SFTP_PACKET_MAXLEN` is a good idea in general, but there doesn't seem to be a one size fits all. While almost all(?) SFTP responses come in very small packages, I believe the `SSH_FXP_READDIR` request should be exempted. The proposed patch, enhances the package size reading to include parsing the full SFTP packet header. And in case a package is of type `SSH_FXP_NAME` and matches an expected `readdir_request_id`, it does not fail if `LIBSSH2_SFTP_PACKET_MAXLEN` is hit. The chances of accidentally hiding data-corruption are pretty non-existent, because both SFTP `request_id` and packet type must match. No change in behavior otherwise. Best, Zenju Previous discussion: #268 #269 With the above changes, the `LIBSSH2_SFTP_PACKET_MAXLEN` value could (and should?) probably be set back to a small number again. Integration-patches-by: Viktor Szakats --- src/sftp.c | 39 +++++++++++++++++++++++++-------------- src/sftp.h | 7 ++++--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index 629311dfdf..aad28154e1 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -287,6 +287,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) ssize_t rc; unsigned long recv_window; int packet_type; + uint32_t request_id; _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "recv packet")); @@ -315,35 +316,44 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) /* each packet starts with a 32 bit length field */ rc = _libssh2_channel_read(channel, 0, - (char *)&sftp->partial_size[ - sftp->partial_size_len], - 4 - sftp->partial_size_len); + (char *)&sftp->packet_header[ + sftp->packet_header_len], + sizeof(sftp->packet_header) - + sftp->packet_header_len); if(rc == LIBSSH2_ERROR_EAGAIN) return (int)rc; else if(rc < 0) return _libssh2_error(session, (int)rc, "channel read"); - sftp->partial_size_len += rc; + sftp->packet_header_len += rc; - if(4 != sftp->partial_size_len) - /* we got a short read for the length part */ + if(sftp->packet_header_len != sizeof(sftp->packet_header)) + /* we got a short read for the header part */ return LIBSSH2_ERROR_EAGAIN; - sftp->partial_len = _libssh2_ntohu32(sftp->partial_size); + /* parse SFTP packet header */ + sftp->partial_len = _libssh2_ntohu32(sftp->packet_header); + packet_type = sftp->packet_header[4]; + request_id = _libssh2_ntohu32(sftp->packet_header + 5); + /* make sure we don't proceed if the packet size is unreasonably large */ - if(sftp->partial_len > LIBSSH2_SFTP_PACKET_MAXLEN) { + if(sftp->partial_len > LIBSSH2_SFTP_PACKET_MAXLEN && + /* exception: response to SSH_FXP_READDIR request */ + !(sftp->readdir_state != libssh2_NB_state_idle && + sftp->readdir_request_id == request_id && + packet_type == SSH_FXP_NAME)) { libssh2_channel_flush(channel); - sftp->partial_size_len = 0; + sftp->packet_header_len = 0; return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, "SFTP packet too large"); } - if(sftp->partial_len == 0) + if(sftp->partial_len < 5) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate empty SFTP packet"); + "Invalid SFTP packet size"); _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Data begin - Packet Length: %lu", @@ -352,10 +362,11 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) if(!packet) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate SFTP packet"); - sftp->partial_size_len = 0; - sftp->partial_received = 0; /* how much of the packet already - received */ + sftp->packet_header_len = 0; sftp->partial_packet = packet; + /* copy over packet type(4) and request id(1) */ + sftp->partial_received = 5; + memcpy(packet, sftp->packet_header + 4, 5); window_adjust: recv_window = libssh2_channel_window_read_ex(channel, NULL, NULL); diff --git a/src/sftp.h b/src/sftp.h index 891a89db1d..267301f1bc 100644 --- a/src/sftp.h +++ b/src/sftp.h @@ -149,9 +149,10 @@ struct _LIBSSH2_SFTP uint32_t last_errno; /* Holder for partial packet, use in libssh2_sftp_packet_read() */ - unsigned char partial_size[4]; /* buffer for size field */ - size_t partial_size_len; /* size field length */ - unsigned char *partial_packet; /* The data */ + unsigned char packet_header[9]; + /* packet size (4) packet type (1) request id (4) */ + size_t packet_header_len; /* packet_header length */ + unsigned char *partial_packet; /* The data, with header */ uint32_t partial_len; /* Desired number of bytes */ size_t partial_received; /* Bytes received so far */ From 738cbf5503641e643d55bed56d5d79deebae1af1 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 3 May 2023 01:05:27 +0000 Subject: [PATCH 345/424] docker-bridge.ps1: use native newlines Also add a shebang and exec flag to ease testing/handling on *nix. PowerShell accepts both LF and CRLF. Cherry-picked from #1017 --- ci/appveyor/docker-bridge.ps1 | 48 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) mode change 100644 => 100755 ci/appveyor/docker-bridge.ps1 diff --git a/ci/appveyor/docker-bridge.ps1 b/ci/appveyor/docker-bridge.ps1 old mode 100644 new mode 100755 index 9778ee0193..201ef1d44c --- a/ci/appveyor/docker-bridge.ps1 +++ b/ci/appveyor/docker-bridge.ps1 @@ -1,23 +1,25 @@ -# Partially copied from https://github.com/appveyor/ci/blob/master/scripts/enable-rdp.ps1 - -# get current IP -$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like 'ethernet*'}).IPAddress -$port = 3389 -if($ip.StartsWith('172.24.')) { - $port = 33800 + ($ip.split('.')[2] - 16) * 256 + $ip.split('.')[3] -} elseif ($ip.StartsWith('192.168.') -or $ip.StartsWith('10.240.')) { - # new environment - behind NAT - $port = 33800 + ($ip.split('.')[2] - 0) * 256 + $ip.split('.')[3] -} elseif ($ip.StartsWith('10.0.')) { - $port = 33800 + ($ip.split('.')[2] - 0) * 256 + $ip.split('.')[3] -} - -# get external IP -$extip = (New-Object Net.WebClient).DownloadString('https://www.appveyor.com/tools/my-ip.aspx').Trim() - -# allow inbound traffic -New-NetFirewallRule -DisplayName "SSH via RDP port" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 22,3389 - -# launch remote docker daemon with reverse SSH tunnel -$scriptPath = (split-path -parent $MyInvocation.MyCommand.Definition) -replace '\\', '/' -& C:\msys64\usr\bin\sh -l -c "$scriptPath/docker-bridge.sh $ip $extip $port" +#!/usr/bin/env pwsh + +# Partially copied from https://github.com/appveyor/ci/blob/master/scripts/enable-rdp.ps1 + +# get current IP +$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like 'ethernet*'}).IPAddress +$port = 3389 +if($ip.StartsWith('172.24.')) { + $port = 33800 + ($ip.split('.')[2] - 16) * 256 + $ip.split('.')[3] +} elseif ($ip.StartsWith('192.168.') -or $ip.StartsWith('10.240.')) { + # new environment - behind NAT + $port = 33800 + ($ip.split('.')[2] - 0) * 256 + $ip.split('.')[3] +} elseif ($ip.StartsWith('10.0.')) { + $port = 33800 + ($ip.split('.')[2] - 0) * 256 + $ip.split('.')[3] +} + +# get external IP +$extip = (New-Object Net.WebClient).DownloadString('https://www.appveyor.com/tools/my-ip.aspx').Trim() + +# allow inbound traffic +New-NetFirewallRule -DisplayName "SSH via RDP port" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 22,3389 + +# launch remote docker daemon with reverse SSH tunnel +$scriptPath = (split-path -parent $MyInvocation.MyCommand.Definition) -replace '\\', '/' +& C:\msys64\usr\bin\sh -l -c "$scriptPath/docker-bridge.sh $ip $extip $port" From 7aab5bd6f9960afdf380af772822b2c43e4f33d8 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Apr 2023 20:55:48 +0000 Subject: [PATCH 346/424] build: fix autoreconf warnings - update `AC_HELP_STRING' to 'AS_HELP_STRING`: ``` configure.ac:[...]: warning: The macro `AC_HELP_STRING' is obsolete. ``` "AC_HELP_STRING is deprecated in 2.70+ and I believe AS_HELP_STRING works already since 2.59 so bump the minimum required version to that." Ref: https://github.com/curl/curl/commit/a59f04611629f0db9ad8e768b9def73b9b4d9423 - simplify to avoid: ``` src/Makefile.inc:48: warning: variable 'EXTRA_DIST_SOURCES' is defined but no program or src/Makefile.inc:48: library has 'DIST' as canonical name (possible typo) ``` Regression from 2c18b6fc8df060c770fa7e5da704c32cf40a5757 - `AC_TRY_LINK`/`AC_TRY_COMPILE`: ``` configure.ac:335: warning: The macro `AC_TRY_COMPILE' is obsolete. configure.ac:335: warning: The macro `AC_TRY_LINK' is obsolete. ``` - `libtool`-related ones: ``` configure.ac:70: warning: The macro `AC_LIBTOOL_WIN32_DLL' is obsolete. configure.ac:70: warning: AC_LIBTOOL_WIN32_DLL: Remove this warning and the call to _LT_SET_OPTION when you configure.ac:70: put the 'win32-dll' option into LT_INIT's first parameter. configure.ac:71: warning: The macro `AC_PROG_LIBTOOL' is obsolete. ``` Using code copied from curl: https://github.com/curl/curl/blob/9ce7eee07042605045dcfd02a6f5b38ad5c8a05d/m4/xc-lt-iface.m4#L157-L163 - delete commented and obsolete `AC_HEADER_STDC`. - formatting. Most cherry-picked from `autoupdate` updates. Cherry-picked from #1017 Closes #1021 --- acinclude.m4 | 28 ++++++++++++++-------------- configure.ac | 34 +++++++++++++++++++--------------- m4/lib-link.m4 | 4 ++-- src/Makefile.am | 5 ++--- src/Makefile.inc | 2 +- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 49592e5c18..1d7121e71c 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -554,12 +554,12 @@ AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], [ AC_MSG_CHECKING([non-blocking sockets style]) - AC_TRY_COMPILE([ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ /* headers for O_NONBLOCK test */ #include #include #include -],[ +]], [[ /* try to compile O_NONBLOCK */ #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) @@ -578,22 +578,22 @@ AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], #endif int socket; int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK); -],[ +]])],[ dnl the O_NONBLOCK test was fine nonblock="O_NONBLOCK" AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets]) ],[ dnl the code was bad, try a different program now, test 2 - AC_TRY_COMPILE([ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ /* headers for FIONBIO test */ #include #include -],[ +]], [[ /* FIONBIO source test (old-style unix) */ int socket; int flags = ioctl(socket, FIONBIO, &flags); -],[ +]])],[ dnl FIONBIO test was good nonblock="FIONBIO" AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets]) @@ -601,28 +601,28 @@ AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets]) dnl FIONBIO test was also bad dnl the code was bad, try a different program now, test 3 - AC_TRY_LINK([ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ /* headers for IoctlSocket test (Amiga?) */ #include -],[ +]], [[ /* IoctlSocket source code */ int socket; int flags = IoctlSocket(socket, FIONBIO, (long)1); -],[ +]])],[ dnl ioctlsocket test was good nonblock="IoctlSocket" AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets]) ],[ dnl Ioctlsocket did not compile, do test 4! - AC_TRY_COMPILE([ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ /* headers for SO_NONBLOCK test (BeOS) */ #include -],[ +]], [[ /* SO_NONBLOCK source code */ long b = 1; int socket; int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); -],[ +]])],[ dnl the SO_NONBLOCK test was good nonblock="SO_NONBLOCK" AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets]) @@ -844,8 +844,8 @@ AC_DEFUN([LIBSSH2_CHECK_OPTION_WERROR], [ AC_MSG_CHECKING([whether to enable compiler warnings as errors]) OPT_COMPILER_WERROR="default" AC_ARG_ENABLE(werror, -AC_HELP_STRING([--enable-werror],[Enable compiler warnings as errors]) -AC_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]), +AS_HELP_STRING([--enable-werror],[Enable compiler warnings as errors]) +AS_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]), OPT_COMPILER_WERROR=$enableval) case "$OPT_COMPILER_WERROR" in no) diff --git a/configure.ac b/configure.ac index 42f7b2593d..4f83ddb617 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ -# AC_PREREQ(2.57) -AC_INIT(libssh2, [-], libssh2-devel@lists.haxx.se) +# AC_PREREQ(2.59) +AC_INIT([libssh2],[-],[libssh2-devel@lists.haxx.se]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([src]) AC_CONFIG_HEADERS([src/libssh2_config.h]) @@ -67,8 +67,13 @@ AC_PATH_PROGS(SSHD, [sshd], [], [$PATH$PATH_SEPARATOR/usr/libexec$PATH_SEPARATOR]dnl [/usr/sbin$PATH_SEPARATOR/usr/etc$PATH_SEPARATOR/etc]) AM_CONDITIONAL(SSHD, test -n "$SSHD") +m4_ifdef([LT_INIT], +[dnl +LT_INIT([win32-dll]) +],[dnl AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL +]) AC_C_BIGENDIAN LT_LANG([Windows Resource]) @@ -89,7 +94,7 @@ m4_set_add([crypto_backends], [wincng]) m4_set_add([crypto_backends], [wolfssl]) AC_ARG_WITH([crypto], - AC_HELP_STRING([--with-crypto=auto|]m4_set_contents([crypto_backends], [|]), + AS_HELP_STRING([--with-crypto=auto|]m4_set_contents([crypto_backends], [|]), [Select crypto backend (default: auto)]), use_crypto=$withval, use_crypto=auto @@ -120,7 +125,7 @@ fi # libz AC_ARG_WITH([libz], - AC_HELP_STRING([--with-libz],[Use libz for compression]), + AS_HELP_STRING([--with-libz],[Use libz for compression]), use_libz=$withval, use_libz=auto) @@ -151,7 +156,7 @@ AC_SUBST(LIBSREQUIRED) # Optional Settings # AC_ARG_ENABLE(clear-memory, - AC_HELP_STRING([--disable-clear-memory],[Disable clearing of memory before being freed]), + AS_HELP_STRING([--disable-clear-memory],[Disable clearing of memory before being freed]), [CLEAR_MEMORY=$enableval]) if test "$CLEAR_MEMORY" = "no"; then AC_DEFINE(LIBSSH2_NO_CLEAR_MEMORY, 1, [Disable clearing of memory before being freed]) @@ -165,8 +170,8 @@ dnl option to switch on compiler debug options dnl AC_MSG_CHECKING([whether to enable pedantic and debug compiler options]) AC_ARG_ENABLE(debug, -AC_HELP_STRING([--enable-debug],[Enable pedantic and debug options]) -AC_HELP_STRING([--disable-debug],[Disable debug options]), +AS_HELP_STRING([--enable-debug],[Enable pedantic and debug options]) +AS_HELP_STRING([--disable-debug],[Disable debug options]), [ case "$enable_debug" in no) AC_MSG_RESULT(no) @@ -194,8 +199,8 @@ dnl on gcc >= 4.0 and SunPro C. dnl AC_MSG_CHECKING([whether to enable hidden symbols in the library]) AC_ARG_ENABLE(hidden-symbols, -AC_HELP_STRING([--enable-hidden-symbols],[Hide internal symbols in library]) -AC_HELP_STRING([--disable-hidden-symbols],[Leave all symbols with default visibility in library]), +AS_HELP_STRING([--enable-hidden-symbols],[Hide internal symbols in library]) +AS_HELP_STRING([--disable-hidden-symbols],[Leave all symbols with default visibility in library]), [ case "$enableval" in no) AC_MSG_RESULT(no) @@ -241,8 +246,8 @@ AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" = xyes]) # Build example applications? AC_MSG_CHECKING([whether to build example applications]) AC_ARG_ENABLE([examples-build], -AC_HELP_STRING([--enable-examples-build], [Build example applications (this is the default)]) -AC_HELP_STRING([--disable-examples-build], [Do not build example applications]), +AS_HELP_STRING([--enable-examples-build], [Build example applications (this is the default)]) +AS_HELP_STRING([--disable-examples-build], [Do not build example applications]), [case "$enableval" in no | false) build_examples='no' @@ -270,7 +275,6 @@ AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"]) # Checks for header files. -# AC_HEADER_STDC AC_CHECK_HEADERS([errno.h fcntl.h stdio.h unistd.h sys/param.h sys/uio.h]) AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) @@ -308,16 +312,16 @@ AC_CHECK_FUNCS(gettimeofday select strtoll explicit_bzero explicit_memset memset dnl Check for select() into ws2_32 for Msys/Mingw if test "$ac_cv_func_select" != "yes"; then AC_MSG_CHECKING([for select in ws2_32]) - AC_TRY_LINK([ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #ifdef HAVE_WINDOWS_H #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include #endif - ],[ + ]], [[ select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL); - ],[ + ]])],[ AC_MSG_RESULT([yes]) HAVE_SELECT="1" AC_DEFINE_UNQUOTED(HAVE_SELECT, 1, diff --git a/m4/lib-link.m4 b/m4/lib-link.m4 index f157d983da..7a41234bf2 100644 --- a/m4/lib-link.m4 +++ b/m4/lib-link.m4 @@ -6,7 +6,7 @@ dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. -AC_PREREQ(2.54) +AC_PREREQ([2.54]) dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and dnl the libraries corresponding to explicit and implicit dependencies. @@ -74,7 +74,7 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ ac_save_LIBS="$LIBS" LIBS="$LIBS $LIB[]NAME" - AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[$3]], [[$4]])],[ac_cv_lib[]Name=yes],[ac_cv_lib[]Name=no]) LIBS="$ac_save_LIBS" ]) if test "$ac_cv_lib[]Name" = yes; then diff --git a/src/Makefile.am b/src/Makefile.am index cb7ecb0460..91222d54c2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign nostdinc -# Get the CSOURCES, HHEADERS and EXTRA_DIST_SOURCES defines +# Get the CSOURCES, HHEADERS and EXTRA_DIST defines include Makefile.inc libssh2_la_SOURCES = $(CSOURCES) $(HHEADERS) @@ -8,8 +8,7 @@ if HAVE_WINDRES libssh2_la_SOURCES += libssh2.rc endif -EXTRA_DIST = $(EXTRA_DIST_SOURCES) \ - libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt +EXTRA_DIST += libssh2_config.h.in libssh2_config_cmake.h.in CMakeLists.txt lib_LTLIBRARIES = libssh2.la diff --git a/src/Makefile.inc b/src/Makefile.inc index 19c07e195c..c0d7e82873 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -45,7 +45,7 @@ HHEADERS = \ userauth_kbd_packet.h \ wincng.h -EXTRA_DIST_SOURCES = \ +EXTRA_DIST = \ blowfish.c \ libgcrypt.c \ mbedtls.c \ From 6972eb158e4229c643d157390730540e8aa4d9b7 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Apr 2023 21:00:34 +0000 Subject: [PATCH 347/424] ci: restrict permissions in GitHub Actions Cherry-picked from #1017 --- .github/workflows/appveyor_docker.yml | 2 ++ .github/workflows/ci.yml | 2 ++ .github/workflows/cifuzz.yml | 3 +++ 3 files changed, 7 insertions(+) diff --git a/.github/workflows/appveyor_docker.yml b/.github/workflows/appveyor_docker.yml index f0fa0eaf9e..ab53e65ad5 100644 --- a/.github/workflows/appveyor_docker.yml +++ b/.github/workflows/appveyor_docker.yml @@ -40,6 +40,8 @@ on: ssh_privkey: required: true +permissions: {} + jobs: daemon: runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e5062be86..1660a07bd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,8 @@ on: pull_request: branches: [master] +permissions: {} + jobs: check_style: name: style-check diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index 500cb63580..4c570270c0 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -1,5 +1,8 @@ name: CIFuzz on: [pull_request] + +permissions: {} + jobs: Fuzzing: runs-on: ubuntu-latest From 7c982347909e2a010e6c8502f155db893ce1141d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Apr 2023 07:53:34 +0000 Subject: [PATCH 348/424] appveyor: wait more for SSH connection from GHA Cherry-picked from #1017 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 898baf75af..a6f7372bad 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -164,7 +164,7 @@ before_test: - appveyor-retry choco install -y --no-progress --limit-output --timeout 180 docker-cli - ps: | Write-Host "Waiting for SSH connection from GitHub Actions" -NoNewline - $endDate = (Get-Date).AddMinutes(2) + $endDate = (Get-Date).AddMinutes(3) while((Get-Process -Name "sshd" -ErrorAction SilentlyContinue).Count -eq 1 -and (Get-Date) -lt $endDate) { Write-Host "." -NoNewline Start-Sleep -Seconds 1 From efdacfc791d087131a91ced20a7aa910cc9a3026 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Apr 2023 12:53:32 +0000 Subject: [PATCH 349/424] tidy-up: add missing newline to error msg, formatting Also: - fix indent - lowercase variables names - fix formatting in `src/global.c` Cherry-picked from #1017 --- src/global.c | 2 +- tests/openssh_fixture.c | 6 +++--- tests/test_agent_forward_ok.c | 18 +++++++++--------- tests/test_read.c | 18 +++++++++--------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/global.c b/src/global.c index 68289845f0..c5894364e2 100644 --- a/src/global.c +++ b/src/global.c @@ -74,5 +74,5 @@ void _libssh2_init_if_needed(void) { if(_libssh2_initialized == 0) - (void)libssh2_init (0); + (void)libssh2_init(0); } diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 5eab34339e..3989db774b 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -177,8 +177,8 @@ static int build_openssh_server_docker_image(void) } buildcmd[sizeof(buildcmd)-1] = 0; snprintf(buildcmd, sizeof(buildcmd)-1, - "docker build --quiet -t libssh2/openssh_server %s", - srcdir_path("openssh_server")); + "docker build --quiet -t libssh2/openssh_server %s", + srcdir_path("openssh_server")); return run_command(NULL, buildcmd); } @@ -455,7 +455,7 @@ void stop_openssh_fixture(void) running_container_id = NULL; } else if(have_docker) { - fprintf(stderr, "Cannot stop container - none started"); + fprintf(stderr, "Cannot stop container - none started\n"); } } diff --git a/tests/test_agent_forward_ok.c b/tests/test_agent_forward_ok.c index 7c9cfe3c5d..664b724ffa 100644 --- a/tests/test_agent_forward_ok.c +++ b/tests/test_agent_forward_ok.c @@ -1,8 +1,8 @@ #include "runner.h" -static const char *USERNAME = "libssh2"; /* set in Dockerfile */ -static const char *KEY_FILE_PRIVATE = "key_rsa"; -static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */ +static const char *username = "libssh2"; /* set in Dockerfile */ +static const char *key_file_private = "key_rsa"; +static const char *key_file_public = "key_rsa.pub"; /* set in Dockerfile */ int test(LIBSSH2_SESSION *session) { @@ -10,8 +10,8 @@ int test(LIBSSH2_SESSION *session) LIBSSH2_CHANNEL *channel; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); + libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -23,10 +23,10 @@ int test(LIBSSH2_SESSION *session) return 1; } - rc = libssh2_userauth_publickey_fromfile_ex(session, USERNAME, - (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), - srcdir_path(KEY_FILE_PRIVATE), + rc = libssh2_userauth_publickey_fromfile_ex(session, username, + (unsigned int)strlen(username), + srcdir_path(key_file_public), + srcdir_path(key_file_private), NULL); if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); diff --git a/tests/test_read.c b/tests/test_read.c index 24160b8547..58fb43acbd 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -5,9 +5,9 @@ #include /* for getenv() */ /* set in Dockerfile */ -static const char *USERNAME = "libssh2"; -static const char *KEY_FILE_PRIVATE = "key_rsa"; -static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; +static const char *username = "libssh2"; +static const char *key_file_private = "key_rsa"; +static const char *key_file_public = "key_rsa.pub"; int test(LIBSSH2_SESSION *session) { @@ -29,8 +29,8 @@ int test(LIBSSH2_SESSION *session) const char *env; const char *userauth_list = - libssh2_userauth_list(session, USERNAME, - (unsigned int)strlen(USERNAME)); + libssh2_userauth_list(session, username, + (unsigned int)strlen(username)); if(!userauth_list) { print_last_session_error("libssh2_userauth_list"); return 1; @@ -42,10 +42,10 @@ int test(LIBSSH2_SESSION *session) return 1; } - rc = libssh2_userauth_publickey_fromfile_ex(session, USERNAME, - (unsigned int)strlen(USERNAME), - srcdir_path(KEY_FILE_PUBLIC), - srcdir_path(KEY_FILE_PRIVATE), + rc = libssh2_userauth_publickey_fromfile_ex(session, username, + (unsigned int)strlen(username), + srcdir_path(key_file_public), + srcdir_path(key_file_private), NULL); if(rc) { print_last_session_error("libssh2_userauth_publickey_fromfile_ex"); From 3f3236eb084feae070ed835aa55e28f3b98ec8a0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 29 Apr 2023 22:40:31 +0000 Subject: [PATCH 350/424] test_ssh2: support `FIXTURE_TRACE_ALL*` envvars Cherry-picked from #1017 --- tests/test_ssh2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_ssh2.c b/tests/test_ssh2.c index 2f918cc749..3ac4d693e0 100644 --- a/tests/test_ssh2.c +++ b/tests/test_ssh2.c @@ -121,6 +121,12 @@ int main(int argc, char *argv[]) goto shutdown; } + if(getenv("FIXTURE_TRACE_ALL_CONNECT") || + getenv("FIXTURE_TRACE_ALL")) { + libssh2_trace(session, ~0); + fprintf(stdout, "Trace all enabled.\n"); + } + libssh2_session_set_blocking(session, 1); rc = libssh2_session_handshake(session, sock); From cda41f7cb87c3af5258ba48ccef19d3efdbd3d3b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Apr 2023 00:03:16 +0000 Subject: [PATCH 351/424] tests: teach to use the `USERNAME` envvar on Windows Necessary to pick the correct local username when run on Windows. Cherry-picked from #1017 --- tests/session_fixture.c | 7 ++++++- tests/test_ssh2.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 922a442b14..f17dbde6c1 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -438,8 +438,13 @@ int test_auth_pubkey(LIBSSH2_SESSION *session, int flags, const char *userauth_list; /* Ignore our hard-wired Dockerfile user when not running under Docker */ - if(!openssh_fixture_have_docker() && strcmp(username, "libssh2") == 0) + if(!openssh_fixture_have_docker() && strcmp(username, "libssh2") == 0) { username = getenv("USER"); +#ifdef WIN32 + if(!username) + username = getenv("USERNAME"); +#endif + } userauth_list = libssh2_userauth_list(session, username, (unsigned int)strlen(username)); diff --git a/tests/test_ssh2.c b/tests/test_ssh2.c index 3ac4d693e0..50ab58513d 100644 --- a/tests/test_ssh2.c +++ b/tests/test_ssh2.c @@ -63,6 +63,10 @@ int main(int argc, char *argv[]) if(getenv("USER")) username = getenv("USER"); +#ifdef WIN32 + else if(getenv("USERNAME")) + username = getenv("USERNAME"); +#endif if(getenv("PRIVKEY")) privkey = getenv("PRIVKEY"); From 081c04571b32ff23a0e55ac488cd2908ea3423d8 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Apr 2023 11:23:34 +0000 Subject: [PATCH 352/424] tidy-up: avoid word 'simply' Cherry-picked from #1017 --- docs/INSTALL_AUTOTOOLS | 2 +- docs/libssh2_sftp_readdir_ex.3 | 2 +- docs/libssh2_sftp_seek.3 | 4 ++-- docs/libssh2_sftp_seek64.3 | 4 ++-- docs/libssh2_sftp_write.3 | 3 +-- src/transport.c | 2 +- src/userauth.c | 5 ++--- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/INSTALL_AUTOTOOLS b/docs/INSTALL_AUTOTOOLS index 607ef079e7..ce1461a4bf 100644 --- a/docs/INSTALL_AUTOTOOLS +++ b/docs/INSTALL_AUTOTOOLS @@ -37,7 +37,7 @@ file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves +and enabled with `--cache-file=config.cache' or shortly `-C') that saves the results of its tests to speed up reconfiguring. (Caching is disabled by default to prevent problems with accidental use of stale cache files.) diff --git a/docs/libssh2_sftp_readdir_ex.3 b/docs/libssh2_sftp_readdir_ex.3 index c655298ef7..7f553f91d6 100644 --- a/docs/libssh2_sftp_readdir_ex.3 +++ b/docs/libssh2_sftp_readdir_ex.3 @@ -30,7 +30,7 @@ truncated to fit. \fIlongentry_maxlen\fP bytes to read data into. The format of the `longname' field is unspecified by SFTP protocol. It MUST be suitable for use in the output of a directory listing command (in fact, the recommended operation for -a directory listing command is to simply display this data). +a directory listing command is to display this data). \fIlongentry_maxlen\fP - is the length of longentry in bytes. If the length of the full directory entry is longer than the space provided by diff --git a/docs/libssh2_sftp_seek.3 b/docs/libssh2_sftp_seek.3 index f5d313bf1e..4a8c373218 100644 --- a/docs/libssh2_sftp_seek.3 +++ b/docs/libssh2_sftp_seek.3 @@ -21,8 +21,8 @@ Deprecated function. Use \fIlibssh2_sftp_seek64(3)\fP instead! Move the file handle's internal pointer to an arbitrary location. Note that libssh2 implements file pointers as a localized concept to make file access appear more POSIX like. No packets are exchanged with the server -during a seek operation. The localized file pointer is simply used as a -convenience offset during read/write operations. +during a seek operation. The localized file pointer is used as a convenience +offset during read/write operations. .SH SEE ALSO .BR libssh2_sftp_open_ex(3), .BR libssh2_sftp_seek64(3) diff --git a/docs/libssh2_sftp_seek64.3 b/docs/libssh2_sftp_seek64.3 index e3f5640707..a9c9a35afc 100644 --- a/docs/libssh2_sftp_seek64.3 +++ b/docs/libssh2_sftp_seek64.3 @@ -19,8 +19,8 @@ libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, Move the file handle's internal pointer to an arbitrary location. libssh2 implements file pointers as a localized concept to make file access appear more POSIX like. No packets are exchanged with the server during a seek -operation. The localized file pointer is simply used as a convenience offset -during read/write operations. +operation. The localized file pointer is used as a convenience offset during +read/write operations. You MUST NOT seek during writing or reading a file with SFTP, as the internals use outstanding packets and changing the "file position" during transit will diff --git a/docs/libssh2_sftp_write.3 b/docs/libssh2_sftp_write.3 index 8b62e941c1..08a497d6a9 100644 --- a/docs/libssh2_sftp_write.3 +++ b/docs/libssh2_sftp_write.3 @@ -56,8 +56,7 @@ otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. If this function returns 0 (zero) it should not be considered an error, but -simply that there was no error but yet no payload data got sent to the other -end. +that there was no error but yet no payload data got sent to the other end. .SH ERRORS \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. diff --git a/src/transport.c b/src/transport.c index 4eeceab354..aefd634762 100644 --- a/src/transport.c +++ b/src/transport.c @@ -696,7 +696,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) numbytes -= numdecrypt; } - /* if there are bytes to copy that aren't decrypted, simply + /* if there are bytes to copy that aren't decrypted, copy them as-is to the target buffer */ if(numbytes > 0) { diff --git a/src/userauth.c b/src/userauth.c index 78b511cc40..a110ddbc3d 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -1475,9 +1475,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, session->userauth_pblc_method_len = _libssh2_ntohu32(pubkeydata); if(session->userauth_pblc_method_len > pubkeydata_len - 4) - /* the method length simply cannot be longer than the entire - passed in data, so we use this to detect crazy input - data */ + /* the method length cannot be longer than the entire passed + in data, so we use this to detect crazy input data */ return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, "Invalid public key"); From 31851511bfaad779e9e3dafc54564fb33c513850 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Apr 2023 11:27:48 +0000 Subject: [PATCH 353/424] tidy-up: avoid word 'just' Cherry-picked from #1017 --- buildconf | 2 +- docs/INSTALL_CMAKE.md | 12 ++++++------ docs/libssh2_channel_set_blocking.3 | 2 +- docs/libssh2_free.3 | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/buildconf b/buildconf index ebdd3972b6..1649f37bd2 100755 --- a/buildconf +++ b/buildconf @@ -1,7 +1,7 @@ #!/bin/sh echo "***" >&2 -echo "*** Do not use buildconf. Instead, just use: autoreconf -fi" >&2 +echo "*** Do not use buildconf. Instead, use: autoreconf -fi" >&2 echo "*** Doing it for you now, but buildconf may disappear in the future." >&2 echo "***" >&2 diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 600edad446..36c9fc099e 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -89,8 +89,8 @@ The previous examples used CMake to start the build using: cmake --build . -Alternatively, once CMake has configured your project, you can just -use your own build tool, e.g GNU make, Visual Studio, etc., from that +Alternatively, once CMake has configured your project, you can use +your own build tool, e.g GNU make, Visual Studio, etc., from that point onwards. Tests @@ -130,16 +130,16 @@ How can I use libssh2 in my project if it also uses CMake? ---------------------------------------------------------- If your own project also uses CMake, you do not need to worry about -setting it up with libssh2's location. Just add just the following -lines and CMake will find libssh2 on your system, set up the necessary -paths and link the library with your binary. +setting it up with libssh2's location. Add the following lines and +CMake will find libssh2 on your system, set up the necessary paths and +link the library with your binary. find_package(Libssh2 REQUIRED CONFIG) target_link_libraries(my_project_target Libssh2::libssh2) Of course, you still have to make libssh2 available on your system first. You can install it in the traditional way shown above, but you -do not have to. Instead you can just build it, which will export its +do not have to. Instead you can build it, which will export its location to the user package registry [3] where `find_package` will find it. diff --git a/docs/libssh2_channel_set_blocking.3 b/docs/libssh2_channel_set_blocking.3 index 18dd6067ad..69b9c6acf3 100644 --- a/docs/libssh2_channel_set_blocking.3 +++ b/docs/libssh2_channel_set_blocking.3 @@ -14,7 +14,7 @@ libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking); \fIblocking\fP - Set to a non-zero value to make the channel block, or zero to make it non-blocking. -Currently this is just a short cut call to +Currently this is a short cut call to .BR libssh2_session_set_blocking(3) and therefore will affect the session and all channels. .SH RETURN VALUE diff --git a/docs/libssh2_free.3 b/docs/libssh2_free.3 index a057f800dc..eef86dd40f 100644 --- a/docs/libssh2_free.3 +++ b/docs/libssh2_free.3 @@ -11,7 +11,7 @@ libssh2_free(LIBSSH2_SESSION *session, void *ptr); .SH DESCRIPTION Deallocate memory allocated by earlier call to libssh2 functions. It uses the memory allocation callbacks provided by the application, if -any. Otherwise, this will just call free(). +any. Otherwise, this will call free(). This function is mostly useful under Windows when libssh2 is linked to one run-time library and the application to another. From 5ee6d0ffbcb915d285ad2a11944ef99ff95885cc Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 30 Apr 2023 11:36:39 +0000 Subject: [PATCH 354/424] tidy-up: avoid expression 'of course' Cherry-picked from #1017 --- docs/INSTALL_CMAKE.md | 13 ++++++------- src/session.h | 7 +++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 36c9fc099e..d1a6cf77a3 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -36,8 +36,8 @@ cryptography library available. The library binary will be put in Customising the build --------------------- -Of course, you might want to customise the build options. You can -pass the options to CMake on the command line: +You might want to customise the build options. You can pass the options +to CMake on the command line: cmake -D