~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/chown/preserve-root

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# Verify that --preserve-root works.
3
 
 
4
 
# Copyright (C) 2006-2011 Free Software Foundation, Inc.
5
 
 
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.
10
 
 
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.
15
 
 
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/>.
18
 
 
19
 
. "${srcdir=.}/init.sh"; path_prepend_ ../src
20
 
print_ver_ chown
21
 
skip_if_root_
22
 
 
23
 
mkdir d && ln -s / d/slink-to-root
24
 
 
25
 
 
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
31
 
 
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
36
 
 
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
43
 
 
44
 
# These must fail.
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
48
 
 
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
56
 
==== test -RHh
57
 
==== test -RLh
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
62
 
EOF
63
 
 
64
 
compare out exp || fail=1
65
 
 
66
 
Exit $fail