mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
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 bb18442fe8
)
This commit is contained in:
@@ -526,7 +526,7 @@ int ssh_connect(ssh_session session) {
|
|||||||
} else {
|
} else {
|
||||||
ret=ssh_socket_connect(session->socket,
|
ret=ssh_socket_connect(session->socket,
|
||||||
session->opts.host,
|
session->opts.host,
|
||||||
session->opts.port,
|
session->opts.port > 0 ? session->opts.port : 22,
|
||||||
session->opts.bindaddr);
|
session->opts.bindaddr);
|
||||||
}
|
}
|
||||||
if (ret == SSH_ERROR) {
|
if (ret == SSH_ERROR) {
|
||||||
|
@@ -245,7 +245,7 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOC_PORT:
|
case SOC_PORT:
|
||||||
if (session->opts.port == 22) {
|
if (session->opts.port == 0) {
|
||||||
p = ssh_config_get_str_tok(&s, NULL);
|
p = ssh_config_get_str_tok(&s, NULL);
|
||||||
if (p && *parsing) {
|
if (p && *parsing) {
|
||||||
ssh_options_set(session, SSH_OPTIONS_PORT_STR, p);
|
ssh_options_set(session, SSH_OPTIONS_PORT_STR, p);
|
||||||
|
@@ -435,7 +435,7 @@ int ssh_is_server_known(ssh_session session) {
|
|||||||
return SSH_SERVER_ERROR;
|
return SSH_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
host = ssh_lowercase(session->opts.host);
|
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) {
|
if (host == NULL || hostport == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
SAFE_FREE(host);
|
SAFE_FREE(host);
|
||||||
@@ -542,7 +542,7 @@ int ssh_write_knownhost(ssh_session session) {
|
|||||||
|
|
||||||
host = ssh_lowercase(session->opts.host);
|
host = ssh_lowercase(session->opts.host);
|
||||||
/* If using a nonstandard port, save the host in the [host]:port format */
|
/* 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);
|
hostport = ssh_hostport(host, session->opts.port);
|
||||||
SAFE_FREE(host);
|
SAFE_FREE(host);
|
||||||
if (hostport == NULL) {
|
if (hostport == NULL) {
|
||||||
@@ -682,7 +682,7 @@ char **ssh_knownhosts_algorithms(ssh_session session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
host = ssh_lowercase(session->opts.host);
|
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);
|
array = malloc(sizeof(char *) * KNOWNHOSTS_MAXTYPES);
|
||||||
|
|
||||||
if (host == NULL || hostport == NULL || array == NULL) {
|
if (host == NULL || hostport == NULL || array == NULL) {
|
||||||
|
@@ -871,11 +871,14 @@ int ssh_options_get_port(ssh_session session, unsigned int* port_target) {
|
|||||||
if (session == NULL) {
|
if (session == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!session->opts.port) {
|
|
||||||
ssh_set_error_invalid(session);
|
if (session->opts.port == 0) {
|
||||||
return -1;
|
*port_target = 22;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*port_target = session->opts.port;
|
*port_target = session->opts.port;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -100,7 +100,7 @@ ssh_session ssh_new(void) {
|
|||||||
|
|
||||||
/* OPTIONS */
|
/* OPTIONS */
|
||||||
session->opts.StrictHostKeyChecking = 1;
|
session->opts.StrictHostKeyChecking = 1;
|
||||||
session->opts.port = 22;
|
session->opts.port = 0;
|
||||||
session->opts.fd = -1;
|
session->opts.fd = -1;
|
||||||
session->opts.ssh2 = 1;
|
session->opts.ssh2 = 1;
|
||||||
session->opts.compressionlevel=7;
|
session->opts.compressionlevel=7;
|
||||||
|
Reference in New Issue
Block a user