~ubuntu-branches/ubuntu/precise/dovecot/precise-updates

« back to all changes in this revision

Viewing changes to pigeonhole/src/lib-sieve/sieve-binary-dumper.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-04-04 14:56:38 UTC
  • mfrom: (1.15.1) (4.1.26 sid)
  • Revision ID: package-import@ubuntu.com-20120404145638-qmvdul6vwpcqparv
Tags: 1:2.0.19-0ubuntu1
* New upstream release (LP: #970782).
* Merge from Debian testing, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/{control,rules}: enable PIE hardening.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst:
      Convert init script to upstart.
  + d/patches/fix-racey-restart.patch: Backported patch from current
    development release which ensures all child processes terminate prior
    to the main dovecot process.
  + debian/patches/CVE-2011-4318.patch: Dropped - applied upstream
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
* d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002-2011 Pigeonhole authors, see the included COPYING file
 
1
/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file
2
2
 */
3
3
 
4
4
#include "lib.h"
15
15
 
16
16
/*
17
17
 * Binary dumper object
18
 
 */
19
 
 
 
18
 */ 
 
19
 
20
20
struct sieve_binary_dumper {
21
21
        pool_t pool;
22
 
 
 
22
        
23
23
        /* Dumptime environment */
24
 
        struct sieve_dumptime_env dumpenv;
 
24
        struct sieve_dumptime_env dumpenv; 
25
25
};
26
26
 
27
27
struct sieve_binary_dumper *sieve_binary_dumper_create
28
 
(struct sieve_binary *sbin)
 
28
(struct sieve_binary *sbin) 
29
29
{
30
30
        pool_t pool;
31
31
        struct sieve_binary_dumper *dumper;
32
 
 
33
 
        pool = pool_alloconly_create("sieve_binary_dumper", 4096);
 
32
        
 
33
        pool = pool_alloconly_create("sieve_binary_dumper", 4096);      
34
34
        dumper = p_new(pool, struct sieve_binary_dumper, 1);
35
35
        dumper->pool = pool;
36
36
        dumper->dumpenv.dumper = dumper;
37
 
 
 
37
        
38
38
        dumper->dumpenv.sbin = sbin;
39
39
        sieve_binary_ref(sbin);
40
 
 
 
40
        
41
41
        dumper->dumpenv.svinst = sieve_binary_svinst(sbin);
42
42
 
43
43
        return dumper;
44
44
}
45
45
 
46
 
void sieve_binary_dumper_free(struct sieve_binary_dumper **dumper)
 
46
void sieve_binary_dumper_free(struct sieve_binary_dumper **dumper) 
47
47
{
48
48
        sieve_binary_unref(&(*dumper)->dumpenv.sbin);
49
49
        pool_unref(&((*dumper)->pool));
50
 
 
 
50
        
51
51
        *dumper = NULL;
52
52
}
53
53
 
56
56
        return dumper->pool;
57
57
}
58
58
 
59
 
/*
60
 
 * Formatted output
 
59
/* 
 
60
 * Formatted output 
61
61
 */
62
62
 
63
63
void sieve_binary_dumpf
64
64
(const struct sieve_dumptime_env *denv, const char *fmt, ...)
65
 
{
 
65
66
66
        string_t *outbuf = t_str_new(128);
67
67
        va_list args;
68
 
 
69
 
        va_start(args, fmt);
 
68
        
 
69
        va_start(args, fmt);                    
70
70
        str_vprintfa(outbuf, fmt, args);
71
71
        va_end(args);
72
 
 
 
72
        
73
73
        o_stream_send(denv->stream, str_data(outbuf), str_len(outbuf));
74
74
}
75
75
 
78
78
{
79
79
        string_t *outbuf = t_str_new(128);
80
80
        va_list args;
81
 
 
82
 
        va_start(args, fmt);
 
81
        
 
82
        va_start(args, fmt);                    
83
83
        str_printfa(outbuf, "\n* ");
84
84
        str_vprintfa(outbuf, fmt, args);
85
85
        str_printfa(outbuf, ":\n\n");
86
86
        va_end(args);
87
 
 
 
87
        
88
88
        o_stream_send(denv->stream, str_data(outbuf), str_len(outbuf));
89
89
}
90
90
 
91
 
/*
 
91
/* 
92
92
 * Dumping the binary
93
93
 */
94
94
 
95
95
bool sieve_binary_dumper_run
96
 
(struct sieve_binary_dumper *dumper, struct ostream *stream, bool verbose)
97
 
{
 
96
(struct sieve_binary_dumper *dumper, struct ostream *stream, bool verbose) 
 
97
{       
98
98
        struct sieve_binary *sbin = dumper->dumpenv.sbin;
99
99
        struct sieve_dumptime_env *denv = &(dumper->dumpenv);
100
100
        int count, i;
101
 
 
 
101
        
102
102
        dumper->dumpenv.stream = stream;
103
103
 
104
104
        /* Dump list of binary blocks */
111
111
                for ( i = 0; i < count; i++ ) {
112
112
                        struct sieve_binary_block *sblock = sieve_binary_block_get(sbin, i);
113
113
 
114
 
                        sieve_binary_dumpf(denv,
115
 
                                "%3d: size: %"PRIuSIZE_T" bytes\n", i,
 
114
                        sieve_binary_dumpf(denv, 
 
115
                                "%3d: size: %"PRIuSIZE_T" bytes\n", i, 
116
116
                                sieve_binary_block_get_size(sblock));
117
117
                }
118
118
        }
119
 
 
 
119
        
120
120
        /* Dump list of used extensions */
121
 
 
 
121
        
122
122
        count = sieve_binary_extensions_count(sbin);
123
123
        if ( count > 0 ) {
124
124
                sieve_binary_dump_sectionf
125
125
                        (denv, "Required extensions (block: %d)", SBIN_SYSBLOCK_EXTENSIONS);
126
 
 
 
126
        
127
127
                for ( i = 0; i < count; i++ ) {
128
128
                        const struct sieve_extension *ext = sieve_binary_extension_get_by_index
129
129
                                (sbin, i);
130
130
 
131
131
                        struct sieve_binary_block *sblock = sieve_binary_extension_get_block
132
132
                                (sbin, ext);
133
 
 
 
133
        
134
134
                        if ( sblock == NULL ) {
135
 
                                sieve_binary_dumpf(denv, "%3d: %s (id: %d)\n",
 
135
                                sieve_binary_dumpf(denv, "%3d: %s (id: %d)\n", 
136
136
                                        i, sieve_extension_name(ext), ext->id);
137
137
                        } else {
138
 
                                sieve_binary_dumpf(denv, "%3d: %s (id: %d; block: %d)\n",
139
 
                                        i, sieve_extension_name(ext), ext->id,
 
138
                                sieve_binary_dumpf(denv, "%3d: %s (id: %d; block: %d)\n", 
 
139
                                        i, sieve_extension_name(ext), ext->id, 
140
140
                                        sieve_binary_block_get_id(sblock));
141
141
                        }
142
142
                }
143
143
        }
144
144
 
145
145
        /* Dump extension-specific elements of the binary */
146
 
 
 
146
        
147
147
        count = sieve_binary_extensions_count(sbin);
148
 
        if ( count > 0 ) {
 
148
        if ( count > 0 ) {      
149
149
                for ( i = 0; i < count; i++ ) {
150
150
                        bool success = TRUE;
151
151
 
152
 
                        T_BEGIN {
 
152
                        T_BEGIN { 
153
153
                                const struct sieve_extension *ext = sieve_binary_extension_get_by_index
154
154
                                        (sbin, i);
155
 
 
156
 
                                if ( ext->def != NULL && ext->def->binary_dump != NULL ) {
 
155
        
 
156
                                if ( ext->def != NULL && ext->def->binary_dump != NULL ) {      
157
157
                                        success = ext->def->binary_dump(ext, denv);
158
158
                                }
159
159
                        } T_END;
161
161
                        if ( !success ) return FALSE;
162
162
                }
163
163
        }
164
 
 
 
164
        
165
165
        /* Dump main program */
166
 
 
 
166
        
167
167
        sieve_binary_dump_sectionf
168
168
                (denv, "Main program (block: %d)", SBIN_SYSBLOCK_MAIN_PROGRAM);
169
169
 
170
 
        dumper->dumpenv.sblock =
 
170
        dumper->dumpenv.sblock = 
171
171
                sieve_binary_block_get(sbin, SBIN_SYSBLOCK_MAIN_PROGRAM);
172
172
        dumper->dumpenv.cdumper = sieve_code_dumper_create(&(dumper->dumpenv));
173
173
 
174
174
        if ( dumper->dumpenv.cdumper != NULL ) {
175
175
                sieve_code_dumper_run(dumper->dumpenv.cdumper);
176
 
 
 
176
                
177
177
                sieve_code_dumper_free(&dumper->dumpenv.cdumper);
178
178
        }
179
 
 
 
179
        
180
180
        /* Finish with empty line */
181
181
        sieve_binary_dumpf(denv, "\n");
182
182
 
193
193
        struct sieve_binary *sbin = dumper->dumpenv.sbin;
194
194
        struct sieve_dumptime_env *denv = &(dumper->dumpenv);
195
195
        int count, i;
196
 
 
 
196
        
197
197
        dumper->dumpenv.stream = stream;
198
198
 
199
199
        count = sieve_binary_block_count(sbin);
206
206
        for ( i = 0; i < count; i++ ) {
207
207
                struct sieve_binary_block *sblock = sieve_binary_block_get(sbin, i);
208
208
 
209
 
                sieve_binary_dumpf(denv,
210
 
                        "%3d: size: %"PRIuSIZE_T" bytes\n", i,
 
209
                sieve_binary_dumpf(denv, 
 
210
                        "%3d: size: %"PRIuSIZE_T" bytes\n", i, 
211
211
                        sieve_binary_block_get_size(sblock));
212
212
        }
213
213
 
222
222
                size_t offset;
223
223
 
224
224
                data = (const char *) buffer_get_data(blockbuf, &data_size);
225
 
 
 
225
                
226
226
                sieve_binary_dump_sectionf
227
 
                        (denv, "Block %d (%"PRIuSIZE_T" bytes, file offset %08llx)", i,
 
227
                        (denv, "Block %d (%"PRIuSIZE_T" bytes, file offset %08llx)", i, 
228
228
                                data_size, sblock->offset + 8 /* header size (yuck) */);
229
229
 
230
230
                line = t_str_new(128);
236
236
                        str_printfa(line, "%08llx  ", (unsigned long long) offset);
237
237
 
238
238
                        for ( b = 0; b < len; b++ ) {
239
 
                                str_printfa(line, "%02x ", (unsigned int) data[offset+b]);
 
239
                                str_printfa(line, "%02x ", (unsigned int) data[offset+b]);      
240
240
                                if ( b == 7 ) str_append_c(line, ' ');
241
241
                        }
242
242
 
264
264
                        str_truncate(line, 0);
265
265
                        offset += len;
266
266
                }
267
 
 
 
267
                
268
268
                str_printfa(line, "%08llx\n", (unsigned long long) offset);
269
269
                o_stream_send(stream, str_data(line), str_len(line));
270
270
        }
271
 
}
 
271
 
272