~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101901

« back to all changes in this revision

Viewing changes to libsieve/src/lib-sieve/sieve-match.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 "mempool.h"
 
6
#include "hash.h"
 
7
#include "array.h"
 
8
 
 
9
#include "sieve-extensions.h"
 
10
#include "sieve-commands.h"
 
11
#include "sieve-code.h"
 
12
#include "sieve-binary.h"
 
13
#include "sieve-validator.h"
 
14
#include "sieve-generator.h"
 
15
#include "sieve-interpreter.h"
 
16
#include "sieve-dump.h"
 
17
#include "sieve-comparators.h"
 
18
#include "sieve-match-types.h"
 
19
 
 
20
#include "sieve-match.h"
 
21
 
 
22
/*
 
23
 * Matching implementation
 
24
 */
 
25
 
 
26
struct sieve_match_context *sieve_match_begin
 
27
(struct sieve_interpreter *interp, const struct sieve_match_type *mtch, 
 
28
        const struct sieve_comparator *cmp, 
 
29
        const struct sieve_match_key_extractor *kextract,
 
30
        struct sieve_coded_stringlist *key_list)
 
31
{
 
32
        struct sieve_match_context *mctx;
 
33
        pool_t pool;
 
34
 
 
35
        pool = pool_alloconly_create("sieve_match_context", 1024);
 
36
        mctx = p_new(pool, struct sieve_match_context, 1);  
 
37
 
 
38
        mctx->pool = pool;
 
39
        mctx->interp = interp;
 
40
        mctx->match_type = mtch;
 
41
        mctx->comparator = cmp;
 
42
        mctx->kextract = kextract;
 
43
        mctx->key_list = key_list;
 
44
 
 
45
        if ( mtch->match_init != NULL ) {
 
46
                mtch->match_init(mctx);
 
47
        }
 
48
 
 
49
        return mctx;
 
50
}
 
51
 
 
52
int sieve_match_value
 
53
        (struct sieve_match_context *mctx, const char *value, size_t val_size)
 
54
{
 
55
        const struct sieve_match_type *mtch = mctx->match_type;
 
56
        sieve_coded_stringlist_reset(mctx->key_list);
 
57
        bool ok = TRUE;
 
58
 
 
59
        /* Reject unimplemented match-type */
 
60
        if ( mtch->match == NULL )
 
61
                return FALSE;
 
62
                                
 
63
        /* Match to all key values */
 
64
        if ( mtch->is_iterative ) {
 
65
                unsigned int key_index = 0;
 
66
                string_t *key_item = NULL;
 
67
                int ret = 0;
 
68
        
 
69
                while ( (ok=sieve_coded_stringlist_next_item(mctx->key_list, &key_item)) 
 
70
                        && key_item != NULL ) 
 
71
                {                               
 
72
                        T_BEGIN {
 
73
                                if ( mctx->kextract != NULL && mtch->allow_key_extract ) {
 
74
                                        const struct sieve_match_key_extractor *kext = mctx->kextract;
 
75
                                        void *kctx;
 
76
                                
 
77
                                        if ( (ret=kext->init(&kctx, key_item)) > 0 ) {
 
78
                                                const char *key;
 
79
                                                size_t key_size;
 
80
                                                                
 
81
                                                while ( (ret=kext->extract_key(kctx, &key, &key_size)) > 0 ) {                          
 
82
                                                        ret = mtch->match
 
83
                                                                (mctx, value, val_size, key, key_size, key_index);
 
84
                                                
 
85
                                                        if ( ret != 0 ) break;
 
86
                                                }
 
87
                                        }  
 
88
                                } else {
 
89
                                        ret = mtch->match(mctx, value, val_size, str_c(key_item), 
 
90
                                                        str_len(key_item), key_index);
 
91
                                }
 
92
                        } T_END;
 
93
                        
 
94
                        if ( ret != 0 )
 
95
                                break;
 
96
        
 
97
                        key_index++;
 
98
                }
 
99
 
 
100
                if ( !ok ) 
 
101
                        return -1;
 
102
 
 
103
                if ( ret < 0 ) 
 
104
                        return ret;
 
105
                if ( ret > 0 )
 
106
                        return TRUE;
 
107
 
 
108
        } else {
 
109
                bool result;
 
110
 
 
111
                T_BEGIN {
 
112
                        result = mtch->match(mctx, value, val_size, NULL, 0, -1);
 
113
                } T_END;
 
114
 
 
115
                return result;
 
116
        }
 
117
 
 
118
        return FALSE;
 
119
}
 
120
 
 
121
int sieve_match_end(struct sieve_match_context **mctx)
 
122
{
 
123
        const struct sieve_match_type *mtch = (*mctx)->match_type;
 
124
        int ret = FALSE;
 
125
 
 
126
        if ( mtch->match_deinit != NULL ) {
 
127
                ret = mtch->match_deinit(*mctx);
 
128
        }
 
129
 
 
130
    pool_unref(&(*mctx)->pool);
 
131
    *mctx = NULL;
 
132
 
 
133
        return ret;
 
134
}
 
135
 
 
136
/*
 
137
 * Reading match operands
 
138
 */
 
139
 
 
140
bool sieve_match_dump_optional_operands
 
141
(const struct sieve_dumptime_env *denv, sieve_size_t *address, int *opt_code)
 
142
{
 
143
        if ( *opt_code != SIEVE_MATCH_OPT_END || 
 
144
                sieve_operand_optional_present(denv->sbin, address) ) {
 
145
                do {
 
146
                        if ( !sieve_operand_optional_read(denv->sbin, address, opt_code) ) 
 
147
                                return FALSE;
 
148
 
 
149
                        switch ( *opt_code ) {
 
150
                        case SIEVE_MATCH_OPT_END:
 
151
                                break;
 
152
                        case SIEVE_MATCH_OPT_COMPARATOR:
 
153
                                if ( !sieve_opr_comparator_dump(denv, address) )
 
154
                                        return FALSE;
 
155
                                break;
 
156
                        case SIEVE_MATCH_OPT_MATCH_TYPE:
 
157
                                if ( !sieve_opr_match_type_dump(denv, address) )
 
158
                                        return FALSE;
 
159
                                break;
 
160
                        default: 
 
161
                                return TRUE;
 
162
                        }
 
163
                } while ( *opt_code != SIEVE_MATCH_OPT_END );
 
164
        }
 
165
        
 
166
        return TRUE;
 
167
}
 
168
 
 
169
int sieve_match_read_optional_operands
 
170
(const struct sieve_runtime_env *renv, sieve_size_t *address, int *opt_code,
 
171
        const struct sieve_comparator **cmp_r, const struct sieve_match_type **mtch_r)
 
172
{        
 
173
        /* Handle any optional arguments */
 
174
        if ( *opt_code != SIEVE_MATCH_OPT_END || 
 
175
                sieve_operand_optional_present(renv->sbin, address) ) {
 
176
                do {
 
177
                        if ( !sieve_operand_optional_read(renv->sbin, address, opt_code) ) {
 
178
                                sieve_runtime_trace_error(renv, "invalid optional operand");
 
179
                                return SIEVE_EXEC_BIN_CORRUPT;
 
180
                        }
 
181
 
 
182
                        switch ( *opt_code ) {
 
183
                        case SIEVE_MATCH_OPT_END: 
 
184
                                break;
 
185
                        case SIEVE_MATCH_OPT_COMPARATOR:
 
186
                                if ( (*cmp_r = sieve_opr_comparator_read(renv, address)) == NULL ) {
 
187
                                        sieve_runtime_trace_error(renv, "invalid comparator operand");
 
188
                                        return SIEVE_EXEC_BIN_CORRUPT;
 
189
                                }
 
190
                                break;
 
191
                        case SIEVE_MATCH_OPT_MATCH_TYPE:
 
192
                                if ( (*mtch_r = sieve_opr_match_type_read(renv, address)) == NULL ) {
 
193
                                        sieve_runtime_trace_error(renv, "invalid match type operand");
 
194
                                        return SIEVE_EXEC_BIN_CORRUPT;
 
195
                                }
 
196
                                break;
 
197
                        default:
 
198
                                return SIEVE_EXEC_OK;
 
199
                        }
 
200
                } while ( *opt_code != SIEVE_MATCH_OPT_END );
 
201
        }
 
202
        
 
203
        return SIEVE_EXEC_OK;
 
204
}
 
205