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
7e4855926e tests/mansyntax.sh: avoid if ! for portability
Ref: https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Builtins.html#Limitations-of-Builtins

Fixes #704
Closes #935
2023-04-08 22:25:46 +00:00
Viktor Szakats
dfb086bfe2 tidy-up: indentation in guarded #includes [ci skip] 2023-04-08 10:56:14 +00:00
Viktor Szakats
bc0cd58e87 Makefile.mk: drop PROOT variable [ci skip] 2023-04-07 23:51:07 +00:00
Viktor Szakats
59666e03f0 build: hand-crafted config rework & header tidy-up
- introduce the concept of a project level setup header
  `src/libssh2_setup.h`, that is used by `src`, `example` and `tests`
  alike. Move there all common platform/compiler configuration from
  `src/libssh2_priv.h`, individual sources and `CMakeFiles.txt` files.
  Also move there our hand-crafted (= not auto-generated by CMake or
  autotools) configuration `win32/libssh2-config.h`.

- `win32` directory is empty now, delete it.

- `Makefile.mk`: adapt to the above. Build-directory is the target
  triplet, or any custom name set via `BLD_DIR`.

- sync header path order between build systems:
  build/src -> source/src -> source/include

- delete redundant references to `windows.h`, `winsock2.h`,
  `ws2tcpip.h`.

- delete unnecessary #includes, update order (`libssh2_setup.h` first,
  `winsock2.h` first), simplify where possible.

  This makes the code warning-free without `WIN32_LEAN_AND_MEAN`.
  At the same time this patch applies this macro globally, to avoid
  header bloat.

- example: add missing *nix header guards.

- example: fix misindented `HAVE_UNISTD_H` `#ifdef`s.

- set `WIN32` with all build-tools.

- set `HAVE_SYS_PARAM_H` in the hand-crafted config for MinGW.
  To match auto-detection.

- move a source-specific macro to `misc.c` from `libssh2_priv.h`.

See the PR's individual commits for step-by-step updates.

Closes #932
2023-04-07 23:44:43 +00:00
Viktor Szakats
8774f4973f Makefile.mk: build tests and other improvements [ci skip]
- use `example` target for building examples (was: `test`).

- add support for building tests via the `test` target.

- accept lib-only options in a new `LIBSSH2_CPPFLAGS_LIB` variable.

  Useful to pass `-DLIBSSH2_EXPORTS` for correct `dllexport` in
  `libssh2.dll`.

- fix to put dynamic library in lib directory for non-Windows builds

- fix to not delete lib objects on `testclean`
2023-04-07 23:11:59 +00:00
Viktor Szakats
72cd241239 test_warmup: re-implement as test()
Instead of overriding `main()`. To align with the other tests.

Overriding `main()` can cause duplicate symbols without using a lib for
the `runner` code.

Follow-up to 40ac6b230a

Closes #934
2023-04-07 15:43:26 +00:00
Viktor Szakats
ed72926640 NMakefile: drop /DEBUG linker option in release mode [ci skip] 2023-04-07 14:17:38 +00:00
Viktor Szakats
17a419ba62 NMakefile: simplify [ci skip] 2023-04-07 14:16:26 +00:00
Viktor Szakats
dfbd28308e Makefile.mk: merge two rules [ci skip] 2023-04-07 14:15:11 +00:00
Viktor Szakats
2082db93b2 TODO: update item about compiler warnings [ci skip]
Follow-up to 08354e0abb
Follow-up to 2934790572
Follow-up to 5a96f494ee
Follow-up to 463449fb9e
Follow-up to 02f2700a61
2023-04-06 10:54:38 +00:00
ihsinme
4048d0ba26 example/x11: Add null-termination (#749) 2023-04-05 16:23:54 +02:00
Viktor Szakats
85582df111 crypto: fix LIBSSH2_NO_MD5 compiler warnings
Follow-up to be31457f30

Closes #933
2023-04-05 13:59:49 +00:00
Viktor Szakats
bdad217440 build: add new man pages
Follow-up to c20c81ab10
2023-04-05 13:58:36 +00:00
Daniel Silverstone
c20c81ab10 Configurable session read timeout (#892)
This set of changes provides a mechanism to runtime-configure the
previously #define'd timeout for reading packets from a session. The
intention here is to also extend libcurl to be able to use this
interface so that when fetching from sftp servers which are very slow
to return directory listings, connections do not time-out so much.

* Add new field to session to hold configurable read timeout

* Updated `_libssh2_packet_require()`, `_libssh2_packet_requirev()`,
  and `sftp_packet_requirev()` to use new field in session structure

* Updated docs for API functions to set/get read timeout field in
  session structure

* Updated `libssh2.h` to declare the get/set read timeout functions

Co-authored-by: Jon Axtell <jon.axtell@codethink.co.uk>
Credit: Daniel Silverstone
2023-04-05 15:53:53 +02:00
Viktor Szakats
a7d60c62ab cmake: whitespace fixes [ci skip] 2023-04-04 17:54:17 +00:00
Viktor Szakats
d709e3f9d0 libssh2.h: bump LIBSSH2_COPYRIGHT year [ci skip] 2023-04-04 17:52:10 +00:00
Viktor Szakats
901bf00d02 Makefile.mk: move portable GNU Make file to the root
Move the GNU Make file formerly known as `win32/GNUmakefile` to the
root directory from `win32`. It now supports any platform with a
GCC-like toolchain, while also keeping support for win32.

For non-Windows platforms it's necessary to provide a hand-crafted
`libssh2_config.h` header for now.

Usage: `make -f Makefile.mk`
2023-04-04 02:57:29 +02:00
Viktor Szakats
d58b713687 src: include limits.h for *_MAX macros
Follow-up to 5a96f494ee

Reported-by: OldWorldOrdr on github
Fixes #928
Closes #930
2023-04-04 00:03:52 +00:00
Viktor Szakats
202a4f3f7a build: MSVS warning suppression option tidy-up
- in `win32/libssh2_config.h` replace `_CRT_SECURE_NO_DEPRECATE` with
  `_CRT_SECURE_NO_WARNINGS`, to use the official macro for this, like
  in CMake.

  Also, it's now safe to move it back under `_MSC_VER`.

  Suppressing:

  `warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.`
  `warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead.`

- move `_CRT_NONSTDC_NO_DEPRECATE` to `example` and `tests`.
  Not needed for `src`.

  Suppressing:

  `warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup.`
  `warning C4996: 'write': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _write.`

- move `_WINSOCK_DEPRECATED_NO_WARNINGS` from source files to
  CMake files, in `example` and `tests`. Also limit this to MSVC.

  Suppressing:

  `warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead`

TODO: try fixing these instead of suppressing.

Closes #929
2023-04-04 00:03:33 +00:00
Viktor Szakats
8c24a3f599 win32/GNUmakefile: make it movable [ci skip]
- add `BLD_DIR` to customize the output directory (where libs, .zip,
  obj subdir will go). This directory must exist.

  It remains `./win32` for Windows builds.

- add `CONFIG_H_DIR` option to customize `libssh2_config.h` location.

  It remains `./win32` for Windows builds.

- include `.def` in distro zip for Windows.

- ready to move to the root directory.
2023-04-04 00:01:33 +00:00
Viktor Szakats
1cd1aaefa6 win32/GNUmakefile: drop an unnecessary variable [ci skip] 2023-04-03 15:16:51 +00:00
Viktor Szakats
e387311bd6 windows: re-add libssh2.rc
Lost while moving it from the win32 directory

Follow-up to 194cfc0f84
2023-04-03 12:27:05 +00:00
Viktor Szakats
be31457f30 crypto: add LIBSSH2_NO_MD5 to disable MD5 support
Closes #927
2023-04-03 12:10:47 +00:00
Viktor Szakats
ad6aae302a hostkey: fix hash_len field constants
Replace incorrect `MD5_DIGEST_LENGTH` with `SHA_DIGEST_LENGTH` for these
hostkey algos:

- `ssh-rsa` and `ssh-dss`

  Ref: 7a5ffc8cee (2004-12-07 Initial)

- `ssh-rsa-cert-v01@openssh.com`

  Ref: 4b21e49d9d (2022-07-28)
  Ref: #710

Also delete local fall-back definition of `MD5_DIGEST_LENGTH` (added
in 9af7eb48dc). Macro is no longer used.

Reported-by: Markus-Schmidt on github
Fixes #919
Closes #926
2023-04-03 12:09:48 +00:00
Viktor Szakats
2e3e0be816 ci: add MSVS 2008/2010 build tests and fix warnings
Also:

- fix newly surfaced (bogus) warnings in examples with MSVS 2010:

  ```
  ..\..\example\direct_tcpip.c(262): warning C4127: conditional expression is constant
  ```
  Happens for every `FD_SET()` macro reference.

  Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46677835/job/ni4hs97bh18c14ap

- silence MSVS 2010 predefined Windows macro warnings:

  ```
  ..\..\src\wincng.c(867): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size
  ..\..\src\wincng.c(897): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size
  ..\..\src\wincng.c(1132): warning C4306: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size
  ```

  Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46678071/job/08t5ktvkcgdghp7r

Closes #925
2023-04-03 12:08:50 +00:00
Viktor Szakats
d1b36efe41 transport: rename local RANDOM_PADDING macro
Rename `RANDOM_PADDING` macro used internally to enable some code.

Committed in the initial version of `transport.c` in
9d55db6501 (2007-02-02). libssh2 code
never defined it.

The name happens to collide with a Windows macro in `wincrypt.h`.
`transport.c` doesn't include this header, but it includes `winsock2.h`,
and it turns out it can also define this macro in some cases, e.g.
when `WIN32_LEAN_AND_MEAN` is not set.

To be on the safe side, prefix the name with `LIBSSH2_` to avoid
enabling it by accident.

Q: Maybe it'd be best to delete it with the guarded code?

Reported-by: Markus-Schmidt on github
Fixes #921
Closes #924
2023-04-03 12:07:49 +00:00
Viktor Szakats
194cfc0f84 windows: move libssh2.rc to the src directory
Closes #918
2023-04-03 12:07:13 +00:00
Viktor Szakats
a7a2fcdab6 autotools: delete unused conditional HAVE_SYS_UN_H
No longer necessary after moving the disabling/enabling logic from
build tool to `example/x11.c`.

Reverts 4774d500e7
Follow-up to d245c66cc0
2023-04-02 12:12:18 +02:00
Viktor Szakats
cffcae4e0d win32/GNUmakefile: update help & exit without crypto backend [ci skip]
Follow-up to: 5bcd25c4c9
Follow-up to: 68fd02fba0
2023-04-02 10:00:43 +00:00
Viktor Szakats
fb1195cf88 build: respect autotools DLL_EXPORT in libssh2.h
The `DLL_EXPORT` macro is automatically set by autotools when building
the libssh2 DLL. Certain toolchains might require this to correctly
export symbols, so make sure to respect it in `libssh2.h` to enable
`declspec(dllexport)`.

With this patch we have a manual macro for that (`LIBSSH2_EXPORT`),
this autotools one, the CMake one, and `_WINDLL` (added in
c355d31ff9), possibly defined by Visual
Studio.

Closes #917
2023-04-02 03:24:39 +00:00
Viktor Szakats
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
Viktor Szakats
a07ba9ee71 autotools: delete src/libssh2.pc.in reference [ci skip]
Follow-up to 06f2819219
2023-04-02 00:28:38 +00:00
Viktor Szakats
1b59e90705 tidy-up: null-mac/cipher documentation
Move documentation for these deleted build-level options from
autotools/cmake docs to the source code itself.

Follow-up to 50c9bf868e

Closes #915
2023-04-01 23:41:57 +00:00
Viktor Szakats
06f2819219 cmake: re-use existing libssh2.pc template
Instead of maintaining a second copy of `libssh2.pc.in` in `src` just
for CMake, teach CMake to use the existing template in the root dir,
that we already use with autotools.

Closes #914
2023-04-01 23:41:42 +00:00
Viktor Szakats
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
Viktor Szakats
5f790d24ef NMakefile: drop redundant variable and assignments [ci skip] 2023-04-01 19:45:53 +00:00
Viktor Szakats
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
Viktor Szakats
ba53142e0e cmake: detect WinCNG last
This gives a chance to auto-detect mbedTLS on Windows with CMake.
2023-04-01 19:31:25 +02:00
Viktor Szakats
62235989e8 NMakefile: rename config variables, default to WinCNG [ci skip]
- replace `OPENSSLINC` and `OPENSSLLIB` with `OPENSSL_PATH`.
  Assume `include` and `lib` subdirs for headers and libs.

- replace `WITH_ZLIB`, `ZLIBINC` and `ZLIBLIB` with `ZLIB_PATH`.
  Assume `include` and `lib` subdirs for header and lib.

- make WinCNG the default if `WITH_OPENSSL` is not set.
2023-04-01 17:28:23 +00:00
Viktor Szakats
f058f7eacc win32/GNUmakefile: rename object dir and update .gitignore [ci skip]
From `<triplet>-{release|debug}` to `{release|debug}-<triplet>`.

Follow-up to 68fd02fba0
2023-04-01 16:39:48 +00:00
Viktor Szakats
5bcd25c4c9 win32/GNUmakefile: add libgcrypt support [ci skip]
In the previous commit 969487113a,
the commit message should read `win32/GNUmakefile: ` instead of
`libssh2-gnumake.sh: `. Sorry for the mixup.
2023-04-01 16:20:30 +00:00
Viktor Szakats
969487113a libssh2-gnumake.sh: make variable names platform-agnostic [ci skip]
Also more consistent. Refer to DLL/SO/shared as 'dyn'.

Also add comment on how to find customizable environment variables.
2023-04-01 15:51:13 +00:00
Viktor Szakats
68fd02fba0 win32/GNUmakefile: make it support non-Windows builds [ci skip]
With 20-ish extra lines, make this Makefile support all GCC-like
toolchains.

The temporary directory becomes `<triplet>-{release|debug}` from
the former `{release|debug}`.

Also change the lib directory name in the `dist` package from
`win32` to `lib`, to match other packages and build tools.
2023-04-01 15:41:15 +00:00
Viktor Szakats
82644b649a win32/GNUmakefile: default to WinCNG [ci skip]
Also check for wolfSSL before mbedTLS to match CMake.
2023-04-01 15:24:40 +00:00
Viktor Szakats
618c0e68ac win32/GNUmakefile: fixups to previous commit [ci skip]
- `-lws2_32` is necessary when building examples.

- drop a temporary variable.

Follow-up to d245c66cc0
2023-04-01 11:53:55 +00:00
Viktor Szakats
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
Viktor Szakats
0d1ef8a7cb win32/libssh2_config.h: set HAVE_LONGLONG & HAVE_STDLIB_H [ci skip]
- enable `HAVE_LONGLONG` for MinGW and MSVC versions supporting it.

  Necessary for `GNUmakefile`/`NMakefile` builds to create the same
  binaries as CMake/autotools ones do.

- enable `HAVE_STDLIB_H`. It has been universally available on
  Windows for a long time.

  Fixes these clang-cl warnings:
  ```
  src\wincng.c(444,5) :  warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
      free(buf);
      ^
  src\wincng.c(491,20) :  warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long long)' [-Wimplicit-function-declaration]
      pbHashObject = malloc(dwHashObject);
                     ^
  src\wincng.c(491,20) :  note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
  src\wincng.c(2106,14) :  warning: implicitly declaring library function 'realloc' with type 'void *(void *, unsigned long long)' [-Wimplicit-function-declaration]
      bignum = realloc(bn->bignum, length);
               ^
  src\wincng.c(2106,14) :  note: include the header <stdlib.h> or explicitly provide a declaration for 'realloc'
  3 warnings generated.
  ```
2023-04-01 01:52:22 +00:00
Viktor Szakats
d245c66cc0 example: make x11 exclusion build-tool-agnostic
Whether to build the `x11` example or not was decided by each build
tool. CMake didn't build it even on supported platforms. GNUMakefile
used a specific blocklist for it, while autotools enabled it based on
feature-detection.

Migrate the enabler logic to an #ifdef in source and build `x11`
unconditionally with all build tools.

On unsupported platforms (=Windows) this program now displays a short
message stating that fact.

Also:

- fix `x11.c` warnings uncovered after CMake started building it.

- use `libssh2_socket_t` type for portability in `x11.c` too.

- use detected header guards in `x11.c`.

- delete a duplicate reference to `-lws2_32` from `win32/GNUmakefile`
  while there.

Closes #909
2023-04-01 01:36:54 +00:00
Viktor Szakats
91af53851d .gitignore updates [ci skip] 2023-03-31 23:45:36 +00:00
Viktor Szakats
9aa1964dfb tidy-up: whitespace, sorting, comment and naming fixups 2023-03-31 23:46:06 +02:00