mail-user.h revision c7819f72f3f9cbfa976830dc6f3190873469b901
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef MAIL_USER_H
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen#define MAIL_USER_H
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen#include "mail-storage-settings.h"
5e327e031d1591f8bff17b67eba7139afbd36cddTimo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstruct module;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstruct mail_user;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
a2fdfd2efdbb2d912aad23900a466cf74114920bTimo Sirainenstruct mail_user_vfuncs {
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen void (*deinit)(struct mail_user *user);
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi};
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
c6be98b5270900746f35ebe28bd636019976e29eTimo Sirainenstruct mail_user {
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen pool_t pool;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen struct mail_user_vfuncs v;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen int refcount;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen const char *username;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* don't access the home directly. It may be set lazily. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen const char *_home;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen uid_t uid;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen const char *service;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen struct ip_addr *local_ip, *remote_ip;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen const struct var_expand_table *var_expand_table;
5e327e031d1591f8bff17b67eba7139afbd36cddTimo Sirainen /* error during initialization */
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen const char *error;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainen const struct setting_parser_info *set_info;
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainen const struct mail_user_settings *unexpanded_set;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen struct mail_user_settings *set;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen struct mail_namespace *namespaces;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen struct mail_storage *storages;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen ARRAY_DEFINE(hooks, const struct mail_storage_hooks *);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_user_module_context *);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* Either home is set or there is no home for the user. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen unsigned int home_looked_up:1;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* User is an administrator. Allow operations not normally allowed
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen for other people. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen unsigned int admin:1;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi /* mail_user_init() has been called */
f300f927771a39549ce6cb7607129508e9041b4aStephan Bosch unsigned int initialized:1;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi /* Shortcut to mail_storage_settings.mail_debug */
e60c3e17c656c53da60f0ac51aa15e9ef2742d77Stephan Bosch unsigned int mail_debug:1;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi /* If INBOX can't be opened, log an error, but only once. */
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi unsigned int inbox_open_error_logged:1;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen};
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainenstruct mail_user_module_register {
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen unsigned int id;
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen};
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainenunion mail_user_module_context {
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen struct mail_user_vfuncs super;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi struct mail_user_module_register *reg;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi};
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomiextern struct mail_user_module_register mail_user_module_register;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomiextern struct auth_master_connection *mail_user_auth_master_conn;
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomistruct mail_user *mail_user_alloc(const char *username,
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen const struct setting_parser_info *set_info,
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen const struct mail_user_settings *set);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Returns -1 if settings were invalid. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenint mail_user_init(struct mail_user *user, const char **error_r);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid mail_user_ref(struct mail_user *user);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid mail_user_unref(struct mail_user **user);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Find another user from the given user's namespaces. */
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainenstruct mail_user *mail_user_find(struct mail_user *user, const char *name);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Specify mail location %variable expansion data. */
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainenvoid mail_user_set_vars(struct mail_user *user, uid_t uid, const char *service,
5e327e031d1591f8bff17b67eba7139afbd36cddTimo Sirainen const struct ip_addr *local_ip,
5e327e031d1591f8bff17b67eba7139afbd36cddTimo Sirainen const struct ip_addr *remote_ip);
5e327e031d1591f8bff17b67eba7139afbd36cddTimo Sirainen/* Return %variable expansion table for the user. */
5e327e031d1591f8bff17b67eba7139afbd36cddTimo Sirainenconst struct var_expand_table *
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenmail_user_var_expand_table(struct mail_user *user);
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen/* Specify the user's home directory. This should be called also when it's
a13b1245bee0b6524b4aeb3c8fd9e34af648b746Aki Tuomi known that the user doesn't have a home directory to avoid the internal
c6be98b5270900746f35ebe28bd636019976e29eTimo Sirainen lookup. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid mail_user_set_home(struct mail_user *user, const char *home);
a2fdfd2efdbb2d912aad23900a466cf74114920bTimo Sirainen/* Get the home directory for the user. Returns 1 if home directory looked up
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen successfully, 0 if there is no home directory (either user doesn't exist or
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen has no home directory) or -1 if lookup failed. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenint mail_user_get_home(struct mail_user *user, const char **home_r);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Returns path + file prefix for creating a temporary file. Uses home
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen directory if possible, fallbacks to mail directory. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenconst char *mail_user_get_temp_prefix(struct mail_user *user);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Returns TRUE if plugin is loaded for the user. */
c6be98b5270900746f35ebe28bd636019976e29eTimo Sirainenbool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* If name exists in plugin_envs, return its value. */
a2fdfd2efdbb2d912aad23900a466cf74114920bTimo Sirainenconst char *mail_user_plugin_getenv(struct mail_user *user, const char *name);
237a6211c7fc4d6dbb58dd0467da6dba1b8f21f6Timo Sirainenconst char *mail_user_set_plugin_getenv(const struct mail_user_settings *set,
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen const char *name);
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainen/* Add more namespaces to user's namespaces. The ->next pointers may be
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen changed, so the namespaces pointer will be updated to user->namespaces. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid mail_user_add_namespace(struct mail_user *user,
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen struct mail_namespace **namespaces);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Drop autocreated shared namespaces that don't have any "usable" mailboxes. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid mail_user_drop_useless_namespaces(struct mail_user *user);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* Replace ~/ at the beginning of the path with the user's home directory. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenconst char *mail_user_home_expand(struct mail_user *user, const char *path);
2d1892aaeb63b9774237b6e60d6bb04bf6f8259cTimo Sirainen/* Returns 0 if ok, -1 if home directory isn't set. */
2d1892aaeb63b9774237b6e60d6bb04bf6f8259cTimo Sirainenint mail_user_try_home_expand(struct mail_user *user, const char **path);
c1fc5a97a15332f1253ee13a9cab65a7b4b6cd5fTimo Sirainen/* Returns unique user+ip identifier for anvil. */
c1fc5a97a15332f1253ee13a9cab65a7b4b6cd5fTimo Sirainenconst char *mail_user_get_anvil_userip_ident(struct mail_user *user);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
107659c01b2359b0ee426bde020c8d4e29ede30dTimo Sirainen#endif
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen