Use HOME before /etc/passwd to find id_dropbear (#137)

Currently dbclient uses the value of HOME by default when looking for
~/.ssh/known_hosts, falling back to /etc/passwd if HOME is not set (so
that people can work around broken values in /etc/passwd).

However, when locating the default authentication key (defaults to
~/.ssh/id_dropbear), paths not starting with / are always prefixed with
the value from /etc/passwd.

Make the behaviour consistent by adjusting expand_homedir_path to use
the value of HOME, falling back to /etc/passwd if HOME is not set.
This commit is contained in:
Matt Robinson 2021-10-19 06:02:47 +01:00 committed by GitHub
parent 0e43d68d81
commit 742e296115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -609,11 +609,19 @@ otherwise home directory is prepended */
char * expand_homedir_path(const char *inpath) { char * expand_homedir_path(const char *inpath) {
struct passwd *pw = NULL; struct passwd *pw = NULL;
if (inpath[0] != '/') { if (inpath[0] != '/') {
char *homedir = getenv("HOME");
if (!homedir) {
pw = getpwuid(getuid()); pw = getpwuid(getuid());
if (pw && pw->pw_dir) { if (pw) {
int len = strlen(inpath) + strlen(pw->pw_dir) + 2; homedir = pw->pw_dir;
}
}
if (homedir) {
int len = strlen(inpath) + strlen(homedir) + 2;
char *buf = m_malloc(len); char *buf = m_malloc(len);
snprintf(buf, len, "%s/%s", pw->pw_dir, inpath); snprintf(buf, len, "%s/%s", homedir, inpath);
return buf; return buf;
} }
} }