dovecot-1.2: acl+mbox: Create also temp acllist file to control ...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jul 8 05:37:48 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/bf4f542ec6df
changeset: 9207:bf4f542ec6df
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jul 07 22:37:42 2009 -0400
description:
acl+mbox: Create also temp acllist file to control directory.

diffstat:

1 file changed, 24 insertions(+), 28 deletions(-)
src/plugins/acl/acl-backend-vfile-acllist.c |   52 ++++++++++++---------------

diffs (103 lines):

diff -r 644b956f5f5a -r bf4f542ec6df src/plugins/acl/acl-backend-vfile-acllist.c
--- a/src/plugins/acl/acl-backend-vfile-acllist.c	Tue Jul 07 22:35:50 2009 -0400
+++ b/src/plugins/acl/acl-backend-vfile-acllist.c	Tue Jul 07 22:37:42 2009 -0400
@@ -38,7 +38,7 @@ acllist_clear(struct acl_backend_vfile *
 	}
 }
 
-static const char *acl_list_get_path(struct acl_backend_vfile *backend)
+static const char *acl_list_get_root_dir(struct acl_backend_vfile *backend)
 {
 	struct mail_storage *storage;
 	const char *rootdir, *maildir;
@@ -61,7 +61,13 @@ static const char *acl_list_get_path(str
 					NULL, MAILBOX_LIST_PATH_TYPE_CONTROL);
 		}
 	}
-	return t_strconcat(rootdir, "/"ACLLIST_FILENAME, NULL);
+	return rootdir;
+}
+
+static const char *acl_list_get_path(struct acl_backend_vfile *backend)
+{
+	return t_strconcat(acl_list_get_root_dir(backend),
+			   "/"ACLLIST_FILENAME, NULL);
 }
 
 static int acl_backend_vfile_acllist_read(struct acl_backend_vfile *backend)
@@ -189,34 +195,13 @@ acllist_append(struct acl_backend_vfile 
 }
 
 static int
-acllist_rename(struct acl_backend_vfile *backend, const char *temp_path)
-{
-	const char *acllist_path;
-
-	acllist_path = acl_list_get_path(backend);
-	if (rename(temp_path, acllist_path) == 0)
-		return 0;
-
-	if (errno == ENOENT) {
-		if (mailbox_list_create_parent_dir(backend->backend.list, NULL,
-						   acllist_path) < 0)
-			return -1;
-		if (rename(temp_path, acllist_path) == 0)
-			return 0;
-	}
-
-	i_error("rename(%s, %s) failed: %m", temp_path, acllist_path);
-	return -1;
-}
-
-static int
 acl_backend_vfile_acllist_try_rebuild(struct acl_backend_vfile *backend)
 {
 	struct mailbox_list *list = backend->backend.list;
 	struct mail_namespace *ns;
 	struct mailbox_list_iterate_context *iter;
 	const struct mailbox_info *info;
-	const char *rootdir, *origin;
+	const char *rootdir, *origin, *acllist_path;
 	struct ostream *output;
 	struct stat st;
 	string_t *path;
@@ -226,8 +211,7 @@ acl_backend_vfile_acllist_try_rebuild(st
 
 	i_assert(!backend->rebuilding_acllist);
 
-	rootdir = mailbox_list_get_path(list, NULL,
-					MAILBOX_LIST_PATH_TYPE_DIR);
+	rootdir = acl_list_get_root_dir(backend);
 	if (rootdir == NULL)
 		return 0;
 
@@ -245,6 +229,12 @@ acl_backend_vfile_acllist_try_rebuild(st
 	   the file at the same time the result should be the same. */
 	mailbox_list_get_permissions(list, NULL, &mode, &gid, &origin);
 	fd = safe_mkstemp_group(path, mode, gid, origin);
+	if (fd == -1 && errno == ENOENT) {
+		if (mailbox_list_create_parent_dir(backend->backend.list, NULL,
+						   str_c(path)) < 0)
+			return -1;
+		fd = safe_mkstemp_group(path, mode, gid, origin);
+	}
 	if (fd == -1) {
 		if (errno == EACCES) {
 			/* Ignore silently if we can't create it */
@@ -289,8 +279,14 @@ acl_backend_vfile_acllist_try_rebuild(st
 		ret = -1;
 	}
 
-	if (ret == 0)
-		ret = acllist_rename(backend, str_c(path));
+	if (ret == 0) {
+		acllist_path = acl_list_get_path(backend);
+		if (rename(str_c(path), acllist_path) < 0) {
+			i_error("rename(%s, %s) failed: %m",
+				str_c(path), acllist_path);
+			ret = -1;
+		}
+	}
 	if (ret == 0) {
 		struct acl_user *auser = ACL_USER_CONTEXT(ns->user);
 


More information about the dovecot-cvs mailing list