~ubuntu-branches/ubuntu/quantal/dovecot/quantal

« back to all changes in this revision

Viewing changes to sieve/src/lib-sieve/plugins/include/ext-include-binary.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-29 09:21:32 UTC
  • mfrom: (4.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20100629092132-q4pr5lfuvmjqou19
Tags: 1:1.2.12-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  + Add mail-stack-delivery as per server-maverick-mail-integration spec:
   - Update debian/rules
   - Convert existing package to a dummy package and add new binary in debian/control
   - Update maintainer scripts.
   - Move previously installed backups and config files to new package name
     space in preinst
   - Add new debian/mail-stack-delivery.prerm to handle downgrades
   - Rename debian/dovecot-postfix.* to debian/mail-stack-delivery.*
  + 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/*.
  + Add ufw integration:
    - Created debian/dovecot-common.ufw.profile.
    - debian/rules: install profile.
    - debian/control: suggest ufw.
  + debian/{control,rules}: enable PIE hardening.
  + debian/control: Update Vcs-* headers.
  + Add SMTP-AUTH support for Outlook (login auth mechanism) 
  + debian/dovecot-common.dirs: Added usr/share/doc/dovecot-common
  + debian/patches/fix-dovecot-config-parser.patch: Fix ordering of external config 
    files. (LP: #597818)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
/*
23
23
 * Forward declarations
24
24
 */
25
 
 
 
25
 
26
26
static bool ext_include_binary_save
27
27
        (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
28
28
static bool ext_include_binary_open
32
32
static void ext_include_binary_free
33
33
        (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context);
34
34
 
35
 
/* 
 
35
/*
36
36
 * Binary include extension
37
37
 */
38
 
 
 
38
 
39
39
const struct sieve_binary_extension include_binary_ext = {
40
40
        &include_extension,
41
41
        ext_include_binary_save,
47
47
/*
48
48
 * Binary context management
49
49
 */
50
 
 
 
50
 
51
51
struct ext_include_binary_context {
52
52
        struct sieve_binary *binary;
53
53
        unsigned int dependency_block;
54
 
        
 
54
 
55
55
        struct hash_table *included_scripts;
56
56
        ARRAY_DEFINE(include_index, struct ext_include_script_info *);
57
57
 
58
58
        struct sieve_variable_scope *global_vars;
59
59
};
60
60
 
61
 
 
 
61
 
62
62
static struct ext_include_binary_context *ext_include_binary_create_context
63
63
(const struct sieve_extension *this_ext, struct sieve_binary *sbin)
64
64
{
65
65
        pool_t pool = sieve_binary_pool(sbin);
66
 
        
67
 
        struct ext_include_binary_context *ctx = 
 
66
 
 
67
        struct ext_include_binary_context *ctx =
68
68
                p_new(pool, struct ext_include_binary_context, 1);
69
 
        
70
 
        ctx->binary = sbin;                     
71
 
        ctx->included_scripts = hash_table_create(default_pool, pool, 0, 
72
 
                (hash_callback_t *) sieve_script_hash, 
 
69
 
 
70
        ctx->binary = sbin;
 
71
        ctx->included_scripts = hash_table_create(default_pool, pool, 0,
 
72
                (hash_callback_t *) sieve_script_hash,
73
73
                (hash_cmp_callback_t *) sieve_script_cmp);
74
74
        p_array_init(&ctx->include_index, pool, 128);
75
75
 
80
80
 
81
81
struct ext_include_binary_context *ext_include_binary_get_context
82
82
(const struct sieve_extension *this_ext, struct sieve_binary *sbin)
83
 
{       
 
83
{
84
84
        struct ext_include_binary_context *ctx = (struct ext_include_binary_context *)
85
85
                sieve_binary_extension_get_context(sbin, this_ext);
86
 
        
 
86
 
87
87
        if ( ctx == NULL )
88
88
                ctx = ext_include_binary_create_context(this_ext, sbin);
89
 
        
 
89
 
90
90
        return ctx;
91
91
}
92
 
 
 
92
 
93
93
struct ext_include_binary_context *ext_include_binary_init
94
 
(const struct sieve_extension *this_ext, struct sieve_binary *sbin, 
 
94
(const struct sieve_extension *this_ext, struct sieve_binary *sbin,
95
95
        struct sieve_ast *ast)
96
96
{
97
97
        struct ext_include_ast_context *ast_ctx =
98
98
                ext_include_get_ast_context(this_ext, ast);
99
99
        struct ext_include_binary_context *ctx;
100
 
        
 
100
 
101
101
        /* Get/create our context from the binary we are working on */
102
102
        ctx = ext_include_binary_get_context(this_ext, sbin);
103
 
        
 
103
 
104
104
        /* Create dependency block */
105
105
        if ( ctx->dependency_block == 0 )
106
 
                ctx->dependency_block = 
 
106
                ctx->dependency_block =
107
107
                        sieve_binary_extension_create_block(sbin, this_ext);
108
108
 
109
109
        if ( ctx->global_vars == NULL ) {
110
110
                ctx->global_vars = ast_ctx->global_vars;
111
111
                sieve_variable_scope_ref(ctx->global_vars);
112
112
        }
113
 
                        
 
113
 
114
114
        return ctx;
115
115
}
116
116
 
130
130
        incscript->script = script;
131
131
        incscript->location = location;
132
132
        incscript->block_id = block_id;
133
 
        
 
133
 
134
134
        /* Unreferenced on binary_free */
135
135
        sieve_script_ref(script);
136
 
        
 
136
 
137
137
        hash_table_insert
138
138
                (binctx->included_scripts, (void *) script, (void *) incscript);
139
139
        array_append(&binctx->include_index, &incscript, 1);
147
147
{
148
148
        struct ext_include_script_info *incscript = (struct ext_include_script_info *)
149
149
                hash_table_lookup(binctx->included_scripts, script);
150
 
                
 
150
 
151
151
        if ( incscript == NULL )
152
152
                return FALSE;
153
 
                                
 
153
 
154
154
        *script_info_r = incscript;
155
155
        return TRUE;
156
156
}
157
157
 
158
158
const struct ext_include_script_info *ext_include_binary_script_get_included
159
159
(struct ext_include_binary_context *binctx, unsigned int include_id)
160
 
{               
161
 
        if ( include_id > 0 && 
 
160
{
 
161
        if ( include_id > 0 &&
162
162
                (include_id - 1) < array_count(&binctx->include_index) ) {
163
163
                struct ext_include_script_info *const *sinfo =
164
164
                        array_idx(&binctx->include_index, include_id - 1);
183
183
}
184
184
 
185
185
/*
186
 
 * Variables 
 
186
 * Variables
187
187
 */
188
188
 
189
189
struct sieve_variable_scope *ext_include_binary_get_global_scope
190
190
(const struct sieve_extension *this_ext, struct sieve_binary *sbin)
191
191
{
192
 
        struct ext_include_binary_context *binctx = 
 
192
        struct ext_include_binary_context *binctx =
193
193
                ext_include_binary_get_context(this_ext, sbin);
194
194
 
195
195
        return binctx->global_vars;
200
200
 */
201
201
 
202
202
static bool ext_include_binary_save
203
 
(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_binary *sbin, 
 
203
(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_binary *sbin,
204
204
        void *context)
205
205
{
206
 
        struct ext_include_binary_context *binctx = 
 
206
        struct ext_include_binary_context *binctx =
207
207
                (struct ext_include_binary_context *) context;
208
208
        struct ext_include_script_info *const *scripts;
209
209
        unsigned int script_count, i;
210
210
        unsigned int prvblk;
211
211
        bool result = TRUE;
212
 
        
 
212
 
213
213
        sieve_binary_block_clear(sbin, binctx->dependency_block);
214
 
        if ( !sieve_binary_block_set_active(sbin, binctx->dependency_block, &prvblk) )  
 
214
        if ( !sieve_binary_block_set_active(sbin, binctx->dependency_block, &prvblk) )
215
215
                return FALSE;
216
216
 
217
217
        scripts = array_get(&binctx->include_index, &script_count);
227
227
        }
228
228
 
229
229
        result = ext_include_variables_save(sbin, binctx->global_vars);
230
 
        
 
230
 
231
231
        (void) sieve_binary_block_set_active(sbin, prvblk, NULL);
232
232
 
233
233
        return result;
236
236
static bool ext_include_binary_open
237
237
(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context)
238
238
{
239
 
        struct ext_include_binary_context *binctx = 
 
239
        struct ext_include_binary_context *binctx =
240
240
                (struct ext_include_binary_context *) context;
241
241
        unsigned int block, prvblk, depcount, i;
242
242
        sieve_size_t offset;
243
 
        
 
243
 
244
244
        block = sieve_binary_extension_get_block(sbin, ext);
245
 
        
 
245
 
246
246
        if ( !sieve_binary_block_set_active(sbin, block, &prvblk) )
247
 
                return FALSE; 
248
 
                
249
 
        offset = 0;     
250
 
                
 
247
                return FALSE;
 
248
 
 
249
        offset = 0;
 
250
 
251
251
        if ( !sieve_binary_read_unsigned(sbin, &offset, &depcount) ) {
252
252
                sieve_sys_error("include: failed to read include count "
253
 
                        "for dependency block %d of binary %s", block, sieve_binary_path(sbin)); 
 
253
                        "for dependency block %d of binary %s", block, sieve_binary_path(sbin));
254
254
                return FALSE;
255
255
        }
256
 
        
257
 
        /* Check include limit */       
 
256
 
 
257
        /* Check include limit */
258
258
        if ( depcount > EXT_INCLUDE_MAX_INCLUDES ) {
259
259
                sieve_sys_error("include: binary %s includes too many scripts (%u > %u)",
260
 
                        sieve_binary_path(sbin), depcount, EXT_INCLUDE_MAX_INCLUDES); 
 
260
                        sieve_binary_path(sbin), depcount, EXT_INCLUDE_MAX_INCLUDES);
261
261
                return FALSE;
262
262
        }
263
 
        
 
263
 
264
264
        /* Read dependencies */
265
265
        for ( i = 0; i < depcount; i++ ) {
266
266
                unsigned int block_id;
268
268
                string_t *script_name;
269
269
                const char *script_dir;
270
270
                struct sieve_script *script;
271
 
                
272
 
                if ( 
 
271
 
 
272
                if (
273
273
                        !sieve_binary_read_unsigned(sbin, &offset, &block_id) ||
274
274
                        !sieve_binary_read_byte(sbin, &offset, &location) ||
275
275
                        !sieve_binary_read_string(sbin, &offset, &script_name) ) {
276
276
                        /* Binary is corrupt, recompile */
277
277
                        sieve_sys_error("include: failed to read included script "
278
 
                                "from dependency block %d of binary %s", block, sieve_binary_path(sbin)); 
 
278
                                "from dependency block %d of binary %s", block, sieve_binary_path(sbin));
279
279
                        return FALSE;
280
280
                }
281
 
                
 
281
 
282
282
                if ( location >= EXT_INCLUDE_LOCATION_INVALID ) {
283
283
                        /* Binary is corrupt, recompile */
284
284
                        sieve_sys_error("include: dependency block %d of binary %s "
285
 
                                "reports invalid script location (id %d)", 
286
 
                                block, sieve_binary_path(sbin), location); 
 
285
                                "reports invalid script location (id %d)",
 
286
                                block, sieve_binary_path(sbin), location);
287
287
                        return FALSE;
288
 
                }               
289
 
                
 
288
                }
 
289
 
290
290
                /* Can we find/open the script dependency ? */
291
291
                script_dir = ext_include_get_script_directory
292
 
                        (ext, location, str_c(script_name));            
293
 
                if ( script_dir == NULL || 
 
292
                        (ext, location, str_c(script_name));
 
293
                if ( script_dir == NULL ||
294
294
                        !(script=sieve_script_create_in_directory
295
295
                                (ext->svinst, script_dir, str_c(script_name), NULL, NULL)) ) {
296
296
                        /* No, recompile */
297
297
                        return FALSE;
298
298
                }
299
 
                
 
299
 
300
300
                (void)ext_include_binary_script_include(binctx, script, location, block_id);
301
 
                                
 
301
 
302
302
                sieve_script_unref(&script);
303
303
        }
304
304
 
305
305
        if ( !ext_include_variables_load
306
306
                (ext, sbin, &offset, block, &binctx->global_vars) )
307
307
                return FALSE;
308
 
        
 
308
 
309
309
        /* Restore previously active block */
310
310
        (void)sieve_binary_block_set_active(sbin, prvblk, NULL);
311
311
 
312
 
        return TRUE;    
 
312
        return TRUE;
313
313
}
314
314
 
315
315
static bool ext_include_binary_up_to_date
316
 
(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_binary *sbin, 
 
316
(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_binary *sbin,
317
317
        void *context)
318
318
{
319
 
        struct ext_include_binary_context *binctx = 
 
319
        struct ext_include_binary_context *binctx =
320
320
                (struct ext_include_binary_context *) context;
321
321
        struct hash_iterate_context *hctx;
322
322
        void *key, *value;
323
 
                
 
323
 
324
324
        /* Check all included scripts for changes */
325
325
        hctx = hash_table_iterate_init(binctx->included_scripts);
326
326
        while ( hash_table_iterate(hctx, &key, &value) ) {
327
 
                struct ext_include_script_info *incscript = 
 
327
                struct ext_include_script_info *incscript =
328
328
                        (struct ext_include_script_info *) value;
329
 
                
 
329
 
330
330
                /* Is the binary old than this dependency? */
331
331
                if ( sieve_binary_script_newer(sbin, incscript->script) ) {
332
332
                        /* No, recompile */
339
339
}
340
340
 
341
341
static void ext_include_binary_free
342
 
(const struct sieve_extension *ext ATTR_UNUSED, 
 
342
(const struct sieve_extension *ext ATTR_UNUSED,
343
343
        struct sieve_binary *sbin ATTR_UNUSED, void *context)
344
344
{
345
 
        struct ext_include_binary_context *binctx = 
 
345
        struct ext_include_binary_context *binctx =
346
346
                (struct ext_include_binary_context *) context;
347
347
        struct hash_iterate_context *hctx;
348
348
        void *key, *value;
349
 
                
 
349
 
350
350
        /* Release references to all included script objects */
351
351
        hctx = hash_table_iterate_init(binctx->included_scripts);
352
352
        while ( hash_table_iterate(hctx, &key, &value) ) {
353
 
                struct ext_include_script_info *incscript = 
 
353
                struct ext_include_script_info *incscript =
354
354
                        (struct ext_include_script_info *) value;
355
 
                
 
355
 
356
356
                sieve_script_unref(&incscript->script);
357
357
        }
358
358
        hash_table_iterate_deinit(&hctx);
359
359
 
360
360
        hash_table_destroy(&binctx->included_scripts);
361
361
 
362
 
        if ( binctx->global_vars != NULL ) 
 
362
        if ( binctx->global_vars != NULL )
363
363
                sieve_variable_scope_unref(&binctx->global_vars);
364
364
}
365
365
 
366
366
/*
367
 
 * Dumping the binary 
 
367
 * Dumping the binary
368
368
 */
369
369
 
370
370
bool ext_include_binary_dump
371
371
(const struct sieve_extension *ext, struct sieve_dumptime_env *denv)
372
372
{
373
373
        struct sieve_binary *sbin = denv->sbin;
374
 
        struct ext_include_binary_context *binctx = 
 
374
        struct ext_include_binary_context *binctx =
375
375
                ext_include_binary_get_context(ext, sbin);
376
376
        struct hash_iterate_context *hctx;
377
377
        void *key, *value;
380
380
        if ( !ext_include_variables_dump(denv, binctx->global_vars) )
381
381
                return FALSE;
382
382
 
383
 
        hctx = hash_table_iterate_init(binctx->included_scripts);               
 
383
        hctx = hash_table_iterate_init(binctx->included_scripts);
384
384
        while ( hash_table_iterate(hctx, &key, &value) ) {
385
 
                struct ext_include_script_info *incscript = 
 
385
                struct ext_include_script_info *incscript =
386
386
                        (struct ext_include_script_info *) value;
387
387
 
388
 
                sieve_binary_dump_sectionf(denv, "Included %s script '%s' (block: %d)", 
389
 
                        ext_include_script_location_name(incscript->location), 
 
388
                sieve_binary_dump_sectionf(denv, "Included %s script '%s' (block: %d)",
 
389
                        ext_include_script_location_name(incscript->location),
390
390
                        sieve_script_name(incscript->script), incscript->block_id);
391
 
                        
 
391
 
392
392
                if ( prvblk == 0 ) {
393
 
                        if ( !sieve_binary_block_set_active(sbin, incscript->block_id, &prvblk) )       
 
393
                        if ( !sieve_binary_block_set_active(sbin, incscript->block_id, &prvblk) )
394
394
                                return FALSE;
395
395
                } else {
396
 
                        if ( !sieve_binary_block_set_active(sbin, incscript->block_id, NULL) )  
 
396
                        if ( !sieve_binary_block_set_active(sbin, incscript->block_id, NULL) )
397
397
                                return FALSE;
398
398
                }
399
 
                                
 
399
 
400
400
                denv->cdumper = sieve_code_dumper_create(denv);
401
401
 
402
402
                if ( denv->cdumper == NULL )
405
405
                sieve_code_dumper_run(denv->cdumper);
406
406
                sieve_code_dumper_free(&(denv->cdumper));
407
407
        }
408
 
        
409
 
        if ( !sieve_binary_block_set_active(sbin, prvblk, NULL) ) 
 
408
 
 
409
        if ( !sieve_binary_block_set_active(sbin, prvblk, NULL) )
410
410
                return FALSE;
411
 
        
 
411
 
412
412
        hash_table_iterate_deinit(&hctx);
413
 
        
 
413
 
414
414
        return TRUE;
415
415
}
416
416
 
417
417
bool ext_include_code_dump
418
 
(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, 
 
418
(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv,
419
419
        sieve_size_t *address ATTR_UNUSED)
420
420
{
421
421
        struct sieve_binary *sbin = denv->sbin;
422
 
        struct ext_include_binary_context *binctx = 
 
422
        struct ext_include_binary_context *binctx =
423
423
                ext_include_binary_get_context(ext, sbin);
424
424
        struct ext_include_context *ectx = ext_include_get_context(ext);
425
 
        
 
425
 
426
426
        sieve_ext_variables_dump_set_scope
427
427
                (ectx->var_ext, denv, ext, binctx->global_vars);
428
428