2
# Verify that --preserve-root works.
4
# Copyright (C) 2006-2011 Free Software Foundation, Inc.
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
. "${srcdir=.}/init.sh"; path_prepend_ ../src
23
mkdir d && ln -s / d/slink-to-root
26
# Even if --preserve-root were to malfunction, allowing the chown or
27
# chgrp to traverse through "/", since we're running as non-root,
28
# they would be very unlikely to cause any changes.
29
chown -R --preserve-root 0 / > out 2>&1 && fail=1
30
chgrp -R --preserve-root 0 / >> out 2>&1 && fail=1
32
# Here, if --preserve-root were to malfunction, chmod could make changes,
33
# but only to files owned and unreadable by the user running this test,
34
# and then, only to make them readable by owner.
35
chmod -R --preserve-root u+r / >> out 2>&1 && fail=1
37
# With -RHh, --preserve-root should trigger nothing,
38
# since the symlink in question is not a command line argument.
39
# Contrary to the above commands, these two should succeed.
40
echo '==== test -RHh' >> out
41
chown -RHh --preserve-root `id -u` d >> out 2>&1 || fail=1
42
chgrp -RHh --preserve-root `id -g` d >> out 2>&1 || fail=1
45
echo '==== test -RLh' >> out
46
chown -RLh --preserve-root `id -u` d >> out 2>&1 && fail=1
47
chgrp -RLh --preserve-root `id -g` d >> out 2>&1 && fail=1
49
cat <<\EOF > exp || fail=1
50
chown: it is dangerous to operate recursively on `/'
51
chown: use --no-preserve-root to override this failsafe
52
chgrp: it is dangerous to operate recursively on `/'
53
chgrp: use --no-preserve-root to override this failsafe
54
chmod: it is dangerous to operate recursively on `/'
55
chmod: use --no-preserve-root to override this failsafe
58
chown: it is dangerous to operate recursively on `d/slink-to-root' (same as `/')
59
chown: use --no-preserve-root to override this failsafe
60
chgrp: it is dangerous to operate recursively on `d/slink-to-root' (same as `/')
61
chgrp: use --no-preserve-root to override this failsafe
64
compare out exp || fail=1