]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail processes now specify user/lip/rip in config requests.
authorTimo Sirainen <tss@iki.fi>
Wed, 6 May 2009 19:53:07 +0000 (15:53 -0400)
committerTimo Sirainen <tss@iki.fi>
Wed, 6 May 2009 19:53:07 +0000 (15:53 -0400)
--HG--
branch : HEAD

src/auth/auth-settings.c
src/lib-master/master-service-settings.c
src/lib-master/master-service-settings.h
src/lib-storage/mail-storage-service.c
src/log/main.c
src/login-common/login-settings.c
src/master/main.c

index 3e7094d4884bb970915eaabeaaeafe455d2c8056..6539a4cd77be48e739a40458c5d331cb95f1bf90 100644 (file)
@@ -186,8 +186,7 @@ auth_settings_read(struct master_service *service, const char *name)
        struct auth_root_settings *set;
        unsigned int i, count;
 
-       if (master_service_settings_read(service, set_roots, NULL, FALSE,
-                                        &error) < 0)
+       if (master_service_settings_read_simple(service, set_roots, &error) < 0)
                i_fatal("Error reading configuration: %s", error);
 
        sets = master_service_settings_get_others(service);
index 53cec8f6976ba719d1f4d1a8a2b9b88f6aa194db..98f7da5dad05b93a510a005956c483b20f3c399f 100644 (file)
@@ -4,6 +4,7 @@
 #include "array.h"
 #include "istream.h"
 #include "write-full.h"
+#include "str.h"
 #include "settings-parser.h"
 #include "master-service-private.h"
 #include "master-service-settings.h"
@@ -16,7 +17,6 @@
 #define DOVECOT_CONFIG_BIN_PATH BINDIR"/doveconf"
 
 #define CONFIG_HANDSHAKE "VERSION\t1\t0\n"
-#define CONFIG_REQUEST_SERVICE "REQ\tservice=%s\n"
 
 #undef DEF
 #define DEF(type, name) \
@@ -97,31 +97,49 @@ master_service_exec_config(struct master_service *service, bool preserve_home)
 }
 
 static int
-master_service_read_config(struct master_service *service, bool preserve_home,
+master_service_read_config(struct master_service *service,
+                          const struct master_service_settings_input *input,
                           const char **error_r)
 {
-       const char *path, *str;
-       int fd;
+       const char *path;
+       struct stat st;
+       int fd, ret;
 
        path = master_service_get_config_path(service);
        fd = net_connect_unix(path);
        if (fd < 0) {
-               struct stat st;
-
                *error_r = t_strdup_printf("net_connect_unix(%s) failed: %m",
                                           path);
 
                if (stat(path, &st) == 0 && !S_ISFIFO(st.st_mode)) {
                        /* it's a file, not a socket */
-                       master_service_exec_config(service, preserve_home);
+                       master_service_exec_config(service,
+                                                  input->preserve_home);
                }
                return -1;
        }
        net_set_nonblock(fd, FALSE);
 
-       str = t_strdup_printf(CONFIG_HANDSHAKE CONFIG_REQUEST_SERVICE,
-                             service->name);
-       if (write_full(fd, str, strlen(str)) < 0) {
+       T_BEGIN {
+               string_t *str;
+
+               str = t_str_new(128);
+               str_append(str, CONFIG_HANDSHAKE);
+               str_printfa(str, "REQ\tservice=%s", service->name);
+               if (input->username != NULL)
+                       str_printfa(str, "\tuser=%s", input->username);
+               if (input->local_ip.family != 0) {
+                       str_printfa(str, "\tlip=%s",
+                                   net_ip2addr(&input->local_ip));
+               }
+               if (input->remote_ip.family != 0) {
+                       str_printfa(str, "\trip=%s",
+                                   net_ip2addr(&input->remote_ip));
+               }
+               str_append_c(str, '\n');
+               ret = write_full(fd, str_data(str), str_len(str));
+       } T_END;
+       if (ret < 0) {
                *error_r = t_strdup_printf("write_full(%s) failed: %m", path);
                return -1;
        }
@@ -151,22 +169,20 @@ master_service_apply_config_overrides(struct master_service *service,
 }
 
 int master_service_settings_read(struct master_service *service,
-                                const struct setting_parser_info *roots[],
-                                const struct dynamic_settings_parser *dyn_parsers,
-                                bool preserve_home, const char **error_r)
+                                const struct master_service_settings_input *input,
+                                const char **error_r)
 {
        ARRAY_DEFINE(all_roots, const struct setting_parser_info *);
        const struct setting_parser_info *tmp_root;
        struct setting_parser_context *parser;
-       struct istream *input;
+       struct istream *istream;
        const char *error, *env, *const *keys;
        void **sets;
        unsigned int i;
        int ret, fd = -1;
 
        if (getenv("DOVECONF_ENV") == NULL) {
-               fd = master_service_read_config(service, preserve_home,
-                                               error_r);
+               fd = master_service_read_config(service, input, error_r);
                if (fd == -1)
                        return -1;
        }
@@ -178,15 +194,17 @@ int master_service_settings_read(struct master_service *service,
                        pool_alloconly_create("master service settings", 4096);
        }
 
-       if (dyn_parsers != NULL)
-               settings_parser_info_update(service->set_pool, dyn_parsers);
+       if (input->dyn_parsers != NULL) {
+               settings_parser_info_update(service->set_pool,
+                                           input->dyn_parsers);
+       }
 
        p_array_init(&all_roots, service->set_pool, 8);
        tmp_root = &master_service_setting_parser_info;
        array_append(&all_roots, &tmp_root, 1);
-       if (roots != NULL) {
-               for (i = 0; roots[i] != NULL; i++)
-                       array_append(&all_roots, &roots[i], 1);
+       if (input->roots != NULL) {
+               for (i = 0; input->roots[i] != NULL; i++)
+                       array_append(&all_roots, &input->roots[i], 1);
        }
 
        parser = settings_parser_init_list(service->set_pool,
@@ -194,9 +212,9 @@ int master_service_settings_read(struct master_service *service,
                        SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS);
 
        if (fd != -1) {
-               input = i_stream_create_fd(fd, (size_t)-1, FALSE);
-               ret = settings_parse_stream_read(parser, input);
-               i_stream_unref(&input);
+               istream = i_stream_create_fd(fd, (size_t)-1, FALSE);
+               ret = settings_parse_stream_read(parser, istream);
+               i_stream_unref(&istream);
                i_assert(ret <= 0);
                if (ret < 0) {
                        *error_r = settings_parser_get_error(parser);
@@ -210,11 +228,11 @@ int master_service_settings_read(struct master_service *service,
                return -1;
        }
        env = getenv("VARS_EXPANDED");
-       if (env != NULL) {
+       if (env != NULL) T_BEGIN {
                keys = t_strsplit(env, " ");
                settings_parse_set_keys_expandeded(parser, service->set_pool,
                                                   keys);
-       }
+       } T_END;
 
        if (array_is_created(&service->config_overrides)) {
                if (master_service_apply_config_overrides(service, parser,
@@ -243,6 +261,17 @@ int master_service_settings_read(struct master_service *service,
        return 0;
 }
 
+int master_service_settings_read_simple(struct master_service *service,
+                                       const struct setting_parser_info **roots,
+                                       const char **error_r)
+{
+       struct master_service_settings_input input;
+
+       memset(&input, 0, sizeof(input));
+       input.roots = roots;
+       return master_service_settings_read(service, &input, error_r);
+}
+
 const struct master_service_settings *
 master_service_settings_get(struct master_service *service)
 {
index 8b610a572ba492cd57ada7dade04cee1c5a60770..c253a49a5c44be5e5ef38251c736093e3a7b93e7 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef MASTER_SERVICE_SETTINGS_H
 #define MASTER_SERVICE_SETTINGS_H
 
+#include "network.h"
+
 struct setting_parser_info;
 struct dynamic_settings_parser;
 struct master_service;
@@ -13,12 +15,23 @@ struct master_service_settings {
        bool version_ignore;
 };
 
+struct master_service_settings_input {
+       const struct setting_parser_info **roots;
+       const struct dynamic_settings_parser *dyn_parsers;
+       bool preserve_home;
+
+       const char *username;
+       struct ip_addr local_ip, remote_ip;
+};
+
 extern struct setting_parser_info master_service_setting_parser_info;
 
 int master_service_settings_read(struct master_service *service,
-                                const struct setting_parser_info *roots[],
-                                const struct dynamic_settings_parser *dyn_parsers,
-                                bool preserve_home, const char **error_r);
+                                const struct master_service_settings_input *input,
+                                const char **error_r);
+int master_service_settings_read_simple(struct master_service *service,
+                                       const struct setting_parser_info **roots,
+                                       const char **error_r);
 const struct master_service_settings *
 master_service_settings_get(struct master_service *service);
 void **master_service_settings_get_others(struct master_service *service);
index c4efc51d6e629918ac786ec4dae0c5217d894693..7429455e9d17f0f5cfe1f5cb5ff7ba6d63799e38 100644 (file)
@@ -303,11 +303,13 @@ service_drop_privileges(const struct mail_user_settings *set,
 
 static void
 mail_storage_service_init_settings(struct master_service *service,
+                                  const struct mail_storage_service_input *input,
                                   const struct setting_parser_info *set_roots[],
                                   bool preserve_home)
 {
        ARRAY_DEFINE(all_set_roots, const struct setting_parser_info *);
        const struct setting_parser_info *info = &mail_user_setting_parser_info;
+       struct master_service_settings_input set_input;
        const char *error;
        unsigned int i;
 
@@ -327,10 +329,16 @@ mail_storage_service_init_settings(struct master_service *service,
 
        /* read settings after registering storages so they can have their
           own setting definitions too */
-       set_roots = array_idx_modifiable(&all_set_roots, 0);
-       if (master_service_settings_read(service, set_roots,
-                                        mail_storage_get_dynamic_parsers(),
-                                        preserve_home, &error) < 0)
+       memset(&set_input, 0, sizeof(set_input));
+       set_input.roots = array_idx_modifiable(&all_set_roots, 0);
+       set_input.dyn_parsers = mail_storage_get_dynamic_parsers();
+       set_input.preserve_home = preserve_home;
+       if (input != NULL) {
+               set_input.username = input->username;
+               set_input.local_ip = input->local_ip;
+               set_input.remote_ip = input->remote_ip;
+       }
+       if (master_service_settings_read(service, &set_input, &error) < 0)
                i_fatal("Error reading configuration: %s", error);
 }
 
@@ -472,7 +480,8 @@ mail_storage_service_init_user(struct master_service *service,
        master_service_init_finish(service);
 
        userdb_lookup = (flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0;
-       mail_storage_service_init_settings(service, set_roots, !userdb_lookup);
+       mail_storage_service_init_settings(service, &input, set_roots,
+                                          !userdb_lookup);
 
        if ((flags & MAIL_STORAGE_SERVICE_FLAG_DEBUG) != 0)
                set_keyval(service->set_parser, "mail_debug", "yes");
@@ -564,7 +573,7 @@ mail_storage_service_multi_init(struct master_service *service,
        ctx->service = service;
        ctx->flags = flags;
 
-       mail_storage_service_init_settings(service, set_roots, FALSE);
+       mail_storage_service_init_settings(service, NULL, set_roots, FALSE);
 
        set = master_service_settings_get(service);
        sets = master_service_settings_get_others(service);
index d8496ee964444124a270c06255226addfb173aaf..d9a3707ae4f107b3156a75300980a6a9f7650211 100644 (file)
@@ -60,8 +60,7 @@ int main(int argc, char *argv[])
                        exit(FATAL_DEFAULT);
        }
 
-       if (master_service_settings_read(service, NULL, NULL, FALSE,
-                                        &error) < 0)
+       if (master_service_settings_read_simple(service, NULL, &error) < 0)
                i_fatal("Error reading configuration: %s", error);
 
        master_service_init_log(service, "log: ", 0);
index cf2711492c09abc5890e38621249543c5502c8ba..559f2b4edd3f685c41df9da81b3e8942cdff95a3 100644 (file)
@@ -181,8 +181,8 @@ struct login_settings *login_settings_read(struct master_service *service)
        const char *error;
        void **sets;
 
-       if (master_service_settings_read(service, set_roots, NULL, FALSE,
-                                        &error) < 0)
+       if (master_service_settings_read_simple(service, set_roots,
+                                               &error) < 0)
                i_fatal("Error reading configuration: %s", error);
 
        sets = master_service_settings_get_others(service);
index 1bc69bd5bcb29abd8aeb3b63231e997b4230109d..55db150ea1c31b167288e60622c170dc2cad94b9 100644 (file)
@@ -641,8 +641,8 @@ int main(int argc, char *argv[])
            dup2(null_fd, STDOUT_FILENO) < 0)
                i_fatal("dup2(null_fd) failed: %m");
 
-       if (master_service_settings_read(master_service, set_roots, NULL, FALSE,
-                                        &error) < 0)
+       if (master_service_settings_read_simple(master_service, set_roots,
+                                               &error) < 0)
                i_fatal("Error reading configuration: %s", error);
        sets = master_service_settings_get_others(master_service);
        set = sets[0];