Mercurial > dovecot > original-hg > dovecot-1.2
changeset 9624:45769d0cc39c HEAD
mbox: Creating new mailboxes should base permissions on mail root dir, not always use 0600.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 25 Oct 2010 16:22:04 +0100 |
parents | b2d30a8d3fb4 |
children | b30af25c622d |
files | src/lib-storage/index/mbox/mbox-storage.c |
diffstat | 1 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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; }