libsmb: Use clistr_smb2_extract_snapshot_token() in cli_smb2_create_fnum_send()
authorJeremy Allison <jra@samba.org>
Thu, 15 Dec 2022 21:32:35 +0000 (13:32 -0800)
committerVolker Lendecke <vl@samba.org>
Fri, 16 Dec 2022 07:42:38 +0000 (07:42 +0000)
Now that fname is writable, we can avoid a bit of complexity with
clistr_smb2_extract_snapshot_token()

Signed-off-by: Volker Lendecke <vl@samba.org>
Signed-off-by: Jeremy Allison <jra@samba.org>
source3/libsmb/cli_smb2_fnum.c

index 084aef283cb96c02b00fa137941b3ab849c6a2ba..6db9fca612c28176a19088417de52d0b246c40cb 100644 (file)
@@ -224,8 +224,7 @@ struct tevent_req *cli_smb2_create_fnum_send(
        struct cli_smb2_create_fnum_state *state;
        char *fname = NULL;
        size_t fname_len = 0;
-       const char *startp = NULL;
-       const char *endp = NULL;
+       bool have_twrp;
        NTTIME ntt;
        NTSTATUS status;
 
@@ -246,23 +245,8 @@ struct tevent_req *cli_smb2_create_fnum_send(
        }
 
        /* Check for @GMT- paths. Remove the @GMT and turn into TWrp if so. */
-       fname_len = strlen(fname);
-       if (clistr_is_previous_version_path(fname, &startp, &endp, &ntt)) {
-               size_t len_before_gmt = startp - fname;
-               size_t len_after_gmt = fname + fname_len - endp;
-
-               char *new_fname = talloc_array(state, char,
-                               len_before_gmt + len_after_gmt + 1);
-
-               if (tevent_req_nomem(new_fname, req)) {
-                       return tevent_req_post(req, ev);
-               }
-
-               memcpy(new_fname, fname, len_before_gmt);
-               memcpy(new_fname + len_before_gmt, endp, len_after_gmt + 1);
-               fname = new_fname;
-               fname_len = len_before_gmt + len_after_gmt;
-
+       have_twrp = clistr_smb2_extract_snapshot_token(fname, &ntt);
+       if (have_twrp) {
                status = smb2_create_blob_add(
                        state,
                        &state->in_cblobs,