summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-11-23 01:06:39 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2016-11-23 01:06:39 +0100
commit8ee41e99502f3983fcfb75d9a88cd3dbcc4de78d (patch)
treec15971eb8abff4edd3ef85e29e5dfcb00d3fb6be
parent2bc1a49404e22e50e91c61e7cb07144871448c20 (diff)
hurd: Fix O_DIRECTORY | O_NOFOLLOW
Appending / to the path to be looked up makes us always follow a final symlink, even with O_NOTRANS (since the final resolution is after the '/'). In the O_DIRECTORY | O_NOFOLLOW case, we thus have to really open the node and stat it, which we already do anyway, and check for directory type. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r--.topdeps2
-rw-r--r--.topmsg12
-rw-r--r--hurd/hurdlookup.c2
-rw-r--r--hurd/lookup-retry.c2
4 files changed, 10 insertions, 8 deletions
diff --git a/.topdeps b/.topdeps
index 180b47c18b..74ee41695b 100644
--- a/.topdeps
+++ b/.topdeps
@@ -1 +1 @@
-baseline
+t/NOFOLLOW
diff --git a/.topmsg b/.topmsg
index 663abf4b87..ba4b793578 100644
--- a/.topmsg
+++ b/.topmsg
@@ -1,10 +1,10 @@
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
-Subject: [PATCH] hurd: Fix O_NOFOLLOW
+Subject: [PATCH] hurd: Fix O_DIRECTORY | O_NOFOLLOW
-The error code documented by POSIX for opening a symlink with O_NOFOLLOW
-is ELOOP.
-
-Also, if the translator does not expose symlink as a symlink translator but
-as a S_IFLNK file, O_NOFOLLOW needs to return ELOOP too.
+Appending / to the path to be looked up makes us always follow a final
+symlink, even with O_NOTRANS (since the final resolution is after the
+'/'). In the O_DIRECTORY | O_NOFOLLOW case, we thus have to really open
+the node and stat it, which we already do anyway, and check for
+directory type.
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
diff --git a/hurd/hurdlookup.c b/hurd/hurdlookup.c
index dbff009539..bd720c27ec 100644
--- a/hurd/hurdlookup.c
+++ b/hurd/hurdlookup.c
@@ -72,7 +72,7 @@ __hurd_file_name_lookup (error_t (*use_init_port)
if (flags & O_NOFOLLOW) /* See lookup-retry.c about O_NOFOLLOW. */
flags |= O_NOTRANS;
- if (flags & O_DIRECTORY)
+ if (flags & O_DIRECTORY && !(flags & O_NOFOLLOW))
{
/* The caller wants to require that the file we look up is a directory.
We can do this without an extra RPC by appending a trailing slash
diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index b7a6a2b2a5..d37295972b 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -147,6 +147,8 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
err = __io_stat (*result, &st);
if (!err)
{
+ if (flags & O_DIRECTORY && !S_ISDIR(st.st_mode))
+ err = ENOTDIR;
if (S_ISLNK(st.st_mode))
err = ELOOP;
else if (st.st_mode & (S_IPTRANS|S_IATRANS))