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

« back to all changes in this revision

Viewing changes to libsieve/src/lib-sieve/tst-address.c

  • Committer: Chuck Short
  • Date: 2010-01-21 20:21:25 UTC
  • mfrom: (4.1.11 squeeze)
  • Revision ID: zulcss@ubuntu.com-20100121202125-pme73o491kfwj5nc
* 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 restriction
    - 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 config
    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.
    - 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.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
* New upstream release.
* debian/patches/gold-fix.patch: Removed. Fixed upstream.
* Moved libexec to lib corrections in dovecot-managesieve.patch and
  dovecot-managesieve-dist.patch to dovecot-example.patch
* debian/patches/dovecot-mboxlocking.patch: Regenerated to avoid FTBFS
  when quilt isn't installed.
* debian/patches/quota-mountpoint.patch: Removed. Not needed anymore.
* debian/patches/dovecot-quota.patch: Removed. Quotas aren't properly
  enabled unless mail_plugins = quota imap_quota.
* debian/patches/gold-fix.patch: Fixed configure script to build even
  with binutils-gold or --no-add-needed linker flag (Closes: #554306)
* debian/dovecot-common.init: fixed LSB headers. Thanks to Pascal Volk.
  (Closes: #558040)
* debian/changelog: added CVE references to previous changelog entry.
* debian/rules: checked up the build system. It's not fragile anymore.
  (Closes: 493803)
* debian/dovecot-common.postinst: Now invoking dpkg-reconfigure
  on dovecot-common is enough to generate new certificates
  if the previous ones were removed. (Closes: #545582)
* debian/rules: No longer install convert-tool in /usr/bin.
  It isn't an user utility and it should stay in /usr/lib/dovecot
  like all other similar tool.
* New upstream release. (Closes: #557601)
* [SECURITY] Fixes local information disclosure and denial of service.
  (see: http://www.dovecot.org/list/dovecot-news/2009-November/000143.html
  and CVE-2009-3897)
* Added myself to uploaders.
* Switched to the new source format "3.0 (quilt)":
  - removed dpatch from build-depends
  - removed debian/README.source because now we use only standard
    dpkg features
  - regenerated all patches
* Prepared to switch to multi-origin source:
  - recreated dovecot-libsieve.patch and dovecot-managesieve-dist.patch
    starting from the upstream tarball
  - removed all autotools related build-depends and build-conflict
  - renamed dovecot-libsieve and dovecot-managesieve directories
    to libsieve and managesieve.
* debian/rules: Moved the configuration of libsieve and managesieve from
  the build phase to the configuration phase
* Added dovecot-dbg package  with debugging symbols.  Thanks Stephan Bosch.
  (Closes: #554710)
* Fixed some stray libexec'isms in the default configuration.
* New upstream release.
* debian/dovecot-common.init:
  - use $CONF when starting the daemon. (Closes: #549944)
  - always output start/stop messages. (Closes: #523810)

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-sanitize.h"
 
6
 
 
7
#include "sieve-common.h"
 
8
#include "sieve-commands.h"
 
9
#include "sieve-code.h"
 
10
#include "sieve-comparators.h"
 
11
#include "sieve-match-types.h"
 
12
#include "sieve-address-parts.h"
 
13
#include "sieve-validator.h"
 
14
#include "sieve-generator.h"
 
15
#include "sieve-interpreter.h"
 
16
#include "sieve-dump.h"
 
17
#include "sieve-match.h"
 
18
 
 
19
#include <stdio.h>
 
20
 
 
21
/* 
 
22
 * Address test
 
23
 *
 
24
 * Syntax:
 
25
 *    address [ADDRESS-PART] [COMPARATOR] [MATCH-TYPE]
 
26
 *       <header-list: string-list> <key-list: string-list>
 
27
 */
 
28
 
 
29
static bool tst_address_registered
 
30
        (struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg);
 
31
static bool tst_address_validate
 
32
        (struct sieve_validator *valdtr, struct sieve_command_context *tst);
 
33
static bool tst_address_generate
 
34
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
 
35
 
 
36
const struct sieve_command tst_address = { 
 
37
        "address", 
 
38
        SCT_TEST, 
 
39
        2, 0, FALSE, FALSE,
 
40
        tst_address_registered,
 
41
        NULL, 
 
42
        tst_address_validate, 
 
43
        tst_address_generate, 
 
44
        NULL 
 
45
};
 
46
 
 
47
/* 
 
48
 * Address operation 
 
49
 */
 
50
 
 
51
static bool tst_address_operation_dump
 
52
        (const struct sieve_operation *op, 
 
53
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
54
static int tst_address_operation_execute
 
55
        (const struct sieve_operation *op, 
 
56
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
57
 
 
58
const struct sieve_operation tst_address_operation = { 
 
59
        "ADDRESS",
 
60
        NULL,
 
61
        SIEVE_OPERATION_ADDRESS,
 
62
        tst_address_operation_dump, 
 
63
        tst_address_operation_execute 
 
64
};
 
65
 
 
66
/* 
 
67
 * Test registration 
 
68
 */
 
69
 
 
70
static bool tst_address_registered
 
71
        (struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg) 
 
72
{
 
73
        /* The order of these is not significant */
 
74
        sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_AM_OPT_COMPARATOR );
 
75
        sieve_address_parts_link_tags(valdtr, cmd_reg, SIEVE_AM_OPT_ADDRESS_PART);
 
76
        sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_AM_OPT_MATCH_TYPE);
 
77
 
 
78
        return TRUE;
 
79
}
 
80
 
 
81
/* 
 
82
 * Validation 
 
83
 */
 
84
 
 
85
/* List of valid headers:
 
86
 *   Implementations MUST restrict the address test to headers that
 
87
 *   contain addresses, but MUST include at least From, To, Cc, Bcc,
 
88
 *   Sender, Resent-From, and Resent-To, and it SHOULD include any other
 
89
 *   header that utilizes an "address-list" structured header body.
 
90
 *
 
91
 * This list explicitly does not contain the envelope-to and return-path 
 
92
 * headers. The envelope test must be used to test against these addresses.
 
93
 *
 
94
 * FIXME: this restriction is somewhat odd. Sieve list advises to allow 
 
95
 *        any other header as long as its content matches the address-list
 
96
 *        grammar.
 
97
 */
 
98
static const char * const _allowed_headers[] = {
 
99
        /* Required */
 
100
        "from", "to", "cc", "bcc", "sender", "resent-from", "resent-to",
 
101
 
 
102
        /* Additional (RFC 822 / RFC 2822) */
 
103
        "reply-to", "resent-reply-to", "resent-sender", "resent-cc", "resent-bcc",  
 
104
 
 
105
        /* Non-standard (RFC 2076, draft-palme-mailext-headers-08.txt) */
 
106
        "for-approval", "for-handling", "for-comment", "apparently-to", "errors-to", 
 
107
        "delivered-to", "return-receipt-to", "x-admin", "read-receipt-to", 
 
108
        "x-confirm-reading-to", "return-receipt-requested", 
 
109
        "registered-mail-reply-requested-by", "mail-followup-to", "mail-reply-to",
 
110
        "abuse-reports-to", "x-complaints-to", "x-report-abuse-to",
 
111
        
 
112
        /* Undocumented */
 
113
        "x-beenthere",
 
114
        
 
115
        NULL  
 
116
};
 
117
 
 
118
static int _header_is_allowed
 
119
(void *context ATTR_UNUSED, struct sieve_ast_argument *arg)
 
120
{
 
121
        if ( sieve_argument_is_string_literal(arg) ) {
 
122
                const char *header = sieve_ast_strlist_strc(arg);
 
123
 
 
124
                const char * const *hdsp = _allowed_headers;
 
125
                while ( *hdsp != NULL ) {
 
126
                        if ( strcasecmp( *hdsp, header ) == 0 ) 
 
127
                                return TRUE;
 
128
 
 
129
                        hdsp++;
 
130
                }
 
131
                
 
132
                return FALSE;
 
133
        }
 
134
        
 
135
        return TRUE;
 
136
}
 
137
 
 
138
static bool tst_address_validate
 
139
        (struct sieve_validator *valdtr, struct sieve_command_context *tst) 
 
140
{
 
141
        struct sieve_ast_argument *arg = tst->first_positional;
 
142
        struct sieve_ast_argument *header;
 
143
                
 
144
        if ( !sieve_validate_positional_argument
 
145
                (valdtr, tst, arg, "header list", 1, SAAT_STRING_LIST) ) {
 
146
                return FALSE;
 
147
        }
 
148
        
 
149
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
 
150
                return FALSE;
 
151
 
 
152
        if ( !sieve_command_verify_headers_argument(valdtr, arg) )
 
153
        return FALSE;
 
154
 
 
155
        /* Check if supplied header names are allowed
 
156
         *   FIXME: verify dynamic header names at runtime 
 
157
         */
 
158
        header = arg;
 
159
        if ( !sieve_ast_stringlist_map(&header, NULL, _header_is_allowed) ) {           
 
160
                sieve_argument_validate_error(valdtr, header, 
 
161
                        "specified header '%s' is not allowed for the address test", 
 
162
                        str_sanitize(sieve_ast_strlist_strc(header), 64));
 
163
                return FALSE;
 
164
        }
 
165
 
 
166
        /* Check key list */
 
167
        
 
168
        arg = sieve_ast_argument_next(arg);
 
169
        
 
170
        if ( !sieve_validate_positional_argument
 
171
                (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) {
 
172
                return FALSE;
 
173
        }
 
174
 
 
175
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
 
176
                return FALSE;
 
177
        
 
178
        /* Validate the key argument to a specified match type */
 
179
        return sieve_match_type_validate
 
180
                (valdtr, tst, arg, &is_match_type, &i_ascii_casemap_comparator); 
 
181
}
 
182
 
 
183
/* 
 
184
 * Code generation 
 
185
 */
 
186
 
 
187
static bool tst_address_generate
 
188
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx) 
 
189
{
 
190
        sieve_operation_emit_code(cgenv->sbin, &tst_address_operation);
 
191
        
 
192
        /* Generate arguments */        
 
193
        return sieve_generate_arguments(cgenv, ctx, NULL);
 
194
}
 
195
 
 
196
/* 
 
197
 * Code dump 
 
198
 */
 
199
 
 
200
static bool tst_address_operation_dump
 
201
(const struct sieve_operation *op ATTR_UNUSED,  
 
202
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
203
{
 
204
        sieve_code_dumpf(denv, "ADDRESS");
 
205
        sieve_code_descend(denv);
 
206
        
 
207
        /* Handle any optional arguments */
 
208
        if ( !sieve_addrmatch_default_dump_optionals(denv, address) )
 
209
                return FALSE;
 
210
 
 
211
        return
 
212
                sieve_opr_stringlist_dump(denv, address, "header list") &&
 
213
                sieve_opr_stringlist_dump(denv, address, "key list");
 
214
}
 
215
 
 
216
/* 
 
217
 * Code execution 
 
218
 */
 
219
 
 
220
static int tst_address_operation_execute
 
221
(const struct sieve_operation *op ATTR_UNUSED, 
 
222
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
223
{       
 
224
        bool result = TRUE;
 
225
        const struct sieve_comparator *cmp = &i_ascii_casemap_comparator;
 
226
        const struct sieve_match_type *mtch = &is_match_type;
 
227
        const struct sieve_address_part *addrp = &all_address_part;
 
228
        struct sieve_match_context *mctx;
 
229
        struct sieve_coded_stringlist *hdr_list;
 
230
        struct sieve_coded_stringlist *key_list;
 
231
        string_t *hdr_item;
 
232
        bool matched;
 
233
        int ret;
 
234
        
 
235
        /* Read optional operands */
 
236
        if ( (ret=sieve_addrmatch_default_get_optionals
 
237
                (renv, address, &addrp, &mtch, &cmp)) <= 0 ) 
 
238
                return ret;
 
239
                
 
240
        /* Read header-list */
 
241
        if ( (hdr_list=sieve_opr_stringlist_read(renv, address)) == NULL ) {
 
242
                sieve_runtime_trace_error(renv, "invalid header-list operand");
 
243
                return SIEVE_EXEC_BIN_CORRUPT;
 
244
        }
 
245
 
 
246
        /* Read key-list */
 
247
        if ( (key_list=sieve_opr_stringlist_read(renv, address)) == NULL ) {
 
248
                sieve_runtime_trace_error(renv, "invalid key-list operand");
 
249
                return SIEVE_EXEC_BIN_CORRUPT;
 
250
        }
 
251
 
 
252
        sieve_runtime_trace(renv, "ADDRESS test");
 
253
 
 
254
        /* Initialize match context */
 
255
        mctx = sieve_match_begin(renv->interp, mtch, cmp, NULL, key_list);
 
256
        
 
257
        /* Iterate through all requested headers to match */
 
258
        hdr_item = NULL;
 
259
        matched = FALSE;
 
260
        while ( result && !matched && 
 
261
                (result=sieve_coded_stringlist_next_item(hdr_list, &hdr_item)) 
 
262
                && hdr_item != NULL ) {
 
263
                const char *const *headers;
 
264
                        
 
265
                if ( mail_get_headers_utf8(renv->msgdata->mail, str_c(hdr_item), &headers) >= 0 ) {     
 
266
                        int i;
 
267
 
 
268
                        for ( i = 0; !matched && headers[i] != NULL; i++ ) {
 
269
                                if ( (ret=sieve_address_match(addrp, mctx, headers[i])) < 0 ) {
 
270
                                        result = FALSE;
 
271
                                        break;
 
272
                                }
 
273
                                
 
274
                                matched = ret > 0;                              
 
275
                        } 
 
276
                }
 
277
        }
 
278
        
 
279
        /* Finish match */
 
280
 
 
281
        if ( (ret=sieve_match_end(&mctx)) < 0 )
 
282
                result = FALSE;
 
283
        else
 
284
                matched = ( ret > 0 || matched );
 
285
        
 
286
        /* Set test result for subsequent conditional jump */
 
287
        if ( result ) {
 
288
                sieve_interpreter_set_test_result(renv->interp, matched);
 
289
                return SIEVE_EXEC_OK;
 
290
        }
 
291
 
 
292
        sieve_runtime_trace_error(renv, "invalid string-list item");    
 
293
        return SIEVE_EXEC_BIN_CORRUPT;
 
294
}