ssh_set_app_data(): attach application specific data to 'struct ssh'

This commit is contained in:
Markus Friedl
2012-03-01 15:13:37 +01:00
parent a9b5c1feef
commit becc57491f
4 changed files with 26 additions and 8 deletions

View File

@@ -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];

View File

@@ -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);

View File

@@ -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)

View File

@@ -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.