Re: How does chown(2) works with symlinks?

Mark.Hemment@uniplex.co.uk
Mon, 8 Jul 96 09:44:46 +0100


Linus wrote:
> If you want to change the owner of the file it points to, use:
> fd = open(...);
> fchown(fd,..);

> which should always work the way you expect. If you use "chown()" on
> the pathname it will change the synlink itself (if you think about it,
> that is actually the reasonable behaviour: otherwise you could never
> change the owner of the symlink).

> I think some older versions of linux actually changed the file that the
> symlink pointed to, and it got changed at one point. I could be mistaken,
> though,

This behaviour is incompatible with most (all?) other versions of
UNIX I've used - SVR4 derived, and Solaris.

The chown(2) syscall should follow the link(s). The OS provides another
call, lchown(2), for operating directly on a symlink (some also
provide a lchmod(2), such as SCO's OpenServer). There is also a
lstat(2).

For me, a chown(2) makes more sense if it follows the link - I want
to change the ownership of the file that would be open(2)ed or
stat(2)ed, not something inbetween.

I believe the latest POSIX drafts have tackled symbolic links (they
worked around the issue before). It would be nice to known what
they say...

markhe