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

« back to all changes in this revision

Viewing changes to libsieve/src/testsuite/cmd-test-binary.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-binary.h"
 
15
#include "testsuite-script.h"
 
16
 
 
17
/*
 
18
 * Test_binary command
 
19
 *
 
20
 * Syntax:   
 
21
 *   test_binary ( :load / :save ) <mailbox: string>
 
22
 */
 
23
 
 
24
static bool cmd_test_binary_registered
 
25
        (struct sieve_validator *valdtr, 
 
26
                struct sieve_command_registration *cmd_reg);
 
27
static bool cmd_test_binary_validate
 
28
        (struct sieve_validator *valdtr, struct sieve_command_context *cmd);
 
29
static bool cmd_test_binary_generate
 
30
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
 
31
 
 
32
const struct sieve_command cmd_test_binary = { 
 
33
        "test_binary", 
 
34
        SCT_COMMAND, 
 
35
        1, 0, FALSE, FALSE,
 
36
        cmd_test_binary_registered, 
 
37
        NULL,
 
38
        cmd_test_binary_validate, 
 
39
        cmd_test_binary_generate, 
 
40
        NULL 
 
41
};
 
42
 
 
43
/* 
 
44
 * Operations
 
45
 */ 
 
46
 
 
47
static bool cmd_test_binary_operation_dump
 
48
        (const struct sieve_operation *op,
 
49
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
50
static int cmd_test_binary_operation_execute
 
51
        (const struct sieve_operation *op, 
 
52
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
53
 
 
54
/* test_binary_create operation */
 
55
 
 
56
const struct sieve_operation test_binary_load_operation = { 
 
57
        "TEST_BINARY_LOAD",
 
58
        &testsuite_extension, 
 
59
        TESTSUITE_OPERATION_TEST_BINARY_LOAD,
 
60
        cmd_test_binary_operation_dump, 
 
61
        cmd_test_binary_operation_execute 
 
62
};
 
63
 
 
64
/* test_binary_delete operation */
 
65
 
 
66
const struct sieve_operation test_binary_save_operation = { 
 
67
        "TEST_BINARY_SAVE",
 
68
        &testsuite_extension, 
 
69
        TESTSUITE_OPERATION_TEST_BINARY_SAVE,
 
70
        cmd_test_binary_operation_dump, 
 
71
        cmd_test_binary_operation_execute 
 
72
};
 
73
 
 
74
/*
 
75
 * Compiler context data
 
76
 */
 
77
 
 
78
enum test_binary_operation {
 
79
        BINARY_OP_LOAD, 
 
80
        BINARY_OP_SAVE,
 
81
        BINARY_OP_LAST
 
82
};
 
83
 
 
84
const struct sieve_operation *test_binary_operations[] = {
 
85
        &test_binary_load_operation,
 
86
        &test_binary_save_operation
 
87
};
 
88
 
 
89
struct cmd_test_binary_context_data {
 
90
        enum test_binary_operation binary_op;
 
91
        const char *folder;
 
92
};
 
93
 
 
94
/* 
 
95
 * Command tags 
 
96
 */
 
97
 
 
98
static bool cmd_test_binary_validate_tag
 
99
        (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
 
100
                struct sieve_command_context *cmd);
 
101
 
 
102
static const struct sieve_argument test_binary_load_tag = { 
 
103
        "load", 
 
104
        NULL, NULL,
 
105
        cmd_test_binary_validate_tag,
 
106
        NULL, NULL 
 
107
};
 
108
 
 
109
static const struct sieve_argument test_binary_save_tag = { 
 
110
        "save", 
 
111
        NULL, NULL, 
 
112
        cmd_test_binary_validate_tag,
 
113
        NULL, NULL 
 
114
};
 
115
 
 
116
static bool cmd_test_binary_registered
 
117
(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg) 
 
118
{
 
119
        /* Register our tags */
 
120
        sieve_validator_register_tag(valdtr, cmd_reg, &test_binary_load_tag, 0);        
 
121
        sieve_validator_register_tag(valdtr, cmd_reg, &test_binary_save_tag, 0);        
 
122
 
 
123
        return TRUE;
 
124
}
 
125
 
 
126
static bool cmd_test_binary_validate_tag
 
127
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
 
128
        struct sieve_command_context *cmd)
 
129
{
 
130
        struct cmd_test_binary_context_data *ctx_data = 
 
131
                (struct cmd_test_binary_context_data *) cmd->data;      
 
132
        
 
133
        if ( ctx_data != NULL ) {
 
134
                sieve_argument_validate_error
 
135
                        (valdtr, *arg, "exactly one of the ':load' or ':save' tags must be "
 
136
                                "specified for the test_binary command, but more were found");
 
137
                return NULL;            
 
138
        }
 
139
        
 
140
        ctx_data = p_new
 
141
                (sieve_command_pool(cmd), struct cmd_test_binary_context_data, 1);
 
142
        cmd->data = ctx_data;
 
143
        
 
144
        if ( (*arg)->argument == &test_binary_load_tag ) 
 
145
                ctx_data->binary_op = BINARY_OP_LOAD;
 
146
        else
 
147
                ctx_data->binary_op = BINARY_OP_SAVE;
 
148
 
 
149
        /* Delete this tag */
 
150
        *arg = sieve_ast_arguments_detach(*arg, 1);
 
151
 
 
152
        return TRUE;
 
153
}
 
154
 
 
155
/* 
 
156
 * Validation 
 
157
 */
 
158
 
 
159
static bool cmd_test_binary_validate
 
160
(struct sieve_validator *valdtr, struct sieve_command_context *cmd) 
 
161
{
 
162
        struct sieve_ast_argument *arg = cmd->first_positional;
 
163
        
 
164
        if ( cmd->data == NULL ) {
 
165
                sieve_command_validate_error(valdtr, cmd, 
 
166
                        "the test_binary command requires either the :load or the :save tag "
 
167
                        "to be specified");
 
168
                return FALSE;           
 
169
        }
 
170
                
 
171
        if ( !sieve_validate_positional_argument
 
172
                (valdtr, cmd, arg, "binary-name", 1, SAAT_STRING) ) {
 
173
                return FALSE;
 
174
        }
 
175
        
 
176
        return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE);
 
177
}
 
178
 
 
179
/* 
 
180
 * Code generation 
 
181
 */
 
182
 
 
183
static bool cmd_test_binary_generate
 
184
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *cmd)
 
185
{
 
186
        struct cmd_test_binary_context_data *ctx_data =
 
187
                (struct cmd_test_binary_context_data *) cmd->data; 
 
188
 
 
189
        i_assert( ctx_data->binary_op < BINARY_OP_LAST );
 
190
        
 
191
        /* Emit operation */
 
192
        sieve_operation_emit_code(cgenv->sbin, 
 
193
                test_binary_operations[ctx_data->binary_op]);
 
194
                
 
195
        /* Generate arguments */
 
196
        if ( !sieve_generate_arguments(cgenv, cmd, NULL) )
 
197
                return FALSE;
 
198
 
 
199
        return TRUE;
 
200
}
 
201
 
 
202
/* 
 
203
 * Code dump
 
204
 */
 
205
 
 
206
static bool cmd_test_binary_operation_dump
 
207
(const struct sieve_operation *op,
 
208
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
209
{
 
210
        sieve_code_dumpf(denv, "%s:", op->mnemonic);
 
211
        
 
212
        sieve_code_descend(denv);
 
213
        
 
214
        return sieve_opr_string_dump(denv, address, "binary-name");
 
215
}
 
216
 
 
217
 
 
218
/*
 
219
 * Intepretation
 
220
 */
 
221
 
 
222
static int cmd_test_binary_operation_execute
 
223
(const struct sieve_operation *op,
 
224
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
225
{
 
226
        string_t *binary_name = NULL;
 
227
 
 
228
        /* 
 
229
         * Read operands 
 
230
         */
 
231
 
 
232
        /* Binary Name */
 
233
 
 
234
        if ( !sieve_opr_string_read(renv, address, &binary_name) ) {
 
235
                sieve_runtime_trace_error(renv, "invalid mailbox operand");
 
236
                return SIEVE_EXEC_BIN_CORRUPT;
 
237
        }
 
238
 
 
239
        /*
 
240
         * Perform operation
 
241
         */
 
242
                
 
243
        sieve_runtime_trace(renv, "%s %s:", op->mnemonic, str_c(binary_name));
 
244
 
 
245
        if ( op == &test_binary_load_operation ) {
 
246
                struct sieve_binary *sbin = testsuite_binary_load(str_c(binary_name));
 
247
 
 
248
                if ( sbin != NULL ) {
 
249
                        testsuite_script_set_binary(sbin);
 
250
 
 
251
                        sieve_binary_unref(&sbin);
 
252
                } else {
 
253
                        sieve_sys_error("failed to load binary %s", str_c(binary_name));
 
254
                        return SIEVE_EXEC_FAILURE;
 
255
                }
 
256
 
 
257
        } else if ( op == &test_binary_save_operation ) {
 
258
                struct sieve_binary *sbin = testsuite_script_get_binary();
 
259
 
 
260
                if ( sbin != NULL ) 
 
261
                        testsuite_binary_save(sbin, str_c(binary_name));
 
262
                else {
 
263
                        sieve_sys_error("no compiled binary to save as %s", str_c(binary_name));
 
264
                        return SIEVE_EXEC_FAILURE;
 
265
                }
 
266
        }
 
267
 
 
268
        return SIEVE_EXEC_OK;
 
269
}