From 59666e03f04927e5fe3e8d8772d40729f63c570e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 7 Apr 2023 23:32:42 +0000 Subject: [PATCH] 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 --- .gitignore | 3 +- CMakeLists.txt | 3 +- Makefile.am | 1 - Makefile.inc | 6 +- Makefile.mk | 14 ++- NMakefile | 2 +- acinclude.m4 | 2 +- cmake/CheckNonblockingSocketSupport.cmake | 1 - cmake/max_warnings.cmake | 2 - example/CMakeLists.txt | 7 +- example/Makefile.am | 2 +- example/direct_tcpip.c | 20 +++-- example/scp.c | 7 +- example/scp_nonblock.c | 11 +-- example/scp_write.c | 13 +-- example/scp_write_nonblock.c | 13 +-- example/sftp.c | 11 +-- example/sftp_RW_nonblock.c | 11 +-- example/sftp_append.c | 9 +- example/sftp_mkdir.c | 9 +- example/sftp_mkdir_nonblock.c | 9 +- example/sftp_nonblock.c | 11 +-- example/sftp_write.c | 9 +- example/sftp_write_nonblock.c | 13 +-- example/sftp_write_sliding.c | 13 +-- example/sftpdir.c | 9 +- example/sftpdir_nonblock.c | 13 +-- example/ssh2.c | 10 +-- example/ssh2_agent.c | 10 +-- example/ssh2_agent_forwarding.c | 13 +-- example/ssh2_echo.c | 13 +-- example/ssh2_exec.c | 13 +-- example/subsystem_netconf.c | 14 +-- example/tcpip-forward.c | 20 +++-- example/x11.c | 6 +- include/libssh2.h | 21 +++-- include/libssh2_sftp.h | 2 +- src/Makefile.am | 2 +- src/agent.c | 3 - src/agent.h | 3 - src/agent_win.c | 16 +--- src/libssh2_priv.h | 57 ++++-------- src/libssh2_setup.h | 90 +++++++++++++++++++ src/misc.c | 4 +- src/session.c | 5 ++ tests/CMakeLists.txt | 13 +-- tests/Makefile.am | 2 +- tests/openssh_fixture.c | 4 - tests/runner.c | 1 - tests/runner.h | 4 + tests/session_fixture.c | 5 -- tests/session_fixture.h | 1 + tests/ssh2.c | 6 +- tests/test_agent_forward_succeeds.c | 5 -- tests/test_hostkey.c | 5 -- tests/test_hostkey_hash.c | 6 -- ...teractive_auth_fails_with_wrong_response.c | 5 -- ...t_keyboard_interactive_auth_info_request.c | 4 +- ...tive_auth_succeeds_with_correct_response.c | 5 -- ..._password_auth_fails_with_wrong_password.c | 5 -- ..._password_auth_fails_with_wrong_username.c | 5 -- ...d_auth_succeeds_with_correct_credentials.c | 5 -- ...est_public_key_auth_fails_with_wrong_key.c | 5 -- ...c_key_auth_succeeds_with_correct_dsa_key.c | 5 -- ...key_auth_succeeds_with_correct_ecdsa_key.c | 5 -- ...y_auth_succeeds_with_correct_ed25519_key.c | 5 -- ...cceeds_with_correct_ed25519_key_from_mem.c | 4 - ...ceeds_with_correct_encrypted_ed25519_key.c | 5 -- ..._succeeds_with_correct_encrypted_rsa_key.c | 5 -- ...c_key_auth_succeeds_with_correct_rsa_key.c | 5 -- ...th_succeeds_with_correct_rsa_openssh_key.c | 5 -- ...h_succeeds_with_correct_signed_ecdsa_key.c | 5 -- ...uth_succeeds_with_correct_signed_rsa_key.c | 5 -- tests/test_read.c | 5 -- tests/test_warmup.c | 5 -- win32/.gitignore | 7 -- win32/libssh2_config.h | 38 -------- 77 files changed, 250 insertions(+), 466 deletions(-) create mode 100644 src/libssh2_setup.h delete mode 100644 win32/.gitignore delete mode 100644 win32/libssh2_config.h diff --git a/.gitignore b/.gitignore index 64c776c3..3eda965d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,10 +8,9 @@ *.exe *.obj .*.swp +*-*-* Debug Release -debug-* -release-* *.exp Makefile Makefile.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c39302..bd51aa89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,9 +127,9 @@ check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files(sys/un.h HAVE_SYS_UN_H) +check_include_files(sys/param.h HAVE_SYS_PARAM_H) # for example and tests -check_include_files(sys/param.h HAVE_SYS_PARAM_H) check_include_files(arpa/inet.h HAVE_ARPA_INET_H) check_include_files(netinet/in.h HAVE_NETINET_IN_H) @@ -330,6 +330,7 @@ endif() if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND) # The check actually compiles the header. This requires windows.h. + # Check necessary for old-MinGW check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) if(HAVE_BCRYPT_H) diff --git a/Makefile.am b/Makefile.am index 3f6f7907..5caa0553 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,6 @@ VMSFILES = vms/libssh2_make_example.dcl vms/libssh2_make_help.dcl \ vms/readme.vms vms/libssh2_config.h WIN32FILES = NMakefile \ - win32/libssh2_config.h \ src/libssh2.rc OS400FILES = os400/README400 os400/initscript.sh os400/make.sh \ diff --git a/Makefile.inc b/Makefile.inc index a6524cde..e3c1f0cc 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -4,6 +4,6 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ version.c knownhost.c agent.c $(CRYPTO_CSOURCES) pem.c keepalive.c global.c \ blowfish.c bcrypt_pbkdf.c agent_win.c os400qc3.c -HHEADERS = libssh2_priv.h $(CRYPTO_HHEADERS) transport.h channel.h comp.h \ - mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h blf.h agent.h \ - userauth_kbd_packet.h os400qc3.h +HHEADERS = libssh2_priv.h libssh2_setup.h $(CRYPTO_HHEADERS) transport.h \ + channel.h comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h \ + blf.h agent.h userauth_kbd_packet.h os400qc3.h diff --git a/Makefile.mk b/Makefile.mk index 0c7a1feb..337d23b9 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -47,18 +47,17 @@ else TRIPLET ?= $(shell $(CC) -dumpmachine) endif +BLD_DIR ?= $(PROOT)/$(TRIPLET) + ifneq ($(findstring -w,$(TRIPLET)),) WIN32 := 1 BIN_EXT := .exe DYN_EXT := .dll - BLD_DIR ?= $(PROOT)/win32 - CONFIG_H_DIR ?= $(PROOT)/win32 else - BLD_DIR ?= $(PROOT) - CONFIG_H_DIR ?= $(PROOT) + CPPFLAGS += -I$(BLD_DIR) -DHAVE_CONFIG_H endif -CPPFLAGS += -I$(CONFIG_H_DIR) -I$(PROOT)/include +CPPFLAGS += -I$(PROOT)/src -I$(PROOT)/include RCFLAGS += -I$(PROOT)/include # examples, tests @@ -87,9 +86,9 @@ endif DB ?= NDEBUG CPPFLAGS += -D$(DB) ifeq ($(DB),NDEBUG) - OBJ_DIR := release-$(TRIPLET) + OBJ_DIR := release else - OBJ_DIR := debug-$(TRIPLET) + OBJ_DIR := debug CFLAGS += -g CPPFLAGS += -DLIBSSH2DEBUG endif @@ -264,7 +263,6 @@ dist: all $(DISTDIR) $(DISTDIR)/readme.txt @$(call COPY, $(PROOT)/README, $(DISTDIR)) @$(call COPY, $(PROOT)/RELEASE-NOTES, $(DISTDIR)) @$(call COPY, $(PROOT)/include/*.h, $(DISTDIR)/include) - @$(call COPY, $(CONFIG_H_DIR)/libssh2_config.h, $(DISTDIR)/include) @$(call COPY, $(TARGET).a, $(DISTDIR)/lib) ifdef WIN32 @$(call COPY, $(libssh2_def_LIBRARY), $(DISTDIR)/bin) diff --git a/NMakefile b/NMakefile index 8cf64bac..19756816 100644 --- a/NMakefile +++ b/NMakefile @@ -11,7 +11,7 @@ CFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG DLLFLAGS=/LD !endif -CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iwin32 /Iinclude +CFLAGS=/nologo /GL /Zi /EHsc $(CFLAGS) /Iinclude !if "$(OPENSSL_PATH)" != "" CFLAGS=$(CFLAGS) /DLIBSSH2_OPENSSL /I$(OPENSSL_PATH)\include diff --git a/acinclude.m4 b/acinclude.m4 index 85de8c14..9c497944 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -217,7 +217,6 @@ dnl the code was bad, try a different program now, test 3 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#include #include #endif ],[ @@ -451,6 +450,7 @@ m4_case([$1], LIBS="$LIBS -lcrypt32" + # Check necessary for old-MinGW LIBSSH2_LIB_HAVE_LINKFLAGS([bcrypt], [], [ #include #include diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index 6affb1cc..b34b8b98 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -74,7 +74,6 @@ int main(void) #define WIN32_LEAN_AND_MEAN #endif -#include #include int main(void) diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index e14c67a8..6d203344 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -27,8 +27,6 @@ if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") endif() endif() - - add_definitions(-D_CRT_SECURE_NO_WARNINGS) elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang") if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f062634f..72ca9489 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -39,11 +39,6 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) -if(MSVC) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) -endif() - set(EXAMPLES direct_tcpip scp @@ -74,7 +69,7 @@ foreach(example ${EXAMPLES}) add_executable(example-${example} ${example}.c) list(APPEND EXAMPLE_TARGETS example-${example}) # to find generated header - target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src) + target_include_directories(example-${example} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ../src) target_link_libraries(example-${example} ${LIB_STATIC} ${LIBRARIES}) endforeach() diff --git a/example/Makefile.am b/example/Makefile.am index 495f93eb..0d9594b5 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -29,5 +29,5 @@ noinst_PROGRAMS = \ tcpip-forward \ x11 -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/example -I../src +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/include LDADD = $(top_builddir)/src/libssh2.la diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index f724373c..cf19fed3 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -1,16 +1,22 @@ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -#include -#include -#include +#include /* for socklen_t */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) #define send(s, b, l, f) send((s), (b), (int)(l), (f)) -#else +#endif + +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include #endif @@ -30,10 +36,6 @@ #define INADDR_NONE (in_addr_t)-1 #endif -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; const char *keyfile2 = "/home/username/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/scp.c b/example/scp.c index ead7a84b..999a960e 100644 --- a/example/scp.c +++ b/example/scp.c @@ -2,11 +2,10 @@ * Sample showing how to do a simple SCP transfer. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -15,8 +14,8 @@ #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index d7b97bed..1160150e 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -7,11 +7,10 @@ * "scp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -23,8 +22,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -39,10 +38,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/scp_write.c b/example/scp_write.c index 0962a89d..581db95a 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -2,20 +2,17 @@ * Sample showing how to do an SCP upload. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -30,10 +27,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - int main(int argc, char *argv[]) { uint32_t hostaddr; diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index f9f12b1d..742896bb 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -2,12 +2,9 @@ * Sample showing how to do an SCP non-blocking upload transfer. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -17,8 +14,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -34,10 +31,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftp.c b/example/sftp.c index 78a4e4cb..12073b70 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -7,12 +7,11 @@ * "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -21,8 +20,8 @@ #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -37,10 +36,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - const char *keyfile1 = "~/.ssh/id_rsa.pub"; const char *keyfile2 = "~/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 76dc525e..6d30ae7f 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -7,12 +7,11 @@ * Using the SFTP server running on 127.0.0.1 */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -24,8 +23,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +39,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #define STORAGE "/tmp/sftp-storage" /* this is the local file name this example uses to store the downloaded file in */ diff --git a/example/sftp_append.c b/example/sftp_append.c index 0278009c..a24d0532 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -7,21 +7,18 @@ * sftp_append 192.168.0.1 user password localfile /tmp/remotefile */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 30231ee9..4838c1ef 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -7,21 +7,18 @@ * "sftp 192.168.0.1 user password /tmp/sftp_mkdir" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index be5f7afe..4563a153 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -7,21 +7,18 @@ * "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index ea16f238..760b78ba 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -7,12 +7,11 @@ * "sftp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include #ifdef WIN32 -# include # define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H @@ -24,8 +23,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +39,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/sftp_write.c b/example/sftp_write.c index e3725d1b..a241a424 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -7,21 +7,18 @@ * "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index b907109c..db57fd5f 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -7,13 +7,10 @@ * "sftp 192.168.0.1 user password thisfile /tmp/storehere" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -23,8 +20,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +37,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 26223140..2be99d29 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -7,13 +7,10 @@ * "sftp 192.168.0.1 user password file /tmp/storehere" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -23,8 +20,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -40,10 +37,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/sftpdir.c b/example/sftpdir.c index 8d6dad58..976ae818 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -7,13 +7,10 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -36,10 +33,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #if defined(_MSC_VER) #define __FILESIZE "I64u" #else diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 457ed7e0..779dd3d4 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -7,21 +7,18 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -36,10 +33,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - #if defined(_MSC_VER) #define __FILESIZE "I64u" #else diff --git a/example/ssh2.c b/example/ssh2.c index afd1d647..b1e026f5 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -11,22 +11,18 @@ * command executes on the remote machine */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif # ifdef HAVE_ARPA_INET_H #include diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 1815c10d..2056ba6d 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -6,22 +6,18 @@ * "ssh2_agent host user" */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif # ifdef HAVE_ARPA_INET_H #include diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 2110d6fa..2e7f104a 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -13,12 +13,9 @@ * */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -28,8 +25,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -45,10 +42,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index c08b4bef..36651d7f 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -8,12 +8,9 @@ * */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -23,8 +20,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -39,10 +36,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index 7d0db115..9fc3dbce 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -10,12 +10,9 @@ * */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif @@ -25,8 +22,8 @@ #ifdef HAVE_SYS_SELECT_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include @@ -41,10 +38,6 @@ #include #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) { struct timeval timeout; diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index b3198770..2101cedc 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -1,14 +1,16 @@ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include -#ifdef WIN32 -#include -#include -#include -#else +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include #endif diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index c90865fd..8dea412f 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -1,16 +1,22 @@ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #ifdef WIN32 -#include -#include -#include +#include /* for socklen_t */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) #define send(s, b, l, f) send((s), (b), (int)(l), (f)) -#else +#endif + +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include #endif @@ -30,10 +36,6 @@ #define INADDR_NONE (in_addr_t)-1 #endif -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - const char *keyfile1 = "/home/username/.ssh/id_rsa.pub"; const char *keyfile2 = "/home/username/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/x11.c b/example/x11.c index 70f40092..c8971252 100644 --- a/example/x11.c +++ b/example/x11.c @@ -5,8 +5,8 @@ * "ssh2 host user password [DEBUG]" */ +#include "libssh2_setup.h" #include -#include "libssh2_config.h" #include @@ -42,10 +42,6 @@ #include -#if defined(_MSC_VER) && _MSC_VER < 1700 -#pragma warning(disable:4127) -#endif - #define _PATH_UNIX_X "/tmp/.X11-unix/X%d" /* diff --git a/include/libssh2.h b/include/libssh2.h index 0c82911a..2a859cb9 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -87,7 +87,12 @@ #ifdef __cplusplus extern "C" { #endif -#ifdef _WIN32 + +#if defined(_WIN32) || defined(WIN32) +#define _LIBSSH2_WIN32 +#endif + +#ifdef _LIBSSH2_WIN32 # include # include #endif @@ -99,7 +104,7 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API -# ifdef WIN32 +# ifdef _LIBSSH2_WIN32 # if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || \ defined(_WINDLL) || defined(libssh2_shared_EXPORTS) # ifdef LIBSSH2_LIBRARY @@ -110,9 +115,9 @@ extern "C" { # else # define LIBSSH2_API # endif -# else /* !WIN32 */ +# else /* !_LIBSSH2_WIN32 */ # define LIBSSH2_API -# endif /* WIN32 */ +# endif /* _LIBSSH2_WIN32 */ #endif /* LIBSSH2_API */ #ifdef HAVE_SYS_UIO_H @@ -138,13 +143,13 @@ typedef unsigned long long libssh2_uint64_t; typedef long long libssh2_int64_t; #endif -#ifdef WIN32 +#ifdef _LIBSSH2_WIN32 typedef SOCKET libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET INVALID_SOCKET -#else /* !WIN32 */ +#else /* !_LIBSSH2_WIN32 */ typedef int libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET -1 -#endif /* WIN32 */ +#endif /* _LIBSSH2_WIN32 */ /* * Determine whether there is small or large file support on windows. @@ -170,7 +175,7 @@ typedef int libssh2_socket_t; # undef LIBSSH2_USE_WIN32_LARGE_FILES #endif -#if defined(_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ +#if defined(_LIBSSH2_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ !defined(LIBSSH2_USE_WIN32_SMALL_FILES) # define LIBSSH2_USE_WIN32_SMALL_FILES #endif diff --git a/include/libssh2_sftp.h b/include/libssh2_sftp.h index d35ff27a..5c152d75 100644 --- a/include/libssh2_sftp.h +++ b/include/libssh2_sftp.h @@ -40,7 +40,7 @@ #include "libssh2.h" -#ifndef WIN32 +#ifndef _LIBSSH2_WIN32 #include #endif diff --git a/src/Makefile.am b/src/Makefile.am index 84e21019..240bed14 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,7 +31,7 @@ lib_LTLIBRARIES = libssh2.la # srcdir/include for the shipped headers # builddir/src for the generated config header when building out of the source # tree -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/src +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/include VERSION=-version-info 1:1:0 diff --git a/src/agent.c b/src/agent.c index 0907e598..a7b5de7e 100644 --- a/src/agent.c +++ b/src/agent.c @@ -50,9 +50,6 @@ #endif #include "userauth.h" #include "session.h" -#ifdef WIN32 -#include -#endif /* Requests from client to agent for protocol 1 key operations */ #define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1 diff --git a/src/agent.h b/src/agent.h index 64bbfe01..605ba05d 100644 --- a/src/agent.h +++ b/src/agent.h @@ -41,9 +41,6 @@ #include "libssh2_priv.h" #include "session.h" -#ifdef WIN32 -#include -#endif /* non-blocking mode on agent connection is not yet implemented, but for future use. */ diff --git a/src/agent_win.c b/src/agent_win.c index be6be4b7..95e2b8cd 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -40,21 +40,11 @@ #include "libssh2_priv.h" #include "agent.h" #include -#ifdef HAVE_SYS_UN_H -#include -#else -/* Use the existence of sys/un.h as a test if Unix domain socket is - supported. winsock*.h define PF_UNIX/AF_UNIX but do not actually - support them. */ -#undef PF_UNIX -#endif -#include "userauth.h" -#include "session.h" -#ifdef WIN32 -#include -#endif #if defined(WIN32) && !defined(LIBSSH2_WINDOWS_APP) + +#include /* for getenv() */ + /* Code to talk to OpenSSH was taken and modified from the Win32 port of * Portable OpenSSH by the PowerShell team. Commit * 8ab565c53f3619d6a1f5ac229e212cad8a52852c of diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 67c4da54..6b048df2 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -39,50 +39,12 @@ * OF SUCH DAMAGE. */ -/* Disable warnings: C4127: conditional expression is constant */ -#if defined(_MSC_VER) && _MSC_VER < 1900 -#pragma warning(disable:4127) -#endif - -/* Define mingw-w64 version macros, eg __MINGW{32,64}_{MINOR,MAJOR}_VERSION */ -#ifdef __MINGW32__ -#include <_mingw.h> -#endif +/* Header used by 'src' */ #define LIBSSH2_LIBRARY -#include "libssh2_config.h" -/* Number of bits in a file offset, on hosts where this is settable. */ -#if defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR) -# ifndef _FILE_OFFSET_BITS -# define _FILE_OFFSET_BITS 64 -# endif -#endif - -#ifdef WIN32 -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#undef WIN32_LEAN_AND_MEAN - -/* Detect Windows App environment which has a restricted access - to the Win32 APIs. */ -# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ - defined(WINAPI_FAMILY) -# include -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ - !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define LIBSSH2_WINDOWS_APP -# endif -# endif - -#include -#include -/* Force parameter type. */ -#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) -#define send(s, b, l, f) send((s), (b), (int)(l), (f)) -#endif +/* platform/compiler-specific setup */ +#include "libssh2_setup.h" #include #include @@ -128,6 +90,19 @@ #include "libssh2_sftp.h" #include "misc.h" +#ifdef WIN32 +/* Detect Windows App environment which has a restricted access + to the Win32 APIs. */ +# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ + defined(WINAPI_FAMILY) +# include +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define LIBSSH2_WINDOWS_APP +# endif +# endif +#endif + #ifndef FALSE #define FALSE 0 #endif diff --git a/src/libssh2_setup.h b/src/libssh2_setup.h new file mode 100644 index 00000000..ac769233 --- /dev/null +++ b/src/libssh2_setup.h @@ -0,0 +1,90 @@ +#ifndef LIBSSH2_SETUP_H +#define LIBSSH2_SETUP_H + +/* Header for platform/compiler-specific initialization. + Used by 'src', 'example', 'tests' */ + +#if defined(_WIN32) && !defined(WIN32) +#define WIN32 +#endif + +/* Define mingw-w64 version macros, eg __MINGW{32,64}_{MINOR,MAJOR}_VERSION */ +#ifdef __MINGW32__ +#include <_mingw.h> +#endif + +/* Configuration provided by build tools (autotools and CMake), + and via platform-specific directories for os400 and vms */ +#if defined(HAVE_CONFIG_H) || defined(__OS400__) || defined(__VMS) + +#include "libssh2_config.h" + +/* Hand-crafted configuration for platforms which lack config tool. */ +#elif defined(WIN32) + +#define HAVE_IOCTLSOCKET +#define HAVE_SELECT +#define HAVE_SNPRINTF + +#ifdef __MINGW32__ +# define HAVE_UNISTD_H +# define HAVE_INTTYPES_H +# define HAVE_SYS_TIME_H +# define HAVE_SYS_PARAM_H +# define HAVE_GETTIMEOFDAY +# define HAVE_LONGLONG +# define HAVE_STRTOLL +#elif defined(_MSC_VER) +# if _MSC_VER >= 1310 +# define HAVE_LONGLONG +# endif +# if _MSC_VER >= 1800 +# define HAVE_STRTOLL +# endif +# if _MSC_VER < 1900 +# undef HAVE_SNPRINTF +# endif +#endif + +#endif /* defined(HAVE_CONFIG_H) */ + +/* Below applies to both auto-detected and hand-crafted configs */ + +#ifdef WIN32 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __MINGW32__ +# ifdef __MINGW64_VERSION_MAJOR +/* Number of bits in a file offset, on hosts where this is settable. */ +# ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +# endif +# endif +#elif defined(_MSC_VER) +# ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS /* for fopen(), getenv() */ +# endif +# ifndef LIBSSH2_LIBRARY /* apply to examples and tests only */ +# ifndef _CRT_NONSTDC_NO_DEPRECATE +# define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write() */ +# endif +# ifndef _WINSOCK_DEPRECATED_NO_WARNINGS +# define _WINSOCK_DEPRECATED_NO_WARNINGS /* for inet_addr() */ +# endif +# endif +# if _MSC_VER < 1500 +# define vsnprintf _vsnprintf +# endif +# if _MSC_VER < 1900 +# define strdup _strdup +/* Silence bogus warning C4127: conditional expression is constant */ +# pragma warning(disable:4127) +# endif +#endif + +#endif /* WIN32 */ + +#endif /* LIBSSH2_SETUP_H */ diff --git a/src/misc.c b/src/misc.c index 86990029..654877bd 100644 --- a/src/misc.c +++ b/src/misc.c @@ -51,7 +51,9 @@ #endif #ifdef WIN32 -#include +/* Force parameter type. */ +#define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) +#define send(s, b, l, f) send((s), (b), (int)(l), (f)) #endif #include diff --git a/src/session.c b/src/session.c index 96a2167b..5d2b023b 100644 --- a/src/session.c +++ b/src/session.c @@ -38,6 +38,11 @@ */ #include "libssh2_priv.h" + +#ifdef WIN32 +#include /* for socklen_t */ +#endif + #include #ifdef HAVE_UNISTD_H #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 91ce4f66..e7925233 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,11 +39,6 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) -if(MSVC) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) -endif() - set(TESTS warmup hostkey @@ -83,21 +78,21 @@ if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS") endif() add_library(runner STATIC runner.h runner.c openssh_fixture.h openssh_fixture.c session_fixture.h session_fixture.c) -target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../include) +target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include) target_compile_definitions(runner PRIVATE FIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}") # test building against shared libssh2 lib if(BUILD_SHARED_LIBS) set(test warmup) # any test will do add_executable(test_${test}_shared test_${test}.c) - target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src") + target_include_directories(test_${test}_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) target_link_libraries(test_${test}_shared runner ${LIB_SHARED} ${LIBRARIES}) endif() foreach(test ${TESTS}) add_executable(test_${test} test_${test}.c) list(APPEND TEST_TARGETS test_${test}) - target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src") + target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src) target_link_libraries(test_${test} runner ${LIB_STATIC} ${LIBRARIES}) add_test( @@ -143,7 +138,7 @@ endforeach() add_executable(test_keyboard_interactive_auth_info_request test_keyboard_interactive_auth_info_request.c ../src/userauth_kbd_packet.c) target_compile_definitions(test_keyboard_interactive_auth_info_request PRIVATE "${CRYPTO_BACKEND_DEFINE}") -target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src/" "${CRYPTO_BACKEND_INCLUDE_DIR}") +target_include_directories(test_keyboard_interactive_auth_info_request PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src "${CRYPTO_BACKEND_INCLUDE_DIR}") find_program(GCOV_PATH gcov) set(TGT_OPTIONS -g --coverage -fprofile-abs-path) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) diff --git a/tests/Makefile.am b/tests/Makefile.am index f0ada7d3..d9f73165 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = ossfuzz -AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include -I$(top_builddir)/src +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/include ctests = simple$(EXEEXT) TESTS = $(ctests) mansyntax.sh diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 3e453d93..75a40ab1 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -37,11 +37,7 @@ #include "session_fixture.h" #include "openssh_fixture.h" -#include "libssh2_config.h" -#ifdef WIN32 -#include -#endif #ifdef HAVE_SYS_SOCKET_H #include #endif diff --git a/tests/runner.c b/tests/runner.c index f3522bba..aff8cae5 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -35,7 +35,6 @@ * OF SUCH DAMAGE. */ -#include "session_fixture.h" #include "runner.h" int main(void) diff --git a/tests/runner.h b/tests/runner.h index f32a7af2..6cd54934 100644 --- a/tests/runner.h +++ b/tests/runner.h @@ -38,6 +38,10 @@ #ifndef LIBSSH2_TESTS_RUNNER_H #define LIBSSH2_TESTS_RUNNER_H +/* Most tests need these */ +#include "session_fixture.h" +#include + int test(LIBSSH2_SESSION *session); #endif diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 7087c359..232c0498 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -36,7 +36,6 @@ */ #include "session_fixture.h" -#include "libssh2_config.h" #include "openssh_fixture.h" #include @@ -45,15 +44,11 @@ #include #endif -#ifdef WIN32 -#include -#include #ifdef _MSC_VER #include #define getcwd _getcwd #define chdir _chdir #endif -#endif #ifdef HAVE_SYS_SOCKET_H #include diff --git a/tests/session_fixture.h b/tests/session_fixture.h index 3820a5a9..5314fa57 100644 --- a/tests/session_fixture.h +++ b/tests/session_fixture.h @@ -38,6 +38,7 @@ #ifndef LIBSSH2_TESTS_SESSION_FIXTURE_H #define LIBSSH2_TESTS_SESSION_FIXTURE_H +#include "libssh2_setup.h" #include #if defined(_MSC_VER) && _MSC_VER < 1900 diff --git a/tests/ssh2.c b/tests/ssh2.c index b338c922..f9120651 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -1,13 +1,9 @@ /* Self test, based on examples/ssh2.c. */ -#include "libssh2_config.h" +#include "libssh2_setup.h" #include #include -#ifdef WIN32 -# include -# include -#endif #ifdef HAVE_SYS_SOCKET_H # include #endif diff --git a/tests/test_agent_forward_succeeds.c b/tests/test_agent_forward_succeeds.c index 990531df..7d835feb 100644 --- a/tests/test_agent_forward_succeeds.c +++ b/tests/test_agent_forward_succeeds.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - const char *USERNAME = "libssh2"; /* set in Dockerfile */ const char *KEY_FILE_PRIVATE = "key_rsa"; const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */ diff --git a/tests/test_hostkey.c b/tests/test_hostkey.c index 007b9bfb..3ab01ab0 100644 --- a/tests/test_hostkey.c +++ b/tests/test_hostkey.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *EXPECTED_RSA_HOSTKEY = "AAAAB3NzaC1yc2EAAAABIwAAAQEArrr/JuJmaZligyfS8vcNur+mWR2ddDQtVdhHzdKU" "UoR6/Om6cvxpe61H1YZO1xCpLUBXmkki4HoNtYOpPB2W4V+8U4BDeVBD5crypEOE1+7B" diff --git a/tests/test_hostkey_hash.c b/tests/test_hostkey_hash.c index 6f22d68f..41f1e44d 100644 --- a/tests/test_hostkey_hash.c +++ b/tests/test_hostkey_hash.c @@ -1,10 +1,4 @@ -#include "session_fixture.h" #include "runner.h" -#include "libssh2_config.h" - -#include - -#include static const char *EXPECTED_RSA_HOSTKEY = "AAAAB3NzaC1yc2EAAAABIwAAAQEArrr/JuJmaZligyfS8vcNur+mWR2ddDQtVdhHzdKU" diff --git a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c index 9927a96c..9a37afb4 100644 --- a/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c +++ b/tests/test_keyboard_interactive_auth_fails_with_wrong_response.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *USERNAME = "libssh2"; /* set in Dockerfile */ static const char *WRONG_PASSWORD = "i'm not the password"; diff --git a/tests/test_keyboard_interactive_auth_info_request.c b/tests/test_keyboard_interactive_auth_info_request.c index 989681f9..d30c0cfc 100644 --- a/tests/test_keyboard_interactive_auth_info_request.c +++ b/tests/test_keyboard_interactive_auth_info_request.c @@ -35,11 +35,11 @@ * OF SUCH DAMAGE. */ -#include - #include "libssh2_priv.h" #include "userauth_kbd_packet.h" +#include + #define PASS 0 #define FAIL -1 diff --git a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c index 14746e96..f15ab7dc 100644 --- a/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c +++ b/tests/test_keyboard_interactive_auth_succeeds_with_correct_response.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "my test password"; diff --git a/tests/test_password_auth_fails_with_wrong_password.c b/tests/test_password_auth_fails_with_wrong_password.c index ec57b3b9..e72c7ff8 100644 --- a/tests/test_password_auth_fails_with_wrong_password.c +++ b/tests/test_password_auth_fails_with_wrong_password.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *USERNAME = "libssh2"; /* set in Dockerfile */ static const char *WRONG_PASSWORD = "i'm not the password"; diff --git a/tests/test_password_auth_fails_with_wrong_username.c b/tests/test_password_auth_fails_with_wrong_username.c index 6ada9682..12516c88 100644 --- a/tests/test_password_auth_fails_with_wrong_username.c +++ b/tests/test_password_auth_fails_with_wrong_username.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *PASSWORD = "my test password"; static const char *WRONG_USERNAME = "i dont exist"; diff --git a/tests/test_password_auth_succeeds_with_correct_credentials.c b/tests/test_password_auth_succeeds_with_correct_credentials.c index 7b3fd7d8..01be0c59 100644 --- a/tests/test_password_auth_succeeds_with_correct_credentials.c +++ b/tests/test_password_auth_succeeds_with_correct_credentials.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "my test password"; diff --git a/tests/test_public_key_auth_fails_with_wrong_key.c b/tests/test_public_key_auth_fails_with_wrong_key.c index 83cba13d..c371c21c 100644 --- a/tests/test_public_key_auth_fails_with_wrong_key.c +++ b/tests/test_public_key_auth_fails_with_wrong_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - static const char *USERNAME = "libssh2"; /* set in Dockerfile */ static const char *KEY_FILE_PRIVATE = "key_dsa_wrong"; static const char *KEY_FILE_PUBLIC = "key_dsa_wrong.pub"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c index 6d77b3b9..bc5319c6 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_dsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_dsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c index 768f417c..2d1650c8 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ecdsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_ecdsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c index 31b9bf0d..e0380f69 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_ed25519"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c index 8f7865ff..b9d9385f 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c +++ b/tests/test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c @@ -1,9 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include #include static const char *USERNAME = "libssh2"; /* set in Dockerfile */ diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c index 0095cf47..7a305cef 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_ed25519_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "libssh2"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c index 08acc2be..15803afe 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_encrypted_rsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *PASSWORD = "libssh2"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c index 96792259..6b905e6e 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c index cac578a3..4440f124 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_rsa_openssh_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa_openssh"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c index 93d5a310..f5c51f98 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_ecdsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "signed_key_ecdsa"; diff --git a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c index 4a9a6ddd..65c5597b 100644 --- a/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c +++ b/tests/test_public_key_auth_succeeds_with_correct_signed_rsa_key.c @@ -1,10 +1,5 @@ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "signed_key_rsa"; diff --git a/tests/test_read.c b/tests/test_read.c index b7f9d6af..03ab99dc 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -1,12 +1,7 @@ /* libssh2 test receiving large amounts of data through a channel */ -#include "session_fixture.h" #include "runner.h" -#include - -#include - /* configured in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa"; diff --git a/tests/test_warmup.c b/tests/test_warmup.c index c8f2c21c..4eb19514 100644 --- a/tests/test_warmup.c +++ b/tests/test_warmup.c @@ -1,13 +1,8 @@ /* Warm-up test. Always return success. Workaround for CI/docker/etc flakiness on the first run. */ -#include "session_fixture.h" #include "runner.h" -#include - -#include - int test(LIBSSH2_SESSION *session) { size_t len = 0; diff --git a/win32/.gitignore b/win32/.gitignore deleted file mode 100644 index 5f852e42..00000000 --- a/win32/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -*.a -*.dll -*.def -*.exe -debug-* -release-* -libssh2-*.zip diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h deleted file mode 100644 index 60c14676..00000000 --- a/win32/libssh2_config.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef LIBSSH2_CONFIG_H -#define LIBSSH2_CONFIG_H - -#ifndef WIN32 -#define WIN32 -#endif - -#define HAVE_IOCTLSOCKET -#define HAVE_SELECT -#define HAVE_SNPRINTF - -#ifdef __MINGW32__ -# define HAVE_UNISTD_H -# define HAVE_INTTYPES_H -# define HAVE_SYS_TIME_H -# define HAVE_GETTIMEOFDAY -# define HAVE_LONGLONG -# define HAVE_STRTOLL -#elif defined(_MSC_VER) -# ifndef _CRT_SECURE_NO_WARNINGS -# define _CRT_SECURE_NO_WARNINGS -# endif -# if _MSC_VER >= 1310 -# define HAVE_LONGLONG -# endif -# if _MSC_VER >= 1800 -# define HAVE_STRTOLL -# endif -# if _MSC_VER < 1900 -# undef HAVE_SNPRINTF -# if _MSC_VER < 1500 -# define vsnprintf _vsnprintf -# endif -# define strdup _strdup -# endif -#endif - -#endif /* LIBSSH2_CONFIG_H */