t_perm.sh revision 272343
178447Sdd# $NetBSD: t_perm.sh,v 1.6 2012/03/18 09:46:50 jruoho Exp $ 278447Sdd# 378447Sdd# Copyright (c) 2011 The NetBSD Foundation, Inc. 478447Sdd# All rights reserved. 578447Sdd# 678447Sdd# This code is derived from software contributed to The NetBSD Foundation 778447Sdd# by Jukka Ruohonen. 878447Sdd# 978447Sdd# Redistribution and use in source and binary forms, with or without 1078447Sdd# modification, are permitted provided that the following conditions 1178447Sdd# are met: 1278447Sdd# 1. Redistributions of source code must retain the above copyright 1378447Sdd# notice, this list of conditions and the following disclaimer. 1478447Sdd# 2. Redistributions in binary form must reproduce the above copyright 1578447Sdd# notice, this list of conditions and the following disclaimer in the 1678447Sdd# documentation and/or other materials provided with the distribution. 1778447Sdd# 1878447Sdd# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1978447Sdd# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2078447Sdd# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2178447Sdd# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2278447Sdd# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2378447Sdd# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2478447Sdd# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2578447Sdd# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2678447Sdd# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2778447Sdd# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2878447Sdd# POSSIBILITY OF SUCH DAMAGE. 2978447Sdd# 3078447Sddfile="/tmp/d_sysctl.out" 3178447Sdd 3278447Sddclean() { 3378447Sdd 3478447Sdd if [ -f $file ]; then 3578447Sdd rm $file 3678447Sdd fi 3778447Sdd} 3878447Sdd 3978447Sddsysctl_write() { 4078447Sdd 4178447Sdd deadbeef="3735928559" 4278447Sdd 4378447Sdd sysctl $1 | cut -d= -f1 > $file 4478447Sdd 4578447Sdd if [ ! -f $file ]; then 4678447Sdd atf_fail "sysctl failed" 4778447Sdd fi 4878447Sdd 4978447Sdd while read line; do 5078447Sdd 5178447Sdd node=$(echo $line) 5278447Sdd 5378447Sdd case $node in 5478447Sdd 5578447Sdd "$1."*) 5678447Sdd atf_check -s not-exit:0 -e ignore \ 5778447Sdd -x sysctl -w $node=$deadbeef 5878447Sdd ;; 5978447Sdd esac 6078447Sdd 6178447Sdd done < $file 6278447Sdd 6378447Sdd # A functional verification that $deadbeef 6478447Sdd # was not actually written to the node. 6578447Sdd # 6678447Sdd if [ ! -z $(sysctl $1 | grep $deadbeef) ]; then 6778447Sdd atf_fail "value was written" 6878447Sdd fi 6978447Sdd} 7078447Sdd 7178447Sdd# ddb. 7278447Sdd# 7378447Sddatf_test_case sysctl_ddb cleanup 7478447Sddsysctl_ddb_head() { 7578447Sdd atf_set "require.user" "unprivileged" 7678447Sdd atf_set "descr" "Test writing to 'ddb' sysctl node as an user" 7778447Sdd} 7878447Sdd 7978447Sddsysctl_ddb_body() { 8078447Sdd sysctl_write "ddb" 8178447Sdd} 8278447Sdd 8378447Sddsysctl_ddb_cleanup() { 8478447Sdd clean 8578447Sdd} 8678447Sdd 8778447Sdd# hw. 8878447Sdd# 8978447Sddatf_test_case sysctl_hw cleanup 9078447Sddsysctl_hw_head() { 9178447Sdd atf_set "require.user" "unprivileged" 9278447Sdd atf_set "descr" "Test writing to 'hw' sysctl node as an user" 9378447Sdd} 9478447Sdd 9578447Sddsysctl_hw_body() { 9678447Sdd sysctl_write "hw" 9778447Sdd} 9878447Sdd 9978447Sddsysctl_hw_cleanup() { 10078447Sdd clean 10178447Sdd} 10278447Sdd 10378447Sdd# kern. 10478447Sdd# 10578447Sddatf_test_case sysctl_kern cleanup 10678447Sddsysctl_kern_head() { 10778447Sdd atf_set "require.user" "unprivileged" 10878447Sdd atf_set "descr" "Test writing to 'kern' " \ 10978447Sdd "sysctl node as an user (PR kern/44946)" 11078447Sdd} 11178447Sdd 11278447Sddsysctl_kern_body() { 11378447Sdd sysctl_write "kern" 11478447Sdd} 11578447Sdd 11678447Sddsysctl_kern_cleanup() { 11778447Sdd clean 11878447Sdd} 11978447Sdd 12078447Sdd# machdep. 12178447Sdd# 12278447Sddatf_test_case sysctl_machdep cleanup 12378447Sddsysctl_machdep_head() { 12478447Sdd atf_set "require.user" "unprivileged" 12578447Sdd atf_set "descr" "Test writing to 'machdep' sysctl node as an user" 12678447Sdd} 12778447Sdd 12878447Sddsysctl_machdep_body() { 12978447Sdd sysctl_write "machdep" 13078447Sdd} 13178447Sdd 13278447Sddsysctl_machdep_cleanup() { 13378447Sdd clean 13478447Sdd} 13578447Sdd 13678447Sdd# net. 13778447Sdd# 13878447Sddatf_test_case sysctl_net cleanup 13978447Sddsysctl_net_head() { 14078447Sdd atf_set "require.user" "unprivileged" 14178447Sdd atf_set "descr" "Test writing to 'net' sysctl node as an user" 14278447Sdd} 14378447Sdd 14478447Sddsysctl_net_body() { 14578447Sdd sysctl_write "net" 14678447Sdd} 14778447Sdd 14878447Sddsysctl_net_cleanup() { 14978447Sdd clean 15078447Sdd} 15178447Sdd 15278447Sdd# security. 15378447Sdd# 15478447Sddatf_test_case sysctl_security cleanup 15578447Sddsysctl_security_head() { 15678447Sdd atf_set "require.user" "unprivileged" 15778447Sdd atf_set "descr" "Test writing to 'security' sysctl node as an user" 15878447Sdd} 15978447Sdd 16078447Sddsysctl_security_body() { 16178447Sdd sysctl_write "security" 16278447Sdd} 16378447Sdd 16478447Sddsysctl_security_cleanup() { 16578447Sdd clean 16678447Sdd} 16778447Sdd 16878447Sdd# vfs. 16978447Sdd# 17078447Sddatf_test_case sysctl_vfs cleanup 17178447Sddsysctl_vfs_head() { 17278447Sdd atf_set "require.user" "unprivileged" 17378447Sdd atf_set "descr" "Test writing to 'vfs' sysctl node as an user" 17478447Sdd} 17578447Sdd 17678447Sddsysctl_vfs_body() { 17778447Sdd sysctl_write "vfs" 17878447Sdd} 17978447Sdd 18078447Sddsysctl_vfs_cleanup() { 18178447Sdd clean 18278447Sdd} 18378447Sdd 18478447Sdd# vm. 18578447Sdd# 18678447Sddatf_test_case sysctl_vm cleanup 18778447Sddsysctl_vm_head() { 18878447Sdd atf_set "require.user" "unprivileged" 18978447Sdd atf_set "descr" "Test writing to 'vm' sysctl node as an user" 19078447Sdd} 19178447Sdd 19278447Sddsysctl_vm_body() { 19378447Sdd sysctl_write "vm" 19478447Sdd} 19578447Sdd 19678447Sddsysctl_vm_cleanup() { 19778447Sdd clean 19878447Sdd} 19978447Sdd 20078447Sddatf_init_test_cases() { 20178447Sdd atf_add_test_case sysctl_ddb 20278447Sdd atf_add_test_case sysctl_hw 20378447Sdd atf_add_test_case sysctl_kern 20478447Sdd atf_add_test_case sysctl_machdep 20578447Sdd atf_add_test_case sysctl_net 20678447Sdd atf_add_test_case sysctl_security 20778447Sdd atf_add_test_case sysctl_vfs 20878447Sdd atf_add_test_case sysctl_vm 20978447Sdd} 21078447Sdd