From 55a14bce15b9f44441b5f56616d73651a294d770 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 15 Jul 2010 13:42:33 +0100 Subject: [PATCH] Added mail_temp_dir setting, used by deliver and lmtp for creating temp mail files. --- src/lda/main.c | 38 +------------------------ src/lib-storage/mail-storage-settings.c | 2 ++ src/lib-storage/mail-storage-settings.h | 1 + src/lib-storage/mail-user.c | 34 ++++------------------ src/lib-storage/mail-user.h | 8 +++--- src/lmtp/client.c | 2 +- src/lmtp/client.h | 3 +- src/lmtp/commands.c | 2 +- src/lmtp/lmtp-settings.c | 6 +++- src/lmtp/lmtp-settings.h | 4 ++- src/plugins/quota/quota-fs.c | 14 --------- 11 files changed, 26 insertions(+), 88 deletions(-) diff --git a/src/lda/main.c b/src/lda/main.c index 69c6b9db4b..f37a0d30e4 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -85,51 +85,15 @@ static const char *address_sanitize(const char *address) return ret; } -static int deliver_create_dir(struct mail_user *user, const char *dir) -{ - struct mail_namespace *ns; - const char *origin; - mode_t mode; - gid_t gid; - - ns = mail_namespace_find_inbox(user->namespaces); - if (ns == NULL) - ns = user->namespaces; - - mailbox_list_get_dir_permissions(ns->list, NULL, &mode, &gid, &origin); - if (mkdir_parents_chgrp(dir, mode, gid, origin) == 0) { - return 0; - } else if (errno == EACCES) { - i_error("%s", eacces_error_get_creating("mkdir_parents_chown", - dir)); - return -1; - } else { - i_error("mkdir_parents_chown(%s, gid=%s) failed: %m", - dir, dec2str(gid)); - return -1; - } -} - static int seekable_fd_callback(const char **path_r, void *context) { struct mail_deliver_context *ctx = context; - const char *dir, *p; string_t *path; int fd; path = t_str_new(128); - str_append(path, mail_user_get_temp_prefix(ctx->dest_user)); + mail_user_set_get_temp_prefix(path, ctx->dest_user->set); fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1); - if (fd == -1 && errno == ENOENT) { - dir = str_c(path); - p = strrchr(dir, '/'); - if (p != NULL) { - dir = t_strdup_until(dir, p); - if (deliver_create_dir(ctx->dest_user, dir) < 0) - return -1; - fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1); - } - } if (fd == -1) { i_error("safe_mkstemp(%s) failed: %m", str_c(path)); return -1; diff --git a/src/lib-storage/mail-storage-settings.c b/src/lib-storage/mail-storage-settings.c index d67df15623..21db987eee 100644 --- a/src/lib-storage/mail-storage-settings.c +++ b/src/lib-storage/mail-storage-settings.c @@ -141,6 +141,7 @@ const struct setting_parser_info mail_namespace_setting_parser_info = { static const struct setting_define mail_user_setting_defines[] = { DEF(SET_STR, base_dir), DEF(SET_STR, auth_socket_path), + DEF(SET_STR, mail_temp_dir), DEF(SET_STR, mail_uid), DEF(SET_STR, mail_gid), @@ -169,6 +170,7 @@ static const struct setting_define mail_user_setting_defines[] = { static const struct mail_user_settings mail_user_default_settings = { .base_dir = PKG_RUNDIR, .auth_socket_path = "auth-userdb", + .mail_temp_dir = "/tmp", .mail_uid = "", .mail_gid = "", diff --git a/src/lib-storage/mail-storage-settings.h b/src/lib-storage/mail-storage-settings.h index aeb6b36ef1..934d0e4f9b 100644 --- a/src/lib-storage/mail-storage-settings.h +++ b/src/lib-storage/mail-storage-settings.h @@ -53,6 +53,7 @@ struct mail_namespace_settings { struct mail_user_settings { const char *base_dir; const char *auth_socket_path; + const char *mail_temp_dir; const char *mail_uid; const char *mail_gid; diff --git a/src/lib-storage/mail-user.c b/src/lib-storage/mail-user.c index 361857408a..44a66db9b6 100644 --- a/src/lib-storage/mail-user.c +++ b/src/lib-storage/mail-user.c @@ -23,8 +23,6 @@ struct mail_user_module_register mail_user_module_register = { 0 }; struct auth_master_connection *mail_user_auth_master_conn; -static const char *mail_user_get_temp_prefix_base(struct mail_user *user); - static void mail_user_deinit_base(struct mail_user *user) { mail_namespaces_deinit(&user->namespaces); @@ -57,7 +55,6 @@ struct mail_user *mail_user_alloc(const char *username, i_panic("Settings check unexpectedly failed: %s", error); user->v.deinit = mail_user_deinit_base; - user->v.get_temp_prefix = mail_user_get_temp_prefix_base; p_array_init(&user->module_contexts, user->pool, 5); return user; } @@ -339,32 +336,13 @@ int mail_user_try_home_expand(struct mail_user *user, const char **pathp) return 0; } -static const char *mail_user_get_temp_prefix_base(struct mail_user *user) -{ - struct mail_namespace *ns; - const char *dir; - - if (user->_home != NULL) { - return t_strconcat(user->_home, "/.temp.", my_hostname, ".", - my_pid, ".", NULL); - } - - ns = mail_namespace_find_inbox(user->namespaces); - if (ns == NULL) - ns = user->namespaces; - - if (ns->storage->temp_path_prefix != NULL) - return ns->storage->temp_path_prefix; - - dir = mailbox_list_get_path(ns->list, NULL, - MAILBOX_LIST_PATH_TYPE_DIR); - return t_strconcat(dir, "/", - mailbox_list_get_temp_prefix(ns->list), NULL); -} - -const char *mail_user_get_temp_prefix(struct mail_user *user) +void mail_user_set_get_temp_prefix(string_t *dest, + const struct mail_user_settings *set) { - return user->v.get_temp_prefix(user); + str_append(dest, set->mail_temp_dir); + str_append(dest, "/dovecot."); + str_append(dest, master_service_get_name(master_service)); + str_append_c(dest, '.'); } const char *mail_user_get_anvil_userip_ident(struct mail_user *user) diff --git a/src/lib-storage/mail-user.h b/src/lib-storage/mail-user.h index 355d7eae30..894dcf8bc3 100644 --- a/src/lib-storage/mail-user.h +++ b/src/lib-storage/mail-user.h @@ -8,7 +8,6 @@ struct mail_user; struct mail_user_vfuncs { void (*deinit)(struct mail_user *user); - const char *(*get_temp_prefix)(struct mail_user *user); }; struct mail_user { @@ -89,9 +88,10 @@ void mail_user_set_home(struct mail_user *user, const char *home); successfully, 0 if there is no home directory (either user doesn't exist or has no home directory) or -1 if lookup failed. */ int mail_user_get_home(struct mail_user *user, const char **home_r); -/* Returns path + file prefix for creating a temporary file. Uses home - directory if possible, fallbacks to mail directory. */ -const char *mail_user_get_temp_prefix(struct mail_user *user); +/* Appends path + file prefix for creating a temporary file. + The file prefix doesn't contain any uniqueness. */ +void mail_user_set_get_temp_prefix(string_t *dest, + const struct mail_user_settings *set); /* Returns TRUE if plugin is loaded for the user. */ bool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module); diff --git a/src/lmtp/client.c b/src/lmtp/client.c index df7e456797..123d5d1252 100644 --- a/src/lmtp/client.c +++ b/src/lmtp/client.c @@ -163,7 +163,7 @@ static void client_read_settings(struct client *client) &set_parser, &error) < 0) i_fatal("%s", error); - lmtp_settings_dup(set_parser, client->pool, + lmtp_settings_dup(set_parser, client->pool, &client->user_set, &client->lmtp_set, &client->set); } diff --git a/src/lmtp/client.h b/src/lmtp/client.h index 522fe91fe2..e00ba6caeb 100644 --- a/src/lmtp/client.h +++ b/src/lmtp/client.h @@ -3,7 +3,7 @@ #include "network.h" -#define CLIENT_MAIL_DATA_MAX_INMEMORY_SIZE (1024*128) +#define CLIENT_MAIL_DATA_MAX_INMEMORY_SIZE 1//(1024*128) struct mail_recipient { const char *address; @@ -45,6 +45,7 @@ struct client { const struct setting_parser_info *user_set_info; const struct lda_settings *set; const struct lmtp_settings *lmtp_set; + const struct mail_user_settings *user_set; int fd_in, fd_out; struct io *io; struct istream *input; diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index 71bff8a4b0..92486d3286 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -736,7 +736,7 @@ static int client_input_add_file(struct client *client, /* move everything to a temporary file. FIXME: it really shouldn't be in /tmp.. */ path = t_str_new(256); - str_append(path, "/tmp/dovecot.lmtp."); + mail_user_set_get_temp_prefix(path, client->user_set); fd = safe_mkstemp_hostpid(path, 0600, (uid_t)-1, (gid_t)-1); if (fd == -1) return -1; diff --git a/src/lmtp/lmtp-settings.c b/src/lmtp/lmtp-settings.c index 323322fa1a..e917593323 100644 --- a/src/lmtp/lmtp-settings.c +++ b/src/lmtp/lmtp-settings.c @@ -8,6 +8,7 @@ #include "master-service-settings.h" #include "lda-settings.h" #include "lmtp-settings.h" +#include "mail-storage-settings.h" #include #include @@ -83,12 +84,15 @@ const struct setting_parser_info lmtp_setting_parser_info = { }; void lmtp_settings_dup(const struct setting_parser_context *set_parser, - pool_t pool, const struct lmtp_settings **lmtp_set_r, + pool_t pool, + const struct mail_user_settings **user_set_r, + const struct lmtp_settings **lmtp_set_r, const struct lda_settings **lda_set_r) { void **sets; sets = settings_parser_get_list(set_parser) + 1; + *user_set_r = settings_dup(&mail_user_setting_parser_info, sets[0], pool); *lda_set_r = settings_dup(&lda_setting_parser_info, sets[1], pool); *lmtp_set_r = settings_dup(&lmtp_setting_parser_info, sets[2], pool); } diff --git a/src/lmtp/lmtp-settings.h b/src/lmtp/lmtp-settings.h index d57f92ec4d..b0e859631d 100644 --- a/src/lmtp/lmtp-settings.h +++ b/src/lmtp/lmtp-settings.h @@ -11,7 +11,9 @@ struct lmtp_settings { extern const struct setting_parser_info lmtp_setting_parser_info; void lmtp_settings_dup(const struct setting_parser_context *set_parser, - pool_t pool, const struct lmtp_settings **lmtp_set_r, + pool_t pool, + const struct mail_user_settings **user_set_r, + const struct lmtp_settings **lmtp_set_r, const struct lda_settings **lda_set_r); #endif diff --git a/src/plugins/quota/quota-fs.c b/src/plugins/quota/quota-fs.c index 32376c7553..1ebb64debb 100644 --- a/src/plugins/quota/quota-fs.c +++ b/src/plugins/quota/quota-fs.c @@ -92,17 +92,6 @@ static struct quota_root *fs_quota_alloc(void) return &root->root; } -static const char * -quota_fs_mail_user_get_temp_prefix(struct mail_user *user ATTR_UNUSED) -{ - /* when filesystem quota is used, temp files will decrease the user's - quota if they're written under user's home. for example with lda - large mails are also first written to this temp directory, so if it - were in user's home, the user would always have two have twice - as much space available as necessary. */ - return t_strconcat("/tmp/dovecot.", my_pid, ".", NULL); -} - static int fs_quota_init(struct quota_root *_root, const char *args) { struct fs_quota_root *root = (struct fs_quota_root *)_root; @@ -128,9 +117,6 @@ static int fs_quota_init(struct quota_root *_root, const char *args) return -1; } } - - _root->quota->user->v.get_temp_prefix = - quota_fs_mail_user_get_temp_prefix; return 0; } -- 2.47.3