~ubuntu-branches/ubuntu/raring/apparmor/raring

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/openat.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-03-23 16:42:01 UTC
  • Revision ID: james.westby@ubuntu.com-20070323164201-jkax6f0oku087b7l
Tags: upstream-2.0.1+510.dfsg
ImportĀ upstreamĀ versionĀ 2.0.1+510.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/bash
 
2
# $Id: openat.sh 441 2007-03-14 20:53:10Z steve-beattie $
 
3
 
 
4
#       Copyright (C) 2002-2007 Novell/SUSE
 
5
#
 
6
#       This program is free software; you can redistribute it and/or
 
7
#       modify it under the terms of the GNU General Public License as
 
8
#       published by the Free Software Foundation, version 2 of the
 
9
#       License.
 
10
 
 
11
#=NAME open
 
12
#=DESCRIPTION
 
13
# Verify that the openat syscall is correctly managed for confined profiles.
 
14
#=END
 
15
 
 
16
pwd=`dirname $0`
 
17
pwd=`cd $pwd ; /bin/pwd`
 
18
 
 
19
bin=$pwd
 
20
 
 
21
. $bin/prologue.inc
 
22
 
 
23
dir=${tmpdir}
 
24
subdir=deleteme
 
25
otherdir=otherdir
 
26
file=${subdir}/file
 
27
filepath=${dir}/${file}
 
28
okperm=rw
 
29
badperm1=r
 
30
badperm2=w
 
31
 
 
32
resettest () {
 
33
        rm -rf ${dir}/${subdir} ${dir}/${otherdir}
 
34
        mkdir ${dir}/${subdir}
 
35
}
 
36
 
 
37
# PASS UNCONFINED
 
38
resettest
 
39
runchecktest "OPENAT unconfined RW (create) " pass $dir $file
 
40
 
 
41
# PASS TEST (the file shouldn't exist, so open should create it
 
42
resettest
 
43
genprofile ${dir}:r ${filepath}:$okperm
 
44
runchecktest "OPENAT RW (create) " pass $dir $file
 
45
 
 
46
# PASS TEST
 
47
resettest
 
48
touch ${filepath}
 
49
genprofile ${dir}:r ${filepath}:$okperm
 
50
runchecktest "OPENAT RW (exists)" pass $dir $file
 
51
 
 
52
# FAILURE TEST (1)
 
53
resettest
 
54
touch ${filepath}
 
55
genprofile ${dir}:r ${filepath}:$badperm1
 
56
runchecktest "OPENAT R" fail $dir $file
 
57
 
 
58
# FAILURE TEST (2)
 
59
resettest
 
60
touch ${filepath}
 
61
genprofile ${dir}:r ${filepath}:$badperm2
 
62
runchecktest "OPENAT W (exists)" fail $dir $file
 
63
 
 
64
# FAILURE TEST (3)
 
65
resettest
 
66
genprofile ${dir}:r ${filepath}:$badperm1 cap:dac_override
 
67
runchecktest "OPENAT R+dac_override" fail $dir $file
 
68
 
 
69
# FAILURE TEST (4)
 
70
# This is testing for bug: https://bugs.wirex.com/show_bug.cgi?id=2885
 
71
# When we open O_CREAT|O_RDWR, we are (were?) allowing only write access
 
72
# to be required.
 
73
resettest
 
74
genprofile ${dir}:r ${filepath}:$badperm2
 
75
runchecktest "OPENAT W (create)" fail $dir $file
 
76
 
 
77
# PASS rename of directory in between opendir/openat
 
78
resettest
 
79
genprofile ${dir}/${subdir}:rw ${dir}/otherdir:w ${dir}/otherdir/file:rw
 
80
runchecktest "OPENAT RW (rename/newpath)" pass --rename ${dir}/otherdir ${dir}/${subdir} file
 
81
 
 
82
# PASS rename of directory in between opendir/openat - file exists
 
83
resettest
 
84
touch ${filepath}
 
85
genprofile ${dir}/${subdir}:rw ${dir}/otherdir:w ${dir}/otherdir/file:rw
 
86
runchecktest "OPENAT RW (rename/newpath)" pass --rename ${dir}/otherdir ${dir}/${subdir} file
 
87
 
 
88
# FAIL rename of directory in between opendir/openat - use old name
 
89
resettest
 
90
genprofile ${dir}/${subdir}:rw ${dir}/otherdir:w ${dir}/${subdir}/file:rw
 
91
runchecktest "OPENAT RW (rename/newpath)" fail --rename ${dir}/otherdir ${dir}/${subdir} file
 
92
exit
 
93
 
 
94
# FAIL rename of directory in between opendir/openat - use old name, file exists
 
95
resettest
 
96
touch ${filepath}
 
97
genprofile ${dir}/${subdir}:rw ${dir}/otherdir:w ${dir}/${subdir}/file:rw
 
98
runchecktest "OPENAT RW (rename/newpath)" fail --rename ${dir}/otherdir ${dir}/${subdir} file