id_test.sh 5.9 KB

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