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

Re: chmod/chown -R - maybe an ITP

On Mon, 13 Dec 1999, Daniel Burrows wrote:
>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.

My message wasn't clear on that, the comment "check contents..." should be
replaced with C code to do so.  Then we can be absolutely sure that we are
changing the Inode we want to change.

>> 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..)

If you have to run find every time then the user will be encouraged to use
the program which doesn't require all the extra typing of find, and run the
old chmod/chown programs.

The ultimate result is that some innovations that would truly benefit
consumers never occur for the sole reason that they do not coincide with
Microsoft's self-interest.
-- Judge Thomas Penfield Jackson, U.S. District Judge

Reply to: