summaryrefslogtreecommitdiff
path: root/lib/chdir-safer.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-12-27 07:54:37 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-12-27 07:54:37 +0000
commit8846a6bfdd11703c53d6bbb288b5f1fd74468143 (patch)
tree172afb64234c7e115afc1ac1d9d45bf5ef8b6226 /lib/chdir-safer.c
parenta2c8ec26a4cb771ee0e13e2b08daf0f3c9b03d97 (diff)
downloadcoreutils-8846a6bfdd11703c53d6bbb288b5f1fd74468143.tar.xz
(chdir_no_follow): Don't bother trying to open directory for write
access: POSIX says that must fail.
Diffstat (limited to 'lib/chdir-safer.c')
-rw-r--r--lib/chdir-safer.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c
index f6b42ce9d..1aeaae840 100644
--- a/lib/chdir-safer.c
+++ b/lib/chdir-safer.c
@@ -44,27 +44,18 @@
&& (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
/* Like chdir, but fail if DIR is a symbolic link to a directory (or
- similar funny business), or if DIR is neither readable nor
- writable. This avoids a minor race condition between when a
- directory is created or statted and when the process chdirs into it.
-
- On some systems, a writable yet unreadable directory cannot be
- opened via open with O_WRONLY. For example, on Linux 2.6, the
- open syscall fails with EISDIR. */
+ similar funny business), or if DIR not readable. This avoids a
+ minor race condition between when a directory is created or statted
+ and when the process chdirs into it. */
int
chdir_no_follow (char const *dir)
{
int result = 0;
int saved_errno;
- int open_flags = O_DIRECTORY | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK;
- int fd = open (dir, O_RDONLY | open_flags);
+ int fd = open (dir,
+ O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK);
if (fd < 0)
- {
- if (errno == EACCES)
- fd = open (dir, O_WRONLY | open_flags);
- if (fd < 0)
- return fd;
- }
+ return -1;
/* If open follows symlinks, lstat DIR and fstat FD to ensure that
they are the same file; if they are different files, set errno to