From becc57491f31545d23e855158fc526ca1a91915b Mon Sep 17 00:00:00 2001 From: Markus Friedl Date: Thu, 1 Mar 2012 15:13:37 +0100 Subject: [PATCH] ssh_set_app_data(): attach application specific data to 'struct ssh' --- ssh/packet.h | 3 +++ ssh/ssh-keyscan.c | 13 +++++-------- ssh/ssh_api.c | 12 ++++++++++++ ssh/ssh_api.h | 6 ++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ssh/packet.h b/ssh/packet.h index 5c8a816..f68da5f 100644 --- a/ssh/packet.h +++ b/ssh/packet.h @@ -45,6 +45,9 @@ struct ssh { /* Authentication context */ void *authctxt; + /* Application specific data */ + void *app_data; + /* Key exchange */ Kex *kex; Newkeys *current_keys[MODE_MAX]; diff --git a/ssh/ssh-keyscan.c b/ssh/ssh-keyscan.c index 4473170..8688ccd 100644 --- a/ssh/ssh-keyscan.c +++ b/ssh/ssh-keyscan.c @@ -40,6 +40,7 @@ #include "misc.h" #include "hostfile.h" #include "err.h" +#include "ssh_api.h" /* Flag indicating whether IPv4 or IPv6. This can be set on the command line. Default value is AF_UNSPEC means both IPv4 and IPv6. */ @@ -208,13 +209,8 @@ key_print_wrapper(struct sshkey *hostkey, struct ssh *ssh) { con *c; - TAILQ_FOREACH(c, &tq, c_link) { - if (c->c_ssh == ssh) { - keyprint(c, hostkey); - c->c_done = 1; - break; - } - } + if ((c = ssh_get_app_data(ssh)) != NULL) + keyprint(c, hostkey); /* always abort key exchange */ return -1; } @@ -254,7 +250,7 @@ keygrab_ssh2(con *c) c->c_ssh->kex->kex[KEX_DH_GEX_SHA1] = kexgex_client; c->c_ssh->kex->kex[KEX_DH_GEX_SHA256] = kexgex_client; c->c_ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client; - c->c_ssh->kex->verify_host_key = key_print_wrapper; + ssh_set_verify_host_key_callback(c->c_ssh, key_print_wrapper); /* * do the key-exchange until an error occurs or until * the key_print_wrapper() callback sets c_done. @@ -434,6 +430,7 @@ congreet(int s) } *cp = '\0'; c->c_ssh = ssh_packet_set_connection(NULL, s, s); + ssh_set_app_data(c->c_ssh, c); /* back link */ if (sscanf(buf, "SSH-%d.%d-%[^\n]\n", &remote_major, &remote_minor, remote_version) == 3) c->c_ssh->compat = compat_datafellows(remote_version); diff --git a/ssh/ssh_api.c b/ssh/ssh_api.c index 1dd7d3b..cd2f825 100644 --- a/ssh/ssh_api.c +++ b/ssh/ssh_api.c @@ -102,6 +102,18 @@ ssh_free(struct ssh *ssh) free(ssh); } +void +ssh_set_app_data(struct ssh *ssh, void *app_data) +{ + ssh->app_data = app_data; +} + +void * +ssh_get_app_data(struct ssh *ssh) +{ + return ssh->app_data; +} + /* Returns < 0 on error, 0 otherwise */ int ssh_add_hostkey(struct ssh *ssh, struct sshkey *key) diff --git a/ssh/ssh_api.h b/ssh/ssh_api.h index 9e69fe1..7d39c35 100644 --- a/ssh/ssh_api.h +++ b/ssh/ssh_api.h @@ -30,6 +30,12 @@ int ssh_init(struct ssh **, int is_server, struct kex_params *kex_params); */ void ssh_free(struct ssh *); +/* + * attach application specific data to the connection state + */ +void ssh_set_app_data(struct ssh *, void *); +void *ssh_get_app_data(struct ssh *); + /* * ssh_add_hostkey() registers a private/public hostkey for an ssh * connection.