summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/queue.c17
-rw-r--r--usr.sbin/smtpd/smtpd.c26
2 files changed, 35 insertions, 8 deletions
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index 8c00308eac9..e436119d74e 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.7 2008/11/10 21:29:18 chl Exp $ */
+/* $OpenBSD: queue.c,v 1.8 2008/11/11 01:01:39 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -794,7 +794,7 @@ queue_record_submission(struct message *message)
char *spool;
size_t spoolsz;
int fd;
- int mode = O_CREAT|O_TRUNC|O_WRONLY|O_EXCL|O_SYNC|O_EXLOCK;
+ int mode = O_CREAT|O_TRUNC|O_WRONLY|O_EXCL|O_SYNC;
int spret;
FILE *fp;
int hm;
@@ -844,6 +844,9 @@ queue_record_submission(struct message *message)
if (unlink(linkname) == -1)
fatal("queue_record_submission: unlink");
+ if (flock(fd, LOCK_EX) == -1)
+ fatal("queue_record_submission: flock");
+
fp = fdopen(fd, "w");
if (fp == NULL)
fatal("fdopen");
@@ -1115,9 +1118,12 @@ queue_update_database(struct message *message)
if (spret == -1 || spret >= MAXPATHLEN)
fatal("queue_update_database: pathname too long");
- if ((fd = open(pathname, O_RDWR|O_EXLOCK)) == -1)
+ if ((fd = open(pathname, O_RDWR)) == -1)
fatal("queue_update_database: cannot open database");
+ if (flock(fd, LOCK_EX) == -1)
+ fatal("queue_update_database: cannot get a lock on database");
+
fp = fdopen(fd, "w");
if (fp == NULL)
fatal("fdopen");
@@ -1142,7 +1148,7 @@ queue_record_daemon(struct message *message)
char message_uid[MAXPATHLEN];
size_t spoolsz;
int fd;
- int mode = O_CREAT|O_TRUNC|O_WRONLY|O_EXCL|O_SYNC|O_EXLOCK;
+ int mode = O_CREAT|O_TRUNC|O_WRONLY|O_EXCL|O_SYNC;
int spret;
FILE *fp;
@@ -1179,6 +1185,9 @@ queue_record_daemon(struct message *message)
if (unlink(linkname) == -1)
err(1, "unlink");
+ if (flock(fd, LOCK_EX) == -1)
+ err(1, "flock");
+
fp = fdopen(fd, "w");
if (fp == NULL)
fatal("fdopen");
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;
}