1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-04-19 02:24:04 +03:00

279 Commits

Author SHA1 Message Date
Viktor Szakats
a1a28ac943
clang-tidy: fix and/or silence issues found, and more
- kex: drop unused assigment.
- knownhost: error when salt is NULL.
- mbedtls: avoid unnecessary inline assigments, that were ignored for
  the second block and replaceable with a `ret = 0` initialization for
  the first one.
- mbedtls: fix ignoring an API failure and ending up calling
  `mbedtls_rsa_check_privkey()` unconditionally.
- misc: initialize datalen on error in `_libssh2_base64_decode()`.
- openssl: drop unused assigments.
- openssl: fix unused static function.
- packet: avoid NULL deref.
- packet: avoid NULL in `memcpy` src.
- publickey: optimize struct layout to avoid padding.
- sftp: replace ignored `rc` error assigment with `_libssh2_error()` call.
- transport: fix potential NULL ptr dereferences.
- transport: silence uninitialized value warnings.
- userauth: drop unused assigment.
- userauth: possible use of unitialized pointer.
- userauth: replace `rewind()` with `fseek()`.
  `rewind()` returns an error condition in `errno`. `errno` is
  problematic and reduces portability. Use `fseek()` to avoid it.
- userauth: replace potential NULL deref by returning error from
  `sign_frommemory()`. Possible false positive. `rc` should be set
  upstream if the callback is NULL.
- userauth: replace potential NULL deref by returning error from
  `sign_fromfile()`. clang-tidy did not warn about this one, but
  let's match `sign_frommemory()` anyway.
- wincng: fix potentially unused macros.
- wincng: make sure bignum is not NULL before use.

tests:
- openssh_fixture: drop unused assignment.
- session_fixture: exit if `username` not set, to avoid `strlen(NULL)`.
- session_fixture: replace `rewind()` with `fseek()`.
  `rewind()` returns an error condition in `errno`. `errno` is
  problematic and reduces portability. Use `fseek()` to avoid it.
- test_read: exit if `username` not set, to avoid `strlen(NULL)`.

examples:
- scp_write_nonblock: fix file handle leak.
- sftp_write_nonblock: file handle leak on error.
- sftp_write_sliding: file handle leak on error.
- ssh2_agent_forwarding: fix unused error codes.

Details in the subcommits under the PR.

Thanks-to: Michael Buckley
Thanks-to: Will Cosgrove

Closes #1561
2025-03-24 14:37:08 +01:00
Viktor Szakats
a751d578be
tidy-up: replace exit() with return
In examples and the manual page for `libssh2_version()`.

Closes #1541
2025-02-13 13:51:49 +01:00
Viktor Szakats
5cca650b1d
tidy-up: prefer #ifdef / #ifndef (formatting)
Closes #1532
2025-01-31 13:04:32 +01:00
Viktor Szakats
784446b6c5
build: add support for clang-cl, add CI job
- ci/appveyor: add clang-cl job.
- ci/appvayor: optimize setting an env.
- build: fix clang-cl builds.
- build: fix `-Wcast-function-type` compiler warnings for OpenSSL 3.
- build: use `stdint.h` with MSVC when supported.
- src: use `PRId64` for MSVC where supported.
- src: avoid recursive macro definition for `recv()` and `send()`.
- session: silence `-Wcast-function-type` for `libssh2_session_callback_set2()`.
  Sadly this function is still not fully warning-clean, and it
  seems we'd need separate setter-getters for each callback
  to avoid all warnings.

Closes #1484
2025-01-31 05:13:18 +01:00
Viktor Szakats
7027604505
libssh2_scp_send, libssh2_scp_send_ex: add deprecation warning
Also:
- switch to non-deprecated alternative in examples.
- add pointers and deprecation warning to libssh2_scp_send man page.

Cherry-picked from #1484
2025-01-31 02:04:59 +01:00
Viktor Szakats
90a686ef3a
gitignore: compress rules
Cherry-picked from #1484
2025-01-31 02:00:28 +01:00
Viktor Szakats
606c102e52
build: enable -Wcast-qual, fix fallouts
- enable compiler warning `-Wcast-qual`.
- add `LIBSSH2_UNCONST()` macro to strip const where absolutely
  necessary to avoid compiler warnings.
- fix const stripping by constifying where necessary.
- fix const stripping by using `LIBSSH2_UNCONST()`.
- libgcrypt.h: drop unnecessary casts.
- openssl: fix to use new `BIO_new_mem_buf()` parameter types
  with wolfSSL.

Cherry-picked from #1484
Closes #1527
2025-01-31 00:57:26 +01:00
Viktor Szakats
a3aa6b4ca8
cmake: misc improvements, add LIBSSH2_USE_PKGCONFIG option
- show platform flags (via curl).
- add `LIBSSH2_USE_PKGCONFIG` option to control whether to use
  `pkg-config` to find dependencies.
- set `.pc` names withing the Find modules.
- add `mbedcrypto` to `libssh2.pc` only when detected via `pkg-config`.
  Workaround for older mbedtls versions and non-CMake mbedTLS builds
  (as of mbedTLS 3.6.2) that don't emit an `mbedcrypto.pc` file.
- set header paths relative to the project root (tidy-up).
- use `-isystem` for crypto backend and zlib header paths.
  To match autotools.
- sync header path order with autotools.
- rename local variables to underscore-lowercase.
- minor tidy-ups.

Cherry-picked from #1484
Closes #1525
2025-01-30 23:36:39 +01:00
Viktor Szakats
854cfa8292
build: prepare builds for clang-cl, add cmake ossfuzz support
- cmake: add support to build ossfuzz.
  Enable with `-DBUILD_OSSFUZZ=ON`.
  Also supports `-DLIB_FUZZING_ENGINE=` like autotools does.
- check for `__clang__` when suppressing warnings in source. Necessary
  for clang-cl, which set `__clang__`, but doesn't set `__GNU__`.
- cmake: optimize out 4 picky warning option detections with gcc.
- cmake: bring `-pedantic-error`, `-Wall` use closer to curl's.
- cmake: set `-Wno-language-extension-token` for clang-cl.
- cmake: escape only the necessary `-W` options for clang-cl.
- cmake: apply picky warnings to C++.
- cmake: replace `unset(VAR)` with `set(VAR "")` for init.
- cmake: prefer dash-style MSVC options.
- cmake: simplify `MATCHES` expression.
- cmake: formatting/whitespace.
- ci/GHA: bump `actions/upload-artifact` to v4

Closes #1524
2025-01-30 22:01:49 +01:00
Viktor Szakats
0fce9dcc29
cmake: rename two variables and initialize them
- `LIBRARIES` -> `LIBSSH2_LIBS`
- `SOCKET_LIBRARIES` -> `LIBSSH2_LIBS_SOCKET`

Also initialize them before use.

Cherry-picked from #1445
Closes #1464
2024-10-03 21:57:48 +02:00
Viktor Szakats
9d9ee7807d
cmake: tidy up syntax, minor improvements
- make internal variables underscore-lowercase.
- unfold lines.
- fold lines setting header directories.
- fix indent.
- drop interim variable `EXAMPLES`.
- initialize some variables before populating them.
- clear a variable after use.
- add `libssh2_dumpvars()` function for debugging.
- allow to override default `CMAKE_UNITY_BUILD_BATCH_SIZE`.
- bump up default `CMAKE_UNITY_BUILD_BATCH_SIZE` to 0 (was 32).
- tidy up option descriptions.

Closes #1446
2024-09-07 21:27:55 +02:00
Viktor Szakats
29a4b607d8
tidy-up: do/while formatting
Also fix an indentation and delete empty lines.

Closes #1440
2024-08-06 10:56:22 +02:00
Viktor Szakats
323a14b2ca
build: silence warnings inside FD_SET()/FD_ISSET() macros
Use an ugly workaround to silence `-Wsign-conversion` warnings triggered
by the internals of `FD_SET()`/`FD_ISSET()` macros. They've been showing
up in OmniOS CI builds when compiling `example` programs. They also have
been seen with older Cygwin and other envs and configurations.

Also scope two related variables in examples.

E.g.:
```
../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
  251 |         FD_SET(forwardsock, &fds);
      |         ^~~~~~
../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:251:9: warning: conversion to 'long int' from 'long unsigned int' may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
  259 |         if(rc && FD_ISSET(forwardsock, &fds)) {
      |                  ^~~~~~~~
../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
```
Ref: https://github.com/libssh2/libssh2/actions/runs/8854199687/job/24316762831#step:3:2020

Closes #1379
2024-04-29 01:16:21 +02:00
Viktor Szakats
6556bfbd43
autotools: use AM_CFLAGS
Use `AM_CFLAGS` to pass custom, per-target C flags. This replaces using
`CFLAGS` which triggered this warning when running `autoreconf -fi`:
```
tests/Makefile.am:8: warning: 'CFLAGS' is a user variable, you should not override it;
tests/Makefile.am:8: use 'AM_CFLAGS' instead
```
(Only for `tests`, even though `example` and `src` also used this
method. The warning is also missing from curl, that also uses
`CFLAGS`.)

Follow-up to 3ec53f3ea26f61cbf2e0fbbeccb852fca7f9b156 #1286
Closes #1378
2024-04-26 22:58:55 +02:00
Viktor Szakats
24503cb9e1
example: restore sys/time.h for AIX
In AIX, `time.h` header file doesn't have definitions like
`fd_set`, `struct timeval`, which are found in `sys/time.h`.

Add `sys/time.h` to files affected when available.

Regression from e53aae0e16dbf53ddd1a4fcfc50e365a15fcb8b9 #1001.

Reported-by: shubhamhii on GitHub
Assisted-by: shubhamhii on GitHub
Fixes #1334
Fixes #1335
Closes #1340
2024-03-29 09:12:10 +00:00
Viktor Szakats
c0f69548be
session: add libssh2_session_callback_set2()
Add new `libssh2_session_callback_set2()` API that deprecates
`libssh2_session_callback_set()`.

The new implementation offers the same functionality, but accepts and
returns a generic function pointer (of type `libssh2_cb_generic *`), as
opposed to the old function that used data pointers (`void *`). The new
solution thus avoids data to function (and vice versa) pointer
conversions, which has undefined behaviour in standard C.

About the name: It seems the `*2` suffix was used in the past for
replacement functions for deprecated ones. Let's stick with that.
`*_ex` was preferred for new functions that extend existing ones with
new features.

Closes #1285
2023-12-18 15:02:17 +00:00
Viktor Szakats
3ec53f3ea2
build: enable -pedantic-errors
According to the manual, this isn't the same as `-Werror -pedantic`.
Enable it together with `-Werror`.

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-pedantic-errors-1

This option results in autotools feature detection going into crazies.
To avoid this, we add it to `CFLAGS` late. Idea copied from curl.

This option has an effect only with gcc 5.0 and newer as of this commit.
Let's enable it for clang and older versions too for simplicity. Ref:
d5c0351055
https://github.com/curl/curl/pull/2747

Closes #1286
2023-12-17 15:15:34 +00:00
Viktor Szakats
94b6bad3c8
example, tests: call WSACleanup() for each WSAStartup()
On Windows.

Closes #1283
2023-12-13 01:28:14 +00:00
Viktor Szakats
28dbf01667
add portable LIBSSH2_SOCKET_CLOSE() macro
Add `LIBSSH2_SOCKET_CLOSE()` to the public `libssh2.h` header, for user
code. It translates to `closesocket()` on Windows and `close()` on other
platforms.

Use it in example code.

It makes them more readable by reducing the number of `_WIN32` guards.

Closes #1278
2023-12-08 11:19:04 +00:00
Viktor Szakats
3f60ccb76b
example: use libssh2_socket_t in X11 example
Cherry-picked from #1277
2023-12-08 02:01:18 +00:00
Viktor Szakats
2e5a8719d7
tidy-up: bump casts from int to long for large C99 types in printfs
Cast large integer types to avoid dealing with printf masks for
`size_t` and other C99 types. Some of existing code used `int`
for this, bump them to `long`.

Ref: afa6b865604019ab27ec033294edfe3ded9ae0c0 #1257

Closes #1264
2023-12-04 13:11:28 +00:00
Viktor Szakats
afa6b86560
build: enable missing OpenSSF-recommended warnings, with fixes
Ref:
https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
(2023-11-29)

Enable new warnings:

- replace `-Wno-sign-conversion` with `-Wsign-conversion`.

  Fix them in example, tests and wincng. There remain about 360 of these
  warnings in `src`. Add a TODO item for those and disable `-Werror` for
  this particular warning.

- enable `-Wformat=2` for clang (in both cmake and autotools).

- enable `__attribute__((format))` for `_libssh2_debug()`,
  `_libssh2_snprintf()` and in tests for `run_command()`.

  `LIBSSH2_PRINTF()` copied from `CURL_TEMP_PRINTF()` in curl.

- enable `-Wimplicit-fallthrough`.

- enable `-Wtrampolines`.

Fix them:

- src: replace obsolete fall-through-comments with
  `__attribute__((fallthrough))`.

- wincng: fix `-Wsign-conversion` warnings.

- tests: fix `-Wsign-conversion` warnings.

- example: fix `-Wsign-conversion` warnings.

- src: fix `-Wformat` issues in trace calls.

  Also, where necessary fix `int` and `unsigned char` casts to
  `unsigned int` and adjust printf format strings. These were not
  causing compiler warnings.

  Cast large types to `long` to avoid dealing with printf masks for
  `size_t` and other C99 types. Existing code often used `int` for this.
  I'll update them to `long` in an upcoming commit.

- tests: fix `-Wformat` warning.

- silence `-Wformat-nonliteral` warnings.

- mbedtls: silence `-Wsign-conversion`/`-Warith-conversion`
  in external header.

Closes #1257
2023-12-03 01:32:20 +00:00
Viktor Szakats
744e059f31
example, tests: fix/silence -Wformat-truncation=2 gcc warnings
Then sync this warning option with curl.

Seems like a false positive and/or couldn't figure how to fix it, so silence:
```
example/ssh2.c:227:38: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size 0 [-Werror=format-truncation=]
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                      ^~
example/ssh2.c:227:34: note: assuming directive output of 1 byte
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                  ^~~~~~~
example/ssh2.c:227:13: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 2
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example/ssh2.c:228:38: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size 0 [-Werror=format-truncation=]
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                      ^~
example/ssh2.c:228:34: note: assuming directive output of 1 byte
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                  ^~~~~~~
example/ssh2.c:228:13: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 2
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/7055480458/job/19205970397#step:10:98

Fix:
```
tests/openssh_fixture.c:116:38: error: ' 2>&1' directive output may be truncated writing 5 bytes into a region of size between 1 and 1024 [-Werror=format-truncation=]
tests/openssh_fixture.c:116:11: note: 'snprintf' output between 6 and 1029 bytes into a destination of size 1024
```
Ref: https://github.com/libssh2/libssh2/actions/runs/7055480458/job/19205969221#step:10:51

Tested via #1257
2023-12-01 13:31:47 +00:00
Viktor Szakats
2e57dcb9d2
example: fix indentation follow-up
Fix long line and fix more indentations.

Follow-up to 9e896e1b80911a53d6aabb322e034e6ca51b6898
2023-12-01 13:02:11 +00:00
Viktor Szakats
9e896e1b80
example: fix indentation
Tested via #1257
2023-12-01 12:18:01 +00:00
ren mingshuai
8d69e63db9
example: replace remaining libssh2_scp_recv with libssh2_scp_recv2 in output messages (#1258)
libssh2_scp_recv is deprecated and has been replaced by libssh2_scp_recv2
in prior commit.

Follow-up to 6c84a426beb494980579e5c1d244ea54d3fc1a3f
2023-12-01 04:52:12 +01:00
Viktor Szakats
0c9a8e3590
ci: add OpenBSD (v7.4) job + fix build error in example
- Use CMake, LibreSSL and clang from the base install.

- This uncovered a build error in `example/subsystem_netconf.c`, caused
  by using the `%n` printf mask. This is a security risk and some
  systems (notably OpenBSD) disable this feature.

  Fix it by applying this patch from OpenBSD ports (from 2021-09-11):
  https://cvsweb.openbsd.org/ports/security/libssh2/patches/patch-example_subsystem_netconf_c?rev=1.1&content-type=text/x-cvsweb-markup
  2c5b2f3e94
  "The old code is also broken, as it passes a pointer to a variable
  of a different size (on LP64).  There is no check for truncation,
  but buf[] is 1MB in size."
  Patch-by: naddy

  ```
  /home/runner/work/libssh2/libssh2/example/subsystem_netconf.c:252:17: error: '%n' format specifier support is deactivated and will call abort(3) [-Werror]
        "]]>]]>\n%n", (int *)&len);
                 ~^
  /home/runner/work/libssh2/libssh2/example/subsystem_netconf.c:270:17: error: '%n' format specifier support is deactivated and will call abort(3) [-Werror]
        "]]>]]>\n%n", (int *)&len);
                 ~^
  2 errors generated.
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/6991449778/job/19022024280#step:3:420

Also made tests with arm64, but it takes consistently almost 14m to
finish the job, vs. 2-3m for the native amd64:
https://github.com/libssh2/libssh2/actions/runs/6991648984/job/19022440525
https://github.com/libssh2/libssh2/actions/runs/6991551220/job/19022233651

Cherry-picked from #1250
Closes #1250
2023-11-26 10:16:56 +00:00
Viktor Szakats
c6589b8823
stop using leading underscores in macro names
Underscored macros are reserved for the compiler / standard lib / etc.
Stop using them in user code.

We used them as header guards in `src` and in `__FILESIZE` in `example`.

Closes #1248
2023-11-25 13:09:27 +00:00
Viktor Szakats
6fbc9505d8
windows: use built-in _WIN32 macro to detect Windows
Instead of `WIN32`.

The compiler defines `_WIN32`. Windows SDK headers or build env defines
`WIN32`, or we have to take care of it. The agreement seems to be that
`_WIN32` is the preferred practice here.

Minor downside is that CMake uses `WIN32` and we also adopted it in
`Makefile.mk`.

In public libssh2 headers we stick with accepting either `_WIN32` or
`WIN32` and define our own namespaced `LIBSSH2_WIN32` based on them.

grepping for `WIN32` remains useful to detect Windows-specific code.

Closes #1195
2023-09-29 19:15:08 +00:00
Viktor Szakats
4a64ca1430
cmake: tidy-up foreach() syntax
Use `IN LISTS` and `IN ITEMS`. This appears to be the preferred way
within CMake's own source code and possibly improves readability.

Fixup a side-effect of `IN LISTS`, where it retains empty values at
the end of the list, as opposed to the syntax used before, which
dropped it. In our case this happened with lines read from a text
file via `file(READ)`.

https://cmake.org/cmake/help/v3.7/command/foreach.html

Closes #1180
2023-08-28 22:57:02 +00:00
Viktor Szakats
3fa5282d62
cmake: style tidy up
- quote text literals to improve readability.
  (exceptions: `FILES` items, `add_subdirectory` names, `find_package`
  names, literal target names, version numbers, 0/1, built-in CMake
  values and CMake keywords, list items in `cmake/max_warnings.cmake`)
- quote standalone variables that could break syntax on empty values.
- replace `libssh2_SOURCE_DIR` with `PROJECT_SOURCE_DIR`.
- add missing mode to `message()` call.
- `TRUE`/`FALSE` → `ON`/`OFF`.
- add missing default value `OFF` to `option()` for clarity.
- unfold some lines.
- `INSTALL_CMAKE.md` fixes and updates. Show defaults.

Closes #1166
2023-08-15 15:08:30 +00:00
Viktor Szakats
2fdc10ba04
cmake: formatting [ci skip] 2023-07-25 08:38:54 +00:00
Viktor Szakats
279a2e57e5
example: fix regression in ssh2_exec.c
Regression from b13936bd6a89993cd3bf4a18317ca5bd84bb08d7 #861 #846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes #1105
Closes #1106
2023-06-25 16:48:49 +00:00
Daniel Stenberg
f6aa31f48f provide SPDX identifiers
- All files have prominent copyright and SPDX identifier
- If not embedded in the file, in the .reuse/dep5 file
- All used licenses are in LICENSES/ (not shipped in tarballs)
- A new REUSE CI job verify that all files are OK

Assisted-by: Viktor Szakats

Closes #1084
2023-06-07 08:18:55 +02:00
Viktor Szakats
187d89bb07
copyright: remove years from copyright headers
Also:
- uppercase `(C)`.
- add missing 'All rights reserved.' lines.
- drop duplicate 'Author' lines.
- add copyright headers where missing.
- enable copyright header check in checksrc.

Reasons for deleting years (copied as-is from curl):
- they are mostly pointless in all major jurisdictions
- many big corporations and projects already don't use them
- saves us from pointless churn
- git keeps history for us
- the year range is kept in COPYING

Closes #1082
2023-06-04 19:19:16 +00:00
Viktor Szakats
003fb454c3
tidy-up: avoid exclamations, prefer single quotes, in outputs
Closes #1079
2023-06-03 12:51:56 +00:00
Viktor Szakats
e7a542da6a
add copyright/credits
Closes #1050
2023-05-29 17:07:11 +00:00
Viktor Szakats
7129ea9ca8
cmake: add and test "unity" builds
"Unity" (aka "jumbo", aka "amalgamation" builds concatenate source files
before compiling. It has these benefits for example: faster builds,
improved code optimization, cleaner code. Let's support and test this.

- enable unity builds for some existing CI builds to test this build
  scenario.
- tune `UNITY_BUILD_BATCH_SIZE` size.
- disable unity build for example and test programs (they use one source
  each already).

You can enable it by passing `-DCMAKE_UNITY_BUILD=ON` to cmake.
Supported by CMake 3.16 and newer.

Ref: https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html

Closes #1034
2023-05-07 10:03:20 +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
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 cda41f7cb87c3af5258ba48ccef19d3efdbd3d3b, that fixed
running test_ssh2 on Windows via sshd_fixture.

Cherry-picked from #1017
2023-05-03 13:07:13 +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 4e2580628dd1f8dc51ac65ac747ebcf0e93fa3d1

Cherry-picked from #1017
Closes #1022
2023-05-03 12:30:43 +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
a683133dfe
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
2023-04-27 14:27:17 +00:00
Viktor Szakats
d67aaaffc4
tidy-up: text nits, English contractions [ci skip]
In input/output text and docs mostly.
2023-04-27 14:19:03 +00:00
Viktor Szakats
e53aae0e16
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
2023-04-26 00:52:19 +00:00
Viktor Szakats
17801d2064
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
2023-04-18 08:41:20 +00:00
Viktor Szakats
803f19f004
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
2023-04-18 08:20:05 +00:00
Viktor Szakats
9ecb22daab
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
2023-04-16 22:50:01 +00:00
Viktor Szakats
1b0c93b755
checksrc: fix NOTEQUALSZERO warnings
Closes #963
2023-04-14 19:16:27 +00:00
Viktor Szakats
2efdb6747a
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
2023-04-14 11:07:53 +00:00