home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 16 / hacker16 / 16_HACKER16.ISO / linux / tpm-security-server-1.2.1.iso / archive / etc / rc.d / init.d / ipsec < prev    next >
Encoding:
Text File  |  2004-01-29  |  4.1 KB  |  163 lines

  1. #!/bin/sh
  2. # IPsec startup and shutdown script
  3. # Copyright (C) 1998, 1999, 2001  Henry Spencer.
  4. # Copyright (C) 2002              Michael Richardson <mcr@freeswan.org>
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by the
  7. # Free Software Foundation; either version 2 of the License, or (at your
  8. # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12. # for more details.
  13. #
  14. # RCSID $Id: setup.in,v 1.118 2003/02/27 16:51:55 dhr Exp $
  15. #
  16. # ipsec         init.d script for starting and stopping
  17. #               the IPsec security subsystem (KLIPS and Pluto).
  18. #
  19. # This script becomes /etc/rc.d/init.d/ipsec (or possibly /etc/init.d/ipsec)
  20. # and is also accessible as "ipsec setup" (the preferred route for human
  21. # invocation).
  22. #
  23. # The startup and shutdown times are a difficult compromise (in particular,
  24. # it is almost impossible to reconcile them with the insanely early/late
  25. # times of NFS filesystem startup/shutdown).  Startup is after startup of
  26. # syslog and pcmcia support; shutdown is just before shutdown of syslog.
  27. #
  28. # chkconfig: 2345 47 68
  29. # description: IPsec provides encrypted and authenticated communications; \
  30. # KLIPS is the kernel half of it, Pluto is the user-level management daemon.
  31.  
  32. me='ipsec setup'        # for messages
  33.  
  34.  
  35. # where the private directory and the config files are
  36. IPSEC_EXECDIR="${IPSEC_EXECDIR-/usr/libexec/ipsec}"
  37. IPSEC_LIBDIR="${IPSEC_LIBDIR-/usr/lib/ipsec}"
  38. IPSEC_SBINDIR="${IPSEC_SBINDIR-/usr/sbin}"
  39. IPSEC_CONFS="${IPSEC_CONFS-/etc}"
  40.  
  41. if test " $IPSEC_DIR" = " "    # if we were not called by the ipsec command
  42. then
  43.     # we must establish a suitable PATH ourselves
  44.     PATH="${IPSEC_SBINDIR}":/sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin
  45.     export PATH
  46.  
  47.     IPSEC_DIR="$IPSEC_LIBDIR"
  48.     export IPSEC_DIR IPSEC_CONFS IPSEC_LIBDIR IPSEC_EXECDIR
  49. fi
  50.  
  51. # Check that the ipsec command is available.
  52. found=
  53. for dir in `echo $PATH | tr ':' ' '`
  54. do
  55.     if test -f $dir/ipsec -a -x $dir/ipsec
  56.     then
  57.         found=yes
  58.         break            # NOTE BREAK OUT
  59.     fi
  60. done
  61. if ! test "$found"
  62. then
  63.     echo "cannot find ipsec command -- \`$1' aborted" |
  64.         logger -s -p daemon.error -t ipsec_setup
  65.     exit 1
  66. fi
  67.  
  68. # accept a few flags
  69.  
  70. export IPSEC_setupflags
  71. IPSEC_setupflags=""
  72.  
  73. config=""
  74.  
  75. for dummy
  76. do
  77.     case "$1" in
  78.     --showonly|--show)  IPSEC_setupflags="$1" ;;
  79.     --config)  config="--config $2" ; shift    ;;
  80.     *) break ;;
  81.     esac
  82.     shift
  83. done
  84.  
  85.  
  86. # Pick up IPsec configuration (until we have done this, successfully, we
  87. # do not know where errors should go, hence the explicit "daemon.error"s.)
  88. # Note the "--export", which exports the variables created.
  89. eval `ipsec _confread $config --optional --varprefix IPSEC --export --type config setup`
  90. if test " $IPSEC_confreadstatus" != " "
  91. then
  92.     echo "$IPSEC_confreadstatus -- \`$1' aborted" |
  93.         logger -s -p daemon.error -t ipsec_setup
  94.     exit 1
  95. fi
  96.  
  97. IPSEC_confreadsection=${IPSEC_confreadsection:-setup}
  98. export IPSEC_confreadsection
  99.  
  100. IPSECsyslog=${IPSECsyslog-daemon.error}
  101. export IPSECsyslog
  102.  
  103. # misc setup
  104. umask 022
  105.  
  106.  
  107. # do it
  108. case "$1" in
  109.   start|--start|stop|--stop|_autostop|_autostart)
  110.     if test " `id -u`" != " 0"
  111.     then
  112.         echo "permission denied (must be superuser)" |
  113.             logger -s -p $IPSECsyslog -t ipsec_setup 2>&1
  114.         exit 1
  115.     fi
  116.     tmp=/var/run/ipsec_setup.st
  117.     (
  118.         ipsec _realsetup $1
  119.         echo "$?" >$tmp
  120.     ) 2>&1 | logger -s -p $IPSECsyslog -t ipsec_setup 2>&1
  121.     st=$?
  122.     if test -f $tmp
  123.     then
  124.         st=`cat $tmp`
  125.         rm -f $tmp
  126.     fi
  127.     exit $st
  128.     ;;
  129.  
  130.   restart|--restart|force-reload)
  131.     $0 $IPSEC_setupflags stop
  132.     $0 $IPSEC_setupflags start
  133.     ;;
  134.  
  135.   _autorestart)            # for internal use only
  136.     $0 $IPSEC_setupflags _autostop
  137.     $0 $IPSEC_setupflags _autostart
  138.     ;;
  139.  
  140.   status|--status)
  141.     ipsec _realsetup $1
  142.     exit
  143.     ;;
  144.  
  145.   --version)
  146.     echo "$me $IPSEC_VERSION"
  147.     exit 0
  148.     ;;
  149.  
  150.   --help)
  151.     echo "Usage: $me {--start|--stop|--restart|--status}"
  152.     exit 0
  153.     ;;
  154.  
  155.   *)
  156.     echo "Usage: $me {--start|--stop|--restart|--status}" >&2
  157.     exit 2
  158. esac
  159.  
  160. exit 0
  161.