#!/bin/sh
#RC:RUNINRC
#RC:AFTER network2
#
#	$Id: rc.network,v 1.35 1998/11/15 20:30:04 msmith Exp $
#	From: @(#)netstart	5.9 (Berkeley) 3/30/91

# Note that almost all the user-configurable behavior is no longer in
# this file, but rather in /etc/rc.conf.  Please check that file
# first before contemplating any changes here.  If you do need to change
# this file for some reason, we would like to know about it.

if [ -n "$network_pass2_done" ]; then
    echo -n 'Starting final network daemons:'

    if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then
	    echo -n ' mountd'
	    if [ "X${weak_mountd_authentication}" = X"YES" ]; then
		    mountd_flags="-n"
	    fi
	    mountd ${mountd_flags}
	    if [ "X${nfs_reserved_port_only}" = X"YES" ]; then
		    sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 2>&1
	    fi
	    echo -n ' nfsd';		nfsd ${nfs_server_flags}
	    if [ "X$rpc_lockd_enable" = X"YES" ]; then
		echo -n ' rpc.lockd';		rpc.lockd
	    fi
	    if [ "X$rpc_statd_enable" = X"YES" ]; then
		echo -n ' rpc.statd';		rpc.statd
	    fi
    fi
    
    if [ "X${nfs_client_enable}" = X"YES" ]; then
	    echo -n ' nfsiod';		nfsiod ${nfs_client_flags}
	    if [ ! "X${nfs_access_cache}" = X ]; then
		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache}
	    fi
    fi

    if [ "X${amd_enable}" = X"YES" ]; then
	    echo -n ' amd'
	    if [ "X${amd_map_program}" != X"NO" ]; then
		amd_flags="${amd_flags} `eval ${amd_map_program}`"
	    fi
	    amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
    fi

    if [ "X${rwhod_enable}" = X"YES" ]; then
	    echo -n ' rwhod';	rwhod
    fi

    # Kerberos runs ONLY on the Kerberos server machine
    if [ "X${kerberos_server_enable}" = X"YES" ]; then
	    if [ "X${kerberos_stash}" = "XYES" ]; then
		stash_flag=-n
	    else
		stash_flag=
	    fi
	    echo -n ' kerberos'; \
		kerberos ${stash_flag} >> /var/log/kerberos.log &
	    if [ "X${kadmind_server_enable}" = "XYES" ]; then
		echo -n ' kadmind'; \
		(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
	    fi
	    unset stash_flag
    fi
    
    # Network Address Translation daemon
       if [ "X${natd_enable}" = X"YES" -a X"${natd_interface}" != X"" \
               -a X"${firewall_enable}" = X"YES" ]; then
               if echo ${natd_interface} | \
                       grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
                       natd_ifarg="-a ${natd_interface}"
               else
                       natd_ifarg="-n ${natd_interface}"
               fi
               echo -n ' natd'; natd ${natd_flags} ${natd_ifarg}
       fi

    echo '.'
    network_pass3_done=YES
fi
