aboutsummaryrefslogtreecommitdiff
path: root/src/server_ssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server_ssh.c')
-rw-r--r--src/server_ssh.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/server_ssh.c b/src/server_ssh.c
index 1c72b61..9f24657 100644
--- a/src/server_ssh.c
+++ b/src/server_ssh.c
@@ -1,36 +1,47 @@
#include <stdlib.h>
+#include <assert.h>
#include <libssh/callbacks.h>
#include <libssh/server.h>
#include "server_ssh.h"
#include "server.h"
+#include "log.h"
struct server_callbacks potd_ssh_callbacks = {
.on_listen = ssh_on_listen,
.on_shutdown = ssh_on_shutdown
};
-static void set_default_keys(ssh_bind sshbind, int rsa_already_set,
- int dsa_already_set, int ecdsa_already_set);
+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 server_ctx *ctx)
{
ctx->server_cbs = potd_ssh_callbacks;
- ssh_init();
+ 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->server_dat.data = d;
- if (!d->sshbind)
+ if (!d->sshbind || !d->session)
+ return 1;
+ if (set_default_keys(d->sshbind, 0, 0, 0))
return 1;
- set_default_keys(d->sshbind, 0, 0, 0);
return 0;
}
int ssh_on_listen(struct server_data *data)
{
+ ssh_data *d = (ssh_data *) data->data;
+
+ if (ssh_bind_listen(d->sshbind) < 0) {
+ E("Error listening to SSH socket: %s", ssh_get_error(d->sshbind));
+ }
return 0;
}
@@ -39,19 +50,23 @@ int ssh_on_shutdown(struct server_data *data)
return 0;
}
-static void set_default_keys(ssh_bind sshbind, int rsa_already_set,
+static int set_default_keys(ssh_bind sshbind, int rsa_already_set,
int dsa_already_set, int ecdsa_already_set)
{
if (!rsa_already_set) {
- ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
- "./ssh_host_rsa_key");
+ if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
+ "./ssh_host_rsa_key"))
+ return 1;
}
if (!dsa_already_set) {
- ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY,
- "./ssh_host_dsa_key");
+ if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY,
+ "./ssh_host_dsa_key"))
+ return 1;
}
if (!ecdsa_already_set) {
- ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY,
- "./ssh_host_ecdsa_key");
+ if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY,
+ "./ssh_host_ecdsa_key"))
+ return 1;
}
+ return 0;
}