maint: add a syntax check to prevent use of NULL
[coreutils.git] / tests / cp / capability.sh
blobbe3a7f8efe3cac18ad2cc9d6993336bb0177bbf2
1 #!/bin/sh
2 # Ensure cp --preserves copies capabilities
4 # Copyright (C) 2010-2023 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 <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ cp
21 require_root_
22 working_umask_or_skip_
25 grep '^#define HAVE_CAP 1' $CONFIG_HEADER > /dev/null \
26 || skip_ "configured without libcap support"
28 (setcap --help) 2>&1 |grep 'usage: setcap' > /dev/null \
29 || skip_ "setcap utility not found"
30 (getcap --help) 2>&1 |grep 'usage: getcap' > /dev/null \
31 || skip_ "getcap utility not found"
34 touch file || framework_failure_
35 chown $NON_ROOT_USERNAME file || framework_failure_
37 setcap 'cap_net_bind_service=ep' file ||
38 skip_ "setcap doesn't work"
39 getcap file | grep cap_net_bind_service >/dev/null ||
40 skip_ "getcap doesn't work"
42 cp --preserve=xattr file copy1 || fail=1
44 # Before coreutils 8.5 the capabilities would not be preserved,
45 # as the owner was set _after_ copying xattrs, thus clearing any capabilities.
46 cp --preserve=all file copy2 || fail=1
48 for file in copy1 copy2; do
49 getcap $file | grep cap_net_bind_service >/dev/null || fail=1
50 done
52 Exit $fail