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
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
2213352758 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
2023-04-18 08:20:29 +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
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
Viktor Szakats
01f3fbf01c ci: rename Logging to Debug in AppVeyor 2023-04-17 14:31:54 +00:00
Viktor Szakats
739e41bf40 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
2023-04-17 14:30:51 +00:00
Viktor Szakats
fe64bad58f tests: switch to debian:bullseye-slim in Dockerfile
'slim' provides all we need, with less bloat.

Tested in #976

Follow-up to 78cb64a859
2023-04-16 22:50:40 +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
238def4da8 autotools: rename a variable
To match its counterpart we use for clang and to better match
the original code in curl.

Follow-up to ec0feae792

Closes #977
2023-04-16 19:18:40 +00:00
Viktor Szakats
29fd14e22a ssh2.sh: revert likely wrong quoting [ci skip]
Follow-up to 5012442850
2023-04-16 18:38:41 +00:00
Viktor Szakats
16071c225f build: add -Wbad-function-cast picky warning
Also adjust minimum gcc versions in comment.

Closes #975
2023-04-16 17:22:10 +00:00
Viktor Szakats
819573f94e tests: restore debian:bullseye in Dockerfile
Follow-up to 78cb64a859
2023-04-16 17:08:16 +00:00
Viktor Szakats
5644eea216 session: simplify preprocessor logic
- by using #elif
- by merging two blocks

Closes #972
2023-04-16 16:20:20 +00:00
Viktor Szakats
c9160bf89c tests: try debian:testing for Dockerfile
Follow-up to 78cb64a859
2023-04-16 16:16:18 +00:00
Viktor Szakats
9ffbb05b44 src: add and use LIBSSH2_MIN/MAX macros
Also for #797

Closes #974
2023-04-16 15:48:59 +00:00
Viktor Szakats
78cb64a859 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
2023-04-16 15:43:43 +00:00
Viktor Szakats
f1e80d8d8c 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
2023-04-15 16:15:16 +00:00
Jörgen Sigvardsson
0a500b3554 scp: option to not quote paths (#803)
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 <jorgen.sigvardsson@westermo.com>
2023-04-15 18:11:19 +02:00
Viktor Szakats
31e6d95d01 cmake: make Windows builds initialize faster
By skipping unixy header checks that always fail with
the MSVC toolchain or all Windows toolchains.

Closes #968
2023-04-15 02:51:26 +00:00
Viktor Szakats
bf3b44ca18 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
2023-04-15 02:50:41 +00:00
Viktor Szakats
c627c1256b tidy-up: more whitespace in src
Closes #966
2023-04-15 02:49:52 +00:00
Viktor Szakats
5d399233d8 checksrc: fix EQUALSNULL warnings
`s/([a-z0-9._>*-]+) == NULL/!\1/g`

Closes #964
2023-04-15 02:46:09 +00:00
Viktor Szakats
cd5b114e7d Makefile.am: add new OS400 header [ci skip]
Follow-up to 6dc42e9d62
2023-04-14 19:28:36 +00:00
Viktor Szakats
1b0c93b755 checksrc: fix NOTEQUALSZERO warnings
Closes #963
2023-04-14 19:16:27 +00:00
Viktor Szakats
8b4387d0dc checksrc: fix SIZEOFNOPAREN warnings
`s/sizeof ([a-z0-9._>*-]+)/sizeof(\1)/g`

Closes #962
2023-04-14 19:15:18 +00:00
Viktor Szakats
146a25a06d crypto: add LIBSSH2_NO_HMAC_RIPEMD option
See also: 38015f4e46
See also: be31457f30

Ref: https://github.com/stribika/stribika.github.io/issues/46

Closes #965
2023-04-14 19:14:10 +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
Viktor Szakats
0162d1649c src: fix indentation of macro definitions (follow-up)
Follow-up to d5438f4ba9
2023-04-13 23:44:41 +00:00
Viktor Szakats
d5438f4ba9 src: fix indentation of macro definitions
And some comment cleanup.

Closes #958
2023-04-13 23:39:01 +00:00
Viktor Szakats
f4f5841dd5 example/ssh2_exec: drop conditional code for deprecated API 2023-04-13 15:55:26 +02:00
monnerat
6dc42e9d62 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
2023-04-13 14:08:12 +02:00
Viktor Szakats
bf85faaa92 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
2023-04-13 11:35:21 +00:00
Viktor Szakats
ec0feae792 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:
- a8fbdb461c/acinclude.m4
- a8fbdb461c/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
2023-04-13 11:12:22 +00:00
Viktor Szakats
224fffb178 include: delete leading underscore from macro name
It can cause compiler warnings in 3rd-party code.

Follow-up to 59666e03f0

Closes #957
2023-04-13 11:09:35 +00:00
Viktor Szakats
1ccae7d548 ci: use OpenSSL 3 on AppVeyor VS2022 images
Closes #954
2023-04-12 09:17:54 +00:00
Viktor Szakats
73d95a055c 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 4f0f4bff5a
Follow-up to ff3c774e03

Closes #951
2023-04-12 09:17:10 +00:00
Viktor Szakats
fe02bd2b2d 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
37624b61e3.

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
2023-04-11 00:45:41 +00:00
Viktor Szakats
e590450dcc 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
2023-04-11 00:38:35 +00:00
Viktor Szakats
504026262d include: indentation fixes 2023-04-11 02:33:45 +02:00
Viktor Szakats
0924632fa0 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
2023-04-10 23:03:43 +00:00
Viktor Szakats
fe706697ed 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
2023-04-10 14:23:17 +02:00
Viktor Szakats
c76b96cbe6 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
2023-04-10 09:24:31 +00:00
Viktor Szakats
38015f4e46 crypto: add LIBSSH2_NO_DSA to disable DSA support
See also: be31457f30

Closes #942
2023-04-10 09:21:30 +00:00
Viktor Szakats
4f0f4bff5a 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.<crypto-backend>.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: dfabe8bca2/CMakeLists.txt (L1399-L1413)

  Also fixes missing `libssh2_setup.h` from `src/CMakeFiles.txt` after
  59666e03f0.

- 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
2023-04-10 09:20:13 +00:00
Zenju
e1e78e3670 sftp: always clear protocol error (#787) 2023-04-09 12:15:44 +02:00
Viktor Szakats
8017592163 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:
  dfabe8bca2/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
2023-04-09 10:13:43 +00:00
Viktor Szakats
c1ed4e99df build: make windows.h even leaner
Disable GDI and NLS features in `windows.h`. libssh2 doesn't use these.

Closes #940
2023-04-09 10:13:09 +00:00
Viktor Szakats
ff3c774e03 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
2023-04-08 22:26:47 +00:00
Viktor Szakats
279dd47247 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
2023-04-08 22:26:25 +00:00
Viktor Szakats
fb9f888308 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
2023-04-08 22:26:10 +00:00