1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-01-27 00:18:12 +03:00
Commit Graph

3010 Commits

Author SHA1 Message Date
Viktor Szakats
c7d4844386 maketgz: add .xz, .bz2, .zip source archive formats (#874)
Copied from curl:
4528690cd5/maketgz (L174-L222)

[ci skip]
2023-03-24 00:34:40 +01:00
Viktor Szakats
dbe5e680b7 dist: delete reference to recently deleted file [ci skip]
Follow-up to b8762c1003
2023-03-23 23:27:29 +00:00
Viktor Szakats
52c8a9ba04 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.
2023-03-23 19:43:32 +01:00
Viktor Szakats
0834b9bcc8 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.
2023-03-22 23:09:53 +01:00
Viktor Szakats
1d32ad1ced 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).
2023-03-22 19:43:26 +01:00
Viktor Szakats
9cc2e5945f cmake: fix error with static lib off and example/tests on (#869)
Regression from 4e2580628d
2023-03-22 16:55:32 +01:00
Viktor Szakats
7a039d9a7a ci: parallelize more (#867) 2023-03-22 13:52:52 +01:00
Viktor Szakats
3b547417ef cmake/src: move build options before target definitions (#864)
To allow more flexibility when defining targets.
2023-03-22 11:25:03 +01:00
Viktor Szakats
61a7d45d24 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
2023-03-22 11:23:57 +01:00
Viktor Szakats
4e2580628d 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: b60dca8b64 #547 by berney on github
Fixes: #547
Fixes: #675
Closes: #863
2023-03-22 02:47:58 +00:00
Viktor Szakats
b0cb0b1965 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
2023-03-20 20:51:59 +00:00
Viktor Szakats
b13936bd6a 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
2023-03-20 15:49:37 +00:00
Viktor Szakats
ec0a51db1f 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
2023-03-20 09:30:40 +00:00
Viktor Szakats
5a9944e754 wincng: fix memory leak in _libssh2_dh_secret()
Patch-by: iruis on github
Assisted-by: Marc Hörsken
Bug #846, commit e3487092ef9553af67633c6747cb9ab2f86465e0.
Fixes #856
Closes #858
2023-03-20 00:35:15 +00:00
Viktor Szakats
244a1ae856 nw, os400, watcom: stop setting unused macros [ci skip] (#859) 2023-03-19 20:01:48 +01:00
Viktor Szakats
4997f921ee 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
2023-03-19 17:42:12 +00:00
Viktor Szakats
de91e22081 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
2023-03-19 15:51:52 +00:00
Viktor Szakats
2ac44a19aa 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.
2023-03-17 16:55:48 +01:00
Viktor Szakats
c5f2efdf9d 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
2023-03-17 09:42:10 +00:00
Viktor Szakats
ca2e8d5b5e 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
2023-03-17 00:24:35 +01:00
Viktor Szakats
d0714c321a 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
2023-03-16 12:43:38 +01:00
Dan Fandrich
289b4a1c0c 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
2023-03-14 15:18:49 -07:00
Viktor Szakats
f928da9f95 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
2023-03-14 20:42:53 +00:00
Jakob Egger
e96e96628b build: update instructions for autoreconf (#847)
The "convenience script" talks about the "buildconf" file,
which is no longer recommended.
2023-03-14 13:38:28 +01:00
Viktor Szakats
664239faa1 win32: set HAVE_STRTOLL with MSVS 2013 and newer (#845)
As in curl:
7fa6e36583/lib/config-win32.h (L221)
2023-03-13 20:07:25 +01:00
Viktor Szakats
2215ee37e9 GNUmakefile: move HAVE_STRTOLL to libssh2_config.h [ci skip] (#844) 2023-03-13 15:27:10 +01:00
Viktor Szakats
0c00d3b955 src: silence unused variable warnings (#843) 2023-03-13 12:09:46 +01:00
Viktor Szakats
b8762c1003 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:
  a8861b6ccd

Closes #842
2023-03-13 11:08:19 +00:00
Viktor Szakats
3ac32253f9 wincng: fix memory leak in libssh2_dh_key_pair() (#829)
Fixes #722
2023-03-13 12:04:29 +01:00
Viktor Szakats
c45ba4d624 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.
2023-03-11 16:43:13 +01:00
Viktor Szakats
509c84e3c5 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 2e2812dde8
2023-03-11 11:08:42 +01:00
Viktor Szakats
0621f97c7b 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)
2023-03-11 11:06:42 +01:00
Viktor Szakats
a273816521 win32: convert tabs to spaces [ci skip] (#838)
Also strip stray newlines from `win32/rules.mk`.
2023-03-10 18:53:38 +01:00
Viktor Szakats
0e8971f443 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
2023-03-10 14:06:17 +01:00
Viktor Szakats
f0b729f791 cmake: drop unnecessary exception for warmup build (#835) 2023-03-10 11:08:57 +01:00
Viktor Szakats
0c04f44fb9 cmake: reflect minimum version in docs (#834)
Follow-up to 505ea626b6
2023-03-10 00:56:35 +01:00
Viktor Szakats
adac94af31 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 9f217a17f6

Ref: #817
2023-03-10 00:55:37 +01:00
Viktor Szakats
40ac6b230a 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
2023-03-10 00:53:55 +01:00
Viktor Szakats
ae90a35d15 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 4cdf785cd3.
2023-03-09 19:49:20 +01:00
Viktor Szakats
8795d9c817 cmake: unset forced CMAKE_C_STANDARD 90 (#822)
Added in cf80f2f4b5 (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?
2023-03-09 11:48:21 +01:00
Viktor Szakats
99c1333ba7 example: silence MSVS 2013 C4127 warnings (#828) 2023-03-09 10:46:40 +01:00
Viktor Szakats
33b6d5f89d 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 31fb8860db
2023-03-09 00:41:48 +01:00
Viktor Szakats
27318779a3 fix compiling with LIBSSH2_NO_CLEAR_MEMORY and OpenSSL (#825)
Regression from a0e424a51c

Fixes #824
2023-03-08 22:13:09 +01:00
Viktor Szakats
57f1d38140 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 4cdf785cd3.
2023-03-08 16:19:22 +01:00
Viktor Szakats
7cce783081 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`.
2023-03-08 16:18:44 +01:00
Viktor Szakats
07a8b8e033 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 16619a8edd.
2023-03-08 16:12:51 +01:00
Viktor Szakats
10c8beab1f 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
2023-03-08 13:59:59 +01:00
Viktor Szakats
9ad1258f1f cmake: use only needed socket libs when checking non-blocking sockets (#816)
Based on patch by Christian Beier.

Fixes #694
Closes #712
2023-03-08 13:56:01 +01:00
Viktor Szakats
19884e5055 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.
2023-03-08 09:36:11 +01:00
Viktor Szakats
9f217a17f6 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:
  e4d920c4b7/cmake/Findwolfssl.cmake
via commit:
  296396d373
by Stefan Eissing
2023-03-08 09:34:37 +01:00