Recovering Solaris file Permissions
Ever have someone perform a chmod 777 .*, chown -R *, etc… here is how to fix it without reinstalling or restoring from tape. You do need root access either locally or remotely.
Almost all packages installed on a Solaris machine have their settings kept in one file. It is /var/sadm/install/contents.
Root# cd /var/sadm/install
you will find a file named contents, where this contains the original installation file permissions which is used during OS installation.
# Remove = signs and all /devices entries–
1. First take a backup copy of the file contents.
root# cp contents bkp_contents
2.Remove = signs and all /devices entries–
egrep -v “=|devices” contents > contents.new
3. we require the 1,4,5,6 fields of the file contents.new
cat contents.new | cut -f1,4,5,6 -d” ” > contents.new1
4. Replace all white spaces with :
Either you can use SED or you can use vi mode
4.a) sed -i ’s/ /:/g/’ contents.new1 > contents.new
or
4.b) vi contents.new1
:%s/ /:/g ( This will search for the blank spaces and replaces with semicolon.
cp contents.new1 contents.new
5.) Now create a file named restore_perm
vi restore_perms
#!/bin/sh
#########################################################
for FILE in `cat /var/sadm/install/contents.new`
do
FNAME=`echo $FILE | awk -F: ‘{print $1}’`
PERM=`echo $FILE | awk -F: ‘{print $2}’`
OWNR=`echo $FILE | awk -F: ‘{print $3}’`
GRP=`echo $FILE | awk -F: ‘{print $4}’`
echo “chown $OWNR:$GRP $FNAME”
chown $OWNR:$GRP $FNAME
echo “chmod $PERM $FNAME”
chmod $PERM $FNAME
done
# End
#########################################################
6.) Change the Permissions to the Script
chmod 555 restore_perms
7.) Execute the Script
./restore_perms

Awesome!
Thanks.