Re: Why is chmod(2)?

Jakub Jelinek (jj@sunsite.ms.mff.cuni.cz)
Wed, 22 Sep 1999 08:39:14 +0200


On Wed, Sep 22, 1999 at 02:08:28AM +0200, Kristian Koehntopp wrote:
>
> I was talking about Unix system security recently and came
> across a strange question which you may be able to answer. The
> question is: "Why is chmod(2)", i.e. why are there so many
> kernel functions which take pathnames as parameters, when there
> are similar functions which take an fd.
>
> One obvious reason is of course compatibility. There are
> binaries that call chmod(2) and they should continue to work.
> But compatibility aside, can chmod(2) be implemented as chmod(3)
> using open(2) and fchmod(2) and is the same true for all other
> system calls which take pathnames as an argument?

open(2)ing some files (e.g. devices) may produce various side effects which
are usually not desirable when you e.g. want to list a directory.
Also, with your suggestion, ls -l would require to open each of the files,
fstat it, close it, that's 3 times the amount of syscalls needed now.
What about stale symlinks? They should be lstatable, but open(2) will not
open you a file, nor the difference between lstat/stat disappears. Bad.

If the program needs to make sure a file is not changed underneath, it can
use open/fstat/close.

Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jj@sunsite.mff.cuni.cz | http://sunsite.mff.cuni.cz
Administrator of SunSITE Czech Republic, MFF, Charles University
___________________________________________________________________
UltraLinux | http://ultra.linux.cz/ | http://ultra.penguin.cz/
Linux version 2.3.18 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

-
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/