]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Plugin setting backwards compatibility support and other fixes.
authorTimo Sirainen <tss@iki.fi>
Mon, 2 Feb 2009 06:49:00 +0000 (01:49 -0500)
committerTimo Sirainen <tss@iki.fi>
Mon, 2 Feb 2009 06:49:00 +0000 (01:49 -0500)
--HG--
branch : HEAD

17 files changed:
TODO
src/imap/Makefile.am
src/imap/imap-settings.c
src/imap/imap-settings.h
src/imap/main.c
src/lib-settings/settings-parser.c
src/lib-settings/settings-parser.h
src/master/mail-process.c
src/plugins/convert/convert-settings.c
src/plugins/convert/convert-settings.h
src/plugins/expire/auth-client.c
src/plugins/expire/expire-settings.c
src/plugins/expire/expire-settings.h
src/pop3/Makefile.am
src/pop3/main.c
src/pop3/pop3-settings.c
src/pop3/pop3-settings.h

diff --git a/TODO b/TODO
index e428618a99b1f1f41685b077142796f44c042068..b802b3b03b5d3bf39604c4838e747a7b465d8b94 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,9 +3,7 @@
    - go through mail-process.c. nfs test?
    - support !include and !include_try
    - add back all setting verification code from master
-   - plugins:
-      - backwards compatibility so userdb can continue returning quota_* etc?
-      - acl: master_user, acl_groups are now plugin envs..
+   - master_user, acl_groups are now plugin envs.. is it correct?
  - proxying: support fallbacking to local (or other?) server if the first
    one is down
 user_attrs {
index 5f51edb3630338bf599f38cc1d22c45f3a01ca32..80b3777df65dc7ca46ea59013203f20ea21882ac 100644 (file)
@@ -10,6 +10,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib-imap \
        -I$(top_srcdir)/src/lib-index \
        -I$(top_srcdir)/src/lib-storage \
+       -DPKG_RUNDIR=\""$(rundir)"\" \
        -DMODULEDIR=\""$(moduledir)"\"
 
 imap_LDFLAGS = -export-dynamic
index 945e01ec35e83118d126e5ff0254e552f352b316..d6efdc6c4890fa9d5c8dc9ca6902b4500de68eb1 100644 (file)
@@ -16,6 +16,9 @@
        { SET_DEFLIST, name, offsetof(struct imap_settings, field), defines }
 
 static struct setting_define imap_setting_defines[] = {
+       DEF(SET_STR, base_dir),
+       DEF(SET_STR, auth_socket_path),
+
        DEF(SET_BOOL, mail_debug),
        DEF(SET_BOOL, shutdown_clients),
        DEF(SET_BOOL, verbose_proctitle),
@@ -34,6 +37,9 @@ static struct setting_define imap_setting_defines[] = {
 };
 
 static struct imap_settings imap_default_settings = {
+       MEMBER(base_dir) PKG_RUNDIR,
+       MEMBER(auth_socket_path) "auth-master",
+
        MEMBER(mail_debug) FALSE,
        MEMBER(shutdown_clients) FALSE,
        MEMBER(verbose_proctitle) FALSE,
@@ -66,6 +72,14 @@ struct setting_parser_info imap_setting_parser_info = {
 
 static pool_t settings_pool = NULL;
 
+static void fix_base_path(struct imap_settings *set, const char **str)
+{
+       if (*str != NULL && **str != '\0' && **str != '/') {
+               *str = p_strconcat(settings_pool,
+                                  set->base_dir, "/", *str, NULL);
+       }
+}
+
 void imap_settings_read(const struct imap_settings **set_r,
                        const struct mail_user_settings **user_set_r)
 {
@@ -74,7 +88,8 @@ void imap_settings_read(const struct imap_settings **set_r,
                 &mail_user_setting_parser_info
        };
        struct setting_parser_context *parser;
-       const char *const *expanded;
+       struct imap_settings *set;
+       const char *const *expanded, *value;
        void **sets;
 
        if (settings_pool == NULL)
@@ -95,9 +110,25 @@ void imap_settings_read(const struct imap_settings **set_r,
 
        expanded = t_strsplit(getenv("VARS_EXPANDED"), " ");
        settings_parse_set_keys_expandeded(parser, settings_pool, expanded);
+       /* settings from userdb are in the VARS_EXPANDED list. for each
+          unknown setting in the list assume it's a plugin setting. */
+       for (; *expanded != NULL; expanded++) {
+               if (settings_parse_is_valid_key(parser, *expanded))
+                       continue;
+
+               value = getenv(t_str_ucase(*expanded));
+               if (value == NULL)
+                       continue;
+
+               settings_parse_line(parser, t_strconcat("plugin/", *expanded,
+                                                       "=", value, NULL));
+       }
 
        sets = settings_parser_get_list(parser);
-       *set_r = sets[0];
+       set = sets[0];
+       fix_base_path(set, &set->auth_socket_path);
+
+       *set_r = set;
        *user_set_r = sets[1];
        settings_parser_deinit(&parser);
 }
index df188cbcf3efcde01f5dc6ae43bd9381214e7259..5226d13844458b88d0e75b30c80f4bc65d00444c 100644 (file)
@@ -4,6 +4,9 @@
 struct mail_user_settings;
 
 struct imap_settings {
+       const char *base_dir;
+       const char *auth_socket_path;
+
        bool mail_debug;
        bool shutdown_clients;
        bool verbose_proctitle;
index 7014342e822d0c3e84432909a209cc62f299c285..153d6b1861564e647e279e8c0f4e85ed9eced48b 100644 (file)
@@ -195,7 +195,7 @@ static void main_init(const struct imap_settings *set,
        }
 
        dict_drivers_register_builtin();
-       mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL);
+       mail_users_init(set->auth_socket_path, set->mail_debug);
        clients_init();
        commands_init();
 
index f9c32a606a48ee6c107bdbab8a1c59354452c633..183987b7460c1141fd61ad72fcf442f243027eb4 100644 (file)
@@ -403,6 +403,15 @@ static int settings_parse_keyvalue(struct setting_parser_context *ctx,
        }
 }
 
+bool settings_parse_is_valid_key(struct setting_parser_context *ctx,
+                                const char *key)
+{
+       const struct setting_define *def;
+       struct setting_link *link;
+
+       return settings_find_key(ctx, key, &def, &link);
+}
+
 int settings_parse_line(struct setting_parser_context *ctx, const char *line)
 {
        const char *key, *value;
index 790b63ad069a30ade92e23aea2388a7e90b7e716..b8a964d5fcd8fd31bf04495850b3d7a621bb340b 100644 (file)
@@ -98,6 +98,9 @@ settings_parse_get_prev_info(struct setting_parser_context *ctx);
 void settings_parse_save_input(struct setting_parser_context *ctx,
                               string_t *dest);
 
+/* Returns TRUE if the given key is a valid setting. */
+bool settings_parse_is_valid_key(struct setting_parser_context *ctx,
+                                const char *key);
 /* Parse a single line. Returns 1 if OK, 0 if key is unknown, -1 if error. */
 int settings_parse_line(struct setting_parser_context *ctx, const char *line);
 /* Parse data already read in input stream. */
index 1f934d5f75c5bc2833d3efada2aae65c4f814867..5e9d8f95a8daa0ac13226e60eb6983cb31203590 100644 (file)
@@ -316,7 +316,7 @@ create_mail_process(enum process_type process_type, struct master_settings *set,
                    pid_t *pid_r)
 {
        const struct var_expand_table *var_expand_table;
-       const char *p, *addr, *mail, *chroot_dir, *home_dir, *full_home_dir;
+       const char *p, *addr, *chroot_dir, *home_dir, *full_home_dir;
        const char *system_user, *master_user, *key;
        struct mail_process_group *process_group;
        char title[1024];
@@ -340,16 +340,19 @@ create_mail_process(enum process_type process_type, struct master_settings *set,
        }
 
        t_array_init(&extra_args, 16);
-       mail = home_dir = chroot_dir = system_user = ""; master_user = NULL;
+       home_dir = chroot_dir = system_user = ""; master_user = NULL;
        uid = (uid_t)-1; gid = (gid_t)-1; nice_value = 0;
        home_given = FALSE;
        for (; *args != NULL; args++) {
                if (strncmp(*args, "home=", 5) == 0) {
                        home_dir = *args + 5;
                        home_given = TRUE;
-               } else if (strncmp(*args, "mail=", 5) == 0)
-                       mail = *args + 5;
-               else if (strncmp(*args, "chroot=", 7) == 0)
+               } else if (strncmp(*args, "mail=", 5) == 0) {
+                       const char *arg;
+
+                       arg = t_strconcat("mail_location=", *args + 5, NULL);
+                       array_append(&extra_args, &arg, 1);
+               } else if (strncmp(*args, "chroot=", 7) == 0)
                        chroot_dir = *args + 7;
                else if (strncmp(*args, "nice=", 5) == 0)
                        nice_value = atoi(*args + 5);
index 628b1a49417075948b0dafedaef88786bdb6abae..6053d987ad157b1b9c11e3fcfa838acbc29f804e 100644 (file)
        { type, #name, offsetof(struct convert_settings, name), NULL }
 
 static struct setting_define convert_setting_defines[] = {
+       DEF(SET_STR, base_dir),
        DEF(SET_STR, auth_socket_path),
+
        { SET_STRLIST, "plugin", offsetof(struct convert_settings, plugin_envs), NULL },
 
        SETTING_DEFINE_LIST_END
 };
 
 static struct convert_settings convert_default_settings = {
-       MEMBER(auth_socket_path) PKG_RUNDIR"/auth-master"
+       MEMBER(base_dir) PKG_RUNDIR,
+       MEMBER(auth_socket_path) "auth-master"
 };
 
 struct setting_parser_info convert_setting_parser_info = {
@@ -35,6 +38,14 @@ struct setting_parser_info convert_setting_parser_info = {
 
 static pool_t settings_pool = NULL;
 
+static void fix_base_path(struct convert_settings *set, const char **str)
+{
+       if (*str != NULL && **str != '\0' && **str != '/') {
+               *str = p_strconcat(settings_pool,
+                                  set->base_dir, "/", *str, NULL);
+       }
+}
+
 void convert_settings_read(const struct convert_settings **set_r,
                           const struct mail_user_settings **user_set_r)
 {
@@ -43,7 +54,7 @@ void convert_settings_read(const struct convert_settings **set_r,
                 &mail_user_setting_parser_info
        };
        struct setting_parser_context *parser;
-       const char *const *expanded;
+       struct convert_settings *set;
        void **sets;
 
        if (settings_pool == NULL)
@@ -62,11 +73,11 @@ void convert_settings_read(const struct convert_settings **set_r,
                        settings_parser_get_error(parser));
        }
 
-       expanded = t_strsplit(getenv("VARS_EXPANDED"), " ");
-       settings_parse_set_keys_expandeded(parser, settings_pool, expanded);
-
        sets = settings_parser_get_list(parser);
-       *set_r = sets[0];
+       set = sets[0];
+       fix_base_path(set, &set->auth_socket_path);
+
+       *set_r = set;
        *user_set_r = sets[1];
        settings_parser_deinit(&parser);
 }
index 97ea2d148bc82cc1147852968935decceb6ec6f5..8bb2e1e49ff8c9e0830207c0f330fe59facadaa9 100644 (file)
@@ -4,6 +4,7 @@
 struct mail_user_settings;
 
 struct convert_settings {
+       const char *base_dir;
        const char *auth_socket_path;
 
        ARRAY_DEFINE(plugin_envs, const char *);
index 18b293aa554a9e04cf1787daa91c1aa2691794c8..be4a961b0afee3e8930d316e6c351f6eafeed2be 100644 (file)
@@ -4,6 +4,7 @@
 #include "array.h"
 #include "env-util.h"
 #include "restrict-access.h"
+#include "str.h"
 #include "auth-client.h"
 #include "auth-master.h"
 
@@ -14,6 +15,7 @@ static uid_t current_uid = 0;
 static void auth_set_env(const char *user, struct auth_user_reply *reply)
 {
        const char *const *fields, *key, *value;
+       string_t *expanded_vars;
        unsigned int i, count;
 
        if (reply->gid != (gid_t)-1 && getegid() != reply->gid) {
@@ -52,16 +54,22 @@ static void auth_set_env(const char *user, struct auth_user_reply *reply)
                current_uid = reply->uid;
        }
 
+       expanded_vars = t_str_new(128);
+       str_append(expanded_vars, "VARS_EXPANDED=");
        fields = array_get(&reply->extra_fields, &count);
        for (i = 0; i < count; i++) {
-               key = t_str_ucase(t_strcut(fields[i], '='));
+               key = t_strcut(fields[i], '=');
                value = strchr(fields[i], '=');
                if (value != NULL)
                        value++;
                else
                        value = "1";
-               env_put(t_strconcat(key, "=", value, NULL));
+               env_put(t_strconcat(t_str_ucase(key), "=", value, NULL));
+
+               str_append(expanded_vars, key);
+               str_append_c(expanded_vars, ' ');
        }
+       env_put(str_c(expanded_vars));
        env_put(t_strconcat("HOME=", reply->home, NULL));
 }
 
index 16525f133751936583b7ad55c5de5fdc909cde5f..9633288cde8996f47b3ea9a2c7aa37f231a7d024 100644 (file)
        { type, #name, offsetof(struct expire_settings, name), NULL }
 
 static struct setting_define expire_setting_defines[] = {
+       DEF(SET_STR, base_dir),
        DEF(SET_STR, auth_socket_path),
+
        { SET_STRLIST, "plugin", offsetof(struct expire_settings, plugin_envs), NULL },
 
        SETTING_DEFINE_LIST_END
 };
 
 static struct expire_settings expire_default_settings = {
-       MEMBER(auth_socket_path) PKG_RUNDIR"/auth-master"
+       MEMBER(base_dir) PKG_RUNDIR,
+       MEMBER(auth_socket_path) "auth-master"
 };
 
 struct setting_parser_info expire_setting_parser_info = {
@@ -35,6 +38,14 @@ struct setting_parser_info expire_setting_parser_info = {
 
 static pool_t settings_pool = NULL;
 
+static void fix_base_path(struct expire_settings *set, const char **str)
+{
+       if (*str != NULL && **str != '\0' && **str != '/') {
+               *str = p_strconcat(settings_pool,
+                                  set->base_dir, "/", *str, NULL);
+       }
+}
+
 void expire_settings_read(const struct expire_settings **set_r,
                          const struct mail_user_settings **user_set_r)
 {
@@ -43,7 +54,8 @@ void expire_settings_read(const struct expire_settings **set_r,
                 &mail_user_setting_parser_info
        };
        struct setting_parser_context *parser;
-       const char *const *expanded;
+       struct expire_settings *set;
+       const char *const *expanded, *value;
        void **sets;
 
        if (settings_pool == NULL)
@@ -64,9 +76,25 @@ void expire_settings_read(const struct expire_settings **set_r,
 
        expanded = t_strsplit(getenv("VARS_EXPANDED"), " ");
        settings_parse_set_keys_expandeded(parser, settings_pool, expanded);
+       /* settings from userdb are in the VARS_EXPANDED list. for each
+          unknown setting in the list assume it's a plugin setting. */
+       for (; *expanded != NULL; expanded++) {
+               if (settings_parse_is_valid_key(parser, *expanded))
+                       continue;
+
+               value = getenv(t_str_ucase(*expanded));
+               if (value == NULL)
+                       continue;
+
+               settings_parse_line(parser, t_strconcat("plugin/", *expanded,
+                                                       "=", value, NULL));
+       }
 
        sets = settings_parser_get_list(parser);
-       *set_r = sets[0];
+       set = sets[0];
+       fix_base_path(set, &set->auth_socket_path);
+
+       *set_r = set;
        *user_set_r = sets[1];
        settings_parser_deinit(&parser);
 }
index 9ff06bfe22a15a4826d3ff557ae9c44ba6808f75..46e5c576e9ceda1e13cd213fc09953ce9a2b4118 100644 (file)
@@ -4,6 +4,7 @@
 struct mail_user_settings;
 
 struct expire_settings {
+       const char *base_dir;
        const char *auth_socket_path;
 
        ARRAY_DEFINE(plugin_envs, const char *);
index f1cd0544eba26bbd4d2461da0bc525b8398b4f43..56a89dc67bb98a54e0821bc009dc57af8f7b5457 100644 (file)
@@ -8,6 +8,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib-dict \
        -I$(top_srcdir)/src/lib-mail \
        -I$(top_srcdir)/src/lib-storage \
+       -DPKG_RUNDIR=\""$(rundir)"\" \
        -DMODULEDIR=\""$(moduledir)"\"
 
 pop3_LDFLAGS = -export-dynamic
index d39dd2ba7f2533522c62f5b876b7184d10070731..67a6de6b0a8656c1c9ffed37641dbe1cb75e146f 100644 (file)
@@ -202,7 +202,7 @@ static bool main_init(const struct pop3_settings *set,
        }
 
        dict_drivers_register_builtin();
-       mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL);
+       mail_users_init(set->auth_socket_path, set->mail_debug);
        clients_init();
 
        module_dir_init(modules);
index ae749614da8bdc9a54bade9c651cd3878d122b4a..cd9767872d306fdc0f9bf9ccd8e9b524aec599de 100644 (file)
@@ -16,6 +16,9 @@
        { SET_DEFLIST, name, offsetof(struct pop3_settings, field), defines }
 
 static struct setting_define pop3_setting_defines[] = {
+       DEF(SET_STR, base_dir),
+       DEF(SET_STR, auth_socket_path),
+
        DEF(SET_BOOL, mail_debug),
        DEF(SET_BOOL, shutdown_clients),
        DEF(SET_BOOL, verbose_proctitle),
@@ -35,6 +38,9 @@ static struct setting_define pop3_setting_defines[] = {
 };
 
 static struct pop3_settings pop3_default_settings = {
+       MEMBER(base_dir) PKG_RUNDIR,
+       MEMBER(auth_socket_path) "auth-master",
+
        MEMBER(mail_debug) FALSE,
        MEMBER(shutdown_clients) FALSE,
        MEMBER(verbose_proctitle) FALSE,
@@ -65,6 +71,14 @@ struct setting_parser_info pop3_setting_parser_info = {
 
 static pool_t settings_pool = NULL;
 
+static void fix_base_path(struct pop3_settings *set, const char **str)
+{
+       if (*str != NULL && **str != '\0' && **str != '/') {
+               *str = p_strconcat(settings_pool,
+                                  set->base_dir, "/", *str, NULL);
+       }
+}
+
 void pop3_settings_read(const struct pop3_settings **set_r,
                        const struct mail_user_settings **user_set_r)
 {
@@ -73,7 +87,8 @@ void pop3_settings_read(const struct pop3_settings **set_r,
                 &mail_user_setting_parser_info
        };
        struct setting_parser_context *parser;
-       const char *const *expanded;
+       struct pop3_settings *set;
+       const char *const *expanded, *value;
        void **sets;
 
        if (settings_pool == NULL)
@@ -94,9 +109,25 @@ void pop3_settings_read(const struct pop3_settings **set_r,
 
        expanded = t_strsplit(getenv("VARS_EXPANDED"), " ");
        settings_parse_set_keys_expandeded(parser, settings_pool, expanded);
+       /* settings from userdb are in the VARS_EXPANDED list. for each
+          unknown setting in the list assume it's a plugin setting. */
+       for (; *expanded != NULL; expanded++) {
+               if (settings_parse_is_valid_key(parser, *expanded))
+                       continue;
+
+               value = getenv(t_str_ucase(*expanded));
+               if (value == NULL)
+                       continue;
+
+               settings_parse_line(parser, t_strconcat("plugin/", *expanded,
+                                                       "=", value, NULL));
+       }
 
        sets = settings_parser_get_list(parser);
-       *set_r = sets[0];
+       set = sets[0];
+       fix_base_path(set, &set->auth_socket_path);
+
+       *set_r = set;
        *user_set_r = sets[1];
        settings_parser_deinit(&parser);
 }
index 85553666472c0114708c56d5678c6d042e20ec01..12df00cc1aa3b246e0f69ee173b11a9243c1c686 100644 (file)
@@ -4,6 +4,9 @@
 struct mail_user_settings;
 
 struct pop3_settings {
+       const char *base_dir;
+       const char *auth_socket_path;
+
        bool mail_debug;
        bool shutdown_clients;
        bool verbose_proctitle;