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

« back to all changes in this revision

Viewing changes to libsieve/src/testsuite/tst-test-result.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
/* FIXME: this file is very similar to tst-test-error.c. Maybe it is best to 
 
5
 * implement errors and actions as testsuite-objects and implement a common
 
6
 * interface to test these.
 
7
 */
 
8
 
 
9
#include "sieve-common.h"
 
10
#include "sieve-error.h"
 
11
#include "sieve-script.h"
 
12
#include "sieve-commands.h"
 
13
#include "sieve-actions.h"
 
14
#include "sieve-comparators.h"
 
15
#include "sieve-match-types.h"
 
16
#include "sieve-validator.h"
 
17
#include "sieve-generator.h"
 
18
#include "sieve-interpreter.h"
 
19
#include "sieve-code.h"
 
20
#include "sieve-binary.h"
 
21
#include "sieve-result.h"
 
22
#include "sieve-dump.h"
 
23
#include "sieve-match.h"
 
24
 
 
25
#include "testsuite-common.h"
 
26
#include "testsuite-result.h"
 
27
 
 
28
/*
 
29
 * test_result command
 
30
 *
 
31
 * Syntax:   
 
32
 *   test_result [MATCH-TYPE] [COMPARATOR] [:index number] 
 
33
 *     <key-list: string-list>
 
34
 */
 
35
 
 
36
static bool tst_test_result_registered
 
37
    (struct sieve_validator *validator, struct sieve_command_registration *cmd_reg);
 
38
static bool tst_test_result_validate
 
39
        (struct sieve_validator *validator, struct sieve_command_context *cmd);
 
40
static bool tst_test_result_generate
 
41
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
 
42
 
 
43
const struct sieve_command tst_test_result = { 
 
44
        "test_result", 
 
45
        SCT_TEST, 
 
46
        1, 0, FALSE, FALSE,
 
47
        tst_test_result_registered, 
 
48
        NULL,
 
49
        tst_test_result_validate, 
 
50
        tst_test_result_generate, 
 
51
        NULL 
 
52
};
 
53
 
 
54
/* 
 
55
 * Operation 
 
56
 */
 
57
 
 
58
static bool tst_test_result_operation_dump
 
59
        (const struct sieve_operation *op,
 
60
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
61
static int tst_test_result_operation_execute
 
62
        (const struct sieve_operation *op, 
 
63
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
64
 
 
65
const struct sieve_operation test_result_operation = { 
 
66
        "test_result",
 
67
        &testsuite_extension, 
 
68
        TESTSUITE_OPERATION_TEST_RESULT,
 
69
        tst_test_result_operation_dump, 
 
70
        tst_test_result_operation_execute 
 
71
};
 
72
 
 
73
/*
 
74
 * Tagged arguments
 
75
 */ 
 
76
 
 
77
/* NOTE: This will be merged with the date-index extension when it is 
 
78
 * implemented.
 
79
 */
 
80
 
 
81
/* FIXME: at least merge this with the test_error version of this tag */
 
82
 
 
83
static bool tst_test_result_validate_index_tag
 
84
        (struct sieve_validator *validator, struct sieve_ast_argument **arg,
 
85
                struct sieve_command_context *cmd);
 
86
 
 
87
static const struct sieve_argument test_result_index_tag = {
 
88
    "index",
 
89
    NULL, NULL,
 
90
    tst_test_result_validate_index_tag,
 
91
    NULL, NULL
 
92
};
 
93
 
 
94
enum tst_test_result_optional {
 
95
        OPT_INDEX = SIEVE_MATCH_OPT_LAST,
 
96
};
 
97
 
 
98
/*
 
99
 * Argument implementation
 
100
 */
 
101
 
 
102
static bool tst_test_result_validate_index_tag
 
103
(struct sieve_validator *validator, struct sieve_ast_argument **arg,
 
104
        struct sieve_command_context *cmd)
 
105
{
 
106
        struct sieve_ast_argument *tag = *arg;
 
107
 
 
108
        /* Detach the tag itself */
 
109
        *arg = sieve_ast_arguments_detach(*arg,1);
 
110
 
 
111
        /* Check syntax:
 
112
         *   :index number
 
113
         */
 
114
        if ( !sieve_validate_tag_parameter
 
115
                (validator, cmd, tag, *arg, SAAT_NUMBER) ) {
 
116
                return FALSE;
 
117
        }
 
118
 
 
119
        /* Skip parameter */
 
120
        *arg = sieve_ast_argument_next(*arg);
 
121
        return TRUE;
 
122
}
 
123
 
 
124
 
 
125
/*
 
126
 * Command registration
 
127
 */
 
128
 
 
129
static bool tst_test_result_registered
 
130
(struct sieve_validator *validator, struct sieve_command_registration *cmd_reg)
 
131
{
 
132
        /* The order of these is not significant */
 
133
        sieve_comparators_link_tag(validator, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR);
 
134
        sieve_match_types_link_tags(validator, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE);
 
135
 
 
136
        sieve_validator_register_tag
 
137
                (validator, cmd_reg, &test_result_index_tag, OPT_INDEX);
 
138
 
 
139
        return TRUE;
 
140
}
 
141
 
 
142
/* 
 
143
 * Validation 
 
144
 */
 
145
 
 
146
static bool tst_test_result_validate
 
147
(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command_context *tst) 
 
148
{
 
149
        struct sieve_ast_argument *arg = tst->first_positional;
 
150
        
 
151
        if ( !sieve_validate_positional_argument
 
152
                (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) {
 
153
                return FALSE;
 
154
        }
 
155
 
 
156
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
 
157
                return FALSE;
 
158
 
 
159
        /* Validate the key argument to a specified match type */
 
160
        return sieve_match_type_validate
 
161
                (valdtr, tst, arg, &is_match_type, &i_octet_comparator);
 
162
}
 
163
 
 
164
/* 
 
165
 * Code generation 
 
166
 */
 
167
 
 
168
static inline struct testsuite_generator_context *
 
169
_get_generator_context(struct sieve_generator *gentr)
 
170
{
 
171
        return (struct testsuite_generator_context *) 
 
172
                sieve_generator_extension_get_context(gentr, &testsuite_extension);
 
173
}
 
174
 
 
175
static bool tst_test_result_generate
 
176
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *tst)
 
177
{
 
178
        sieve_operation_emit_code(cgenv->sbin, &test_result_operation);
 
179
 
 
180
        /* Generate arguments */
 
181
        return sieve_generate_arguments(cgenv, tst, NULL);
 
182
}
 
183
 
 
184
/* 
 
185
 * Code dump
 
186
 */
 
187
 
 
188
static bool tst_test_result_operation_dump
 
189
(const struct sieve_operation *op ATTR_UNUSED,
 
190
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
191
{
 
192
        int opt_code = 0;
 
193
 
 
194
        sieve_code_dumpf(denv, "TEST_RESULT:");
 
195
        sieve_code_descend(denv);
 
196
 
 
197
        /* Handle any optional arguments */
 
198
        do {
 
199
                if ( !sieve_match_dump_optional_operands(denv, address, &opt_code) )
 
200
                        return FALSE;
 
201
 
 
202
                switch ( opt_code ) {
 
203
                case SIEVE_MATCH_OPT_END:
 
204
                        break;
 
205
                case OPT_INDEX:
 
206
                        if ( !sieve_opr_number_dump(denv, address, "index") )
 
207
                                return FALSE;
 
208
                        break;
 
209
                default:
 
210
                        return FALSE;
 
211
                }
 
212
        } while ( opt_code != SIEVE_MATCH_OPT_END );
 
213
 
 
214
        return sieve_opr_stringlist_dump(denv, address, "key list");
 
215
}
 
216
 
 
217
/*
 
218
 * Intepretation
 
219
 */
 
220
 
 
221
static int tst_test_result_operation_execute
 
222
(const struct sieve_operation *op ATTR_UNUSED,
 
223
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
224
{       
 
225
        int opt_code = 0;
 
226
        bool result = TRUE;
 
227
        const struct sieve_comparator *cmp = &i_octet_comparator;
 
228
        const struct sieve_match_type *mtch = &is_match_type;
 
229
        struct sieve_match_context *mctx;
 
230
        struct sieve_coded_stringlist *key_list;
 
231
        bool matched;
 
232
        struct sieve_result_iterate_context *rictx;
 
233
        const struct sieve_action *action;
 
234
        bool keep;
 
235
        int cur_index = 0, index = 0;
 
236
        int ret;
 
237
 
 
238
        /*
 
239
         * Read operands
 
240
         */
 
241
 
 
242
        /* Handle optional operands */
 
243
        do {
 
244
                sieve_number_t number; 
 
245
 
 
246
                if ( (ret=sieve_match_read_optional_operands
 
247
                        (renv, address, &opt_code, &cmp, &mtch)) <= 0 )
 
248
                        return ret;
 
249
 
 
250
                switch ( opt_code ) {
 
251
                case SIEVE_MATCH_OPT_END:
 
252
                        break;
 
253
                case OPT_INDEX:
 
254
                        if ( !sieve_opr_number_read(renv, address, &number) ) {
 
255
                                sieve_runtime_trace_error(renv, "invalid index operand");
 
256
                                return SIEVE_EXEC_BIN_CORRUPT;
 
257
                        }
 
258
                        index = (int) number;
 
259
                        break;
 
260
                default:
 
261
                        sieve_runtime_trace_error(renv, "invalid optional operand");
 
262
                        return SIEVE_EXEC_BIN_CORRUPT;
 
263
                }       
 
264
        } while ( opt_code != SIEVE_MATCH_OPT_END);
 
265
 
 
266
        /* Read key-list */
 
267
        if ( (key_list=sieve_opr_stringlist_read(renv, address)) == NULL ) {
 
268
                sieve_runtime_trace_error(renv, "invalid key-list operand");
 
269
                return SIEVE_EXEC_BIN_CORRUPT;
 
270
        }
 
271
 
 
272
        /*
 
273
         * Perform operation
 
274
         */
 
275
        
 
276
        sieve_runtime_trace(renv, "TEST_RESULT test (index: %d)", index);
 
277
 
 
278
        rictx = testsuite_result_iterate_init();
 
279
 
 
280
  /* Initialize match */
 
281
  mctx = sieve_match_begin(renv->interp, mtch, cmp, NULL, key_list);
 
282
 
 
283
  /* Iterate through all errors to match */
 
284
        matched = FALSE;
 
285
        cur_index = 1;
 
286
        ret = 0;
 
287
        while ( result && !matched &&
 
288
                (action=sieve_result_iterate_next(rictx, &keep, NULL)) != NULL ) {
 
289
                const char *act_name;
 
290
                
 
291
                if ( keep ) 
 
292
                        act_name = "keep";
 
293
                else
 
294
                        act_name = ( action == NULL || action->name == NULL ) ? "" : action->name;
 
295
 
 
296
                if ( index == 0 || index == cur_index ) {
 
297
                        if ( (ret=sieve_match_value(mctx, act_name, strlen(act_name))) < 0 ) {
 
298
                                result = FALSE;
 
299
                                break;
 
300
                        }
 
301
                }
 
302
 
 
303
                matched = ret > 0;
 
304
                cur_index++;
 
305
        }
 
306
 
 
307
        /* Finish match */
 
308
        if ( (ret=sieve_match_end(&mctx)) < 0 )
 
309
                result = FALSE;
 
310
        else
 
311
                matched = ( ret > 0 || matched );
 
312
 
 
313
        /* Set test result for subsequent conditional jump */
 
314
        if ( result ) {
 
315
                sieve_interpreter_set_test_result(renv->interp, matched);
 
316
                return SIEVE_EXEC_OK;
 
317
        }
 
318
 
 
319
        sieve_runtime_trace_error(renv, "invalid string-list item");
 
320
        return SIEVE_EXEC_BIN_CORRUPT;
 
321
}
 
322
 
 
323
 
 
324
 
 
325