#-----------------------------------------------------------------------
# Copyright (C) 2000-2001, Jean-Sebastien Morisset <jsmoriss@mvlan.net>
#-----------------------------------------------------------------------
# $Id: 610-afp-clients,v 1.1 2001/10/04 23:32:27 cjgraham Exp $
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# This module should be placed in /etc/firewall/modules/public/services.
# You'll also need the port forwarding module (in public/port-forwarding)
#
# After installing the module, the user should execute rc.firewall with
# the --update-config parameter. The necessary options will be added to
# the configuration file.
#
#-----------------------------------------------------------------------
# MODULE CONFIGURATION
#-----------------------------------------------------------------------
#
#m# 23
#a# accept ignore deny
#i# cluster
#n# afp
#t# clients
#
#   |--------------------------------------------------------------------|
#d# afp (Ports 548 TCP, 548 UDP)
#d# The following rules will allow an external Macintosh to connect to
#d# an internal Apple File Server host when strict or paranoid mode is on.
#   |--------------------------------------------------------------------|
#
#-----------------------------------------------------------------------
# START OF MODULE CODE
#-----------------------------------------------------------------------

module_name="afp"           # module name used in options
module_type="clients"       # the module type (clients, servers, etc.)
service_name="AFP"          # displayed on-screen
tcp_service_port="548"      # port number for this service
udp_service_port="548"      # port number for this service

[ ! "$CLUSTER_NAME" ] && { inchain="$INCHAIN"; outchain="$OUTCHAIN"; } || \
                         { inchain="$OUTCHAIN"; outchain="$INCHAIN"; }

for action in ignore deny accept
do
	case $action in
		accept|ignore)
			action_log_msg="$LOG_MSG"; action_log="$LOG";;
		deny)
			action_log_msg="(logged)"; action_log="-l"  ;;
	esac

	for host in `Option_Value $action $INTOPT $module_name $module_type`
	do
		case $action in
			ignore|deny)
				echo "Deny $INTOPT $IPADDR $service_name <- $host $action_log_msg"
				ipchains -A $inchain -j DENY -p tcp -s $host -d $IPADDR $tcp_service_port $action_log
				ipchains -A $inchain -j DENY -p udp -s $host -d $IPADDR $udp_service_port $action_log
				;;
			accept)
				Hostports accept local tcp "$service_name" $host $tcp_service_port
				Hostports accept local udp ""              $host $udp_service_port
				;;
		esac
	done
done

unset module_name module_type service_name service_port
unset action action_log_msg action_log host inchain outchain

