Mercurial > dovecot > core-2.2
annotate src/plugins/acl/acl-lookup-dict.c @ 23017:c1d36f2575c7 default tip
lib-imap: Fix "Don't accept strings with NULs" cherry-pick
author | Timo Sirainen <timo.sirainen@open-xchange.com> |
---|---|
date | Thu, 29 Aug 2019 09:55:25 +0300 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
1 /* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */ |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "array.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "str.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "dict.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "mail-user.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "mail-namespace.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "acl-api-private.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "acl-storage.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "acl-plugin.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "acl-lookup-dict.h" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #define DICT_SHARED_BOXES_PATH "shared-boxes/" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 struct acl_lookup_dict { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 struct mail_user *user; |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
19 struct dict *dict; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 }; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 struct acl_lookup_dict_iter { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 pool_t pool; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 struct acl_lookup_dict *dict; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
26 pool_t iter_value_pool; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 ARRAY_TYPE(const_string) iter_ids; |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
28 ARRAY_TYPE(const_string) iter_values; |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
29 unsigned int iter_idx, iter_value_idx; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 unsigned int failed:1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 }; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 struct acl_lookup_dict *acl_lookup_dict_init(struct mail_user *user) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 struct acl_lookup_dict *dict; |
15218
22c22d704422
lib-dict: dict_init() now returns error string instead of logging it
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
37 const char *uri, *error; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 dict = i_new(struct acl_lookup_dict, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 dict->user = user; |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
41 |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
42 uri = mail_user_plugin_getenv(user, "acl_shared_dict"); |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
43 if (uri != NULL) { |
15067
9bff478f81fd
dict_init() API changed to return int.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
44 if (dict_init(uri, DICT_DATA_TYPE_STRING, "", |
15218
22c22d704422
lib-dict: dict_init() now returns error string instead of logging it
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
45 user->set->base_dir, &dict->dict, &error) < 0) |
22c22d704422
lib-dict: dict_init() now returns error string instead of logging it
Timo Sirainen <tss@iki.fi>
parents:
15162
diff
changeset
|
46 i_error("acl: dict_init(%s) failed: %s", uri, error); |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
47 } else if (user->mail_debug) { |
10082
62b37dcf173e
Log debug-level messages with i_debug().
Pascal Volk <user@localhost.localdomain.org>
parents:
9545
diff
changeset
|
48 i_debug("acl: No acl_shared_dict setting - " |
62b37dcf173e
Log debug-level messages with i_debug().
Pascal Volk <user@localhost.localdomain.org>
parents:
9545
diff
changeset
|
49 "shared mailbox listing is disabled"); |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
50 } |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 return dict; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 void acl_lookup_dict_deinit(struct acl_lookup_dict **_dict) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 struct acl_lookup_dict *dict = *_dict; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 *_dict = NULL; |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
59 if (dict->dict != NULL) |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
60 dict_deinit(&dict->dict); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 i_free(dict); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
12771
a868f845cd40
acl: Added doveadm acl debug command.
Timo Sirainen <tss@iki.fi>
parents:
12770
diff
changeset
|
64 bool acl_lookup_dict_is_enabled(struct acl_lookup_dict *dict) |
a868f845cd40
acl: Added doveadm acl debug command.
Timo Sirainen <tss@iki.fi>
parents:
12770
diff
changeset
|
65 { |
a868f845cd40
acl: Added doveadm acl debug command.
Timo Sirainen <tss@iki.fi>
parents:
12770
diff
changeset
|
66 return dict->dict != NULL; |
a868f845cd40
acl: Added doveadm acl debug command.
Timo Sirainen <tss@iki.fi>
parents:
12770
diff
changeset
|
67 } |
a868f845cd40
acl: Added doveadm acl debug command.
Timo Sirainen <tss@iki.fi>
parents:
12770
diff
changeset
|
68 |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 static void |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 acl_lookup_dict_write_rights_id(string_t *dest, const struct acl_rights *right) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 switch (right->id_type) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 case ACL_ID_ANYONE: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 case ACL_ID_AUTHENTICATED: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 /* don't bother separating these */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 str_append(dest, "anyone"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 break; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 case ACL_ID_USER: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 str_append(dest, "user/"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 str_append(dest, right->identifier); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 break; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 case ACL_ID_GROUP: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 case ACL_ID_GROUP_OVERRIDE: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 str_append(dest, "group/"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 str_append(dest, right->identifier); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 break; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 case ACL_ID_OWNER: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 case ACL_ID_TYPE_COUNT: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 i_unreached(); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 |
15125
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
93 static bool |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
94 acl_rights_is_same_user(const struct acl_rights *right, struct mail_user *user) |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
95 { |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
96 return right->id_type == ACL_ID_USER && |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
97 strcmp(right->identifier, user->username) == 0; |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
98 } |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
99 |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 static int acl_lookup_dict_rebuild_add_backend(struct mail_namespace *ns, |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 ARRAY_TYPE(const_string) *ids) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 struct acl_backend *backend; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 struct acl_mailbox_list_context *ctx; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 struct acl_object *aclobj; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 struct acl_object_list_iter *iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 struct acl_rights rights; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 const char *name, *id_dup; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 string_t *id; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 int ret, ret2 = 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 |
16087
d211174a2392
acl: Don't crash when rebuilding acl dict for "unusable" namespaces.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
112 if ((ns->flags & NAMESPACE_FLAG_NOACL) != 0 || ns->owner == NULL || |
d211174a2392
acl: Don't crash when rebuilding acl dict for "unusable" namespaces.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
113 ACL_LIST_CONTEXT(ns->list) == NULL) |
8464 | 114 return 0; |
115 | |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 id = t_str_new(128); |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9374
diff
changeset
|
117 backend = acl_mailbox_list_get_backend(ns->list); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 ctx = acl_backend_nonowner_lookups_iter_init(backend); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 while ((ret = acl_backend_nonowner_lookups_iter_next(ctx, &name)) > 0) { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9374
diff
changeset
|
120 aclobj = acl_object_init_from_name(backend, name); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 iter = acl_object_list_init(aclobj); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 while ((ret = acl_object_list_next(iter, &rights)) > 0) { |
15125
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
124 /* avoid pointless user -> user entries, |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
125 which some clients do */ |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
126 if (acl_rights_has_nonowner_lookup_changes(&rights) && |
3eaeacc85b4c
acl: Don't add sameuser -> sameuser entries to ACL dict.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
127 !acl_rights_is_same_user(&rights, ns->owner)) { |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 str_truncate(id, 0); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 acl_lookup_dict_write_rights_id(id, &rights); |
8466
4553e28eb4f5
acl: Update acl_dict correctly also for other visible users' shared namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8464
diff
changeset
|
130 str_append_c(id, '/'); |
8467
03c418eadc8b
mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents:
8466
diff
changeset
|
131 str_append(id, ns->owner->username); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 id_dup = t_strdup(str_c(id)); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 array_append(ids, &id_dup, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 acl_object_list_deinit(&iter); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 if (ret < 0) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 ret2 = -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 acl_object_deinit(&aclobj); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 acl_backend_nonowner_lookups_iter_deinit(&ctx); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 return ret < 0 || ret2 < 0 ? -1 : 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 static int |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 acl_lookup_dict_rebuild_update(struct acl_lookup_dict *dict, |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 const ARRAY_TYPE(const_string) *new_ids_arr, |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 bool no_removes) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 const char *username = dict->user->username; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 struct dict_iterate_context *iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 struct dict_transaction_context *dt; |
9491
0059b2381024
Use array_sort() instead of qsort() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
153 const char *prefix, *key, *value, *const *old_ids, *const *new_ids, *p; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 ARRAY_TYPE(const_string) old_ids_arr; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 unsigned int newi, oldi, old_count, new_count; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 string_t *path; |
21322
5ab8dc1a4a6f
global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
157 size_t prefix_len; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 int ret; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 |
8466
4553e28eb4f5
acl: Update acl_dict correctly also for other visible users' shared namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8464
diff
changeset
|
160 /* get all existing identifiers for the user. we might be able to |
4553e28eb4f5
acl: Update acl_dict correctly also for other visible users' shared namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8464
diff
changeset
|
161 sync identifiers also for other users whose shared namespaces we |
4553e28eb4f5
acl: Update acl_dict correctly also for other visible users' shared namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8464
diff
changeset
|
162 have, but it's possible that the other users have other namespaces |
4553e28eb4f5
acl: Update acl_dict correctly also for other visible users' shared namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8464
diff
changeset
|
163 that aren't visible to us, so we don't want to remove anything |
4553e28eb4f5
acl: Update acl_dict correctly also for other visible users' shared namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8464
diff
changeset
|
164 that could break them. */ |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 t_array_init(&old_ids_arr, 128); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 prefix = DICT_PATH_SHARED DICT_SHARED_BOXES_PATH; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 prefix_len = strlen(prefix); |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
168 iter = dict_iterate_init(dict->dict, prefix, DICT_ITERATE_FLAG_RECURSE); |
10659
7309b5c84ca9
lib-dict: Changed dict_iterate API.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
169 while (dict_iterate(iter, &key, &value)) { |
12093
d377c610b19d
acl: Fixed removing entries from shared dict when rebuilding
Timo Sirainen <tss@iki.fi>
parents:
10659
diff
changeset
|
170 /* prefix/$type/$dest/$source */ |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 key += prefix_len; |
12093
d377c610b19d
acl: Fixed removing entries from shared dict when rebuilding
Timo Sirainen <tss@iki.fi>
parents:
10659
diff
changeset
|
172 p = strrchr(key, '/'); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 if (p != NULL && strcmp(p + 1, username) == 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 key = t_strdup_until(key, p); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 array_append(&old_ids_arr, &key, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 } |
10659
7309b5c84ca9
lib-dict: Changed dict_iterate API.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
178 if (dict_iterate_deinit(&iter) < 0) { |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 i_error("acl: dict iteration failed, can't update dict"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 return -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 /* sort the existing identifiers */ |
9491
0059b2381024
Use array_sort() instead of qsort() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
184 array_sort(&old_ids_arr, i_strcmp_p); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 /* sync the identifiers */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 path = t_str_new(256); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 str_append(path, prefix); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
190 dt = dict_transaction_begin(dict->dict); |
9491
0059b2381024
Use array_sort() instead of qsort() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
191 old_ids = array_get(&old_ids_arr, &old_count); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 new_ids = array_get(new_ids_arr, &new_count); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 for (newi = oldi = 0; newi < new_count || oldi < old_count; ) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 ret = newi == new_count ? 1 : |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 oldi == old_count ? -1 : |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 strcmp(new_ids[newi], old_ids[oldi]); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 if (ret == 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 newi++; oldi++; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 } else if (ret < 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 /* new identifier, add it */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 str_truncate(path, prefix_len); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 str_append(path, new_ids[newi]); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 dict_set(dt, str_c(path), "1"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 newi++; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 } else if (!no_removes) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 /* old identifier removed */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 str_truncate(path, prefix_len); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 str_append(path, old_ids[oldi]); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 str_append_c(path, '/'); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 str_append(path, username); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 dict_unset(dt, str_c(path)); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 oldi++; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 if (dict_transaction_commit(&dt) < 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 i_error("acl: dict commit failed"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 return -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 return 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 int acl_lookup_dict_rebuild(struct acl_lookup_dict *dict) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 struct mail_namespace *ns; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 ARRAY_TYPE(const_string) ids_arr; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 const char **ids; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 unsigned int i, dest, count; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 int ret = 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
230 if (dict->dict == NULL) |
8441
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
231 return 0; |
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
232 |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 /* get all ACL identifiers with a positive lookup right */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 t_array_init(&ids_arr, 128); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 for (ns = dict->user->namespaces; ns != NULL; ns = ns->next) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 if (acl_lookup_dict_rebuild_add_backend(ns, &ids_arr) < 0) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 ret = -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 /* sort identifiers and remove duplicates */ |
9491
0059b2381024
Use array_sort() instead of qsort() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
241 array_sort(&ids_arr, i_strcmp_p); |
0059b2381024
Use array_sort() instead of qsort() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
242 |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 ids = array_get_modifiable(&ids_arr, &count); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 for (i = 1, dest = 0; i < count; i++) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 if (strcmp(ids[dest], ids[i]) != 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 if (++dest != i) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 ids[dest] = ids[i]; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 if (++dest < count) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 array_delete(&ids_arr, dest, count-dest); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 /* if lookup failed at some point we can still add new ids, |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 but we can't remove any existing ones */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 if (acl_lookup_dict_rebuild_update(dict, &ids_arr, ret < 0) < 0) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 ret = -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 return ret; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
260 static void acl_lookup_dict_iterate_read(struct acl_lookup_dict_iter *iter) |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 { |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
262 struct dict_iterate_context *dict_iter; |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
263 const char *const *idp, *prefix, *key, *value; |
21322
5ab8dc1a4a6f
global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
264 size_t prefix_len; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 idp = array_idx(&iter->iter_ids, iter->iter_idx); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 iter->iter_idx++; |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
268 iter->iter_value_idx = 0; |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
269 |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
270 prefix = t_strconcat(DICT_PATH_SHARED DICT_SHARED_BOXES_PATH, |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
271 *idp, "/", NULL); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
272 prefix_len = strlen(prefix); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
274 /* read all of it to memory. at least currently dict-proxy can support |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
275 only one iteration at a time, but the acl code can end up rebuilding |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
276 the dict, which opens another iteration. */ |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
277 p_clear(iter->iter_value_pool); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
278 array_clear(&iter->iter_values); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
279 dict_iter = dict_iterate_init(iter->dict->dict, prefix, |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
280 DICT_ITERATE_FLAG_RECURSE); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
281 while (dict_iterate(dict_iter, &key, &value)) { |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
282 i_assert(prefix_len < strlen(key)); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
283 |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
284 key = p_strdup(iter->iter_value_pool, key + prefix_len); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
285 array_append(&iter->iter_values, &key, 1); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
286 } |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
287 if (dict_iterate_deinit(&dict_iter) < 0) |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
288 iter->failed = TRUE; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 struct acl_lookup_dict_iter * |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 acl_lookup_dict_iterate_visible_init(struct acl_lookup_dict *dict) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 struct acl_user *auser = ACL_USER_CONTEXT(dict->user); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
295 struct acl_lookup_dict_iter *iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 const char *id; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 unsigned int i; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 pool_t pool; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
300 pool = pool_alloconly_create("acl lookup dict iter", 1024); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 iter = p_new(pool, struct acl_lookup_dict_iter, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 iter->pool = pool; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 iter->dict = dict; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 p_array_init(&iter->iter_ids, pool, 16); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 id = "anyone"; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 array_append(&iter->iter_ids, &id, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 id = p_strconcat(pool, "user/", dict->user->username, NULL); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 array_append(&iter->iter_ids, &id, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
311 i_array_init(&iter->iter_values, 64); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
312 iter->iter_value_pool = |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
313 pool_alloconly_create("acl lookup dict iter values", 1024); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
314 |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 /* get all groups we belong to */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 if (auser->groups != NULL) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 for (i = 0; auser->groups[i] != NULL; i++) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 id = p_strconcat(pool, "group/", auser->groups[i], |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 NULL); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 array_append(&iter->iter_ids, &id, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 /* iterate through all identifiers that match us, start with the |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 first one */ |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
326 if (dict->dict != NULL) |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
327 acl_lookup_dict_iterate_read(iter); |
12770
d03bdf2bf709
acl: Fixed crash when acl_lookup_dict was disabled and user belonged to groups.
Timo Sirainen <tss@iki.fi>
parents:
12215
diff
changeset
|
328 else |
d03bdf2bf709
acl: Fixed crash when acl_lookup_dict was disabled and user belonged to groups.
Timo Sirainen <tss@iki.fi>
parents:
12215
diff
changeset
|
329 array_clear(&iter->iter_ids); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 return iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 const char * |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 acl_lookup_dict_iterate_visible_next(struct acl_lookup_dict_iter *iter) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 { |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
336 const char *const *keys; |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
337 unsigned int count; |
8441
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
338 |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
339 keys = array_get(&iter->iter_values, &count); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
340 if (iter->iter_value_idx < count) |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
341 return keys[iter->iter_value_idx++]; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 if (iter->iter_idx < array_count(&iter->iter_ids)) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 /* get to the next iterator */ |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
345 acl_lookup_dict_iterate_read(iter); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 return acl_lookup_dict_iterate_visible_next(iter); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 return NULL; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 int acl_lookup_dict_iterate_visible_deinit(struct acl_lookup_dict_iter **_iter) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
353 struct acl_lookup_dict_iter *iter = *_iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 int ret = iter->failed ? -1 : 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 *_iter = NULL; |
12215
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
357 array_free(&iter->iter_values); |
ecc0bc80288c
acl: Avoid opening two dict iterators at the same time.
Timo Sirainen <tss@iki.fi>
parents:
12093
diff
changeset
|
358 pool_unref(&iter->iter_value_pool); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 pool_unref(&iter->pool); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 return ret; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 } |