Imported Upstream version 20080930
[ltp-debian.git] / testcases / audit-test / trustedprograms / tests / test_newrole.bash
blob39fa3f3670883e2277616fc531a2d2e8b1aa6ebe
1 #!/bin/bash
2 ###############################################################################
3 # (c) Copyright Hewlett-Packard Development Company, L.P., 2007
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of version 2 the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ###############################################################################
18 # PURPOSE:
19 # Successfully newrole to another role and verify the audit
20 # The test starts at lspp_test_r which has access to staff_r
21 # verify that using newrole to change roles works, and that it is audited
23 source testcase.bash || exit 2
25 # setup
26 old_context=`id -Z`
27 exp_context=staff_u:staff_r:staff_t:SystemLow-SystemHigh
28 auid=$(cat /proc/self/loginuid)
30 # test
31 expect -c "
32 spawn newrole -r staff_r
33 expect {
34 -nocase Authenticating {exp_continue}
35 -nocase \"Password: \" {send \"$PASSWD\\r\"; exp_continue}
36 -re \".*is not a valid context$\" {exit -1}
37 -re \"bash: .*Permission denied$\" {exp_continue}
38 -re \"\[.*staff_r.*\]# $\" {exit 0}
42 # verify
43 if [ $? -ne 0 ]; then
44 exit_fail "newrole failed to change roles"
47 msg_1="newrole: old-context=${old_context} new-context=${exp_context}.*"
48 augrok -q type=USER_ROLE_CHANGE auid=$auid \
49 msg_1=~"$msg_1" || exit_fail "missing: \"$msg_1\""
51 exit_pass