Commit ed04bc83 ed04bc837e353e61e4c43f6bdbd9a67859c61f61 by Sergey Poznyakoff

Fix delivery to MH and Maildir mailboxes

After successful delivery, maidag would switch back to root privileges
too early, due to which the mailbox would be closed when running with
root UID.  I the property file (.mu-prop) did not exist, it would
therefore be created by root.  Subsequent attempts to open it by user
would fail.  One of consequences is that the UIDVALIDITY value would
be recalculated each time the mailbox is opened.  This would force
imap4 clients to rescan mailboxes infinitely, as each scan would change
the UIDVALIDITY again.

This patch fixes the initialization of UIDVALIDITY and fixes maidag to
switch back to root privileges only after closing the mailbox.  It also
makes sure MH and Maildir mailboxes write .mu-prop upon closing, not
upon destroying the mailbox.

* libmailutils/base/amd.c (amd_close): Save property.
(_amd_scan0): Use mailbox modification time as initial
uidvalidity value.
* maidag/deliver.c (deliver_to_mailbox): Remove uselsess UID/GID
transitions.
1 parent 1186b695
...@@ -519,6 +519,8 @@ amd_close (mu_mailbox_t mailbox) ...@@ -519,6 +519,8 @@ amd_close (mu_mailbox_t mailbox)
519 free (amd->msg_array); 519 free (amd->msg_array);
520 amd->msg_array = NULL; 520 amd->msg_array = NULL;
521 521
522 mu_property_save (amd->prop);
523
522 amd->msg_count = 0; /* number of messages in the list */ 524 amd->msg_count = 0; /* number of messages in the list */
523 amd->msg_max = 0; /* maximum message buffer capacity */ 525 amd->msg_max = 0; /* maximum message buffer capacity */
524 526
...@@ -675,7 +677,7 @@ _amd_scan0 (struct _amd_data *amd, size_t msgno, size_t *pcount, ...@@ -675,7 +677,7 @@ _amd_scan0 (struct _amd_data *amd, size_t msgno, size_t *pcount,
675 _amd_prop_fetch_ulong (amd, _MU_AMD_PROP_UIDVALIDITY, &uidval) || 677 _amd_prop_fetch_ulong (amd, _MU_AMD_PROP_UIDVALIDITY, &uidval) ||
676 !uidval) 678 !uidval)
677 { 679 {
678 uidval = (unsigned long)time (NULL); 680 uidval = (unsigned long) amd->mtime;
679 _amd_prop_store_off (amd, _MU_AMD_PROP_UIDVALIDITY, uidval); 681 _amd_prop_store_off (amd, _MU_AMD_PROP_UIDVALIDITY, uidval);
680 } 682 }
681 return 0; 683 return 0;
......
...@@ -225,7 +225,7 @@ deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg, ...@@ -225,7 +225,7 @@ deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg,
225 } 225 }
226 #endif 226 #endif
227 227
228 if (!failed && switch_user_id (auth, 1) == 0) 228 if (!failed)
229 { 229 {
230 status = mu_mailbox_append_message (mbox, msg); 230 status = mu_mailbox_append_message (mbox, msg);
231 if (status) 231 if (status)
...@@ -244,7 +244,6 @@ deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg, ...@@ -244,7 +244,6 @@ deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg,
244 failed++; 244 failed++;
245 } 245 }
246 } 246 }
247 switch_user_id (auth, 0);
248 } 247 }
249 248
250 mu_mailbox_close (mbox); 249 mu_mailbox_close (mbox);
......