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