# HG changeset patch # User Matt Robinson # Date 1634619767 -3600 # Node ID 7f549ee3df48b15579f2baedc3c8d73f95a72634 # Parent d99b167994b5f5432d6efd9cc9d94d2967909a3f 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. diff -r d99b167994b5 -r 7f549ee3df48 dbutil.c --- a/dbutil.c Tue Oct 19 12:49:19 2021 +0800 +++ b/dbutil.c Tue Oct 19 06:02:47 2021 +0100 @@ -609,11 +609,19 @@ char * expand_homedir_path(const char *inpath) { struct passwd *pw = NULL; if (inpath[0] != '/') { - pw = getpwuid(getuid()); - if (pw && pw->pw_dir) { - int len = strlen(inpath) + strlen(pw->pw_dir) + 2; + char *homedir = getenv("HOME"); + + if (!homedir) { + pw = getpwuid(getuid()); + if (pw) { + homedir = pw->pw_dir; + } + } + + if (homedir) { + int len = strlen(inpath) + strlen(homedir) + 2; char *buf = m_malloc(len); - snprintf(buf, len, "%s/%s", pw->pw_dir, inpath); + snprintf(buf, len, "%s/%s", homedir, inpath); return buf; } }