[comp.emacs] Saving a file in emacs without the right permission bits

konath@sj.ate.slb.com (Kannan Konath) (04/19/91)

I am using GNU Emacs 18.57 on Sparc SLC running SunOS 4.1.1

When I create a file it is created with permission bits set to
rw-r--r--.   I walk over to another workstation with a different
user, who has the same group id as I do,  and try editing the same
file. 

Emacs tells me the buffer is read-only but if I do a "C-x C-q"
(toogle-read-only)  the "%%" disappears from the status line and turns
to "--".  I alter the file and when I try saving it, emacs responds by
asking me whether I really want to save the file, to which I reply
yes.  It saves the file and changes the ownership of the file to
the new user.

My question is this:

Isn't it illegal for another user to be able to overwrite a file over
which he does not have "w" status?  

kannan

-- 
------------------------------------------------------------------------------
Kannan Konath				Phone:	(408) 437-5143	
Software Engineer			Email:	konath@sj.ate.slb.com
Board Test Products

barmar@think.com (Barry Margolin) (04/19/91)

In article <1991Apr18.220342.25107@sj.ate.slb.com> konath@sj.ate.slb.com (Kannan Konath) writes:
>  I alter the file and when I try saving it, emacs responds by
>asking me whether I really want to save the file, to which I reply
>yes.  It saves the file and changes the ownership of the file to
>the new user.
>Isn't it illegal for another user to be able to overwrite a file over
>which he does not have "w" status?  

Yes -- that's why it asks permission first :-)

Actually, it's not overwriting the file, and it's not changing its
ownership.  GNU Emacs renames the old file to filename~ or
filename.~<version#>~, and then creates a *new* file with the old file's
name.  Since you created the new file, you are its owner.

The only access you need to do this is write access to the directory; the
access on the file itself doesn't matter, because you aren't actually
modifying the file, just the directory entry that refers to it.

To verify this, use "ls -i" before and after saving the file, and notice
that it has a different inode number.
 
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

jackr@dblues.wpd.sgi.com (John "Jack" Repenning) (04/19/91)

In article <stngjn.@rpi.edu> ramabads@cs.rpi.edu (Shiva ) writes:

   Excuse this dumb question, but should'nt the owner be the only person who
   is allowed to rename files ???  Especially if the permissions are 644 as 
   Kanan claims ???

Renaming is allowed for anyone with write permission on the directory.
That's a UN*X rule, out of Emacs' hands.  (Maybe you meant, "this is a
dumb rule," in which case your philosophy is supportable, but purely
academic in the face of the well-established precedent.)

Removing a file is also controlled by directory permissions, not file
permissions (although rm(1) takes the trouble to ask if you really
meant that, if file permissions are set against you - and, if you
don't specify "-f").

Putting different data into a file depends upon write permissions on
the file, which makes sense.

Changing permissions on a file also depends upon write permissions on
the file, rather than on the directory as you might suppose (if you
reason vaguely that permissions are some kind of meta-data, perhaps).
Of course, it's necessary that write permissions on the file control
the right to change permissions, else the write permissions on the
file are a mere mockery.

But since renaming is controlled in blythe disregard for the
permissions on the file itself, there's certainly a bit of mockery
here: without write permission on the file, you may (a) rename a file
to something else, (b) copy its content to a new file of the same
name, (c) change the contents of the new file, and finally (d) remove
the old file.  Sure *looks* like you changed the contents of the file,
doesn't it?  (Unless you use the "ls -i" trick to notice the changed
inode number - which is hardly a comfort to anyone who wanted the file
contents not to change!)



Jack Repenning			9U-530	     jackr@wpd.sgi.com
Silicon Graphics, Inc.		            Off:(415) 335-7477
Systems Software Technology Center	    Fax:(415) 969-2314

ramabads@cs.rpi.edu (Shiva ) (04/19/91)

In article <1991Apr19.052504.2074@Think.COM>, barmar@think.com (Barry Margolin) writes:
|> 
|> Actually, it's not overwriting the file, and it's not changing its
|> ownership.  GNU Emacs renames the old file to filename~ or
|> filename.~<version#>~, and then creates a *new* file with the old file's
|> name.  Since you created the new file, you are its owner.
|> 

Excuse this dumb question, but should'nt the owner be the only person who
is allowed to rename files ???  Especially if the permissions are 644 as 
Kanan claims ???

-shiva
-=-
Shivkumar Ramabadran          (shiva)             ramabads@turing.cs.rpi.edu

"Always do what you are afraid to do. "
-=-

barmar@think.com (Barry Margolin) (04/20/91)

In article <stngjn.@rpi.edu> ramabads@cs.rpi.edu writes:
>Excuse this dumb question, but should'nt the owner be the only person who
>is allowed to rename files ???  Especially if the permissions are 644 as 
>Kanan claims ???

Renaming the file only affects the directory, not the file itself, so it
only requires write permission on the directory.  Consider the situation
where your friend creates a file in his directory, and then you make a hard
link to it in your directory.  Your friend is the owner of the file, but
you should be able to rename or remove your link to it.


--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar