int fd = open("foo", O_RDWR);
fchmod(fd, 0);
close(fd);
Ooops! Now how do I reset the mode of "foo"? (Except as root...)
Same issue with stat(): just because you can't open a file doesn't mean
you should be prohibited from stat()'ing it.
Originally, Unix didn't have fchmod(), fstat(), fchown(), and so on.
When they were introduced, some old-timers protested that they encouraged
sloppy programming ("If you can't remember what you called it when you
open it, you don't deserve to be able to chmod() it"). But the f*() calls
are useful in avoiding security races, reducing path-mangling overhead,
and handling the more exotic ways of passing descriptors around.
In brief, we need 'em both.
-Ed
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/