2001-05-11 09:14:22 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
# make sure chown --from=... works
|
|
|
|
|
|
2023-01-01 14:50:15 +00:00
|
|
|
# Copyright (C) 2001-2023 Free Software Foundation, Inc.
|
2006-08-17 19:58:17 +00:00
|
|
|
|
2007-07-23 14:35:58 +02:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2006-08-17 19:58:17 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-23 14:35:58 +02:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
2006-08-17 19:58:17 +00:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2017-09-19 01:13:23 -07:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2006-08-17 19:58:17 +00:00
|
|
|
|
2012-09-02 21:55:12 +02:00
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
2012-08-22 15:04:04 +02:00
|
|
|
print_ver_ chown
|
2007-12-08 12:29:25 +01:00
|
|
|
require_root_
|
2001-05-11 09:14:22 +00:00
|
|
|
|
2011-08-04 20:52:31 +02:00
|
|
|
touch f || framework_failure_
|
2001-05-11 09:14:22 +00:00
|
|
|
|
2004-12-14 10:42:58 +00:00
|
|
|
chown -R --preserve-root 0:1 f
|
2001-05-11 09:14:22 +00:00
|
|
|
|
|
|
|
|
# Make sure the owner and group are 0 and 1 respectively.
|
2012-04-03 20:32:44 +02:00
|
|
|
set _ $(ls -n f); shift; test "$3:$4" = 0:1 || fail=1
|
2001-05-11 09:14:22 +00:00
|
|
|
|
2011-05-26 11:15:11 +01:00
|
|
|
# Make sure the correct diagnostic is output
|
|
|
|
|
# Note we output a name even though an id was specified.
|
|
|
|
|
chown -v --from=42 43 f > out || fail=1
|
2012-04-03 20:32:44 +02:00
|
|
|
printf "ownership of 'f' retained as $(id -nu)\n" > exp
|
2011-11-22 10:08:04 +01:00
|
|
|
compare exp out || fail=1
|
2011-05-26 11:15:11 +01:00
|
|
|
|
|
|
|
|
# Ensure diagnostics work for non existent files.
|
2015-01-13 03:30:33 +00:00
|
|
|
returns_ 1 chown -v 0 nf > out || fail=1
|
2012-01-07 17:43:50 +01:00
|
|
|
printf "failed to change ownership of 'nf' to 0\n" > exp
|
2011-11-22 10:08:04 +01:00
|
|
|
compare exp out || fail=1
|
2011-05-26 11:15:11 +01:00
|
|
|
|
2004-07-28 23:05:27 +00:00
|
|
|
chown --from=0:1 2:010 f || fail=1
|
2001-05-11 09:14:22 +00:00
|
|
|
|
2004-07-28 23:05:27 +00:00
|
|
|
# And now they should be 2 and 10 respectively.
|
2012-04-03 20:32:44 +02:00
|
|
|
set _ $(ls -n f); shift; test "$3:$4" = 2:10 || fail=1
|
2001-05-11 09:14:22 +00:00
|
|
|
|
2004-12-14 10:42:58 +00:00
|
|
|
ln -s f slink
|
|
|
|
|
# Applying chown to a symlink with --no-dereference
|
|
|
|
|
# should change only the link.
|
|
|
|
|
chown --no-dereference 0:1 slink || fail=1
|
|
|
|
|
# owner/group on the symlink should be set
|
2012-04-03 20:32:44 +02:00
|
|
|
set _ $(ls -n slink); shift; test "$3:$4" = 0:1 || fail=1
|
2004-12-14 10:42:58 +00:00
|
|
|
# owner/group on the referent should remain unchanged
|
2012-04-03 20:32:44 +02:00
|
|
|
set _ $(ls -n f); shift; test "$3:$4" = 2:10 || fail=1
|
2004-12-14 10:42:58 +00:00
|
|
|
|
|
|
|
|
chown --no-dereference --from=0:1 2:010 slink || fail=1
|
|
|
|
|
# owner/group on the symlink should be changed
|
2012-04-03 20:32:44 +02:00
|
|
|
set _ $(ls -n slink); shift; test "$3:$4" = 2:10 || fail=1
|
2004-12-14 10:42:58 +00:00
|
|
|
|
2008-09-07 10:31:27 +02:00
|
|
|
Exit $fail
|