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

« back to all changes in this revision

Viewing changes to libsieve/src/lib-sieve/plugins/include/cmd-global.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
 
 
6
#include "sieve-common.h"
 
7
#include "sieve-code.h"
 
8
#include "sieve-commands.h"
 
9
#include "sieve-validator.h" 
 
10
#include "sieve-generator.h"
 
11
#include "sieve-binary.h"
 
12
#include "sieve-interpreter.h"
 
13
#include "sieve-dump.h"
 
14
 
 
15
#include "sieve-ext-variables.h"
 
16
 
 
17
#include "ext-include-common.h"
 
18
#include "ext-include-binary.h"
 
19
#include "ext-include-variables.h"
 
20
 
 
21
/* 
 
22
 * Commands 
 
23
 */
 
24
 
 
25
static bool cmd_global_validate
 
26
  (struct sieve_validator *validator, struct sieve_command_context *cmd);
 
27
static bool cmd_global_generate
 
28
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *cmd);
 
29
 
 
30
const struct sieve_command cmd_global = {
 
31
    "global",
 
32
    SCT_COMMAND,
 
33
    1, 0, FALSE, FALSE,
 
34
    NULL, NULL,
 
35
    cmd_global_validate,
 
36
    cmd_global_generate,
 
37
    NULL
 
38
};
 
39
 
 
40
/* DEPRICATED:
 
41
 */
 
42
                
 
43
/* Import command 
 
44
 * 
 
45
 * Syntax
 
46
 *   import
 
47
 */     
 
48
const struct sieve_command cmd_import = { 
 
49
        "import", 
 
50
        SCT_COMMAND, 
 
51
        1, 0, FALSE, FALSE,
 
52
        NULL, NULL,
 
53
        cmd_global_validate, 
 
54
        cmd_global_generate, 
 
55
        NULL
 
56
};
 
57
 
 
58
/* Export command 
 
59
 * 
 
60
 * Syntax
 
61
 *   export
 
62
 */     
 
63
const struct sieve_command cmd_export = { 
 
64
        "export", 
 
65
        SCT_COMMAND, 
 
66
        1, 0, FALSE, FALSE,
 
67
        NULL, NULL, 
 
68
        cmd_global_validate, 
 
69
        cmd_global_generate, 
 
70
        NULL
 
71
};
 
72
 
 
73
/*
 
74
 * Operations
 
75
 */
 
76
 
 
77
static bool opc_global_dump
 
78
        (const struct sieve_operation *op,      
 
79
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
80
static int opc_global_execute
 
81
        (const struct sieve_operation *op, 
 
82
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
83
 
 
84
/* Global operation */
 
85
 
 
86
const struct sieve_operation global_operation = { 
 
87
        "global",
 
88
        &include_extension,
 
89
        EXT_INCLUDE_OPERATION_GLOBAL,
 
90
        opc_global_dump, 
 
91
        opc_global_execute
 
92
};
 
93
 
 
94
/*
 
95
 * Validation
 
96
 */
 
97
 
 
98
static bool cmd_global_validate
 
99
  (struct sieve_validator *validator, struct sieve_command_context *cmd) 
 
100
{
 
101
        struct sieve_ast_argument *arg = cmd->first_positional;
 
102
        struct sieve_command_context *prev_context = 
 
103
                sieve_command_prev_context(cmd);
 
104
 
 
105
        /* Check valid command placement */
 
106
        if ( !sieve_command_is_toplevel(cmd) ||
 
107
                ( !sieve_command_is_first(cmd) && prev_context != NULL &&
 
108
                        prev_context->command != &cmd_require ) ) {
 
109
 
 
110
                if ( cmd->command == &cmd_global ) {
 
111
                        if ( prev_context->command != &cmd_global ) {
 
112
                                sieve_command_validate_error(validator, cmd, 
 
113
                                        "a global command can only be placed at top level "
 
114
                                        "at the beginning of the file after any require or other global commands");
 
115
                                return FALSE;
 
116
                        }
 
117
                } else {
 
118
                        if ( prev_context->command != &cmd_import && prev_context->command != &cmd_export ) {
 
119
                sieve_command_validate_error(validator, cmd,
 
120
                    "the DEPRICATED %s command can only be placed at top level "
 
121
                    "at the beginning of the file after any require or import/export commands",
 
122
                                        cmd->command->identifier);
 
123
                return FALSE;
 
124
            }
 
125
                }
 
126
        }
 
127
 
 
128
        /* Check for use of variables extension */      
 
129
        if ( !sieve_ext_variables_is_active(validator) ) {
 
130
                sieve_command_validate_error(validator, cmd, 
 
131
                        "%s command requires that variables extension is active",
 
132
                        cmd->command->identifier);
 
133
                return FALSE;
 
134
        }
 
135
                
 
136
        /* Register global variable */
 
137
        if ( sieve_ast_argument_type(arg) == SAAT_STRING ) {
 
138
                /* Single string */
 
139
                const char *identifier = sieve_ast_argument_strc(arg);
 
140
                struct sieve_variable *var;
 
141
                
 
142
                if ( (var=ext_include_variable_import_global
 
143
                        (validator, cmd, identifier)) == NULL )
 
144
                        return FALSE;
 
145
                        
 
146
                arg->context = (void *) var;
 
147
 
 
148
        } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) {
 
149
                /* String list */
 
150
                struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg);
 
151
                
 
152
                while ( stritem != NULL ) {
 
153
                        const char *identifier = sieve_ast_argument_strc(stritem);
 
154
                        struct sieve_variable *var;
 
155
                        
 
156
                        if ( (var=ext_include_variable_import_global
 
157
                                (validator, cmd, identifier)) == NULL )
 
158
                                return FALSE;
 
159
 
 
160
                        stritem->context = (void *) var;
 
161
        
 
162
                        stritem = sieve_ast_strlist_next(stritem);
 
163
                }
 
164
        } else {
 
165
                /* Something else */
 
166
                sieve_argument_validate_error(validator, arg, 
 
167
                        "the %s command accepts a single string or string list argument, "
 
168
                        "but %s was found", cmd->command->identifier,
 
169
                        sieve_ast_argument_name(arg));
 
170
                return FALSE;
 
171
        }
 
172
        
 
173
        /* Join global commands with predecessors if possible */
 
174
        if ( prev_context->command == cmd->command ) {
 
175
                /* Join this command's string list with the previous one */
 
176
                prev_context->first_positional = sieve_ast_stringlist_join
 
177
                        (prev_context->first_positional, cmd->first_positional);
 
178
                
 
179
                if ( prev_context->first_positional == NULL ) {
 
180
                        /* Not going to happen unless MAXINT stringlist items are specified */
 
181
                        sieve_command_validate_error(validator, cmd, 
 
182
                                "compiler reached AST limit (script too complex)");
 
183
                        return FALSE;
 
184
                }
 
185
 
 
186
                /* Detach this command node */
 
187
                sieve_ast_node_detach(cmd->ast_node);
 
188
        }
 
189
                
 
190
        return TRUE;
 
191
}
 
192
 
 
193
/*
 
194
 * Code generation
 
195
 */
 
196
 
 
197
static bool cmd_global_generate
 
198
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *cmd) 
 
199
{
 
200
        struct sieve_ast_argument *arg = cmd->first_positional;
 
201
 
 
202
        sieve_operation_emit_code(cgenv->sbin, &global_operation);
 
203
                                
 
204
        if ( sieve_ast_argument_type(arg) == SAAT_STRING ) {
 
205
                /* Single string */
 
206
                struct sieve_variable *var = (struct sieve_variable *) arg->context;
 
207
                
 
208
                (void)sieve_binary_emit_unsigned(cgenv->sbin, 1);
 
209
                (void)sieve_binary_emit_unsigned(cgenv->sbin, var->index);
 
210
                
 
211
        } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) {
 
212
                /* String list */
 
213
                struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg);
 
214
                
 
215
                (void)sieve_binary_emit_unsigned(cgenv->sbin, sieve_ast_strlist_count(arg));
 
216
                                                
 
217
                while ( stritem != NULL ) {
 
218
                        struct sieve_variable *var = (struct sieve_variable *) stritem->context;
 
219
                        
 
220
                        (void)sieve_binary_emit_unsigned(cgenv->sbin, var->index);
 
221
                        
 
222
                        stritem = sieve_ast_strlist_next(stritem);
 
223
                }
 
224
        } else {
 
225
                i_unreached();
 
226
        }
 
227
                        
 
228
        return TRUE;
 
229
}
 
230
 
 
231
/* 
 
232
 * Code dump
 
233
 */
 
234
 
 
235
static bool opc_global_dump
 
236
(const struct sieve_operation *op ATTR_UNUSED,
 
237
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
238
{
 
239
        unsigned int count, i, var_count;
 
240
        struct sieve_variable_scope *scope;
 
241
        struct sieve_variable * const *vars;
 
242
        
 
243
        if ( !sieve_binary_read_unsigned(denv->sbin, address, &count) )
 
244
                return FALSE;
 
245
 
 
246
        sieve_code_dumpf(denv, "GLOBAL (count: %u):", count);
 
247
 
 
248
        scope = ext_include_binary_get_global_scope(denv->sbin);
 
249
        vars = sieve_variable_scope_get_variables(scope, &var_count);
 
250
 
 
251
        sieve_code_descend(denv);
 
252
 
 
253
        for ( i = 0; i < count; i++ ) {
 
254
                unsigned int index;
 
255
                
 
256
                sieve_code_mark(denv);
 
257
                if ( !sieve_binary_read_unsigned(denv->sbin, address, &index) ||
 
258
                        index >= var_count )
 
259
                        return FALSE;
 
260
                        
 
261
                sieve_code_dumpf(denv, "VAR[%d]: '%s'", index, vars[index]->identifier); 
 
262
        }
 
263
         
 
264
        return TRUE;
 
265
}
 
266
 
 
267
/* 
 
268
 * Execution
 
269
 */
 
270
 
 
271
static int opc_global_execute
 
272
(const struct sieve_operation *op ATTR_UNUSED,
 
273
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
274
{
 
275
        struct sieve_variable_scope *scope;     
 
276
        struct sieve_variable_storage *storage;
 
277
        struct sieve_variable * const *vars;
 
278
        unsigned int var_count, count, i;
 
279
                
 
280
        if ( !sieve_binary_read_unsigned(renv->sbin, address, &count) ) {
 
281
                sieve_runtime_trace_error(renv, "invalid count operand");
 
282
                return SIEVE_EXEC_BIN_CORRUPT;
 
283
        }
 
284
        
 
285
        scope = ext_include_binary_get_global_scope(renv->sbin);
 
286
        vars = sieve_variable_scope_get_variables(scope, &var_count);
 
287
        storage = ext_include_interpreter_get_global_variables(renv->interp);
 
288
 
 
289
        for ( i = 0; i < count; i++ ) {
 
290
                unsigned int index;
 
291
                
 
292
                if ( !sieve_binary_read_unsigned(renv->sbin, address, &index) ) {
 
293
                        sieve_runtime_trace_error(renv, "invalid global variable operand");
 
294
                        return SIEVE_EXEC_BIN_CORRUPT;
 
295
                }
 
296
                
 
297
                if ( index >= var_count ) {
 
298
                        sieve_runtime_trace_error(renv, "invalid global variable index (%u > %u)",
 
299
                                index, var_count);
 
300
                        return SIEVE_EXEC_BIN_CORRUPT;
 
301
                }
 
302
                
 
303
                /* Make sure variable is initialized (export) */
 
304
                (void)sieve_variable_get_modifiable(storage, index, NULL); 
 
305
        }
 
306
 
 
307
        return SIEVE_EXEC_OK;
 
308
}
 
309
 
 
310