Mercurial > dovecot > core-2.2
changeset 15288:83695d6d41aa
mbox: Fixed getting filesystem permissions when parent dir has setgid-bit enabled.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 02 Oct 2012 21:56:09 +0300 |
parents | 38727d3e90ec |
children | 94c7e875f9b9 |
files | src/lib-storage/mailbox-list.c |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mailbox-list.c Tue Oct 02 21:36:43 2012 +0300 +++ b/src/lib-storage/mailbox-list.c Tue Oct 02 21:56:09 2012 +0300 @@ -638,7 +638,7 @@ void mailbox_list_get_permissions(struct mailbox_list *list, const char *name, struct mailbox_permissions *permissions_r) { - const char *path, *parent_name, *p; + const char *path, *parent_name, *parent_path, *p; struct stat st; memset(permissions_r, 0, sizeof(*permissions_r)); @@ -708,6 +708,21 @@ } else { permissions_r->file_create_gid = st.st_gid; } + if (!S_ISDIR(st.st_mode) && + permissions_r->file_create_gid != (gid_t)-1) { + /* we need to stat() the parent directory to see if + it has setgid-bit set */ + p = strrchr(path, '/'); + parent_path = p == NULL ? NULL : + t_strdup_until(path, p); + if (parent_path != NULL && + stat(parent_path, &st) == 0 && + (st.st_mode & S_ISGID) != 0) { + /* directory's GID is used automatically for + new files */ + permissions_r->file_create_gid = (gid_t)-1; + } + } } if (name == NULL) {