1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-07 08:02:56 +03:00
Commit Graph

2997 Commits

Author SHA1 Message Date
Viktor Szakats
f12e25af30 cmake: prefill for faster config phase on Windows
Prefill known detection results on Windows with MinGW and MSVC, to
avoid spending time on detecting these on every cmake configuration
run.

With MinGW + clang and MSVC, this elminates all detections.
With MinGW + gcc, it reduces them to 3.

Cherry-picked from #1031
2023-05-05 01:20:42 +00:00
Viktor Szakats
62acef1c44 libssh2_setup.h: set HAVE_INTTYPES_H for MSVC
To sync up the hand-crafted config with actual detection results
by CMake and autotools. Sources compiled fine without it anyway.

Cherry-picked from #1031
2023-05-05 01:20:26 +00:00
Viktor Szakats
a190503e8e cmake: re-add select() detection (regression)
`select()` detection suffered two regressions: First I accidentally
deleted it for non-Windows [1]. Then the Windows-specific setting got
missed from the generated `libssh2_config.h` after a rearrangement in
`CMakeLists.txt` files.

[1] 31fb8860db (2023-03-07)
[2] 803f19f004 (2023-04-18)

This patch restores detection. For Windows, enable it unconditionally,
not only for speed reasons, but because detection needs `ws2_32`, and
even that is broken on the x86 platform. According to the original
`cmake/SocketLibraries.cmake`, caused by a calling convention mismatch.
FWIW autotools detects it correctly.

Cherry-picked from #1031
2023-05-05 01:19:31 +00:00
Viktor Szakats
b9eafb9625 ci: merge make job into msys2 section, enable zlib + openssl
Follow up to dd62576627

Cherry-picked from #1030
2023-05-04 20:20:42 +00:00
Viktor Szakats
fd97eccecc ci: add missing timeouts for autotools tests
Cherry-picked from #1030
2023-05-04 20:18:39 +00:00
Viktor Szakats
3d64a3f510 ci: add mingw-w64 clang and gcc CMake jobs
Cherry-picked from #1030
2023-05-04 20:17:32 +00:00
Viktor Szakats
1289033598 cmake: assume bcrypt.h with WinCNG
autotools already didn't check for `bcrypt.h`, and such check is only
required for old/legacy mingw without obsolete/incomplete Windows
headers.

curl deprecated old-mingw support just recently and will delete support
in September 2023.

This patch saves some complexity and detection time by dropping this
check for CMake. Meaning that mingw-w64 is now required to compile
libssh2 when using the WinCNG backend for 32-bit builds. Other backends
and CPU platforms are not affected.

Ref: e4d5685cb5

Closes #1026
2023-05-04 20:17:01 +00:00
Viktor Szakats
a9f1acabe3 cmake: do not check for poll() on Windows
While it seems to exist on mingw in theory, it's not detected as of this
writing. It also has issues, and not ready for production use:
https://stackoverflow.com/questions/1671827/poll-c-function-on-windows

On MSVC it's even less supported.

Skip checking this to save CMake detection time.

Closes #1027
2023-05-04 20:16:55 +00:00
Viktor Szakats
0287961682 agent_win: make a struct static and other build improvements
Also:
- merge back `agent.h` into `agent.c` where it was earlier.
  Ref: c998f79384
- introduce `HAVE_WIN32_AGENT` internal macro.
- fix two guards to exclude more code unused in UWP builds.

Follow-up to 1c1317cb76

Closes #1028
2023-05-04 20:16:46 +00:00
Viktor Szakats
fc003d4dc3 tidy-up: formatting nits
Whitespace and redundant parenthesis in `return`s.

Closes #1029
2023-05-04 20:16:28 +00:00
Nick Woodruff
272a17ce26 sftp: parse attribute extensions, if present, to avoid stream parsing errors (#1019)
Prevents directory listing errors when attribute extensions are present
by advancing stream parsing past extensions.
2023-05-03 22:39:25 +02:00
Viktor Szakats
d4690e9509 tests: merge sshd_fixture.sh into test_sshd.test
Merge the loop executing multiple tests and the script that actually
launches the tests into a single script. This same script is now called
from both autotools and CMake. autotools loads the list of tests from
`Makefile.inc`, CMake passes it via the command-line. It's also possible
to call the script manually with a custom list of tests or individual
ones.

With this setup we're now launching a single sshd session for all tests,
instead of launching and killing it for each test. This did not improve
reliability of these test on CI machines, and it's easy to go back to
the previous behaviour if necessary.

Also:

- allow passing custom sshd options via `SSHD_FLAGS`.

- add `SSHD_TESTS_LIMIT_TO` to limit the number of tests to its value.
  E.g. `SSHD_TESTS_LIMIT_TO=1` executes the first test only. Meant for
  debugging.

- use `ssh` to test the connection (if available) instead of fixed
  amount of wait. Made to also work on Windows.

- set `PermitRootLogin yes` in `sshd`, to allow running tests as root.

- show `sshd` path and version.

Cherry-picked from #1017 (the last one)
Closes #1024
2023-05-03 19:15:16 +00:00
Viktor Szakats
8aa1ca859f ci: make sure to run tests after all builds in GHA
Whenever possible. Due to flakiness/hangs/timeouts, keep sshd
tests disabled on Windows and macOS.

Also keep Docker tests disabled on these platforms, they do not work:

GHA Windows:
```
no matching manifest for windows/amd64 in the manifest list entries
```

GHA macOS:
```
sh: docker: command not found
```

It's not possible to run UWP and ARM64 binaries:
UWP:
```
Test #2: test_simple ......................Exit code 0xc0000135
```
Needs but doesn't find: `VCRUNTIME140_APP.dll`.

ARM64
```
D:/a/libssh2/libssh2/bld/tests/Release/test_ssh2.exe: cannot execute binary file: Exec format error
```

Cherry-picked from #1017
2023-05-03 15:01:53 +00:00
Viktor Szakats
8d076c0f0c tests: disable sshd tests on Windows via new options
Instead of using hacks inside the build systems.

`SSHD` variable added to GitHub Actions is not currently used.
Added there to make it easy to experiment with these tests and
the path is non-trivial to discover. Using the Windows built-in
sshd server is another option (haven't discovered its path yet).

Cherry-picked from #1017
2023-05-03 15:01:53 +00:00
Viktor Szakats
62178a367a tests: add cmake/autotools options to disable running tests
autotools:
- `--disable-docker-tests`
- `--disable-sshd-tests`

cmake:
- `RUN_DOCKER_TESTS`
- `RUN_SSHD_TESTS`

Update automake and ci to use this new flag and delete former logic
of relying on Windows detection and `HOST_WINDOWS`. Also fix honoring
this when running `test_read_algos.test`.

This allows to disable these individually and on per-CI/local-job basis.
To run as much tests as the env allows.

Cherry-picked from #1017
2023-05-03 15:01:53 +00:00
Viktor Szakats
54e8d02169 ci: add make distcheck job
Cherry-picked from #1017
2023-05-03 14:13:24 +00:00
Viktor Szakats
0c57c56fce ci: switch to out-of-tree autotools builds
Cherry-picked from #1017
2023-05-03 14:12:16 +00:00
Viktor Szakats
03ee8d3cc4 ci: restore parallel builds with cmake
Also add missing -j3 for macOS builds.

Partial revert of 0d08974633

Cherry-picked from #1017
2023-05-03 14:06:50 +00:00
Viktor Szakats
c01ccf898b ci: sync names, steps, syntax, build dirname between jobs
Also:

- delete an unused 64-bit option for Linux (all jobs are 64-bit).

- fix to not install libgcrypt and openssl when doing mbedTLS builds.

[ Empty lines after multiline run commands are solely to unbreak
my editor's syntax highlighting. They can be deleted in the future ]

Cherry-picked from #1017
2023-05-03 14:03:24 +00:00
Viktor Szakats
dd62576627 ci: add Makefile.mk test, with LIBSSH2_NO_* options
Cherry-picked from #1017
2023-05-03 13:07:15 +00:00
Viktor Szakats
875bc599e5 Makefile.mk: use Makefile.inc from example and tests
Instead of assembling the list using `$(wildcard ...)`.

Also split off a `tests/Makefile.inc` from `tests/Makefile.am`. With its
simpler syntax, this also allows to delete some complexity from the
CMake loader.

Cherry-picked from #1017
2023-05-03 13:07:15 +00:00
Viktor Szakats
8270633eeb example, tests: fix ssh2 to correctly return failure
Before this patch ssh2 and test_ssh2 returned success even if the session
failed at `libssh2_session_handshake()` or after.

This patch depends on cda41f7cb8, that fixed
running test_ssh2 on Windows via sshd_fixture.

Cherry-picked from #1017
2023-05-03 13:07:13 +00:00
Viktor Szakats
0a29a63ca6 tests: set -e -u in shell scripts
Cherry-picked from #1017
2023-05-03 12:56:36 +00:00
Viktor Szakats
612ca85aaa cmake: use shared libs again in example and tests
Re-sync with autotools and v1.10.0 behavior.

This improves build times. It also allows to stop building our special
shared test target to test shared builds.

Follow-up to 4e2580628d

Cherry-picked from #1017
Closes #1022
2023-05-03 12:30:43 +00:00
Viktor Szakats
bc120a343b tests: retry KEX failures when using the WinCNG backend
Twice. This tests are flaky and we haven't figured out why. In the
meantime use this workaround to test and log these issues, but also
ensure that CI run aren't flagged red because of it.

Also:
- kex: add debug message when hostkey `sig_verify` fails,
  to help tracking WinCNG KEX failures.
- test_ssh2: also add retry logic.
  I'm not quite sure this is correct. Please let me know.
- session_fixture: bump up `src_path` slots to fit retries and show
  message when hitting the limit.
- session_fixture: clear `kbd_password` static variable after use.
- session_fixture: close and deinit socket after use.
- session_fixture: deinit libssh2 after use.

Ref: #804 #846 #979 #1012 #1015

Cherry-picked from #1017
Closes #1023
2023-05-03 12:30:38 +00:00
Viktor Szakats
d70919fb00 example, test_ssh2: shutdown socket before close
Syncing them with `tests/session_fixture.c`.

Cherry-picked from #1017
2023-05-03 12:26:28 +00:00
Viktor Szakats
e99c84f682 ci.yml: fix indentation [ci skip]
Cherry-picked from #1017
2023-05-03 09:13:26 +00:00
Viktor Szakats
baecb5eb68 Makefile.mk: make tests depend on runner lib
Cherry-picked from #1017
2023-05-03 01:58:41 +00:00
Viktor Szakats
1c1317cb76 build: compile agent_win.c via agent.c
Silences these warnings on non-Windows:
```
ranlib: file: libssh2.a(agent_win.c.o) has no symbols
```

Cherry-picked from #1017
2023-05-03 01:54:22 +00:00
Viktor Szakats
74ffa1e01d cmake: delete obsolete comment
Follow-up to 8017592163

Cherry-picked from #1017
2023-05-03 01:51:10 +00:00
Viktor Szakats
b87fbc91cb checksrc.sh: fix it to run from any current directory
Also silence a shellcheck warning.

Cherry-picked from #1017
2023-05-03 01:49:46 +00:00
Viktor Szakats
ce9d789689 ISSUE_TEMPLATE: ask for crypto backend version
Also fix casing in backend names.

Cherry-picked from #1017
2023-05-03 01:48:54 +00:00
Viktor Szakats
33f3260a4a tests: fix newlines in test keys for sshd on Windows
Make sure these files get LF newlines on checkout. Before this patch
a checked out libssh2 Git repository may have used CRLF newlines in text
files, include test keys. Private keys with CRLF newlines could confuse
sshd on Windows:

```
# sshd version: 'OpenSSH_9.2, OpenSSL 1.1.1t  7 Feb 2023'
Unable to load host key "/d/a/libssh2/libssh2/tests/openssh_server/ssh_host_ed25519_key": invalid format
Unable to load host key: /d/a/libssh2/libssh2/tests/openssh_server/ssh_host_ed25519_key
```
Ref: https://github.com/libssh2/libssh2/actions/runs/4846188677/jobs/8635575847#step:6:39

Cherry-picked from #1017
2023-05-03 01:45:59 +00:00
Viktor Szakats
ec8689b264 cmake: move option descriptions next to definition
Cherry-picked from #1017
2023-05-03 01:37:49 +00:00
Viktor Szakats
d964289e54 checksrc: sync with curl
There were no new issues detected.

Cherry-picked from #1017
2023-05-03 01:35:16 +00:00
Viktor Szakats
df513c0128 openssl: enable AES-GCM with wolfSSL
Follow-up to 3c953c05d6 #797

There is pending issue with wolfSSL, where encryption/decryption is not
working (both with and without this patch). Ref: #1020

Cherry-picked from #1017
2023-05-03 01:35:16 +00:00
Viktor Szakats
82ef89611a appveyor: add a UWP OpenSSL 3 build
Cherry-picked from #1017
2023-05-03 01:35:16 +00:00
Viktor Szakats
5ca2d638e8 appveyor: skip before_test when not doing tests
Also merge `before_test` section into `test_script`.

Cherry-picked from #1017
2023-05-03 01:35:16 +00:00
Viktor Szakats
dee8ec9270 docs: delete two stray characters
Cherry-picked from #1017
2023-05-03 01:35:16 +00:00
Viktor Szakats
5ee6d0ffbc tidy-up: avoid expression 'of course'
Cherry-picked from #1017
2023-05-03 01:35:10 +00:00
Viktor Szakats
31851511bf tidy-up: avoid word 'just'
Cherry-picked from #1017
2023-05-03 01:35:05 +00:00
Viktor Szakats
081c04571b tidy-up: avoid word 'simply'
Cherry-picked from #1017
2023-05-03 01:34:58 +00:00
Viktor Szakats
cda41f7cb8 tests: teach to use the USERNAME envvar on Windows
Necessary to pick the correct local username when run on Windows.

Cherry-picked from #1017
2023-05-03 01:19:33 +00:00
Viktor Szakats
3f3236eb08 test_ssh2: support FIXTURE_TRACE_ALL* envvars
Cherry-picked from #1017
2023-05-03 01:17:26 +00:00
Viktor Szakats
efdacfc791 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
2023-05-03 01:13:07 +00:00
Viktor Szakats
7c98234790 appveyor: wait more for SSH connection from GHA
Cherry-picked from #1017
2023-05-03 01:11:30 +00:00
Viktor Szakats
6972eb158e ci: restrict permissions in GitHub Actions
Cherry-picked from #1017
2023-05-03 01:09:59 +00:00
Viktor Szakats
7aab5bd6f9 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: a59f046116

- 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 2c18b6fc8d

- `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:
  9ce7eee070/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
2023-05-03 01:09:15 +00:00
Viktor Szakats
738cbf5503 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
2023-05-03 01:08:33 +00:00
Zenju
fc7e79e442 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
2023-05-01 22:17:18 +02:00