1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00
Commit Graph

319 Commits

Author SHA1 Message Date
Viktor Szakats
99803822cb tidy-up: miscellaneous
- fix typos in comments and documentation.
- fix references to non-existing functions in comments.
- libssh2_session_free: fix see-also reference on man page.
- libssh2_scp_recv2: fix typo in prototype on man page.
- man2help: use increment operator.
- badwords: extend with new words and an exclusion.
- userauth: unfold string.
- clang-format and manual formatting.

Closes #1988
2026-06-05 18:12:37 +02:00
Viktor Szakats
f69dc3f881 include: exclude two misspelled macros with LIBSSH2_NO_DEPRECATED
Non-misspelled alternatives available since libssh2 v0.15.0.

In user code replace these two:
```
LIBSSH2_FX_UNKNOWN_PRINCIPLE
LIBSSH2_FX_LOCK_CONFlICT
```
with:
```
LIBSSH2_FX_UNKNOWN_PRINCIPAL
LIBSSH2_FX_LOCK_CONFLICT
```
respectively.

Also fix spelling in comments.

Follow-up to 2b2664bfd4 #1977
Follow-up to 4b8db8c1ab

Closes #1987
2026-06-05 16:49:31 +02:00
Viktor Szakats
2b2664bfd4 include: add deprecated attributes where missing, related doc updates
- `libssh2_knownhost_add()`.
- `libssh2_poll_channel_read()`.
  Follow-up to 2b8038e175
- `libssh2_sftp_seek()`.
  Follow-up to 6875285b71
- `libssh2_sftp_tell()`.
  Follow-up to 8eba2961ac
- exclude `LIBSSH2_KNOWNHOST_KEY_SSHDSS` and `LIBSSH2_HOSTKEY_TYPE_DSS`
  macros when `LIBSSH2_NO_DEPRECATED` is set.
  They are both documented as deprecated in man pages.
- disable the above two features when building libssh2 with
  `LIBSSH2_NO_DEPRECATED`.
- TODO: add `libssh2_sign_sk()` for a future rename to
  `libssh2_userauth_sign_sk()`.
- TODO: add remark for `libssh2_session_flag()`.

Also considered `libssh2_session_flag()` which is marked for removal in
TODO (bab3a30220), but it's the only way
to enable compression, which is also used by curl. It needs an API
replacement to control compression, or perhaps only deprecate the rest
of flags.

Closes #1977
2026-06-05 11:38:06 +02:00
Viktor Szakats
e0635ab4cf libssh2_sign_sk: add LIBSSH2_API attribute, document availability
Based on it having a public man page, it was likely meant to be a public
function. Mark it `LIBSSH2_API` to export it from the DLL on Windows.

Also move its public prototype next to userauth functions, since its
implemented in userauth.c (though not using the namespace).

Follow-up to ed439a29bb #698

Closes #1965
2026-06-03 18:55:21 +02:00
Viktor Szakats
f0279a69b5 include: move return type inline with the declarations, where missing
Move `LIBSSH2_API` inline, too.

Also:
- fix missing argument names from a function typedef.
- fix pointer argument formatting.

Follow-up to e85ce25b4c #1960
Follow-up to 6ffb96321c #1935

Closes #1964
2026-06-03 10:50:15 +02:00
Viktor Szakats
9538c99fc4 badwords: add checker script, fix issues found
Checker script and wordlist comes from curl.

Also:
- checksrc.pl: sync up with curl.
- unfold an IETF URL.
- update all IETF URLs where missing.

Closes #1959
2026-06-01 13:22:40 +02:00
Viktor Szakats
412e9df8d6 src: verify _libssh2_store_bignum2_bytes() success
In userauth and wincng.

Also:
- fix pre-existing memory leak on a `_libssh2_wincng_ecdsa_sign()` error
  branch.

Follow-up to ebf644fb6a #1025

Closes #1942
2026-05-14 19:33:05 +02:00
Viktor Szakats
c40bcbf8ae tidy-up: misc
- fix indentation for PP directives.
- drop redundant parentheses.
- typo in comment.
- HACKING-CRYPTO: fix stray spaces and indent.

Closes #1940
2026-05-14 15:57:56 +02:00
Viktor Szakats
07ffced7c2 scripts: move maketgz, git2news.pl from root to scripts directory
To match curl and to avoid clutter in root.

Closes #1918
2026-05-01 17:03:55 +02:00
Viktor Szakats
a73aa23c9f checksrc: stop disabling TYPEDEFSTRUCT globally
Silence locally in public headers. They are part of the documented
public interface, removing them would be a breaking change.

Follow-up to 35aa0b2cd7 #1910
Follow-up to 7dd7e62629 #1909
Follow-up to c07e953a2f #1908
Follow-up to 967647c4da #1907

Closes #1912
2026-05-01 14:19:03 +02:00
Viktor Szakats
1db7f0239d tidy-up: formatting
- reflow a few lines.
- drop space between cast and value. To match majority of code.
- drop space between `*` and variable in declarations and argument
  lists. To match majority of code.

Closes #1899
2026-04-30 10:28:29 +02:00
Viktor Szakats
b6f307dca9 tidy-up: add missing, and drop redundant parentheses
Also:
- apply minor whitespace fixes.
- VMS/man2help.c: clarify `if` expression, drop redundant `else`
  expression.

Follow-up to 6e47049cff #1844

Closes #1898
2026-04-29 19:52:56 +02:00
Viktor Szakats
cbdb0a8caf libssh2.h: merge two #if branches
Follow-up to 3532601532 #1578 #1793

Closes #1869
2026-04-23 00:27:21 +02:00
Viktor Szakats
6e47049cff clang-tidy: extend checks, fix fallouts
- bump to newest clang-tidy (v20) in CI.
- enable more checks.
- disable picky warnings when used with gcc compiler.
- blowfish: delete unused code.
- blowfish: delete redundant static function prototypes.
- fix fallouts:
  - add missing parentheses in macro values.
  - drop redundant parentheses.
  - drop useless `return`.
  - move assigments out of `if` expressions.
  - sync arguments names between prototype and implementation.
  - suppress false positives.

Closes #1844
2026-04-10 23:18:09 +02:00
Viktor Szakats
94d4a2d136 libssh2_poll: add deprecated attribute, drop from no-deprecated builds
Deprecated since v1.2.0 (2009-08-10).

Also:
- disable examples ssh2_echo and x11 for no-deprecate builds. They
  will need to be rewritten or deleted due to reliance on this API.
- ssh2_echo: replace a macro with `sizeof()`.
- update man page.

Follow-up to b1414503f5 #1266
Follow-up to 2b8038e175

Closes #1838
2026-04-09 00:27:15 +02:00
Jim B
3532601532 _WINDLL being defined doesn't mean libssh2 was built as a DLL (#1578) (#1793)
https://github.com/libssh2/libssh2/issues/1578
WINDLL means that the current project using this library is a DLL; not
that this library was built as a DLL. This check for _WINDLL is
incorrect, and the LIBSSH2_EXPORTS flag should be used instead.

Description of problem - build libssh2 as a static library to be
included in a dynamic library; if libssh2 uses _WINDLL then the names
generated are `__imp_*` which do not exist in the static build of the
library.

---------

Co-authored-by: d3x0r <d3x0r@no-reply.github.com>
2026-04-06 08:26:08 -07:00
Viktor Szakats
71804d9f8d checksrc: update, fix fallouts
Closes #1772
2025-12-26 00:38:59 +01:00
Viktor Szakats
46c7a4807c windows: always enable large-file support
It's supported by all known mingw-w64 and MSVC versions, likely also by
other modern Windows compilers.

After this patch, the `LIBSSH2_USE_WIN32_LARGE_FILES` and
`LIBSSH2_USE_WIN32_SMALL_FILES` macros are ignored by the libssh2 public
header, and it no longer defines them.

Closes #1771
2025-12-26 00:03:51 +01:00
Viktor Szakats
1d464325fe include: drop stray bits of Windows CE support
libssh2 cannot be compiled for WinCE. Delete two preprocessor conditions
in the public header checking for WinCE.

Closes #1770
2025-12-25 23:45:27 +01:00
Viktor Szakats
cbe7654d72 windows: drop support for Visual Studio 2008 and older
Closes #1769
2025-12-25 23:42:25 +01:00
Viktor Szakats
c3e6dbd469 tidy-up: fix typos found by typos-cli 1.36.2
Closes #1654
2025-09-13 22:58:06 +02: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
cf3aac1aba libssh2_base64_decode: add deprecation warning
Cherry-picked from #1484
2025-01-31 02:04:59 +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
Stephan Eggermont
780bf13aa2 libssh2.h: typo fixes
Closes #1496
2024-11-21 11:46:26 +01:00
Pascal Neuperger
83590ac70d libssh2.h: add note about release versions to LIBSSH2_VERSION
As noted in #771 and #1473, the blessed and signed releases are on
libssh2.org and any other archives, like those generated by GitHub,
are just a collection of files from the tag and are not the official
releases.

This adds a note, which already exists for `LIBSSH2_TIMESTAMP`, to
`LIBSSH2_VERSION`, to clarify this fact.

Closes #1475
2024-10-23 01:15:07 +02:00
Viktor Szakats
c04d57e785 libssh2.h: bump to 1.11.2_DEV 2024-10-21 12:00:17 +02:00
Viktor Szakats
00e5975ad2 libssh2.h: bump to 1.11.1 2024-10-21 11:59:53 +02:00
Viktor Szakats
b7ab0faa70 disable DSA by default
Also:
- add `LIBSSH2_DSA_ENABLE` to enable it explicitly.
- test the above option in CI.
- say 'deprecated' in docs and public header.
- disable DSA in the CI server config.
  (OpenSSH 9.8 no longer builds with it by default)
  https://www.openssh.com/txt/release-9.8
  Patch-by: Jose Quaresma
- disable more DSA code when not enabled.

Fixes #1433
Closes #1435
2024-07-30 22:59:02 +02:00
Michael Buckley
fb6527468c sftp: implement posix-rename@openssh.com
Add a new function `libssh2_sftp_posix_rename_ex()` and
`libssh2_sftp_posix_rename()`, which implement
the posix-rename@openssh.com extension.

If the server does not support this extension, the function returns
`LIBSSH2_FX_OP_UNSUPPORTED` and it's up to the user to recover, possibly
by calling `libssh2_sftp_rename()`.

Co-authored-by: Viktor Szakats (bump to size_t)
Closes #1386
2024-06-26 19:31:34 +02:00
Adam
ac2e8c73b1 src: fix type warning in libssh2_sftp_unlink macro
The `libssh2_sftp_unlink` macro was implicitly casting the `size_t`
returned by `strlen` to the `unsigned int` type expected by
`libssh2_sftp_unlink_ex`.

This fix adds an explicit cast to match similar macro definitions in
the same file (e.g. `libssh2_sftp_rename`, `libssh2_sftp_mkdir`).

Closes #1406
2024-06-14 04:47:44 +02:00
Viktor Szakats
a6a9093b39 userauth: avoid oob with huge interactive kbd response
- If the length of a response is `UINT_MAX - 3` or larger, an unsigned
  integer overflow occurs on 64-bit systems. Avoid such truncation to
  always allocate enough memory to avoid subsequent out of boundary
  writes.

  Patch-by: Tobias Stoeckmann

- also add FIXME to bump up length field to `size_t` (ABI break)

Closes #1337
2024-03-29 09:11:40 +00:00
Viktor Szakats
4718ede4e0 src: check hash update/final success
Also:
- delete unused internal macro `libssh2_md5()` where defined.
- prefix `libssh2_os400qc3_hash*()` function names with underscore.
  These are public/visible, but internal.
- add FIXMEs to OS/400 code to verify update/final calls; some OS API,
  some internal.

Ref: https://github.com/libssh2/libssh2/pull/1301#discussion_r1446861650
Reviewed-by: Michael Buckley
Reviewed-by: Patrick Monnerat
Closes #1303
2024-01-18 23:54:29 +00:00
Viktor Szakats
2ed9eb92f3 src: check hash init success
Before this patch, SHA2 and SHA1 init function results were cast to
`void`. This patch makes sure to verify these values.

Also:
- exclude an `assert(0)` from release builds in `_libssh2_sha_algo_ctx_init()`.
  (return error instead)
- fix indentation / whitespace

Reviewed-by: Michael Buckley
Closes #1301
2024-01-10 16:32:26 +00:00
Viktor Szakats
f64885b6ab mac: handle low-level errors
- update low-level hmac functions from macros to functions.
- libgcrypt: propagate low-level hmac errors.
- libgcrypt: add error checks for hmac calls.
- os400qc3: add error checks, propagate them.
  Assisted-by: Patrick Monnerat
- mbedtls: fix propagating low-level hmac errors.
- wincng: fix propagating low-level hmac errors.
- mac: verify success of low-level hmac functions.
- knownhost: verify success of low-level hmac functions.
- transport: verify success of MAC hash call.
- minor type cleanup in wincng.
- delete unused ripemd wrapper in wincng.
- delete unused SHA384 wrapper in mbedtls.

Reported-by: Paul Howarth
Reviewed-by: Michael Buckley
Closes #1297
2024-01-10 16:32:22 +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
9839ebe5e9 libssh2.h: add deprecated function warnings
With deprecated-at versions and suggested replacement function.

It's possible to silence them by defining `LIBSSH2_DISABLE_DEPRECATION`.

Also add depcreated-at versions to documentation, and unify wording.

Ref: https://github.com/libssh2/libssh2/pull/1260#issuecomment-1837017987
Closes #1289
2023-12-16 17:43:02 +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
ren mingshuai
b1414503f5 build: add LIBSSH2_NO_DEPRECATED option (#1266)
The following APIs have been deprecated for over 10 years and
use `LIBSSH2_NO_DEPRECATED` to mark them as deprecated:

libssh2_session_startup()
libssh2_banner_set()
libssh2_channel_receive_window_adjust()
libssh2_channel_handle_extended_data()
libssh2_scp_recv()

Add these options to disable them:
- autotools: `--disable-deprecated`
- cmake: `-DLIBSSH2_NO_DEPRECATED=ON`
- `CPPFLAGS`: `-DLIBSSH2_NO_DEPRECATED`

Fixes #1259
Replaces #1260
Co-authored-by: Viktor Szakats
Closes #1267
2023-12-06 00:14:53 +01: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
b136c37998 tidy-up: unsigned -> unsigned int
In the `interval` argument of public `libssh2_keepalive_config()`.

Tested via #1257
2023-12-02 09:53:56 +00:00
Viktor Szakats
631e7734c8 libssh2.h: use _WIN32 for Windows detection instead of rolling our own
Sync up `libssh2.h` Windows detection with the libssh2 source code.

`libssh2.h` was using `WIN32` and `LIBSSH2_WIN32` for Windows detection,
next to the official `_WIN32`. After this patch it only uses `_WIN32`
for this. Also, make it stop defining `LIBSSH2_WIN32`.

There is a slight chance these break compatibility with Windows
compilers that fail to define `_WIN32`. I'm not aware of any obsolete
or modern compiler affected, but in case there is one, one possible
solution is to define this macro manually.

Closes #1238
2023-11-22 13:10:54 +00:00
Viktor Szakats
481be044e0 revert: build: respect autotools DLL_EXPORT in libssh2.h
Revert fb1195cf88 #917

On a second look this change did not improve anything with autotools
builds. autotools seems to handle the dll export matter without it.

This patch also broke (e.g.) curl-for-win autotools builds, where the
curl build defines `DLL_EXPORT` while building libcurl DLL. `libssh2.h`
picks it up, resulting in unresolved symbols while trying to link a
static libssh2 on Windows. The best fix seems to be to revert this,
instead of adding extra tweaks to dependents.

Fixes:
https://ci.appveyor.com/project/curlorg/curl-for-win/builds/47667412#L11035
```
ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_block_directions
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_do)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_multi_statemach)
>>> referenced 8 more times

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_init_ex
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_set_read_timeout
[...]
```

Closes #1141
2023-07-29 23:52:33 +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
e800038cb9 libssh2.h: bump to 1.11.1_DEV [ci skip] 2023-05-30 23:12:40 +00:00
Daniel Stenberg
1c3f1b7da5 libssh2.h: bump to 1.11.0 for release 2023-05-30 17:58:13 +02: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 5db836b2a8

Closes #999
2023-04-27 14:27:17 +00:00
Michael Buckley
bc4e619e76 Agent forwarding implementation (#752)
This PR contains a series of patches that date back many years and I
believe were discussed on the mailing list, but never merged. We have
been using these in our local copy of libssh2 without issue since 2015,
if not earlier. I believe this is the full set of changes, as we tried
to use comments to mark where our copy of libssh2 differs from the
canonical version.

This also contains changes I made earlier this year, but which were not
discussed on the mailing list, to support certificates and FIDO2 keys
with agent forwarding.

Note that this is not a complete implementation of agent forwarding, as
that is outside the scope of libssh2. Clients still need to provide
their own implementation that parses ssh-agent methods after calling
libssh2_channel_read() and calls the appropriate callback messages in
libssh2. See the man page changes in this PR for more details.

Integration-patches-by: Viktor Szakats

* prefer size_t
* prefer unsigned int over u_int in public function
* add const
* docs, indent, checksrc, debug call, compiler warning fixes
2023-04-22 10:54:20 +02:00
Keith Dart
a4544c0117 channel: add support for "signal" message
Can send specific signals to remote process. Allows for slightly
improved remote process management, if the server supports it.

Integration-patches-by: Viktor Szakats

* doc updates
* change `signame_len` to `size_t`
* variable scopes
* fix checksrc warnings

Closes #672
Closes #991
2023-04-20 21:51:29 +00:00