1458cbf0aSEnji Cooper 2458cbf0aSEnji Cooper# Import helper functions 3458cbf0aSEnji Cooper. $(atf_get_srcdir)/helper_functions.shin 4458cbf0aSEnji Cooper 5458cbf0aSEnji Cooper# Test add user 6458cbf0aSEnji Cooperatf_test_case user_add 7458cbf0aSEnji Cooperuser_add_body() { 8458cbf0aSEnji Cooper populate_etc_skel 9458cbf0aSEnji Cooper 10458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test 11458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*" \ 12458cbf0aSEnji Cooper grep "^test:.*" $HOME/master.passwd 13458cbf0aSEnji Cooper} 14458cbf0aSEnji Cooper 15458cbf0aSEnji Cooper# Test add user with option -N 16458cbf0aSEnji Cooperatf_test_case user_add_noupdate 17458cbf0aSEnji Cooperuser_add_noupdate_body() { 18458cbf0aSEnji Cooper populate_etc_skel 19458cbf0aSEnji Cooper 20458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*" ${PW} useradd test -N 21458cbf0aSEnji Cooper atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd 22458cbf0aSEnji Cooper} 23458cbf0aSEnji Cooper 24458cbf0aSEnji Cooper# Test add user with comments 25458cbf0aSEnji Cooperatf_test_case user_add_comments 26458cbf0aSEnji Cooperuser_add_comments_body() { 27458cbf0aSEnji Cooper populate_etc_skel 28458cbf0aSEnji Cooper 2932bd1c2bSDavid Bright atf_check -s exit:0 ${PW} useradd test -c 'Test User,work!,123,user@example.com' 3032bd1c2bSDavid Bright atf_check -s exit:0 -o match:'^test:.*:Test User,work!,123,user@example.com:' \ 3132bd1c2bSDavid Bright grep '^test:.*:Test User,work!,123,user@example.com:' $HOME/master.passwd 32458cbf0aSEnji Cooper} 33458cbf0aSEnji Cooper 34458cbf0aSEnji Cooper# Test add user with comments and option -N 35458cbf0aSEnji Cooperatf_test_case user_add_comments_noupdate 36458cbf0aSEnji Cooperuser_add_comments_noupdate_body() { 37458cbf0aSEnji Cooper populate_etc_skel 38458cbf0aSEnji Cooper 39458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \ 40458cbf0aSEnji Cooper ${PW} useradd test -c "Test User,work,123,456" -N 41458cbf0aSEnji Cooper atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd 42458cbf0aSEnji Cooper} 43458cbf0aSEnji Cooper 44458cbf0aSEnji Cooper# Test add user with invalid comments 45458cbf0aSEnji Cooperatf_test_case user_add_comments_invalid 46458cbf0aSEnji Cooperuser_add_comments_invalid_body() { 47458cbf0aSEnji Cooper populate_etc_skel 48458cbf0aSEnji Cooper 49458cbf0aSEnji Cooper atf_check -s exit:65 -e match:"invalid character" \ 50458cbf0aSEnji Cooper ${PW} useradd test -c "Test User,work,123:456,456" 51458cbf0aSEnji Cooper atf_check -s exit:1 -o empty \ 52458cbf0aSEnji Cooper grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd 53458cbf0aSEnji Cooper} 54458cbf0aSEnji Cooper 55458cbf0aSEnji Cooper# Test add user with invalid comments and option -N 56458cbf0aSEnji Cooperatf_test_case user_add_comments_invalid_noupdate 57458cbf0aSEnji Cooperuser_add_comments_invalid_noupdate_body() { 58458cbf0aSEnji Cooper populate_etc_skel 59458cbf0aSEnji Cooper 60458cbf0aSEnji Cooper atf_check -s exit:65 -e match:"invalid character" \ 61458cbf0aSEnji Cooper ${PW} useradd test -c "Test User,work,123:456,456" -N 62458cbf0aSEnji Cooper atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd 63458cbf0aSEnji Cooper} 64458cbf0aSEnji Cooper 65458cbf0aSEnji Cooper# Test add user with alternate homedir 66458cbf0aSEnji Cooperatf_test_case user_add_homedir 67458cbf0aSEnji Cooperuser_add_homedir_body() { 68458cbf0aSEnji Cooper populate_etc_skel 69458cbf0aSEnji Cooper 70458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -d /foo/bar 71458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*:.*::0:0:User &:/foo/bar:.*" \ 72458cbf0aSEnji Cooper ${PW} usershow test 73458cbf0aSEnji Cooper} 74458cbf0aSEnji Cooper 75458cbf0aSEnji Cooper# Test add user with account expiration as an epoch date 76458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_epoch 77458cbf0aSEnji Cooperuser_add_account_expiration_epoch_body() { 78458cbf0aSEnji Cooper populate_etc_skel 79458cbf0aSEnji Cooper 80458cbf0aSEnji Cooper DATE=`date -j -v+1d "+%s"` 81458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -e ${DATE} 82458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*:.*::0:${DATE}:.*" \ 83458cbf0aSEnji Cooper ${PW} usershow test 84458cbf0aSEnji Cooper} 85458cbf0aSEnji Cooper 86458cbf0aSEnji Cooper# Test add user with account expiration as a DD-MM-YYYY date 87458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_date_numeric 88458cbf0aSEnji Cooperuser_add_account_expiration_date_numeric_body() { 89458cbf0aSEnji Cooper populate_etc_skel 90458cbf0aSEnji Cooper 91458cbf0aSEnji Cooper DATE=`date -j -v+1d "+%d-%m-%Y"` 92458cbf0aSEnji Cooper EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"` 93458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -e ${DATE} 94458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \ 95458cbf0aSEnji Cooper ${PW} usershow test 96458cbf0aSEnji Cooper} 97458cbf0aSEnji Cooper 98458cbf0aSEnji Cooper# Test add user with account expiration as a DD-MM-YYYY date 99458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_date_month 100458cbf0aSEnji Cooperuser_add_account_expiration_date_month_body() { 101458cbf0aSEnji Cooper populate_etc_skel 102458cbf0aSEnji Cooper 103458cbf0aSEnji Cooper DATE=`date -j -v+1d "+%d-%b-%Y"` 104458cbf0aSEnji Cooper EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"` 105458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -e ${DATE} 106458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \ 107458cbf0aSEnji Cooper ${PW} usershow test 108458cbf0aSEnji Cooper} 109458cbf0aSEnji Cooper 110458cbf0aSEnji Cooper# Test add user with account expiration as a relative date 111458cbf0aSEnji Cooperatf_test_case user_add_account_expiration_date_relative 112458cbf0aSEnji Cooperuser_add_account_expiration_date_relative_body() { 113458cbf0aSEnji Cooper populate_etc_skel 114458cbf0aSEnji Cooper 115458cbf0aSEnji Cooper EPOCH=`date -j -v+13m "+%s"` 116458cbf0aSEnji Cooper BUF=`expr $EPOCH + 5` 117458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -e +13o 118458cbf0aSEnji Cooper TIME=`${PW} usershow test | awk -F ':' '{print $7}'` 119458cbf0aSEnji Cooper [ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \ 120458cbf0aSEnji Cooper atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds." 121458cbf0aSEnji Cooper} 122458cbf0aSEnji Cooper 123458cbf0aSEnji Cooper# Test add user with password expiration as an epoch date 124458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_epoch 125458cbf0aSEnji Cooperuser_add_password_expiration_epoch_body() { 126458cbf0aSEnji Cooper populate_etc_skel 127458cbf0aSEnji Cooper 128458cbf0aSEnji Cooper DATE=`date -j -v+1d "+%s"` 129458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -p ${DATE} 130458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*:.*::${DATE}:0:.*" \ 131458cbf0aSEnji Cooper ${PW} usershow test 132458cbf0aSEnji Cooper} 133458cbf0aSEnji Cooper 134458cbf0aSEnji Cooper# Test add user with password expiration as a DD-MM-YYYY date 135458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_date_numeric 136458cbf0aSEnji Cooperuser_add_password_expiration_date_numeric_body() { 137458cbf0aSEnji Cooper populate_etc_skel 138458cbf0aSEnji Cooper 139458cbf0aSEnji Cooper DATE=`date -j -v+1d "+%d-%m-%Y"` 140458cbf0aSEnji Cooper EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"` 141458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -p ${DATE} 142458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \ 143458cbf0aSEnji Cooper ${PW} usershow test 144458cbf0aSEnji Cooper} 145458cbf0aSEnji Cooper 146458cbf0aSEnji Cooper# Test add user with password expiration as a DD-MMM-YYYY date 147458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_date_month 148458cbf0aSEnji Cooperuser_add_password_expiration_date_month_body() { 149458cbf0aSEnji Cooper populate_etc_skel 150458cbf0aSEnji Cooper 151458cbf0aSEnji Cooper DATE=`date -j -v+1d "+%d-%b-%Y"` 152458cbf0aSEnji Cooper EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"` 153458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -p ${DATE} 154458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \ 155458cbf0aSEnji Cooper ${PW} usershow test 156458cbf0aSEnji Cooper} 157458cbf0aSEnji Cooper 158458cbf0aSEnji Cooper# Test add user with password expiration as a relative date 159458cbf0aSEnji Cooperatf_test_case user_add_password_expiration_date_relative 160458cbf0aSEnji Cooperuser_add_password_expiration_date_relative_body() { 161458cbf0aSEnji Cooper populate_etc_skel 162458cbf0aSEnji Cooper 163458cbf0aSEnji Cooper EPOCH=`date -j -v+13m "+%s"` 164458cbf0aSEnji Cooper BUF=`expr $EPOCH + 5` 165458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd test -p +13o 166458cbf0aSEnji Cooper TIME=`${PW} usershow test | awk -F ':' '{print $6}'` 167458cbf0aSEnji Cooper [ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \ 168458cbf0aSEnji Cooper atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds." 169458cbf0aSEnji Cooper} 170458cbf0aSEnji Cooper 171458cbf0aSEnji Cooperatf_test_case user_add_name_too_long 172458cbf0aSEnji Cooperuser_add_name_too_long_body() { 173458cbf0aSEnji Cooper populate_etc_skel 174458cbf0aSEnji Cooper atf_check -e match:"too long" -s exit:64 \ 175458cbf0aSEnji Cooper ${PW} useradd name_very_vert_very_very_very_long 176458cbf0aSEnji Cooper} 177458cbf0aSEnji Cooper 1788d2dbd28SEd Masteatf_test_case user_add_name_with_spaces 1798d2dbd28SEd Masteuser_add_name_with_spaces_body() { 1808d2dbd28SEd Maste populate_etc_skel 1818d2dbd28SEd Maste atf_check -s exit:65 -e match:"invalid character" \ 1828d2dbd28SEd Maste ${PW} useradd 'test user' 1838d2dbd28SEd Maste atf_check -s exit:1 -o empty grep "^test user:.*" $HOME/master.passwd 1848d2dbd28SEd Maste # Try again with -n which uses a slightly different code path. 1858d2dbd28SEd Maste atf_check -s exit:65 -e match:"invalid character" \ 1868d2dbd28SEd Maste ${PW} useradd -n 'test user' 1878d2dbd28SEd Maste atf_check -s exit:1 -o empty grep "^test user:.*" $HOME/master.passwd 1888d2dbd28SEd Maste} 1898d2dbd28SEd Maste 1908d2dbd28SEd Masteatf_test_case user_add_name_with_spaces_and_gid_specified 1918d2dbd28SEd Masteuser_add_name_with_spaces_and_gid_specified_body() { 1928d2dbd28SEd Maste populate_etc_skel 1938d2dbd28SEd Maste gid=12345 1948d2dbd28SEd Maste user_name="test user" 1958d2dbd28SEd Maste # pw useradd should fail because of the space in the user 1968d2dbd28SEd Maste # name, not because the group doesn't exist. 1978d2dbd28SEd Maste atf_check -s exit:65 -e match:"invalid character" \ 1988d2dbd28SEd Maste ${PW} useradd "${user_name}" -g ${gid} 1998d2dbd28SEd Maste atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd 2008d2dbd28SEd Maste # Try again with -n which uses a slightly different code path. 2018d2dbd28SEd Maste atf_check -s exit:65 -e match:"invalid character" \ 2028d2dbd28SEd Maste ${PW} useradd -n "${user_name}" -g ${gid} 2038d2dbd28SEd Maste atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd 2048d2dbd28SEd Maste # Make sure the user isn't added even if the group exists 2058d2dbd28SEd Maste atf_check -s exit:0 ${PW} groupadd blafasel -g ${gid} 2068d2dbd28SEd Maste atf_check -s exit:65 -e match:"invalid character" \ 2078d2dbd28SEd Maste ${PW} useradd "${user_name}" -g ${gid} 2088d2dbd28SEd Maste atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd 2098d2dbd28SEd Maste # Try again with the -n option. 2108d2dbd28SEd Maste atf_check -s exit:65 -e match:"invalid character" \ 2118d2dbd28SEd Maste ${PW} useradd -n "${user_name}" -g ${gid} 2128d2dbd28SEd Maste atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd 2138d2dbd28SEd Maste} 2148d2dbd28SEd Maste 215458cbf0aSEnji Cooperatf_test_case user_add_expiration 216458cbf0aSEnji Cooperuser_add_expiration_body() { 217458cbf0aSEnji Cooper populate_etc_skel 218458cbf0aSEnji Cooper 219458cbf0aSEnji Cooper atf_check -s exit:0 \ 220458cbf0aSEnji Cooper ${PW} useradd foo -e 20-03-2037 221458cbf0aSEnji Cooper atf_check -o inline:"foo:*:1001:1001::0:2121120000:User &:/home/foo:/bin/sh\n" \ 222458cbf0aSEnji Cooper -s exit:0 grep "^foo" ${HOME}/master.passwd 223458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} userdel foo 224458cbf0aSEnji Cooper atf_check -s exit:0 \ 225458cbf0aSEnji Cooper ${PW} useradd foo -e 20-03-37 226458cbf0aSEnji Cooper atf_check -o inline:"foo:*:1001:1001::0:2121120000:User &:/home/foo:/bin/sh\n" \ 227458cbf0aSEnji Cooper -s exit:0 grep "^foo" ${HOME}/master.passwd 228458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} userdel foo 229458cbf0aSEnji Cooper atf_check -s exit:0 \ 230458cbf0aSEnji Cooper ${PW} useradd foo -e 20-Mar-2037 231458cbf0aSEnji Cooper atf_check -o inline:"foo:*:1001:1001::0:2121120000:User &:/home/foo:/bin/sh\n" \ 232458cbf0aSEnji Cooper -s exit:0 grep "^foo" ${HOME}/master.passwd 233458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} userdel foo 234458cbf0aSEnji Cooper atf_check -e inline:"pw: Invalid date\n" -s exit:1 \ 235458cbf0aSEnji Cooper ${PW} useradd foo -e 20-Foo-2037 236458cbf0aSEnji Cooper atf_check -e inline:"pw: Invalid date\n" -s exit:1 \ 237458cbf0aSEnji Cooper ${PW} useradd foo -e 20-13-2037 238458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -e "12:00 20-03-2037" 239458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} userdel foo 240458cbf0aSEnji Cooper atf_check -e inline:"pw: Invalid date\n" -s exit:1 \ 241458cbf0aSEnji Cooper ${PW} useradd foo -e "12 20-03-2037" 242458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -e "20-03-2037 12:00" 243458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} userdel foo 244458cbf0aSEnji Cooper} 245458cbf0aSEnji Cooper 246458cbf0aSEnji Cooperatf_test_case user_add_invalid_user_entry 247458cbf0aSEnji Cooperuser_add_invalid_user_entry_body() { 248458cbf0aSEnji Cooper touch ${HOME}/master.passwd 249458cbf0aSEnji Cooper touch ${HOME}/group 250458cbf0aSEnji Cooper 251458cbf0aSEnji Cooper pwd_mkdb -p -d ${HOME} ${HOME}/master.passwd || \ 252458cbf0aSEnji Cooper atf_fail "generate passwd from master.passwd" 253458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 254458cbf0aSEnji Cooper echo "foo1:*:1002" >> ${HOME}/master.passwd 255458cbf0aSEnji Cooper atf_check -s exit:1 -e match:"Invalid user entry" ${PW} useradd foo2 256458cbf0aSEnji Cooper} 257458cbf0aSEnji Cooper 258458cbf0aSEnji Cooperatf_test_case user_add_invalid_group_entry 259458cbf0aSEnji Cooperuser_add_invalid_group_entry_body() { 260458cbf0aSEnji Cooper touch ${HOME}/master.passwd 261458cbf0aSEnji Cooper touch ${HOME}/group 262458cbf0aSEnji Cooper 263458cbf0aSEnji Cooper pwd_mkdb -p -d ${HOME} ${HOME}/master.passwd || \ 264458cbf0aSEnji Cooper atf_fail "generate passwd from master.passwd" 265458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 266458cbf0aSEnji Cooper echo 'foo1:*:1002' >> group 267458cbf0aSEnji Cooper atf_check -s exit:1 -e match:"Invalid group entry" ${PW} useradd foo2 268458cbf0aSEnji Cooper} 269458cbf0aSEnji Cooper 270458cbf0aSEnji Cooperatf_test_case user_add_password_from_h 271458cbf0aSEnji Cooperuser_add_password_from_h_body() { 272458cbf0aSEnji Cooper populate_etc_skel 273458cbf0aSEnji Cooper 274458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -h 0 <<-EOF 275458cbf0aSEnji Cooper $(echo mypassword) 276458cbf0aSEnji Cooper EOF 277458cbf0aSEnji Cooper passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd` 278458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:$passhash \ 279458cbf0aSEnji Cooper $(atf_get_srcdir)/crypt $passhash "mypassword" 280458cbf0aSEnji Cooper} 281458cbf0aSEnji Cooper 282458cbf0aSEnji Cooperatf_test_case user_add_R 283458cbf0aSEnji Cooperuser_add_R_body() { 284458cbf0aSEnji Cooper populate_root_etc_skel 285458cbf0aSEnji Cooper 286458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} useradd foo 287458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} useradd bar -m 288458cbf0aSEnji Cooper test -d ${HOME}/home || atf_fail "Home parent directory not created" 289458cbf0aSEnji Cooper test -d ${HOME}/home/bar || atf_fail "Directory not created" 290458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} userdel bar 291458cbf0aSEnji Cooper test -d ${HOME}/home/bar || atf_fail "Directory removed" 292458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} useradd bar 293458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} userdel bar -r 294458cbf0aSEnji Cooper [ ! -d ${HOME}/home/bar ] || atf_fail "Directory not removed" 295458cbf0aSEnji Cooper} 296458cbf0aSEnji Cooper 297bbb2d2ceSMike Karelsatf_test_case user_add_R_no_symlink 298bbb2d2ceSMike Karelsuser_add_R_no_symlink_body() { 299458cbf0aSEnji Cooper populate_root_etc_skel 300458cbf0aSEnji Cooper 301458cbf0aSEnji Cooper mkdir ${HOME}/usr 302458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} useradd foo -m 303bbb2d2ceSMike Karels [ ! -d ${HOME}/usr/home ] || atf_fail "/usr/home created" 304bbb2d2ceSMike Karels test -d ${HOME}/home || atf_fail "/home directory not created" 305bbb2d2ceSMike Karels} 306bbb2d2ceSMike Karels 307bbb2d2ceSMike Karelsatf_test_case user_add_R_intermed 308bbb2d2ceSMike Karelsuser_add_R_intermed_body() { 309bbb2d2ceSMike Karels populate_root_etc_skel 310bbb2d2ceSMike Karels 311bbb2d2ceSMike Karels atf_check -s exit:0 ${RPW} useradd foo -m -d /a/b/c/foo 312bbb2d2ceSMike Karels test -d ${HOME}/a/b/c || atf_fail "intermediate directories not created" 313bbb2d2ceSMike Karels test -d ${HOME}/a/b/c/foo || atf_fail "user directory not created" 314458cbf0aSEnji Cooper} 315458cbf0aSEnji Cooper 316*e12b7446SDag-Erling Smørgravatf_test_case user_add_dir 317*e12b7446SDag-Erling Smørgravuser_add_dir_body() { 318*e12b7446SDag-Erling Smørgrav populate_root_etc_skel 319*e12b7446SDag-Erling Smørgrav 320*e12b7446SDag-Erling Smørgrav atf_check -s exit:0 ${RPW} useradd foo -M 0705 -m 321*e12b7446SDag-Erling Smørgrav atf_check grep -q '^foo:' $HOME/etc/master.passwd 322*e12b7446SDag-Erling Smørgrav atf_check test -d ${HOME}/home/foo 323*e12b7446SDag-Erling Smørgrav atf_check -o save:ugid \ 324*e12b7446SDag-Erling Smørgrav awk -F: '$1 == "foo" { print $3, $4 }' \ 325*e12b7446SDag-Erling Smørgrav $HOME/etc/master.passwd 326*e12b7446SDag-Erling Smørgrav atf_check -o file:ugid \ 327*e12b7446SDag-Erling Smørgrav stat -f '%u %g' ${HOME}/home/foo 328*e12b7446SDag-Erling Smørgrav atf_check -o inline:"40705\n" \ 329*e12b7446SDag-Erling Smørgrav stat -f '%p' ${HOME}/home/foo 330*e12b7446SDag-Erling Smørgrav} 331*e12b7446SDag-Erling Smørgrav 332458cbf0aSEnji Cooperatf_test_case user_add_skel 333458cbf0aSEnji Cooperuser_add_skel_body() { 334458cbf0aSEnji Cooper populate_root_etc_skel 335458cbf0aSEnji Cooper 336458cbf0aSEnji Cooper mkdir ${HOME}/skel 337458cbf0aSEnji Cooper echo "a" > ${HOME}/skel/.a 338458cbf0aSEnji Cooper echo "b" > ${HOME}/skel/b 339458cbf0aSEnji Cooper mkdir ${HOME}/skel/c 340458cbf0aSEnji Cooper mkdir ${HOME}/skel/c/d 341458cbf0aSEnji Cooper mkdir ${HOME}/skel/dot.plop 342458cbf0aSEnji Cooper echo "c" > ${HOME}/skel/c/d/dot.c 343458cbf0aSEnji Cooper mkdir ${HOME}/home 344458cbf0aSEnji Cooper ln -sf /nonexistent ${HOME}/skel/c/foo 345458cbf0aSEnji Cooper atf_check -s exit:0 ${RPW} useradd foo -k /skel -m 346458cbf0aSEnji Cooper test -d ${HOME}/home/foo || atf_fail "Directory not created" 347458cbf0aSEnji Cooper test -f ${HOME}/home/foo/.a || atf_fail "File not created" 348458cbf0aSEnji Cooper atf_check -o file:${HOME}/skel/.a -s exit:0 cat ${HOME}/home/foo/.a 349458cbf0aSEnji Cooper atf_check -o file:${HOME}/skel/b -s exit:0 cat ${HOME}/home/foo/b 350458cbf0aSEnji Cooper test -d ${HOME}/home/foo/c || atf_fail "Dotted directory in skel not copied" 351458cbf0aSEnji Cooper test -d ${HOME}/home/foo/.plop || atf_fail "Directory in skell not created" 352458cbf0aSEnji Cooper atf_check -o inline:"/nonexistent\n" -s ignore readlink -f ${HOME}/home/foo/c/foo 353458cbf0aSEnji Cooper atf_check -o file:${HOME}/skel/c/d/dot.c -s exit:0 cat ${HOME}/home/foo/c/d/.c 354458cbf0aSEnji Cooper} 355458cbf0aSEnji Cooper 356458cbf0aSEnji Cooperatf_test_case user_add_uid0 357458cbf0aSEnji Cooperuser_add_uid0_body() { 358458cbf0aSEnji Cooper populate_etc_skel 359458cbf0aSEnji Cooper atf_check -e inline:"pw: WARNING: new account \`foo' has a uid of 0 (superuser access!)\n" \ 360458cbf0aSEnji Cooper -s exit:0 ${PW} useradd foo -u 0 -g 0 -d /root -s /bin/sh -c "Bourne-again Superuser" -o 361458cbf0aSEnji Cooper atf_check \ 362458cbf0aSEnji Cooper -o inline:"foo:*:0:0::0:0:Bourne-again Superuser:/root:/bin/sh\n" \ 363458cbf0aSEnji Cooper -s exit:0 ${PW} usershow foo 364458cbf0aSEnji Cooper} 365458cbf0aSEnji Cooper 366458cbf0aSEnji Cooperatf_test_case user_add_uid_too_large 367458cbf0aSEnji Cooperuser_add_uid_too_large_body() { 368458cbf0aSEnji Cooper populate_etc_skel 369458cbf0aSEnji Cooper atf_check -s exit:64 -e inline:"pw: Bad id '9999999999999': too large\n" \ 370458cbf0aSEnji Cooper ${PW} useradd -n test1 -u 9999999999999 371458cbf0aSEnji Cooper} 372458cbf0aSEnji Cooper 373458cbf0aSEnji Cooperatf_test_case user_add_bad_shell 374458cbf0aSEnji Cooperuser_add_bad_shell_body() { 375458cbf0aSEnji Cooper populate_etc_skel 376458cbf0aSEnji Cooper 377458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -s sh 378458cbf0aSEnji Cooper atf_check -s exit:78 -e ignore ${PW} useradd bar -s badshell 379458cbf0aSEnji Cooper} 380458cbf0aSEnji Cooper 381458cbf0aSEnji Cooperatf_test_case user_add_already_exists 382458cbf0aSEnji Cooperuser_add_already_exists_body() { 383458cbf0aSEnji Cooper populate_etc_skel 384458cbf0aSEnji Cooper 385458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo 386458cbf0aSEnji Cooper atf_check -s exit:65 \ 387458cbf0aSEnji Cooper -e inline:"pw: login name \`foo' already exists\n" \ 388458cbf0aSEnji Cooper ${PW} useradd foo 389458cbf0aSEnji Cooper} 390458cbf0aSEnji Cooper 391458cbf0aSEnji Cooperatf_test_case user_add_w_error 392458cbf0aSEnji Cooperuser_add_w_error_body() { 393458cbf0aSEnji Cooper populate_etc_skel 394458cbf0aSEnji Cooper 395458cbf0aSEnji Cooper atf_check -s exit:1 -e match:"pw: Invalid value for default password" \ 396458cbf0aSEnji Cooper ${PW} useradd foo -w invalid_value 397458cbf0aSEnji Cooper} 398458cbf0aSEnji Cooper 399458cbf0aSEnji Cooperatf_test_case user_add_w_no 400458cbf0aSEnji Cooperuser_add_w_no_body() { 401458cbf0aSEnji Cooper populate_etc_skel 402458cbf0aSEnji Cooper 403458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -w no 404458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^foo:\*" grep "^foo:" $HOME/master.passwd 405458cbf0aSEnji Cooper} 406458cbf0aSEnji Cooper 407458cbf0aSEnji Cooperatf_test_case user_add_w_none 408458cbf0aSEnji Cooperuser_add_w_none_body() { 409458cbf0aSEnji Cooper populate_etc_skel 410458cbf0aSEnji Cooper 411458cbf0aSEnji Cooper atf_check -s exit:0 ${PW} useradd foo -w none 412458cbf0aSEnji Cooper atf_check -s exit:0 -o match:"^foo::" grep "^foo:" $HOME/master.passwd 413458cbf0aSEnji Cooper} 414458cbf0aSEnji Cooper 415458cbf0aSEnji Cooperatf_test_case user_add_w_random 416458cbf0aSEnji Cooperuser_add_w_random_body() { 417458cbf0aSEnji Cooper populate_etc_skel 418458cbf0aSEnji Cooper 419458cbf0aSEnji Cooper password=`${PW} useradd foo -w random | cat` 420458cbf0aSEnji Cooper passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd` 421458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:$passhash \ 422458cbf0aSEnji Cooper $(atf_get_srcdir)/crypt $passhash "$password" 423458cbf0aSEnji Cooper} 424458cbf0aSEnji Cooper 425458cbf0aSEnji Cooperatf_test_case user_add_w_yes 426458cbf0aSEnji Cooperuser_add_w_yes_body() { 427458cbf0aSEnji Cooper populate_etc_skel 428458cbf0aSEnji Cooper password=`${PW} useradd foo -w random | cat` 429458cbf0aSEnji Cooper passhash=`awk -F ':' '/^foo:/ {print $2}' $HOME/master.passwd` 430458cbf0aSEnji Cooper atf_check -s exit:0 -o inline:$passhash \ 431458cbf0aSEnji Cooper $(atf_get_srcdir)/crypt $passhash "$password" 432458cbf0aSEnji Cooper} 433458cbf0aSEnji Cooper 434458cbf0aSEnji Cooperatf_test_case user_add_with_pw_conf 435458cbf0aSEnji Cooperuser_add_with_pw_conf_body() 436458cbf0aSEnji Cooper{ 437458cbf0aSEnji Cooper populate_etc_skel 438458cbf0aSEnji Cooper atf_check -s exit:0 \ 439458cbf0aSEnji Cooper ${PW} useradd -D -C ${HOME}/pw.conf \ 440458cbf0aSEnji Cooper -u 2000,32767 -i 2000,32767 441458cbf0aSEnji Cooper atf_check -s exit:0 \ 442458cbf0aSEnji Cooper -o inline:"minuid = 2000\nmaxuid = 32767\nmingid = 2000\nmaxgid = 32767\n" \ 443458cbf0aSEnji Cooper grep "^m.*id =" ${HOME}/pw.conf 444458cbf0aSEnji Cooper atf_check -s exit:0 \ 445458cbf0aSEnji Cooper ${PW} useradd foo -C ${HOME}/pw.conf 446458cbf0aSEnji Cooper} 447ea7fdebeSYuri Pankov 448d1005f6aSBaptiste Daroussinatf_test_case user_add_defaultgroup 449d1005f6aSBaptiste Daroussinuser_add_defaultgroup_body() 450d1005f6aSBaptiste Daroussin{ 451d1005f6aSBaptiste Daroussin populate_etc_skel 452d1005f6aSBaptiste Daroussin echo 'defaultgroup = "plop"' > ${HOME}/pw.conf 453d1005f6aSBaptiste Daroussin atf_check -s exit:0 \ 454d1005f6aSBaptiste Daroussin ${PW} groupadd plop -g 442 455d1005f6aSBaptiste Daroussin atf_check -s exit:0 \ 456d1005f6aSBaptiste Daroussin ${PW} useradd foo -C ${HOME}/pw.conf 457d1005f6aSBaptiste Daroussin atf_check -s exit:0 \ 458d1005f6aSBaptiste Daroussin -o inline:"foo:*:1001:442::0:0:User &:/home/foo:/bin/sh\n" \ 459d1005f6aSBaptiste Daroussin ${PW} usershow foo 460d1005f6aSBaptiste Daroussin} 461458cbf0aSEnji Cooper 462ea7fdebeSYuri Pankovatf_test_case user_add_conf_defaultpasswd 463ea7fdebeSYuri Pankovuser_add_conf_defaultpasswd_body() 464ea7fdebeSYuri Pankov{ 465ea7fdebeSYuri Pankov populate_etc_skel 466ea7fdebeSYuri Pankov 467ea7fdebeSYuri Pankov atf_check -s exit:0 ${PW} useradd -D -w no 468ea7fdebeSYuri Pankov atf_check -o inline:"defaultpasswd = \"no\"\n" \ 469ea7fdebeSYuri Pankov grep defaultpasswd ${HOME}/pw.conf 470ea7fdebeSYuri Pankov atf_check -s exit:0 ${PW} useradd -D -w none 471ea7fdebeSYuri Pankov atf_check -o inline:"defaultpasswd = \"none\"\n" \ 472ea7fdebeSYuri Pankov grep defaultpasswd ${HOME}/pw.conf 473ea7fdebeSYuri Pankov atf_check -s exit:0 ${PW} useradd -D -w random 474ea7fdebeSYuri Pankov atf_check -o inline:"defaultpasswd = \"random\"\n" \ 475ea7fdebeSYuri Pankov grep defaultpasswd ${HOME}/pw.conf 476ea7fdebeSYuri Pankov atf_check -s exit:0 ${PW} useradd -D -w yes 477ea7fdebeSYuri Pankov atf_check -o inline:"defaultpasswd = \"yes\"\n" \ 478ea7fdebeSYuri Pankov grep defaultpasswd ${HOME}/pw.conf 479ea7fdebeSYuri Pankov} 480ea7fdebeSYuri Pankov 481181692abSNaman Soodatf_test_case user_add_existing_login_group 482181692abSNaman Sooduser_add_existing_login_group_body() 483181692abSNaman Sood{ 484181692abSNaman Sood populate_etc_skel 485181692abSNaman Sood 486181692abSNaman Sood atf_check -s exit:0 ${PW} groupadd testuser 487181692abSNaman Sood atf_check -s exit:0 ${PW} useradd user1 -G testuser 488181692abSNaman Sood atf_check -s exit:0 ${PW} useradd testuser 489181692abSNaman Sood atf_check -o match:"1" \ 490181692abSNaman Sood sh -c "grep testuser ${HOME}/group | wc -l" 491181692abSNaman Sood} 492181692abSNaman Sood 493181692abSNaman Soodatf_test_case user_add_already_in_group 494181692abSNaman Sooduser_add_already_in_group_body() 495181692abSNaman Sood{ 496181692abSNaman Sood populate_etc_skel 497181692abSNaman Sood 498181692abSNaman Sood echo "testgroup:*:4242:testuser" >> ${HOME}/group 499181692abSNaman Sood atf_check -s exit:0 ${PW} useradd testuser -G testgroup 500181692abSNaman Sood atf_check -o not-match:"testuser,testuser" \ 501181692abSNaman Sood grep testuser ${HOME}/group 502181692abSNaman Sood} 503181692abSNaman Sood 504458cbf0aSEnji Cooperatf_init_test_cases() { 505458cbf0aSEnji Cooper atf_add_test_case user_add 506458cbf0aSEnji Cooper atf_add_test_case user_add_noupdate 507458cbf0aSEnji Cooper atf_add_test_case user_add_comments 508458cbf0aSEnji Cooper atf_add_test_case user_add_comments_noupdate 509458cbf0aSEnji Cooper atf_add_test_case user_add_comments_invalid 510458cbf0aSEnji Cooper atf_add_test_case user_add_comments_invalid_noupdate 511458cbf0aSEnji Cooper atf_add_test_case user_add_homedir 512458cbf0aSEnji Cooper atf_add_test_case user_add_account_expiration_epoch 513458cbf0aSEnji Cooper atf_add_test_case user_add_account_expiration_date_numeric 514458cbf0aSEnji Cooper atf_add_test_case user_add_account_expiration_date_month 515458cbf0aSEnji Cooper atf_add_test_case user_add_account_expiration_date_relative 516458cbf0aSEnji Cooper atf_add_test_case user_add_password_expiration_epoch 517458cbf0aSEnji Cooper atf_add_test_case user_add_password_expiration_date_numeric 518458cbf0aSEnji Cooper atf_add_test_case user_add_password_expiration_date_month 519458cbf0aSEnji Cooper atf_add_test_case user_add_password_expiration_date_relative 520458cbf0aSEnji Cooper atf_add_test_case user_add_name_too_long 5218d2dbd28SEd Maste atf_add_test_case user_add_name_with_spaces 5228d2dbd28SEd Maste atf_add_test_case user_add_name_with_spaces_and_gid_specified 523458cbf0aSEnji Cooper atf_add_test_case user_add_expiration 524458cbf0aSEnji Cooper atf_add_test_case user_add_invalid_user_entry 525458cbf0aSEnji Cooper atf_add_test_case user_add_invalid_group_entry 526458cbf0aSEnji Cooper atf_add_test_case user_add_password_from_h 527458cbf0aSEnji Cooper atf_add_test_case user_add_R 528bbb2d2ceSMike Karels atf_add_test_case user_add_R_no_symlink 529bbb2d2ceSMike Karels atf_add_test_case user_add_R_intermed 530*e12b7446SDag-Erling Smørgrav atf_add_test_case user_add_dir 531458cbf0aSEnji Cooper atf_add_test_case user_add_skel 532458cbf0aSEnji Cooper atf_add_test_case user_add_uid0 533458cbf0aSEnji Cooper atf_add_test_case user_add_uid_too_large 534458cbf0aSEnji Cooper atf_add_test_case user_add_bad_shell 535458cbf0aSEnji Cooper atf_add_test_case user_add_already_exists 536458cbf0aSEnji Cooper atf_add_test_case user_add_w_error 537458cbf0aSEnji Cooper atf_add_test_case user_add_w_no 538458cbf0aSEnji Cooper atf_add_test_case user_add_w_none 539458cbf0aSEnji Cooper atf_add_test_case user_add_w_random 540458cbf0aSEnji Cooper atf_add_test_case user_add_w_yes 541458cbf0aSEnji Cooper atf_add_test_case user_add_with_pw_conf 542d1005f6aSBaptiste Daroussin atf_add_test_case user_add_defaultgroup 543ea7fdebeSYuri Pankov 544ea7fdebeSYuri Pankov atf_add_test_case user_add_conf_defaultpasswd 545181692abSNaman Sood atf_add_test_case user_add_existing_login_group 546181692abSNaman Sood atf_add_test_case user_add_already_in_group 547458cbf0aSEnji Cooper} 548