~ubuntu-branches/ubuntu/trusty/dovecot/trusty-updates

« back to all changes in this revision

Viewing changes to src/imap/imap-metadata.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (1.15.3) (96.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140108093549-814nkqdcxfbvgktg
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) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "imap-common.h"
 
4
#include "imap-metadata.h"
 
5
 
 
6
bool imap_metadata_verify_entry_name(struct client_command_context *cmd,
 
7
                                     const char *name)
 
8
{
 
9
        unsigned int i;
 
10
        bool ok;
 
11
 
 
12
        if (name[0] != '/') {
 
13
                client_send_command_error(cmd,
 
14
                        "Entry name must begin with '/'");
 
15
                return FALSE;
 
16
        }
 
17
        for (i = 0; name[i] != '\0'; i++) {
 
18
                switch (name[i]) {
 
19
                case '/':
 
20
                        if (i > 0 && name[i-1] == '/') {
 
21
                                client_send_command_error(cmd,
 
22
                                        "Entry name can't contain consecutive '/'");
 
23
                                return FALSE;
 
24
                        }
 
25
                        if (name[i+1] == '\0') {
 
26
                                client_send_command_error(cmd,
 
27
                                        "Entry name can't end with '/'");
 
28
                                return FALSE;
 
29
                        }
 
30
                        break;
 
31
                case '*':
 
32
                        client_send_command_error(cmd,
 
33
                                "Entry name can't contain '*'");
 
34
                        return FALSE;
 
35
                case '%':
 
36
                        client_send_command_error(cmd,
 
37
                                "Entry name can't contain '%'");
 
38
                        return FALSE;
 
39
                default:
 
40
                        if (name[i] <= 0x19) {
 
41
                                client_send_command_error(cmd,
 
42
                                        "Entry name can't contain control chars");
 
43
                                return FALSE;
 
44
                        }
 
45
                        break;
 
46
                }
 
47
        }
 
48
        T_BEGIN {
 
49
                const char *prefix, *p = strchr(name+1, '/');
 
50
 
 
51
                prefix = p == NULL ? name : t_strdup_until(name, p);
 
52
                ok = strcasecmp(prefix, IMAP_METADATA_PRIVATE_PREFIX) == 0 ||
 
53
                        strcasecmp(prefix, IMAP_METADATA_SHARED_PREFIX) == 0;
 
54
        } T_END;
 
55
        if (!ok) {
 
56
                client_send_command_error(cmd,
 
57
                        "Entry name must begin with /private or /shared");
 
58
                return FALSE;
 
59
        }
 
60
        return TRUE;
 
61
}
 
62
 
 
63
void imap_metadata_entry2key(const char *entry, const char *key_prefix,
 
64
                             enum mail_attribute_type *type_r,
 
65
                             const char **key_r)
 
66
{
 
67
        if (strncmp(entry, IMAP_METADATA_PRIVATE_PREFIX,
 
68
                    strlen(IMAP_METADATA_PRIVATE_PREFIX)) == 0) {
 
69
                *key_r = entry + strlen(IMAP_METADATA_PRIVATE_PREFIX);
 
70
                *type_r = MAIL_ATTRIBUTE_TYPE_PRIVATE;
 
71
        } else {
 
72
                i_assert(strncmp(entry, IMAP_METADATA_SHARED_PREFIX,
 
73
                                 strlen(IMAP_METADATA_SHARED_PREFIX)) == 0);
 
74
                *key_r = entry + strlen(IMAP_METADATA_SHARED_PREFIX);
 
75
                *type_r = MAIL_ATTRIBUTE_TYPE_SHARED;
 
76
        }
 
77
        if ((*key_r)[0] == '\0') {
 
78
                /* /private or /shared prefix has no value itself */
 
79
        } else {
 
80
                i_assert((*key_r)[0] == '/');
 
81
                *key_r += 1;
 
82
        }
 
83
        if (key_prefix != NULL)
 
84
                *key_r = t_strconcat(key_prefix, *key_r, NULL);
 
85
}