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

« back to all changes in this revision

Viewing changes to libsieve/src/lib-sieve/plugins/enotify/tst-notify-method-capability.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 <stdio.h>
 
5
 
 
6
#include "sieve-common.h"
 
7
#include "sieve-commands.h"
 
8
#include "sieve-code.h"
 
9
#include "sieve-comparators.h"
 
10
#include "sieve-match-types.h"
 
11
#include "sieve-validator.h"
 
12
#include "sieve-generator.h"
 
13
#include "sieve-interpreter.h"
 
14
#include "sieve-dump.h"
 
15
#include "sieve-match.h"
 
16
 
 
17
#include "ext-enotify-common.h"
 
18
 
 
19
/* 
 
20
 * String test 
 
21
 *
 
22
 * Syntax:
 
23
 *   notify_method_capability [COMPARATOR] [MATCH-TYPE]
 
24
 *     <notification-uri: string>
 
25
 *     <notification-capability: string>
 
26
 *     <key-list: string-list>
 
27
 */
 
28
 
 
29
static bool tst_notifymc_registered
 
30
        (struct sieve_validator *validator, struct sieve_command_registration *cmd_reg);
 
31
static bool tst_notifymc_validate
 
32
        (struct sieve_validator *validator, struct sieve_command_context *tst);
 
33
static bool tst_notifymc_generate
 
34
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
 
35
 
 
36
const struct sieve_command notify_method_capability_test = { 
 
37
        "notify_method_capability", 
 
38
        SCT_TEST, 
 
39
        3, 0, FALSE, FALSE,
 
40
        tst_notifymc_registered, 
 
41
        NULL,
 
42
        tst_notifymc_validate, 
 
43
        tst_notifymc_generate, 
 
44
        NULL 
 
45
};
 
46
 
 
47
/* 
 
48
 * String operation
 
49
 */
 
50
 
 
51
static bool tst_notifymc_operation_dump
 
52
        (const struct sieve_operation *op, 
 
53
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
54
static int tst_notifymc_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 notify_method_capability_operation = { 
 
59
        "NOTIFY_METHOD_CAPABILITY",
 
60
        &enotify_extension, 
 
61
        EXT_ENOTIFY_OPERATION_NOTIFY_METHOD_CAPABILITY, 
 
62
        tst_notifymc_operation_dump, 
 
63
        tst_notifymc_operation_execute 
 
64
};
 
65
 
 
66
/* 
 
67
 * Optional arguments 
 
68
 */
 
69
 
 
70
enum tst_notifymc_optional {    
 
71
        OPT_END,
 
72
        OPT_COMPARATOR,
 
73
        OPT_MATCH_TYPE
 
74
};
 
75
 
 
76
/* 
 
77
 * Test registration 
 
78
 */
 
79
 
 
80
static bool tst_notifymc_registered
 
81
        (struct sieve_validator *validator, struct sieve_command_registration *cmd_reg) 
 
82
{
 
83
        /* The order of these is not significant */
 
84
        sieve_comparators_link_tag(validator, cmd_reg, OPT_COMPARATOR);
 
85
        sieve_match_types_link_tags(validator, cmd_reg, OPT_MATCH_TYPE);
 
86
 
 
87
        return TRUE;
 
88
}
 
89
 
 
90
/* 
 
91
 * Test validation 
 
92
 */
 
93
 
 
94
static bool tst_notifymc_validate
 
95
        (struct sieve_validator *validator, struct sieve_command_context *tst) 
 
96
{               
 
97
        struct sieve_ast_argument *arg = tst->first_positional;
 
98
        
 
99
        if ( !sieve_validate_positional_argument
 
100
                (validator, tst, arg, "notification-uri", 1, SAAT_STRING) ) {
 
101
                return FALSE;
 
102
        }
 
103
        
 
104
        if ( !sieve_validator_argument_activate(validator, tst, arg, FALSE) )
 
105
                return FALSE;
 
106
        
 
107
        arg = sieve_ast_argument_next(arg);
 
108
 
 
109
        if ( !sieve_validate_positional_argument
 
110
                (validator, tst, arg, "notification-capability", 2, SAAT_STRING) ) {
 
111
                return FALSE;
 
112
        }
 
113
        
 
114
        if ( !sieve_validator_argument_activate(validator, tst, arg, FALSE) )
 
115
                return FALSE;
 
116
                
 
117
        arg = sieve_ast_argument_next(arg);
 
118
 
 
119
        if ( !sieve_validate_positional_argument
 
120
                (validator, tst, arg, "key-list", 3, SAAT_STRING_LIST) ) {
 
121
                return FALSE;
 
122
        }
 
123
        
 
124
        if ( !sieve_validator_argument_activate(validator, tst, arg, FALSE) )
 
125
                return FALSE;
 
126
 
 
127
        /* Validate the key argument to a specified match type */
 
128
        return sieve_match_type_validate
 
129
                (validator, tst, arg, &is_match_type, &i_ascii_casemap_comparator);
 
130
}
 
131
 
 
132
/* 
 
133
 * Test generation 
 
134
 */
 
135
 
 
136
static bool tst_notifymc_generate
 
137
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx) 
 
138
{
 
139
        sieve_operation_emit_code(cgenv->sbin, &notify_method_capability_operation);
 
140
 
 
141
        /* Generate arguments */
 
142
        return sieve_generate_arguments(cgenv, ctx, NULL);
 
143
}
 
144
 
 
145
/* 
 
146
 * Code dump 
 
147
 */
 
148
 
 
149
static bool tst_notifymc_operation_dump
 
150
(const struct sieve_operation *op ATTR_UNUSED,
 
151
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
152
{
 
153
        int opt_code = 0;
 
154
 
 
155
        sieve_code_dumpf(denv, "NOTIFY_METHOD_CAPABILITY");
 
156
        sieve_code_descend(denv);
 
157
 
 
158
        /* Handle any optional arguments */
 
159
        if ( !sieve_match_dump_optional_operands(denv, address, &opt_code) )
 
160
                return FALSE;
 
161
 
 
162
        if ( opt_code != SIEVE_MATCH_OPT_END )
 
163
                return FALSE;
 
164
                
 
165
        return
 
166
                sieve_opr_string_dump(denv, address, "notify uri") &&
 
167
                sieve_opr_string_dump(denv, address, "notify capability") &&
 
168
                sieve_opr_stringlist_dump(denv, address, "key list");
 
169
}
 
170
 
 
171
/* 
 
172
 * Code execution 
 
173
 */
 
174
 
 
175
static int tst_notifymc_operation_execute
 
176
(const struct sieve_operation *op ATTR_UNUSED, 
 
177
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
178
{
 
179
        int ret, mret;
 
180
        bool result = TRUE;
 
181
        int opt_code = 0;
 
182
        const struct sieve_comparator *cmp = &i_octet_comparator;
 
183
        const struct sieve_match_type *mtch = &is_match_type;
 
184
        struct sieve_match_context *mctx;
 
185
        string_t *notify_uri, *notify_capability;
 
186
        struct sieve_coded_stringlist *key_list;
 
187
        const char *cap_value;
 
188
        bool matched;
 
189
 
 
190
        /*
 
191
         * Read operands 
 
192
         */
 
193
        
 
194
        /* Handle match-type and comparator operands */
 
195
        if ( (ret=sieve_match_read_optional_operands
 
196
                (renv, address, &opt_code, &cmp, &mtch)) <= 0 )
 
197
                return ret;
 
198
        
 
199
        /* Check whether we neatly finished the list of optional operands */
 
200
        if ( opt_code != SIEVE_MATCH_OPT_END) {
 
201
                sieve_runtime_trace_error(renv, "invalid optional operand");
 
202
                return SIEVE_EXEC_BIN_CORRUPT;
 
203
        }
 
204
 
 
205
        /* Read notify uri */
 
206
        if ( !sieve_opr_string_read(renv, address, &notify_uri) ) {
 
207
                sieve_runtime_trace_error(renv, "invalid notify-uri operand");
 
208
                return SIEVE_EXEC_BIN_CORRUPT;
 
209
        }
 
210
        
 
211
        /* Read notify capability */
 
212
        if ( !sieve_opr_string_read(renv, address, &notify_capability) ) {
 
213
                sieve_runtime_trace_error(renv, "invalid notify-uri operand");
 
214
                return SIEVE_EXEC_BIN_CORRUPT;
 
215
        }
 
216
        
 
217
        /* Read key-list */
 
218
        if ( (key_list=sieve_opr_stringlist_read(renv, address)) == NULL ) {
 
219
                sieve_runtime_trace_error(renv, "invalid key-list operand");
 
220
                return SIEVE_EXEC_BIN_CORRUPT;
 
221
        }
 
222
 
 
223
        /*
 
224
         * Perform operation
 
225
         */
 
226
 
 
227
        sieve_runtime_trace(renv, "NOTIFY_METHOD_CAPABILITY test");
 
228
 
 
229
        cap_value = ext_enotify_runtime_get_method_capability
 
230
                (renv, 0 /* FIXME */, notify_uri, str_c(notify_capability));
 
231
 
 
232
        if ( cap_value != NULL ) {
 
233
                mctx = sieve_match_begin(renv->interp, mtch, cmp, NULL, key_list);      
 
234
 
 
235
                if ( (mret=sieve_match_value(mctx, cap_value, strlen(cap_value))) < 0 )
 
236
                        result = FALSE;
 
237
                matched = ( mret > 0 );         
 
238
 
 
239
                if ( (mret=sieve_match_end(&mctx)) < 0 ) 
 
240
                        result = FALSE;
 
241
                matched = ( mret > 0 ) || matched;              
 
242
        } else {
 
243
                matched = FALSE;
 
244
        }
 
245
        
 
246
        if ( result ) {
 
247
                sieve_interpreter_set_test_result(renv->interp, matched);
 
248
                return SIEVE_EXEC_OK;
 
249
        }
 
250
        
 
251
        sieve_runtime_trace_error(renv, "invalid string list item");
 
252
        return SIEVE_EXEC_BIN_CORRUPT;
 
253
}