diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2023-01-21 22:14:12 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2023-01-21 22:14:12 +0000 |
commit | 36b28fa52e94fba0af59aa6a24ca4035d7793a98 (patch) | |
tree | 93cb6ba7faf0f31ec671bf0a5806ea6a1479b920 | |
parent | 036fe1afba37d9b20509671d3048c6088f018134 (diff) | |
download | libgit2-36b28fa52e94fba0af59aa6a24ca4035d7793a98.tar.gz |
ssh: support windows `known_hosts` files
Use `git_sysdir_find_global_file` to identify the path to the home
directory's `.ssh/known_hosts`; this takes Windows paths into account by
preferring `HOME`, then falling back to `HOMEPATH` and `USERPROFILE`
directories.
-rw-r--r-- | src/libgit2/transports/ssh.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/libgit2/transports/ssh.c b/src/libgit2/transports/ssh.c index 85e779744..56b591006 100644 --- a/src/libgit2/transports/ssh.c +++ b/src/libgit2/transports/ssh.c @@ -16,6 +16,7 @@ #include "netops.h" #include "smart.h" #include "streams/socket.h" +#include "sysdir.h" #include "git2/credential.h" #include "git2/sys/credential.h" @@ -421,7 +422,8 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char * return 0; } -#define KNOWN_HOSTS_FILE ".ssh/known_hosts" +#define SSH_DIR ".ssh" +#define KNOWN_HOSTS_FILE "known_hosts" /* * Load the known_hosts file. @@ -430,16 +432,14 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char * */ static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session) { - git_str path = GIT_STR_INIT, home = GIT_STR_INIT; + git_str path = GIT_STR_INIT, sshdir = GIT_STR_INIT; LIBSSH2_KNOWNHOSTS *known_hosts = NULL; int error; GIT_ASSERT_ARG(hosts); - if ((error = git__getenv(&home, "HOME")) < 0) - return error; - - if ((error = git_str_joinpath(&path, git_str_cstr(&home), KNOWN_HOSTS_FILE)) < 0) + if ((error = git_sysdir_find_global_file(&sshdir, SSH_DIR)) < 0 || + (error = git_str_joinpath(&path, git_str_cstr(&sshdir), KNOWN_HOSTS_FILE)) < 0) goto out; if ((known_hosts = libssh2_knownhost_init(session)) == NULL) { @@ -461,7 +461,7 @@ static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session out: *hosts = known_hosts; - git_str_clear(&home); + git_str_clear(&sshdir); git_str_clear(&path); return error; |