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

« back to all changes in this revision

Viewing changes to libsieve/src/testsuite/cmd-test-message.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 "sieve-common.h"
 
5
#include "sieve-commands.h"
 
6
#include "sieve-validator.h"
 
7
#include "sieve-generator.h"
 
8
#include "sieve-interpreter.h"
 
9
#include "sieve-code.h"
 
10
#include "sieve-binary.h"
 
11
#include "sieve-dump.h"
 
12
 
 
13
#include "testsuite-common.h"
 
14
#include "testsuite-smtp.h"
 
15
#include "testsuite-mailstore.h"
 
16
 
 
17
/*
 
18
 * Test_message command
 
19
 *
 
20
 * Syntax:   
 
21
 *   test_message ( :smtp / :mailbox <mailbox: string> ) <index: number>
 
22
 */
 
23
 
 
24
static bool cmd_test_message_registered
 
25
        (struct sieve_validator *valdtr, 
 
26
                struct sieve_command_registration *cmd_reg);
 
27
static bool cmd_test_message_validate
 
28
        (struct sieve_validator *valdtr, struct sieve_command_context *cmd);
 
29
static bool cmd_test_message_generate
 
30
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
 
31
 
 
32
const struct sieve_command cmd_test_message = { 
 
33
        "test_message", 
 
34
        SCT_HYBRID, 
 
35
        1, 0, FALSE, FALSE,
 
36
        cmd_test_message_registered, 
 
37
        NULL,
 
38
        cmd_test_message_validate, 
 
39
        cmd_test_message_generate, 
 
40
        NULL 
 
41
};
 
42
 
 
43
/* 
 
44
 * Operations
 
45
 */ 
 
46
 
 
47
/* Test_message_smtp operation */
 
48
 
 
49
static bool cmd_test_message_smtp_operation_dump
 
50
        (const struct sieve_operation *op,
 
51
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
52
static int cmd_test_message_smtp_operation_execute
 
53
        (const struct sieve_operation *op, 
 
54
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
55
 
 
56
const struct sieve_operation test_message_smtp_operation = { 
 
57
        "TEST_MESSAGE_SMTP",
 
58
        &testsuite_extension, 
 
59
        TESTSUITE_OPERATION_TEST_MESSAGE_SMTP,
 
60
        cmd_test_message_smtp_operation_dump, 
 
61
        cmd_test_message_smtp_operation_execute 
 
62
};
 
63
 
 
64
/* Test_message_mailbox operation */
 
65
 
 
66
static bool cmd_test_message_mailbox_operation_dump
 
67
        (const struct sieve_operation *op,
 
68
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
69
static int cmd_test_message_mailbox_operation_execute
 
70
        (const struct sieve_operation *op, 
 
71
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
72
 
 
73
const struct sieve_operation test_message_mailbox_operation = { 
 
74
        "TEST_MESSAGE_MAILBOX",
 
75
        &testsuite_extension, 
 
76
        TESTSUITE_OPERATION_TEST_MESSAGE_MAILBOX,
 
77
        cmd_test_message_mailbox_operation_dump, 
 
78
        cmd_test_message_mailbox_operation_execute 
 
79
};
 
80
 
 
81
/*
 
82
 * Compiler context data
 
83
 */
 
84
 
 
85
enum test_message_source {
 
86
        MSG_SOURCE_SMTP, 
 
87
        MSG_SOURCE_MAILBOX,
 
88
        MSG_SOURCE_LAST
 
89
};
 
90
 
 
91
const struct sieve_operation *test_message_operations[] = {
 
92
        &test_message_smtp_operation,
 
93
        &test_message_mailbox_operation
 
94
};
 
95
 
 
96
struct cmd_test_message_context_data {
 
97
        enum test_message_source msg_source;
 
98
        const char *folder;
 
99
};
 
100
 
 
101
#define CMD_TEST_MESSAGE_ERROR_DUP_TAG \
 
102
        "exactly one of the ':smtp' or ':folder' tags must be specified " \
 
103
        "for the test_message command, but more were found"
 
104
 
 
105
/* 
 
106
 * Command tags 
 
107
 */
 
108
 
 
109
static bool cmd_test_message_validate_smtp_tag
 
110
        (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
 
111
                struct sieve_command_context *cmd);
 
112
static bool cmd_test_message_validate_folder_tag
 
113
        (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
 
114
                struct sieve_command_context *cmd);
 
115
 
 
116
static const struct sieve_argument test_message_smtp_tag = { 
 
117
        "smtp", 
 
118
        NULL, NULL,
 
119
        cmd_test_message_validate_smtp_tag,
 
120
        NULL, NULL 
 
121
};
 
122
 
 
123
static const struct sieve_argument test_message_folder_tag = { 
 
124
        "folder", 
 
125
        NULL, NULL, 
 
126
        cmd_test_message_validate_folder_tag,
 
127
        NULL, NULL 
 
128
};
 
129
 
 
130
static bool cmd_test_message_registered
 
131
(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg) 
 
132
{
 
133
        /* Register our tags */
 
134
        sieve_validator_register_tag(valdtr, cmd_reg, &test_message_folder_tag, 0);     
 
135
        sieve_validator_register_tag(valdtr, cmd_reg, &test_message_smtp_tag, 0);       
 
136
 
 
137
        return TRUE;
 
138
}
 
139
 
 
140
static struct cmd_test_message_context_data *cmd_test_message_validate_tag
 
141
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
 
142
        struct sieve_command_context *cmd)
 
143
{
 
144
        struct cmd_test_message_context_data *ctx_data = 
 
145
                (struct cmd_test_message_context_data *) cmd->data;     
 
146
        
 
147
        if ( ctx_data != NULL ) {
 
148
                sieve_argument_validate_error
 
149
                        (valdtr, *arg, CMD_TEST_MESSAGE_ERROR_DUP_TAG);
 
150
                return NULL;            
 
151
        }
 
152
        
 
153
        ctx_data = p_new
 
154
                (sieve_command_pool(cmd), struct cmd_test_message_context_data, 1);
 
155
        cmd->data = ctx_data;
 
156
        
 
157
        /* Delete this tag */
 
158
        *arg = sieve_ast_arguments_detach(*arg, 1);
 
159
 
 
160
        return ctx_data;
 
161
}
 
162
 
 
163
static bool cmd_test_message_validate_smtp_tag
 
164
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
 
165
        struct sieve_command_context *cmd)
 
166
{
 
167
        struct cmd_test_message_context_data *ctx_data = 
 
168
                cmd_test_message_validate_tag(valdtr, arg, cmd);
 
169
 
 
170
        /* Return value is NULL on error */
 
171
        if ( ctx_data == NULL ) return FALSE;
 
172
        
 
173
        /* Assign chosen message source */
 
174
        ctx_data->msg_source = MSG_SOURCE_SMTP;
 
175
                        
 
176
        return TRUE;
 
177
}
 
178
 
 
179
static bool cmd_test_message_validate_folder_tag
 
180
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
 
181
        struct sieve_command_context *cmd)
 
182
{
 
183
        struct sieve_ast_argument *tag = *arg;
 
184
        struct cmd_test_message_context_data *ctx_data = 
 
185
                cmd_test_message_validate_tag(valdtr, arg, cmd);
 
186
        
 
187
        /* Return value is NULL on error */
 
188
        if ( ctx_data == NULL ) return FALSE;
 
189
 
 
190
        /* Assign chose message source */
 
191
        ctx_data->msg_source = MSG_SOURCE_MAILBOX;
 
192
        
 
193
        /* Check syntax:
 
194
         *   :folder string
 
195
         */
 
196
        if ( !sieve_validate_tag_parameter
 
197
                (valdtr, cmd, tag, *arg, SAAT_STRING) ) {
 
198
                return FALSE;
 
199
        }
 
200
 
 
201
        /* Skip parameter */
 
202
        *arg = sieve_ast_argument_next(*arg);
 
203
                        
 
204
        return TRUE;
 
205
}
 
206
 
 
207
/* 
 
208
 * Validation 
 
209
 */
 
210
 
 
211
static bool cmd_test_message_validate
 
212
(struct sieve_validator *valdtr, struct sieve_command_context *cmd) 
 
213
{
 
214
        struct sieve_ast_argument *arg = cmd->first_positional;
 
215
        
 
216
        if ( cmd->data == NULL ) {
 
217
                sieve_command_validate_error(valdtr, cmd, 
 
218
                        "the test_message command requires either the :smtp or the :mailbox tag "
 
219
                        "to be specified");
 
220
                return FALSE;           
 
221
        }
 
222
                
 
223
        if ( !sieve_validate_positional_argument
 
224
                (valdtr, cmd, arg, "index", 1, SAAT_NUMBER) ) {
 
225
                return FALSE;
 
226
        }
 
227
        
 
228
        return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE);
 
229
}
 
230
 
 
231
/* 
 
232
 * Code generation 
 
233
 */
 
234
 
 
235
static bool cmd_test_message_generate
 
236
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *cmd)
 
237
{
 
238
        struct cmd_test_message_context_data *ctx_data =
 
239
                (struct cmd_test_message_context_data *) cmd->data; 
 
240
 
 
241
        i_assert( ctx_data->msg_source < MSG_SOURCE_LAST );
 
242
        
 
243
        /* Emit operation */
 
244
        sieve_operation_emit_code(cgenv->sbin, 
 
245
                test_message_operations[ctx_data->msg_source]);
 
246
 
 
247
        /* Emit is_test flag */
 
248
        sieve_binary_emit_byte(cgenv->sbin, ( cmd->ast_node->type == SAT_TEST ));
 
249
                
 
250
        /* Generate arguments */
 
251
        if ( !sieve_generate_arguments(cgenv, cmd, NULL) )
 
252
                return FALSE;
 
253
 
 
254
        return TRUE;
 
255
}
 
256
 
 
257
/* 
 
258
 * Code dump
 
259
 */
 
260
 
 
261
static bool cmd_test_message_smtp_operation_dump
 
262
(const struct sieve_operation *op ATTR_UNUSED,
 
263
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
264
{
 
265
        unsigned int is_test;
 
266
 
 
267
    if ( !sieve_binary_read_byte(denv->sbin, address, &is_test) )
 
268
                return FALSE;
 
269
 
 
270
        sieve_code_dumpf(denv, "TEST_MESSAGE_SMTP (%s):", 
 
271
                ( is_test ? "TEST" : "COMMAND" ));
 
272
        
 
273
        sieve_code_descend(denv);
 
274
        
 
275
        return sieve_opr_number_dump(denv, address, "index");
 
276
}
 
277
 
 
278
static bool cmd_test_message_mailbox_operation_dump
 
279
(const struct sieve_operation *op ATTR_UNUSED,
 
280
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
281
{
 
282
        unsigned int is_test;
 
283
 
 
284
    if ( !sieve_binary_read_byte(denv->sbin, address, &is_test) )
 
285
                return FALSE;
 
286
 
 
287
        sieve_code_dumpf(denv, "TEST_MESSAGE_MAILBOX (%s):",
 
288
                ( is_test ? "TEST" : "COMMAND" ));
 
289
        
 
290
        sieve_code_descend(denv);
 
291
 
 
292
        return 
 
293
                sieve_opr_string_dump(denv, address, "folder") &&
 
294
                sieve_opr_number_dump(denv, address, "index");
 
295
}
 
296
 
 
297
/*
 
298
 * Intepretation
 
299
 */
 
300
 
 
301
static int cmd_test_message_smtp_operation_execute
 
302
(const struct sieve_operation *op ATTR_UNUSED,
 
303
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
304
{
 
305
        sieve_number_t msg_index;
 
306
    unsigned int is_test = -1;
 
307
        bool result;
 
308
 
 
309
        /* 
 
310
         * Read operands 
 
311
         */
 
312
 
 
313
        /* Is test */
 
314
 
 
315
    if ( !sieve_binary_read_byte(renv->sbin, address, &is_test) ) {
 
316
                sieve_runtime_trace_error(renv, "invalid is_test flag");
 
317
                return SIEVE_EXEC_BIN_CORRUPT;
 
318
        }
 
319
 
 
320
        /* Index */
 
321
 
 
322
        if ( !sieve_opr_number_read(renv, address, &msg_index) ) {
 
323
                sieve_runtime_trace_error(renv, "invalid index operand");
 
324
                return SIEVE_EXEC_BIN_CORRUPT;
 
325
        }
 
326
 
 
327
        /*
 
328
         * Perform operation
 
329
         */
 
330
                
 
331
        sieve_runtime_trace(renv, "TEST_MESSAGE_SMTP (%s) [%d]", 
 
332
                ( is_test ? "TEST" : "COMMAND" ), msg_index);
 
333
 
 
334
        result = testsuite_smtp_get(renv, msg_index);
 
335
 
 
336
        if ( is_test ) {
 
337
                sieve_interpreter_set_test_result(renv->interp, result);
 
338
                return SIEVE_EXEC_OK;
 
339
        }
 
340
 
 
341
        if ( !result )
 
342
                testsuite_test_failf("no outgoing SMTP message with index %d", msg_index);
 
343
 
 
344
        return SIEVE_EXEC_OK;
 
345
}
 
346
 
 
347
static int cmd_test_message_mailbox_operation_execute
 
348
(const struct sieve_operation *op ATTR_UNUSED,
 
349
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
350
{
 
351
        string_t *folder;
 
352
        sieve_number_t msg_index;
 
353
        unsigned int is_test = -1;
 
354
        bool result;
 
355
 
 
356
        /*
 
357
         * Read operands
 
358
         */
 
359
 
 
360
        /* Is test */
 
361
    if ( !sieve_binary_read_byte(renv->sbin, address, &is_test) ) {
 
362
                sieve_runtime_trace_error(renv, "invalid is_test flag");
 
363
                return SIEVE_EXEC_BIN_CORRUPT;
 
364
        }
 
365
 
 
366
        /* Folder */
 
367
        if ( !sieve_opr_string_read(renv, address, &folder) ) {
 
368
                sieve_runtime_trace_error(renv, "invalid folder operand");
 
369
                return SIEVE_EXEC_BIN_CORRUPT;
 
370
        }
 
371
        
 
372
        /* Index */
 
373
        if ( !sieve_opr_number_read(renv, address, &msg_index) ) {
 
374
                sieve_runtime_trace_error(renv, "invalid index operand");
 
375
                return SIEVE_EXEC_BIN_CORRUPT;
 
376
        }
 
377
 
 
378
        /*
 
379
         * Perform operation
 
380
         */
 
381
                
 
382
        sieve_runtime_trace(renv, "TEST_MESSAGE_MAILBOX (%s) \"%s\" [%d]", 
 
383
                ( is_test ? "TEST" : "COMMAND" ), str_c(folder), msg_index);
 
384
 
 
385
        result = testsuite_mailstore_mail_index(renv, str_c(folder), msg_index);
 
386
 
 
387
        if ( is_test ) {
 
388
                sieve_interpreter_set_test_result(renv->interp, result);
 
389
                return SIEVE_EXEC_OK;
 
390
        }
 
391
 
 
392
        if ( !result )
 
393
                testsuite_test_failf("no message in folder '%s' with index %d", 
 
394
                        str_c(folder), msg_index);
 
395
 
 
396
        return SIEVE_EXEC_OK;
 
397
}
 
398
 
 
399
 
 
400
 
 
401
 
 
402