mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-12 11:10:28 +09:00
Fix percent expand character %d to home directory
Fixes: #349 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Pavol Žáčik <pzacik@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
13
src/misc.c
13
src/misc.c
@@ -1236,7 +1236,7 @@ char *ssh_path_expand_tilde(const char *d)
|
||||
/** @internal
|
||||
* @brief expands a string in function of session options
|
||||
* @param[in] s Format string to expand. Known parameters:
|
||||
* %d SSH configuration directory (~/.ssh)
|
||||
* %d user home directory (~)
|
||||
* %h target host name
|
||||
* %u local username
|
||||
* %l local hostname
|
||||
@@ -1301,10 +1301,9 @@ char *ssh_path_expand_escape(ssh_session session, const char *s)
|
||||
case '%':
|
||||
goto escape;
|
||||
case 'd':
|
||||
if (session->opts.sshdir) {
|
||||
x = strdup(session->opts.sshdir);
|
||||
} else {
|
||||
ssh_set_error(session, SSH_FATAL, "Cannot expand sshdir");
|
||||
x = ssh_get_user_home_dir(session);
|
||||
if (x == NULL) {
|
||||
ssh_set_error(session, SSH_FATAL, "Cannot expand homedir");
|
||||
free(buf);
|
||||
free(r);
|
||||
return NULL;
|
||||
@@ -1348,9 +1347,7 @@ char *ssh_path_expand_escape(ssh_session session, const char *s)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ssh_set_error(session,
|
||||
SSH_FATAL,
|
||||
"Wrong escape sequence detected");
|
||||
ssh_set_error(session, SSH_FATAL, "Wrong escape sequence detected");
|
||||
free(buf);
|
||||
free(r);
|
||||
return NULL;
|
||||
|
||||
@@ -1963,7 +1963,7 @@ int ssh_options_parse_config(ssh_session session, const char *filename)
|
||||
|
||||
/* set default filename */
|
||||
if (filename == NULL) {
|
||||
expanded_filename = ssh_path_expand_escape(session, "%d/config");
|
||||
expanded_filename = ssh_path_expand_escape(session, "%d/.ssh/config");
|
||||
} else {
|
||||
expanded_filename = ssh_path_expand_escape(session, filename);
|
||||
}
|
||||
@@ -2021,7 +2021,7 @@ int ssh_options_apply(ssh_session session)
|
||||
|
||||
if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
|
||||
if (session->opts.knownhosts == NULL) {
|
||||
tmp = ssh_path_expand_escape(session, "%d/known_hosts");
|
||||
tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
|
||||
} else {
|
||||
tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ ssh_session ssh_new(void)
|
||||
}
|
||||
#endif /* WITH_GSSAPI */
|
||||
|
||||
id = strdup("%d/id_ed25519");
|
||||
id = strdup("%d/.ssh/id_ed25519");
|
||||
if (id == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ ssh_session ssh_new(void)
|
||||
}
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
id = strdup("%d/id_ecdsa");
|
||||
id = strdup("%d/.ssh/id_ecdsa");
|
||||
if (id == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ ssh_session ssh_new(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
id = strdup("%d/id_rsa");
|
||||
id = strdup("%d/.ssh/id_rsa");
|
||||
if (id == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ ssh_session ssh_new(void)
|
||||
|
||||
#ifdef WITH_FIDO2
|
||||
/* Add security key identities */
|
||||
id = strdup("%d/id_ed25519_sk");
|
||||
id = strdup("%d/.ssh/id_ed25519_sk");
|
||||
if (id == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ ssh_session ssh_new(void)
|
||||
}
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
id = strdup("%d/id_ecdsa_sk");
|
||||
id = strdup("%d/.ssh/id_ecdsa_sk");
|
||||
if (id == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user