Author: bapt
Date: Fri Sep 30 23:35:47 2016
New Revision: 306539
URL: https://svnweb.freebsd.org/changeset/base/306539

Log:
  Import dma snapshot 20160929

Modified:
  vendor/dma/dist/dma-mbox-create.c

Modified: vendor/dma/dist/dma-mbox-create.c
==============================================================================
--- vendor/dma/dist/dma-mbox-create.c   Fri Sep 30 23:19:08 2016        
(r306538)
+++ vendor/dma/dist/dma-mbox-create.c   Fri Sep 30 23:35:47 2016        
(r306539)
@@ -89,9 +89,7 @@ main(int argc, char **argv)
        struct group *gr;
        uid_t user_uid;
        gid_t mail_gid;
-       int error;
-       char fn[PATH_MAX+1];
-       int f;
+       int f, maildirfd;
 
        openlog("dma-mbox-create", 0, LOG_MAIL);
 
@@ -131,26 +129,22 @@ main(int argc, char **argv)
        if (!pw)
                logfail(EX_NOUSER, "cannot find user `%s'", user);
 
-       user_uid = pw->pw_uid;
+       maildirfd = open(_PATH_MAILDIR, O_RDONLY);
+       if (maildirfd < 0)
+               logfail(EX_NOINPUT, "cannot open maildir %s", _PATH_MAILDIR);
 
-       error = snprintf(fn, sizeof(fn), "%s/%s", _PATH_MAILDIR, user);
-       if (error < 0 || (size_t)error >= sizeof(fn)) {
-               if (error >= 0) {
-                       errno = 0;
-                       logfail(EX_USAGE, "mbox path too long");
-               }
-               logfail(EX_CANTCREAT, "cannot build mbox path for `%s/%s'", 
_PATH_MAILDIR, user);
-       }
+       user_uid = pw->pw_uid;
 
-       f = open(fn, O_RDONLY|O_CREAT|O_NOFOLLOW, 0600);
+       f = openat(maildirfd, user, O_RDONLY|O_CREAT|O_NOFOLLOW, 0600);
        if (f < 0)
-               logfail(EX_NOINPUT, "cannt open mbox `%s'", fn);
+               logfail(EX_NOINPUT, "cannot open mbox `%s'", user);
 
        if (fchown(f, user_uid, mail_gid))
-               logfail(EX_OSERR, "cannot change owner of mbox `%s'", fn);
+               logfail(EX_OSERR, "cannot change owner of mbox `%s'", user);
 
        if (fchmod(f, 0620))
-               logfail(EX_OSERR, "cannot change permissions of mbox `%s'", fn);
+               logfail(EX_OSERR, "cannot change permissions of mbox `%s'",
+                   user);
 
        /* file should be present with the right owner and permissions */
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to