imap-acl-plugin.c revision c1faff067b29fb48426cb84260adba563e93189a
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2008-2012 Dovecot authors, see the included COPYING file */
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainen#define ERROR_NOT_ADMIN "["IMAP_RESP_CODE_NOPERM"] " \
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainen "You lack administrator privileges on this mailbox."
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenstatic const struct imap_acl_letter_map imap_acl_letter_map[] = {
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainenconst char *imap_acl_plugin_version = DOVECOT_VERSION;
8e361d2906b0e44f7175a20981f8d2280645b58bTimo Sirainenstatic imap_client_created_func_t *next_hook_client_created;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct mailbox *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenacl_mailbox_open_as_admin(struct client_command_context *cmd, const char *name)
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainen enum mailbox_existence existence = MAILBOX_EXISTENCE_NONE;
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen if (ACL_USER_CONTEXT(cmd->client->user) == NULL) {
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen client_send_command_error(cmd, "ACLs disabled.");
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainen /* Force opening the mailbox so that we can give a nicer error message
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen if mailbox isn't selectable but is listable. */
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_READONLY |
651fc0f1e43fef3e02e0e7b5f498973b05f641d7Timo Sirainen if (mailbox_exists(box, TRUE, &existence) == 0 &&
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_ADMIN);
07e80e04c8876b6bf3f95266f48b41e1a681e445Timo Sirainen /* mailbox doesn't exist / not an administrator. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_LOOKUP) <= 0) {
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen client_send_tagline(cmd, "NO "ERROR_NOT_ADMIN);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstatic const struct imap_acl_letter_map *
d5960ce1c0adda5c9e259bc429123ebc29c60baeTimo Sirainen unsigned int i;
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen for (i = 0; imap_acl_letter_map[i].name != NULL; i++) {
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen if (strcmp(imap_acl_letter_map[i].name, name) == 0)
6eb30032b4a50c383dea4c9c74342d906de6ad36Timo Sirainenimap_acl_write_rights_list(string_t *dest, const char *const *rights)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* write only letters */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenimap_acl_write_right(string_t *dest, string_t *tmp,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *const *rights = neg ? right->neg_rights : right->rights;
case ACL_ID_GROUP:
case ACL_ID_GROUP_OVERRIDE:
case ACL_ID_TYPE_COUNT:
i_unreached();
case ACL_ID_OWNER:
return TRUE;
case ACL_ID_USER:
return FALSE;
return ret;
bool add_default)
const char *username;
int ret;
if (!convert_owner) {
return ret;
const char *mailbox;
int ret;
return FALSE;
return TRUE;
if (ret == 0) {
return TRUE;
const char *mailbox;
const char *const *rights;
return FALSE;
return TRUE;
return TRUE;
return TRUE;
return TRUE;
return TRUE;
return FALSE;
return TRUE;
return TRUE;
const char **error_r)
switch (*letters) {
const char *env;
id);
const char *const *default_rights;
case ACL_MODIFY_MODE_ADD:
case ACL_MODIFY_MODE_REMOVE:
case ACL_MODIFY_MODE_REPLACE:
struct acl_rights *r;
return FALSE;
return TRUE;
identifier++;
switch (*rights) {
rights++;
rights++;
return TRUE;
return TRUE;
return TRUE;
return TRUE;
if (negative) {
return TRUE;
return FALSE;
return TRUE;
identifier++;
return TRUE;
return TRUE;
return TRUE;
void imap_acl_plugin_deinit(void)