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

agent: list supported backends in libssh2_build_options()

Internally: make the agent backend guards unique for each backend, make
them contain the backend name. Use them in `agent.c`, move them to a
separate header and also reuse them from `version.c`.

Ref: https://github.com/libssh2/libssh2/pull/2285#discussion_r3572085858
Follow-up to 2673970d2a #2178

Closes #2312
This commit is contained in:
Viktor Szakats
2026-07-14 17:02:22 +02:00
parent 80323ce425
commit 09073098c5
5 changed files with 62 additions and 28 deletions

View File

@@ -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

View File

@@ -36,6 +36,7 @@ CSOURCES = \
wincng.c
HHEADERS = \
agent.h \
chacha.h \
channel.h \
cipher-chachapoly.h \

View File

@@ -36,18 +36,7 @@
#include <stdlib.h> /* 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 <sys/un.h>
#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;

24
src/agent.h Normal file
View File

@@ -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 <sys/un.h>
#define SSH2_AGENT_BACKEND_UNIX "Unix"
#endif
#endif /* LIBSSH2_AGENT_H */

View File

@@ -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"