Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5033:612b5c358d2e HEAD
Saved mails and dovecot-keywords file didn't set the group from
dovecot-shared file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 18 Jan 2007 19:20:49 +0200 |
parents | b6b2b1d98f42 |
children | 1b28e0434d85 |
files | src/lib-storage/index/maildir/maildir-keywords.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/maildir/maildir-storage.h src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/maildir/maildir-util.c |
diffstat | 5 files changed, 84 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-keywords.c Thu Jan 18 18:57:43 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-keywords.c Thu Jan 18 19:20:49 2007 +0200 @@ -254,13 +254,62 @@ return idx >= count ? NULL : keywords[idx]; } +static int maildir_keywords_write_fd(struct maildir_keywords *mk, + const char *path, int fd) +{ + struct maildir_mailbox *mbox = mk->mbox; + const char *const *keywords; + unsigned int i, count; + string_t *str; + struct stat st; + + str = t_str_new(256); + keywords = array_get(&mk->list, &count); + for (i = 0; i < count; i++) { + if (keywords[i] != NULL) + str_printfa(str, "%u %s\n", i, keywords[i]); + } + if (write_full(fd, str_data(str), str_len(str)) < 0) { + mail_storage_set_critical(STORAGE(mbox->storage), + "write_full(%s) failed: %m", path); + return -1; + } + + if (fstat(fd, &st) < 0) { + mail_storage_set_critical(STORAGE(mbox->storage), + "fstat(%s) failed: %m", path); + return -1; + } + + if (st.st_gid != mbox->mail_create_gid && + mbox->mail_create_gid != (gid_t)-1) { + if (fchown(fd, (uid_t)-1, mbox->mail_create_gid) < 0) { + mail_storage_set_critical(STORAGE(mbox->storage), + "fchown(%s) failed: %m", path); + } + } + + /* mtime must grow every time */ + if (st.st_mtime <= mk->synced_mtime) { + struct utimbuf ut; + + mk->synced_mtime = ioloop_time <= mk->synced_mtime ? + mk->synced_mtime + 1 : ioloop_time; + ut.actime = ioloop_time; + ut.modtime = mk->synced_mtime; + if (utime(path, &ut) < 0) { + mail_storage_set_critical(STORAGE(mbox->storage), + "utime(%s) failed: %m", path); + return -1; + } + } + return 0; +} + static int maildir_keywords_commit(struct maildir_keywords *mk) { struct dotlock *dotlock; - const char *lock_path, *const *keywords; - unsigned int i, count; - struct utimbuf ut; - string_t *str; + const char *lock_path; mode_t old_mask; int fd; @@ -272,7 +321,6 @@ /* we could just create the temp file directly, but doing it this ways avoids potential problems with overwriting contents in malicious symlinks */ - t_push(); lock_path = t_strconcat(mk->path, ".lock", NULL); (void)unlink(lock_path); old_mask = umask(0777 & ~mk->mbox->mail_create_mode); @@ -282,44 +330,21 @@ if (fd == -1) { mail_storage_set_critical(STORAGE(mk->mbox->storage), "file_dotlock_open(%s) failed: %m", mk->path); - t_pop(); return -1; } - str = t_str_new(256); - keywords = array_get(&mk->list, &count); - for (i = 0; i < count; i++) { - if (keywords[i] != NULL) - str_printfa(str, "%u %s\n", i, keywords[i]); - } - if (write_full(fd, str_data(str), str_len(str)) < 0) { - mail_storage_set_critical(STORAGE(mk->mbox->storage), - "write_full(%s) failed: %m", mk->path); - (void)file_dotlock_delete(&dotlock); - t_pop(); - return -1; - } - - /* mtime must grow every time */ - mk->synced_mtime = ioloop_time <= mk->synced_mtime ? - mk->synced_mtime + 1 : ioloop_time; - ut.actime = ioloop_time; - ut.modtime = mk->synced_mtime; - if (utime(lock_path, &ut) < 0) { - mail_storage_set_critical(STORAGE(mk->mbox->storage), - "utime(%s) failed: %m", lock_path); + if (maildir_keywords_write_fd(mk, lock_path, fd) < 0) { + file_dotlock_delete(&dotlock); return -1; } if (file_dotlock_replace(&dotlock, 0) < 0) { mail_storage_set_critical(STORAGE(mk->mbox->storage), "file_dotlock_replace(%s) failed: %m", mk->path); - t_pop(); return -1; } mk->changed = FALSE; - t_pop(); return 0; } @@ -339,7 +364,10 @@ void maildir_keywords_sync_deinit(struct maildir_keywords_sync_ctx *ctx) { - maildir_keywords_commit(ctx->mk); + t_push(); + (void)maildir_keywords_commit(ctx->mk); + t_pop(); + array_free(&ctx->idx_to_chr); i_free(ctx); }
--- a/src/lib-storage/index/maildir/maildir-storage.c Thu Jan 18 18:57:43 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Thu Jan 18 19:20:49 2007 +0200 @@ -432,10 +432,12 @@ mbox->uidlist = maildir_uidlist_init(mbox); mbox->keywords = maildir_keywords_init(mbox); - if (!shared) + if (!shared) { mbox->mail_create_mode = 0600; - else { + mbox->mail_create_gid = (gid_t)-1; + } else { mbox->mail_create_mode = st.st_mode & 0666; + mbox->mail_create_gid = st.st_gid; mbox->private_flags_mask = MAIL_SEEN; }
--- a/src/lib-storage/index/maildir/maildir-storage.h Thu Jan 18 18:57:43 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.h Thu Jan 18 19:20:49 2007 +0200 @@ -77,7 +77,8 @@ time_t dirty_cur_time; enum maildir_dirty_flags last_dirty_flags; - mode_t mail_create_mode; + mode_t mail_create_mode; + gid_t mail_create_gid; unsigned int private_flags_mask; unsigned int syncing_commit:1;
--- a/src/lib-storage/index/maildir/maildir-uidlist.c Thu Jan 18 18:57:43 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-uidlist.c Thu Jan 18 19:20:49 2007 +0200 @@ -82,6 +82,7 @@ static int maildir_uidlist_lock_timeout(struct maildir_uidlist *uidlist, bool nonblock) { + struct maildir_mailbox *mbox = uidlist->mbox; const char *path; mode_t old_mask; int fd; @@ -91,26 +92,32 @@ return 1; } - path = t_strconcat(uidlist->mbox->control_dir, - "/" MAILDIR_UIDLIST_NAME, NULL); - old_mask = umask(0777 & ~uidlist->mbox->mail_create_mode); + path = t_strconcat(mbox->control_dir, "/" MAILDIR_UIDLIST_NAME, NULL); + old_mask = umask(0777 & ~mbox->mail_create_mode); fd = file_dotlock_open(&uidlist->dotlock_settings, path, nonblock ? DOTLOCK_CREATE_FLAG_NONBLOCK : 0, &uidlist->dotlock); umask(old_mask); if (fd == -1) { if (errno == EAGAIN) { - mail_storage_set_error(STORAGE(uidlist->mbox->storage), + mail_storage_set_error(STORAGE(mbox->storage), "Timeout while waiting for lock"); - STORAGE(uidlist->mbox->storage)->temporary_error = TRUE; + STORAGE(mbox->storage)->temporary_error = TRUE; return 0; } - mail_storage_set_critical(STORAGE(uidlist->mbox->storage), + mail_storage_set_critical(STORAGE(mbox->storage), "file_dotlock_open(%s) failed: %m", path); return -1; } uidlist->lock_fd = fd; + if (mbox->mail_create_gid != (gid_t)-1) { + if (fchown(fd, (uid_t)-1, mbox->mail_create_gid) < 0) { + mail_storage_set_critical(STORAGE(mbox->storage), + "fchown(%s) failed: %m", path); + } + } + /* our view of uidlist must be up-to-date if we plan on changing it */ if (maildir_uidlist_update(uidlist) < 0) return -1;
--- a/src/lib-storage/index/maildir/maildir-util.c Thu Jan 18 18:57:43 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-util.c Thu Jan 18 19:20:49 2007 +0200 @@ -132,6 +132,12 @@ mail_storage_set_critical(STORAGE(mbox->storage), "open(%s) failed: %m", path); } + } else if (st.st_gid != mbox->mail_create_gid && + mbox->mail_create_gid != (gid_t)-1) { + if (fchown(fd, (uid_t)-1, mbox->mail_create_gid) < 0) { + mail_storage_set_critical(STORAGE(mbox->storage), + "fchown(%s) failed: %m", path); + } } pool_unref(pool);