#!/bin/sh
#Script de verification des debris dans /home et /home/mail

TMPFILE=`mktemp`

( for i in $( ls -l /home | awk '$3 != $8 { print $8 }' )
    do id $i 2> /dev/null > /dev/null || echo $i
  done ) | grep -v -E "^(ca|cimetiere|ftp|club|lost\+found|sqlgrey|squid|tftpboot)$" > $TMPFILE
if [ -s $TMPFILE ]
then
    echo "*** Homes a supprimer ***"
    cat $TMPFILE
    echo
fi

(for i in $( getent passwd | awk -F ":" '{ print $3 }' | sort | uniq -c | awk '$1 > 1 { print $2 }' )
  do if [ $i -eq 120 ] #Respbats
     then l=`getent passwd | awk -F ":" '$3 == "120"'`
          if [ `echo "$l" | wc -l` -gt 2 ]
          then echo "$l"
	  fi
     else getent passwd | awk -F ":" '$3 == "'$i'"'
     fi
  done) > $TMPFILE
if [ -s $TMPFILE ]
then
    echo "*** uid partages ***"
    cat $TMPFILE
    echo
fi

(ls -l /home /home/mail | awk '( substr($1,6,1) == "w" && $4 == "users" ) || substr($1,9,1) == "w"') > $TMPFILE
if [ -s $TMPFILE ]
then
    echo "*** /home/mail ouverts a tous ***"
    cat $TMPFILE
    echo
fi

ls -l /home/ /home/mail/ | awk '$3 != $8' | grep -v -E " (ca|cimetiere|ftp|club|lost\+found|mail|sqlgrey|squid|tftpboot)$" > $TMPFILE
if [ -s $TMPFILE ]
then
    echo "*** Erreurs de droits ***"
    cat $TMPFILE
fi

rm -f $TMPFILE
