On Thu, Jun 16, 2011 at 06:38:51PM +0200, Jesus Sanchez wrote:
> > 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
> >
>
>
> Looking others *BSDs in NetBSD noticed this and made the change. You can
> see in revision 1.33 of utils.c (
> http://cvsweb.netbsd.org/bsdweb.cgi/src/bin/cp/utils.c?only_with_tag=MAIN)
> in case you think it's OK to make the patch
> their diff version it's much better than mine. The NetBSD change matches
> POSIX.
>
> Regards.
> -Jesus
Below is the actual diff. I believe this is right indeed.
-Otto
Index: utils.c
===================================================================
RCS file: /cvs/src/bin/cp/utils.c,v
retrieving revision 1.30
diff -u -p -r1.30 utils.c
--- utils.c 27 Oct 2009 23:59:21 -0000 1.30
+++ utils.c 19 Jun 2011 07:06:50 -0000
@@ -178,7 +178,8 @@ copy_file(FTSENT *entp, int dne)
*/
#define RETAINBITS \
(S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
- else if (fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
+ if (!pflag && dne &&
+ fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
if (fstat(to_fd, &to_stat)) {
warn("%s", to.p_path);
rval = 1;