Commit f26d92a4 by Edward Thomson

ssh: exec with paths for OpenSSH

Handle custom paths for OpenSSH.
parent 3eb7ff2b
...@@ -24,7 +24,31 @@ int git_smart_subtransport_ssh( ...@@ -24,7 +24,31 @@ int git_smart_subtransport_ssh(
GIT_UNUSED(owner); GIT_UNUSED(owner);
GIT_UNUSED(param); GIT_UNUSED(param);
git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support"); git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport; library was built without SSH support");
return -1;
#endif
}
static int transport_set_paths(git_transport *t, git_strarray *paths)
{
transport_smart *smart = (transport_smart *)t;
#ifdef GIT_SSH_LIBSSH2
return git_smart_subtransport_ssh_libssh2_set_paths(
(git_smart_subtransport *)smart->wrapped,
paths->strings[0],
paths->strings[1]);
#elif GIT_SSH_EXEC
return git_smart_subtransport_ssh_exec_set_paths(
(git_smart_subtransport *)smart->wrapped,
paths->strings[0],
paths->strings[1]);
#else
GIT_UNUSED(t);
GIT_UNUSED(smart);
GIT_UNUSED(paths);
GIT_ASSERT(!"cannot create SSH library; library was built without SSH support");
return -1; return -1;
#endif #endif
} }
...@@ -34,16 +58,14 @@ int git_transport_ssh_with_paths( ...@@ -34,16 +58,14 @@ int git_transport_ssh_with_paths(
git_remote *owner, git_remote *owner,
void *payload) void *payload)
{ {
#ifdef GIT_SSH_LIBSSH2
git_strarray *paths = (git_strarray *) payload; git_strarray *paths = (git_strarray *) payload;
git_transport *transport; git_transport *transport;
transport_smart *smart;
int error; int error;
git_smart_subtransport_definition ssh_definition = { git_smart_subtransport_definition ssh_definition = {
git_smart_subtransport_ssh, git_smart_subtransport_ssh,
0, /* no RPC */ 0, /* no RPC */
NULL, NULL
}; };
if (paths->count != 2) { if (paths->count != 2) {
...@@ -54,25 +76,10 @@ int git_transport_ssh_with_paths( ...@@ -54,25 +76,10 @@ int git_transport_ssh_with_paths(
if ((error = git_transport_smart(&transport, owner, &ssh_definition)) < 0) if ((error = git_transport_smart(&transport, owner, &ssh_definition)) < 0)
return error; return error;
smart = (transport_smart *) transport; if ((error = transport_set_paths(transport, paths)) < 0)
if ((error = git_smart_subtransport_ssh_libssh2_set_paths(
(git_smart_subtransport *)smart->wrapped,
paths->strings[0],
paths->strings[1])) < 0)
return error; return error;
*out = transport; *out = transport;
return 0; return 0;
#elif GIT_SSH_EXEC
abort();
#else
GIT_UNUSED(out);
GIT_UNUSED(owner);
GIT_UNUSED(payload);
git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support");
return -1;
#endif
} }
...@@ -28,6 +28,9 @@ typedef struct { ...@@ -28,6 +28,9 @@ typedef struct {
ssh_exec_subtransport_stream *current_stream; ssh_exec_subtransport_stream *current_stream;
char *cmd_uploadpack;
char *cmd_receivepack;
git_smart_service_t action; git_smart_service_t action;
git_process *process; git_process *process;
} ssh_exec_subtransport; } ssh_exec_subtransport;
...@@ -173,10 +176,12 @@ static int start_ssh( ...@@ -173,10 +176,12 @@ static int start_ssh(
switch (action) { switch (action) {
case GIT_SERVICE_UPLOADPACK_LS: case GIT_SERVICE_UPLOADPACK_LS:
command = "git-upload-pack"; command = transport->cmd_uploadpack ?
transport->cmd_uploadpack : "git-upload-pack";
break; break;
case GIT_SERVICE_RECEIVEPACK_LS: case GIT_SERVICE_RECEIVEPACK_LS:
command = "git-receive-pack"; command = transport->cmd_receivepack ?
transport->cmd_receivepack : "git-receive-pack";
break; break;
default: default:
git_error_set(GIT_ERROR_NET, "invalid action"); git_error_set(GIT_ERROR_NET, "invalid action");
...@@ -277,6 +282,8 @@ static void ssh_exec_subtransport_free(git_smart_subtransport *t) ...@@ -277,6 +282,8 @@ static void ssh_exec_subtransport_free(git_smart_subtransport *t)
{ {
ssh_exec_subtransport *transport = (ssh_exec_subtransport *)t; ssh_exec_subtransport *transport = (ssh_exec_subtransport *)t;
git__free(transport->cmd_uploadpack);
git__free(transport->cmd_receivepack);
git__free(transport); git__free(transport);
} }
...@@ -301,4 +308,23 @@ int git_smart_subtransport_ssh_exec( ...@@ -301,4 +308,23 @@ int git_smart_subtransport_ssh_exec(
return 0; return 0;
} }
int git_smart_subtransport_ssh_exec_set_paths(
git_smart_subtransport *subtransport,
const char *cmd_uploadpack,
const char *cmd_receivepack)
{
ssh_exec_subtransport *t = (ssh_exec_subtransport *)subtransport;
git__free(t->cmd_uploadpack);
git__free(t->cmd_receivepack);
t->cmd_uploadpack = git__strdup(cmd_uploadpack);
GIT_ERROR_CHECK_ALLOC(t->cmd_uploadpack);
t->cmd_receivepack = git__strdup(cmd_receivepack);
GIT_ERROR_CHECK_ALLOC(t->cmd_receivepack);
return 0;
}
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment