smbd: Prevent creation of vetoed files
authorRalph Boehme <slow@samba.org>
Wed, 5 Apr 2023 09:03:52 +0000 (11:03 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 6 Apr 2023 23:03:50 +0000 (23:03 +0000)
The problem is when checking for vetoed names on the last path component in
openat_pathref_fsp_case_insensitive() we return
NT_STATUS_OBJECT_NAME_NOT_FOUND. The in the caller
filename_convert_dirfsp_nosymlink() this is treated as the "file creation case"
causing filename_convert_dirfsp_nosymlink() to return NT_STATUS_OK.

In order to correctly distinguish between the cases

1) file doesn't exist, we may be creating it, return
2) a vetoed a file

we need 2) to return a more specific error to
filename_convert_dirfsp_nosymlink(). I've chosen NT_STATUS_OBJECT_NAME_INVALID
which gets mapped to the appropriate errror NT_STATUS_OBJECT_PATH_NOT_FOUND or
NT_STATUS_OBJECT_NAME_NOT_FOUND depending on which path component was vetoed.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15143

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Apr  6 23:03:50 UTC 2023 on atb-devel-224

selftest/knownfail.d/samba3.blackbox.test_veto_files.get_veto_file [deleted file]
source3/smbd/filename.c

diff --git a/selftest/knownfail.d/samba3.blackbox.test_veto_files.get_veto_file b/selftest/knownfail.d/samba3.blackbox.test_veto_files.get_veto_file
deleted file mode 100644 (file)
index ff8f37f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba3.blackbox.test_veto_files.create_veto_file\(fileserver\)
index e5cb3c867cd92e68d1c3185a0a0ec0ca94f00c9f..a5ee0392bae4b855414b13346b4d4a3a0a7da309 100644 (file)
@@ -752,7 +752,7 @@ static NTSTATUS openat_pathref_fsp_case_insensitive(
        if (IS_VETO_PATH(dirfsp->conn, smb_fname_rel->base_name)) {
                DBG_DEBUG("veto files rejecting last component %s\n",
                          smb_fname_str_dbg(smb_fname_rel));
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               return NT_STATUS_NETWORK_OPEN_RESTRICTION;
        }
 
        status = openat_pathref_fsp(dirfsp, smb_fname_rel);
@@ -818,7 +818,7 @@ static NTSTATUS openat_pathref_fsp_case_insensitive(
                        DBG_DEBUG("veto files rejecting last component %s\n",
                                  smb_fname_str_dbg(smb_fname_rel));
                        TALLOC_FREE(cache_key.data);
-                       return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+                       return NT_STATUS_NETWORK_OPEN_RESTRICTION;
                }
 
                status = openat_pathref_fsp(dirfsp, smb_fname_rel);
@@ -848,7 +848,7 @@ lookup:
                if (IS_VETO_PATH(dirfsp->conn, smb_fname_rel->base_name)) {
                        DBG_DEBUG("veto files rejecting last component %s\n",
                                smb_fname_str_dbg(smb_fname_rel));
-                       return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+                       return NT_STATUS_NETWORK_OPEN_RESTRICTION;
                }
 
                status = openat_pathref_fsp(dirfsp, smb_fname_rel);
@@ -1292,6 +1292,10 @@ static NTSTATUS filename_convert_dirfsp_nosymlink(
                goto done;
        }
 
+       if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_OPEN_RESTRICTION)) {
+               /* A vetoed file, pretend it's not there  */
+               status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
        if (!NT_STATUS_IS_OK(status)) {
                goto fail;
        }