summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-02-24 00:30:50 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-11 10:18:16 +0100
commitf2723b28a45424e9b6933d65055f774cd7d5bfd1 (patch)
tree126bba8f1a7b180540b5e0da6a3837065b13fc05
parent275b0e23030a397427c9b6c6645473ef07b48351 (diff)
downloadlibgit2-f2723b28a45424e9b6933d65055f774cd7d5bfd1.tar.gz
ssh: GIT_SSH_LIBSSH2 is now distinct from GIT_SSH
We may want to support SSH but with a different provider that is not libssh2. Add GIT_SSH to indicate that we have some inbuilt SSH support and GIT_SSH_LIBSSH2 to indicate that support is via libssh2. This is similar to how we support GIT_HTTPS and GIT_OPENSSL, for example.
-rw-r--r--CMakeLists.txt2
-rw-r--r--cmake/SelectSSH.cmake31
-rw-r--r--src/libgit2/libgit2.c2
-rw-r--r--src/libgit2/transport.c3
-rw-r--r--src/libgit2/transports/credential.c2
-rw-r--r--src/libgit2/transports/ssh.c4
-rw-r--r--src/libgit2/transports/ssh_libssh2.c6
-rw-r--r--src/util/git2_features.h.in3
8 files changed, 28 insertions, 25 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa5167538..353dec0f9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,7 +30,7 @@ option(USE_THREADS "Use threads for parallel processing when possibl
option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON)
# Backend selection
-option(USE_SSH "Link with libssh2 to enable SSH support" OFF)
+option(USE_SSH "Enable SSH support. Can be set to a specific backend" ON)
option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
option(USE_SHA1 "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS" ON)
option(USE_SHA256 "Enable SHA256. Can be set to HTTPS/Builtin" ON)
diff --git a/cmake/SelectSSH.cmake b/cmake/SelectSSH.cmake
index 23dfc9785..684116200 100644
--- a/cmake/SelectSSH.cmake
+++ b/cmake/SelectSSH.cmake
@@ -1,5 +1,5 @@
-# Optional external dependency: libssh2
-if(USE_SSH)
+# find libssh2
+if(USE_SSH STREQUAL ON OR USE_SSH STREQUAL "libssh2")
find_pkglibraries(LIBSSH2 libssh2)
if(NOT LIBSSH2_FOUND)
find_package(LibSSH2)
@@ -12,30 +12,29 @@ if(USE_SSH)
if(NOT LIBSSH2_FOUND)
message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
endif()
-endif()
-if(LIBSSH2_FOUND)
- set(GIT_SSH 1)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES})
list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
- set(GIT_SSH_MEMORY_CREDENTIALS 1)
+ set(GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1)
endif()
-else()
- message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
-endif()
-if(WIN32 AND EMBED_SSH_PATH)
- file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
- list(SORT SSH_SRC)
- list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
+ if(WIN32 AND EMBED_SSH_PATH)
+ file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
+ list(SORT SSH_SRC)
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
+
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
+ file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
+ endif()
- list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
- file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
set(GIT_SSH 1)
+ set(GIT_SSH_LIBSSH2 1)
+ add_feature_info(SSH ON "using libssh2")
+else()
+ add_feature_info(SSH OFF "SSH transport support")
endif()
-add_feature_info(SSH GIT_SSH "SSH transport support")
diff --git a/src/libgit2/libgit2.c b/src/libgit2/libgit2.c
index b92e1c7f3..d1995839a 100644
--- a/src/libgit2/libgit2.c
+++ b/src/libgit2/libgit2.c
@@ -123,7 +123,7 @@ int git_libgit2_features(void)
#ifdef GIT_HTTPS
| GIT_FEATURE_HTTPS
#endif
-#if defined(GIT_SSH)
+#if defined(GIT_SSH_LIBSSH2)
| GIT_FEATURE_SSH
#endif
#if defined(GIT_USE_NSEC)
diff --git a/src/libgit2/transport.c b/src/libgit2/transport.c
index 640ccacae..c61d0a68b 100644
--- a/src/libgit2/transport.c
+++ b/src/libgit2/transport.c
@@ -22,6 +22,7 @@ typedef struct transport_definition {
static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1, NULL };
static git_smart_subtransport_definition git_subtransport_definition = { git_smart_subtransport_git, 0, NULL };
+
#ifdef GIT_SSH
static git_smart_subtransport_definition ssh_subtransport_definition = { git_smart_subtransport_ssh, 0, NULL };
#endif
@@ -33,11 +34,13 @@ static transport_definition transports[] = {
{ "http://", git_transport_smart, &http_subtransport_definition },
{ "https://", git_transport_smart, &http_subtransport_definition },
{ "file://", git_transport_local, NULL },
+
#ifdef GIT_SSH
{ "ssh://", git_transport_smart, &ssh_subtransport_definition },
{ "ssh+git://", git_transport_smart, &ssh_subtransport_definition },
{ "git+ssh://", git_transport_smart, &ssh_subtransport_definition },
#endif
+
{ NULL, 0, 0 }
};
diff --git a/src/libgit2/transports/credential.c b/src/libgit2/transports/credential.c
index 6e00b0282..b47bd63a1 100644
--- a/src/libgit2/transports/credential.c
+++ b/src/libgit2/transports/credential.c
@@ -204,7 +204,7 @@ int git_credential_ssh_key_memory_new(
const char *privatekey,
const char *passphrase)
{
-#ifdef GIT_SSH_MEMORY_CREDENTIALS
+#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS
return git_credential_ssh_key_type_new(
cred,
username,
diff --git a/src/libgit2/transports/ssh.c b/src/libgit2/transports/ssh.c
index bef0b1440..7171e9cb3 100644
--- a/src/libgit2/transports/ssh.c
+++ b/src/libgit2/transports/ssh.c
@@ -14,7 +14,7 @@ int git_smart_subtransport_ssh(
git_transport *owner,
void *param)
{
-#ifdef GIT_SSH
+#ifdef GIT_SSH_LIBSSH2
return git_smart_subtransport_ssh_libssh2(out, owner, param);
#else
GIT_UNUSED(out);
@@ -31,7 +31,7 @@ int git_transport_ssh_with_paths(
git_remote *owner,
void *payload)
{
-#ifdef GIT_SSH
+#ifdef GIT_SSH_LIBSSH2
git_strarray *paths = (git_strarray *) payload;
git_transport *transport;
transport_smart *smart;
diff --git a/src/libgit2/transports/ssh_libssh2.c b/src/libgit2/transports/ssh_libssh2.c
index f7a0ceed5..b45191857 100644
--- a/src/libgit2/transports/ssh_libssh2.c
+++ b/src/libgit2/transports/ssh_libssh2.c
@@ -7,7 +7,7 @@
#include "ssh_libssh2.h"
-#ifdef GIT_SSH
+#ifdef GIT_SSH_LIBSSH2
#include <libssh2.h>
@@ -343,7 +343,7 @@ static int _git_ssh_authenticate_session(
session, c->username, c->prompt_callback);
break;
}
-#ifdef GIT_SSH_MEMORY_CREDENTIALS
+#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS
case GIT_CREDENTIAL_SSH_MEMORY: {
git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
@@ -1020,7 +1020,7 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use
if (!git__prefixcmp(ptr, SSH_AUTH_PUBLICKEY)) {
*out |= GIT_CREDENTIAL_SSH_KEY;
*out |= GIT_CREDENTIAL_SSH_CUSTOM;
-#ifdef GIT_SSH_MEMORY_CREDENTIALS
+#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS
*out |= GIT_CREDENTIAL_SSH_MEMORY;
#endif
ptr += strlen(SSH_AUTH_PUBLICKEY);
diff --git a/src/util/git2_features.h.in b/src/util/git2_features.h.in
index 1575be641..34d4186cb 100644
--- a/src/util/git2_features.h.in
+++ b/src/util/git2_features.h.in
@@ -29,7 +29,8 @@
#cmakedefine GIT_QSORT_S
#cmakedefine GIT_SSH 1
-#cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1
+#cmakedefine GIT_SSH_LIBSSH2 1
+#cmakedefine GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1
#cmakedefine GIT_NTLM 1
#cmakedefine GIT_GSSAPI 1