#!/bin/sh
#
#ident	"@(#)i.krbconf	1.3	07/11/14 SMI"
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

KRBCONFTMP=${PKG_INSTALL_ROOT:-/}/etc/krb5/krb5conftmp.$$

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

while read src dest
do
	if [ ! -f $dest ] ; then
		cp $src $dest
	else
		sed -e "/^[	 ]*___slave_kdcs___/d" \
			-e "/^[	 ]*___domain_mapping___/d" $dest > $KRBCONFTMP
		cp $KRBCONFTMP $dest
		rm -f $KRBCONFTMP

		# If the existing krb5.conf file is not configured and using
		# the old template (resulting in mis-configuration) then 
		# comment-out the misconfigured entries.
		egrep -s "^[ 	]*default_realm = ___default_realm___" $dest
		if [ $? -eq 0 ] ; then
			sed -e "s/^\([ 	]*default_realm = ___default_realm___\)/#\1/" \
			    -e "s/^\([ 	]*___default_realm___ = {\)/#\1/" \
			    -e "s/^\([ 	]*kdc = ___master_kdc___\)/#\1/" \
			    -e "s/^\([ 	]*kdc = ___slave_kdc.___\)/#\1/g" \
			    -e '/^[ 	]*admin_server = ___master_kdc___/{
			        N
			        s/^\([ 	]*admin_server = ___master_kdc___\)\n\([ 	]*\}\)$/#\1\
#\2/
			    }' \
			    -e "s/^\([ 	]*___domainname___ = ___default_realm___\)/#\1/" \
			    $dest > $KRBCONFTMP
			cp $KRBCONFTMP $dest
			rm -f $KRBCONFTMP
		fi
	fi
done
exit 0
