mail-storage-service.c revision 8d5c97bf940e43e8ec6e9f1ec8655f3b20edafbe
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* If time moves backwards more than this, kill ourself instead of sleeping. */
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen "Invalid user settings. Refer to server log for more information."
5aeb15e5817fbd4b1d8de540aa7673e3819a8030Timo Sirainen const char *set_cache_module, *set_cache_service;
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen struct master_service_settings_cache *set_cache;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *system_groups_user, *uid_source, *gid_source;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstruct module *mail_storage_service_modules = NULL;
648d24583c1574441c4fa0331a90bd4d6e7996c5Timo Sirainenmail_user_set_get_mail_debug(const struct setting_parser_info *user_info,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen mail_set = mail_user_set_get_driver_settings(user_info, user_set,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void set_keyval(struct mail_storage_service_ctx *ctx,
80fc743146da5130de34174cdaad2576f103723fTimo Sirainen struct setting_parser_context *set_parser = user->set_parser;
80fc743146da5130de34174cdaad2576f103723fTimo Sirainen const char *str;
80fc743146da5130de34174cdaad2576f103723fTimo Sirainen if (master_service_set_has_config_override(ctx->service, key)) {
80fc743146da5130de34174cdaad2576f103723fTimo Sirainen /* this setting was already overridden with -o parameter */
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen if (mail_user_set_get_mail_debug(user->user_info,
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen i_debug("Ignoring overridden (-o) userdb setting: %s",
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen if (settings_parse_line(set_parser, str) < 0) {
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainenstatic int set_line(struct mail_storage_service_ctx *ctx,
ffd9a1898a18fadfc5dce399162c25d50548f905Timo Sirainen struct setting_parser_context *set_parser = user->set_parser;
1e923fcf497665fe071a154c31fb452766b0b2deTimo Sirainen const char *key;
d161e3c2cde2bd8d5917840f68823a2259ed426eTimo Sirainen mail_debug = mail_user_set_get_mail_debug(user->user_info,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen if (!settings_parse_is_valid_key(set_parser, key)) {
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen /* assume it's a plugin setting */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen if (master_service_set_has_config_override(ctx->service, key)) {
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen /* this setting was already overridden with -o parameter */
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen i_debug("Ignoring overridden (-o) userdb setting: %s",
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen "Unknown userdb setting: %s" :
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainenstatic bool validate_chroot(const struct mail_user_settings *user_set,
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen const char *dir)
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen const char *const *chroot_dirs;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen chroot_dirs = t_strsplit(user_set->valid_chroot_dirs, ":");
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen strncmp(dir, *chroot_dirs, strlen(*chroot_dirs)) == 0)
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainenuser_reply_handle(struct mail_storage_service_ctx *ctx,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen const char **error_r)
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen unsigned int i, count;
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen set_keyval(ctx, user, "mail_uid", dec2str(reply->uid));
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen set_keyval(ctx, user, "mail_gid", dec2str(reply->gid));
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* wu-ftpd like <chroot>/./<home> - check only if there's even
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen a possibility of using them (non-empty valid_chroot_dirs) */
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen set_keyval(ctx, user, "mail_home", reply->home);
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen if (!validate_chroot(user->user_set, chroot)) {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen "userdb returned invalid chroot directory: %s "
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen str = array_get(&reply->extra_fields, &count);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen if (strncmp(line, "system_groups_user=", 19) == 0) {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen if (n != 0) {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen *error_r = t_strdup_printf("Invalid userdb input '%s': %s",
6825360d446542046757b06064282301c4c6b27cTimo Sirainen str[i], settings_parser_get_error(user->set_parser));
6825360d446542046757b06064282301c4c6b27cTimo Sirainenservice_auth_userdb_lookup(struct mail_storage_service_ctx *ctx,
6825360d446542046757b06064282301c4c6b27cTimo Sirainen const struct mail_storage_service_input *input,
6825360d446542046757b06064282301c4c6b27cTimo Sirainen const char *const **fields_r,
c8d093d149253fe8faec267c5057f45fe626f84cTimo Sirainen const char **error_r)
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ret = auth_master_user_lookup(ctx->conn, *user, &info, pool,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen i_debug("changed username to %s", new_username);
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen } else if (ret == 0)
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainenstatic bool parse_uid(const char *str, uid_t *uid_r, const char **error_r)
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen *error_r = t_strdup_printf("getpwnam(%s) failed: %m", str);
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen *error_r = t_strconcat("Unknown UNIX UID user: ", str, NULL);
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainenstatic bool parse_gid(const char *str, gid_t *gid_r, const char **error_r)
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen *error_r = t_strdup_printf("getgrnam(%s) failed: %m", str);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen *error_r = t_strconcat("Unknown UNIX GID group: ", str, NULL);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenservice_drop_privileges(struct mail_storage_service_user *user,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen if (!parse_uid(set->mail_uid, &rset.uid, &error)) {
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen *error_r = t_strdup_printf("%s (from %s)", error,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen "Mail access for users with UID %s not permitted "
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen "(see first_valid_uid in config file, uid from %s).",
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen *error_r = "User is missing UID (see mail_uid setting)";
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen if (!parse_gid(set->mail_gid, &rset.gid, &error)) {
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen *error_r = t_strdup_printf("%s (from %s)", error,
c53e8ee216904ffe6de4f6518d9f9f5107b7610eTimo Sirainen "Mail access for users with GID %s not permitted "
c53e8ee216904ffe6de4f6518d9f9f5107b7610eTimo Sirainen "(see first_valid_gid in config file, gid from %s).",
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen } else if (rset.gid == (gid_t)-1 && disallow_root &&
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen *error_r = "User is missing GID (see mail_gid setting)";
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen if (!parse_gid(set->mail_privileged_group, &rset.privileged_gid,
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen "%s (in mail_privileged_group setting)", error);
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen rset.extra_groups = t_strconcat(set->mail_access_groups, ",",
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen /* we can't chroot if we want to switch between users. there's not
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen much point either (from security point of view) */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen rset.chroot_dir = *chroot == '\0' || keep_setuid_root ? NULL : chroot;
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen rset.system_groups_user = user->system_groups_user;
14c474d9f4591c397ed0b5206af6537c7b52c924Timo Sirainen cur_chroot = restrict_access_get_current_chroot();
e3689d0f073341e844638f34e1e4d0b7bb053cc8Timo Sirainen "can't un-chroot for this user";
e3689d0f073341e844638f34e1e4d0b7bb053cc8Timo Sirainen if (strcmp(rset.chroot_dir, cur_chroot) != 0) {
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen "Process is already chrooted to %s, "
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* chrooting to same directory where we're already chrooted */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen (rset.uid == 0 || (rset.uid == (uid_t)-1 && current_euid == 0))) {
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen *error_r = "Mail access not allowed for root";
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* we're changing the UID,
1f80b32fc28f7a723ff07c1694230a090808b506Timo Sirainen switch back to root first */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen restrict_access(&rset, *home == '\0' ? NULL : home,
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen i_fatal("seteuid(%s) failed: %m", dec2str(setuid_uid));
94aa90d2d17a7aebcda5a4193a62e80ddbb169b7Timo Sirainenmail_storage_service_init_post(struct mail_storage_service_ctx *ctx,
af1e2b2ab5d1c5ca5afe482ef8c8161c17acc190Timo Sirainen const char *home, struct mail_user **mail_user_r,
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen const char **error_r)
95a284736b8b11319a3f575ba249ba2eb7dbac1bTimo Sirainen mail_user = mail_user_alloc(user->input.username, user->user_info,
94aa90d2d17a7aebcda5a4193a62e80ddbb169b7Timo Sirainen mail_user_set_home(mail_user, *home == '\0' ? NULL : home);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen mail_user_set_vars(mail_user, geteuid(), ctx->service->name,
94aa90d2d17a7aebcda5a4193a62e80ddbb169b7Timo Sirainen &user->input.local_ip, &user->input.remote_ip);
94aa90d2d17a7aebcda5a4193a62e80ddbb169b7Timo Sirainen mail_set = mail_user_set_get_storage_set(mail_user);
0b49cfeae91a4020a404714b11c99e8e955fb631Timo Sirainen dec2str(geteuid()), dec2str(getegid()), home);
da5d50534cfca45d0aaaf0bdac17b287b4588809Timo Sirainen if ((user->flags & MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP) != 0 &&
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen (user->flags & MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS) == 0) {
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* we don't want to write core files to any users' home
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen directories since they could contain information about other
1fd0d511885c30028aba388588151acf4ee85e75Timo Sirainen users' mails as well. so do no chdiring to home. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen (user->flags & MAIL_STORAGE_SERVICE_FLAG_NO_CHDIR) == 0) {
1fd0d511885c30028aba388588151acf4ee85e75Timo Sirainen /* If possible chdir to home directory, so that core file
da5d50534cfca45d0aaaf0bdac17b287b4588809Timo Sirainen could be written in case we crash. */
0c27b881989bc2b391281650ee89a8cc4d89f5e7Timo Sirainen if ((user->flags & MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES) == 0) {
0c27b881989bc2b391281650ee89a8cc4d89f5e7Timo Sirainen if (mail_namespaces_init(mail_user, error_r) < 0) {
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainenstatic const struct var_expand_table *
ee246b46953e4b94b2f22e093373674fa9155500Timo Sirainenget_var_expand_table(struct master_service *service,
1fd0d511885c30028aba388588151acf4ee85e75Timo Sirainen static struct var_expand_table static_tab[] = {
1fd0d511885c30028aba388588151acf4ee85e75Timo Sirainen tab[1].value = t_strcut(input->username, '@');
1fd0d511885c30028aba388588151acf4ee85e75Timo Sirainen tab[5].value = net_ip2addr(&input->remote_ip);
1fd0d511885c30028aba388588151acf4ee85e75Timo Sirainenstatic const char *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenuser_expand_varstr(struct master_service *service,
1fd0d511885c30028aba388588151acf4ee85e75Timo Sirainen struct mail_storage_service_input *input, const char *str)
41e6eb07b411ea58352ba9d2cc8cf340325d49f3Timo Sirainen i_assert(*str == SETTING_STRVAR_UNEXPANDED[0]);
41e6eb07b411ea58352ba9d2cc8cf340325d49f3Timo Sirainen var_expand(ret, str + 1, get_var_expand_table(service, input));
41e6eb07b411ea58352ba9d2cc8cf340325d49f3Timo Sirainenmail_storage_service_init_log(struct mail_storage_service_ctx *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen var_expand(str, user->user_set->mail_log_prefix,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen get_var_expand_table(ctx->service, &user->input));
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen master_service_init_log(ctx->service, str_c(str));
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstatic void mail_storage_service_time_moved(time_t old_time, time_t new_time)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen i_warning("Time jumped forwards %ld seconds", diff);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen i_fatal("Time just moved backwards by %ld seconds. "
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen "This might cause a lot of problems, "
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen "so I'll just kill myself now. "
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen "http://wiki2.dovecot.org/TimeMovedBackwards", diff);
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen i_error("Time just moved backwards by %ld seconds. "
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen "I'll sleep now until we're back in present. "
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen "http://wiki2.dovecot.org/TimeMovedBackwards", diff);
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen /* Sleep extra second to make sure usecs also grows. */
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen /* don't use sleep()'s return value, because
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen it could get us to a long loop in case
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen interrupts just keep coming */
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainenmail_storage_service_init(struct master_service *service,
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen const struct setting_parser_info *set_roots[],
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen unsigned int count;
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen io_loop_set_time_moved_callback(current_ioloop,
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen pool = pool_alloconly_create("mail storage service", 2048);
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen ctx = p_new(pool, struct mail_storage_service_ctx, 1);
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen /* @UNSAFE */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen for (count = 0; set_roots[count] != NULL; count++) ;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen p_new(pool, const struct setting_parser_info *, count + 2);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen ctx->set_roots[0] = &mail_user_setting_parser_info;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* do all the global initialization. delay initializing plugins until
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen we drop privileges the first time. */
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen if ((flags & MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT) == 0) {
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen /* note: we may not have read any settings yet, so this logging
dec85d9856c33f427a06dda01e0e50de0bc8fa7dTimo Sirainen may still be going to wrong location */
dec85d9856c33f427a06dda01e0e50de0bc8fa7dTimo Sirainen const char *log_prefix = t_strconcat(service->name, ": ", NULL);
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen io_loop_set_default_log_prefix(current_ioloop, log_prefix);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenmail_storage_service_get_auth_conn(struct mail_storage_service_ctx *ctx)
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainenmail_storage_service_input_get_flags(struct mail_storage_service_ctx *ctx,
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen const struct mail_storage_service_input *input)
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen flags = (ctx->flags & ~input->flags_override_remove) |
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* FIXME: for API backwards compatibility only */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen flags &= ~MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_storage_service_read_settings(struct mail_storage_service_ctx *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_storage_service_input *input,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct setting_parser_info **user_info_r,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct setting_parser_context **parser_r,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char **error_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct master_service_settings_input set_input;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct setting_parser_info *const *roots;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct master_service_settings_output set_output;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct dynamic_settings_parser *dyn_parsers;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int i;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_storage_service_input_get_flags(ctx, input);
15cc66ca72982a43e3bfa58f307adc57e9caa52dTimo Sirainen /* settings reader may exec doveconf, which is going to clear
15cc66ca72982a43e3bfa58f307adc57e9caa52dTimo Sirainen environment, and if we're not doing a userdb lookup we want to
a045c3aba2610c6ed0bf1c346df1c6d8f7b9fbfdTimo Sirainen (flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) == 0;
c61d52810496376a2ea60b8f4e27bbcaa8754f3fTimo Sirainen (flags & MAIL_STORAGE_SERVICE_FLAG_USE_SYSEXITS) != 0;
2bd96c58be42146cb84076331604cadb2994fce5Timo Sirainen ctx->set_cache_module = p_strdup(ctx->pool, set_input.module);
2bd96c58be42146cb84076331604cadb2994fce5Timo Sirainen ctx->set_cache_service = p_strdup(ctx->pool, set_input.service);
5cc772dc8b507be0bc1996b5717943ba13432e08Timo Sirainen ctx->set_cache = master_service_settings_cache_init(
27db4ce5fe399c981e09dcf9e885a1546afd34f4Timo Sirainen ctx->service, set_input.module, set_input.service);
5cc772dc8b507be0bc1996b5717943ba13432e08Timo Sirainen /* already looked up settings at least once.
5cc772dc8b507be0bc1996b5717943ba13432e08Timo Sirainen we really shouldn't be execing anymore. */
ccffbed92cb02c24fd717808a84138240bf1885bTimo Sirainen dyn_parsers = mail_storage_get_dynamic_parsers(pool);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if (null_strcmp(set_input.module, ctx->set_cache_module) == 0 &&
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen null_strcmp(set_input.service, ctx->set_cache_service) == 0) {
ccffbed92cb02c24fd717808a84138240bf1885bTimo Sirainen if (master_service_settings_cache_read(ctx->set_cache,
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen settings_parser_dyn_update(pool, &set_input.roots, dyn_parsers);
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen if (master_service_settings_read(ctx->service, &set_input,
e3689d0f073341e844638f34e1e4d0b7bb053cc8Timo Sirainen mail_user_setting_parser_info.module_name) == 0) {
1f80b32fc28f7a723ff07c1694230a090808b506Timo Sirainenmail_storage_service_first_init(struct mail_storage_service_ctx *ctx,
93688bfedcfb2b9c02750b8d4d409123a386de5cTimo Sirainen ctx->debug = mail_user_set_get_mail_debug(user_info, user_set);
1f80b32fc28f7a723ff07c1694230a090808b506Timo Sirainen if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_IDLE_TIMEOUT) != 0)
e156adefc1260d31a145df2f5e9b3c82050d4163Timo Sirainen ctx->conn = auth_master_init(user_set->auth_socket_path, flags);
93688bfedcfb2b9c02750b8d4d409123a386de5cTimo Sirainenmail_storage_service_load_modules(struct mail_storage_service_ctx *ctx,
1f80b32fc28f7a723ff07c1694230a090808b506Timo Sirainen if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_PLUGINS) != 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mod_set.version = master_service_get_version_string(ctx->service);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mod_set.binary_name = master_service_get_name(ctx->service);
ef5fb27361cc5e15766e85e28355750ff04b13c9Timo Sirainen mod_set.debug = mail_user_set_get_mail_debug(user_info, user_set);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen module_dir_load_missing(mail_storage_service_modules,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_storage_service_lookup(struct mail_storage_service_ctx *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_storage_service_input *input,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char **error_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct setting_parser_context *set_parser;
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen user_pool = pool_alloconly_create("mail storage service user", 1024*5);
1dd875d96ab5640f78250079961c10e99ed4aa79Timo Sirainen if (mail_storage_service_read_settings(ctx, input, user_pool,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen flags = mail_storage_service_input_get_flags(ctx, input);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if ((flags & MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT) == 0 &&
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* initialize logging again, in case we only read the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen settings for the first above */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user_set = settings_parser_get_list(set_parser)[1];
error_r);
if (ret <= 0) {
return ret;
if (ret > 0) {
return ret;
unsigned int len;
bool disallow_root =
bool temp_priv_drop =
if (!temp_priv_drop) {
if (!temp_priv_drop ||
&error) < 0)
const char **error_r)
int ret;
if (ret <= 0)
return ret;
if (ret < 0) {
return ret;
const char *error;
&error) < 0)
const char **username_r)
const struct mail_storage_service_input *
struct setting_parser_context *
T_BEGIN {
} T_END;
return set;