summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2023-09-02 16:47:13 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-09-02 16:47:41 +0200
commitba9feb14c5f5780758b6d62ebb44cd90b99eccc4 (patch)
tree287e5c475f4b60a8b445737cc6f6d59ae06cfc9b
parent004164ff9965a9cb3452ca0cb34ae04ed6e1b6f6 (diff)
S_dir_lookup: Handle O_DIRECTORY
When e.g. looking up a socket with O_DIRECTORY, we should return ENOTDIR rather than EACCESS.
-rw-r--r--libdiskfs/dir-lookup.c3
-rw-r--r--libnetfs/dir-lookup.c2
2 files changed, 3 insertions, 2 deletions
diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 8df81cfa..76b9cb54 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -56,6 +56,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
int type;
struct protid *newpi = 0;
struct peropen *newpo = 0;
+ int orig_flags = flags;
if (!dircred)
return EOPNOTSUPP;
@@ -447,7 +448,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
gotit:
type = np->dn_stat.st_mode & S_IFMT;
- if (mustbedir && type != S_IFDIR)
+ if ((mustbedir || orig_flags & O_DIRECTORY) && type != S_IFDIR)
{
err = ENOTDIR;
goto out;
diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index d77feac8..23cc1fe1 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -410,7 +410,7 @@ netfs_S_dir_lookup (struct protid *dircred,
/* At this point, NP is the node to return. */
gotit:
- if (mustbedir)
+ if (mustbedir || (flags & O_DIRECTORY))
{
err = netfs_validate_stat (np, dircred->user);
if (err)