No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / mail_params.c
blobf7e27647432982bc4309fe1c747c7634db03525c
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* mail_params 3
6 /* SUMMARY
7 /* global mail configuration parameters
8 /* SYNOPSIS
9 /* #include <mail_params.h>
11 /* char *var_myhostname;
12 /* char *var_mydomain;
13 /* char *var_myorigin;
14 /* char *var_mydest;
15 /* char *var_relayhost;
16 /* char *var_transit_origin;
17 /* char *var_transit_dest;
18 /* char *var_mail_name;
19 /* int var_helpful_warnings;
20 /* char *var_syslog_name;
21 /* char *var_mail_owner;
22 /* uid_t var_owner_uid;
23 /* gid_t var_owner_gid;
24 /* char *var_sgid_group;
25 /* gid_t var_sgid_gid;
26 /* char *var_default_privs;
27 /* uid_t var_default_uid;
28 /* gid_t var_default_gid;
29 /* char *var_config_dir;
30 /* char *var_daemon_dir;
31 /* char *var_data_dir;
32 /* char *var_command_dir;
33 /* char *var_queue_dir;
34 /* int var_use_limit;
35 /* int var_idle_limit;
36 /* int var_event_drain;
37 /* int var_bundle_rcpt;
38 /* char *var_procname;
39 /* int var_pid;
40 /* int var_ipc_timeout;
41 /* char *var_pid_dir;
42 /* int var_dont_remove;
43 /* char *var_inet_interfaces;
44 /* char *var_proxy_interfaces;
45 /* char *var_inet_protocols;
46 /* char *var_mynetworks;
47 /* char *var_double_bounce_sender;
48 /* int var_line_limit;
49 /* char *var_alias_db_map;
50 /* int var_message_limit;
51 /* char *var_mail_release;
52 /* char *var_mail_version;
53 /* int var_ipc_idle_limit;
54 /* int var_ipc_ttl_limit;
55 /* char *var_db_type;
56 /* char *var_hash_queue_names;
57 /* int var_hash_queue_depth;
58 /* int var_trigger_timeout;
59 /* char *var_rcpt_delim;
60 /* int var_fork_tries;
61 /* int var_fork_delay;
62 /* int var_flock_tries;
63 /* int var_flock_delay;
64 /* int var_flock_stale;
65 /* int var_disable_dns;
66 /* int var_soft_bounce;
67 /* time_t var_starttime;
68 /* int var_ownreq_special;
69 /* int var_daemon_timeout;
70 /* char *var_syslog_facility;
71 /* char *var_relay_domains;
72 /* char *var_fflush_domains;
73 /* char *var_mynetworks_style;
74 /* char *var_verp_delims;
75 /* char *var_verp_filter;
76 /* char *var_par_dom_match;
77 /* char *var_config_dirs;
79 /* int var_inet_windowsize;
80 /* char *var_import_environ;
81 /* char *var_export_environ;
82 /* char *var_debug_peer_list;
83 /* int var_debug_peer_level;
84 /* int var_in_flow_delay;
85 /* int var_fault_inj_code;
86 /* char *var_bounce_service;
87 /* char *var_cleanup_service;
88 /* char *var_defer_service;
89 /* char *var_pickup_service;
90 /* char *var_queue_service;
91 /* char *var_rewrite_service;
92 /* char *var_showq_service;
93 /* char *var_error_service;
94 /* char *var_flush_service;
95 /* char *var_verify_service;
96 /* char *var_trace_service;
97 /* char *var_proxymap_service;
98 /* char *var_proxywrite_service;
99 /* int var_db_create_buf;
100 /* int var_db_read_buf;
101 /* int var_mime_maxdepth;
102 /* int var_mime_bound_len;
103 /* int var_header_limit;
104 /* int var_token_limit;
105 /* int var_disable_mime_input;
106 /* int var_disable_mime_oconv;
107 /* int var_strict_8bitmime;
108 /* int var_strict_7bit_hdrs;
109 /* int var_strict_8bit_body;
110 /* int var_strict_encoding;
111 /* int var_verify_neg_cache;
112 /* int var_oldlog_compat;
113 /* int var_delay_max_res;
114 /* char *var_int_filt_classes;
115 /* int var_cyrus_sasl_authzid;
117 /* char *var_multi_conf_dirs;
118 /* char *var_multi_wrapper;
119 /* char *var_multi_group;
120 /* char *var_multi_name;
121 /* bool var_multi_enable;
123 /* void mail_params_init()
125 /* const char null_format_string[1];
126 /* DESCRIPTION
127 /* This module (actually the associated include file) define the names
128 /* and defaults of all mail configuration parameters.
130 /* mail_params_init() initializes the built-in parameters listed above.
131 /* These parameters are relied upon by library routines, so they are
132 /* initialized globally so as to avoid hard-to-find errors due to
133 /* missing initialization. This routine must be called early, at
134 /* least before entering a chroot jail.
136 /* null_format_string is a workaround for gcc compilers that complain
137 /* about empty or null format strings.
138 /* DIAGNOSTICS
139 /* Fatal errors: out of memory; null system or domain name.
140 /* LICENSE
141 /* .ad
142 /* .fi
143 /* The Secure Mailer license must be distributed with this software.
144 /* AUTHOR(S)
145 /* Wietse Venema
146 /* IBM T.J. Watson Research
147 /* P.O. Box 704
148 /* Yorktown Heights, NY 10598, USA
149 /*--*/
151 /* System library. */
153 #include <sys_defs.h>
154 #include <unistd.h>
155 #include <stdlib.h>
156 #include <string.h>
157 #include <pwd.h>
158 #include <grp.h>
159 #include <time.h>
160 #include <ctype.h>
162 #ifdef STRCASECMP_IN_STRINGS_H
163 #include <strings.h>
164 #endif
166 /* Utility library. */
168 #include <msg.h>
169 #include <msg_syslog.h>
170 #include <get_hostname.h>
171 #include <valid_hostname.h>
172 #include <stringops.h>
173 #include <safe.h>
174 #include <safe_open.h>
175 #include <mymalloc.h>
176 #ifdef HAS_DB
177 #include <dict_db.h>
178 #endif
179 #include <inet_proto.h>
180 #include <vstring_vstream.h>
181 #include <iostuff.h>
183 /* Global library. */
185 #include <mynetworks.h>
186 #include <mail_conf.h>
187 #include <mail_version.h>
188 #include <mail_proto.h>
189 #include <verp_sender.h>
190 #include <own_inet_addr.h>
191 #include <mail_params.h>
194 * Special configuration variables.
196 char *var_myhostname;
197 char *var_mydomain;
198 char *var_myorigin;
199 char *var_mydest;
200 char *var_relayhost;
201 char *var_transit_origin;
202 char *var_transit_dest;
203 char *var_mail_name;
204 int var_helpful_warnings;
205 char *var_syslog_name;
206 char *var_mail_owner;
207 uid_t var_owner_uid;
208 gid_t var_owner_gid;
209 char *var_sgid_group;
210 gid_t var_sgid_gid;
211 char *var_default_privs;
212 uid_t var_default_uid;
213 gid_t var_default_gid;
214 char *var_config_dir;
215 char *var_daemon_dir;
216 char *var_data_dir;
217 char *var_command_dir;
218 char *var_queue_dir;
219 int var_use_limit;
220 int var_event_drain;
221 int var_idle_limit;
222 int var_bundle_rcpt;
223 char *var_procname;
224 int var_pid;
225 int var_ipc_timeout;
226 char *var_pid_dir;
227 int var_dont_remove;
228 char *var_inet_interfaces;
229 char *var_proxy_interfaces;
230 char *var_inet_protocols;
231 char *var_mynetworks;
232 char *var_double_bounce_sender;
233 int var_line_limit;
234 char *var_alias_db_map;
235 int var_message_limit;
236 char *var_mail_release;
237 char *var_mail_version;
238 int var_ipc_idle_limit;
239 int var_ipc_ttl_limit;
240 char *var_db_type;
241 char *var_hash_queue_names;
242 int var_hash_queue_depth;
243 int var_trigger_timeout;
244 char *var_rcpt_delim;
245 int var_fork_tries;
246 int var_fork_delay;
247 int var_flock_tries;
248 int var_flock_delay;
249 int var_flock_stale;
250 int var_disable_dns;
251 int var_soft_bounce;
252 time_t var_starttime;
253 int var_ownreq_special;
254 int var_daemon_timeout;
255 char *var_syslog_facility;
256 char *var_relay_domains;
257 char *var_fflush_domains;
258 char *var_mynetworks_style;
259 char *var_verp_delims;
260 char *var_verp_filter;
261 int var_in_flow_delay;
262 char *var_par_dom_match;
263 char *var_config_dirs;
265 int var_inet_windowsize;
266 char *var_import_environ;
267 char *var_export_environ;
268 char *var_debug_peer_list;
269 int var_debug_peer_level;
270 int var_fault_inj_code;
271 char *var_bounce_service;
272 char *var_cleanup_service;
273 char *var_defer_service;
274 char *var_pickup_service;
275 char *var_queue_service;
276 char *var_rewrite_service;
277 char *var_showq_service;
278 char *var_error_service;
279 char *var_flush_service;
280 char *var_verify_service;
281 char *var_trace_service;
282 char *var_proxymap_service;
283 char *var_proxywrite_service;
284 int var_db_create_buf;
285 int var_db_read_buf;
286 int var_mime_maxdepth;
287 int var_mime_bound_len;
288 int var_header_limit;
289 int var_token_limit;
290 int var_disable_mime_input;
291 int var_disable_mime_oconv;
292 int var_strict_8bitmime;
293 int var_strict_7bit_hdrs;
294 int var_strict_8bit_body;
295 int var_strict_encoding;
296 int var_verify_neg_cache;
297 int var_oldlog_compat;
298 int var_delay_max_res;
299 char *var_int_filt_classes;
300 int var_cyrus_sasl_authzid;
302 char *var_multi_conf_dirs;
303 char *var_multi_wrapper;
304 char *var_multi_group;
305 char *var_multi_name;
306 bool var_multi_enable;
308 const char null_format_string[1] = "";
310 /* check_myhostname - lookup hostname and validate */
312 static const char *check_myhostname(void)
314 static const char *name;
315 const char *dot;
316 const char *domain;
319 * Use cached result.
321 if (name)
322 return (name);
325 * If the local machine name is not in FQDN form, try to append the
326 * contents of $mydomain. Use a default domain as a final workaround.
328 name = get_hostname();
329 if ((dot = strchr(name, '.')) == 0) {
330 if ((domain = mail_conf_lookup_eval(VAR_MYDOMAIN)) == 0)
331 domain = DEF_MYDOMAIN;
332 name = concatenate(name, ".", domain, (char *) 0);
334 return (name);
337 /* check_mydomainname - lookup domain name and validate */
339 static const char *check_mydomainname(void)
341 char *dot;
344 * Use a default domain when the hostname is not a FQDN ("foo").
346 if ((dot = strchr(var_myhostname, '.')) == 0)
347 return (DEF_MYDOMAIN);
348 return (dot + 1);
351 /* check_default_privs - lookup default user attributes and validate */
353 static void check_default_privs(void)
355 struct passwd *pwd;
357 if ((pwd = getpwnam(var_default_privs)) == 0)
358 msg_fatal("file %s/%s: parameter %s: unknown user name value: %s",
359 var_config_dir, MAIN_CONF_FILE,
360 VAR_DEFAULT_PRIVS, var_default_privs);
361 if ((var_default_uid = pwd->pw_uid) == 0)
362 msg_fatal("file %s/%s: parameter %s: user %s has privileged user ID",
363 var_config_dir, MAIN_CONF_FILE,
364 VAR_DEFAULT_PRIVS, var_default_privs);
365 if ((var_default_gid = pwd->pw_gid) == 0)
366 msg_fatal("file %s/%s: parameter %s: user %s has privileged group ID",
367 var_config_dir, MAIN_CONF_FILE,
368 VAR_DEFAULT_PRIVS, var_default_privs);
371 /* check_mail_owner - lookup owner user attributes and validate */
373 static void check_mail_owner(void)
375 struct passwd *pwd;
377 if ((pwd = getpwnam(var_mail_owner)) == 0)
378 msg_fatal("file %s/%s: parameter %s: unknown user name value: %s",
379 var_config_dir, MAIN_CONF_FILE,
380 VAR_MAIL_OWNER, var_mail_owner);
381 if ((var_owner_uid = pwd->pw_uid) == 0)
382 msg_fatal("file %s/%s: parameter %s: user %s has privileged user ID",
383 var_config_dir, MAIN_CONF_FILE,
384 VAR_MAIL_OWNER, var_mail_owner);
385 if ((var_owner_gid = pwd->pw_gid) == 0)
386 msg_fatal("file %s/%s: parameter %s: user %s has privileged group ID",
387 var_config_dir, MAIN_CONF_FILE,
388 VAR_MAIL_OWNER, var_mail_owner);
391 * This detects only some forms of sharing. Enumerating the entire
392 * password file name space could be expensive. The purpose of this code
393 * is to discourage user ID sharing by developers and package
394 * maintainers.
396 if ((pwd = getpwuid(var_owner_uid)) != 0
397 && strcmp(pwd->pw_name, var_mail_owner) != 0)
398 msg_fatal("file %s/%s: parameter %s: user %s has same user ID as %s",
399 var_config_dir, MAIN_CONF_FILE,
400 VAR_MAIL_OWNER, var_mail_owner, pwd->pw_name);
403 /* check_sgid_group - lookup setgid group attributes and validate */
405 static void check_sgid_group(void)
407 struct group *grp;
409 if ((grp = getgrnam(var_sgid_group)) == 0)
410 msg_fatal("file %s/%s: parameter %s: unknown group name: %s",
411 var_config_dir, MAIN_CONF_FILE,
412 VAR_SGID_GROUP, var_sgid_group);
413 if ((var_sgid_gid = grp->gr_gid) == 0)
414 msg_fatal("file %s/%s: parameter %s: group %s has privileged group ID",
415 var_config_dir, MAIN_CONF_FILE,
416 VAR_SGID_GROUP, var_sgid_group);
419 * This detects only some forms of sharing. Enumerating the entire group
420 * file name space could be expensive. The purpose of this code is to
421 * discourage group ID sharing by developers and package maintainers.
423 if ((grp = getgrgid(var_sgid_gid)) != 0
424 && strcmp(grp->gr_name, var_sgid_group) != 0)
425 msg_fatal("file %s/%s: parameter %s: group %s has same group ID as %s",
426 var_config_dir, MAIN_CONF_FILE,
427 VAR_SGID_GROUP, var_sgid_group, grp->gr_name);
430 /* check_overlap - disallow UID or GID sharing */
432 static void check_overlap(void)
434 if (strcmp(var_default_privs, var_mail_owner) == 0)
435 msg_fatal("file %s/%s: parameters %s and %s specify the same user %s",
436 var_config_dir, MAIN_CONF_FILE,
437 VAR_DEFAULT_PRIVS, VAR_MAIL_OWNER,
438 var_default_privs);
439 if (var_default_uid == var_owner_uid)
440 msg_fatal("file %s/%s: parameters %s and %s: users %s and %s have the same user ID: %ld",
441 var_config_dir, MAIN_CONF_FILE,
442 VAR_DEFAULT_PRIVS, VAR_MAIL_OWNER,
443 var_default_privs, var_mail_owner,
444 (long) var_owner_uid);
445 if (var_default_gid == var_owner_gid)
446 msg_fatal("file %s/%s: parameters %s and %s: users %s and %s have the same group ID: %ld",
447 var_config_dir, MAIN_CONF_FILE,
448 VAR_DEFAULT_PRIVS, VAR_MAIL_OWNER,
449 var_default_privs, var_mail_owner,
450 (long) var_owner_gid);
451 if (var_default_gid == var_sgid_gid)
452 msg_fatal("file %s/%s: parameters %s and %s: user %s and group %s have the same group ID: %ld",
453 var_config_dir, MAIN_CONF_FILE,
454 VAR_DEFAULT_PRIVS, VAR_SGID_GROUP,
455 var_default_privs, var_sgid_group,
456 (long) var_sgid_gid);
457 if (var_owner_gid == var_sgid_gid)
458 msg_fatal("file %s/%s: parameters %s and %s: user %s and group %s have the same group ID: %ld",
459 var_config_dir, MAIN_CONF_FILE,
460 VAR_MAIL_OWNER, VAR_SGID_GROUP,
461 var_mail_owner, var_sgid_group,
462 (long) var_sgid_gid);
465 #ifdef MYORIGIN_FROM_FILE
467 /* read_param_from_file - read parameter value from file */
469 static char *read_param_from_file(const char *path)
471 VSTRING *why = vstring_alloc(100);
472 VSTRING *buf = vstring_alloc(100);
473 VSTREAM *fp;
474 char *bp;
475 char *result;
478 * Ugly macros to make complex expressions less unreadable.
480 #define SKIP(start, var, cond) \
481 for (var = start; *var && (cond); var++);
483 #define TRIM(s) { \
484 char *p; \
485 for (p = (s) + strlen(s); p > (s) && ISSPACE(p[-1]); p--); \
486 *p = 0; \
489 fp = safe_open(path, O_RDONLY, 0, (struct stat *) 0, -1, -1, why);
490 if (fp == 0)
491 msg_fatal("%s: %s", path, vstring_str(why));
492 vstring_get_nonl(buf, fp);
493 if (vstream_ferror(fp)) /* FIX 20070501 */
494 msg_fatal("%s: read error: %m", path);
495 vstream_fclose(fp);
496 SKIP(vstring_str(buf), bp, ISSPACE(*bp));
497 TRIM(bp);
498 result = mystrdup(bp);
500 vstring_free(why);
501 vstring_free(buf);
502 return (result);
505 #endif
507 /* mail_params_init - configure built-in parameters */
509 void mail_params_init()
511 static const CONFIG_STR_TABLE first_str_defaults[] = {
512 VAR_SYSLOG_FACILITY, DEF_SYSLOG_FACILITY, &var_syslog_facility, 1, 0,
513 VAR_INET_PROTOCOLS, DEF_INET_PROTOCOLS, &var_inet_protocols, 1, 0,
514 VAR_MULTI_CONF_DIRS, DEF_MULTI_CONF_DIRS, &var_multi_conf_dirs, 0, 0,
515 VAR_MULTI_WRAPPER, DEF_MULTI_WRAPPER, &var_multi_wrapper, 0, 0,
516 VAR_MULTI_GROUP, DEF_MULTI_GROUP, &var_multi_group, 0, 0,
517 VAR_MULTI_NAME, DEF_MULTI_NAME, &var_multi_name, 0, 0,
520 static const CONFIG_STR_FN_TABLE function_str_defaults[] = {
521 VAR_MYHOSTNAME, check_myhostname, &var_myhostname, 1, 0,
522 VAR_MYDOMAIN, check_mydomainname, &var_mydomain, 1, 0,
525 static const CONFIG_STR_TABLE other_str_defaults[] = {
526 VAR_MAIL_NAME, DEF_MAIL_NAME, &var_mail_name, 1, 0,
527 VAR_SYSLOG_NAME, DEF_SYSLOG_NAME, &var_syslog_name, 1, 0,
528 VAR_MAIL_OWNER, DEF_MAIL_OWNER, &var_mail_owner, 1, 0,
529 VAR_SGID_GROUP, DEF_SGID_GROUP, &var_sgid_group, 1, 0,
530 VAR_MYDEST, DEF_MYDEST, &var_mydest, 0, 0,
531 VAR_MYORIGIN, DEF_MYORIGIN, &var_myorigin, 1, 0,
532 VAR_RELAYHOST, DEF_RELAYHOST, &var_relayhost, 0, 0,
533 VAR_DAEMON_DIR, DEF_DAEMON_DIR, &var_daemon_dir, 1, 0,
534 VAR_DATA_DIR, DEF_DATA_DIR, &var_data_dir, 1, 0,
535 VAR_COMMAND_DIR, DEF_COMMAND_DIR, &var_command_dir, 1, 0,
536 VAR_QUEUE_DIR, DEF_QUEUE_DIR, &var_queue_dir, 1, 0,
537 VAR_PID_DIR, DEF_PID_DIR, &var_pid_dir, 1, 0,
538 VAR_INET_INTERFACES, DEF_INET_INTERFACES, &var_inet_interfaces, 1, 0,
539 VAR_PROXY_INTERFACES, DEF_PROXY_INTERFACES, &var_proxy_interfaces, 0, 0,
540 VAR_DOUBLE_BOUNCE, DEF_DOUBLE_BOUNCE, &var_double_bounce_sender, 1, 0,
541 VAR_DEFAULT_PRIVS, DEF_DEFAULT_PRIVS, &var_default_privs, 1, 0,
542 VAR_ALIAS_DB_MAP, DEF_ALIAS_DB_MAP, &var_alias_db_map, 0, 0,
543 VAR_MAIL_RELEASE, DEF_MAIL_RELEASE, &var_mail_release, 1, 0,
544 VAR_MAIL_VERSION, DEF_MAIL_VERSION, &var_mail_version, 1, 0,
545 VAR_DB_TYPE, DEF_DB_TYPE, &var_db_type, 1, 0,
546 VAR_HASH_QUEUE_NAMES, DEF_HASH_QUEUE_NAMES, &var_hash_queue_names, 1, 0,
547 VAR_RCPT_DELIM, DEF_RCPT_DELIM, &var_rcpt_delim, 0, 1,
548 VAR_RELAY_DOMAINS, DEF_RELAY_DOMAINS, &var_relay_domains, 0, 0,
549 VAR_FFLUSH_DOMAINS, DEF_FFLUSH_DOMAINS, &var_fflush_domains, 0, 0,
550 VAR_EXPORT_ENVIRON, DEF_EXPORT_ENVIRON, &var_export_environ, 0, 0,
551 VAR_IMPORT_ENVIRON, DEF_IMPORT_ENVIRON, &var_import_environ, 0, 0,
552 VAR_MYNETWORKS_STYLE, DEF_MYNETWORKS_STYLE, &var_mynetworks_style, 1, 0,
553 VAR_DEBUG_PEER_LIST, DEF_DEBUG_PEER_LIST, &var_debug_peer_list, 0, 0,
554 VAR_VERP_DELIMS, DEF_VERP_DELIMS, &var_verp_delims, 2, 2,
555 VAR_VERP_FILTER, DEF_VERP_FILTER, &var_verp_filter, 1, 0,
556 VAR_PAR_DOM_MATCH, DEF_PAR_DOM_MATCH, &var_par_dom_match, 0, 0,
557 VAR_CONFIG_DIRS, DEF_CONFIG_DIRS, &var_config_dirs, 0, 0,
558 VAR_BOUNCE_SERVICE, DEF_BOUNCE_SERVICE, &var_bounce_service, 1, 0,
559 VAR_CLEANUP_SERVICE, DEF_CLEANUP_SERVICE, &var_cleanup_service, 1, 0,
560 VAR_DEFER_SERVICE, DEF_DEFER_SERVICE, &var_defer_service, 1, 0,
561 VAR_PICKUP_SERVICE, DEF_PICKUP_SERVICE, &var_pickup_service, 1, 0,
562 VAR_QUEUE_SERVICE, DEF_QUEUE_SERVICE, &var_queue_service, 1, 0,
563 VAR_REWRITE_SERVICE, DEF_REWRITE_SERVICE, &var_rewrite_service, 1, 0,
564 VAR_SHOWQ_SERVICE, DEF_SHOWQ_SERVICE, &var_showq_service, 1, 0,
565 VAR_ERROR_SERVICE, DEF_ERROR_SERVICE, &var_error_service, 1, 0,
566 VAR_FLUSH_SERVICE, DEF_FLUSH_SERVICE, &var_flush_service, 1, 0,
567 VAR_VERIFY_SERVICE, DEF_VERIFY_SERVICE, &var_verify_service, 1, 0,
568 VAR_TRACE_SERVICE, DEF_TRACE_SERVICE, &var_trace_service, 1, 0,
569 VAR_PROXYMAP_SERVICE, DEF_PROXYMAP_SERVICE, &var_proxymap_service, 1, 0,
570 VAR_PROXYWRITE_SERVICE, DEF_PROXYWRITE_SERVICE, &var_proxywrite_service, 1, 0,
571 VAR_INT_FILT_CLASSES, DEF_INT_FILT_CLASSES, &var_int_filt_classes, 0, 0,
574 static const CONFIG_STR_FN_TABLE function_str_defaults_2[] = {
575 VAR_MYNETWORKS, mynetworks, &var_mynetworks, 0, 0,
578 static const CONFIG_INT_TABLE other_int_defaults[] = {
579 VAR_MAX_USE, DEF_MAX_USE, &var_use_limit, 1, 0,
580 VAR_DONT_REMOVE, DEF_DONT_REMOVE, &var_dont_remove, 0, 0,
581 VAR_LINE_LIMIT, DEF_LINE_LIMIT, &var_line_limit, 512, 0,
582 VAR_MESSAGE_LIMIT, DEF_MESSAGE_LIMIT, &var_message_limit, 0, 0,
583 VAR_HASH_QUEUE_DEPTH, DEF_HASH_QUEUE_DEPTH, &var_hash_queue_depth, 1, 0,
584 VAR_FORK_TRIES, DEF_FORK_TRIES, &var_fork_tries, 1, 0,
585 VAR_FLOCK_TRIES, DEF_FLOCK_TRIES, &var_flock_tries, 1, 0,
586 VAR_DEBUG_PEER_LEVEL, DEF_DEBUG_PEER_LEVEL, &var_debug_peer_level, 1, 0,
587 VAR_FAULT_INJ_CODE, DEF_FAULT_INJ_CODE, &var_fault_inj_code, 0, 0,
588 VAR_DB_CREATE_BUF, DEF_DB_CREATE_BUF, &var_db_create_buf, 1, 0,
589 VAR_DB_READ_BUF, DEF_DB_READ_BUF, &var_db_read_buf, 1, 0,
590 VAR_HEADER_LIMIT, DEF_HEADER_LIMIT, &var_header_limit, 1, 0,
591 VAR_TOKEN_LIMIT, DEF_TOKEN_LIMIT, &var_token_limit, 1, 0,
592 VAR_MIME_MAXDEPTH, DEF_MIME_MAXDEPTH, &var_mime_maxdepth, 1, 0,
593 VAR_MIME_BOUND_LEN, DEF_MIME_BOUND_LEN, &var_mime_bound_len, 1, 0,
594 VAR_DELAY_MAX_RES, DEF_DELAY_MAX_RES, &var_delay_max_res, MIN_DELAY_MAX_RES, MAX_DELAY_MAX_RES,
595 VAR_INET_WINDOW, DEF_INET_WINDOW, &var_inet_windowsize, 0, 0,
598 static const CONFIG_TIME_TABLE time_defaults[] = {
599 VAR_EVENT_DRAIN, DEF_EVENT_DRAIN, &var_event_drain, 1, 0,
600 VAR_MAX_IDLE, DEF_MAX_IDLE, &var_idle_limit, 1, 0,
601 VAR_IPC_TIMEOUT, DEF_IPC_TIMEOUT, &var_ipc_timeout, 1, 0,
602 VAR_IPC_IDLE, DEF_IPC_IDLE, &var_ipc_idle_limit, 1, 0,
603 VAR_IPC_TTL, DEF_IPC_TTL, &var_ipc_ttl_limit, 1, 0,
604 VAR_TRIGGER_TIMEOUT, DEF_TRIGGER_TIMEOUT, &var_trigger_timeout, 1, 0,
605 VAR_FORK_DELAY, DEF_FORK_DELAY, &var_fork_delay, 1, 0,
606 VAR_FLOCK_DELAY, DEF_FLOCK_DELAY, &var_flock_delay, 1, 0,
607 VAR_FLOCK_STALE, DEF_FLOCK_STALE, &var_flock_stale, 1, 0,
608 VAR_DAEMON_TIMEOUT, DEF_DAEMON_TIMEOUT, &var_daemon_timeout, 1, 0,
609 VAR_IN_FLOW_DELAY, DEF_IN_FLOW_DELAY, &var_in_flow_delay, 0, 10,
612 static const CONFIG_BOOL_TABLE bool_defaults[] = {
613 VAR_DISABLE_DNS, DEF_DISABLE_DNS, &var_disable_dns,
614 VAR_SOFT_BOUNCE, DEF_SOFT_BOUNCE, &var_soft_bounce,
615 VAR_OWNREQ_SPECIAL, DEF_OWNREQ_SPECIAL, &var_ownreq_special,
616 VAR_STRICT_8BITMIME, DEF_STRICT_8BITMIME, &var_strict_8bitmime,
617 VAR_STRICT_7BIT_HDRS, DEF_STRICT_7BIT_HDRS, &var_strict_7bit_hdrs,
618 VAR_STRICT_8BIT_BODY, DEF_STRICT_8BIT_BODY, &var_strict_8bit_body,
619 VAR_STRICT_ENCODING, DEF_STRICT_ENCODING, &var_strict_encoding,
620 VAR_DISABLE_MIME_INPUT, DEF_DISABLE_MIME_INPUT, &var_disable_mime_input,
621 VAR_DISABLE_MIME_OCONV, DEF_DISABLE_MIME_OCONV, &var_disable_mime_oconv,
622 VAR_VERIFY_NEG_CACHE, DEF_VERIFY_NEG_CACHE, &var_verify_neg_cache,
623 VAR_OLDLOG_COMPAT, DEF_OLDLOG_COMPAT, &var_oldlog_compat,
624 VAR_HELPFUL_WARNINGS, DEF_HELPFUL_WARNINGS, &var_helpful_warnings,
625 VAR_CYRUS_SASL_AUTHZID, DEF_CYRUS_SASL_AUTHZID, &var_cyrus_sasl_authzid,
626 VAR_MULTI_ENABLE, DEF_MULTI_ENABLE, &var_multi_enable,
629 const char *cp;
630 INET_PROTO_INFO *proto_info;
633 * Extract syslog_facility early, so that from here on all errors are
634 * logged with the proper facility.
636 get_mail_conf_str_table(first_str_defaults);
638 if (!msg_syslog_facility(var_syslog_facility))
639 msg_fatal("file %s/%s: parameter %s: unrecognized value: %s",
640 var_config_dir, MAIN_CONF_FILE,
641 VAR_SYSLOG_FACILITY, var_syslog_facility);
644 * What protocols should we attempt to support? The result is stored in
645 * the global inet_proto_table variable.
647 proto_info = inet_proto_init(VAR_INET_PROTOCOLS, var_inet_protocols);
650 * Variables whose defaults are determined at runtime. Some sites use
651 * short hostnames in the host table; some sites name their system after
652 * the domain.
654 get_mail_conf_str_fn_table(function_str_defaults);
655 if (!valid_hostname(var_myhostname, DO_GRIPE))
656 msg_fatal("file %s/%s: parameter %s: bad parameter value: %s",
657 var_config_dir, MAIN_CONF_FILE,
658 VAR_MYHOSTNAME, var_myhostname);
659 if (!valid_hostname(var_mydomain, DO_GRIPE))
660 msg_fatal("file %s/%s: parameter %s: bad parameter value: %s",
661 var_config_dir, MAIN_CONF_FILE,
662 VAR_MYDOMAIN, var_mydomain);
665 * Variables that are needed by almost every program.
667 * XXX Reading the myorigin value from file is originally a Debian Linux
668 * feature. This code is not enabled by default because of problems: 1)
669 * it re-implements its own parameter syntax checks, and 2) it does not
670 * implement $name expansions.
672 get_mail_conf_str_table(other_str_defaults);
673 #ifdef MYORIGIN_FROM_FILE
674 if (*var_myorigin == '/') {
675 char *origin = read_param_from_file(var_myorigin);
677 if (*origin == 0)
678 msg_fatal("%s file %s is empty", VAR_MYORIGIN, var_myorigin);
679 myfree(var_myorigin); /* FIX 20070501 */
680 var_myorigin = origin;
682 #endif
683 get_mail_conf_int_table(other_int_defaults);
684 get_mail_conf_bool_table(bool_defaults);
685 get_mail_conf_time_table(time_defaults);
686 check_default_privs();
687 check_mail_owner();
688 check_sgid_group();
689 check_overlap();
690 #ifdef HAS_DB
691 dict_db_cache_size = var_db_read_buf;
692 #endif
693 inet_windowsize = var_inet_windowsize;
696 * Variables whose defaults are determined at runtime, after other
697 * variables have been set. This dependency is admittedly a bit tricky.
698 * XXX Perhaps we should just register variables, and let the evaluator
699 * figure out in what order to evaluate things.
701 get_mail_conf_str_fn_table(function_str_defaults_2);
704 * FIX 200412 The IPv6 patch did not call own_inet_addr_list() before
705 * entering the chroot jail on Linux IPv6 systems. Linux has the IPv6
706 * interface list in /proc, which is not available after chrooting.
708 (void) own_inet_addr_list();
711 * The PID variable cannot be set from the configuration file!!
713 set_mail_conf_int(VAR_PID, var_pid = getpid());
716 * Neither can the start time variable. It isn't even visible.
718 time(&var_starttime);
721 * Export the syslog name so children can inherit and use it before they
722 * have initialized.
724 if ((cp = safe_getenv(CONF_ENV_LOGTAG)) == 0
725 || strcmp(cp, var_syslog_name) != 0)
726 if (setenv(CONF_ENV_LOGTAG, var_syslog_name, 1) < 0)
727 msg_fatal("setenv %s %s: %m", CONF_ENV_LOGTAG, var_syslog_name);
730 * I have seen this happen just too often.
732 if (strcasecmp(var_myhostname, var_relayhost) == 0)
733 msg_fatal("%s and %s parameter settings must not be identical: %s",
734 VAR_MYHOSTNAME, VAR_RELAYHOST, var_myhostname);
737 * XXX These should be caught by a proper parameter parsing algorithm.
739 if (var_myorigin[strcspn(var_myorigin, ", \t\r\n")])
740 msg_fatal("%s parameter setting must not contain multiple values: %s",
741 VAR_MYORIGIN, var_myorigin);
743 if (var_relayhost[strcspn(var_relayhost, ", \t\r\n")])
744 msg_fatal("%s parameter setting must not contain multiple values: %s",
745 VAR_RELAYHOST, var_relayhost);
748 * One more sanity check.
750 if ((cp = verp_delims_verify(var_verp_delims)) != 0)
751 msg_fatal("file %s/%s: parameters %s and %s: %s",
752 var_config_dir, MAIN_CONF_FILE,
753 VAR_VERP_DELIMS, VAR_VERP_FILTER, cp);