mail-user.h revision 691f802ef6ec2105079d420ba26b21088402c6da
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen#ifndef MAIL_USER_H
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen#define MAIL_USER_H
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainen#include "unichar.h"
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen#include "mail-storage-settings.h"
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct module;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct stats;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct fs_settings;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct ssl_iostream_settings;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct mail_user;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct mail_user_vfuncs {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen void (*deinit)(struct mail_user *user);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen void (*stats_fill)(struct mail_user *user, struct stats *stats);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen};
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct mail_user {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen pool_t pool;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_user_vfuncs v, *vlast;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen int refcount;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* User's creator if such exists. For example for autocreated shared
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen mailbox users their creator is the logged in user. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_user *creator;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Set if user was created via mail_storage_service. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_storage_service_user *_service_user;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *username;
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen /* don't access the home directly. It may be set lazily. */
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen const char *_home;
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainen uid_t uid;
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainen gid_t gid;
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainen const char *service;
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainen const char *session_id;
7db7fbea5d8a07463b625f93d69166d56018dadfTimo Sirainen struct ip_addr *local_ip, *remote_ip;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *auth_token, *auth_user;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *const *userdb_fields;
b4a7dbfb4256abcd2f983d56bd032acd55f59591Timo Sirainen
b4a7dbfb4256abcd2f983d56bd032acd55f59591Timo Sirainen const struct var_expand_table *var_expand_table;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* If non-NULL, fail the user initialization with this error.
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen This could be set by plugins that need to fail the initialization. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *error;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const struct setting_parser_info *set_info;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const struct mail_user_settings *unexpanded_set;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_user_settings *set;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_namespace *namespaces;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_storage *storages;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen ARRAY(const struct mail_storage_hooks *) hooks;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen normalizer_func_t *default_normalizer;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Filled lazily by mailbox_attribute_*() when accessing attributes. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct dict *_attr_dict;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen ARRAY(union mail_user_module_context *) module_contexts;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* User doesn't exist (as reported by userdb lookup when looking
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen up home) */
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen unsigned int nonexistent:1;
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen /* Either home is set or there is no home for the user. */
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen unsigned int home_looked_up:1;
cb3ab2fd5668700a89b274a43595cfbfa1616e4bTimo Sirainen /* User is anonymous */
4487c66123ca4830f8afbf4efcd7a260848d0e05Timo Sirainen unsigned int anonymous:1;
4487c66123ca4830f8afbf4efcd7a260848d0e05Timo Sirainen /* This is an autocreated user (e.g. for shared namespace or
4487c66123ca4830f8afbf4efcd7a260848d0e05Timo Sirainen lda raw storage) */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int autocreated:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* mail_user_init() has been called */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int initialized:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Shortcut to mail_storage_settings.mail_debug */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int mail_debug:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* If INBOX can't be opened, log an error, but only once. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int inbox_open_error_logged:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Fuzzy search works for this user (FTS enabled) */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int fuzzy_search:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* We're running dsync */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int dsyncing:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Failed to create attribute dict, don't try again */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int attr_dict_failed:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* We're deinitializing the user */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int deinitializing:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* Enable administrator user commands for the user */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int admin:1;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen};
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct mail_user_module_register {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int id;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen};
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenunion mail_user_module_context {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_user_vfuncs super;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen struct mail_user_module_register *reg;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen};
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct mail_user_module_register mail_user_module_register;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenextern struct auth_master_connection *mail_user_auth_master_conn;
a618726eb3eb09a3866fe93208baf923d593f4d3Timo Sirainenextern const struct var_expand_func_table *mail_user_var_expand_func_table;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct mail_user *mail_user_alloc(const char *username,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const struct setting_parser_info *set_info,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const struct mail_user_settings *set);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Returns -1 if settings were invalid. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenint mail_user_init(struct mail_user *user, const char **error_r);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid mail_user_ref(struct mail_user *user);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid mail_user_unref(struct mail_user **user);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Duplicate a mail_user. mail_user_init() and mail_namespaces_init() need to
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen be called before the user is usable. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstruct mail_user *mail_user_dup(struct mail_user *user);
67e0afe62b26d222614b8d817155bf5c74bd7fe0Stephan Bosch
67e0afe62b26d222614b8d817155bf5c74bd7fe0Stephan Bosch/* Find another user from the given user's namespaces. */
67e0afe62b26d222614b8d817155bf5c74bd7fe0Stephan Boschstruct mail_user *mail_user_find(struct mail_user *user, const char *name);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Specify mail location %variable expansion data. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid mail_user_set_vars(struct mail_user *user, const char *service,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const struct ip_addr *local_ip,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const struct ip_addr *remote_ip);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Return %variable expansion table for the user. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenconst struct var_expand_table *
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenmail_user_var_expand_table(struct mail_user *user);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Specify the user's home directory. This should be called also when it's
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen known that the user doesn't have a home directory to avoid the internal
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen lookup. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid mail_user_set_home(struct mail_user *user, const char *home);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Get the home directory for the user. Returns 1 if home directory looked up
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen successfully, 0 if there is no home directory (either user doesn't exist or
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen has no home directory) or -1 if lookup failed. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenint mail_user_get_home(struct mail_user *user, const char **home_r);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Appends path + file prefix for creating a temporary file.
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen The file prefix doesn't contain any uniqueness. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenvoid mail_user_set_get_temp_prefix(string_t *dest,
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const struct mail_user_settings *set);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Returns TRUE if plugin is loaded for the user. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenbool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* If name exists in plugin_envs, return its value. */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenconst char *mail_user_plugin_getenv(struct mail_user *user, const char *name);
const char *mail_user_set_plugin_getenv(const struct mail_user_settings *set,
const char *name);
/* Add more namespaces to user's namespaces. The ->next pointers may be
changed, so the namespaces pointer will be updated to user->namespaces. */
void mail_user_add_namespace(struct mail_user *user,
struct mail_namespace **namespaces);
/* Drop autocreated shared namespaces that don't have any "usable" mailboxes. */
void mail_user_drop_useless_namespaces(struct mail_user *user);
/* Replace ~/ at the beginning of the path with the user's home directory. */
const char *mail_user_home_expand(struct mail_user *user, const char *path);
/* Returns 0 if ok, -1 if home directory isn't set. */
int mail_user_try_home_expand(struct mail_user *user, const char **path);
/* Returns unique user+ip identifier for anvil. */
const char *mail_user_get_anvil_userip_ident(struct mail_user *user);
/* Basically the same as mail_storage_find_class(), except automatically load
storage plugins when needed. */
struct mail_storage *
mail_user_get_storage_class(struct mail_user *user, const char *name);
/* Initialize fs_settings from mail_user settings. */
void mail_user_init_fs_settings(struct mail_user *user,
struct fs_settings *fs_set,
struct ssl_iostream_settings *ssl_set);
/* Fill statistics for user. By default there are no statistics, so stats
plugin must be loaded to have anything filled. */
void mail_user_stats_fill(struct mail_user *user, struct stats *stats);
#endif