Home | History | Annotate | Download | only in smack
      1 #!/bin/sh
      2 #
      3 # Copyright (c) 2009 Casey Schaufler under the terms of the
      4 # GNU General Public License version 2, as published by the
      5 # Free Software Foundation
      6 #
      7 # Test setting access rules
      8 #
      9 # Environment:
     10 #	CAP_MAC_ADMIN
     11 #
     12 # "%-23s %-23s %4s"
     13 #
     14 #               1         2         3         4         5         6
     15 #      123456789012345678901234567890123456789012345678901234567890123456789
     16 
     17 export TCID=smack_set_load
     18 export TST_TOTAL=1
     19 
     20 . test.sh
     21 
     22 . smack_common.sh
     23 
     24 rule_a="TheOne                  TheOther                rwxa"
     25 rule_b="TheOne                  TheOther                r---"
     26 
     27 old_rule=$(grep "^TheOne" "$smackfsdir/load" 2>/dev/null | grep ' TheOther ')
     28 
     29 echo -n "$rule_a" 2>/dev/null > "$smackfsdir/load"
     30 new_rule=$(grep "^TheOne" "$smackfsdir/load" 2>/dev/null | grep ' TheOther ')
     31 if [ "$new_rule" = "" ]; then
     32 	tst_brkm TFAIL "Rule did not get set."
     33 fi
     34 mode=$(echo "$new_rule" | sed -e 's/.* //')
     35 if [ "$mode" != "rwxa" ]; then
     36 	tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
     37 fi
     38 
     39 echo -n "$rule_b" 2>/dev/null > "$smackfsdir/load"
     40 new_rule=$(grep "^TheOne" "$smackfsdir/load" 2>/dev/null | grep ' TheOther ')
     41 if [ "$new_rule" = "" ]; then
     42 	tst_brkm TFAIL "Rule did not get set."
     43 fi
     44 mode=$(echo "$new_rule" | sed -e 's/.* //')
     45 if [ "$mode" != "r" ]; then
     46 	tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
     47 fi
     48 
     49 if [ "$old_rule" != "$new_rule" ]; then
     50 	tst_resm TINFO "Notice: Test access rule changed from \"$old_rule\"" \
     51 		       "to \"$new_rule\"."
     52 fi
     53 
     54 tst_resm TPASS "Test \"$TCID\" success."
     55 tst_exit
     56