dovecot-2.2: mbox: Fixed getting filesystem permissions when par...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 29 17:55:53 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/83695d6d41aa
changeset: 15288:83695d6d41aa
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Oct 02 21:56:09 2012 +0300
description:
mbox: Fixed getting filesystem permissions when parent dir has setgid-bit enabled.

diffstat:

 src/lib-storage/mailbox-list.c |  17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r 38727d3e90ec -r 83695d6d41aa src/lib-storage/mailbox-list.c
--- 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) {


More information about the dovecot-cvs mailing list