void sieve_tool_set_homedir(struct sieve_tool *tool, const char *homedir) { if ( tool->homedir != NULL ) { if ( strcmp(homedir, tool->homedir) == 0 ) return; i_free(tool->homedir); } tool->homedir = i_strdup(homedir); if ( tool->mail_user_dovecot != NULL ) mail_user_set_home(tool->mail_user_dovecot, tool->homedir); if ( tool->mail_user != NULL ) mail_user_set_home(tool->mail_user, tool->homedir); }
void sieve_tool_init_mail_user (struct sieve_tool *tool, const char *mail_location) { struct mail_user *mail_user_dovecot = tool->mail_user_dovecot; const char *username = tool->username; struct mail_namespace *ns = NULL; const char *home = NULL, *errstr = NULL; tool->mail_user = mail_user_alloc (username, mail_user_dovecot->set_info, mail_user_dovecot->unexpanded_set); if ( (home=sieve_tool_get_homedir(sieve_tool)) != NULL ) { mail_user_set_home(tool->mail_user, home); } if ( mail_user_init(tool->mail_user, &errstr) < 0 ) i_fatal("Test user initialization failed: %s", errstr); if ( mail_namespaces_init_location (tool->mail_user, mail_location, &errstr) < 0 ) i_fatal("Test storage creation failed: %s", errstr); ns = tool->mail_user->namespaces; ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL; }
struct mail_user * raw_storage_create_from_set(const struct setting_parser_info *set_info, const struct mail_user_settings *set) { struct mail_user *user; struct mail_namespace *ns; struct mail_namespace_settings *ns_set; struct mail_storage_settings *mail_set; const char *error; user = mail_user_alloc("raw mail user", set_info, set); user->autocreated = TRUE; mail_user_set_home(user, "/"); if (mail_user_init(user, &error) < 0) i_fatal("Raw user initialization failed: %s", error); ns_set = p_new(user->pool, struct mail_namespace_settings, 1); ns_set->name = "raw-storage"; ns_set->location = ":LAYOUT=none"; ns_set->separator = "/"; ns = mail_namespaces_init_empty(user); /* raw storage doesn't have INBOX. We especially don't want LIST to return INBOX. */ ns->flags &= ~NAMESPACE_FLAG_INBOX_USER; ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL; ns->set = ns_set; /* absolute paths are ok with raw storage */ mail_set = p_new(user->pool, struct mail_storage_settings, 1); *mail_set = *ns->mail_set; mail_set->mail_full_filesystem_access = TRUE; ns->mail_set = mail_set; if (mail_storage_create(ns, "raw", 0, &error) < 0) i_fatal("Couldn't create internal raw storage: %s", error); if (mail_namespaces_init_finish(ns, &error) < 0) i_fatal("Couldn't create internal raw namespace: %s", error); return user; }
static int mail_storage_service_init_post(struct mail_storage_service_ctx *ctx, struct mail_storage_service_user *user, struct mail_storage_service_privileges *priv, struct mail_user **mail_user_r, const char **error_r) { const struct mail_storage_settings *mail_set; const char *home = priv->home; struct mail_user *mail_user; /* NOTE: if more user initialization is added, add it also to mail_user_dup() */ mail_user = mail_user_alloc(user->input.username, user->user_info, user->user_set); mail_user->_service_user = user; mail_user_set_home(mail_user, *home == '\0' ? NULL : home); mail_user_set_vars(mail_user, ctx->service->name, &user->input.local_ip, &user->input.remote_ip); mail_user->uid = priv->uid == (uid_t)-1 ? geteuid() : priv->uid; mail_user->gid = priv->gid == (gid_t)-1 ? getegid() : priv->gid; mail_user->anonymous = user->anonymous; mail_user->admin = user->admin; mail_user->auth_token = p_strdup(mail_user->pool, user->auth_token); mail_user->auth_user = p_strdup(mail_user->pool, user->auth_user); mail_user->session_id = p_strdup(mail_user->pool, user->input.session_id); mail_user->userdb_fields = user->input.userdb_fields == NULL ? NULL : p_strarray_dup(mail_user->pool, user->input.userdb_fields); mail_user->autoexpunge_enabled = (user->flags & MAIL_STORAGE_SERVICE_FLAG_AUTOEXPUNGE) != 0; mail_set = mail_user_set_get_storage_set(mail_user); if (mail_set->mail_debug) { string_t *str = t_str_new(64); str_printfa(str, "Effective uid=%s, gid=%s, home=%s", dec2str(geteuid()), dec2str(getegid()), home); if (*priv->chroot != '\0') str_printfa(str, ", chroot=%s", priv->chroot); i_debug("%s", str_c(str)); } if ((user->flags & MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP) != 0 && (user->flags & MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS) == 0) { /* we don't want to write core files to any users' home directories since they could contain information about other users' mails as well. so do no chdiring to home. */ } else if (*home != '\0' && (user->flags & MAIL_STORAGE_SERVICE_FLAG_NO_CHDIR) == 0) { /* If possible chdir to home directory, so that core file could be written in case we crash. */ if (chdir(home) < 0) { if (errno == EACCES) { i_error("%s", eacces_error_get("chdir", t_strconcat(home, "/", NULL))); } if (errno != ENOENT) i_error("chdir(%s) failed: %m", home); else if (mail_set->mail_debug) i_debug("Home dir not found: %s", home); } } if (mail_user_init(mail_user, error_r) < 0) { mail_user_unref(&mail_user); return -1; } if ((user->flags & MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES) == 0) { if (mail_namespaces_init(mail_user, error_r) < 0) { mail_user_unref(&mail_user); return -1; } } *mail_user_r = mail_user; return 0; }