diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2008-11-11 01:01:40 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2008-11-11 01:01:40 +0000 |
commit | 404a92d239f5e936d432390be576f0cd3f8128cb (patch) | |
tree | 24c2bd98f86855bd8b7f286b2ea0ea0875a62050 /usr.sbin/smtpd/smtpd.c | |
parent | d11262169e806d6dcf85b23709c44bf1d722e7b4 (diff) |
remove the use of O_EXLOCK, when open()ing a file, and use flock() instead.
ok gilles@
Diffstat (limited to 'usr.sbin/smtpd/smtpd.c')
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 16cbd5cc4cb..28641ca0a83 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.6 2008/11/10 17:24:24 deraadt Exp $ */ +/* $OpenBSD: smtpd.c,v 1.7 2008/11/11 01:01:39 chl Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -781,7 +781,7 @@ parent_open_mailbox(struct batch *batchp, struct path *path) if (spret == -1 || spret >= MAXPATHLEN) return -1; - fd = open(pathname, O_CREAT|O_APPEND|O_RDWR|O_EXLOCK|O_SYNC|O_NONBLOCK, 0600); + fd = open(pathname, O_CREAT|O_APPEND|O_RDWR|O_SYNC|O_NONBLOCK, 0600); if (fd == -1) { /* XXX - this needs to be discussed ... */ switch (errno) { @@ -805,6 +805,12 @@ parent_open_mailbox(struct batch *batchp, struct path *path) return -1; } + if (flock(fd, LOCK_EX) == -1) { + close(fd); + batchp->message.status |= S_MESSAGE_TEMPFAILURE; + return -1; + } + fchown(fd, pw->pw_uid, 0); return fd; @@ -842,12 +848,18 @@ parent_open_maildir(struct batch *batchp, struct path *path) return -1; } - fd = open(pathname, O_CREAT|O_RDWR|O_TRUNC|O_EXLOCK|O_SYNC, 0600); + fd = open(pathname, O_CREAT|O_RDWR|O_TRUNC|O_SYNC, 0600); if (fd == -1) { batchp->message.status |= S_MESSAGE_TEMPFAILURE; return -1; } + if (flock(fd, LOCK_EX) == -1) { + close(fd); + batchp->message.status |= S_MESSAGE_TEMPFAILURE; + return -1; + } + fchown(fd, pw->pw_uid, pw->pw_gid); return fd; @@ -986,7 +998,7 @@ parent_open_filename(struct batch *batchp, struct path *path) if (spret == -1 || spret >= MAXPATHLEN) return -1; - fd = open(pathname, O_CREAT|O_APPEND|O_RDWR|O_EXLOCK|O_SYNC|O_NONBLOCK, 0600); + fd = open(pathname, O_CREAT|O_APPEND|O_RDWR|O_SYNC|O_NONBLOCK, 0600); if (fd == -1) { /* XXX - this needs to be discussed ... */ switch (errno) { @@ -1010,6 +1022,12 @@ parent_open_filename(struct batch *batchp, struct path *path) return -1; } + if (flock(fd, LOCK_EX) == -1) { + close(fd); + batchp->message.status |= S_MESSAGE_TEMPFAILURE; + return -1; + } + return fd; } |