From: Timo Sirainen Date: Mon, 2 Feb 2009 06:49:00 +0000 (-0500) Subject: Plugin setting backwards compatibility support and other fixes. X-Git-Tag: 2.0.alpha1~1037^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad0f1d2f2e7f1d42b2de403b04a0ffe1675109cc;p=thirdparty%2Fdovecot%2Fcore.git Plugin setting backwards compatibility support and other fixes. --HG-- branch : HEAD --- diff --git a/TODO b/TODO index e428618a99..b802b3b03b 100644 --- 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 { diff --git a/src/imap/Makefile.am b/src/imap/Makefile.am index 5f51edb363..80b3777df6 100644 --- a/src/imap/Makefile.am +++ b/src/imap/Makefile.am @@ -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 diff --git a/src/imap/imap-settings.c b/src/imap/imap-settings.c index 945e01ec35..d6efdc6c48 100644 --- a/src/imap/imap-settings.c +++ b/src/imap/imap-settings.c @@ -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); } diff --git a/src/imap/imap-settings.h b/src/imap/imap-settings.h index df188cbcf3..5226d13844 100644 --- a/src/imap/imap-settings.h +++ b/src/imap/imap-settings.h @@ -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; diff --git a/src/imap/main.c b/src/imap/main.c index 7014342e82..153d6b1861 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -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(); diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index f9c32a606a..183987b746 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -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; diff --git a/src/lib-settings/settings-parser.h b/src/lib-settings/settings-parser.h index 790b63ad06..b8a964d5fc 100644 --- a/src/lib-settings/settings-parser.h +++ b/src/lib-settings/settings-parser.h @@ -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. */ diff --git a/src/master/mail-process.c b/src/master/mail-process.c index 1f934d5f75..5e9d8f95a8 100644 --- a/src/master/mail-process.c +++ b/src/master/mail-process.c @@ -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); diff --git a/src/plugins/convert/convert-settings.c b/src/plugins/convert/convert-settings.c index 628b1a4941..6053d987ad 100644 --- a/src/plugins/convert/convert-settings.c +++ b/src/plugins/convert/convert-settings.c @@ -13,14 +13,17 @@ { 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); } diff --git a/src/plugins/convert/convert-settings.h b/src/plugins/convert/convert-settings.h index 97ea2d148b..8bb2e1e49f 100644 --- a/src/plugins/convert/convert-settings.h +++ b/src/plugins/convert/convert-settings.h @@ -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 *); diff --git a/src/plugins/expire/auth-client.c b/src/plugins/expire/auth-client.c index 18b293aa55..be4a961b0a 100644 --- a/src/plugins/expire/auth-client.c +++ b/src/plugins/expire/auth-client.c @@ -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)); } diff --git a/src/plugins/expire/expire-settings.c b/src/plugins/expire/expire-settings.c index 16525f1337..9633288cde 100644 --- a/src/plugins/expire/expire-settings.c +++ b/src/plugins/expire/expire-settings.c @@ -13,14 +13,17 @@ { 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); } diff --git a/src/plugins/expire/expire-settings.h b/src/plugins/expire/expire-settings.h index 9ff06bfe22..46e5c576e9 100644 --- a/src/plugins/expire/expire-settings.h +++ b/src/plugins/expire/expire-settings.h @@ -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 *); diff --git a/src/pop3/Makefile.am b/src/pop3/Makefile.am index f1cd0544eb..56a89dc67b 100644 --- a/src/pop3/Makefile.am +++ b/src/pop3/Makefile.am @@ -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 diff --git a/src/pop3/main.c b/src/pop3/main.c index d39dd2ba7f..67a6de6b0a 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -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); diff --git a/src/pop3/pop3-settings.c b/src/pop3/pop3-settings.c index ae749614da..cd9767872d 100644 --- a/src/pop3/pop3-settings.c +++ b/src/pop3/pop3-settings.c @@ -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); } diff --git a/src/pop3/pop3-settings.h b/src/pop3/pop3-settings.h index 8555366647..12df00cc1a 100644 --- a/src/pop3/pop3-settings.h +++ b/src/pop3/pop3-settings.h @@ -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;