X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/05dba91fcb152e1941e7f7f145b1d830c5e8f6d0..2a795362ca3ea8da3879ea14d81ee2238e40ad91:/uip/slocal.c diff --git a/uip/slocal.c b/uip/slocal.c index a807d816..6bbcde6a 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -34,6 +34,10 @@ #include #include +/* Hopefully, grp.h declares initgroups(). If we run into a platform + where it doesn't, we could consider declaring it here as well. */ +#include + /* This define is needed for Berkeley db v2 and above to * make the header file expose the 'historical' ndbm APIs. * We define it unconditionally because this is simple and @@ -179,14 +183,14 @@ int main (int argc, char **argv) { int fd, status; - FILE *fp = stdin; + FILE *fp; char *cp, *mdlvr = NULL, buf[BUFSIZ]; char mailbox[BUFSIZ], tmpfil[BUFSIZ]; char **argp, **arguments; if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; } - mts_init (invo_name); + mts_init (); arguments = getarguments (invo_name, argc, argv, 0); argp = arguments; @@ -269,15 +273,28 @@ main (int argc, char **argv) if (addr == NULL) addr = getusername (); - if (user == NULL) - user = (cp = strchr(addr, '.')) ? ++cp : addr; + if (user == NULL) { + user = getusername (); + } if ((pw = getpwnam (user)) == NULL) adios (NULL, "no such local user as %s", user); if (chdir (pw->pw_dir) == -1) - chdir ("/"); + if (chdir ("/") < 0) { + advise ("/", "chdir"); + } umask (0077); + if (geteuid() == 0) { + if (setgid (pw->pw_gid) != 0) { + adios ("setgid", "unable to set group to %ld", (long) pw->pw_gid); + } + initgroups (pw->pw_name, pw->pw_gid); + if (setuid (pw->pw_uid) != 0) { + adios ("setuid", "unable to set user to %ld", (long) pw->pw_uid); + } + } + if (info == NULL) info = ""; @@ -1053,8 +1070,12 @@ usr_pipe (int fd_arg, char *cmd, char *pgm, char **vec, int suppress) /* child process */ if (fd != 0) dup2 (fd, 0); - freopen ("/dev/null", "w", stdout); - freopen ("/dev/null", "w", stderr); + if (freopen ("/dev/null", "w", stdout) == NULL) { + advise ("stdout", "freopen"); + } + if (freopen ("/dev/null", "w", stderr) == NULL) { + advise ("stderr", "freopen"); + } if (fd != 3) dup2 (fd, 3); closefds (4); @@ -1400,6 +1421,7 @@ suppress_duplicates (int fd, char *file) rewind (in); for (;;) { + int failed_to_lock = 0; int bufsz = sizeof buf; state = m_getfld (&gstate, name, buf, &bufsz, in); switch (state) { @@ -1437,7 +1459,8 @@ suppress_duplicates (int fd, char *file) * This will fail if your Maildelivery file doesn't * exist. */ - if ((lockfd = lkopendata(file, O_RDWR, 0)) == -1) { + if ((lockfd = lkopendata(file, O_RDWR, 0, &failed_to_lock)) + == -1) { advise (file, "unable to perform file locking on"); free (cp); fclose (in);