mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 08:53:48 +00:00
Add a wrapper to provide the libssh2 error message
This commit is contained in:
parent
8821c9aa5b
commit
b622aabec0
@ -67,6 +67,7 @@ typedef enum {
|
|||||||
GITERR_CHECKOUT,
|
GITERR_CHECKOUT,
|
||||||
GITERR_FETCHHEAD,
|
GITERR_FETCHHEAD,
|
||||||
GITERR_MERGE,
|
GITERR_MERGE,
|
||||||
|
GITERR_SSH,
|
||||||
} git_error_t;
|
} git_error_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,6 +37,14 @@ typedef struct {
|
|||||||
git_cred *cred;
|
git_cred *cred;
|
||||||
} ssh_subtransport;
|
} ssh_subtransport;
|
||||||
|
|
||||||
|
static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg)
|
||||||
|
{
|
||||||
|
char *ssherr;
|
||||||
|
libssh2_session_last_error(session, &ssherr, NULL, 0);
|
||||||
|
|
||||||
|
giterr_set(GITERR_SSH, "%s: %s", errmsg, ssherr);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a git protocol request.
|
* Create a git protocol request.
|
||||||
*
|
*
|
||||||
@ -81,8 +89,8 @@ static int send_command(ssh_stream *s)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
error = libssh2_channel_exec(s->channel, request.ptr);
|
error = libssh2_channel_exec(s->channel, request.ptr);
|
||||||
if (error < 0) {
|
if (error < LIBSSH2_ERROR_NONE) {
|
||||||
giterr_set(GITERR_NET, "SSH could not execute request");
|
ssh_error(s->session, "SSH could not execute request");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +115,8 @@ static int ssh_stream_read(
|
|||||||
if (!s->sent_command && send_command(s) < 0)
|
if (!s->sent_command && send_command(s) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((rc = libssh2_channel_read(s->channel, buffer, buf_size)) < 0) {
|
if ((rc = libssh2_channel_read(s->channel, buffer, buf_size)) < LIBSSH2_ERROR_NONE) {
|
||||||
giterr_set(GITERR_NET, "SSH could not read data");
|
ssh_error(s->session, "SSH could not read data");;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +135,8 @@ static int ssh_stream_write(
|
|||||||
if (!s->sent_command && send_command(s) < 0)
|
if (!s->sent_command && send_command(s) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (libssh2_channel_write(s->channel, buffer, len) < 0) {
|
if (libssh2_channel_write(s->channel, buffer, len) < LIBSSH2_ERROR_NONE) {
|
||||||
giterr_set(GITERR_NET, "SSH could not write data");
|
ssh_error(s->session, "SSH could not write data");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,8 +270,8 @@ static int _git_ssh_authenticate_session(
|
|||||||
}
|
}
|
||||||
} while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
|
} while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != LIBSSH2_ERROR_NONE) {
|
||||||
giterr_set(GITERR_NET, "Failed to authenticate SSH session");
|
ssh_error(session, "Failed to authenticate SSH session");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,9 +297,9 @@ static int _git_ssh_session_create(
|
|||||||
rc = libssh2_session_startup(s, socket.socket);
|
rc = libssh2_session_startup(s, socket.socket);
|
||||||
} while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
|
} while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
|
||||||
|
|
||||||
if (0 != rc) {
|
if (rc != LIBSSH2_ERROR_NONE) {
|
||||||
|
ssh_error(s, "Failed to start SSH session");
|
||||||
libssh2_session_free(s);
|
libssh2_session_free(s);
|
||||||
giterr_set(GITERR_NET, "Failed to start SSH session");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,11 +354,11 @@ static int _git_ssh_setup_conn(
|
|||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
if (!t->cred) {
|
if (!t->cred) {
|
||||||
giterr_set(GITERR_NET, "Callback failed to initialize SSH credentials");
|
giterr_set(GITERR_SSH, "Callback failed to initialize SSH credentials");
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
giterr_set(GITERR_NET, "Cannot set up SSH connection without credentials");
|
giterr_set(GITERR_SSH, "Cannot set up SSH connection without credentials");
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
assert(t->cred);
|
assert(t->cred);
|
||||||
@ -368,7 +376,7 @@ static int _git_ssh_setup_conn(
|
|||||||
|
|
||||||
channel = libssh2_channel_open_session(session);
|
channel = libssh2_channel_open_session(session);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
giterr_set(GITERR_NET, "Failed to open SSH channel");
|
ssh_error(session, "Failed to open SSH channel");
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user