]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - tools/regression/mac/mac_bsdextended/test_matches.sh
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / tools / regression / mac / mac_bsdextended / test_matches.sh
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 uidrange="60000:100000"
7 gidrange="60000:100000"
8 uidinrange="nobody"
9 uidoutrange="daemon"
10 gidinrange="nobody" # We expect $uidinrange in this group
11 gidoutrange="daemon" # We expect $uidinrange in this group
12
13 playground="/stuff/nobody/" # Must not be on root fs
14
15 #
16 # Setup
17 #
18 rm -f $playground/test*
19 ugidfw remove 1
20
21 file1=$playground/test-$uidinrange
22 file2=$playground/test-$uidoutrange
23 cat <<EOF> $playground/test-script.pl
24 if (open(F, ">" . shift)) { exit 0; } else { exit 1; }
25 EOF
26 command1="perl $playground/test-script.pl $file1"
27 command2="perl $playground/test-script.pl $file2"
28
29 echo -n "$uidinrange file: "
30 su -m $uidinrange -c "$command1 && echo good"
31 chown "$uidinrange":"$gidinrange" $file1
32 chmod a+w $file1
33
34 echo -n "$uidoutrange file: "
35 $command2 && echo good
36 chown "$uidoutrange":"$gidoutrange" $file2
37 chmod a+w $file2
38
39 #
40 # No rules
41 #
42 echo -n "no rules $uidinrange: "
43 su -fm $uidinrange -c "$command1 && echo good"
44 echo -n "no rules $uidoutrange: "
45 su -fm $uidoutrange -c "$command1 && echo good"
46
47 #
48 # Subject Match on uid
49 #
50 ugidfw set 1 subject uid $uidrange object mode rasx
51 echo -n "subject uid in range: "
52 su -fm $uidinrange -c "$command1 || echo good"
53 echo -n "subject uid out range: "
54 su -fm $uidoutrange -c "$command1 && echo good"
55
56 #
57 # Subject Match on gid
58 #
59 ugidfw set 1 subject gid $gidrange object mode rasx
60 echo -n "subject gid in range: "
61 su -fm $uidinrange -c "$command1 || echo good"
62 echo -n "subject gid out range: "
63 su -fm $uidoutrange -c "$command1 && echo good"
64
65 #
66 # Subject Match on jail
67 #
68 echo -n "subject matching jailid: "
69 rm -f $playground/test-jail
70 jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 3; touch $playground/test-jail) &"`
71 ugidfw set 1 subject jailid $jailid object mode rasx
72 sleep 6
73 if [ ! -f $playground/test-jail ] ; then echo good ; fi
74
75 echo -n "subject nonmatching jailid: "
76 rm -f $playground/test-jail
77 jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 3; touch $playground/test-jail) &"`
78 sleep 6
79 if [ -f $playground/test-jail ] ; then echo good ; fi
80
81 #
82 # Object uid
83 #
84 ugidfw set 1 subject object uid $uidrange mode rasx
85 echo -n "object uid in range: "
86 su -fm $uidinrange -c "$command1 || echo good"
87 echo -n "object uid out range: "
88 su -fm $uidinrange -c "$command2 && echo good"
89 ugidfw set 1 subject object uid $uidrange mode rasx
90 echo -n "object uid in range (differennt subject): "
91 su -fm $uidoutrange -c "$command1 || echo good"
92 echo -n "object uid out range (differennt subject): "
93 su -fm $uidoutrange -c "$command2 && echo good"
94
95 #
96 # Object gid
97 #
98 ugidfw set 1 subject object gid $uidrange mode rasx
99 echo -n "object gid in range: "
100 su -fm $uidinrange -c "$command1 || echo good"
101 echo -n "object gid out range: "
102 su -fm $uidinrange -c "$command2 && echo good"
103 echo -n "object gid in range (differennt subject): "
104 su -fm $uidoutrange -c "$command1 || echo good"
105 echo -n "object gid out range (differennt subject): "
106 su -fm $uidoutrange -c "$command2 && echo good"
107
108 #
109 # Object filesys
110 #
111 ugidfw set 1 subject uid $uidrange object filesys / mode rasx
112 echo -n "object out of filesys: "
113 su -fm $uidinrange -c "$command1 && echo good"
114 ugidfw set 1 subject uid $uidrange object filesys $playground mode rasx
115 echo -n "object in filesys: "
116 su -fm $uidinrange -c "$command1 || echo good"
117
118 #
119 # Object suid
120 #
121 ugidfw set 1 subject uid $uidrange object suid mode rasx
122 echo -n "object notsuid: "
123 su -fm $uidinrange -c "$command1 && echo good"
124 chmod u+s $file1
125 echo -n "object suid: "
126 su -fm $uidinrange -c "$command1 || echo good"
127 chmod u-s $file1
128
129 #
130 # Object sgid
131 #
132 ugidfw set 1 subject uid $uidrange object sgid mode rasx
133 echo -n "object notsgid: "
134 su -fm $uidinrange -c "$command1 && echo good"
135 chmod g+s $file1
136 echo -n "object sgid: "
137 su -fm $uidinrange -c "$command1 || echo good"
138 chmod g-s $file1
139
140 #
141 # Object uid matches subject
142 #
143 ugidfw set 1 subject uid $uidrange object uid_of_subject mode rasx
144 echo -n "object uid notmatches subject: "
145 su -fm $uidinrange -c "$command2 && echo good"
146 echo -n "object uid matches subject: "
147 su -fm $uidinrange -c "$command1 || echo good"
148
149 #
150 # Object gid matches subject
151 #
152 ugidfw set 1 subject uid $uidrange object gid_of_subject mode rasx
153 echo -n "object gid notmatches subject: "
154 su -fm $uidinrange -c "$command2 && echo good"
155 echo -n "object gid matches subject: "
156 su -fm $uidinrange -c "$command1 || echo good"
157
158 #
159 # Object type
160 #
161 ugidfw set 1 subject uid $uidrange object type dbclsp mode rasx
162 echo -n "object not type: "
163 su -fm $uidinrange -c "$command1 && echo good"
164 ugidfw set 1 subject uid $uidrange object type r mode rasx
165 echo -n "object type: "
166 su -fm $uidinrange -c "$command1 || echo good"
167