getcwd() and friends.

Guy Harris guy at auspex.auspex.com
Wed Apr 5 15:09:12 AEST 1989


>Worse than that, the permission required to open a directory is "r"
>(since one may not open a directory for writing), whereas the
>permission required to change to one is "x".  Hence, Unix protection
>would be completely violated by the existance of fchdir().

Oh dearie me.  From SunOS 4.0:

NAME
     chdir - change current working directory

SYNOPSIS
     int chdir (path)
     char *path;

     int fchdir (fd)
     int fd;

DESCRIPTION
     chdir() and fchdir cause a directory to become  the  current
     working directory, that is, the starting point for pathnames
     not beginning with `/'.

     In order for a directory to become the current directory,  a
     process must have execute (search) access to the directory.

     The path argument to chdir() points to  the  pathname  of  a
     directory.   The  fd  argument  to  fchdir  is the open file
     descriptor of a directory.

RETURN VALUE
     Upon successful completion, a value of 0 is returned.   Oth-
     erwise,  a value of -1 is returned and errno is set to indi-
     cate the error.

WARNING
     fchdir is provided  as  a  performance  enhancement  and  is
     guaranteed to fail under certain conditions.  In particular,
     if auditing is active the call will never succeed, and  EIN-
     VAL  will  be  returned.  Applications which use this system
     call must be coded to detect  this  failure  and  switch  to
     using chdir() from that point on.

Fortunately, "fchdir" requires you to have execute permission on the
directory in question, so you're safe there, even if it won't let you
change to some directories to which you could otherwise change....



More information about the Comp.unix.wizards mailing list