~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to dovecot-managesieve/src/lib-managesieve/managesieve-quote.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:
1
 
/* Copyright (c) 2002-2009 Dovecot Sieve authors, see the included COPYING file
2
 
 */
3
 
 
4
 
#include "lib.h"
5
 
#include "str.h"
6
 
#include "managesieve-parser.h"
7
 
#include "managesieve-quote.h"
8
 
 
9
 
/* Turn the value string into a valid MANAGESIEVE string or literal, no matter 
10
 
 * what. QUOTED-SPECIALS are escaped, but any invalid (UTF-8) character
11
 
 * is simply removed. Linebreak characters are not considered invalid, but
12
 
 * they do force the generation of a string literal.
13
 
 */
14
 
void managesieve_quote_append(string_t *str, const unsigned char *value,
15
 
                       size_t value_len, bool compress_lwsp)
16
 
{
17
 
        size_t i, extra = 0;
18
 
        bool 
19
 
                last_lwsp = TRUE, 
20
 
                literal = FALSE, 
21
 
                modify = FALSE,
22
 
                escape = FALSE;
23
 
        int utf8_len;
24
 
 
25
 
        if (value == NULL) {
26
 
                str_append(str, "\"\"");
27
 
                return;
28
 
        }
29
 
 
30
 
        if (value_len == (size_t)-1)
31
 
                value_len = strlen((const char *) value);
32
 
 
33
 
        for (i = 0; i < value_len; i++) {
34
 
                switch (value[i]) {
35
 
                case ' ':
36
 
                case '\t':
37
 
                        if (last_lwsp && compress_lwsp) {
38
 
                                modify = TRUE;
39
 
                                extra++;
40
 
                        }
41
 
                        last_lwsp = TRUE;
42
 
                        break;
43
 
                case '"':
44
 
                case '\\':
45
 
                        escape = TRUE;
46
 
                        last_lwsp = FALSE;
47
 
                        break;
48
 
                case 13:
49
 
                case 10:
50
 
                        literal = TRUE;
51
 
                        last_lwsp = TRUE;
52
 
                        break;
53
 
                default:
54
 
                        /* Enforce valid UTF-8
55
 
                         */
56
 
                        if ( (utf8_len=UTF8_LEN(value[i])) == 0 ) {
57
 
                                modify = TRUE;
58
 
                                extra++;
59
 
                                break;
60
 
                        }
61
 
 
62
 
                        if ( utf8_len > 1 ) {
63
 
                                int c = utf8_len - 1;
64
 
 
65
 
                                if ( (i+utf8_len-1) >= value_len ) {
66
 
                                        /* Value ends in the middle of a UTF-8 character;
67
 
                                         * Kill the partial UTF-8 character
68
 
                                         */
69
 
                                        extra += i + utf8_len - value_len;
70
 
                                        modify = TRUE;
71
 
                                        break;          
72
 
                                }
73
 
 
74
 
                                /* Parse the series of UTF8_1 characters */
75
 
                                for (i++; c > 0; c--, i++ ) {
76
 
                                        if (!IS_UTF8_1(value[i])) {
77
 
                                                extra += utf8_len - c;
78
 
                                                modify = TRUE;
79
 
                                                break;
80
 
                                        }
81
 
                                }
82
 
                        }
83
 
                        
84
 
                        last_lwsp = FALSE;
85
 
                }
86
 
        }
87
 
 
88
 
        if (!literal) {
89
 
                /* no linebreak chars, return as (escaped) "string" */
90
 
                str_append_c(str, '"');
91
 
        } else {
92
 
                /* return as literal */
93
 
                str_printfa(str, "{%"PRIuSIZE_T"}\r\n", value_len - extra);
94
 
        }
95
 
 
96
 
        if (!modify && (literal || !escape))
97
 
                str_append_n(str, value, value_len);
98
 
        else {
99
 
                last_lwsp = TRUE;
100
 
                for (i = 0; i < value_len; i++) {
101
 
                        switch (value[i]) {
102
 
                        case '"':
103
 
                        case '\\':
104
 
                                last_lwsp = FALSE;
105
 
                                if (!literal) 
106
 
                                        str_append_c(str, '\\');
107
 
                                str_append_c(str, value[i]);
108
 
                                break;
109
 
                        case ' ':
110
 
                        case '\t':
111
 
                                if (!last_lwsp || !compress_lwsp)
112
 
                                        str_append_c(str, ' ');
113
 
                                last_lwsp = TRUE;
114
 
                                break;
115
 
                        case 13:
116
 
                        case 10:
117
 
                                last_lwsp = TRUE;
118
 
                                str_append_c(str, value[i]);
119
 
                                break;
120
 
                        default:
121
 
                                /* Enforce valid UTF-8
122
 
                                 */
123
 
                                if ( (utf8_len=UTF8_LEN(value[i])) == 0 ) 
124
 
                                        break;
125
 
      
126
 
                                if ( utf8_len > 1 ) {
127
 
                                        int c = utf8_len - 1;
128
 
                                        int j;
129
 
 
130
 
                                        if ( (i+utf8_len-1) >= value_len ) {
131
 
                                                /* Value ends in the middle of a UTF-8 character;
132
 
                                                 * Kill the partial character
133
 
                                                 */
134
 
                                                i = value_len;
135
 
                                                break;
136
 
                                        }
137
 
 
138
 
                                        /* Parse the series of UTF8_1 characters */
139
 
                                        for (j = i+1; c > 0; c--, j++ ) {
140
 
                                                if (!IS_UTF8_1(value[j])) {
141
 
                                                        /* Skip until after this erroneous character */
142
 
                                                        i = j;
143
 
                                                        break;
144
 
                                                }
145
 
                                        }
146
 
 
147
 
                                        /* Append the UTF-8 character. Last octet is done later */
148
 
                                        c = utf8_len - 1;
149
 
                                        for (; c > 0; c--, i++ ) 
150
 
                                                str_append_c(str, value[i]);
151
 
                                }
152
 
     
153
 
                                last_lwsp = FALSE;
154
 
                                str_append_c(str, value[i]);
155
 
                                break;
156
 
                        }
157
 
                }
158
 
        }
159
 
 
160
 
        if (!literal)
161
 
                str_append_c(str, '"');
162
 
}
163
 
 
164
 
char *managesieve_quote(pool_t pool, const unsigned char *value, size_t value_len)
165
 
{
166
 
        string_t *str;
167
 
        char *ret;
168
 
 
169
 
        if (value == NULL)
170
 
                return "\"\"";
171
 
 
172
 
        t_push();
173
 
        str = t_str_new(value_len + MAX_INT_STRLEN + 5);
174
 
        managesieve_quote_append(str, value, value_len, TRUE);
175
 
        ret = p_strndup(pool, str_data(str), str_len(str));
176
 
        t_pop();
177
 
 
178
 
        return ret;
179
 
}