30
30
static MODULE_CONTEXT_DEFINE_INIT(acl_mail_module, &mail_module_register);
31
31
static struct acl_transaction_context acl_transaction_failure;
33
static int mailbox_acl_right_lookup(struct mailbox *box, unsigned int right_idx)
33
struct acl_backend *acl_storage_get_backend(struct mail_storage *storage)
35
struct acl_mail_storage *astorage = ACL_CONTEXT(storage);
37
return astorage->rights.backend;
40
struct acl_object *acl_storage_get_default_aclobj(struct mail_storage *storage)
42
struct acl_mail_storage *astorage = ACL_CONTEXT(storage);
44
return astorage->rights.backend->default_aclobj;
47
struct acl_object *acl_mailbox_get_aclobj(struct mailbox *box)
49
struct acl_mailbox *abox = ACL_CONTEXT(box);
54
int acl_mailbox_right_lookup(struct mailbox *box, unsigned int right_idx)
35
56
struct acl_mailbox *abox = ACL_CONTEXT(box);
36
57
struct acl_mail_storage *astorage = ACL_CONTEXT(box->storage);
53
74
static bool acl_is_readonly(struct mailbox *box)
55
76
struct acl_mailbox *abox = ACL_CONTEXT(box);
77
enum acl_storage_rights save_right;
57
79
if (abox->module_ctx.super.is_readonly(box))
60
if (mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_INSERT) > 0)
82
save_right = (box->open_flags & MAILBOX_OPEN_POST_SESSION) != 0 ?
83
ACL_STORAGE_RIGHT_POST : ACL_STORAGE_RIGHT_INSERT;
84
if (acl_mailbox_right_lookup(box, save_right) > 0)
62
if (mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_EXPUNGE) > 0)
86
if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_EXPUNGE) > 0)
65
89
/* Next up is the "shared flag rights" */
66
if (mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0)
90
if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0)
68
92
if ((box->private_flags_mask & MAIL_DELETED) == 0 &&
69
mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_DELETED) > 0)
93
acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_DELETED) > 0)
71
95
if ((box->private_flags_mask & MAIL_SEEN) == 0 &&
72
mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN) > 0)
96
acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN) > 0)
102
ret = mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE);
126
ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE);
105
129
*flags_r = ret > 0;
107
ret = mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN);
131
ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN);
110
134
*flag_seen_r = ret > 0;
112
ret = mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_DELETED);
136
ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_DELETED);
115
139
*flag_del_r = ret > 0;
249
acl_save_init(struct mailbox_transaction_context *t,
250
enum mail_flags flags, struct mail_keywords *keywords,
251
time_t received_date, int timezone_offset,
252
const char *from_envelope, struct istream *input,
253
struct mail *dest_mail, struct mail_save_context **ctx_r)
273
acl_save_begin(struct mail_save_context *ctx, struct istream *input)
255
struct acl_mailbox *abox = ACL_CONTEXT(t->box);
257
if (mailbox_acl_right_lookup(t->box, ACL_STORAGE_RIGHT_INSERT) <= 0)
259
if (acl_save_get_flags(t->box, &flags, &keywords) < 0)
262
return abox->module_ctx.super.
263
save_init(t, flags, keywords, received_date,
264
timezone_offset, from_envelope,
265
input, dest_mail, ctx_r);
275
struct mailbox *box = ctx->transaction->box;
276
struct acl_mailbox *abox = ACL_CONTEXT(box);
277
enum acl_storage_rights save_right;
279
save_right = (box->open_flags & MAILBOX_OPEN_POST_SESSION) != 0 ?
280
ACL_STORAGE_RIGHT_POST : ACL_STORAGE_RIGHT_INSERT;
281
if (acl_mailbox_right_lookup(box, save_right) <= 0)
283
if (acl_save_get_flags(box, &ctx->flags, &ctx->keywords) < 0)
286
return abox->module_ctx.super.save_begin(ctx, input);
269
acl_copy(struct mailbox_transaction_context *t, struct mail *mail,
270
enum mail_flags flags, struct mail_keywords *keywords,
271
struct mail *dest_mail)
290
acl_copy(struct mail_save_context *ctx, struct mail *mail)
292
struct mailbox_transaction_context *t = ctx->transaction;
273
293
struct acl_mailbox *abox = ACL_CONTEXT(t->box);
275
if (mailbox_acl_right_lookup(t->box, ACL_STORAGE_RIGHT_INSERT) <= 0)
277
if (acl_save_get_flags(t->box, &flags, &keywords) < 0)
280
return abox->module_ctx.super.copy(t, mail, flags, keywords, dest_mail);
294
enum acl_storage_rights save_right;
296
save_right = (t->box->open_flags & MAILBOX_OPEN_POST_SESSION) != 0 ?
297
ACL_STORAGE_RIGHT_POST : ACL_STORAGE_RIGHT_INSERT;
298
if (acl_mailbox_right_lookup(t->box, save_right) <= 0)
300
if (acl_save_get_flags(t->box, &ctx->flags, &ctx->keywords) < 0)
303
return abox->module_ctx.super.copy(ctx, mail);
337
360
abox->aclobj = acl_object_init_from_name(astorage->rights.backend,
339
362
mailbox_get_name(box));
341
box->v.is_readonly = acl_is_readonly;
342
box->v.allow_new_keywords = acl_allow_new_keywords;
343
box->v.close = acl_mailbox_close;
344
box->v.mail_alloc = acl_mail_alloc;
345
box->v.save_init = acl_save_init;
346
box->v.keywords_create = acl_keywords_create;
347
box->v.copy = acl_copy;
348
box->v.transaction_commit = acl_transaction_commit;
364
if ((box->open_flags & MAILBOX_OPEN_IGNORE_ACLS) == 0) {
365
box->v.is_readonly = acl_is_readonly;
366
box->v.allow_new_keywords = acl_allow_new_keywords;
367
box->v.close = acl_mailbox_close;
368
box->v.mail_alloc = acl_mail_alloc;
369
box->v.save_begin = acl_save_begin;
370
box->v.keywords_create = acl_keywords_create;
371
box->v.copy = acl_copy;
372
box->v.transaction_commit = acl_transaction_commit;
349
374
MODULE_CONTEXT_SET(box, acl_storage_module, abox);