From da1fdfb68b95a246f45be0e08d9a8ebda386be88 Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Fri, 11 Oct 2024 10:34:12 +0900 Subject: [PATCH] Open file requests with trailing slash should fail When opening "file.txt/" explorer.exe expects to get an error. This also fixes Run As Administrator, when mimic is set to "ntfs". Signed-off-by: Jorgen Lundman --- module/os/windows/zfs/zfs_vnops_windows.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/module/os/windows/zfs/zfs_vnops_windows.c b/module/os/windows/zfs/zfs_vnops_windows.c index a38ec3c33a3..40dbc0ed0c1 100644 --- a/module/os/windows/zfs/zfs_vnops_windows.c +++ b/module/os/windows/zfs/zfs_vnops_windows.c @@ -598,6 +598,7 @@ zfs_find_dvp_vp(zfsvfs_t *zfsvfs, char *filename, int finalpartmaynotexist, int fullstrlen; char namebuffer[MAXNAMELEN]; BOOLEAN FileOpenReparsePoint; + BOOLEAN has_trailing_separator = FALSE; FileOpenReparsePoint = BooleanFlagOn(options, FILE_OPEN_REPARSE_POINT); @@ -624,8 +625,10 @@ zfs_find_dvp_vp(zfsvfs_t *zfsvfs, char *filename, int finalpartmaynotexist, // Sometimes we are given a path like "\Directory\directory\" // with the final separator, we want to eat that final character. if ((fullstrlen > 2) && - (filename[fullstrlen - 1] == '\\')) + (filename[fullstrlen - 1] == '\\')) { filename[--fullstrlen] = 0; + has_trailing_separator = TRUE; + } for (word = strtok_r(filename, "/\\", &brkt); word; @@ -756,6 +759,14 @@ zfs_find_dvp_vp(zfsvfs_t *zfsvfs, char *filename, int finalpartmaynotexist, return (ESRCH); } + // Check if we got a file, but request had trailing slash + if (vp != NULL && !vnode_isdir(vp) && has_trailing_separator) { + VN_RELE(vp); + VN_RELE(dvp); + // NTFS returns STATUS_OBJECT_NAME_INVALID + return (STATUS_OBJECT_NAME_INVALID); // ENOTDIR + } + if (lastname) { *lastname = word /* ? word : filename */; @@ -1773,6 +1784,7 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo, } VN_RELE(dvp); } else { + // Technically, this should call zfs_open() - // but zfs_open is mostly empty