From 81e769ec6a75c679694e6b7e6e1288ae63b96991 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Wed, 13 Mar 2013 21:57:45 +0100 Subject: [PATCH] channels: implement callback for agent forwarding request Reviewed-by: Andreas Schneider --- include/libssh/callbacks.h | 14 ++++++++++++++ src/channels.c | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h index f9e1126f..06b8678a 100644 --- a/include/libssh/callbacks.h +++ b/include/libssh/callbacks.h @@ -481,6 +481,16 @@ typedef int (*ssh_channel_pty_request_callback) (ssh_session session, typedef int (*ssh_channel_shell_request_callback) (ssh_session session, ssh_channel channel, void *userdata); +/** + * @brief SSH auth-agent-request from the client. This request is + * sent by a client when agent forwarding is available. + * Server is free to ignore this callback, no answer is expected. + * @param channel the channel + * @param userdata Userdata to be passed to the callback function. + */ +typedef void (*channel_auth_agent_req_callback) (ssh_session session, + ssh_channel channel, + void *userdata); struct ssh_channel_callbacks_struct { /** DON'T SET THIS use ssh_callbacks_init() instead. */ size_t size; @@ -520,6 +530,10 @@ struct ssh_channel_callbacks_struct { * This function will be called when a client requests a shell */ ssh_channel_shell_request_callback channel_shell_request_function; + /** This function will be called when a client requests agent + * authentication forwarding. + */ + channel_auth_agent_req_callback channel_auth_agent_req_function; }; typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks; diff --git a/src/channels.c b/src/channels.c index 47fcee09..dd0f0ff1 100644 --- a/src/channels.c +++ b/src/channels.c @@ -833,6 +833,16 @@ SSH_PACKET_CALLBACK(channel_rcv_request) { return SSH_PACKET_USED; } + if (strcmp(request, "auth-agent-req@openssh.com") == 0) { + SAFE_FREE(request); + ssh_log(session, SSH_LOG_PROTOCOL, "Received an auth-agent-req request"); + if(ssh_callbacks_exists(channel->callbacks, channel_auth_agent_req_function)) { + channel->callbacks->channel_auth_agent_req_function(channel->session, channel, + channel->callbacks->userdata); + } + leave_function(); + return SSH_PACKET_USED; + } /* If we are here, that means we have a request that is not in the understood * client requests. That means we need to create a ssh message to be passed * to the user code handling ssh messages