| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
cd $(dirname $0) |
| 6 |
|
| 7 |
. ../../common/config.sh |
| 8 |
. ../../common/log.sh |
| 9 |
|
| 10 |
log_start "$0" "userdel delete links, but not the pointed file/directory" |
| 11 |
|
| 12 |
save_config |
| 13 |
|
| 14 |
# restore the files on exit |
| 15 |
trap 'log_status "$0" "FAILURE"; restore_config' 0 |
| 16 |
|
| 17 |
change_config |
| 18 |
|
| 19 |
mkdir /home/foo |
| 20 |
trap 'log_status "$0" "FAILURE"; restore_config; rm -rf /home/foo' 0 |
| 21 |
mkdir /home/bar |
| 22 |
trap 'log_status "$0" "FAILURE"; restore_config; rm -rf /home/foo /home/bar' 0 |
| 23 |
touch /home/baz |
| 24 |
trap 'log_status "$0" "FAILURE"; restore_config; rm -rf /home/foo /home/bar /home/baz' 0 |
| 25 |
echo toto > /home/foo/toto |
| 26 |
ln -s /home/bar /home/foo/bar |
| 27 |
ln -s /home/baz /home/foo/baz |
| 28 |
chown -R foo:foo /home/foo /home/bar /home/baz |
| 29 |
|
| 30 |
echo -n "Delete user foo (userdel -r foo)..." |
| 31 |
userdel -r foo 2>tmp/userdel.err |
| 32 |
echo "OK" |
| 33 |
|
| 34 |
echo "userdel reported:" |
| 35 |
echo "=======================================================================" |
| 36 |
cat tmp/userdel.err |
| 37 |
echo "=======================================================================" |
| 38 |
echo -n "Check the userdel message..." |
| 39 |
diff -au data/userdel.err tmp/userdel.err |
| 40 |
echo "userdel message OK." |
| 41 |
rm -f tmp/userdel.err |
| 42 |
echo "OK" |
| 43 |
|
| 44 |
echo -n "Check the passwd file..." |
| 45 |
../../common/compare_file.pl data/passwd /etc/passwd |
| 46 |
echo "OK" |
| 47 |
echo -n "Check the group file..." |
| 48 |
../../common/compare_file.pl data/group /etc/group |
| 49 |
echo "OK" |
| 50 |
echo -n "Check the shadow file..." |
| 51 |
../../common/compare_file.pl data/shadow /etc/shadow |
| 52 |
echo "OK" |
| 53 |
echo -n "Check the gshadow file..." |
| 54 |
../../common/compare_file.pl data/gshadow /etc/gshadow |
| 55 |
echo "OK" |
| 56 |
echo -n "Check the user's home directory was removed..." |
| 57 |
test ! -d /home/foo |
| 58 |
echo "OK" |
| 59 |
echo -n "Check that directory pointed from a foo's link is not removed..." |
| 60 |
test -d /home/bar |
| 61 |
echo "OK" |
| 62 |
echo -n "Check that file pointed from a foo's link is not removed..." |
| 63 |
test -f /home/baz |
| 64 |
echo "OK" |
| 65 |
rm -rf /home/bar /home/baz |
| 66 |
|
| 67 |
log_status "$0" "SUCCESS" |
| 68 |
restore_config |
| 69 |
trap '' 0 |
| 70 |
|