smack_set_cipso.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 llllCCCCccccCCCCcccc 5 6
  15. # 123456789012345678901234567890123456789012345678901234567890123456789
  16. export TCID=smack_set_cipso
  17. export TST_TOTAL=1
  18. . test.sh
  19. . smack_common.sh
  20. rule_a="TheOne 2 0 "
  21. rule_b="TheOne 3 1 55 "
  22. rule_c="TheOne 4 2 17 33 "
  23. old_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
  24. echo -n "$rule_a" 2>/dev/null > "$smackfsdir/cipso"
  25. new_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
  26. if [ "$new_rule" = "" ]; then
  27. tst_brkm TFAIL "Rule did not get set."
  28. fi
  29. right=$(echo "$new_rule" | grep ' 2')
  30. if [ "$right" = "" ]; then
  31. tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
  32. fi
  33. echo -n "$rule_b" 2>/dev/null > "$smackfsdir/cipso"
  34. new_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
  35. if [ "$new_rule" = "" ]; then
  36. tst_brkm TFAIL "Rule did not get set."
  37. fi
  38. right=$(echo $new_rule | grep '/55')
  39. if [ "$right" = "" ]; then
  40. tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
  41. fi
  42. echo -n "$rule_c" 2>/dev/null > "$smackfsdir/cipso"
  43. new_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
  44. if [ "$new_rule" = "" ]; then
  45. tst_brkm TFAIL "Rule did not get set."
  46. fi
  47. right=$(echo "$new_rule" | grep '/17,33')
  48. if [ "$right" = "" ]; then
  49. tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
  50. fi
  51. if [ "$old_rule" != "$new_rule" ]; then
  52. tst_resm TINFO "Notice: Test access rule changed from \"$old_rule\"" \
  53. "to \"$new_rule\"."
  54. fi
  55. tst_resm TPASS "Test \"$TCID\" success."
  56. tst_exit