Agent forwarding works

--HG--
branch : agent-client
extra : convert_revision : eb0dae4b62e243ba37a897beb7ba81a4f637d8b3
This commit is contained in:
Matt Johnston 2009-07-30 15:14:33 +00:00
parent bacd2a8c79
commit bb8234c2f1
11 changed files with 49 additions and 24 deletions

View File

@ -35,14 +35,16 @@
* 10000 is arbitrary */ * 10000 is arbitrary */
#define MAX_AGENT_REPLY 10000 #define MAX_AGENT_REPLY 10000
int agentreq(struct ChanSess * chansess); int svr_agentreq(struct ChanSess * chansess);
void agentcleanup(struct ChanSess * chansess); void svr_agentcleanup(struct ChanSess * chansess);
void agentset(struct ChanSess *chansess); void svr_agentset(struct ChanSess *chansess);
/* client functions */ /* client functions */
void load_agent_keys(m_list * ret_list); void cli_load_agent_keys(m_list * ret_list);
void agent_buf_sign(buffer *sigblob, sign_key *key, void agent_buf_sign(buffer *sigblob, sign_key *key,
const unsigned char *data, unsigned int len); const unsigned char *data, unsigned int len);
void cli_setup_agent(struct Channel *channel);
#ifdef __hpux #ifdef __hpux
#define seteuid(a) setresuid(-1, (a), -1) #define seteuid(a) setresuid(-1, (a), -1)

View File

@ -81,6 +81,7 @@ void cli_chansess_winchange();
#ifdef ENABLE_CLI_NETCAT #ifdef ENABLE_CLI_NETCAT
void cli_send_netcat_request(); void cli_send_netcat_request();
#endif #endif
void cli_start_send_channel_request(struct Channel *channel, unsigned char *type);
void svr_chansessinitialise(); void svr_chansessinitialise();
extern const struct ChanType svrchansess; extern const struct ChanType svrchansess;

View File

@ -226,10 +226,20 @@ out:
} }
} }
void cli_setup_agent(struct Channel *channel) {
if (!getenv("SSH_AUTH_SOCK")) {
return;
}
cli_start_send_channel_request(channel, "auth-agent-req@openssh.com");
/* Don't want replies */
buf_putbyte(ses.writepayload, 0);
encrypt_packet();
}
/* Returned keys are prepended to ret_list, which will /* Returned keys are prepended to ret_list, which will
be updated. */ be updated. */
void load_agent_keys(m_list *ret_list) void cli_load_agent_keys(m_list *ret_list) {
{
/* agent_fd will be closed after successful auth */ /* agent_fd will be closed after successful auth */
cli_opts.agent_fd = connect_agent(); cli_opts.agent_fd = connect_agent();
if (cli_opts.agent_fd < 0) { if (cli_opts.agent_fd < 0) {

View File

@ -187,10 +187,9 @@ int cli_auth_pubkey() {
TRACE(("enter cli_auth_pubkey")) TRACE(("enter cli_auth_pubkey"))
if (cli_opts.agent_fwd && if (!cli_opts.agent_keys_loaded) {
!cli_opts.agent_keys_loaded) {
/* get the list of available keys from the agent */ /* get the list of available keys from the agent */
load_agent_keys(cli_opts.privkeys); cli_load_agent_keys(cli_opts.privkeys);
cli_opts.agent_keys_loaded = 1; cli_opts.agent_keys_loaded = 1;
} }

View File

@ -33,13 +33,12 @@
#include "runopts.h" #include "runopts.h"
#include "termcodes.h" #include "termcodes.h"
#include "chansession.h" #include "chansession.h"
#include "agentfwd.h"
static void cli_closechansess(struct Channel *channel); static void cli_closechansess(struct Channel *channel);
static int cli_initchansess(struct Channel *channel); static int cli_initchansess(struct Channel *channel);
static void cli_chansessreq(struct Channel *channel); static void cli_chansessreq(struct Channel *channel);
static void start_channel_request(struct Channel *channel, unsigned char *type);
static void send_chansess_pty_req(struct Channel *channel); static void send_chansess_pty_req(struct Channel *channel);
static void send_chansess_shell_req(struct Channel *channel); static void send_chansess_shell_req(struct Channel *channel);
@ -92,7 +91,7 @@ static void cli_closechansess(struct Channel *UNUSED(channel)) {
} }
static void start_channel_request(struct Channel *channel, void cli_start_send_channel_request(struct Channel *channel,
unsigned char *type) { unsigned char *type) {
CHECKCLEARTOWRITE(); CHECKCLEARTOWRITE();
@ -287,7 +286,7 @@ static void send_chansess_pty_req(struct Channel *channel) {
TRACE(("enter send_chansess_pty_req")) TRACE(("enter send_chansess_pty_req"))
start_channel_request(channel, "pty-req"); cli_start_send_channel_request(channel, "pty-req");
/* Don't want replies */ /* Don't want replies */
buf_putbyte(ses.writepayload, 0); buf_putbyte(ses.writepayload, 0);
@ -330,7 +329,7 @@ static void send_chansess_shell_req(struct Channel *channel) {
reqtype = "shell"; reqtype = "shell";
} }
start_channel_request(channel, reqtype); cli_start_send_channel_request(channel, reqtype);
/* XXX TODO */ /* XXX TODO */
buf_putbyte(ses.writepayload, 0); /* Don't want replies */ buf_putbyte(ses.writepayload, 0); /* Don't want replies */
@ -361,6 +360,12 @@ static int cli_initchansess(struct Channel *channel) {
cli_init_stdpipe_sess(channel); cli_init_stdpipe_sess(channel);
#ifdef ENABLE_CLI_AGENTFWD
if (cli_opts.agent_fwd) {
cli_setup_agent(channel);
}
#endif
if (cli_opts.wantpty) { if (cli_opts.wantpty) {
send_chansess_pty_req(channel); send_chansess_pty_req(channel);
} }

View File

@ -235,7 +235,7 @@ static void cli_sessionloop() {
cli_send_netcat_request(); cli_send_netcat_request();
} else } else
#endif #endif
if (!cli_opts.no_cmd) { if (!cli_opts.no_cmd) {
cli_send_chansess_request(); cli_send_chansess_request();
} }
TRACE(("leave cli_sessionloop: running")) TRACE(("leave cli_sessionloop: running"))

View File

@ -82,6 +82,11 @@ by the ssh server.
Always accept hostkeys if they are unknown. If a hostkey mismatch occurs the Always accept hostkeys if they are unknown. If a hostkey mismatch occurs the
connection will abort as normal. connection will abort as normal.
.TP .TP
.B \-A
Forward agent connections to the remote host. dbclient will use any
OpenSSH-style agent program if available ($SSH_AUTH_SOCK will be set) for
public key authentication. Forwarding is only enabled if -A is specified.
.TP
.B \-W \fIwindowsize .B \-W \fIwindowsize
Specify the per-channel receive window buffer size. Increasing this Specify the per-channel receive window buffer size. Increasing this
may improve network performance at the expense of memory use. Use -h to see the may improve network performance at the expense of memory use. Use -h to see the

View File

@ -39,7 +39,7 @@
* Caution: Don't use this in an unfriendly environment (ie unfirewalled), * Caution: Don't use this in an unfriendly environment (ie unfirewalled),
* since the printing may not sanitise strings etc. This will add a reasonable * since the printing may not sanitise strings etc. This will add a reasonable
* amount to your executable size. */ * amount to your executable size. */
#define DEBUG_TRACE /*#define DEBUG_TRACE*/
/* All functions writing to the cleartext payload buffer call /* All functions writing to the cleartext payload buffer call
* CHECKCLEARTOWRITE() before writing. This is only really useful if you're * CHECKCLEARTOWRITE() before writing. This is only really useful if you're

View File

@ -84,7 +84,6 @@ int signkey_type_from_name(const char* name, int namelen) {
#endif #endif
TRACE(("signkey_type_from_name unexpected key type.")) TRACE(("signkey_type_from_name unexpected key type."))
printhex("Key type", name, namelen);
return DROPBEAR_SIGNKEY_NONE; return DROPBEAR_SIGNKEY_NONE;
} }

View File

@ -49,10 +49,12 @@ static void agentaccept(struct Listener * listener, int sock);
/* Handles client requests to start agent forwarding, sets up listening socket. /* Handles client requests to start agent forwarding, sets up listening socket.
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
int agentreq(struct ChanSess * chansess) { int svr_agentreq(struct ChanSess * chansess) {
int fd; int fd;
TRACE(("enter svr_agentreq"))
if (!svr_pubkey_allows_agentfwd()) { if (!svr_pubkey_allows_agentfwd()) {
return DROPBEAR_FAILURE; return DROPBEAR_FAILURE;
} }
@ -89,10 +91,12 @@ int agentreq(struct ChanSess * chansess) {
} }
return DROPBEAR_SUCCESS; return DROPBEAR_SUCCESS;
TRACE(("success"))
fail: fail:
TRACE(("fail"))
/* cleanup */ /* cleanup */
agentcleanup(chansess); svr_agentcleanup(chansess);
return DROPBEAR_FAILURE; return DROPBEAR_FAILURE;
} }
@ -118,7 +122,7 @@ static void agentaccept(struct Listener *UNUSED(listener), int sock) {
/* set up the environment variable pointing to the socket. This is called /* set up the environment variable pointing to the socket. This is called
* just before command/shell execution, after dropping priveleges */ * just before command/shell execution, after dropping priveleges */
void agentset(struct ChanSess * chansess) { void svr_agentset(struct ChanSess * chansess) {
char *path = NULL; char *path = NULL;
int len; int len;
@ -137,7 +141,7 @@ void agentset(struct ChanSess * chansess) {
} }
/* close the socket, remove the socket-file */ /* close the socket, remove the socket-file */
void agentcleanup(struct ChanSess * chansess) { void svr_agentcleanup(struct ChanSess * chansess) {
char *path = NULL; char *path = NULL;
uid_t uid; uid_t uid;

View File

@ -287,7 +287,7 @@ static void closechansess(struct Channel *channel) {
#endif #endif
#ifndef DISABLE_AGENTFWD #ifndef DISABLE_AGENTFWD
agentcleanup(chansess); svr_agentcleanup(chansess);
#endif #endif
/* clear child pid entries */ /* clear child pid entries */
@ -346,7 +346,7 @@ static void chansessionrequest(struct Channel *channel) {
#endif #endif
#ifndef DISABLE_AGENTFWD #ifndef DISABLE_AGENTFWD
} else if (strcmp(type, "auth-agent-req@openssh.com") == 0) { } else if (strcmp(type, "auth-agent-req@openssh.com") == 0) {
ret = agentreq(chansess); ret = svr_agentreq(chansess);
#endif #endif
} else if (strcmp(type, "signal") == 0) { } else if (strcmp(type, "signal") == 0) {
ret = sessionsignal(chansess); ret = sessionsignal(chansess);
@ -894,7 +894,7 @@ static void execchild(void *user_data) {
#endif #endif
#ifndef DISABLE_AGENTFWD #ifndef DISABLE_AGENTFWD
/* set up agent env variable */ /* set up agent env variable */
agentset(chansess); svr_agentset(chansess);
#endif #endif
usershell = m_strdup(get_user_shell()); usershell = m_strdup(get_user_shell());