1#!/bin/bash 2# Test script for busybox id vs. coreutils id. 3# Needs root privileges for some tests. 4 5cp /usr/bin/id . 6BUSYBOX=./busybox 7ID=./id 8LIST=`awk -F: '{ printf "%s\n", $1 }' /etc/passwd` 9FLAG_USER_EXISTS="no" 10TEST_USER="f583ca884c1d93458fb61ed137ff44f6" 11 12echo "test 1: id [options] nousername" 13rm -f foo bar 14for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 15do 16 #echo "$OPTIONS" 17 $BUSYBOX id $OPTIONS >foo 2>/dev/null 18 RET1=$? 19 $ID $OPTIONS >bar 2>/dev/null 20 RET2=$? 21 if test "$RET1" != "$RET2"; then 22 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 23 fi 24 diff foo bar 25done 26 27echo "test 2: id [options] username" 28rm -f foo bar 29for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 30do 31 #echo "$OPTIONS" 32 for i in $LIST ; do 33 if test "$i" = "$TEST_USER"; then 34 FLAG_USER_EXISTS="yes" 35 fi 36 $BUSYBOX id $OPTIONS $i >foo 2>/dev/null 37 RET1=$? 38 $ID $OPTIONS $i >bar 2>/dev/null 39 RET2=$? 40 if test "$RET1" != "$RET2"; then 41 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 42 fi 43 diff foo bar 44 done 45done 46 47if test $FLAG_USER_EXISTS = "yes"; then 48 echo "test 3,4,5,6,7,8,9,10,11,12 skipped because test user $TEST_USER already exists" 49 rm -f foo bar 50 exit 1 51fi 52 53adduser -s /bin/true -g "" -H -D "$TEST_USER" || exit 1 54 55chown $TEST_USER.$TEST_USER $BUSYBOX 56chmod u+s $BUSYBOX 2>&1 /dev/null 57chown $TEST_USER.$TEST_USER $ID 58chmod u+s $ID 2>&1 /dev/null 59 60echo "test 3 setuid, existing user: id [options] no username" 61rm -f foo bar 62for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 63do 64 #echo "$OPTIONS" 65 $BUSYBOX id $OPTIONS >foo 2>/dev/null 66 RET1=$? 67 $ID $OPTIONS >bar 2>/dev/null 68 RET2=$? 69 if test "$RET1" != "$RET2"; then 70 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 71 fi 72 diff foo bar 73 #done 74done 75 76echo "test 4 setuid, existing user: id [options] username" 77rm -f foo bar 78for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 79do 80 #echo "$OPTIONS" 81 for i in $LIST ; do 82 $BUSYBOX id $OPTIONS $i >foo 2>/dev/null 83 RET1=$? 84 $ID $OPTIONS $i >bar 2>/dev/null 85 RET2=$? 86 if test "$RET1" != "$RET2"; then 87 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 88 fi 89 diff foo bar 90 done 91done 92 93chown $TEST_USER.$TEST_USER $BUSYBOX 94chmod g+s $BUSYBOX 2>&1 /dev/null 95chown $TEST_USER.$TEST_USER $ID 96chmod g+s $ID 2>&1 /dev/null 97 98echo "test 5 setgid, existing user: id [options] no username" 99rm -f foo bar 100for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 101do 102 #echo "$OPTIONS" 103 $BUSYBOX id $OPTIONS >foo 2>/dev/null 104 RET1=$? 105 $ID $OPTIONS >bar 2>/dev/null 106 RET2=$? 107 if test "$RET1" != "$RET2"; then 108 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 109 fi 110 diff foo bar 111 #done 112done 113 114echo "test 6 setgid, existing user: id [options] username" 115rm -f foo bar 116for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 117do 118 #echo "$OPTIONS" 119 for i in $LIST ; do 120 $BUSYBOX id $OPTIONS $i >foo 2>/dev/null 121 RET1=$? 122 $ID $OPTIONS $i >bar 2>/dev/null 123 RET2=$? 124 if test "$RET1" != "$RET2"; then 125 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 126 fi 127 diff foo bar 128 done 129done 130 131chown $TEST_USER.$TEST_USER $BUSYBOX 132chmod u+s,g+s $BUSYBOX 2>&1 /dev/null 133chown $TEST_USER.$TEST_USER $ID 134chmod u+s,g+s $ID 2>&1 /dev/null 135 136echo "test 7 setuid, setgid, existing user: id [options] no username" 137rm -f foo bar 138for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 139do 140 #echo "$OPTIONS" 141 $BUSYBOX id $OPTIONS >foo 2>/dev/null 142 RET1=$? 143 $ID $OPTIONS >bar 2>/dev/null 144 RET2=$? 145 if test "$RET1" != "$RET2"; then 146 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 147 fi 148 diff foo bar 149 #done 150done 151 152echo "test 8 setuid, setgid, existing user: id [options] username" 153rm -f foo bar 154for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 155do 156 #echo "$OPTIONS" 157 for i in $LIST ; do 158 $BUSYBOX id $OPTIONS $i >foo 2>/dev/null 159 RET1=$? 160 $ID $OPTIONS $i >bar 2>/dev/null 161 RET2=$? 162 if test "$RET1" != "$RET2"; then 163 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 164 fi 165 diff foo bar 166 done 167done 168 169deluser $TEST_USER || exit 1 170 171echo "test 9 setuid, setgid, not existing user: id [options] no username" 172rm -f foo bar 173for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 174do 175 #echo "$OPTIONS" 176 $BUSYBOX id $OPTIONS >foo 2>/dev/null 177 RET1=$? 178 $ID $OPTIONS >bar 2>/dev/null 179 RET2=$? 180 if test "$RET1" != "$RET2"; then 181 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 182 fi 183 diff foo bar 184done 185 186echo "test 10 setuid, setgid, not existing user: id [options] username" 187rm -f foo bar 188for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 189do 190 #echo "$OPTIONS" 191 for i in $LIST ; do 192 $BUSYBOX id $OPTIONS $i >foo 2>/dev/null 193 RET1=$? 194 $ID $OPTIONS $i >bar 2>/dev/null 195 RET2=$? 196 if test "$RET1" != "$RET2"; then 197 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 198 fi 199 diff foo bar 200 done 201done 202 203chown .root $BUSYBOX 2>&1 /dev/null 204chown .root $ID 2>&1 /dev/null 205chmod g+s $BUSYBOX 2>&1 /dev/null 206chmod g+s $ID 2>&1 /dev/null 207 208echo "test 11 setgid, not existing group: id [options] no username" 209rm -f foo bar 210for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 211do 212 #echo "$OPTIONS" 213 $BUSYBOX id $OPTIONS >foo 2>/dev/null 214 RET1=$? 215 $ID $OPTIONS >bar 2>/dev/null 216 RET2=$? 217 if test "$RET1" != "$RET2"; then 218 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 219 fi 220 diff foo bar 221 #done 222done 223 224echo "test 12 setgid, not existing group: id [options] username" 225rm -f foo bar 226for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" 227do 228 #echo "$OPTIONS" 229 for i in $LIST ; do 230 $BUSYBOX id $OPTIONS $i >foo 2>/dev/null 231 RET1=$? 232 $ID $OPTIONS $i >bar 2>/dev/null 233 RET2=$? 234 if test "$RET1" != "$RET2"; then 235 echo "Return Values differ ($RET1 != $RET2): options $OPTIONS" 236 fi 237 diff foo bar 238 done 239done 240 241chown root.root $BUSYBOX 2>&1 /dev/null 242chown root.root $ID 2>&1 /dev/null 243rm -f $ID 244rm -f foo bar 245