]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: consolidate "have_file_open_below" logic in have_file_open_below()
authorRalph Boehme <slow@samba.org>
Sun, 13 Oct 2024 15:44:18 +0000 (17:44 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 5 Nov 2024 14:39:30 +0000 (14:39 +0000)
Let have_file_open_below() be the single function to check if
"have_file_open_below" and let it check internally whether to just search the
fsp list in the process or traversing locking.tdb based on the setting of
"strict rename".

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

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/dir.c
source3/smbd/dir.h
source3/smbd/smb2_reply.c

index 35aa3687b4b24502c3f860cf9051d8ead108fbdf..64a747f294f267205a239d348c620d0667494eb0 100644 (file)
@@ -1286,22 +1286,31 @@ static int have_file_open_below_fn(const struct share_mode_data *data,
        return -1;
 }
 
-bool have_file_open_below(connection_struct *conn,
-                                const struct smb_filename *name)
+bool have_file_open_below(struct files_struct *fsp)
 {
        struct have_file_open_below_state state = {
                .found_one = false,
        };
        int ret;
 
-       if (!VALID_STAT(name->st)) {
+       if (!lp_strict_rename(SNUM(fsp->conn))) {
+               if (file_find_subpath(fsp)) {
+                       return true;
+               }
                return false;
        }
-       if (!S_ISDIR(name->st.st_ex_mode)) {
+
+       if (!VALID_STAT(fsp->fsp_name->st)) {
+               return false;
+       }
+       if (!S_ISDIR(fsp->fsp_name->st.st_ex_mode)) {
                return false;
        }
 
-       ret = opens_below_forall_read(conn, name, have_file_open_below_fn, &state);
+       ret = opens_below_forall_read(fsp->conn,
+                                     fsp->fsp_name,
+                                     have_file_open_below_fn,
+                                     &state);
        if (ret == -1) {
                return false;
        }
@@ -1659,9 +1668,7 @@ NTSTATUS can_delete_directory_fsp(files_struct *fsp)
                return status;
        }
 
-       if (lp_strict_rename(SNUM(conn)) &&
-           have_file_open_below(fsp->conn, fsp->fsp_name))
-       {
+       if (have_file_open_below(fsp)) {
                return NT_STATUS_ACCESS_DENIED;
        }
 
index c6272652c0db679c6f99f93051b3a907ae64e042..21e4632eb632102da3e0ac7d7e5b32ae10e867bd 100644 (file)
@@ -47,8 +47,7 @@ char *dptr_ReadDirName(TALLOC_CTX *ctx, struct dptr_struct *dptr);
 void dptr_RewindDir(struct dptr_struct *dptr);
 void dptr_set_priv(struct dptr_struct *dptr);
 const char *dptr_wcard(struct smbd_server_connection *sconn, int key);
-bool have_file_open_below(connection_struct *conn,
-                         const struct smb_filename *name);
+bool have_file_open_below(struct files_struct *fsp);
 bool opens_below_forall(struct connection_struct *conn,
                        const struct smb_filename *dir_name,
                        int (*fn)(struct share_mode_data *data,
index d829e691ad27ea5a81222b1122c58d046a2323c1..1ac214041f2f5b1a184189bfc446bef4c6a342a0 100644 (file)
@@ -1169,17 +1169,7 @@ static NTSTATUS can_rename(connection_struct *conn, files_struct *fsp,
                /* If no pathnames are open below this
                   directory, allow the rename. */
 
-               if (lp_strict_rename(SNUM(conn))) {
-                       /*
-                        * Strict rename, check open file db.
-                        */
-                       if (have_file_open_below(fsp->conn, fsp->fsp_name)) {
-                               return NT_STATUS_ACCESS_DENIED;
-                       }
-               } else if (file_find_subpath(fsp)) {
-                       /*
-                        * No strict rename, just look in local process.
-                        */
+               if (have_file_open_below(fsp)) {
                        return NT_STATUS_ACCESS_DENIED;
                }
                return NT_STATUS_OK;