3 # Copyright (c) 2008, 2009 Edward Tomasz NapieraĆa <trasz@FreeBSD.org>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # This is an NFSv4 ACL fuzzer. It expects to be run by non-root in a scratch
31 # directory on a filesystem with NFSv4 ACLs support. Output it generates
32 # is expected to be fed to /usr/src/tools/regression/acltools/run script.
34 NUMBER_OF_COMMANDS=300
39 eval $1 2>&1 | sed 's/^/> /'
46 rnd=`expr $rnd % $max`
57 2) echo "$TMP/aaa/ccc" ;;
58 3) echo "$TMP/bbb/ddd" ;;
62 f_prepend_random_acl_on()
75 rnd=`rnd_from_0_to 30`
76 if [ -n "$p" -a $rnd -ge 14 ]; then
101 rnd=`rnd_from_0_to 10`
102 if [ $rnd -ge 6 ]; then
114 rnd=`rnd_from_0_to 1`
123 run_command "setfacl -a0 $acl $file"
129 run_command "getfacl -qn $file"
135 run_command "ls -al $file | sed -n '2p' | cut -d' ' -f1"
146 run_command "chmod $b1$b2$b3$b4 $file $2"
152 run_command "touch $file"
158 run_command "rm -f $file"
164 run_command "mkdir $file"
170 run_command "rmdir $file"
177 run_command "mv -f $from $to"
180 # XXX: To be implemented: chown(8), setting times with touch(1).
182 switch_to_random_user()
184 # XXX: To be implemented.
187 execute_random_command()
189 rnd=`rnd_from_0_to 20`
192 0|10|11|12|13|15) cmd=f_prepend_random_acl_on ;;
196 4|18|19) cmd=f_touch ;;
198 6|16|17) cmd=f_mkdir ;;
206 echo "# Fuzzing; will stop after $NUMBER_OF_COMMANDS commands."
207 TMP="aclfuzzer_`dd if=/dev/random bs=1k count=1 2>/dev/null | openssl md5`"
211 run_command "umask 022"
212 run_command "mkdir $TMP"
215 while [ "$i" -lt "$NUMBER_OF_COMMANDS" ]; do
216 switch_to_random_user
217 execute_random_command
221 run_command "find $TMP -exec setfacl -a0 everyone@:rxd:allow {} \;"
222 run_command "rm -rfv $TMP"
224 echo "# Fuzzed, thank you."