2001-03-29 18:15:54

by Xavier Ordoquy

[permalink] [raw]
Subject: Bug in the file attributes ?


Hi,

I just made a manipulation that disturbs me. So I'm asking whether it's a
bug or a features.

user> su
root> echo "test" > test
root> ls -l
-rw-r--r-- 1 root root 5 Mar 29 19:14 test
root> exit
user> rm test
rm: remove write-protected file `test'? y
user> ls test
ls: test: No such file or directory

This is in the user home directory.
Since the file is read only for the user, it should not be able to remove
it. Moreover, the user can't write to test.
So I think this is a bug.

---
Xavier Ordoquy, Aurora-linux
If NT is the answer, you didn't understand the question.


2001-03-29 18:45:44

by Andreas Dilger

[permalink] [raw]
Subject: Re: Bug in the file attributes ?

Xavier Ordoquy writes:
> I just made a manipulation that disturbs me. So I'm asking whether it's a
> bug or a features.
>
> user> su
> root> echo "test" > test
> root> ls -l
> -rw-r--r-- 1 root root 5 Mar 29 19:14 test
> root> exit
> user> rm test
> rm: remove write-protected file `test'? y
> user> ls test
> ls: test: No such file or directory
>
> This is in the user home directory.
> Since the file is read only for the user, it should not be able to remove
> it. Moreover, the user can't write to test.

This is definitely not a bug. Deleting a file (under *nix) does not
"modify" the file at all, it is modifying the directory where the file
resides. In this case, a user _will_ have permission to write into
their home directory, so they can delete the file, but not modify it.

Why do such a thing? If you have group/world write permission on a
directory, then people who have write permission to the _directory_
should be able to delete files even if they don't own them. However,
if you set the "sticky" bit on the directory (chmod +t /dir), then only
the owner of the file can delete it, like in /tmp.

Cheers, Andreas
--
Andreas Dilger \ "If a man ate a pound of pasta and a pound of antipasto,
\ would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/ -- Dogbert

2001-03-29 18:51:44

by Xavier Ordoquy

[permalink] [raw]
Subject: Re: Bug in the file attributes ?


OK, thanks for the answer.
I've spoken to a few people before and they hadn't heard about it.
Since once upon the time on a solaris system I've had a root file that I
couldn't remove even if I hold the rights of the directory.
This is why I figured out this was a bug.
Anyway, thanks for that.

---
Xavier Ordoquy, Aurora-linux
If NT is the answer, you didn't understand the question.

2001-03-29 18:51:35

by Justin Carlson

[permalink] [raw]
Subject: Re: Bug in the file attributes ?

On Thu, 29 Mar 2001, Xavier Ordoquy wrote:
> Hi,
>
> I just made a manipulation that disturbs me. So I'm asking whether it's a
> bug or a features.
>
> user> su
> root> echo "test" > test
> root> ls -l
> -rw-r--r-- 1 root root 5 Mar 29 19:14 test
> root> exit
> user> rm test
> rm: remove write-protected file `test'? y
> user> ls test
> ls: test: No such file or directory
>
> This is in the user home directory.
> Since the file is read only for the user, it should not be able to remove
> it. Moreover, the user can't write to test.
> So I think this is a bug.

You don't need write perms on a file to remove it, you need write perms on the
directory. If you've got write permissions on the directory, you can remove
any file in the directory, regardless of the permissions.

-Justin

2001-03-29 18:48:54

by Stephen Clouse

[permalink] [raw]
Subject: Re: Bug in the file attributes ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Mar 29, 2001 at 08:20:32PM +0000, Xavier Ordoquy wrote:
> This is in the user home directory.
> Since the file is read only for the user, it should not be able to remove
> it. Moreover, the user can't write to test.
> So I think this is a bug.

You have failed to RTFM. There is no bug here.

http://www.linuxdoc.org/FAQ/Linux-FAQ/x1955.html#AEN2242

- --
Stephen Clouse <[email protected]>
Senior Programmer, IQ Coordinator Project Lead
The IQ Group, Inc. <http://www.theiqgroup.com/>

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBOsOC1gOGqGs0PadnEQJtVwCgm23nRu0O14SwWvxjZDulld8m24YAn2vb
yHGvzJR10oC1dabikTezfX+3
=TlMz
-----END PGP SIGNATURE-----

2001-03-29 19:05:24

by John Jasen

[permalink] [raw]
Subject: Re: Bug in the file attributes ?

On Thu, 29 Mar 2001, Xavier Ordoquy wrote:

> OK, thanks for the answer.
> I've spoken to a few people before and they hadn't heard about it.
> Since once upon the time on a solaris system I've had a root file that I
> couldn't remove even if I hold the rights of the directory.
> This is why I figured out this was a bug.
> Anyway, thanks for that.

I think, I could very easily be mistaken, tho', that being able to do this
is part of posix compliance.

--
-- John E. Jasen ([email protected])
-- In theory, theory and practise are the same. In practise, they aren't.

2001-03-29 19:26:44

by Jesse Pollard

[permalink] [raw]
Subject: Re: Bug in the file attributes ?

--------- Received message begins Here ---------

>
>
> Hi,
>
> I just made a manipulation that disturbs me. So I'm asking whether it's a
> bug or a features.
>
> user> su
> root> echo "test" > test
> root> ls -l
> -rw-r--r-- 1 root root 5 Mar 29 19:14 test
> root> exit
> user> rm test
> rm: remove write-protected file `test'? y
> user> ls test
> ls: test: No such file or directory
>
> This is in the user home directory.
> Since the file is read only for the user, it should not be able to remove
> it. Moreover, the user can't write to test.
> So I think this is a bug.

Nope - rm only updates the directory, which the user owns; not the file.
The prompt is just being nice.

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: [email protected]

Any opinions expressed are solely my own.

2001-03-29 23:00:18

by Brian Beattie

[permalink] [raw]
Subject: Re: Bug in the file attributes ?

On Thu, 29 Mar 2001, Andreas Dilger wrote:

> Xavier Ordoquy writes:
> > I just made a manipulation that disturbs me. So I'm asking whether it's a
> > bug or a features.
> >
> > user> su
> > root> echo "test" > test
> > root> ls -l
> > -rw-r--r-- 1 root root 5 Mar 29 19:14 test
> > root> exit
> > user> rm test
> > rm: remove write-protected file `test'? y
> > user> ls test
> > ls: test: No such file or directory
> >
> > This is in the user home directory.
> > Since the file is read only for the user, it should not be able to remove
> > it. Moreover, the user can't write to test.
>
> This is definitely not a bug. Deleting a file (under *nix) does not
> "modify" the file at all, it is modifying the directory where the file
> resides.

To be correct and pedantic, in a traditional Unix type filesystem, one
does not remove a file...one dereferences it, i.e. "unlink", as part of
this process garbage collection is performed which checks the reference
count. If the inode's reference count is zero, the inode and data blocks
are returned to their respective free lists. All the rm command does, is
to remove the directory entry and decrement the reference count :). This
is why Unix has a rm (remove link) as opposed to a del (delete file)
command.

Brian...just being pedantic :-^

Brian Beattie
[email protected]
503.578.5899 Des2-3C-5

2001-03-30 02:35:15

by Tim Wright

[permalink] [raw]
Subject: Re: Bug in the file attributes ?

On Thu, Mar 29, 2001 at 10:51:18AM -0800, Justin Carlson wrote:
> You don't need write perms on a file to remove it, you need write perms on the
> directory. If you've got write permissions on the directory, you can remove
> any file in the directory, regardless of the permissions.
>
> -Justin

Except when the "sticky" bit is set. This is useful for shared temporary
directories. Files can be created by anyone, but they can only be unlinked
by the owner or by the superuser. Take a look at the permissions of /var/tmp.

Tim

--
Tim Wright - [email protected] or [email protected] or [email protected]
IBM Linux Technology Center, Beaverton, Oregon
Interested in Linux scalability ? Look at http://lse.sourceforge.net/
"Nobody ever said I was charming, they said "Rimmer, you're a git!"" RD VI