dovecot-1.2: Added struct mail_user and fixed the code to suppor...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Aug 12 19:28:51 EEST 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/db66611fd195
changeset: 8082:db66611fd195
user: Timo Sirainen <tss at iki.fi>
date: Tue Aug 12 12:28:42 2008 -0400
description:
Added struct mail_user and fixed the code to support multiple users per process.
diffstat:
43 files changed, 550 insertions(+), 411 deletions(-)
src/deliver/deliver.c | 26 +
src/imap/client.c | 16 -
src/imap/client.h | 5
src/imap/cmd-list.c | 8
src/imap/cmd-namespace.c | 6
src/imap/cmd-subscribe.c | 4
src/imap/commands-util.c | 2
src/imap/main.c | 23 -
src/lib-storage/Makefile.am | 2
src/lib-storage/index/maildir/maildir-storage.c | 16 -
src/lib-storage/index/mbox/mbox-save.c | 8
src/lib-storage/index/mbox/mbox-storage.c | 46 +--
src/lib-storage/mail-namespace.c | 24 -
src/lib-storage/mail-namespace.h | 9
src/lib-storage/mail-storage-private.h | 1
src/lib-storage/mail-storage.c | 6
src/lib-storage/mail-storage.h | 3
src/plugins/acl/acl-mailbox-list.c | 6
src/plugins/convert/convert-plugin.c | 6
src/plugins/convert/convert-storage.c | 9
src/plugins/convert/convert-storage.h | 2
src/plugins/convert/convert-tool.c | 12
src/plugins/expire/expire-plugin.c | 1
src/plugins/expire/expire-tool.c | 11
src/plugins/imap-quota/imap-quota-plugin.c | 8
src/plugins/lazy-expunge/lazy-expunge-plugin.c | 60 +++-
src/plugins/quota/quota-count.c | 2
src/plugins/quota/quota-dict.c | 9
src/plugins/quota/quota-maildir.c | 18 -
src/plugins/quota/quota-plugin.c | 37 +-
src/plugins/quota/quota-plugin.h | 6
src/plugins/quota/quota-private.h | 55 ++-
src/plugins/quota/quota-storage.c | 54 +++
src/plugins/quota/quota.c | 339 ++++++++++++-----------
src/plugins/quota/quota.h | 42 +-
src/plugins/trash/trash-plugin.c | 19 -
src/plugins/virtual/virtual-config.c | 10
src/plugins/virtual/virtual-plugin.c | 22 -
src/plugins/virtual/virtual-plugin.h | 2
src/plugins/virtual/virtual-storage.c | 3
src/pop3/client.c | 9
src/pop3/client.h | 6
src/pop3/main.c | 8
diffs (truncated from 2543 to 300 lines):
diff -r 0d5fba71cb93 -r db66611fd195 src/deliver/deliver.c
--- a/src/deliver/deliver.c Fri Aug 08 17:16:07 2008 -0400
+++ b/src/deliver/deliver.c Tue Aug 12 12:28:42 2008 -0400
@@ -777,7 +777,8 @@ int main(int argc, char *argv[])
const char *auth_socket;
const char *home, *destaddr, *user, *value, *errstr, *path;
ARRAY_TYPE(string) extra_fields;
- struct mail_namespace *ns, *raw_ns;
+ struct mail_user *mail_user, *raw_mail_user;
+ struct mail_namespace *raw_ns;
struct mail_storage *storage;
struct mailbox *box;
struct raw_mailbox *raw_box;
@@ -1002,12 +1003,16 @@ int main(int argc, char *argv[])
module_dir_init(modules);
namespace_pool = pool_alloconly_create("namespaces", 1024);
- if (mail_namespaces_init(namespace_pool, user, &ns) < 0)
+ mail_user = mail_user_init(user, home);
+ if (mail_namespaces_init(namespace_pool, mail_user) < 0)
i_fatal("Namespace initialization failed");
- raw_ns = mail_namespaces_init_empty(namespace_pool);
+ /* create a separate mail user for the internal namespace */
+ raw_mail_user = mail_user_init(user, NULL);
+ raw_ns = mail_namespaces_init_empty(namespace_pool, raw_mail_user);
raw_ns->flags |= NAMESPACE_FLAG_INTERNAL;
- if (mail_storage_create(raw_ns, "raw", "/tmp", user,
+
+ if (mail_storage_create(raw_ns, "raw", "/tmp",
MAIL_STORAGE_FLAG_FULL_FS_ACCESS,
FILE_LOCK_METHOD_FCNTL, &errstr) < 0)
i_fatal("Couldn't create internal raw storage: %s", errstr);
@@ -1044,7 +1049,8 @@ int main(int argc, char *argv[])
if (deliver_mail == NULL)
ret = -1;
else {
- if (deliver_mail(ns, &storage, mail, destaddr, mailbox) <= 0) {
+ if (deliver_mail(mail_user->namespaces, &storage, mail,
+ destaddr, mailbox) <= 0) {
/* if message was saved, don't bounce it even though
the script failed later. */
ret = saved_mail ? 0 : -1;
@@ -1056,12 +1062,14 @@ int main(int argc, char *argv[])
if (ret < 0 && !tried_default_save) {
/* plugins didn't handle this. save into the default mailbox. */
- ret = deliver_save(ns, &storage, mailbox, mail, 0, NULL);
+ ret = deliver_save(mail_user->namespaces,
+ &storage, mailbox, mail, 0, NULL);
}
if (ret < 0 && strcasecmp(mailbox, "INBOX") != 0) {
/* still didn't work. try once more to save it
to INBOX. */
- ret = deliver_save(ns, &storage, "INBOX", mail, 0, NULL);
+ ret = deliver_save(mail_user->namespaces,
+ &storage, "INBOX", mail, 0, NULL);
}
if (ret < 0 ) {
@@ -1108,8 +1116,8 @@ int main(int argc, char *argv[])
mailbox_transaction_rollback(&t);
mailbox_close(&box);
- mail_namespaces_deinit(&raw_ns);
- mail_namespaces_deinit(&ns);
+ mail_user_deinit(&mail_user);
+ mail_user_deinit(&raw_mail_user);
module_dir_unload(&modules);
mail_storage_deinit();
diff -r 0d5fba71cb93 -r db66611fd195 src/imap/client.c
--- a/src/imap/client.c Fri Aug 08 17:16:07 2008 -0400
+++ b/src/imap/client.c Tue Aug 12 12:28:42 2008 -0400
@@ -25,10 +25,10 @@ static void client_idle_timeout(struct c
client_destroy(client, "Disconnected for inactivity");
}
-struct client *client_create(int fd_in, int fd_out,
- struct mail_namespace *namespaces)
+struct client *client_create(int fd_in, int fd_out, struct mail_user *user)
{
struct client *client;
+ struct mail_namespace *ns;
/* always use nonblocking I/O */
net_set_nonblock(fd_in, TRUE);
@@ -48,12 +48,11 @@ struct client *client_create(int fd_in,
client_idle_timeout, client);
client->command_pool = pool_alloconly_create("client command", 1024*12);
- client->namespaces = namespaces;
-
- while (namespaces != NULL) {
- mail_storage_set_callbacks(namespaces->storage,
+ client->user = user;
+
+ for (ns = user->namespaces; ns != NULL; ns = ns->next) {
+ mail_storage_set_callbacks(ns->storage,
&mail_storage_callbacks, client);
- namespaces = namespaces->next;
}
i_assert(my_client == NULL);
@@ -130,6 +129,7 @@ void client_destroy(struct client *clien
void client_destroy(struct client *client, const char *reason)
{
struct client_command_context *cmd;
+
i_assert(!client->destroyed);
client->destroyed = TRUE;
@@ -161,7 +161,7 @@ void client_destroy(struct client *clien
client_search_updates_free(client);
mailbox_close(&client->mailbox);
}
- mail_namespaces_deinit(&client->namespaces);
+ mail_user_deinit(&client->user);
if (client->free_parser != NULL)
imap_parser_destroy(&client->free_parser);
diff -r 0d5fba71cb93 -r db66611fd195 src/imap/client.h
--- a/src/imap/client.h Fri Aug 08 17:16:07 2008 -0400
+++ b/src/imap/client.h Tue Aug 12 12:28:42 2008 -0400
@@ -74,7 +74,7 @@ struct client {
struct ostream *output;
struct timeout *to_idle, *to_idle_output;
- struct mail_namespace *namespaces;
+ struct mail_user *user;
struct mailbox *mailbox;
struct mailbox_keywords keywords;
unsigned int select_counter; /* increased when mailbox is changed */
@@ -124,8 +124,7 @@ struct client {
/* Create new client with specified input/output handles. socket specifies
if the handle is a socket. */
-struct client *client_create(int fd_in, int fd_out,
- struct mail_namespace *namespaces);
+struct client *client_create(int fd_in, int fd_out, struct mail_user *user);
void client_destroy(struct client *client, const char *reason);
/* Disconnect client connection */
diff -r 0d5fba71cb93 -r db66611fd195 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c Fri Aug 08 17:16:07 2008 -0400
+++ b/src/imap/cmd-list.c Tue Aug 12 12:28:42 2008 -0400
@@ -185,7 +185,7 @@ list_get_inbox_flags(struct cmd_list_con
}
/* find the INBOX flags */
- ns = mail_namespace_find_inbox(ctx->cmd->client->namespaces);
+ ns = mail_namespace_find_inbox(ctx->cmd->client->user->namespaces);
list_iter = mailbox_list_iter_init(ns->list, "INBOX", 0);
info = mailbox_list_iter_next(list_iter);
if (info != NULL) {
@@ -704,13 +704,13 @@ static void cmd_list_ref_root(struct cli
/* Special request to return the hierarchy delimiter and mailbox root
name. If namespace has a prefix, it's returned as the mailbox root.
Otherwise we'll emulate UW-IMAP behavior. */
- ns = mail_namespace_find_visible(client->namespaces, &ref);
+ ns = mail_namespace_find_visible(client->user->namespaces, &ref);
if (ns != NULL) {
ns_prefix = ns->prefix;
ns_sep = ns->sep;
} else {
ns_prefix = "";
- ns_sep = mail_namespace_get_root_sep(client->namespaces);
+ ns_sep = mail_namespace_get_root_sep(client->user->namespaces);
}
str = t_str_new(64);
@@ -754,7 +754,7 @@ bool cmd_list_full(struct client_command
ctx = p_new(cmd->pool, struct cmd_list_context, 1);
ctx->cmd = cmd;
- ctx->ns = client->namespaces;
+ ctx->ns = client->user->namespaces;
ctx->lsub = lsub;
cmd->context = ctx;
diff -r 0d5fba71cb93 -r db66611fd195 src/imap/cmd-namespace.c
--- a/src/imap/cmd-namespace.c Fri Aug 08 17:16:07 2008 -0400
+++ b/src/imap/cmd-namespace.c Tue Aug 12 12:28:42 2008 -0400
@@ -42,11 +42,11 @@ bool cmd_namespace(struct client_command
str = t_str_new(256);
str_append(str, "* NAMESPACE ");
- list_namespaces(client->namespaces, NAMESPACE_PRIVATE, str);
+ list_namespaces(client->user->namespaces, NAMESPACE_PRIVATE, str);
str_append_c(str, ' ');
- list_namespaces(client->namespaces, NAMESPACE_SHARED, str);
+ list_namespaces(client->user->namespaces, NAMESPACE_SHARED, str);
str_append_c(str, ' ');
- list_namespaces(client->namespaces, NAMESPACE_PUBLIC, str);
+ list_namespaces(client->user->namespaces, NAMESPACE_PUBLIC, str);
client_send_line(client, str_c(str));
client_send_tagline(cmd, "OK Namespace completed.");
diff -r 0d5fba71cb93 -r db66611fd195 src/imap/cmd-subscribe.c
--- a/src/imap/cmd-subscribe.c Fri Aug 08 17:16:07 2008 -0400
+++ b/src/imap/cmd-subscribe.c Tue Aug 12 12:28:42 2008 -0400
@@ -35,7 +35,7 @@ bool cmd_subscribe_full(struct client_co
return FALSE;
verify_name = mailbox;
- ns = mail_namespace_find_subscribable(cmd->client->namespaces,
+ ns = mail_namespace_find_subscribable(cmd->client->user->namespaces,
&mailbox);
if (ns == NULL) {
client_send_tagline(cmd, "NO Unknown namespace.");
@@ -49,7 +49,7 @@ bool cmd_subscribe_full(struct client_co
verify_name = t_strndup(verify_name, strlen(verify_name)-1);
}
- if (have_listable_namespace_prefix(cmd->client->namespaces,
+ if (have_listable_namespace_prefix(cmd->client->user->namespaces,
verify_name)) {
/* subscribing to a listable namespace prefix, allow it. */
} else {
diff -r 0d5fba71cb93 -r db66611fd195 src/imap/commands-util.c
--- a/src/imap/commands-util.c Fri Aug 08 17:16:07 2008 -0400
+++ b/src/imap/commands-util.c Tue Aug 12 12:28:42 2008 -0400
@@ -23,7 +23,7 @@ client_find_namespace(struct client_comm
{
struct mail_namespace *ns;
- ns = mail_namespace_find(cmd->client->namespaces, mailbox);
+ ns = mail_namespace_find(cmd->client->user->namespaces, mailbox);
if (ns != NULL)
return ns;
diff -r 0d5fba71cb93 -r db66611fd195 src/imap/main.c
--- a/src/imap/main.c Fri Aug 08 17:16:07 2008 -0400
+++ b/src/imap/main.c Tue Aug 12 12:28:42 2008 -0400
@@ -161,8 +161,8 @@ static void main_init(void)
{
struct client *client;
struct ostream *output;
- struct mail_namespace *ns;
- const char *user, *str, *tag;
+ struct mail_user *user;
+ const char *username, *home, *str, *tag;
lib_signals_init();
lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
@@ -170,18 +170,16 @@ static void main_init(void)
lib_signals_ignore(SIGPIPE, TRUE);
lib_signals_ignore(SIGALRM, FALSE);
- user = getenv("USER");
- if (user == NULL) {
+ username = getenv("USER");
+ if (username == NULL) {
if (IS_STANDALONE())
- user = getlogin();
- if (user == NULL)
+ username = getlogin();
+ if (username == NULL)
i_fatal("USER environment missing");
}
+ home = getenv("HOME");
if (getenv("DEBUG") != NULL) {
- const char *home;
-
- home = getenv("HOME");
i_info("Effective uid=%s, gid=%s, home=%s",
dec2str(geteuid()), dec2str(getegid()),
home != NULL ? home : "(none)");
@@ -232,9 +230,10 @@ static void main_init(void)
parse_workarounds();
namespace_pool = pool_alloconly_create("namespaces", 1024);
- if (mail_namespaces_init(namespace_pool, user, &ns) < 0)
+ user = mail_user_init(username, home);
+ if (mail_namespaces_init(namespace_pool, user) < 0)
i_fatal("Namespace initialization failed");
- client = client_create(0, 1, ns);
+ client = client_create(0, 1, user);
output = client->output;
o_stream_ref(output);
@@ -246,7 +245,7 @@ static void main_init(void)
client_send_line(client, t_strconcat(
"* PREAUTH [CAPABILITY ",
str_c(capability_string), "] "
- "Logged in as ", user, NULL));
+ "Logged in as ", user->username, NULL));
} else {
client_send_line(client, t_strconcat(
tag, " OK [CAPABILITY ",
diff -r 0d5fba71cb93 -r db66611fd195 src/lib-storage/Makefile.am
--- a/src/lib-storage/Makefile.am Fri Aug 08 17:16:07 2008 -0400
+++ b/src/lib-storage/Makefile.am Tue Aug 12 12:28:42 2008 -0400
@@ -16,6 +16,7 @@ libstorage_a_SOURCES = \
mail-search.c \
mail-search-build.c \
mail-storage.c \
+ mail-user.c \
mailbox-list.c \
More information about the dovecot-cvs
mailing list