Mercurial > dropbear
changeset 1851:7f549ee3df48
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.
author | Matt Robinson <git@nerdoftheherd.com> |
---|---|
date | Tue, 19 Oct 2021 06:02:47 +0100 |
parents | d99b167994b5 |
children | e0c1825c567d |
files | dbutil.c |
diffstat | 1 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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; } }