3 # Copyright (c) 2013 Hudson River Trading LLC
4 # Written by: John H. Baldwin <jhb@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Regression tests for the pre-world (-p) mode
36 echo "Usage: preworld.sh [-s script] [-w workdir]"
40 # Allow the user to specify an alternate work directory or script.
42 while getopts "s:w:" option; do
61 CONFLICTS=$WORKDIR/conflicts
69 # Populate trees with pre-world files and additional files
70 # that should not be touched.
72 rm -rf $SRC $OLD $TEST $CONFLICTS
74 # Create the "old" source tree as the starting point
76 cat >> $OLD/etc/master.passwd <<EOF
78 root::0:0::0:0:Charlie &:/root:/bin/csh
79 toor:*:0:0::0:0:Bourne-again Superuser:/root:
80 daemon:*:1:1::0:0:Owner of many system processes:/root:/usr/sbin/nologin
81 operator:*:2:5::0:0:System &:/:/usr/sbin/nologin
82 _dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin
83 uucp:*:66:66::0:0:UUCP pseudo-user:/var/spool/uucppublic:/usr/local/libexec/uucp/uucico
84 pop:*:68:6::0:0:Post Office Owner:/nonexistent:/usr/sbin/nologin
85 www:*:80:80::0:0:World Wide Web Owner:/nonexistent:/usr/sbin/nologin
86 hast:*:845:845::0:0:HAST unprivileged user:/var/empty:/usr/sbin/nologin
87 nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin
89 cat >> $OLD/etc/group <<EOF
106 cat >> $OLD/etc/inetd.conf <<EOF
110 # Copy the "old" source tree to the test tree and make local
113 sed -I "" -e 's/root::/root:<rpass>:/' $TEST/etc/master.passwd
114 cat >> $TEST/etc/master.passwd <<EOF
115 john:<password>:1001:1001::0:0:John Baldwin:/home/john:/bin/tcsh
116 messagebus:*:556:556::0:0:D-BUS Daemon User:/nonexistent:/usr/sbin/nologin
117 polkit:*:562:562::0:0:PolicyKit User:/nonexistent:/usr/sbin/nologin
118 haldaemon:*:560:560::0:0:HAL Daemon User:/nonexistent:/usr/sbin/nologin
120 awk '/wheel/ { printf "%s,john\n", $0; next } // { print }' \
121 $OLD/etc/group > $TEST/etc/group
122 cat >> $TEST/etc/group <<EOF
128 rm $TEST/etc/inetd.conf
129 touch $TEST/etc/localtime
131 # Copy the "old" source tree to the new source tree and
132 # make upstream modifications.
134 sed -I "" -e '/:80:/i\
135 auditdistd:*:78:77::0:0:Auditdistd unprivileged user:/var/empty:/usr/sbin/nologin' \
136 $SRC/etc/master.passwd
137 sed -I "" -e '/:80:/i\
140 cat >> $SRC/etc/inetd.conf <<EOF
145 # $1 - relative path to file that should be missing from TEST
148 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
149 echo "File $1 should be missing"
153 # $1 - relative path to file that should be present in TEST
156 if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then
157 echo "File $1 should be present"
161 # $1 - relative path to regular file that should be present in TEST
162 # $2 - optional string that should match file contents
163 # $3 - optional MD5 of the flie contents, overrides $2 if present
168 if ! [ -f $TEST/$1 ]; then
169 echo "File $1 should be a regular file"
170 elif [ $# -eq 2 ]; then
171 contents=`cat $TEST/$1`
172 if [ "$contents" != "$2" ]; then
173 echo "File $1 has wrong contents"
175 elif [ $# -eq 3 ]; then
176 sum=`md5 -q $TEST/$1`
177 if [ "$sum" != "$3" ]; then
178 echo "File $1 has wrong contents"
183 # $1 - relative path to a regular file that should have a conflict
184 # $2 - optional MD5 of the conflict file contents
189 if ! [ -f $CONFLICTS/$1 ]; then
190 echo "File $1 missing conflict"
191 elif [ $# -gt 1 ]; then
192 sum=`md5 -q $CONFLICTS/$1`
193 if [ "$sum" != "$2" ]; then
194 echo "Conflict $1 has wrong contents"
202 echo "Checking tree for correct results:"
204 file /etc/master.passwd "" 1385366e8b424d33d59b7d8a2bdb15d3
205 file /etc/group "" 21273f845f6ec0cda9188c4ddac9ed47
206 missing /etc/inetd.conf
208 # These should be auto-generated by pwd_mkdb
209 file /etc/passwd "" 9831537874bdc99adccaa2b0293248a1
214 if [ `id -u` -ne 0 ]; then
218 if [ -r /etc/etcupdate.conf ]; then
219 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
224 $COMMAND -np -s $SRC -d $WORKDIR -D $TEST > $WORKDIR/testn.out
226 cat > $WORKDIR/correct.out <<EOF
231 echo "Differences for -n:"
232 diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out
234 $COMMAND -p -s $SRC -d $WORKDIR -D $TEST > $WORKDIR/test.out
236 echo "Differences for real:"
237 diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out