Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6776:47c746a769ba HEAD
Create dbox files using mailbox.file_create_mode.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 11 Nov 2007 17:43:56 +0200 |
parents | b6135e6a5ff2 |
children | 186b164a9579 |
files | src/lib-storage/index/dbox/dbox-file.c src/lib-storage/index/dbox/dbox-file.h src/lib-storage/index/dbox/dbox-index.c |
diffstat | 3 files changed, 47 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-file.c Sun Nov 11 17:21:19 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-file.c Sun Nov 11 17:43:56 2007 +0200 @@ -431,6 +431,21 @@ dbox_file_read_header(file); } +int dbox_create_fd(struct dbox_mailbox *mbox, const char *path) +{ + mode_t old_mask; + int fd; + + old_mask = umask(0777 & ~mbox->ibox.box.file_create_mode); + fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0777); + umask(old_mask); + if (fd == -1) { + mail_storage_set_critical(mbox->ibox.box.storage, + "open(%s, O_CREAT) failed: %m", path); + } + return fd; +} + static int dbox_file_create(struct dbox_file *file) { string_t *hdr; @@ -442,12 +457,9 @@ file->current_path = i_strdup_printf("%s/%s", file->mbox->path, file->fname); } - file->fd = open(file->current_path, O_RDWR | O_CREAT | O_TRUNC, 0600); - if (file->fd == -1) { - mail_storage_set_critical(file->mbox->ibox.box.storage, - "open(%s, O_CREAT) failed: %m", file->current_path); + file->fd = dbox_create_fd(file->mbox, file->current_path); + if (file->fd == -1) return -1; - } file->output = o_stream_create_fd_file(file->fd, 0, FALSE); hdr = t_str_new(128);
--- a/src/lib-storage/index/dbox/dbox-file.h Sun Nov 11 17:21:19 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-file.h Sun Nov 11 17:43:56 2007 +0200 @@ -224,6 +224,7 @@ void dbox_msg_header_fill(struct dbox_message_header *dbox_msg_hdr, uint32_t uid, uoff_t message_size); +int dbox_create_fd(struct dbox_mailbox *mbox, const char *path); void dbox_file_set_syscall_error(struct dbox_file *file, const char *function); #endif
--- a/src/lib-storage/index/dbox/dbox-index.c Sun Nov 11 17:21:19 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-index.c Sun Nov 11 17:43:56 2007 +0200 @@ -517,6 +517,30 @@ str_append_c(str, '\n'); } +static int dbox_index_create_fd(struct dbox_mailbox *mbox, string_t *temp_path, + bool locked) +{ + mode_t old_mask; + int fd; + + if (locked) { + str_append(temp_path, ".tmp"); + return dbox_create_fd(mbox, str_c(temp_path)); + } + + str_append_c(temp_path, '.'); + old_mask = umask(0777 & ~mbox->ibox.box.file_create_mode); + fd = safe_mkstemp_hostpid(temp_path, 0777, (uid_t)-1, (gid_t)-1); + umask(old_mask); + + if (fd == -1) { + mail_storage_set_critical(mbox->ibox.box.storage, + "safe_mkstemp_hostpid(%s) failed: %m", + str_c(temp_path)); + } + return fd; +} + static int dbox_index_recreate(struct dbox_index *index, bool locked) { struct mail_storage *storage = &index->mbox->storage->storage; @@ -530,27 +554,11 @@ t_push(); temp_path = t_str_new(256); str_append(temp_path, index->path); - if (locked) { - str_append(temp_path, ".tmp"); - fd = open(str_c(temp_path), O_RDWR | O_CREAT | O_TRUNC, 0600); - if (fd == -1) { - mail_storage_set_critical(storage, - "open(%s, O_CREAT) failed: %m", - str_c(temp_path)); - t_pop(); - return -1; - } - } else { - str_append_c(temp_path, '.'); - fd = safe_mkstemp_hostpid(temp_path, 0600, - (uid_t)-1, (gid_t)-1); - if (fd == -1) { - mail_storage_set_critical(storage, - "safe_mkstemp_hostpid(%s) failed: %m", - str_c(temp_path)); - t_pop(); - return -1; - } + + fd = dbox_index_create_fd(index->mbox, temp_path, locked); + if (fd == -1) { + t_pop(); + return -1; } str = t_str_new(256);