On 06/15/11 11:48, Philip Guenther wrote:
On Jun 15, 2011, at 2:30 AM, Jesus Sanchez<[email protected]> wrote:
A more readable version of the previous diff.
The first change moves the setfile() call out of
the 'if' to avoid the case of the pflag being active
and setfile() returning 0 witch makes the retainbits
block executed, it might not be desirable after the
chmod() in setfile().
To rephrase what I said on the list and offlist: please justify your claim that
the manual is correct and the binary wrong, preferrably by reference to what
the POSIX standard requires.
Philip Guenther
quote from IEEE Std 1003.1-2008,
(http://pubs.opengroup.org/onlinepubs/9699919799/toc.htm) the utilities cp
section for the option '-p' and the behavior if target file exist:
-p
Duplicate the following characteristics of each source file in the
corresponding destination file:
1.
The time of last data modification and time of last access. If this
duplication fails for any reason, cp shall write a diagnostic
message to
standard error.
2.
The user ID and group ID. If this duplication fails for any reason,
it is unspecified whether cp writes a diagnostic message to
standard error.
3.
The file permission bits and the S_ISUID and S_ISGID bits. Other,
implementation-defined, bits may be duplicated as well. If this
duplication
fails for any reason, cp shall write a diagnostic message to
standard error.
If the user ID or the group ID cannot be duplicated, the file
permission
bits S_ISUID and S_ISGID shall be cleared. If these bits are
present in the
source file but are not duplicated in the destination file, it is
unspecified
whether cp writes a diagnostic message to standard error.
[...]
If source_file is of type regular file, the following steps shall be taken:
1.
The behavior is unspecified if dest_file exists and was written by a
previous
step. Otherwise, if dest_file exists, the following steps shall be taken:
1.
If the -i option is in effect, the cp utility shall write a prompt
to the
standard error and read a line from the standard input. If the
response is not
affirmative, cp shall do nothing more with source_file and go on to any
remaining files.
2.
A file descriptor for dest_file shall be obtained by performing actions
equivalent to the open() function defined in the System Interfaces
volume of
POSIX.1-2008 called using dest_file as the path argument, and the
bitwise-inclusive OR of O_WRONLY and O_TRUNC as the oflag argument.
3.
If the attempt to obtain a file descriptor fails and the -f option
is in
effect, cp shall attempt to remove the file by performing actions
equivalent to
the unlink() function defined in the System Interfaces volume of
POSIX.1-2008
called using dest_file as the path argument. If this attempt
succeeds, cp shall
continue with step 3b.
[...]
---------------------------------------------------------
So it seems that the cp(1) manpage got it right, if the file exists preserve
mode, if the file doesn't exist apply the umask. In the case of the '-p'
option
preserve setuid and setgid bits if UID and GID can be preserved. If I'm
right
it's a binary mismatch.
Hope this helps.
-Jesus