Denis Vlasenko | 34e68c8 | 2008-10-29 00:27:31 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Test script for busybox id vs. coreutils id. |
| 3 | # Needs root privileges for some tests. |
| 4 | |
| 5 | cp /usr/bin/id . |
| 6 | BUSYBOX=./busybox |
| 7 | ID=./id |
| 8 | LIST=`awk -F: '{ printf "%s\n", $1 }' /etc/passwd` |
| 9 | FLAG_USER_EXISTS="no" |
| 10 | TEST_USER="f583ca884c1d93458fb61ed137ff44f6" |
| 11 | |
| 12 | echo "test 1: id [options] nousername" |
| 13 | rm -f foo bar |
| 14 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 15 | do |
| 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 |
| 25 | done |
| 26 | |
| 27 | echo "test 2: id [options] username" |
| 28 | rm -f foo bar |
| 29 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 30 | do |
| 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 |
| 45 | done |
| 46 | |
| 47 | if 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 |
| 51 | fi |
| 52 | |
| 53 | adduser -s /bin/true -g "" -H -D "$TEST_USER" || exit 1 |
| 54 | |
| 55 | chown $TEST_USER.$TEST_USER $BUSYBOX |
| 56 | chmod u+s $BUSYBOX 2>&1 /dev/null |
| 57 | chown $TEST_USER.$TEST_USER $ID |
| 58 | chmod u+s $ID 2>&1 /dev/null |
| 59 | |
| 60 | echo "test 3 setuid, existing user: id [options] no username" |
| 61 | rm -f foo bar |
| 62 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 63 | do |
| 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 |
| 74 | done |
| 75 | |
| 76 | echo "test 4 setuid, existing user: id [options] username" |
| 77 | rm -f foo bar |
| 78 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 79 | do |
| 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 |
| 91 | done |
| 92 | |
| 93 | chown $TEST_USER.$TEST_USER $BUSYBOX |
| 94 | chmod g+s $BUSYBOX 2>&1 /dev/null |
| 95 | chown $TEST_USER.$TEST_USER $ID |
| 96 | chmod g+s $ID 2>&1 /dev/null |
| 97 | |
| 98 | echo "test 5 setgid, existing user: id [options] no username" |
| 99 | rm -f foo bar |
| 100 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 101 | do |
| 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 |
| 112 | done |
| 113 | |
| 114 | echo "test 6 setgid, existing user: id [options] username" |
| 115 | rm -f foo bar |
| 116 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 117 | do |
| 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 |
| 129 | done |
| 130 | |
| 131 | chown $TEST_USER.$TEST_USER $BUSYBOX |
| 132 | chmod u+s,g+s $BUSYBOX 2>&1 /dev/null |
| 133 | chown $TEST_USER.$TEST_USER $ID |
| 134 | chmod u+s,g+s $ID 2>&1 /dev/null |
| 135 | |
| 136 | echo "test 7 setuid, setgid, existing user: id [options] no username" |
| 137 | rm -f foo bar |
| 138 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 139 | do |
| 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 |
| 150 | done |
| 151 | |
| 152 | echo "test 8 setuid, setgid, existing user: id [options] username" |
| 153 | rm -f foo bar |
| 154 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 155 | do |
| 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 |
| 167 | done |
| 168 | |
| 169 | deluser $TEST_USER || exit 1 |
| 170 | |
| 171 | echo "test 9 setuid, setgid, not existing user: id [options] no username" |
| 172 | rm -f foo bar |
| 173 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 174 | do |
| 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 |
| 184 | done |
| 185 | |
| 186 | echo "test 10 setuid, setgid, not existing user: id [options] username" |
| 187 | rm -f foo bar |
| 188 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 189 | do |
| 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 |
| 201 | done |
| 202 | |
| 203 | chown .root $BUSYBOX 2>&1 /dev/null |
| 204 | chown .root $ID 2>&1 /dev/null |
| 205 | chmod g+s $BUSYBOX 2>&1 /dev/null |
| 206 | chmod g+s $ID 2>&1 /dev/null |
| 207 | |
| 208 | echo "test 11 setgid, not existing group: id [options] no username" |
| 209 | rm -f foo bar |
| 210 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 211 | do |
| 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 |
| 222 | done |
| 223 | |
| 224 | echo "test 12 setgid, not existing group: id [options] username" |
| 225 | rm -f foo bar |
| 226 | for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr" |
| 227 | do |
| 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 |
| 239 | done |
| 240 | |
| 241 | chown root.root $BUSYBOX 2>&1 /dev/null |
| 242 | chown root.root $ID 2>&1 /dev/null |
| 243 | rm -f $ID |
| 244 | rm -f foo bar |