FYI: safe use of chown

Ryo Furue furue at hawaii.edu
Mon Nov 10 19:55:19 GMT 2008


Hi,

| # whoami
| joe
| 
| # cd ; pwd
| /home/joe
| 
| # ln -s /etc/passwd passwd
| 
| Guess what happens when you come along as root and do:
| 
| chown -R joe:joegroup /home/joe   ???
| 
| /etc/passwd gets owned by 'joe'.  (according to POSIX rules on
| symlink dereferencing.  (see chown() and lchown())
| 
| 
| I have learned to get in the habit of ALWAYS typing '-h' with '-R':
| 
|    chown -hR user:group {dir}
| 
| where '-h' specifies to NOT traverse/dereference symlinks.

Thanks for the information.  I did a little research and
conclude that your advice is good, because, as you said,
different Unix systems behave differently and "-h" is always
safer to add than not.

Initially I was puzzled to read the manpage of chown(1) because
it says the default behavior of chown is that it doesn't change
the owner of the linked-to file when encountering a symbolic
link, meaning it's safe without "-h".  Then, I found this
explanation:

  http://www.hackinglinuxexposed.com/articles/20020402.html

which says that the system call chown(2) does change the linked-to
file rather than the symbolic itself, that the Linux version
of the chown(1) command is inconsistent with the system call,
and that there are systems on which the command is consistent
with the system call, such as Solaris.

So, all things considered, it's better to develop a habit of
using "-h" unless you have a reason not to do so.

Cheers,
Ryo
___________________________________________________
This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.




More information about the kde mailing list