From bb18442fe8f58a483713eb2b988b3da9869ddf86 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 28 Oct 2014 10:33:20 +0100 Subject: options: Fix setting the port. Make sure we correctly read the port from the config file. Signed-off-by: Andreas Schneider --- src/client.c | 2 +- src/config.c | 2 +- src/known_hosts.c | 6 +++--- src/options.c | 9 ++++++--- src/session.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src') 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; -- cgit