mail-storage-service.c revision d2ca20a479e76af8557b4a74b0b51e4de0e3c9e3
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2009-2013 Dovecot authors, see the included COPYING file */
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen/* If time moves backwards more than this, kill ourself instead of sleeping. */
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen "Invalid user settings. Refer to server log for more information."
b346610430690398b8c840006004a2df4aa8ce92Timo Sirainen struct auth_master_connection *conn, *iter_conn;
659fe5d24825b160cae512538088020d97a60239Timo Sirainen const char *set_cache_module, *set_cache_service;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen struct master_service_settings_cache *set_cache;
7212243efb0d8fa1cd8b2e37b7498323540b9e97Timo Sirainen const char *const **userdb_next_fieldsp;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen const char *system_groups_user, *uid_source, *gid_source;
7212243efb0d8fa1cd8b2e37b7498323540b9e97Timo Sirainenstruct module *mail_storage_service_modules = NULL;
7212243efb0d8fa1cd8b2e37b7498323540b9e97Timo Sirainenmail_user_set_get_mail_debug(const struct setting_parser_info *user_info,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen mail_set = mail_user_set_get_driver_settings(user_info, user_set,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainenstatic void set_keyval(struct mail_storage_service_ctx *ctx,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen struct setting_parser_context *set_parser = user->set_parser;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen const char *str;
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen if (master_service_set_has_config_override(ctx->service, key)) {
659fe5d24825b160cae512538088020d97a60239Timo Sirainen /* this setting was already overridden with -o parameter */
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen if (mail_user_set_get_mail_debug(user->user_info,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen i_debug("Ignoring overridden (-o) userdb setting: %s",
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen if (settings_parse_line(set_parser, str) < 0) {
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainenstatic int set_line(struct mail_storage_service_ctx *ctx,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen struct setting_parser_context *set_parser = user->set_parser;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen const char *key, *orig_key, *append_value = NULL;
40a5aeebf6b4858b93f0ddff0bf12fba769cf903Timo Sirainen unsigned int len;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen mail_debug = mail_user_set_get_mail_debug(user->user_info,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen /* key+=value */
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen if (!settings_parse_is_valid_key(set_parser, key)) {
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen /* assume it's a plugin setting */
5ada3f57a970f226eb29956d30f66afc3537200dTimo Sirainen if (master_service_set_has_config_override(ctx->service, key)) {
5ada3f57a970f226eb29956d30f66afc3537200dTimo Sirainen /* this setting was already overridden with -o parameter */
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen i_debug("Ignoring overridden (-o) userdb setting: %s",
61ddcdc28f50d9cb9994fcc4ad63f9dff0e80628Timo Sirainen value = settings_parse_get_value(set_parser, key, &type);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen "'+' can only be used for strings.", orig_key);
5d1833b98fa85d8061626aa986f38dcbcd70553eTimo Sirainen /* possibly a password field (e.g. imapc_password).
5d1833b98fa85d8061626aa986f38dcbcd70553eTimo Sirainen hide the value. */
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen "Unknown userdb setting: %s" :
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic bool validate_chroot(const struct mail_user_settings *user_set,
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen const char *dir)
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen const char *const *chroot_dirs;
9404a7b90dcb80d31bd37ee2493f03751acdb1bdTimo Sirainen chroot_dirs = t_strsplit(user_set->valid_chroot_dirs, ":");
9404a7b90dcb80d31bd37ee2493f03751acdb1bdTimo Sirainen strncmp(dir, *chroot_dirs, strlen(*chroot_dirs)) == 0)
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainenuser_reply_handle(struct mail_storage_service_ctx *ctx,
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen const char **error_r)
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen unsigned int i, count;
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen set_keyval(ctx, user, "mail_uid", dec2str(reply->uid));
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen set_keyval(ctx, user, "mail_gid", dec2str(reply->gid));
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen /* wu-ftpd like <chroot>/./<home> - check only if there's even
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen a possibility of using them (non-empty valid_chroot_dirs) */
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen if (!validate_chroot(user->user_set, chroot)) {
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen "userdb returned invalid chroot directory: %s "
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen str = array_get(&reply->extra_fields, &count);
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen for (i = 0; i < count; i++) {
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen if (strncmp(line, "system_groups_user=", 19) == 0) {
#ifdef HAVE_SETPRIORITY
} else T_BEGIN {
} T_END;
if (ret < 0)
if (ret < 0) {
return ret;
const char *const **fields_r,
const char **error_r)
const char *new_username;
int ret;
if (ret > 0) {
} else if (ret == 0)
return ret;
return TRUE;
return FALSE;
return FALSE;
return TRUE;
return TRUE;
return FALSE;
return FALSE;
return TRUE;
static const struct var_expand_table *
return tab;
const struct var_expand_table *
const char *str)
const char **error_r)
static void mail_storage_service_seteuid_root(void)
if (seteuid(0) < 0) {
&error)) {
if (disallow_root &&
if (keep_setuid_root) {
if (current_euid != 0) {
if (!setenv_only) {
const char **error_r)
T_BEGIN {
} T_END;
user);
if (diff > 0) {
diff++;
struct mail_storage_service_ctx *
const char *version;
unsigned int count;
geteuid() != 0) {
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)
void **sets;
geteuid() != 0) {
&error) < 0) {
error_r);
if (ret <= 0) {
return ret;
if (ret > 0) {
return ret;
const char *error;
unsigned int len;
bool disallow_root =
bool temp_priv_drop =
bool use_chroot;
if (use_chroot) {
if (!temp_priv_drop ||
const char *error;
const char **error_r)
int ret;
if (ret <= 0)
return ret;
if (ret < 0) {
return ret;
const char *error;
void **sets;
&error) < 0)
int ret = 0;
return ret;
flags);
const char **username_r)
const struct mail_storage_settings *
const struct mail_storage_service_input *
struct setting_parser_context *
T_BEGIN {
} T_END;
return set;