dovecot-1.0: Extra fields from userdb lookup should override eve...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Aug 24 21:43:35 EEST 2007
details: http://hg.dovecot.org/dovecot-1.0/rev/bc2b06d0fba6
changeset: 5389:bc2b06d0fba6
user: Timo Sirainen <tss at iki.fi>
date: Fri Aug 24 21:43:28 2007 +0300
description:
Extra fields from userdb lookup should override everything. Fixed the code
to work the same way as master process handles it, so there should be no
more differences.
diffstat:
3 files changed, 72 insertions(+), 54 deletions(-)
src/deliver/auth-client.c | 22 ++++------
src/deliver/auth-client.h | 6 +-
src/deliver/deliver.c | 98 ++++++++++++++++++++++++++-------------------
diffs (247 lines):
diff -r 68f23f982234 -r bc2b06d0fba6 src/deliver/auth-client.c
--- a/src/deliver/auth-client.c Fri Aug 24 20:00:13 2007 +0300
+++ b/src/deliver/auth-client.c Fri Aug 24 21:43:28 2007 +0300
@@ -1,6 +1,7 @@
/* Copyright (C) 2005-2006 Timo Sirainen */
#include "lib.h"
+#include "array.h"
#include "ioloop.h"
#include "network.h"
#include "istream.h"
@@ -29,6 +30,7 @@ struct auth_connection {
struct ioloop *ioloop;
uid_t euid;
const char *user;
+ array_t *ARRAY_DEFINE_PTR(extra_fields, char *);
unsigned int handshaked:1;
};
@@ -49,10 +51,9 @@ static void auth_connection_destroy(stru
static void auth_parse_input(struct auth_connection *conn, const char *args)
{
- const char *const *tmp, *key, *value;
+ const char *const *tmp;
uid_t uid = 0;
gid_t gid = 0;
- int home_found = FALSE;
const char *chroot = getenv("MAIL_CHROOT");
bool debug = getenv("DEBUG") != NULL;
@@ -87,14 +88,9 @@ static void auth_parse_input(struct auth
}
} else if (strncmp(*tmp, "chroot=", 7) == 0) {
chroot = *tmp + 7;
- } else if (strncmp(*tmp, "home=", 5) == 0) {
- home_found = TRUE;
- env_put(t_strconcat("HOME=", *tmp + 5, NULL));
} else {
- key = t_str_ucase(t_strcut(*tmp, '='));
- value = strchr(*tmp, '=');
- if (value != NULL)
- env_put(t_strconcat(key, "=", value+1, NULL));
+ char *field = i_strdup(*tmp);
+ array_append(conn->extra_fields, &field, 1);
}
}
@@ -199,8 +195,10 @@ static void auth_client_timeout(void *co
auth_connection_destroy(conn);
}
-int auth_client_put_user_env(struct ioloop *ioloop, const char *auth_socket,
- const char *user, uid_t euid)
+int auth_client_lookup_and_restrict(struct ioloop *ioloop,
+ const char *auth_socket,
+ const char *user, uid_t euid,
+ array_t *extra_fields_r)
{
struct auth_connection *conn;
@@ -213,6 +211,7 @@ int auth_client_put_user_env(struct iolo
conn->user = user;
conn->to = timeout_add(1000*AUTH_REQUEST_TIMEOUT,
auth_client_timeout, conn);
+ conn->extra_fields = extra_fields_r;
o_stream_send_str(conn->output,
t_strconcat("VERSION\t1\t0\n"
@@ -223,4 +222,3 @@ int auth_client_put_user_env(struct iolo
io_loop_run(ioloop);
return return_value;
}
-
diff -r 68f23f982234 -r bc2b06d0fba6 src/deliver/auth-client.h
--- a/src/deliver/auth-client.h Fri Aug 24 20:00:13 2007 +0300
+++ b/src/deliver/auth-client.h Fri Aug 24 21:43:28 2007 +0300
@@ -1,7 +1,9 @@
#ifndef __AUTH_CLIENT_H
#define __AUTH_CLIENT_H
-int auth_client_put_user_env(struct ioloop *ioloop, const char *auth_socket,
- const char *user, uid_t euid);
+int auth_client_lookup_and_restrict(struct ioloop *ioloop,
+ const char *auth_socket,
+ const char *user, uid_t euid,
+ array_t *extra_fields_r);
#endif
diff -r 68f23f982234 -r bc2b06d0fba6 src/deliver/deliver.c
--- a/src/deliver/deliver.c Fri Aug 24 20:00:13 2007 +0300
+++ b/src/deliver/deliver.c Fri Aug 24 21:43:28 2007 +0300
@@ -487,7 +487,7 @@ static void open_logfile(const char *use
i_set_failure_timestamp_format(stamp);
}
-static const char *expand_envs(const char *destination)
+static void expand_envs(const char *destination)
{
const struct var_expand_table *table;
const char *mail_env, *const *envs;
@@ -503,26 +503,38 @@ static const char *expand_envs(const cha
env_put(str_c(str));
}
- /* get the table again in case plugin provided the home directory
- (yea, kludgy) */
- table = get_var_expand_table(destination, getenv("HOME"));
-
- /* MAIL comes from userdb, MAIL_LOCATION from dovecot.conf.
- We don't want to expand settings coming from userdb. */
- mail_env = getenv("MAIL");
+ mail_env = getenv("MAIL_LOCATION");
if (mail_env == NULL) {
- mail_env = getenv("MAIL_LOCATION");
- if (mail_env == NULL) {
- /* Keep this for backwards compatibility */
- mail_env = getenv("DEFAULT_MAIL_ENV");
- }
- if (mail_env != NULL) {
- table = get_var_expand_table(destination,
- getenv("HOME"));
- mail_env = expand_mail_env(mail_env, table);
- }
- }
- return mail_env;
+ /* Keep this for backwards compatibility */
+ mail_env = getenv("DEFAULT_MAIL_ENV");
+ }
+ if (mail_env != NULL) {
+ /* get the table again in case plugin envs provided the home
+ directory (yea, kludgy) */
+ table = get_var_expand_table(destination, getenv("HOME"));
+ mail_env = expand_mail_env(mail_env, table);
+ }
+ env_put(t_strconcat("MAIL=", mail_env, NULL));
+}
+
+static void putenv_extra_fields(array_t *extra_fields)
+{
+ ARRAY_SET_TYPE(extra_fields, char *);
+ char **fields;
+ const char *key, *p;
+ unsigned int i, count;
+
+ fields = array_get_modifyable(extra_fields, &count);
+ for (i = 0; i < count; i++) {
+ p = strchr(fields[i], '=');
+ if (p == NULL)
+ env_put(t_strconcat(fields[i], "=1", NULL));
+ else {
+ key = t_str_ucase(t_strdup_until(fields[i], p));
+ env_put(t_strconcat(key, p, NULL));
+ }
+ i_free(fields[i]);
+ }
}
static void print_help(void)
@@ -538,8 +550,9 @@ int main(int argc, char *argv[])
const char *envelope_sender = DEFAULT_ENVELOPE_SENDER;
const char *mailbox = "INBOX";
const char *auth_socket, *env_tz;
- const char *home, *destination, *user, *value, *mail_env;
- enum mail_storage_flags flags;
+ const char *home, *destination, *user, *value;
+ array_t ARRAY_DEFINE(extra_fields, char *);
+ enum mail_storage_flags flags;
enum mail_storage_lock_method lock_method;
struct mail_storage *storage, *mbox_storage;
struct mailbox *box;
@@ -661,30 +674,36 @@ int main(int argc, char *argv[])
TRUE, version);
}
+ ARRAY_CREATE(&extra_fields, pool_datastack_create(), char *, 64);
if (destination != NULL) {
auth_socket = getenv("AUTH_SOCKET_PATH");
if (auth_socket == NULL)
auth_socket = DEFAULT_AUTH_SOCKET_PATH;
- ret = auth_client_put_user_env(ioloop, auth_socket,
- destination, process_euid);
+ ret = auth_client_lookup_and_restrict(ioloop, auth_socket,
+ destination, process_euid,
+ &extra_fields);
if (ret != 0)
return ret;
-
- /* If possible chdir to home directory, so that core file
- could be written in case we crash. */
- home = getenv("HOME");
- if (home != NULL) {
- if (chdir(home) < 0) {
- if (errno != ENOENT)
- i_error("chdir(%s) failed: %m", home);
- else if (getenv("DEBUG") != NULL)
- i_info("Home dir not found: %s", home);
- }
- }
} else {
destination = user;
}
+
+ expand_envs(destination);
+ putenv_extra_fields(&extra_fields);
+
+ /* If possible chdir to home directory, so that core file
+ could be written in case we crash. */
+ home = getenv("HOME");
+ if (home != NULL) {
+ if (chdir(home) < 0) {
+ if (errno != ENOENT)
+ i_error("chdir(%s) failed: %m", home);
+ else if (getenv("DEBUG") != NULL)
+ i_info("Home dir not found: %s", home);
+ }
+ }
+
env_put(t_strconcat("USER=", destination, NULL));
value = getenv("UMASK");
@@ -705,8 +724,6 @@ int main(int argc, char *argv[])
if (deliver_set->sendmail_path == NULL)
deliver_set->sendmail_path = DEFAULT_SENDMAIL_PATH;
- mail_env = expand_envs(destination);
-
dict_client_register();
duplicate_init();
mail_storage_init();
@@ -716,12 +733,13 @@ int main(int argc, char *argv[])
/* FIXME: how should we handle namespaces? */
mail_storage_parse_env(&flags, &lock_method);
- storage = mail_storage_create_with_data(mail_env, destination,
+ storage = mail_storage_create_with_data(getenv("MAIL"), destination,
flags, lock_method);
if (storage == NULL) {
i_fatal_status(EX_TEMPFAIL,
"Failed to create storage for '%s' with mail '%s'",
- destination, mail_env == NULL ? "(null)" : mail_env);
+ destination,
+ getenv("MAIL") == NULL ? "(null)" : getenv("MAIL"));
}
if (hook_mail_storage_created != NULL)
More information about the dovecot-cvs
mailing list