diff options
author | 2018-04-13 14:11:37 +0000 | |
---|---|---|
committer | 2018-04-13 14:11:37 +0000 | |
commit | 55ba48e5cea3a5734f97e87fe27e407175c2a56b (patch) | |
tree | c2ccc716196e333cf2871fd46fa97154e658be69 | |
parent | Remove compatibility with pfctl from 6.1 and plug a few leaks (diff) | |
download | wireguard-openbsd-55ba48e5cea3a5734f97e87fe27e407175c2a56b.tar.xz wireguard-openbsd-55ba48e5cea3a5734f97e87fe27e407175c2a56b.zip |
mg tries to write backups to the wrong directory when run under a
different effective user, i.e. when invoced via su and
backup-to-home-directory is enabled.
Problem pointed out and diff provied by Lucas Gabriel Vuotto
<lvuotto92 () gmail ! com>, thanks!
Subsequently slacked on for nearly a year by yours truly.
Then remembered when Han Boetes <hboetes () gmail ! com> came up with
a similar diff because of a problem report by Mark Willson where it
turned out that getlogin(2) is not very portable.
OK tb
-rw-r--r-- | usr.bin/mg/fileio.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c index 0987f6f30de..4db188b1009 100644 --- a/usr.bin/mg/fileio.c +++ b/usr.bin/mg/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.104 2017/05/30 07:05:22 florian Exp $ */ +/* $OpenBSD: fileio.c,v 1.105 2018/04/13 14:11:37 florian Exp $ */ /* This file is in the public domain. */ @@ -703,7 +703,7 @@ expandtilde(const char *fn) struct stat statbuf; const char *cp; char user[LOGIN_NAME_MAX], path[NFILEN]; - char *un, *ret; + char *ret; size_t ulen, plen; path[0] = '\0'; @@ -722,16 +722,13 @@ expandtilde(const char *fn) return (NULL); return(ret); } - if (ulen == 0) { /* ~/ or ~ */ - if ((un = getlogin()) != NULL) - (void)strlcpy(user, un, sizeof(user)); - else - user[0] = '\0'; - } else { /* ~user/ or ~user */ + if (ulen == 0) /* ~/ or ~ */ + pw = getpwuid(geteuid()); + else { /* ~user/ or ~user */ memcpy(user, &fn[1], ulen); user[ulen] = '\0'; + pw = getpwnam(user); } - pw = getpwnam(user); if (pw != NULL) { plen = strlcpy(path, pw->pw_dir, sizeof(path)); if (plen == 0 || path[plen - 1] != '/') { |