1272343Sngie# $NetBSD: t_perm.sh,v 1.6 2012/03/18 09:46:50 jruoho Exp $ 2272343Sngie# 3272343Sngie# Copyright (c) 2011 The NetBSD Foundation, Inc. 4272343Sngie# All rights reserved. 5272343Sngie# 6272343Sngie# This code is derived from software contributed to The NetBSD Foundation 7272343Sngie# by Jukka Ruohonen. 8272343Sngie# 9272343Sngie# Redistribution and use in source and binary forms, with or without 10272343Sngie# modification, are permitted provided that the following conditions 11272343Sngie# are met: 12272343Sngie# 1. Redistributions of source code must retain the above copyright 13272343Sngie# notice, this list of conditions and the following disclaimer. 14272343Sngie# 2. Redistributions in binary form must reproduce the above copyright 15272343Sngie# notice, this list of conditions and the following disclaimer in the 16272343Sngie# documentation and/or other materials provided with the distribution. 17272343Sngie# 18272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21272343Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28272343Sngie# POSSIBILITY OF SUCH DAMAGE. 29272343Sngie# 30272343Sngiefile="/tmp/d_sysctl.out" 31272343Sngie 32272343Sngieclean() { 33272343Sngie 34272343Sngie if [ -f $file ]; then 35272343Sngie rm $file 36272343Sngie fi 37272343Sngie} 38272343Sngie 39272343Sngiesysctl_write() { 40272343Sngie 41272343Sngie deadbeef="3735928559" 42272343Sngie 43272343Sngie sysctl $1 | cut -d= -f1 > $file 44272343Sngie 45272343Sngie if [ ! -f $file ]; then 46272343Sngie atf_fail "sysctl failed" 47272343Sngie fi 48272343Sngie 49272343Sngie while read line; do 50272343Sngie 51272343Sngie node=$(echo $line) 52272343Sngie 53272343Sngie case $node in 54272343Sngie 55272343Sngie "$1."*) 56272343Sngie atf_check -s not-exit:0 -e ignore \ 57272343Sngie -x sysctl -w $node=$deadbeef 58272343Sngie ;; 59272343Sngie esac 60272343Sngie 61272343Sngie done < $file 62272343Sngie 63272343Sngie # A functional verification that $deadbeef 64272343Sngie # was not actually written to the node. 65272343Sngie # 66272343Sngie if [ ! -z $(sysctl $1 | grep $deadbeef) ]; then 67272343Sngie atf_fail "value was written" 68272343Sngie fi 69272343Sngie} 70272343Sngie 71272343Sngie# ddb. 72272343Sngie# 73272343Sngieatf_test_case sysctl_ddb cleanup 74272343Sngiesysctl_ddb_head() { 75272343Sngie atf_set "require.user" "unprivileged" 76272343Sngie atf_set "descr" "Test writing to 'ddb' sysctl node as an user" 77272343Sngie} 78272343Sngie 79272343Sngiesysctl_ddb_body() { 80272343Sngie sysctl_write "ddb" 81272343Sngie} 82272343Sngie 83272343Sngiesysctl_ddb_cleanup() { 84272343Sngie clean 85272343Sngie} 86272343Sngie 87272343Sngie# hw. 88272343Sngie# 89272343Sngieatf_test_case sysctl_hw cleanup 90272343Sngiesysctl_hw_head() { 91272343Sngie atf_set "require.user" "unprivileged" 92272343Sngie atf_set "descr" "Test writing to 'hw' sysctl node as an user" 93272343Sngie} 94272343Sngie 95272343Sngiesysctl_hw_body() { 96272343Sngie sysctl_write "hw" 97272343Sngie} 98272343Sngie 99272343Sngiesysctl_hw_cleanup() { 100272343Sngie clean 101272343Sngie} 102272343Sngie 103272343Sngie# kern. 104272343Sngie# 105272343Sngieatf_test_case sysctl_kern cleanup 106272343Sngiesysctl_kern_head() { 107272343Sngie atf_set "require.user" "unprivileged" 108272343Sngie atf_set "descr" "Test writing to 'kern' " \ 109272343Sngie "sysctl node as an user (PR kern/44946)" 110272343Sngie} 111272343Sngie 112272343Sngiesysctl_kern_body() { 113272343Sngie sysctl_write "kern" 114272343Sngie} 115272343Sngie 116272343Sngiesysctl_kern_cleanup() { 117272343Sngie clean 118272343Sngie} 119272343Sngie 120272343Sngie# machdep. 121272343Sngie# 122272343Sngieatf_test_case sysctl_machdep cleanup 123272343Sngiesysctl_machdep_head() { 124272343Sngie atf_set "require.user" "unprivileged" 125272343Sngie atf_set "descr" "Test writing to 'machdep' sysctl node as an user" 126272343Sngie} 127272343Sngie 128272343Sngiesysctl_machdep_body() { 129272343Sngie sysctl_write "machdep" 130272343Sngie} 131272343Sngie 132272343Sngiesysctl_machdep_cleanup() { 133272343Sngie clean 134272343Sngie} 135272343Sngie 136272343Sngie# net. 137272343Sngie# 138272343Sngieatf_test_case sysctl_net cleanup 139272343Sngiesysctl_net_head() { 140272343Sngie atf_set "require.user" "unprivileged" 141272343Sngie atf_set "descr" "Test writing to 'net' sysctl node as an user" 142272343Sngie} 143272343Sngie 144272343Sngiesysctl_net_body() { 145272343Sngie sysctl_write "net" 146272343Sngie} 147272343Sngie 148272343Sngiesysctl_net_cleanup() { 149272343Sngie clean 150272343Sngie} 151272343Sngie 152272343Sngie# security. 153272343Sngie# 154272343Sngieatf_test_case sysctl_security cleanup 155272343Sngiesysctl_security_head() { 156272343Sngie atf_set "require.user" "unprivileged" 157272343Sngie atf_set "descr" "Test writing to 'security' sysctl node as an user" 158272343Sngie} 159272343Sngie 160272343Sngiesysctl_security_body() { 161272343Sngie sysctl_write "security" 162272343Sngie} 163272343Sngie 164272343Sngiesysctl_security_cleanup() { 165272343Sngie clean 166272343Sngie} 167272343Sngie 168272343Sngie# vfs. 169272343Sngie# 170272343Sngieatf_test_case sysctl_vfs cleanup 171272343Sngiesysctl_vfs_head() { 172272343Sngie atf_set "require.user" "unprivileged" 173272343Sngie atf_set "descr" "Test writing to 'vfs' sysctl node as an user" 174272343Sngie} 175272343Sngie 176272343Sngiesysctl_vfs_body() { 177272343Sngie sysctl_write "vfs" 178272343Sngie} 179272343Sngie 180272343Sngiesysctl_vfs_cleanup() { 181272343Sngie clean 182272343Sngie} 183272343Sngie 184272343Sngie# vm. 185272343Sngie# 186272343Sngieatf_test_case sysctl_vm cleanup 187272343Sngiesysctl_vm_head() { 188272343Sngie atf_set "require.user" "unprivileged" 189272343Sngie atf_set "descr" "Test writing to 'vm' sysctl node as an user" 190272343Sngie} 191272343Sngie 192272343Sngiesysctl_vm_body() { 193272343Sngie sysctl_write "vm" 194272343Sngie} 195272343Sngie 196272343Sngiesysctl_vm_cleanup() { 197272343Sngie clean 198272343Sngie} 199272343Sngie 200272343Sngieatf_init_test_cases() { 201272343Sngie atf_add_test_case sysctl_ddb 202272343Sngie atf_add_test_case sysctl_hw 203272343Sngie atf_add_test_case sysctl_kern 204272343Sngie atf_add_test_case sysctl_machdep 205272343Sngie atf_add_test_case sysctl_net 206272343Sngie atf_add_test_case sysctl_security 207272343Sngie atf_add_test_case sysctl_vfs 208272343Sngie atf_add_test_case sysctl_vm 209272343Sngie} 210