diff --git a/docs/libssh2_build_options.md b/docs/libssh2_build_options.md index 1cf42ccc..d4c915c6 100644 --- a/docs/libssh2_build_options.md +++ b/docs/libssh2_build_options.md @@ -29,10 +29,15 @@ enabled/disabled statuses. # RETURN VALUE A read-only, space-separated list of key:value pairs describing build options. -Options use `on` or `off`, except `crypto` which may report these values: +Options use `on` or `off`, except: + +`crypto`, which reports one of these values: `AWS-LC`, `BoringSSL`, `Libgcrypt`, `LibreSSL`, `mbedTLS`, `OpenSSL`, `OpenSSL/1.1.1`, `OS400QC3`, `WinCNG`, `wolfSSL`. +`agent`, which is listed for each supported agent backend: +`Pageant` (Windows-specific), `OpenSSH` (Windows-specific), `Unix`. + # EXAMPLE ~~~c diff --git a/src/Makefile.inc b/src/Makefile.inc index dc24c8d0..4553d3d0 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -36,6 +36,7 @@ CSOURCES = \ wincng.c HHEADERS = \ + agent.h \ chacha.h \ channel.h \ cipher-chachapoly.h \ diff --git a/src/agent.c b/src/agent.c index 6cdb00cd..f9dc748d 100644 --- a/src/agent.c +++ b/src/agent.c @@ -36,18 +36,7 @@ #include /* for getenv() */ -#ifdef HAVE_SYS_UN_H -/* Use the existence of sys/un.h as a test if Unix domain socket is - supported. Windows also supports it via winsock*.h, but not used - here at this time. */ -#include -#define HAVE_AF_UNIX -#endif - -#if defined(_WIN32) && !defined(LIBSSH2_WINDOWS_UWP) -#define HAVE_WIN32_AGENTS -#endif - +#include "agent.h" #include "userauth.h" #include "session.h" @@ -141,14 +130,14 @@ struct _LIBSSH2_AGENT { char *identity_agent_path; /* Path to a custom identity agent socket */ -#ifdef HAVE_WIN32_AGENTS +#ifdef SSH2_AGENT_BACKEND_WIN32_OPENSSH OVERLAPPED overlapped; HANDLE pipe; BOOL pending_io; #endif }; -#ifdef HAVE_WIN32_AGENTS +#ifdef SSH2_AGENT_BACKEND_WIN32_PAGEANT /* Code to talk to Pageant was taken from PuTTY. * * Portions copyright Robert de Bath, Joris van Rantwijk, Delian @@ -253,9 +242,9 @@ static struct agent_ops agent_ops_pageant = { agent_transact_pageant, agent_disconnect_pageant }; -#endif /* HAVE_WIN32_AGENTS */ +#endif /* SSH2_AGENT_BACKEND_WIN32_PAGEANT */ -#ifdef HAVE_WIN32_AGENTS +#ifdef SSH2_AGENT_BACKEND_WIN32_OPENSSH /* Code to talk to OpenSSH was taken and modified from the Win32 port of * Portable OpenSSH by the PowerShell team. Commit @@ -537,9 +526,9 @@ static struct agent_ops agent_ops_openssh = { agent_disconnect_openssh }; -#endif /* HAVE_WIN32_AGENTS */ +#endif /* SSH2_AGENT_BACKEND_WIN32_OPENSSH */ -#ifdef HAVE_AF_UNIX +#ifdef SSH2_AGENT_BACKEND_UNIX static int agent_connect_unix(LIBSSH2_AGENT *agent) { const char *path; @@ -702,18 +691,20 @@ static struct agent_ops agent_ops_unix = { agent_transact_unix, agent_disconnect_unix }; -#endif /* HAVE_AF_UNIX */ +#endif /* SSH2_AGENT_BACKEND_UNIX */ static struct { const char *name; struct agent_ops *ops; } agent_supported_backends[] = { -#ifdef HAVE_WIN32_AGENTS - { "Pageant", &agent_ops_pageant }, - { "OpenSSH", &agent_ops_openssh }, +#ifdef SSH2_AGENT_BACKEND_WIN32_PAGEANT + { SSH2_AGENT_BACKEND_WIN32_PAGEANT, &agent_ops_pageant }, #endif -#ifdef HAVE_AF_UNIX - { "Unix", &agent_ops_unix }, +#ifdef SSH2_AGENT_BACKEND_WIN32_OPENSSH + { SSH2_AGENT_BACKEND_WIN32_OPENSSH, &agent_ops_openssh }, +#endif +#ifdef SSH2_AGENT_BACKEND_UNIX + { SSH2_AGENT_BACKEND_UNIX, &agent_ops_unix }, #endif { NULL, NULL } }; @@ -1075,7 +1066,7 @@ LIBSSH2_AGENT *libssh2_agent_init(LIBSSH2_SESSION *session) agent->identity_agent_path = NULL; ssh2_list_init(&agent->head); -#ifdef HAVE_WIN32_AGENTS +#ifdef SSH2_AGENT_BACKEND_WIN32_OPENSSH agent->pipe = INVALID_HANDLE_VALUE; memset(&agent->overlapped, 0, sizeof(OVERLAPPED)); agent->pending_io = FALSE; diff --git a/src/agent.h b/src/agent.h new file mode 100644 index 00000000..f38019c8 --- /dev/null +++ b/src/agent.h @@ -0,0 +1,24 @@ +#ifndef LIBSSH2_AGENT_H +#define LIBSSH2_AGENT_H +/* Copyright (C) Daiki Ueno + * Copyright (C) Daniel Stenberg + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "libssh2_priv.h" + +#if defined(_WIN32) && !defined(LIBSSH2_WINDOWS_UWP) +#define SSH2_AGENT_BACKEND_WIN32_PAGEANT "Pageant" +#define SSH2_AGENT_BACKEND_WIN32_OPENSSH "OpenSSH" +#endif + +#ifdef HAVE_SYS_UN_H +/* Use the existence of sys/un.h as a test if Unix domain socket (AF_UNIX) + is supported. Windows also supports it via winsock*.h, but not used here + at this time. */ +#include +#define SSH2_AGENT_BACKEND_UNIX "Unix" +#endif + +#endif /* LIBSSH2_AGENT_H */ diff --git a/src/version.c b/src/version.c index ac12157c..3c41733c 100644 --- a/src/version.c +++ b/src/version.c @@ -32,6 +32,8 @@ #include "libssh2_priv.h" +#include "agent.h" + const char *libssh2_version(int req_version_num) { if(req_version_num <= LIBSSH2_VERSION_NUM) @@ -45,8 +47,7 @@ libssh2_crypto_engine_t libssh2_crypto_engine(void) } static const char *ssh2_build_options = - "crypto:" - SSH2_CRYPTO_ENGINE_NAME + "crypto:" SSH2_CRYPTO_ENGINE_NAME " " "MD5:" #if LIBSSH2_MD5 @@ -167,6 +168,18 @@ static const char *ssh2_build_options = "off" #endif " " +#ifdef SSH2_AGENT_BACKEND_WIN32_PAGEANT + "agent:" SSH2_AGENT_BACKEND_WIN32_PAGEANT + " " +#endif +#ifdef SSH2_AGENT_BACKEND_WIN32_OPENSSH + "agent:" SSH2_AGENT_BACKEND_WIN32_OPENSSH + " " +#endif +#ifdef SSH2_AGENT_BACKEND_UNIX + "agent:" SSH2_AGENT_BACKEND_UNIX + " " +#endif "clear-memory:" #ifndef LIBSSH2_NO_CLEAR_MEMORY "on"