mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
When copying to a directory, use functions like openat to access the destination files, when such functions are available. This should be more efficient and should avoid some race conditions. * bootstrap.conf (gnulib_modules): Add areadlinkat-with-size, fchmodat, fchownat, mkdirat, mkfifoat, utimensat. * src/copy.c (lchown) [!HAVE_LCHOWN]: * src/copy.c, src/system.h (rpl_mkfifo, mkfifo) [!HAVE_MKFIFO]: Remove. All uses removed. (utimens_symlink): Remove; we shouldn’t have to worry about those obsolete systems any more. All uses replaced by utimensat. * src/copy.c (copy_dir, set_owner, fchmod_or_lchmod, copy_reg) (same_file_ok, writable_destination, overwrite_ok, abandon_move) (create_hard_link, src_is_dst_backup, copy_internal, copy): * src/cp.c (make_dir_parents_private, re_protect): New args for directory-relative names. All uses changed. Continue to pass full names as needed, for diagnostics and for lower-level functions like qset_acl that do not support directory-relative names. * src/copy.c (copy_reg): Prefer readlinkat to lstatat for merely checking whether a file is a symlink, to avoid EOVERFLOW issues. (subst_suffix): New function. (create_hard_link): Accept a null SRC_NAME as meaning that if it is needed it needs to be constructed from SRC_RELNAME, DST_NAME, and DST_RELNAME. (source_is_dst_backup): Use subst_suffix instead of doing it by hand. (copy_internal): Remember and use directory-relative names instead of full names. * src/cp.c (lchown) [!HAVE_LCHOWN]: Remove. All uses removed. (must_be_working_directory): New function. (target_directory_operand): Simply take file name as arg, and return a file descriptor or negative number on failure; open with O_DIRECTORY to obtain any file descriptor. All uses changed. (target_dirfd_valid): New function. (do_copy): Use these new functions to obtain a file descriptor for any target directory, and use directory-relative names for that directory. (main): Omit no-longer-needed stat when --target-directory, as do_copy now does this. * src/ln.c (O_PATHSEARCH): Move from here ... * src/system.h: ... to here. * tests/cp/fail-perm.sh: Adjust to change in diagnostic wording, and add a test for --no-target-directory.
67 lines
2.0 KiB
Bash
Executable File
67 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Copyright (C) 2000-2022 Free Software Foundation, Inc.
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (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
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
|
print_ver_ cp
|
|
skip_if_root_
|
|
|
|
chmod g-s . || framework_failure_
|
|
mkdir D D/D || framework_failure_
|
|
touch D/a || framework_failure_
|
|
chmod 0 D/a || framework_failure_
|
|
chmod u=rx,go=,-st D || framework_failure_
|
|
|
|
|
|
# This is expected to exit non-zero, because it can't read D/a.
|
|
returns_ 1 cp -pR D DD > /dev/null 2>&1 || fail=1
|
|
|
|
# Permissions on DD must be 'dr-x------'
|
|
|
|
mode=$(ls -ld DD|cut -b-10)
|
|
test "$mode" = dr-x------ || fail=1
|
|
|
|
chmod 0 D
|
|
ln -s D/D symlink
|
|
touch F
|
|
cat > exp <<\EOF
|
|
cp: cannot stat 'symlink': Permission denied
|
|
EOF
|
|
|
|
cp F symlink 2> out && fail=1
|
|
# HPUX appears to fail with EACCES rather than EPERM.
|
|
# Transform their diagnostic
|
|
# ...: The file access permissions do not allow the specified action.
|
|
# to the expected one:
|
|
sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
|
|
compare exp out || fail=1
|
|
|
|
cp --no-target-directory F symlink 2> out && fail=1
|
|
sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
|
|
compare exp out || fail=1
|
|
|
|
cat > exp <<\EOF
|
|
cp: target directory 'symlink': Permission denied
|
|
EOF
|
|
|
|
cp --target-directory=symlink F 2> out && fail=1
|
|
sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
|
|
compare exp out || fail=1
|
|
|
|
chmod 700 D
|
|
|
|
Exit $fail
|