Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8205:b62042ddb79e HEAD
Squat: Create files with the correct mode and group.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 22 Sep 2008 21:04:38 +0300 |
parents | f643f8c0e29d |
children | 53ad035a2d0b |
files | src/plugins/fts-squat/fts-backend-squat.c src/plugins/fts-squat/squat-test.c src/plugins/fts-squat/squat-trie-private.h src/plugins/fts-squat/squat-trie.c src/plugins/fts-squat/squat-trie.h src/plugins/fts-squat/squat-uidlist.c |
diffstat | 6 files changed, 47 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/fts-squat/fts-backend-squat.c Sat Sep 20 19:30:07 2008 +0300 +++ b/src/plugins/fts-squat/fts-backend-squat.c Mon Sep 22 21:04:38 2008 +0300 @@ -78,7 +78,8 @@ backend->trie = squat_trie_init(t_strconcat(path, "/"SQUAT_FILE_PREFIX, NULL), status.uidvalidity, storage->lock_method, - flags); + flags, box->file_create_mode, + box->file_create_gid); env = getenv("FTS_SQUAT"); if (env != NULL)
--- a/src/plugins/fts-squat/squat-test.c Sat Sep 20 19:30:07 2008 +0300 +++ b/src/plugins/fts-squat/squat-test.c Mon Sep 22 21:04:38 2008 +0300 @@ -56,7 +56,7 @@ (void)unlink(trie_path); (void)unlink(uidlist_path); trie = squat_trie_init(trie_path, time(NULL), - FILE_LOCK_METHOD_FCNTL, FALSE); + FILE_LOCK_METHOD_FCNTL, FALSE, 0600, (gid_t)-1); clock_start = clock(); gettimeofday(&tv_start, NULL);
--- a/src/plugins/fts-squat/squat-trie-private.h Sat Sep 20 19:30:07 2008 +0300 +++ b/src/plugins/fts-squat/squat-trie-private.h Mon Sep 22 21:04:38 2008 +0300 @@ -118,6 +118,8 @@ enum squat_index_flags flags; enum file_lock_method lock_method; + mode_t create_mode; + gid_t create_gid; uint32_t uidvalidity; char *path; @@ -184,6 +186,7 @@ return value; } +int squat_trie_create_fd(struct squat_trie *trie, const char *path, int flags); void squat_trie_delete(struct squat_trie *trie); #endif
--- a/src/plugins/fts-squat/squat-trie.c Sat Sep 20 19:30:07 2008 +0300 +++ b/src/plugins/fts-squat/squat-trie.c Mon Sep 22 21:04:38 2008 +0300 @@ -128,7 +128,8 @@ struct squat_trie * squat_trie_init(const char *path, uint32_t uidvalidity, - enum file_lock_method lock_method, enum squat_index_flags flags) + enum file_lock_method lock_method, enum squat_index_flags flags, + mode_t mode, gid_t gid) { struct squat_trie *trie; @@ -139,6 +140,8 @@ trie->lock_method = lock_method; trie->uidvalidity = uidvalidity; trie->flags = flags; + trie->create_mode = mode; + trie->create_gid = gid; squat_trie_normalize_map_build(trie); trie->dotlock_set.use_excl_lock = @@ -1532,6 +1535,28 @@ node_read_children(trie, &trie->root, 1); } +int squat_trie_create_fd(struct squat_trie *trie, const char *path, int flags) +{ + mode_t old_mask; + int fd; + + old_mask = umask(0); + fd = open(path, O_RDWR | O_CREAT | flags, trie->create_mode); + umask(old_mask); + if (fd == -1) { + i_error("creat(%s) failed: %m", path); + return -1; + } + if (trie->create_gid != (gid_t)-1) { + if (fchown(fd, (uid_t)-1, trie->create_gid) < 0) { + i_error("fchown(%s, -1, %ld) failed: %m", + path, (long)trie->create_gid); + return -1; + } + } + return fd; +} + int squat_trie_build_init(struct squat_trie *trie, uint32_t *last_uid_r, struct squat_trie_build_context **ctx_r) { @@ -1539,11 +1564,10 @@ struct squat_uidlist_build_context *uidlist_build_ctx; if (trie->fd == -1) { - trie->fd = open(trie->path, O_RDWR | O_CREAT, 0600); - if (trie->fd == -1) { - i_error("creat(%s) failed: %m", trie->path); + trie->fd = squat_trie_create_fd(trie, trie->path, 0); + if (trie->fd == -1) return -1; - } + if (trie->file_cache != NULL) file_cache_set_fd(trie->file_cache, trie->fd); i_assert(trie->locked_file_size == 0); @@ -1593,11 +1617,10 @@ ctx->compress_nodes = TRUE; path = t_strconcat(trie->path, ".tmp", NULL); - fd = open(path, O_RDWR | O_CREAT, 0600); - if (fd == -1) { - i_error("creat(%s) failed: %m", path); + fd = squat_trie_create_fd(trie, path, O_TRUNC); + if (fd == -1) return -1; - } + if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) { ret = file_wait_lock(fd, path, F_WRLCK, trie->lock_method,
--- a/src/plugins/fts-squat/squat-trie.h Sat Sep 20 19:30:07 2008 +0300 +++ b/src/plugins/fts-squat/squat-trie.h Mon Sep 22 21:04:38 2008 +0300 @@ -20,7 +20,7 @@ struct squat_trie * squat_trie_init(const char *path, uint32_t uidvalidity, enum file_lock_method lock_method, - enum squat_index_flags flags); + enum squat_index_flags flags, mode_t mode, gid_t gid); void squat_trie_deinit(struct squat_trie **trie); void squat_trie_set_partial_len(struct squat_trie *trie, unsigned int len);
--- a/src/plugins/fts-squat/squat-uidlist.c Sat Sep 20 19:30:07 2008 +0300 +++ b/src/plugins/fts-squat/squat-uidlist.c Mon Sep 22 21:04:38 2008 +0300 @@ -638,11 +638,10 @@ return -1; squat_uidlist_close(uidlist); - uidlist->fd = open(uidlist->path, O_RDWR | O_CREAT, 0600); - if (uidlist->fd == -1) { - i_error("open(%s) failed: %m", uidlist->path); + uidlist->fd = squat_trie_create_fd(uidlist->trie, + uidlist->path, 0); + if (uidlist->fd == -1) return -1; - } } return 1; } @@ -652,11 +651,10 @@ int ret; if (uidlist->fd == -1) { - uidlist->fd = open(uidlist->path, O_RDWR | O_CREAT, 0600); - if (uidlist->fd == -1) { - i_error("creat(%s) failed: %m", uidlist->path); + uidlist->fd = squat_trie_create_fd(uidlist->trie, + uidlist->path, 0); + if (uidlist->fd == -1) return -1; - } } if (squat_uidlist_lock(uidlist) <= 0) return -1; @@ -920,11 +918,9 @@ return -1; temp_path = t_strconcat(build_ctx->uidlist->path, ".tmp", NULL); - fd = open(temp_path, O_RDWR | O_TRUNC | O_CREAT, 0600); - if (fd < 0) { - i_error("open(%s) failed: %m", temp_path); + fd = squat_trie_create_fd(build_ctx->uidlist->trie, temp_path, O_TRUNC); + if (fd == -1) return -1; - } ctx = i_new(struct squat_uidlist_rebuild_context, 1); ctx->uidlist = build_ctx->uidlist;