1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci#
3f08c3bdfSopenharmony_ci# Copyright (c) 2009 Casey Schaufler under the terms of the
4f08c3bdfSopenharmony_ci# GNU General Public License version 2, as published by the
5f08c3bdfSopenharmony_ci# Free Software Foundation
6f08c3bdfSopenharmony_ci#
7f08c3bdfSopenharmony_ci# Test setting access rules
8f08c3bdfSopenharmony_ci#
9f08c3bdfSopenharmony_ci# Environment:
10f08c3bdfSopenharmony_ci#	CAP_MAC_ADMIN
11f08c3bdfSopenharmony_ci#
12f08c3bdfSopenharmony_ci# "%-23s %-23s %4s"
13f08c3bdfSopenharmony_ci#
14f08c3bdfSopenharmony_ci#               1         2    llllCCCCccccCCCCcccc     5         6
15f08c3bdfSopenharmony_ci#      123456789012345678901234567890123456789012345678901234567890123456789
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ciexport TCID=smack_set_cipso
18f08c3bdfSopenharmony_ciexport TST_TOTAL=1
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci. test.sh
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_ci. smack_common.sh
23f08c3bdfSopenharmony_ci
24f08c3bdfSopenharmony_cirule_a="TheOne                  2   0   "
25f08c3bdfSopenharmony_cirule_b="TheOne                  3   1   55  "
26f08c3bdfSopenharmony_cirule_c="TheOne                  4   2   17  33  "
27f08c3bdfSopenharmony_ci
28f08c3bdfSopenharmony_ciold_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
29f08c3bdfSopenharmony_ci
30f08c3bdfSopenharmony_ciecho -n "$rule_a" 2>/dev/null > "$smackfsdir/cipso"
31f08c3bdfSopenharmony_cinew_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
32f08c3bdfSopenharmony_ciif [ "$new_rule" = "" ]; then
33f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule did not get set."
34f08c3bdfSopenharmony_cifi
35f08c3bdfSopenharmony_ciright=$(echo "$new_rule" | grep ' 2')
36f08c3bdfSopenharmony_ciif [ "$right" = "" ]; then
37f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
38f08c3bdfSopenharmony_cifi
39f08c3bdfSopenharmony_ci
40f08c3bdfSopenharmony_ciecho -n "$rule_b" 2>/dev/null > "$smackfsdir/cipso"
41f08c3bdfSopenharmony_cinew_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
42f08c3bdfSopenharmony_ciif [ "$new_rule" = "" ]; then
43f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule did not get set."
44f08c3bdfSopenharmony_cifi
45f08c3bdfSopenharmony_ciright=$(echo $new_rule | grep '/55')
46f08c3bdfSopenharmony_ciif [ "$right" = "" ]; then
47f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
48f08c3bdfSopenharmony_cifi
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_ciecho -n "$rule_c" 2>/dev/null > "$smackfsdir/cipso"
51f08c3bdfSopenharmony_cinew_rule=$(grep "^TheOne" "$smackfsdir/cipso" 2>/dev/null)
52f08c3bdfSopenharmony_ciif [ "$new_rule" = "" ]; then
53f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule did not get set."
54f08c3bdfSopenharmony_cifi
55f08c3bdfSopenharmony_ciright=$(echo "$new_rule" | grep '/17,33')
56f08c3bdfSopenharmony_ciif [ "$right" = "" ]; then
57f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule \"$new_rule\" is not set correctly."
58f08c3bdfSopenharmony_cifi
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_ciif [ "$old_rule" != "$new_rule" ]; then
61f08c3bdfSopenharmony_ci	tst_resm TINFO "Notice: Test access rule changed from \"$old_rule\"" \
62f08c3bdfSopenharmony_ci		       "to \"$new_rule\"."
63f08c3bdfSopenharmony_cifi
64f08c3bdfSopenharmony_ci
65f08c3bdfSopenharmony_citst_resm TPASS "Test \"$TCID\" success."
66f08c3bdfSopenharmony_citst_exit
67