#!/bin/sh
#
# rc.inet2	This shell script boots up the entire INET system.
#		Note, that when this script is used to also fire
#		up any important remote NFS disks (like the /usr
#		distribution), care must be taken to actually
#		have all the needed binaries online _now_ ...
#
# Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
# Modified for Slackware by Patrick Volkerding <volkerdi@slackware.com>
#

# Some constants:
NET="/usr/sbin"
IN_SERV="lpd"
LPSPOOL="/var/spool/lpd"

# If we see IPv4 packet forwarding support in the kernel, we will turn it on.
# This was the default for 2.0.x kernels, but with recent kernels it must be
# activated through a file in /proc.  IPv4 packet forwarding support is 
# required if you plan to use your Linux machine as a router or firewall.
# If you don't want your Linux machine to forward packets, change the 1 below
# to a 0.
IPV4_FORWARD=1
if [ -f /proc/sys/net/ipv4/ip_forward ]; then
  if [ "$IPV4_FORWARD" = "1" ]; then
    echo "Activating IPv4 packet forwarding..."
    echo 1 > /proc/sys/net/ipv4/ip_forward
  else
    echo "Disabling IPv4 packet forwarding..."
    echo 0 > /proc/sys/net/ipv4/ip_forward
  fi
fi

# When using IPv4 packet forwarding, you will also get the rp_filter, which
# automatically rejects incoming packets if the routing table entry for their
# source address doesn't match the network interface they're arriving on.  This
# has security advantages because it prevents the so-called IP spoofing,
# however it can pose problems if you use asymmetric routing (packets from you
# to a host take a different path than packets from that host to you) or if
# you operate a non-routing host which has several IP addresses on different
# interfaces.  To turn rp_filter off, uncomment the lines below:
# if [ -r /proc/sys/net/ipv4/conf/all/rp_filter ]; then
#   echo "Disabling rp_filter..."
#   echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
# fi

# Start the SUN RPC Portmapper:
if [ -x /sbin/rpc.portmap ]; then
  echo "Starting /sbin/rpc.portmap..."
  /sbin/rpc.portmap
fi

# At this point, we are ready to talk to The World...

# Mount NFS filesystems:
echo "Mounting remote file systems..."
/sbin/mount -a -t nfs      	 # This may be our /usr runtime!!!
# Show the mounted volumes:
/sbin/mount -v -t nfs

# Begin a list of started daemons:
echo -n "Starting daemons: "

# Start the SYSLOGD/KLOGD daemons:
if [ -x ${NET}/syslogd ]; then
  echo -n " syslogd"
  ${NET}/syslogd
  sleep 1 # prevent syslogd/klogd race condition on SMP kernels
  echo -n " klogd"
  # '-c 3' = display level 'error' or higher messages on console
  ${NET}/klogd -c 3
fi

# Start the INET SuperServer:
if [ -x ${NET}/inetd ]; then
  echo -n " inetd"
  ${NET}/inetd
else
  echo
  echo "WARNING:  ${NET}/inetd not found."
  echo -n "Continuing daemon loading: "
fi

# Look for sshd in the two most common locations (compiled with --prefix=/usr
# or with --prefix=/usr/local) and if we find it, start it up
if [ -x /usr/local/sbin/sshd ]; then
  echo -n " sshd"
  /usr/local/sbin/sshd
elif [ -x /usr/sbin/sshd ]; then
  echo -n " sshd"
  /usr/sbin/sshd
fi

# # Option number one:  Start the NAMED/BIND name server as root.
# # Note that BIND has a somewhat spotty history in terms of security,
# # but they recommend running it as root, and if you don't, not all
# # the features (especially when attached to a dynamic IP such as
# # through PPP) will neccessary work correctly).
# if [ -x ${NET}/named ]; then
#   echo -n " named"
#   ${NET}/named
# fi

# # Option number two:  Start the NAMED/BIND name server as user daemon.
# # This is another way to start BIND for the more paranoid.  By starting it as
# # user daemon, group daemon, if there does turn out to be a vulnerability,
# # the attacker can at best gain user deamon access to your machine, which is
# # a considerably better situation than if they gain root access.  Note that
# # for this option to work at all, you'll need to change the ownership of the
# # directory /var/named to daemon like this: chown -R daemon.daemon /var/named
# # If you don't have this directory, you'll have to make it first.
# # Also, for the *really* paranoid, you can read this document for
# # instructions on running BIND in a "chroot jail":
# #   /usr/doc/Linux-HOWTOs/Chroot-BIND-HOWTO
# if [ -x ${NET}/named ]; then
#   echo -n " named"
#   ${NET}/named -u daemon -g daemon
# fi

# # Start the ROUTEd server:
# if [ -x ${NET}/routed ]; then
#   echo -n " routed"
#   ${NET}/routed -g -s
# fi

# # Start the RWHO server:
# if [ -x ${NET}/rwhod ]; then
#   echo -n " rwhod"
#   ${NET}/rwhod
# fi

# Start the various INET servers:
for server in ${IN_SERV} ; do
  if [ -x ${NET}/${server} ]; then
    echo -n " ${server}"
    ${NET}/${server}
  fi
done

# # Setting up NIS:
# # (NOTE: For detailed information about setting up NIS, see the documentation
# # in /usr/doc/yp-tools, /usr/doc/ypbind, and /usr/doc/ypserv)
# #
# # First, we must set the NIS domainname.  NOTE: this is not
# # necessarily the same as your DNS domainname, set in 
# # /etc/resolv.conf!  The NIS domainname is the name of a domain
# # served by your NIS server.
#
# if [ -r /etc/defaultdomain ]; then
#   nisdomainname `cat /etc/defaultdomain`
# fi
#
# # Then, we start up ypbind.  It will use broadcast to find a server.
#
# if [ -d /var/yp ] ; then
#   echo -n " ypbind"
#   ${NET}/ypbind 
# fi
#
# # If you are the NIS master server for the NIS domain, then
# # you must run rpc.yppasswdd, which is the RPC server that 
# # lets users change their passwords.
#
# if [ -x ${NET}/rpc.yppasswdd ]; then
#   echo -n " yppasswdd"
#   ${NET}/rpc.yppasswdd
# fi 

# # Start the various SUN RPC servers:
if [ -x /sbin/rpc.portmap ]; then
  # Start the NFS server daemons.
  if [ -x ${NET}/rpc.mountd ]; then
    echo -n " mountd"
    ${NET}/rpc.mountd
  fi
  if [ -x ${NET}/rpc.nfsd ]; then
    echo -n " nfsd"
    ${NET}/rpc.nfsd
  fi
#  # Fire up the PC-NFS daemon(s):
#  if [ -x ${NET}/rpc.pcnfsd ]; then
#    echo -n " pcnfsd"
#    ${NET}/rpc.pcnfsd ${LPSPOOL}
#  fi
#  if [ -x ${NET}/rpc.bwnfsd ]; then
#    echo -n " bwnfsd"
#    ${NET}/rpc.bwnfsd ${LPSPOOL}
#  fi
fi # Done starting various SUN RPC servers.

# The 'echo' below will put a carriage return at the end
# of the list of started servers.
echo

# Done!

