mail-storage-service.c revision 6727b100f6afdde039efc755a7cf45c93362f347
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen/* If time moves backwards more than this, kill ourself instead of sleeping. */
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen "Invalid user settings. Refer to server log for more information."
2eccb2637d0153bb7f9ad39a70f254cece74342cTimo Sirainen const char *set_cache_module, *set_cache_service;
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen struct master_service_settings_cache *set_cache;
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen const char *system_groups_user, *uid_source, *gid_source;
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainenstruct module *mail_storage_service_modules = NULL;
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainenmail_user_set_get_mail_debug(const struct setting_parser_info *user_info,
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainen mail_set = mail_user_set_get_driver_settings(user_info, user_set,
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainenstatic void set_keyval(struct mail_storage_service_ctx *ctx,
a01faca549a403b2eda938cea0b1fb76c3ff44b6Aki Tuomi struct setting_parser_context *set_parser = user->set_parser;
a01faca549a403b2eda938cea0b1fb76c3ff44b6Aki Tuomi const char *str;
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen if (master_service_set_has_config_override(ctx->service, key)) {
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen /* this setting was already overridden with -o parameter */
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen if (mail_user_set_get_mail_debug(user->user_info,
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen i_debug("Ignoring overridden (-o) userdb setting: %s",
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen if (settings_parse_line(set_parser, str) < 0) {
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainenstatic int set_line(struct mail_storage_service_ctx *ctx,
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen struct setting_parser_context *set_parser = user->set_parser;
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen const char *key, *orig_key, *append_value = NULL;
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen unsigned int len;
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen mail_debug = mail_user_set_get_mail_debug(user->user_info,
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen /* key+=value */
791fb70b3255a11a91ce0c2dc3ae1460d4cf8459Timo Sirainen if (!settings_parse_is_valid_key(set_parser, key)) {
a18e2525cb076066784967d6c8118a01dd38ac6bTimo Sirainen /* assume it's a plugin setting */
a18e2525cb076066784967d6c8118a01dd38ac6bTimo Sirainen if (master_service_set_has_config_override(ctx->service, key)) {
a18e2525cb076066784967d6c8118a01dd38ac6bTimo Sirainen /* this setting was already overridden with -o parameter */
2eccb2637d0153bb7f9ad39a70f254cece74342cTimo Sirainen i_debug("Ignoring overridden (-o) userdb setting: %s",
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen value = settings_parse_get_value(set_parser, key, &type);
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen "'+' can only be used for strings.", orig_key);
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen "Unknown userdb setting: %s" :
f6497ac81e6de57870936d538acccb75ce408fc1Timo Sirainenstatic bool validate_chroot(const struct mail_user_settings *user_set,
f6497ac81e6de57870936d538acccb75ce408fc1Timo Sirainen const char *dir)
f6497ac81e6de57870936d538acccb75ce408fc1Timo Sirainen const char *const *chroot_dirs;
f6497ac81e6de57870936d538acccb75ce408fc1Timo Sirainen chroot_dirs = t_strsplit(user_set->valid_chroot_dirs, ":");
f6497ac81e6de57870936d538acccb75ce408fc1Timo Sirainen strncmp(dir, *chroot_dirs, strlen(*chroot_dirs)) == 0)
f6497ac81e6de57870936d538acccb75ce408fc1Timo Sirainenuser_reply_handle(struct mail_storage_service_ctx *ctx,
f6ae9ae80a1fcf6c8f45ab759f0074caaa66c9c8Timo Sirainen const char **error_r)
736b1800b0409ba7443d33ecb8d0fb9f8b091660Timo Sirainen unsigned int i, count;
736b1800b0409ba7443d33ecb8d0fb9f8b091660Timo Sirainen set_keyval(ctx, user, "mail_uid", dec2str(reply->uid));
f6ae9ae80a1fcf6c8f45ab759f0074caaa66c9c8Timo Sirainen set_keyval(ctx, user, "mail_gid", dec2str(reply->gid));
a18503d5dc0751a1f9785e48438a219d95c0b9c2Timo Sirainen /* wu-ftpd like <chroot>/./<home> - check only if there's even
a18503d5dc0751a1f9785e48438a219d95c0b9c2Timo Sirainen a possibility of using them (non-empty valid_chroot_dirs) */
f6ae9ae80a1fcf6c8f45ab759f0074caaa66c9c8Timo Sirainen if (!validate_chroot(user->user_set, chroot)) {
f6ae9ae80a1fcf6c8f45ab759f0074caaa66c9c8Timo Sirainen "userdb returned invalid chroot directory: %s "
736b1800b0409ba7443d33ecb8d0fb9f8b091660Timo Sirainen str = array_get(&reply->extra_fields, &count);
736b1800b0409ba7443d33ecb8d0fb9f8b091660Timo Sirainen if (strncmp(line, "system_groups_user=", 19) == 0) {
a01faca549a403b2eda938cea0b1fb76c3ff44b6Aki Tuomi if (n != 0) {
736b1800b0409ba7443d33ecb8d0fb9f8b091660Timo Sirainen *error_r = t_strdup_printf("Invalid userdb input '%s': %s",
10972f2a15f5538860fcc1d4adda227d59d2d757Timo Sirainen str[i], settings_parser_get_error(user->set_parser));
10972f2a15f5538860fcc1d4adda227d59d2d757Timo Sirainenservice_auth_userdb_lookup(struct mail_storage_service_ctx *ctx,
10972f2a15f5538860fcc1d4adda227d59d2d757Timo Sirainen const struct mail_storage_service_input *input,
10972f2a15f5538860fcc1d4adda227d59d2d757Timo Sirainen const char *const **fields_r,
bb869cc24b24a8df84a43154c628785d6aee784cTimo Sirainen const char **error_r)
bb869cc24b24a8df84a43154c628785d6aee784cTimo Sirainen ret = auth_master_user_lookup(ctx->conn, *user, &info, pool,
f6497ac81e6de57870936d538acccb75ce408fc1Timo Sirainen i_debug("changed username to %s", new_username);
bb869cc24b24a8df84a43154c628785d6aee784cTimo Sirainen } else if (ret == 0)
return ret;
return TRUE;
return FALSE;
return FALSE;
return TRUE;
return TRUE;
return FALSE;
return FALSE;
return TRUE;
&error)) {
if (disallow_root &&
if (keep_setuid_root) {
if (current_euid != 0) {
if (seteuid(0) < 0)
if (!setenv_only) {
const char **error_r)
static const struct var_expand_table *
return tab;
T_BEGIN {
} T_END;
user);
if (diff > 0) {
diff++;
struct mail_storage_service_ctx *
unsigned int count;
count = 0;
return ctx;
struct auth_master_connection *
static enum mail_storage_service_flags
return flags;
const char **error_r)
i_unreached();
const char **error_r)
&error) < 0) {
error_r);
if (ret <= 0) {
return ret;
if (ret > 0) {
return ret;
unsigned int len;
bool disallow_root =
bool temp_priv_drop =
bool use_chroot;
if (use_chroot) {
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;