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

« back to all changes in this revision

Viewing changes to libsieve/src/lib-sieve/plugins/imap4flags/cmd-flag.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-code.h"
 
7
#include "sieve-commands.h"
 
8
#include "sieve-validator.h" 
 
9
#include "sieve-generator.h"
 
10
#include "sieve-interpreter.h"
 
11
#include "sieve-dump.h"
 
12
 
 
13
#include "ext-imap4flags-common.h"
 
14
 
 
15
/*
 
16
 * Commands
 
17
 */
 
18
 
 
19
/* Forward declarations */
 
20
 
 
21
static bool cmd_flag_generate
 
22
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
 
23
 
 
24
/* Setflag command 
 
25
 *
 
26
 * Syntax: 
 
27
 *   setflag [<variablename: string>] <list-of-flags: string-list>
 
28
 */
 
29
 
 
30
const struct sieve_command cmd_setflag = { 
 
31
        "setflag", 
 
32
        SCT_COMMAND,
 
33
        -1, /* We check positional arguments ourselves */
 
34
        0, FALSE, FALSE, 
 
35
        NULL, NULL,
 
36
        ext_imap4flags_command_validate, 
 
37
        cmd_flag_generate, 
 
38
        NULL 
 
39
};
 
40
 
 
41
/* Addflag command 
 
42
 *
 
43
 * Syntax:
 
44
 *   addflag [<variablename: string>] <list-of-flags: string-list>
 
45
 */
 
46
 
 
47
const struct sieve_command cmd_addflag = { 
 
48
        "addflag", 
 
49
        SCT_COMMAND,
 
50
        -1, /* We check positional arguments ourselves */
 
51
        0, FALSE, FALSE, 
 
52
        NULL, NULL,
 
53
        ext_imap4flags_command_validate, 
 
54
        cmd_flag_generate, 
 
55
        NULL 
 
56
};
 
57
 
 
58
 
 
59
/* Removeflag command 
 
60
 *
 
61
 * Syntax:
 
62
 *   removeflag [<variablename: string>] <list-of-flags: string-list>
 
63
 */
 
64
 
 
65
const struct sieve_command cmd_removeflag = { 
 
66
        "removeflag", 
 
67
        SCT_COMMAND,
 
68
        -1, /* We check positional arguments ourselves */
 
69
        0, FALSE, FALSE, 
 
70
        NULL, NULL,
 
71
        ext_imap4flags_command_validate, 
 
72
        cmd_flag_generate, 
 
73
        NULL 
 
74
};
 
75
 
 
76
/*
 
77
 * Operations
 
78
 */
 
79
 
 
80
/* Forward declarations */
 
81
 
 
82
bool cmd_flag_operation_dump
 
83
        (const struct sieve_operation *op,
 
84
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
85
static int cmd_flag_operation_execute
 
86
        (const struct sieve_operation *op,      
 
87
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
88
 
 
89
/* Setflag operation */
 
90
 
 
91
const struct sieve_operation setflag_operation = { 
 
92
        "SETFLAG",
 
93
        &imap4flags_extension,
 
94
        ext_imap4flags_OPERATION_SETFLAG,
 
95
        cmd_flag_operation_dump,
 
96
        cmd_flag_operation_execute
 
97
};
 
98
 
 
99
/* Addflag operation */
 
100
 
 
101
const struct sieve_operation addflag_operation = { 
 
102
        "ADDFLAG",
 
103
        &imap4flags_extension,
 
104
        ext_imap4flags_OPERATION_ADDFLAG,
 
105
        cmd_flag_operation_dump,        
 
106
        cmd_flag_operation_execute
 
107
};
 
108
 
 
109
/* Removeflag operation */
 
110
 
 
111
const struct sieve_operation removeflag_operation = { 
 
112
        "REMOVEFLAG",
 
113
        &imap4flags_extension,
 
114
        ext_imap4flags_OPERATION_REMOVEFLAG,
 
115
        cmd_flag_operation_dump, 
 
116
        cmd_flag_operation_execute 
 
117
};
 
118
 
 
119
/* 
 
120
 * Code generation 
 
121
 */
 
122
 
 
123
static bool cmd_flag_generate
 
124
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx)
 
125
{
 
126
        const struct sieve_command *command = ctx->command;
 
127
 
 
128
        /* Emit operation */
 
129
        if ( command == &cmd_setflag ) 
 
130
                sieve_operation_emit_code(cgenv->sbin, &setflag_operation);
 
131
        else if ( command == &cmd_addflag ) 
 
132
                sieve_operation_emit_code(cgenv->sbin, &addflag_operation);
 
133
        else if ( command == &cmd_removeflag ) 
 
134
                sieve_operation_emit_code(cgenv->sbin, &removeflag_operation);
 
135
 
 
136
        /* Generate arguments */
 
137
        if ( !sieve_generate_arguments(cgenv, ctx, NULL) )
 
138
                return FALSE;   
 
139
 
 
140
        return TRUE;
 
141
}
 
142
 
 
143
/*
 
144
 * Code dump
 
145
 */
 
146
 
 
147
bool cmd_flag_operation_dump
 
148
(const struct sieve_operation *op,
 
149
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
150
{
 
151
        const struct sieve_operand *operand;
 
152
 
 
153
        sieve_code_dumpf(denv, "%s", op->mnemonic);
 
154
        sieve_code_descend(denv);
 
155
        
 
156
        sieve_code_mark(denv);
 
157
        operand = sieve_operand_read(denv->sbin, address);
 
158
        if ( operand == NULL ) {
 
159
                sieve_code_dumpf(denv, "ERROR: INVALID OPERAND");
 
160
                return FALSE;
 
161
        }
 
162
 
 
163
        if ( sieve_operand_is_variable(operand) ) {     
 
164
                return 
 
165
                        sieve_opr_string_dump_data(denv, operand, address, 
 
166
                                "variable name") &&
 
167
                        sieve_opr_stringlist_dump(denv, address, 
 
168
                                "list of flags");
 
169
        }
 
170
        
 
171
        return 
 
172
                sieve_opr_stringlist_dump_data(denv, operand, address,
 
173
                        "list of flags");
 
174
}
 
175
 
 
176
/*
 
177
 * Code execution
 
178
 */
 
179
 
 
180
static int cmd_flag_operation_execute
 
181
(const struct sieve_operation *op,
 
182
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
183
{
 
184
        const struct sieve_operand *operand;
 
185
        sieve_size_t op_address = *address;
 
186
        bool result = TRUE;
 
187
        string_t *flag_item;
 
188
        struct sieve_coded_stringlist *flag_list;
 
189
        struct sieve_variable_storage *storage;
 
190
        unsigned int var_index;
 
191
        ext_imapflag_flag_operation_t flag_op;
 
192
        int ret;
 
193
                
 
194
        /* 
 
195
         * Read operands 
 
196
         */
 
197
 
 
198
        operand = sieve_operand_read(renv->sbin, address);
 
199
        if ( operand == NULL ) {
 
200
                sieve_runtime_trace_error(renv, "invalid operand");
 
201
                return SIEVE_EXEC_BIN_CORRUPT;
 
202
        }
 
203
                
 
204
        if ( sieve_operand_is_variable(operand) ) {             
 
205
 
 
206
                /* Read the variable operand */
 
207
                if ( !sieve_variable_operand_read_data
 
208
                        (renv, operand, address, &storage, &var_index) ) {
 
209
                        sieve_runtime_trace_error(renv, "invalid variable operand");
 
210
                        return SIEVE_EXEC_BIN_CORRUPT;
 
211
                }
 
212
                
 
213
                /* Read flag list */
 
214
                if ( (flag_list=sieve_opr_stringlist_read(renv, address)) == NULL ) {
 
215
                        sieve_runtime_trace_error(renv, "invalid flag-list operand");
 
216
                        return SIEVE_EXEC_BIN_CORRUPT;
 
217
                }
 
218
 
 
219
        } else if ( sieve_operand_is_stringlist(operand) ) {    
 
220
                storage = NULL;
 
221
                var_index = 0;
 
222
                
 
223
                /* Read flag list */
 
224
                if ( (flag_list=sieve_opr_stringlist_read_data
 
225
                        (renv, operand, op_address, address)) == NULL ) {
 
226
                        sieve_runtime_trace_error(renv, "invalid flag-list operand");
 
227
                        return SIEVE_EXEC_BIN_CORRUPT;
 
228
                }
 
229
 
 
230
        } else {
 
231
                sieve_runtime_trace_error(renv, "unexpected operand '%s'", 
 
232
                        operand->name);
 
233
                return SIEVE_EXEC_BIN_CORRUPT;
 
234
        }
 
235
        
 
236
        /*
 
237
         * Perform operation
 
238
         */     
 
239
        
 
240
        sieve_runtime_trace(renv, "%s command", op->mnemonic);
 
241
 
 
242
        /* Determine what to do */
 
243
 
 
244
        if ( op == &setflag_operation )
 
245
                flag_op = ext_imap4flags_set_flags;
 
246
        else if ( op == &addflag_operation )
 
247
                flag_op = ext_imap4flags_add_flags;
 
248
        else if ( op == &removeflag_operation )
 
249
                flag_op = ext_imap4flags_remove_flags;
 
250
        else
 
251
                i_unreached();
 
252
 
 
253
        /* Iterate through all flags and perform requested operation */
 
254
        
 
255
        while ( (result=sieve_coded_stringlist_next_item(flag_list, &flag_item)) && 
 
256
                flag_item != NULL ) {
 
257
 
 
258
                if ( (ret=flag_op(renv, storage, var_index, flag_item)) <= 0)
 
259
                        return ret;
 
260
        }
 
261
 
 
262
        if ( !result ) {        
 
263
                sieve_runtime_trace_error(renv, "invalid flag-list item");
 
264
                return SIEVE_EXEC_BIN_CORRUPT;
 
265
        }
 
266
 
 
267
        return SIEVE_EXEC_OK;
 
268
}