mail-user.h revision f534c0d42f1470fca8e4ff3493c94927bf600260
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#ifndef MAIL_USER_H
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define MAIL_USER_H
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#include "mail-storage-settings.h"
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcestruct module;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcestruct mail_user;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcestruct mail_user_vfuncs {
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce void (*deinit)(struct mail_user *user);
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce};
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcestruct mail_user {
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce pool_t pool;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce struct mail_user_vfuncs v, *vlast;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce int refcount;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce const char *username;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce /* don't access the home directly. It may be set lazily. */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce const char *_home;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce uid_t uid;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce const char *service;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce struct ip_addr *local_ip, *remote_ip;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce const struct var_expand_table *var_expand_table;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce /* If non-NULL, fail the user initialization with this error.
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce This could be set by plugins that need to fail the initialization. */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce const char *error;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce const struct setting_parser_info *set_info;
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce const struct mail_user_settings *unexpanded_set;
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce struct mail_user_settings *set;
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce struct mail_namespace *namespaces;
2745b0156f12df7a7eb93d57716233243658e4d9Jakub Hrozek struct mail_storage *storages;
22a21e910fd216ec1468fe769dcc29f1621a52a4Ondrej Kos ARRAY_DEFINE(hooks, const struct mail_storage_hooks *);
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce /* Module-specific contexts. See mail_storage_module_id. */
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ARRAY_DEFINE(module_contexts, union mail_user_module_context *);
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce /* Either home is set or there is no home for the user. */
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce unsigned int home_looked_up:1;
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce /* User is an administrator. Allow operations not normally allowed
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce for other people. */
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce unsigned int admin:1;
7c69221077c780e62f6c536e78675f2dc1c131bcMichal Zidek /* This is an autocreated user (e.g. for shared namespace or
7c69221077c780e62f6c536e78675f2dc1c131bcMichal Zidek lda raw storage) */
7c69221077c780e62f6c536e78675f2dc1c131bcMichal Zidek unsigned int autocreated:1;
aa7202c8ae677becd6c91d6a27a607fe0f3995eePavel Březina /* mail_user_init() has been called */
f9961e5f82e0ef474d6492371bfdf9e74e208a99Pavel Březina unsigned int initialized:1;
f9961e5f82e0ef474d6492371bfdf9e74e208a99Pavel Březina /* Shortcut to mail_storage_settings.mail_debug */
7a4e3e29196e3abc1746714fcf93624edae89f93Lukas Slebodnik unsigned int mail_debug:1;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* If INBOX can't be opened, log an error, but only once. */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek unsigned int inbox_open_error_logged:1;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek};
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
dcc6877aa2e2dd63a9dc9c411a9c58feaeb36b9aStephen Gallagherstruct mail_user_module_register {
bc30ce9b7d588a17e58012e699986f0d6898b791Pavel Březina unsigned int id;
b5ee224324b0158641d9b110f81d2bc6eddddc13Pavel Reichl};
2a96981a0ac781d01e5bba473409ed2bdf4cd4e0Jakub Hrozek
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozekunion mail_user_module_context {
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek struct mail_user_vfuncs super;
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek struct mail_user_module_register *reg;
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek};
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozekextern struct mail_user_module_register mail_user_module_register;
7a4e3e29196e3abc1746714fcf93624edae89f93Lukas Slebodnikextern struct auth_master_connection *mail_user_auth_master_conn;
60cab26b12df9a2153823972cde0c38ca86e01b9Yassir Elley
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walterstruct mail_user *mail_user_alloc(const char *username,
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek const struct setting_parser_info *set_info,
a2ea3f5d9ef9f17efbb61e942c2bc6cff7d1ebf2Jakub Hrozek const struct mail_user_settings *set);
f3a25949de81f80c136bb073e4a8f504b080c20cJakub Hrozek/* Returns -1 if settings were invalid. */
8394eddba54b5d3e3fda868145e3751247bdbdb2Michal Zidekint mail_user_init(struct mail_user *user, const char **error_r);
5a5c5cdeb92f4012fc75fd717bfea06598f68f12Pavel Reichl
7a4e3e29196e3abc1746714fcf93624edae89f93Lukas Slebodnikvoid mail_user_ref(struct mail_user *user);
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozekvoid mail_user_unref(struct mail_user **user);
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozek
7a4e3e29196e3abc1746714fcf93624edae89f93Lukas Slebodnik/* Find another user from the given user's namespaces. */
979e8d8d6ed444007eeff6be5269e8dc5d2bdf68Pavel Reichlstruct mail_user *mail_user_find(struct mail_user *user, const char *name);
7650ded4ffa87fcf7ce5adf00920fecf89cffcf5Michal Zidek
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/* Specify mail location %variable expansion data. */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcevoid mail_user_set_vars(struct mail_user *user, uid_t uid, const char *service,
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce const struct ip_addr *local_ip,
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce const struct ip_addr *remote_ip);
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/* Return %variable expansion table for the user. */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorceconst struct var_expand_table *
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcemail_user_var_expand_table(struct mail_user *user);
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/* Specify the user's home directory. This should be called also when it's
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce known that the user doesn't have a home directory to avoid the internal
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce lookup. */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcevoid mail_user_set_home(struct mail_user *user, const char *home);
/* Get the home directory for the user. Returns 1 if home directory looked up
successfully, 0 if there is no home directory (either user doesn't exist or
has no home directory) or -1 if lookup failed. */
int mail_user_get_home(struct mail_user *user, const char **home_r);
/* Appends path + file prefix for creating a temporary file.
The file prefix doesn't contain any uniqueness. */
void mail_user_set_get_temp_prefix(string_t *dest,
const struct mail_user_settings *set);
/* Returns TRUE if plugin is loaded for the user. */
bool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module);
/* If name exists in plugin_envs, return its value. */
const 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);
#endif