aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2016-09-30 23:35:47 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2016-09-30 23:35:47 +0000
commitbf3a47a7ab4802326f33d469e02f6632c12946e9 (patch)
tree0161435f229ef01bcd02aa869c153279a89426de
parenteb8bc5621c0e1eaeb75884f5d7f36edd90d4cd9b (diff)
downloadsrc-bf3a47a7ab4802326f33d469e02f6632c12946e9.tar.gz
src-bf3a47a7ab4802326f33d469e02f6632c12946e9.zip
Import dma snapshot 20160929vendor/dma/20160929
Notes
Notes: svn path=/vendor/dma/dist/; revision=306539 svn path=/vendor/dma/20160929/; revision=306540; tag=vendor/dma/20160929
-rw-r--r--dma-mbox-create.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/dma-mbox-create.c b/dma-mbox-create.c
index 45a4792a3f6f..80088601f2d7 100644
--- a/dma-mbox-create.c
+++ b/dma-mbox-create.c
@@ -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 */