8000 Merge pull request #6617 from libgit2/ethomson/openssh · libgit2/libgit2@f51e70d · GitHub
[go: up one dir, main page]

Skip to content

Commit f51e70d 10000

Browse files
authored
Merge pull request #6617 from libgit2/ethomson/openssh
Add OpenSSH support
2 parents da265cd + ac39914 commit f51e70d

31 files changed

+3499
-1163
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,40 @@ jobs:
2525
strategy:
2626
matrix:
2727
platform:
28-
- name: "Linux (Xenial, GCC, OpenSSL)"
28+
- name: "Linux (Xenial, GCC, OpenSSL, libssh2)"
2929
id: xenial-gcc-openssl
3030
container:
3131
name: xenial
3232
env:
3333
CC: gcc
3434
CMAKE_GENERATOR: Ninja
35-
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON
35+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=libssh2 -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON
3636
os: ubuntu-latest
37-
- name: Linux (Xenial, GCC, mbedTLS)
37+
- name: Linux (Xenial, GCC, mbedTLS, OpenSSH)
3838
id: xenial-gcc-mbedtls
3939
container:
4040
name: xenial
4141
env:
4242
CC: gcc
4343
CMAKE_GENERATOR: Ninja
44-
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
44+
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec
4545
os: ubuntu-latest
46-
- name: "Linux (Xenial, Clang, OpenSSL)"
46+
- name: "Linux (Xenial, Clang, OpenSSL, OpenSSH)"
4747
id: xenial-clang-openssl
4848
container:
4949
name: xenial
5050
env:
5151
CC: clang
5252
CMAKE_GENERATOR: Ninja
53-
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
53+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec
5454
os: ubuntu-latest
55-
- name: "Linux (Xenial, Clang, mbedTLS)"
55+
- name: "Linux (Xenial, Clang, mbedTLS, libssh2)"
5656
id: xenial-clang-mbedtls
5757
container:
5858
name: xenial
5959
env:
6060
CC: clang
61-
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
61+
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=libssh2
6262
CMAKE_GENERATOR: Ninja
6363
os: ubuntu-latest
6464
- name: "macOS"

CMakeLists.txt

< F438 span class="sr-only">Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ option(USE_THREADS "Use threads for parallel processing when possibl
3030
option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON)
3131

3232
# Backend selection
33-
option(USE_SSH "Link with libssh2 to enable SSH support" OFF)
33+
option(USE_SSH "Enable SSH support. Can be set to a specific backend" OFF)
3434
option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
3535
option(USE_SHA1 "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS" ON)
3636
option(USE_SHA256 "Enable SHA256. Can be set to HTTPS/Builtin" ON)

ci/test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ if [ -z "$SKIP_SSH_TESTS" ]; then
199199
PubkeyAuthentication yes
200200
ChallengeResponseAuthentication no
201201
StrictModes no
202+
HostCertificate ${SSHD_DIR}/id_rsa.pub
203+
HostKey ${SSHD_DIR}/id_rsa
202204
# Required here as sshd will simply close connection otherwise
203205
UsePAM no
204206
EOF
@@ -414,6 +416,8 @@ if [ -z "$SKIP_SSH_TESTS" ]; then
414416
export GITTEST_REMOTE_SSH_PASSPHRASE=""
415417
export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
416418
419+
export GITTEST_SSH_CMD="ssh -i ${HOME}/.ssh/id_rsa -o UserKnownHostsFile=${HOME}/.ssh/known_hosts"
420+
417421
echo ""
418422
echo "Running ssh tests"
419423
echo ""
@@ -430,6 +434,8 @@ if [ -z "$SKIP_SSH_TESTS" ]; then
430434
run_test ssh
431435
unset GITTEST_REMOTE_URL
432436
437+
unset GITTEST_SSH_CMD
438+
433439
unset GITTEST_REMOTE_USER
434440
unset GITTEST_REMOTE_SSH_KEY
435441
unset GITTEST_REMOTE_SSH_PUBKEY
10000

cmake/SelectSSH.cmake

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# Optional external dependency: libssh2
2-
if(USE_SSH)
1+
if(USE_SSH STREQUAL "exec")
2+
set(GIT_SSH 1)
3+
set(GIT_SSH_EXEC 1)
4+
5+
add_feature_info(SSH ON "using OpenSSH exec support")
6+
elseif(USE_SSH STREQUAL ON OR USE_SSH STREQUAL "libssh2")
37
find_pkglibraries(LIBSSH2 libssh2)
8+
49
if(NOT LIBSSH2_FOUND)
510
find_package(LibSSH2)
611
set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
@@ -12,30 +17,28 @@ if(USE_SSH)
1217
if(NOT LIBSSH2_FOUND)
1318
message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
1419
endif()
15-
endif()
1620

17-
if(LIBSSH2_FOUND)
18-
set(GIT_SSH 1)
1921
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
2022
list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES})
2123
list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
2224

2325
check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
2426
if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
25-
set(GIT_SSH_MEMORY_CREDENTIALS 1)
27+
set(GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1)
2628
endif()
27-
else()
28-
message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
29-
endif()
3029

31-
if(WIN32 AND EMBED_SSH_PATH)
32-
file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
33-
list(SORT SSH_SRC)
34-
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
30+
if(WIN32 AND EMBED_SSH_PATH)
31+
file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
32+
list(SORT SSH_SRC)
33+
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
34+
35+
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
36+
file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
37+
endif()
3538

36-
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
37-
file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
3839
set(GIT_SSH 1)
40+
set(GIT_SSH_LIBSSH2 1)
41+
add_feature_info(SSH ON "using libssh2")
42+
else()
43+
add_feature_info(SSH OFF "SSH transport support")
3944
endif()
40-
41-
add_feature_info(SSH GIT_SSH "SSH transport support")

script/valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
exec valgrind --leak-check=full --show-reachable=yes --error-exitcode=125 --num-callers=50 --suppressions="$(dirname "${BASH_SOURCE[0]}")/valgrind.supp" "$@"
2+
exec valgrind --leak-check=full --show-reachable=yes --child-silent-after-fork=yes --error-exitcode=125 --num-callers=50 --suppressions="$(dirname "${BASH_SOURCE[0]}")/valgrind.supp" "$@"

src/libgit2/libgit2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "streams/socket.h"
3535
#include "transports/smart.h"
3636
#include "transports/http.h"
37-
#include "transports/ssh.h"
37+
#include "transports/ssh_libssh2.h"
3838

3939
#ifdef GIT_WIN32
4040
# include "win32/w32_leakcheck.h"
@@ -80,7 +80,7 @@ int git_libgit2_init(void)
8080
git_sysdir_global_init,
8181
git_filter_global_init,
8282
git_merge_driver_global_init,
83-
git_transport_ssh_global_init,
83+
git_transport_ssh_libssh2_global_init,
8484
git_stream_registry_global_init,
8585
git_socket_stream_global_init,
8686
git_openssl_stream_global_init,
@@ -126,10 +126,10 @@ int git_libgit2_features(void)
126126
#ifdef GIT_HTTPS
127127
| GIT_FEATURE_HTTPS
128128
#endif
129-
#if defined(GIT_SSH)
129+
#ifdef GIT_SSH
130130
| GIT_FEATURE_SSH
131131
#endif
132-
#if defined(GIT_USE_NSEC)
132+
#ifdef GIT_USE_NSEC
133133
| GIT_FEATURE_NSEC
134134
#endif
135135
;

src/libgit2/transport.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct transport_definition {
2222

2323
static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1, NULL };
2424
static git_smart_subtransport_definition git_subtransport_definition = { git_smart_subtransport_git, 0, NULL };
25+
2526
#ifdef GIT_SSH
2627
static git_smart_subtransport_definition ssh_subtransport_definition = { git_smart_subtransport_ssh, 0, NULL };
2728
#endif
@@ -33,11 +34,13 @@ static transport_definition transports[] = {
3334
{ "http://", git_transport_smart, &http_subtransport_definition },
3435
{ "https://", git_transport_smart, &http_subtransport_definition },
3536
{ "file://", git_transport_local, NULL },
37+
3638
#ifdef GIT_SSH
3739
{ "ssh://", git_transport_smart, &ssh_subtransport_definition },
3840
{ "ssh+git://", git_transport_smart, &ssh_subtransport_definition },
3941
{ "git+ssh://", git_transport_smart, &ssh_subtransport_definition },
4042
#endif
43+
4144
{ NULL, 0, 0 }
4245
};
4346

src/libgit2/transports/credential.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int git_credential_ssh_key_memory_new(
204204
const char *privatekey,
205205
const char *passphrase)
206206
{
207-
#ifdef GIT_SSH_MEMORY_CREDENTIALS
207+
#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS
208208
return git_credential_ssh_key_type_new(
209209
cred,
210210
username,

src/libgit2/transports/smart.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,27 @@ static int git_smart__close(git_transport *transport)
370370
git_vector *common = &t->common;
371371
unsigned int i;
372372
git_pkt *p;
373+
git_smart_service_t service;
373374
int ret;
374375
git_smart_subtransport_stream *stream;
375376
const char flush[] = "0000";
376377

378+
if (t->direction == GIT_DIRECTION_FETCH) {
379+
service = GIT_SERVICE_UPLOADPACK;
380+
} else if (t->direction == GIT_DIRECTION_PUSH) {
381+
service = GIT_SERVICE_RECEIVEPACK;
382+
} else {
383+
git_error_set(GIT_ERROR_NET, "invalid direction");
384+
return -1;
385+
}
386+
377387
/*
378388
* If we're still connected at this point and not using RPC,
379389
* we should say goodbye by sending a flush, or git-daemon
380390
* will complain that we disconnected unexpectedly.
381391
*/
382392
if (t->connected && !t->rpc &&
383-
!t->wrapped->action(&stream, t->wrapped, t->url, GIT_SERVICE_UPLOADPACK)) {
393+
!t->wrapped->action(&stream, t->wrapped, t->url, service)) {
384394
t->current_stream->write(t->current_stream, flush, 4);
385395
}
386396

@@ -513,7 +523,6 @@ int git_transport_smart(git_transport **out, git_remote *owner, void *param)
513523
definition->callback(&t->wrapped, &t->parent, definition->param) < 0) {
514524
git_vector_free(&t->refs);
515525
git_vector_free(&t->heads);
516-
t->wrapped->free(t->wrapped);
517526
git__free(t);
518527
return -1;
519528
}

src/libgit2/transports/smart_protocol.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int git_smart__store_refs(transport_smart *t, int flushes)
5959
return recvd;
6060

6161
if (recvd == 0) {
62-
git_error_set(GIT_ERROR_NET, "early EOF");
62+
git_error_set(GIT_ERROR_NET, "could not read refs from remote repository");
6363
return GIT_EEOF;
6464
}
6565

@@ -285,7 +285,7 @@ static int recv_pkt(
285285
if ((ret = git_smart__recv(t)) < 0) {
286286
return ret;
287287
} else if (ret == 0) {
288-
git_error_set(GIT_ERROR_NET, "early EOF");
288+
git_error_set(GIT_ERROR_NET, "could not read from remote repository");
289289
return GIT_EEOF;
290290
}
291291
} while (error);
@@ -940,7 +940,7 @@ static int parse_report(transport_smart *transport, git_push *push)
940940
}
941941

942942
if (recvd == 0) {
943-
git_error_set(GIT_ERROR_NET, "early EOF");
943+
git_error_set(GIT_ERROR_NET, "could not read report from remote repository");
944944
error = GIT_EEOF;
945945
goto done;
946946
}

0 commit comments

Comments
 (0)
0