changeset 8769:cc8d4d06ef9f HEAD

mailboxes: Copy root directory's +x modes for newly created dirs perfectly.
author Timo Sirainen <tss@iki.fi>
date Sat, 21 Feb 2009 18:47:48 -0500
parents 91e880ae387a
children f1414fa48b4b
files src/lib-storage/mailbox-list-private.h src/lib-storage/mailbox-list.c
diffstat 2 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mailbox-list-private.h	Sat Feb 21 18:22:11 2009 -0500
+++ b/src/lib-storage/mailbox-list-private.h	Sat Feb 21 18:47:48 2009 -0500
@@ -79,7 +79,7 @@
 	enum mailbox_list_flags flags;
 
 	/* -1 if not set yet. use mailbox_list_get_permissions() to set them */
-	mode_t file_create_mode;
+	mode_t file_create_mode, dir_create_mode;
 	gid_t file_create_gid;
 
 	char *error_string;
--- a/src/lib-storage/mailbox-list.c	Sat Feb 21 18:22:11 2009 -0500
+++ b/src/lib-storage/mailbox-list.c	Sat Feb 21 18:47:48 2009 -0500
@@ -194,6 +194,7 @@
 	list->ns = ns;
 	list->flags = flags;
 	list->file_create_mode = (mode_t)-1;
+	list->dir_create_mode = (mode_t)-1;
 	list->file_create_gid = (gid_t)-1;
 
 	/* copy settings */
@@ -289,10 +290,11 @@
 	}
 
 	list->file_create_mode = st.st_mode & 0666;
+	list->dir_create_mode = st.st_mode & 0777;
 	if (S_ISDIR(st.st_mode) && (st.st_mode & S_ISGID) != 0) {
 		/* directory's GID is used automatically for new files */
 		list->file_create_gid = (gid_t)-1;
-	} else if ((st.st_mode & 0060) == 0) {
+	} else if ((st.st_mode & 0070) == 0) {
 		/* group doesn't have any permissions, so don't bother
 		   changing it */
 		list->file_create_gid = (gid_t)-1;
@@ -306,7 +308,7 @@
 	if ((list->flags & MAILBOX_LIST_FLAG_DEBUG) != 0 && name == NULL) {
 		i_info("Namespace %s: Using permissions from %s: "
 		       "mode=0%o gid=%ld", list->ns->prefix, path,
-		       (int)list->file_create_mode,
+		       (int)list->dir_create_mode,
 		       list->file_create_gid == (gid_t)-1 ? -1L :
 		       (long)list->file_create_gid);
 	}
@@ -322,13 +324,7 @@
 	mode_t mode;
 
 	mailbox_list_get_permissions(list, name, &mode, gid_r);
-
-	/* add the execute bit if either read or write bit is set */
-	if ((mode & 0600) != 0) mode |= 0100;
-	if ((mode & 0060) != 0) mode |= 0010;
-	if ((mode & 0006) != 0) mode |= 0001;
-
-	*mode_r = mode;
+	*mode_r = list->dir_create_mode;
 }
 
 bool mailbox_list_is_valid_pattern(struct mailbox_list *list,