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

Re: chmod/chown -R - maybe an ITP



On Mon, Dec 13, 1999 at 04:05:19PM +0100, Russell Coker was heard to say:
> According to the man pages O_EXCL only makes sense for creating files.
> 
> The solution is to write a program which does a readdir stat()'ing all the
> files, when it finds one it thinks should be changed it does:
> fd = open(filename);
> if(fd > -1)
> {
>   fstat(fd, buf);
>   // check contents of buf and log an error if we don't like them
>   fchown(fd, owner group);
> }

  Maybe I'm being dense, but it looks to me like this has the same race
condition, although it's harder to exploit since the time gap is small.

> Not overly hard to do, but the sort of thing that should be done once and
> done right, not done at every site.
> I think that I could write a usable program performing the function of any
> program in fileutils in 30 minutes or less.  However such programs wouldn't
> be as functional as the fileutils ones, and I wouldn't want to write and
> maintain them seperately for different sites.

  I'd like to suggest, unless there's a really good reason, that you not build
recursion into your programs -- that is, that you just implement a single-file
'safe chown' operation, which checks that the owner is what it's expecting and
then changes it.  This will be easier to write and probably more flexible, and
I don't see any reason that find can't do the recursion for you. (though I
could be missing something obvious..)

  Daniel

-- 
"I can see that you are clearly a much better swordsman than I am!"
"Then why are you smiling?"
"Because I know something you don't know."
"And what is that?"
"I am not left-handed."
  -- "The Princess Bride"


Reply to: