9 # execute Postfix administrative commands
11 # \fBpostfix-script\fR \fIcommand\fR
13 # The \fBpostfix-script\fR script executes Postfix administrative
14 # commands in an environment that is set up by the \fBpostfix\fR(1)
17 # master(8) Postfix master program
18 # postfix(1) Postfix administrative interface
22 # The Secure Mailer license must be distributed with this software.
25 # IBM T.J. Watson Research
27 # Yorktown Heights, NY 10598, USA
30 # Avoid POSIX death due to SIGHUP when some parent process exits.
34 case $daemon_directory in
35 "") echo This
script must be run by the postfix
command.
1>&2
36 echo Do not run directly.
1>&2
40 LOGGER
="$command_directory/postlog -t $MAIL_LOGTAG/postfix-script"
41 INFO
="$LOGGER -p info"
42 WARN
="$LOGGER -p warn"
43 ERROR
="$LOGGER -p error"
44 FATAL
="$LOGGER -p fatal"
45 PANIC
="$LOGGER -p panic"
51 # Can't do much without these in place.
53 cd $command_directory ||
{
54 $FATAL no Postfix
command directory
$command_directory!
57 cd $daemon_directory ||
{
58 $FATAL no Postfix daemon directory
$daemon_directory!
62 $FATAL no Postfix master program
$daemon_directory/master
!
65 cd $config_directory ||
{
66 $FATAL no Postfix configuration directory
$config_directory!
69 cd $queue_directory ||
{
70 $FATAL no Postfix queue directory
$queue_directory!
73 def_config_directory
=`$command_directory/postconf -dh config_directory` ||
{
74 $FATAL cannot execute
$command_directory/postconf
!
78 # If this is a secondary instance, don't touch shared files.
80 instances
=`test ! -f $def_config_directory/main.cf ||
81 $command_directory/postconf -c $def_config_directory \
82 -h multi_instance_directories | sed 's/,/ /'` ||
{
83 $FATAL cannot execute
$command_directory/postconf
!
88 for name
in $instances
91 "$def_config_directory") ;;
92 "$config_directory") check_shared_files
=; break;;
113 $daemon_directory/master
-t 2>/dev
/null ||
{
114 $FATAL the Postfix
mail system is already running
117 if [ -f $queue_directory/quick-start
]
119 rm -f $queue_directory/quick-start
121 $daemon_directory/postfix-script check-fatal ||
{
122 $FATAL Postfix integrity check failed
!
125 # Foreground this so it can be stopped. All inodes are cached.
126 $daemon_directory/postfix-script check-warn
128 $INFO starting the Postfix
mail system
129 $daemon_directory/master
&
134 $daemon_directory/master
-t 2>/dev
/null
&& {
135 $FATAL the Postfix
mail system is not running
138 $INFO stopping the Postfix
mail system
139 kill -9 `sed 1q pid/master.pid`
144 $daemon_directory/postfix-script stop
145 touch $queue_directory/quick-start
150 $daemon_directory/master
-t 2>/dev
/null
&& {
151 $FATAL the Postfix
mail system is not running
154 $INFO stopping the Postfix
mail system
155 kill `sed 1q pid/master.pid`
158 $daemon_directory/master
-t && exit 0
159 $INFO waiting
for the Postfix
mail system to terminate
162 $WARN stopping the Postfix
mail system with force
163 pid
=`awk '{ print $1; exit 0 } END { exit 1 }' pid/master.pid` &&
169 $daemon_directory/master
-t 2>/dev
/null
&& {
170 $FATAL the Postfix
mail system is not running
173 $INFO aborting the Postfix
mail system
174 kill `sed 1q pid/master.pid`
179 $daemon_directory/master
-t 2>/dev
/null
&& {
180 $FATAL the Postfix
mail system is not running
183 $INFO refreshing the Postfix
mail system
184 $command_directory/postsuper active ||
exit 1
185 kill -HUP `sed 1q pid/master.pid`
186 $command_directory/postsuper
&
191 cd $queue_directory ||
{
192 $FATAL no Postfix queue directory
$queue_directory!
195 $command_directory/postqueue
-f
200 $daemon_directory/postfix-script check-fatal ||
exit 1
201 $daemon_directory/postfix-script check-warn
207 $daemon_directory/master
-t 2>/dev
/null
&& {
208 $INFO the Postfix
mail system is not running
211 $INFO the Postfix
mail system is running
: PID
: `sed 1q pid/master.pid`
217 # This command is NOT part of the public interface.
219 $SHELL $daemon_directory/post-install create-missing ||
{
220 $FATAL unable to create missing queue directories
224 # Look for incomplete installations.
226 test -f $config_directory/master.cf ||
{
227 $FATAL no
$config_directory/master.cf
file found
231 # See if all queue files are in the right place. This is slow.
232 # We must scan all queues for mis-named queue files before the
233 # mail system can run.
235 $command_directory/postsuper ||
exit 1
240 # This command is NOT part of the public interface.
242 todo
="$config_directory $queue_directory $queue_directory/pid"
243 test -n "$check_shared_files" && todo
="$daemon_directory $todo"
247 ls -lLd $dir |
(grep " root " >/dev
/null ||
248 $WARN not owned by root
: $dir)
251 # Some people break Postfix's security model.
252 ls -lLd $queue_directory |
egrep '^.....(w|...w)' >/dev
/null
&& \
253 $WARN group or other writable
: $queue_directory
255 todo
="$config_directory/*"
256 test -n "$check_shared_files" && todo
="$daemon_directory/* $todo"
258 find $todo ! -user root \
259 -exec $WARN not owned by root
: {} \
;
261 todo
="$config_directory/."
262 test -n "$check_shared_files" && todo
="$daemon_directory/. $todo"
265 \
( -perm -020 -o -perm -002 \
) -type f \
266 -exec $WARN group or other writable
: {} \
;
268 find $data_directory/.
! -user $mail_owner \
269 -exec $WARN not owned by
$mail_owner: {} \
;
271 find `ls -d $queue_directory/* | \
272 egrep '/(saved|incoming|active|defer|deferred|bounce|hold|trace|corrupt|public|private|flush)$'` \
273 ! \
( -type p
-o -type s \
) ! -user $mail_owner \
274 -exec $WARN not owned by
$mail_owner: {} \
;
276 todo
="$queue_directory/public $queue_directory/maildrop"
277 test -n "$check_shared_files" &&
278 todo
="$command_directory/postqueue $command_directory/postdrop $todo"
281 -prune ! -group $setgid_group \
282 -exec $WARN not owned by group
$setgid_group: {} \
;
284 test -n "$check_shared_files" &&
285 find $command_directory/postqueue
$command_directory/postdrop \
286 -prune ! -perm -02111 \
287 -exec $WARN not set-gid or not owner
+group
+world executable
: {} \
;
289 for name
in `ls -d $queue_directory/* | \
290 egrep '/(bin|etc|lib|usr)$'` ; \
292 find $name ! -user root \
293 -exec $WARN not owned by root
: {} \
; ; \
296 # WARNING: this should not descend into the maildrop directory.
297 # maildrop is the least trusted Postfix directory.
299 find $queue_directory/maildrop
/.
-prune ! -user $mail_owner \
300 -exec $WARN not owned by
$mail_owner: $queue_directory/maildrop \
;
302 for dir
in bin etc lib sbin usr
304 test -d $dir && find $dir -type f
-print |
while read path
307 cmp -s $path /$path ||
308 $WARN $queue_directory/$path and
/$path differ
313 find corrupt
-type f
-exec $WARN damaged message
: {} \
;
315 # XXX also: look for weird stuff, weird permissions, etc.
317 test -n "$check_shared_files" -a -f /usr
/sbin
/sendmail
-a \
318 -f /usr
/lib
/sendmail
&& {
319 cmp -s /usr
/sbin
/sendmail
/usr
/lib
/sendmail ||
{
320 $WARN /usr
/lib
/sendmail and
/usr
/sbin
/sendmail differ
321 $WARN Replace one by a symbolic link to the other
327 set-permissions|upgrade-configuration
)
328 $daemon_directory/post-install create-missing
"$@"
332 # Currently not part of the public interface.
334 $daemon_directory/post-install
"$@"
338 # Currently not part of the public interface.
343 $ERROR "unknown command: '$1'"
344 $FATAL "usage: postfix start (or stop, reload, abort, flush, check, status, set-permissions, upgrade-configuration)"