Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
brong committed Nov 7, 2023
1 parent 89814a5 commit 86bca4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 14 additions & 1 deletion imap/mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -2492,8 +2492,11 @@ static int mailbox_lock_index_internal(struct mailbox *mailbox, int locktype)

if (locktype == LOCK_EXCLUSIVE) {
/* we can't upgrade a readonly mailbox */
if (mailbox->is_readonly)
if (mailbox->is_readonly) {
assert(0);
return IMAP_MAILBOX_LOCKED;
}

r = lock_blocking(mailbox->index_fd, index_fname);
}
else if (locktype == LOCK_SHARED) {
Expand All @@ -2507,9 +2510,13 @@ static int mailbox_lock_index_internal(struct mailbox *mailbox, int locktype)
if (!r) {
if (fstat(mailbox->index_fd, &sbuf) != 0) {
r = IMAP_MAILBOX_BADFORMAT;
assert(0);
abort();
}
else if (sbuf.st_size < OFFSET_NUM_RECORDS) {
assert(0);
r = IMAP_MAILBOX_BADFORMAT;
abort();
}
else {
mailbox->index_ino = sbuf.st_ino;
Expand All @@ -2522,10 +2529,12 @@ static int mailbox_lock_index_internal(struct mailbox *mailbox, int locktype)
}

if (r) {
assert(0);
lock_unlock(mailbox->index_fd, index_fname);
xsyslog(LOG_ERR, "IOERROR: lock index failed",
"mailbox=<%s> error=<%s>",
mailbox_name(mailbox), error_message(r));
abort();
return IMAP_IOERROR;
}

Expand All @@ -2539,6 +2548,7 @@ static int mailbox_lock_index_internal(struct mailbox *mailbox, int locktype)
"mailbox=<%s> header=<%s>",
mailbox_name(mailbox), header_fname);
mailbox_unlock_index(mailbox, NULL);
abort();
return IMAP_IOERROR;
}

Expand All @@ -2550,6 +2560,7 @@ static int mailbox_lock_index_internal(struct mailbox *mailbox, int locktype)
"mailbox=<%s> error=<%s>",
mailbox_name(mailbox), error_message(r));
mailbox_unlock_index(mailbox, NULL);
abort();
return r;
}
}
Expand All @@ -2563,6 +2574,7 @@ static int mailbox_lock_index_internal(struct mailbox *mailbox, int locktype)
"mailbox=<%s> error=<%s>",
mailbox_name(mailbox), error_message(r));
mailbox_unlock_index(mailbox, NULL);
abort();
return r;
}

Expand Down Expand Up @@ -5904,6 +5916,7 @@ EXPORTED int mailbox_create(const char *name,
}
r = lock_blocking(mailbox->index_fd, fname);
if (r) {
abort();
xsyslog(LOG_ERR, "IOERROR: lock index failed",
"fname=<%s>",
fname);
Expand Down
10 changes: 8 additions & 2 deletions imap/mboxname.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,21 @@ EXPORTED int mboxname_lock(const char *mboxname, struct mboxlock **mboxlockptr,
locktype = (locktype_and_flags & ~LOCK_NONBLOCK);

fname = mboxname_lockpath(mboxname);
if (!fname)
if (!fname) {
abort();
return IMAP_MAILBOX_BADNAME;
}

lockitem = find_lockitem(mboxname);

/* already open? just use this one */
if (lockitem) {
/* can't change locktype! */
if (lockitem->l.locktype != locktype)
if (lockitem->l.locktype != locktype) {
syslog(LOG_ERR, "IOERROR: trying to change lock type %s", mboxname);
abort();
return IMAP_MAILBOX_LOCKED;
}

lockitem->nopen++;
goto done;
Expand Down Expand Up @@ -240,6 +245,7 @@ EXPORTED int mboxname_lock(const char *mboxname, struct mboxlock **mboxlockptr,
if (r) {
xsyslog(LOG_ERR, "can not lock mailbox",
"name=<%s> error=<%s>", mboxname, error_message(r));
abort();
remove_lockitem(lockitem);
}
else *mboxlockptr = &lockitem->l;
Expand Down

0 comments on commit 86bca4e

Please sign in to comment.