#!/bin/ksh -p
#
# ident "@(#)utatiscrub.ksh	1.3	08/10/30 SMI"
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# utatiscrub - Automatic Token Importation Stale Registration Removal
#

Usage() {
	printf "Usage: %s\n" `basename $0`
}

selectImportedTokens() {
	${UTUSER} -xo \
		| /bin/nawk -F, '$1 ~ "user\\.IMPORTED-.*" \
		 { print $2 }'
}

# main

PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Solaris 10 Trusted Extension guard
#
ORIGIN=`/usr/bin/dirname $0`
UTIL_LIB=${ORIGIN:-/opt/SUNWut/lib}/../lib/support_lib/util_lib
. $UTIL_LIB
FailExecInLocalZoneOnTx
#
# Solaris 10 Trusted Extension guard
#

UTATI=/etc/opt/SUNWut/basedir/lib/utati
UTUSER=/etc/opt/SUNWut/basedir/sbin/utuser

if [ $# != 0 ]; then
	Usage
	exit 1
fi

for token in `selectImportedTokens`; do
	${UTATI} -d $token
	STATUS=$?
	if [ $STATUS -ne 0 ]; then
		logger -p user.error -t `basename $0` "utati returned status $STATUS"
	fi
done

exit 0
