/src/dovecot/src/lib-storage/mail-user.h
Line | Count | Source |
1 | | #ifndef MAIL_USER_H |
2 | | #define MAIL_USER_H |
3 | | |
4 | | #include "net.h" |
5 | | #include "unichar.h" |
6 | | #include "mail-storage-settings.h" |
7 | | #include "process-stat.h" |
8 | | |
9 | | #define SETTINGS_EVENT_MAIL_USER "mail_user" |
10 | | |
11 | | struct module; |
12 | | struct fs_parameters; |
13 | | struct ssl_iostream_settings; |
14 | | struct master_service_anvil_session; |
15 | | struct mail_user; |
16 | | struct dict_op_settings; |
17 | | |
18 | | struct mail_user_vfuncs { |
19 | | uoff_t (*get_mail_max_size)(struct mail_user *user); |
20 | | void (*deinit)(struct mail_user *user); |
21 | | void (*deinit_pre)(struct mail_user *user); |
22 | | }; |
23 | | |
24 | | struct mail_user_connection_data { |
25 | | struct ip_addr *local_ip, *remote_ip; |
26 | | in_port_t local_port, remote_port; |
27 | | const char *local_name; |
28 | | |
29 | | bool end_client_tls_secured:1; |
30 | | }; |
31 | | |
32 | | struct mail_user { |
33 | | pool_t pool; |
34 | | struct mail_user_vfuncs v, *vlast; |
35 | | int refcount; |
36 | | |
37 | | struct event *event; |
38 | | /* User's creator if such exists. For example for autocreated shared |
39 | | mailbox users their creator is the logged in user. */ |
40 | | struct mail_user *creator; |
41 | | struct mail_storage_service_user *service_user; |
42 | | |
43 | | const char *username; |
44 | | /* don't access the home directly. It may be set lazily. */ |
45 | | const char *_home; |
46 | | |
47 | | uid_t uid; |
48 | | gid_t gid; |
49 | | const char *service; |
50 | | const char *protocol; |
51 | | const char *session_id; |
52 | | struct mail_user_connection_data conn; |
53 | | const char *auth_mech, *auth_token, *auth_user; |
54 | | const char *master_user; |
55 | | const char *const *userdb_fields; |
56 | | const char *const *_alt_usernames; |
57 | | /* Timestamp when this session was initially created. Most importantly |
58 | | this stays the same after IMAP client is hibernated and restored. */ |
59 | | time_t session_create_time; |
60 | | |
61 | | const struct var_expand_params *var_expand_params; |
62 | | /* If non-NULL, fail the user initialization with this error. |
63 | | This could be set by plugins that need to fail the initialization. */ |
64 | | const char *error; |
65 | | |
66 | | const struct mail_user_settings *set; |
67 | | struct mail_namespace *namespaces; |
68 | | struct mail_storage *storages; |
69 | | struct dict_op_settings *dict_op_set; |
70 | | ARRAY(const struct mail_storage_hooks *) hooks; |
71 | | |
72 | | normalizer_func_t *default_normalizer; |
73 | | /* Filled lazily by mailbox_attribute_*() when accessing attributes. */ |
74 | | struct dict *_attr_dict; |
75 | | |
76 | | /* Module-specific contexts. See mail_storage_module_id. */ |
77 | | ARRAY(union mail_user_module_context *) module_contexts; |
78 | | |
79 | | struct process_stat proc_stat; |
80 | | |
81 | | /* User doesn't exist (as reported by userdb lookup when looking |
82 | | up home) */ |
83 | | bool nonexistent:1; |
84 | | /* Either home is set or there is no home for the user. */ |
85 | | bool home_looked_up:1; |
86 | | /* User is anonymous */ |
87 | | bool anonymous:1; |
88 | | /* This is an autocreated user (e.g. for shared namespace or |
89 | | lda raw storage) */ |
90 | | bool autocreated:1; |
91 | | /* mail_user_init() has been called */ |
92 | | bool initialized:1; |
93 | | /* The initial namespaces have been created and |
94 | | hook_mail_namespaces_created() has been called. */ |
95 | | bool namespaces_created:1; |
96 | | /* If INBOX can't be opened, log an error, but only once. */ |
97 | | bool inbox_open_error_logged:1; |
98 | | /* Fuzzy search works for this user (FTS enabled) */ |
99 | | bool fuzzy_search:1; |
100 | | /* We're running dsync */ |
101 | | bool dsyncing:1; |
102 | | /* Failed to create attribute dict, don't try again */ |
103 | | bool attr_dict_failed:1; |
104 | | /* We're deinitializing the user */ |
105 | | bool deinitializing:1; |
106 | | /* Enable administrator user commands for the user */ |
107 | | bool admin:1; |
108 | | /* Enable all statistics gathering */ |
109 | | bool stats_enabled:1; |
110 | | /* This session was restored (e.g. IMAP unhibernation) */ |
111 | | bool session_restored:1; |
112 | | }; |
113 | | |
114 | | struct mail_user_module_register { |
115 | | unsigned int id; |
116 | | }; |
117 | | |
118 | | union mail_user_module_context { |
119 | | struct mail_user_vfuncs super; |
120 | | struct mail_user_module_register *reg; |
121 | | }; |
122 | | extern struct mail_user_module_register mail_user_module_register; |
123 | | extern struct auth_master_connection *mail_user_auth_master_conn; |
124 | | extern const struct var_expand_provider *mail_user_var_expand_providers; |
125 | | |
126 | | struct mail_user * |
127 | | mail_user_alloc(struct mail_storage_service_user *service_user); |
128 | | /* Returns -1 if settings were invalid. */ |
129 | | int mail_user_init(struct mail_user *user, const char **error_r); |
130 | | |
131 | | void mail_user_ref(struct mail_user *user); |
132 | | void mail_user_unref(struct mail_user **user); |
133 | | /* Assert that this is the last reference for the user and unref it. */ |
134 | | void mail_user_deinit(struct mail_user **user); |
135 | | |
136 | | /* Duplicate a mail_user. mail_user_init() and mail_namespaces_init() need to |
137 | | be called before the user is usable. */ |
138 | | struct mail_user *mail_user_dup(struct mail_user *user); |
139 | | |
140 | | /* Find another user from the given user's namespaces. */ |
141 | | struct mail_user *mail_user_find(struct mail_user *user, const char *name); |
142 | | |
143 | | /* Specify mail location %variable expansion data. */ |
144 | | void mail_user_set_vars(struct mail_user *user, const char *service, |
145 | | const struct mail_user_connection_data *conn); |
146 | | /* Return %variable expansion table for the user. */ |
147 | | const struct var_expand_params * |
148 | | mail_user_var_expand_params(struct mail_user *user); |
149 | | |
150 | | /* Specify the user's home directory. This should be called also with home=NULL |
151 | | when it's known that the user doesn't have a home directory to avoid the |
152 | | internal lookup. */ |
153 | | void mail_user_set_home(struct mail_user *user, const char *home); |
154 | | /* Get the home directory for the user. Returns 1 if home directory looked up |
155 | | successfully, 0 if there is no home directory (either user doesn't exist or |
156 | | has no home directory) or -1 if lookup failed. The returned home string |
157 | | is valid until the user is freed. */ |
158 | | int mail_user_get_home(struct mail_user *user, const char **home_r); |
159 | | /* Appends path + file prefix for creating a temporary file. |
160 | | The file prefix doesn't contain any uniqueness. */ |
161 | | void mail_user_set_get_temp_prefix(string_t *dest, |
162 | | const struct mail_user_settings *set); |
163 | | /* Get volatile directory from INBOX namespace if configured. Returns NULL if |
164 | | none is configured. */ |
165 | | const char *mail_user_get_volatile_dir(struct mail_user *user); |
166 | | /* Returns 1 on success, 0 if lock_secs is reached, -1 on error */ |
167 | | int mail_user_lock_file_create(struct mail_user *user, const char *lock_fname, |
168 | | unsigned int lock_secs, |
169 | | struct file_lock **lock_r, const char **error_r); |
170 | | |
171 | | /* Returns TRUE if plugin is loaded for the user. */ |
172 | | bool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module); |
173 | | |
174 | | /* Add more namespaces to user's namespaces. The ->next pointers may be |
175 | | changed, so the namespaces pointer will be updated to user->namespaces. */ |
176 | | void mail_user_add_namespace(struct mail_user *user, |
177 | | struct mail_namespace **namespaces); |
178 | | /* Drop autocreated shared namespaces that don't have any "usable" mailboxes. */ |
179 | | void mail_user_drop_useless_namespaces(struct mail_user *user); |
180 | | |
181 | | /* Replace ~/ at the beginning of the path with the user's home directory. */ |
182 | | const char *mail_user_home_expand(struct mail_user *user, const char *path); |
183 | | /* Returns 0 if ok, -1 if home directory isn't set. */ |
184 | | int mail_user_try_home_expand(struct mail_user *user, const char **path); |
185 | | /* Fill out anvil session struct for the user session. */ |
186 | | void mail_user_get_anvil_session(struct mail_user *user, |
187 | | struct master_service_anvil_session *session_r); |
188 | | /* Returns NULL-terminated array of (user_field, value) pairs. The fields are |
189 | | extracted from user->userdb_fields[]. */ |
190 | | const char *const *mail_user_get_alt_usernames(struct mail_user *user); |
191 | | |
192 | | /* Basically the same as mail_storage_find_class(), except automatically load |
193 | | storage plugins when needed. */ |
194 | | struct mail_storage * |
195 | | mail_user_get_storage_class(struct mail_user *user, const char *name); |
196 | | |
197 | | /* Import any event_ fields from userdb fields to mail user event. */ |
198 | | void mail_user_add_event_fields(struct mail_user *user); |
199 | | |
200 | | /* Initialize fs_parameters from mail_user settings. */ |
201 | | void mail_user_init_fs_parameters(struct mail_user *user, |
202 | | struct fs_parameters *fs_set); |
203 | | |
204 | | /* Try to mkdir() user's home directory. Ideally this should be called only |
205 | | after the caller tries to create a file to the home directory, but it fails |
206 | | with ENOENT. This way it avoids unnecessary disk IO to the home. */ |
207 | | int mail_user_home_mkdir(struct mail_user *user); |
208 | | |
209 | | /* Return dict_op_settings for the user. The returned settings are valid until |
210 | | the user is freed. */ |
211 | | const struct dict_op_settings * |
212 | | mail_user_get_dict_op_settings(struct mail_user *user); |
213 | | |
214 | | |
215 | | /* Obtain the postmaster address to be used for this user as an RFC 5322 (IMF) |
216 | | address. Returns false if the configured postmaster address is invalid in |
217 | | which case error_r contains the error message. */ |
218 | | static inline bool |
219 | | mail_user_get_postmaster_address(struct mail_user *user, |
220 | | const struct message_address **address_r, |
221 | | const char **error_r) |
222 | 0 | { |
223 | 0 | return mail_user_set_get_postmaster_address(user->set, address_r, |
224 | 0 | error_r); |
225 | 0 | } Unexecuted instantiation: testsuite-common.c:mail_user_get_postmaster_address Unexecuted instantiation: testsuite-objects.c:mail_user_get_postmaster_address Unexecuted instantiation: testsuite-message.c:mail_user_get_postmaster_address Unexecuted instantiation: testsuite-mailstore.c:mail_user_get_postmaster_address Unexecuted instantiation: cmd-test-message.c:mail_user_get_postmaster_address Unexecuted instantiation: sieve-tool.c:mail_user_get_postmaster_address |
226 | | |
227 | | /* Obtain the postmaster address to be used for this user as an RFC 5321 (SMTP) |
228 | | address. Returns false if the configured postmaster address is invalid in |
229 | | which case error_r contains the error message. */ |
230 | | static inline bool |
231 | | mail_user_get_postmaster_smtp(struct mail_user *user, |
232 | | const struct smtp_address **address_r, |
233 | | const char **error_r) |
234 | 0 | { |
235 | 0 | return mail_user_set_get_postmaster_smtp(user->set, address_r, |
236 | 0 | error_r); |
237 | 0 | } Unexecuted instantiation: testsuite-common.c:mail_user_get_postmaster_smtp Unexecuted instantiation: testsuite-objects.c:mail_user_get_postmaster_smtp Unexecuted instantiation: testsuite-message.c:mail_user_get_postmaster_smtp Unexecuted instantiation: testsuite-mailstore.c:mail_user_get_postmaster_smtp Unexecuted instantiation: cmd-test-message.c:mail_user_get_postmaster_smtp Unexecuted instantiation: sieve-tool.c:mail_user_get_postmaster_smtp |
238 | | |
239 | | uoff_t mail_user_get_mail_max_size(struct mail_user *user); |
240 | | |
241 | | #endif |