Date: Fri, 7 Oct 2016 06:11:15 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r306800 - stable/11/contrib/dma Message-ID: <201610070611.u976BFll076346@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Fri Oct 7 06:11:15 2016 New Revision: 306800 URL: https://svnweb.freebsd.org/changeset/base/306800 Log: MFC r306541 Import dma 20160929 Modified: stable/11/contrib/dma/dma-mbox-create.c Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/dma/dma-mbox-create.c ============================================================================== --- stable/11/contrib/dma/dma-mbox-create.c Fri Oct 7 02:33:45 2016 (r306799) +++ stable/11/contrib/dma/dma-mbox-create.c Fri Oct 7 06:11:15 2016 (r306800) @@ -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 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201610070611.u976BFll076346>