Jonathan McKeown wrote:
> On Thursday 07 February 2008 20:07, Pietro Cerutti wrote:
> 
>> HostServer exports via NFS /www, which belongs to user:www
>> (uid=1001, gid=80). The directory has the segid flag set:
>>
>> drwsr-xr-x  13 user www 512 Feb 7 00:58 www
>>
>> HostClient mounts the exported directory on /share/www. HostClient
>> doesn't know anything about gid 80.
>>
>> Now, on HostClient, user copies aFile to /share/www using the -p flag of
>> cp(1).
>>
>>> cp -p aFile /share/www/
>>> ls -l
>> -rw-------  1 user user  2981888 Feb  7 01:09 /www/aFile
>>
>> As shown, the setgid flag of /www hasn't worked.
> 
> Hang on - you asked cp to preserve the user and group ownership of the file 
> (cp -p). As far as I can see, it's done what you asked it to. I would regard 
> any other result as violating the Principle of Least Astonishment.

You are right. I thought that the setgid of the destination directory
had priority over the -p. If it's not the case, then this means that
mv(1) cannot be used across filesystems when one wants to ensure that
the setgid of the target directory does what it's supposed to do. From
man mv(1):

"As the rename(2) call does not work across file systems, mv uses cp(1)
and rm(1) to accomplish the move.  The effect is equivalent to:

           rm -f destination_path && \
           cp -pRP source_file destination && \
           rm -rf source_file
"

Note that mv invokes cp with the -p option. Is there any way to prevent
that?

> Jonathan


-- 
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to