Debian Codegraph @

tests/usertools/usermod/49_usermod_change_gid+move_homedir_other_device/usermod.test

raw
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" "usermod can move the user's home directory, over a new device and changes the owner of the user's file"
11
12 save_config
13
14 # restore the files on exit
15 trap 'log_status "$0" "FAILURE"; restore_config; rm -rf /home/foo /home/foo2; umount /tmp/home; rmdir /tmp/home' 0
16
17 change_config
18
19 mkdir /home/foo
20 mkdir /home/foo/titi
21 echo toto > /home/foo/toto
22 echo tyty > /home/foo/tyty
23 ln /home/foo/toto /home/foo/.tata
24 ln /home/foo/tyty /home/foo/.tyty
25 ln -s /home/foo/toto /home/foo/tutu
26 mknod /home/foo/null c 1 3
27 ln /etc/profile /home/foo/profile2
28 echo root > /home/foo/uroot
29 echo root > /home/foo/groot
30 chown -R foo:foo /home/foo
31 chown root /home/foo/uroot
32 chgrp root /home/foo/groot
33 stat --printf "%A %u:%g %N\n" /home/foo/* /home/foo/.* 2>/dev/null | sort
34
35 mkdir /tmp/home
36 mount --bind /home /tmp/home
37
38 echo -n "Change the user's home directory (usermod -m -d /tmp/home/foo2 -g 1001 foo ..."
39 usermod -m -d /tmp/home/foo2 -g 1001 foo
40 echo "OK"
41
42 echo -n "Check the passwd file..."
43 ../../../common/compare_file.pl data/passwd /etc/passwd
44 echo "OK"
45 echo -n "Check the group file..."
46 ../../../common/compare_file.pl config/etc/group /etc/group
47 echo "OK"
48 echo -n "Check the shadow file..."
49 ../../../common/compare_file.pl config/etc/shadow /etc/shadow
50 echo "OK"
51 echo -n "Check the gshadow file..."
52 ../../../common/compare_file.pl config/etc/gshadow /etc/gshadow
53 echo "OK"
54 echo -n "Check the user's home directory was removed..."
55 test ! -d /home/foo
56 echo "OK"
57 echo -n "Check the user's home directory was moved..."
58 test -d /home/foo2
59 echo "OK"
60 echo -n "Check content of /tmp/test-newusers..."
61 stat --printf "%A %u:%g %N\n" /home/foo2/* /home/foo2/.* 2>/dev/null | sort > tmp/home_ls-a
62 diff -rauN data/home_ls-a tmp/home_ls-a
63 echo "OK"
64 echo -n "Check that hardlink to another homedir file remains a hardlink..."
65 dev_ino=$(stat --printf "%d-%i" /home/foo2/toto)
66 dev_ino2=$(stat --printf "%d-%i" /home/foo2/.tata)
67 test "$dev_ino" = "$dev_ino2"
68 echo "OK"
69 echo -n "Check hardlink to outside the homedir..."
70 dev_ino=$(stat --printf "%d-%i" /etc/profile)
71 dev_ino2=$(stat --printf "%d-%i" /home/foo2/profile2)
72 echo "$dev_ino" != "$dev_ino2"
73 #test "$dev_ino" = "$dev_ino2"
74 echo "NOT IMPLEMENTED"
75 rm -f tmp/home_ls-a
76
77 echo -n "Remove the new home directory..."
78 rm -rf /home/foo2
79 echo "done"
80
81 umount /tmp/home
82 rmdir /tmp/home
83
84 log_status "$0" "SUCCESS"
85 restore_config
86 trap '' 0
87