diff options
-rw-r--r-- | src/forward.c | 2 | ||||
-rw-r--r-- | src/forward.h | 3 | ||||
-rw-r--r-- | src/server_ssh.c | 48 | ||||
-rw-r--r-- | src/server_ssh.h | 3 |
4 files changed, 41 insertions, 15 deletions
diff --git a/src/forward.c b/src/forward.c index ebe8d27..54b64fe 100644 --- a/src/forward.c +++ b/src/forward.c @@ -34,7 +34,7 @@ int fwd_setup(forward_ctx *ctx, const char *host, const char *port) } if (!ctx->fwd_cbs.on_listen) return 1; - if (ctx->fwd_cbs.on_listen(ctx)) + if (ctx->fwd_cbs.on_listen(ctx, host, port)) return 1; if (socket_connect_in(&ctx->sock, fwd_addr)) { E_STRERR("Connection to forward socket"); diff --git a/src/forward.h b/src/forward.h index f98d331..4d9c88f 100644 --- a/src/forward.h +++ b/src/forward.h @@ -6,7 +6,8 @@ struct forward_ctx; typedef int (*init_cb) (struct forward_ctx *ctx); -typedef int (*on_listen_cb) (struct forward_ctx *ctx); +typedef int (*on_listen_cb) (struct forward_ctx *ctx, const char *host, + const char *port); typedef int (*on_shutdown_cb) (struct forward_ctx *ctx); typedef struct fwd_callbacks { diff --git a/src/server_ssh.c b/src/server_ssh.c index 7336544..8c57ac6 100644 --- a/src/server_ssh.c +++ b/src/server_ssh.c @@ -1,3 +1,4 @@ +#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <libssh/callbacks.h> @@ -30,26 +31,27 @@ static void ssh_log_cb(int priority, const char *function, const char *buffer, v int ssh_init_cb(struct forward_ctx *ctx) { - N("libssh version: %d.%d.%d", - LIBSSH_VERSION_MAJOR, LIBSSH_VERSION_MINOR, - LIBSSH_VERSION_MICRO); - if (LIBSSH_VERSION_MAJOR != 0 || LIBSSH_VERSION_MINOR < 7 || - LIBSSH_VERSION_MICRO < 90) + N("libssh version: %s", ssh_version(0)); + if (ssh_version(SSH_VERSION_INT(0,7,90)) == NULL) { - W("%s", "libssh versions before 0.7.90 are not supported and may suffer" + W("%s", + "libssh versions before 0.7.90 are not supported and may suffer " "from problems with the pki key generation/export"); } ctx->fwd_cbs = potd_ssh_callbacks; if (ssh_init()) return 1; - ssh_set_log_callback(ssh_log_cb); - ssh_set_log_level(SSH_LOG_FUNCTIONS); + ssh_data *d = (ssh_data *) calloc(1, sizeof(*d)); assert(d); d->sshbind = ssh_bind_new(); d->session = ssh_new(); ctx->data = d; + + ssh_set_log_callback(ssh_log_cb); + ssh_set_log_level(SSH_LOG_FUNCTIONS); + if (!d->sshbind || !d->session) return 1; if (gen_default_keys()) @@ -60,10 +62,18 @@ int ssh_init_cb(struct forward_ctx *ctx) return 0; } -int ssh_on_listen(struct forward_ctx *ctx) +int ssh_on_listen(struct forward_ctx *ctx, const char *host, + const char *port) { ssh_data *d = (ssh_data *) ctx->data; + if (ssh_bind_options_set(d->sshbind, SSH_BIND_OPTIONS_BINDADDR, + host)) + return 1; + if (ssh_bind_options_set(d->sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, + port)) + return 1; + if (ssh_bind_listen(d->sshbind) < 0) { E("Error listening to SSH socket: %s", ssh_get_error(d->sshbind)); } @@ -110,15 +120,18 @@ static int gen_default_keys(void) if (gen_export_sshkey(SSH_KEYTYPE_RSA, 1024, "./ssh_host_rsa_key")) { W("%s", "libssh RSA key generation failed, using fallback ssh-keygen"); - s |= system("ssh-keygen -t rsa -b 1024 -f ./ssh_host_rsa_key"); + remove("./ssh_host_rsa_key"); + s |= system("ssh-keygen -t rsa -b 1024 -f ./ssh_host_rsa_key -N '' >/dev/null 2>/dev/null"); } if (gen_export_sshkey(SSH_KEYTYPE_DSS, 1024, "./ssh_host_dsa_key")) { W("%s", "libssh DSA key generation failed, using fallback ssh-keygen"); - s |= system("ssh-keygen -t dsa -b 1024 -f ./ssh_host_dsa_key"); + remove("./ssh_host_dsa_key"); + s |= system("ssh-keygen -t dsa -b 1024 -f ./ssh_host_dsa_key -N '' >/dev/null 2>/dev/null"); } if (gen_export_sshkey(SSH_KEYTYPE_ECDSA, 1024, "./ssh_host_ecdsa_key")) { W("%s", "libssh ECDSA key generation failed, using fallback ssh-keygen"); - s |= system("ssh-keygen -t ecdsa -b 256 -f ./ssh_host_ecdsa_key"); + remove("./ssh_host_ecdsa_key"); + s |= system("ssh-keygen -t ecdsa -b 256 -f ./ssh_host_ecdsa_key -N '' >/dev/null 2>/dev/null"); } return s != 0; @@ -170,4 +183,15 @@ static int gen_export_sshkey(enum ssh_keytypes_e type, int length, const char *p static void ssh_log_cb(int priority, const char *function, const char *buffer, void *userdata) { + switch (priority) { + case 0: + W("libssh: %s", buffer); + break; + case 1: + N("libssh: %s", buffer); + break; + default: + D("libssh: %s", buffer); + break; + } } diff --git a/src/server_ssh.h b/src/server_ssh.h index e0744f8..f1d6bcd 100644 --- a/src/server_ssh.h +++ b/src/server_ssh.h @@ -8,7 +8,8 @@ int ssh_init_cb(struct forward_ctx *ctx); -int ssh_on_listen(struct forward_ctx *ctx); +int ssh_on_listen(struct forward_ctx *ctx, const char *host, + const char *port); int ssh_on_shutdown(struct forward_ctx *ctx); |