]> diplodocus.org Git - mdeliver/commitdiff
Fall back to finding the home directory using getpwuid(3) if the HOME
authordsp <>
Tue, 22 Jan 2008 23:15:31 +0000 (23:15 +0000)
committerdsp <>
Tue, 22 Jan 2008 23:15:31 +0000 (23:15 +0000)
environment variable isn't set.

mdeliver.1.pod
mdeliver.c

index d3971c2..57439fe 100644 (file)
@@ -49,7 +49,7 @@ The following environment variable affects the execution of B<mdeliver>:
 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,
 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<mdeliver> will fall back to using getpwuid(3).
 
 =back
 
 
 =back
 
index 44e7e16..31144f9 100644 (file)
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <pwd.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -359,6 +360,7 @@ main(int argc, char *argv[])
 {
     char *home;
     char newfn[LEN_FILENAME];
 {
     char *home;
     char newfn[LEN_FILENAME];
+    struct passwd *pwd;
     struct stat st;
 
     if (argv[1] && argv[1][0] == '-' && argv[1][1] == 'v') {
     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) {
     }
 
     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) {
     }
 
     if (chdir(home) != 0) {