mail-storage-service.h revision b9b841558c5f91db7f5fc71c0ac62aad1bbf6418
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#ifndef MAIL_STORAGE_SERVICE_H
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#define MAIL_STORAGE_SERVICE_H
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#include "network.h"
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct master_service;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct mail_user;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct setting_parser_context;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct setting_parser_info;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct mail_storage_service_user;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenenum mail_storage_service_flags {
3b94ff5951db4d4eddb7a80ed4e3f61207202635Timo Sirainen /* Fail if we don't drop root privileges */
3b94ff5951db4d4eddb7a80ed4e3f61207202635Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT = 0x01,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* Lookup user from userdb */
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP = 0x02,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* Force mail_debug=yes */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_DEBUG = 0x04,
3b94ff5951db4d4eddb7a80ed4e3f61207202635Timo Sirainen /* Keep the current process permissions */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_NO_RESTRICT_ACCESS = 0x08,
0373a24e97602b4c394e93a70b75f45e5869fa51Timo Sirainen /* Don't chdir() to user's home */
0373a24e97602b4c394e93a70b75f45e5869fa51Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_NO_CHDIR = 0x10,
0373a24e97602b4c394e93a70b75f45e5869fa51Timo Sirainen /* Drop privileges only temporarily (keep running as setuid-root) */
0373a24e97602b4c394e93a70b75f45e5869fa51Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP = 0x20,
22535a9e685e29214082878e37a267157044618eTimo Sirainen /* Enable core dumps even when dropping privileges temporarily */
22535a9e685e29214082878e37a267157044618eTimo Sirainen MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS = 0x40,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* Don't initialize logging or change log prefixes */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT = 0x80,
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen /* Don't load plugins in _service_lookup() */
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_NO_PLUGINS = 0x100,
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen /* Don't close auth connections because of idling. */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_NO_IDLE_TIMEOUT = 0x200,
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen /* When executing doveconf, tell it to use sysexits codes */
061da1b9d309301a7e3f5e0f240d7a7e99652d63Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_USE_SYSEXITS = 0x400,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* Don't create namespaces, only the user. */
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES = 0x800
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen};
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct mail_storage_service_input {
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen const char *module;
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen const char *service;
08aea01ef9a9d20703e0fcf8618e6195c0037a44Timo Sirainen const char *username;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen struct ip_addr local_ip, remote_ip;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen const char *const *userdb_fields;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
/* Override specified global flags */
enum mail_storage_service_flags flags_override_add;
enum mail_storage_service_flags flags_override_remove;
/* override MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP for this lookup */
unsigned int no_userdb_lookup:1;
};
extern struct module *mail_storage_service_modules;
struct mail_storage_service_ctx *
mail_storage_service_init(struct master_service *service,
const struct setting_parser_info *set_roots[],
enum mail_storage_service_flags flags);
struct auth_master_connection *
mail_storage_service_get_auth_conn(struct mail_storage_service_ctx *ctx);
int mail_storage_service_read_settings(struct mail_storage_service_ctx *ctx,
const struct mail_storage_service_input *input,
pool_t pool,
const struct setting_parser_info **user_info_r,
const struct setting_parser_context **parser_r,
const char **error_r);
/* Read settings and initialize context to use them. Do nothing if service is
already initialized. This is mainly necessary when calling _get_auth_conn()
or _all_init(). */
void mail_storage_service_init_settings(struct mail_storage_service_ctx *ctx,
const struct mail_storage_service_input *input);
/* Returns 1 if ok, 0 if user wasn't found, -1 if fatal error,
-2 if error is user-specific (e.g. invalid settings).
Error can be safely shown to untrusted users. */
int mail_storage_service_lookup(struct mail_storage_service_ctx *ctx,
const struct mail_storage_service_input *input,
struct mail_storage_service_user **user_r,
const char **error_r);
/* Returns 0 if ok, -1 if fatal error, -2 if error is user-specific. */
int mail_storage_service_next(struct mail_storage_service_ctx *ctx,
struct mail_storage_service_user *user,
struct mail_user **mail_user_r);
void mail_storage_service_restrict_setenv(struct mail_storage_service_ctx *ctx,
struct mail_storage_service_user *user);
/* Combine lookup() and next() into one call. */
int mail_storage_service_lookup_next(struct mail_storage_service_ctx *ctx,
const struct mail_storage_service_input *input,
struct mail_storage_service_user **user_r,
struct mail_user **mail_user_r,
const char **error_r);
void mail_storage_service_user_free(struct mail_storage_service_user **user);
/* Initialize iterating through all users. Return the number of users. */
unsigned int
mail_storage_service_all_init(struct mail_storage_service_ctx *ctx);
/* Iterate through all usernames. Returns 1 if username was returned, 0 if
there are no more users, -1 if error. */
int mail_storage_service_all_next(struct mail_storage_service_ctx *ctx,
const char **username_r);
void mail_storage_service_deinit(struct mail_storage_service_ctx **ctx);
/* Return the settings pointed to by set_root parameter in _init().
The settings contain all the changes done by userdb lookups. */
void **mail_storage_service_user_get_set(struct mail_storage_service_user *user);
const struct mail_storage_service_input *
mail_storage_service_user_get_input(struct mail_storage_service_user *user);
struct setting_parser_context *
mail_storage_service_user_get_settings_parser(struct mail_storage_service_user *user);
/* Return the settings pointed to by set_root parameter in _init() */
void *mail_storage_service_get_settings(struct master_service *service);
#endif