aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2014-10-28 10:33:20 +0100
committerAndreas Schneider <asn@cryptomilk.org>2014-12-25 12:35:21 +0100
commita45dd8e00037125d0789fe6d4a8ab1557a02e5ac (patch)
tree8ad02cced31368d61e0d1bffe3c3d74418f75f88
parent319129399d3191e9ddd04bef05d2c707ecaa9455 (diff)
downloadlibssh-a45dd8e00037125d0789fe6d4a8ab1557a02e5ac.tar.gz
libssh-a45dd8e00037125d0789fe6d4a8ab1557a02e5ac.tar.xz
libssh-a45dd8e00037125d0789fe6d4a8ab1557a02e5ac.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> (cherry picked from commit bb18442fe8f58a483713eb2b988b3da9869ddf86)
-rw-r--r--src/client.c2
-rw-r--r--src/config.c2
-rw-r--r--src/known_hosts.c6
-rw-r--r--src/options.c9
-rw-r--r--src/session.c2
5 files changed, 12 insertions, 9 deletions
diff --git a/src/client.c b/src/client.c
index ca6cf059..40e31014 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 f21a71a1..6a7f1eeb 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 e80697d8..cd999fda 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 3b702ef5..8d170206 100644
--- a/src/options.c
+++ b/src/options.c
@@ -871,11 +871,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 91b36b7f..87a9f1ae 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;