smbd: Use share_mode_forall_entries() in set_delete_on_close_lck()
authorVolker Lendecke <vl@samba.org>
Wed, 14 Aug 2019 15:29:19 +0000 (17:29 +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/locking/locking.c

index e8820ee03567effa13fa66f5ff993ad5ab793ff7..d3d954c2d8372a65a821ba66199202b906a0d8fe 100644 (file)
@@ -1021,6 +1021,35 @@ void reset_delete_on_close_lck(files_struct *fsp,
        }
 }
 
+struct set_delete_on_close_state {
+       struct messaging_context *msg_ctx;
+       DATA_BLOB blob;
+};
+
+static bool set_delete_on_close_fn(
+       struct share_mode_entry *e,
+       bool *modified,
+       void *private_data)
+{
+       struct set_delete_on_close_state *state = private_data;
+       NTSTATUS status;
+
+       status = messaging_send(
+               state->msg_ctx,
+               e->pid,
+               MSG_SMB_NOTIFY_CANCEL_DELETED,
+               &state->blob);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               struct server_id_buf tmp;
+               DBG_DEBUG("messaging_send to %s returned %s\n",
+                         server_id_str_buf(e->pid, &tmp),
+                         nt_errstr(status));
+       }
+
+       return false;
+}
+
 /****************************************************************************
  Sets the delete on close flag over all share modes on this file.
  Modify the share mode entry for all files open
@@ -1037,11 +1066,12 @@ void set_delete_on_close_lck(files_struct *fsp,
                        const struct security_token *nt_tok,
                        const struct security_unix_token *tok)
 {
-       struct messaging_context *msg_ctx = fsp->conn->sconn->msg_ctx;
        struct share_mode_data *d = lck->data;
+       struct set_delete_on_close_state state = {
+               .msg_ctx = fsp->conn->sconn->msg_ctx
+       };
        uint32_t i;
        bool ret;
-       DATA_BLOB fid_blob = {};
        enum ndr_err_code ndr_err;
 
        SMB_ASSERT(nt_tok != NULL);
@@ -1067,30 +1097,23 @@ void set_delete_on_close_lck(files_struct *fsp,
        ret = add_delete_on_close_token(lck->data, fsp->name_hash, nt_tok, tok);
        SMB_ASSERT(ret);
 
-       ndr_err = ndr_push_struct_blob(&fid_blob, talloc_tos(), &fsp->file_id,
-                                      (ndr_push_flags_fn_t)ndr_push_file_id);
+       ndr_err = ndr_push_struct_blob(
+               &state.blob,
+               talloc_tos(),
+               &fsp->file_id,
+               (ndr_push_flags_fn_t)ndr_push_file_id);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                DEBUG(10, ("ndr_push_file_id failed: %s\n",
                           ndr_errstr(ndr_err)));
        }
 
-       for (i=0; i<d->num_share_modes; i++) {
-               struct share_mode_entry *e = &d->share_modes[i];
-               NTSTATUS status;
-
-               status = messaging_send(
-                       msg_ctx, e->pid, MSG_SMB_NOTIFY_CANCEL_DELETED,
-                       &fid_blob);
-
-               if (!NT_STATUS_IS_OK(status)) {
-                       struct server_id_buf tmp;
-                       DEBUG(10, ("%s: messaging_send to %s returned %s\n",
-                                  __func__, server_id_str_buf(e->pid, &tmp),
-                                  nt_errstr(status)));
-               }
+       ret = share_mode_forall_entries(
+               lck, set_delete_on_close_fn, &state);
+       if (!ret) {
+               DBG_DEBUG("share_mode_forall_entries failed\n");
        }
 
-       TALLOC_FREE(fid_blob.data);
+       TALLOC_FREE(state.blob.data);
 }
 
 bool set_delete_on_close(files_struct *fsp, bool delete_on_close,