diff options
author | Peter Volpe <pvolpe@redhat.com> | 2015-06-26 08:47:47 -0700 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-06-29 09:47:02 +0200 |
commit | 7aeba71a92d5a2dcb606e94f95516b975242586c (patch) | |
tree | 5c04ae950d445506b01cd52b3dbc1b0518190769 | |
parent | e020dd8d5917c3c957b73211cecc618d9f0207cb (diff) | |
download | libssh-7aeba71a92d5a2dcb606e94f95516b975242586c.tar.gz libssh-7aeba71a92d5a2dcb606e94f95516b975242586c.tar.xz libssh-7aeba71a92d5a2dcb606e94f95516b975242586c.zip |
agent: Add ssh_set_agent_socket
Allow callers to specify their own socket
for an ssh agent.
Signed-off-by: Peter Volpe <pvolpe@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | include/libssh/libssh.h | 1 | ||||
-rw-r--r-- | src/agent.c | 23 |
2 files changed, 21 insertions, 3 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 983966da..e52317f9 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -588,6 +588,7 @@ LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socke fd_set *readfds, struct timeval *timeout); LIBSSH_API int ssh_service_request(ssh_session session, const char *service); LIBSSH_API int ssh_set_agent_channel(ssh_session session, ssh_channel channel); +LIBSSH_API int ssh_set_agent_socket(ssh_session session, socket_t fd); LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking); LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter, ssh_counter rcounter); diff --git a/src/agent.c b/src/agent.c index d5257604..922d7530 100644 --- a/src/agent.c +++ b/src/agent.c @@ -185,15 +185,32 @@ int ssh_set_agent_channel(ssh_session session, ssh_channel channel){ return SSH_OK; } +/** @brief sets the SSH agent socket. + * The SSH agent will be used to authenticate this client using + * the given socket to communicate with the ssh-agent. The caller + * is responsible for connecting to the socket prior to calling + * this function. + * @returns SSH_OK in case of success + * SSH_ERROR in case of an error + */ +int ssh_set_agent_socket(ssh_session session, socket_t fd){ + if (!session) + return SSH_ERROR; + if (!session->agent){ + ssh_set_error(session, SSH_REQUEST_DENIED, "Session has no active agent"); + return SSH_ERROR; + } + + ssh_socket_set_fd(session->agent->sock, fd); + return SSH_OK; +} void agent_close(struct ssh_agent_struct *agent) { if (agent == NULL) { return; } - if (getenv("SSH_AUTH_SOCK")) { - ssh_socket_close(agent->sock); - } + ssh_socket_close(agent->sock); } void agent_free(ssh_agent agent) { |