]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Use share_mode_forall_entries() in has_other_nonposix_opens_fn()
authorVolker Lendecke <vl@samba.org>
Wed, 14 Aug 2019 19:40:07 +0000 (21:40 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 17 Sep 2019 22:49:37 +0000 (22:49 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/close.c

index baae5b736ff0987b5943e5982c9f1d22b1c6d13b..5b29d3477327b09581b3371930f27fc5153d2cdf 100644 (file)
@@ -233,37 +233,53 @@ NTSTATUS delete_all_streams(connection_struct *conn,
        return status;
 }
 
-bool has_other_nonposix_opens(struct share_mode_lock *lck,
-                             struct files_struct *fsp)
+struct has_other_nonposix_opens_state {
+       files_struct *fsp;
+       bool found_another;
+};
+
+static bool has_other_nonposix_opens_fn(
+       struct share_mode_entry *e,
+       bool *modified,
+       void *private_data)
 {
-       struct share_mode_data *data = lck->data;
-       struct server_id self = messaging_server_id(fsp->conn->sconn->msg_ctx);
-       uint32_t i;
-
-       for (i=0; i<data->num_share_modes; i++) {
-               struct share_mode_entry *e = &data->share_modes[i];
+       struct has_other_nonposix_opens_state *state = private_data;
+       struct files_struct *fsp = state->fsp;
 
-               if (!is_valid_share_mode_entry(e)) {
-                       continue;
-               }
-               if (e->name_hash != fsp->name_hash) {
-                       continue;
-               }
-               if ((fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) &&
-                   (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) {
-                       continue;
-               }
-               if (serverid_equal(&self, &e->pid) &&
-                   (e->share_file_id == fsp->fh->gen_id)) {
-                       continue;
-               }
-               if (share_mode_stale_pid(data, i)) {
-                       continue;
+       if (e->name_hash != fsp->name_hash) {
+               return false;
+       }
+       if ((fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) &&
+           (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) {
+               return false;
+       }
+       if (e->share_file_id == fsp->fh->gen_id) {
+               struct server_id self = messaging_server_id(
+                       fsp->conn->sconn->msg_ctx);
+               if (server_id_equal(&self, &e->pid)) {
+                       return false;
                }
-               return true;
        }
+       if (share_entry_stale_pid(e)) {
+               return false;
+       }
+
+       state->found_another = true;
+       return true;
+}
 
-       return false;
+bool has_other_nonposix_opens(struct share_mode_lock *lck,
+                             struct files_struct *fsp)
+{
+       struct has_other_nonposix_opens_state state = { .fsp = fsp };
+       bool ok;
+
+       ok = share_mode_forall_entries(
+               lck, has_other_nonposix_opens_fn, &state);
+       if (!ok) {
+               return false;
+       }
+       return state.found_another;
 }
 
 /****************************************************************************