From 5c702e03f52dcfafa5ab0eb114ca8a6e7cac076f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 14 Jul 2022 15:13:40 +0200 Subject: [PATCH] smbd: Factor out extract_snapshot_token() from canonicalize_snapshot_path() We'll use this elsewhere soon. Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- source3/smbd/filename.c | 28 +++++++++++++++++++--------- source3/smbd/proto.h | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index 58fec6f9113..7042503eee1 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -300,6 +300,24 @@ static bool find_snapshot_token( return true; } +bool extract_snapshot_token(char *fname, NTTIME *twrp) +{ + const char *start = NULL; + const char *next = NULL; + size_t remaining; + bool found; + + found = find_snapshot_token(fname, &start, &next, twrp); + if (!found) { + return false; + } + + remaining = strlen(next); + memmove(discard_const_p(char, start), next, remaining+1); + + return true; +} + /* * Strip a valid @GMT-token from any incoming filename path, * adding any NTTIME encoded in the pathname into the @@ -318,9 +336,6 @@ NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname, uint32_t ucf_flags, NTTIME twrp) { - const char *start = NULL; - const char *next = NULL; - size_t remaining; bool found; if (twrp != 0) { @@ -331,16 +346,11 @@ NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname, return NT_STATUS_OK; } - found = find_snapshot_token( - smb_fname->base_name, &start, &next, &twrp); + found = extract_snapshot_token(smb_fname->base_name, &twrp); if (!found) { return NT_STATUS_OK; } - remaining = strlen(next); - - memmove(discard_const_p(char, start), next, remaining+1); - if (smb_fname->twrp == 0) { smb_fname->twrp = twrp; } diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 166317f7965..64653976e22 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -356,6 +356,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx, NTTIME twrp, struct smb_filename **smb_fname, uint32_t ucf_flags); +bool extract_snapshot_token(char *fname, NTTIME *twrp); NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname, uint32_t ucf_flags, NTTIME twrp); -- 2.47.3