diff options
author | 2015-02-24 09:36:19 +0530 | |
---|---|---|
committer | 2015-02-24 09:36:19 +0530 | |
commit | 3e6090d675631b7d805020038b90cee934f4badb (patch) | |
tree | 9059e3f9811c2925ceedb5d2ed2f59239d428733 /smtpd/queue_fs.c | |
parent | Document uncorrupt command. (diff) | |
download | OpenSMTPD-3e6090d675631b7d805020038b90cee934f4badb.tar.xz OpenSMTPD-3e6090d675631b7d805020038b90cee934f4badb.zip |
rename(2) will fail if the corresponding bucket dir isn't present.
Create the bucket dir if it doesn't exist before rename. Feedback
from gilles.
Diffstat (limited to 'smtpd/queue_fs.c')
-rw-r--r-- | smtpd/queue_fs.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/smtpd/queue_fs.c b/smtpd/queue_fs.c index 2ec04ad0..1e7b9444 100644 --- a/smtpd/queue_fs.c +++ b/smtpd/queue_fs.c @@ -246,6 +246,7 @@ static int queue_fs_message_uncorrupt(uint32_t msgid) { struct stat sb; + char bucketdir[PATH_MAX]; char queuedir[PATH_MAX]; char corruptdir[PATH_MAX]; @@ -261,9 +262,26 @@ queue_fs_message_uncorrupt(uint32_t msgid) return (0); } + + if (! bsnprintf(bucketdir, sizeof bucketdir, "%s/%02x", PATH_QUEUE, + (msgid & 0xff000000) >> 24)) { + log_warnx("warn: queue-fs: path too long"); + return (0); + } + + /* create the bucket */ + if (mkdir(bucketdir, 0700) == -1) { + if (errno == ENOSPC) + return (0); + if (errno != EEXIST) { + log_warn("warn: queue-fs: mkdir"); + return (0); + } + } + if (rename(corruptdir, queuedir) == -1) { log_warn("warn: queue-fs: rename"); - return 0; + return (0); } return (1); |