]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/netbsd-tests/sbin/sysctl/t_perm.sh
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / netbsd-tests / sbin / sysctl / t_perm.sh
1 # $NetBSD: t_perm.sh,v 1.6 2012/03/18 09:46:50 jruoho Exp $
2 #
3 # Copyright (c) 2011 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # This code is derived from software contributed to The NetBSD Foundation
7 # by Jukka Ruohonen.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 #    notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 #    notice, this list of conditions and the following disclaimer in the
16 #    documentation and/or other materials provided with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 #
30 file="/tmp/d_sysctl.out"
31
32 clean() {
33
34         if [ -f $file ]; then
35                 rm $file
36         fi
37 }
38
39 sysctl_write() {
40
41         deadbeef="3735928559"
42
43         sysctl $1 | cut -d= -f1 > $file
44
45         if [ ! -f $file ]; then
46                 atf_fail "sysctl failed"
47         fi
48
49         while read line; do
50
51                 node=$(echo $line)
52
53                 case $node in
54
55                 "$1."*)
56                         atf_check -s not-exit:0 -e ignore \
57                                 -x sysctl -w $node=$deadbeef
58                         ;;
59                 esac
60
61         done < $file
62
63         # A functional verification that $deadbeef
64         # was not actually written to the node.
65         #
66         if [ ! -z $(sysctl $1 | grep $deadbeef) ]; then
67                 atf_fail "value was written"
68         fi
69 }
70
71 # ddb.
72 #
73 atf_test_case sysctl_ddb cleanup
74 sysctl_ddb_head() {
75         atf_set "require.user" "unprivileged"
76         atf_set "descr" "Test writing to 'ddb' sysctl node as an user"
77 }
78
79 sysctl_ddb_body() {
80         sysctl_write "ddb"
81 }
82
83 sysctl_ddb_cleanup() {
84         clean
85 }
86
87 # hw.
88 #
89 atf_test_case sysctl_hw cleanup
90 sysctl_hw_head() {
91         atf_set "require.user" "unprivileged"
92         atf_set "descr" "Test writing to 'hw' sysctl node as an user"
93 }
94
95 sysctl_hw_body() {
96         sysctl_write "hw"
97 }
98
99 sysctl_hw_cleanup() {
100         clean
101 }
102
103 # kern.
104 #
105 atf_test_case sysctl_kern cleanup
106 sysctl_kern_head() {
107         atf_set "require.user" "unprivileged"
108         atf_set "descr" "Test writing to 'kern' " \
109                 "sysctl node as an user (PR kern/44946)"
110 }
111
112 sysctl_kern_body() {
113         sysctl_write "kern"
114 }
115
116 sysctl_kern_cleanup() {
117         clean
118 }
119
120 # machdep.
121 #
122 atf_test_case sysctl_machdep cleanup
123 sysctl_machdep_head() {
124         atf_set "require.user" "unprivileged"
125         atf_set "descr" "Test writing to 'machdep' sysctl node as an user"
126 }
127
128 sysctl_machdep_body() {
129         sysctl_write "machdep"
130 }
131
132 sysctl_machdep_cleanup() {
133         clean
134 }
135
136 # net.
137 #
138 atf_test_case sysctl_net cleanup
139 sysctl_net_head() {
140         atf_set "require.user" "unprivileged"
141         atf_set "descr" "Test writing to 'net' sysctl node as an user"
142 }
143
144 sysctl_net_body() {
145         sysctl_write "net"
146 }
147
148 sysctl_net_cleanup() {
149         clean
150 }
151
152 # security.
153 #
154 atf_test_case sysctl_security cleanup
155 sysctl_security_head() {
156         atf_set "require.user" "unprivileged"
157         atf_set "descr" "Test writing to 'security' sysctl node as an user"
158 }
159
160 sysctl_security_body() {
161         sysctl_write "security"
162 }
163
164 sysctl_security_cleanup() {
165         clean
166 }
167
168 # vfs.
169 #
170 atf_test_case sysctl_vfs cleanup
171 sysctl_vfs_head() {
172         atf_set "require.user" "unprivileged"
173         atf_set "descr" "Test writing to 'vfs' sysctl node as an user"
174 }
175
176 sysctl_vfs_body() {
177         sysctl_write "vfs"
178 }
179
180 sysctl_vfs_cleanup() {
181         clean
182 }
183
184 # vm.
185 #
186 atf_test_case sysctl_vm cleanup
187 sysctl_vm_head() {
188         atf_set "require.user" "unprivileged"
189         atf_set "descr" "Test writing to 'vm' sysctl node as an user"
190 }
191
192 sysctl_vm_body() {
193         sysctl_write "vm"
194 }
195
196 sysctl_vm_cleanup() {
197         clean
198 }
199
200 atf_init_test_cases() {
201         atf_add_test_case sysctl_ddb
202         atf_add_test_case sysctl_hw
203         atf_add_test_case sysctl_kern
204         atf_add_test_case sysctl_machdep
205         atf_add_test_case sysctl_net
206         atf_add_test_case sysctl_security
207         atf_add_test_case sysctl_vfs
208         atf_add_test_case sysctl_vm
209 }