From: dsp <> Date: Tue, 22 Jan 2008 23:15:31 +0000 (+0000) Subject: Fall back to finding the home directory using getpwuid(3) if the HOME X-Git-Url: https://diplodocus.org/git/mdeliver/commitdiff_plain/3ccd655f2af2469c48d22560963c4e387ccce8b1?ds=inline;hp=6bcc7209b6b0d137a4ff92acf219ccb36628c8f6 Fall back to finding the home directory using getpwuid(3) if the HOME environment variable isn't set. --- diff --git a/mdeliver.1.pod b/mdeliver.1.pod index d3971c2..57439fe 100644 --- a/mdeliver.1.pod +++ b/mdeliver.1.pod @@ -49,7 +49,7 @@ The following environment variable affects the execution of B: The HOME environment variable defines in which directory the Maildir will be found. If HOME is set to ``/home/charlie'', ``/home/charlie/Maildir'' will be where delivery is attempted to. If this variable is not set, -delivery will fail. +B will fall back to using getpwuid(3). =back diff --git a/mdeliver.c b/mdeliver.c index 44e7e16..31144f9 100644 --- a/mdeliver.c +++ b/mdeliver.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -359,6 +360,7 @@ main(int argc, char *argv[]) { char *home; char newfn[LEN_FILENAME]; + struct passwd *pwd; struct stat st; if (argv[1] && argv[1][0] == '-' && argv[1][1] == 'v') { @@ -367,7 +369,11 @@ main(int argc, char *argv[]) } if ((home = getenv("HOME")) == NULL) { - errx("HOME is not set."); + if ((pwd = getpwuid(geteuid())) != NULL) { + home = pwd->pw_dir; + } else { + errx("HOME is not set and getpwuid() failed."); + } } if (chdir(home) != 0) {