From cd0352a9ca2988d7a4525fbcd21fd730e1f37ed7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 2 Aug 2024 11:04:31 +0200 Subject: [PATCH] libsmb: Slightly restructure map_smb2_handle_to_fnum Pass the persistent/volatile handle as uint64's. Why? I found the talloc_memdup() slightly misleading, and smbXcli handles those 2 id's separately. map_smb2_handle_to_fnum() is the function to create the smb2_hnd. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/libsmb/cli_smb2_fnum.c | 37 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c index 7f44435963f..c0b7d38eced 100644 --- a/source3/libsmb/cli_smb2_fnum.c +++ b/source3/libsmb/cli_smb2_fnum.c @@ -56,23 +56,27 @@ struct smb2_hnd { */ /*************************************************************** - Allocate a new fnum between 1 and 0xFFFE from an smb2_hnd. + Allocate a new fnum between 1 and 0xFFFE from an smb2 file id. Ensures handle is owned by cli struct. ***************************************************************/ static NTSTATUS map_smb2_handle_to_fnum(struct cli_state *cli, - const struct smb2_hnd *ph, /* In */ - uint16_t *pfnum) /* Out */ + uint64_t fid_persistent, + uint64_t fid_volatile, + uint16_t *pfnum) { int ret; struct idr_context *idp = cli->smb2.open_handles; - struct smb2_hnd *owned_h = talloc_memdup(cli, - ph, - sizeof(struct smb2_hnd)); + struct smb2_hnd *owned_h = NULL; + owned_h = talloc(cli, struct smb2_hnd); if (owned_h == NULL) { return NT_STATUS_NO_MEMORY; } + *owned_h = (struct smb2_hnd){ + .fid_persistent = fid_persistent, + .fid_volatile = fid_volatile, + }; if (idp == NULL) { /* Lazy init */ @@ -342,22 +346,25 @@ static void cli_smb2_create_fnum_done(struct tevent_req *subreq) subreq, struct tevent_req); struct cli_smb2_create_fnum_state *state = tevent_req_data( req, struct cli_smb2_create_fnum_state); - struct smb2_hnd h; + uint64_t fid_persistent, fid_volatile; NTSTATUS status; - status = smb2cli_create_recv( - subreq, - &h.fid_persistent, - &h.fid_volatile, &state->cr, - state, - &state->out_cblobs, - &state->symlink); + status = smb2cli_create_recv(subreq, + &fid_persistent, + &fid_volatile, + &state->cr, + state, + &state->out_cblobs, + &state->symlink); TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } - status = map_smb2_handle_to_fnum(state->cli, &h, &state->fnum); + status = map_smb2_handle_to_fnum(state->cli, + fid_persistent, + fid_volatile, + &state->fnum); if (tevent_req_nterror(req, status)) { return; } -- 2.47.3