Subject: Re: cp copying perms of setuid source without -p: is this a bug?
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@tac.gw.com>
List: tech-userlevel
Date: 05/10/2005 09:09:41
In article <d5pbcv$8tv$1@sea.gmane.org>, Jed Davis <jdev@panix.com> wrote:
>It goes something like this:
>
>  hostname# ls -l /dev/null                       
>  crw-rw-rw-  1 root  wheel  2, 2 May  9 18:33 /dev/null
>  hostname# cp /usr/libexec/ssh-keysign /dev/null
>  hostname# ls -l /dev/null                      
>  cr-sr-xr-x  1 root  wheel  2, 2 May  9 23:25 /dev/null
>
>The code responsible is in src/bin/cp/utils.c, lines 184-200 in r1.27;
>the purpose of that being apparently to handle setuid bits safely.
>However, it seems to me that, if pflag==0, then there's no point to any
>of this and it should all be skipped --- rather than skipping only the
>setfile() and proceeding into the tests for the source's having been
>set[ug]id and the ensuing fchmod().
>
>However, that code goes back to the beginning of NetBSD's CVS history, so
>I felt I should ask about this first rather than immediately filing a PR.

Please send-pr. cp without -p when executed by root is supposed to copy
the permissions when the file is being created, but not when the file
already exists. At least this is what solaris and linux do.

christos