From 35b99c87ef92df006f8b0a41bbea051f0faeadb9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 12 Aug 2022 19:12:44 +0200 Subject: [PATCH] s3:smbd: let openat_pathref_dirfsp_nosymlink() handle ELOOP similar to ENOTDIR This is no likely to happen as we use O_NOFOLLOW with O_DIRECTORY, but it's better to be prepared... This will be more important in the upcoming openat2(RESOLVE_NO_SYMLINK) case, but we should be consitent... Signed-off-by: Stefan Metzmacher Reviewed-by: Volker Lendecke --- source3/smbd/files.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index f23e9e96e52..23de0ad63c2 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -860,7 +860,15 @@ next: &how); } - if ((fd == -1) && (errno == ENOTDIR)) { + /* + * O_NOFOLLOW|O_DIRECTORY results in + * ENOTDIR instead of ELOOP. + * + * But we should be prepared to handle ELOOP too. + */ + if ((fd == -1) && (errno == ENOTDIR || errno == ELOOP)) { + NTSTATUS orig_status = map_nt_error_from_unix(errno); + status = readlink_talloc( mem_ctx, dirfsp, &rel_fname, substitute); @@ -898,7 +906,7 @@ next: /* * Restore the error status from SMB_VFS_OPENAT() */ - status = NT_STATUS_NOT_A_DIRECTORY; + status = orig_status; } goto fail; } -- 2.47.3