summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2008-11-17 20:37:49 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2008-11-17 20:37:49 +0000
commita9dfda02a27a352c15082cb94cc0113364334d9d (patch)
tree597989f0935b9e9460f952747da819f6e4209daa /usr.sbin/smtpd
parentcf58cde57bba5a66efedcf9d55da032cb1497fbc (diff)
- replace uses of O_EXLOCK and O_EXLOCK|O_NONBLOCK with the corresponding
open()/flock() constructs as chl@ says it prevents him from doing a portable build. discussed with chl@, diff is common work from him and myself
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/queue.c21
-rw-r--r--usr.sbin/smtpd/smtpd.c30
2 files changed, 30 insertions, 21 deletions
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index d520cb250d1..9dde5a0b244 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.11 2008/11/11 21:17:49 gilles Exp $ */
+/* $OpenBSD: queue.c,v 1.12 2008/11/17 20:37:48 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -813,7 +813,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_EXCL;
+ int mode = O_CREAT|O_TRUNC|O_WRONLY|O_EXCL|O_SYNC;
int spret;
FILE *fp;
int hm;
@@ -863,8 +863,8 @@ 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");
+ if (flock(fd, LOCK_EX) == -1)
+ fatal("queue_record_submission: flock");
fp = fdopen(fd, "w");
if (fp == NULL)
@@ -1116,6 +1116,7 @@ queue_update_database(struct message *message)
char pathname[MAXPATHLEN];
int spret;
FILE *fp;
+ mode_t mode = O_RDWR;
if (message->type & T_DAEMON_MESSAGE) {
spool = PATH_DAEMON;
@@ -1137,9 +1138,13 @@ 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, mode)) == -1)
fatal("queue_update_database: cannot open database");
+
+ if (flock(fd, LOCK_EX) == -1)
+ fatal("queue_update_database: flock");
+
fp = fdopen(fd, "w");
if (fp == NULL)
fatal("fdopen");
@@ -1164,7 +1169,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;
@@ -1201,8 +1206,8 @@ queue_record_daemon(struct message *message)
if (unlink(linkname) == -1)
err(1, "unlink");
-// if (flock(fd, LOCK_EX) == -1)
-// err(1, "flock");
+ if (flock(fd, LOCK_EX) == -1)
+ err(1, "flock");
fp = fdopen(fd, "w");
if (fp == NULL)
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index e3cb5a7f23a..2bbd72ba0bc 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.9 2008/11/17 20:14:23 gilles Exp $ */
+/* $OpenBSD: smtpd.c,v 1.10 2008/11/17 20:37:48 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -771,6 +771,7 @@ parent_open_mailbox(struct batch *batchp, struct path *path)
struct passwd *pw;
char pathname[MAXPATHLEN];
int spret;
+ mode_t mode = O_CREAT|O_APPEND|O_RDWR|O_SYNC|O_NONBLOCK;
pw = getpwnam(path->pw_name);
if (pw == NULL) {
@@ -782,7 +783,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_SYNC|O_NONBLOCK|O_EXLOCK, 0600);
+ fd = open(pathname, mode, 0600);
if (fd == -1) {
/* XXX - this needs to be discussed ... */
switch (errno) {
@@ -803,15 +804,16 @@ parent_open_mailbox(struct batch *batchp, struct path *path)
default:
batchp->message.status |= S_MESSAGE_PERMFAILURE;
}
+
return -1;
}
-/*
- if (flock(fd, LOCK_EX) == -1) {
+
+ if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
close(fd);
batchp->message.status |= S_MESSAGE_TEMPFAILURE;
return -1;
}
-*/
+
fchown(fd, pw->pw_uid, 0);
return fd;
@@ -825,6 +827,7 @@ parent_open_maildir(struct batch *batchp, struct path *path)
struct passwd *pw;
char pathname[MAXPATHLEN];
int spret;
+ mode_t mode = O_CREAT|O_RDWR|O_TRUNC|O_SYNC;
pw = getpwnam(path->pw_name);
if (pw == NULL) {
@@ -849,18 +852,18 @@ parent_open_maildir(struct batch *batchp, struct path *path)
return -1;
}
- fd = open(pathname, O_CREAT|O_RDWR|O_TRUNC|O_SYNC|O_EXLOCK, 0600);
+ fd = open(pathname, mode, 0600);
if (fd == -1) {
batchp->message.status |= S_MESSAGE_TEMPFAILURE;
return -1;
}
-/*
- if (flock(fd, LOCK_EX) == -1) {
+
+ if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
close(fd);
batchp->message.status |= S_MESSAGE_TEMPFAILURE;
return -1;
}
-*/
+
fchown(fd, pw->pw_uid, pw->pw_gid);
return fd;
@@ -994,12 +997,13 @@ parent_open_filename(struct batch *batchp, struct path *path)
int fd;
char pathname[MAXPATHLEN];
int spret;
+ mode_t mode = O_CREAT|O_APPEND|O_RDWR|O_SYNC|O_NONBLOCK;
spret = snprintf(pathname, MAXPATHLEN, "%s", path->u.filename);
if (spret == -1 || spret >= MAXPATHLEN)
return -1;
- fd = open(pathname, O_CREAT|O_APPEND|O_RDWR|O_SYNC|O_NONBLOCK|O_EXLOCK, 0600);
+ fd = open(pathname, mode, 0600);
if (fd == -1) {
/* XXX - this needs to be discussed ... */
switch (errno) {
@@ -1022,13 +1026,13 @@ parent_open_filename(struct batch *batchp, struct path *path)
}
return -1;
}
-/*
- if (flock(fd, LOCK_EX) == -1) {
+
+ if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
close(fd);
batchp->message.status |= S_MESSAGE_TEMPFAILURE;
return -1;
}
-*/
+
return fd;
}