diff options
author | Alan Dunn <amdunn@gmail.com> | 2014-01-21 08:19:30 -0600 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2014-01-21 16:06:53 +0100 |
commit | 086847f99747d1422028d0a4ee5a05d5f07d9423 (patch) | |
tree | 9ab1f2486ac6c0400bba90892cfe3feaddcd58aa /src/bind.c | |
parent | cb9786b3ae7455fc1206157fa27ce25e1a1b227b (diff) | |
download | libssh-086847f99747d1422028d0a4ee5a05d5f07d9423.tar.gz libssh-086847f99747d1422028d0a4ee5a05d5f07d9423.tar.xz libssh-086847f99747d1422028d0a4ee5a05d5f07d9423.zip |
Separate out key import functionality from ssh_bind_listen
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/bind.c')
-rw-r--r-- | src/bind.c | 35 |
1 files changed, 23 insertions, 12 deletions
@@ -144,26 +144,19 @@ ssh_bind ssh_bind_new(void) { return ptr; } -int ssh_bind_listen(ssh_bind sshbind) { - const char *host; - socket_t fd; +static int ssh_bind_import_keys(ssh_bind sshbind) { int rc; - if (ssh_init() < 0) { - ssh_set_error(sshbind, SSH_FATAL, "ssh_init() failed"); - return -1; - } - if (sshbind->ecdsakey == NULL && sshbind->dsakey == NULL && sshbind->rsakey == NULL) { ssh_set_error(sshbind, SSH_FATAL, - "DSA or RSA host key file must be set before listen()"); + "ECDSA, DSA, or RSA host key file must be set"); return SSH_ERROR; } #ifdef HAVE_ECC - if (sshbind->ecdsakey) { + if (sshbind->ecdsa == NULL && sshbind->ecdsakey != NULL) { rc = ssh_pki_import_privkey_file(sshbind->ecdsakey, NULL, NULL, @@ -185,7 +178,7 @@ int ssh_bind_listen(ssh_bind sshbind) { } #endif - if (sshbind->dsakey) { + if (sshbind->dsa == NULL && sshbind->dsakey != NULL) { rc = ssh_pki_import_privkey_file(sshbind->dsakey, NULL, NULL, @@ -207,7 +200,7 @@ int ssh_bind_listen(ssh_bind sshbind) { } } - if (sshbind->rsakey) { + if (sshbind->rsa == NULL && sshbind->rsakey != NULL) { rc = ssh_pki_import_privkey_file(sshbind->rsakey, NULL, NULL, @@ -229,6 +222,24 @@ int ssh_bind_listen(ssh_bind sshbind) { } } + return SSH_OK; +} + +int ssh_bind_listen(ssh_bind sshbind) { + const char *host; + socket_t fd; + int rc; + + if (ssh_init() < 0) { + ssh_set_error(sshbind, SSH_FATAL, "ssh_init() failed"); + return -1; + } + + rc = ssh_bind_import_keys(sshbind); + if (rc != SSH_OK) { + return SSH_ERROR; + } + if (sshbind->bindfd == SSH_INVALID_SOCKET) { host = sshbind->bindaddr; if (host == NULL) { |