On Wed, 2005-06-08 at 21:39 +0300, Shachar Shemesh wrote:
> Alon Altman wrote:
> 
> > On Wed, 8 Jun 2005, Shachar Shemesh wrote:
> >
> >> Hi all,
> >>
> >> Does anyone know WHY only root can create hard links to directories? 
> >> What is the attack/problem this permission restriction is trying to 
> >> solve?
> >
> >
> > Because only root can unlink a non-empty directory?
> 
> I was hoping to learn something new from the answers, but I have to 
> admit that I didn't expect anything like that.
> 
> WHY can root unlink a non-empty directory? Why is that useful? What's 
> the difference between that and "rm -r", and when would I want to use that?
> 
> Congrats, Alon. Not only did you not answer my question, you've added to 
> the mystery :-)

My assumption: if you hard-link to a file not owned by you, inside a
directory you do have write access to (otherwise you can't create the
link), the file will of course be identical to the original file (it
_is_ a hard-link). Meaning it will have the same owner, same
permissions, and same bits in general. 

So...

1) I am in /home/shimi/test and my uid is 500
2) I do ln -d /sbin/ifconfig
3) If I do ls -li, I see "ifconfig" with the same inode
of /sbin/ifconfig, owned by uid 0.
4) I try rm -rf ~/test - and I fail. I cannot erase the file "ifconfig"
because it is not owned by me (even though I created it. bad!). I also
can't erase the directory because it's non-empty (and I'm not root).

Why can root erase a non-empty directory? If you want to dereference the
directory but not the files. Why would you want to do that? I guess it
could be related to hard-linked directories... ;)

-- 
shimi <[EMAIL PROTECTED]>


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to