dovecot-1.2: mbox: Creating new mailboxes should base permission...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 25 18:22:07 EEST 2010


details:   http://hg.dovecot.org/dovecot-1.2/rev/45769d0cc39c
changeset: 9624:45769d0cc39c
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 25 16:22:04 2010 +0100
description:
mbox: Creating new mailboxes should base permissions on mail root dir, not always use 0600.

diffstat:

 src/lib-storage/index/mbox/mbox-storage.c |  21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diffs (46 lines):

diff -r b2d30a8d3fb4 -r 45769d0cc39c src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c	Sat Oct 16 18:39:43 2010 +0100
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Mon Oct 25 16:22:04 2010 +0100
@@ -7,6 +7,7 @@
 #include "restrict-access.h"
 #include "mkdir-parents.h"
 #include "unlink-directory.h"
+#include "eacces-error.h"
 #include "mbox-storage.h"
 #include "mbox-lock.h"
 #include "mbox-file.h"
@@ -732,7 +733,7 @@
 {
 	const char *path, *p, *origin;
 	struct stat st;
-	mode_t mode;
+	mode_t mode, old_mask;
 	gid_t gid;
 	int fd;
 
@@ -778,8 +779,24 @@
 	}
 
 	/* create the mailbox file */
-	fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0660);
+	mailbox_list_get_permissions(_storage->list, NULL,
+				     &mode, &gid, &origin);
+	old_mask = umask(0);
+	fd = open(path, O_RDWR | O_CREAT | O_EXCL, mode);
+	umask(old_mask);
 	if (fd != -1) {
+		if (gid != (gid_t)-1) {
+			if (fchown(fd, (uid_t)-1, gid) == 0) {
+				/* ok */
+			} else if (errno == EPERM) {
+				mail_storage_set_critical(_storage, "%s",
+					eperm_error_get_chgrp("fchown", path,
+							      gid, origin));
+			} else {
+				mail_storage_set_critical(_storage,
+					"fchown(%s) failed: %m", path);
+			}
+		}
 		(void)close(fd);
 		return 0;
 	}


More information about the dovecot-cvs mailing list