[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: chmod/chown -R - maybe an ITP



On Tue, 14 Dec 1999, Craig Sanders wrote:

> On Tue, Dec 14, 1999 at 10:05:53AM +1100, Craig Sanders wrote:
> 
> >     find $@ -uid $1 | xargs chown $2
> 
> a safer version (but still vulnerable to races) is:
> 
>      find $@ -uid $1 -follow -links 1 | xargs chown $2
> 
> you could write a safe-chown program, but even that would be vulnerable
> to races, since there is no atomic test-and-chown operation...it would
> just reduce the window of opportunity.

You're wrong, of course, as was pointed out earlier in the thread.

Once you open a file, you can check it's the right one with fstat(), and
chown it with fchown(), and it can't be replaced in between (since you
have an fd open to it, and it will stay open to the original file).

Jules

/----------------+-------------------------------+---------------------\
|  Jelibean aka  | jules@jellybean.co.uk         |  6 Evelyn Rd	       |
|  Jules aka     | jules@debian.org              |  Richmond, Surrey   |
|  Julian Bean   | jmlb2@hermes.cam.ac.uk        |  TW9 2TF *UK*       |
+----------------+-------------------------------+---------------------+
|  War doesn't demonstrate who's right... just who's left.             |
|  When privacy is outlawed... only the outlaws have privacy.          |
\----------------------------------------------------------------------/


Reply to: