File:  [CSRG BSD Unix] / 43BSDReno / contrib / isode-beta / others / quipu / uips / manage / alias_chk
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:56 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43reno
BSD 4.3reno

#!/bin/sh

#Syntax:		alias_chk	<DN> 
#
# Think of better name. Tool designed to check recursively through tree for
# bad aliases, and what is wrong.

# A file name for the bad aliases and diagnostics to be echoed into...
Error_file=ALIAS_ERR_DETCTD

if test -z "$DISHPROC"
then
        DISHPROC="127.0.0.1 `expr $$ + 10000`"
        export DISHPROC
fi

if test $# = 0
then
	echo "We need an object. Aborting..."
	exit
fi

echo Binding...
if test $# -gt 1
then
	bind -c $2
else
	bind
fi

if ( moveto "$1" )
then
	echo -n
else
	echo "Does '$1' exist?"
	exit
fi

if test `compare -attribute "objectClass=alias" -print -dontdereferencealias 2>&1` = "TRUE"
then
	Entry=`squid | awk -F: '{if (NR == 2) print $2}' | sed -e "s/ @//"`
	echo "Checking alias $Entry"
	moveto ..

	# Check that all the 4 correct attributes are present, and no more.
	showentry "$1" -dontderef -novalue -all -nosequence > tmp_entry_$$
	if [ `grep -c "commonName" tmp_entry_$$` = 0 -o `grep -c "organizationName" tmp_entry_$$` = 0 -o `grep -c "organizationalUnitName" tmp_entry_$$` = 0 ]
	then 
		cat tmp_entry_$$ | sed -e "s/commonName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
		cat tmp_entry_$$ | sed -e "s/organizationName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
		cat tmp_entry_$$ | sed -e "s/organizationalUnitName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	else
		echo "Common Name attribute missing. Please add." | tee -a Error_file
	fi
	if test `grep -c "objectClass" tmp_entry_$$` = 0
	then 
		echo "objectClass attribute missing. Please add." | tee -a Error_file
	else
		cat tmp_entry_$$ | sed -e "s/objectClass//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	fi
	if test `grep -c "accessControlList" tmp_entry_$$` = 0
	then 
		echo "ACL attribute missing. Please add." | tee -a Error_file
	else
		cat tmp_entry_$$ | sed -e "s/accessControlList//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	fi
	if test `grep -c "aliasedObjectName" tmp_entry_$$` = 0
	then 
		echo "aliasedObjectName attribute missing. Please add." | tee -a Error_file
		mv tmp_entry_$$2 tmp_entry_$$
	else
		cat tmp_entry_$$ | sed -e "s/aliasedObjectName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	fi
	cat tmp_entry_$$ | sed -e "s/lastModifiedBy//" | sed -e "s/lastModifiedTime//" > tmp_entry_$$2
	mv tmp_entry_$$2 tmp_entry_$$

	# Number of words remaining = number of extra attributes.
	if  test `cat tmp_entry_$$ | wc -w` != 0
	then
		echo "Un-necessary attributes present: Please remove" | tee -a Error_file
		cat tmp_entry_$$ | awk '{if $0 != "" print $0}'
	fi

	# Now to check that the entry "aliasObject" points to, 
	# actually exists, and that it points back to this entry. 

	Object=`showentry "$1" -dontderef -type "aliasedObjectName" -edb -nokey -nocache`
	showentry "@$Object" -type "seeAlso" -nokey -edb > tmp_entry_$$
	if test -s tmp_entry_$$
	then
		if test `grep -c "$Entry" tmp_entry_$$` = 0
		then
			echo "Object does not point back to alias. (Nice but not essential.)"  | tee -a Error_file
		fi 
	else
		echo "Object $Object does not exist, or has no seeAlso attribute." | tee -a Error_file
	fi

	rm tmp_entry_$$
	exit
fi


echo -n "We are at: "
Location=`squid | awk -F: '{if (NR == 2) print $2}' | sed -e "s/ @//"`
echo $Location

#Check the aliases in the current entry
search -filter "objectClass=alias" -nosequence -dontderef -edb -nosizelimit > tmp_ali_chk_$$

if test -s tmp_ali_chk_$$
then
cat tmp_ali_chk_$$ | while read i
do
	showentry "$i" -dontderef -novalue -all > tmp_entry_$$
	moveto "$i"
	Entry=`squid | awk -F: '{if (NR == 2) print $2}' | sed -e "s/ @//"`
	echo "Checking alias $Entry"
	moveto ..

	# Check that all the 4 correct attributes are present, and no more.
	if [ `grep -c "commonName" tmp_entry_$$` = 0 -o `grep -c "organizationName" tmp_entry_$$` = 0 -o `grep -c "organizationalUnitName" tmp_entry_$$` = 0 ]
	then 
		cat tmp_entry_$$ | sed -e "s/commonName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
		cat tmp_entry_$$ | sed -e "s/organizationName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
		cat tmp_entry_$$ | sed -e "s/organizationalUnitName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	else
		echo "Common Name attribute missing. Please add." | tee -a Error_file
	fi
	if test `grep -c "objectClass" tmp_entry_$$` = 0
	then 
		echo "objectClass attribute missing. Please add." | tee -a Error_file
	else
		cat tmp_entry_$$ | sed -e "s/objectClass//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	fi
	if test `grep -c "accessControlList" tmp_entry_$$` = 0
	then 
		echo "ACL attribute missing. Please add." | tee -a Error_file
	else
		cat tmp_entry_$$ | sed -e "s/accessControlList//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	fi
	if test `grep -c "aliasedObjectName" tmp_entry_$$` = 0
	then 
		echo "aliasedObjectName attribute missing. Please add." | tee -a Error_file
		mv tmp_entry_$$2 tmp_entry_$$
	else
		cat tmp_entry_$$ | sed -e "s/aliasedObjectName//" > tmp_entry_$$2
		mv tmp_entry_$$2 tmp_entry_$$
	fi
	cat tmp_entry_$$ | sed -e "s/lastModifiedBy//" | sed -e "s/lastModifiedTime//" > tmp_entry_$$2
	mv tmp_entry_$$2 tmp_entry_$$

	# Number of words remaining = number of extra attributes.
	if  test `cat tmp_entry_$$ | wc -w` != 0
	then
		echo "Un-necessary attributes present: Please remove" | tee -a Error_file
		cat tmp_entry_$$ | awk '{if $0 != "" print $0}'
	fi



	# Now to check that the entry "aliasObject" points to, 
	# actually exists, and that it points back to this entry. 

	Object=`showentry "$i" -dontderef -type "aliasedObjectName" -nokey -edb`
	showentry "@$Object" -type "seeAlso" -nokey -edb > tmp_entry_$$
	if test -s tmp_entry_$$
	then
		if test `grep -c "$Entry" tmp_entry_$$` = 0
		then
			echo "Object does not point back to alias. (Nice but not essential.)" | tee -a Error_file
		fi 
	else
		echo "Object $Object does not exist, or has no seeAlso attribute." | tee -a Error_file
	fi
	rm tmp_entry_$$
	echo
done
else
	echo "No aliases here. Moving down a level."
fi

# Now recurse to the next level.
search -filter "objectClass=quipuNonLeafObject" -nosequence -edb -sizelimit 10 > tmp_ali_chk2_$$

if test -s tmp_ali_chk2_$$
then
	cat tmp_ali_chk2_$$ | while read i
	do
		alias_chk "$i"
		moveto ..
	done
else
	echo "No more levels down here."
fi

rm tmp_ali_chk_$$ tmp_ali_chk2_$$

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.