bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2006-2018 Dovecot authors, see the included COPYING file */
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen#include "lib.h"
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen#include "array.h"
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen#include "istream.h"
e7ca5f820d6a1a8fe549a2966ac707a60e055ef4Timo Sirainen#include "mail-namespace.h"
b039dabf4c53f72454e795930e7643b6e0e625f9Timo Sirainen#include "mailbox-list-private.h"
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen#include "acl-api-private.h"
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen#include "acl-lookup-dict.h"
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen#include "acl-plugin.h"
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstruct acl_storage_module acl_storage_module =
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MODULE_CONTEXT_INIT(&mail_storage_module_register);
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainenstruct acl_user_module acl_user_module =
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen MODULE_CONTEXT_INIT(&mail_user_module_register);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainenstatic void acl_user_deinit(struct mail_user *user)
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen{
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen struct acl_user *auser = ACL_USER_CONTEXT(user);
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen
3131b3878de3245db7552234e66d437e8fde9351Aki Tuomi i_assert(auser != NULL);
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen acl_lookup_dict_deinit(&auser->acl_lookup_dict);
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen auser->module_ctx.super.deinit(user);
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen}
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenstatic void acl_mail_user_create(struct mail_user *user, const char *env)
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen{
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct mail_user_vfuncs *v = user->vlast;
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen struct acl_user *auser;
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen auser = p_new(user->pool, struct acl_user, 1);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen auser->module_ctx.super = *v;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen user->vlast = &auser->module_ctx.super;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->deinit = acl_user_deinit;
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen auser->acl_lookup_dict = acl_lookup_dict_init(user);
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen auser->acl_env = env;
dd5683e19979085fdfe9f269876f2a91ea604679Timo Sirainen auser->acl_user = mail_user_plugin_getenv(user, "acl_user");
dd5683e19979085fdfe9f269876f2a91ea604679Timo Sirainen if (auser->acl_user == NULL)
dd5683e19979085fdfe9f269876f2a91ea604679Timo Sirainen auser->acl_user = mail_user_plugin_getenv(user, "master_user");
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen env = mail_user_plugin_getenv(user, "acl_groups");
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen if (env != NULL) {
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen auser->groups =
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen (const char *const *)p_strsplit(user->pool, env, ",");
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen }
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen MODULE_CONTEXT_SET(user, acl_user_module, auser);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen}
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenvoid acl_mail_user_created(struct mail_user *user)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen{
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen const char *env;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen env = mail_user_plugin_getenv(user, "acl");
8813889171eb9a85552a8f342ee76e26293a722fTimo Sirainen if (env != NULL && *env != '\0')
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen acl_mail_user_create(user, env);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen else {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen if (user->mail_debug)
e5acc283bf030b0b5c79ca4e52d315c516a299faPascal Volk i_debug("acl: No acl setting - ACLs are disabled");
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen }
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainen}