
#-----------------------------------------------------------------------
# Copyright (C) 2000-2001, Jean-Sebastien Morisset <jsmoriss@mvlan.net>
#-----------------------------------------------------------------------
# $Id: include_group.sh,v 1.5 2001/08/11 17:01:20 jsmoriss Exp $
#-----------------------------------------------------------------------
#  $RCSfile: include_group.sh,v $
#   $Author: jsmoriss $
# $Revision: 1.5 $
#     $Date: 2001/08/11 17:01:20 $
#   $Locker:  $ 
#     $Name:  $
#-----------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation <http://www.gnu.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License (LICENSE file in archive) for more details.
#
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# A bourne shell function used by rcf; a very secure, fast, and complete
# firewall for linux <http://jsmoriss.mvlan.net/linux/rcf.html>.
#
#-----------------------------------------------------------------------
# FUNCTION
#-----------------------------------------------------------------------

Include_Group () {

	OPTION=$1
	eval VALUE=\"\$$OPTION\"

	# skip options we know don't contain a group spec.
	[ "$VALUE" ] && if [ "`echo $VALUE|sed -ne 's/^.*\([ \.]\/\).*$/\1/p'`" ]
	then
		SEARCH_FOR_GROUP="1"	# search option at least once
		while [ "$SEARCH_FOR_GROUP" -gt "0" ]
		do
			SEARCH_FOR_GROUP="0"	# don't search again unless we reset this variable
			for FIELD in $VALUE
			do
				if [ "`echo $FIELD|sed -ne 's/^\(\/\).*$/\1/p'`" ]
				then
					FILENAME="${FIELD}"
				elif [ "`echo $FIELD|sed -ne 's/^\(\.\/\).*$/\1/p'`" ]
				then
					FILENAME="${GROUP_DIR}/`echo $FIELD|sed -e 's/^\.\///'`"
				fi
	
				[ "$FILENAME" ] && \
					if [ -f "$FILENAME" ]
					then
						echo "Adding `Sed_Basename $FILENAME` group to $OPTION"
						FIELD="`sed -ne 's/^\([^# ]*\).*$/\1/p' $FILENAME`"
						# search again if we find another file spec.
						[ "`echo $FIELD|sed -ne 's/^.*\([ \.]\/\).*$/\1/p'`" ] && SEARCH_FOR_GROUP="1"
					else
						echo "WARNING: Unable to read $FILENAME"
						echo "         group into $OPTION option!"
						FIELD=""
					fi
				unset FILENAME
				[ "$NEW_VALUE" ] && NEW_VALUE="$NEW_VALUE $FIELD" || NEW_VALUE="$FIELD"
			done
			# reset variable for next search
			VALUE="$NEW_VALUE"
			unset NEW_VALUE
		done
		eval $OPTION=\"$VALUE\"
		unset SEARCH_FOR_GROUP FIELD
	fi
	unset OPTION VALUE
}

