[aklug] Re: Strange hard linking

From: Kevin Miller <atftb2@alaska.net>
Date: Fri Nov 26 2010 - 14:57:29 AKST

On 11/26/2010 02:24 PM, Christopher Howard wrote:
> So, I was messing around the other day, and found this rather wierd
> behavior in Linux:
>
> First, I go root, and cd to some public directory. I create a file
> with some text in it (we'll call it file0) with the new file of
> course being own by root.
>
> Next, I switch back to a regular user account. I cd to my /tmp
> directory, and use the ln command to create a new file (file1) in the
> /tmp directory that is a hard link to file0. The new file1, strangely
> enough, is not own by me, but is owned by root, although it does have
> "everyone" read permissions.
>
> Then, I go root again, and I delete file0. I switch back to my
> regular user, and discover that file1 still exists, and is still
> owned by root. I cannot delete it with my regular user account.
>
> So, in summary, as a non-root user, I have the ability to "create"
> (preserve?) files that I do not own and that I cannot delete.

I believe that's because what is really owned is the inode entry. When
you create the first file, root "owns" the inode. When you create the
hard link, it's really just a pointer to the inode (If I understand
arightly). So when you delete the first file, the entry is deleted for
the public directory but the file still exists as created.

I'm sure my explanation is rather limited - others here can/will
probably clarify more fully.

What were the world permissions on the original file?

-- 
Kevin Miller - http://www.alaska.net/~atftb
Juneau, Alaska
In a recent survey, 7 out of 10 hard drives preferred Linux
Registered Linux User No: 307357, http://counter.li.org
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Fri Nov 26 14:57:28 2010

This archive was generated by hypermail 2.1.8 : Fri Nov 26 2010 - 14:57:28 AKST