]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: add has_nonposix_opens()
authorRalph Boehme <slow@samba.org>
Wed, 16 Oct 2024 05:37:25 +0000 (07:37 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 5 Nov 2024 14:39:30 +0000 (14:39 +0000)
...reusing has_other_nonposix_opens_fn().

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/close.c
source3/smbd/proto.h

index 5cb2bb6f17c2dcba5147fdb42187f1edefaffce8..b14955c511e480ec05a9c79358525197705378d4 100644 (file)
@@ -239,18 +239,20 @@ static bool has_other_nonposix_opens_fn(
        struct has_other_nonposix_opens_state *state = private_data;
        struct files_struct *fsp = state->fsp;
 
-       if (e->name_hash != fsp->name_hash) {
-               return false;
-       }
        if (e->flags & SHARE_MODE_FLAG_POSIX_OPEN) {
                return false;
        }
-       if (e->share_file_id == fh_get_gen_id(fsp->fh)) {
-               struct server_id self = messaging_server_id(
-                       fsp->conn->sconn->msg_ctx);
-               if (server_id_equal(&self, &e->pid)) {
+       if (fsp != NULL) {
+               if (e->name_hash != fsp->name_hash) {
                        return false;
                }
+               if (e->share_file_id == fh_get_gen_id(fsp->fh)) {
+                       struct server_id self = messaging_server_id(
+                               fsp->conn->sconn->msg_ctx);
+                       if (server_id_equal(&self, &e->pid)) {
+                               return false;
+                       }
+               }
        }
        if (share_entry_stale_pid(e)) {
                return false;
@@ -274,6 +276,19 @@ bool has_other_nonposix_opens(struct share_mode_lock *lck,
        return state.found_another;
 }
 
+bool has_nonposix_opens(struct share_mode_lock *lck)
+{
+       struct has_other_nonposix_opens_state state = {};
+       bool ok;
+
+       ok = share_mode_forall_entries(
+               lck, has_other_nonposix_opens_fn, &state);
+       if (!ok) {
+               return false;
+       }
+       return state.found_another;
+}
+
 struct close_share_mode_lock_state {
        struct share_mode_entry_prepare_state prepare_state;
        const char *object_type;
index 8437b4d140e8792db1540da61b81fed539b72fb7..7b1b40e094bdf42f2f823ae520a59d0f1db645b5 100644 (file)
@@ -137,6 +137,7 @@ NTSTATUS recursive_rmdir(TALLOC_CTX *ctx,
                     struct smb_filename *smb_dname);
 bool has_other_nonposix_opens(struct share_mode_lock *lck,
                              struct files_struct *fsp);
+bool has_nonposix_opens(struct share_mode_lock *lck);
 
 /* The following definitions come from smbd/conn.c  */