home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20120305.etc.tar.gz / bradford.20120305.etc.tar / etc / postfix / postfix-script < prev    next >
Text File  |  2006-05-02  |  6KB  |  284 lines

  1. #!/bin/sh
  2.  
  3. #++
  4. # NAME
  5. #    postfix-script 1
  6. # SUMMARY
  7. #    execute Postfix administrative commands
  8. # SYNOPSIS
  9. #    \fBpostfix-script\fR \fIcommand\fR
  10. # DESCRIPTION
  11. #    The \fBpostfix-script\fR script executes Postfix administrative
  12. #    commands in an environment that is set up by the \fBpostfix\fR(1)
  13. #    command.
  14. # SEE ALSO
  15. #    master(8) Postfix master program
  16. #    postfix(1) Postfix administrative interface
  17. # LICENSE
  18. # .ad
  19. # .fi
  20. #    The Secure Mailer license must be distributed with this software.
  21. # AUTHOR(S)
  22. #    Wietse Venema
  23. #    IBM T.J. Watson Research
  24. #    P.O. Box 704
  25. #    Yorktown Heights, NY 10598, USA
  26. #--
  27.  
  28. # Avoid POSIX death due to SIGHUP when some parent process exits.
  29.  
  30. trap '' 1
  31.  
  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
  35.     exit 1
  36. esac
  37.  
  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"
  44.  
  45. umask 022
  46. SHELL=/bin/sh
  47.  
  48. #
  49. # Can't do much without these in place.
  50. #
  51. cd $command_directory || {
  52.     $FATAL no Postfix command directory $command_directory!
  53.     exit 1
  54. }
  55. cd $daemon_directory || {
  56.     $FATAL no Postfix daemon directory $daemon_directory!
  57.     exit 1
  58. }
  59. test -f master || {
  60.     $FATAL no Postfix master program $daemon_directory/master!
  61.     exit 1
  62. }
  63. cd $config_directory || {
  64.     $FATAL no Postfix configuration directory $config_directory!
  65.     exit 1
  66. }
  67. cd $queue_directory || {
  68.     $FATAL no Postfix queue directory $queue_directory!
  69.     exit 1
  70. }
  71.  
  72. #
  73. # Parse JCL
  74. #
  75. case $1 in
  76.  
  77. start_msg)
  78.  
  79.     echo "Start postfix"
  80.     ;;
  81.  
  82. stop_msg)
  83.  
  84.     echo "Stop postfix"
  85.     ;;
  86.  
  87. start)
  88.  
  89.     $daemon_directory/master -t 2>/dev/null || {
  90.         $FATAL the Postfix mail system is already running
  91.         exit 1
  92.     }
  93.     if [ -f $queue_directory/quick-start ]
  94.     then
  95.         rm -f $queue_directory/quick-start
  96.     else
  97.         $config_directory/postfix-script check-fatal || {
  98.             $FATAL Postfix integrity check failed!
  99.             exit 1
  100.         }
  101.         # Foreground this so it can be stopped. All inodes are cached.
  102.         $config_directory/postfix-script check-warn
  103.     fi
  104.     $INFO starting the Postfix mail system
  105.     $daemon_directory/master &
  106.     ;;
  107.  
  108. drain)
  109.  
  110.     $daemon_directory/master -t 2>/dev/null && {
  111.         $FATAL the Postfix mail system is not running
  112.         exit 1
  113.     }
  114.     $INFO stopping the Postfix mail system
  115.     kill -9 `sed 1q pid/master.pid`
  116.     ;;
  117.  
  118. quick-stop)
  119.  
  120.     $config_directory/postfix-script stop
  121.     touch $queue_directory/quick-start
  122.     ;;
  123.  
  124. stop)
  125.  
  126.     $daemon_directory/master -t 2>/dev/null && {
  127.         $FATAL the Postfix mail system is not running
  128.         exit 1
  129.     }
  130.     $INFO stopping the Postfix mail system
  131.     kill `sed 1q pid/master.pid`
  132.     ;;
  133.  
  134. abort)
  135.  
  136.     $daemon_directory/master -t 2>/dev/null && {
  137.         $FATAL the Postfix mail system is not running
  138.         exit 1
  139.     }
  140.     $INFO aborting the Postfix mail system
  141.     kill `sed 1q pid/master.pid`
  142.     ;;
  143.  
  144. reload)
  145.  
  146.     $daemon_directory/master -t 2>/dev/null && {
  147.         $FATAL the Postfix mail system is not running
  148.         exit 1
  149.     }
  150.     $INFO refreshing the Postfix mail system
  151.     $command_directory/postsuper active || exit 1
  152.     kill -HUP `sed 1q pid/master.pid`
  153.     $command_directory/postsuper &
  154.     ;;
  155.  
  156. flush)
  157.  
  158.     cd $queue_directory || {
  159.         $FATAL no Postfix queue directory $queue_directory!
  160.         exit 1
  161.     }
  162.     $command_directory/postqueue -f
  163.     ;;
  164.  
  165. check)
  166.  
  167.     $config_directory/postfix-script check-fatal || exit 1
  168.     $config_directory/postfix-script check-warn
  169.     exit 0
  170.     ;;
  171.  
  172. check-fatal)
  173.     # This command is NOT part of the public interface.
  174.  
  175.     $SHELL $config_directory/post-install create-missing || {
  176.         $WARN unable to create missing queue directories
  177.         exit 1
  178.     }
  179.  
  180.     # Look for incomplete installations.
  181.  
  182.     test -f $config_directory/master.cf || {
  183.         $FATAL no $config_directory/master.cf file found
  184.         exit 1
  185.     }
  186.  
  187.     # See if all queue files are in the right place. This is slow.
  188.     # We must scan all queues for mis-named queue files before the
  189.     # mail system can run.
  190.  
  191.     $command_directory/postsuper || exit 1
  192.     exit 0
  193.     ;;
  194.  
  195. check-warn)
  196.     # This command is NOT part of the public interface.
  197.  
  198.     for dir in $daemon_directory $config_directory $queue_directory
  199.     do
  200.         ls -lLd $dir | (grep " root " >/dev/null ||
  201.             $WARN not owned by root: $dir)
  202.     done
  203.  
  204.     find $daemon_directory/* $config_directory/* ! -user root \
  205.         -exec $WARN not owned by root: {} \;
  206.  
  207.     find $daemon_directory/. $config_directory/. \
  208.         \( -perm -020 -o -perm -002 \) -type f \
  209.         -exec $WARN group or other writable: {} \;
  210.  
  211.     find `ls -d $queue_directory/* | \
  212.         egrep '/(incoming|active|defer|deferred|bounce|hold|trace|corrupt|public|private|flush)$'` \
  213.         ! \( -type p -o -type s \) ! -user $mail_owner \
  214.         -exec $WARN not owned by $mail_owner: {} \;
  215.  
  216.     find $queue_directory/public $queue_directory/maildrop \
  217.         $command_directory/postqueue $command_directory/postdrop \
  218.         -prune ! -group $setgid_group \
  219.         -exec $WARN not owned by group $setgid_group: {} \;
  220.  
  221.     find $command_directory/postqueue $command_directory/postdrop \
  222.         -prune ! -perm -02111 \
  223.         -exec $WARN not set-gid or not owner+group+world executable: {} \;
  224.  
  225.     for name in `ls -d $queue_directory/* | \
  226.         egrep '/(bin|etc|lib|usr)$'` ; \
  227.     do \
  228.         find $name ! -user root \
  229.         -exec $WARN not owned by root: {} \; ; \
  230.     done
  231.  
  232.     # WARNING: this should not descend into the maildrop directory.
  233.     # maildrop is the least trusted Postfix directory.
  234.  
  235.     find $queue_directory/maildrop/. -prune ! -user $mail_owner \
  236.         -exec $WARN not owned by $mail_owner: $queue_directory/maildrop \;
  237.  
  238.     for dir in bin etc lib sbin usr
  239.     do
  240.         test -d $dir && find $dir -type f -print | while read path
  241.         do
  242.             test -f /$path && {
  243.                 cmp -s $path /$path || 
  244.                 $WARN $queue_directory/$path and /$path differ
  245.             }
  246.         done
  247.     done
  248.  
  249.     find corrupt -type f -exec $WARN damaged message: {} \;
  250.  
  251.     # XXX also: look for weird stuff, weird permissions, etc.
  252.  
  253.     test -f /usr/sbin/sendmail -a -f /usr/lib/sendmail && {
  254.         cmp -s /usr/sbin/sendmail /usr/lib/sendmail || {
  255.         $WARN /usr/lib/sendmail and /usr/sbin/sendmail differ
  256.         $WARN Replace one by a symbolic link to the other
  257.         }
  258.     }
  259.     exit 0
  260.     ;;
  261.  
  262. set-permissions|upgrade-configuration)
  263.     $config_directory/post-install create-missing "$@"
  264.     ;;
  265.  
  266. post-install)
  267.     # Currently not part of the public interface.
  268.     shift
  269.     $config_directory/post-install "$@"
  270.     ;;
  271.  
  272. /*)
  273.     # Currently not part of the public interface.
  274.     "$@"
  275.     ;;
  276.  
  277. *)
  278.  
  279.     $FATAL "usage: postfix start (or stop, reload, abort, flush, check, set-permissions, upgrade-configuration)"
  280.     exit 1
  281.     ;;
  282.  
  283. esac
  284.