]> 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 d3971c2498e8f25f0493012034d12b3e96e9e449..57439fec2a968f932cda943d90e6ec60d29242c9 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 44e7e1641c5f0631b0af9fe47ab53dac17baa2e3..31144f96a77adbbc3af7021dcdceb44307be0663 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) {