Mercurial > dovecot > core-2.2
annotate src/plugins/acl/acl-lookup-dict.c @ 9434:e374a365521d HEAD
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
This will allow namespaces to share the same storage and a single namespace
to have multiple storages (multiple mailbox formats). Neither works
currently, and this commit probably breaks some things.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 02 Jun 2009 22:30:28 -0400 |
parents | e4429faabf59 |
children | 0059b2381024 |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8467
diff
changeset
|
1 /* Copyright (c) 2008-2009 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 #include <stdlib.h> |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #define DICT_SHARED_BOXES_PATH "shared-boxes/" |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 struct acl_lookup_dict { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 struct mail_user *user; |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
20 struct dict *dict; |
8433
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 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 struct acl_lookup_dict_iter { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 pool_t pool; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 struct acl_lookup_dict *dict; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 ARRAY_TYPE(const_string) iter_ids; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 struct dict_iterate_context *dict_iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 unsigned int iter_idx; |
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 const char *prefix; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 unsigned int prefix_len; |
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 unsigned int failed:1; |
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 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 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
|
38 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 struct acl_lookup_dict *dict; |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
40 const char *uri; |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 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
|
43 dict->user = user; |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
44 |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
45 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
|
46 if (uri != NULL) { |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
47 dict->dict = dict_init(uri, DICT_DATA_TYPE_STRING, ""); |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
48 if (dict->dict == NULL) |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
49 i_error("acl: dict_init(%s) failed", uri); |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
50 } else if (user->mail_debug) { |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
51 i_info("acl: No acl_shared_dict setting - " |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
52 "shared mailbox listing is disabled"); |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
53 } |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 return 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 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 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
|
58 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 struct acl_lookup_dict *dict = *_dict; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 *_dict = NULL; |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
62 if (dict->dict != NULL) |
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
63 dict_deinit(&dict->dict); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 i_free(dict); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 static void |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 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
|
69 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 switch (right->id_type) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 case ACL_ID_ANYONE: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 case ACL_ID_AUTHENTICATED: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 /* don't bother separating these */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 str_append(dest, "anyone"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 break; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 case ACL_ID_USER: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 str_append(dest, "user/"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 str_append(dest, right->identifier); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 break; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 case ACL_ID_GROUP: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 case ACL_ID_GROUP_OVERRIDE: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 str_append(dest, "group/"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 str_append(dest, right->identifier); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 break; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 case ACL_ID_OWNER: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 case ACL_ID_TYPE_COUNT: |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 i_unreached(); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 } |
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 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
|
92 ARRAY_TYPE(const_string) *ids) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 struct acl_backend *backend; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 struct acl_mailbox_list_context *ctx; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 struct acl_object *aclobj; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 struct acl_object_list_iter *iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 struct acl_rights rights; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 const char *name, *id_dup; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 string_t *id; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 int ret, ret2 = 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 |
9374
e4429faabf59
Split NAMESPACE_FLAG_INTERNAL into distinct _NOQUOTA and _NOACL flags.
Timo Sirainen <tss@iki.fi>
parents:
9004
diff
changeset
|
103 if ((ns->flags & NAMESPACE_FLAG_NOACL) != 0 || ns->owner == NULL) |
8464 | 104 return 0; |
105 | |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 iter = acl_object_list_init(aclobj); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 while ((ret = acl_object_list_next(iter, &rights)) > 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 if (acl_rights_has_nonowner_lookup_changes(&rights)) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 str_truncate(id, 0); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 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
|
117 str_append_c(id, '/'); |
8467
03c418eadc8b
mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents:
8466
diff
changeset
|
118 str_append(id, ns->owner->username); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 id_dup = t_strdup(str_c(id)); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 array_append(ids, &id_dup, 1); |
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 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 acl_object_list_deinit(&iter); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 if (ret < 0) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 ret2 = -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 acl_object_deinit(&aclobj); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 acl_backend_nonowner_lookups_iter_deinit(&ctx); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 return ret < 0 || ret2 < 0 ? -1 : 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 static int |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 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
|
134 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
|
135 bool no_removes) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 const char *username = dict->user->username; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 struct dict_iterate_context *iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 struct dict_transaction_context *dt; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 const char *prefix, *key, *value, **old_ids, *const *new_ids, *p; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 ARRAY_TYPE(const_string) old_ids_arr; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 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
|
143 string_t *path; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 unsigned int prefix_len; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 int ret; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
8466
4553e28eb4f5
acl: Update acl_dict correctly also for other visible users' shared namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8464
diff
changeset
|
147 /* 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
|
148 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
|
149 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
|
150 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
|
151 that could break them. */ |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 t_array_init(&old_ids_arr, 128); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 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
|
154 prefix_len = strlen(prefix); |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
155 iter = dict_iterate_init(dict->dict, prefix, DICT_ITERATE_FLAG_RECURSE); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 while ((ret = dict_iterate(iter, &key, &value)) > 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 /* prefix/$dest/$source */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 key += prefix_len; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 p = strchr(key, '/'); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 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
|
161 key = t_strdup_until(key, p); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 array_append(&old_ids_arr, &key, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 dict_iterate_deinit(&iter); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 if (ret < 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 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
|
168 return -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 /* sort the existing identifiers */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 old_ids = array_get_modifiable(&old_ids_arr, &old_count); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 qsort(old_ids, old_count, sizeof(*old_ids), i_strcmp_p); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 /* sync the identifiers */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 path = t_str_new(256); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 str_append(path, prefix); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
179 dt = dict_transaction_begin(dict->dict); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 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
|
181 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
|
182 ret = newi == new_count ? 1 : |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 oldi == old_count ? -1 : |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 strcmp(new_ids[newi], old_ids[oldi]); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 if (ret == 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 newi++; oldi++; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 } else if (ret < 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 /* new identifier, add it */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 str_truncate(path, prefix_len); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 str_append(path, new_ids[newi]); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 dict_set(dt, str_c(path), "1"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 newi++; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 } else if (!no_removes) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 /* old identifier removed */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 str_truncate(path, prefix_len); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 str_append(path, old_ids[oldi]); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 str_append_c(path, '/'); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 str_append(path, username); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 dict_unset(dt, str_c(path)); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 oldi++; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 if (dict_transaction_commit(&dt) < 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 i_error("acl: dict commit failed"); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 return -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 return 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 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
|
211 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 struct mail_namespace *ns; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 ARRAY_TYPE(const_string) ids_arr; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 const char **ids; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 unsigned int i, dest, count; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 int ret = 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
218 if (dict->dict == NULL) |
8441
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
219 return 0; |
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
220 |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 /* 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
|
222 t_array_init(&ids_arr, 128); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 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
|
224 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
|
225 ret = -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 /* sort identifiers and remove duplicates */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 ids = array_get_modifiable(&ids_arr, &count); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 qsort(ids, count, sizeof(*ids), i_strcmp_p); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 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
|
233 if (strcmp(ids[dest], ids[i]) != 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 if (++dest != i) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 ids[dest] = ids[i]; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 if (++dest < count) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 array_delete(&ids_arr, dest, count-dest); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 /* 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
|
242 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
|
243 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
|
244 ret = -1; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 return ret; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 static void acl_lookup_dict_iterate_start(struct acl_lookup_dict_iter *iter) |
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 const char *const *idp; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 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
|
253 iter->iter_idx++; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 iter->prefix = p_strconcat(iter->pool, DICT_PATH_SHARED |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 DICT_SHARED_BOXES_PATH, *idp, "/", NULL); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 iter->prefix_len = strlen(iter->prefix); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
258 iter->dict_iter = dict_iterate_init(iter->dict->dict, iter->prefix, |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 DICT_ITERATE_FLAG_RECURSE); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 struct acl_lookup_dict_iter * |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 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
|
264 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 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
|
266 struct acl_lookup_dict_iter *iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 const char *id; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 unsigned int i; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 pool_t pool; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 pool = pool_alloconly_create("acl lookup dict iter", 512); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 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
|
273 iter->pool = pool; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 iter->dict = dict; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 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
|
277 id = "anyone"; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 array_append(&iter->iter_ids, &id, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 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
|
280 array_append(&iter->iter_ids, &id, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 /* get all groups we belong to */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 if (auser->groups != NULL) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 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
|
285 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
|
286 NULL); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 array_append(&iter->iter_ids, &id, 1); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 } |
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 /* 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
|
292 first one */ |
9004
a5555606846b
Fixed plugins to work with config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
293 if (dict->dict != NULL) |
8441
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
294 acl_lookup_dict_iterate_start(iter); |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
295 return iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 const char * |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 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
|
300 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 const char *key, *value; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 int ret; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 |
8441
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
304 if (iter->dict_iter == NULL) |
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
305 return 0; |
6d5ca089bd1e
Don't crash if acl_dict setting is missing.
Timo Sirainen <tss@iki.fi>
parents:
8433
diff
changeset
|
306 |
8433
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 ret = dict_iterate(iter->dict_iter, &key, &value); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 if (ret > 0) { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 i_assert(iter->prefix_len < strlen(key)); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 return key + iter->prefix_len; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 if (ret < 0) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 iter->failed = TRUE; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 dict_iterate_deinit(&iter->dict_iter); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 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
|
317 /* get to the next iterator */ |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 acl_lookup_dict_iterate_start(iter); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 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
|
320 } |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 return NULL; |
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 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
|
325 { |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 struct acl_lookup_dict_iter *iter = *_iter; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 int ret = iter->failed ? -1 : 0; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 *_iter = NULL; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 if (iter->dict_iter != NULL) |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 dict_iterate_deinit(&iter->dict_iter); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 pool_unref(&iter->pool); |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 return ret; |
dfe39e9a9e78
Initial support for LISTing users with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 } |