#include #include #include #include #include "server_ssh.h" #include "log.h" typedef struct ssh_data { ssh_bind sshbind; ssh_session session; } ssh_data; struct fwd_callbacks potd_ssh_callbacks = { .on_listen = ssh_on_listen, .on_shutdown = ssh_on_shutdown }; static int set_default_keys(ssh_bind sshbind, int rsa_already_set, int dsa_already_set, int ecdsa_already_set); int ssh_init_cb(struct forward_ctx *ctx) { ctx->fwd_cbs = potd_ssh_callbacks; if (ssh_init()) return 1; ssh_data *d = (ssh_data *) calloc(1, sizeof(*d)); assert(d); d->sshbind = ssh_bind_new(); d->session = ssh_new(); ctx->data = d; if (!d->sshbind || !d->session) return 1; if (set_default_keys(d->sshbind, 0, 0, 0)) return 1; return 0; } int ssh_on_listen(struct forward_ctx *ctx) { ssh_data *d = (ssh_data *) ctx->data; if (ssh_bind_listen(d->sshbind) < 0) { E("Error listening to SSH socket: %s", ssh_get_error(d->sshbind)); } return 0; } int ssh_on_shutdown(struct forward_ctx *ctx) { return 0; } static int set_default_keys(ssh_bind sshbind, int rsa_already_set, int dsa_already_set, int ecdsa_already_set) { if (!rsa_already_set) { if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, "./ssh_host_rsa_key")) return 1; } if (!dsa_already_set) { if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, "./ssh_host_dsa_key")) return 1; } if (!ecdsa_already_set) { if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY, "./ssh_host_ecdsa_key")) return 1; } return 0; }