diff --git a/src/misc.c b/src/misc.c index 2c1e30fc..ec9a51d2 100644 --- a/src/misc.c +++ b/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; diff --git a/src/options.c b/src/options.c index d83a3c5d..93136c9b 100644 --- a/src/options.c +++ b/src/options.c @@ -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); } diff --git a/src/session.c b/src/session.c index 7ed4a98b..8db2c17a 100644 --- a/src/session.c +++ b/src/session.c @@ -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; } diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c index 70e3661d..99d59b94 100644 --- a/tests/client/torture_auth.c +++ b/tests/client/torture_auth.c @@ -376,7 +376,7 @@ torture_auth_autopubkey_protected_auth_function (const char *prompt, char *buf, assert_int_equal(echo, 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); 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. */ - 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); rc = ssh_connect(session); diff --git a/tests/client/torture_auth_cert.c b/tests/client/torture_auth_cert.c index 9b535b2c..1d808cfe 100644 --- a/tests/client/torture_auth_cert.c +++ b/tests/client/torture_auth_cert.c @@ -100,13 +100,10 @@ static int session_setup(void **state) static int session_setup_ssh_dir(void **state) { struct torture_state *s = *state; - const char *no_home = "~/.no_ssh"; - int rc; session_setup(state); - rc = ssh_options_set(s->ssh.session, SSH_OPTIONS_SSH_DIR, no_home); - assert_ssh_return_code(s->ssh.session, rc); + s->ssh.session->opts.homedir = strdup("~/.no_ssh"); return 0; } diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c index d6392832..a2d8326d 100644 --- a/tests/unittests/torture_config.c +++ b/tests/unittests/torture_config.c @@ -25,7 +25,7 @@ extern LIBSSH_THREAD int ssh_log_level; #define HOSTKEYALGORITHMS "ssh-ed25519,ecdsa-sha2-nistp521,ssh-rsa" #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 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 BIND_ADDRESS "::1" diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index 7d311afc..bb567323 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -288,7 +288,8 @@ static void torture_path_expand_escape(void **state) { const char *s = "%d/%h/%p/by/%r"; 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.port = 0; session->opts.username = strdup("root"); @@ -310,9 +311,10 @@ static void torture_path_expand_known_hosts(void **state) { ssh_session session = *state; 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_string_equal(tmp, "/home/guru/.ssh/known_hosts"); free(tmp); @@ -322,9 +324,10 @@ static void torture_path_expand_percent(void **state) { ssh_session session = *state; 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_string_equal(tmp, "/home/guru/.ssh/config%1"); free(tmp); diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c index d38e1806..97b051e1 100644 --- a/tests/unittests/torture_options.c +++ b/tests/unittests/torture_options.c @@ -2067,25 +2067,25 @@ static void torture_options_apply (void **state) rc = ssh_list_append(awaited_list, id); assert_int_equal(rc, SSH_OK); /* 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); assert_int_equal(rc, SSH_OK); #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); assert_int_equal(rc, SSH_OK); #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); assert_int_equal(rc, SSH_OK); #ifdef WITH_FIDO2 /* 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); assert_int_equal(rc, SSH_OK); #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); assert_int_equal(rc, SSH_OK); #endif /* HAVE_ECC */