mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +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
|
/** @internal
|
||||||
* @brief expands a string in function of session options
|
* @brief expands a string in function of session options
|
||||||
* @param[in] s Format string to expand. Known parameters:
|
* @param[in] s Format string to expand. Known parameters:
|
||||||
* %d SSH configuration directory (~/.ssh)
|
* %d user home directory (~)
|
||||||
* %h target host name
|
* %h target host name
|
||||||
* %u local username
|
* %u local username
|
||||||
* %l local hostname
|
* %l local hostname
|
||||||
@@ -1301,10 +1301,9 @@ char *ssh_path_expand_escape(ssh_session session, const char *s)
|
|||||||
case '%':
|
case '%':
|
||||||
goto escape;
|
goto escape;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (session->opts.sshdir) {
|
x = ssh_get_user_home_dir(session);
|
||||||
x = strdup(session->opts.sshdir);
|
if (x == NULL) {
|
||||||
} else {
|
ssh_set_error(session, SSH_FATAL, "Cannot expand homedir");
|
||||||
ssh_set_error(session, SSH_FATAL, "Cannot expand sshdir");
|
|
||||||
free(buf);
|
free(buf);
|
||||||
free(r);
|
free(r);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1348,9 +1347,7 @@ char *ssh_path_expand_escape(ssh_session session, const char *s)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ssh_set_error(session,
|
ssh_set_error(session, SSH_FATAL, "Wrong escape sequence detected");
|
||||||
SSH_FATAL,
|
|
||||||
"Wrong escape sequence detected");
|
|
||||||
free(buf);
|
free(buf);
|
||||||
free(r);
|
free(r);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -1963,7 +1963,7 @@ int ssh_options_parse_config(ssh_session session, const char *filename)
|
|||||||
|
|
||||||
/* set default filename */
|
/* set default filename */
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
expanded_filename = ssh_path_expand_escape(session, "%d/config");
|
expanded_filename = ssh_path_expand_escape(session, "%d/.ssh/config");
|
||||||
} else {
|
} else {
|
||||||
expanded_filename = ssh_path_expand_escape(session, filename);
|
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.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
|
||||||
if (session->opts.knownhosts == NULL) {
|
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 {
|
} else {
|
||||||
tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
|
tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ ssh_session ssh_new(void)
|
|||||||
}
|
}
|
||||||
#endif /* WITH_GSSAPI */
|
#endif /* WITH_GSSAPI */
|
||||||
|
|
||||||
id = strdup("%d/id_ed25519");
|
id = strdup("%d/.ssh/id_ed25519");
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ ssh_session ssh_new(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
id = strdup("%d/id_ecdsa");
|
id = strdup("%d/.ssh/id_ecdsa");
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ ssh_session ssh_new(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
id = strdup("%d/id_rsa");
|
id = strdup("%d/.ssh/id_rsa");
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@@ -200,7 +200,7 @@ ssh_session ssh_new(void)
|
|||||||
|
|
||||||
#ifdef WITH_FIDO2
|
#ifdef WITH_FIDO2
|
||||||
/* Add security key identities */
|
/* Add security key identities */
|
||||||
id = strdup("%d/id_ed25519_sk");
|
id = strdup("%d/.ssh/id_ed25519_sk");
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ ssh_session ssh_new(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
id = strdup("%d/id_ecdsa_sk");
|
id = strdup("%d/.ssh/id_ecdsa_sk");
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ torture_auth_autopubkey_protected_auth_function (const char *prompt, char *buf,
|
|||||||
assert_int_equal(echo, 0);
|
assert_int_equal(echo, 0);
|
||||||
assert_int_equal(verify, 0);
|
assert_int_equal(verify, 0);
|
||||||
|
|
||||||
expected_id = ssh_path_expand_escape(data->session, "%d/id_rsa_protected");
|
expected_id = ssh_path_expand_escape(data->session, "%d/.ssh/id_rsa_protected");
|
||||||
assert_true(expected_id != NULL);
|
assert_true(expected_id != NULL);
|
||||||
|
|
||||||
rc = ssh_userauth_publickey_auto_get_current_identity(data->session, &id);
|
rc = ssh_userauth_publickey_auto_get_current_identity(data->session, &id);
|
||||||
@@ -429,7 +429,7 @@ static void torture_auth_autopubkey_protected(void **state) {
|
|||||||
|
|
||||||
/* Try id_rsa_protected first.
|
/* Try id_rsa_protected first.
|
||||||
*/
|
*/
|
||||||
rc = ssh_options_set(session, SSH_OPTIONS_IDENTITY, "%d/id_rsa_protected");
|
rc = ssh_options_set(session, SSH_OPTIONS_IDENTITY, "%d/.ssh/id_rsa_protected");
|
||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
|
|
||||||
rc = ssh_connect(session);
|
rc = ssh_connect(session);
|
||||||
|
|||||||
@@ -100,13 +100,10 @@ static int session_setup(void **state)
|
|||||||
static int session_setup_ssh_dir(void **state)
|
static int session_setup_ssh_dir(void **state)
|
||||||
{
|
{
|
||||||
struct torture_state *s = *state;
|
struct torture_state *s = *state;
|
||||||
const char *no_home = "~/.no_ssh";
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
session_setup(state);
|
session_setup(state);
|
||||||
|
|
||||||
rc = ssh_options_set(s->ssh.session, SSH_OPTIONS_SSH_DIR, no_home);
|
s->ssh.session->opts.homedir = strdup("~/.no_ssh");
|
||||||
assert_ssh_return_code(s->ssh.session, rc);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ extern LIBSSH_THREAD int ssh_log_level;
|
|||||||
#define HOSTKEYALGORITHMS "ssh-ed25519,ecdsa-sha2-nistp521,ssh-rsa"
|
#define HOSTKEYALGORITHMS "ssh-ed25519,ecdsa-sha2-nistp521,ssh-rsa"
|
||||||
#define PUBKEYACCEPTEDTYPES "rsa-sha2-512,ssh-rsa,ecdsa-sha2-nistp521"
|
#define PUBKEYACCEPTEDTYPES "rsa-sha2-512,ssh-rsa,ecdsa-sha2-nistp521"
|
||||||
#define MACS "hmac-sha1,hmac-sha2-256,hmac-sha2-512,hmac-sha1-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com"
|
#define MACS "hmac-sha1,hmac-sha2-256,hmac-sha2-512,hmac-sha1-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com"
|
||||||
#define USER_KNOWN_HOSTS "%d/my_known_hosts"
|
#define USER_KNOWN_HOSTS "%d/.ssh/my_known_hosts"
|
||||||
#define GLOBAL_KNOWN_HOSTS "/etc/ssh/my_ssh_known_hosts"
|
#define GLOBAL_KNOWN_HOSTS "/etc/ssh/my_ssh_known_hosts"
|
||||||
#define BIND_ADDRESS "::1"
|
#define BIND_ADDRESS "::1"
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,8 @@ static void torture_path_expand_escape(void **state) {
|
|||||||
const char *s = "%d/%h/%p/by/%r";
|
const char *s = "%d/%h/%p/by/%r";
|
||||||
char *e;
|
char *e;
|
||||||
|
|
||||||
session->opts.sshdir = strdup("guru");
|
/* Set the homedir here to prevent querying the NSS DB */
|
||||||
|
session->opts.homedir = strdup("guru");
|
||||||
session->opts.host = strdup("meditation");
|
session->opts.host = strdup("meditation");
|
||||||
session->opts.port = 0;
|
session->opts.port = 0;
|
||||||
session->opts.username = strdup("root");
|
session->opts.username = strdup("root");
|
||||||
@@ -310,9 +311,10 @@ static void torture_path_expand_known_hosts(void **state) {
|
|||||||
ssh_session session = *state;
|
ssh_session session = *state;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
session->opts.sshdir = strdup("/home/guru/.ssh");
|
/* Set the homedir here to prevent querying the NSS DB */
|
||||||
|
session->opts.homedir = strdup("/home/guru");
|
||||||
|
|
||||||
tmp = ssh_path_expand_escape(session, "%d/known_hosts");
|
tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
|
||||||
assert_non_null(tmp);
|
assert_non_null(tmp);
|
||||||
assert_string_equal(tmp, "/home/guru/.ssh/known_hosts");
|
assert_string_equal(tmp, "/home/guru/.ssh/known_hosts");
|
||||||
free(tmp);
|
free(tmp);
|
||||||
@@ -322,9 +324,10 @@ static void torture_path_expand_percent(void **state) {
|
|||||||
ssh_session session = *state;
|
ssh_session session = *state;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
session->opts.sshdir = strdup("/home/guru/.ssh");
|
/* Set the homedir here to prevent querying the NSS DB */
|
||||||
|
session->opts.homedir = strdup("/home/guru");
|
||||||
|
|
||||||
tmp = ssh_path_expand_escape(session, "%d/config%%1");
|
tmp = ssh_path_expand_escape(session, "%d/.ssh/config%%1");
|
||||||
assert_non_null(tmp);
|
assert_non_null(tmp);
|
||||||
assert_string_equal(tmp, "/home/guru/.ssh/config%1");
|
assert_string_equal(tmp, "/home/guru/.ssh/config%1");
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|||||||
@@ -2067,25 +2067,25 @@ static void torture_options_apply (void **state)
|
|||||||
rc = ssh_list_append(awaited_list, id);
|
rc = ssh_list_append(awaited_list, id);
|
||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
/* append the defaults; this list is copied from ssh_new@src/session.c */
|
/* append the defaults; this list is copied from ssh_new@src/session.c */
|
||||||
id = ssh_path_expand_escape(session, "%d/id_ed25519");
|
id = ssh_path_expand_escape(session, "%d/.ssh/id_ed25519");
|
||||||
rc = ssh_list_append(awaited_list, id);
|
rc = ssh_list_append(awaited_list, id);
|
||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
id = ssh_path_expand_escape(session, "%d/id_ecdsa");
|
id = ssh_path_expand_escape(session, "%d/.ssh/id_ecdsa");
|
||||||
rc = ssh_list_append(awaited_list, id);
|
rc = ssh_list_append(awaited_list, id);
|
||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
#endif
|
#endif
|
||||||
id = ssh_path_expand_escape(session, "%d/id_rsa");
|
id = ssh_path_expand_escape(session, "%d/.ssh/id_rsa");
|
||||||
rc = ssh_list_append(awaited_list, id);
|
rc = ssh_list_append(awaited_list, id);
|
||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
#ifdef WITH_FIDO2
|
#ifdef WITH_FIDO2
|
||||||
/* Add security key identities */
|
/* Add security key identities */
|
||||||
id = ssh_path_expand_escape(session, "%d/id_ed25519_sk");
|
id = ssh_path_expand_escape(session, "%d/.ssh/id_ed25519_sk");
|
||||||
rc = ssh_list_append(awaited_list, id);
|
rc = ssh_list_append(awaited_list, id);
|
||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
id = ssh_path_expand_escape(session, "%d/id_ecdsa_sk");
|
id = ssh_path_expand_escape(session, "%d/.ssh/id_ecdsa_sk");
|
||||||
rc = ssh_list_append(awaited_list, id);
|
rc = ssh_list_append(awaited_list, id);
|
||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
#endif /* HAVE_ECC */
|
#endif /* HAVE_ECC */
|
||||||
|
|||||||
Reference in New Issue
Block a user