[dovecot-cvs] dovecot/src/lib-index mail-cache-compress.c, 1.26, 1.27 mail-index.c, 1.164, 1.165 mail-transaction-log.c, 1.72, 1.73

cras at dovecot.org cras at dovecot.org
Fri Nov 12 00:24:10 EET 2004


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv13967/lib-index

Modified Files:
	mail-cache-compress.c mail-index.c mail-transaction-log.c 
Log Message:
dovecot-shared file was supposed to show permissions/gid for files created
in the maildir, but it didn't work for indexes.



Index: mail-cache-compress.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-compress.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mail-cache-compress.c	11 Nov 2004 22:01:39 -0000	1.26
+++ mail-cache-compress.c	11 Nov 2004 22:24:08 -0000	1.27
@@ -7,6 +7,8 @@
 #include "file-set-size.h"
 #include "mail-cache-private.h"
 
+#include <sys/stat.h>
+
 struct mail_cache_copy_context {
 	int new_msg;
 	buffer_t *buffer, *field_seen;
@@ -234,6 +236,7 @@
 
 int mail_cache_compress(struct mail_cache *cache, struct mail_index_view *view)
 {
+        mode_t old_mask;
 	int fd, ret, locked;
 
 	if ((ret = mail_cache_lock(cache)) < 0)
@@ -250,16 +253,25 @@
 	i_warning("Compressing cache file %s", cache->filepath);
 #endif
 
+	old_mask = umask(cache->index->mode ^ 0666);
 	fd = file_dotlock_open(cache->filepath, NULL, NULL,
 			       MAIL_CACHE_LOCK_TIMEOUT,
 			       MAIL_CACHE_LOCK_CHANGE_TIMEOUT,
 			       MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT, NULL, NULL);
+	umask(old_mask);
+
 	if (fd == -1) {
 		mail_cache_set_syscall_error(cache, "file_dotlock_open()");
 		if (locked) mail_cache_unlock(cache);
 		return -1;
 	}
 
+	if (cache->index->gid != (gid_t)-1 &&
+	    fchown(fd, (uid_t)-1, cache->index->gid) < 0) {
+		mail_cache_set_syscall_error(cache, "fchown()");
+		return -1;
+	}
+
 	// FIXME: check that cache file wasn't just recreated
 
 	ret = 0;

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- mail-index.c	11 Nov 2004 22:01:39 -0000	1.164
+++ mail-index.c	11 Nov 2004 22:24:08 -0000	1.165
@@ -853,16 +853,18 @@
 
 int mail_index_create_tmp_file(struct mail_index *index, const char **path_r)
 {
+        mode_t old_mask;
 	const char *path;
 	int fd;
 
 	path = *path_r = t_strconcat(index->filepath, ".tmp", NULL);
+	old_mask = umask(0);
 	fd = open(path, O_RDWR|O_CREAT|O_TRUNC, index->mode);
+	umask(old_mask);
 	if (fd == -1)
 		return mail_index_file_set_syscall_error(index, path, "open()");
 
-	if (index->gid != (gid_t)-1 &&
-	    fchown(index->fd, (uid_t)-1, index->gid) < 0) {
+	if (index->gid != (gid_t)-1 && fchown(fd, (uid_t)-1, index->gid) < 0) {
 		mail_index_file_set_syscall_error(index, path, "fchown()");
 		return -1;
 	}

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- mail-transaction-log.c	11 Nov 2004 22:01:39 -0000	1.72
+++ mail-transaction-log.c	11 Nov 2004 22:24:08 -0000	1.73
@@ -392,20 +392,30 @@
 mail_transaction_log_file_create(struct mail_transaction_log *log,
 				 const char *path, dev_t dev, ino_t ino)
 {
+        mode_t old_mask;
 	int fd, fd2;
 
 	/* With dotlocking we might already have path.lock created, so this
 	   filename has to be different. */
+	old_mask = umask(log->index->mode ^ 0666);
 	fd = file_dotlock_open(path, NULL, LOG_NEW_DOTLOCK_SUFFIX,
 			       LOG_DOTLOCK_TIMEOUT,
 			       LOG_DOTLOCK_STALE_TIMEOUT,
 			       LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT, NULL, NULL);
+	umask(old_mask);
+
 	if (fd == -1) {
 		mail_index_file_set_syscall_error(log->index, path,
 						  "file_dotlock_open()");
 		return -1;
 	}
 
+	if (log->index->gid != (gid_t)-1 &&
+	    fchown(fd, (uid_t)-1, log->index->gid) < 0) {
+		mail_index_file_set_syscall_error(log->index, path, "fchown()");
+		return -1;
+	}
+
 	fd2 = mail_transaction_log_file_create2(log, path, fd, dev, ino);
 	if (fd2 < 0) {
 		(void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX, fd);



More information about the dovecot-cvs mailing list