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
29 # This is an NFSv4 ACL fuzzer. It expects to be run by non-root in a scratch
30 # directory on a filesystem with NFSv4 ACLs support. Output it generates
31 # is expected to be fed to /usr/src/tools/regression/acltools/run script.
33 NUMBER_OF_COMMANDS=300
38 eval $1 2>&1 | sed 's/^/> /'
45 rnd=`expr $rnd % $max`
56 2) echo "$TMP/aaa/ccc" ;;
57 3) echo "$TMP/bbb/ddd" ;;
61 f_prepend_random_acl_on()
74 rnd=`rnd_from_0_to 30`
75 if [ -n "$p" -a $rnd -ge 14 ]; then
100 rnd=`rnd_from_0_to 10`
101 if [ $rnd -ge 6 ]; then
113 rnd=`rnd_from_0_to 1`
122 run_command "setfacl -a0 $acl $file"
128 run_command "getfacl -qn $file"
134 run_command "ls -al $file | sed -n '2p' | cut -d' ' -f1"
145 run_command "chmod $b1$b2$b3$b4 $file $2"
151 run_command "touch $file"
157 run_command "rm -f $file"
163 run_command "mkdir $file"
169 run_command "rmdir $file"
176 run_command "mv -f $from $to"
179 # XXX: To be implemented: chown(8), setting times with touch(1).
181 switch_to_random_user()
183 # XXX: To be implemented.
186 execute_random_command()
188 rnd=`rnd_from_0_to 20`
191 0|10|11|12|13|15) cmd=f_prepend_random_acl_on ;;
195 4|18|19) cmd=f_touch ;;
197 6|16|17) cmd=f_mkdir ;;
205 echo "# Fuzzing; will stop after $NUMBER_OF_COMMANDS commands."
206 TMP="aclfuzzer_`dd if=/dev/random bs=1k count=1 2>/dev/null | openssl md5`"
210 run_command "umask 022"
211 run_command "mkdir $TMP"
214 while [ "$i" -lt "$NUMBER_OF_COMMANDS" ]; do
215 switch_to_random_user
216 execute_random_command
220 run_command "find $TMP -exec setfacl -a0 everyone@:rxd:allow {} \;"
221 run_command "rm -rfv $TMP"
223 echo "# Fuzzed, thank you."