1 /*	$NetBSD: cleanup_init.c,v 1.7 2022/10/08 16:12:45 christos Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	cleanup_init 3
6 /* SUMMARY
7 /*	cleanup callable interface, initializations
8 /* SYNOPSIS
9 /*	#include "cleanup.h"
10 /*
11 /*	CONFIG_BOOL_TABLE cleanup_bool_table[];
12 /*
13 /*	CONFIG_INT_TABLE cleanup_int_table[];
14 /*
15 /*	CONFIG_BOOL_TABLE cleanup_bool_table[];
16 /*
17 /*	CONFIG_STR_TABLE cleanup_str_table[];
18 /*
19 /*	CONFIG_TIME_TABLE cleanup_time_table[];
20 /*
21 /*	void	cleanup_pre_jail(service_name, argv)
22 /*	char	*service_name;
23 /*	char	**argv;
24 /*
25 /*	void	cleanup_post_jail(service_name, argv)
26 /*	char	*service_name;
27 /*	char	**argv;
28 /*
29 /*	char	*cleanup_path;
30 /*	VSTRING	*cleanup_trace_path;
31 /*
32 /*	void	cleanup_all()
33 /*
34 /*	void	cleanup_sig(sigval)
35 /*	int	sigval;
36 /* DESCRIPTION
37 /*	This module implements a callable interface to the cleanup service
38 /*	for one-time initializations that must be done before any message
39 /*	processing can take place.
40 /*
41 /*	cleanup_{bool,int,str,time}_table[] specify configuration
42 /*	parameters that must be initialized before calling any functions
43 /*	in this module. These tables satisfy the interface as specified in
44 /*	single_service(3).
45 /*
46 /*	cleanup_pre_jail() and cleanup_post_jail() perform mandatory
47 /*	initializations before and after the process enters the optional
48 /*	chroot jail. These functions satisfy the interface as specified
49 /*	in single_service(3).
50 /*
51 /*	cleanup_path is either a null pointer or it is the name of a queue
52 /*	file that currently is being written. This information is used
53 /*	by cleanup_all() to remove incomplete files after a fatal error,
54 /*	or by cleanup_sig() after arrival of a SIGTERM signal.
55 /*
56 /*	cleanup_trace_path is either a null pointer or the pathname of a
57 /*	trace logfile with DSN SUCCESS notifications. This information is
58 /*	used to remove a trace file when the mail transaction is canceled.
59 /*
60 /*	cleanup_all() must be called in case of fatal error, in order
61 /*	to remove an incomplete queue file.
62 /*
63 /*	cleanup_sig() must be called in case of SIGTERM, in order
64 /*	to remove an incomplete queue file.
65 /* DIAGNOSTICS
66 /*	Problems and transactions are logged to \fBsyslogd\fR(8)
67 /*	or \fBpostlogd\fR(8).
68 /* SEE ALSO
69 /*	cleanup_api(3) cleanup callable interface, message processing
70 /* LICENSE
71 /* .ad
72 /* .fi
73 /*	The Secure Mailer license must be distributed with this software.
74 /* AUTHOR(S)
75 /*	Wietse Venema
76 /*	IBM T.J. Watson Research
77 /*	P.O. Box 704
78 /*	Yorktown Heights, NY 10598, USA
79 /*
80 /*	Wietse Venema
81 /*	Google, Inc.
82 /*	111 8th Avenue
83 /*	New York, NY 10011, USA
84 /*--*/
85 
86 /* System library. */
87 
88 #include <sys_defs.h>
89 #include <signal.h>
90 #include <string.h>
91 
92 /* Utility library. */
93 
94 #include <msg.h>
95 #include <iostuff.h>
96 #include <name_code.h>
97 #include <name_mask.h>
98 #include <stringops.h>
99 
100 /* Global library. */
101 
102 #include <mail_addr.h>
103 #include <mail_params.h>
104 #include <mail_version.h>		/* milter_macro_v */
105 #include <ext_prop.h>
106 #include <flush_clnt.h>
107 #include <hfrom_format.h>
108 
109 /* Application-specific. */
110 
111 #include "cleanup.h"
112 
113  /*
114   * Global state: any queue files that we have open, so that the error
115   * handler can clean up in case of trouble.
116   */
117 char   *cleanup_path;			/* queue file name */
118 
119  /*
120   * Another piece of global state: pathnames of partial bounce or trace
121   * logfiles that need to be cleaned up when the cleanup request is aborted.
122   */
123 VSTRING *cleanup_trace_path;
124 
125  /*
126   * Tunable parameters.
127   */
128 int     var_hopcount_limit;		/* max mailer hop count */
129 char   *var_canonical_maps;		/* common canonical maps */
130 char   *var_send_canon_maps;		/* sender canonical maps */
131 char   *var_rcpt_canon_maps;		/* recipient canonical maps */
132 char   *var_canon_classes;		/* what to canonicalize */
133 char   *var_send_canon_classes;		/* what sender to canonicalize */
134 char   *var_rcpt_canon_classes;		/* what recipient to canonicalize */
135 char   *var_virt_alias_maps;		/* virtual alias maps */
136 char   *var_masq_domains;		/* masquerade domains */
137 char   *var_masq_exceptions;		/* users not masqueraded */
138 char   *var_header_checks;		/* primary header checks */
139 char   *var_mimehdr_checks;		/* mime header checks */
140 char   *var_nesthdr_checks;		/* nested header checks */
141 char   *var_body_checks;		/* any body checks */
142 int     var_dup_filter_limit;		/* recipient dup filter */
143 char   *var_empty_addr;			/* destination of bounced bounces */
144 int     var_delay_warn_time;		/* delay that triggers warning */
145 char   *var_prop_extension;		/* propagate unmatched extension */
146 char   *var_always_bcc;			/* big brother */
147 char   *var_rcpt_witheld;		/* recipients not disclosed */
148 bool    var_canon_env_rcpt;		/* canonicalize envelope recipient */
149 char   *var_masq_classes;		/* what to masquerade */
150 int     var_qattr_count_limit;		/* named attribute limit */
151 int     var_virt_recur_limit;		/* maximum virtual alias recursion */
152 int     var_virt_expan_limit;		/* maximum virtual alias expansion */
153 int     var_body_check_len;		/* when to stop body scan */
154 char   *var_send_bcc_maps;		/* sender auto-bcc maps */
155 char   *var_rcpt_bcc_maps;		/* recipient auto-bcc maps */
156 char   *var_remote_rwr_domain;		/* header-only surrogate */
157 char   *var_msg_reject_chars;		/* reject these characters */
158 char   *var_msg_strip_chars;		/* strip these characters */
159 int     var_verp_bounce_off;		/* don't verp the bounces */
160 int     var_milt_conn_time;		/* milter connect/handshake timeout */
161 int     var_milt_cmd_time;		/* milter command timeout */
162 int     var_milt_msg_time;		/* milter content timeout */
163 char   *var_milt_protocol;		/* Sendmail 8 milter protocol */
164 char   *var_milt_def_action;		/* default milter action */
165 char   *var_milt_daemon_name;		/* {daemon_name} macro value */
166 char   *var_milt_v;			/* {v} macro value */
167 char   *var_milt_conn_macros;		/* connect macros */
168 char   *var_milt_helo_macros;		/* HELO macros */
169 char   *var_milt_mail_macros;		/* MAIL FROM macros */
170 char   *var_milt_rcpt_macros;		/* RCPT TO macros */
171 char   *var_milt_data_macros;		/* DATA macros */
172 char   *var_milt_eoh_macros;		/* end-of-header macros */
173 char   *var_milt_eod_macros;		/* end-of-data macros */
174 char   *var_milt_unk_macros;		/* unknown command macros */
175 char   *var_cleanup_milters;		/* non-SMTP mail */
176 char   *var_milt_head_checks;		/* post-Milter header checks */
177 char   *var_milt_macro_deflts;		/* default macro settings */
178 int     var_auto_8bit_enc_hdr;		/* auto-detect 8bit encoding header */
179 int     var_always_add_hdrs;		/* always add missing headers */
180 int     var_virt_addrlen_limit;		/* stop exponential growth */
181 char   *var_hfrom_format;		/* header_from_format */
182 
183 const CONFIG_INT_TABLE cleanup_int_table[] = {
184     VAR_HOPCOUNT_LIMIT, DEF_HOPCOUNT_LIMIT, &var_hopcount_limit, 1, 0,
185     VAR_DUP_FILTER_LIMIT, DEF_DUP_FILTER_LIMIT, &var_dup_filter_limit, 0, 0,
186     VAR_QATTR_COUNT_LIMIT, DEF_QATTR_COUNT_LIMIT, &var_qattr_count_limit, 1, 0,
187     VAR_VIRT_RECUR_LIMIT, DEF_VIRT_RECUR_LIMIT, &var_virt_recur_limit, 1, 0,
188     VAR_VIRT_EXPAN_LIMIT, DEF_VIRT_EXPAN_LIMIT, &var_virt_expan_limit, 1, 0,
189     VAR_VIRT_ADDRLEN_LIMIT, DEF_VIRT_ADDRLEN_LIMIT, &var_virt_addrlen_limit, 1, 0,
190     VAR_BODY_CHECK_LEN, DEF_BODY_CHECK_LEN, &var_body_check_len, 0, 0,
191     0,
192 };
193 
194 const CONFIG_BOOL_TABLE cleanup_bool_table[] = {
195     VAR_VERP_BOUNCE_OFF, DEF_VERP_BOUNCE_OFF, &var_verp_bounce_off,
196     VAR_AUTO_8BIT_ENC_HDR, DEF_AUTO_8BIT_ENC_HDR, &var_auto_8bit_enc_hdr,
197     VAR_ALWAYS_ADD_HDRS, DEF_ALWAYS_ADD_HDRS, &var_always_add_hdrs,
198     0,
199 };
200 
201 const CONFIG_TIME_TABLE cleanup_time_table[] = {
202     VAR_DELAY_WARN_TIME, DEF_DELAY_WARN_TIME, &var_delay_warn_time, 0, 0,
203     VAR_MILT_CONN_TIME, DEF_MILT_CONN_TIME, &var_milt_conn_time, 1, 0,
204     VAR_MILT_CMD_TIME, DEF_MILT_CMD_TIME, &var_milt_cmd_time, 1, 0,
205     VAR_MILT_MSG_TIME, DEF_MILT_MSG_TIME, &var_milt_msg_time, 1, 0,
206     0,
207 };
208 
209 const CONFIG_STR_TABLE cleanup_str_table[] = {
210     VAR_CANONICAL_MAPS, DEF_CANONICAL_MAPS, &var_canonical_maps, 0, 0,
211     VAR_SEND_CANON_MAPS, DEF_SEND_CANON_MAPS, &var_send_canon_maps, 0, 0,
212     VAR_RCPT_CANON_MAPS, DEF_RCPT_CANON_MAPS, &var_rcpt_canon_maps, 0, 0,
213     VAR_CANON_CLASSES, DEF_CANON_CLASSES, &var_canon_classes, 1, 0,
214     VAR_SEND_CANON_CLASSES, DEF_SEND_CANON_CLASSES, &var_send_canon_classes, 1, 0,
215     VAR_RCPT_CANON_CLASSES, DEF_RCPT_CANON_CLASSES, &var_rcpt_canon_classes, 1, 0,
216     VAR_VIRT_ALIAS_MAPS, DEF_VIRT_ALIAS_MAPS, &var_virt_alias_maps, 0, 0,
217     VAR_MASQ_DOMAINS, DEF_MASQ_DOMAINS, &var_masq_domains, 0, 0,
218     VAR_EMPTY_ADDR, DEF_EMPTY_ADDR, &var_empty_addr, 1, 0,
219     VAR_MASQ_EXCEPTIONS, DEF_MASQ_EXCEPTIONS, &var_masq_exceptions, 0, 0,
220     VAR_HEADER_CHECKS, DEF_HEADER_CHECKS, &var_header_checks, 0, 0,
221     VAR_MIMEHDR_CHECKS, DEF_MIMEHDR_CHECKS, &var_mimehdr_checks, 0, 0,
222     VAR_NESTHDR_CHECKS, DEF_NESTHDR_CHECKS, &var_nesthdr_checks, 0, 0,
223     VAR_BODY_CHECKS, DEF_BODY_CHECKS, &var_body_checks, 0, 0,
224     VAR_PROP_EXTENSION, DEF_PROP_EXTENSION, &var_prop_extension, 0, 0,
225     VAR_ALWAYS_BCC, DEF_ALWAYS_BCC, &var_always_bcc, 0, 0,
226     VAR_RCPT_WITHELD, DEF_RCPT_WITHELD, &var_rcpt_witheld, 0, 0,
227     VAR_MASQ_CLASSES, DEF_MASQ_CLASSES, &var_masq_classes, 0, 0,
228     VAR_SEND_BCC_MAPS, DEF_SEND_BCC_MAPS, &var_send_bcc_maps, 0, 0,
229     VAR_RCPT_BCC_MAPS, DEF_RCPT_BCC_MAPS, &var_rcpt_bcc_maps, 0, 0,
230     VAR_REM_RWR_DOMAIN, DEF_REM_RWR_DOMAIN, &var_remote_rwr_domain, 0, 0,
231     VAR_MSG_REJECT_CHARS, DEF_MSG_REJECT_CHARS, &var_msg_reject_chars, 0, 0,
232     VAR_MSG_STRIP_CHARS, DEF_MSG_STRIP_CHARS, &var_msg_strip_chars, 0, 0,
233     VAR_MILT_PROTOCOL, DEF_MILT_PROTOCOL, &var_milt_protocol, 1, 0,
234     VAR_MILT_DEF_ACTION, DEF_MILT_DEF_ACTION, &var_milt_def_action, 1, 0,
235     VAR_MILT_DAEMON_NAME, DEF_MILT_DAEMON_NAME, &var_milt_daemon_name, 1, 0,
236     VAR_MILT_V, DEF_MILT_V, &var_milt_v, 1, 0,
237     VAR_MILT_CONN_MACROS, DEF_MILT_CONN_MACROS, &var_milt_conn_macros, 0, 0,
238     VAR_MILT_HELO_MACROS, DEF_MILT_HELO_MACROS, &var_milt_helo_macros, 0, 0,
239     VAR_MILT_MAIL_MACROS, DEF_MILT_MAIL_MACROS, &var_milt_mail_macros, 0, 0,
240     VAR_MILT_RCPT_MACROS, DEF_MILT_RCPT_MACROS, &var_milt_rcpt_macros, 0, 0,
241     VAR_MILT_DATA_MACROS, DEF_MILT_DATA_MACROS, &var_milt_data_macros, 0, 0,
242     VAR_MILT_EOH_MACROS, DEF_MILT_EOH_MACROS, &var_milt_eoh_macros, 0, 0,
243     VAR_MILT_EOD_MACROS, DEF_MILT_EOD_MACROS, &var_milt_eod_macros, 0, 0,
244     VAR_MILT_UNK_MACROS, DEF_MILT_UNK_MACROS, &var_milt_unk_macros, 0, 0,
245     VAR_CLEANUP_MILTERS, DEF_CLEANUP_MILTERS, &var_cleanup_milters, 0, 0,
246     VAR_MILT_HEAD_CHECKS, DEF_MILT_HEAD_CHECKS, &var_milt_head_checks, 0, 0,
247     VAR_MILT_MACRO_DEFLTS, DEF_MILT_MACRO_DEFLTS, &var_milt_macro_deflts, 0, 0,
248     VAR_HFROM_FORMAT, DEF_HFROM_FORMAT, &var_hfrom_format, 1, 0,
249     0,
250 };
251 
252  /*
253   * Mappings.
254   */
255 MAPS   *cleanup_comm_canon_maps;
256 MAPS   *cleanup_send_canon_maps;
257 MAPS   *cleanup_rcpt_canon_maps;
258 int     cleanup_comm_canon_flags;
259 int     cleanup_send_canon_flags;
260 int     cleanup_rcpt_canon_flags;
261 MAPS   *cleanup_header_checks;
262 MAPS   *cleanup_mimehdr_checks;
263 MAPS   *cleanup_nesthdr_checks;
264 MAPS   *cleanup_body_checks;
265 MAPS   *cleanup_virt_alias_maps;
266 ARGV   *cleanup_masq_domains;
267 STRING_LIST *cleanup_masq_exceptions;
268 int     cleanup_masq_flags;
269 MAPS   *cleanup_send_bcc_maps;
270 MAPS   *cleanup_rcpt_bcc_maps;
271 
272  /*
273   * Character filters.
274   */
275 VSTRING *cleanup_reject_chars;
276 VSTRING *cleanup_strip_chars;
277 
278  /*
279   * Address extension propagation restrictions.
280   */
281 int     cleanup_ext_prop_mask;
282 
283  /*
284   * Milter support.
285   */
286 MILTERS *cleanup_milters;
287 
288  /*
289   * From: header format.
290   */
291 int     cleanup_hfrom_format;
292 
293 /* cleanup_all - callback for the runtime error handler */
294 
cleanup_all(void)295 void    cleanup_all(void)
296 {
297     cleanup_sig(0);
298 }
299 
300 /* cleanup_sig - callback for the SIGTERM handler */
301 
cleanup_sig(int sig)302 void    cleanup_sig(int sig)
303 {
304 
305     /*
306      * msg_fatal() is safe against calling itself recursively, but signals
307      * need extra safety.
308      *
309      * XXX While running as a signal handler, can't ask the memory manager to
310      * release VSTRING storage.
311      */
312     if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
313 	if (cleanup_trace_path) {
314 	    (void) REMOVE(vstring_str(cleanup_trace_path));
315 	    cleanup_trace_path = 0;
316 	}
317 	if (cleanup_path) {
318 	    (void) REMOVE(cleanup_path);
319 	    cleanup_path = 0;
320 	}
321 	if (sig)
322 	    _exit(sig);
323     }
324 }
325 
326 /* cleanup_pre_jail - initialize before entering the chroot jail */
327 
cleanup_pre_jail(char * unused_name,char ** unused_argv)328 void    cleanup_pre_jail(char *unused_name, char **unused_argv)
329 {
330     static const NAME_MASK send_canon_class_table[] = {
331 	CANON_CLASS_ENV_FROM, CLEANUP_CANON_FLAG_ENV_FROM,
332 	CANON_CLASS_HDR_FROM, CLEANUP_CANON_FLAG_HDR_FROM,
333 	0,
334     };
335     static const NAME_MASK rcpt_canon_class_table[] = {
336 	CANON_CLASS_ENV_RCPT, CLEANUP_CANON_FLAG_ENV_RCPT,
337 	CANON_CLASS_HDR_RCPT, CLEANUP_CANON_FLAG_HDR_RCPT,
338 	0,
339     };
340     static const NAME_MASK canon_class_table[] = {
341 	CANON_CLASS_ENV_FROM, CLEANUP_CANON_FLAG_ENV_FROM,
342 	CANON_CLASS_ENV_RCPT, CLEANUP_CANON_FLAG_ENV_RCPT,
343 	CANON_CLASS_HDR_FROM, CLEANUP_CANON_FLAG_HDR_FROM,
344 	CANON_CLASS_HDR_RCPT, CLEANUP_CANON_FLAG_HDR_RCPT,
345 	0,
346     };
347     static const NAME_MASK masq_class_table[] = {
348 	MASQ_CLASS_ENV_FROM, CLEANUP_MASQ_FLAG_ENV_FROM,
349 	MASQ_CLASS_ENV_RCPT, CLEANUP_MASQ_FLAG_ENV_RCPT,
350 	MASQ_CLASS_HDR_FROM, CLEANUP_MASQ_FLAG_HDR_FROM,
351 	MASQ_CLASS_HDR_RCPT, CLEANUP_MASQ_FLAG_HDR_RCPT,
352 	0,
353     };
354 
355     if (*var_canonical_maps)
356 	cleanup_comm_canon_maps =
357 	    maps_create(VAR_CANONICAL_MAPS, var_canonical_maps,
358 			DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
359 			| DICT_FLAG_UTF8_REQUEST);
360     if (*var_send_canon_maps)
361 	cleanup_send_canon_maps =
362 	    maps_create(VAR_SEND_CANON_MAPS, var_send_canon_maps,
363 			DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
364 			| DICT_FLAG_UTF8_REQUEST);
365     if (*var_rcpt_canon_maps)
366 	cleanup_rcpt_canon_maps =
367 	    maps_create(VAR_RCPT_CANON_MAPS, var_rcpt_canon_maps,
368 			DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
369 			| DICT_FLAG_UTF8_REQUEST);
370     if (*var_virt_alias_maps)
371 	cleanup_virt_alias_maps = maps_create(VAR_VIRT_ALIAS_MAPS,
372 					      var_virt_alias_maps,
373 					      DICT_FLAG_LOCK
374 					      | DICT_FLAG_FOLD_FIX
375 					      | DICT_FLAG_UTF8_REQUEST);
376     if (*var_canon_classes)
377 	cleanup_comm_canon_flags =
378 	    name_mask(VAR_CANON_CLASSES, canon_class_table,
379 		      var_canon_classes);
380     if (*var_send_canon_classes)
381 	cleanup_send_canon_flags =
382 	    name_mask(VAR_CANON_CLASSES, send_canon_class_table,
383 		      var_send_canon_classes);
384     if (*var_rcpt_canon_classes)
385 	cleanup_rcpt_canon_flags =
386 	    name_mask(VAR_CANON_CLASSES, rcpt_canon_class_table,
387 		      var_rcpt_canon_classes);
388     if (*var_masq_domains)
389 	cleanup_masq_domains = argv_split(var_masq_domains, CHARS_COMMA_SP);
390     if (*var_header_checks)
391 	cleanup_header_checks =
392 	    maps_create(VAR_HEADER_CHECKS, var_header_checks, DICT_FLAG_LOCK);
393     if (*var_mimehdr_checks)
394 	cleanup_mimehdr_checks =
395 	    maps_create(VAR_MIMEHDR_CHECKS, var_mimehdr_checks, DICT_FLAG_LOCK);
396     if (*var_nesthdr_checks)
397 	cleanup_nesthdr_checks =
398 	    maps_create(VAR_NESTHDR_CHECKS, var_nesthdr_checks, DICT_FLAG_LOCK);
399     if (*var_body_checks)
400 	cleanup_body_checks =
401 	    maps_create(VAR_BODY_CHECKS, var_body_checks, DICT_FLAG_LOCK);
402     if (*var_masq_exceptions)
403 	cleanup_masq_exceptions =
404 	    string_list_init(VAR_MASQ_EXCEPTIONS, MATCH_FLAG_RETURN,
405 			     var_masq_exceptions);
406     if (*var_masq_classes)
407 	cleanup_masq_flags = name_mask(VAR_MASQ_CLASSES, masq_class_table,
408 				       var_masq_classes);
409     if (*var_send_bcc_maps)
410 	cleanup_send_bcc_maps =
411 	    maps_create(VAR_SEND_BCC_MAPS, var_send_bcc_maps,
412 			DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
413 			| DICT_FLAG_UTF8_REQUEST);
414     if (*var_rcpt_bcc_maps)
415 	cleanup_rcpt_bcc_maps =
416 	    maps_create(VAR_RCPT_BCC_MAPS, var_rcpt_bcc_maps,
417 			DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
418 			| DICT_FLAG_UTF8_REQUEST);
419     if (*var_cleanup_milters)
420 	cleanup_milters = milter_create(var_cleanup_milters,
421 					var_milt_conn_time,
422 					var_milt_cmd_time,
423 					var_milt_msg_time,
424 					var_milt_protocol,
425 					var_milt_def_action,
426 					var_milt_conn_macros,
427 					var_milt_helo_macros,
428 					var_milt_mail_macros,
429 					var_milt_rcpt_macros,
430 					var_milt_data_macros,
431 					var_milt_eoh_macros,
432 					var_milt_eod_macros,
433 					var_milt_unk_macros,
434 					var_milt_macro_deflts);
435     if (*var_milt_head_checks)
436 	cleanup_milter_header_checks_init();
437 
438     flush_init();
439 }
440 
441 /* cleanup_post_jail - initialize after entering the chroot jail */
442 
cleanup_post_jail(char * unused_name,char ** unused_argv)443 void    cleanup_post_jail(char *unused_name, char **unused_argv)
444 {
445 
446     /*
447      * Optionally set the file size resource limit. XXX This limits the
448      * message content to somewhat less than requested, because the total
449      * queue file size also includes envelope information. Unless people set
450      * really low limit, the difference is going to matter only when a queue
451      * file has lots of recipients.
452      */
453     if (ENFORCING_SIZE_LIMIT(var_message_limit))
454 	set_file_limit((off_t) var_message_limit);
455 
456     /*
457      * Control how unmatched extensions are propagated.
458      */
459     cleanup_ext_prop_mask =
460 	ext_prop_mask(VAR_PROP_EXTENSION, var_prop_extension);
461 
462     /*
463      * Setup the filters for characters that should be rejected, and for
464      * characters that should be removed.
465      */
466     if (*var_msg_reject_chars) {
467 	cleanup_reject_chars = vstring_alloc(strlen(var_msg_reject_chars));
468 	unescape(cleanup_reject_chars, var_msg_reject_chars);
469     }
470     if (*var_msg_strip_chars) {
471 	cleanup_strip_chars = vstring_alloc(strlen(var_msg_strip_chars));
472 	unescape(cleanup_strip_chars, var_msg_strip_chars);
473     }
474 
475     /*
476      * From: header formatting.
477      */
478     cleanup_hfrom_format = hfrom_format_parse(VAR_HFROM_FORMAT, var_hfrom_format);
479 }
480