#! /bin/csh -f
#
# (c) Copyright 1993-1997 Check Point Software Technologies Ltd.
# All rights reserved.
# 
# This is proprietary information of Check Point Software Technologies
# Ltd., which is provided for informational purposes only and for use
# solely in conjunction with the authorized use of Check Point Software
# Technologies Ltd. products.  The viewing and use of this information is
# subject, to the extent appropriate, to the terms and conditions of the
# license agreement that authorizes the use of the relevant product.
# 
#
# $Header: /fw/cvs/fw-1/fwutil/fwstop.csh,v 1.20.2.6 1997/08/10 12:50:31 ofer Exp $
#

#
# Usage: fwstop [-proc]
#
# -proc: kill only user-mode processes 

if (! $?FWDIR) setenv FWDIR /etc/fw
set path = ( $FWDIR/bin /bin /usr/bin /etc /usr/etc )

source ${FWDIR}/scripts/readprod

fw kill fwd
fw kill snmpd

if ($fw1_management) then
	fw kill fwm
	fw kill fwalert >& /dev/null
endif

if ($fw1_firewall == 0) goto no_modunload

if ($fw1_auth) then
	fw kill in.ahttpd >& /dev/null
	fw kill in.atelnetd >& /dev/null
	fw kill in.arlogind >& /dev/null
	fw kill in.aftpd >& /dev/null
	fw kill in.asmtpd >& /dev/null
endif
fw kill in.aclientd >& /dev/null
fw kill in.lhttpd >& /dev/null

if ("X$1" == "X-proc") goto no_modunload

if (-f /kernel/genunix || -f /kernel/unix || -f /hp-ux || -f /stand/vmunix) then
	fw unload all.all
	fw ctl uninstall
	goto no_modunload
endif

if (-f /usr/lib/drivers/netinet) then
	fw unload all.all
	fw ctl uninstall
	$FWDIR/modules/fw_cfg -u
	goto no_modunload
endif

if (-f /kernel) then
	#
	# Freebsd
	#
    /sbin/modunload -n fw1_mod >& /dev/null
    if ($status != 0) then
        echo 'fwstop: Module not loaded'
        exit 1
    endif
    exit 0
endif

set id = `modstat |  awk 'BEGIN { found = 1; } { for(i = 2; i <= NF; i++) if($i == "fw") { print $1; found = 0; }} END { exit found; }'`
if ($status) then
	echo 'fwstop: Module not loaded'
	exit 1
endif
sleep 2
echo 'FW: Unloading kernel module'
modunload -id $id

no_modunload:

exit 0
