diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2014-10-28 10:33:20 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2014-12-25 12:32:16 +0100 |
commit | bb18442fe8f58a483713eb2b988b3da9869ddf86 (patch) | |
tree | 1469c0d6289a313d73907ab95c5985e838c9a23b | |
parent | c2aed4ca78030d9014a890cb4370e6dc8264823f (diff) | |
download | libssh-bb18442fe8f58a483713eb2b988b3da9869ddf86.tar.gz libssh-bb18442fe8f58a483713eb2b988b3da9869ddf86.tar.xz libssh-bb18442fe8f58a483713eb2b988b3da9869ddf86.zip |
options: Fix setting the port.
Make sure we correctly read the port from the config file.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | src/client.c | 2 | ||||
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/known_hosts.c | 6 | ||||
-rw-r--r-- | src/options.c | 9 | ||||
-rw-r--r-- | src/session.c | 2 |
5 files changed, 12 insertions, 9 deletions
diff --git a/src/client.c b/src/client.c index 0a45944c..64ce5dec 100644 --- a/src/client.c +++ b/src/client.c @@ -526,7 +526,7 @@ int ssh_connect(ssh_session session) { } else { ret=ssh_socket_connect(session->socket, session->opts.host, - session->opts.port, + session->opts.port > 0 ? session->opts.port : 22, session->opts.bindaddr); } if (ret == SSH_ERROR) { diff --git a/src/config.c b/src/config.c index 0d869613..0d44c215 100644 --- a/src/config.c +++ b/src/config.c @@ -245,7 +245,7 @@ static int ssh_config_parse_line(ssh_session session, const char *line, } break; case SOC_PORT: - if (session->opts.port == 22) { + if (session->opts.port == 0) { p = ssh_config_get_str_tok(&s, NULL); if (p && *parsing) { ssh_options_set(session, SSH_OPTIONS_PORT_STR, p); diff --git a/src/known_hosts.c b/src/known_hosts.c index 8c05c8de..f7828d5f 100644 --- a/src/known_hosts.c +++ b/src/known_hosts.c @@ -435,7 +435,7 @@ int ssh_is_server_known(ssh_session session) { return SSH_SERVER_ERROR; } host = ssh_lowercase(session->opts.host); - hostport = ssh_hostport(host, session->opts.port); + hostport = ssh_hostport(host, session->opts.port > 0 ? session->opts.port : 22); if (host == NULL || hostport == NULL) { ssh_set_error_oom(session); SAFE_FREE(host); @@ -542,7 +542,7 @@ int ssh_write_knownhost(ssh_session session) { host = ssh_lowercase(session->opts.host); /* If using a nonstandard port, save the host in the [host]:port format */ - if(session->opts.port != 22) { + if (session->opts.port > 0 && session->opts.port != 22) { hostport = ssh_hostport(host, session->opts.port); SAFE_FREE(host); if (hostport == NULL) { @@ -682,7 +682,7 @@ char **ssh_knownhosts_algorithms(ssh_session session) { } host = ssh_lowercase(session->opts.host); - hostport = ssh_hostport(host, session->opts.port); + hostport = ssh_hostport(host, session->opts.port > 0 ? session->opts.port : 22); array = malloc(sizeof(char *) * KNOWNHOSTS_MAXTYPES); if (host == NULL || hostport == NULL || array == NULL) { diff --git a/src/options.c b/src/options.c index bf4e680b..2b8abb48 100644 --- a/src/options.c +++ b/src/options.c @@ -891,11 +891,14 @@ int ssh_options_get_port(ssh_session session, unsigned int* port_target) { if (session == NULL) { return -1; } - if (!session->opts.port) { - ssh_set_error_invalid(session); - return -1; + + if (session->opts.port == 0) { + *port_target = 22; + return 0; } + *port_target = session->opts.port; + return 0; } diff --git a/src/session.c b/src/session.c index 90206d42..63364c51 100644 --- a/src/session.c +++ b/src/session.c @@ -100,7 +100,7 @@ ssh_session ssh_new(void) { /* OPTIONS */ session->opts.StrictHostKeyChecking = 1; - session->opts.port = 22; + session->opts.port = 0; session->opts.fd = -1; session->opts.ssh2 = 1; session->opts.compressionlevel=7; |