]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added mail_temp_dir setting, used by deliver and lmtp for creating temp mail files.
authorTimo Sirainen <tss@iki.fi>
Thu, 15 Jul 2010 12:42:33 +0000 (13:42 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 15 Jul 2010 12:42:33 +0000 (13:42 +0100)
src/lda/main.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h
src/lib-storage/mail-user.c
src/lib-storage/mail-user.h
src/lmtp/client.c
src/lmtp/client.h
src/lmtp/commands.c
src/lmtp/lmtp-settings.c
src/lmtp/lmtp-settings.h
src/plugins/quota/quota-fs.c

index 69c6b9db4b222be8e631eac3a8dd56126e68ee25..f37a0d30e47cc113a0b0a57dfbf34928b7240721 100644 (file)
@@ -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;
index d67df15623541412c948cdd9771c01316680778d..21db987eeee919346dde810efcc1a36f94e2e7b7 100644 (file)
@@ -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 = "",
index aeb6b36ef12be98f27903353059cf58674c7b843..934d0e4f9b2fe37ec9b20981b2d65a1728e184c3 100644 (file)
@@ -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;
index 361857408a7ce3390fc6bd4081397e2f4940afc5..44a66db9b6650d8534745fb29cd6bc69b5aa568b 100644 (file)
@@ -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)
index 355d7eae303c7376ad44376a393bf0c107db24da..894dcf8bc3facc1561e6d8ddaa47836de897018b 100644 (file)
@@ -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);
index df7e4567978f99d623ae182af4790e1426ecd26d..123d5d12525551add49e3780e7883332dc2e6a85 100644 (file)
@@ -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);
 }
 
index 522fe91fe21af8526ad36d8254f557d60b0978f2..e00ba6caeb90133a3c1c3782a7c14873f27a68c7 100644 (file)
@@ -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;
index 71bff8a4b088a9ad56ac5994f39b616b6657a4e5..92486d328698de9344149303aee98d3bad7e8bf0 100644 (file)
@@ -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;
index 323322fa1a6b903351b6d84f34b5c85a121c32ea..e9175933231d67c28896597f0f307a9ef3285ecb 100644 (file)
@@ -8,6 +8,7 @@
 #include "master-service-settings.h"
 #include "lda-settings.h"
 #include "lmtp-settings.h"
+#include "mail-storage-settings.h"
 
 #include <stddef.h>
 #include <unistd.h>
@@ -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);
 }
index d57f92ec4da1122ce3dc3ff0dd5071836a00496d..b0e859631d8982456890903f74572a20bfa74812 100644 (file)
@@ -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
index 32376c7553eb3c876cd4a1a41205f31be50c0521..1ebb64debbd09093e4ae5e1d38269d5e8dcbd422 100644 (file)
@@ -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;
 }