~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002110912

« back to all changes in this revision

Viewing changes to src/plugins/acl/acl-mailbox.c

  • Committer: Bazaar Package Importer
  • Author(s): CHuck Short, Chuck Short
  • Date: 2009-11-06 00:47:29 UTC
  • mfrom: (4.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106004729-i39n7v9e7d4h51f6
Tags: 1:1.2.6-1ubuntu1
* Merge from debian testing, remaining changes:
  Add new binary pkg dovecot-postfix that integrates postfix and dovecot
  automatically: (LP: #164837)
  + debian/control:
    - add new binary with short description
    - set Architecture all for dovecot-postfix (LP: #329878)
  + debian/dovecot-postfix.postinst:
    - create initial certificate symlinks to snakeoil.
    - set up postfix with postconf to:
      - use Maildir/ as the default mailbox.
      - use dovecot as the sasl authentication server.
      - use dovecot LDA (deliver).
      - use tls for smtp{d} services.
    - fix certificates paths in postfix' main.cf
    - add reject_unauth_destination to postfix' recipient restrictions
    - add reject_unknown_sender_domain to postfix' sender restrictions
    - rename configuration name on remove, delete on purge
    - restart dovecot after linking certificates
    - handle use case when postfix is unconfigurated
   + debian/dovecot-postfix.dirs: create backup directory for postfix's configuration
   + restart postfix and dovecot.
   + debian/dovecot-postfix.postrm:
     - remove all dovecot related configuration from postfix.
     - restart postfix and dovecot.
   + debian/dovecot-common.init:
     - check if /etc/dovecot/dovecot-postfix.conf exists and use it
       as the configuration file if so.
   + debian/patches/warning-ubuntu-postfix.dpatch
     - add warning about dovecot-postfix.conf in dovecot default 
       configuration file
   + debian/patches/dovecot-postfix.conf.diff:
     - Ubuntu server custom changes to the default dovecot configuration for
       better interfation with postfix
     - enable sieve plugin
   + debian/patches/dovecot-postfix.conf.diff:
     + Ubuntu server custom changes to the default dovecot configuration for
       better integration with postfix:
       - enable imap, pop3, imaps, pop3s and managesieve by default.
       - enable dovecot LDA (deliver).
       - enable SASL auth socket in postfix private directory.
   + debian/rules:
     - copy, patch and install dovecot-postfix.conf in /etc/dovecot/.
     - build architecure independent packages too
   + Use Snakeoil SSL certificates by default.
     - debian/control: Depend on ssl-cert.
     - debian/patches/ssl-cert-snakeoil.dpatch: Change default SSL cert
       paths to snakeoil.
     - debian/dovecot-common.postinst: Relax grep for SSL_* a bit.
   + Add autopkgtest to debian/tests/*.
   + Fast TearDown: Update the lsb init header to not stop in level 6.
   + Add ufw integration:
     - Created debian/dovecot-common.ufw.profile.
     - debian/rules:
       + install profile
     - debian/control:
       + Suggest ufw
   + debian/{control,rules}: enable PIE hardening.
   + dovecot-imapd, dovecot-pop3: Replaces dovecot-common (<< 1:1.1). LP: #254721
   + debian/control:
     - Update Vcs-* headers.
   + debian/rules:
     - Create emtpy stamp.h.in files in dovecot-sieve/ and dovecot-managesieve/
       if they're not there since empty files are not included in the diff.gz 
       file.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
   + Dropped:
     - debian/patches/security-CVE-2009-3235: Applied upstream.
     - debian/patches/fix-pop3-assertion.dpatch: Applied upstream.
     - dovecot-sieve and dovecot-managesieve: Use the debian patches instead.

  [Chuck Short]
  - Updated dovecot-sieve to 0.1.13.
  - Updated dovecot-managesieve to 0.11.9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
static MODULE_CONTEXT_DEFINE_INIT(acl_mail_module, &mail_module_register);
31
31
static struct acl_transaction_context acl_transaction_failure;
32
32
 
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)
 
34
{
 
35
        struct acl_mail_storage *astorage = ACL_CONTEXT(storage);
 
36
 
 
37
        return astorage->rights.backend;
 
38
}
 
39
 
 
40
struct acl_object *acl_storage_get_default_aclobj(struct mail_storage *storage)
 
41
{
 
42
        struct acl_mail_storage *astorage = ACL_CONTEXT(storage);
 
43
 
 
44
        return astorage->rights.backend->default_aclobj;
 
45
}
 
46
 
 
47
struct acl_object *acl_mailbox_get_aclobj(struct mailbox *box)
 
48
{
 
49
        struct acl_mailbox *abox = ACL_CONTEXT(box);
 
50
 
 
51
        return abox->aclobj;
 
52
}
 
53
 
 
54
int acl_mailbox_right_lookup(struct mailbox *box, unsigned int right_idx)
34
55
{
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)
54
75
{
55
76
        struct acl_mailbox *abox = ACL_CONTEXT(box);
 
77
        enum acl_storage_rights save_right;
56
78
 
57
79
        if (abox->module_ctx.super.is_readonly(box))
58
80
                return TRUE;
59
81
 
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)
61
85
                return FALSE;
62
 
        if (mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_EXPUNGE) > 0)
 
86
        if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_EXPUNGE) > 0)
63
87
                return FALSE;
64
88
 
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)
67
91
                return FALSE;
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)
70
94
                return FALSE;
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)
73
97
                return FALSE;
74
98
 
75
99
        return TRUE;
82
106
        if (!abox->module_ctx.super.allow_new_keywords(box))
83
107
                return FALSE;
84
108
 
85
 
        return mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0;
 
109
        return acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0;
86
110
}
87
111
 
88
112
static int acl_mailbox_close(struct mailbox *box)
99
123
{
100
124
        int ret;
101
125
 
102
 
        ret = mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE);
 
126
        ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE);
103
127
        if (ret < 0)
104
128
                return -1;
105
129
        *flags_r = ret > 0;
106
130
 
107
 
        ret = mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN);
 
131
        ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN);
108
132
        if (ret < 0)
109
133
                return -1;
110
134
        *flag_seen_r = ret > 0;
111
135
 
112
 
        ret = mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_DELETED);
 
136
        ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_DELETED);
113
137
        if (ret < 0)
114
138
                return -1;
115
139
        *flag_del_r = ret > 0;
171
195
        union mail_module_context *amail = ACL_MAIL_CONTEXT(mail);
172
196
        int ret;
173
197
 
174
 
        ret = mailbox_acl_right_lookup(_mail->box, ACL_STORAGE_RIGHT_WRITE);
 
198
        ret = acl_mailbox_right_lookup(_mail->box, ACL_STORAGE_RIGHT_WRITE);
175
199
        if (ret <= 0) {
176
200
                /* if we don't have permission, just silently return success. */
177
201
                if (ret < 0)
188
212
        union mail_module_context *amail = ACL_MAIL_CONTEXT(mail);
189
213
        int ret;
190
214
 
191
 
        ret = mailbox_acl_right_lookup(_mail->box, ACL_STORAGE_RIGHT_EXPUNGE);
 
215
        ret = acl_mailbox_right_lookup(_mail->box, ACL_STORAGE_RIGHT_EXPUNGE);
192
216
        if (ret <= 0) {
193
217
                /* if we don't have permission, silently return success so
194
218
                   users won't see annoying error messages in case their
246
270
}
247
271
 
248
272
static int
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)
254
274
{
255
 
        struct acl_mailbox *abox = ACL_CONTEXT(t->box);
256
 
 
257
 
        if (mailbox_acl_right_lookup(t->box, ACL_STORAGE_RIGHT_INSERT) <= 0)
258
 
                return -1;
259
 
        if (acl_save_get_flags(t->box, &flags, &keywords) < 0)
260
 
                return -1;
261
 
 
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;
 
278
 
 
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)
 
282
                return -1;
 
283
        if (acl_save_get_flags(box, &ctx->flags, &ctx->keywords) < 0)
 
284
                return -1;
 
285
 
 
286
        return abox->module_ctx.super.save_begin(ctx, input);
266
287
}
267
288
 
268
289
static int
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)
272
291
{
 
292
        struct mailbox_transaction_context *t = ctx->transaction;
273
293
        struct acl_mailbox *abox = ACL_CONTEXT(t->box);
274
 
 
275
 
        if (mailbox_acl_right_lookup(t->box, ACL_STORAGE_RIGHT_INSERT) <= 0)
276
 
                return -1;
277
 
        if (acl_save_get_flags(t->box, &flags, &keywords) < 0)
278
 
                return -1;
279
 
 
280
 
        return abox->module_ctx.super.copy(t, mail, flags, keywords, dest_mail);
 
294
        enum acl_storage_rights save_right;
 
295
 
 
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)
 
299
                return -1;
 
300
        if (acl_save_get_flags(t->box, &ctx->flags, &ctx->keywords) < 0)
 
301
                return -1;
 
302
 
 
303
        return abox->module_ctx.super.copy(ctx, mail);
281
304
}
282
305
 
283
306
static int
305
328
        struct acl_mailbox *abox = ACL_CONTEXT(box);
306
329
        int ret;
307
330
 
308
 
        ret = mailbox_acl_right_lookup(box, ACL_STORAGE_RIGHT_WRITE);
 
331
        ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE);
309
332
        if (ret < 0) {
310
333
                if (!skip_invalid)
311
334
                        return -1;
337
360
        abox->aclobj = acl_object_init_from_name(astorage->rights.backend,
338
361
                                                 box->storage,
339
362
                                                 mailbox_get_name(box));
340
 
        
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;
 
363
 
 
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;
 
373
        }
349
374
        MODULE_CONTEXT_SET(box, acl_storage_module, abox);
350
375
        return box;
351
376
}