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
13f08c3bdfSopenharmony_ciexport TCID=smack_set_netlabel
14f08c3bdfSopenharmony_ciexport TST_TOTAL=1
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_ci. test.sh
17f08c3bdfSopenharmony_ci
18f08c3bdfSopenharmony_ci. smack_common.sh
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_cirule_a="191.191.191.191 TheOne"
21f08c3bdfSopenharmony_cirule_a1="191.191.191.191/32 TheOne"
22f08c3bdfSopenharmony_cirule_b="191.190.190.0/24 TheOne"
23f08c3bdfSopenharmony_ci
24f08c3bdfSopenharmony_ciold32=$(grep "^191.191.191.191/32" "$smackfsdir/netlabel" 2>/dev/null)
25f08c3bdfSopenharmony_ciold24=$(grep "^191.190.190.0/24" "$smackfsdir/netlabel" 2>/dev/null)
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_ciecho -n "$rule_a" 2>/dev/null > "$smackfsdir/netlabel"
28f08c3bdfSopenharmony_cinew32=$(grep "$rule_a1" $smackfsdir/netlabel 2>/dev/null)
29f08c3bdfSopenharmony_ciif [ "$new32" != "$rule_a1" ]; then
30f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule \"$rule_a\" did not get set."
31f08c3bdfSopenharmony_cifi
32f08c3bdfSopenharmony_ci
33f08c3bdfSopenharmony_ciecho -n "$rule_b" 2>/dev/null > "$smackfsdir/netlabel"
34f08c3bdfSopenharmony_cinew24=$(grep "$rule_b" "$smackfsdir/netlabel" 2>/dev/null)
35f08c3bdfSopenharmony_ciif [ "$new24" != "$rule_b" ]; then
36f08c3bdfSopenharmony_ci	tst_brkm TFAIL "Rule \"$rule_b\" did not get set."
37f08c3bdfSopenharmony_cifi
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_ciif [ "$old24" != "$new24" ]; then
40f08c3bdfSopenharmony_ci	tst_resm TINFO "Notice: Test access rule changed from \"$old24\" to" \
41f08c3bdfSopenharmony_ci		       "\"$new24\"."
42f08c3bdfSopenharmony_cifi
43f08c3bdfSopenharmony_ci
44f08c3bdfSopenharmony_ciif [ "$old32" != "$new32" ]; then
45f08c3bdfSopenharmony_ci	tst_resm TINFO "Notice: Test access rule changed from \"$old32\" to \
46f08c3bdfSopenharmony_ci\"$new32\"."
47f08c3bdfSopenharmony_cifi
48f08c3bdfSopenharmony_ci
49f08c3bdfSopenharmony_citst_resm TPASS "Test \"$TCID\" success."
50f08c3bdfSopenharmony_citst_exit
51