1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

smbd: Send "share_file_id" with the rename msg

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
This commit is contained in:
Volker Lendecke 2019-05-17 10:44:23 +02:00 committed by Jeremy Allison
parent f1226bfbe9
commit 07bbcf3aec
3 changed files with 54 additions and 47 deletions

View 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;

View 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) {

View 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)) {
fsp = file_find_dif(sconn, msg->id, msg->share_file_id);
if (fsp == NULL) {
DBG_DEBUG("fsp not found\n");
goto out;
}
if (strcmp(fsp->conn->connectpath, msg->servicepath) == 0) {
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);
}