]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Slightly restructure map_smb2_handle_to_fnum
authorVolker Lendecke <vl@samba.org>
Fri, 2 Aug 2024 09:04:31 +0000 (11:04 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 6 Aug 2024 16:29:33 +0000 (16:29 +0000)
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 <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/cli_smb2_fnum.c

index 7f44435963f7e625fd6987ea7b680314fbd6d7c4..c0b7d38eceddb2d9796ee0fcbaa791511bfd094b 100644 (file)
@@ -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;
        }