7 # execute Postfix administrative commands
9 # \fBpostfix-script\fR \fIcommand\fR
11 # The \fBpostfix-script\fR script executes Postfix administrative
12 # commands in an environment that is set up by the \fBpostfix\fR(1)
15 # master(8) Postfix master program
16 # postfix(1) Postfix administrative interface
20 # The Secure Mailer license must be distributed with this software.
23 # IBM T.J. Watson Research
25 # Yorktown Heights, NY 10598, USA
28 # Avoid POSIX death due to SIGHUP when some parent process exits.
32 case $daemon_directory in
33 "") echo This script must be run by the postfix command. 1>&2
34 echo Do not run directly. 1>&2
38 LOGGER="$command_directory/postlog -t $MAIL_LOGTAG/postfix-script"
39 INFO="$LOGGER -p info"
40 WARN="$LOGGER -p warn"
41 ERROR="$LOGGER -p error"
42 FATAL="$LOGGER -p fatal"
43 PANIC="$LOGGER -p panic"
45 if [ "X${1#quiet-}" != "X${1}" ]; then
56 # Can't do much without these in place.
58 cd $command_directory || {
59 $FATAL no Postfix command directory $command_directory!
62 cd $daemon_directory || {
63 $FATAL no Postfix daemon directory $daemon_directory!
67 $FATAL no Postfix master program $daemon_directory/master!
70 cd $config_directory || {
71 $FATAL no Postfix configuration directory $config_directory!
74 cd $queue_directory || {
75 $FATAL no Postfix queue directory $queue_directory!
78 def_config_directory=`$command_directory/postconf -dh config_directory` || {
79 $FATAL cannot execute $command_directory/postconf!
83 # If this is a secondary instance, don't touch shared files.
85 instances=`test ! -f $def_config_directory/main.cf ||
86 $command_directory/postconf -c $def_config_directory \
87 -h multi_instance_directories | sed 's/,/ /'` || {
88 $FATAL cannot execute $command_directory/postconf!
93 for name in $instances
96 "$def_config_directory") ;;
97 "$config_directory") check_shared_files=; break;;
118 $daemon_directory/master -t 2>/dev/null || {
119 $FATAL the Postfix mail system is already running
122 $daemon_directory/postfix-script quick-check || {
123 $FATAL Postfix integrity check failed!
126 $INFO starting the Postfix mail system
127 $daemon_directory/master &
132 $daemon_directory/master -t 2>/dev/null || {
133 $FATAL the Postfix mail system is already running
136 if [ -f $queue_directory/quick-start ]
138 rm -f $queue_directory/quick-start
140 $daemon_directory/postfix-script check-fatal || {
141 $FATAL Postfix integrity check failed!
144 # Foreground this so it can be stopped. All inodes are cached.
145 $daemon_directory/postfix-script check-warn
147 $INFO starting the Postfix mail system
148 # NOTE: wait in foreground process to get the initialization status.
149 $daemon_directory/master -w || {
150 $FATAL "mail system startup failed"
157 $daemon_directory/master -t 2>/dev/null && {
158 $FATAL the Postfix mail system is not running
161 $INFO stopping the Postfix mail system
162 kill -9 `sed 1q pid/master.pid`
167 $daemon_directory/postfix-script stop
168 touch $queue_directory/quick-start
173 $daemon_directory/master -t 2>/dev/null && {
174 $FATAL the Postfix mail system is not running
177 $INFO stopping the Postfix mail system
178 kill `sed 1q pid/master.pid`
181 $daemon_directory/master -t && exit 0
182 $INFO waiting for the Postfix mail system to terminate
185 $WARN stopping the Postfix mail system with force
186 pid=`awk '{ print $1; exit 0 } END { exit 1 }' pid/master.pid` &&
192 $daemon_directory/master -t 2>/dev/null && {
193 $FATAL the Postfix mail system is not running
196 $INFO aborting the Postfix mail system
197 kill `sed 1q pid/master.pid`
202 $daemon_directory/master -t 2>/dev/null && {
203 $FATAL the Postfix mail system is not running
206 $INFO refreshing the Postfix mail system
207 $command_directory/postsuper active || exit 1
208 kill -HUP `sed 1q pid/master.pid`
209 $command_directory/postsuper &
214 cd $queue_directory || {
215 $FATAL no Postfix queue directory $queue_directory!
218 $command_directory/postqueue -f
223 $daemon_directory/postfix-script check-fatal || exit 1
224 $daemon_directory/postfix-script check-warn
230 $daemon_directory/master -t 2>/dev/null && {
231 $INFO the Postfix mail system is not running
234 $INFO the Postfix mail system is running: PID: `sed 1q pid/master.pid`
239 # This command is NOT part of the public interface.
241 $SHELL $daemon_directory/post-install create-missing || {
242 $WARN unable to create missing queue directories
246 # Look for incomplete installations.
248 test -f $config_directory/master.cf || {
249 $FATAL no $config_directory/master.cf file found
256 # This command is NOT part of the public interface.
258 $daemon_directory/postfix-script quick-check
260 # See if all queue files are in the right place. This is slow.
261 # We must scan all queues for mis-named queue files before the
262 # mail system can run.
264 $command_directory/postsuper || exit 1
269 # This command is NOT part of the public interface.
271 todo="$config_directory $queue_directory $queue_directory/pid"
272 test -n "$check_shared_files" && todo="$daemon_directory $todo"
276 ls -lLd $dir | (grep " root " >/dev/null ||
277 $WARN not owned by root: $dir)
280 # Some people break Postfix's security model.
281 ls -lLd $queue_directory | egrep '^.....(w|...w)' >/dev/null && \
282 $WARN group or other writable: $queue_directory
284 todo="$config_directory/*"
285 test -n "$check_shared_files" && todo="$daemon_directory/* $todo"
287 find $todo ! -user root \
288 -exec $WARN not owned by root: {} \;
290 todo="$config_directory/."
291 test -n "$check_shared_files" && todo="$daemon_directory/. $todo"
294 \( -perm -020 -o -perm -002 \) -type f \
295 -exec $WARN group or other writable: {} \;
297 find $data_directory/. ! -user $mail_owner \
298 -exec $WARN not owned by $mail_owner: {} \;
300 ls -lLd $data_directory | egrep '^.....(w|...w)' >/dev/null && \
301 $WARN group or other writable: $data_directory
303 find `ls -d $queue_directory/* | \
304 egrep '/(saved|incoming|active|defer|deferred|bounce|hold|trace|corrupt|public|private|flush)$'` \
305 ! \( -type p -o -type s \) ! -user $mail_owner \
306 -exec $WARN not owned by $mail_owner: {} \;
308 todo="$queue_directory/public $queue_directory/maildrop"
309 test -n "$check_shared_files" &&
310 todo="$command_directory/postqueue $command_directory/postdrop $todo"
313 -prune ! -group $setgid_group \
314 -exec $WARN not owned by group $setgid_group: {} \;
316 test -n "$check_shared_files" &&
317 find $command_directory/postqueue $command_directory/postdrop \
318 -prune ! -perm -02111 \
319 -exec $WARN not set-gid or not owner+group+world executable: {} \;
321 for name in `ls -d $queue_directory/* | \
322 egrep '/(bin|etc|lib|usr)$'` ; \
324 find $name ! -user root \
325 -exec $WARN not owned by root: {} \; ; \
328 # WARNING: this should not descend into the maildrop directory.
329 # maildrop is the least trusted Postfix directory.
331 find $queue_directory/maildrop/. -prune ! -user $mail_owner \
332 -exec $WARN not owned by $mail_owner: $queue_directory/maildrop \;
334 for dir in bin etc lib sbin usr
336 test -d $dir && find $dir -type f -print | while read path
339 cmp -s $path /$path ||
340 $WARN $queue_directory/$path and /$path differ
345 find corrupt -type f -exec $WARN damaged message: {} \;
347 # XXX also: look for weird stuff, weird permissions, etc.
349 test -n "$check_shared_files" -a -f /usr/sbin/sendmail -a \
350 -f /usr/lib/sendmail && {
351 cmp -s /usr/sbin/sendmail /usr/lib/sendmail || {
352 $WARN /usr/lib/sendmail and /usr/sbin/sendmail differ
353 $WARN Replace one by a symbolic link to the other
359 set-permissions|upgrade-configuration)
360 $daemon_directory/post-install create-missing "$@"
364 # Currently not part of the public interface.
366 $daemon_directory/post-install "$@"
370 # Currently not part of the public interface.
375 $ERROR "unknown command: '$1'"
376 $FATAL "usage: postfix start (or stop, reload, abort, flush, check, status, set-permissions, upgrade-configuration)"