Postfix3.3.1
postfix.c
[詳解]
1 /*++
2 /* NAME
3 /* postfix 1
4 /* SUMMARY
5 /* Postfix control program
6 /* SYNOPSIS
7 /* .fi
8 /* \fBpostfix\fR [\fB-Dv\fR] [\fB-c \fIconfig_dir\fR] \fIcommand\fR
9 /* DESCRIPTION
10 /* This command is reserved for the superuser. To submit mail,
11 /* use the Postfix \fBsendmail\fR(1) command.
12 /*
13 /* The \fBpostfix\fR(1) command controls the operation of the Postfix
14 /* mail system: start or stop the \fBmaster\fR(8) daemon, do a health
15 /* check, and other maintenance.
16 /*
17 /* By default, the \fBpostfix\fR(1) command sets up a standardized
18 /* environment and runs the \fBpostfix-script\fR shell script
19 /* to do the actual work.
20 /*
21 /* However, when support for multiple Postfix instances is
22 /* configured, \fBpostfix\fR(1) executes the command specified
23 /* with the \fBmulti_instance_wrapper\fR configuration parameter.
24 /* This command will execute the \fIcommand\fR for each
25 /* applicable Postfix instance.
26 /*
27 /* The following commands are implemented:
28 /* .IP \fBcheck\fR
29 /* Warn about bad directory/file ownership or permissions,
30 /* and create missing directories.
31 /* .IP \fBstart\fR
32 /* Start the Postfix mail system. This also runs the configuration
33 /* check described above.
34 /* .IP \fBstart-fg\fR
35 /* Like \fBstart\fR, but keep the \fBmaster\fR(8) daemon running
36 /* in the foreground, and enable \fBmaster\fR(8) "init" mode
37 /* when running as PID 1.
38 /* This command requires that multi-instance support is
39 /* disabled (i.e. the multi_instance_directories parameter
40 /* value must be empty). When running Postfix inside a container,
41 /* mount the container host's /dev/log socket inside the
42 /* container (example: "docker run -v /dev/log:/dev/log ...")
43 /* and specify a distinct Postfix "syslog_name" prefix that
44 /* identifies logging from the Postfix instance.
45 /* .IP \fBstop\fR
46 /* Stop the Postfix mail system in an orderly fashion. If
47 /* possible, running processes are allowed to terminate at
48 /* their earliest convenience.
49 /* .sp
50 /* Note: in order to refresh the Postfix mail system after a
51 /* configuration change, do not use the \fBstart\fR and \fBstop\fR
52 /* commands in succession. Use the \fBreload\fR command instead.
53 /* .IP \fBabort\fR
54 /* Stop the Postfix mail system abruptly. Running processes are
55 /* signaled to stop immediately.
56 /* .IP \fBflush\fR
57 /* Force delivery: attempt to deliver every message in the deferred
58 /* mail queue. Normally, attempts to deliver delayed mail happen at
59 /* regular intervals, the interval doubling after each failed attempt.
60 /* .sp
61 /* Warning: flushing undeliverable mail frequently will result in
62 /* poor delivery performance of all other mail.
63 /* .IP \fBreload\fR
64 /* Re-read configuration files. Running processes terminate at their
65 /* earliest convenience.
66 /* .IP \fBstatus\fR
67 /* Indicate if the Postfix mail system is currently running.
68 /* .IP "\fBset-permissions\fR [\fIname\fR=\fIvalue ...\fR]"
69 /* Set the ownership and permissions of Postfix related files and
70 /* directories, as specified in the \fBpostfix-files\fR file.
71 /* .sp
72 /* Specify \fIname\fR=\fIvalue\fR to override and update specific
73 /* main.cf configuration parameters. Use this, for example, to
74 /* change the \fBmail_owner\fR or \fBsetgid_group\fR setting for an
75 /* already installed Postfix system.
76 /* .sp
77 /* This feature is available in Postfix 2.1 and later. With
78 /* Postfix 2.0 and earlier, use "\fB$config_directory/post-install
79 /* set-permissions\fR".
80 /* .IP "\fBtls\fR \fIsubcommand\fR"
81 /* Enable opportunistic TLS in the Postfix SMTP client or
82 /* server, and manage Postfix SMTP server TLS private keys and
83 /* certificates. See postfix-tls(1) for documentation.
84 /* .sp
85 /* This feature is available in Postfix 3.1 and later.
86 /* .IP "\fBupgrade-configuration\fR [\fIname\fR=\fIvalue ...\fR]"
87 /* Update the \fBmain.cf\fR and \fBmaster.cf\fR files with information
88 /* that Postfix needs in order to run: add or update services, and add
89 /* or update configuration parameter settings.
90 /* .sp
91 /* Specify \fIname\fR=\fIvalue\fR to override and update specific
92 /* main.cf configuration parameters.
93 /* .sp
94 /* This feature is available in Postfix 2.1 and later. With
95 /* Postfix 2.0 and earlier, use "\fB$config_directory/post-install
96 /* upgrade-configuration\fR".
97 /* .PP
98 /* The following options are implemented:
99 /* .IP "\fB-c \fIconfig_dir\fR"
100 /* Read the \fBmain.cf\fR and \fBmaster.cf\fR configuration files in
101 /* the named directory instead of the default configuration directory.
102 /* Use this to distinguish between multiple Postfix instances on the
103 /* same host.
104 /*
105 /* With Postfix 2.6 and later, this option forces the postfix(1)
106 /* command to operate on the specified Postfix instance only.
107 /* This behavior is inherited by postfix(1) commands that run
108 /* as a descendant of the current process.
109 /* .IP "\fB-D\fR (with \fBpostfix start\fR only)"
110 /* Run each Postfix daemon under control of a debugger as specified
111 /* via the \fBdebugger_command\fR configuration parameter.
112 /* .IP \fB-v\fR
113 /* Enable verbose logging for debugging purposes. Multiple \fB-v\fR
114 /* options make the software increasingly verbose.
115 /* ENVIRONMENT
116 /* .ad
117 /* .fi
118 /* The \fBpostfix\fR(1) command exports the following environment
119 /* variables before executing the \fBpostfix-script\fR file:
120 /* .IP \fBMAIL_CONFIG\fR
121 /* This is set when the -c command-line option is present.
122 /*
123 /* With Postfix 2.6 and later, this environment variable forces
124 /* the postfix(1) command to operate on the specified Postfix
125 /* instance only. This behavior is inherited by postfix(1)
126 /* commands that run as a descendant of the current process.
127 /* .IP \fBMAIL_VERBOSE\fR
128 /* This is set when the -v command-line option is present.
129 /* .IP \fBMAIL_DEBUG\fR
130 /* This is set when the -D command-line option is present.
131 /* CONFIGURATION PARAMETERS
132 /* .ad
133 /* .fi
134 /* The following \fBmain.cf\fR configuration parameters are
135 /* exported as environment variables with the same names:
136 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR"
137 /* The default location of the Postfix main.cf and master.cf
138 /* configuration files.
139 /* .IP "\fBcommand_directory (see 'postconf -d' output)\fR"
140 /* The location of all postfix administrative commands.
141 /* .IP "\fBdaemon_directory (see 'postconf -d' output)\fR"
142 /* The directory with Postfix support programs and daemon programs.
143 /* .IP "\fBhtml_directory (see 'postconf -d' output)\fR"
144 /* The location of Postfix HTML files that describe how to build,
145 /* configure or operate a specific Postfix subsystem or feature.
146 /* .IP "\fBmail_owner (postfix)\fR"
147 /* The UNIX system account that owns the Postfix queue and most Postfix
148 /* daemon processes.
149 /* .IP "\fBmailq_path (see 'postconf -d' output)\fR"
150 /* Sendmail compatibility feature that specifies where the Postfix
151 /* \fBmailq\fR(1) command is installed.
152 /* .IP "\fBmanpage_directory (see 'postconf -d' output)\fR"
153 /* Where the Postfix manual pages are installed.
154 /* .IP "\fBnewaliases_path (see 'postconf -d' output)\fR"
155 /* Sendmail compatibility feature that specifies the location of the
156 /* \fBnewaliases\fR(1) command.
157 /* .IP "\fBqueue_directory (see 'postconf -d' output)\fR"
158 /* The location of the Postfix top-level queue directory.
159 /* .IP "\fBreadme_directory (see 'postconf -d' output)\fR"
160 /* The location of Postfix README files that describe how to build,
161 /* configure or operate a specific Postfix subsystem or feature.
162 /* .IP "\fBsendmail_path (see 'postconf -d' output)\fR"
163 /* A Sendmail compatibility feature that specifies the location of
164 /* the Postfix \fBsendmail\fR(1) command.
165 /* .IP "\fBsetgid_group (postdrop)\fR"
166 /* The group ownership of set-gid Postfix commands and of group-writable
167 /* Postfix directories.
168 /* .PP
169 /* Available in Postfix version 2.5 and later:
170 /* .IP "\fBdata_directory (see 'postconf -d' output)\fR"
171 /* The directory with Postfix-writable data files (for example:
172 /* caches, pseudo-random numbers).
173 /* .PP
174 /* Available in Postfix version 3.0 and later:
175 /* .IP "\fBmeta_directory (see 'postconf -d' output)\fR"
176 /* The location of non-executable files that are shared among
177 /* multiple Postfix instances, such as postfix-files, dynamicmaps.cf,
178 /* and the multi-instance template files main.cf.proto and master.cf.proto.
179 /* .IP "\fBshlib_directory (see 'postconf -d' output)\fR"
180 /* The location of Postfix dynamically-linked libraries
181 /* (libpostfix-*.so), and the default location of Postfix database
182 /* plugins (postfix-*.so) that have a relative pathname in the
183 /* dynamicmaps.cf file.
184 /* .PP
185 /* Available in Postfix version 3.1 and later:
186 /* .IP "\fBopenssl_path (openssl)\fR"
187 /* The location of the OpenSSL command line program \fBopenssl\fR(1).
188 /* .PP
189 /* Other configuration parameters:
190 /* .IP "\fBimport_environment (see 'postconf -d' output)\fR"
191 /* The list of environment parameters that a privileged Postfix
192 /* process will import from a non-Postfix parent process, or name=value
193 /* environment overrides.
194 /* .IP "\fBsyslog_facility (mail)\fR"
195 /* The syslog facility of Postfix logging.
196 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR"
197 /* A prefix that is prepended to the process name in syslog
198 /* records, so that, for example, "smtpd" becomes "prefix/smtpd".
199 /* .PP
200 /* Available in Postfix version 2.6 and later:
201 /* .IP "\fBmulti_instance_directories (empty)\fR"
202 /* An optional list of non-default Postfix configuration directories;
203 /* these directories belong to additional Postfix instances that share
204 /* the Postfix executable files and documentation with the default
205 /* Postfix instance, and that are started, stopped, etc., together
206 /* with the default Postfix instance.
207 /* .IP "\fBmulti_instance_wrapper (empty)\fR"
208 /* The pathname of a multi-instance manager command that the
209 /* \fBpostfix\fR(1) command invokes when the multi_instance_directories
210 /* parameter value is non-empty.
211 /* .IP "\fBmulti_instance_group (empty)\fR"
212 /* The optional instance group name of this Postfix instance.
213 /* .IP "\fBmulti_instance_name (empty)\fR"
214 /* The optional instance name of this Postfix instance.
215 /* .IP "\fBmulti_instance_enable (no)\fR"
216 /* Allow this Postfix instance to be started, stopped, etc., by a
217 /* multi-instance manager.
218 /* FILES
219 /* .ad
220 /* .fi
221 /* Prior to Postfix version 2.6, all of the following files
222 /* were in \fB$config_directory\fR. Some files are now in
223 /* \fB$daemon_directory\fR so that they can be shared among
224 /* multiple instances that run the same Postfix version.
225 /*
226 /* Use the command "\fBpostconf config_directory\fR" or
227 /* "\fBpostconf daemon_directory\fR" to expand the names
228 /* into their actual values.
229 /* .na
230 /* .nf
231 /*
232 /* $config_directory/main.cf, Postfix configuration parameters
233 /* $config_directory/master.cf, Postfix daemon processes
234 /* $daemon_directory/postfix-files, file/directory permissions
235 /* $daemon_directory/postfix-script, administrative commands
236 /* $daemon_directory/post-install, post-installation configuration
237 /* $daemon_directory/dynamicmaps.cf, plug-in database clients
238 /* SEE ALSO
239 /* Commands:
240 /* postalias(1), create/update/query alias database
241 /* postcat(1), examine Postfix queue file
242 /* postconf(1), Postfix configuration utility
243 /* postfix(1), Postfix control program
244 /* postfix-tls(1), Postfix TLS management
245 /* postkick(1), trigger Postfix daemon
246 /* postlock(1), Postfix-compatible locking
247 /* postlog(1), Postfix-compatible logging
248 /* postmap(1), Postfix lookup table manager
249 /* postmulti(1), Postfix multi-instance manager
250 /* postqueue(1), Postfix mail queue control
251 /* postsuper(1), Postfix housekeeping
252 /* mailq(1), Sendmail compatibility interface
253 /* newaliases(1), Sendmail compatibility interface
254 /* sendmail(1), Sendmail compatibility interface
255 /*
256 /* Postfix configuration:
257 /* bounce(5), Postfix bounce message templates
258 /* master(5), Postfix master.cf file syntax
259 /* postconf(5), Postfix main.cf file syntax
260 /* postfix-wrapper(5), Postfix multi-instance API
261 /*
262 /* Table-driven mechanisms:
263 /* access(5), Postfix SMTP access control table
264 /* aliases(5), Postfix alias database
265 /* canonical(5), Postfix input address rewriting
266 /* generic(5), Postfix output address rewriting
267 /* header_checks(5), body_checks(5), Postfix content inspection
268 /* relocated(5), Users that have moved
269 /* transport(5), Postfix routing table
270 /* virtual(5), Postfix virtual aliasing
271 /*
272 /* Table lookup mechanisms:
273 /* cidr_table(5), Associate CIDR pattern with value
274 /* ldap_table(5), Postfix LDAP client
275 /* lmdb_table(5), Postfix LMDB database driver
276 /* memcache_table(5), Postfix memcache client
277 /* mysql_table(5), Postfix MYSQL client
278 /* nisplus_table(5), Postfix NIS+ client
279 /* pcre_table(5), Associate PCRE pattern with value
280 /* pgsql_table(5), Postfix PostgreSQL client
281 /* regexp_table(5), Associate POSIX regexp pattern with value
282 /* socketmap_table(5), Postfix socketmap client
283 /* sqlite_table(5), Postfix SQLite database driver
284 /* tcp_table(5), Postfix client-server table lookup
285 /*
286 /* Daemon processes:
287 /* anvil(8), Postfix connection/rate limiting
288 /* bounce(8), defer(8), trace(8), Delivery status reports
289 /* cleanup(8), canonicalize and enqueue message
290 /* discard(8), Postfix discard delivery agent
291 /* dnsblog(8), DNS black/whitelist logger
292 /* error(8), Postfix error delivery agent
293 /* flush(8), Postfix fast ETRN service
294 /* local(8), Postfix local delivery agent
295 /* master(8), Postfix master daemon
296 /* oqmgr(8), old Postfix queue manager
297 /* pickup(8), Postfix local mail pickup
298 /* pipe(8), deliver mail to non-Postfix command
299 /* postscreen(8), Postfix zombie blocker
300 /* proxymap(8), Postfix lookup table proxy server
301 /* qmgr(8), Postfix queue manager
302 /* qmqpd(8), Postfix QMQP server
303 /* scache(8), Postfix connection cache manager
304 /* showq(8), list Postfix mail queue
305 /* smtp(8), lmtp(8), Postfix SMTP+LMTP client
306 /* smtpd(8), Postfix SMTP server
307 /* spawn(8), run non-Postfix server
308 /* tlsmgr(8), Postfix TLS cache and randomness manager
309 /* tlsproxy(8), Postfix TLS proxy server
310 /* trivial-rewrite(8), Postfix address rewriting
311 /* verify(8), Postfix address verification
312 /* virtual(8), Postfix virtual delivery agent
313 /*
314 /* Other:
315 /* syslogd(8), system logging
316 /* README FILES
317 /* .ad
318 /* .fi
319 /* Use "\fBpostconf readme_directory\fR" or
320 /* "\fBpostconf html_directory\fR" to locate this information.
321 /* .na
322 /* .nf
323 /* OVERVIEW, overview of Postfix commands and processes
324 /* BASIC_CONFIGURATION_README, Postfix basic configuration
325 /* ADDRESS_REWRITING_README, Postfix address rewriting
326 /* SMTPD_ACCESS_README, SMTP relay/access control
327 /* CONTENT_INSPECTION_README, Postfix content inspection
328 /* QSHAPE_README, Postfix queue analysis
329 /* LICENSE
330 /* .ad
331 /* .fi
332 /* The Secure Mailer license must be distributed with this software.
333 /* AUTHOR(S)
334 /* Wietse Venema
335 /* IBM T.J. Watson Research
336 /* P.O. Box 704
337 /* Yorktown Heights, NY 10598, USA
338 /*
339 /* Wietse Venema
340 /* Google, Inc.
341 /* 111 8th Avenue
342 /* New York, NY 10011, USA
343 /*
344 /* TLS support by:
345 /* Lutz Jaenicke
346 /* Brandenburg University of Technology
347 /* Cottbus, Germany
348 /*
349 /* Victor Duchovni
350 /* Morgan Stanley
351 /*
352 /* SASL support originally by:
353 /* Till Franke
354 /* SuSE Rhein/Main AG
355 /* 65760 Eschborn, Germany
356 /*
357 /* LMTP support originally by:
358 /* Philip A. Prindeville
359 /* Mirapoint, Inc.
360 /* USA.
361 /*
362 /* Amos Gouaux
363 /* University of Texas at Dallas
364 /* P.O. Box 830688, MC34
365 /* Richardson, TX 75083, USA
366 /*
367 /* IPv6 support originally by:
368 /* Mark Huizer, Eindhoven University, The Netherlands
369 /* Jun-ichiro 'itojun' Hagino, KAME project, Japan
370 /* The Linux PLD project
371 /* Dean Strik, Eindhoven University, The Netherlands
372 /*--*/
373 
374 /* System library. */
375 
376 #include <sys_defs.h>
377 #include <sys/stat.h>
378 #include <vstream.h>
379 #include <stdlib.h>
380 #include <unistd.h>
381 #include <string.h>
382 #include <fcntl.h>
383 #include <syslog.h>
384 #ifdef USE_PATHS_H
385 #include <paths.h>
386 #endif
387 
388 /* Utility library. */
389 
390 #include <msg.h>
391 #include <msg_vstream.h>
392 #include <msg_syslog.h>
393 #include <stringops.h>
394 #include <clean_env.h>
395 #include <argv.h>
396 #include <safe.h>
397 #include <warn_stat.h>
398 
399 /* Global library. */
400 
401 #include <mail_conf.h>
402 #include <mail_params.h>
403 #include <mail_version.h>
404 #include <mail_parm_split.h>
405 
406 /* Additional installation parameters. */
407 
408 static char *var_sendmail_path;
409 static char *var_mailq_path;
410 static char *var_newalias_path;
411 static char *var_manpage_dir;
412 static char *var_sample_dir;
413 static char *var_readme_dir;
414 static char *var_html_dir;
415 
416 /* check_setenv - setenv() with extreme prejudice */
417 
418 static void check_setenv(char *name, char *value)
419 {
420 #define CLOBBER 1
421  if (setenv(name, value, CLOBBER) < 0)
422  msg_fatal("setenv: %m");
423 }
424 
426 
427 /* main - run administrative script from controlled environment */
428 
429 int main(int argc, char **argv)
430 {
431  char *script;
432  struct stat st;
433  char *slash;
434  int fd;
435  int ch;
436  ARGV *import_env;
437  static const CONFIG_STR_TABLE str_table[] = {
438  VAR_SENDMAIL_PATH, DEF_SENDMAIL_PATH, &var_sendmail_path, 1, 0,
439  VAR_MAILQ_PATH, DEF_MAILQ_PATH, &var_mailq_path, 1, 0,
440  VAR_NEWALIAS_PATH, DEF_NEWALIAS_PATH, &var_newalias_path, 1, 0,
441  VAR_MANPAGE_DIR, DEF_MANPAGE_DIR, &var_manpage_dir, 1, 0,
442  VAR_SAMPLE_DIR, DEF_SAMPLE_DIR, &var_sample_dir, 1, 0,
443  VAR_README_DIR, DEF_README_DIR, &var_readme_dir, 1, 0,
444  VAR_HTML_DIR, DEF_HTML_DIR, &var_html_dir, 1, 0,
445  0,
446  };
447  int force_single_instance;
448  ARGV *my_argv;
449 
450  /*
451  * Fingerprint executables and core dumps.
452  */
454 
455  /*
456  * Be consistent with file permissions.
457  */
458  umask(022);
459 
460  /*
461  * To minimize confusion, make sure that the standard file descriptors
462  * are open before opening anything else. XXX Work around for 44BSD where
463  * fstat can return EBADF on an open file descriptor.
464  */
465  for (fd = 0; fd < 3; fd++)
466  if (fstat(fd, &st) == -1
467  && (close(fd), open("/dev/null", O_RDWR, 0)) != fd)
468  msg_fatal("open /dev/null: %m");
469 
470  /*
471  * Set up diagnostics. XXX What if stdin is the system console during
472  * boot time? It seems a bad idea to log startup errors to the console.
473  * This is UNIX, a system that can run without hand holding.
474  */
475  if ((slash = strrchr(argv[0], '/')) != 0 && slash[1])
476  argv[0] = slash + 1;
477  if (isatty(STDERR_FILENO))
478  msg_vstream_init(argv[0], VSTREAM_ERR);
479  msg_syslog_init(argv[0], LOG_PID, LOG_FACILITY);
480 
481  /*
482  * Check the Postfix library version as soon as we enable logging.
483  */
485 
486  /*
487  * The mail system must be run by the superuser so it can revoke
488  * privileges for selected operations. That's right - it takes privileges
489  * to toss privileges.
490  */
491  if (getuid() != 0) {
492  msg_error("to submit mail, use the Postfix sendmail command");
493  msg_fatal("the postfix command is reserved for the superuser");
494  }
495  if (unsafe() != 0)
496  msg_fatal("the postfix command must not run as a set-uid process");
497 
498  /*
499  * Parse switches.
500  */
501  while ((ch = GETOPT(argc, argv, "c:Dv")) > 0) {
502  switch (ch) {
503  default:
504  msg_fatal("usage: %s [-c config_dir] [-Dv] command", argv[0]);
505  case 'c':
506  if (*optarg != '/')
507  msg_fatal("-c requires absolute pathname");
508  check_setenv(CONF_ENV_PATH, optarg);
509  break;
510  case 'D':
511  check_setenv(CONF_ENV_DEBUG, "");
512  break;
513  case 'v':
514  msg_verbose++;
515  check_setenv(CONF_ENV_VERB, "");
516  break;
517  }
518  }
519  force_single_instance = (getenv(CONF_ENV_PATH) != 0);
520 
521  /*
522  * Copy a bunch of configuration parameters into the environment for easy
523  * access by the maintenance shell script.
524  */
525  mail_conf_read();
526  get_mail_conf_str_table(str_table);
527 
528  /*
529  * Alert the sysadmin that the backwards-compatible settings are still in
530  * effect.
531  */
533  msg_info("Postfix is running with backwards-compatible default "
534  "settings");
535  msg_info("See http://www.postfix.org/COMPATIBILITY_README.html "
536  "for details");
537  msg_info("To disable backwards compatibility use \"postconf "
538  VAR_COMPAT_LEVEL "=%d\" and \"postfix reload\"",
540  }
541 
542  /*
543  * Environment import filter, to enforce consistent behavior whether this
544  * command is started by hand, or at system boot time. This is necessary
545  * because some shell scripts use environment settings to override
546  * main.cf settings.
547  */
549  clean_env(import_env->argv);
550  argv_free(import_env);
551 
552  check_setenv("PATH", ROOT_PATH); /* sys_defs.h */
553  check_setenv(CONF_ENV_PATH, var_config_dir);/* mail_conf.h */
554 
555  check_setenv(VAR_COMMAND_DIR, var_command_dir); /* main.cf */
556  check_setenv(VAR_DAEMON_DIR, var_daemon_dir); /* main.cf */
557  check_setenv(VAR_DATA_DIR, var_data_dir); /* main.cf */
558  check_setenv(VAR_META_DIR, var_meta_dir); /* main.cf */
559  check_setenv(VAR_QUEUE_DIR, var_queue_dir); /* main.cf */
560  check_setenv(VAR_CONFIG_DIR, var_config_dir); /* main.cf */
561  check_setenv(VAR_SHLIB_DIR, var_shlib_dir); /* main.cf */
562 
563  /*
564  * Do we want to keep adding things here as shell scripts evolve?
565  */
566  check_setenv(VAR_MAIL_OWNER, var_mail_owner); /* main.cf */
567  check_setenv(VAR_SGID_GROUP, var_sgid_group); /* main.cf */
568  check_setenv(VAR_SENDMAIL_PATH, var_sendmail_path); /* main.cf */
569  check_setenv(VAR_MAILQ_PATH, var_mailq_path); /* main.cf */
570  check_setenv(VAR_NEWALIAS_PATH, var_newalias_path); /* main.cf */
571  check_setenv(VAR_MANPAGE_DIR, var_manpage_dir); /* main.cf */
572  check_setenv(VAR_SAMPLE_DIR, var_sample_dir); /* main.cf */
573  check_setenv(VAR_README_DIR, var_readme_dir); /* main.cf */
574  check_setenv(VAR_HTML_DIR, var_html_dir); /* main.cf */
575 
576  /*
577  * Make sure these directories exist. Run the maintenance scripts with as
578  * current directory the mail database.
579  */
580  if (chdir(var_command_dir))
581  msg_fatal("chdir(%s): %m", var_command_dir);
582  if (chdir(var_daemon_dir))
583  msg_fatal("chdir(%s): %m", var_daemon_dir);
584  if (chdir(var_queue_dir))
585  msg_fatal("chdir(%s): %m", var_queue_dir);
586 
587  /*
588  * Run the management script.
589  */
590  if (force_single_instance
592  script = concatenate(var_daemon_dir, "/postfix-script", (char *) 0);
593  if (optind < 1)
594  msg_panic("bad optind value");
595  argv[optind - 1] = script;
596  execvp(script, argv + optind - 1);
597  msg_fatal("%s: %m", script);
598  }
599 
600  /*
601  * Hand off control to a multi-instance manager.
602  */
603  else {
604  if (*var_multi_wrapper == 0)
605  msg_fatal("multi-instance support is requested, but %s is empty",
608  do {
609  argv_add(my_argv, argv[optind], (char *) 0);
610  } while (argv[optind++] != 0);
611  execvp(my_argv->argv[0], my_argv->argv);
612  msg_fatal("%s: %m", my_argv->argv[0]);
613  }
614 }
int msg_verbose
Definition: msg.c:177
void msg_error(const char *fmt,...)
Definition: msg.c:231
char * var_import_environ
Definition: mail_params.c:296
char * var_command_dir
Definition: mail_params.c:244
ARGV * argv_free(ARGV *argvp)
Definition: argv.c:136
Definition: argv.h:17
#define VAR_IMPORT_ENVIRON
Definition: mail_params.h:2506
NORETURN msg_panic(const char *fmt,...)
Definition: msg.c:295
#define stat(p, s)
Definition: warn_stat.h:18
#define LOG_FACILITY
Definition: mail_params.h:357
#define DEF_MANPAGE_DIR
Definition: mail_params.h:2682
char * var_sgid_group
Definition: mail_params.c:236
char * var_multi_conf_dirs
Definition: mail_params.c:334
char ** argv
Definition: argv.h:20
void argv_add(ARGV *argvp,...)
Definition: argv.c:197
char * var_config_dir
Definition: mail_params.c:241
int unsafe(void)
Definition: unsafe.c:59
#define DEF_HTML_DIR
Definition: mail_params.h:2697
#define CONF_ENV_VERB
Definition: mail_conf.h:23
#define VAR_QUEUE_DIR
Definition: mail_params.h:277
void mail_conf_read(void)
Definition: mail_conf.c:178
void clean_env(char **preserve_list)
Definition: clean_env.c:59
#define VAR_DAEMON_DIR
Definition: mail_params.h:286
#define CONF_ENV_DEBUG
Definition: mail_conf.h:24
#define CONF_ENV_PATH
Definition: mail_conf.h:22
ARGV * mail_parm_split(const char *name, const char *value)
#define VAR_META_DIR
Definition: mail_params.h:4027
#define CLOBBER
#define VAR_MAIL_OWNER
Definition: mail_params.h:87
#define VAR_SGID_GROUP
Definition: mail_params.h:93
MAIL_VERSION_STAMP_DECLARE
Definition: postfix.c:425
char * var_shlib_dir
Definition: mail_params.c:247
#define CHARS_SPACE
Definition: sys_defs.h:1762
#define VAR_SHLIB_DIR
Definition: mail_params.h:4021
#define MAIL_VERSION_STAMP_ALLOCATE
Definition: mail_version.h:67
#define VAR_HTML_DIR
Definition: mail_params.h:2695
VAR_CONFIG_DIR
Definition: install_table.h:1
#define VAR_COMPAT_LEVEL
Definition: mail_params.h:50
#define VAR_MAILQ_PATH
Definition: mail_params.h:2665
#define VAR_COMMAND_DIR
Definition: mail_params.h:292
void get_mail_conf_str_table(const CONFIG_STR_TABLE *)
char * var_data_dir
Definition: mail_params.c:243
NORETURN msg_fatal(const char *fmt,...)
Definition: msg.c:249
#define CHARS_COMMA_SP
Definition: sys_defs.h:1761
#define MAIL_VERSION_CHECK
Definition: mail_version.h:90
#define VAR_MULTI_WRAPPER
Definition: mail_params.h:3558
char * concatenate(const char *arg0,...)
Definition: concatenate.c:42
int var_compat_level
Definition: mail_params.c:347
#define DEF_SENDMAIL_PATH
Definition: mail_params.h:2662
ARGV * argv_split(const char *, const char *)
Definition: argv_split.c:63
#define GETOPT(argc, argv, str)
Definition: sys_defs.h:1313
#define CUR_COMPAT_LEVEL
Definition: mail_params.h:52
void msg_syslog_init(const char *name, int logopt, int facility)
Definition: msg_syslog.c:173
#define DEF_MAILQ_PATH
Definition: mail_params.h:2667
#define DEF_README_DIR
Definition: mail_params.h:2692
#define DEF_SAMPLE_DIR
Definition: mail_params.h:2687
char * var_daemon_dir
Definition: mail_params.c:242
#define VAR_SENDMAIL_PATH
Definition: mail_params.h:2660
char * var_mail_owner
Definition: mail_params.c:233
char * var_queue_dir
Definition: mail_params.c:246
void msg_vstream_init(const char *name, VSTREAM *vp)
Definition: msg_vstream.c:77
int main(int argc, char **argv)
Definition: postfix.c:429
char * var_multi_wrapper
Definition: mail_params.c:335
char * var_meta_dir
Definition: mail_params.c:245
#define VAR_README_DIR
Definition: mail_params.h:2690
#define VAR_SAMPLE_DIR
Definition: mail_params.h:2685
#define DEF_NEWALIAS_PATH
Definition: mail_params.h:2672
#define VAR_DATA_DIR
Definition: mail_params.h:310
#define VSTREAM_ERR
Definition: vstream.h:68
#define fstat(f, s)
Definition: warn_stat.h:20
#define VAR_NEWALIAS_PATH
Definition: mail_params.h:2670
#define VAR_MANPAGE_DIR
Definition: mail_params.h:2680
void msg_info(const char *fmt,...)
Definition: msg.c:199