761362f2ac35f7a6fa1f2e3551fee9492be92ca4
[feisty_meow.git] / scripts / files / find_bad_protection.sh
1 #!/bin/bash
2
3 source $FEISTY_MEOW_SCRIPTS/core/date_stringer.sh
4
5 bad_file="$HOME/bad_protections.txt"
6 if [ $# = 0 ]; then dirname=$HOME; export dirname;
7 else dirname=$1; export dirname; fi
8
9 echo "Searching for bad file protections in $dirname..."
10 echo "This includes any files that are writable by other or that have the"
11 echo "SetUID or SetGID bits turned on."
12
13 echo "Bad file modes and owners report for $(date_stringer)." >$bad_file
14 echo "" >>$bad_file
15
16 export outfile="$(mktemp "$TMP/zz_badprot.XXXXXX")"
17
18 echo "These files have bad modes:" >>$bad_file
19 find "$dirname" -type f -exec ls -AlF {} ';'  >$outfile
20 cat $outfile | 
21   sed -n -e '/^.....w/p
22     /^........w/p
23     /^..s.../p
24     /^.....s/p' |
25   grep '^[^l]' >>$bad_file
26 rm $outfile
27 echo "" >>$bad_file
28
29 echo "These directories have bad modes:" >>$bad_file
30 find "$dirname" -type d -exec ls -Ald {} ';' >$outfile
31
32 #this is same as above block.  make it a function.
33 cat $outfile | 
34   sed -n -e '/^.....w/p
35     /^........w/p
36     /^..s.../p
37     /^.....s/p' |
38   grep '^[^l]' >>$bad_file
39 rm $outfile
40 #
41
42 echo "Searching for Files Not Owned by the User in $HOME...."
43 echo "" >>$bad_file
44 bash $FEISTY_MEOW_SCRIPTS/find_non_owned.sh $HOME >>$bad_file
45
46 echo "" >>$bad_file
47 echo "" >>$bad_file
48
49 echo $(basename $0) " is finished.  Showing report from $bad_file"
50
51 less $bad_file
52
53 #optional: rm $bad_file
54