~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/plugins/imap-acl/imap-acl-plugin.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2008-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2008-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "imap-common.h"
4
4
#include "str.h"
44
44
        { '\0', NULL }
45
45
};
46
46
 
47
 
const char *imap_acl_plugin_version = DOVECOT_VERSION;
 
47
const char *imap_acl_plugin_version = DOVECOT_ABI_VERSION;
48
48
 
49
49
static struct module *imap_acl_module;
50
 
static void (*next_hook_client_created)(struct client **client);
 
50
static imap_client_created_func_t *next_hook_client_created;
51
51
 
52
52
static struct mailbox *
53
53
acl_mailbox_open_as_admin(struct client_command_context *cmd, const char *name)
163
163
                i_unreached();
164
164
        }
165
165
 
166
 
        imap_quote_append(dest, str_data(tmp), str_len(tmp), FALSE);
 
166
        imap_append_astring(dest, str_c(tmp));
167
167
        str_append_c(dest, ' ');
168
168
        imap_acl_write_rights_list(dest, rights);
169
169
}
288
288
 
289
289
        str = t_str_new(128);
290
290
        str_append(str, "* ACL ");
291
 
        imap_quote_append_string(str, mailbox, FALSE);
 
291
        imap_append_astring(str, mailbox);
292
292
 
293
293
        ns = mailbox_get_namespace(box);
294
294
        backend = acl_mailbox_list_get_backend(ns->list);
295
295
        ret = imap_acl_write_aclobj(str, backend,
296
296
                                    acl_mailbox_get_aclobj(box), TRUE,
297
 
                                    ns->type == NAMESPACE_PRIVATE);
 
297
                                    ns->type == MAIL_NAMESPACE_TYPE_PRIVATE);
298
298
        if (ret == 0) {
299
299
                client_send_line(cmd->client, str_c(str));
300
300
                client_send_tagline(cmd, "OK Getacl completed.");
347
347
 
348
348
        str = t_str_new(128);
349
349
        str_append(str, "* MYRIGHTS ");
350
 
        imap_quote_append_string(str, orig_mailbox, FALSE);
 
350
        imap_append_astring(str, orig_mailbox);
351
351
        str_append_c(str,' ');
352
352
        imap_acl_write_rights_list(str, rights);
353
353
 
372
372
 
373
373
        str = t_str_new(128);
374
374
        str_append(str, "* LISTRIGHTS ");
375
 
        imap_quote_append_string(str, mailbox, FALSE);
 
375
        imap_append_astring(str, mailbox);
376
376
        str_append_c(str, ' ');
377
 
        imap_quote_append_string(str, identifier, FALSE);
 
377
        imap_append_astring(str, identifier);
378
378
        str_append_c(str, ' ');
379
379
        str_append(str, "\"\" l r w s t p i e k x a c d");
380
380
 
423
423
                        }
424
424
                }
425
425
        }
426
 
        (void)array_append_space(&rights);
 
426
        array_append_zero(&rights);
427
427
        *rights_r = array_idx(&rights, 0);
428
428
        return 0;
429
429
}
528
528
        default:
529
529
                return;
530
530
        }
531
 
        (void)array_append_space(&new_rights);
 
531
        array_append_zero(&new_rights);
532
532
        update->rights.rights = array_idx(&new_rights, 0);
533
533
}
534
534
 
 
535
static int
 
536
cmd_acl_mailbox_update(struct mailbox *box,
 
537
                       const struct acl_rights_update *update,
 
538
                       const char **error_r)
 
539
{
 
540
        struct mailbox_transaction_context *t;
 
541
        int ret;
 
542
 
 
543
        if (mailbox_open(box) < 0) {
 
544
                *error_r = mailbox_get_last_error(box, NULL);
 
545
                return -1;
 
546
        }
 
547
 
 
548
        t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL);
 
549
        ret = acl_mailbox_update_acl(t, update);
 
550
        if (mailbox_transaction_commit(&t) < 0)
 
551
                ret = -1;
 
552
        *error_r = MAIL_ERRSTR_CRITICAL_MSG;
 
553
        return ret;
 
554
}
 
555
 
535
556
static bool cmd_setacl(struct client_command_context *cmd)
536
557
{
537
558
        struct mail_namespace *ns;
588
609
 
589
610
        ns = mailbox_get_namespace(box);
590
611
        backend = acl_mailbox_list_get_backend(ns->list);
591
 
        if (ns->type == NAMESPACE_PUBLIC && r->id_type == ACL_ID_OWNER) {
 
612
        if (ns->type == MAIL_NAMESPACE_TYPE_PUBLIC &&
 
613
            r->id_type == ACL_ID_OWNER) {
592
614
                client_send_tagline(cmd, "NO Public namespaces have no owner");
593
615
                mailbox_free(&box);
594
616
                return TRUE;
600
622
                update.modify_mode = ACL_MODIFY_MODE_REMOVE;
601
623
                update.rights.neg_rights = update.rights.rights;
602
624
                update.rights.rights = NULL;
603
 
        } else if (ns->type == NAMESPACE_PRIVATE && r->rights != NULL &&
 
625
        } else if (ns->type == MAIL_NAMESPACE_TYPE_PRIVATE &&
 
626
                   r->rights != NULL &&
604
627
                   ((r->id_type == ACL_ID_USER &&
605
628
                     acl_backend_user_name_equals(backend, r->identifier)) ||
606
629
                    (r->id_type == ACL_ID_OWNER &&
611
634
                imap_acl_update_ensure_keep_admins(backend, aclobj, &update);
612
635
        }
613
636
 
614
 
        if (acl_object_update(aclobj, &update) < 0)
615
 
                client_send_tagline(cmd, "NO "MAIL_ERRSTR_CRITICAL_MSG);
 
637
        if (cmd_acl_mailbox_update(box, &update, &error) < 0)
 
638
                client_send_tagline(cmd, t_strdup_printf("NO %s", error));
616
639
        else
617
640
                client_send_tagline(cmd, "OK Setacl complete.");
618
641
        mailbox_free(&box);
650
673
        if (box == NULL)
651
674
                return TRUE;
652
675
 
653
 
        if (acl_object_update(acl_mailbox_get_aclobj(box), &update) < 0)
654
 
                client_send_tagline(cmd, "NO "MAIL_ERRSTR_CRITICAL_MSG);
 
676
        if (cmd_acl_mailbox_update(box, &update, &error) < 0)
 
677
                client_send_tagline(cmd, t_strdup_printf("NO %s", error));
655
678
        else
656
679
                client_send_tagline(cmd, "OK Deleteacl complete.");
657
680
        mailbox_free(&box);