smbd: Send "share_file_id" with the rename msg
authorVolker Lendecke <vl@samba.org>
Fri, 17 May 2019 08:44:23 +0000 (10:44 +0200)
committerJeremy Allison <jra@samba.org>
Sat, 18 May 2019 20:18:54 +0000 (20:18 +0000)
file_id plus share_file_id remotely specify the fsp. This avoids the
explicit loop in the receiver.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat May 18 20:18:55 UTC 2019 on sn-devel-184

source3/librpc/idl/open_files.idl
source3/locking/locking.c
source3/smbd/open.c

index 8111cb6360f1a34a302d88210b279eaf02df2d8c..d724d73821461f524a7fabcd285767f8a9440e5a 100644 (file)
@@ -107,6 +107,7 @@ interface open_files
 
        typedef [public] struct {
                file_id id;
+               udlong share_file_id;
                [string,charset(UTF8)] char *servicepath;
                [string,charset(UTF8)] char *base_name;
                [string,charset(UTF8)] char *stream_name;
index f46391faf458b6418ff266f1f12e718383d00a91..073651fd84129eb52750e83615227b53ee3bbab6 100644 (file)
@@ -507,8 +507,6 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
                .base_name = smb_fname_dst->base_name,
                .stream_name = smb_fname_dst->stream_name,
        };
-       DATA_BLOB blob;
-       enum ndr_err_code ndr_err;
        uint32_t i;
        struct server_id self_pid = messaging_server_id(msg_ctx);
        bool ok;
@@ -536,24 +534,11 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
        }
        d->modified = True;
 
-       ndr_err = ndr_push_struct_blob(
-               &blob,
-               talloc_tos(),
-               &msg,
-               (ndr_push_flags_fn_t)ndr_push_file_rename_message);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               DBG_DEBUG("ndr_push_file_rename_message failed: %s\n",
-                         ndr_errstr(ndr_err));
-               return false;
-       }
-       if (DEBUGLVL(10)) {
-               NDR_PRINT_DEBUG(file_rename_message, &msg);
-       }
-
        /* Send the messages. */
        for (i=0; i<d->num_share_modes; i++) {
                struct share_mode_entry *se = &d->share_modes[i];
-               struct server_id_buf tmp;
+               DATA_BLOB blob;
+               enum ndr_err_code ndr_err;
 
                if (!is_valid_share_mode_entry(se)) {
                        continue;
@@ -576,13 +561,29 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
                        continue;
                }
 
-               DBG_DEBUG("sending rename message to %s\n",
-                         server_id_str_buf(se->pid, &tmp));
+               msg.share_file_id = se->share_file_id;
+
+               ndr_err = ndr_push_struct_blob(
+                       &blob,
+                       talloc_tos(),
+                       &msg,
+                       (ndr_push_flags_fn_t)ndr_push_file_rename_message);
+               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+                       DBG_DEBUG("ndr_push_file_rename_message failed: %s\n",
+                                 ndr_errstr(ndr_err));
+                       return false;
+               }
+               if (DEBUGLEVEL >= 10) {
+                       struct server_id_buf tmp;
+                       DBG_DEBUG("sending rename message to %s\n",
+                                 server_id_str_buf(se->pid, &tmp));
+                       NDR_PRINT_DEBUG(file_rename_message, &msg);
+               }
 
                messaging_send(msg_ctx, se->pid, MSG_SMB_FILE_RENAME, &blob);
-       }
 
-       TALLOC_FREE(blob.data);
+               TALLOC_FREE(blob.data);
+       }
 
        ok = share_mode_forall_leases(lck, rename_lease_fn, NULL);
        if (!ok) {
index 43690e54fda0e74f4e58c3721c401202912f319a..ec7906b4b7782f33c4550dc1a2b85d74c6540a47 100644 (file)
@@ -4426,7 +4426,6 @@ void msg_file_was_renamed(struct messaging_context *msg_ctx,
        enum ndr_err_code ndr_err;
        files_struct *fsp;
        struct smb_filename *smb_fname = NULL;
-       NTSTATUS status;
        struct smbd_server_connection *sconn =
                talloc_get_type_abort(private_data,
                struct smbd_server_connection);
@@ -4447,7 +4446,7 @@ void msg_file_was_renamed(struct messaging_context *msg_ctx,
                          ndr_errstr(ndr_err));
                goto out;
        }
-       if (DEBUGLVL(10)) {
+       if (DEBUGLEVEL >= 10) {
                struct server_id_buf buf;
                DBG_DEBUG("Got rename message from %s\n",
                          server_id_str_buf(src, &buf));
@@ -4466,32 +4465,38 @@ void msg_file_was_renamed(struct messaging_context *msg_ctx,
                goto out;
        }
 
-       for(fsp = file_find_di_first(sconn, msg->id); fsp;
-           fsp = file_find_di_next(fsp)) {
-
-               if (strcmp(fsp->conn->connectpath, msg->servicepath) == 0) {
+       fsp = file_find_dif(sconn, msg->id, msg->share_file_id);
+       if (fsp == NULL) {
+               DBG_DEBUG("fsp not found\n");
+               goto out;
+       }
 
-                       DEBUG(10,("msg_file_was_renamed: renaming file %s from %s -> %s\n",
-                               fsp_fnum_dbg(fsp), fsp_str_dbg(fsp),
-                               smb_fname_str_dbg(smb_fname)));
-                       status = fsp_set_smb_fname(fsp, smb_fname);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               goto out;
-                       }
-               } else {
-                       /* TODO. JRA. */
-                       /* Now we have the complete path we can work out if this is
-                          actually within this share and adjust newname accordingly. */
-                       DEBUG(10,("msg_file_was_renamed: share mismatch (sharepath %s "
-                               "not sharepath %s) "
-                               "%s from %s -> %s\n",
-                               fsp->conn->connectpath,
-                               msg->servicepath,
-                               fsp_fnum_dbg(fsp),
-                               fsp_str_dbg(fsp),
-                               smb_fname_str_dbg(smb_fname)));
-               }
-        }
+       if (strcmp(fsp->conn->connectpath, msg->servicepath) == 0) {
+               NTSTATUS status;
+               DBG_DEBUG("renaming file %s from %s -> %s\n",
+                         fsp_fnum_dbg(fsp),
+                         fsp_str_dbg(fsp),
+                         smb_fname_str_dbg(smb_fname));
+               status = fsp_set_smb_fname(fsp, smb_fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DBG_DEBUG("fsp_set_smb_fname failed: %s\n",
+                                 nt_errstr(status));
+               }
+       } else {
+               /* TODO. JRA. */
+               /*
+                * Now we have the complete path we can work out if
+                * this is actually within this share and adjust
+                * newname accordingly.
+                */
+               DBG_DEBUG("share mismatch (sharepath %s not sharepath %s) "
+                         "%s from %s -> %s\n",
+                         fsp->conn->connectpath,
+                         msg->servicepath,
+                         fsp_fnum_dbg(fsp),
+                         fsp_str_dbg(fsp),
+                         smb_fname_str_dbg(smb_fname));
+       }
  out:
        TALLOC_FREE(msg);
 }