Fix a security race with "cp -p A B" when B already exists.
commitb64119bc54791809b9fc3a225761b1c913fe66bc
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 1 Dec 2007 09:09:57 +0000 (1 10:09 +0100)
committerJim Meyering <meyering@redhat.com>
Sat, 1 Dec 2007 09:09:57 +0000 (1 10:09 +0100)
tree15566919c6c92780e8677a300cef940668fe2bad
parent317413874c935c8605ae3549e7575e03427b953e
Fix a security race with "cp -p A B" when B already exists.

* src/copy.h (struct cp_options): New member owner_privileges.
* src/copy.c (USE_ACL): Define to 0 if not defined, for convenience.
(owner_failure_ok): New function.
(set_owner): Avoid a security-related race by doing an extra chmod
first if it looks like there might be trouble right after a chown.
Accept a source struct stat rather than a uid and gid, and
accept a boolean NEW_DST and destination struct stat.
All callers changed.
* src/copy.h (cp_options_default): New function, replacing the
old chown_privileges.
* src/copy.c (cp_options_default): Likewise.
* src/cp.c (cp_option_init): Use it.
* src/install.c (cp_option_init): Likewise.
* src/mv.c (cp_option_init): Likewise.
ChangeLog
src/copy.c
src/copy.h
src/cp.c
src/install.c
src/mv.c