bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2006-2018 Dovecot authors, see the included COPYING file */
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenextern struct acl_backend_vfuncs acl_backend_vfile;
7d8afd1e15bdf23b5fd13aa9ac9606aca2797125Timo Sirainenstatic const char *const *owner_mailbox_rights = all_mailbox_rights;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenstatic const char *const non_owner_mailbox_rights[] = { NULL };
e7ca5f820d6a1a8fe549a2966ac707a60e055ef4Timo Sirainenacl_backend_init(const char *data, struct mailbox_list *list,
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen const char *acl_username, const char *const *groups,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct mail_user *user = mailbox_list_get_user(list);
e5acc283bf030b0b5c79ca4e52d315c516a299faPascal Volk i_debug("acl: initializing backend with data: %s", data);
e5acc283bf030b0b5c79ca4e52d315c516a299faPascal Volk i_debug("acl: acl username = %s", acl_username);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen i_fatal("Unknown ACL backend: %s", t_strcut(data, ':'));
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen backend->username = p_strdup(backend->pool, acl_username);
95c8d28ebfc13f3252b71c71f3d5c0d809110a08Timo Sirainen mail_user_plugin_getenv_bool(user, "acl_globals_only");
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen p_new(backend->pool, const char *, group_count);
0e731a17eb66e67b2280b7788295bf469b1bcccdTimo Sirainen for (i = 0; i < group_count; i++) {
c7d655351dc85d917a27392c0d6ac89867786424Timo Sirainen backend->groups[i] = p_strdup(backend->pool, groups[i]);
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen i_qsort(backend->groups, group_count, sizeof(const char *),
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen if (acl_backend_vfile.init(backend, data) < 0)
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen i_fatal("acl: backend vfile init failed with data: %s",
7705148680904051b573a9125ecee765032a5809Timo Sirainen backend->default_rights = owner ? owner_mailbox_rights :
3809b9691c46926aa54968ac8e418d04361e1efaTimo Sirainen acl_cache_mask_init(backend->cache, backend->pool,
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenvoid acl_backend_deinit(struct acl_backend **_backend)
0b2f7be9fadfd4026a9174e51170890cde3edf48Timo Sirainenconst char *acl_backend_get_acl_username(struct acl_backend *backend)
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenbool acl_backend_user_is_authenticated(struct acl_backend *backend)
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainenbool acl_backend_user_is_owner(struct acl_backend *backend)
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenbool acl_backend_user_name_equals(struct acl_backend *backend,
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen /* anonymous user never matches */
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen return strcmp(backend->username, username) == 0;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenbool acl_backend_user_is_in_group(struct acl_backend *backend,
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen return i_bsearch(group_name, backend->groups, backend->group_count,
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen sizeof(const char *), bsearch_strcmp) != NULL;
27a7dee37444438522e04273ce17e6c48775b35cTimo Sirainenbool acl_backend_rights_match_me(struct acl_backend *backend,
27a7dee37444438522e04273ce17e6c48775b35cTimo Sirainen return acl_backend_user_is_authenticated(backend);
27a7dee37444438522e04273ce17e6c48775b35cTimo Sirainen return acl_backend_user_is_in_group(backend, rights->identifier);
27a7dee37444438522e04273ce17e6c48775b35cTimo Sirainen return acl_backend_user_name_equals(backend, rights->identifier);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenunsigned int acl_backend_lookup_right(struct acl_backend *backend,
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen return acl_cache_right_lookup(backend->cache, right);
515d649c1802beb48433b90125518c00d0a1fbb4Timo Sirainenstruct acl_object *acl_backend_get_default_object(struct acl_backend *backend)
02c28668f01219ae17e112cd4d3cdd3a0af539a1Timo Sirainen struct mail_user *user = mailbox_list_get_user(backend->list);
515d649c1802beb48433b90125518c00d0a1fbb4Timo Sirainen struct mail_namespace *ns = mailbox_list_get_namespace(backend->list);
b1e097e04ceff5800101ec3615f815f2d0f2fd12Timo Sirainen if (mail_user_plugin_getenv_bool(user, "acl_defaults_from_inbox")) {
02c28668f01219ae17e112cd4d3cdd3a0af539a1Timo Sirainen if (ns->type == MAIL_NAMESPACE_TYPE_PRIVATE ||
515d649c1802beb48433b90125518c00d0a1fbb4Timo Sirainen acl_object_init_from_name(backend, default_name);
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainenint acl_backend_get_default_rights(struct acl_backend *backend,
515d649c1802beb48433b90125518c00d0a1fbb4Timo Sirainen struct acl_object *aclobj = acl_backend_get_default_object(backend);
515d649c1802beb48433b90125518c00d0a1fbb4Timo Sirainen if (backend->v.object_refresh_cache(aclobj) < 0)