dovecot-2.0: Added mail_temp_dir setting, used by deliver and lm...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Jul 15 15:42:38 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/7a6cf8dae9bf
changeset: 11822:7a6cf8dae9bf
user: Timo Sirainen <tss at iki.fi>
date: Thu Jul 15 13:42:33 2010 +0100
description:
Added mail_temp_dir setting, used by deliver and lmtp for creating temp mail files.
diffstat:
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(-)
diffs (287 lines):
diff -r 0d16970d9df3 -r 7a6cf8dae9bf src/lda/main.c
--- a/src/lda/main.c Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lda/main.c Thu Jul 15 13:42:33 2010 +0100
@@ -85,51 +85,15 @@
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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lib-storage/mail-storage-settings.c
--- a/src/lib-storage/mail-storage-settings.c Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lib-storage/mail-storage-settings.c Thu Jul 15 13:42:33 2010 +0100
@@ -141,6 +141,7 @@
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 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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lib-storage/mail-storage-settings.h
--- a/src/lib-storage/mail-storage-settings.h Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lib-storage/mail-storage-settings.h Thu Jul 15 13:42:33 2010 +0100
@@ -53,6 +53,7 @@
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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lib-storage/mail-user.c
--- a/src/lib-storage/mail-user.c Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lib-storage/mail-user.c Thu Jul 15 13:42:33 2010 +0100
@@ -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 @@
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 @@
return 0;
}
-static const char *mail_user_get_temp_prefix_base(struct mail_user *user)
+void mail_user_set_get_temp_prefix(string_t *dest,
+ const struct mail_user_settings *set)
{
- 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)
-{
- 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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lib-storage/mail-user.h
--- a/src/lib-storage/mail-user.h Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lib-storage/mail-user.h Thu Jul 15 13:42:33 2010 +0100
@@ -8,7 +8,6 @@
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 @@
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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lmtp/client.c
--- a/src/lmtp/client.c Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lmtp/client.c Thu Jul 15 13:42:33 2010 +0100
@@ -163,7 +163,7 @@
&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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lmtp/client.h
--- a/src/lmtp/client.h Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lmtp/client.h Thu Jul 15 13:42:33 2010 +0100
@@ -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 @@
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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lmtp/commands.c
--- a/src/lmtp/commands.c Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lmtp/commands.c Thu Jul 15 13:42:33 2010 +0100
@@ -736,7 +736,7 @@
/* 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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lmtp/lmtp-settings.c
--- a/src/lmtp/lmtp-settings.c Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lmtp/lmtp-settings.c Thu Jul 15 13:42:33 2010 +0100
@@ -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 @@
};
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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/lmtp/lmtp-settings.h
--- a/src/lmtp/lmtp-settings.h Wed Jul 14 17:16:55 2010 +0100
+++ b/src/lmtp/lmtp-settings.h Thu Jul 15 13:42:33 2010 +0100
@@ -11,7 +11,9 @@
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 -r 0d16970d9df3 -r 7a6cf8dae9bf src/plugins/quota/quota-fs.c
--- a/src/plugins/quota/quota-fs.c Wed Jul 14 17:16:55 2010 +0100
+++ b/src/plugins/quota/quota-fs.c Thu Jul 15 13:42:33 2010 +0100
@@ -92,17 +92,6 @@
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 @@
return -1;
}
}
-
- _root->quota->user->v.get_temp_prefix =
- quota_fs_mail_user_get_temp_prefix;
return 0;
}
More information about the dovecot-cvs
mailing list