ssh: propagate the error code from the auth callback We need to be able to get a GIT_EUSER back through the outermost call.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 8ee080b..43440bc 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -389,7 +389,7 @@ static int _git_ssh_setup_conn(
{
char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL;
const char *default_port="22";
- int no_callback = 0, auth_methods;
+ int no_callback = 0, auth_methods, error = 0;
ssh_stream *s;
LIBSSH2_SESSION* session=NULL;
LIBSSH2_CHANNEL* channel=NULL;
@@ -401,10 +401,10 @@ static int _git_ssh_setup_conn(
s = (ssh_stream *)*stream;
if (!git__prefixcmp(url, prefix_ssh)) {
- if (gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port) < 0)
+ if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port)) < 0)
goto on_error;
} else {
- if (git_ssh_extract_url_parts(&host, &user, url) < 0)
+ if ((error = git_ssh_extract_url_parts(&host, &user, url)) < 0)
goto on_error;
port = git__strdup(default_port);
GITERR_CHECK_ALLOC(port);
@@ -416,16 +416,15 @@ static int _git_ssh_setup_conn(
GIT_CREDTYPE_SSH_INTERACTIVE;
}
- if (gitno_connect(&s->socket, host, port, 0) < 0)
+ if ((error = gitno_connect(&s->socket, host, port, 0)) < 0)
goto on_error;
if (user && pass) {
- if (git_cred_userpass_plaintext_new(&t->cred, user, pass) < 0)
+ if ((error = git_cred_userpass_plaintext_new(&t->cred, user, pass)) < 0)
goto on_error;
} else if (!t->owner->cred_acquire_cb) {
no_callback = 1;
} else {
- int error;
error = t->owner->cred_acquire_cb(&t->cred, t->owner->url, user, auth_methods,
t->owner->cred_acquire_payload);
@@ -435,25 +434,28 @@ static int _git_ssh_setup_conn(
goto on_error;
else if (!t->cred) {
giterr_set(GITERR_SSH, "Callback failed to initialize SSH credentials");
+ error = -1;
goto on_error;
}
}
if (no_callback) {
giterr_set(GITERR_SSH, "authentication required but no callback set");
+ error = -1;
goto on_error;
}
assert(t->cred);
- if (_git_ssh_session_create(&session, s->socket) < 0)
+ if ((error = _git_ssh_session_create(&session, s->socket)) < 0)
goto on_error;
- if (_git_ssh_authenticate_session(session, t->cred) < 0)
+ if ((error = _git_ssh_authenticate_session(session, t->cred)) < 0)
goto on_error;
channel = libssh2_channel_open_session(session);
if (!channel) {
+ error = -1;
ssh_error(session, "Failed to open SSH channel");
goto on_error;
}
@@ -488,7 +490,7 @@ on_error:
if (session)
libssh2_session_free(session);
- return -1;
+ return error;
}
static int ssh_uploadpack_ls(
@@ -496,10 +498,7 @@ static int ssh_uploadpack_ls(
const char *url,
git_smart_subtransport_stream **stream)
{
- if (_git_ssh_setup_conn(t, url, cmd_uploadpack, stream) < 0)
- return -1;
-
- return 0;
+ return _git_ssh_setup_conn(t, url, cmd_uploadpack, stream);
}
static int ssh_uploadpack(
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 8660d31..37112dc 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -243,8 +243,7 @@ void test_online_clone__cred_callback_failure_return_code_is_tunnelled(void)
g_options.remote_callbacks.credentials = cred_failure_cb;
- /* TODO: this should expect -172. */
- cl_git_fail_with(git_clone(&g_repo, remote_url, "./foo", &g_options), -1);
+ cl_git_fail_with(-172, git_clone(&g_repo, remote_url, "./foo", &g_options));
}
void test_online_clone__credentials(void)