1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-29 13:01:14 +03:00

22 Commits

Author SHA1 Message Date
40e817ff50 os400: drop vsprintf() use
Follow-up to discussion in #1457

Plus e-mail address update.

Closes #1462
2024-10-02 16:04:30 +02:00
bfa00f1bd5 tidy-up: around stdint.h
- os400: delete unused `HAVE_STDINT_H`.

- fuzz: delete redundant `stdint.h` use.
  `inttypes.h` is already included via `testinput.h`.

- docs/TODO: adjust type in planned function.

Closes #1212
2023-11-06 15:00:08 +00:00
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
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
5db836b2a8 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
be9ee7095e.

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
2023-04-26 16:46:05 +00:00
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
191c4e8c71 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 f1e80d8d8c
Follow-up to 5644eea216

Closes #980
2023-04-18 08:19:34 +00:00
185292a06b 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
2023-04-02 03:24:16 +00:00
cab599120c 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
2023-04-01 23:41:07 +00:00
eb236329c4 delete redundant HAVE_WINSOCK2_H
`libssh2.h` required `winsock2.h` for `_WIN32` since
81d53de4dc (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 b66d7317ca

TODO: Straighten out the use a mixture of `HAVE_WINDOWS_H`,
      `WIN32`, `_WIN32` to detect Windows.
2023-04-01 19:32:08 +02:00
b66d7317ca 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`.
2023-04-01 13:15:55 +02:00
2f16d8105c 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
2023-03-27 18:28:27 +02:00
50c9bf868e 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.
2023-03-27 11:34:54 +02:00
38177f18dd 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: cf8ca63ea0 (2004-12-31)
RFC: https://datatracker.ietf.org/doc/html/rfc4419 (2006-03)
2023-03-27 11:28:51 +02:00
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
244a1ae856 nw, os400, watcom: stop setting unused macros [ci skip] (#859) 2023-03-19 20:01:48 +01:00
31fb8860db 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
2023-03-07 15:14:22 +00:00
a0e424a51c 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
2023-03-07 14:21:46 +00:00
4cdf785cd3 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
2023-03-07 14:08:12 +00:00
2addafb77b build fixes and improvements (mostly for Windows)
- 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:
    233810bb5f/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: c910cd382d deleted `mswsock.h` from `src/libssh2_priv.h`
  2008: 8c43bc52b1 added `winsock2.h` and `ws2tcpip.h` to `src/libssh2_priv.h`
  2005: dc4bb1af96 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
  9d55db6501.

- 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
2023-03-03 13:30:03 +00:00
6eb132f159 mailing list: moved to lists.haxx.se 2021-09-03 09:17:34 +02:00
dac4b3bac3 os400: add supplementary header files/wrappers. Define configuration. 2016-01-18 13:35:28 +01:00