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

« back to all changes in this revision

Viewing changes to libsieve/src/testsuite/testsuite-objects.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
#include "string.h"
 
6
#include "ostream.h"
 
7
#include "hash.h"
 
8
#include "mail-storage.h"
 
9
 
 
10
#include "sieve.h"
 
11
#include "sieve-code.h"
 
12
#include "sieve-commands.h"
 
13
#include "sieve-extensions.h"
 
14
#include "sieve-validator.h"
 
15
#include "sieve-generator.h"
 
16
#include "sieve-binary.h"
 
17
#include "sieve-dump.h"
 
18
 
 
19
#include "testsuite-common.h"
 
20
#include "testsuite-objects.h"
 
21
#include "testsuite-message.h"
 
22
 
 
23
/* 
 
24
 * Testsuite core objects
 
25
 */
 
26
 
 
27
enum testsuite_object_code {
 
28
        TESTSUITE_OBJECT_MESSAGE,
 
29
        TESTSUITE_OBJECT_ENVELOPE
 
30
};
 
31
 
 
32
const struct testsuite_object *testsuite_core_objects[] = {
 
33
        &message_testsuite_object, &envelope_testsuite_object
 
34
};
 
35
 
 
36
const unsigned int testsuite_core_objects_count =
 
37
        N_ELEMENTS(testsuite_core_objects);
 
38
 
 
39
/* 
 
40
 * Testsuite object registry
 
41
 */
 
42
 
 
43
void testsuite_object_register
 
44
(struct sieve_validator *valdtr, const struct testsuite_object *tobj) 
 
45
{
 
46
        struct testsuite_validator_context *ctx = testsuite_validator_context_get
 
47
                (valdtr);
 
48
        
 
49
        sieve_validator_object_registry_add
 
50
                (ctx->object_registrations, &tobj->object);
 
51
}
 
52
 
 
53
const struct testsuite_object *testsuite_object_find
 
54
(struct sieve_validator *valdtr, const char *identifier) 
 
55
{
 
56
        struct testsuite_validator_context *ctx = testsuite_validator_context_get
 
57
                (valdtr);
 
58
        const struct sieve_object *object = 
 
59
                sieve_validator_object_registry_find
 
60
                        (ctx->object_registrations, identifier);
 
61
 
 
62
        return (const struct testsuite_object *) object;
 
63
}
 
64
 
 
65
void testsuite_register_core_objects
 
66
        (struct testsuite_validator_context *ctx)
 
67
{
 
68
        unsigned int i;
 
69
        
 
70
        /* Register core testsuite objects */
 
71
        for ( i = 0; i < testsuite_core_objects_count; i++ ) {
 
72
                sieve_validator_object_registry_add
 
73
                        (ctx->object_registrations, &(testsuite_core_objects[i]->object));
 
74
        }
 
75
}
 
76
 
 
77
/* 
 
78
 * Testsuite object code
 
79
 */ 
 
80
 
 
81
const struct sieve_operand_class sieve_testsuite_object_operand_class = 
 
82
        { "testsuite object" };
 
83
 
 
84
static const struct sieve_extension_objects core_testsuite_objects =
 
85
        SIEVE_EXT_DEFINE_OBJECTS(testsuite_core_objects);
 
86
 
 
87
const struct sieve_operand testsuite_object_operand = { 
 
88
        "testsuite-object",
 
89
        &testsuite_extension, 
 
90
        TESTSUITE_OPERAND_OBJECT, 
 
91
        &sieve_testsuite_object_operand_class,
 
92
        &core_testsuite_objects
 
93
};
 
94
 
 
95
static void testsuite_object_emit
 
96
(struct sieve_binary *sbin, const struct testsuite_object *obj,
 
97
        int member_id)
 
98
 
99
        sieve_opr_object_emit(sbin, &obj->object);
 
100
        
 
101
        if ( obj->get_member_id != NULL ) {
 
102
                (void) sieve_binary_emit_byte(sbin, (unsigned char) member_id);
 
103
        }
 
104
}
 
105
 
 
106
const struct testsuite_object *testsuite_object_read
 
107
(struct sieve_binary *sbin, sieve_size_t *address)
 
108
{
 
109
        const struct sieve_operand *operand = sieve_operand_read(sbin, address);
 
110
        
 
111
        return (const struct testsuite_object *) sieve_opr_object_read_data
 
112
                (sbin, operand, &sieve_testsuite_object_operand_class, address);
 
113
}
 
114
 
 
115
const struct testsuite_object *testsuite_object_read_member
 
116
(struct sieve_binary *sbin, sieve_size_t *address, int *member_id)
 
117
{
 
118
        const struct testsuite_object *object;
 
119
                
 
120
        if ( (object = testsuite_object_read(sbin, address)) == NULL )
 
121
                return NULL;
 
122
                
 
123
        *member_id = -1;
 
124
        if ( object->get_member_id != NULL ) {
 
125
                if ( !sieve_binary_read_code(sbin, address, member_id) ) 
 
126
                        return NULL;
 
127
        }
 
128
        
 
129
        return object;
 
130
}
 
131
 
 
132
const char *testsuite_object_member_name
 
133
(const struct testsuite_object *object, int member_id)
 
134
{
 
135
        const char *member = NULL;
 
136
 
 
137
        if ( object->get_member_id != NULL ) {
 
138
                if ( object->get_member_name != NULL )
 
139
                        member = object->get_member_name(member_id);
 
140
        } else 
 
141
                return object->object.identifier;
 
142
                
 
143
        if ( member == NULL )   
 
144
                return t_strdup_printf("%s.%d", object->object.identifier, member_id);
 
145
        
 
146
        return t_strdup_printf("%s.%s", object->object.identifier, member);
 
147
}
 
148
 
 
149
bool testsuite_object_dump
 
150
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
151
{
 
152
        const struct testsuite_object *object;
 
153
        int member_id;
 
154
 
 
155
        sieve_code_mark(denv);
 
156
                
 
157
        if ( (object = testsuite_object_read_member(denv->sbin, address, &member_id)) 
 
158
                == NULL )
 
159
                return FALSE;
 
160
        
 
161
        sieve_code_dumpf(denv, "%s: %s",
 
162
                sieve_testsuite_object_operand_class.name, 
 
163
                testsuite_object_member_name(object, member_id));
 
164
        
 
165
        return TRUE;
 
166
}
 
167
 
 
168
/* 
 
169
 * Testsuite object argument
 
170
 */
 
171
 
 
172
static bool arg_testsuite_object_generate
 
173
        (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, 
 
174
                struct sieve_command_context *cmd);
 
175
 
 
176
const struct sieve_argument testsuite_object_argument = { 
 
177
        "testsuite-object", 
 
178
        NULL, NULL, NULL, NULL,
 
179
        arg_testsuite_object_generate 
 
180
};
 
181
 
 
182
struct testsuite_object_argctx {
 
183
        const struct testsuite_object *object;
 
184
        int member;
 
185
};
 
186
 
 
187
bool testsuite_object_argument_activate
 
188
(struct sieve_validator *valdtr, struct sieve_ast_argument *arg,
 
189
        struct sieve_command_context *cmd) 
 
190
{
 
191
        const char *objname = sieve_ast_argument_strc(arg);
 
192
        const struct testsuite_object *object;
 
193
        int member_id;
 
194
        const char *member;
 
195
        struct testsuite_object_argctx *ctx;
 
196
        
 
197
        /* Parse the object specifier */
 
198
        
 
199
        member = strchr(objname, '.');
 
200
        if ( member != NULL ) {
 
201
                objname = t_strdup_until(objname, member);
 
202
                member++;
 
203
        }
 
204
        
 
205
        /* Find the object */
 
206
        
 
207
        object = testsuite_object_find(valdtr, objname);
 
208
        if ( object == NULL ) {
 
209
                sieve_argument_validate_error(valdtr, arg, 
 
210
                        "unknown testsuite object '%s'", objname);
 
211
                return FALSE;
 
212
        }
 
213
        
 
214
        /* Find the object member */
 
215
        
 
216
        member_id = -1;
 
217
        if ( member != NULL ) {
 
218
                if ( object->get_member_id == NULL || 
 
219
                        (member_id=object->get_member_id(member)) == -1 ) {
 
220
                        sieve_argument_validate_error(valdtr, arg, 
 
221
                                "member '%s' does not exist for testsuite object '%s'", member, objname);
 
222
                        return FALSE;
 
223
                }
 
224
        }
 
225
        
 
226
        /* Assign argument context */
 
227
        
 
228
        ctx = p_new(sieve_command_pool(cmd), struct testsuite_object_argctx, 1);
 
229
        ctx->object = object;
 
230
        ctx->member = member_id;
 
231
        
 
232
        arg->argument = &testsuite_object_argument;
 
233
        arg->context = (void *) ctx;
 
234
        
 
235
        return TRUE;
 
236
}
 
237
 
 
238
static bool arg_testsuite_object_generate
 
239
        (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, 
 
240
        struct sieve_command_context *cmd ATTR_UNUSED)
 
241
{
 
242
        struct testsuite_object_argctx *ctx = 
 
243
                (struct testsuite_object_argctx *) arg->context;
 
244
        
 
245
        testsuite_object_emit(cgenv->sbin, ctx->object, ctx->member);
 
246
                
 
247
        return TRUE;
 
248
}
 
249
 
 
250
/* 
 
251
 * Testsuite core object implementation
 
252
 */
 
253
 
 
254
static bool tsto_message_set_member
 
255
        (const struct sieve_runtime_env *renv, int id, string_t *value);
 
256
 
 
257
static int tsto_envelope_get_member_id(const char *identifier);
 
258
static const char *tsto_envelope_get_member_name(int id);
 
259
static bool tsto_envelope_set_member
 
260
        (const struct sieve_runtime_env *renv, int id, string_t *value);
 
261
 
 
262
const struct testsuite_object message_testsuite_object = { 
 
263
        SIEVE_OBJECT("message", &testsuite_object_operand, TESTSUITE_OBJECT_MESSAGE),
 
264
        NULL, NULL, 
 
265
        tsto_message_set_member, 
 
266
        NULL
 
267
};
 
268
 
 
269
const struct testsuite_object envelope_testsuite_object = { 
 
270
        SIEVE_OBJECT("envelope", &testsuite_object_operand, TESTSUITE_OBJECT_ENVELOPE),
 
271
        tsto_envelope_get_member_id, 
 
272
        tsto_envelope_get_member_name,
 
273
        tsto_envelope_set_member, 
 
274
        NULL
 
275
};
 
276
 
 
277
enum testsuite_object_envelope_field {
 
278
        TESTSUITE_OBJECT_ENVELOPE_FROM,
 
279
        TESTSUITE_OBJECT_ENVELOPE_TO,
 
280
        TESTSUITE_OBJECT_ENVELOPE_AUTH_USER
 
281
};
 
282
 
 
283
static bool tsto_message_set_member
 
284
(const struct sieve_runtime_env *renv, int id, string_t *value) 
 
285
{
 
286
        if ( id != -1 ) return FALSE;
 
287
        
 
288
        testsuite_message_set_string(renv, value);
 
289
        
 
290
        return TRUE;
 
291
}
 
292
 
 
293
static int tsto_envelope_get_member_id(const char *identifier)
 
294
{
 
295
        if ( strcasecmp(identifier, "from") == 0 )
 
296
                return TESTSUITE_OBJECT_ENVELOPE_FROM;
 
297
        if ( strcasecmp(identifier, "to") == 0 )
 
298
                return TESTSUITE_OBJECT_ENVELOPE_TO;
 
299
        if ( strcasecmp(identifier, "auth") == 0 )
 
300
                return TESTSUITE_OBJECT_ENVELOPE_AUTH_USER;     
 
301
        
 
302
        return -1;
 
303
}
 
304
 
 
305
static const char *tsto_envelope_get_member_name(int id) 
 
306
{
 
307
        switch ( id ) {
 
308
        case TESTSUITE_OBJECT_ENVELOPE_FROM: 
 
309
                return "from";
 
310
        case TESTSUITE_OBJECT_ENVELOPE_TO: 
 
311
                return "to";
 
312
        case TESTSUITE_OBJECT_ENVELOPE_AUTH_USER: 
 
313
                return "auth";
 
314
        }
 
315
        
 
316
        return NULL;
 
317
}
 
318
 
 
319
static bool tsto_envelope_set_member
 
320
(const struct sieve_runtime_env *renv, int id, string_t *value)
 
321
{
 
322
        switch ( id ) {
 
323
        case TESTSUITE_OBJECT_ENVELOPE_FROM: 
 
324
                testsuite_envelope_set_sender(renv, str_c(value));
 
325
                return TRUE;
 
326
        case TESTSUITE_OBJECT_ENVELOPE_TO:
 
327
                testsuite_envelope_set_recipient(renv, str_c(value));
 
328
                return TRUE;
 
329
        case TESTSUITE_OBJECT_ENVELOPE_AUTH_USER: 
 
330
                testsuite_envelope_set_auth_user(renv, str_c(value));
 
331
                return TRUE;
 
332
        }
 
333
        
 
334
        return FALSE;
 
335
}