aboutsummaryrefslogtreecommitdiff
path: root/libssh/server.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-29 16:59:15 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-29 16:59:15 +0000
commitfa63c0adee01954b8a492dda1eb16eb3a986ae2a (patch)
treef966078ead2ec3a4ec0da86bb414fdda9d4c0a73 /libssh/server.c
parent78ad279a43a27a4a780ebefde3a4bfbde0091535 (diff)
downloadlibssh-fa63c0adee01954b8a492dda1eb16eb3a986ae2a.tar.gz
libssh-fa63c0adee01954b8a492dda1eb16eb3a986ae2a.tar.xz
libssh-fa63c0adee01954b8a492dda1eb16eb3a986ae2a.zip
Improve server_set_kex().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@654 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/server.c')
-rw-r--r--libssh/server.c86
1 files changed, 47 insertions, 39 deletions
diff --git a/libssh/server.c b/libssh/server.c
index 349e910..f2a2f27 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -269,49 +269,57 @@ void ssh_bind_free(SSH_BIND *ssh_bind){
extern char *supported_methods[];
static int server_set_kex(SSH_SESSION * session) {
- KEX *server = &session->server_kex;
- SSH_OPTIONS *options = session->options;
- int i, j;
- char *wanted;
- memset(server,0,sizeof(KEX));
- // the program might ask for a specific cookie to be sent. useful for server
- // debugging
- if (options->wanted_cookie)
- memcpy(server->cookie, options->wanted_cookie, 16);
- else
- ssh_get_random(server->cookie, 16,0);
- if (session->dsa_key && session->rsa_key) {
- if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-dss,ssh-rsa") < 0) {
- return -1;
- }
- } else {
- if (session->dsa_key) {
- if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-dss") < 0) {
- return -1;
- }
- } else {
- if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-rsa") < 0) {
- return -1;
- }
- }
+ KEX *server = &session->server_kex;
+ SSH_OPTIONS *options = session->options;
+ int i, j;
+ char *wanted;
+
+ ZERO_STRUCTP(server);
+ /*
+ * The program might ask for a specific cookie to be sent. Useful for server
+ * debugging
+ */
+ if (options->wanted_cookie) {
+ memcpy(server->cookie, options->wanted_cookie, 16);
+ } else {
+ ssh_get_random(server->cookie, 16, 0);
+ }
+
+ if (session->dsa_key != NULL && session->rsa_key != NULL) {
+ if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS,
+ "ssh-dss,ssh-rsa") < 0) {
+ return -1;
}
- server->methods = malloc(10 * sizeof(char **));
- if (server->methods == NULL) {
+ } else if (session->dsa_key != NULL) {
+ if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-dss") < 0) {
return -1;
}
- for (i = 0; i < 10; i++) {
- if (!(wanted = options->wanted_methods[i]))
- wanted = supported_methods[i];
- server->methods[i] = strdup(wanted);
- if (server->methods[i] == NULL) {
- for (j = i - 1; j <= 0; j--) {
- SAFE_FREE(server->methods[j]);
- }
- SAFE_FREE(server->methods);
- return -1;
- }
+ } else {
+ if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-rsa") < 0) {
+ return -1;
}
- return 0;
+ }
+
+ server->methods = malloc(10 * sizeof(char **));
+ if (server->methods == NULL) {
+ return -1;
+ }
+
+ for (i = 0; i < 10; i++) {
+ if ((wanted = options->wanted_methods[i]) == NULL) {
+ wanted = supported_methods[i];
+ }
+ server->methods[i] = strdup(wanted);
+ if (server->methods[i] == NULL) {
+ for (j = i - 1; j <= 0; j--) {
+ SAFE_FREE(server->methods[j]);
+ }
+ SAFE_FREE(server->methods);
+ return -1;
+ }
+ }
+
+ return 0;
}
static int dh_handshake_server(SSH_SESSION *session){